Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Documentation for html Property in Lexical Editor Configuration #6762

Closed
Kingscliq opened this issue Oct 25, 2024 · 19 comments · Fixed by #6770
Closed

Add Documentation for html Property in Lexical Editor Configuration #6762

Kingscliq opened this issue Oct 25, 2024 · 19 comments · Fixed by #6770

Comments

@Kingscliq
Copy link
Contributor

Kingscliq commented Oct 25, 2024

The html property in the Lexical editor configuration allows developers to add importDOM and exportDOM implementations directly, without needing node replacement. However, this property is currently undocumented, leading to a missed opportunity for users to utilize it effectively when working with HTML parsing and serialization in their editors.

Adding comprehensive documentation for the html property could benefit developers looking to manage HTML imports and exports, especially when aiming to integrate with other systems that rely on HTML or when handling complex content transformations.

Proposed Solution:

  1. Update the Lexical documentation to include the html property in the editor configuration section.

  2. Provide a brief example demonstrating the use of import and export with html.

Originally posted by @etrepum in #6532 (comment)

@Kingscliq
Copy link
Contributor Author

Kingscliq commented Oct 25, 2024

Hi @etrepum I was going through the docs and want to be sure if this is similar to what I am trying to add to the documentation, or what I should be adding will be an addition to this?

Link

@etrepum
Copy link
Collaborator

etrepum commented Oct 25, 2024

Yes, exportDOM is similar to the html export config

export type DOMExportOutputMap = Map<
Klass<LexicalNode>,
(editor: LexicalEditor, target: LexicalNode) => DOMExportOutput
>;

export type HTMLConfig = {
export?: DOMExportOutputMap;
import?: DOMConversionMap;
};
export type CreateEditorArgs = {
disableEvents?: boolean;
editorState?: EditorState;
namespace?: string;
nodes?: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>;
onError?: ErrorHandler;
parentEditor?: LexicalEditor;
editable?: boolean;
theme?: EditorThemeClasses;
html?: HTMLConfig;
};

There's also the import property which is similar to importDOM

@Kingscliq
Copy link
Contributor Author

Kingscliq commented Oct 25, 2024

Yes, exportDOM is similar to the html export config

export type DOMExportOutputMap = Map<
Klass<LexicalNode>,
(editor: LexicalEditor, target: LexicalNode) => DOMExportOutput
>;

export type HTMLConfig = {
export?: DOMExportOutputMap;
import?: DOMConversionMap;
};
export type CreateEditorArgs = {
disableEvents?: boolean;
editorState?: EditorState;
namespace?: string;
nodes?: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>;
onError?: ErrorHandler;
parentEditor?: LexicalEditor;
editable?: boolean;
theme?: EditorThemeClasses;
html?: HTMLConfig;
};

There's also the import property which is similar to importDOM

This is so cool, How did you do this?

@Kingscliq
Copy link
Contributor Author

I mean, like referencing the files directly including the lines numbers and files

@Kingscliq
Copy link
Contributor Author

So is it safe to day, it is documented already, I should go ahead and provide examples usage on the lexical-website package?

@etrepum
Copy link
Collaborator

etrepum commented Oct 25, 2024

The html property of the editor config (CreateEditorArgs) is not documented and it does not have any examples. It has two properties, import and export. import is similar to importDOM and export is similar to exportDOM.

@etrepum
Copy link
Collaborator

etrepum commented Oct 25, 2024

You can link to specific parts of a file on GitHub by clicking the line number and then shift-clicking another line number to select a range, then you click the […] button and copy the permalink. When you paste that permalink in a github issue/pr/discussion then its contents will be unfurled

@Kingscliq
Copy link
Contributor Author

You can link to specific parts of a file on GitHub by clicking the line number and then shift-clicking another line number to select a range, then you click the […] button and copy the permalink. When you paste that permalink in a github issue/pr/discussion then its contents will be unfurled

Thanks for the tips

@Kingscliq
Copy link
Contributor Author

The html property of the editor config (CreateEditorArgs) is not documented and it does not have any examples. It has two properties, import and export. import is similar to importDOM and export is similar to exportDOM.

Okay then, I will hop on it

@Kingscliq
Copy link
Contributor Author

One more question, the changes I will be making should be on the should be on the lexical-website package right? which has been written with MarkDown all through, and for the example, can I put a link to the codesandbox or add to lexical-playground package.

Noot sure how to put this question, I hope its clear enough

@etrepum
Copy link
Collaborator

etrepum commented Oct 25, 2024

There are two places that this documentation can be added, one is directly in the source code via tsdoc/jsdoc block comments that get extracted by typedoc /** … */ and the other are the markdown files in lexical-website (the ones that are not automatically generated). It's up to you whether you choose to do one or both of those, any addition is a big improvement for a feature with no docs!

For an example of the feature I would recommend either adding it to one of the existing examples, the playground, or creating a new example project in the examples folder (which can be linked to in docs via stackblitz). Codesandbox examples are not great because they are not managed in the monorepo so they quickly become stale or stop working altogether when someone cleans up their account.

@Kingscliq
Copy link
Contributor Author

There are two places that this documentation can be added, one is directly in the source code via tsdoc/jsdoc block comments that get extracted by typedoc /** … */ and the other are the markdown files in lexical-website (the ones that are not automatically generated). It's up to you whether you choose to do one or both of those, any addition is a big improvement for a feature with no docs!

For an example of the feature I would recommend either adding it to one of the existing examples, the playground, or creating a new example project in the examples folder (which can be linked to in docs via stackblitz). Codesandbox examples are not great because they are not managed in the monorepo so they quickly become stale or stop working altogether when someone cleans up their account.

This would be very helpful, thanks @etrepum

@Kingscliq
Copy link
Contributor Author

Hi @etrepum, just before I raise a PR for this I wanted to be sure, I am putting the brief description and example in the right place
Screenshot 2024-10-26 at 6 59 39 AM

@etrepum
Copy link
Collaborator

etrepum commented Oct 26, 2024

I don't think that package is the best place to document it because you'd be using it from either lexical's createEditor or LexicalComposer's initialConfig. Maybe https://lexical.dev/docs/concepts/serialization would be the best place alongside other importDOM and exportDOM docs.

The example code in that screenshot is not correct at all, not sure if that is just a placeholder?

@Kingscliq
Copy link
Contributor Author

Kingscliq commented Oct 26, 2024

I don't think that package is the best place to document it because you'd be using it from either lexical's createEditor or LexicalComposer's initialConfig. Maybe https://lexical.dev/docs/concepts/serialization would be the best place alongside other importDOM and exportDOM docs.

The example code in that screenshot is not correct at all, not sure if that is just a placeholder?

Got it! I am moving it to concepts/serialization.

yes, the example is a placeholder, I wanted to be sure that, that was the best place to put it or If I should put it in a different place. Then I also have a more concise doc for the HTML properties and the difference between the exportDOM/ importDOM properties and import/export. I need clarity on where to place the example

@Kingscliq
Copy link
Contributor Author

I was also going throught the playground, wanted to ask about the exportDOM implementation. I left details on the screenshots @etrepum

Screenshot 2024-10-26 at 8 41 52 AM

@etrepum
Copy link
Collaborator

etrepum commented Oct 26, 2024

Yes that button triggers exportDOM, indirectly via $generateHtmlFromNodes. The exportDOM method is called on each node in the document to assemble the result. The html export config allows the method to be overridden without subclassing and node replacement.

@vadimkantorov
Copy link

vadimkantorov commented Oct 30, 2024

Curious if slowness of export could be an issue for export as html as e.g. it is for export as markdown:

Images can take a lot of time to encode as base64, so having some solution for this might be good (e.g. allowing export as "virtual-urls" / hooks image export, so that the user can upload/manage images by themselves) and optionally somehow being able to do the export on a worker thread

@etrepum
Copy link
Collaborator

etrepum commented Oct 30, 2024

This issue doesn't really have anything to do with the bad strategy that the playground uses to represent images for demonstration purposes. If you were to change how it handles images, you would just modify that node's createDOM and exportDOM directly rather than configure exportDOM somewhere else. This configuration option is only relevant to exportDOM and importDOM (not createDOM) and is only useful for when you don't want to modify the class, but since that class isn't available on NPM and it would have to be copied into your project to use it there's no reason why you couldn't modify its exportDOM directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants