Is the intent to always serialize Lexical state to the database? #5512
sherrellbc
started this conversation in
General
Replies: 1 comment
-
Hope you've figured it out by now, commenting just in case and potentially for others It depends, in our case we store a plaintext version and the full json editor state in the db, especially cause we're working with rich text as you mentioned Still I have this to restore from plaintext in certain cases or where I later changed a const initialConfig: InitialConfigType = {
editorState(editor) {
editor.update(() => {
const root = $getRoot();
const splitted = plaintext.split(/\r?\n|\r|\n/g);
splitted.forEach((v) => {
const paragraphNode = $createFederParagraphNode();
const textNode = $createFederTextNode(v);
paragraphNode.append(textNode);
root.append(paragraphNode);
});
});
},
}; This ensures that paragraphs are properly restored and is sufficient in our case so far, you could of course tweak it to your needs. Hope this helps ❤️ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a simple application that instantiates a
PlainTextPlugin
that has some simple markdown processing. The users can save the contents and then later edit them. I can easily get the text-based contents of the editor (and save to my database) but it is not simple (impossible?) to create a new Lexical editor and restore this text.I see no way to restore Lexical editor state from string contents - only from a serialized JSON state or from an actual
EditorState
object. This is unexpected, since by requiring the Lexical state to be the source of state means the the content stored in the database must necessarily be tightly coupled with Lexical. This makes it difficult to e.g. just render the text content or switch frontend editors.I understand that it does not make sense for something like RichTextPlugin since there is additional state for formatting and such that will be lost, but there really should be some way to say "set the editor's text content to this string", right?
Beta Was this translation helpful? Give feedback.
All reactions