Problems to create an interactive and selectable node #3161
-
Hello everyone,
I'm using Lexical to create a react platform where users can interact with legal documents, we allow users to select and classify parts of the documents, like the image bellow: The text above is in portuguese, but the important part is the highlighted text with a tag between brackets and the close button at the end. The requirements of this features are the following:
I tried two approaches and got stuck in both of them for different reasons. I'll explain both of my approaches and describe my problem with each one of them. First approach: use a DecoratorNodeBeing a React developer my first approach was to use a I end up with something like this: decorate(editor: LexicalEditor): JSX.Element {
return (
<HighlightedText
...
onClick={() =>
editor.dispatchCommand(ON_TEXT_CLICK_COMMAND, ...)
}
onClose={() => {
editor.dispatchCommand(ON_X_CLICK_COMMAND, ...)
}}
/>
)
} The shortcoming of this solution is the selection interface. Since this is a Second approach: extend a
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
What you want to use is a mutation listener on your given custom node. This will allow you to know when said nodes are created, updated and destroyed. In the creation phase, you can add event listeners to the DOM element using |
Beta Was this translation helpful? Give feedback.
-
@pedrocalderon Hi Pedro I presume you somehow save the user's highlight/tag information in a database and later deserialize it to put back the classifications. I was wondering if you saved the entire (document + classification) serialization together as a whole, or if you can save just the classifications separately from the original document. I've got a similar use case where users must be able to highlight/memo on selected parts of the document but the original document cannot be modified. I was having trouble trying to separately serialize the user highlight/memos and then put them back on top of the document later on, so any help or suggestions would be greatly appreciated :) |
Beta Was this translation helpful? Give feedback.
What you want to use is a mutation listener on your given custom node. This will allow you to know when said nodes are created, updated and destroyed. In the creation phase, you can add event listeners to the DOM element using
editor.getElementByKey