Editor State | Lexical
With Lexical, the source of truth is not the DOM, but rather an underlying state model that Lexical maintains and associates with an editor instance. While HTML is great for storing rich text content it's often "way too flexible" when it comes to text editing. For example the following lines of content will produce equal outcome: Of course, there are ways to normalize all these variants to a single canonical form, however this would require DOM manipulation and so re-rendering of the content. And to overcome this we can use Virtual DOM, or State. On top of that it allows to decouple content structure from content formatting. Let's look at this example stored in HTML: In contrast, Lexical decouples structure from formatting by offsetting this information to attributes. This allows us to have canonical document structure regardless of the order in which different styles were applied. You can get the latest editor state from an editor by calling editor.getEditorState(). Editor states have
Copy page On this page Why is it necessary? With Lexical, the source of truth is not the DOM, but rather an underlying state model that Lexical maintains and associates with an editor instance. While HTML is great for storing rich text content it's often "way too flexible" when it comes to text editing. For example the following lines of content will produce equal outcome: < i > < b > Lexical </ b > </ i > < i > < b > Lex < b > < b > ical </ b > </ i > < b > < i > Lexical </ i > </ b > See rendered version! Lexical Lex ical Lexical Of course, there are ways to normalize all these variants to
Explore this link on the map →related reading
- Peritext: A CRDT for Rich-Text Collaborationinkandswitch.com
- You Might Not Need an Effect – Reactreact.dev
- 22 UX improvements to the web editormintlify.com
- Announcing Lex’s $2.75m Seed Round, Led by True Venturesevery.to
- Hemingway Editorhemingwayapp.com
- Redux Essentials, Part 1: Redux Overview and Concepts | Reduxredux.js.org
- State as a Snapshot – Reactreact.dev
- Updating Objects in State – Reactreact.dev
- Colimit - Discover Curated Annotationstreeline.vercel.app
- React graph viscrubier.github.io
- Blogged Answers: A (Mostly) Complete Guide to React Rendering Behavior · Mark's Dev Blogblog.isquaredsoftware.com
- GitHub - helix-editor/helix: A post-modern modal text editor. · GitHubgithub.com