Architecture
Lexical Core Package
Thelexical-core/ package defines shared editor infrastructure:
lexical-core defines the nodes, plugins, and transformers that are required for interoperability between our front end Lexical editors and the back end document transformation features. All files in this package should ONLY import from lexical or from other files in this package.
Key principle: Lexical-core must remain isolated - no dependencies on app-specific code.
Custom Nodes
Node Structure
Example frompackages/lexical-core/nodes/CommentNode.ts:
Node Requirements
Custom nodes must implement:- Type identifier -
static getType() - Serialization -
exportJSON()andstatic importJSON() - DOM rendering -
createDOM()andupdateDOM() - Factory function -
$createNodeName() - Type guard -
$isNodeName()
Version Management
Lexical Version Counter
Frompackages/core/component/LexicalMarkdown/version.ts:
- Increment
MARKDOWN_VERSION_COUNTER - Add a note documenting the change
- Ensure backward compatibility or migration path
CRDT Collaboration
loro-crdt Integration
Macro usesloro-crdt for real-time collaborative editing:
Mirror Pattern
Theloro-mirror/ package provides bidirectional sync:
- User edits in Lexical editor
- Changes sync TO_LORO CRDT
- CRDT broadcasts to other clients
- Remote changes sync FROM_LORO to local editor
Conflict Resolution
Loro CRDTs handle conflicts automatically:- Concurrent edits merge deterministically
- Last-write-wins for scalar values
- Operational transforms for text
Editor Plugins
Plugin Structure
Lexical plugins are React-like components that run inside the editor:Common Plugins
History Plugin - Undo/redoEditor State Management
Editor Instance
Fromblock-md/signal/markdownBlockData.ts:
- Store editor instance in block store
- Access from any component in block
- Separate editors for title and content
Reading Editor State
Updating Editor State
update() for mutations, read() for reads.
Markdown Transformers
Transformers convert between Lexical and Markdown:lexical-core/transformers/.
Accessibility
Lexical provides built-in accessibility:- ARIA labels and roles
- Keyboard navigation
- Screen reader support
- Focus management