How to update a mention once it got renamed or deleted? #2646
Replies: 1 comment 1 reply
-
hey, quite old though I'm curious did you figure it out? I think it depends on your requirements, but one thing I started doing in my custom details.mentions = lexical.$nodesOfType(MentionNode).map((n) => n.exportJSON()); which I then store separate from the tree, currently all in 1 json column but possibly going to store mentions for example in a separate table so I can store more details like if that user has been notified etc and also have easy back-links. Not sure about the need to store an id in a MentionNode, though you'd need to keep track of which mentions are still in the current lexical state and which ones have been removed. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to build a mention feature in the editor. I started by copying the
MentionsPlugin
,MentionNode
andLexicalTypeaheadMenuPlugin
from the playground.In the playground, when you use a mention and export state into JSON (that's the format I want to store in the database) it outputs something like this for
MentionNode
:The problem is, that it doesn't store the
id
of the element, so I don't know what has got mentioned. I changed the schema ofMentionNode
to return something like this:I removed
mentionName
and addedentity
andentityId
so that I can later on react if something changes.Now, what if user (or whatever other object we mention) renames? We have the
id
so can probably update the schema, but where to do it - frontend or backend?I think the easiest thing is to traverse the saved state on the backend, collect all mentioned
ids
and get the fresh mentions? 🤔 How to iterate over the lexical state - is there some helper around that?Beta Was this translation helpful? Give feedback.
All reactions