Skip to main content

lexical

Classes​

DecoratorNode​

Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:23

Extends​

Extended by​

Type Parameters​

T​

T

Implements​

Constructors​

Constructor​

new DecoratorNode<T>(key?): DecoratorNode<T>

Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:41

Parameters​
key?​

string

Returns​

DecoratorNode<T>

Properties​

importDOM?​

static optional importDOM?: () => DOMConversionMap<any> | null

Defined in: packages/lexical/src/LexicalNode.ts:1162

Returns​

DOMConversionMap<any> | null

Methods​

$config()​

$config(): BaseStaticNodeConfig

Defined in: packages/lexical/src/LexicalNode.ts:1053

Override this to implement the new static node configuration protocol, this method is called directly on the prototype and must not depend on anything initialized in the constructor. Generally it should be a trivial implementation.

Returns​

BaseStaticNodeConfig

Example​
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Inherited from​

LexicalNode.$config

afterCloneFrom()​

afterCloneFrom(prevNode): void

Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:51

Perform any state updates on the clone of prevNode that are not already handled by the constructor call in the static clone method. If you have state to update in your clone that is not handled directly by the constructor, it is advisable to override this method but it is required to include a call to super.afterCloneFrom(prevNode) in your implementation. This is only intended to be called by $cloneWithProperties function or via a super call.

Parameters​
prevNode​

this

Returns​

void

Example​
class ClassesTextNode extends TextNode {
// Not shown: static getType, static importJSON, exportJSON, createDOM, updateDOM
__classes = new Set<string>();
static clone(node: ClassesTextNode): ClassesTextNode {
// The inherited TextNode constructor is used here, so
// classes is not set by this method.
return new ClassesTextNode(node.__text, node.__key);
}
afterCloneFrom(node: this): void {
// This calls TextNode.afterCloneFrom and LexicalNode.afterCloneFrom
// for necessary state updates
super.afterCloneFrom(node);
this.__addClasses(node.__classes);
}
// This method is a private implementation detail, it is not
// suitable for the public API because it does not call getWritable
__addClasses(classNames: Iterable<string>): this {
for (const className of classNames) {
this.__classes.add(className);
}
return this;
}
addClass(...classNames: string[]): this {
return this.getWritable().__addClasses(classNames);
}
removeClass(...classNames: string[]): this {
const node = this.getWritable();
for (const className of classNames) {
this.__classes.delete(className);
}
return this;
}
getClasses(): Set<string> {
return this.getLatest().__classes;
}
}
Inherited from​

LexicalNode.afterCloneFrom

config()​
Call Signature​

config<Config>(type, config): AbstractStaticNodeConfigRecord<Config>

Defined in: packages/lexical/src/LexicalNode.ts:1066

This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.

An abstract base class that has no concrete node type may pass a well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of a string type to declare configuration shared with its subclasses.

Type Parameters​
Config​

Config extends StaticNodeConfigValue<DecoratorNode<T>, string>

Parameters​
type​

symbol

config​

Config

Returns​

AbstractStaticNodeConfigRecord<Config>

Inherited from​

LexicalNode.config

Call Signature​

config<Type, Config>(type, config): StaticNodeConfigRecord<Type, Config>

Defined in: packages/lexical/src/LexicalNode.ts:1070

This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.

An abstract base class that has no concrete node type may pass a well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of a string type to declare configuration shared with its subclasses.

Type Parameters​
Type​

Type extends string

Config​

Config extends StaticNodeConfigValue<DecoratorNode<T>, Type>

Parameters​
type​

Type

config​

Config

Returns​

StaticNodeConfigRecord<Type, Config>

Inherited from​

LexicalNode.config

createDOM()​

createDOM(_config, _editor): HTMLElement

Defined in: packages/lexical/src/LexicalNode.ts:1748

Called during the reconciliation process to determine which nodes to insert into the DOM for this Lexical Node.

This method must return exactly one HTMLElement. Nested elements are not supported.

Do not attempt to update the Lexical EditorState during this phase of the update lifecycle.

Parameters​
_config​

EditorConfig

allows access to things like the EditorTheme (to apply classes) during reconciliation.

_editor​

LexicalEditor

allows access to the editor for context during reconciliation.

Returns​

HTMLElement

Inherited from​

LexicalNode.createDOM

createParentElementNode()​

createParentElementNode(): ElementNode

Defined in: packages/lexical/src/LexicalNode.ts:2313

The creation logic for any required parent. Should be implemented if isParentRequired returns true.

Returns​

ElementNode

Inherited from​

LexicalNode.createParentElementNode

decorate()​

decorate(editor, config): T | null

Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:72

The returned value is added to the LexicalEditor._decorators

Parameters​
editor​

LexicalEditor

config​

EditorConfig

Returns​

T | null

exportDOM()​

exportDOM(editor): DOMExportOutput

Defined in: packages/lexical/src/LexicalNode.ts:1796

Controls how the this node is serialized to HTML. This is important for copy and paste between Lexical and non-Lexical editors, or Lexical editors with different namespaces, in which case the primary transfer format is HTML. It's also important if you're serializing to HTML for any other reason via $generateHtmlFromNodes. You could also use this method to build your own HTML renderer.

Parameters​
editor​

LexicalEditor

Returns​

DOMExportOutput

Inherited from​

LexicalNode.exportDOM

exportJSON()​
Call Signature​

exportJSON(compact?): SerializedLexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:1837

Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.

The base implementation writes every property the node's schema declares (its own and those it inherits), reading each through its getter — get<Prop> by default, or the name recorded with withAccessors. A getter that returns undefined omits its property. Override this only for output a schema can not describe, and call super.exportJSON(compact) when you do.

This may serialize the instance as-is, without resolving the latest version. A property declared with withField is read straight off the node, which is the optimization the serialization walk is built on — every node the walk reaches comes from the EditorState's node map and is already current, so it resolves nothing per node.

So on a reference that a getWritable() (any set<Prop>) has since superseded, this writes pre-mutation values. Which properties do is not something to rely on: a property whose accessor a subclass overrode still goes through that accessor and resolves the latest, so one node can write a current text beside a stale style. Call node.getLatest().exportJSON() whenever you hold such a reference rather than reasoning about which properties resolve.

This is a breaking change. Every property previously went through an accessor, and every accessor resolves getLatest(), so a stale reference exported current values.

Parameters​
compact?​

false

Write the compact form: omit a property the parser derives rather than reads, one whose value is the schema default parsing would restore, and the deprecated version. The two forms describe the same document. A node that overrides this and ignores the flag simply keeps writing the full form, which still parses.

Returns​

SerializedLexicalNode

Inherited from​

LexicalNode.exportJSON

Call Signature​

exportJSON(compact): SerializedPartial<SerializedLexicalNode>

Defined in: packages/lexical/src/LexicalNode.ts:1846

The compact form omits properties, so what it returns is the partial serialized type — every node-specific property optional — rather than the full one. Passing a boolean whose value is not statically known selects this overload too, which is right: neither form can be promised then.

Parameters​
compact​

boolean

Returns​

SerializedPartial<SerializedLexicalNode>

See​

SerializedPartial

Inherited from​

LexicalNode.exportJSON

getCommonAncestor()​

getCommonAncestor<T>(node): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1507

Type Parameters​
T​

T extends ElementNode = ElementNode

Parameters​
node​

LexicalNode

the other node to find the common ancestor of.

Returns​

T | null

Deprecated​

use $getCommonAncestor

Returns the closest common ancestor of this node and the provided one or null if one cannot be found.

Inherited from​

LexicalNode.getCommonAncestor

getDOMSlot()​

getDOMSlot(element): DOMSlot<HTMLElement>

Defined in: packages/lexical/src/LexicalNode.ts:1784

Experimental

Returns a DOMSlot pointing at the content-bearing element of this node's DOM. The default returns a slot wrapping the keyed DOM as-is.

Override this when createDOM returns a wrapper around the content-bearing element (e.g. <span><br/></span> for a styled line break), so selection / reconciliation logic can target the inner element.

ElementNode overrides this to return an ElementDOMSlot with children-management semantics (used by the reconciler to place managed children).

Parameters​
element​

HTMLElement

Returns​

DOMSlot<HTMLElement>

Inherited from​

LexicalNode.getDOMSlot

getIndexWithinParent()​

getIndexWithinParent(): number

Defined in: packages/lexical/src/LexicalNode.ts:1284

Returns the zero-based index of this node within the parent.

Returns​

number

Inherited from​

LexicalNode.getIndexWithinParent

getKey()​

getKey(): string

Defined in: packages/lexical/src/LexicalNode.ts:1276

Returns this nodes key.

Returns​

string

Inherited from​

LexicalNode.getKey

getLatest()​

getLatest(): this

Defined in: packages/lexical/src/LexicalNode.ts:1657

Returns the latest version of the node from the active EditorState. This is used to avoid getting values from stale node references.

Returns​

this

Inherited from​

LexicalNode.getLatest

getNextSibling()​
Call Signature​

getNextSibling(): LexicalNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1463

Returns the node after this one in the same parent, or null if there is no such node.

Returns​

LexicalNode | null

Inherited from​

LexicalNode.getNextSibling

Call Signature​

getNextSibling<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1470

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getNextSibling() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getNextSibling

getNextSiblings()​
Call Signature​

getNextSiblings(): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1481

Returns all nodes after this one in the same parent, in document order.

Returns​

LexicalNode[]

Inherited from​

LexicalNode.getNextSiblings

Call Signature​

getNextSiblings<T>(): T[]

Defined in: packages/lexical/src/LexicalNode.ts:1488

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getNextSiblings() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

Inherited from​

LexicalNode.getNextSiblings

getNodesBetween()​

getNodesBetween(targetNode): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1576

Returns a list of nodes that are between this node and the target node in the EditorState.

Parameters​
targetNode​

LexicalNode

the node that marks the other end of the range of nodes to be returned.

Returns​

LexicalNode[]

Inherited from​

LexicalNode.getNodesBetween

getParent()​
Call Signature​

getParent(): ElementNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1304

Returns the parent of this node, or null if none is found.

Returns​

ElementNode | null

Inherited from​

LexicalNode.getParent

Call Signature​

getParent<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1311

Type Parameters​
T​

T extends ElementNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getParent() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getParent

getParentKeys()​

getParentKeys(): string[]

Defined in: packages/lexical/src/LexicalNode.ts:1402

Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.

Returns​

string[]

Inherited from​

LexicalNode.getParentKeys

getParentOrThrow()​
Call Signature​

getParentOrThrow(): ElementNode

Defined in: packages/lexical/src/LexicalNode.ts:1324

Returns the parent of this node, or throws if none is found.

Returns​

ElementNode

Inherited from​

LexicalNode.getParentOrThrow

Call Signature​

getParentOrThrow<T>(): T

Defined in: packages/lexical/src/LexicalNode.ts:1331

Type Parameters​
T​

T extends ElementNode

Returns​

T

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getParentOrThrow() as T, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getParentOrThrow

getParents()​

getParents(): ElementNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1387

Returns a list of the every ancestor of this node, all the way up to the RootNode.

Returns​

ElementNode[]

Inherited from​

LexicalNode.getParents

getPreviousSibling()​
Call Signature​

getPreviousSibling(): LexicalNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1416

Returns the node before this one in the same parent, or null if there is no such node.

Returns​

LexicalNode | null

Inherited from​

LexicalNode.getPreviousSibling

Call Signature​

getPreviousSibling<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1423

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getPreviousSibling() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getPreviousSibling

getPreviousSiblings()​
Call Signature​

getPreviousSiblings(): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1434

Returns all nodes before this one in the same parent, in document order.

Returns​

LexicalNode[]

Inherited from​

LexicalNode.getPreviousSiblings

Call Signature​

getPreviousSiblings<T>(): T[]

Defined in: packages/lexical/src/LexicalNode.ts:1441

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getPreviousSiblings() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

Inherited from​

LexicalNode.getPreviousSiblings

getTextContent()​

getTextContent(): string

Defined in: packages/lexical/src/LexicalNode.ts:1719

Returns the text content of the node. Override this for custom nodes that should have a representation in plain text format (for copy + paste, for example)

Returns​

string

Inherited from​

LexicalNode.getTextContent

getTextContentSize()​

getTextContentSize(): number

Defined in: packages/lexical/src/LexicalNode.ts:1727

Returns the length of the string produced by calling getTextContent on this node.

Returns​

number

Inherited from​

LexicalNode.getTextContentSize

getTopLevelElement()​

getTopLevelElement(): DecoratorNode<T> | ElementNode | null

Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:24

Returns the highest (in the EditorState tree) non-root ancestor of this node, or null if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".

Returns​

DecoratorNode<T> | ElementNode | null

Inherited from​

LexicalNode.getTopLevelElement

getTopLevelElementOrThrow()​

getTopLevelElementOrThrow(): DecoratorNode<T> | ElementNode

Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:25

Returns the highest (in the EditorState tree) non-root ancestor of this node, or throws if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".

Returns​

DecoratorNode<T> | ElementNode

Inherited from​

LexicalNode.getTopLevelElementOrThrow

getType()​

getType(): string

Defined in: packages/lexical/src/LexicalNode.ts:1187

Returns the string type of this node.

Returns​

string

Inherited from​

LexicalNode.getType

getWritable()​

getWritable(): this

Defined in: packages/lexical/src/LexicalNode.ts:1678

Returns a mutable version of the node using $cloneWithProperties if necessary. Will throw an error if called outside of a Lexical Editor LexicalEditor.update callback.

Returns​

this

Inherited from​

LexicalNode.getWritable

insertAfter()​

insertAfter(nodeToInsert, restoreSelection?): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:2117

Inserts a node after this LexicalNode (as the next sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert after this one.

restoreSelection?​

boolean = true

Whether or not to attempt to resolve the selection to the appropriate place after the operation is complete.

Returns​

LexicalNode

Inherited from​

LexicalNode.insertAfter

insertBefore()​

insertBefore(nodeToInsert, restoreSelection?): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:2224

Inserts a node before this LexicalNode (as the previous sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert before this one.

restoreSelection?​

boolean = true

Whether or not to attempt to resolve the selection to the appropriate place after the operation is complete.

Returns​

LexicalNode

Inherited from​

LexicalNode.insertBefore

is()​

is(object): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1524

Returns true if the provided node is the exact same one as this node, from Lexical's perspective. Always use this instead of referential equality.

Parameters​
object​

LexicalNode | null | undefined

the node to perform the equality comparison on.

Returns​

boolean

Inherited from​

LexicalNode.is

isAttached()​

isAttached(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1204

Returns true if there is a path between this node and the RootNode, false otherwise. This is a way of determining if the node is "attached" EditorState. Unattached nodes won't be reconciled and will ultimately be cleaned up by the Lexical GC.

Returns​

boolean

Inherited from​

LexicalNode.isAttached

isBefore()​

isBefore(targetNode): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1542

Returns true if this node logically precedes the target node in the editor state, false otherwise (including if there is no common ancestor).

Note that this notion of isBefore is based on post-order; a descendant node is always before its ancestors. See also $getCommonAncestor and $comparePointCaretNext for more flexible ways to determine the relative positions of nodes.

Parameters​
targetNode​

LexicalNode

the node we're testing to see if it's after this one.

Returns​

boolean

Inherited from​

LexicalNode.isBefore

isDirty()​

isDirty(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1646

Returns true if this node has been marked dirty during this update cycle.

Returns​

boolean

Inherited from​

LexicalNode.isDirty

isInline()​

isInline(): boolean

Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:89

Returns​

boolean

Inherited from​

LexicalNode.isInline

isIsolated()​

isIsolated(): boolean

Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:85

Whether this decorator is isolated from caret interaction: an isolated decorator can not be traversed, extended over, selected as a node, or deleted by an adjacent caret operation. A caret that reaches one stops there, so an inline isolated decorator is only reachable by pointer.

Defaults to false, which lets the caret step over the decorator (and select it, when DecoratorNode.isKeyboardSelectable is also true).

Returns​

boolean

isKeyboardSelectable()​

isKeyboardSelectable(): boolean

Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:93

Returns​

boolean

isParentOf()​

isParentOf(targetNode): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1565

Returns true if this node is an ancestor of and distinct from the target node, false otherwise.

Parameters​
targetNode​

LexicalNode

the would-be child node.

Returns​

boolean

Inherited from​

LexicalNode.isParentOf

isParentRequired()​

isParentRequired(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:2305

Whether or not this node has a required parent. Used during copy + paste operations to normalize nodes that would otherwise be orphaned. For example, ListItemNodes without a ListNode parent or TextNodes with a ParagraphNode parent.

Returns​

boolean

Inherited from​

LexicalNode.isParentRequired

isSelected()​

isSelected(selection?): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1231

Returns true if this node is contained within the provided Selection., false otherwise. Relies on the algorithms implemented in BaseSelection.getNodes to determine what's included.

Parameters​
selection?​

BaseSelection | null

The selection that we want to determine if the node is in.

Returns​

boolean

Inherited from​

LexicalNode.isSelected

markDirty()​

markDirty(): void

Defined in: packages/lexical/src/LexicalNode.ts:2388

Marks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.

Returns​

void

Inherited from​

LexicalNode.markDirty

remove()​

remove(preserveEmptyParent?): void

Defined in: packages/lexical/src/LexicalNode.ts:1949

Removes this LexicalNode from the EditorState. If the node isn't re-inserted somewhere, the Lexical garbage collector will eventually clean it up.

Parameters​
preserveEmptyParent?​

boolean

If falsy, the node's parent will be removed if it's empty after the removal operation. This is the default behavior, subject to other node heuristics such as ElementNode#canBeEmpty

Returns​

void

Inherited from​

LexicalNode.remove

replace()​

replace<N>(replaceWith, includeChildren?): N

Defined in: packages/lexical/src/LexicalNode.ts:1966

Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.

Named slots are bound to their host node and are never transferred: this node keeps its slot map, so if it is reattached elsewhere (as $wrapNodeInElement does) its slots come with it, and if it stays detached the slot subtrees are garbage-collected along with it. To move a slot value onto another host, use $setSlot explicitly.

Type Parameters​
N​

N extends LexicalNode

Parameters​
replaceWith​

N

The node to replace this one with.

includeChildren?​

boolean

Whether or not to transfer the children of this node to the replacing node.

Returns​

N

Inherited from​

LexicalNode.replace

resetOnCopyNodeFrom()​

resetOnCopyNodeFrom(originalNode): void

Defined in: packages/lexical/src/LexicalNode.ts:1155

Reset state in this copy of originalNode, if necessary

Parameters​
originalNode​

this

Returns​

void

Inherited from​

LexicalNode.resetOnCopyNodeFrom

selectEnd()​

selectEnd(): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2321

Returns​

RangeSelection

Inherited from​

LexicalNode.selectEnd

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2360

Moves selection to the next sibling of this node, at the specified offsets.

Parameters​
anchorOffset?​

number

The anchor offset for selection.

focusOffset?​

number

The focus offset for selection

Returns​

RangeSelection

Inherited from​

LexicalNode.selectNext

selectPrevious()​

selectPrevious(anchorOffset?, focusOffset?): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2331

Moves selection to the previous sibling of this node, at the specified offsets.

Parameters​
anchorOffset?​

number

The anchor offset for selection.

focusOffset?​

number

The focus offset for selection

Returns​

RangeSelection

Inherited from​

LexicalNode.selectPrevious

selectStart()​

selectStart(): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2317

Returns​

RangeSelection

Inherited from​

LexicalNode.selectStart

updateDOM()​

updateDOM(_prevNode, _dom, _config): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1762

Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.

Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.

Parameters​
_prevNode​

unknown

_dom​

HTMLElement

_config​

EditorConfig

Returns​

boolean

Inherited from​

LexicalNode.updateDOM

updateFromJSON()​

updateFromJSON(serializedNode): this

Defined in: packages/lexical/src/LexicalNode.ts:1917

Update this LexicalNode instance from serialized JSON. It's recommended to implement as much logic as possible in this method instead of the static importJSON method, so that the functionality can be inherited in subclasses.

The LexicalUpdateJSON utility type should be used to ignore any type, version, or children properties in the JSON so that the extended JSON from subclasses are acceptable parameters for the super call.

If overridden, this method must call super.

Parameters​
serializedNode​

LexicalParseJSON<SerializedLexicalNode>

Returns​

this

Example​
class MyTextNode extends TextNode {
// ...
static importJSON(serializedNode: SerializedMyTextNode): MyTextNode {
return $createMyTextNode()
.updateFromJSON(serializedNode);
}
updateFromJSON(
serializedNode: LexicalUpdateJSON<SerializedMyTextNode>,
): this {
return super.updateFromJSON(serializedNode)
.setMyProperty(serializedNode.myProperty);
}
}

The whole schema is applied, so a property the JSON omits is set to its schema default rather than left as it is — that is what lets the compact form omit a default-valued property and have parsing restore it. (A flat NodeState is the exception: it is applied only when present.) Pass the node's complete serialized form unless you mean to reset what you leave out.

Inherited from​

LexicalNode.updateFromJSON

clone()​

static clone(_data): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:1030

Clones this node, creating a new node with a different key and adding it to the EditorState (but not attaching it anywhere!). All nodes must implement this method.

Parameters​
_data​

unknown

Returns​

LexicalNode

getType()​

static getType(): string

Defined in: packages/lexical/src/LexicalNode.ts:1014

Returns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.

Returns​

string

importJSON()​

static importJSON(_serializedNode): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:1871

Controls how the this node is deserialized from JSON. This is usually boilerplate, but provides an abstraction between the node implementation and serialized interface that can be important if you ever make breaking changes to a node schema (by adding or removing properties). See Serialization & Deserialization.

Parameters​
_serializedNode​

Omit<SerializedLexicalNode & Partial<SerializedLexicalNode>, "$slots" | "children" | "version"> & object & Record<string, unknown>

Returns​

LexicalNode

transform()​

static transform(): ((node) => void) | null

Defined in: packages/lexical/src/LexicalNode.ts:1935

Experimental

Registers the returned function as a transform on the node during Editor initialization. Most such use cases should be addressed via the LexicalEditor.registerNodeTransform API.

Experimental - use at your own risk.

Returns​

((node) => void) | null


ElementNode​

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:232

Extends​

Extended by​

Implements​

Constructors​

Constructor​

new ElementNode(key?): ElementNode

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:303

Parameters​
key?​

string

Returns​

ElementNode

Properties​

importDOM?​

static optional importDOM?: () => DOMConversionMap<any> | null

Defined in: packages/lexical/src/LexicalNode.ts:1162

Returns​

DOMConversionMap<any> | null

Methods​

$config()​

$config(): BaseStaticNodeConfig & StaticNodeConfigAccessor<{ $transform: { }; extends: typeof LexicalNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<ElementNode, { direction?: "ltr" | "rtl" | null; format?: "" | "left" | "start" | "center" | "right" | "end" | "justify"; indent?: string | number; textFormat?: string | number; textStyle?: string; }>; }>

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:281

Override this to implement the new static node configuration protocol, this method is called directly on the prototype and must not depend on anything initialized in the constructor. Generally it should be a trivial implementation.

Returns​

BaseStaticNodeConfig & StaticNodeConfigAccessor<{ $transform: { }; extends: typeof LexicalNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<ElementNode, { direction?: "ltr" | "rtl" | null; format?: "" | "left" | "start" | "center" | "right" | "end" | "justify"; indent?: string | number; textFormat?: string | number; textStyle?: string; }>; }>

Example​
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Inherited from​

LexicalNode.$config

afterCloneFrom()​

afterCloneFrom(prevNode): void

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:329

Perform any state updates on the clone of prevNode that are not already handled by the constructor call in the static clone method. If you have state to update in your clone that is not handled directly by the constructor, it is advisable to override this method but it is required to include a call to super.afterCloneFrom(prevNode) in your implementation. This is only intended to be called by $cloneWithProperties function or via a super call.

Parameters​
prevNode​

this

Returns​

void

Example​
class ClassesTextNode extends TextNode {
// Not shown: static getType, static importJSON, exportJSON, createDOM, updateDOM
__classes = new Set<string>();
static clone(node: ClassesTextNode): ClassesTextNode {
// The inherited TextNode constructor is used here, so
// classes is not set by this method.
return new ClassesTextNode(node.__text, node.__key);
}
afterCloneFrom(node: this): void {
// This calls TextNode.afterCloneFrom and LexicalNode.afterCloneFrom
// for necessary state updates
super.afterCloneFrom(node);
this.__addClasses(node.__classes);
}
// This method is a private implementation detail, it is not
// suitable for the public API because it does not call getWritable
__addClasses(classNames: Iterable<string>): this {
for (const className of classNames) {
this.__classes.add(className);
}
return this;
}
addClass(...classNames: string[]): this {
return this.getWritable().__addClasses(classNames);
}
removeClass(...classNames: string[]): this {
const node = this.getWritable();
for (const className of classNames) {
this.__classes.delete(className);
}
return this;
}
getClasses(): Set<string> {
return this.getLatest().__classes;
}
}
Inherited from​

LexicalNode.afterCloneFrom

append()​

append(...nodesToAppend): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:774

Parameters​
nodesToAppend​

...LexicalNode[]

Returns​

this

canBeEmpty()​

canBeEmpty(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1072

Returns​

boolean

canIndent()​

canIndent(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1044

Returns​

boolean

canInsertTextAfter()​

canInsertTextAfter(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1078

Returns​

boolean

canInsertTextBefore()​

canInsertTextBefore(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1075

Returns​

boolean

canMergeWhenEmpty()​

canMergeWhenEmpty(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1121

Determines whether this node, when empty, can merge with a first block of nodes being inserted.

This method is specifically called in RangeSelection.insertNodes to determine merging behavior during nodes insertion.

Returns​

boolean

Example​
// In a ListItemNode or QuoteNode implementation:
canMergeWhenEmpty(): true {
return true;
}
clear()​

clear(): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:768

Returns​

this

collapseAtStart()​

collapseAtStart(selection): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1058

Parameters​
selection​

RangeSelection

Returns​

boolean

config()​
Call Signature​

config<Config>(type, config): AbstractStaticNodeConfigRecord<Config>

Defined in: packages/lexical/src/LexicalNode.ts:1066

This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.

An abstract base class that has no concrete node type may pass a well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of a string type to declare configuration shared with its subclasses.

Type Parameters​
Config​

Config extends StaticNodeConfigValue<ElementNode, string>

Parameters​
type​

symbol

config​

Config

Returns​

AbstractStaticNodeConfigRecord<Config>

Inherited from​

LexicalNode.config

Call Signature​

config<Type, Config>(type, config): StaticNodeConfigRecord<Type, Config>

Defined in: packages/lexical/src/LexicalNode.ts:1070

This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.

An abstract base class that has no concrete node type may pass a well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of a string type to declare configuration shared with its subclasses.

Type Parameters​
Type​

Type extends string

Config​

Config extends StaticNodeConfigValue<ElementNode, Type>

Parameters​
type​

Type

config​

Config

Returns​

StaticNodeConfigRecord<Type, Config>

Inherited from​

LexicalNode.config

createDOM()​

createDOM(_config, _editor): HTMLElement

Defined in: packages/lexical/src/LexicalNode.ts:1748

Called during the reconciliation process to determine which nodes to insert into the DOM for this Lexical Node.

This method must return exactly one HTMLElement. Nested elements are not supported.

Do not attempt to update the Lexical EditorState during this phase of the update lifecycle.

Parameters​
_config​

EditorConfig

allows access to things like the EditorTheme (to apply classes) during reconciliation.

_editor​

LexicalEditor

allows access to the editor for context during reconciliation.

Returns​

HTMLElement

Inherited from​

LexicalNode.createDOM

createParentElementNode()​

createParentElementNode(): ElementNode

Defined in: packages/lexical/src/LexicalNode.ts:2313

The creation logic for any required parent. Should be implemented if isParentRequired returns true.

Returns​

ElementNode

Inherited from​

LexicalNode.createParentElementNode

excludeFromCopy()​

excludeFromCopy(destination?): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1061

Parameters​
destination?​

"clone" | "html"

Returns​

boolean

exportDOM()​

exportDOM(editor): DOMExportOutput

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:967

Controls how the this node is serialized to HTML. This is important for copy and paste between Lexical and non-Lexical editors, or Lexical editors with different namespaces, in which case the primary transfer format is HTML. It's also important if you're serializing to HTML for any other reason via $generateHtmlFromNodes. You could also use this method to build your own HTML renderer.

Parameters​
editor​

LexicalEditor

Returns​

DOMExportOutput

Inherited from​

LexicalNode.exportDOM

exportJSON()​
Call Signature​

exportJSON(compact?): SerializedElementNode

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:233

Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.

The base implementation writes every property the node's schema declares (its own and those it inherits), reading each through its getter — get<Prop> by default, or the name recorded with withAccessors. A getter that returns undefined omits its property. Override this only for output a schema can not describe, and call super.exportJSON(compact) when you do.

This may serialize the instance as-is, without resolving the latest version. A property declared with withField is read straight off the node, which is the optimization the serialization walk is built on — every node the walk reaches comes from the EditorState's node map and is already current, so it resolves nothing per node.

So on a reference that a getWritable() (any set<Prop>) has since superseded, this writes pre-mutation values. Which properties do is not something to rely on: a property whose accessor a subclass overrode still goes through that accessor and resolves the latest, so one node can write a current text beside a stale style. Call node.getLatest().exportJSON() whenever you hold such a reference rather than reasoning about which properties resolve.

This is a breaking change. Every property previously went through an accessor, and every accessor resolves getLatest(), so a stale reference exported current values.

Parameters​
compact?​

false

Write the compact form: omit a property the parser derives rather than reads, one whose value is the schema default parsing would restore, and the deprecated version. The two forms describe the same document. A node that overrides this and ignores the flag simply keeps writing the full form, which still parses.

Returns​

SerializedElementNode

Inherited from​

LexicalNode.exportJSON

Call Signature​

exportJSON(compact): SerializedPartial<SerializedElementNode>

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:234

The compact form omits properties, so what it returns is the partial serialized type — every node-specific property optional — rather than the full one. Passing a boolean whose value is not statically known selects this overload too, which is right: neither form can be promised then.

Parameters​
compact​

boolean

Returns​

SerializedPartial<SerializedElementNode>

See​

SerializedPartial

Inherited from​

LexicalNode.exportJSON

extractWithChild()​

extractWithChild(child, selection, destination): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1100

Parameters​
child​

LexicalNode

selection​

BaseSelection | null

destination​

"clone" | "html"

Returns​

boolean

getAllTextNodes()​

getAllTextNodes(): TextNode[]

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:420

Returns​

TextNode[]

getChildAtIndex()​
Call Signature​

getChildAtIndex(index): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:605

Returns the child of this node at the given index, or null if the index is out of range.

Parameters​
index​

number

Returns​

LexicalNode | null

Call Signature​

getChildAtIndex<T>(index): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:612

Type Parameters​
T​

T extends LexicalNode

Parameters​
index​

number

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getChildAtIndex(index) as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getChildren()​
Call Signature​

getChildren(): LexicalNode[]

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:374

Returns the children of this node, in document order.

Returns​

LexicalNode[]

Call Signature​

getChildren<T>(): T[]

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:381

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getChildren() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

getChildrenKeys()​

getChildrenKeys(): string[]

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:391

Returns​

string[]

getChildrenSize()​

getChildrenSize(): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:400

Returns​

number

getCommonAncestor()​

getCommonAncestor<T>(node): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1507

Type Parameters​
T​

T extends ElementNode = ElementNode

Parameters​
node​

LexicalNode

the other node to find the common ancestor of.

Returns​

T | null

Deprecated​

use $getCommonAncestor

Returns the closest common ancestor of this node and the provided one or null if one cannot be found.

Inherited from​

LexicalNode.getCommonAncestor

getDescendantByIndex()​
Call Signature​

getDescendantByIndex(index): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:505

Returns the deepest descendant corresponding to the child at the given index, or null if this node has no children.

Parameters​
index​

number

Returns​

LexicalNode | null

Call Signature​

getDescendantByIndex<T>(index): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:512

Type Parameters​
T​

T extends LexicalNode

Parameters​
index​

number

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getDescendantByIndex(index) as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getDirection()​

getDirection(): "ltr" | "rtl" | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:678

Returns​

"ltr" | "rtl" | null

getDOMSlot()​

getDOMSlot(element): ElementDOMSlot<HTMLElement>

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:964

Experimental

An ElementNode subclass can override this to control where its children are inserted into the DOM, e.g. to add a wrapping node or accessory nodes before or after the children. The root of the node returned by createDOM must still be exactly one HTMLElement.

Parameters​
element​

HTMLElement

Returns​

ElementDOMSlot<HTMLElement>

Inherited from​

LexicalNode.getDOMSlot

getFirstChild()​
Call Signature​

getFirstChild(): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:536

Returns the first child of this node, or null if it has no children.

Returns​

LexicalNode | null

Call Signature​

getFirstChild<T>(): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:543

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getFirstChild() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getFirstChildOrThrow()​
Call Signature​

getFirstChildOrThrow(): LexicalNode

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:552

Returns the first child of this node, or throws if it has no children.

Returns​

LexicalNode

Call Signature​

getFirstChildOrThrow<T>(): T

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:559

Type Parameters​
T​

T extends LexicalNode

Returns​

T

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getFirstChildOrThrow() as T, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getFirstDescendant()​
Call Signature​

getFirstDescendant(): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:459

Returns the deepest first descendant of this node, or null if it has no children.

Descendant navigation is children-only by design: it feeds selectStart / selectEnd and selection, which must not see slots (slots are isolated).

Returns​

LexicalNode | null

Call Signature​

getFirstDescendant<T>(): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:466

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getFirstDescendant() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getFormat()​

getFormat(): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:355

Returns​

number

getFormatFlags()​

getFormatFlags(type, alignWithFormat): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:702

Returns the format flags applied to the node as a 32-bit integer.

Parameters​
type​

TextFormatType

alignWithFormat​

number | null

Returns​

number

a number representing the TextFormatTypes applied to the node.

getFormatType()​

getFormatType(): ElementFormatType

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:359

Returns​

ElementFormatType

getIndent()​

getIndent(): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:367

Returns​

number

getIndexWithinParent()​

getIndexWithinParent(): number

Defined in: packages/lexical/src/LexicalNode.ts:1284

Returns the zero-based index of this node within the parent.

Returns​

number

Inherited from​

LexicalNode.getIndexWithinParent

getKey()​

getKey(): string

Defined in: packages/lexical/src/LexicalNode.ts:1276

Returns this nodes key.

Returns​

string

Inherited from​

LexicalNode.getKey

getLastChild()​
Call Signature​

getLastChild(): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:570

Returns the last child of this node, or null if it has no children.

Returns​

LexicalNode | null

Call Signature​

getLastChild<T>(): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:577

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getLastChild() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getLastChildOrThrow()​
Call Signature​

getLastChildOrThrow(): LexicalNode

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:586

Returns the last child of this node, or throws if it has no children.

Returns​

LexicalNode

Call Signature​

getLastChildOrThrow<T>(): T

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:593

Type Parameters​
T​

T extends LexicalNode

Returns​

T

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getLastChildOrThrow() as T, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getLastDescendant()​
Call Signature​

getLastDescendant(): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:482

Returns the deepest last descendant of this node, or null if it has no children.

Returns​

LexicalNode | null

Call Signature​

getLastDescendant<T>(): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:489

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getLastDescendant() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getLatest()​

getLatest(): this

Defined in: packages/lexical/src/LexicalNode.ts:1657

Returns the latest version of the node from the active EditorState. This is used to avoid getting values from stale node references.

Returns​

this

Inherited from​

LexicalNode.getLatest

getNextSibling()​
Call Signature​

getNextSibling(): LexicalNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1463

Returns the node after this one in the same parent, or null if there is no such node.

Returns​

LexicalNode | null

Inherited from​

LexicalNode.getNextSibling

Call Signature​

getNextSibling<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1470

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getNextSibling() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getNextSibling

getNextSiblings()​
Call Signature​

getNextSiblings(): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1481

Returns all nodes after this one in the same parent, in document order.

Returns​

LexicalNode[]

Inherited from​

LexicalNode.getNextSiblings

Call Signature​

getNextSiblings<T>(): T[]

Defined in: packages/lexical/src/LexicalNode.ts:1488

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getNextSiblings() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

Inherited from​

LexicalNode.getNextSiblings

getNodesBetween()​

getNodesBetween(targetNode): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1576

Returns a list of nodes that are between this node and the target node in the EditorState.

Parameters​
targetNode​

LexicalNode

the node that marks the other end of the range of nodes to be returned.

Returns​

LexicalNode[]

Inherited from​

LexicalNode.getNodesBetween

getParent()​
Call Signature​

getParent(): ElementNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1304

Returns the parent of this node, or null if none is found.

Returns​

ElementNode | null

Inherited from​

LexicalNode.getParent

Call Signature​

getParent<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1311

Type Parameters​
T​

T extends ElementNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getParent() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getParent

getParentKeys()​

getParentKeys(): string[]

Defined in: packages/lexical/src/LexicalNode.ts:1402

Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.

Returns​

string[]

Inherited from​

LexicalNode.getParentKeys

getParentOrThrow()​
Call Signature​

getParentOrThrow(): ElementNode

Defined in: packages/lexical/src/LexicalNode.ts:1324

Returns the parent of this node, or throws if none is found.

Returns​

ElementNode

Inherited from​

LexicalNode.getParentOrThrow

Call Signature​

getParentOrThrow<T>(): T

Defined in: packages/lexical/src/LexicalNode.ts:1331

Type Parameters​
T​

T extends ElementNode

Returns​

T

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getParentOrThrow() as T, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getParentOrThrow

getParents()​

getParents(): ElementNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1387

Returns a list of the every ancestor of this node, all the way up to the RootNode.

Returns​

ElementNode[]

Inherited from​

LexicalNode.getParents

getPreviousSibling()​
Call Signature​

getPreviousSibling(): LexicalNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1416

Returns the node before this one in the same parent, or null if there is no such node.

Returns​

LexicalNode | null

Inherited from​

LexicalNode.getPreviousSibling

Call Signature​

getPreviousSibling<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1423

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getPreviousSibling() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getPreviousSibling

getPreviousSiblings()​
Call Signature​

getPreviousSiblings(): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1434

Returns all nodes before this one in the same parent, in document order.

Returns​

LexicalNode[]

Inherited from​

LexicalNode.getPreviousSiblings

Call Signature​

getPreviousSiblings<T>(): T[]

Defined in: packages/lexical/src/LexicalNode.ts:1441

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getPreviousSiblings() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

Inherited from​

LexicalNode.getPreviousSiblings

getStyle()​

getStyle(): string

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:363

Returns​

string

getTextContent()​

getTextContent(): string

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:640

Returns the text content of the node. Override this for custom nodes that should have a representation in plain text format (for copy + paste, for example)

Returns​

string

Inherited from​

LexicalNode.getTextContent

getTextContentSize()​

getTextContentSize(): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:659

Returns the length of the string produced by calling getTextContent on this node.

Returns​

number

Inherited from​

LexicalNode.getTextContentSize

getTextFormat()​

getTextFormat(): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:682

Returns​

number

getTextStyle()​

getTextStyle(): string

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:708

Returns​

string

getTopLevelElement()​

getTopLevelElement(): ElementNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:241

Returns the highest (in the EditorState tree) non-root ancestor of this node, or null if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".

Returns​

ElementNode | null

Inherited from​

LexicalNode.getTopLevelElement

getTopLevelElementOrThrow()​

getTopLevelElementOrThrow(): ElementNode

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:242

Returns the highest (in the EditorState tree) non-root ancestor of this node, or throws if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".

Returns​

ElementNode

Inherited from​

LexicalNode.getTopLevelElementOrThrow

getType()​

getType(): string

Defined in: packages/lexical/src/LexicalNode.ts:1187

Returns the string type of this node.

Returns​

string

Inherited from​

LexicalNode.getType

getWritable()​

getWritable(): this

Defined in: packages/lexical/src/LexicalNode.ts:1678

Returns a mutable version of the node using $cloneWithProperties if necessary. Will throw an error if called outside of a Lexical Editor LexicalEditor.update callback.

Returns​

this

Inherited from​

LexicalNode.getWritable

hasFormat()​

hasFormat(type): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:686

Parameters​
type​

ElementFormatType

Returns​

boolean

hasTextFormat()​

hasTextFormat(type): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:693

Parameters​
type​

TextFormatType

Returns​

boolean

insertAfter()​

insertAfter(nodeToInsert, restoreSelection?): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:2117

Inserts a node after this LexicalNode (as the next sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert after this one.

restoreSelection?​

boolean = true

Whether or not to attempt to resolve the selection to the appropriate place after the operation is complete.

Returns​

LexicalNode

Inherited from​

LexicalNode.insertAfter

insertBefore()​

insertBefore(nodeToInsert, restoreSelection?): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:2224

Inserts a node before this LexicalNode (as the previous sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert before this one.

restoreSelection?​

boolean = true

Whether or not to attempt to resolve the selection to the appropriate place after the operation is complete.

Returns​

LexicalNode

Inherited from​

LexicalNode.insertBefore

insertNewAfter()​

insertNewAfter(selection, restoreSelection?): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1038

Parameters​
selection​

RangeSelection

restoreSelection?​

boolean

Returns​

LexicalNode | null

is()​

is(object): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1524

Returns true if the provided node is the exact same one as this node, from Lexical's perspective. Always use this instead of referential equality.

Parameters​
object​

LexicalNode | null | undefined

the node to perform the equality comparison on.

Returns​

boolean

Inherited from​

LexicalNode.is

isAttached()​

isAttached(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1204

Returns true if there is a path between this node and the RootNode, false otherwise. This is a way of determining if the node is "attached" EditorState. Unattached nodes won't be reconciled and will ultimately be cleaned up by the Lexical GC.

Returns​

boolean

Inherited from​

LexicalNode.isAttached

isBefore()​

isBefore(targetNode): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1542

Returns true if this node logically precedes the target node in the editor state, false otherwise (including if there is no common ancestor).

Note that this notion of isBefore is based on post-order; a descendant node is always before its ancestors. See also $getCommonAncestor and $comparePointCaretNext for more flexible ways to determine the relative positions of nodes.

Parameters​
targetNode​

LexicalNode

the node we're testing to see if it's after this one.

Returns​

boolean

Inherited from​

LexicalNode.isBefore

isDirty()​

isDirty(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:410

Returns true if this node has been marked dirty during this update cycle.

Returns​

boolean

Inherited from​

LexicalNode.isDirty

isEmpty()​

isEmpty(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:404

Returns​

boolean

isInline()​

isInline(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1086

If the method is overridden and returns true, ensure that canBeEmpty() returns false for the inline node to work correctly

Returns​

boolean

Inherited from​

LexicalNode.isInline

isLastChild()​

isLastChild(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:415

Returns​

boolean

isParentOf()​

isParentOf(targetNode): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1565

Returns true if this node is an ancestor of and distinct from the target node, false otherwise.

Parameters​
targetNode​

LexicalNode

the would-be child node.

Returns​

boolean

Inherited from​

LexicalNode.isParentOf

isParentRequired()​

isParentRequired(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:2305

Whether or not this node has a required parent. Used during copy + paste operations to normalize nodes that would otherwise be orphaned. For example, ListItemNodes without a ListNode parent or TextNodes with a ParagraphNode parent.

Returns​

boolean

Inherited from​

LexicalNode.isParentRequired

isSelected()​

isSelected(selection?): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1231

Returns true if this node is contained within the provided Selection., false otherwise. Relies on the algorithms implemented in BaseSelection.getNodes to determine what's included.

Parameters​
selection?​

BaseSelection | null

The selection that we want to determine if the node is in.

Returns​

boolean

Inherited from​

LexicalNode.isSelected

isShadowRoot()​

isShadowRoot(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1093

Returns​

boolean

markDirty()​

markDirty(): void

Defined in: packages/lexical/src/LexicalNode.ts:2388

Marks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.

Returns​

void

Inherited from​

LexicalNode.markDirty

remove()​

remove(preserveEmptyParent?): void

Defined in: packages/lexical/src/LexicalNode.ts:1949

Removes this LexicalNode from the EditorState. If the node isn't re-inserted somewhere, the Lexical garbage collector will eventually clean it up.

Parameters​
preserveEmptyParent?​

boolean

If falsy, the node's parent will be removed if it's empty after the removal operation. This is the default behavior, subject to other node heuristics such as ElementNode#canBeEmpty

Returns​

void

Inherited from​

LexicalNode.remove

replace()​

replace<N>(replaceWith, includeChildren?): N

Defined in: packages/lexical/src/LexicalNode.ts:1966

Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.

Named slots are bound to their host node and are never transferred: this node keeps its slot map, so if it is reattached elsewhere (as $wrapNodeInElement does) its slots come with it, and if it stays detached the slot subtrees are garbage-collected along with it. To move a slot value onto another host, use $setSlot explicitly.

Type Parameters​
N​

N extends LexicalNode

Parameters​
replaceWith​

N

The node to replace this one with.

includeChildren?​

boolean

Whether or not to transfer the children of this node to the replacing node.

Returns​

N

Inherited from​

LexicalNode.replace

resetOnCopyNodeFrom()​

resetOnCopyNodeFrom(originalNode): void

Defined in: packages/lexical/src/LexicalNode.ts:1155

Reset state in this copy of originalNode, if necessary

Parameters​
originalNode​

this

Returns​

void

Inherited from​

LexicalNode.resetOnCopyNodeFrom

select()​

select(_anchorOffset?, _focusOffset?): RangeSelection

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:715

Parameters​
_anchorOffset?​

number

_focusOffset?​

number

Returns​

RangeSelection

selectEnd()​

selectEnd(): RangeSelection

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:764

Returns​

RangeSelection

Inherited from​

LexicalNode.selectEnd

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2360

Moves selection to the next sibling of this node, at the specified offsets.

Parameters​
anchorOffset?​

number

The anchor offset for selection.

focusOffset?​

number

The focus offset for selection

Returns​

RangeSelection

Inherited from​

LexicalNode.selectNext

selectPrevious()​

selectPrevious(anchorOffset?, focusOffset?): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2331

Moves selection to the previous sibling of this node, at the specified offsets.

Parameters​
anchorOffset?​

number

The anchor offset for selection.

focusOffset?​

number

The focus offset for selection

Returns​

RangeSelection

Inherited from​

LexicalNode.selectPrevious

selectStart()​

selectStart(): RangeSelection

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:760

Returns​

RangeSelection

Inherited from​

LexicalNode.selectStart

setDirection()​

setDirection(direction): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:777

Parameters​
direction​

"ltr" | "rtl" | null

Returns​

this

setFormat()​

setFormat(type): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:782

Parameters​
type​

ElementFormatType

Returns​

this

setIndent()​

setIndent(indentLevel): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:802

Parameters​
indentLevel​

number

Returns​

this

setStyle()​

setStyle(style): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:787

Parameters​
style​

string

Returns​

this

setTextFormat()​

setTextFormat(type): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:792

Parameters​
type​

number

Returns​

this

setTextStyle()​

setTextStyle(style): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:797

Parameters​
style​

string

Returns​

this

splice()​

splice(start, deleteCount, nodesToInsert): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:807

Parameters​
start​

number

deleteCount​

number

nodesToInsert​

LexicalNode[]

Returns​

this

updateDOM()​

updateDOM(_prevNode, _dom, _config): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1762

Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.

Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.

Parameters​
_prevNode​

unknown

_dom​

HTMLElement

_config​

EditorConfig

Returns​

boolean

Inherited from​

LexicalNode.updateDOM

updateFromJSON()​

updateFromJSON(serializedNode): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:235

Update this LexicalNode instance from serialized JSON. It's recommended to implement as much logic as possible in this method instead of the static importJSON method, so that the functionality can be inherited in subclasses.

The LexicalUpdateJSON utility type should be used to ignore any type, version, or children properties in the JSON so that the extended JSON from subclasses are acceptable parameters for the super call.

If overridden, this method must call super.

Parameters​
serializedNode​

LexicalParseJSON<SerializedElementNode>

Returns​

this

Example​
class MyTextNode extends TextNode {
// ...
static importJSON(serializedNode: SerializedMyTextNode): MyTextNode {
return $createMyTextNode()
.updateFromJSON(serializedNode);
}
updateFromJSON(
serializedNode: LexicalUpdateJSON<SerializedMyTextNode>,
): this {
return super.updateFromJSON(serializedNode)
.setMyProperty(serializedNode.myProperty);
}
}

The whole schema is applied, so a property the JSON omits is set to its schema default rather than left as it is — that is what lets the compact form omit a default-valued property and have parsing restore it. (A flat NodeState is the exception: it is applied only when present.) Pass the node's complete serialized form unless you mean to reset what you leave out.

Inherited from​

LexicalNode.updateFromJSON

clone()​

static clone(_data): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:1030

Clones this node, creating a new node with a different key and adding it to the EditorState (but not attaching it anywhere!). All nodes must implement this method.

Parameters​
_data​

unknown

Returns​

LexicalNode

getType()​

static getType(): string

Defined in: packages/lexical/src/LexicalNode.ts:1014

Returns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.

Returns​

string

importJSON()​

static importJSON(_serializedNode): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:1871

Controls how the this node is deserialized from JSON. This is usually boilerplate, but provides an abstraction between the node implementation and serialized interface that can be important if you ever make breaking changes to a node schema (by adding or removing properties). See Serialization & Deserialization.

Parameters​
_serializedNode​

Omit<SerializedLexicalNode & Partial<SerializedLexicalNode>, "$slots" | "children" | "version"> & object & Record<string, unknown>

Returns​

LexicalNode

transform()​

static transform(): ((node) => void) | null

Defined in: packages/lexical/src/LexicalNode.ts:1935

Experimental

Registers the returned function as a transform on the node during Editor initialization. Most such use cases should be addressed via the LexicalEditor.registerNodeTransform API.

Experimental - use at your own risk.

Returns​

((node) => void) | null


LineBreakNode​

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:27

Extends​

Methods​

$config()​

$config(): BaseStaticNodeConfig & object & StaticNodeTypeAccessor<"linebreak"> & StaticNodeConfigAccessor<{ extends: typeof LexicalNode; generated: GeneratedJSONFactory; importDOM: { br: (node) => { conversion: (node) => DOMConversionOutput; priority: 0; } | null; }; }>

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:31

Override this to implement the new static node configuration protocol, this method is called directly on the prototype and must not depend on anything initialized in the constructor. Generally it should be a trivial implementation.

Returns​

BaseStaticNodeConfig & object & StaticNodeTypeAccessor<"linebreak"> & StaticNodeConfigAccessor<{ extends: typeof LexicalNode; generated: GeneratedJSONFactory; importDOM: { br: (node) => { conversion: (node) => DOMConversionOutput; priority: 0; } | null; }; }>

Example​
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Overrides​

LexicalNode.$config

createDOM()​

createDOM(): HTMLElement

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:53

Called during the reconciliation process to determine which nodes to insert into the DOM for this Lexical Node.

This method must return exactly one HTMLElement. Nested elements are not supported.

Do not attempt to update the Lexical EditorState during this phase of the update lifecycle.

Returns​

HTMLElement

Overrides​

LexicalNode.createDOM

getTextContent()​

getTextContent(): "\n"

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:49

Returns the text content of the node. Override this for custom nodes that should have a representation in plain text format (for copy + paste, for example)

Returns​

"\n"

Overrides​

LexicalNode.getTextContent

isInline()​

isInline(): true

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:61

Returns​

true

Overrides​

LexicalNode.isInline

updateDOM()​

updateDOM(): false

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:57

Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.

Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.

Returns​

false

Overrides​

LexicalNode.updateDOM


ParagraphNode​

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:52

Extends​

Methods​

$config()​

$config(): BaseStaticNodeConfig & StaticNodeConfigAccessor<{ $transform: { }; extends: typeof LexicalNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<ElementNode, { direction?: "ltr" | "rtl" | null; format?: "" | "left" | "start" | "center" | "right" | "end" | "justify"; indent?: string | number; textFormat?: string | number; textStyle?: string; }>; }> & object & StaticNodeTypeAccessor<"paragraph"> & StaticNodeConfigAccessor<{ extends: typeof ElementNode; generated: GeneratedJSONFactory; importDOM: { p: () => object; }; }>

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:56

Override this to implement the new static node configuration protocol, this method is called directly on the prototype and must not depend on anything initialized in the constructor. Generally it should be a trivial implementation.

Returns​

BaseStaticNodeConfig & StaticNodeConfigAccessor<{ $transform: { }; extends: typeof LexicalNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<ElementNode, { direction?: "ltr" | "rtl" | null; format?: "" | "left" | "start" | "center" | "right" | "end" | "justify"; indent?: string | number; textFormat?: string | number; textStyle?: string; }>; }> & object & StaticNodeTypeAccessor<"paragraph"> & StaticNodeConfigAccessor<{ extends: typeof ElementNode; generated: GeneratedJSONFactory; importDOM: { p: () => object; }; }>

Example​
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Overrides​

ElementNode.$config

collapseAtStart()​

collapseAtStart(): boolean

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:178

Returns​

boolean

Overrides​

ElementNode.collapseAtStart

createDOM()​

createDOM(config): HTMLElement

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:71

Called during the reconciliation process to determine which nodes to insert into the DOM for this Lexical Node.

This method must return exactly one HTMLElement. Nested elements are not supported.

Do not attempt to update the Lexical EditorState during this phase of the update lifecycle.

Parameters​
config​

EditorConfig

Returns​

HTMLElement

Overrides​

ElementNode.createDOM

exportDOM()​

exportDOM(editor): DOMExportOutput

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:88

Controls how the this node is serialized to HTML. This is important for copy and paste between Lexical and non-Lexical editors, or Lexical editors with different namespaces, in which case the primary transfer format is HTML. It's also important if you're serializing to HTML for any other reason via $generateHtmlFromNodes. You could also use this method to build your own HTML renderer.

Parameters​
editor​

LexicalEditor

Returns​

DOMExportOutput

Overrides​

ElementNode.exportDOM

exportJSON()​
Call Signature​

exportJSON(compact?): SerializedParagraphNode

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:107

Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.

The base implementation writes every property the node's schema declares (its own and those it inherits), reading each through its getter — get<Prop> by default, or the name recorded with withAccessors. A getter that returns undefined omits its property. Override this only for output a schema can not describe, and call super.exportJSON(compact) when you do.

This may serialize the instance as-is, without resolving the latest version. A property declared with withField is read straight off the node, which is the optimization the serialization walk is built on — every node the walk reaches comes from the EditorState's node map and is already current, so it resolves nothing per node.

So on a reference that a getWritable() (any set<Prop>) has since superseded, this writes pre-mutation values. Which properties do is not something to rely on: a property whose accessor a subclass overrode still goes through that accessor and resolves the latest, so one node can write a current text beside a stale style. Call node.getLatest().exportJSON() whenever you hold such a reference rather than reasoning about which properties resolve.

This is a breaking change. Every property previously went through an accessor, and every accessor resolves getLatest(), so a stale reference exported current values.

Parameters​
compact?​

false

Write the compact form: omit a property the parser derives rather than reads, one whose value is the schema default parsing would restore, and the deprecated version. The two forms describe the same document. A node that overrides this and ignores the flag simply keeps writing the full form, which still parses.

Returns​

SerializedParagraphNode

Overrides​

ElementNode.exportJSON

Call Signature​

exportJSON(compact): SerializedPartial<SerializedParagraphNode>

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:108

The compact form omits properties, so what it returns is the partial serialized type — every node-specific property optional — rather than the full one. Passing a boolean whose value is not statically known selects this overload too, which is right: neither form can be promised then.

Parameters​
compact​

boolean

Returns​

SerializedPartial<SerializedParagraphNode>

See​

SerializedPartial

Overrides​

ElementNode.exportJSON

extractWithChild()​

extractWithChild(child, selection, destination): boolean

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:130

Parameters​
child​

LexicalNode

selection​

BaseSelection | null

destination​

"clone" | "html"

Returns​

boolean

Overrides​

ElementNode.extractWithChild

insertNewAfter()​

insertNewAfter(rangeSelection, restoreSelection): ParagraphNode

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:163

Parameters​
rangeSelection​

RangeSelection

restoreSelection​

boolean

Returns​

ParagraphNode

Overrides​

ElementNode.insertNewAfter

updateDOM()​

updateDOM(prevNode, dom, config): boolean

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:80

Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.

Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.

Parameters​
prevNode​

ParagraphNode

dom​

HTMLElement

config​

EditorConfig

Returns​

boolean

Overrides​

ElementNode.updateDOM


RootNode​

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:26

Extends​

Constructors​

Constructor​

new RootNode(): RootNode

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:34

Returns​

RootNode

Overrides​

ElementNode.constructor

Methods​

$config()​

$config(): BaseStaticNodeConfig & StaticNodeConfigAccessor<{ $transform: { }; extends: typeof LexicalNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<ElementNode, { direction?: "ltr" | "rtl" | null; format?: "" | "left" | "start" | "center" | "right" | "end" | "justify"; indent?: string | number; textFormat?: string | number; textStyle?: string; }>; }> & object & StaticNodeTypeAccessor<"root"> & StaticNodeConfigAccessor<{ extends: typeof ElementNode; }>

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:30

Override this to implement the new static node configuration protocol, this method is called directly on the prototype and must not depend on anything initialized in the constructor. Generally it should be a trivial implementation.

Returns​

BaseStaticNodeConfig & StaticNodeConfigAccessor<{ $transform: { }; extends: typeof LexicalNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<ElementNode, { direction?: "ltr" | "rtl" | null; format?: "" | "left" | "start" | "center" | "right" | "end" | "justify"; indent?: string | number; textFormat?: string | number; textStyle?: string; }>; }> & object & StaticNodeTypeAccessor<"root"> & StaticNodeConfigAccessor<{ extends: typeof ElementNode; }>

Example​
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Overrides​

ElementNode.$config

collapseAtStart()​

collapseAtStart(): true

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:99

Returns​

true

Overrides​

ElementNode.collapseAtStart

getTextContent()​

getTextContent(): string

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:46

Returns the text content of the node. Override this for custom nodes that should have a representation in plain text format (for copy + paste, for example)

Returns​

string

Overrides​

ElementNode.getTextContent

getTopLevelElementOrThrow()​

getTopLevelElementOrThrow(): never

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:39

Returns the highest (in the EditorState tree) non-root ancestor of this node, or throws if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".

Returns​

never

Overrides​

ElementNode.getTopLevelElementOrThrow

insertAfter()​

insertAfter(nodeToInsert): LexicalNode

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:67

Inserts a node after this LexicalNode (as the next sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert after this one.

Returns​

LexicalNode

Overrides​

ElementNode.insertAfter

insertBefore()​

insertBefore(nodeToInsert): LexicalNode

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:63

Inserts a node before this LexicalNode (as the previous sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert before this one.

Returns​

LexicalNode

Overrides​

ElementNode.insertBefore

remove()​

remove(): never

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:55

Removes this LexicalNode from the EditorState. If the node isn't re-inserted somewhere, the Lexical garbage collector will eventually clean it up.

Returns​

never

Overrides​

ElementNode.remove

replace()​

replace<N>(node): never

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:59

Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.

Named slots are bound to their host node and are never transferred: this node keeps its slot map, so if it is reattached elsewhere (as $wrapNodeInElement does) its slots come with it, and if it stays detached the slot subtrees are garbage-collected along with it. To move a slot value onto another host, use $setSlot explicitly.

Type Parameters​
N​

N = LexicalNode

Parameters​
node​

N

Returns​

never

Overrides​

ElementNode.replace

splice()​

splice(start, deleteCount, nodesToInsert): this

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:78

Parameters​
start​

number

deleteCount​

number

nodesToInsert​

LexicalNode[]

Returns​

this

Overrides​

ElementNode.splice

updateDOM()​

updateDOM(prevNode, dom): false

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:73

Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.

Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.

Parameters​
prevNode​

this

dom​

HTMLElement

Returns​

false

Overrides​

ElementNode.updateDOM

importJSON()​

static importJSON(serializedNode): RootNode

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:92

Controls how the this node is deserialized from JSON. This is usually boilerplate, but provides an abstraction between the node implementation and serialized interface that can be important if you ever make breaking changes to a node schema (by adding or removing properties). See Serialization & Deserialization.

Parameters​
serializedNode​

SerializedPartial<SerializedElementNode>

Returns​

RootNode

Overrides​

ElementNode.importJSON


TabNode​

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:64

Extends​

Constructors​

Constructor​

new TabNode(key?): TabNode

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:76

Parameters​
key?​

string | undefined

Returns​

TabNode

Overrides​

TextNode.constructor

Methods​

$config()​

$config(): BaseStaticNodeConfig & object & StaticNodeTypeAccessor<"text"> & StaticNodeConfigAccessor<{ extends: typeof LexicalNode; generated: GeneratedJSONFactory; importDOM: { #text: () => object; b: () => object; code: () => object; em: () => object; i: () => object; mark: () => object; s: () => object; span: () => object; strong: () => object; sub: () => object; sup: () => object; u: () => object; }; json: NodeSerializationSchema<TextNode, { detail?: string | number; format?: string | number; mode?: "normal" | "token" | "segmented"; style?: string; text?: string; }>; }> & object & StaticNodeTypeAccessor<"tab"> & StaticNodeConfigAccessor<{ extends: typeof TextNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<TabNode, { detail?: string | number; mode?: "normal"; text?: string; }>; }>

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:65

Override this to implement the new static node configuration protocol, this method is called directly on the prototype and must not depend on anything initialized in the constructor. Generally it should be a trivial implementation.

Returns​

BaseStaticNodeConfig & object & StaticNodeTypeAccessor<"text"> & StaticNodeConfigAccessor<{ extends: typeof LexicalNode; generated: GeneratedJSONFactory; importDOM: { #text: () => object; b: () => object; code: () => object; em: () => object; i: () => object; mark: () => object; s: () => object; span: () => object; strong: () => object; sub: () => object; sup: () => object; u: () => object; }; json: NodeSerializationSchema<TextNode, { detail?: string | number; format?: string | number; mode?: "normal" | "token" | "segmented"; style?: string; text?: string; }>; }> & object & StaticNodeTypeAccessor<"tab"> & StaticNodeConfigAccessor<{ extends: typeof TextNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<TabNode, { detail?: string | number; mode?: "normal"; text?: string; }>; }>

Example​
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Overrides​

TextNode.$config

canInsertTextAfter()​

canInsertTextAfter(): boolean

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:135

This method is meant to be overridden by TextNode subclasses to control the behavior of those nodes when a user event would cause text to be inserted after them in the editor. If true, Lexical will attempt to insert text into this node. If false, it will insert the text in a new sibling node.

Returns​

boolean

true if text can be inserted after the node, false otherwise.

Overrides​

TextNode.canInsertTextAfter

canInsertTextBefore()​

canInsertTextBefore(): boolean

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:131

This method is meant to be overridden by TextNode subclasses to control the behavior of those nodes when a user event would cause text to be inserted before them in the editor. If true, Lexical will attempt to insert text into this node. If false, it will insert the text in a new sibling node.

Returns​

boolean

true if text can be inserted before the node, false otherwise.

Overrides​

TextNode.canInsertTextBefore

createDOM()​

createDOM(config): HTMLElement

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:81

Called during the reconciliation process to determine which nodes to insert into the DOM for this Lexical Node.

This method must return exactly one HTMLElement. Nested elements are not supported.

Do not attempt to update the Lexical EditorState during this phase of the update lifecycle.

Parameters​
config​

EditorConfig

Returns​

HTMLElement

Overrides​

TextNode.createDOM

setDetail()​

setDetail(detail): this

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:121

Sets the node detail to the provided TextDetailType or 32-bit integer. Note that the TextDetailType version of the argument can only specify one detail value and doing so will remove all other detail values that may be applied to the node. For toggling behavior, consider using TextNode.toggleDirectionless or TextNode.toggleUnmergeable

Parameters​
detail​

number | TextDetailType

TextDetailType or 32-bit integer representing the node detail.

Returns​

this

this TextNode. // TODO 0.12 This should just be a string.

Overrides​

TextNode.setDetail

setMode()​

setMode(type): this

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:126

Sets the mode of the node.

Note: during IME composition, a segmented TextNode may be temporarily switched to normal mode to preserve the DOM element that the browser's composition tracker is bound to. Subclass transforms or method overrides that assume the node is always in segmented mode should account for this transient state.

Parameters​
type​

TextModeType

Returns​

this

this TextNode.

Overrides​

TextNode.setMode

setTextContent()​

setTextContent(_text): this

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:96

Always normalizes the stored content to '\t' regardless of input — see comment below for the rationale.

Parameters​
_text​

string

Returns​

this

Overrides​

TextNode.setTextContent

spliceText()​

spliceText(offset, delCount, newText, moveSelection?): TextNode

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:107

Inserts the provided text into this TextNode at the provided offset, deleting the number of characters specified. Can optionally calculate a new selection after the operation is complete.

Parameters​
offset​

number

the offset at which the splice operation should begin.

delCount​

number

the number of characters to delete, starting from the offset.

newText​

string

the text to insert into the TextNode at the offset.

moveSelection?​

boolean

optional, whether or not to move selection to the end of the inserted substring.

Returns​

TextNode

this TextNode.

Overrides​

TextNode.spliceText


TextNode​

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:357

Extends​

Extended by​

Implements​

Constructors​

Constructor​

new TextNode(text?, key?): TextNode

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:460

Parameters​
text?​

string = ''

key?​

string

Returns​

TextNode

Properties​

__text​

__text: string

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:387

importDOM?​

static optional importDOM?: () => DOMConversionMap<any> | null

Defined in: packages/lexical/src/LexicalNode.ts:1162

Returns​

DOMConversionMap<any> | null

Methods​

$config()​

$config(): BaseStaticNodeConfig & object & StaticNodeTypeAccessor<"text"> & StaticNodeConfigAccessor<{ extends: typeof LexicalNode; generated: GeneratedJSONFactory; importDOM: { #text: () => object; b: () => object; code: () => object; em: () => object; i: () => object; mark: () => object; s: () => object; span: () => object; strong: () => object; sub: () => object; sup: () => object; u: () => object; }; json: NodeSerializationSchema<TextNode, { detail?: string | number; format?: string | number; mode?: "normal" | "token" | "segmented"; style?: string; text?: string; }>; }>

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:402

Override this to implement the new static node configuration protocol, this method is called directly on the prototype and must not depend on anything initialized in the constructor. Generally it should be a trivial implementation.

Returns​

BaseStaticNodeConfig & object & StaticNodeTypeAccessor<"text"> & StaticNodeConfigAccessor<{ extends: typeof LexicalNode; generated: GeneratedJSONFactory; importDOM: { #text: () => object; b: () => object; code: () => object; em: () => object; i: () => object; mark: () => object; s: () => object; span: () => object; strong: () => object; sub: () => object; sup: () => object; u: () => object; }; json: NodeSerializationSchema<TextNode, { detail?: string | number; format?: string | number; mode?: "normal" | "token" | "segmented"; style?: string; text?: string; }>; }>

Example​
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Inherited from​

LexicalNode.$config

afterCloneFrom()​

afterCloneFrom(prevNode): void

Defined in: packages/lexical/src/LexicalNode.ts:1139

Perform any state updates on the clone of prevNode that are not already handled by the constructor call in the static clone method. If you have state to update in your clone that is not handled directly by the constructor, it is advisable to override this method but it is required to include a call to super.afterCloneFrom(prevNode) in your implementation. This is only intended to be called by $cloneWithProperties function or via a super call.

Parameters​
prevNode​

this

Returns​

void

Example​
class ClassesTextNode extends TextNode {
// Not shown: static getType, static importJSON, exportJSON, createDOM, updateDOM
__classes = new Set<string>();
static clone(node: ClassesTextNode): ClassesTextNode {
// The inherited TextNode constructor is used here, so
// classes is not set by this method.
return new ClassesTextNode(node.__text, node.__key);
}
afterCloneFrom(node: this): void {
// This calls TextNode.afterCloneFrom and LexicalNode.afterCloneFrom
// for necessary state updates
super.afterCloneFrom(node);
this.__addClasses(node.__classes);
}
// This method is a private implementation detail, it is not
// suitable for the public API because it does not call getWritable
__addClasses(classNames: Iterable<string>): this {
for (const className of classNames) {
this.__classes.add(className);
}
return this;
}
addClass(...classNames: string[]): this {
return this.getWritable().__addClasses(classNames);
}
removeClass(...classNames: string[]): this {
const node = this.getWritable();
for (const className of classNames) {
this.__classes.delete(className);
}
return this;
}
getClasses(): Set<string> {
return this.getLatest().__classes;
}
}
Inherited from​

LexicalNode.afterCloneFrom

canHaveFormat()​

canHaveFormat(): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:611

Returns​

boolean

true if the text node supports font styling, false otherwise.

canInsertTextAfter()​

canInsertTextAfter(): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1004

This method is meant to be overridden by TextNode subclasses to control the behavior of those nodes when a user event would cause text to be inserted after them in the editor. If true, Lexical will attempt to insert text into this node. If false, it will insert the text in a new sibling node.

Returns​

boolean

true if text can be inserted after the node, false otherwise.

canInsertTextBefore()​

canInsertTextBefore(): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:993

This method is meant to be overridden by TextNode subclasses to control the behavior of those nodes when a user event would cause text to be inserted before them in the editor. If true, Lexical will attempt to insert text into this node. If false, it will insert the text in a new sibling node.

Returns​

boolean

true if text can be inserted before the node, false otherwise.

config()​
Call Signature​

config<Config>(type, config): AbstractStaticNodeConfigRecord<Config>

Defined in: packages/lexical/src/LexicalNode.ts:1066

This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.

An abstract base class that has no concrete node type may pass a well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of a string type to declare configuration shared with its subclasses.

Type Parameters​
Config​

Config extends StaticNodeConfigValue<TextNode, string>

Parameters​
type​

symbol

config​

Config

Returns​

AbstractStaticNodeConfigRecord<Config>

Inherited from​

LexicalNode.config

Call Signature​

config<Type, Config>(type, config): StaticNodeConfigRecord<Type, Config>

Defined in: packages/lexical/src/LexicalNode.ts:1070

This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.

An abstract base class that has no concrete node type may pass a well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of a string type to declare configuration shared with its subclasses.

Type Parameters​
Type​

Type extends string

Config​

Config extends StaticNodeConfigValue<TextNode, Type>

Parameters​
type​

Type

config​

Config

Returns​

StaticNodeConfigRecord<Type, Config>

Inherited from​

LexicalNode.config

createDOM()​

createDOM(config, editor?): HTMLElement

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:624

Called during the reconciliation process to determine which nodes to insert into the DOM for this Lexical Node.

This method must return exactly one HTMLElement. Nested elements are not supported.

Do not attempt to update the Lexical EditorState during this phase of the update lifecycle.

Parameters​
config​

EditorConfig

editor?​

LexicalEditor

Returns​

HTMLElement

Inherited from​

LexicalNode.createDOM

createParentElementNode()​

createParentElementNode(): ElementNode

Defined in: packages/lexical/src/LexicalNode.ts:2313

The creation logic for any required parent. Should be implemented if isParentRequired returns true.

Returns​

ElementNode

Inherited from​

LexicalNode.createParentElementNode

exportDOM()​

exportDOM(editor): DOMExportOutput

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:714

Controls how the this node is serialized to HTML. This is important for copy and paste between Lexical and non-Lexical editors, or Lexical editors with different namespaces, in which case the primary transfer format is HTML. It's also important if you're serializing to HTML for any other reason via $generateHtmlFromNodes. You could also use this method to build your own HTML renderer.

Parameters​
editor​

LexicalEditor

Returns​

DOMExportOutput

Inherited from​

LexicalNode.exportDOM

exportJSON()​
Call Signature​

exportJSON(compact?): SerializedTextNode

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:358

Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.

The base implementation writes every property the node's schema declares (its own and those it inherits), reading each through its getter — get<Prop> by default, or the name recorded with withAccessors. A getter that returns undefined omits its property. Override this only for output a schema can not describe, and call super.exportJSON(compact) when you do.

This may serialize the instance as-is, without resolving the latest version. A property declared with withField is read straight off the node, which is the optimization the serialization walk is built on — every node the walk reaches comes from the EditorState's node map and is already current, so it resolves nothing per node.

So on a reference that a getWritable() (any set<Prop>) has since superseded, this writes pre-mutation values. Which properties do is not something to rely on: a property whose accessor a subclass overrode still goes through that accessor and resolves the latest, so one node can write a current text beside a stale style. Call node.getLatest().exportJSON() whenever you hold such a reference rather than reasoning about which properties resolve.

This is a breaking change. Every property previously went through an accessor, and every accessor resolves getLatest(), so a stale reference exported current values.

Parameters​
compact?​

false

Write the compact form: omit a property the parser derives rather than reads, one whose value is the schema default parsing would restore, and the deprecated version. The two forms describe the same document. A node that overrides this and ignores the flag simply keeps writing the full form, which still parses.

Returns​

SerializedTextNode

Inherited from​

LexicalNode.exportJSON

Call Signature​

exportJSON(compact): SerializedPartial<SerializedTextNode>

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:359

The compact form omits properties, so what it returns is the partial serialized type — every node-specific property optional — rather than the full one. Passing a boolean whose value is not statically known selects this overload too, which is right: neither form can be promised then.

Parameters​
compact​

boolean

Returns​

SerializedPartial<SerializedTextNode>

See​

SerializedPartial

Inherited from​

LexicalNode.exportJSON

getCommonAncestor()​

getCommonAncestor<T>(node): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1507

Type Parameters​
T​

T extends ElementNode = ElementNode

Parameters​
node​

LexicalNode

the other node to find the common ancestor of.

Returns​

T | null

Deprecated​

use $getCommonAncestor

Returns the closest common ancestor of this node and the provided one or null if one cannot be found.

Inherited from​

LexicalNode.getCommonAncestor

getDetail()​

getDetail(): number

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:487

Returns a 32-bit integer that represents the TextDetailTypes currently applied to the TextNode. You probably don't want to use this method directly - consider using TextNode.isDirectionless or TextNode.isUnmergeable instead.

Returns​

number

a number representing the detail of the text node.

getDOMSlot()​

getDOMSlot(element): DOMSlot<HTMLElement>

Defined in: packages/lexical/src/LexicalNode.ts:1784

Experimental

Returns a DOMSlot pointing at the content-bearing element of this node's DOM. The default returns a slot wrapping the keyed DOM as-is.

Override this when createDOM returns a wrapper around the content-bearing element (e.g. <span><br/></span> for a styled line break), so selection / reconciliation logic can target the inner element.

ElementNode overrides this to return an ElementDOMSlot with children-management semantics (used by the reconciler to place managed children).

Parameters​
element​

HTMLElement

Returns​

DOMSlot<HTMLElement>

Inherited from​

LexicalNode.getDOMSlot

getFormat()​

getFormat(): number

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:475

Returns a 32-bit integer that represents the TextFormatTypes currently applied to the TextNode. You probably don't want to use this method directly - consider using TextNode.hasFormat instead.

Returns​

number

a number representing the format of the text node.

getFormatFlags()​

getFormatFlags(type, alignWithFormat): number

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:601

Returns the format flags applied to the node as a 32-bit integer.

Parameters​
type​

TextFormatType

alignWithFormat​

number | null

Returns​

number

a number representing the TextFormatTypes applied to the node.

getIndexWithinParent()​

getIndexWithinParent(): number

Defined in: packages/lexical/src/LexicalNode.ts:1284

Returns the zero-based index of this node within the parent.

Returns​

number

Inherited from​

LexicalNode.getIndexWithinParent

getKey()​

getKey(): string

Defined in: packages/lexical/src/LexicalNode.ts:1276

Returns this nodes key.

Returns​

string

Inherited from​

LexicalNode.getKey

getLatest()​

getLatest(): this

Defined in: packages/lexical/src/LexicalNode.ts:1657

Returns the latest version of the node from the active EditorState. This is used to avoid getting values from stale node references.

Returns​

this

Inherited from​

LexicalNode.getLatest

getMode()​

getMode(): TextModeType

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:497

Returns the mode (TextModeType) of the TextNode, which may be "normal", "token", or "segmented"

Returns​

TextModeType

TextModeType.

getNextSibling()​
Call Signature​

getNextSibling(): LexicalNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1463

Returns the node after this one in the same parent, or null if there is no such node.

Returns​

LexicalNode | null

Inherited from​

LexicalNode.getNextSibling

Call Signature​

getNextSibling<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1470

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getNextSibling() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getNextSibling

getNextSiblings()​
Call Signature​

getNextSiblings(): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1481

Returns all nodes after this one in the same parent, in document order.

Returns​

LexicalNode[]

Inherited from​

LexicalNode.getNextSiblings

Call Signature​

getNextSiblings<T>(): T[]

Defined in: packages/lexical/src/LexicalNode.ts:1488

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getNextSiblings() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

Inherited from​

LexicalNode.getNextSiblings

getNodesBetween()​

getNodesBetween(targetNode): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1576

Returns a list of nodes that are between this node and the target node in the EditorState.

Parameters​
targetNode​

LexicalNode

the node that marks the other end of the range of nodes to be returned.

Returns​

LexicalNode[]

Inherited from​

LexicalNode.getNodesBetween

getParent()​
Call Signature​

getParent(): ElementNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1304

Returns the parent of this node, or null if none is found.

Returns​

ElementNode | null

Inherited from​

LexicalNode.getParent

Call Signature​

getParent<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1311

Type Parameters​
T​

T extends ElementNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getParent() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getParent

getParentKeys()​

getParentKeys(): string[]

Defined in: packages/lexical/src/LexicalNode.ts:1402

Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.

Returns​

string[]

Inherited from​

LexicalNode.getParentKeys

getParentOrThrow()​
Call Signature​

getParentOrThrow(): ElementNode

Defined in: packages/lexical/src/LexicalNode.ts:1324

Returns the parent of this node, or throws if none is found.

Returns​

ElementNode

Inherited from​

LexicalNode.getParentOrThrow

Call Signature​

getParentOrThrow<T>(): T

Defined in: packages/lexical/src/LexicalNode.ts:1331

Type Parameters​
T​

T extends ElementNode

Returns​

T

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getParentOrThrow() as T, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getParentOrThrow

getParents()​

getParents(): ElementNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1387

Returns a list of the every ancestor of this node, all the way up to the RootNode.

Returns​

ElementNode[]

Inherited from​

LexicalNode.getParents

getPreviousSibling()​
Call Signature​

getPreviousSibling(): LexicalNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1416

Returns the node before this one in the same parent, or null if there is no such node.

Returns​

LexicalNode | null

Inherited from​

LexicalNode.getPreviousSibling

Call Signature​

getPreviousSibling<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1423

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getPreviousSibling() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

LexicalNode.getPreviousSibling

getPreviousSiblings()​
Call Signature​

getPreviousSiblings(): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1434

Returns all nodes before this one in the same parent, in document order.

Returns​

LexicalNode[]

Inherited from​

LexicalNode.getPreviousSiblings

Call Signature​

getPreviousSiblings<T>(): T[]

Defined in: packages/lexical/src/LexicalNode.ts:1441

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getPreviousSiblings() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

Inherited from​

LexicalNode.getPreviousSiblings

getStyle()​

getStyle(): string

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:507

Returns the styles currently applied to the node. This is analogous to CSSText in the DOM.

Returns​

string

CSSText-like string of styles applied to the underlying DOM node.

getTextContent()​

getTextContent(): string

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:591

Returns the text content of the node as a string.

Returns​

string

a string representing the text content of the node.

Inherited from​

LexicalNode.getTextContent

getTextContentSize()​

getTextContentSize(): number

Defined in: packages/lexical/src/LexicalNode.ts:1727

Returns the length of the string produced by calling getTextContent on this node.

Returns​

number

Inherited from​

LexicalNode.getTextContentSize

getTopLevelElement()​

getTopLevelElement(): ElementNode | null

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:361

Returns the highest (in the EditorState tree) non-root ancestor of this node, or null if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".

Returns​

ElementNode | null

Inherited from​

LexicalNode.getTopLevelElement

getTopLevelElementOrThrow()​

getTopLevelElementOrThrow(): ElementNode

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:362

Returns the highest (in the EditorState tree) non-root ancestor of this node, or throws if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".

Returns​

ElementNode

Inherited from​

LexicalNode.getTopLevelElementOrThrow

getType()​

getType(): string

Defined in: packages/lexical/src/LexicalNode.ts:1187

Returns the string type of this node.

Returns​

string

Inherited from​

LexicalNode.getType

getWritable()​

getWritable(): this

Defined in: packages/lexical/src/LexicalNode.ts:1678

Returns a mutable version of the node using $cloneWithProperties if necessary. Will throw an error if called outside of a Lexical Editor LexicalEditor.update callback.

Returns​

this

Inherited from​

LexicalNode.getWritable

hasFormat()​

hasFormat(type): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:570

Returns whether or not the node has the provided format applied. Use this with the human-readable TextFormatType string values to get the format of a TextNode.

Parameters​
type​

TextFormatType

the TextFormatType to check for.

Returns​

boolean

true if the node has the provided format, false otherwise.

insertAfter()​

insertAfter(nodeToInsert, restoreSelection?): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:2117

Inserts a node after this LexicalNode (as the next sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert after this one.

restoreSelection?​

boolean = true

Whether or not to attempt to resolve the selection to the appropriate place after the operation is complete.

Returns​

LexicalNode

Inherited from​

LexicalNode.insertAfter

insertBefore()​

insertBefore(nodeToInsert, restoreSelection?): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:2224

Inserts a node before this LexicalNode (as the previous sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert before this one.

restoreSelection?​

boolean = true

Whether or not to attempt to resolve the selection to the appropriate place after the operation is complete.

Returns​

LexicalNode

Inherited from​

LexicalNode.insertBefore

is()​

is(object): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1524

Returns true if the provided node is the exact same one as this node, from Lexical's perspective. Always use this instead of referential equality.

Parameters​
object​

LexicalNode | null | undefined

the node to perform the equality comparison on.

Returns​

boolean

Inherited from​

LexicalNode.is

isAttached()​

isAttached(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1204

Returns true if there is a path between this node and the RootNode, false otherwise. This is a way of determining if the node is "attached" EditorState. Unattached nodes won't be reconciled and will ultimately be cleaned up by the Lexical GC.

Returns​

boolean

Inherited from​

LexicalNode.isAttached

isBefore()​

isBefore(targetNode): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1542

Returns true if this node logically precedes the target node in the editor state, false otherwise (including if there is no common ancestor).

Note that this notion of isBefore is based on post-order; a descendant node is always before its ancestors. See also $getCommonAncestor and $comparePointCaretNext for more flexible ways to determine the relative positions of nodes.

Parameters​
targetNode​

LexicalNode

the node we're testing to see if it's after this one.

Returns​

boolean

Inherited from​

LexicalNode.isBefore

isComposing()​

isComposing(): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:528

Returns​

boolean

true if Lexical detects that an IME or other 3rd-party script is attempting to mutate the TextNode, false otherwise.

isDirectionless()​

isDirectionless(): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:547

Returns whether or not the node is "directionless". Directionless nodes don't respect changes between RTL and LTR modes.

Returns​

boolean

true if the node is directionless, false otherwise.

isDirty()​

isDirty(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1646

Returns true if this node has been marked dirty during this update cycle.

Returns​

boolean

Inherited from​

LexicalNode.isDirty

isInline()​

isInline(): true

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:618

Returns​

true

true if the text node is inline, false otherwise.

Inherited from​

LexicalNode.isInline

isParentOf()​

isParentOf(targetNode): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1565

Returns true if this node is an ancestor of and distinct from the target node, false otherwise.

Parameters​
targetNode​

LexicalNode

the would-be child node.

Returns​

boolean

Inherited from​

LexicalNode.isParentOf

isParentRequired()​

isParentRequired(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:2305

Whether or not this node has a required parent. Used during copy + paste operations to normalize nodes that would otherwise be orphaned. For example, ListItemNodes without a ListNode parent or TextNodes with a ParagraphNode parent.

Returns​

boolean

Inherited from​

LexicalNode.isParentRequired

isSegmented()​

isSegmented(): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:538

Returns whether or not the node is in "segmented" mode. TextNodes in segmented mode can be navigated through character-by-character with a RangeSelection, but are deleted in space-delimited "segments".

Returns​

boolean

true if the node is in segmented mode, false otherwise.

isSelected()​

isSelected(selection?): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1231

Returns true if this node is contained within the provided Selection., false otherwise. Relies on the algorithms implemented in BaseSelection.getNodes to determine what's included.

Parameters​
selection?​

BaseSelection | null

The selection that we want to determine if the node is in.

Returns​

boolean

Inherited from​

LexicalNode.isSelected

isSimpleText()​

isSimpleText(): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:581

Returns whether or not the node is simple text. Simple text is defined as a TextNode that has the string type "text" (i.e., not a subclass) and has no mode applied to it (i.e., not segmented or token).

Returns​

boolean

true if the node is simple text, false otherwise.

isTextEntity()​

isTextEntity(): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1236

This method is meant to be overridden by TextNode subclasses to control the behavior of those nodes when used with the registerLexicalTextEntity function. If you're using registerLexicalTextEntity, the node class that you create and replace matched text with should return true from this method.

Returns​

boolean

true if the node is to be treated as a "text entity", false otherwise.

isToken()​

isToken(): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:518

Returns whether or not the node is in "token" mode. TextNodes in token mode can be navigated through character-by-character with a RangeSelection, but are deleted as a single entity (not individually by character).

Returns​

boolean

true if the node is in token mode, false otherwise.

isUnmergeable()​

isUnmergeable(): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:557

Returns whether or not the node is unmergeable. In some scenarios, Lexical tries to merge adjacent TextNodes into a single TextNode. If a TextNode is unmergeable, this won't happen.

Returns​

boolean

true if the node is unmergeable, false otherwise.

markDirty()​

markDirty(): void

Defined in: packages/lexical/src/LexicalNode.ts:2388

Marks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.

Returns​

void

Inherited from​

LexicalNode.markDirty

mergeWithSibling()​

mergeWithSibling(target): TextNode

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1181

Merges the target TextNode into this TextNode, removing the target node.

Parameters​
target​

TextNode

the TextNode to merge into this one.

Returns​

TextNode

this TextNode.

remove()​

remove(preserveEmptyParent?): void

Defined in: packages/lexical/src/LexicalNode.ts:1949

Removes this LexicalNode from the EditorState. If the node isn't re-inserted somewhere, the Lexical garbage collector will eventually clean it up.

Parameters​
preserveEmptyParent?​

boolean

If falsy, the node's parent will be removed if it's empty after the removal operation. This is the default behavior, subject to other node heuristics such as ElementNode#canBeEmpty

Returns​

void

Inherited from​

LexicalNode.remove

replace()​

replace<N>(replaceWith, includeChildren?): N

Defined in: packages/lexical/src/LexicalNode.ts:1966

Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.

Named slots are bound to their host node and are never transferred: this node keeps its slot map, so if it is reattached elsewhere (as $wrapNodeInElement does) its slots come with it, and if it stays detached the slot subtrees are garbage-collected along with it. To move a slot value onto another host, use $setSlot explicitly.

Type Parameters​
N​

N extends LexicalNode

Parameters​
replaceWith​

N

The node to replace this one with.

includeChildren?​

boolean

Whether or not to transfer the children of this node to the replacing node.

Returns​

N

Inherited from​

LexicalNode.replace

resetOnCopyNodeFrom()​

resetOnCopyNodeFrom(originalNode): void

Defined in: packages/lexical/src/LexicalNode.ts:1155

Reset state in this copy of originalNode, if necessary

Parameters​
originalNode​

this

Returns​

void

Inherited from​

LexicalNode.resetOnCopyNodeFrom

select()​

select(_anchorOffset?, _focusOffset?): RangeSelection

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:891

Sets the current Lexical selection to be a RangeSelection with anchor and focus on this TextNode at the provided offsets.

Parameters​
_anchorOffset?​

number

the offset at which the Selection anchor will be placed.

_focusOffset?​

number

the offset at which the Selection focus will be placed.

Returns​

RangeSelection

the new RangeSelection.

selectEnd()​

selectEnd(): RangeSelection

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:936

Returns​

RangeSelection

Inherited from​

LexicalNode.selectEnd

selectionTransform()​

selectionTransform(prevSelection, nextSelection): void

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:753

Parameters​
prevSelection​

BaseSelection | null

nextSelection​

RangeSelection

Returns​

void

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2360

Moves selection to the next sibling of this node, at the specified offsets.

Parameters​
anchorOffset?​

number

The anchor offset for selection.

focusOffset?​

number

The focus offset for selection

Returns​

RangeSelection

Inherited from​

LexicalNode.selectNext

selectPrevious()​

selectPrevious(anchorOffset?, focusOffset?): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2331

Moves selection to the previous sibling of this node, at the specified offsets.

Parameters​
anchorOffset?​

number

The anchor offset for selection.

focusOffset?​

number

The focus offset for selection

Returns​

RangeSelection

Inherited from​

LexicalNode.selectPrevious

selectStart()​

selectStart(): RangeSelection

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:932

Returns​

RangeSelection

Inherited from​

LexicalNode.selectStart

setDetail()​

setDetail(detail): this

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:788

Sets the node detail to the provided TextDetailType or 32-bit integer. Note that the TextDetailType version of the argument can only specify one detail value and doing so will remove all other detail values that may be applied to the node. For toggling behavior, consider using TextNode.toggleDirectionless or TextNode.toggleUnmergeable

Parameters​
detail​

number | TextDetailType

TextDetailType or 32-bit integer representing the node detail.

Returns​

this

this TextNode. // TODO 0.12 This should just be a string.

setFormat()​

setFormat(format): this

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:770

Sets the node format to the provided TextFormatType or 32-bit integer. Note that the TextFormatType version of the argument can only specify one format and doing so will remove all other formats that may be applied to the node. For toggling behavior, consider using TextNode.toggleFormat

Parameters​
format​

number | TextFormatType

TextFormatType or 32-bit integer representing the node format.

Returns​

this

this TextNode. // TODO 0.12 This should just be a string.

setMode()​

setMode(type): this

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:857

Sets the mode of the node.

Note: during IME composition, a segmented TextNode may be temporarily switched to normal mode to preserve the DOM element that the browser's composition tracker is bound to. Subclass transforms or method overrides that assume the node is always in segmented mode should account for this transient state.

Parameters​
type​

TextModeType

Returns​

this

this TextNode.

setStyle()​

setStyle(style): this

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:803

Sets the node style to the provided CSSText-like string. Set this property as you would an HTMLElement style attribute to apply inline styles to the underlying DOM Element.

Parameters​
style​

string

CSSText to be applied to the underlying HTMLElement.

Returns​

this

this TextNode.

setTextContent()​

setTextContent(text): this

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:874

Sets the text content of the node.

Parameters​
text​

string

the string to set as the text value of the node.

Returns​

this

this TextNode.

spliceText()​

spliceText(offset, delCount, newText, moveSelection?): TextNode

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:952

Inserts the provided text into this TextNode at the provided offset, deleting the number of characters specified. Can optionally calculate a new selection after the operation is complete.

Parameters​
offset​

number

the offset at which the splice operation should begin.

delCount​

number

the number of characters to delete, starting from the offset.

newText​

string

the text to insert into the TextNode at the offset.

moveSelection?​

boolean

optional, whether or not to move selection to the end of the inserted substring.

Returns​

TextNode

this TextNode.

splitText()​

splitText(...splitOffsets): TextNode[]

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1016

Splits this TextNode at the provided character offsets, forming new TextNodes from the substrings formed by the split, and inserting those new TextNodes into the editor, replacing the one that was split.

Parameters​
splitOffsets​

...number[]

rest param of the text content character offsets at which this node should be split.

Returns​

TextNode[]

an Array containing the newly-created TextNodes.

toggleDirectionless()​

toggleDirectionless(): this

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:829

Toggles the directionless detail value of the node. Prefer using this method over setDetail.

Returns​

this

this TextNode.

toggleFormat()​

toggleFormat(type): this

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:818

Applies the provided format to this TextNode if it's not present. Removes it if it's present. The subscript and superscript formats are mutually exclusive. Prefer using this method to turn specific formats on and off.

Parameters​
type​

TextFormatType

TextFormatType to toggle.

Returns​

this

this TextNode.

toggleUnmergeable()​

toggleUnmergeable(): this

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:840

Toggles the unmergeable detail value of the node. Prefer using this method over setDetail.

Returns​

this

this TextNode.

updateDOM()​

updateDOM(prevNode, dom, config): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:647

Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.

Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.

Parameters​
prevNode​

this

dom​

HTMLElement

config​

EditorConfig

Returns​

boolean

Inherited from​

LexicalNode.updateDOM

updateFromJSON()​

updateFromJSON(serializedNode): this

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:360

Update this LexicalNode instance from serialized JSON. It's recommended to implement as much logic as possible in this method instead of the static importJSON method, so that the functionality can be inherited in subclasses.

The LexicalUpdateJSON utility type should be used to ignore any type, version, or children properties in the JSON so that the extended JSON from subclasses are acceptable parameters for the super call.

If overridden, this method must call super.

Parameters​
serializedNode​

LexicalParseJSON<SerializedTextNode>

Returns​

this

Example​
class MyTextNode extends TextNode {
// ...
static importJSON(serializedNode: SerializedMyTextNode): MyTextNode {
return $createMyTextNode()
.updateFromJSON(serializedNode);
}
updateFromJSON(
serializedNode: LexicalUpdateJSON<SerializedMyTextNode>,
): this {
return super.updateFromJSON(serializedNode)
.setMyProperty(serializedNode.myProperty);
}
}

The whole schema is applied, so a property the JSON omits is set to its schema default rather than left as it is — that is what lets the compact form omit a default-valued property and have parsing restore it. (A flat NodeState is the exception: it is applied only when present.) Pass the node's complete serialized form unless you mean to reset what you leave out.

Inherited from​

LexicalNode.updateFromJSON

clone()​

static clone(_data): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:1030

Clones this node, creating a new node with a different key and adding it to the EditorState (but not attaching it anywhere!). All nodes must implement this method.

Parameters​
_data​

unknown

Returns​

LexicalNode

getType()​

static getType(): string

Defined in: packages/lexical/src/LexicalNode.ts:1014

Returns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.

Returns​

string

importJSON()​

static importJSON(_serializedNode): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:1871

Controls how the this node is deserialized from JSON. This is usually boilerplate, but provides an abstraction between the node implementation and serialized interface that can be important if you ever make breaking changes to a node schema (by adding or removing properties). See Serialization & Deserialization.

Parameters​
_serializedNode​

Omit<SerializedLexicalNode & Partial<SerializedLexicalNode>, "$slots" | "children" | "version"> & object & Record<string, unknown>

Returns​

LexicalNode

transform()​

static transform(): ((node) => void) | null

Defined in: packages/lexical/src/LexicalNode.ts:1935

Experimental

Registers the returned function as a transform on the node during Editor initialization. Most such use cases should be addressed via the LexicalEditor.registerNodeTransform API.

Experimental - use at your own risk.

Returns​

((node) => void) | null

Interfaces​

BaseCaret​

Defined in: packages/lexical/src/caret/LexicalCaret.ts:48

Extends​

Extended by​

Type Parameters​

T​

T extends LexicalNode

D​

D extends CaretDirection

Type​

Type

Properties​

direction​

readonly direction: D

Defined in: packages/lexical/src/caret/LexicalCaret.ts:58

next if pointing at the next sibling or first child, previous if pointing at the previous sibling or last child

getAdjacentCaret​

getAdjacentCaret: () => SiblingCaret<LexicalNode, D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:64

Get a new SiblingCaret from getNodeAtCaret() in the same direction.

Returns​

SiblingCaret<LexicalNode, D> | null

getNodeAtCaret​

getNodeAtCaret: () => LexicalNode | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:62

Get the node connected to the origin in the caret's direction, or null if there is no node

Returns​

LexicalNode | null

getParentAtCaret​

getParentAtCaret: () => ElementNode | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:60

Get the ElementNode that is the logical parent (origin for ChildCaret, origin.getParent() for SiblingCaret)

Returns​

ElementNode | null

getSiblingCaret​

getSiblingCaret: () => SiblingCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:68

Get a new SiblingCaret with this same node

Returns​

SiblingCaret<T, D>

insert​

insert: (node) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:76

Insert a node connected to origin in this direction (before the node that this caret is pointing towards, if any existed). For a SiblingCaret this is origin.insertAfter(node) for next, or origin.insertBefore(node) for previous. For a ChildCaret this is origin.splice(0, 0, [node]) for next or origin.append(node) for previous.

Parameters​
node​

LexicalNode

Returns​

this

origin​

readonly origin: T

Defined in: packages/lexical/src/caret/LexicalCaret.ts:54

The origin node of this caret, typically this is what you will use in traversals

remove​

remove: () => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:70

Remove the getNodeAtCaret() node that this caret is pointing towards, if it exists

Returns​

this

replaceOrInsert​

replaceOrInsert: (node, includeChildren?) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:78

If getNodeAtCaret() is not null then replace it with node, otherwise insert node

Parameters​
node​

LexicalNode

includeChildren?​

boolean

Returns​

this

splice​

splice: (deleteCount, nodes, nodesDirection?) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:86

Splice an iterable (typically an Array) of nodes into this location.

Parameters​
deleteCount​

number

The number of existing nodes to replace or delete

nodes​

Iterable<LexicalNode>

An iterable of nodes that will be inserted in this location, using replace instead of insert for the first deleteCount nodes

nodesDirection?​

CaretDirection

The direction of the nodes iterable, defaults to 'next'

Returns​

this

type​

readonly type: Type

Defined in: packages/lexical/src/caret/LexicalCaret.ts:56

sibling for a SiblingCaret (pointing at the next or previous sibling) or child for a ChildCaret (pointing at the first or last child)


BaseSelection​

Defined in: packages/lexical/src/LexicalSelection.ts:398

Properties​

_cachedNodes​

_cachedNodes: LexicalNode[] | null

Defined in: packages/lexical/src/LexicalSelection.ts:399

dirty​

dirty: boolean

Defined in: packages/lexical/src/LexicalSelection.ts:400

Methods​

clone()​

clone(): BaseSelection

Defined in: packages/lexical/src/LexicalSelection.ts:402

Returns​

BaseSelection

extract()​

extract(): LexicalNode[]

Defined in: packages/lexical/src/LexicalSelection.ts:403

Returns​

LexicalNode[]

getCachedNodes()​

getCachedNodes(): LexicalNode[] | null

Defined in: packages/lexical/src/LexicalSelection.ts:413

Returns​

LexicalNode[] | null

getNodes()​

getNodes(): LexicalNode[]

Defined in: packages/lexical/src/LexicalSelection.ts:404

Returns​

LexicalNode[]

getStartEndPoints()​

getStartEndPoints(): [PointType, PointType] | null

Defined in: packages/lexical/src/LexicalSelection.ts:410

Returns​

[PointType, PointType] | null

getTextContent()​

getTextContent(): string

Defined in: packages/lexical/src/LexicalSelection.ts:405

Returns​

string

insertNodes()​

insertNodes(nodes): void

Defined in: packages/lexical/src/LexicalSelection.ts:409

Parameters​
nodes​

LexicalNode[]

Returns​

void

insertRawText()​

insertRawText(text): void

Defined in: packages/lexical/src/LexicalSelection.ts:407

Parameters​
text​

string

Returns​

void

insertText()​

insertText(text): void

Defined in: packages/lexical/src/LexicalSelection.ts:406

Parameters​
text​

string

Returns​

void

is()​

is(selection): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:408

Parameters​
selection​

BaseSelection | null

Returns​

boolean

isBackward()​

isBackward(): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:412

Returns​

boolean

isCollapsed()​

isCollapsed(): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:411

Returns​

boolean

setCachedNodes()​

setCachedNodes(nodes): void

Defined in: packages/lexical/src/LexicalSelection.ts:414

Parameters​
nodes​

LexicalNode[] | null

Returns​

void


CaretRange​

Defined in: packages/lexical/src/caret/LexicalCaret.ts:96

A RangeSelection expressed as a pair of Carets

Extends​

Type Parameters​

D​

D extends CaretDirection = CaretDirection

Properties​

anchor​

anchor: PointCaret<D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:101

direction​

readonly direction: D

Defined in: packages/lexical/src/caret/LexicalCaret.ts:100

focus​

focus: PointCaret<D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:102

getTextSlices​

getTextSlices: () => TextPointCaretSliceTuple<D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:124

There are between zero and two non-null TextSliceCarets for a CaretRange. Note that when anchor and focus share an origin node the second element will be null because the slice is entirely represented by the first element.

[slice, slice]: anchor and focus are TextPointCaret with distinct origin nodes [slice, null]: anchor is a TextPointCaret [null, slice]: focus is a TextPointCaret [null, null]: Neither anchor nor focus are TextPointCarets

Returns​

TextPointCaretSliceTuple<D>

isCollapsed​

isCollapsed: () => boolean

Defined in: packages/lexical/src/caret/LexicalCaret.ts:104

Return true if anchor and focus are the same caret

Returns​

boolean

iterNodeCarets​

iterNodeCarets: (rootMode?) => IterableIterator<NodeCaret<D>>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:113

Iterate the carets between anchor and focus in a pre-order fashion, note that this does not include any text slices represented by the anchor and/or focus. Those are accessed separately from getTextSlices.

An ElementNode origin will be yielded as a ChildCaret on enter, and a SiblingCaret on leave.

Parameters​
rootMode?​

RootMode

Returns​

IterableIterator<NodeCaret<D>>

type​

readonly type: "node-caret-range"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:99

Methods​

[iterator]()​

[iterator](): Iterator<NodeCaret<D>, any, any>

Defined in: typescript/lib/lib.es2015.iterable.d.ts:47

Returns​

Iterator<NodeCaret<D>, any, any>

Inherited from​

Iterable.[iterator]


ChildCaret​

Defined in: packages/lexical/src/caret/LexicalCaret.ts:229

A ChildCaret points from an origin ElementNode towards its first or last child.

Extends​

Type Parameters​

T​

T extends ElementNode = ElementNode

D​

D extends CaretDirection = CaretDirection

Properties​

direction​

readonly direction: D

Defined in: packages/lexical/src/caret/LexicalCaret.ts:58

next if pointing at the next sibling or first child, previous if pointing at the previous sibling or last child

Inherited from​

BaseCaret.direction

getAdjacentCaret​

getAdjacentCaret: () => SiblingCaret<LexicalNode, D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:64

Get a new SiblingCaret from getNodeAtCaret() in the same direction.

Returns​

SiblingCaret<LexicalNode, D> | null

Inherited from​

BaseCaret.getAdjacentCaret

getChildCaret​

getChildCaret: () => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:238

Return this, the ChildCaret is already a child caret of its origin

Returns​

this

getFlipped​

getFlipped: () => NodeCaret<FlipDirection<D>>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:266

Get a new NodeCaret with the head and tail of its directional arrow flipped, such that flipping twice is the identity. For example, given a non-empty parent with a firstChild and lastChild, and a second emptyParent node with no children:

Returns​

NodeCaret<FlipDirection<D>>

Example​
caret.getFlipped().getFlipped().is(caret) === true;
$getChildCaret(parent, 'next').getFlipped().is($getSiblingCaret(firstChild, 'previous')) === true;
$getSiblingCaret(lastChild, 'next').getFlipped().is($getChildCaret(parent, 'previous')) === true;
$getSiblingCaret(firstChild, 'next).getFlipped().is($getSiblingCaret(lastChild, 'previous')) === true;
$getChildCaret(emptyParent, 'next').getFlipped().is($getChildCaret(emptyParent, 'previous')) === true;
getLatest​

getLatest: () => ChildCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:234

Get a new caret with the latest origin pointer

Returns​

ChildCaret<T, D>

getNodeAtCaret​

getNodeAtCaret: () => LexicalNode | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:62

Get the node connected to the origin in the caret's direction, or null if there is no node

Returns​

LexicalNode | null

Inherited from​

BaseCaret.getNodeAtCaret

getParentAtCaret​

getParentAtCaret: () => T

Defined in: packages/lexical/src/caret/LexicalCaret.ts:236

Get the ElementNode that is the logical parent (origin for ChildCaret, origin.getParent() for SiblingCaret)

Returns​

T

Overrides​

BaseCaret.getParentAtCaret

getParentCaret​

getParentCaret: (mode?) => SiblingCaret<T, D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:235

Parameters​
mode?​

RootMode

Returns​

SiblingCaret<T, D> | null

getSiblingCaret​

getSiblingCaret: () => SiblingCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:68

Get a new SiblingCaret with this same node

Returns​

SiblingCaret<T, D>

Inherited from​

BaseCaret.getSiblingCaret

insert​

insert: (node) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:76

Insert a node connected to origin in this direction (before the node that this caret is pointing towards, if any existed). For a SiblingCaret this is origin.insertAfter(node) for next, or origin.insertBefore(node) for previous. For a ChildCaret this is origin.splice(0, 0, [node]) for next or origin.append(node) for previous.

Parameters​
node​

LexicalNode

Returns​

this

Inherited from​

BaseCaret.insert

isSameNodeCaret​

isSameNodeCaret: (other) => other is ChildCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:243

Return true if other is a ChildCaret with the same origin (by node key comparison) and direction.

Parameters​
other​

PointCaret<CaretDirection> | null | undefined

Returns​

other is ChildCaret<T, D>

isSamePointCaret​

isSamePointCaret: (other) => other is ChildCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:250

Return true if other is a ChildCaret with the same origin (by node key comparison) and direction.

Parameters​
other​

PointCaret<CaretDirection> | null | undefined

Returns​

other is ChildCaret<T, D>

origin​

readonly origin: T

Defined in: packages/lexical/src/caret/LexicalCaret.ts:54

The origin node of this caret, typically this is what you will use in traversals

Inherited from​

BaseCaret.origin

remove​

remove: () => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:70

Remove the getNodeAtCaret() node that this caret is pointing towards, if it exists

Returns​

this

Inherited from​

BaseCaret.remove

replaceOrInsert​

replaceOrInsert: (node, includeChildren?) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:78

If getNodeAtCaret() is not null then replace it with node, otherwise insert node

Parameters​
node​

LexicalNode

includeChildren?​

boolean

Returns​

this

Inherited from​

BaseCaret.replaceOrInsert

splice​

splice: (deleteCount, nodes, nodesDirection?) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:86

Splice an iterable (typically an Array) of nodes into this location.

Parameters​
deleteCount​

number

The number of existing nodes to replace or delete

nodes​

Iterable<LexicalNode>

An iterable of nodes that will be inserted in this location, using replace instead of insert for the first deleteCount nodes

nodesDirection?​

CaretDirection

The direction of the nodes iterable, defaults to 'next'

Returns​

this

Inherited from​

BaseCaret.splice

type​

readonly type: "child"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:56

sibling for a SiblingCaret (pointing at the next or previous sibling) or child for a ChildCaret (pointing at the first or last child)

Inherited from​

BaseCaret.type


CommonAncestorResultAncestor​

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1351

Node a is an ancestor of node b, and not the same node

Type Parameters​

A​

A extends ElementNode

Properties​

commonAncestor​

readonly commonAncestor: A

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1353

type​

readonly type: "ancestor"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1352


CommonAncestorResultBranch​

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1361

Node a and node b have a common ancestor but are on different branches, the a and b properties of this result are the ancestors of a and b that are children of the commonAncestor. Since they are siblings, their positions are comparable to determine order in the document.

Type Parameters​

A​

A extends LexicalNode

B​

B extends LexicalNode

Properties​

a​

readonly a: ElementNode | A

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1368

The ancestor of a that is a child of commonAncestor

b​

readonly b: ElementNode | B

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1370

The ancestor of b that is a child of commonAncestor

commonAncestor​

readonly commonAncestor: ElementNode

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1366

type​

readonly type: "branch"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1365


CommonAncestorResultDescendant​

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1344

Node a was a descendant of node b, and not the same node

Type Parameters​

B​

B extends ElementNode

Properties​

commonAncestor​

readonly commonAncestor: B

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1346

type​

readonly type: "descendant"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1345


CommonAncestorResultSame​

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1337

The two compared nodes are the same

Type Parameters​

A​

A extends LexicalNode

Properties​

commonAncestor​

readonly commonAncestor: A

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1339

type​

readonly type: "same"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1338


CompactSerializedEditorState​

Defined in: packages/lexical/src/LexicalEditorState.ts:49

A document written in the compact form, which omits from every node the properties parsing restores on its own. The two forms describe the same document, and both parse; this one is smaller and can only be read by a Lexical new enough to restore what it left out.

Distinct from SerializedEditorState because the shapes differ: a property the form omitted is absent, so promising the full type would promise values that are not there.

Properties​

root​

root: SerializedPartial<SerializedElementNode>

Defined in: packages/lexical/src/LexicalEditorState.ts:50


CreateEditorArgs​

Defined in: packages/lexical/src/LexicalEditor.ts:470

Properties​

disableEvents?​

optional disableEvents?: boolean

Defined in: packages/lexical/src/LexicalEditor.ts:471

dom?​

optional dom?: Partial<EditorDOMRenderConfig>

Defined in: packages/lexical/src/LexicalEditor.ts:489

editable?​

optional editable?: boolean

Defined in: packages/lexical/src/LexicalEditor.ts:486

editorState?​

optional editorState?: EditorState

Defined in: packages/lexical/src/LexicalEditor.ts:472

html?​

optional html?: HTMLConfig

Defined in: packages/lexical/src/LexicalEditor.ts:488

namespace?​

optional namespace?: string

Defined in: packages/lexical/src/LexicalEditor.ts:473

nodes?​

optional nodes?: readonly LexicalNodeConfig[]

Defined in: packages/lexical/src/LexicalEditor.ts:474

onError?​

optional onError?: ErrorHandler

Defined in: packages/lexical/src/LexicalEditor.ts:475

onWarn?​

optional onWarn?: ErrorHandler

Defined in: packages/lexical/src/LexicalEditor.ts:484

Optional handler for recoverable, warn-level conditions (e.g. the update-recursion guard tripping). Mirrors onError but is reserved for conditions the editor has already recovered from, so embedders can route them to telemetry at warn severity without raising an error alarm. Defaults to a handler that throws in development (so the condition is impossible to miss) and only console.warns in production.

parentEditor?​

optional parentEditor?: LexicalEditor

Defined in: packages/lexical/src/LexicalEditor.ts:485

theme?​

optional theme?: EditorThemeClasses

Defined in: packages/lexical/src/LexicalEditor.ts:487


DOMExportOutput​

Defined in: packages/lexical/src/LexicalNode.ts:886

Properties​

$getChildNodes?​

optional $getChildNodes?: () => Iterable<LexicalNode>

Defined in: packages/lexical/src/LexicalNode.ts:916

If defined, will be used instead of node.getChildren() to determine which children to render for this LexicalNode.

Returns​

Iterable<LexicalNode>

The children to export

after?​

optional after?: (generatedElement) => HTMLElement | Text | DocumentFragment | null | undefined

Defined in: packages/lexical/src/LexicalNode.ts:895

Called after the node and all of its children are constructed, can be used to perform any in-place updates to the node or return something else entirely.

Parameters​
generatedElement​

HTMLElement | Text | DocumentFragment | null | undefined

element after children are appended

Returns​

HTMLElement | Text | DocumentFragment | null | undefined

The final representation of this node in the exported DOM

append?​

optional append?: (element) => void

Defined in: packages/lexical/src/LexicalNode.ts:909

An optional override to change how and where DOM nodes for this ElementNode's children are appended, particularly useful if this node's children are not direct ancestors.

Parameters​
element​

HTMLElement | Text | DocumentFragment

The DOM of a child node to append

Returns​

void

element​

element: HTMLElement | Text | DocumentFragment | null

Defined in: packages/lexical/src/LexicalNode.ts:901

A DOM node for this lexical node, or null to skip it


DOMSelectionBoundaryPoints​

Defined in: packages/lexical/src/LexicalUtils.ts:2270

Experimental

A subset of Selection covering the four boundary-point fields Lexical reads plus direction. Designed so a Selection instance can be returned where a DOMSelectionBoundaryPoints is expected (see getDOMSelectionPoints).

direction is the standard Selection.direction pass-through: 'forward' / 'backward' / 'none' when the engine implements it, or undefined when a future engine ships getComposedRanges without direction (no current shipping configuration matches — every engine that ships the former also ships the latter). In the undefined case anchor/focus default to the composed StaticRange's tree order; callers needing strict backward fidelity inside a shadow root should check direction !== undefined.

Shape may change as shadow DOM support stabilizes.

Properties​

anchorNode​

anchorNode: Node | null

Defined in: packages/lexical/src/LexicalUtils.ts:2271

Experimental

anchorOffset​

anchorOffset: number

Defined in: packages/lexical/src/LexicalUtils.ts:2272

Experimental

direction?​

optional direction?: "none" | "forward" | "backward"

Defined in: packages/lexical/src/LexicalUtils.ts:2273

Experimental

focusNode​

focusNode: Node | null

Defined in: packages/lexical/src/LexicalUtils.ts:2274

Experimental

focusOffset​

focusOffset: number

Defined in: packages/lexical/src/LexicalUtils.ts:2275

Experimental


DOMSlot​

Defined in: packages/lexical/src/LexicalDOMSlot.ts:121

Experimental

Base class for DOM slots — a pointer to the content-bearing element of a node's DOM, plus optional before / after boundaries marking where the lexical-managed content sits inside that element.

For ElementNode children management see ElementDOMSlot. For non-Element nodes (TextNode, LineBreakNode, DecoratorNode) the slot still supports an internal before / after so subclasses can prepend or append non-lexical siblings around the content node and the reconciler / setTextContent route the actual content through the slot.

Extended by​

Type Parameters​

T​

T extends HTMLElement = HTMLElement

Properties​

after​

readonly after: Node | null

Defined in: packages/lexical/src/LexicalDOMSlot.ts:127

Experimental

Lower boundary: the lexical-managed range starts after this node.

before​

readonly before: Node | null

Defined in: packages/lexical/src/LexicalDOMSlot.ts:125

Experimental

Upper boundary: the lexical-managed range ends before this node.

element​

readonly element: T

Defined in: packages/lexical/src/LexicalDOMSlot.ts:123

Experimental

The content-bearing element of the node's DOM.

Methods​

getFirstChild()​

getFirstChild(): ChildNode | null

Defined in: packages/lexical/src/LexicalDOMSlot.ts:197

Experimental

Returns the first managed child (the first node in this.element that is not a non-lexical prelude / decoration), or null if there is none. Subclasses may override to also skip reconciler-managed scaffolding such as the managed line break.

Returns​

ChildNode | null

insertChild()​

insertChild(dom): this

Defined in: packages/lexical/src/LexicalDOMSlot.ts:160

Experimental

Insert the given node before this.before (if defined) or append it to this.element otherwise. Subclasses may override to respect additional boundaries (e.g. ElementDOMSlot also keeps the managed line break at the end).

Parameters​
dom​

Node

Returns​

this

removeChild()​

removeChild(dom): this

Defined in: packages/lexical/src/LexicalDOMSlot.ts:172

Experimental

Remove the given child from this.element. Throws if it was not a child.

Parameters​
dom​

Node

Returns​

this

replaceChild()​

replaceChild(dom, prevDom): this

Defined in: packages/lexical/src/LexicalDOMSlot.ts:183

Experimental

Replace prevDom with dom. Throws if prevDom is not a child.

Parameters​
dom​

Node

prevDom​

Node

Returns​

this

withAfter()​

withAfter(after): DOMSlot<T>

Defined in: packages/lexical/src/LexicalDOMSlot.ts:142

Experimental

Return a new slot with after updated.

Parameters​
after​

Node | null | undefined

Returns​

DOMSlot<T>

withBefore()​

withBefore(before): DOMSlot<T>

Defined in: packages/lexical/src/LexicalDOMSlot.ts:138

Experimental

Return a new slot with before updated.

Parameters​
before​

Node | null | undefined

Returns​

DOMSlot<T>

withElement()​

withElement<ElementType>(element): DOMSlot<ElementType>

Defined in: packages/lexical/src/LexicalDOMSlot.ts:146

Experimental

Return a new slot with element updated.

Type Parameters​
ElementType​

ElementType extends HTMLElement

Parameters​
element​

ElementType

Returns​

DOMSlot<ElementType>


EditorConfig​

Defined in: packages/lexical/src/LexicalEditor.ts:254

Properties​

disableEvents?​

optional disableEvents?: boolean

Defined in: packages/lexical/src/LexicalEditor.ts:256

dom?​

optional dom?: EditorDOMRenderConfig

Defined in: packages/lexical/src/LexicalEditor.ts:255

namespace​

namespace: string

Defined in: packages/lexical/src/LexicalEditor.ts:257

theme​

theme: EditorThemeClasses

Defined in: packages/lexical/src/LexicalEditor.ts:258


EditorState​

Defined in: packages/lexical/src/LexicalEditorState.ts:145

Properties​

_flushSync​

_flushSync: boolean

Defined in: packages/lexical/src/LexicalEditorState.ts:148

_nodeMap​

_nodeMap: NodeMap

Defined in: packages/lexical/src/LexicalEditorState.ts:146

_parsed​

_parsed: boolean

Defined in: packages/lexical/src/LexicalEditorState.ts:153

True if this EditorState was parsed without running transforms

_readOnly​

_readOnly: boolean

Defined in: packages/lexical/src/LexicalEditorState.ts:149

_selection​

_selection: BaseSelection | null

Defined in: packages/lexical/src/LexicalEditorState.ts:147

_slotsUsed​

_slotsUsed: boolean

Defined in: packages/lexical/src/LexicalEditorState.ts:158

True if this EditorState or the LexicalEditor that created it has ever used slots

Methods​

clone()​

clone(selection?): EditorState

Defined in: packages/lexical/src/LexicalEditorState.ts:189

Parameters​
selection?​

BaseSelection | null

Returns​

EditorState

isEmpty()​

isEmpty(): boolean

Defined in: packages/lexical/src/LexicalEditorState.ts:173

Returns​

boolean

read()​

read<V>(callbackFn, options?): V

Defined in: packages/lexical/src/LexicalEditorState.ts:181

Type Parameters​
V​

V

Parameters​
callbackFn​

() => V

options?​

EditorStateReadOptions

Returns​

V

toJSON()​
Call Signature​

toJSON(compact?): SerializedEditorState

Defined in: packages/lexical/src/LexicalEditorState.ts:218

This document's JSON, in the legacy form that writes every property.

The form is this call's to state, never inherited: called with no argument — including by JSON.stringify, for which this is the toJSON hook — it writes the legacy form whatever $withCompactExport encloses it. That is what makes this signature true, and it is the behavior that predates the compact form.

A nested editor still follows the document containing it, because LexicalEditor.toJSON passes the enclosing form on explicitly rather than leaving it to be picked up here.

Parameters​
compact?​

false

Returns​

SerializedEditorState

Call Signature​

toJSON(compact): CompactSerializedEditorState

Defined in: packages/lexical/src/LexicalEditorState.ts:225

Parameters​
compact​

boolean

Write the compact form, which omits from every node the properties parsing restores on its own. Passing the form here rather than through an enclosing $withCompactExport is what lets the return type say which shape it is.

Returns​

CompactSerializedEditorState


EditorStateReadOptions​

Defined in: packages/lexical/src/LexicalEditorState.ts:134

Properties​

editor?​

optional editor?: LexicalEditor | null

Defined in: packages/lexical/src/LexicalEditorState.ts:135


EditorThemeClasses​

Defined in: packages/lexical/src/LexicalEditor.ts:183

Indexable​

[key: string]: any

Properties​

blockCursor?​

optional blockCursor?: string

Defined in: packages/lexical/src/LexicalEditor.ts:184

characterLimit?​

optional characterLimit?: string

Defined in: packages/lexical/src/LexicalEditor.ts:185

code?​

optional code?: string

Defined in: packages/lexical/src/LexicalEditor.ts:186

codeHighlight?​

optional codeHighlight?: Record<string, string>

Defined in: packages/lexical/src/LexicalEditor.ts:187

collaboration?​

optional collaboration?: object

Defined in: packages/lexical/src/LexicalEditor.ts:239

cursor?​

optional cursor?: string

cursorName?​

optional cursorName?: string

selection?​

optional selection?: string

selectionBg?​

optional selectionBg?: string

embedBlock?​

optional embedBlock?: object

Defined in: packages/lexical/src/LexicalEditor.ts:245

base?​

optional base?: string

focus?​

optional focus?: string

hashtag?​

optional hashtag?: string

Defined in: packages/lexical/src/LexicalEditor.ts:188

heading?​

optional heading?: object

Defined in: packages/lexical/src/LexicalEditor.ts:190

h1?​

optional h1?: string

h2?​

optional h2?: string

h3?​

optional h3?: string

h4?​

optional h4?: string

h5?​

optional h5?: string

h6?​

optional h6?: string

hr?​

optional hr?: string

Defined in: packages/lexical/src/LexicalEditor.ts:198

hrSelected?​

optional hrSelected?: string

Defined in: packages/lexical/src/LexicalEditor.ts:199

image?​

optional image?: string

Defined in: packages/lexical/src/LexicalEditor.ts:200

indent?​

optional indent?: string

Defined in: packages/lexical/src/LexicalEditor.ts:249

optional link?: string

Defined in: packages/lexical/src/LexicalEditor.ts:201

list?​

optional list?: object

Defined in: packages/lexical/src/LexicalEditor.ts:202

checklist?​

optional checklist?: string

listitem?​

optional listitem?: string

listitemChecked?​

optional listitemChecked?: string

listitemUnchecked?​

optional listitemUnchecked?: string

nested?​

optional nested?: object

nested.list?​

optional list?: string

nested.listitem?​

optional listitem?: string

ol?​

optional ol?: string

olDepth?​

optional olDepth?: string[]

ul?​

optional ul?: string

ulDepth?​

optional ulDepth?: string[]

ltr?​

optional ltr?: string

Defined in: packages/lexical/src/LexicalEditor.ts:216

mark?​

optional mark?: string

Defined in: packages/lexical/src/LexicalEditor.ts:217

markOverlap?​

optional markOverlap?: string

Defined in: packages/lexical/src/LexicalEditor.ts:218

paragraph?​

optional paragraph?: string

Defined in: packages/lexical/src/LexicalEditor.ts:219

quote?​

optional quote?: string

Defined in: packages/lexical/src/LexicalEditor.ts:220

root?​

optional root?: string

Defined in: packages/lexical/src/LexicalEditor.ts:221

rtl?​

optional rtl?: string

Defined in: packages/lexical/src/LexicalEditor.ts:222

specialText?​

optional specialText?: string

Defined in: packages/lexical/src/LexicalEditor.ts:189

tab?​

optional tab?: string

Defined in: packages/lexical/src/LexicalEditor.ts:223

table?​

optional table?: string

Defined in: packages/lexical/src/LexicalEditor.ts:224

tableAddColumns?​

optional tableAddColumns?: string

Defined in: packages/lexical/src/LexicalEditor.ts:225

tableAddRows?​

optional tableAddRows?: string

Defined in: packages/lexical/src/LexicalEditor.ts:226

tableCell?​

optional tableCell?: string

Defined in: packages/lexical/src/LexicalEditor.ts:230

tableCellActionButton?​

optional tableCellActionButton?: string

Defined in: packages/lexical/src/LexicalEditor.ts:227

tableCellActionButtonContainer?​

optional tableCellActionButtonContainer?: string

Defined in: packages/lexical/src/LexicalEditor.ts:228

tableCellHeader?​

optional tableCellHeader?: string

Defined in: packages/lexical/src/LexicalEditor.ts:231

tableCellResizer?​

optional tableCellResizer?: string

Defined in: packages/lexical/src/LexicalEditor.ts:232

tableCellSelected?​

optional tableCellSelected?: string

Defined in: packages/lexical/src/LexicalEditor.ts:229

tableRow?​

optional tableRow?: string

Defined in: packages/lexical/src/LexicalEditor.ts:233

tableScrollableWrapper?​

optional tableScrollableWrapper?: string

Defined in: packages/lexical/src/LexicalEditor.ts:234

tableSelected?​

optional tableSelected?: string

Defined in: packages/lexical/src/LexicalEditor.ts:235

tableSelection?​

optional tableSelection?: string

Defined in: packages/lexical/src/LexicalEditor.ts:236

tableStickyScrollbar?​

optional tableStickyScrollbar?: string

Defined in: packages/lexical/src/LexicalEditor.ts:237

text?​

optional text?: TextNodeThemeClasses

Defined in: packages/lexical/src/LexicalEditor.ts:238


ElementDOMSlot​

Defined in: packages/lexical/src/LexicalDOMSlot.ts:301

A utility class for managing the DOM children of an ElementNode.

Extends DOMSlot with ElementNode-specific scaffolding — the reconciler-managed line break that keeps empty elements selectable, and the offset / index resolution helpers needed when mapping DOM selections onto lexical positions. The base before / after boundaries and the children mutation helpers (insertChild, removeChild, …) live on DOMSlot.

Extends​

Type Parameters​

T​

T extends HTMLElement = HTMLElement

Properties​

after​

readonly after: Node | null

Defined in: packages/lexical/src/LexicalDOMSlot.ts:127

Lower boundary: the lexical-managed range starts after this node.

Inherited from​

DOMSlot.after

before​

readonly before: Node | null

Defined in: packages/lexical/src/LexicalDOMSlot.ts:125

Upper boundary: the lexical-managed range ends before this node.

Inherited from​

DOMSlot.before

element​

readonly element: T

Defined in: packages/lexical/src/LexicalDOMSlot.ts:123

The content-bearing element of the node's DOM.

Inherited from​

DOMSlot.element

Methods​

getFirstChild()​

getFirstChild(): ChildNode | null

Defined in: packages/lexical/src/LexicalDOMSlot.ts:197

Returns the first managed child (the first node in this.element that is not a non-lexical prelude / decoration), or null if there is none. Subclasses may override to also skip reconciler-managed scaffolding such as the managed line break.

Returns​

ChildNode | null

Inherited from​

DOMSlot.getFirstChild

insertChild()​

insertChild(dom): this

Defined in: packages/lexical/src/LexicalDOMSlot.ts:160

Insert the given node before this.before (if defined) or append it to this.element otherwise. Subclasses may override to respect additional boundaries (e.g. ElementDOMSlot also keeps the managed line break at the end).

Parameters​
dom​

Node

Returns​

this

Inherited from​

DOMSlot.insertChild

removeChild()​

removeChild(dom): this

Defined in: packages/lexical/src/LexicalDOMSlot.ts:172

Remove the given child from this.element. Throws if it was not a child.

Parameters​
dom​

Node

Returns​

this

Inherited from​

DOMSlot.removeChild

replaceChild()​

replaceChild(dom, prevDom): this

Defined in: packages/lexical/src/LexicalDOMSlot.ts:183

Replace prevDom with dom. Throws if prevDom is not a child.

Parameters​
dom​

Node

prevDom​

Node

Returns​

this

Inherited from​

DOMSlot.replaceChild

withAfter()​

withAfter(after): ElementDOMSlot<T>

Defined in: packages/lexical/src/LexicalDOMSlot.ts:309

Return a new slot with after updated, preserving subclass type.

Parameters​
after​

Node | null | undefined

Returns​

ElementDOMSlot<T>

Overrides​

DOMSlot.withAfter

withBefore()​

withBefore(before): ElementDOMSlot<T>

Defined in: packages/lexical/src/LexicalDOMSlot.ts:305

Return a new slot with before updated, preserving subclass type.

Parameters​
before​

Node | null | undefined

Returns​

ElementDOMSlot<T>

Overrides​

DOMSlot.withBefore

withElement()​

withElement<ElementType>(element): ElementDOMSlot<ElementType>

Defined in: packages/lexical/src/LexicalDOMSlot.ts:313

Return a new slot with element updated, preserving subclass type.

Type Parameters​
ElementType​

ElementType extends HTMLElement

Parameters​
element​

ElementType

Returns​

ElementDOMSlot<ElementType>

Overrides​

DOMSlot.withElement


ExtensionBuildState​

Defined in: packages/lexical/src/extension-core/types.ts:103

Extends​

Extended by​

Type Parameters​

Init​

Init

Properties​

getDependency​

getDependency: <Dependency>(dep) => LexicalExtensionDependency<Dependency>

Defined in: packages/lexical/src/extension-core/types.ts:118

Get the configuration of a dependency by extension (must be a direct dependency of this extension)

Type Parameters​
Dependency​

Dependency extends AnyLexicalExtension

Parameters​
dep​

Dependency

Returns​

LexicalExtensionDependency<Dependency>

getDirectDependentNames​

getDirectDependentNames: () => ReadonlySet<string>

Defined in: packages/lexical/src/extension-core/types.ts:94

Get the names of any direct dependents of this Extension, typically only used for error messages.

Returns​

ReadonlySet<string>

Inherited from​

ExtensionInitState.getDirectDependentNames

getInitResult​

getInitResult: () => Init

Defined in: packages/lexical/src/extension-core/types.ts:124

The result of the init function

Returns​

Init

getPeer​

getPeer: <Dependency>(name) => LexicalExtensionDependency<Dependency> | undefined

Defined in: packages/lexical/src/extension-core/types.ts:111

Get the result of a peerDependency by name, if it exists (must be a peerDependency of this extension)

Type Parameters​
Dependency​

Dependency extends AnyLexicalExtension = never

Parameters​
name​

Dependency["name"]

Returns​

LexicalExtensionDependency<Dependency> | undefined

getPeerNameSet​

getPeerNameSet: () => ReadonlySet<string>

Defined in: packages/lexical/src/extension-core/types.ts:100

Get the names of all peer dependencies of this Extension, even if they do not exist in the builder, typically only used for devtools.

Returns​

ReadonlySet<string>

Inherited from​

ExtensionInitState.getPeerNameSet


ExtensionInitState​

Defined in: packages/lexical/src/extension-core/types.ts:73

An object that the init method can use to access the configuration for extension dependencies

Properties​

getDependency​

getDependency: <Dependency>(dep) => Omit<LexicalExtensionDependency<Dependency>, "output" | "init">

Defined in: packages/lexical/src/extension-core/types.ts:87

Get the configuration of a dependency by extension (must be a direct dependency of this extension)

Type Parameters​
Dependency​

Dependency extends AnyLexicalExtension

Parameters​
dep​

Dependency

Returns​

Omit<LexicalExtensionDependency<Dependency>, "output" | "init">

getDirectDependentNames​

getDirectDependentNames: () => ReadonlySet<string>

Defined in: packages/lexical/src/extension-core/types.ts:94

Get the names of any direct dependents of this Extension, typically only used for error messages.

Returns​

ReadonlySet<string>

getPeer​

getPeer: <Dependency>(name) => Omit<LexicalExtensionDependency<Dependency>, "output" | "init"> | undefined

Defined in: packages/lexical/src/extension-core/types.ts:78

Get the result of a peerDependency by name, if it exists (must be a peerDependency of this extension)

Type Parameters​
Dependency​

Dependency extends AnyLexicalExtension = never

Parameters​
name​

Dependency["name"]

Returns​

Omit<LexicalExtensionDependency<Dependency>, "output" | "init"> | undefined

getPeerNameSet​

getPeerNameSet: () => ReadonlySet<string>

Defined in: packages/lexical/src/extension-core/types.ts:100

Get the names of all peer dependencies of this Extension, even if they do not exist in the builder, typically only used for devtools.

Returns​

ReadonlySet<string>


ExtensionRegisterState​

Defined in: packages/lexical/src/extension-core/types.ts:131

An object that the register method can use to detect unmount and access the configuration for extension dependencies

Extends​

Type Parameters​

Init​

Init

Output​

Output

Properties​

getDependency​

getDependency: <Dependency>(dep) => LexicalExtensionDependency<Dependency>

Defined in: packages/lexical/src/extension-core/types.ts:118

Get the configuration of a dependency by extension (must be a direct dependency of this extension)

Type Parameters​
Dependency​

Dependency extends AnyLexicalExtension

Parameters​
dep​

Dependency

Returns​

LexicalExtensionDependency<Dependency>

Inherited from​

ExtensionBuildState.getDependency

getDirectDependentNames​

getDirectDependentNames: () => ReadonlySet<string>

Defined in: packages/lexical/src/extension-core/types.ts:94

Get the names of any direct dependents of this Extension, typically only used for error messages.

Returns​

ReadonlySet<string>

Inherited from​

ExtensionInitState.getDirectDependentNames

getInitResult​

getInitResult: () => Init

Defined in: packages/lexical/src/extension-core/types.ts:124

The result of the init function

Returns​

Init

Inherited from​

ExtensionBuildState.getInitResult

getOutput​

getOutput: () => Output

Defined in: packages/lexical/src/extension-core/types.ts:140

The result of the output function

Returns​

Output

getPeer​

getPeer: <Dependency>(name) => LexicalExtensionDependency<Dependency> | undefined

Defined in: packages/lexical/src/extension-core/types.ts:111

Get the result of a peerDependency by name, if it exists (must be a peerDependency of this extension)

Type Parameters​
Dependency​

Dependency extends AnyLexicalExtension = never

Parameters​
name​

Dependency["name"]

Returns​

LexicalExtensionDependency<Dependency> | undefined

Inherited from​

ExtensionBuildState.getPeer

getPeerNameSet​

getPeerNameSet: () => ReadonlySet<string>

Defined in: packages/lexical/src/extension-core/types.ts:100

Get the names of all peer dependencies of this Extension, even if they do not exist in the builder, typically only used for devtools.

Returns​

ReadonlySet<string>

Inherited from​

ExtensionInitState.getPeerNameSet

getSignal​

getSignal: () => AbortSignal

Defined in: packages/lexical/src/extension-core/types.ts:136

An AbortSignal that is aborted when this LexicalEditor registration is disposed

Returns​

AbortSignal


FieldOptions​

Defined in: packages/lexical/src/LexicalSchema.ts:418

Both directions of a property that is a node field, as withField takes them: the field name, the two value tables (each used by the one direction it names), and the accessor each direction stands in for.

Properties​

field​

readonly field: string

Defined in: packages/lexical/src/LexicalSchema.ts:419

getter?​

readonly optional getter?: string

Defined in: packages/lexical/src/LexicalSchema.ts:425

The getter this field read stands in for; see SchemaFieldBase.method.

getterTable?​

readonly optional getterTable?: object

Defined in: packages/lexical/src/LexicalSchema.ts:421

Index Signature​

[key: string]: unknown

See​

SchemaGetterField.getterTable

setter?​

readonly optional setter?: string

Defined in: packages/lexical/src/LexicalSchema.ts:427

The setter this field write stands in for; see SchemaFieldBase.method.

setterTable?​

readonly optional setterTable?: object

Defined in: packages/lexical/src/LexicalSchema.ts:423

Index Signature​

[key: string]: unknown

See​

SchemaSetterField.setterTable

when?​

readonly optional when?: string

Defined in: packages/lexical/src/LexicalSchema.ts:434

The predicate gating the export direction; see SchemaGetterField.when. Like getterTable, it belongs to one direction only — the import direction has nothing to gate, since a property that was not written is simply absent.


InitialEditorConfig​

Defined in: packages/lexical/src/extension-core/types.ts:364

Extended by​

Properties​

$initialEditorState?​

optional $initialEditorState?: InitialEditorStateType

Defined in: packages/lexical/src/extension-core/types.ts:431

The initial EditorState as a JSON string, an EditorState, or a function to update the editor (once).

editable?​

optional editable?: boolean

Defined in: packages/lexical/src/extension-core/types.ts:406

Whether the initial state of the editor is editable or not

html?​

optional html?: HTMLConfig

Defined in: packages/lexical/src/extension-core/types.ts:402

Overrides for HTML serialization (exportDOM) and deserialization (importDOM) that does not require subclassing and node replacement

namespace?​

optional namespace?: string

Defined in: packages/lexical/src/extension-core/types.ts:382

The namespace of this Editor. If two editors share the same namespace, JSON will be the clipboard interchange format. Otherwise HTML will be used.

nodes?​

optional nodes?: readonly LexicalNodeConfig[] | (() => readonly LexicalNodeConfig[] | undefined)

Defined in: packages/lexical/src/extension-core/types.ts:392

The nodes that this Extension adds to the Editor configuration, will be merged with other Extensions.

Can be a function to defer the access of the nodes to editor construction which may be useful in cases when the node and extension are defined in different modules and have depenendencies on each other, depending on the bundler configuration.

onError?​

optional onError?: (error, editor) => void

Defined in: packages/lexical/src/extension-core/types.ts:415

The editor will catch errors that happen during updates and reconciliation and call this. It defaults to (error) => { throw error }.

Parameters​
error​

Error

The Error object

editor​

LexicalEditor

The editor that this error came from

Returns​

void

onWarn?​

optional onWarn?: (error, editor) => void

Defined in: packages/lexical/src/extension-core/types.ts:426

Optional handler for recoverable, warn-level conditions (e.g. the update-recursion guard tripping) that the editor has already recovered from. Mirrors onError but at warn severity, so embedders can route the condition to telemetry without raising an error alarm. Defaults to a handler that throws in development and only console.warns in production.

Parameters​
error​

Error

The Error object describing the recovered condition

editor​

LexicalEditor

The editor that this warning came from

Returns​

void

parentEditor?​

optional parentEditor?: LexicalEditor

Defined in: packages/lexical/src/extension-core/types.ts:376

Used when this editor is nested inside of another editor

theme?​

optional theme?: EditorThemeClasses

Defined in: packages/lexical/src/extension-core/types.ts:396

EditorThemeClasses that will be deep merged with other Extensions


InlineFormattableNode​

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:365

Methods​

getFormat()​

getFormat(): number

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:368

Returns​

number

getFormatFlags()​

getFormatFlags(type, alignWithFormat): number

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:369

Parameters​
type​

TextFormatType

alignWithFormat​

number | null

Returns​

number

hasFormat()​

hasFormat(type): boolean

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:370

Parameters​
type​

TextFormatType

Returns​

boolean

setFormat()​

setFormat(format): unknown

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:371

Parameters​
format​

number

Returns​

unknown

toggleFormat()​

toggleFormat(type): unknown

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:372

Parameters​
type​

TextFormatType

Returns​

unknown


KeyboardShortcut​

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:61

Experimental

A keyboard shortcut is pure data: the key and modifiers to match, and the command to dispatch (with the matched KeyboardEvent as its payload) when it does. Keeping the action to a command keeps the mapping declarative — a shortcut table can be rendered as a menu (see formatKeyboardShortcut in @lexical/extension), remapped, or serialized, and the behavior lives in command listeners where any other UI can share it.

Extends​

Properties​

$disabled?​

optional $disabled?: (selection, editor) => boolean

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:86

Experimental

Called with the current selection before the command is dispatched; returning true skips this shortcut (falling through to any other shortcut on the same key and modifiers). Menu builders may use the same predicate to render an item as disabled.

Parameters​
selection​

BaseSelection | null

The current editor selection, or null if none exists.

editor​

LexicalEditor

The editor where KEY_DOWN_COMMAND originated (may differ from the registration editor in nested-editor setups).

Returns​

boolean

true to skip this shortcut, false to allow it.

$dispatch?​

optional $dispatch?: (command, event, $next, editor) => boolean

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:105

Experimental

Optional middleware around the command dispatch, for shortcuts that must run additional code (e.g. setting some state) without defining a wrapper command. It is responsible for calling $next() — which dispatches the command on the originating editor — and returning whether the event was handled (an unhandled event falls through to any other shortcut on the same key and modifiers).

Parameters​
command​

LexicalCommand<KeyboardEvent>

The shortcut's command.

event​

KeyboardEvent

The matched KeyboardEvent.

$next​

() => boolean

Dispatches the shortcut's command on the originating editor and returns whether the dispatch was handled.

editor​

LexicalEditor

The editor where KEY_DOWN_COMMAND originated (may differ from the registration editor in nested-editor setups).

Returns​

boolean

bubbleFromNestedEditors?​

optional bubbleFromNestedEditors?: boolean

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:122

Experimental

By default, shortcut keypresses that originate in nested editors but were not handled by that editor are ignored. Set to true when you want matching events to bubble up to this handler.

This only has an effect when the shortcut listener is registered at a priority above COMMAND_PRIORITY_EDITOR: the nested editor registers the core key-down handler at that priority and it always reports the event as handled, which ends the dispatch before it reaches the outer editor's editor-priority queue.

command​

command: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:69

Experimental

The command dispatched with the matched KeyboardEvent as its payload. The event is considered handled when the dispatch is handled; an unhandled dispatch falls through to any other shortcut on the same key and modifiers. Listeners are responsible for calling event.preventDefault() if the default action must be suppressed.

description?​

optional description?: string

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:74

Experimental

A human readable description of what the shortcut does, for building menus or help dialogs from a shortcut table

key​

key: string

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:36

Experimental

The KeyboardEvent.key to match, case-insensitive (e.g. 'b', '1', 'Enter', 'ArrowLeft')

Inherited from​

KeyboardShortcutMatch.key

modifiers?​

optional modifiers?: KeyboardEventModifierMask

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:42

Experimental

The expected state of the modifier keys. A modifier that is omitted or false must not be pressed, true must be pressed, and 'any' is ignored. The default of {} matches only events with no modifiers.

Inherited from​

KeyboardShortcutMatch.modifiers

unshiftedKey?​

optional unshiftedKey?: string

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:47

Experimental

The unshifted key to display to the user, only relevant when the shift modifier is true on non-Apple environments.

Inherited from​

KeyboardShortcutMatch.unshiftedKey


KeyboardShortcutMatch​

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:31

Experimental

The data that describes which keyboard events a shortcut matches: an event.key value (case-insensitive) plus a KeyboardEventModifierMask. The matching semantics are identical to isExactShortcutMatch, including the event.code fallback for single-character keys on non-Latin keyboard layouts.

Extended by​

Properties​

key​

key: string

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:36

Experimental

The KeyboardEvent.key to match, case-insensitive (e.g. 'b', '1', 'Enter', 'ArrowLeft')

modifiers?​

optional modifiers?: KeyboardEventModifierMask

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:42

Experimental

The expected state of the modifier keys. A modifier that is omitted or false must not be pressed, true must be pressed, and 'any' is ignored. The default of {} matches only events with no modifiers.

unshiftedKey?​

optional unshiftedKey?: string

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:47

Experimental

The unshifted key to display to the user, only relevant when the shift modifier is true on non-Apple environments.


LexicalCommand​

Defined in: packages/lexical/src/LexicalEditor.ts:694

Type Parameters​

TPayload​

TPayload

Properties​

[LexicalCommandBrand]?​

readonly optional [LexicalCommandBrand]?: (payload) => TPayload

Defined in: packages/lexical/src/LexicalEditor.ts:697

Parameters​
payload​

TPayload

Returns​

TPayload

type?​

optional type?: string

Defined in: packages/lexical/src/LexicalEditor.ts:695


LexicalEditor​

Defined in: packages/lexical/src/LexicalEditor.ts:1129

Extended by​

Methods​

blur()​

blur(): void

Defined in: packages/lexical/src/LexicalEditor.ts:1957

Removes focus from the editor.

Returns​

void

dispatchCommand()​

dispatchCommand<TCommand>(type, ...args): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1618

Dispatches a command of the specified type with the specified payload. This triggers all command listeners (set by LexicalEditor.registerCommand) for this type, passing them the provided payload. The command listeners will be triggered in an implicit LexicalEditor.update, unless this was invoked from inside an update in which case that update context will be re-used (as if this was a dollar function itself).

Type Parameters​
TCommand​

TCommand extends AnyLexicalCommand

Parameters​
type​

TCommand

the type of command listeners to trigger.

args​

...CommandPayloadArgs<CommandPayloadType<TCommand>>

Returns​

boolean

focus()​

focus(callbackFn?, options?): void

Defined in: packages/lexical/src/LexicalEditor.ts:1916

Focuses the editor by marking the existing selection as dirty, or by creating a new selection at defaultSelection if one does not already exist. If you want to force a specific selection, you should call root.selectStart() or root.selectEnd() in an update.

Parameters​
callbackFn?​

() => void

A function to run after the editor is focused.

options?​

EditorFocusOptions = {}

A bag of options

Returns​

void

getDecorators()​

getDecorators<T>(): Record<NodeKey, T>

Defined in: packages/lexical/src/LexicalEditor.ts:1629

Gets a map of all decorators in the editor.

Type Parameters​
T​

T

Returns​

Record<NodeKey, T>

A mapping of call decorator keys to their decorated content

getEditorState()​

getEditorState(): EditorState

Defined in: packages/lexical/src/LexicalEditor.ts:1740

Gets the active editor state.

Returns​

EditorState

The editor state

getElementByKey()​

getElementByKey(key): HTMLElement | null

Defined in: packages/lexical/src/LexicalEditor.ts:1732

Gets the underlying HTMLElement associated with the LexicalNode for the given key.

Parameters​
key​

string

the key of the LexicalNode.

Returns​

HTMLElement | null

the HTMLElement rendered by the LexicalNode associated with the key.

getKey()​

getKey(): string

Defined in: packages/lexical/src/LexicalEditor.ts:1647

Gets the key of the editor

Returns​

string

The editor key

getRootElement()​

getRootElement(): HTMLElement | null

Defined in: packages/lexical/src/LexicalEditor.ts:1639

Returns​

HTMLElement | null

the current root element of the editor. If you want to register an event listener, do it via LexicalEditor.registerRootListener, since this reference may not be stable.

hasNode()​

hasNode<T>(node): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1595

Used to assert that a certain node is registered, usually by plugins to ensure nodes that they depend on have been registered.

Type Parameters​
T​

T extends KlassConstructor<typeof LexicalNode>

Parameters​
node​

T

Returns​

boolean

True if the editor has registered the provided node type, false otherwise.

hasNodes()​

hasNodes<T>(nodes): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1604

Used to assert that certain nodes are registered, usually by plugins to ensure nodes that they depend on have been registered.

Type Parameters​
T​

T extends KlassConstructor<typeof LexicalNode>

Parameters​
nodes​

T[]

Returns​

boolean

True if the editor has registered all of the provided node types, false otherwise.

isComposing()​

isComposing(): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1294

Returns​

boolean

true if the editor is currently in "composition" mode due to receiving input through an IME, or 3P extension, for example. Returns false otherwise.

isEditable()​

isEditable(): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1974

Returns true if the editor is editable, false otherwise.

Returns​

boolean

True if the editor is editable, false otherwise.

parseEditorState()​

parseEditorState(maybeStringifiedEditorState, updateFn?): EditorState

Defined in: packages/lexical/src/LexicalEditor.ts:1846

Parses a SerializedEditorState (usually produced by EditorState.toJSON) and returns and EditorState object that can be, for example, passed to LexicalEditor.setEditorState. Typically, deserialization from JSON stored in a database uses this method.

Either form is accepted: parsing restores what a compact document omitted, which is the whole reason it may omit it, so CompactSerializedEditorState — what toJSON(true) returns — goes back in without a cast. So does a document assembled from serialized nodes (ParsableSerializedEditorState), such as @lexical/clipboard's.

Parameters​
maybeStringifiedEditorState​

string | SerializedEditorState | CompactSerializedEditorState | ParsableSerializedEditorState

updateFn?​

() => void

Returns​

EditorState

read()​
Call Signature​

read<T>(callbackFn): T

Defined in: packages/lexical/src/LexicalEditor.ts:1874

Executes a read of the editor's state, with the editor context available (useful for exporting and read-only DOM operations). Much like update, but prevents any mutation of the editor's state.

When called with a single argument the mode defaults to 'force-commit', which flushes any pending updates immediately before the read so it always observes a fully committed and reconciled state. See EditorReadMode for the behavior of the other modes ('pending' and 'latest').

Type Parameters​
T​

T

Parameters​
callbackFn​

() => T

A function that has access to read-only editor state.

Returns​

T

Call Signature​

read<T>(mode, callbackFn): T

Defined in: packages/lexical/src/LexicalEditor.ts:1881

Executes a read of the editor's state in the given mode, with the editor context available. See EditorReadMode for the available modes.

Type Parameters​
T​

T

Parameters​
mode​

EditorReadMode

Which editor state to read and whether to flush first.

callbackFn​

() => T

A function that has access to read-only editor state.

Returns​

T

registerCommand()​

registerCommand<P>(command, listener, priority): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1392

Registers a listener that will trigger anytime the provided command is dispatched with LexicalEditor.dispatch, subject to priority. Listeners that run at a higher priority can "intercept" commands and prevent them from propagating to other handlers by returning true.

Listeners are always invoked in an LexicalEditor.update and can call dollar functions.

Listeners registered at the same priority level will run deterministically in the order of registration.

Type Parameters​
P​

P

Parameters​
command​

LexicalCommand<P>

the command that will trigger the callback.

listener​

CommandListener<P>

the function that will execute when the command is dispatched.

priority​

CommandListenerPriority | CommandListenerPriorityBefore

the relative priority of the listener. 0 | 1 | 2 | 3 | 4 (or COMMAND_PRIORITY_EDITOR | COMMAND_PRIORITY_LOW | COMMAND_PRIORITY_NORMAL | COMMAND_PRIORITY_HIGH | COMMAND_PRIORITY_CRITICAL)

Returns​

a teardown function that can be used to cleanup the listener.

() => void

registerDecoratorListener()​

registerDecoratorListener<T>(listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1329

Registers a listener for when the editor's decorator object changes. The decorator object contains all DecoratorNode keys -> their decorated value. This is primarily used with external UI frameworks.

Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.

Type Parameters​
T​

T

Parameters​
listener​

DecoratorListener<T>

Returns​

a teardown function that can be used to cleanup the listener.

() => void

registerEditableListener()​

registerEditableListener(listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1317

Registers a listener for when the editor changes between editable and non-editable states. Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.

If the listener returns a function, that function will be called before the next transition or teardown.

Parameters​
listener​

EditableListener

Returns​

a teardown function that can be used to cleanup the listener.

() => void

registerMutationListener()​

registerMutationListener(klass, listener, options?): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1460

Registers a listener that will run when a Lexical node of the provided class is mutated. The listener will receive a list of nodes along with the type of mutation that was performed on each: created, destroyed, or updated.

One common use case for this is to attach DOM event listeners to the underlying DOM nodes as Lexical nodes are created. LexicalEditor.getElementByKey can be used for this.

If any existing nodes are in the DOM, and skipInitialization is not true, the listener will be called immediately with an updateTag of 'registerMutationListener' where all nodes have the 'created' NodeMutation. This can be controlled with the skipInitialization option (whose default was previously true for backwards compatibility with <=0.16.1 but has been changed to false as of 0.21.0).

Parameters​
klass​

KlassConstructor<typeof LexicalNode>

The class of the node that you want to listen to mutations on.

listener​

MutationListener

The logic you want to run when the node is mutated.

options?​

MutationListenerOptions

see MutationListenerOptions

Returns​

a teardown function that can be used to cleanup the listener.

() => void

registerNodeTransform()​

registerNodeTransform<T>(klass, listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1563

Registers a listener that will run when a Lexical node of the provided class is marked dirty during an update. The listener will continue to run as long as the node is marked dirty. There are no guarantees around the order of transform execution!

Watch out for infinite loops. See Node Transforms

Type Parameters​
T​

T extends LexicalNode

Parameters​
klass​

Klass<T>

The class of the node that you want to run transforms on.

listener​

Transform<T>

The logic you want to run when the node is updated.

Returns​

a teardown function that can be used to cleanup the listener.

() => void

registerRootListener()​

registerRootListener(listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1359

Registers a listener for when the editor's root DOM element (the content editable Lexical attaches to) changes. This is primarily used to attach event listeners to the root element. The root listener function is executed directly upon registration and then on any subsequent update.

Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.

If the listener returns a function, that function will be called before the next transition or teardown.

Parameters​
listener​

RootListener

Returns​

a teardown function that can be used to cleanup the listener.

() => void

registerTextContentListener()​

registerTextContentListener(listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1342

Registers a listener for when Lexical commits an update to the DOM and the text content of the editor changes from the previous state of the editor. If the text content is the same between updates, no notifications to the listeners will happen.

Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.

Parameters​
listener​

TextContentListener

Returns​

a teardown function that can be used to cleanup the listener.

() => void

registerUpdateListener()​

registerUpdateListener(listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1304

Registers a listener for Editor update event. Will trigger the provided callback each time the editor goes through an update (via LexicalEditor.update) until the teardown function is called.

Parameters​
listener​

UpdateListener

Returns​

a teardown function that can be used to cleanup the listener.

() => void

setEditable()​

setEditable(editable): void

Defined in: packages/lexical/src/LexicalEditor.ts:1982

Sets the editable property of the editor. When false, the editor will not listen for user events on the underling contenteditable.

Parameters​
editable​

boolean

the value to set the editable mode to.

Returns​

void

setEditorState()​

setEditorState(editorState, options?): void

Defined in: packages/lexical/src/LexicalEditor.ts:1749

Imperatively set the EditorState. Triggers reconciliation like an update.

Parameters​
editorState​

EditorState

the state to set the editor

options?​

EditorSetOptions

options for the update.

Returns​

void

setRootElement()​

setRootElement(nextRootElement): void

Defined in: packages/lexical/src/LexicalEditor.ts:1655

Imperatively set the root contenteditable element that Lexical listens for events on.

Parameters​
nextRootElement​

HTMLElement | null

Returns​

void

toJSON()​

toJSON(): SerializedEditor

Defined in: packages/lexical/src/LexicalEditor.ts:2016

Returns a JSON-serializable javascript object NOT a JSON string. You still must call JSON.stringify (or something else) to turn the state into a string you can transfer over the wire and store in a database.

See LexicalNode.exportJSON

This editor's serialized state, in whichever form the export around it is writing — which is how a nested editor (an image caption) stays in the same form as the document containing it.

The form is passed on explicitly rather than picked up by the call below: EditorState.toJSON() with no argument always writes the legacy form, so that its return type is true of what it returns.

Returns​

SerializedEditor

A JSON-serializable javascript object

update()​

update(updateFn, options?): void

Defined in: packages/lexical/src/LexicalEditor.ts:1903

Executes an update to the editor state. The updateFn callback is the ONLY place where Lexical editor state can be safely mutated.

Parameters​
updateFn​

() => void

A function that has access to writable editor state.

options?​

EditorUpdateOptions

A bag of options to control the behavior of the update.

Returns​

void


LexicalEditorWithDispose​

Defined in: packages/lexical/src/extension-core/types.ts:343

A handle to the editor with an attached dispose function

Extends​

Properties​

dispose​

dispose: () => void

Defined in: packages/lexical/src/extension-core/types.ts:348

Dispose the editor and perform all clean-up (also available as Symbol.dispose via Disposable)

Returns​

void

Methods​

[dispose]()​

[dispose](): void

Defined in: typescript/lib/lib.esnext.disposable.d.ts:34

Returns​

void

Inherited from​

Disposable.[dispose]

blur()​

blur(): void

Defined in: packages/lexical/src/LexicalEditor.ts:1957

Removes focus from the editor.

Returns​

void

Inherited from​

LexicalEditor.blur

dispatchCommand()​

dispatchCommand<TCommand>(type, ...args): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1618

Dispatches a command of the specified type with the specified payload. This triggers all command listeners (set by LexicalEditor.registerCommand) for this type, passing them the provided payload. The command listeners will be triggered in an implicit LexicalEditor.update, unless this was invoked from inside an update in which case that update context will be re-used (as if this was a dollar function itself).

Type Parameters​
TCommand​

TCommand extends AnyLexicalCommand

Parameters​
type​

TCommand

the type of command listeners to trigger.

args​

...CommandPayloadArgs<CommandPayloadType<TCommand>>

Returns​

boolean

Inherited from​

LexicalEditor.dispatchCommand

focus()​

focus(callbackFn?, options?): void

Defined in: packages/lexical/src/LexicalEditor.ts:1916

Focuses the editor by marking the existing selection as dirty, or by creating a new selection at defaultSelection if one does not already exist. If you want to force a specific selection, you should call root.selectStart() or root.selectEnd() in an update.

Parameters​
callbackFn?​

() => void

A function to run after the editor is focused.

options?​

EditorFocusOptions = {}

A bag of options

Returns​

void

Inherited from​

LexicalEditor.focus

getDecorators()​

getDecorators<T>(): Record<NodeKey, T>

Defined in: packages/lexical/src/LexicalEditor.ts:1629

Gets a map of all decorators in the editor.

Type Parameters​
T​

T

Returns​

Record<NodeKey, T>

A mapping of call decorator keys to their decorated content

Inherited from​

LexicalEditor.getDecorators

getEditorState()​

getEditorState(): EditorState

Defined in: packages/lexical/src/LexicalEditor.ts:1740

Gets the active editor state.

Returns​

EditorState

The editor state

Inherited from​

LexicalEditor.getEditorState

getElementByKey()​

getElementByKey(key): HTMLElement | null

Defined in: packages/lexical/src/LexicalEditor.ts:1732

Gets the underlying HTMLElement associated with the LexicalNode for the given key.

Parameters​
key​

string

the key of the LexicalNode.

Returns​

HTMLElement | null

the HTMLElement rendered by the LexicalNode associated with the key.

Inherited from​

LexicalEditor.getElementByKey

getKey()​

getKey(): string

Defined in: packages/lexical/src/LexicalEditor.ts:1647

Gets the key of the editor

Returns​

string

The editor key

Inherited from​

LexicalEditor.getKey

getRootElement()​

getRootElement(): HTMLElement | null

Defined in: packages/lexical/src/LexicalEditor.ts:1639

Returns​

HTMLElement | null

the current root element of the editor. If you want to register an event listener, do it via LexicalEditor.registerRootListener, since this reference may not be stable.

Inherited from​

LexicalEditor.getRootElement

hasNode()​

hasNode<T>(node): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1595

Used to assert that a certain node is registered, usually by plugins to ensure nodes that they depend on have been registered.

Type Parameters​
T​

T extends KlassConstructor<typeof LexicalNode>

Parameters​
node​

T

Returns​

boolean

True if the editor has registered the provided node type, false otherwise.

Inherited from​

LexicalEditor.hasNode

hasNodes()​

hasNodes<T>(nodes): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1604

Used to assert that certain nodes are registered, usually by plugins to ensure nodes that they depend on have been registered.

Type Parameters​
T​

T extends KlassConstructor<typeof LexicalNode>

Parameters​
nodes​

T[]

Returns​

boolean

True if the editor has registered all of the provided node types, false otherwise.

Inherited from​

LexicalEditor.hasNodes

isComposing()​

isComposing(): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1294

Returns​

boolean

true if the editor is currently in "composition" mode due to receiving input through an IME, or 3P extension, for example. Returns false otherwise.

Inherited from​

LexicalEditor.isComposing

isEditable()​

isEditable(): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1974

Returns true if the editor is editable, false otherwise.

Returns​

boolean

True if the editor is editable, false otherwise.

Inherited from​

LexicalEditor.isEditable

parseEditorState()​

parseEditorState(maybeStringifiedEditorState, updateFn?): EditorState

Defined in: packages/lexical/src/LexicalEditor.ts:1846

Parses a SerializedEditorState (usually produced by EditorState.toJSON) and returns and EditorState object that can be, for example, passed to LexicalEditor.setEditorState. Typically, deserialization from JSON stored in a database uses this method.

Either form is accepted: parsing restores what a compact document omitted, which is the whole reason it may omit it, so CompactSerializedEditorState — what toJSON(true) returns — goes back in without a cast. So does a document assembled from serialized nodes (ParsableSerializedEditorState), such as @lexical/clipboard's.

Parameters​
maybeStringifiedEditorState​

string | SerializedEditorState | CompactSerializedEditorState | ParsableSerializedEditorState

updateFn?​

() => void

Returns​

EditorState

Inherited from​

LexicalEditor.parseEditorState

read()​
Call Signature​

read<T>(callbackFn): T

Defined in: packages/lexical/src/LexicalEditor.ts:1874

Executes a read of the editor's state, with the editor context available (useful for exporting and read-only DOM operations). Much like update, but prevents any mutation of the editor's state.

When called with a single argument the mode defaults to 'force-commit', which flushes any pending updates immediately before the read so it always observes a fully committed and reconciled state. See EditorReadMode for the behavior of the other modes ('pending' and 'latest').

Type Parameters​
T​

T

Parameters​
callbackFn​

() => T

A function that has access to read-only editor state.

Returns​

T

Inherited from​

LexicalEditor.read

Call Signature​

read<T>(mode, callbackFn): T

Defined in: packages/lexical/src/LexicalEditor.ts:1881

Executes a read of the editor's state in the given mode, with the editor context available. See EditorReadMode for the available modes.

Type Parameters​
T​

T

Parameters​
mode​

EditorReadMode

Which editor state to read and whether to flush first.

callbackFn​

() => T

A function that has access to read-only editor state.

Returns​

T

Inherited from​

LexicalEditor.read

registerCommand()​

registerCommand<P>(command, listener, priority): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1392

Registers a listener that will trigger anytime the provided command is dispatched with LexicalEditor.dispatch, subject to priority. Listeners that run at a higher priority can "intercept" commands and prevent them from propagating to other handlers by returning true.

Listeners are always invoked in an LexicalEditor.update and can call dollar functions.

Listeners registered at the same priority level will run deterministically in the order of registration.

Type Parameters​
P​

P

Parameters​
command​

LexicalCommand<P>

the command that will trigger the callback.

listener​

CommandListener<P>

the function that will execute when the command is dispatched.

priority​

CommandListenerPriority | CommandListenerPriorityBefore

the relative priority of the listener. 0 | 1 | 2 | 3 | 4 (or COMMAND_PRIORITY_EDITOR | COMMAND_PRIORITY_LOW | COMMAND_PRIORITY_NORMAL | COMMAND_PRIORITY_HIGH | COMMAND_PRIORITY_CRITICAL)

Returns​

a teardown function that can be used to cleanup the listener.

() => void

Inherited from​

LexicalEditor.registerCommand

registerDecoratorListener()​

registerDecoratorListener<T>(listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1329

Registers a listener for when the editor's decorator object changes. The decorator object contains all DecoratorNode keys -> their decorated value. This is primarily used with external UI frameworks.

Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.

Type Parameters​
T​

T

Parameters​
listener​

DecoratorListener<T>

Returns​

a teardown function that can be used to cleanup the listener.

() => void

Inherited from​

LexicalEditor.registerDecoratorListener

registerEditableListener()​

registerEditableListener(listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1317

Registers a listener for when the editor changes between editable and non-editable states. Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.

If the listener returns a function, that function will be called before the next transition or teardown.

Parameters​
listener​

EditableListener

Returns​

a teardown function that can be used to cleanup the listener.

() => void

Inherited from​

LexicalEditor.registerEditableListener

registerMutationListener()​

registerMutationListener(klass, listener, options?): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1460

Registers a listener that will run when a Lexical node of the provided class is mutated. The listener will receive a list of nodes along with the type of mutation that was performed on each: created, destroyed, or updated.

One common use case for this is to attach DOM event listeners to the underlying DOM nodes as Lexical nodes are created. LexicalEditor.getElementByKey can be used for this.

If any existing nodes are in the DOM, and skipInitialization is not true, the listener will be called immediately with an updateTag of 'registerMutationListener' where all nodes have the 'created' NodeMutation. This can be controlled with the skipInitialization option (whose default was previously true for backwards compatibility with <=0.16.1 but has been changed to false as of 0.21.0).

Parameters​
klass​

KlassConstructor<typeof LexicalNode>

The class of the node that you want to listen to mutations on.

listener​

MutationListener

The logic you want to run when the node is mutated.

options?​

MutationListenerOptions

see MutationListenerOptions

Returns​

a teardown function that can be used to cleanup the listener.

() => void

Inherited from​

LexicalEditor.registerMutationListener

registerNodeTransform()​

registerNodeTransform<T>(klass, listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1563

Registers a listener that will run when a Lexical node of the provided class is marked dirty during an update. The listener will continue to run as long as the node is marked dirty. There are no guarantees around the order of transform execution!

Watch out for infinite loops. See Node Transforms

Type Parameters​
T​

T extends LexicalNode

Parameters​
klass​

Klass<T>

The class of the node that you want to run transforms on.

listener​

Transform<T>

The logic you want to run when the node is updated.

Returns​

a teardown function that can be used to cleanup the listener.

() => void

Inherited from​

LexicalEditor.registerNodeTransform

registerRootListener()​

registerRootListener(listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1359

Registers a listener for when the editor's root DOM element (the content editable Lexical attaches to) changes. This is primarily used to attach event listeners to the root element. The root listener function is executed directly upon registration and then on any subsequent update.

Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.

If the listener returns a function, that function will be called before the next transition or teardown.

Parameters​
listener​

RootListener

Returns​

a teardown function that can be used to cleanup the listener.

() => void

Inherited from​

LexicalEditor.registerRootListener

registerTextContentListener()​

registerTextContentListener(listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1342

Registers a listener for when Lexical commits an update to the DOM and the text content of the editor changes from the previous state of the editor. If the text content is the same between updates, no notifications to the listeners will happen.

Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.

Parameters​
listener​

TextContentListener

Returns​

a teardown function that can be used to cleanup the listener.

() => void

Inherited from​

LexicalEditor.registerTextContentListener

registerUpdateListener()​

registerUpdateListener(listener): () => void

Defined in: packages/lexical/src/LexicalEditor.ts:1304

Registers a listener for Editor update event. Will trigger the provided callback each time the editor goes through an update (via LexicalEditor.update) until the teardown function is called.

Parameters​
listener​

UpdateListener

Returns​

a teardown function that can be used to cleanup the listener.

() => void

Inherited from​

LexicalEditor.registerUpdateListener

setEditable()​

setEditable(editable): void

Defined in: packages/lexical/src/LexicalEditor.ts:1982

Sets the editable property of the editor. When false, the editor will not listen for user events on the underling contenteditable.

Parameters​
editable​

boolean

the value to set the editable mode to.

Returns​

void

Inherited from​

LexicalEditor.setEditable

setEditorState()​

setEditorState(editorState, options?): void

Defined in: packages/lexical/src/LexicalEditor.ts:1749

Imperatively set the EditorState. Triggers reconciliation like an update.

Parameters​
editorState​

EditorState

the state to set the editor

options?​

EditorSetOptions

options for the update.

Returns​

void

Inherited from​

LexicalEditor.setEditorState

setRootElement()​

setRootElement(nextRootElement): void

Defined in: packages/lexical/src/LexicalEditor.ts:1655

Imperatively set the root contenteditable element that Lexical listens for events on.

Parameters​
nextRootElement​

HTMLElement | null

Returns​

void

Inherited from​

LexicalEditor.setRootElement

toJSON()​

toJSON(): SerializedEditor

Defined in: packages/lexical/src/LexicalEditor.ts:2016

Returns a JSON-serializable javascript object NOT a JSON string. You still must call JSON.stringify (or something else) to turn the state into a string you can transfer over the wire and store in a database.

See LexicalNode.exportJSON

This editor's serialized state, in whichever form the export around it is writing — which is how a nested editor (an image caption) stays in the same form as the document containing it.

The form is passed on explicitly rather than picked up by the call below: EditorState.toJSON() with no argument always writes the legacy form, so that its return type is true of what it returns.

Returns​

SerializedEditor

A JSON-serializable javascript object

Inherited from​

LexicalEditor.toJSON

update()​

update(updateFn, options?): void

Defined in: packages/lexical/src/LexicalEditor.ts:1903

Executes an update to the editor state. The updateFn callback is the ONLY place where Lexical editor state can be safely mutated.

Parameters​
updateFn​

() => void

A function that has access to writable editor state.

options?​

EditorUpdateOptions

A bag of options to control the behavior of the update.

Returns​

void

Inherited from​

LexicalEditor.update


LexicalExtension​

Defined in: packages/lexical/src/extension-core/types.ts:171

An Extension is a composable unit of LexicalEditor configuration (nodes, theme, etc) used to create an editor, plus runtime behavior that is registered after the editor is created.

An Extension may depend on other Extensions, and provide functionality to other extensions through its config.

Extends​

Type Parameters​

Config​

Config extends ExtensionConfigBase

Name​

Name extends string

Output​

Output

Init​

Init

Properties​

$initialEditorState?​

optional $initialEditorState?: InitialEditorStateType

Defined in: packages/lexical/src/extension-core/types.ts:431

The initial EditorState as a JSON string, an EditorState, or a function to update the editor (once).

Inherited from​

InitialEditorConfig.$initialEditorState

afterRegistration?​

optional afterRegistration?: (editor, config, state) => () => void

Defined in: packages/lexical/src/extension-core/types.ts:289

Run any code that must happen after initialization of the editor state (which happens after all register calls).

Parameters​
editor​

LexicalEditor

The editor this Extension is being registered with

config​

Config

The merged configuration specific to this Extension

state​

ExtensionRegisterState<Init, Output>

An object containing an AbortSignal that can be used, and methods for accessing the merged configuration of dependencies and peerDependencies

Returns​

A clean-up function

() => void

build?​

optional build?: (editor, config, state) => Output

Defined in: packages/lexical/src/extension-core/types.ts:254

Perform any tasks that require a LexicalEditor instance, but before registration has taken place. May provide output to be used by dependencies or the application (commands, components, etc.). This will only be run once, and any work performed by the output function must not require cleanup.

Parameters​
editor​

LexicalEditor

config​

Config

state​

ExtensionBuildState<Init>

Returns​

Output

config?​

optional config?: Config

Defined in: packages/lexical/src/extension-core/types.ts:204

The default configuration specific to this Extension. This Config may be seen by this Extension, or any Extension that uses it as a dependency.

The config may be mutated on register, this is particularly useful for vending functionality to other Extensions that depend on this Extension.

conflictsWith?​

optional conflictsWith?: string[]

Defined in: packages/lexical/src/extension-core/types.ts:188

Extension names that must not be loaded with this Extension. If this extension and any of the conflicting extensions are configured in the same editor then a runtime error will be thrown instead of creating the editor. This is used to prevent extensions with incompatible and overlapping functionality from being registered concurrently, such as PlainTextExtension and RichTextExtension.

dependencies?​

optional dependencies?: AnyLexicalExtensionArgument[]

Defined in: packages/lexical/src/extension-core/types.ts:190

Other Extensions that this Extension depends on, can also be used to configure them

editable?​

optional editable?: boolean

Defined in: packages/lexical/src/extension-core/types.ts:406

Whether the initial state of the editor is editable or not

Inherited from​

InitialEditorConfig.editable

html?​

optional html?: HTMLConfig

Defined in: packages/lexical/src/extension-core/types.ts:402

Overrides for HTML serialization (exportDOM) and deserialization (importDOM) that does not require subclassing and node replacement

Inherited from​

InitialEditorConfig.html

init?​

optional init?: (editorConfig, config, state) => Init

Defined in: packages/lexical/src/extension-core/types.ts:242

Perform any necessary initialization before the editor is created, this runs after all configuration overrides for both the editor this this extension have been merged. May be used validate the editor configuration.

Parameters​
editorConfig​

InitialEditorConfig

The in-progress editor configuration (mutable)

config​

Config

The merged configuration specific to this extension (mutable)

state​

ExtensionInitState

An object containing methods for accessing the merged configuration of dependencies and peerDependencies

Returns​

Init

mergeConfig?​

optional mergeConfig?: (config, overrides) => Config

Defined in: packages/lexical/src/extension-core/types.ts:230

By default, Config is shallow merged {...a, ...b} with shallowMergeConfig, if your Extension requires other strategies (such as concatenating an Array) you can implement it here.

Parameters​
config​

Config

The current configuration

overrides​

Partial<Config>

The partial configuration to merge

Returns​

Config

The merged configuration

Example​

Merging an array

const extension = defineExtension({
// ...
mergeConfig(config, overrides) {
const merged = shallowMergeConfig(config, overrides);
if (Array.isArray(overrides.decorators)) {
merged.decorators = [...config.decorators, ...overrides.decorators];
}
return merged;
}
});
name​

readonly name: Name

Defined in: packages/lexical/src/extension-core/types.ts:179

The name of the Extension, must be unique

namespace?​

optional namespace?: string

Defined in: packages/lexical/src/extension-core/types.ts:382

The namespace of this Editor. If two editors share the same namespace, JSON will be the clipboard interchange format. Otherwise HTML will be used.

Inherited from​

InitialEditorConfig.namespace

nodes?​

optional nodes?: readonly LexicalNodeConfig[] | (() => readonly LexicalNodeConfig[] | undefined)

Defined in: packages/lexical/src/extension-core/types.ts:392

The nodes that this Extension adds to the Editor configuration, will be merged with other Extensions.

Can be a function to defer the access of the nodes to editor construction which may be useful in cases when the node and extension are defined in different modules and have depenendencies on each other, depending on the bundler configuration.

Inherited from​

InitialEditorConfig.nodes

onError?​

optional onError?: (error, editor) => void

Defined in: packages/lexical/src/extension-core/types.ts:415

The editor will catch errors that happen during updates and reconciliation and call this. It defaults to (error) => { throw error }.

Parameters​
error​

Error

The Error object

editor​

LexicalEditor

The editor that this error came from

Returns​

void

Inherited from​

InitialEditorConfig.onError

onWarn?​

optional onWarn?: (error, editor) => void

Defined in: packages/lexical/src/extension-core/types.ts:426

Optional handler for recoverable, warn-level conditions (e.g. the update-recursion guard tripping) that the editor has already recovered from. Mirrors onError but at warn severity, so embedders can route the condition to telemetry without raising an error alarm. Defaults to a handler that throws in development and only console.warns in production.

Parameters​
error​

Error

The Error object describing the recovered condition

editor​

LexicalEditor

The editor that this warning came from

Returns​

void

Inherited from​

InitialEditorConfig.onWarn

parentEditor?​

optional parentEditor?: LexicalEditor

Defined in: packages/lexical/src/extension-core/types.ts:376

Used when this editor is nested inside of another editor

Inherited from​

InitialEditorConfig.parentEditor

peerDependencies?​

optional peerDependencies?: NormalizedPeerDependency<AnyLexicalExtension>[]

Defined in: packages/lexical/src/extension-core/types.ts:195

Other Extensions, by name, that this Extension can optionally depend on or configure, if they are directly depended on by another Extension

register?​

optional register?: (editor, config, state) => () => void

Defined in: packages/lexical/src/extension-core/types.ts:272

Add behavior to the editor (register transforms, listeners, etc.) after the Editor is created, but before its initial state is set. The register function may also mutate the config in-place to expose data to other extensions that use it as a dependency.

Parameters​
editor​

LexicalEditor

The editor this Extension is being registered with

config​

Config

The merged configuration specific to this Extension

state​

ExtensionRegisterState<Init, Output>

An object containing an AbortSignal that can be used, and methods for accessing the merged configuration of dependencies and peerDependencies

Returns​

A clean-up function

() => void

theme?​

optional theme?: EditorThemeClasses

Defined in: packages/lexical/src/extension-core/types.ts:396

EditorThemeClasses that will be deep merged with other Extensions

Inherited from​

InitialEditorConfig.theme


LexicalExtensionDependency​

Defined in: packages/lexical/src/extension-core/types.ts:155

Type Parameters​

Dependency​

Dependency extends AnyLexicalExtension

Properties​

config​

config: LexicalExtensionConfig<Dependency>

Defined in: packages/lexical/src/extension-core/types.ts:159

init​

init: LexicalExtensionInit<Dependency>

Defined in: packages/lexical/src/extension-core/types.ts:158

output​

output: LexicalExtensionOutput<Dependency>

Defined in: packages/lexical/src/extension-core/types.ts:160


LexicalNode​

Defined in: packages/lexical/src/LexicalNode.ts:980

Extended by​

Methods​

$config()​

$config(): BaseStaticNodeConfig

Defined in: packages/lexical/src/LexicalNode.ts:1053

Override this to implement the new static node configuration protocol, this method is called directly on the prototype and must not depend on anything initialized in the constructor. Generally it should be a trivial implementation.

Returns​

BaseStaticNodeConfig

Example​
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
afterCloneFrom()​

afterCloneFrom(prevNode): void

Defined in: packages/lexical/src/LexicalNode.ts:1139

Perform any state updates on the clone of prevNode that are not already handled by the constructor call in the static clone method. If you have state to update in your clone that is not handled directly by the constructor, it is advisable to override this method but it is required to include a call to super.afterCloneFrom(prevNode) in your implementation. This is only intended to be called by $cloneWithProperties function or via a super call.

Parameters​
prevNode​

this

Returns​

void

Example​
class ClassesTextNode extends TextNode {
// Not shown: static getType, static importJSON, exportJSON, createDOM, updateDOM
__classes = new Set<string>();
static clone(node: ClassesTextNode): ClassesTextNode {
// The inherited TextNode constructor is used here, so
// classes is not set by this method.
return new ClassesTextNode(node.__text, node.__key);
}
afterCloneFrom(node: this): void {
// This calls TextNode.afterCloneFrom and LexicalNode.afterCloneFrom
// for necessary state updates
super.afterCloneFrom(node);
this.__addClasses(node.__classes);
}
// This method is a private implementation detail, it is not
// suitable for the public API because it does not call getWritable
__addClasses(classNames: Iterable<string>): this {
for (const className of classNames) {
this.__classes.add(className);
}
return this;
}
addClass(...classNames: string[]): this {
return this.getWritable().__addClasses(classNames);
}
removeClass(...classNames: string[]): this {
const node = this.getWritable();
for (const className of classNames) {
this.__classes.delete(className);
}
return this;
}
getClasses(): Set<string> {
return this.getLatest().__classes;
}
}
config()​
Call Signature​

config<Config>(type, config): AbstractStaticNodeConfigRecord<Config>

Defined in: packages/lexical/src/LexicalNode.ts:1066

This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.

An abstract base class that has no concrete node type may pass a well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of a string type to declare configuration shared with its subclasses.

Type Parameters​
Config​

Config extends StaticNodeConfigValue<LexicalNode, string>

Parameters​
type​

symbol

config​

Config

Returns​

AbstractStaticNodeConfigRecord<Config>

Call Signature​

config<Type, Config>(type, config): StaticNodeConfigRecord<Type, Config>

Defined in: packages/lexical/src/LexicalNode.ts:1070

This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.

An abstract base class that has no concrete node type may pass a well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of a string type to declare configuration shared with its subclasses.

Type Parameters​
Type​

Type extends string

Config​

Config extends StaticNodeConfigValue<LexicalNode, Type>

Parameters​
type​

Type

config​

Config

Returns​

StaticNodeConfigRecord<Type, Config>

createDOM()​

createDOM(_config, _editor): HTMLElement

Defined in: packages/lexical/src/LexicalNode.ts:1748

Called during the reconciliation process to determine which nodes to insert into the DOM for this Lexical Node.

This method must return exactly one HTMLElement. Nested elements are not supported.

Do not attempt to update the Lexical EditorState during this phase of the update lifecycle.

Parameters​
_config​

EditorConfig

allows access to things like the EditorTheme (to apply classes) during reconciliation.

_editor​

LexicalEditor

allows access to the editor for context during reconciliation.

Returns​

HTMLElement

createParentElementNode()​

createParentElementNode(): ElementNode

Defined in: packages/lexical/src/LexicalNode.ts:2313

The creation logic for any required parent. Should be implemented if isParentRequired returns true.

Returns​

ElementNode

exportDOM()​

exportDOM(editor): DOMExportOutput

Defined in: packages/lexical/src/LexicalNode.ts:1796

Controls how the this node is serialized to HTML. This is important for copy and paste between Lexical and non-Lexical editors, or Lexical editors with different namespaces, in which case the primary transfer format is HTML. It's also important if you're serializing to HTML for any other reason via $generateHtmlFromNodes. You could also use this method to build your own HTML renderer.

Parameters​
editor​

LexicalEditor

Returns​

DOMExportOutput

exportJSON()​
Call Signature​

exportJSON(compact?): SerializedLexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:1837

Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.

The base implementation writes every property the node's schema declares (its own and those it inherits), reading each through its getter — get<Prop> by default, or the name recorded with withAccessors. A getter that returns undefined omits its property. Override this only for output a schema can not describe, and call super.exportJSON(compact) when you do.

This may serialize the instance as-is, without resolving the latest version. A property declared with withField is read straight off the node, which is the optimization the serialization walk is built on — every node the walk reaches comes from the EditorState's node map and is already current, so it resolves nothing per node.

So on a reference that a getWritable() (any set<Prop>) has since superseded, this writes pre-mutation values. Which properties do is not something to rely on: a property whose accessor a subclass overrode still goes through that accessor and resolves the latest, so one node can write a current text beside a stale style. Call node.getLatest().exportJSON() whenever you hold such a reference rather than reasoning about which properties resolve.

This is a breaking change. Every property previously went through an accessor, and every accessor resolves getLatest(), so a stale reference exported current values.

Parameters​
compact?​

false

Write the compact form: omit a property the parser derives rather than reads, one whose value is the schema default parsing would restore, and the deprecated version. The two forms describe the same document. A node that overrides this and ignores the flag simply keeps writing the full form, which still parses.

Returns​

SerializedLexicalNode

Call Signature​

exportJSON(compact): SerializedPartial<SerializedLexicalNode>

Defined in: packages/lexical/src/LexicalNode.ts:1846

The compact form omits properties, so what it returns is the partial serialized type — every node-specific property optional — rather than the full one. Passing a boolean whose value is not statically known selects this overload too, which is right: neither form can be promised then.

Parameters​
compact​

boolean

Returns​

SerializedPartial<SerializedLexicalNode>

See​

SerializedPartial

getCommonAncestor()​

getCommonAncestor<T>(node): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1507

Type Parameters​
T​

T extends ElementNode = ElementNode

Parameters​
node​

LexicalNode

the other node to find the common ancestor of.

Returns​

T | null

Deprecated​

use $getCommonAncestor

Returns the closest common ancestor of this node and the provided one or null if one cannot be found.

getDOMSlot()​

getDOMSlot(element): DOMSlot<HTMLElement>

Defined in: packages/lexical/src/LexicalNode.ts:1784

Experimental

Returns a DOMSlot pointing at the content-bearing element of this node's DOM. The default returns a slot wrapping the keyed DOM as-is.

Override this when createDOM returns a wrapper around the content-bearing element (e.g. <span><br/></span> for a styled line break), so selection / reconciliation logic can target the inner element.

ElementNode overrides this to return an ElementDOMSlot with children-management semantics (used by the reconciler to place managed children).

Parameters​
element​

HTMLElement

Returns​

DOMSlot<HTMLElement>

getIndexWithinParent()​

getIndexWithinParent(): number

Defined in: packages/lexical/src/LexicalNode.ts:1284

Returns the zero-based index of this node within the parent.

Returns​

number

getKey()​

getKey(): string

Defined in: packages/lexical/src/LexicalNode.ts:1276

Returns this nodes key.

Returns​

string

getLatest()​

getLatest(): this

Defined in: packages/lexical/src/LexicalNode.ts:1657

Returns the latest version of the node from the active EditorState. This is used to avoid getting values from stale node references.

Returns​

this

getNextSibling()​
Call Signature​

getNextSibling(): LexicalNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1463

Returns the node after this one in the same parent, or null if there is no such node.

Returns​

LexicalNode | null

Call Signature​

getNextSibling<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1470

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getNextSibling() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getNextSiblings()​
Call Signature​

getNextSiblings(): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1481

Returns all nodes after this one in the same parent, in document order.

Returns​

LexicalNode[]

Call Signature​

getNextSiblings<T>(): T[]

Defined in: packages/lexical/src/LexicalNode.ts:1488

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getNextSiblings() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

getNodesBetween()​

getNodesBetween(targetNode): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1576

Returns a list of nodes that are between this node and the target node in the EditorState.

Parameters​
targetNode​

LexicalNode

the node that marks the other end of the range of nodes to be returned.

Returns​

LexicalNode[]

getParent()​
Call Signature​

getParent(): ElementNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1304

Returns the parent of this node, or null if none is found.

Returns​

ElementNode | null

Call Signature​

getParent<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1311

Type Parameters​
T​

T extends ElementNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getParent() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getParentKeys()​

getParentKeys(): string[]

Defined in: packages/lexical/src/LexicalNode.ts:1402

Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.

Returns​

string[]

getParentOrThrow()​
Call Signature​

getParentOrThrow(): ElementNode

Defined in: packages/lexical/src/LexicalNode.ts:1324

Returns the parent of this node, or throws if none is found.

Returns​

ElementNode

Call Signature​

getParentOrThrow<T>(): T

Defined in: packages/lexical/src/LexicalNode.ts:1331

Type Parameters​
T​

T extends ElementNode

Returns​

T

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getParentOrThrow() as T, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getParents()​

getParents(): ElementNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1387

Returns a list of the every ancestor of this node, all the way up to the RootNode.

Returns​

ElementNode[]

getPreviousSibling()​
Call Signature​

getPreviousSibling(): LexicalNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1416

Returns the node before this one in the same parent, or null if there is no such node.

Returns​

LexicalNode | null

Call Signature​

getPreviousSibling<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1423

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getPreviousSibling() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

getPreviousSiblings()​
Call Signature​

getPreviousSiblings(): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1434

Returns all nodes before this one in the same parent, in document order.

Returns​

LexicalNode[]

Call Signature​

getPreviousSiblings<T>(): T[]

Defined in: packages/lexical/src/LexicalNode.ts:1441

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getPreviousSiblings() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

getTextContent()​

getTextContent(): string

Defined in: packages/lexical/src/LexicalNode.ts:1719

Returns the text content of the node. Override this for custom nodes that should have a representation in plain text format (for copy + paste, for example)

Returns​

string

getTextContentSize()​

getTextContentSize(): number

Defined in: packages/lexical/src/LexicalNode.ts:1727

Returns the length of the string produced by calling getTextContent on this node.

Returns​

number

getTopLevelElement()​

getTopLevelElement(): DecoratorNode<unknown> | ElementNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1345

Returns the highest (in the EditorState tree) non-root ancestor of this node, or null if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".

Returns​

DecoratorNode<unknown> | ElementNode | null

getTopLevelElementOrThrow()​

getTopLevelElementOrThrow(): DecoratorNode<unknown> | ElementNode

Defined in: packages/lexical/src/LexicalNode.ts:1370

Returns the highest (in the EditorState tree) non-root ancestor of this node, or throws if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".

Returns​

DecoratorNode<unknown> | ElementNode

getType()​

getType(): string

Defined in: packages/lexical/src/LexicalNode.ts:1187

Returns the string type of this node.

Returns​

string

getWritable()​

getWritable(): this

Defined in: packages/lexical/src/LexicalNode.ts:1678

Returns a mutable version of the node using $cloneWithProperties if necessary. Will throw an error if called outside of a Lexical Editor LexicalEditor.update callback.

Returns​

this

insertAfter()​

insertAfter(nodeToInsert, restoreSelection?): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:2117

Inserts a node after this LexicalNode (as the next sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert after this one.

restoreSelection?​

boolean = true

Whether or not to attempt to resolve the selection to the appropriate place after the operation is complete.

Returns​

LexicalNode

insertBefore()​

insertBefore(nodeToInsert, restoreSelection?): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:2224

Inserts a node before this LexicalNode (as the previous sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert before this one.

restoreSelection?​

boolean = true

Whether or not to attempt to resolve the selection to the appropriate place after the operation is complete.

Returns​

LexicalNode

is()​

is(object): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1524

Returns true if the provided node is the exact same one as this node, from Lexical's perspective. Always use this instead of referential equality.

Parameters​
object​

LexicalNode | null | undefined

the node to perform the equality comparison on.

Returns​

boolean

isAttached()​

isAttached(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1204

Returns true if there is a path between this node and the RootNode, false otherwise. This is a way of determining if the node is "attached" EditorState. Unattached nodes won't be reconciled and will ultimately be cleaned up by the Lexical GC.

Returns​

boolean

isBefore()​

isBefore(targetNode): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1542

Returns true if this node logically precedes the target node in the editor state, false otherwise (including if there is no common ancestor).

Note that this notion of isBefore is based on post-order; a descendant node is always before its ancestors. See also $getCommonAncestor and $comparePointCaretNext for more flexible ways to determine the relative positions of nodes.

Parameters​
targetNode​

LexicalNode

the node we're testing to see if it's after this one.

Returns​

boolean

isDirty()​

isDirty(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1646

Returns true if this node has been marked dirty during this update cycle.

Returns​

boolean

isInline()​

isInline(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1191

Returns​

boolean

isParentOf()​

isParentOf(targetNode): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1565

Returns true if this node is an ancestor of and distinct from the target node, false otherwise.

Parameters​
targetNode​

LexicalNode

the would-be child node.

Returns​

boolean

isParentRequired()​

isParentRequired(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:2305

Whether or not this node has a required parent. Used during copy + paste operations to normalize nodes that would otherwise be orphaned. For example, ListItemNodes without a ListNode parent or TextNodes with a ParagraphNode parent.

Returns​

boolean

isSelected()​

isSelected(selection?): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1231

Returns true if this node is contained within the provided Selection., false otherwise. Relies on the algorithms implemented in BaseSelection.getNodes to determine what's included.

Parameters​
selection?​

BaseSelection | null

The selection that we want to determine if the node is in.

Returns​

boolean

markDirty()​

markDirty(): void

Defined in: packages/lexical/src/LexicalNode.ts:2388

Marks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.

Returns​

void

remove()​

remove(preserveEmptyParent?): void

Defined in: packages/lexical/src/LexicalNode.ts:1949

Removes this LexicalNode from the EditorState. If the node isn't re-inserted somewhere, the Lexical garbage collector will eventually clean it up.

Parameters​
preserveEmptyParent?​

boolean

If falsy, the node's parent will be removed if it's empty after the removal operation. This is the default behavior, subject to other node heuristics such as ElementNode#canBeEmpty

Returns​

void

replace()​

replace<N>(replaceWith, includeChildren?): N

Defined in: packages/lexical/src/LexicalNode.ts:1966

Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.

Named slots are bound to their host node and are never transferred: this node keeps its slot map, so if it is reattached elsewhere (as $wrapNodeInElement does) its slots come with it, and if it stays detached the slot subtrees are garbage-collected along with it. To move a slot value onto another host, use $setSlot explicitly.

Type Parameters​
N​

N extends LexicalNode

Parameters​
replaceWith​

N

The node to replace this one with.

includeChildren?​

boolean

Whether or not to transfer the children of this node to the replacing node.

Returns​

N

resetOnCopyNodeFrom()​

resetOnCopyNodeFrom(originalNode): void

Defined in: packages/lexical/src/LexicalNode.ts:1155

Reset state in this copy of originalNode, if necessary

Parameters​
originalNode​

this

Returns​

void

selectEnd()​

selectEnd(): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2321

Returns​

RangeSelection

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2360

Moves selection to the next sibling of this node, at the specified offsets.

Parameters​
anchorOffset?​

number

The anchor offset for selection.

focusOffset?​

number

The focus offset for selection

Returns​

RangeSelection

selectPrevious()​

selectPrevious(anchorOffset?, focusOffset?): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2331

Moves selection to the previous sibling of this node, at the specified offsets.

Parameters​
anchorOffset?​

number

The anchor offset for selection.

focusOffset?​

number

The focus offset for selection

Returns​

RangeSelection

selectStart()​

selectStart(): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2317

Returns​

RangeSelection

updateDOM()​

updateDOM(_prevNode, _dom, _config): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1762

Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.

Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.

Parameters​
_prevNode​

unknown

_dom​

HTMLElement

_config​

EditorConfig

Returns​

boolean

updateFromJSON()​

updateFromJSON(serializedNode): this

Defined in: packages/lexical/src/LexicalNode.ts:1917

Update this LexicalNode instance from serialized JSON. It's recommended to implement as much logic as possible in this method instead of the static importJSON method, so that the functionality can be inherited in subclasses.

The LexicalUpdateJSON utility type should be used to ignore any type, version, or children properties in the JSON so that the extended JSON from subclasses are acceptable parameters for the super call.

If overridden, this method must call super.

Parameters​
serializedNode​

LexicalParseJSON<SerializedLexicalNode>

Returns​

this

Example​
class MyTextNode extends TextNode {
// ...
static importJSON(serializedNode: SerializedMyTextNode): MyTextNode {
return $createMyTextNode()
.updateFromJSON(serializedNode);
}
updateFromJSON(
serializedNode: LexicalUpdateJSON<SerializedMyTextNode>,
): this {
return super.updateFromJSON(serializedNode)
.setMyProperty(serializedNode.myProperty);
}
}

The whole schema is applied, so a property the JSON omits is set to its schema default rather than left as it is — that is what lets the compact form omit a default-valued property and have parsing restore it. (A flat NodeState is the exception: it is applied only when present.) Pass the node's complete serialized form unless you mean to reset what you leave out.


NodeSchemaMeta​

Defined in: packages/lexical/src/LexicalSchema.ts:2455

What a nodeSchema carries: the properties a node declares, and a kind of its own.

Not a member of SerializationSchemaMeta, because a node schema is never nested inside another schema. It describes a node, whose properties are applied one at a time to an object the walk does not own, where an objectValue describes a value that one property holds. Giving the two separate types is what lets a consumer of either be sure which it has.

Properties​

fields​

readonly fields: SerializationSchemaFields

Defined in: packages/lexical/src/LexicalSchema.ts:2457

kind​

readonly kind: "node"

Defined in: packages/lexical/src/LexicalSchema.ts:2456


NodeSelection​

Defined in: packages/lexical/src/LexicalSelection.ts:417

Implements​

Properties​

_cachedNodes​

_cachedNodes: LexicalNode[] | null

Defined in: packages/lexical/src/LexicalSelection.ts:419

Implementation of​

BaseSelection._cachedNodes

_nodes​

_nodes: Set<string>

Defined in: packages/lexical/src/LexicalSelection.ts:418

dirty​

dirty: boolean

Defined in: packages/lexical/src/LexicalSelection.ts:420

Implementation of​

BaseSelection.dirty

Methods​

add()​

add(key): void

Defined in: packages/lexical/src/LexicalSelection.ts:457

Parameters​
key​

string

Returns​

void

clear()​

clear(): void

Defined in: packages/lexical/src/LexicalSelection.ts:469

Returns​

void

clone()​

clone(): NodeSelection

Defined in: packages/lexical/src/LexicalSelection.ts:479

Returns​

NodeSelection

Implementation of​

BaseSelection.clone

delete()​

delete(key): void

Defined in: packages/lexical/src/LexicalSelection.ts:463

Parameters​
key​

string

Returns​

void

deleteNodes()​

deleteNodes(): void

Defined in: packages/lexical/src/LexicalSelection.ts:556

Remove all nodes in the NodeSelection. If there were any nodes, replace the selection with a new RangeSelection at the previous location of the first node.

Returns​

void

extract()​

extract(): LexicalNode[]

Defined in: packages/lexical/src/LexicalSelection.ts:483

Returns​

LexicalNode[]

Implementation of​

BaseSelection.extract

getCachedNodes()​

getCachedNodes(): LexicalNode[] | null

Defined in: packages/lexical/src/LexicalSelection.ts:428

Returns​

LexicalNode[] | null

Implementation of​

BaseSelection.getCachedNodes

getNodes()​

getNodes(): LexicalNode[]

Defined in: packages/lexical/src/LexicalSelection.ts:523

Returns​

LexicalNode[]

Implementation of​

BaseSelection.getNodes

getStartEndPoints()​

getStartEndPoints(): null

Defined in: packages/lexical/src/LexicalSelection.ts:453

Returns​

null

Implementation of​

BaseSelection.getStartEndPoints

getTextContent()​

getTextContent(): string

Defined in: packages/lexical/src/LexicalSelection.ts:542

Returns​

string

Implementation of​

BaseSelection.getTextContent

has()​

has(key): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:475

Parameters​
key​

string

Returns​

boolean

insertNodes()​

insertNodes(nodes): void

Defined in: packages/lexical/src/LexicalSelection.ts:495

Parameters​
nodes​

LexicalNode[]

Returns​

void

Implementation of​

BaseSelection.insertNodes

insertRawText()​

insertRawText(text): void

Defined in: packages/lexical/src/LexicalSelection.ts:487

Parameters​
text​

string

Returns​

void

Implementation of​

BaseSelection.insertRawText

insertText()​

insertText(): void

Defined in: packages/lexical/src/LexicalSelection.ts:491

Returns​

void

Implementation of​

BaseSelection.insertText

is()​

is(selection): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:436

Parameters​
selection​

BaseSelection | null

Returns​

boolean

Implementation of​

BaseSelection.is

isBackward()​

isBackward(): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:449

Returns​

boolean

Implementation of​

BaseSelection.isBackward

isCollapsed()​

isCollapsed(): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:445

Returns​

boolean

Implementation of​

BaseSelection.isCollapsed

setCachedNodes()​

setCachedNodes(nodes): void

Defined in: packages/lexical/src/LexicalSelection.ts:432

Parameters​
nodes​

LexicalNode[] | null

Returns​

void

Implementation of​

BaseSelection.setCachedNodes


NodeSerializationSchema​

Defined in: packages/lexical/src/LexicalSchema.ts:2460

Type Parameters​

N​

N = unknown

In​

In = unknown

Properties​

meta​

readonly meta: NodeSchemaMeta

Defined in: packages/lexical/src/LexicalSchema.ts:2473

The properties this node declares, and the whole of what a node schema is at run time.

A node schema is not a parser. Nothing ever calls one: the composition reads these fields and the walk applies each one to the node, so the whole-object machinery an objectValue carries — a parse that builds an object, a default object, a field-wise equality, a membership predicate — would be constructed per node class and never used. Leaving it out is what keeps it out of an application that declares schemas and never calls objectValue itself.


NumberValueOptions​

Defined in: packages/lexical/src/LexicalSchema.ts:117

Domain constraints for numberValue.

Properties​

clamp?​

readonly optional clamp?: boolean

Defined in: packages/lexical/src/LexicalSchema.ts:140

Bring a value outside min/max to the nearest bound instead of rejecting it. Only a finite number is clamped: a value that is not a number at all, or is not an integer when integer is set, still falls back to the default, because there is no nearest bound for it.

The distinction matters wherever the bound exists to cap work rather than to describe the domain. ListItemNode's indent is capped because applying it nests one list per level, and an over-deep item read as the default 0 would be flattened, where clamping keeps it as deep as the cap allows.

integer?​

readonly optional integer?: boolean

Defined in: packages/lexical/src/LexicalSchema.ts:127

Reject values that are not integers.

max?​

readonly optional max?: number

Defined in: packages/lexical/src/LexicalSchema.ts:125

Reject values above this bound (inclusive); see NumberValueOptions.min.

min?​

readonly optional min?: number

Defined in: packages/lexical/src/LexicalSchema.ts:123

Reject values below this bound (inclusive). With integer, the bound is rounded up to the integer it admits — the same domain, stated so that clamp and anything reading the schema's meta see a member.


OwnStaticNodeConfig​

Defined in: packages/lexical/src/LexicalUtils.ts:3277

Properties​

declaresOwnConfig​

declaresOwnConfig: boolean

Defined in: packages/lexical/src/LexicalUtils.ts:3293

Whether klass declared $config() itself.

ownNodeConfig is the config the class resolves to, which for a class that declared none is its ancestor's — reached through the inherited method, and a fresh object each time, since $config() builds its result per call. Anything walking the chain has to tell the two apart or it attributes an ancestor's declarations to the subclass and counts them twice; see iterStaticNodeConfigChain.

klass​

klass: KlassConstructor<typeof LexicalNode>

Defined in: packages/lexical/src/LexicalUtils.ts:3278

ownNodeConfig​

ownNodeConfig: StaticNodeConfigValue<LexicalNode, string | symbol> | undefined

Defined in: packages/lexical/src/LexicalUtils.ts:3280

ownNodeType​

ownNodeType: string | undefined

Defined in: packages/lexical/src/LexicalUtils.ts:3279


ParsableSerializedEditorState​

Defined in: packages/lexical/src/LexicalEditorState.ts:61

A document as a structural subtree — what $parseSerializedNode accepts at every level — for a caller holding serialized nodes rather than a SerializedEditorState: @lexical/clipboard's BaseSerializedNode[] from $generateJSONFromSelectedNodes, whose version is optional and whose interface carries no index signature, matched neither of the two forms above and could not be handed back to parseEditorState without a cast.

Properties​

root​

root: ParsableSerializedNode

Defined in: packages/lexical/src/LexicalEditorState.ts:62


Point​

Defined in: packages/lexical/src/LexicalSelection.ts:161

Properties​

_selection​

_selection: BaseSelection | null

Defined in: packages/lexical/src/LexicalSelection.ts:165

key​

key: string

Defined in: packages/lexical/src/LexicalSelection.ts:162

offset​

offset: number

Defined in: packages/lexical/src/LexicalSelection.ts:163

type​

type: "text" | "element"

Defined in: packages/lexical/src/LexicalSelection.ts:164

Methods​

getNode()​

getNode(): LexicalNode

Defined in: packages/lexical/src/LexicalSelection.ts:199

Returns​

LexicalNode

is()​

is(point): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:182

Parameters​
point​

PointType

Returns​

boolean

isBefore()​

isBefore(b): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:190

Parameters​
b​

PointType

Returns​

boolean

set()​

set(key, offset, type, onlyIfChanged?): void

Defined in: packages/lexical/src/LexicalSelection.ts:208

Parameters​
key​

string

offset​

number

type​

"text" | "element"

onlyIfChanged?​

boolean

Returns​

void


RangeSelection​

Defined in: packages/lexical/src/LexicalSelection.ts:636

Implements​

Properties​

_cachedNodes​

_cachedNodes: LexicalNode[] | null

Defined in: packages/lexical/src/LexicalSelection.ts:641

Implementation of​

BaseSelection._cachedNodes

anchor​

anchor: PointType

Defined in: packages/lexical/src/LexicalSelection.ts:639

dirty​

dirty: boolean

Defined in: packages/lexical/src/LexicalSelection.ts:644

Implementation of​

BaseSelection.dirty

focus​

focus: PointType

Defined in: packages/lexical/src/LexicalSelection.ts:640

format​

format: number

Defined in: packages/lexical/src/LexicalSelection.ts:637

style​

style: string

Defined in: packages/lexical/src/LexicalSelection.ts:638

Methods​

applyDOMRange()​

applyDOMRange(range): void

Defined in: packages/lexical/src/LexicalSelection.ts:841

Attempts to map a DOM selection range onto this Lexical Selection, setting the anchor, focus, and type accordingly

Parameters​
range​

StaticRange

a DOM Selection range conforming to the StaticRange interface.

Returns​

void

clone()​

clone(): RangeSelection

Defined in: packages/lexical/src/LexicalSelection.ts:877

Creates a new RangeSelection, copying over all the property values from this one.

Returns​

RangeSelection

a new RangeSelection with the same property values as this one.

Implementation of​

BaseSelection.clone

deleteCharacter()​

deleteCharacter(isBackward): void

Defined in: packages/lexical/src/LexicalSelection.ts:1801

Performs one logical character deletion operation on the EditorState based on the current Selection. Handles different node types.

Parameters​
isBackward​

boolean

whether or not the selection is backwards.

Returns​

void

deleteLine()​

deleteLine(isBackward): void

Defined in: packages/lexical/src/LexicalSelection.ts:2091

Performs one logical line deletion operation on the EditorState based on the current Selection. Handles different node types.

Parameters​
isBackward​

boolean

whether or not the selection is backwards.

Returns​

void

deleteWord()​

deleteWord(isBackward): void

Defined in: packages/lexical/src/LexicalSelection.ts:2155

Performs one logical word deletion operation on the EditorState based on the current Selection. Handles different node types.

Parameters​
isBackward​

boolean

whether or not the selection is backwards.

Returns​

void

extract()​

extract(): LexicalNode[]

Defined in: packages/lexical/src/LexicalSelection.ts:1528

Extracts the nodes in the Selection, splitting nodes where necessary to get offset-level precision.

Returns​

LexicalNode[]

The nodes in the Selection

Implementation of​

BaseSelection.extract

formatText()​

formatText(formatType, alignWithFormat?): void

Defined in: packages/lexical/src/LexicalSelection.ts:1155

Applies the provided format to the TextNodes in the Selection, splitting or merging nodes as necessary.

Parameters​
formatType​

TextFormatType

the format type to apply to the nodes in the Selection.

alignWithFormat?​

number | null

a 32-bit integer representing formatting flags to align with.

Returns​

void

forwardDeletion()​

forwardDeletion(anchor, anchorNode, isBackward): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:1769

Helper for handling forward character and word deletion that prevents element nodes like a table, columns layout being destroyed

Parameters​
anchor​

PointType

the anchor

anchorNode​

ElementNode | TextNode

the anchor node in the selection

isBackward​

boolean

whether or not selection is backwards

Returns​

boolean

getCachedNodes()​

getCachedNodes(): LexicalNode[] | null

Defined in: packages/lexical/src/LexicalSelection.ts:663

Returns​

LexicalNode[] | null

Implementation of​

BaseSelection.getCachedNodes

getNodes()​

getNodes(): LexicalNode[]

Defined in: packages/lexical/src/LexicalSelection.ts:710

Gets all the nodes in the Selection. Uses caching to make it generally suitable for use in hot paths.

See also the CaretRange APIs (starting with $caretRangeFromSelection), which are likely to provide a better foundation for any operation where partial selection is relevant (e.g. the anchor or focus are inside an ElementNode and TextNode)

Returns​

LexicalNode[]

an Array containing all the nodes in the Selection

Implementation of​

BaseSelection.getNodes

getStartEndPoints()​

getStartEndPoints(): [PointType, PointType]

Defined in: packages/lexical/src/LexicalSelection.ts:2199

Returns​

[PointType, PointType]

Implementation of​

BaseSelection.getStartEndPoints

getTextContent()​

getTextContent(): string

Defined in: packages/lexical/src/LexicalSelection.ts:759

Gets the (plain) text content of all the nodes in the selection.

Returns​

string

a string representing the text content of all the nodes in the Selection

Implementation of​

BaseSelection.getTextContent

hasFormat()​

hasFormat(type): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:926

Returns whether the provided TextFormatType is present on the Selection. This will be true if all text nodes in the Selection have the specified format.

Parameters​
type​

TextFormatType

the TextFormatType to check for.

Returns​

boolean

true if the provided format is currently toggled on the Selection, false otherwise.

insertLineBreak()​

insertLineBreak(selectStart?): void

Defined in: packages/lexical/src/LexicalSelection.ts:1511

Inserts a logical linebreak, which may be a new LineBreakNode or a new ParagraphNode, into the EditorState at the current Selection.

Parameters​
selectStart?​

boolean

Returns​

void

insertNodes()​

insertNodes(nodes): void

Defined in: packages/lexical/src/LexicalSelection.ts:1169

Attempts to "intelligently" insert an arbitrary list of Lexical nodes into the EditorState at the current Selection according to a set of heuristics that determine how surrounding nodes should be changed, replaced, or moved to accommodate the incoming ones.

Parameters​
nodes​

LexicalNode[]

the nodes to insert

Returns​

void

Implementation of​

BaseSelection.insertNodes

insertParagraph()​

insertParagraph(): ElementNode | null

Defined in: packages/lexical/src/LexicalSelection.ts:1463

Inserts a new ParagraphNode into the EditorState at the current Selection

Returns​

ElementNode | null

the newly inserted node.

insertRawText()​

insertRawText(text): void

Defined in: packages/lexical/src/LexicalSelection.ts:937

Attempts to insert the provided text into the EditorState at the current Selection. converts tabs, newlines, and carriage returns into LexicalNodes.

Parameters​
text​

string

the text to insert into the Selection

Returns​

void

Implementation of​

BaseSelection.insertRawText

insertText()​

insertText(text): void

Defined in: packages/lexical/src/LexicalSelection.ts:946

Insert the provided text into the EditorState at the current Selection.

Parameters​
text​

string

the text to insert into the Selection

Returns​

void

Implementation of​

BaseSelection.insertText

is()​

is(selection): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:677

Used to check if the provided selections is equal to this one by value, including anchor, focus, format, and style properties.

Parameters​
selection​

BaseSelection | null

the Selection to compare this one to.

Returns​

boolean

true if the Selections are equal, false otherwise.

Implementation of​

BaseSelection.is

isBackward()​

isBackward(): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:2187

Returns whether the Selection is "backwards", meaning the focus logically precedes the anchor in the EditorState.

Returns​

boolean

true if the Selection is backwards, false otherwise.

Implementation of​

BaseSelection.isBackward

isCollapsed()​

isCollapsed(): boolean

Defined in: packages/lexical/src/LexicalSelection.ts:695

Returns whether the Selection is "collapsed", meaning the anchor and focus are the same node and have the same offset.

Returns​

boolean

true if the Selection is collapsed, false otherwise.

Implementation of​

BaseSelection.isCollapsed

modify()​

modify(alter, isBackward, granularity): void

Defined in: packages/lexical/src/LexicalSelection.ts:1590

Modifies the Selection according to the parameters and a set of heuristics that account for various node types. Can be used to safely move or extend selection by one logical "unit" without dealing explicitly with all the possible node types.

Parameters​
alter​

"move" | "extend"

the type of modification to perform

isBackward​

boolean

whether or not selection is backwards

granularity​

"character" | "word" | "lineboundary"

the granularity at which to apply the modification

Returns​

void

removeText()​

removeText(): void

Defined in: packages/lexical/src/LexicalSelection.ts:1130

Removes the text in the Selection, adjusting the EditorState accordingly.

Returns​

void

setCachedNodes()​

setCachedNodes(nodes): void

Defined in: packages/lexical/src/LexicalSelection.ts:667

Parameters​
nodes​

LexicalNode[] | null

Returns​

void

Implementation of​

BaseSelection.setCachedNodes

setFormat()​

setFormat(format): void

Defined in: packages/lexical/src/LexicalSelection.ts:904

Sets the value of the format property on the Selection

Parameters​
format​

number

the format to set at the value of the format property.

Returns​

void

setStyle()​

setStyle(style): void

Defined in: packages/lexical/src/LexicalSelection.ts:914

Sets the value of the style property on the Selection

Parameters​
style​

string

the style to set at the value of the style property.

Returns​

void

setTextNodeRange()​

setTextNodeRange(anchorNode, anchorOffset, focusNode, focusOffset): this

Defined in: packages/lexical/src/LexicalSelection.ts:743

Sets this Selection to be of type "text" at the provided anchor and focus values.

Parameters​
anchorNode​

TextNode

the anchor node to set on the Selection

anchorOffset​

number

the offset to set on the Selection

focusNode​

TextNode

the focus node to set on the Selection

focusOffset​

number

the focus offset to set on the Selection

Returns​

this

toggleFormat()​

toggleFormat(format): void

Defined in: packages/lexical/src/LexicalSelection.ts:894

Toggles the provided format on all the TextNodes in the Selection.

Parameters​
format​

TextFormatType

a string TextFormatType to toggle on the TextNodes in the selection

Returns​

void


RawTextVisitor​

Defined in: packages/lexical/src/LexicalSelection.ts:4385

Push-lexer visitor passed to tokenizeRawText. The tokenizer invokes one callback per token it emits; empty text runs are suppressed, so text is only invoked with a non-empty string.

Properties​

linebreak​

readonly linebreak: () => void

Defined in: packages/lexical/src/LexicalSelection.ts:4386

Returns​

void

tab​

readonly tab: () => void

Defined in: packages/lexical/src/LexicalSelection.ts:4387

Returns​

void

text​

readonly text: (text) => void

Defined in: packages/lexical/src/LexicalSelection.ts:4388

Parameters​
text​

string

Returns​

void


RefCountedRegistry​

Defined in: packages/lexical/src/LexicalRefCountedRegistry.ts:20

A registry mapping keys to a per-key activation, reference counted so the activation is created on the first registration for a key and torn down only when the last outstanding registration for that key is released. This lets the same key be driven by more than one caller (or survive a re-entrant / double registration) without double-wiring or premature teardown.

Keys are compared by identity (Map semantics), so any object works — a DOM element, a Document, a Window, or an opaque handle.

Type Parameters​

Key​

Key

Options​

Options = void

Properties​

dispose​

dispose: () => void

Defined in: packages/lexical/src/LexicalRefCountedRegistry.ts:35

Dispose every live registration and clear the registry.

Returns​

void

register​

register: (key, options?) => () => void

Defined in: packages/lexical/src/LexicalRefCountedRegistry.ts:33

Register key (reference counted) and return an idempotent disposer. The first registration for a key runs the activation; the disposer it returns runs once the last registration for that key is released.

options configure the activation and are therefore only read on the activating (first) registration for a key. While a key is live, further registrations share that one activation and their options are ignored — ref counting models repeat registrations as the same logical thing, so registering one key with conflicting options is a caller error, not a merge. Release the key fully before re-registering it with new options.

Parameters​
key​

Key

options?​

Options

Returns​

() => void


SchemaAccessors​

Defined in: packages/lexical/src/LexicalSchema.ts:452

The node accessors a SerializationSchema field is applied through.

A string resolves to a method on the node; {field} resolves to one of the node's own fields. null states that the direction is deliberately unsupported — an export-only property computed from others (setter: null, as ListNode's tag is derived from listType) or an import-only one (getter: null). Leaving a direction undefined uses the conventional get<Prop>/set<Prop> name, which must exist: a name that resolves to nothing would silently drop the property, so it fails at registration.

The two directions are independent, and a node may reasonably mix them: TableCellNode reads headerState straight off the field but applies it through setHeaderStyles, which supplies a default mask.

Properties​

getter?​

readonly optional getter?: SchemaGetterAccessor

Defined in: packages/lexical/src/LexicalSchema.ts:453

setter?​

readonly optional setter?: SchemaSetterAccessor

Defined in: packages/lexical/src/LexicalSchema.ts:454


SchemaFieldBase​

Defined in: packages/lexical/src/LexicalSchema.ts:302

Declares that a serialized property is a node field, read and written directly rather than through an accessor method. The kind is stated rather than inferred from the name: a field and a method are different things to reach for, and deciding between them by looking at the string would make a node's field naming part of this API's contract.

Extended by​

Properties​

field​

readonly field: string

Defined in: packages/lexical/src/LexicalSchema.ts:303

method?​

readonly optional method?: string

Defined in: packages/lexical/src/LexicalSchema.ts:319

The accessor method this direct field access stands in for, when it is not the conventional get<Prop>/set<Prop> for the property. Naming one keeps a subclass in charge of its own property: if any class between the one that declared this field and the node's own class overrides that method, the field access is abandoned and the method is called instead.

Leaving it out defers to the conventional name, which is what nearly every property wants — a node that predates its schema already has those accessors, and overriding getStyle() on a TextNode subclass is ordinary, so migrating a property to a field must not silently take that back. Name one only when the accessor is spelled differently, as TextNode's text is (getTextContent) and LinkNode's url is (getURL). A class with no such method defers to nothing, since both prototypes then resolve undefined.


SchemaGetterField​

Defined in: packages/lexical/src/LexicalSchema.ts:323

A node field read directly on export.

Extends​

Properties​

field​

readonly field: string

Defined in: packages/lexical/src/LexicalSchema.ts:303

Inherited from​

SchemaFieldBase.field

getterTable?​

readonly optional getterTable?: object

Defined in: packages/lexical/src/LexicalSchema.ts:371

A lookup table from the stored field value to the serialized one, for a property whose two representations differ — TextNode stores mode as a bitmask and serializes it as a name.

Without this such a property needs an accessor method, and a method is a call plus, by convention, a getLatest(). Stating the mapping keeps the property on the direct-read path: the table is a plain object of primitives, so it is as inlinable by a code generator as the field read is.

The export direction's table; SchemaSetterField.setterTable is its import mirror. Each is declared only on the direction that reads it, so naming the wrong one is a type error rather than a silently ignored property.

Index Signature​

[key: string]: unknown

method?​

readonly optional method?: string

Defined in: packages/lexical/src/LexicalSchema.ts:319

The accessor method this direct field access stands in for, when it is not the conventional get<Prop>/set<Prop> for the property. Naming one keeps a subclass in charge of its own property: if any class between the one that declared this field and the node's own class overrides that method, the field access is abandoned and the method is called instead.

Leaving it out defers to the conventional name, which is what nearly every property wants — a node that predates its schema already has those accessors, and overriding getStyle() on a TextNode subclass is ordinary, so migrating a property to a field must not silently take that back. Name one only when the accessor is spelled differently, as TextNode's text is (getTextContent) and LinkNode's url is (getURL). A class with no such method defers to nothing, since both prototypes then resolve undefined.

Inherited from​

SchemaFieldBase.method

setterTable?​

readonly optional setterTable?: undefined

Defined in: packages/lexical/src/LexicalSchema.ts:332

Declared as never rather than left out: an excess property is only rejected for a fresh object literal, and these accessors are captured by an inferred type parameter (so the schema can carry the names it declares), which is not fresh. Stating the wrong direction's table as never rejects it by assignability instead, which inference cannot launder away.

when?​

readonly optional when?: string

Defined in: packages/lexical/src/LexicalSchema.ts:355

The name of a node predicate that decides whether this property is written at all. Naming it keeps the property on the direct-field path: without it, a conditionally-persisted property needs an accessor method, and a method is a call plus a getLatest() on every export of every node.

The property is written only when its value differs from the schema default and the predicate returns true — the default is what parsing would restore anyway, so writing it says nothing, and testing it first is what keeps the predicate off the common path. ElementNode's textFormat and textStyle are the motivating case: both are persisted only for an element with no TextNode child.

The predicate must be a pure, zero-argument method: it is called once per export by the walk for each property that names it, and once in total by generated code, which hoists a predicate that several properties share.

Like the field read it gates, this is what SchemaFieldBase.method stands in for: a subclass that overrides that accessor abandons the field and the predicate, because a method that replaces the read replaces the decision to make it.


SchemaSetterField​

Defined in: packages/lexical/src/LexicalSchema.ts:375

A node field written directly on import.

Extends​

Properties​

field​

readonly field: string

Defined in: packages/lexical/src/LexicalSchema.ts:303

Inherited from​

SchemaFieldBase.field

getterTable?​

readonly optional getterTable?: undefined

Defined in: packages/lexical/src/LexicalSchema.ts:377

See​

SchemaGetterField.setterTable for why this is never.

method?​

readonly optional method?: string

Defined in: packages/lexical/src/LexicalSchema.ts:319

The accessor method this direct field access stands in for, when it is not the conventional get<Prop>/set<Prop> for the property. Naming one keeps a subclass in charge of its own property: if any class between the one that declared this field and the node's own class overrides that method, the field access is abandoned and the method is called instead.

Leaving it out defers to the conventional name, which is what nearly every property wants — a node that predates its schema already has those accessors, and overriding getStyle() on a TextNode subclass is ordinary, so migrating a property to a field must not silently take that back. Name one only when the accessor is spelled differently, as TextNode's text is (getTextContent) and LinkNode's url is (getURL). A class with no such method defers to nothing, since both prototypes then resolve undefined.

Inherited from​

SchemaFieldBase.method

setterTable?​

readonly optional setterTable?: object

Defined in: packages/lexical/src/LexicalSchema.ts:390

A lookup table from the serialized value to the stored one — the inverse of SchemaGetterField.getterTable, for the import direction. The parsed value is the key, so the schema still owns the domain: only a value the schema admitted is ever looked up.

Index Signature​

[key: string]: unknown

when?​

readonly optional when?: undefined

Defined in: packages/lexical/src/LexicalSchema.ts:383

A predicate gates the export direction only, so naming one here is the same mistake as naming the wrong table; see SchemaGetterField.setterTable.


SerializationSchema()​

Defined in: packages/lexical/src/LexicalSchema.ts:154

A SerializationSchema is a Parse (so it can be called directly to coerce a value and dropped straight into createState's parse option) that also carries its recoverable default and an introspectable meta description of its domain.

Schemas are built with stringValue, numberValue, booleanValue, enumValue, nullable, and composed into whole-object schemas with objectValue — nodeSchema for a node's own, which is where accessors are named.

Type Parameters​

T​

T

Decls​

Decls = never

In​

In = T

SerializationSchema(value): T

Defined in: packages/lexical/src/LexicalSchema.ts:155

A SerializationSchema is a Parse (so it can be called directly to coerce a value and dropped straight into createState's parse option) that also carries its recoverable default and an introspectable meta description of its domain.

Schemas are built with stringValue, numberValue, booleanValue, enumValue, nullable, and composed into whole-object schemas with objectValue — nodeSchema for a node's own, which is where accessors are named.

Parameters​

value​

unknown

Returns​

T

Properties​

defaultValue​

readonly defaultValue: T

Defined in: packages/lexical/src/LexicalSchema.ts:187

The value returned for an out-of-domain input, i.e. schema(undefined).

getter?​

readonly optional getter?: SchemaGetterAccessor

Defined in: packages/lexical/src/LexicalSchema.ts:211

The name of the node getter that reads this property's value when the base LexicalNode.exportJSON walks a node's serialization schema. When omitted, the getter name defaults to get<Prop> (e.g. foo → getFoo). Use withAccessors to record a name that doesn't follow that convention (e.g. TextNode's text → getTextContent), or a SchemaField to read the value straight from a node field. A getter that returns undefined omits the property from the exported JSON.

meta​

readonly meta: SerializationSchemaMeta

Defined in: packages/lexical/src/LexicalSchema.ts:189

An introspectable description of this schema's domain.

setter?​

readonly optional setter?: SchemaSetterAccessor

Defined in: packages/lexical/src/LexicalSchema.ts:200

The name of the node setter that applies a parsed value of this schema when the base LexicalNode.updateFromJSON walks a node's serialization schema. When omitted, the setter name defaults to set<Prop> for the property this schema is bound to in a nodeSchema (e.g. foo → setFoo). Use withAccessors to record a name that doesn't follow that convention (e.g. TextNode's text → setTextContent), or a SchemaField to write the value straight to a node field.

Methods​

accepts()?​

optional accepts(value): boolean

Defined in: packages/lexical/src/LexicalSchema.ts:262

Whether value is in this schema's domain, for unionValue deciding which member a value belongs to.

A schema is total — it always returns a value — so membership normally has to be inferred from the parse: landing anywhere but the default means the value was recognized. That inference cannot see a value the schema normalizes into its own default, which is why a schema that accepts more than its own value type says so directly.

This asks about a serialized input, not about a parsed value, so it is not a predicate on T: a schema that reads more than it writes accepts inputs no T ever equals, and a transformValue out of its inner type accepts none of the values it produces. In particular, a combinator may — and numberValue with a min deliberately does — decline the very value it defaults to, which is how a union member says "this value is not mine" and lets the union fall through to the member that owns it.

Parameters​
value​

unknown

Returns​

boolean

isEqual()?​

optional isEqual(this, a, b): boolean

Defined in: packages/lexical/src/LexicalSchema.ts:243

Whether two values of this schema's domain say the same thing, for the comparisons that treat a value as absent: compaction dropping a property whose value is the default, and optional({omitDefault}) / nullable({defaultAsNull}).

Absent means identity, which is right for the primitive domains but never true of a reference-typed default: arrayValue and objectValue return a fresh value per parse, so without this an array-valued property equal to its default would still be written out. Mirrors StateValueConfig.isEqual, which exists for the same reason.

Not consulted through a unionValue, which compares structurally because it cannot know which member produced a value. The built-in reference-typed comparators are that comparison, so only a custom one from transformValue differs there; see unionValue for what it costs.

Declared with method syntax deliberately: TypeScript checks a method's parameters bivariantly, which keeps SerializationSchema<T> assignable to AnySerializationSchema. A property would make the type invariant in T and every AnySerializationSchema position would reject it.

this: void because method syntax otherwise implies a receiver this never has: every caller reads the comparator off the schema and calls it on its own — NodeState equality, optional({omitDefault}) and the compact export all do — so a comparator written to read this.meta type-checked and then threw. Declaring the receiver away says so, and costs nothing: the this parameter is not a parameter for bivariance's purposes, so the assignability above is unchanged.

Parameters​
this​

void

a​

T

b​

T

Returns​

boolean


SerializedEditorState​

Defined in: packages/lexical/src/LexicalEditorState.ts:35

Properties​

root​

root: SerializedElementNode

Defined in: packages/lexical/src/LexicalEditorState.ts:36


SetDOMUnmanagedOptions​

Defined in: packages/lexical/src/LexicalUtils.ts:3120

Experimental

Options accepted by setDOMUnmanaged.

Properties​

captureSelection?​

optional captureSelection?: boolean

Defined in: packages/lexical/src/LexicalUtils.ts:3131

Experimental

When true, the marked subtree owns its own window selection — analogous to a DecoratorNode subtree. Selection resolution that would otherwise mark the selection dirty for a caret position inside unmanaged DOM leaves it alone, so the embedded interaction (custom input, focusable widget, etc.) can keep its native caret.

Pass false to clear a previously-set marker; omit the field to leave __lexicalCapturedSelection untouched.


ShadowRootNode​

Defined in: packages/lexical/src/LexicalUtils.ts:1859

Extends​

Properties​

[ShadowRootNodeBrand]​

[ShadowRootNodeBrand]: never

Defined in: packages/lexical/src/LexicalUtils.ts:1860

Methods​

$config()​

$config(): BaseStaticNodeConfig & StaticNodeConfigAccessor<{ $transform: { }; extends: typeof LexicalNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<ElementNode, { direction?: "ltr" | "rtl" | null; format?: "" | "left" | "start" | "center" | "right" | "end" | "justify"; indent?: string | number; textFormat?: string | number; textStyle?: string; }>; }>

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:281

Override this to implement the new static node configuration protocol, this method is called directly on the prototype and must not depend on anything initialized in the constructor. Generally it should be a trivial implementation.

Returns​

BaseStaticNodeConfig & StaticNodeConfigAccessor<{ $transform: { }; extends: typeof LexicalNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<ElementNode, { direction?: "ltr" | "rtl" | null; format?: "" | "left" | "start" | "center" | "right" | "end" | "justify"; indent?: string | number; textFormat?: string | number; textStyle?: string; }>; }>

Example​
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Inherited from​

ElementNode.$config

afterCloneFrom()​

afterCloneFrom(prevNode): void

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:329

Perform any state updates on the clone of prevNode that are not already handled by the constructor call in the static clone method. If you have state to update in your clone that is not handled directly by the constructor, it is advisable to override this method but it is required to include a call to super.afterCloneFrom(prevNode) in your implementation. This is only intended to be called by $cloneWithProperties function or via a super call.

Parameters​
prevNode​

this

Returns​

void

Example​
class ClassesTextNode extends TextNode {
// Not shown: static getType, static importJSON, exportJSON, createDOM, updateDOM
__classes = new Set<string>();
static clone(node: ClassesTextNode): ClassesTextNode {
// The inherited TextNode constructor is used here, so
// classes is not set by this method.
return new ClassesTextNode(node.__text, node.__key);
}
afterCloneFrom(node: this): void {
// This calls TextNode.afterCloneFrom and LexicalNode.afterCloneFrom
// for necessary state updates
super.afterCloneFrom(node);
this.__addClasses(node.__classes);
}
// This method is a private implementation detail, it is not
// suitable for the public API because it does not call getWritable
__addClasses(classNames: Iterable<string>): this {
for (const className of classNames) {
this.__classes.add(className);
}
return this;
}
addClass(...classNames: string[]): this {
return this.getWritable().__addClasses(classNames);
}
removeClass(...classNames: string[]): this {
const node = this.getWritable();
for (const className of classNames) {
this.__classes.delete(className);
}
return this;
}
getClasses(): Set<string> {
return this.getLatest().__classes;
}
}
Inherited from​

ElementNode.afterCloneFrom

append()​

append(...nodesToAppend): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:774

Parameters​
nodesToAppend​

...LexicalNode[]

Returns​

this

Inherited from​

ElementNode.append

canBeEmpty()​

canBeEmpty(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1072

Returns​

boolean

Inherited from​

ElementNode.canBeEmpty

canIndent()​

canIndent(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1044

Returns​

boolean

Inherited from​

ElementNode.canIndent

canInsertTextAfter()​

canInsertTextAfter(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1078

Returns​

boolean

Inherited from​

ElementNode.canInsertTextAfter

canInsertTextBefore()​

canInsertTextBefore(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1075

Returns​

boolean

Inherited from​

ElementNode.canInsertTextBefore

canMergeWhenEmpty()​

canMergeWhenEmpty(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1121

Determines whether this node, when empty, can merge with a first block of nodes being inserted.

This method is specifically called in RangeSelection.insertNodes to determine merging behavior during nodes insertion.

Returns​

boolean

Example​
// In a ListItemNode or QuoteNode implementation:
canMergeWhenEmpty(): true {
return true;
}
Inherited from​

ElementNode.canMergeWhenEmpty

clear()​

clear(): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:768

Returns​

this

Inherited from​

ElementNode.clear

collapseAtStart()​

collapseAtStart(selection): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1058

Parameters​
selection​

RangeSelection

Returns​

boolean

Inherited from​

ElementNode.collapseAtStart

config()​
Call Signature​

config<Config>(type, config): AbstractStaticNodeConfigRecord<Config>

Defined in: packages/lexical/src/LexicalNode.ts:1066

This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.

An abstract base class that has no concrete node type may pass a well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of a string type to declare configuration shared with its subclasses.

Type Parameters​
Config​

Config extends StaticNodeConfigValue<ShadowRootNode, string>

Parameters​
type​

symbol

config​

Config

Returns​

AbstractStaticNodeConfigRecord<Config>

Inherited from​

ElementNode.config

Call Signature​

config<Type, Config>(type, config): StaticNodeConfigRecord<Type, Config>

Defined in: packages/lexical/src/LexicalNode.ts:1070

This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.

An abstract base class that has no concrete node type may pass a well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of a string type to declare configuration shared with its subclasses.

Type Parameters​
Type​

Type extends string

Config​

Config extends StaticNodeConfigValue<ShadowRootNode, Type>

Parameters​
type​

Type

config​

Config

Returns​

StaticNodeConfigRecord<Type, Config>

Inherited from​

ElementNode.config

createDOM()​

createDOM(_config, _editor): HTMLElement

Defined in: packages/lexical/src/LexicalNode.ts:1748

Called during the reconciliation process to determine which nodes to insert into the DOM for this Lexical Node.

This method must return exactly one HTMLElement. Nested elements are not supported.

Do not attempt to update the Lexical EditorState during this phase of the update lifecycle.

Parameters​
_config​

EditorConfig

allows access to things like the EditorTheme (to apply classes) during reconciliation.

_editor​

LexicalEditor

allows access to the editor for context during reconciliation.

Returns​

HTMLElement

Inherited from​

ElementNode.createDOM

createParentElementNode()​

createParentElementNode(): ElementNode

Defined in: packages/lexical/src/LexicalNode.ts:2313

The creation logic for any required parent. Should be implemented if isParentRequired returns true.

Returns​

ElementNode

Inherited from​

ElementNode.createParentElementNode

excludeFromCopy()​

excludeFromCopy(destination?): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1061

Parameters​
destination?​

"clone" | "html"

Returns​

boolean

Inherited from​

ElementNode.excludeFromCopy

exportDOM()​

exportDOM(editor): DOMExportOutput

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:967

Controls how the this node is serialized to HTML. This is important for copy and paste between Lexical and non-Lexical editors, or Lexical editors with different namespaces, in which case the primary transfer format is HTML. It's also important if you're serializing to HTML for any other reason via $generateHtmlFromNodes. You could also use this method to build your own HTML renderer.

Parameters​
editor​

LexicalEditor

Returns​

DOMExportOutput

Inherited from​

ElementNode.exportDOM

exportJSON()​
Call Signature​

exportJSON(compact?): SerializedElementNode

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:233

Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.

The base implementation writes every property the node's schema declares (its own and those it inherits), reading each through its getter — get<Prop> by default, or the name recorded with withAccessors. A getter that returns undefined omits its property. Override this only for output a schema can not describe, and call super.exportJSON(compact) when you do.

This may serialize the instance as-is, without resolving the latest version. A property declared with withField is read straight off the node, which is the optimization the serialization walk is built on — every node the walk reaches comes from the EditorState's node map and is already current, so it resolves nothing per node.

So on a reference that a getWritable() (any set<Prop>) has since superseded, this writes pre-mutation values. Which properties do is not something to rely on: a property whose accessor a subclass overrode still goes through that accessor and resolves the latest, so one node can write a current text beside a stale style. Call node.getLatest().exportJSON() whenever you hold such a reference rather than reasoning about which properties resolve.

This is a breaking change. Every property previously went through an accessor, and every accessor resolves getLatest(), so a stale reference exported current values.

Parameters​
compact?​

false

Write the compact form: omit a property the parser derives rather than reads, one whose value is the schema default parsing would restore, and the deprecated version. The two forms describe the same document. A node that overrides this and ignores the flag simply keeps writing the full form, which still parses.

Returns​

SerializedElementNode

Inherited from​

ElementNode.exportJSON

Call Signature​

exportJSON(compact): SerializedPartial<SerializedElementNode>

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:234

The compact form omits properties, so what it returns is the partial serialized type — every node-specific property optional — rather than the full one. Passing a boolean whose value is not statically known selects this overload too, which is right: neither form can be promised then.

Parameters​
compact​

boolean

Returns​

SerializedPartial<SerializedElementNode>

See​

SerializedPartial

Inherited from​

ElementNode.exportJSON

extractWithChild()​

extractWithChild(child, selection, destination): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1100

Parameters​
child​

LexicalNode

selection​

BaseSelection | null

destination​

"clone" | "html"

Returns​

boolean

Inherited from​

ElementNode.extractWithChild

getAllTextNodes()​

getAllTextNodes(): TextNode[]

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:420

Returns​

TextNode[]

Inherited from​

ElementNode.getAllTextNodes

getChildAtIndex()​
Call Signature​

getChildAtIndex(index): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:605

Returns the child of this node at the given index, or null if the index is out of range.

Parameters​
index​

number

Returns​

LexicalNode | null

Inherited from​

ElementNode.getChildAtIndex

Call Signature​

getChildAtIndex<T>(index): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:612

Type Parameters​
T​

T extends LexicalNode

Parameters​
index​

number

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getChildAtIndex(index) as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getChildAtIndex

getChildren()​
Call Signature​

getChildren(): LexicalNode[]

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:374

Returns the children of this node, in document order.

Returns​

LexicalNode[]

Inherited from​

ElementNode.getChildren

Call Signature​

getChildren<T>(): T[]

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:381

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getChildren() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

Inherited from​

ElementNode.getChildren

getChildrenKeys()​

getChildrenKeys(): string[]

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:391

Returns​

string[]

Inherited from​

ElementNode.getChildrenKeys

getChildrenSize()​

getChildrenSize(): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:400

Returns​

number

Inherited from​

ElementNode.getChildrenSize

getCommonAncestor()​

getCommonAncestor<T>(node): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1507

Type Parameters​
T​

T extends ElementNode = ElementNode

Parameters​
node​

LexicalNode

the other node to find the common ancestor of.

Returns​

T | null

Deprecated​

use $getCommonAncestor

Returns the closest common ancestor of this node and the provided one or null if one cannot be found.

Inherited from​

ElementNode.getCommonAncestor

getDescendantByIndex()​
Call Signature​

getDescendantByIndex(index): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:505

Returns the deepest descendant corresponding to the child at the given index, or null if this node has no children.

Parameters​
index​

number

Returns​

LexicalNode | null

Inherited from​

ElementNode.getDescendantByIndex

Call Signature​

getDescendantByIndex<T>(index): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:512

Type Parameters​
T​

T extends LexicalNode

Parameters​
index​

number

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getDescendantByIndex(index) as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getDescendantByIndex

getDirection()​

getDirection(): "ltr" | "rtl" | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:678

Returns​

"ltr" | "rtl" | null

Inherited from​

ElementNode.getDirection

getDOMSlot()​

getDOMSlot(element): ElementDOMSlot<HTMLElement>

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:964

Experimental

An ElementNode subclass can override this to control where its children are inserted into the DOM, e.g. to add a wrapping node or accessory nodes before or after the children. The root of the node returned by createDOM must still be exactly one HTMLElement.

Parameters​
element​

HTMLElement

Returns​

ElementDOMSlot<HTMLElement>

Inherited from​

ElementNode.getDOMSlot

getFirstChild()​
Call Signature​

getFirstChild(): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:536

Returns the first child of this node, or null if it has no children.

Returns​

LexicalNode | null

Inherited from​

ElementNode.getFirstChild

Call Signature​

getFirstChild<T>(): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:543

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getFirstChild() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getFirstChild

getFirstChildOrThrow()​
Call Signature​

getFirstChildOrThrow(): LexicalNode

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:552

Returns the first child of this node, or throws if it has no children.

Returns​

LexicalNode

Inherited from​

ElementNode.getFirstChildOrThrow

Call Signature​

getFirstChildOrThrow<T>(): T

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:559

Type Parameters​
T​

T extends LexicalNode

Returns​

T

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getFirstChildOrThrow() as T, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getFirstChildOrThrow

getFirstDescendant()​
Call Signature​

getFirstDescendant(): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:459

Returns the deepest first descendant of this node, or null if it has no children.

Descendant navigation is children-only by design: it feeds selectStart / selectEnd and selection, which must not see slots (slots are isolated).

Returns​

LexicalNode | null

Inherited from​

ElementNode.getFirstDescendant

Call Signature​

getFirstDescendant<T>(): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:466

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getFirstDescendant() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getFirstDescendant

getFormat()​

getFormat(): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:355

Returns​

number

Inherited from​

ElementNode.getFormat

getFormatFlags()​

getFormatFlags(type, alignWithFormat): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:702

Returns the format flags applied to the node as a 32-bit integer.

Parameters​
type​

TextFormatType

alignWithFormat​

number | null

Returns​

number

a number representing the TextFormatTypes applied to the node.

Inherited from​

ElementNode.getFormatFlags

getFormatType()​

getFormatType(): ElementFormatType

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:359

Returns​

ElementFormatType

Inherited from​

ElementNode.getFormatType

getIndent()​

getIndent(): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:367

Returns​

number

Inherited from​

ElementNode.getIndent

getIndexWithinParent()​

getIndexWithinParent(): number

Defined in: packages/lexical/src/LexicalNode.ts:1284

Returns the zero-based index of this node within the parent.

Returns​

number

Inherited from​

ElementNode.getIndexWithinParent

getKey()​

getKey(): string

Defined in: packages/lexical/src/LexicalNode.ts:1276

Returns this nodes key.

Returns​

string

Inherited from​

ElementNode.getKey

getLastChild()​
Call Signature​

getLastChild(): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:570

Returns the last child of this node, or null if it has no children.

Returns​

LexicalNode | null

Inherited from​

ElementNode.getLastChild

Call Signature​

getLastChild<T>(): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:577

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getLastChild() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getLastChild

getLastChildOrThrow()​
Call Signature​

getLastChildOrThrow(): LexicalNode

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:586

Returns the last child of this node, or throws if it has no children.

Returns​

LexicalNode

Inherited from​

ElementNode.getLastChildOrThrow

Call Signature​

getLastChildOrThrow<T>(): T

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:593

Type Parameters​
T​

T extends LexicalNode

Returns​

T

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getLastChildOrThrow() as T, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getLastChildOrThrow

getLastDescendant()​
Call Signature​

getLastDescendant(): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:482

Returns the deepest last descendant of this node, or null if it has no children.

Returns​

LexicalNode | null

Inherited from​

ElementNode.getLastDescendant

Call Signature​

getLastDescendant<T>(): T | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:489

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to element.getLastDescendant() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getLastDescendant

getLatest()​

getLatest(): this

Defined in: packages/lexical/src/LexicalNode.ts:1657

Returns the latest version of the node from the active EditorState. This is used to avoid getting values from stale node references.

Returns​

this

Inherited from​

ElementNode.getLatest

getNextSibling()​
Call Signature​

getNextSibling(): LexicalNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1463

Returns the node after this one in the same parent, or null if there is no such node.

Returns​

LexicalNode | null

Inherited from​

ElementNode.getNextSibling

Call Signature​

getNextSibling<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1470

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getNextSibling() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getNextSibling

getNextSiblings()​
Call Signature​

getNextSiblings(): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1481

Returns all nodes after this one in the same parent, in document order.

Returns​

LexicalNode[]

Inherited from​

ElementNode.getNextSiblings

Call Signature​

getNextSiblings<T>(): T[]

Defined in: packages/lexical/src/LexicalNode.ts:1488

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getNextSiblings() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

Inherited from​

ElementNode.getNextSiblings

getNodesBetween()​

getNodesBetween(targetNode): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1576

Returns a list of nodes that are between this node and the target node in the EditorState.

Parameters​
targetNode​

LexicalNode

the node that marks the other end of the range of nodes to be returned.

Returns​

LexicalNode[]

Inherited from​

ElementNode.getNodesBetween

getParent()​
Call Signature​

getParent(): ElementNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1304

Returns the parent of this node, or null if none is found.

Returns​

ElementNode | null

Inherited from​

ElementNode.getParent

Call Signature​

getParent<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1311

Type Parameters​
T​

T extends ElementNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getParent() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getParent

getParentKeys()​

getParentKeys(): string[]

Defined in: packages/lexical/src/LexicalNode.ts:1402

Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.

Returns​

string[]

Inherited from​

ElementNode.getParentKeys

getParentOrThrow()​
Call Signature​

getParentOrThrow(): ElementNode

Defined in: packages/lexical/src/LexicalNode.ts:1324

Returns the parent of this node, or throws if none is found.

Returns​

ElementNode

Inherited from​

ElementNode.getParentOrThrow

Call Signature​

getParentOrThrow<T>(): T

Defined in: packages/lexical/src/LexicalNode.ts:1331

Type Parameters​
T​

T extends ElementNode

Returns​

T

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getParentOrThrow() as T, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getParentOrThrow

getParents()​

getParents(): ElementNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1387

Returns a list of the every ancestor of this node, all the way up to the RootNode.

Returns​

ElementNode[]

Inherited from​

ElementNode.getParents

getPreviousSibling()​
Call Signature​

getPreviousSibling(): LexicalNode | null

Defined in: packages/lexical/src/LexicalNode.ts:1416

Returns the node before this one in the same parent, or null if there is no such node.

Returns​

LexicalNode | null

Inherited from​

ElementNode.getPreviousSibling

Call Signature​

getPreviousSibling<T>(): T | null

Defined in: packages/lexical/src/LexicalNode.ts:1423

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getPreviousSibling() as T | null, and will be removed in a future release. Call this method without a type argument and narrow the result with a type guard instead.

Inherited from​

ElementNode.getPreviousSibling

getPreviousSiblings()​
Call Signature​

getPreviousSiblings(): LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:1434

Returns all nodes before this one in the same parent, in document order.

Returns​

LexicalNode[]

Inherited from​

ElementNode.getPreviousSiblings

Call Signature​

getPreviousSiblings<T>(): T[]

Defined in: packages/lexical/src/LexicalNode.ts:1441

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to node.getPreviousSiblings() as T[], and will be removed in a future release. Call this method without a type argument and narrow the results with a type guard instead.

Inherited from​

ElementNode.getPreviousSiblings

getStyle()​

getStyle(): string

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:363

Returns​

string

Inherited from​

ElementNode.getStyle

getTextContent()​

getTextContent(): string

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:640

Returns the text content of the node. Override this for custom nodes that should have a representation in plain text format (for copy + paste, for example)

Returns​

string

Inherited from​

ElementNode.getTextContent

getTextContentSize()​

getTextContentSize(): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:659

Returns the length of the string produced by calling getTextContent on this node.

Returns​

number

Inherited from​

ElementNode.getTextContentSize

getTextFormat()​

getTextFormat(): number

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:682

Returns​

number

Inherited from​

ElementNode.getTextFormat

getTextStyle()​

getTextStyle(): string

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:708

Returns​

string

Inherited from​

ElementNode.getTextStyle

getTopLevelElement()​

getTopLevelElement(): ElementNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:241

Returns the highest (in the EditorState tree) non-root ancestor of this node, or null if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".

Returns​

ElementNode | null

Inherited from​

ElementNode.getTopLevelElement

getTopLevelElementOrThrow()​

getTopLevelElementOrThrow(): ElementNode

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:242

Returns the highest (in the EditorState tree) non-root ancestor of this node, or throws if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".

Returns​

ElementNode

Inherited from​

ElementNode.getTopLevelElementOrThrow

getType()​

getType(): string

Defined in: packages/lexical/src/LexicalNode.ts:1187

Returns the string type of this node.

Returns​

string

Inherited from​

ElementNode.getType

getWritable()​

getWritable(): this

Defined in: packages/lexical/src/LexicalNode.ts:1678

Returns a mutable version of the node using $cloneWithProperties if necessary. Will throw an error if called outside of a Lexical Editor LexicalEditor.update callback.

Returns​

this

Inherited from​

ElementNode.getWritable

hasFormat()​

hasFormat(type): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:686

Parameters​
type​

ElementFormatType

Returns​

boolean

Inherited from​

ElementNode.hasFormat

hasTextFormat()​

hasTextFormat(type): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:693

Parameters​
type​

TextFormatType

Returns​

boolean

Inherited from​

ElementNode.hasTextFormat

insertAfter()​

insertAfter(nodeToInsert, restoreSelection?): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:2117

Inserts a node after this LexicalNode (as the next sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert after this one.

restoreSelection?​

boolean = true

Whether or not to attempt to resolve the selection to the appropriate place after the operation is complete.

Returns​

LexicalNode

Inherited from​

ElementNode.insertAfter

insertBefore()​

insertBefore(nodeToInsert, restoreSelection?): LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:2224

Inserts a node before this LexicalNode (as the previous sibling).

Parameters​
nodeToInsert​

LexicalNode

The node to insert before this one.

restoreSelection?​

boolean = true

Whether or not to attempt to resolve the selection to the appropriate place after the operation is complete.

Returns​

LexicalNode

Inherited from​

ElementNode.insertBefore

insertNewAfter()​

insertNewAfter(selection, restoreSelection?): LexicalNode | null

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1038

Parameters​
selection​

RangeSelection

restoreSelection?​

boolean

Returns​

LexicalNode | null

Inherited from​

ElementNode.insertNewAfter

is()​

is(object): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1524

Returns true if the provided node is the exact same one as this node, from Lexical's perspective. Always use this instead of referential equality.

Parameters​
object​

LexicalNode | null | undefined

the node to perform the equality comparison on.

Returns​

boolean

Inherited from​

ElementNode.is

isAttached()​

isAttached(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1204

Returns true if there is a path between this node and the RootNode, false otherwise. This is a way of determining if the node is "attached" EditorState. Unattached nodes won't be reconciled and will ultimately be cleaned up by the Lexical GC.

Returns​

boolean

Inherited from​

ElementNode.isAttached

isBefore()​

isBefore(targetNode): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1542

Returns true if this node logically precedes the target node in the editor state, false otherwise (including if there is no common ancestor).

Note that this notion of isBefore is based on post-order; a descendant node is always before its ancestors. See also $getCommonAncestor and $comparePointCaretNext for more flexible ways to determine the relative positions of nodes.

Parameters​
targetNode​

LexicalNode

the node we're testing to see if it's after this one.

Returns​

boolean

Inherited from​

ElementNode.isBefore

isDirty()​

isDirty(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:410

Returns true if this node has been marked dirty during this update cycle.

Returns​

boolean

Inherited from​

ElementNode.isDirty

isEmpty()​

isEmpty(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:404

Returns​

boolean

Inherited from​

ElementNode.isEmpty

isInline()​

isInline(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1086

If the method is overridden and returns true, ensure that canBeEmpty() returns false for the inline node to work correctly

Returns​

boolean

Inherited from​

ElementNode.isInline

isLastChild()​

isLastChild(): boolean

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:415

Returns​

boolean

Inherited from​

ElementNode.isLastChild

isParentOf()​

isParentOf(targetNode): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1565

Returns true if this node is an ancestor of and distinct from the target node, false otherwise.

Parameters​
targetNode​

LexicalNode

the would-be child node.

Returns​

boolean

Inherited from​

ElementNode.isParentOf

isParentRequired()​

isParentRequired(): boolean

Defined in: packages/lexical/src/LexicalNode.ts:2305

Whether or not this node has a required parent. Used during copy + paste operations to normalize nodes that would otherwise be orphaned. For example, ListItemNodes without a ListNode parent or TextNodes with a ParagraphNode parent.

Returns​

boolean

Inherited from​

ElementNode.isParentRequired

isSelected()​

isSelected(selection?): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1231

Returns true if this node is contained within the provided Selection., false otherwise. Relies on the algorithms implemented in BaseSelection.getNodes to determine what's included.

Parameters​
selection?​

BaseSelection | null

The selection that we want to determine if the node is in.

Returns​

boolean

Inherited from​

ElementNode.isSelected

isShadowRoot()​

isShadowRoot(): true

Defined in: packages/lexical/src/LexicalUtils.ts:1861

Returns​

true

Overrides​

ElementNode.isShadowRoot

markDirty()​

markDirty(): void

Defined in: packages/lexical/src/LexicalNode.ts:2388

Marks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.

Returns​

void

Inherited from​

ElementNode.markDirty

remove()​

remove(preserveEmptyParent?): void

Defined in: packages/lexical/src/LexicalNode.ts:1949

Removes this LexicalNode from the EditorState. If the node isn't re-inserted somewhere, the Lexical garbage collector will eventually clean it up.

Parameters​
preserveEmptyParent?​

boolean

If falsy, the node's parent will be removed if it's empty after the removal operation. This is the default behavior, subject to other node heuristics such as ElementNode#canBeEmpty

Returns​

void

Inherited from​

ElementNode.remove

replace()​

replace<N>(replaceWith, includeChildren?): N

Defined in: packages/lexical/src/LexicalNode.ts:1966

Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.

Named slots are bound to their host node and are never transferred: this node keeps its slot map, so if it is reattached elsewhere (as $wrapNodeInElement does) its slots come with it, and if it stays detached the slot subtrees are garbage-collected along with it. To move a slot value onto another host, use $setSlot explicitly.

Type Parameters​
N​

N extends LexicalNode

Parameters​
replaceWith​

N

The node to replace this one with.

includeChildren?​

boolean

Whether or not to transfer the children of this node to the replacing node.

Returns​

N

Inherited from​

ElementNode.replace

resetOnCopyNodeFrom()​

resetOnCopyNodeFrom(originalNode): void

Defined in: packages/lexical/src/LexicalNode.ts:1155

Reset state in this copy of originalNode, if necessary

Parameters​
originalNode​

this

Returns​

void

Inherited from​

ElementNode.resetOnCopyNodeFrom

select()​

select(_anchorOffset?, _focusOffset?): RangeSelection

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:715

Parameters​
_anchorOffset?​

number

_focusOffset?​

number

Returns​

RangeSelection

Inherited from​

ElementNode.select

selectEnd()​

selectEnd(): RangeSelection

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:764

Returns​

RangeSelection

Inherited from​

ElementNode.selectEnd

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2360

Moves selection to the next sibling of this node, at the specified offsets.

Parameters​
anchorOffset?​

number

The anchor offset for selection.

focusOffset?​

number

The focus offset for selection

Returns​

RangeSelection

Inherited from​

ElementNode.selectNext

selectPrevious()​

selectPrevious(anchorOffset?, focusOffset?): RangeSelection

Defined in: packages/lexical/src/LexicalNode.ts:2331

Moves selection to the previous sibling of this node, at the specified offsets.

Parameters​
anchorOffset?​

number

The anchor offset for selection.

focusOffset?​

number

The focus offset for selection

Returns​

RangeSelection

Inherited from​

ElementNode.selectPrevious

selectStart()​

selectStart(): RangeSelection

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:760

Returns​

RangeSelection

Inherited from​

ElementNode.selectStart

setDirection()​

setDirection(direction): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:777

Parameters​
direction​

"ltr" | "rtl" | null

Returns​

this

Inherited from​

ElementNode.setDirection

setFormat()​

setFormat(type): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:782

Parameters​
type​

ElementFormatType

Returns​

this

Inherited from​

ElementNode.setFormat

setIndent()​

setIndent(indentLevel): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:802

Parameters​
indentLevel​

number

Returns​

this

Inherited from​

ElementNode.setIndent

setStyle()​

setStyle(style): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:787

Parameters​
style​

string

Returns​

this

Inherited from​

ElementNode.setStyle

setTextFormat()​

setTextFormat(type): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:792

Parameters​
type​

number

Returns​

this

Inherited from​

ElementNode.setTextFormat

setTextStyle()​

setTextStyle(style): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:797

Parameters​
style​

string

Returns​

this

Inherited from​

ElementNode.setTextStyle

splice()​

splice(start, deleteCount, nodesToInsert): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:807

Parameters​
start​

number

deleteCount​

number

nodesToInsert​

LexicalNode[]

Returns​

this

Inherited from​

ElementNode.splice

updateDOM()​

updateDOM(_prevNode, _dom, _config): boolean

Defined in: packages/lexical/src/LexicalNode.ts:1762

Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.

Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.

Parameters​
_prevNode​

unknown

_dom​

HTMLElement

_config​

EditorConfig

Returns​

boolean

Inherited from​

ElementNode.updateDOM

updateFromJSON()​

updateFromJSON(serializedNode): this

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:235

Update this LexicalNode instance from serialized JSON. It's recommended to implement as much logic as possible in this method instead of the static importJSON method, so that the functionality can be inherited in subclasses.

The LexicalUpdateJSON utility type should be used to ignore any type, version, or children properties in the JSON so that the extended JSON from subclasses are acceptable parameters for the super call.

If overridden, this method must call super.

Parameters​
serializedNode​

LexicalParseJSON<SerializedElementNode>

Returns​

this

Example​
class MyTextNode extends TextNode {
// ...
static importJSON(serializedNode: SerializedMyTextNode): MyTextNode {
return $createMyTextNode()
.updateFromJSON(serializedNode);
}
updateFromJSON(
serializedNode: LexicalUpdateJSON<SerializedMyTextNode>,
): this {
return super.updateFromJSON(serializedNode)
.setMyProperty(serializedNode.myProperty);
}
}

The whole schema is applied, so a property the JSON omits is set to its schema default rather than left as it is — that is what lets the compact form omit a default-valued property and have parsing restore it. (A flat NodeState is the exception: it is applied only when present.) Pass the node's complete serialized form unless you mean to reset what you leave out.

Inherited from​

ElementNode.updateFromJSON


SiblingCaret​

Defined in: packages/lexical/src/caret/LexicalCaret.ts:176

A SiblingCaret points from an origin LexicalNode towards its next or previous sibling.

Extends​

Type Parameters​

T​

T extends LexicalNode = LexicalNode

D​

D extends CaretDirection = CaretDirection

Properties​

direction​

readonly direction: D

Defined in: packages/lexical/src/caret/LexicalCaret.ts:58

next if pointing at the next sibling or first child, previous if pointing at the previous sibling or last child

Inherited from​

BaseCaret.direction

getAdjacentCaret​

getAdjacentCaret: () => SiblingCaret<LexicalNode, D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:64

Get a new SiblingCaret from getNodeAtCaret() in the same direction.

Returns​

SiblingCaret<LexicalNode, D> | null

Inherited from​

BaseCaret.getAdjacentCaret

getChildCaret​

getChildCaret: () => ChildCaret<T & ElementNode, D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:186

If the origin of this node is an ElementNode, return the ChildCaret of this origin in the same direction. If the origin is not an ElementNode, this will return null.

Returns​

ChildCaret<T & ElementNode, D> | null

getFlipped​

getFlipped: () => NodeCaret<FlipDirection<D>>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:223

Get a new NodeCaret with the head and tail of its directional arrow flipped, such that flipping twice is the identity. For example, given a non-empty parent with a firstChild and lastChild, and a second emptyParent node with no children:

Returns​

NodeCaret<FlipDirection<D>>

Example​
caret.getFlipped().getFlipped().is(caret) === true;
$getChildCaret(parent, 'next').getFlipped().is($getSiblingCaret(firstChild, 'previous')) === true;
$getSiblingCaret(lastChild, 'next').getFlipped().is($getChildCaret(parent, 'previous')) === true;
$getSiblingCaret(firstChild, 'next).getFlipped().is($getSiblingCaret(lastChild, 'previous')) === true;
$getChildCaret(emptyParent, 'next').getFlipped().is($getChildCaret(emptyParent, 'previous')) === true;
getLatest​

getLatest: () => SiblingCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:181

Get a new caret with the latest origin pointer

Returns​

SiblingCaret<T, D>

getNodeAtCaret​

getNodeAtCaret: () => LexicalNode | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:62

Get the node connected to the origin in the caret's direction, or null if there is no node

Returns​

LexicalNode | null

Inherited from​

BaseCaret.getNodeAtCaret

getParentAtCaret​

getParentAtCaret: () => ElementNode | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:60

Get the ElementNode that is the logical parent (origin for ChildCaret, origin.getParent() for SiblingCaret)

Returns​

ElementNode | null

Inherited from​

BaseCaret.getParentAtCaret

getParentCaret​

getParentCaret: (mode?) => SiblingCaret<ElementNode, D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:193

Get the caret in the same direction from the parent of this origin.

Parameters​
mode?​

RootMode

'root' to return null at the root, 'shadowRoot' to return null at the root or any shadow root

Returns​

SiblingCaret<ElementNode, D> | null

A SiblingCaret with the parent of this origin, or null if the parent is a root according to mode.

getSiblingCaret​

getSiblingCaret: () => SiblingCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:68

Get a new SiblingCaret with this same node

Returns​

SiblingCaret<T, D>

Inherited from​

BaseCaret.getSiblingCaret

insert​

insert: (node) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:76

Insert a node connected to origin in this direction (before the node that this caret is pointing towards, if any existed). For a SiblingCaret this is origin.insertAfter(node) for next, or origin.insertBefore(node) for previous. For a ChildCaret this is origin.splice(0, 0, [node]) for next or origin.append(node) for previous.

Parameters​
node​

LexicalNode

Returns​

this

Inherited from​

BaseCaret.insert

isSameNodeCaret​

isSameNodeCaret: (other) => other is (SiblingCaret<T, D> | T) extends TextNode ? TextPointCaret<T & TextNode, D> : never

Defined in: packages/lexical/src/caret/LexicalCaret.ts:198

Return true if other is a SiblingCaret or TextPointCaret with the same origin (by node key comparison) and direction.

Parameters​
other​

PointCaret<CaretDirection> | null | undefined

Returns​

other is (SiblingCaret<T, D> | T) extends TextNode ? TextPointCaret<T & TextNode, D> : never

isSamePointCaret​

isSamePointCaret: (other) => other is SiblingCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:207

Return true if other is a SiblingCaret with the same origin (by node key comparison) and direction.

Parameters​
other​

PointCaret<CaretDirection> | null | undefined

Returns​

other is SiblingCaret<T, D>

origin​

readonly origin: T

Defined in: packages/lexical/src/caret/LexicalCaret.ts:54

The origin node of this caret, typically this is what you will use in traversals

Inherited from​

BaseCaret.origin

remove​

remove: () => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:70

Remove the getNodeAtCaret() node that this caret is pointing towards, if it exists

Returns​

this

Inherited from​

BaseCaret.remove

replaceOrInsert​

replaceOrInsert: (node, includeChildren?) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:78

If getNodeAtCaret() is not null then replace it with node, otherwise insert node

Parameters​
node​

LexicalNode

includeChildren?​

boolean

Returns​

this

Inherited from​

BaseCaret.replaceOrInsert

splice​

splice: (deleteCount, nodes, nodesDirection?) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:86

Splice an iterable (typically an Array) of nodes into this location.

Parameters​
deleteCount​

number

The number of existing nodes to replace or delete

nodes​

Iterable<LexicalNode>

An iterable of nodes that will be inserted in this location, using replace instead of insert for the first deleteCount nodes

nodesDirection?​

CaretDirection

The direction of the nodes iterable, defaults to 'next'

Returns​

this

Inherited from​

BaseCaret.splice

type​

readonly type: "sibling"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:56

sibling for a SiblingCaret (pointing at the next or previous sibling) or child for a ChildCaret (pointing at the first or last child)

Inherited from​

BaseCaret.type


SlotChildNode​

Defined in: packages/lexical/src/LexicalNode.ts:975

Experimental

A node that can occupy a named slot, implemented by ElementNode and DecoratorNode. Its up-pointer is __slotHost rather than __parent (the two are mutually exclusive), so the slot boundary behaves like a shadow root.


SlotHostNode​

Defined in: packages/lexical/src/LexicalNode.ts:962

Experimental

A node that can host named slots, implemented by ElementNode and DecoratorNode. The map is allocated lazily (null until the first $setSlot) since most nodes have none. Declaring this off the base LexicalNode is what lets $setSlot / $removeSlot reject a non-host at compile time.


SplitAtPointCaretNextOptions​

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:757

Properties​

$copyElementNode?​

optional $copyElementNode?: (node) => ElementNode

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:759

The function to create the right side of a split ElementNode (default $copyNode)

Parameters​
node​

ElementNode

Returns​

ElementNode

$shouldSplit?​

optional $shouldSplit?: (node, edge) => boolean

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:771

If element.canBeEmpty() and it would create an empty split, this function will be called with the element and 'first' | 'last'. If it returns false, the empty split will not be created. Default is () => true to always split when possible.

Parameters​
node​

ElementNode

edge​

"first" | "last"

Returns​

boolean

$splitTextPointCaretNext?​

optional $splitTextPointCaretNext?: (caret) => NodeCaret<"next">

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:761

The function to split a TextNode (default $splitTextPointCaret)

Parameters​
caret​

TextPointCaret<TextNode, "next">

Returns​

NodeCaret<"next">

removeEmptyDestination?​

optional removeEmptyDestination?: boolean

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:776

If the destination would create an empty split on both sides, then remove it instead of splitting. Default false.

rootMode?​

optional rootMode?: RootMode

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:765

If the parent matches rootMode a split will not occur, default is 'shadowRoot'


StateConfig​

Defined in: packages/lexical/src/LexicalNodeState.ts:413

The return value of createState, for use with $getState and $setState.

Type Parameters​

K​

K extends string | symbol

V​

V

Properties​

defaultValue​

readonly defaultValue: V

Defined in: packages/lexical/src/LexicalNodeState.ts:434

The result of stateValueConfig.parse(undefined), which is computed only once and used as the default value. When the current value isEqual to the defaultValue, it will not be serialized to JSON.

isEqual​

readonly isEqual: (a, b) => boolean

Defined in: packages/lexical/src/LexicalNodeState.ts:428

An equality function from the StateValueConfig, with a default of Object.is.

Parameters​
a​

V

b​

V

Returns​

boolean

key​

readonly key: K

Defined in: packages/lexical/src/LexicalNodeState.ts:415

The string key used when serializing this state to JSON

parse​

readonly parse: (value?) => V

Defined in: packages/lexical/src/LexicalNodeState.ts:417

The parse function from the StateValueConfig passed to createState

Parameters​
value?​

unknown

Returns​

V

resetOnCopyNode​

readonly resetOnCopyNode: boolean

Defined in: packages/lexical/src/LexicalNodeState.ts:435

schema?​

readonly optional schema?: AnySerializationSchema

Defined in: packages/lexical/src/LexicalNodeState.ts:443

The SerializationSchema for this state's value, present when its parse is a schema (e.g. createState('mode', {parse: enumValue([...])})). It exposes the value's introspectable domain so tooling such as @lexical/fast-check can generate examples of this state. It is undefined when parse is a plain function with no schema metadata.

unparse​

readonly unparse: (value) => unknown

Defined in: packages/lexical/src/LexicalNodeState.ts:423

The unparse function from the StateValueConfig passed to createState, with a default that is simply a pass-through that assumes the value is JSON serializable.

Parameters​
value​

V

Returns​

unknown


StateValueConfig​

Defined in: packages/lexical/src/LexicalNodeState.ts:364

Configure a value to be used with StateConfig.

The value type should be inferred from the definition of parse.

If the value type is not JSON serializable, then unparse must also be provided.

Values should be treated as immutable, much like React.useState. Mutating stored values directly will cause unpredictable behavior, is not supported, and may trigger errors in the future.

Examples​

const numberOrNullState = createState('numberOrNull', {parse: (v) => typeof v === 'number' ? v : null});
// ^? State<'numberOrNull', StateValueConfig<number | null>>
const numberState = createState('number', {parse: (v) => typeof v === 'number' ? v : 0});
// ^? State<'number', StateValueConfig<number>>

The Parse schema builders exported from lexical (such as stringValue, numberValue, booleanValue, and enumValue) cover the common primitive and enumeration cases and return a parse function you can use directly:

const formatState = createState('format', {parse: numberValue()});
// ^? State<'format', StateValueConfig<number>>

Only the parse option is required, it is generally not useful to override unparse or isEqual. However, if you are using non-primitive types such as Array, Object, Date, or something more exotic then you would want to override this. In these cases you might want to reach for third party libraries.

const isoDateState = createState('isoDate', {
parse: (v): null | Date => {
const date = typeof v === 'string' ? new Date(v) : null;
return date && !isNaN(date.valueOf()) ? date : null;
}
isEqual: (a, b) => a === b || (a && b && a.valueOf() === b.valueOf()),
unparse: (v) => v && v.toString()
});

You may find it easier to write a parse function using libraries like zod, valibot, ajv, Effect, TypeBox, etc. perhaps with a wrapper function.

Type Parameters​

V​

V

Properties​

isEqual?​

optional isEqual?: (a, b) => boolean

Defined in: packages/lexical/src/LexicalNodeState.ts:401

This is optional and for advanced use cases only.

Used to define the equality function so you can use an Array or Object as V and still omit default values from the exported JSON.

The default is Object.is, but something like fast-deep-equal might be more appropriate for your use case.

Parameters​
a​

V

b​

V

Returns​

boolean

parse​

parse: (jsonValue) => V

Defined in: packages/lexical/src/LexicalNodeState.ts:384

This function must return a default value when called with undefined, otherwise it should parse the given JSON value to your type V. Note that it is not required to copy or clone the given value, you can pass it directly through if it matches the expected type.

When you encounter an invalid value, it's up to you to decide as to whether to ignore it and return the default value, return some non-default error value, or throw an error.

It is possible for V to include undefined, but if it does, then it should also be considered the default value since undefined can not be serialized to JSON so it is indistinguishable from the default.

Similarly, if your V is a function, then usage of $setState must use an updater function because your type will be indistinguishable from an updater function.

Parameters​
jsonValue​

unknown

Returns​

V

resetOnCopyNode?​

optional resetOnCopyNode?: boolean

Defined in: packages/lexical/src/LexicalNodeState.ts:406

When a node is copied with $copyNode (not cloned), reset this value to the default.

unparse?​

optional unparse?: (parsed) => unknown

Defined in: packages/lexical/src/LexicalNodeState.ts:391

This is optional and for advanced use cases only.

You may specify a function that converts V back to JSON. This is mandatory when V is not a JSON serializable type.

Parameters​
parsed​

V

Returns​

unknown


StaticNodeConfigValue​

Defined in: packages/lexical/src/LexicalNode.ts:137

EXPERIMENTAL The configuration of a node returned by LexicalNode.$config()

Example​

class CustomText extends TextNode {
$config() {
return this.config('custom-text', {extends: TextNode}};
}
}

Type Parameters​

T​

T extends LexicalNode

Type​

Type extends string | symbol

Properties​

$transform?​

readonly optional $transform?: (node) => void

Defined in: packages/lexical/src/LexicalNode.ts:156

An alternative to the internal static transform() method that provides better type inference. If implemented this transform will be registered for this class and any subclass.

Parameters​
node​

T

Returns​

void

extends?​

readonly optional extends?: KlassConstructor<typeof LexicalNode>

Defined in: packages/lexical/src/LexicalNode.ts:240

The exact superclass of the node. Always name it.

The runtime fills it in from the prototype chain when it is left out, but the type system cannot: extends is what the composed serialization types follow from one config to the next. A node that omits it still contributes its own declarations — LexicalSchemaInput reads the config in hand — but the walk stops there, so every property the node inherits is missing from the type while the runtime keeps applying it. Where the superclass itself declares a $config() — which TextNode, ElementNode and LineBreakNode all do — omitting it is a compile error on the override rather than a silent loss.

It must be the exact superclass. Nothing checks that: naming a class further up the chain silently skips everything in between, which drops those classes' schema fields, $transform, slots and stateConfigs from every walk.

importDOM?​

readonly optional importDOM?: DOMConversionMap<HTMLElement>

Defined in: packages/lexical/src/LexicalNode.ts:172

An alternative to the static importDOM() method

json?​

readonly optional json?: NodeSerializationSchema<T, unknown>

Defined in: packages/lexical/src/LexicalNode.ts:254

EXPERIMENTAL

A SerializationSchema describing this node's serialized JSON (the node-specific properties it adds over its parent's, not including type/version/children or node state). When provided it is the single source of truth for parsing those properties — a node's updateFromJSON can apply it — and, because the schema is introspectable, tooling such as @lexical/fast-check can use it to generate example serializations.

It is named json rather than schema to avoid ambiguity with other kinds of node schema (e.g. a schema of allowed children).

slots?​

readonly optional slots?: readonly string[]

Defined in: packages/lexical/src/LexicalNode.ts:221

Experimental

named-slots

Canonical order for this host's named slots. Declared names render, fold, serialize, and traverse in this order; occupied names that are not declared follow in code-unit order. Order is derived from this declaration at every $setSlot (never stored), so documents re-canonicalize on load and concurrent collaborative slot additions converge to the same order on every client. The declaration is not a schema: undeclared names are still accepted and retained, so adding, reordering, or dropping entries over time is non-destructive.

Declaring slots also opts the host into eager slots-map creation in @lexical/yjs, which makes each name's first set merge per-entry under concurrency instead of racing on attribute creation.

stateConfigs?​

readonly optional stateConfigs?: readonly RequiredNodeStateConfig[]

Defined in: packages/lexical/src/LexicalNode.ts:204

EXPERIMENTAL

An array of RequiredNodeStateConfig to initialize your node with its state requirements. This may be used to configure serialization of that state.

This function will be called (at most) once per editor initialization, directly on your node's prototype. It must not depend on any state initialized in the constructor.

Example​
const flatState = createState("flat", {parse: parseNumber});
const nestedState = createState("nested", {parse: parseNumber});
class MyNode extends TextNode {
$config() {
return this.config(
'my-node',
{
extends: TextNode,
stateConfigs: [
{ stateConfig: flatState, flat: true},
nestedState,
]
},
);
}
}
type?​

readonly optional type?: Type

Defined in: packages/lexical/src/LexicalNode.ts:150

The exact type of T.getType(), e.g. 'text' - the method itself must have a more generic 'string' type to be compatible wtih subclassing.

For a concrete node this is its string type. An abstract base class is keyed in BaseStaticNodeConfig by a symbol (it has no concrete node type), so Type is widened to string | symbol; the type field is never populated for a symbol-keyed config.

Methods​

$importJSON()?​

optional $importJSON(serializedNode): T

Defined in: packages/lexical/src/LexicalNode.ts:168

An alternative to the static importJSON() method that provides better type inference.

A method signature rather than a function-typed property, so that the parameter is checked bivariantly: the JSON handed in may be the compact form, so a callback may take SerializedPartial<SerializedLexicalNode>, while one written before that form existed takes SerializedLexicalNode (version required) and has to stay assignable. A property's parameter is compared contravariantly and would refuse it.

Parameters​
serializedNode​

SerializedPartial<SerializedLexicalNode>

Returns​

T


StepwiseIteratorConfig​

Defined in: packages/lexical/src/caret/LexicalCaret.ts:127

Type Parameters​

State​

State

Stop​

Stop

Value​

Value

Properties​

hasNext​

readonly hasNext: (value) => value is State

Defined in: packages/lexical/src/caret/LexicalCaret.ts:129

Parameters​
value​

State | Stop

Returns​

value is State

initial​

readonly initial: State | Stop

Defined in: packages/lexical/src/caret/LexicalCaret.ts:128

map​

readonly map: (value) => Value

Defined in: packages/lexical/src/caret/LexicalCaret.ts:131

Parameters​
value​

State

Returns​

Value

step​

readonly step: (value) => State | Stop

Defined in: packages/lexical/src/caret/LexicalCaret.ts:130

Parameters​
value​

State

Returns​

State | Stop


TextPointCaret​

Defined in: packages/lexical/src/caret/LexicalCaret.ts:282

A TextPointCaret is a special case of a SiblingCaret that also carries an offset used for representing partially selected TextNode at the edges of a CaretRange.

The direction determines which part of the text is adjacent to the caret, if next it's all of the text after offset. If previous, it's all of the text before offset.

While this can be used in place of any SiblingCaret of a TextNode, the offset into the text will be ignored except in contexts that specifically use the TextPointCaret or PointCaret types.

Extends​

Type Parameters​

T​

T extends TextNode = TextNode

D​

D extends CaretDirection = CaretDirection

Properties​

direction​

readonly direction: D

Defined in: packages/lexical/src/caret/LexicalCaret.ts:58

next if pointing at the next sibling or first child, previous if pointing at the previous sibling or last child

Inherited from​

BaseCaret.direction

getAdjacentCaret​

getAdjacentCaret: () => SiblingCaret<LexicalNode, D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:64

Get a new SiblingCaret from getNodeAtCaret() in the same direction.

Returns​

SiblingCaret<LexicalNode, D> | null

Inherited from​

BaseCaret.getAdjacentCaret

getChildCaret​

getChildCaret: () => null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:293

A TextPointCaret can not have a ChildCaret.

Returns​

null

getFlipped​

getFlipped: () => TextPointCaret<T, FlipDirection<D>>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:324

Get a new TextPointCaret with the head and tail of its directional arrow flipped, such that flipping twice is the identity. For a TextPointCaret this merely flips the direction because the arrow is internal to the node.

Returns​

TextPointCaret<T, FlipDirection<D>>

Example​
caret.getFlipped().getFlipped().is(caret) === true;
getLatest​

getLatest: () => TextPointCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:289

Get a new caret with the latest origin pointer

Returns​

TextPointCaret<T, D>

getNodeAtCaret​

getNodeAtCaret: () => LexicalNode | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:62

Get the node connected to the origin in the caret's direction, or null if there is no node

Returns​

LexicalNode | null

Inherited from​

BaseCaret.getNodeAtCaret

getParentAtCaret​

getParentAtCaret: () => ElementNode | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:60

Get the ElementNode that is the logical parent (origin for ChildCaret, origin.getParent() for SiblingCaret)

Returns​

ElementNode | null

Inherited from​

BaseCaret.getParentAtCaret

getParentCaret​

getParentCaret: (mode?) => SiblingCaret<ElementNode, D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:300

Get the caret in the same direction from the parent of this origin.

Parameters​
mode?​

RootMode

'root' to return null at the root, 'shadowRoot' to return null at the root or any shadow root

Returns​

SiblingCaret<ElementNode, D> | null

A SiblingCaret with the parent of this origin, or null if the parent is a root according to mode.

getSiblingCaret​

getSiblingCaret: () => SiblingCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:68

Get a new SiblingCaret with this same node

Returns​

SiblingCaret<T, D>

Inherited from​

BaseCaret.getSiblingCaret

insert​

insert: (node) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:76

Insert a node connected to origin in this direction (before the node that this caret is pointing towards, if any existed). For a SiblingCaret this is origin.insertAfter(node) for next, or origin.insertBefore(node) for previous. For a ChildCaret this is origin.splice(0, 0, [node]) for next or origin.append(node) for previous.

Parameters​
node​

LexicalNode

Returns​

this

Inherited from​

BaseCaret.insert

isSameNodeCaret​

isSameNodeCaret: (other) => other is TextPointCaret<T, D> | SiblingCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:305

Return true if other is a TextPointCaret or SiblingCaret with the same origin (by node key comparison) and direction.

Parameters​
other​

PointCaret<CaretDirection> | null | undefined

Returns​

other is TextPointCaret<T, D> | SiblingCaret<T, D>

isSamePointCaret​

isSamePointCaret: (other) => other is TextPointCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:312

Return true if other is a ChildCaret with the same origin (by node key comparison) and direction.

Parameters​
other​

PointCaret<CaretDirection> | null | undefined

Returns​

other is TextPointCaret<T, D>

offset​

readonly offset: number

Defined in: packages/lexical/src/caret/LexicalCaret.ts:287

The offset into the string

origin​

readonly origin: T

Defined in: packages/lexical/src/caret/LexicalCaret.ts:54

The origin node of this caret, typically this is what you will use in traversals

Inherited from​

BaseCaret.origin

remove​

remove: () => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:70

Remove the getNodeAtCaret() node that this caret is pointing towards, if it exists

Returns​

this

Inherited from​

BaseCaret.remove

replaceOrInsert​

replaceOrInsert: (node, includeChildren?) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:78

If getNodeAtCaret() is not null then replace it with node, otherwise insert node

Parameters​
node​

LexicalNode

includeChildren?​

boolean

Returns​

this

Inherited from​

BaseCaret.replaceOrInsert

splice​

splice: (deleteCount, nodes, nodesDirection?) => this

Defined in: packages/lexical/src/caret/LexicalCaret.ts:86

Splice an iterable (typically an Array) of nodes into this location.

Parameters​
deleteCount​

number

The number of existing nodes to replace or delete

nodes​

Iterable<LexicalNode>

An iterable of nodes that will be inserted in this location, using replace instead of insert for the first deleteCount nodes

nodesDirection?​

CaretDirection

The direction of the nodes iterable, defaults to 'next'

Returns​

this

Inherited from​

BaseCaret.splice

type​

readonly type: "text"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:56

sibling for a SiblingCaret (pointing at the next or previous sibling) or child for a ChildCaret (pointing at the first or last child)

Inherited from​

BaseCaret.type


TextPointCaretSlice​

Defined in: packages/lexical/src/caret/LexicalCaret.ts:334

A TextPointCaretSlice is a wrapper for a TextPointCaret that carries a signed distance representing the direction and amount of text selected from the given caret. A negative distance means that text before offset is selected, a positive distance means that text after offset is selected. The offset+distance pair is not affected in any way by the direction of the caret.

Type Parameters​

T​

T extends TextNode = TextNode

D​

D extends CaretDirection = CaretDirection

Properties​

caret​

readonly caret: TextPointCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:339

distance​

readonly distance: number

Defined in: packages/lexical/src/caret/LexicalCaret.ts:340

getSliceIndices​

getSliceIndices: () => [number, number]

Defined in: packages/lexical/src/caret/LexicalCaret.ts:344

Returns​

[number, number]

absolute coordinates into the text (for use with text.slice(...))

getTextContent​

getTextContent: () => string

Defined in: packages/lexical/src/caret/LexicalCaret.ts:348

Returns​

string

The text represented by the slice

getTextContentSize​

getTextContentSize: () => number

Defined in: packages/lexical/src/caret/LexicalCaret.ts:352

Returns​

number

The size of the text represented by the slice

type​

readonly type: "slice"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:338

Methods​

removeTextSlice()​

removeTextSlice(): TextPointCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:364

Remove the slice of text from the contained caret, returning a new TextPointCaret without the wrapper (since the size would be zero).

Note that this is a lower-level utility that does not have any specific behavior for 'segmented' or 'token' modes and it will not remove an empty TextNode.

Returns​

TextPointCaret<T, D>

The inner TextPointCaret with the same offset and direction and the latest TextNode origin after mutation


UpdateListenerPayload​

Defined in: packages/lexical/src/LexicalEditor.ts:546

The payload passed to an UpdateListener

Properties​

dirtyElements​

dirtyElements: Map<string, boolean>

Defined in: packages/lexical/src/LexicalEditor.ts:552

A Map of NodeKeys of ElementNodes to a boolean that is true if the node was intentionally mutated ('unintentional' mutations are triggered when an indirect descendant is marked dirty)

dirtyLeaves​

dirtyLeaves: Set<string>

Defined in: packages/lexical/src/LexicalEditor.ts:557

A Set of NodeKeys of all nodes that were marked dirty that do not inherit from ElementNode.

editorState​

editorState: EditorState

Defined in: packages/lexical/src/LexicalEditor.ts:562

The new EditorState after all updates have been processed, equivalent to editor.getEditorState()

mutatedNodes​

mutatedNodes: MutatedNodes | null

Defined in: packages/lexical/src/LexicalEditor.ts:574

The Map of LexicalNode constructors to a Map<NodeKey, NodeMutation>, this is useful when you have a mutation listener type use cases that should apply to all or most nodes. Will be null if no DOM was mutated, such as when only the selection changed. Note that this will be empty unless at least one MutationListener is explicitly registered (any MutationListener is sufficient to compute the mutatedNodes Map for all nodes).

Added in v0.28.0

normalizedNodes​

normalizedNodes: Set<string>

Defined in: packages/lexical/src/LexicalEditor.ts:583

For advanced use cases only.

Tracks the keys of TextNode descendants that have been merged with their siblings by normalization. Note that these keys may not exist in either editorState or prevEditorState and generally this is only used for conflict resolution edge cases in collab.

prevEditorState​

prevEditorState: EditorState

Defined in: packages/lexical/src/LexicalEditor.ts:587

The previous EditorState that is being discarded

tags​

tags: Set<string>

Defined in: packages/lexical/src/LexicalEditor.ts:593

The set of tags added with update options or $addUpdateTag, node that this includes all tags that were processed in this reconciliation which may have been added by separate updates.

Type Aliases​

AnyLexicalCommand​

AnyLexicalCommand = LexicalCommand<any>

Defined in: packages/lexical/src/LexicalEditor.ts:701


AnyLexicalExtension​

AnyLexicalExtension = LexicalExtension<any, string, any, any>

Defined in: packages/lexical/src/extension-core/types.ts:22

Any concrete LexicalExtension


AnyLexicalExtensionArgument​

AnyLexicalExtensionArgument = AnyLexicalExtension | AnyNormalizedLexicalExtensionArgument

Defined in: packages/lexical/src/extension-core/types.ts:26

Any LexicalExtension or NormalizedLexicalExtensionArgument


AnyNormalizedLexicalExtensionArgument​

AnyNormalizedLexicalExtensionArgument = NormalizedLexicalExtensionArgument<any, string, any, any>

Defined in: packages/lexical/src/extension-core/types.ts:58

Any NormalizedLexicalExtensionArgument


AnySerializationSchema​

AnySerializationSchema = SerializationSchema<unknown, unknown, unknown>

Defined in: packages/lexical/src/LexicalSchema.ts:1084

A SerializationSchema for an unknown type, used where the type is not relevant.


AnyStateConfig​

AnyStateConfig = StateConfig<any, any>

Defined in: packages/lexical/src/LexicalNodeState.ts:520

For advanced use cases, using this type is not recommended unless it is required (due to TypeScript's lack of features like higher-kinded types).

A StateConfig type with any key and any value that can be used in situations where the key and value type can not be known, such as in a generic constraint when working with a collection of StateConfig.

StateConfigKey and StateConfigValue will be useful when this is used as a generic constraint.


BaseStaticNodeConfig​

BaseStaticNodeConfig = { readonly [K in string | symbol]?: StaticNodeConfigValue<LexicalNode, K> }

Defined in: packages/lexical/src/LexicalNode.ts:292

This is the type of LexicalNode.$config() that can be overridden by subclasses.

Concrete nodes are keyed by their string type. An abstract base class (such as ElementNode or DecoratorNode) has no concrete node type, so when it needs to declare configuration that is shared with its concrete subclasses (for example required RequiredNodeStateConfig state or a $transform) it is keyed instead by a well-known symbol, by convention Symbol.for(<NodeClassName>) (e.g. Symbol.for('ElementNode')). The descriptive, globally-registered symbol keeps the config easy to find in a debugger and can never collide with a real node type.


CaretDirection​

CaretDirection = "next" | "previous"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:23

The direction of a caret, 'next' points towards the end of the document and 'previous' points towards the beginning


CaretType​

CaretType = "sibling" | "child"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:33

A sibling caret type points from a LexicalNode origin to its next or previous sibling, and a child caret type points from an ElementNode origin to its first or last child.


CommandListener​

CommandListener<P> = (payload, editor) => boolean

Defined in: packages/lexical/src/LexicalEditor.ts:626

Type Parameters​

P​

P

Parameters​

payload​

P

editor​

LexicalEditor

Returns​

boolean


CommandListenerPriority​

CommandListenerPriority = 0 | 1 | 2 | 3 | 4

Defined in: packages/lexical/src/LexicalEditor.ts:635


CommandListenerPriorityBefore​

CommandListenerPriorityBefore = typeof COMMAND_PRIORITY_BEFORE_CRITICAL | typeof COMMAND_PRIORITY_BEFORE_EDITOR | typeof COMMAND_PRIORITY_BEFORE_HIGH | typeof COMMAND_PRIORITY_BEFORE_LOW | typeof COMMAND_PRIORITY_BEFORE_NORMAL

Defined in: packages/lexical/src/LexicalEditor.ts:636


CommandPayloadArgs​

CommandPayloadArgs<TPayload> = [TPayload extends undefined ? true : never] extends [never] ? [TPayload] : [TPayload]

Defined in: packages/lexical/src/LexicalEditor.ts:726

Type Parameters​

TPayload​

TPayload


CommandPayloadType​

CommandPayloadType<TCommand> = TCommand extends LexicalCommand<infer TPayload> ? TPayload : never

Defined in: packages/lexical/src/LexicalEditor.ts:723

Type helper for extracting the payload type from a command.

Type Parameters​

TCommand​

TCommand extends AnyLexicalCommand

Example​

const MY_COMMAND = createCommand<SomeType>();

// ...

editor.registerCommand(MY_COMMAND, payload => {
// Type of `payload` is inferred here. But lets say we want to extract a function to delegate to
$handleMyCommand(editor, payload);
return true;
});

function $handleMyCommand(editor: LexicalEditor, payload: CommandPayloadType<typeof MY_COMMAND>) {
// `payload` is of type `SomeType`, extracted from the command.
}

CommonAncestorResult​

CommonAncestorResult<A, B> = CommonAncestorResultSame<A> | CommonAncestorResultAncestor<A & ElementNode> | CommonAncestorResultDescendant<B & ElementNode> | CommonAncestorResultBranch<A, B>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1375

The result of comparing two nodes that share some common ancestor

Type Parameters​

A​

A extends LexicalNode

B​

B extends LexicalNode


DOMChildConversion​

DOMChildConversion = (lexicalNode, parentLexicalNode) => LexicalNode | null | undefined

Defined in: packages/lexical/src/LexicalNode.ts:864

Parameters​

lexicalNode​

LexicalNode

parentLexicalNode​

LexicalNode | null | undefined

Returns​

LexicalNode | null | undefined


DOMConversion​

DOMConversion<T> = object

Defined in: packages/lexical/src/LexicalNode.ts:855

Type Parameters​

T​

T extends HTMLElement = HTMLElement

Properties​

conversion​

conversion: DOMConversionFn<T>

Defined in: packages/lexical/src/LexicalNode.ts:856

priority?​

optional priority?: 0 | 1 | 2 | 3 | 4

Defined in: packages/lexical/src/LexicalNode.ts:857


DOMConversionFn​

DOMConversionFn<T> = (element) => DOMConversionOutput | null

Defined in: packages/lexical/src/LexicalNode.ts:860

Type Parameters​

T​

T extends HTMLElement = HTMLElement

Parameters​

element​

T

Returns​

DOMConversionOutput | null


DOMConversionMap​

DOMConversionMap<T> = Record<NodeName, DOMConversionProp<T>>

Defined in: packages/lexical/src/LexicalNode.ts:869

Type Parameters​

T​

T extends HTMLElement = HTMLElement


DOMConversionOutput​

DOMConversionOutput = object

Defined in: packages/lexical/src/LexicalNode.ts:875

Properties​

after?​

optional after?: (childLexicalNodes) => LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:876

Parameters​
childLexicalNodes​

LexicalNode[]

Returns​

LexicalNode[]

forChild?​

optional forChild?: DOMChildConversion

Defined in: packages/lexical/src/LexicalNode.ts:877

node​

node: null | LexicalNode | LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:878


DOMConversionProp​

DOMConversionProp<T> = (node) => DOMConversion<T> | null

Defined in: packages/lexical/src/LexicalNode.ts:832

Type Parameters​

T​

T extends HTMLElement

Parameters​

node​

T

Returns​

DOMConversion<T> | null


DOMConversionPropByTagName​

DOMConversionPropByTagName<K> = DOMConversionProp<K extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[K] : HTMLElement>

Defined in: packages/lexical/src/LexicalNode.ts:836

Type Parameters​

K​

K extends string


DOMConversionTagNameMap​

DOMConversionTagNameMap<K> = { [NodeName in K]?: DOMConversionPropByTagName<NodeName> }

Defined in: packages/lexical/src/LexicalNode.ts:840

Type Parameters​

K​

K extends string


DOMExportOutputMap​

DOMExportOutputMap = Map<Klass<LexicalNode>, (editor, target) => DOMExportOutput>

Defined in: packages/lexical/src/LexicalNode.ts:881


DOMSlotForNode​

DOMSlotForNode<N> = N extends ElementNode ? ElementDOMSlot<HTMLElement> : DOMSlot<HTMLElement>

Defined in: packages/lexical/src/LexicalEditor.ts:382

Experimental

The slot type produced by $getDOMSlot for a given node, narrowed via the node's static class: ElementNode resolves to ElementDOMSlot (with children-management methods), other nodes to the base DOMSlot. Callers passing a known node type get the narrowed slot without manual instanceof checks.

Type Parameters​

N​

N extends LexicalNode


EditableListener​

EditableListener = (editable) => void | (() => void)

Defined in: packages/lexical/src/LexicalEditor.ts:633

A listener that is called when LexicalEditor.setEditable changes the editable state of the editor. If this callback returns a function, that function will be called before the next value update or unregister.

Parameters​

editable​

boolean

Returns​

void | (() => void)


EditorReadMode​

EditorReadMode = "force-commit" | "pending" | "latest"

Defined in: packages/lexical/src/LexicalEditor.ts:173

Controls which editor state LexicalEditor.read observes and whether pending updates are flushed before the read.

  • 'force-commit' (the default) flushes any pending updates immediately before the read, so it always observes a fully committed and reconciled state.
  • 'pending' reads the pending state if it exists, otherwise the committed state, without flushing. This is safe to call when an update may already be in progress at the cost of possibly observing an uncommitted state before node transforms, DOM reconciliation, etc. have run.
  • 'latest' reads the latest committed state without flushing pending updates, equivalent to editor.getEditorState().read(callbackFn, {editor}).

EditorSetOptions​

EditorSetOptions = object

Defined in: packages/lexical/src/LexicalEditor.ts:155

Properties​

tag?​

optional tag?: string

Defined in: packages/lexical/src/LexicalEditor.ts:156


EditorThemeClassName​

EditorThemeClassName = string

Defined in: packages/lexical/src/LexicalEditor.ts:111


EditorUpdateOptions​

EditorUpdateOptions = object

Defined in: packages/lexical/src/LexicalEditor.ts:130

Properties​

discrete?​

optional discrete?: true

Defined in: packages/lexical/src/LexicalEditor.ts:150

If true, prevents this update from being batched, forcing it to run synchronously.

onUpdate?​

optional onUpdate?: () => void

Defined in: packages/lexical/src/LexicalEditor.ts:134

A function to run once the update is complete. See also $onUpdate.

Returns​

void

skipTransforms?​

optional skipTransforms?: true

Defined in: packages/lexical/src/LexicalEditor.ts:140

Setting this to true will suppress all node transforms for this update cycle. Useful for synchronizing updates in some cases.

tag?​

optional tag?: UpdateTag | UpdateTag[]

Defined in: packages/lexical/src/LexicalEditor.ts:145

A tag to identify this update, in an update listener, for instance. See also $addUpdateTag.


ElementFormatType​

ElementFormatType = "left" | "start" | "center" | "right" | "end" | "justify" | ""

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:195


ElementPoint​

ElementPoint = object

Defined in: packages/lexical/src/LexicalSelection.ts:143

Properties​

_selection​

_selection: BaseSelection

Defined in: packages/lexical/src/LexicalSelection.ts:144

getNode​

getNode: () => ElementNode

Defined in: packages/lexical/src/LexicalSelection.ts:145

Returns​

ElementNode

is​

is: (point) => boolean

Defined in: packages/lexical/src/LexicalSelection.ts:146

Parameters​
point​

PointType

Returns​

boolean

isBefore​

isBefore: (point) => boolean

Defined in: packages/lexical/src/LexicalSelection.ts:147

Parameters​
point​

PointType

Returns​

boolean

key​

key: NodeKey

Defined in: packages/lexical/src/LexicalSelection.ts:148

offset​

offset: number

Defined in: packages/lexical/src/LexicalSelection.ts:149

set​

set: (key, offset, type, onlyIfChanged?) => void

Defined in: packages/lexical/src/LexicalSelection.ts:150

Parameters​
key​

NodeKey

offset​

number

type​

"text" | "element"

onlyIfChanged?​

boolean

Returns​

void

type​

type: "element"

Defined in: packages/lexical/src/LexicalSelection.ts:156


EventHandler​

EventHandler = (event, editor) => void

Defined in: packages/lexical/src/LexicalEvents.ts:2015

Parameters​

event​

Event

editor​

LexicalEditor

Returns​

void


EventListenerMap​

EventListenerMap<T> = { [K in keyof EventMapOf<T>]?: (this: T, ev: EventMapOf<T>[K]) => unknown }

Defined in: packages/lexical/src/utils/registerEventListeners.ts:17

A map of event type to listener for a given EventTarget. Each listener's event argument is inferred from the event type, e.g. for an HTMLElement the 'keydown' listener receives a KeyboardEvent.

Type Parameters​

T​

T extends EventTarget


ExtensionConfigBase​

ExtensionConfigBase = Record<never, never>

Defined in: packages/lexical/src/extension-core/types.ts:32

The default extension configuration of an empty object


FlipDirection​

FlipDirection<D> = typeof FLIP_DIRECTION[D]

Defined in: packages/lexical/src/caret/LexicalCaret.ts:27

A type utility to flip next and previous

Type Parameters​

D​

D extends CaretDirection


HTMLConfig​

HTMLConfig = object

Defined in: packages/lexical/src/LexicalEditor.ts:363

Properties​

export?​

optional export?: DOMExportOutputMap

Defined in: packages/lexical/src/LexicalEditor.ts:364

import?​

optional import?: DOMConversionMap

Defined in: packages/lexical/src/LexicalEditor.ts:365


InitialEditorStateType​

InitialEditorStateType = null | string | EditorState | ((editor) => void)

Defined in: packages/lexical/src/extension-core/types.ts:358

All of the possible ways to initialize $initialEditorState:

  • null an empty state, the default
  • string an EditorState serialized to JSON
  • EditorState an EditorState that has been deserialized already (not just parsed JSON)
  • ((editor: LexicalEditor) => void) A function that is called with the editor for you to mutate it

InnerSerializationSchema​

InnerSerializationSchema = SerializationSchema<unknown, never, unknown>

Defined in: packages/lexical/src/LexicalSchema.ts:1097

A SerializationSchema that names no accessor: what every combinator takes (see withAccessors), and what every inner, item and members in a schema's meta is, so a schema reached through those can be wrapped again as it is. A fields record is not: see SerializationSchemaFields.


InnerSerializationSchemaFields​

InnerSerializationSchemaFields = object

Defined in: packages/lexical/src/LexicalSchema.ts:1139

The record objectValue takes: fields that name no accessor, since an object's field is not a node's property (see withAccessors).

Index Signature​

[key: string]: InnerSerializationSchema


KeyboardEventModifierMask​

KeyboardEventModifierMask = { [K in Exclude<keyof KeyboardEventModifiers, "key" | "code">]?: boolean | "any" }

Defined in: packages/lexical/src/LexicalUtils.ts:1194

A record of keyboard modifiers that must be enabled. If the value is 'any' then the modifier key's state is ignored. If the value is true then the modifier key must be pressed. If the value is false or the property is omitted then the modifier key must not be pressed.


KeyboardEventModifiers​

KeyboardEventModifiers = Pick<KeyboardEvent, "key" | "code" | "metaKey" | "ctrlKey" | "shiftKey" | "altKey">

Defined in: packages/lexical/src/LexicalUtils.ts:1182

A KeyboardEvent or structurally similar object with a string key as well as altKey, ctrlKey, metaKey, and shiftKey boolean properties.


Klass​

Klass<T> = InstanceType<T["constructor"]> extends T ? T["constructor"] : GenericConstructor<T> & T["constructor"]

Defined in: packages/lexical/src/LexicalEditor.ts:106

Type Parameters​

T​

T extends LexicalNode


KlassConstructor​

KlassConstructor<Cls> = GenericConstructor<InstanceType<Cls>> & { [k in keyof Cls]: Cls[k] }

Defined in: packages/lexical/src/LexicalEditor.ts:101

Type Parameters​

Cls​

Cls extends GenericConstructor<any>


LexicalExportJSON​

LexicalExportJSON<T> = Prettify<Omit<LexicalFullExportJSON<T>, "type" | "version"> & object & NodeStateJSON<T>>

Defined in: packages/lexical/src/LexicalNode.ts:514

Type Parameters​

T​

T extends LexicalNode


LexicalExtensionArgument​

LexicalExtensionArgument<Config, Name, Output, Init> = LexicalExtension<Config, Name, Output, Init> | NormalizedLexicalExtensionArgument<Config, Name, Output, Init>

Defined in: packages/lexical/src/extension-core/types.ts:146

A LexicalExtension or NormalizedLexicalExtensionArgument (extension with config overrides)

Type Parameters​

Config​

Config extends ExtensionConfigBase

Name​

Name extends string

Output​

Output

Init​

Init


LexicalExtensionConfig​

LexicalExtensionConfig<Extension> = NonNullable<Extension[configTypeSymbol]>

Defined in: packages/lexical/src/extension-core/types.ts:299

Extract the Config type from an Extension

Type Parameters​

Extension​

Extension extends AnyLexicalExtension


LexicalExtensionInit​

LexicalExtensionInit<Extension> = NonNullable<Extension[initTypeSymbol]>

Defined in: packages/lexical/src/extension-core/types.ts:317

Extract the Init type from an Extension

Type Parameters​

Extension​

Extension extends AnyLexicalExtension


LexicalExtensionName​

LexicalExtensionName<Extension> = Extension["name"]

Defined in: packages/lexical/src/extension-core/types.ts:305

Extract the Name type from an Extension

Type Parameters​

Extension​

Extension extends AnyLexicalExtension


LexicalExtensionOutput​

LexicalExtensionOutput<Extension> = NonNullable<Extension[outputTypeSymbol]>

Defined in: packages/lexical/src/extension-core/types.ts:311

Extract the Output type from an Extension

Type Parameters​

Extension​

Extension extends AnyLexicalExtension


LexicalNodeConfig​

LexicalNodeConfig = Klass<LexicalNode> | LexicalNodeReplacement

Defined in: packages/lexical/src/LexicalEditor.ts:371

A LexicalNode class or LexicalNodeReplacement configuration


LexicalNodeReplacement​

LexicalNodeReplacement = object

Defined in: packages/lexical/src/LexicalEditor.ts:339

Configuration entry passed in CreateEditorArgs.nodes to substitute a core node class with a custom subclass. The replacement class itself must also appear in nodes.

See Node Replacement.

Properties​

replace​

replace: Klass<LexicalNode>

Defined in: packages/lexical/src/LexicalEditor.ts:343

The core node class whose instances should be replaced.

with​

with: <T>(node) => LexicalNode

Defined in: packages/lexical/src/LexicalEditor.ts:350

Called by the $create* factories for replace with the freshly-constructed original. Returns the substitute node, which must be an instance of withKlass when set.

Type Parameters​
T​

T extends (...args) => any

Parameters​
node​

InstanceType<T>

Returns​

LexicalNode

withKlass?​

optional withKlass?: Klass<LexicalNode>

Defined in: packages/lexical/src/LexicalEditor.ts:360

The replacement class returned by with. Must extend replace. When set, LexicalEditor.registerNodeTransform and LexicalEditor.registerMutationListener subscriptions registered against replace also fire for the replacement. Will be required in a future version.


LexicalParseJSON​

LexicalParseJSON<S> = Pick<SerializedPartial<S>, Extract<keyof SerializedPartial<S>, typeof NODE_STATE_KEY | "$slots">> & { [K in keyof Omit<SerializedPartial<S>, "$slots" | "children" | "type" | typeof NODE_STATE_KEY | "version">]?: unknown }

Defined in: packages/lexical/src/LexicalNode.ts:690

The shape LexicalNode.updateFromJSON accepts for a node whose serialized type is S, as a schema-driven parser faces it: every node-specific property optional (a compact export omits a default-valued one, and an older document predates a newer one) and unknown, with type, version and children dropped.

unknown, because this is the untrusted-JSON boundary and a parser here is total: it validates every property against the schema's domain and substitutes a default for anything outside it. Typing a property as what it parses to would claim the caller has already done that validation, which is both untrue and narrower than what is accepted — a schema reads more than it writes wherever it has an alias table or reads a number spelled as a string, so format: 'bold' and width: '640' are valid input that the narrower type rejected. The property names stay, so a misspelled one is still an excess-property error. NodeState and slots keep their declared shapes: neither is a schema-declared property, and each is read structurally by the code that applies it rather than validated against a domain.

A node that declares a serialization schema narrows both JSON methods to its own serialized type by declaration merging, which is the one thing a schema cannot do for it:

export interface MarkNode {
exportJSON(compact?: false): SerializedMarkNode;
exportJSON(compact: boolean): SerializedPartial<SerializedMarkNode>;
updateFromJSON(serializedNode: LexicalParseJSON<SerializedMarkNode>): this;
}

A hand-written override that reads its properties typed uses LexicalUpdateJSON instead, as it always has.

Type Parameters​

S​

S extends SerializedLexicalNode


LexicalSchemaInput​

LexicalSchemaInput<T> = GetStaticNodeConfigs<T> extends infer Configs ? Prettify<ComposeSchemaInputs<Configs> & CollectStateInput<CollectStateConfigs<Configs>>> : never

Defined in: packages/lexical/src/LexicalNodeState.ts:292

Every serialized property T accepts, composed across its $config chain — its own and the ones it inherits.

The accepted input rather than the parsed output, which is wider wherever a schema reads more than it writes: a legacy alias, a number spelled as a string, an absent property. That is what a generator of example JSON should say it produces.

Both halves are folded over one binding of GetStaticNodeConfigs — the chain walk NodeState already runs for its own configs — so nothing here can disagree with getComposedSchemaFields about which classes are in a node's chain. That walk follows each config's extends, which is why every config in the tree names one: the runtime defaults it to the superclass, but the type has no way to recover what was left out, and a class that omits it contributes only its own declarations and hides its ancestors'.

The walk is the only bound on chain depth, shared with GetNodeStateConfig and reached in the hundreds rather than the sixteen an earlier bound here allowed; the fold itself is tail-recursive and adds none.

Type Parameters​

T​

T extends LexicalNode


LexicalUpdateJSON​

LexicalUpdateJSON<T> = Omit<T, "children" | "type" | "version">

Defined in: packages/lexical/src/LexicalNode.ts:535

Omit the children, type, and version properties from the given SerializedLexicalNode definition.

This is the shape a hand-written updateFromJSON override reads: each property keeps its declared type. The parser behind a serialization schema faces wider input than that — see LexicalParseJSON.

Type Parameters​

T​

T extends SerializedLexicalNode


MemberOf​

MemberOf<N> = TaggedNamesOf<N> | ObligationsOf<N> | `declared:${"get" | "set"}` | `derived:${"get" | "set"}`

Defined in: packages/lexical/src/LexicalSchema.ts:467

Every member of N a schema may name: its own fields (__-prefixed by convention, which is what makes them distinguishable) and its methods, which covers accessors and when predicates alike.

This is what $config checks a node's schema against, so a field, getter, setter or when naming something the node does not have is a compile error at the declaration rather than a property that silently stops round-tripping.

Type Parameters​

N​

N


MutationListener​

MutationListener = (nodes, payload) => void

Defined in: packages/lexical/src/LexicalEditor.ts:617

Parameters​

nodes​

Map<NodeKey, NodeMutation>

payload​
dirtyLeaves​

Set<string>

prevEditorState​

EditorState

updateTags​

Set<string>

Returns​

void


NamesOf​

NamesOf<S> = S extends SerializationSchema<unknown, infer Decls, unknown> ? Decls : never

Defined in: packages/lexical/src/LexicalSchema.ts:857

The members a schema's declarations name; see MemberOf.

Type Parameters​

S​

S


NodeCaret​

NodeCaret<D> = SiblingCaret<LexicalNode, D> | ChildCaret<ElementNode, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:152

A NodeCaret is the combination of an origin node and a direction that points towards where a connected node will be fetched, inserted, or replaced. A SiblingCaret points from a node to its next or previous sibling, and a ChildCaret points to its first or last child (using next or previous as direction, for symmetry with SiblingCaret).

The differences between NodeCaret and PointType are:

  • NodeCaret can only be used to refer to an entire node (PointCaret is used when a full analog is needed). A PointType of text type can be used to refer to a specific location inside of a TextNode.
  • NodeCaret stores an origin node, type (sibling or child), and direction (next or previous). A PointType stores a type (text or element), the key of a node, and a text or child offset within that node.
  • NodeCaret is directional and always refers to a very specific node, eliminating all ambiguity. PointType can refer to the location before or at a node depending on context.
  • NodeCaret is more robust to nearby mutations, as it relies only on a node's direct connections. An element Any change to the count of previous siblings in an element PointType will invalidate it.
  • NodeCaret is designed to work more directly with the internal representation of the document tree, making it suitable for use in traversals without performing any redundant work.

The caret does not update in response to any mutations, you should not persist it across editor updates, and using a caret after its origin node has been removed or replaced may result in runtime errors.

Type Parameters​

D​

D extends CaretDirection = CaretDirection


NodeKey​

NodeKey = string

Defined in: packages/lexical/src/LexicalNode.ts:919


NodeMap​

NodeMap = Map<NodeKey, LexicalNode>

Defined in: packages/lexical/src/LexicalNode.ts:87


NodeMutation​

NodeMutation = "created" | "updated" | "destroyed"

Defined in: packages/lexical/src/LexicalEditor.ts:529


NodeStateJSON​

NodeStateJSON<T> = Prettify<object & CollectStateJSON<GetNodeStateConfig<T>, true>>

Defined in: packages/lexical/src/LexicalNodeState.ts:307

The NodeState JSON produced by this LexicalNode

Type Parameters​

T​

T extends LexicalNode


NodeStateVersion​

NodeStateVersion = typeof NODE_STATE_DIRECT | typeof NODE_STATE_LATEST

Defined in: packages/lexical/src/LexicalNodeState.ts:54


NormalizedLexicalExtensionArgument​

NormalizedLexicalExtensionArgument<Config, Name, Output, Init> = [LexicalExtension<Config, Name, Output, Init>, ...Partial<Config>[]]

Defined in: packages/lexical/src/extension-core/types.ts:48

A tuple of [extension, ...configOverrides]

Type Parameters​

Config​

Config extends ExtensionConfigBase

Name​

Name extends string

Output​

Output

Init​

Init


NormalizedPeerDependency​

NormalizedPeerDependency<Extension> = [Extension["name"], Partial<LexicalExtensionConfig<Extension>>] & object

Defined in: packages/lexical/src/extension-core/types.ts:40

The result of declarePeerDependency, a tuple of a peer dependency name and its associated configuration. The configuration is an optional element rather than a required one that may be undefined, so a declaration without a config is [name] — every consumer destructures the tuple, and this is what lets the build inline the call to its arguments.

Type Declaration​

[peerDependencySymbol]?​

readonly optional [peerDependencySymbol]?: Extension

Type Parameters​

Extension​

Extension extends AnyLexicalExtension


OutputComponentExtension​

OutputComponentExtension<ComponentType> = OutputExtension<{ Component: ComponentType; }>

Defined in: packages/lexical/src/extension-core/types.ts:323

An Extension that has an OutputComponent of the given type (e.g. React.ComponentType)

Type Parameters​

ComponentType​

ComponentType


OutputExtension​

OutputExtension<Output> = LexicalExtension<any, any, Output, any>

Defined in: packages/lexical/src/extension-core/types.ts:330

An Extension that has an Output of the given type

Type Parameters​

Output​

Output


ParsableSerializedNode​

ParsableSerializedNode = object

Defined in: packages/lexical/src/LexicalNode.ts:643

The least a value has to be for $parseSerializedNode to read it: a type to look the class up by, and subtrees of the same shape.

A type alias rather than an interface, which is what lets it stand in for the internal shape the parse walks: TypeScript gives an alias an implicit index signature and an interface none, and the walk's own parameter carries one. An interface is still assignable to it, which is the direction that matters for a caller like @lexical/clipboard's BaseSerializedNode.

version is optional because the parser drops it — it is deprecated and nothing reads it — so requiring it described the caller rather than the parameter. That mattered because SerializedPartialNode carries an index signature, which an interface never satisfies, and SerializedLexicalNode requires version: a caller holding an interface with an optional version, such as @lexical/clipboard's BaseSerializedNode, matched neither, and the mismatch repeated at every level because children and $slots recurse.

Properties​

$slots?​

optional $slots?: Record<string, ParsableSerializedNode>

Defined in: packages/lexical/src/LexicalNode.ts:645

A slot holds a node subtree, so it relaxes exactly as children do.

children?​

optional children?: ParsableSerializedNode[]

Defined in: packages/lexical/src/LexicalNode.ts:647

Present when the node is an element; the same form all the way down.

type​

type: string

Defined in: packages/lexical/src/LexicalNode.ts:649

The one property every node carries and a reader narrows by.

version?​

optional version?: number

Defined in: packages/lexical/src/LexicalNode.ts:653

Deprecated​

Dropped when parsing; see SerializedLexicalNode.version.


Parse​

Parse<T> = (value) => T

Defined in: packages/lexical/src/LexicalSchema.ts:48

A function that validates an untrusted value (such as a property parsed from JSON) and coerces it into the expected type T, returning a default value when value is not in the expected domain.

By convention — and exactly like the parse of StateValueConfig — calling a Parse with undefined returns its default value.

Type Parameters​

T​

T

Parameters​

value​

unknown

Returns​

T


PasteCommandType​

PasteCommandType = ClipboardEvent | InputEvent | KeyboardEvent

Defined in: packages/lexical/src/LexicalCommands.ts:15


PointCaret​

PointCaret<D> = TextPointCaret<TextNode, D> | SiblingCaret<LexicalNode, D> | ChildCaret<ElementNode, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:168

A PointCaret is a NodeCaret that also includes a TextPointCaret type which refers to a specific offset of a TextNode. This type is separate because it is not relevant to general node traversal so it doesn't make sense to have it show up except when defining a CaretRange and in those cases there will be at most two of them only at the boundaries.

The addition of TextPointCaret allows this type to represent any location that is representable by PointType, as the TextPointCaret refers to a specific offset within a TextNode.

Type Parameters​

D​

D extends CaretDirection = CaretDirection


PointType​

PointType = TextPoint | ElementPoint

Defined in: packages/lexical/src/LexicalSelection.ts:159


RootListener​

RootListener = (rootElement, prevRootElement) => void | (() => void)

Defined in: packages/lexical/src/LexicalEditor.ts:610

A listener that is called when LexicalEditor.setRootElement changes the element that the editor is attached to. If this callback returns a function, that function will be called before the next value update or unregister.

Parameters​

rootElement​

null | HTMLElement

prevRootElement​

null | HTMLElement

Returns​

void | (() => void)


RootMode​

RootMode = "root" | "shadowRoot"

Defined in: packages/lexical/src/caret/LexicalCaret.ts:40

The RootMode is specified in all caret traversals where the traversal can go up towards the root. 'root' means that it will stop at the document root, and 'shadowRoot' will stop at the document root or any shadow root (per $isRootOrShadowRoot).


SchemaAccessor​

SchemaAccessor = string | SchemaField | null

Defined in: packages/lexical/src/LexicalSchema.ts:405

One direction of a SerializationSchema field: a method name, a SchemaField naming a node field, or null for a direction that is deliberately unsupported.


SchemaField​

SchemaField = SchemaGetterField | SchemaSetterField

Defined in: packages/lexical/src/LexicalSchema.ts:398

A node field in whichever direction it was declared for. Prefer the direction-specific types when the direction is known — this union admits both tables, so it cannot reject the one that does not belong.


SchemaGetterAccessor​

SchemaGetterAccessor = string | SchemaGetterField | null

Defined in: packages/lexical/src/LexicalSchema.ts:408

How the export direction reaches a property.


SchemaInput​

SchemaInput<S> = S extends SerializationSchema<unknown, unknown, infer In> ? In : S extends NodeSerializationSchema<never, infer In> ? In : never

Defined in: packages/lexical/src/LexicalSchema.ts:1107

The serialized values a schema accepts; see SerializationSchema and its In parameter.

Type Parameters​

S​

S


SchemaSetterAccessor​

SchemaSetterAccessor = string | SchemaSetterField | null

Defined in: packages/lexical/src/LexicalSchema.ts:411

How the import direction reaches a property.


SerializationSchemaFields​

SerializationSchemaFields = object

Defined in: packages/lexical/src/LexicalSchema.ts:1131

A record of named SerializationSchemas: what an object schema's meta holds in fields. A nodeSchema is an object schema whose fields name accessors and an objectValue is one whose fields do not, and the meta of the two is one type — so a field read back from it may name one, and its type says so.

Index Signature​

[key: string]: AnySerializationSchema


SerializationSchemaMeta​

SerializationSchemaMeta = { kind: "string"; } | { clamp?: boolean; integer?: boolean; kind: "number"; max?: number; min?: number; } | { kind: "boolean"; } | { kind: "enum"; values: readonly unknown[]; } | { item: InnerSerializationSchema; kind: "array"; } | { defaultAsNull?: boolean; inner: InnerSerializationSchema; kind: "nullable"; } | { inner: InnerSerializationSchema; kind: "optional"; omitDefault?: boolean; } | { kind: "union"; members: readonly InnerSerializationSchema[]; } | { kind: "raw"; } | { fields: SerializationSchemaFields; kind: "object"; } | { aliases: {[alias: string]: unknown; }; inner: InnerSerializationSchema; kind: "aliased"; } | { inner: InnerSerializationSchema; kind: "transform"; }

Defined in: packages/lexical/src/LexicalSchema.ts:58

A structural, introspectable description of a SerializationSchema. It carries exactly the information needed to coerce a value (which the schema closes over) so that tooling can also walk it — for example to derive a fast-check arbitrary that generates example values, or to emit a JSON Schema document. The data here is the same domain information the parser already needs, so making it available costs (almost) nothing in the production bundle.

Union Members​

Type Literal​

{ kind: "string"; }


Type Literal​

{ clamp?: boolean; integer?: boolean; kind: "number"; max?: number; min?: number; }

clamp?​

readonly optional clamp?: boolean

Whether a finite value outside the bounds clamps to the nearest.

integer?​

readonly optional integer?: boolean

Whether the domain is restricted to integers.

kind​

readonly kind: "number"

max?​

readonly optional max?: number

The inclusive upper bound of the domain, when constrained.

min?​

readonly optional min?: number

The inclusive lower bound of the domain, when constrained.


Type Literal​

{ kind: "boolean"; }


Type Literal​

{ kind: "enum"; values: readonly unknown[]; }


Type Literal​

{ item: InnerSerializationSchema; kind: "array"; }


Type Literal​

{ defaultAsNull?: boolean; inner: InnerSerializationSchema; kind: "nullable"; }

defaultAsNull?​

readonly optional defaultAsNull?: boolean

Whether a value equal to inner's default is treated as null.

inner​

readonly inner: InnerSerializationSchema

kind​

readonly kind: "nullable"


Type Literal​

{ inner: InnerSerializationSchema; kind: "optional"; omitDefault?: boolean; }

inner​

readonly inner: InnerSerializationSchema

kind​

readonly kind: "optional"

omitDefault?​

readonly optional omitDefault?: boolean

Whether a value equal to inner's default is treated as absent.


Type Literal​

{ kind: "union"; members: readonly InnerSerializationSchema[]; }


Type Literal​

{ kind: "raw"; }


Type Literal​

{ fields: SerializationSchemaFields; kind: "object"; }


Type Literal​

{ aliases: {[alias: string]: unknown; }; inner: InnerSerializationSchema; kind: "aliased"; }

aliases​

readonly aliases: object

Legacy input spellings, mapped to the value each denotes.

Index Signature​

[alias: string]: unknown

inner​

readonly inner: InnerSerializationSchema

kind​

readonly kind: "aliased"


Type Literal​

{ inner: InnerSerializationSchema; kind: "transform"; }

inner​

readonly inner: InnerSerializationSchema

kind​

readonly kind: "transform"

A transformValue: inner's domain on the way in, and an opaque function on the way out.

The kind exists to say that last part. The transform is an arbitrary closure, so it is the one part of a schema that cannot be described structurally, and a consumer that walked into inner and stopped — which is what inheriting inner's meta made every consumer do — would be describing the schema's input while believing it had described its output. For a generator of example inputs that is the right answer; for a code generator it is a parse that silently drops the transform.


SerializationSchemaShape​

SerializationSchemaShape<T> = { readonly [K in keyof T]-?: SerializationSchema<T[K], never, unknown> }

Defined in: packages/lexical/src/LexicalSchema.ts:1156

Maps an object type T to the record of per-property SerializationSchemas.

The input domain is left open. A schema's In is what it accepts, which is wider than what it produces wherever a schema reads more than it writes — numberValue() is a SerializationSchema<number, never, number | string>, since a stringified number is a value it reads. Pinning In to T[K] made this type reject the combinator for the very type it names: a SerializationSchemaShape<{count: number}> would not accept {count: numberValue()}. What the shape is for is saying what each property parses to, which is the T[K] above.

Type Parameters​

T​

T


SerializationSchemaValue​

SerializationSchemaValue<S> = S extends SerializationSchema<infer T, unknown, unknown> ? T : never

Defined in: packages/lexical/src/LexicalSchema.ts:1121

The value type a SerializationSchema parses to.

Type Parameters​

S​

S


SerializedEditor​

SerializedEditor = object

Defined in: packages/lexical/src/LexicalEditor.ts:770

Properties​

editorState​

editorState: CompactSerializedEditorState

Defined in: packages/lexical/src/LexicalEditor.ts:777

Typed as the compact shape because LexicalEditor.toJSON writes whichever form encloses it: a nested editor serialized inside a compact document is compact too, so promising the full shape here would promise properties that are not there. Both forms satisfy this, and both parse.


SerializedElementNode​

SerializedElementNode = Spread<{ children: SerializedLexicalNode[]; direction: "ltr" | "rtl" | null; format: ElementFormatType; indent: number; textFormat?: number; textStyle?: string; }, SerializedLexicalNode>

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:81

No type parameter for the children: a node cannot declare what kind of children it accepts, so any node may appear under any element and SerializedLexicalNode is the only type this can honestly give them. The parameter that used to be here promised a narrowing nothing enforces.


SerializedLexicalNode​

SerializedLexicalNode = object

Defined in: packages/lexical/src/LexicalNode.ts:92

The base type for all serialized nodes

Properties​

$?​

optional $?: Record<string, unknown>

Defined in: packages/lexical/src/LexicalNode.ts:112

Any state persisted with the NodeState API that is not configured for flat storage

$slots?​

optional $slots?: Record<string, SerializedLexicalNode>

Defined in: packages/lexical/src/LexicalNode.ts:121

Experimental

Named slot subtrees keyed by slot name. Present on host nodes (an ElementNode or DecoratorNode that registered slots via $setSlot). The $ prefix keeps the framework-owned key out of the namespace a third-party subclass may already use for its own serialized slots property (mirroring the reserved NodeState '$' key). named-slots

type​

type: string

Defined in: packages/lexical/src/LexicalNode.ts:94

The type string used by the Node class

version​

version: number

Defined in: packages/lexical/src/LexicalNode.ts:107

Deprecated​

A numeric schema version. Nothing reads it — parsing ignores it entirely — and nothing should.

exportJSON() still writes it as 1 so the output stays readable by older versions, which is the only reason it remains, and it stays required here so that the legacy form promises what it actually writes. The two places it is genuinely absent relax it themselves: a compact export omits it along with everything else parsing restores on its own (see SerializedPartial), and the parse shapes drop it outright (see LexicalUpdateJSON).


SerializedLineBreakNode​

SerializedLineBreakNode = SerializedLexicalNode

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:24


SerializedParagraphNode​

SerializedParagraphNode = Spread<{ textFormat: number; textStyle: string; }, SerializedElementNode>

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:43


SerializedPartial​

SerializedPartial<T> = Omit<SerializedLexicalNode & Partial<T>, "$slots" | "children" | "version"> & object & T extends object ? object : unknown

Defined in: packages/lexical/src/LexicalNode.ts:557

The serialized form of a node as accepted by the parsing methods (LexicalNode.importJSON and LexicalNode.updateFromJSON).

Only type identifies the node here: every node-specific property is made optional via Partial. Parsing is generally untrusted and must tolerate missing or out-of-domain values, so implementations are expected to substitute sensible defaults — see the Parse helpers such as stringValue, numberValue, and enumValue. This also enables a "compact" serialization variant in which any property left at its default is omitted.

The deprecated version is relaxed here rather than on SerializedLexicalNode: a compact export omits it, but the legacy form always writes it, and making it optional at the base would take that promise away from the full output type as well.

Type Declaration​

$slots?​

optional $slots?: Record<string, SerializedPartialNode | SerializedLexicalNode>

Slot values are parsed by the same rules, so they relax the same way — and, like the parse entry point, name the declared form too: naming only the indexed SerializedPartialNode meant a slot could not hold a value whose type is a declared interface, since TypeScript gives an interface no implicit index signature.

version?​

optional version?: number

Omitted by a compact export, like every other restorable property.

Type Parameters​

T​

T extends SerializedLexicalNode


SerializedPartialNode​

SerializedPartialNode = object

Defined in: packages/lexical/src/LexicalNode.ts:609

A node of a compact document read without knowing its type, which is every child: a node cannot declare what kind of children it accepts, so any node may appear under any element and there is no type to name their properties from. The outer node of a SerializedPartial is refinable — you know what you asked for — and its children never are.

So the framework properties are named and a node's own arrive as unknown, which a reader narrows by type as it would any untrusted JSON. children and $slots recurse, because a compact export applies to a subtree exactly as it does to its root: naming SerializedPartial<SerializedLexicalNode> for them instead would leave a nested element unable to carry the children it has.

The index signature is what lets a document be written. Without it every node-specific property on a child is an excess-property error, so editor.parseEditorState({root: {children: [{children: [{text: 'hi', type: 'text'}], …}], …}}) — a hand-authored initial state, the most ordinary literal a caller writes — does not compile, and neither does a fixture, a migration script, or $parseSerializedNode on a literal. Closing the type was tried for the misspelling it would catch; excess-property checking fires only on fresh literals, and everything arriving at load comes from JSON.parse, so it caught no misspelling that mattered and cost every correct property. Flow's counterpart is inexact for the same reason.

Indexable​

[key: string]: unknown

A node's own properties: there is no type here to name them from.

Properties​

$?​

optional $?: Record<string, unknown>

Defined in: packages/lexical/src/LexicalNode.ts:615

Node state, parsed by the same rules whatever the node turns out to be.

$slots?​

optional $slots?: Record<string, SerializedPartialNode | SerializedLexicalNode>

Defined in: packages/lexical/src/LexicalNode.ts:617

A slot holds a node subtree, so it relaxes exactly as children do.

children?​

optional children?: SerializedPartialNode[]

Defined in: packages/lexical/src/LexicalNode.ts:619

Present when the node is an element; the same form all the way down.

type​

type: string

Defined in: packages/lexical/src/LexicalNode.ts:611

The one property every node carries and a reader narrows by.

version?​

optional version?: number

Defined in: packages/lexical/src/LexicalNode.ts:613

Omitted by a compact export, like every other restorable property.


SerializedRootNode​

SerializedRootNode = SerializedElementNode

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:23


SerializedTabNode​

SerializedTabNode = SerializedTextNode

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:31


SerializedTextNode​

SerializedTextNode = Spread<{ detail: number; format: number; mode: TextModeType; style: string; text: string; }, SerializedLexicalNode>

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:88


SlotName​

SlotName<T> = DeclaredSlotNames<T> | string & object

Defined in: packages/lexical/src/LexicalSlot.ts:236

Experimental

Slot-name hint for a host node's slot accessors: the names declared in the host class's $config().slots (for editor autocomplete) unioned with string — every string is still accepted (slots take undeclared names at runtime), the declared names just surface as suggestions. A class declaring no slots, or a subclass that inherits them without redeclaring, resolves to plain string.

Type Parameters​

T​

T extends LexicalNode


Spread​

Spread<T1, T2> = Omit<T2, keyof T1> & T1

Defined in: packages/lexical/src/LexicalEditor.ts:97

Type Parameters​

T1​

T1

T2​

T2


StateConfigKey​

StateConfigKey<S> = S extends StateConfig<infer K, infer _V> ? K : never

Defined in: packages/lexical/src/LexicalNodeState.ts:66

Get the key type (K) from a StateConfig

Type Parameters​

S​

S extends AnyStateConfig


StateConfigValue​

StateConfigValue<S> = S extends StateConfig<infer _K, infer V> ? V : never

Defined in: packages/lexical/src/LexicalNodeState.ts:61

Get the value type (V) from a StateConfig

Type Parameters​

S​

S extends AnyStateConfig


StateValueOrUpdater​

StateValueOrUpdater<Cfg> = ValueOrUpdater<StateConfigValue<Cfg>>

Defined in: packages/lexical/src/LexicalNodeState.ts:89

A type alias to make it easier to define setter methods on your node class

Type Parameters​

Cfg​

Cfg extends AnyStateConfig

Example​

const fooState = createState("foo", { parse: ... });
class MyClass extends TextNode {
// ...
setFoo(valueOrUpdater: StateValueOrUpdater<typeof fooState>): this {
return $setState(this, fooState, valueOrUpdater);
}
}

StaticNodeConfig​

StaticNodeConfig<T, Type> = BaseStaticNodeConfig & { readonly [K in Type]?: StaticNodeConfigValue<T, Type> }

Defined in: packages/lexical/src/LexicalNode.ts:301

Used to extract the node and type from a StaticNodeConfigRecord

Type Parameters​

T​

T extends LexicalNode

Type​

Type extends string


TextFormatType​

TextFormatType = "bold" | "underline" | "strikethrough" | "italic" | "highlight" | "code" | "subscript" | "superscript" | "lowercase" | "uppercase" | "capitalize"

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:101


TextModeType​

TextModeType = "normal" | "token" | "segmented"

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:114


TextPoint​

TextPoint = object

Defined in: packages/lexical/src/LexicalSelection.ts:127

Properties​

_selection​

_selection: BaseSelection

Defined in: packages/lexical/src/LexicalSelection.ts:128

getNode​

getNode: () => TextNode

Defined in: packages/lexical/src/LexicalSelection.ts:129

Returns​

TextNode

is​

is: (point) => boolean

Defined in: packages/lexical/src/LexicalSelection.ts:130

Parameters​
point​

PointType

Returns​

boolean

isBefore​

isBefore: (point) => boolean

Defined in: packages/lexical/src/LexicalSelection.ts:131

Parameters​
point​

PointType

Returns​

boolean

key​

key: NodeKey

Defined in: packages/lexical/src/LexicalSelection.ts:132

offset​

offset: number

Defined in: packages/lexical/src/LexicalSelection.ts:133

set​

set: (key, offset, type, onlyIfChanged?) => void

Defined in: packages/lexical/src/LexicalSelection.ts:134

Parameters​
key​

NodeKey

offset​

number

type​

"text" | "element"

onlyIfChanged?​

boolean

Returns​

void

type​

type: "text"

Defined in: packages/lexical/src/LexicalSelection.ts:140


TextPointCaretSliceTuple​

TextPointCaretSliceTuple<D> = readonly [null | TextPointCaretSlice<TextNode, D>, null | TextPointCaretSlice<TextNode, D>]

Defined in: packages/lexical/src/caret/LexicalCaret.ts:373

A utility type to specify that a CaretRange may have zero, one, or two associated TextPointCaretSlice. If the anchor and focus are on the same node, the anchorSlice will contain the slice and focusSlie will be null.

Type Parameters​

D​

D extends CaretDirection


Transform​

Transform<T> = (node) => void

Defined in: packages/lexical/src/LexicalEditor.ts:506

Type Parameters​

T​

T extends LexicalNode

Parameters​

node​

T

Returns​

void


UpdateListener​

UpdateListener = (payload) => void

Defined in: packages/lexical/src/LexicalEditor.ts:599

A listener that gets called after the editor is updated

Parameters​

payload​

UpdateListenerPayload

Returns​

void


UpdateTag​

UpdateTag = typeof COLLABORATION_TAG | typeof CUT_TAG | typeof FOCUS_TAG | typeof HISTORIC_TAG | typeof HISTORY_MERGE_TAG | typeof HISTORY_PUSH_TAG | typeof PASTE_TAG | typeof SKIP_COLLAB_TAG | typeof SKIP_DOM_SELECTION_TAG | typeof SKIP_SCROLL_INTO_VIEW_TAG | typeof COMPOSITION_START_TAG | typeof COMPOSITION_END_TAG | string & object

Defined in: packages/lexical/src/LexicalUpdateTags.ts:89

The set of known update tags to help with TypeScript suggestions.


ValueOrUpdater​

ValueOrUpdater<V> = V | ((prevValue) => V)

Defined in: packages/lexical/src/LexicalNodeState.ts:73

A value type, or an updater for that value type. For use with $setState or any user-defined wrappers around it.

Type Parameters​

V​

V

Variables​

$findMatchingParent​

const $findMatchingParent: {<T>(startingNode, findFn): T | null; (startingNode, findFn): LexicalNode | null; }

Defined in: packages/lexical/src/LexicalUtils.ts:5382

Starts with a node and moves up the tree (toward the root node) to find a matching node based on the search parameters of the findFn. (Consider JavaScripts' .find() function where a testing function must be passed as an argument. eg. if( (node) => node.__type === 'div') ) return true; otherwise return false

Call Signature​

<T>(startingNode, findFn): T | null

Type Parameters​
T​

T extends LexicalNode

Parameters​
startingNode​

LexicalNode

findFn​

(node) => node is T

Returns​

T | null

Call Signature​

(startingNode, findFn): LexicalNode | null

Parameters​
startingNode​

LexicalNode

findFn​

(node) => boolean

Returns​

LexicalNode | null

Param​

startingNode

The node where the search starts.

Param​

findFn

A testing function that returns true if the current node satisfies the testing parameters.

Returns​

startingNode or one of its ancestors that matches the findFn predicate and is not the RootNode, or null if no match was found.


BEFORE_INPUT_COMMAND​

const BEFORE_INPUT_COMMAND: LexicalCommand<InputEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:50

Dispatched on a beforeinput event.


BLUR_COMMAND​

const BLUR_COMMAND: LexicalCommand<FocusEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:286

Dispatched when the editor loses focus.


CAN_REDO_COMMAND​

const CAN_REDO_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:269

Deprecated​

in v0.49.0, use the canRedo signal from HistoryExtension.

A command only reports a change, so a listener registered after the editor is initialized has no way to read the current value. The signal always holds it.

Dispatched when the redo availability changes. Payload is true if redo is available.


CAN_UNDO_COMMAND​

const CAN_UNDO_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:280

Deprecated​

in v0.49.0, use the canUndo signal from HistoryExtension.

A command only reports a change, so a listener registered after the editor is initialized has no way to read the current value. The signal always holds it.

Dispatched when the undo availability changes. Payload is true if undo is available.


CAN_USE_BEFORE_INPUT​

const CAN_USE_BEFORE_INPUT: boolean

Defined in: packages/lexical/src/environment.ts:78

Whether the browser supports the beforeinput event via InputEvent.getTargetRanges().


CAN_USE_DOM​

const CAN_USE_DOM: boolean

Defined in: packages/lexical/src/environment.ts:29

Whether a browser DOM environment is available.


CLEAR_EDITOR_COMMAND​

const CLEAR_EDITOR_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:253

Dispatched to clear all editor content.


CLEAR_HISTORY_COMMAND​

const CLEAR_HISTORY_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:257

Dispatched to clear the undo/redo history stack.


CLICK_COMMAND​

const CLICK_COMMAND: LexicalCommand<MouseEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:47

Dispatched on a mouse click event in the editor.


COLLABORATION_TAG​

const COLLABORATION_TAG: "collaboration" = 'collaboration'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:42

Indicates that the update is related to collaborative editing


COMMAND_PRIORITY_BEFORE_CRITICAL​

const COMMAND_PRIORITY_BEFORE_CRITICAL: -4 = -4

Defined in: packages/lexical/src/LexicalEditor.ts:682

LexicalEditor.registerCommand listener added to the beginning of the critical priority queue (before high, normal, low, editor)


COMMAND_PRIORITY_BEFORE_EDITOR​

const COMMAND_PRIORITY_BEFORE_EDITOR: -8 = -8

Defined in: packages/lexical/src/LexicalEditor.ts:666

LexicalEditor.registerCommand listener added to the beginning of the editor priority queue (after critical, high, normal, low)


COMMAND_PRIORITY_BEFORE_HIGH​

const COMMAND_PRIORITY_BEFORE_HIGH: -5 = -5

Defined in: packages/lexical/src/LexicalEditor.ts:678

LexicalEditor.registerCommand listener added to the beginning of the high priority queue (after critical; before normal, low, editor)


COMMAND_PRIORITY_BEFORE_LOW​

const COMMAND_PRIORITY_BEFORE_LOW: -7 = -7

Defined in: packages/lexical/src/LexicalEditor.ts:670

LexicalEditor.registerCommand listener added to the beginning of the low priority queue (after critical, high, normal; before editor)


COMMAND_PRIORITY_BEFORE_NORMAL​

const COMMAND_PRIORITY_BEFORE_NORMAL: -6 = -6

Defined in: packages/lexical/src/LexicalEditor.ts:674

LexicalEditor.registerCommand listener added to the beginning of the normal priority queue (after critical, high; before low, editor)


COMMAND_PRIORITY_CRITICAL​

const COMMAND_PRIORITY_CRITICAL: 4 = 4

Defined in: packages/lexical/src/LexicalEditor.ts:662

LexicalEditor.registerCommand listener added to the end of the critical priority queue (before high, normal, low, editor)


COMMAND_PRIORITY_EDITOR​

const COMMAND_PRIORITY_EDITOR: 0 = 0

Defined in: packages/lexical/src/LexicalEditor.ts:646

LexicalEditor.registerCommand listener added to the end of the editor priority queue (after critical, high, normal, low)


COMMAND_PRIORITY_HIGH​

const COMMAND_PRIORITY_HIGH: 3 = 3

Defined in: packages/lexical/src/LexicalEditor.ts:658

LexicalEditor.registerCommand listener added to the end of the high priority queue (after critical; before normal, low, editor)


COMMAND_PRIORITY_LOW​

const COMMAND_PRIORITY_LOW: 1 = 1

Defined in: packages/lexical/src/LexicalEditor.ts:650

LexicalEditor.registerCommand listener added to the end of the low priority queue (after critical, high, normal; before editor)


COMMAND_PRIORITY_NORMAL​

const COMMAND_PRIORITY_NORMAL: 2 = 2

Defined in: packages/lexical/src/LexicalEditor.ts:654

LexicalEditor.registerCommand listener added to the end of the normal priority queue (after critical, high; before low, editor)


COMPOSITION_END_COMMAND​

const COMPOSITION_END_COMMAND: LexicalCommand<CompositionEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:60

Dispatched when an IME composition session ends.


COMPOSITION_END_TAG​

const COMPOSITION_END_TAG: "composition-end" = 'composition-end'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:84

The update was triggered by composition-end


COMPOSITION_START_COMMAND​

const COMPOSITION_START_COMMAND: LexicalCommand<CompositionEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:57

Dispatched when an IME composition session starts.


COMPOSITION_START_TAG​

const COMPOSITION_START_TAG: "composition-start" = 'composition-start'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:79

The update was triggered by composition-start


CONTROL_OR_ALT​

const CONTROL_OR_ALT: KeyboardEventModifierMask & KeyboardEventControlOrOther

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:156

The modifier mask for the secondary shortcut modifier: Option (altKey) on Apple platforms and Ctrl elsewhere, conventionally used for word-level editing and block-format shortcuts.


CONTROL_OR_META​

const CONTROL_OR_META: KeyboardEventModifierMask & KeyboardEventControlOrOther

Defined in: packages/lexical/src/LexicalKeyboardShortcuts.ts:145


CONTROLLED_TEXT_INSERTION_COMMAND​

const CONTROLLED_TEXT_INSERTION_COMMAND: LexicalCommand<InputEvent | string>

Defined in: packages/lexical/src/LexicalCommands.ts:83

Dispatched to insert text from an InputEvent or a string.


COPY_COMMAND​

const COPY_COMMAND: LexicalCommand<ClipboardEvent | KeyboardEvent | null>

Defined in: packages/lexical/src/LexicalCommands.ts:236

Dispatched on a copy event, either via the clipboard or a KeyboardEvent (Cmd+C on macOS, Ctrl+C elsewhere).


CUT_COMMAND​

const CUT_COMMAND: LexicalCommand<ClipboardEvent | KeyboardEvent | null>

Defined in: packages/lexical/src/LexicalCommands.ts:243

Dispatched on a cut event, either via the clipboard or a KeyboardEvent (Cmd+X on macOS, Ctrl+X elsewhere).


CUT_TAG​

const CUT_TAG: "cut" = 'cut'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:37

Indicates that the update is related to a cut operation


DELETE_CHARACTER_COMMAND​

const DELETE_CHARACTER_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:67

Dispatched to delete a character, the payload will be true if the deletion is backwards (backspace or delete on macOS) and false if forwards (delete or Fn+Delete on macOS).


DELETE_LINE_COMMAND​

const DELETE_LINE_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:105

Dispatched to delete a line, the payload will be true if the deletion is backwards (Cmd+Delete on macOS), and false if forwards (Fn+Cmd+Delete on macOS).


DELETE_WORD_COMMAND​

const DELETE_WORD_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:97

Dispatched to delete a word, the payload will be true if the deletion is backwards (Ctrl+Backspace or Opt+Delete on macOS), and false if forwards (Ctrl+Delete or Fn+Opt+Delete on macOS).


DRAGEND_COMMAND​

const DRAGEND_COMMAND: LexicalCommand<DragEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:230

Dispatched when a drag operation ends.


DRAGOVER_COMMAND​

const DRAGOVER_COMMAND: LexicalCommand<DragEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:227

Dispatched when a dragged element is over the editor.


DRAGSTART_COMMAND​

const DRAGSTART_COMMAND: LexicalCommand<DragEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:224

Dispatched when a drag operation starts.


DROP_COMMAND​

const DROP_COMMAND: LexicalCommand<DragEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:218

Dispatched on a drop event.


FOCUS_COMMAND​

const FOCUS_COMMAND: LexicalCommand<FocusEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:283

Dispatched when the editor receives focus.


FORMAT_ELEMENT_COMMAND​

const FORMAT_ELEMENT_COMMAND: LexicalCommand<ElementFormatType>

Defined in: packages/lexical/src/LexicalCommands.ts:221

Dispatched to set the element format (alignment) of the selected block.


FORMAT_TEXT_COMMAND​

const FORMAT_TEXT_COMMAND: LexicalCommand<TextFormatType>

Defined in: packages/lexical/src/LexicalCommands.ts:111

Dispatched to format the selected text.


HISTORIC_TAG​

const HISTORIC_TAG: "historic" = 'historic'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:17

Indicates that the update is related to history operations (undo/redo)


HISTORY_MERGE_TAG​

const HISTORY_MERGE_TAG: "history-merge" = 'history-merge'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:27

Indicates that the current update should be merged with the previous history entry


HISTORY_PUSH_TAG​

const HISTORY_PUSH_TAG: "history-push" = 'history-push'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:22

Indicates that a new history entry should be pushed to the history stack


INDENT_CONTENT_COMMAND​

const INDENT_CONTENT_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:210

Dispatched to indent the selected content.


INPUT_COMMAND​

const INPUT_COMMAND: LexicalCommand<InputEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:54

Dispatched on an input event.


INSERT_LINE_BREAK_COMMAND​

const INSERT_LINE_BREAK_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:75

Dispatched to insert a line break. With a false payload the cursor moves to the new line (Shift+Enter), with a true payload the cursor does not move (Ctrl+O on macOS).


INSERT_PARAGRAPH_COMMAND​

const INSERT_PARAGRAPH_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:79

Dispatched to insert a new paragraph (Enter key).


INSERT_TAB_COMMAND​

const INSERT_TAB_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:207

Dispatched to insert a tab character.


IS_ALL_FORMATTING​

const IS_ALL_FORMATTING: number

Defined in: packages/lexical/src/LexicalConstants.ts:82

Bitmask combining all text format flags.


IS_ANDROID​

const IS_ANDROID: boolean

Defined in: packages/lexical/src/environment.ts:97

Whether the current platform is Android.


IS_ANDROID_CHROME​

const IS_ANDROID_CHROME: boolean

Defined in: packages/lexical/src/environment.ts:110

Whether the current browser is Chrome on Android.


IS_APPLE​

const IS_APPLE: boolean

Defined in: packages/lexical/src/environment.ts:62

Whether the current platform is Apple (macOS, iOS, iPadOS, iPod).


IS_APPLE_WEBKIT​

const IS_APPLE_WEBKIT: boolean

Defined in: packages/lexical/src/environment.ts:114

Whether the current browser is Apple WebKit (Safari on macOS/iOS, excludes Chrome).


IS_BOLD​

const IS_BOLD: 1 = 1

Defined in: packages/lexical/src/LexicalConstants.ts:39

Bitmask for bold text formatting.


IS_CHROME​

const IS_CHROME: boolean

Defined in: packages/lexical/src/environment.ts:106

Whether the current browser is Chrome (or Chromium-based).


IS_CODE​

const IS_CODE: 16 = 16

Defined in: packages/lexical/src/LexicalConstants.ts:47

Bitmask for code (monospace) text formatting.


IS_FIREFOX​

const IS_FIREFOX: boolean

Defined in: packages/lexical/src/environment.ts:65

Whether the current browser is Firefox (excludes SeaMonkey).


IS_HIGHLIGHT​

const IS_HIGHLIGHT: 128 = 128

Defined in: packages/lexical/src/LexicalConstants.ts:53

Bitmask for highlighted text formatting.


IS_IOS​

const IS_IOS: boolean

Defined in: packages/lexical/src/environment.ts:94

Whether the current platform is iOS or iPadOS (iPhone, iPad, iPod).


IS_ITALIC​

const IS_ITALIC: 2 = 2

Defined in: packages/lexical/src/LexicalConstants.ts:41

Bitmask for italic text formatting.


IS_SAFARI​

const IS_SAFARI: boolean

Defined in: packages/lexical/src/environment.ts:100

Whether the current browser is Safari (excludes Android WebView which has a similar UA string).


IS_STRIKETHROUGH​

const IS_STRIKETHROUGH: 4 = 4

Defined in: packages/lexical/src/LexicalConstants.ts:43

Bitmask for strikethrough text formatting.


IS_SUBSCRIPT​

const IS_SUBSCRIPT: 32 = 32

Defined in: packages/lexical/src/LexicalConstants.ts:49

Bitmask for subscript text formatting.


IS_SUPERSCRIPT​

const IS_SUPERSCRIPT: 64 = 64

Defined in: packages/lexical/src/LexicalConstants.ts:51

Bitmask for superscript text formatting.


IS_UNDERLINE​

const IS_UNDERLINE: 8 = 8

Defined in: packages/lexical/src/LexicalConstants.ts:45

Bitmask for underline text formatting.


isSelectionCapturedInDecoratorInput​

const isSelectionCapturedInDecoratorInput: (anchorDOM, preResolvedActiveElement?) => boolean = $isSelectionCapturedInDecoratorInput

Defined in: packages/lexical/src/LexicalUtils.ts:257

Returns true if the active element (resolved from the anchor's root) is a decorator's own input (e.g. an input, textarea, or foreign contentEditable) rather than Lexical-managed content.

Parameters​

anchorDOM​

Node

preResolvedActiveElement?​

Element | null

Returns​

boolean

Deprecated​

renamed to $isSelectionCapturedInDecoratorInput by @lexical/eslint-plugin rules-of-lexical


KEY_ARROW_DOWN_COMMAND​

const KEY_ARROW_DOWN_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:168

Dispatched when the 'ArrowDown' key is pressed. The shift and/or alt (option) modifier keys may also be down.


KEY_ARROW_LEFT_COMMAND​

const KEY_ARROW_LEFT_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:150

Dispatched when the 'ArrowLeft' key is pressed. The shift modifier key may also be down.


KEY_ARROW_RIGHT_COMMAND​

const KEY_ARROW_RIGHT_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:138

Dispatched when the 'ArrowRight' key is pressed. The shift modifier key may also be down.


KEY_ARROW_UP_COMMAND​

const KEY_ARROW_UP_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:162

Dispatched when the 'ArrowUp' key is pressed. The shift and/or alt (option) modifier keys may also be down.


KEY_BACKSPACE_COMMAND​

const KEY_BACKSPACE_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:187

Dispatched whenever the 'Backspace' key is pressed, the shift modifier key may be down.


KEY_DELETE_COMMAND​

const KEY_DELETE_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:198

Dispatched whenever the 'Delete' key is pressed (Fn+Delete on macOS).


KEY_DOWN_COMMAND​

const KEY_DOWN_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:132

Dispatched when any key is pressed.


KEY_ENTER_COMMAND​

const KEY_ENTER_COMMAND: LexicalCommand<KeyboardEvent | null>

Defined in: packages/lexical/src/LexicalCommands.ts:175

Dispatched when the enter key is pressed, may also be called with a null payload when the intent is to insert a newline. The shift modifier key must be down, any other modifier keys may also be down.


KEY_ESCAPE_COMMAND​

const KEY_ESCAPE_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:193

Dispatched whenever the 'Escape' key is pressed, any modifier keys may be down.


KEY_MODIFIER_COMMAND​

const KEY_MODIFIER_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:294

Deprecated​

in v0.31.0, use KEY_DOWN_COMMAND and check for modifiers directly.

Dispatched after any KeyboardEvent when modifiers are pressed


KEY_SPACE_COMMAND​

const KEY_SPACE_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:181

Dispatched whenever the space (' ') key is pressed, any modifier keys may be down.


KEY_TAB_COMMAND​

const KEY_TAB_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:204

Dispatched whenever the 'Tab' key is pressed. The shift modifier key may be down.


MOVE_TO_END​

const MOVE_TO_END: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:144

Dispatched when the move to end keyboard shortcut is pressed, (Cmd+Right on macOS; Ctrl+Right elsewhere).


MOVE_TO_START​

const MOVE_TO_START: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:156

Dispatched when the move to start keyboard shortcut is pressed, (Cmd+Left on macOS; Ctrl+Left elsewhere).


NODE_STATE_DIRECT​

const NODE_STATE_DIRECT: "direct" = 'direct'

Defined in: packages/lexical/src/LexicalNodeState.ts:47

Read the state directly from the given object without node.getLatest(). Safe to use outside of editor state context or to read a previous version, equivalent to reading the property directly.


NODE_STATE_KEY​

const NODE_STATE_KEY: "$" = '$'

Defined in: packages/lexical/src/LexicalConstants.ts:198

The property key used to store node state on serialized node JSON.


NODE_STATE_LATEST​

const NODE_STATE_LATEST: "latest" = 'latest'

Defined in: packages/lexical/src/LexicalNodeState.ts:52

Use node.getLatest() before reading the state, per the lexical convention of only working with the latest version of a node.


OUTDENT_CONTENT_COMMAND​

const OUTDENT_CONTENT_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:214

Dispatched to outdent the selected content.


PASTE_COMMAND​

const PASTE_COMMAND: LexicalCommand<PasteCommandType>

Defined in: packages/lexical/src/LexicalCommands.ts:87

Dispatched on a paste event.


PASTE_TAG​

const PASTE_TAG: "paste" = 'paste'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:32

Indicates that the update is related to a paste operation


REDO_COMMAND​

const REDO_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:128

Dispatched on redo (Shift+Cmd+Z on macOS, Shift+Ctrl+Z or Ctrl+Y elsewhere).


REMOVE_TEXT_COMMAND​

const REMOVE_TEXT_COMMAND: LexicalCommand<InputEvent | null>

Defined in: packages/lexical/src/LexicalCommands.ts:90

Dispatched to remove the currently selected text.


removeFromParent​

const removeFromParent: object = $removeFromParent

Defined in: packages/lexical/src/LexicalUtils.ts:594

Deprecated​

renamed to $removeFromParent by @lexical/eslint-plugin rules-of-lexical


SELECT_ALL_COMMAND​

const SELECT_ALL_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:250

Dispatched on the select all keyboard shortcut (Cmd+A on macOS, Ctrl+A elsehwere).


SELECTION_CHANGE_COMMAND​

const SELECTION_CHANGE_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:38

Dispatched in an update, before reconciliation, when the selection changes. $getSelection() is the pending selection; $getPreviousSelection() is the last committed selection. Listeners may modify the pending update. The DOM is not guaranteed to match it: use $onUpdate(() => editor.read('latest', ...)) for DOM-dependent work, including element lookup, focus checks and positioning.


SELECTION_INSERT_CLIPBOARD_NODES_COMMAND​

const SELECTION_INSERT_CLIPBOARD_NODES_COMMAND: LexicalCommand<{ nodes: LexicalNode[]; selection: BaseSelection; }>

Defined in: packages/lexical/src/LexicalCommands.ts:42

Dispatched to insert clipboard nodes at the current selection.


SET_TEXT_FORMAT_COMMAND​

const SET_TEXT_FORMAT_COMMAND: LexicalCommand<Partial<Record<TextFormatType, boolean>>>

Defined in: packages/lexical/src/LexicalCommands.ts:118

Dispatched to explicitly set or unset text formats on the selection. Unlike FORMAT_TEXT_COMMAND which toggles, this command sets each specified format to the exact boolean value provided.


SKIP_COLLAB_TAG​

const SKIP_COLLAB_TAG: "skip-collab" = 'skip-collab'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:47

Indicates that the update should skip collaborative sync


SKIP_DOM_SELECTION_TAG​

const SKIP_DOM_SELECTION_TAG: "skip-dom-selection" = 'skip-dom-selection'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:63

Indicates that the update should skip updating the DOM selection This is useful when you want to make updates without changing the selection or focus.

Note: this tag has no effect on the initial editor state setup (e.g. an editorState supplied via createEditor or $initialEditorState). If you need the editor to not scroll to or focus the initial selection on first mount, call $setSelection(null) inside your initial state setup function instead.


SKIP_SCROLL_INTO_VIEW_TAG​

const SKIP_SCROLL_INTO_VIEW_TAG: "skip-scroll-into-view" = 'skip-scroll-into-view'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:52

Indicates that the update should skip scrolling the selection into view


SKIP_SELECTION_FOCUS_TAG​

const SKIP_SELECTION_FOCUS_TAG: "skip-selection-focus" = 'skip-selection-focus'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:69

Indicates that after changing the selection, the editor should not focus itself This tag is ignored if SKIP_DOM_SELECTION_TAG is used


TEXT_TYPE_TO_FORMAT​

const TEXT_TYPE_TO_FORMAT: Record<TextFormatType | string, number>

Defined in: packages/lexical/src/LexicalConstants.ts:136

Maps TextFormatType string names to their bitmask values.


UNDO_COMMAND​

const UNDO_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:124

Dispatched on undo (Cmd+Z on macOS, Ctrl+Z elsewhere).

Functions​

$addUpdateTag()​

$addUpdateTag(tag): void

Defined in: packages/lexical/src/LexicalUtils.ts:1753

Adds a tag to the current update, which can be read by update listeners and $hasUpdateTag.

Parameters​

tag​

UpdateTag

Returns​

void


$applyNodeReplacement()​

$applyNodeReplacement<N>(node): N

Defined in: packages/lexical/src/LexicalUtils.ts:1908

Applies any registered node replacement for the given node's type, returning the replacement node or the original if none is registered.

Type Parameters​

N​

N extends LexicalNode

Parameters​

node​

N

Returns​

N


$caretFromPoint()​

$caretFromPoint<D>(point, direction): PointCaret<D>

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:67

Type Parameters​

D​

D extends CaretDirection

Parameters​

point​

Pick<PointType, "type" | "key" | "offset">

direction​

D

Returns​

PointCaret<D>

a PointCaret for the point


$caretRangeFromSelection()​

$caretRangeFromSelection(selection): CaretRange

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:162

Get a pair of carets for a RangeSelection.

If the focus is before the anchor, then the direction will be 'previous', otherwise the direction will be 'next'.

Parameters​

selection​

RangeSelection

Returns​

CaretRange


$cloneWithProperties()​

$cloneWithProperties<T>(latestNode): T

Defined in: packages/lexical/src/LexicalUtils.ts:2984

Returns a clone of a node using node.constructor.clone() followed by clone.afterCloneFrom(node). The resulting clone must have the same key, parent/next/prev pointers, and other properties that are not set by node.constructor.clone (format, style, etc.). This is primarily used by LexicalNode.getWritable to create a writable version of an existing node. The clone is the same logical node as the original node, do not try and use this function to duplicate or copy an existing node.

Does not mutate the EditorState.

Type Parameters​

T​

T extends LexicalNode

Parameters​

latestNode​

T

The node to be cloned.

Returns​

T

The clone of the node.


$cloneWithPropertiesEphemeral()​

$cloneWithPropertiesEphemeral<T>(latestNode): T

Defined in: packages/lexical/src/LexicalUtils.ts:3048

Returns a clone with $cloneWithProperties and then "detaches" it from the state by overriding its getLatest and getWritable to always return this. This node can not be added to an EditorState or become the parent, child, or sibling of another node. It is primarily only useful for making in-place temporary modifications to a TextNode when serializing a partial slice.

Does not mutate the EditorState.

Type Parameters​

T​

T extends LexicalNode

Parameters​

latestNode​

T

The node to be cloned.

Returns​

T

The clone of the node.


$comparePointCaretNext()​

$comparePointCaretNext(a, b): -1 | 0 | 1

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1272

A total ordering for PointCaret<'next'>, based on the same order that a CaretRange would iterate them.

For a given origin node:

  • ChildCaret comes before SiblingCaret
  • TextPointCaret comes before SiblingCaret

An exception is thrown when a and b do not have any common ancestor.

This ordering is a sort of mix of pre-order and post-order because each ElementNode will show up as a ChildCaret on 'enter' (pre-order) and a SiblingCaret on 'leave' (post-order).

Parameters​

a​

PointCaret<"next">

b​

PointCaret<"next">

Returns​

-1 | 0 | 1

-1 if a comes before b, 0 if a and b are the same, or 1 if a comes after b


$copyNode()​

$copyNode<T>(node, skipReset?): T

Defined in: packages/lexical/src/LexicalUtils.ts:1889

Returns a shallow clone of node with a new key. All properties of the node will be copied to the new node (by clone and then afterCloneFrom), except those related to parent/sibling/child relationships in the EditorState. This means that the copy must be separately added to the document, and it will not have any children.

Type Parameters​

T​

T extends LexicalNode

Parameters​

node​

T

The node to be copied.

skipReset?​

boolean = false

If true (default false) skip the call to resetOnCopyNodeFrom

Returns​

T

The copy of the node.


$create()​

$create<T>(klass): T

Defined in: packages/lexical/src/LexicalUtils.ts:5359

Create an node from its class.

This directly constructs the final withKlass node type, skipping the intermediate steps where each replaced node would be created and then immediately discarded — once per configured replacement of that node.

A deprecated replace given without a withKlass is the one case that cannot be resolved ahead of construction, since only its with function knows what to build. Such a replacement is still applied, the old way, to the node this constructs.

This does not support any arguments to the constructor. Setters can be used to initialize your node, and they can be chained. You can of course write your own mutliple-argument functions to wrap that.

Type Parameters​

T​

T extends LexicalNode

Parameters​

klass​

Klass<T>

Returns​

T

Example​

function $createTokenText(text: string): TextNode {
return $create(TextNode).setTextContent(text).setMode('token');
}

$createChildrenArray()​

$createChildrenArray(element, nodeMap): string[]

Defined in: packages/lexical/src/LexicalUtils.ts:5409

Builds an ordered array of child node keys for the given ElementNode by walking its linked-list pointers.

Parameters​

element​

ElementNode

nodeMap​

NodeMap | null

Returns​

string[]


$createLineBreakNode()​

$createLineBreakNode(): LineBreakNode

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:71

Creates a LineBreakNode representing a soft line break (Shift+Enter).

Returns​

LineBreakNode


$createNodeSelection()​

$createNodeSelection(): NodeSelection

Defined in: packages/lexical/src/LexicalSelection.ts:3608

Creates an empty NodeSelection with no selected node keys.

Returns​

NodeSelection


$createParagraphNode()​

$createParagraphNode(): ParagraphNode

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:226

Creates a ParagraphNode, the default block-level container for text.

Returns​

ParagraphNode


$createPoint()​

$createPoint(key, offset, type): PointType

Defined in: packages/lexical/src/LexicalSelection.ts:253

Creates a selection endpoint (Point) targeting the given node key at the specified offset.

Parameters​

key​

string

offset​

number

type​

"text" | "element"

Returns​

PointType


$createRangeSelection()​

$createRangeSelection(): RangeSelection

Defined in: packages/lexical/src/LexicalSelection.ts:3601

Creates a detached RangeSelection anchored at the root element origin (offset 0).

Returns​

RangeSelection


$createRangeSelectionFromDom()​

$createRangeSelectionFromDom(domSelection, editor): RangeSelection | null

Defined in: packages/lexical/src/LexicalSelection.ts:3632

Creates a RangeSelection from the given DOM selection, or returns null if one cannot be resolved.

Parameters​

domSelection​

Selection | null

editor​

LexicalEditor

Returns​

RangeSelection | null


$createTabNode()​

$createTabNode(): TabNode

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:141

Creates a TabNode representing a horizontal tab character.

Returns​

TabNode


$createTextNode()​

$createTextNode(text?): TextNode

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1426

Creates a TextNode initialized with the given text, defaulting to empty.

Parameters​

text?​

string = ''

Returns​

TextNode


$exportNodeJSON()​

$exportNodeJSON(node): SerializedPartial<SerializedLexicalNode>

Defined in: packages/lexical/src/LexicalSerializedExport.ts:161

Experimental

Export one node's JSON in the form the active export asks for, with the sanity checks every export walk relies on: the serialized type must match the class, and an element must carry a children array for the walk to fill.

Use this instead of calling node.exportJSON() directly when writing a serialization walk of your own — it is what editorState.toJSON() and the @lexical/clipboard selection export both call, so $withCompactExport governs every one of them alike.

Which form that is decides the shape, so the return type is the SerializedPartial — the one both forms satisfy. A caller that knows it is not under $withCompactExport and wants the full type should call node.exportJSON() directly.

Parameters​

node​

LexicalNode

Returns​

SerializedPartial<SerializedLexicalNode>


$extendCaretToRange()​

$extendCaretToRange<D>(anchor): CaretRange<D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1162

Construct a CaretRange that starts at anchor and goes to the end of the document in the anchor caret's direction.

Type Parameters​

D​

D extends CaretDirection

Parameters​

anchor​

PointCaret<D>

Returns​

CaretRange<D>


$flushSyncAfterUpdate()​

$flushSyncAfterUpdate(): void

Defined in: packages/lexical/src/LexicalUpdates.ts:1222

Equivalent to setting {discrete: true} on the containing editor.update, generally used to ensure that the DOM is updated before returning from an event listener where the browser is expected to natively finish handling the event.

Returns​

void


$formatText()​

$formatText(selection, formatType, alignWithFormat?): void

Defined in: packages/lexical/src/LexicalSelection.ts:2412

Applies the provided format to TextNodes and inline formattable nodes (e.g. DecoratorTextNode) in the selection, splitting or merging TextNodes as necessary and aligning all formattable nodes to the same target format.

For RangeSelection the toggle direction is determined by the selection's computed format (intersection of all text nodes) when no explicit alignment is given. For NodeSelection each node is toggled independently when no explicit alignment is given, since there is no TextNode to use as an alignment reference.

Parameters​

selection​

RangeSelection | NodeSelection

the selection whose nodes should be formatted.

formatType​

TextFormatType

the format type to apply.

alignWithFormat?​

number | null

optional 32-bit bitmask to align with.

Returns​

void


$generateNodesFromRawText()​

$generateNodesFromRawText(text): (TextNode | LineBreakNode)[]

Defined in: packages/lexical/src/LexicalSelection.ts:4424

Convert a raw text string into a flat array of TextNode, LineBreakNode, and TabNode siblings, splitting on \n, \r\n, and \t. Use this when you need the same \n / \t → real-node conversion that RangeSelection.insertRawText performs but without a selection — e.g. when building a CodeNode's children inside a DOM-import rule.

Parameters​

text​

string

Returns​

(TextNode | LineBreakNode)[]


$getAdjacentChildCaret()​

$getAdjacentChildCaret<D>(caret): NodeCaret<D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:985

Gets the adjacent caret, if not-null and if the origin of the adjacent caret is an ElementNode, then return the ChildCaret. This can be used along with the getParentAdjacentCaret method to perform a full DFS style traversal of the tree.

Type Parameters​

D​

D extends CaretDirection

Parameters​

caret​

NodeCaret<D> | null

The caret to start at

Returns​

NodeCaret<D> | null


$getAdjacentNode()​

$getAdjacentNode(focus, isBackward): LexicalNode | null

Defined in: packages/lexical/src/LexicalUtils.ts:1561

Returns the node adjacent to the given selection point in the specified direction, or null if at a boundary.

Parameters​

focus​

PointType

isBackward​

boolean

Returns​

LexicalNode | null


$getAdjacentSiblingOrParentSiblingCaret()​

$getAdjacentSiblingOrParentSiblingCaret<D>(startCaret, rootMode?): [NodeCaret<D>, number] | null

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:691

Returns the Node sibling when this exists, otherwise the closest parent sibling. For example R -> P -> T1, T2 -> P2 returns T2 for node T1, P2 for node T2, and null for node P2.

Type Parameters​

D​

D extends CaretDirection

Parameters​

startCaret​

NodeCaret<D>

The initial caret

rootMode?​

RootMode = 'root'

The root mode, 'root' (default) or 'shadowRoot'

Returns​

[NodeCaret<D>, number] | null

An array (tuple) containing the found caret and the depth difference, or null, if this node doesn't exist.


$getCaretInDirection()​

$getCaretInDirection<Caret, D>(caret, direction): NodeCaret<D> | Caret extends TextPointCaret<TextNode, CaretDirection> ? TextPointCaret<TextNode, D> : never

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1140

Return the caret if it's in the given direction, otherwise return caret.getFlipped().

Type Parameters​

Caret​

Caret extends PointCaret<CaretDirection>

D​

D extends CaretDirection

Parameters​

caret​

Caret

Any PointCaret

direction​

D

The desired direction

Returns​

NodeCaret<D> | Caret extends TextPointCaret<TextNode, CaretDirection> ? TextPointCaret<TextNode, D> : never

A PointCaret in direction


$getCaretRange()​

$getCaretRange<D>(anchor, focus): CaretRange<D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1199

Construct a CaretRange from anchor and focus carets pointing in the same direction. In order to get the expected behavior, the anchor must point towards the focus or be the same point.

In the 'next' direction the anchor should be at or before the focus in the document. In the 'previous' direction the anchor should be at or after the focus in the document (similar to a backwards RangeSelection).

Type Parameters​

D​

D extends CaretDirection

Parameters​

anchor​

PointCaret<D>

focus​

PointCaret<D>

Returns​

CaretRange<D>

a CaretRange


$getCaretRangeInDirection()​

$getCaretRangeInDirection<D>(range, direction): CaretRange<D>

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:643

Return the range if it's in the given direction, otherwise construct a new range using a flipped focus as the anchor and a flipped anchor as the focus. This transformation preserves the section of the document that it's working with, but reverses the order of iteration.

Type Parameters​

D​

D extends CaretDirection

Parameters​

range​

CaretRange<CaretDirection>

Any CaretRange

direction​

D

The desired direction

Returns​

CaretRange<D>

A CaretRange in direction


$getCharacterOffsets()​

$getCharacterOffsets(selection): [number, number]

Defined in: packages/lexical/src/LexicalSelection.ts:2439

Returns the character offsets of the selection's anchor and focus points as an [anchor, focus] tuple.

Parameters​

selection​

BaseSelection

Returns​

[number, number]


$getChildCaret()​

$getChildCaret<T, D>(origin, direction): ChildCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:958

Get a caret that points at the first or last child of the given origin node, which must be an ElementNode.

Type Parameters​

T​

T extends ElementNode

D​

D extends CaretDirection

Parameters​

origin​

T

The origin ElementNode

direction​

D

'next' for first child or 'previous' for last child

Returns​

ChildCaret<T, D>

null if origin is null or not an ElementNode, otherwise a ChildCaret for this origin and direction


$getChildCaretAtIndex()​

$getChildCaretAtIndex<D>(parent, index, direction): NodeCaret<D>

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:665

Get a caret pointing at the child at the given index, or the last caret in that node if out of bounds.

Type Parameters​

D​

D extends CaretDirection

Parameters​

parent​

ElementNode

An ElementNode

index​

number

The index of the origin for the caret

direction​

D

Returns​

NodeCaret<D>

A caret pointing towards the node at that index


$getChildCaretOrSelf()​

$getChildCaretOrSelf<Caret>(caret): Caret | ChildCaret<ElementNode, NonNullable<Caret>["direction"]>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:972

Gets the ChildCaret if one is possible at this caret origin, otherwise return the caret

Type Parameters​

Caret​

Caret extends PointCaret<CaretDirection> | null

Parameters​

caret​

Caret

Returns​

Caret | ChildCaret<ElementNode, NonNullable<Caret>["direction"]>


$getCollapsedCaretRange()​

$getCollapsedCaretRange<D>(anchor): CaretRange<D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1179

Construct a collapsed CaretRange that starts and ends at anchor.

Type Parameters​

D​

D extends CaretDirection

Parameters​

anchor​

PointCaret<D>

Returns​

CaretRange<D>


$getCommonAncestor()​

$getCommonAncestor<A, B>(a, b): CommonAncestorResult<A, B> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1410

Find a common ancestor of a and b and return a detailed result object, or null if there is no common ancestor between the two nodes.

The result object will have a commonAncestor property, and the other properties can be used to quickly compare these positions in the tree.

Type Parameters​

A​

A extends LexicalNode

B​

B extends LexicalNode

Parameters​

a​

A

A LexicalNode

b​

B

A LexicalNode

Returns​

CommonAncestorResult<A, B> | null

A comparison result between the two nodes or null if they have no common ancestor


$getCommonAncestorResultBranchOrder()​

$getCommonAncestorResultBranchOrder<A, B>(compare): -1 | 1

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1315

Return the ordering of siblings in a CommonAncestorResultBranch

Type Parameters​

A​

A extends LexicalNode

B​

B extends LexicalNode

Parameters​

compare​

CommonAncestorResultBranch<A, B>

Returns -1 if a precedes b, 1 otherwise

Returns​

-1 | 1


$getDocument()​

$getDocument(): Document

Defined in: packages/lexical/src/LexicalUtils.ts:2248

Returns the Document that owns the active editor's root element. Falls back to globalThis.document when there is no active editor (e.g. a node method such as createDOM / exportDOM is invoked headlessly, outside of editor.update() / editor.read()), or when the active editor has no root element (e.g. headless mode with @lexical/headless!withDOM | withDOM).

Use this inside createDOM, updateDOM, and exportDOM instead of the bare document global so the node works correctly when the editor lives inside a Shadow DOM or a cross-origin <iframe>.

Unlike most $-prefixed helpers, this does NOT require an ambient active editor: it must remain callable from createDOM / exportDOM, which are public methods that consumers may legitimately call while serializing nodes headlessly. Throwing here would silently break every node whose DOM methods were migrated off the bare document global.

Returns​

Document


$getDOMSlot()​

$getDOMSlot<N>(node, dom, editor?): DOMSlotForNode<N>

Defined in: packages/lexical/src/LexicalUtils.ts:2787

Experimental

Resolve the DOM slot for a node through the configured $getDOMSlot hook, narrowing the return type via DOMSlotForNode: for an ElementNode the result is an ElementDOMSlot (with children-management methods), for non-Element nodes the base DOMSlot pointing at the keyed DOM.

Invariants if an extension override returns a slot that doesn't match the expected narrow type for the node (extension contract violation).

Type Parameters​

N​

N extends LexicalNode

Parameters​

node​

N

dom​

HTMLElement

editor?​

LexicalEditor = ...

Returns​

DOMSlotForNode<N>


$getDOMTextNode()​

$getDOMTextNode(node, dom, editor?): Text | null

Defined in: packages/lexical/src/LexicalUtils.ts:2916

Experimental

Resolve the actual text DOM (Text) for a TextNode through the configured $getDOMSlot hook. Unlike the plain getDOMTextNode which descends the first child chain from a raw element, this routes through the slot so an extension wrapping the text node's keyed DOM (e.g. one that injects a contentEditable=false sibling before the text) still points at the correct content element.

Parameters​

node​

TextNode

dom​

HTMLElement

editor?​

LexicalEditor = ...

Returns​

Text | null


$getEditor()​

$getEditor(): LexicalEditor

Defined in: packages/lexical/src/LexicalUtils.ts:2758

Utility function for accessing current active editor instance.

Returns​

LexicalEditor

Current active editor


$getEditorDOMRenderConfig()​

$getEditorDOMRenderConfig(editor?): EditorDOMRenderConfig

Defined in: packages/lexical/src/LexicalUtils.ts:2770

Experimental

Read the editor's $getDOMSlot configuration (defaulting to the base implementation when no override is registered via DOMRenderExtension). Cross-package consumers (@lexical/utils, @lexical/react) use this to route selection / DOM lookups through extension-configured slots.

Parameters​

editor?​

LexicalEditor = ...

Returns​

EditorDOMRenderConfig


$getNearestNodeFromDOMNode()​

$getNearestNodeFromDOMNode(startingDOM, editorState?): LexicalNode | null

Defined in: packages/lexical/src/LexicalUtils.ts:743

Returns the nearest LexicalNode by walking up the DOM tree from the given node, or null if no Lexical node is found.

Parameters​

startingDOM​

Node

editorState?​

EditorState

Returns​

LexicalNode | null


$getNearestRootOrShadowRoot()​

$getNearestRootOrShadowRoot(node): ElementNode | RootNode

Defined in: packages/lexical/src/LexicalUtils.ts:1836

Returns the given node itself (if it is a slot boundary) or its nearest ancestor that is a RootNode, ShadowRootNode, or slot boundary.

Parameters​

node​

LexicalNode

Returns​

ElementNode | RootNode


$getNodeByKey()​

Call Signature​

$getNodeByKey(key, _editorState?): LexicalNode | null

Defined in: packages/lexical/src/LexicalUtils.ts:681

Returns the node with the given key from the active EditorState (or the given EditorState), or null if it does not exist.

Parameters​
key​

string

_editorState?​

EditorState

Returns​

LexicalNode | null

Call Signature​

$getNodeByKey<T>(key, _editorState?): T | null

Defined in: packages/lexical/src/LexicalUtils.ts:691

Type Parameters​
T​

T extends LexicalNode

Parameters​
key​

string

_editorState?​

EditorState

Returns​

T | null

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to $getNodeByKey(key) as T | null, and will be removed in a future release. Call this function without a type argument and narrow the result with a type guard instead.


$getNodeByKeyOrThrow()​

Call Signature​

$getNodeByKeyOrThrow(key): LexicalNode

Defined in: packages/lexical/src/LexicalUtils.ts:1978

Returns the node with the given key from the active EditorState, or throws if it does not exist.

Parameters​
key​

string

Returns​

LexicalNode

Call Signature​

$getNodeByKeyOrThrow<N>(key): N

Defined in: packages/lexical/src/LexicalUtils.ts:1985

Type Parameters​
N​

N extends LexicalNode

Parameters​
key​

string

Returns​

N

Deprecated​

The type parameter is an unchecked and unsafe cast, equivalent to $getNodeByKeyOrThrow(key) as N, and will be removed in a future release. Call this function without a type argument and narrow the result with a type guard instead.


$getNodeFromDOMNode()​

$getNodeFromDOMNode(dom, editorState?): LexicalNode | null

Defined in: packages/lexical/src/LexicalUtils.ts:708

Returns the LexicalNode directly associated with the given DOM node, or null if the DOM node has no Lexical key.

Parameters​

dom​

Node

editorState?​

EditorState

Returns​

LexicalNode | null


$getPreviousSelection()​

$getPreviousSelection(): BaseSelection | null

Defined in: packages/lexical/src/LexicalSelection.ts:3834

Returns the selection from the previous editor state, or null if none existed.

Returns​

BaseSelection | null


$getRoot()​

$getRoot(): RootNode

Defined in: packages/lexical/src/LexicalUtils.ts:812

Returns the RootNode of the active EditorState.

Returns​

RootNode


$getSelection()​

$getSelection(): BaseSelection | null

Defined in: packages/lexical/src/LexicalSelection.ts:3828

Returns the current selection of the active editor state, or null if none exists.

Returns​

BaseSelection | null


$getSelectionSlotFrame()​

$getSelectionSlotFrame(selection): LexicalNode | null

Defined in: packages/lexical/src/LexicalSlot.ts:182

Experimental

Returns the slot frame that selection lives in, or null when it is outside any slot (or there is no selection). Thin wrapper over $getSlotFrame that picks the node to anchor the walk on.

Selection-driven exporters walk this frame instead of the root's children: a selection wholly inside a slot subtree never includes its host (slots are shadow-root isolated), so a root-children walk would miss the selected nodes entirely and produce an empty payload (cut = data loss).

Every selection type participates. A RangeSelection anchors on its anchor point; anything else (NodeSelection, TableSelection, or an app-defined BaseSelection) anchors on the first node it reports, which is where a click that selects a decorator or a table nested in a slot is handled.

NodeSelection.getNodes()[0] is the first node by insertion order (the internal _nodes Set's iteration order), not document order. For the common single-node case this is the only node and the frame is unambiguous. A multi-node selection that straddles a slot boundary is currently undefined — slots are shadow-isolated, so straddling is already invalid construction, and we pick the first node's frame rather than asserting.

Parameters​

selection​

BaseSelection | null

Returns​

LexicalNode | null


$getSiblingCaret()​

Call Signature​

$getSiblingCaret<T, D>(origin, direction): SiblingCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:851

Get a caret that points at the next or previous sibling of the given origin node.

Type Parameters​
T​

T extends LexicalNode

D​

D extends CaretDirection

Parameters​
origin​

T

The origin node

direction​

D

'next' or 'previous'

Returns​

SiblingCaret<T, D>

null if origin is null, otherwise a SiblingCaret for this origin and direction

Call Signature​

$getSiblingCaret<T, D>(origin, direction): SiblingCaret<T, D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:855

Get a caret that points at the next or previous sibling of the given origin node.

Type Parameters​
T​

T extends LexicalNode

D​

D extends CaretDirection

Parameters​
origin​

T | null

The origin node

direction​

D

'next' or 'previous'

Returns​

SiblingCaret<T, D> | null

null if origin is null, otherwise a SiblingCaret for this origin and direction


$getSlot()​

$getSlot<T>(node, name): LexicalNode | null

Defined in: packages/lexical/src/LexicalSlot.ts:249

Experimental

Returns the node occupying the named slot, or null if the slot is empty. Slots are a shadow-root-isolated channel kept separate from children; see $getSlotHost for the reverse up-link.

Type Parameters​

T​

T extends LexicalNode

Parameters​

node​

T

name​

SlotName<T>

Returns​

LexicalNode | null


$getSlotFrame()​

$getSlotFrame(node): LexicalNode | null

Defined in: packages/lexical/src/LexicalSlot.ts:147

Experimental

Returns the slot value (the "slot frame") whose isolated subtree contains node, or node itself when it is a slot value, or null when the node is not inside any slot. The walk follows getParent() and naturally stops at a slot value because a slotted node's __parent is null. Non-slot trees have __slotHost === null everywhere, so this always returns null there.

Selection-driven exporters use this to find the isolated subtree a RangeSelection lives in (a selection inside a slot never contains the host, so a root-children walk alone would miss it).

Parameters​

node​

LexicalNode

Returns​

LexicalNode | null


$getSlotHost()​

$getSlotHost(node): DecoratorNode<unknown> | ElementNode | null

Defined in: packages/lexical/src/LexicalSlot.ts:98

Experimental

Returns the host element when this node occupies one of its named slots, or null if this node is not slotted. The up-link is kept separate from LexicalNode.getParent so the slot boundary behaves like a shadow root.

Parameters​

node​

LexicalNode

Returns​

DecoratorNode<unknown> | ElementNode | null


$getSlotNames()​

$getSlotNames(node): string[]

Defined in: packages/lexical/src/LexicalSlot.ts:214

Experimental

Returns the names of this node's occupied slots, in insertion order. Empty when the node hosts no slots.

Parameters​

node​

LexicalNode

Returns​

string[]


$getSlotNameWithinHost()​

$getSlotNameWithinHost(slotChild): string | null

Defined in: packages/lexical/src/LexicalSlot.ts:120

Experimental

Returns the slot name this node occupies on its host, or null when the node is not a slot value. Mirrors LexicalNode#getIndexWithinParent for slot children — answers "which named slot does this node sit in?".

Parameters​

slotChild​

LexicalNode

Returns​

string | null


$getState()​

$getState<K, V>(node, stateConfig, version?): V

Defined in: packages/lexical/src/LexicalNodeState.ts:563

The accessor for working with node state. This will read the value for the state on the given node, and will return stateConfig.defaultValue if the state has never been set on this node.

The version parameter is optional and should generally be NODE_STATE_LATEST, consistent with the behavior of other node methods and functions, but for certain use cases such as updateDOM you may have a need to use NODE_STATE_DIRECT to read the state from a previous version of the node.

For very advanced use cases, you can expect that NODE_STATE_DIRECT does not require an editor state, just like directly accessing other properties of a node without an accessor (e.g. textNode.__text).

Type Parameters​

K​

K extends string

V​

V

Parameters​

node​

LexicalNode

Any LexicalNode

stateConfig​

StateConfig<K, V>

The configuration of the state to read

version?​

NodeStateVersion = NODE_STATE_LATEST

The default value NODE_STATE_LATEST will read the latest version of the node state, NODE_STATE_DIRECT will read the version that is stored on this LexicalNode which not reflect the version used in the current editor state

Returns​

V

The current value from the state, or the default value provided by the configuration.


$getStateChange()​

$getStateChange<T, K, V>(node, prevNode, stateConfig): [V, V] | null

Defined in: packages/lexical/src/LexicalNodeState.ts:592

Given two versions of a node and a stateConfig, compare their state values using $getState(nodeVersion, stateConfig, NODE_STATE_DIRECT). If the values are equal according to stateConfig.isEqual, return null, otherwise return [value, prevValue].

This is useful for implementing updateDOM. Note that the NODE_STATE_DIRECT version argument is used for both nodes.

Type Parameters​

T​

T extends LexicalNode

K​

K extends string

V​

V

Parameters​

node​

T

Any LexicalNode

prevNode​

T

A previous version of node

stateConfig​

StateConfig<K, V>

The configuration of the state to read

Returns​

[V, V] | null

[value, prevValue] if changed, otherwise null


$getTextContent()​

$getTextContent(): string

Defined in: packages/lexical/src/LexicalSelection.ts:4437

Returns the text content of the current selection, or an empty string if no selection exists.

Returns​

string


$getTextNodeOffset()​

$getTextNodeOffset(origin, offset, mode?): number

Defined in: packages/lexical/src/caret/LexicalCaret.ts:910

Get a normalized offset into a TextNode given a numeric offset or a direction for which end of the string to use. Throws in dev if the offset is not in the bounds of the text content size.

Parameters​

origin​

TextNode

a TextNode

offset​

number | CaretDirection

An absolute offset into the TextNode string, or a direction for which end to use as the offset

mode?​

"error" | "clamp"

If 'error' (the default) out of bounds offsets will be an error in dev. Otherwise it will clamp to a valid offset.

Returns​

number

An absolute offset into the TextNode string


$getTextPointCaret()​

Call Signature​

$getTextPointCaret<T, D>(origin, direction, offset): TextPointCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:874

Construct a TextPointCaret

Type Parameters​
T​

T extends TextNode

D​

D extends CaretDirection

Parameters​
origin​

T

The TextNode

direction​

D

The direction (next points to the end of the text, previous points to the beginning)

offset​

number | CaretDirection

The offset into the text in absolute positive string coordinates (0 is the start)

Returns​

TextPointCaret<T, D>

a TextPointCaret

Call Signature​

$getTextPointCaret<T, D>(origin, direction, offset): TextPointCaret<T, D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:882

Construct a TextPointCaret

Type Parameters​
T​

T extends TextNode

D​

D extends CaretDirection

Parameters​
origin​

T | null

The TextNode

direction​

D

The direction (next points to the end of the text, previous points to the beginning)

offset​

number | CaretDirection

The offset into the text in absolute positive string coordinates (0 is the start)

Returns​

TextPointCaret<T, D> | null

a TextPointCaret


$getTextPointCaretSlice()​

$getTextPointCaretSlice<T, D>(caret, distance): TextPointCaretSlice<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:943

Construct a TextPointCaretSlice given a TextPointCaret and a signed distance. The distance should be negative to slice text before the caret's offset, and positive to slice text after the offset. The direction of the caret itself is not relevant to the string coordinates when working with a TextPointCaretSlice but mutation operations will preserve the direction.

Type Parameters​

T​

T extends TextNode

D​

D extends CaretDirection

Parameters​

caret​

TextPointCaret<T, D>

distance​

number

Returns​

TextPointCaretSlice<T, D>

TextPointCaretSlice


$hasAncestor()​

$hasAncestor(child, targetNode): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:1792

Returns true if targetNode is an ancestor of child by walking up the parent chain.

Parameters​

child​

LexicalNode

targetNode​

LexicalNode

Returns​

boolean


$hasUpdateTag()​

$hasUpdateTag(tag): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:1747

Returns true if the given tag has been added to the current update via $addUpdateTag.

Parameters​

tag​

UpdateTag

Returns​

boolean


$insertNodes()​

$insertNodes(nodes): void

Defined in: packages/lexical/src/LexicalSelection.ts:4371

Inserts nodes into the current selection, falling back to the previous selection or the end of the root.

Parameters​

nodes​

LexicalNode[]

Returns​

void


$insertNodeToNearestRootAtCaret()​

$insertNodeToNearestRootAtCaret<T, D>(node, caret, options?): NodeCaret<D>

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:837

If the insertion caret is the root/shadow root node (see $isRootOrShadowRoot), the node will be inserted there, otherwise the parent nodes will be split according to the given options.

Type Parameters​

T​

T extends LexicalNode

D​

D extends CaretDirection

Parameters​

node​

T

The node to be inserted

caret​

PointCaret<D>

The location to insert or split from

options?​

SplitAtPointCaretNextOptions

Returns​

NodeCaret<D>

The node after its insertion


$isBlockElementNode()​

$isBlockElementNode(node): node is ElementNode

Defined in: packages/lexical/src/LexicalSelection.ts:3570

Returns true if the given node is a non-inline ElementNode.

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is ElementNode


$isBlockFullySelected()​

$isBlockFullySelected(blockNode, selectionOrRange): boolean

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:906

Checks whether the selection covers the entire block: the selection's start point is at or before the first position inside blockNode and its end point is at or after the last position inside blockNode. A selection that extends beyond the block's boundaries still fully selects the block, and an empty block is fully selected by any selection that touches or surrounds it.

Parameters​

blockNode​

ElementNode

The ElementNode to check, typically a top-level block or the RootNode

selectionOrRange​

RangeSelection | CaretRange<CaretDirection>

The RangeSelection or CaretRange to check

Returns​

boolean

true if the selection covers the entire blockNode


$isChildCaret()​

$isChildCaret<D>(caret): caret is ChildCaret<ElementNode, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:767

Guard to check if the given argument is specifically a ChildCaret

Type Parameters​

D​

D extends CaretDirection

Parameters​

caret​

PointCaret<D> | null | undefined

Returns​

caret is ChildCaret<ElementNode, D>

true if caret is a ChildCaret


$isCompactExport()​

$isCompactExport(): boolean

Defined in: packages/lexical/src/LexicalSerializedExport.ts:132

Experimental

Whether the export walk in progress is writing the compact form.

For the one thing that cannot be told: a schema getter. The walk calls get<Prop>() with no arguments — that contract is what lets getTextContent and getURL be ordinary node methods rather than serialization-specific ones — so a getter whose value depends on the form has to read it here:

getSerializedThumbnail(): string | undefined {
// Derivable from `src`, so the compact form leaves it out.
return $isCompactExport() ? undefined : this.getLatest().__thumbnail;
}

A getter that serializes a nested editor needs nothing either, as long as it goes through editor.toJSON(): that passes the form reported here on to the nested EditorState.toJSON, which is what keeps an image caption in the same form as the document containing it. A getter that reaches past it to editorState.toJSON() gets the legacy form, and has to pass $isCompactExport() itself to follow the document.

This reports the form of the surrounding export walk — what $withCompactExport established, and so what editorState.toJSON(compact) and the @lexical/clipboard selection export establish. It is deliberately not set by an individual LexicalNode.exportJSON call: that method takes its own compact argument and is called by the walk with the walk's form already in effect, so having it set this too would say a document is compact when only one node was asked to be. A bare node.exportJSON(true) outside a walk therefore reports false here.

Anything with a call site of its own should take the form as an argument rather than read it here.

Returns​

boolean


$isDecoratorNode()​

$isDecoratorNode<T>(node): node is DecoratorNode<T>

Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:99

Returns true if the given node is a DecoratorNode.

Type Parameters​

T​

T

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is DecoratorNode<T>


$isEditorState()​

$isEditorState(x): x is EditorState

Defined in: packages/lexical/src/LexicalEditorState.ts:141

Type guard that returns true if the argument is an EditorState

Parameters​

x​

unknown

Returns​

x is EditorState


$isElementDOMSlot()​

$isElementDOMSlot(slot): slot is ElementDOMSlot<HTMLElement>

Defined in: packages/lexical/src/LexicalUtils.ts:2900

Experimental

Type guard narrowing a DOMSlot to an ElementDOMSlot, which exposes children-management methods like insertChild and the managed line-break helpers.

Parameters​

slot​

DOMSlot<HTMLElement>

Returns​

slot is ElementDOMSlot<HTMLElement>


$isElementNode()​

$isElementNode(node): node is ElementNode

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1153

Returns true if the given node is an ElementNode.

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is ElementNode


$isExtendableTextPointCaret()​

$isExtendableTextPointCaret<D>(caret): caret is TextPointCaret<TextNode, D> & { [PointCaretIsExtendableBrand]: never }

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:621

Determine whether the TextPointCaret's offset can be extended further without leaving the TextNode. Returns false if the given caret is not a TextPointCaret or the offset can not be moved further in direction.

Type Parameters​

D​

D extends CaretDirection

Parameters​

caret​

PointCaret<D>

A PointCaret

Returns​

caret is TextPointCaret<TextNode, D> & { [PointCaretIsExtendableBrand]: never }

true if caret is a TextPointCaret with an offset that is not at the end of the text given the direction.


$isInlineElementOrDecoratorNode()​

$isInlineElementOrDecoratorNode<T>(node): node is (ElementNode | DecoratorNode<T>) & { [InlineNodeBrand]: never; isInline: any }

Defined in: packages/lexical/src/LexicalUtils.ts:1822

Returns true if the given node is an inline ElementNode or an inline DecoratorNode.

Type Parameters​

T​

T

Parameters​

node​

LexicalNode

Returns​

node is (ElementNode | DecoratorNode<T>) & { [InlineNodeBrand]: never; isInline: any }


$isInlineFormattable()​

$isInlineFormattable(node): node is LexicalNode & InlineFormattableNode

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:376

Returns true if the given node supports inline text formatting.

Parameters​

node​

LexicalNode & object | null | undefined

Returns​

node is LexicalNode & InlineFormattableNode


$isLeafNode()​

$isLeafNode(node): node is DecoratorNode<unknown> | TextNode | LineBreakNode

Defined in: packages/lexical/src/LexicalUtils.ts:404

Returns true if the given node is a leaf (TextNode, LineBreakNode, or DecoratorNode).

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is DecoratorNode<unknown> | TextNode | LineBreakNode


$isLexicalNode()​

$isLexicalNode(node): node is LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:2464

Returns true if the given value is a LexicalNode instance.

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is LexicalNode


$isLineBreakNode()​

$isLineBreakNode(node): node is LineBreakNode

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:76

Returns true if the given node is a LineBreakNode.

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is LineBreakNode


$isNodeCaret()​

$isNodeCaret<D>(caret): caret is PointCaret<D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:743

Guard to check if the given argument is any type of caret

Type Parameters​

D​

D extends CaretDirection

Parameters​

caret​

PointCaret<D> | null | undefined

Returns​

caret is PointCaret<D>

true if caret is any type of caret


$isNodeSelection()​

$isNodeSelection(x): x is NodeSelection

Defined in: packages/lexical/src/LexicalSelection.ts:2205

Returns true if the given value is a NodeSelection.

Parameters​

x​

unknown

Returns​

x is NodeSelection


$isParagraphNode()​

$isParagraphNode(node): node is ParagraphNode

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:231

Returns true if the given node is a ParagraphNode.

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is ParagraphNode


$isRangeSelection()​

$isRangeSelection(x): x is RangeSelection

Defined in: packages/lexical/src/LexicalSelection.ts:632

Returns true if the given value is a RangeSelection.

Parameters​

x​

unknown

Returns​

x is RangeSelection


$isRootNode()​

$isRootNode(node): node is RootNode

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:109

Returns true if the given node is a RootNode.

Parameters​

node​

LexicalNode | RootNode | null | undefined

Returns​

node is RootNode


$isRootOrShadowRoot()​

$isRootOrShadowRoot(node): node is RootNode | ShadowRootNode

Defined in: packages/lexical/src/LexicalUtils.ts:1872

Returns true if the given node is a RootNode or a ShadowRootNode.

Parameters​

node​

LexicalNode | null

Returns​

node is RootNode | ShadowRootNode


$isSelectionCapturedInDecoratorInput()​

$isSelectionCapturedInDecoratorInput(anchorDOM, preResolvedActiveElement?): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:222

Returns true if the active element (resolved from the anchor's root) is a decorator's own input (e.g. an input, textarea, or foreign contentEditable) rather than Lexical-managed content.

Parameters​

anchorDOM​

Node

preResolvedActiveElement?​

Element | null

Returns​

boolean


$isShadowRootNode()​

$isShadowRootNode(node): node is ShadowRootNode

Defined in: packages/lexical/src/LexicalUtils.ts:1865

Returns true if the given node is an ElementNode whose isShadowRoot() returns true.

Parameters​

node​

LexicalNode | null

Returns​

node is ShadowRootNode


$isSiblingCaret()​

$isSiblingCaret<D>(caret): caret is SiblingCaret<LexicalNode, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:755

Guard to check if the given argument is specifically a SiblingCaret (or TextPointCaret)

Type Parameters​

D​

D extends CaretDirection

Parameters​

caret​

PointCaret<D> | null | undefined

Returns​

caret is SiblingCaret<LexicalNode, D>

true if caret is a SiblingCaret


$isSlotChild()​

$isSlotChild(node): node is LexicalNode & SlotChildNode

Defined in: packages/lexical/src/LexicalSlot.ts:71

Experimental

Shape predicate: true when node carries the child's __slotHost field — i.e. it is an ElementNode or a DecoratorNode. Narrows to SlotChildNode. This is a type guard only; $setSlot rejects inline values at runtime. The slot link acts as a virtual shadow root, so any non-inline block — shadow root or not — can occupy a slot.

Parameters​

node​

LexicalNode

Returns​

node is LexicalNode & SlotChildNode


$isSlotHost()​

$isSlotHost(node): node is LexicalNode & SlotHostNode

Defined in: packages/lexical/src/LexicalSlot.ts:56

Experimental

Shape predicate: true when node carries the host's __slots field — i.e. it is an ElementNode or a DecoratorNode. Narrows to SlotHostNode so the mutation helpers' compile-time host requirement is satisfied. This is a type guard only; the value-level invariant on what may actually be slotted is enforced by $setSlot (shadow-root ElementNode or non-inline DecoratorNode).

Parameters​

node​

LexicalNode

Returns​

node is LexicalNode & SlotHostNode


$isTabNode()​

$isTabNode(node): node is TabNode

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:146

Returns true if the given node is a TabNode.

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is TabNode


$isTextNode()​

$isTextNode(node): node is TextNode

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1431

Returns true if the given node is a TextNode.

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is TextNode


$isTextPointCaret()​

$isTextPointCaret<D>(caret): caret is TextPointCaret<TextNode, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:731

Guard to check if the given caret is specifically a TextPointCaret

Type Parameters​

D​

D extends CaretDirection

Parameters​

caret​

PointCaret<D> | null | undefined

Any caret

Returns​

caret is TextPointCaret<TextNode, D>

true if it is a TextPointCaret


$isTextPointCaretSlice()​

$isTextPointCaretSlice<D>(caretOrSlice): caretOrSlice is TextPointCaretSlice<TextNode, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1122

Guard to check for a TextPointCaretSlice

Type Parameters​

D​

D extends CaretDirection

Parameters​

caretOrSlice​

PointCaret<D> | TextPointCaretSlice<TextNode, D> | null | undefined

A caret or slice

Returns​

caretOrSlice is TextPointCaretSlice<TextNode, D>

true if caretOrSlice is a TextPointCaretSlice


$isTokenOrSegmented()​

$isTokenOrSegmented(node): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:340

Return true if the TextNode is a TabNode, or is in token or segmented mode.

Parameters​

node​

TextNode

Returns​

boolean


$isTokenOrTab()​

$isTokenOrTab(node): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:333

Return true if the TextNode is a TabNode or is in token mode.

Parameters​

node​

TextNode

Returns​

boolean


$markSlotEditable()​

$markSlotEditable(element, editor?): void

Defined in: packages/lexical/src/LexicalUtils.ts:3176

Experimental

Mark a DOM element as a named-slot editable island: set its contentEditable to follow the editor's editable state. A slot rendered inside a non-editable host (a decorator, or a contentEditable=false element shell) does not track the editor on its own, so its container carries an explicit contentEditable; $fullReconcile re-applies this when LexicalEditor.setEditable toggles. Call it for any other editable island an app attaches itself (e.g. a getDOMSlot children element rendered inside a contentEditable=false shell).

Parameters​

element​

HTMLElement & object

editor?​

LexicalEditor = ...

Returns​

void


$needsBlockCursorBeside()​

$needsBlockCursorBeside(node): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:2024

Returns true if the given node needs a block cursor given an adjacent selection, the node must be non-inline and one of:

  • DecoratorNode
  • ShadowRootNode with a parent that is not also a ShadowRootNode
  • An ElementNode that can't be empty

Parameters​

node​

LexicalNode | null

Returns​

boolean


$nodesOfType()​

$nodesOfType<T>(klass): T[]

Defined in: packages/lexical/src/LexicalUtils.ts:1517

Returns all nodes of the given type in the active editor state.

Consider LexicalEditor.registerMutationListener with skipInitialization: false instead if you need to track these nodes over time rather than read them once.

Type Parameters​

T​

T extends LexicalNode

Parameters​

klass​

Klass<T>

Returns​

T[]


$normalizeCaret()​

$normalizeCaret<D>(initialCaret): PointCaret<D>

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:596

Normalize a caret to the deepest equivalent PointCaret. This will return a TextPointCaret with the offset set according to the direction if given a caret with a TextNode origin or a caret with an ElementNode origin with the deepest ChildCaret having an adjacent TextNode.

If given a TextPointCaret, it will be returned, as no normalization is required when an offset is already present.

Type Parameters​

D​

D extends CaretDirection

Parameters​

initialCaret​

PointCaret<D>

Returns​

PointCaret<D>

The normalized PointCaret


$normalizeSelection__EXPERIMENTAL()​

$normalizeSelection__EXPERIMENTAL(selection): RangeSelection

Defined in: packages/lexical/src/LexicalNormalization.ts:100

Descends element-type anchor and focus points of a RangeSelection toward the deepest text-type points, stopping at non-element leaf nodes.

Parameters​

selection​

RangeSelection

Returns​

RangeSelection


$onUpdate()​

$onUpdate(updateFn): void

Defined in: packages/lexical/src/LexicalUtils.ts:1766

Add a function to run after the current update. This will run after any onUpdate function already supplied to editor.update(), as well as any functions added with previous calls to $onUpdate.

Parameters​

updateFn​

() => void

The function to run after the current update.

Returns​

void


$parseSerializedNode()​

$parseSerializedNode(serializedNode): LexicalNode

Defined in: packages/lexical/src/LexicalUpdates.ts:405

Deserializes a SerializedLexicalNode JSON object into its corresponding LexicalNode instance.

Parameters​

serializedNode​

SerializedLexicalNode | SerializedPartialNode | ParsableSerializedNode

Returns​

LexicalNode


$removeSlot()​

$removeSlot<T>(host, name): T

Defined in: packages/lexical/src/LexicalSlot.ts:543

Experimental

Removes the named slot from host, detaching its value (its slot up-link is cleared). No-op if the slot is empty. host is constrained to SlotHostNode so a non-host is rejected at compile time.

Type Parameters​

T​

T extends LexicalNode & SlotHostNode

Parameters​

host​

T

name​

SlotName<T>

Returns​

T


$removeTextFromCaretRange()​

$removeTextFromCaretRange<D>(initialRange, sliceMode?): CaretRange<D>

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:238

Remove all text and nodes in the given range. If the range spans multiple blocks then the remaining contents of the later block will be merged with the earlier block.

Type Parameters​

D​

D extends CaretDirection

Parameters​

initialRange​

CaretRange<D>

The range to remove text and nodes from

sliceMode?​

"removeEmptySlices" | "preserveEmptyTextSliceCaret"

If 'preserveEmptyTextPointCaret' it will leave an empty TextPointCaret at the anchor for insert if one exists, otherwise empty slices will be removed

Returns​

CaretRange<D>

The new collapsed range (biased towards the earlier node)


$rewindSiblingCaret()​

$rewindSiblingCaret<T, D>(caret): NodeCaret<D>

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:189

Given a SiblingCaret we can always compute a caret that points to the origin of that caret in the same direction. The adjacent caret of the returned caret will be equivalent to the given caret.

Type Parameters​

T​

T extends LexicalNode

D​

D extends CaretDirection

Parameters​

caret​

SiblingCaret<T, D>

The caret to "rewind"

Returns​

NodeCaret<D>

A new caret (ChildCaret or SiblingCaret) with the same direction

Example​

siblingCaret.is($rewindSiblingCaret(siblingCaret).getAdjacentCaret())

$selectAll()​

$selectAll(selection?): RangeSelection

Defined in: packages/lexical/src/LexicalUtils.ts:1378

Selects all content within the root. If a selection is provided, scopes to the nearest root or shadow root; otherwise creates a new RangeSelection spanning the entire root.

Parameters​

selection?​

RangeSelection | null

Returns​

RangeSelection


$setCompositionKey()​

$setCompositionKey(compositionKey): void

Defined in: packages/lexical/src/LexicalUtils.ts:648

Sets the active composition key, marking the previous and new composition nodes as dirty for re-rendering.

Parameters​

compositionKey​

string | null

Returns​

void


$setDirectionFromDOM()​

$setDirectionFromDOM<T>(node, domNode): T

Defined in: packages/lexical/src/LexicalUtils.ts:3086

Reads the dir attribute from a DOM element and applies it to the given ElementNode via ElementNode.setDirection when it is a valid direction value ('ltr' or 'rtl'). Other values, including missing or empty dir, leave the node unchanged. Useful inside importDOM converters to preserve explicit text direction from imported HTML.

Type Parameters​

T​

T extends ElementNode

Parameters​

node​

T

The ElementNode to update.

domNode​

HTMLElement

The source HTMLElement whose dir attribute is read.

Returns​

T

The node, with its direction set when the source dir was valid.


$setFormatFromDOM()​

$setFormatFromDOM<T>(node, domNode): T

Defined in: packages/lexical/src/LexicalUtils.ts:3105

Reads the style and CSS textAlign property from a DOM element and set format to the given ElementNode via ElementNode.setFormat when it is a valid alignment value ElementFormatType Other values, including missing or empty, leave the node unchanged. Useful inside importDOM converters to preserve explicit alignment from imported HTML.

Type Parameters​

T​

T extends ElementNode

Parameters​

node​

T

The ElementNode to update.

domNode​

HTMLElement

The source HTMLElement whose style property is read.

Returns​

T

The node, with its align format set when the source style.textAlign was valid.


$setPointFromCaret()​

$setPointFromCaret<D>(point, caret): void

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:97

Update the given point in-place from the PointCaret

Type Parameters​

D​

D extends CaretDirection

Parameters​

point​

PointType

the point to set

caret​

PointCaret<D>

the caret to set the point from

Returns​

void


$setSelection()​

$setSelection(selection): void

Defined in: packages/lexical/src/LexicalUtils.ts:862

Sets the current selection in the active EditorState, marking it dirty and clamping to slot boundaries when applicable.

Parameters​

selection​

BaseSelection | null

Returns​

void


$setSelectionFromCaretRange()​

$setSelectionFromCaretRange(caretRange): RangeSelection

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:133

Set a RangeSelection on the editor from the given CaretRange

Parameters​

caretRange​

CaretRange

Returns​

RangeSelection

The new RangeSelection


$setSlot()​

$setSlot<T>(host, name, node): T

Defined in: packages/lexical/src/LexicalSlot.ts:464

Experimental

Places node into the named slot of host, replacing any existing value under that name. Move semantics, mirroring ElementNode.append / insertBefore: the value is detached from wherever it currently lives — a child of another element, or a slot on this or another host (a node's two up-links, __parent and __slotHost, are mutually exclusive, so it holds exactly one) — before linking, so re-slotting never requires an explicit remove first. The replaced value, if any, is detached.

A slot value must be a non-inline ElementNode or a non-inline DecoratorNode: the slot link itself acts as a virtual shadow root between the host and the value, so the value does not need to be a shadow root — a plain block (e.g. a ParagraphNode subclass serving as a single-line field) is a valid slot value, and selection, traversal, and editing treat its slot boundary exactly like a shadow-root boundary.

host is constrained to SlotHostNode so a non-host is rejected at compile time.

Type Parameters​

T​

T extends LexicalNode & SlotHostNode

Parameters​

host​

T

name​

SlotName<T>

node​

LexicalNode

Returns​

T


$setState()​

$setState<Node, K, V>(node, stateConfig, valueOrUpdater): Node

Defined in: packages/lexical/src/LexicalNodeState.ts:625

Set the state defined by stateConfig on node. Like with React.useState you may directly specify the value or use an updater function that will be called with the previous value of the state on that node (which will be the stateConfig.defaultValue if not set).

When an updater function is used, the node will only be marked dirty if stateConfig.isEqual(prevValue, value) is false.

Type Parameters​

Node​

Node extends LexicalNode

K​

K extends string

V​

V

Parameters​

node​

Node

The LexicalNode to set the state on

stateConfig​

StateConfig<K, V>

The configuration for this state

valueOrUpdater​

ValueOrUpdater<V>

The value or updater function

Returns​

Node

node

Example​

const toggle = createState('toggle', {parse: Boolean});
// set it direction
$setState(node, counterState, true);
// use an updater
$setState(node, counterState, (prev) => !prev);

$setTextFormat()​

$setTextFormat(selection, formats): void

Defined in: packages/lexical/src/LexicalSelection.ts:2369

Explicitly sets or unsets text formats on the selection. Unlike $formatText which toggles based on the current selection state, this function sets each specified format to the exact boolean value provided. Mutually exclusive formats (subscript/superscript, lowercase/uppercase/capitalize) are reconciled by toggleTextFormatType, with later entries winning when the requested formats conflict.

Parameters​

selection​

RangeSelection | NodeSelection

the selection whose nodes should be formatted.

formats​

Partial<Record<TextFormatType, boolean>>

a partial record mapping TextFormatType to boolean.

Returns​

void


$splitAtPointCaretNext()​

$splitAtPointCaretNext(pointCaret, __namedParameters?): NodeCaret<"next"> | null

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:789

Split a node at a PointCaret and return a NodeCaret at that point, or null if the node can't be split. This is non-recursive and will only perform at most one split.

Parameters​

pointCaret​

PointCaret<"next">

__namedParameters?​

SplitAtPointCaretNextOptions = {}

Returns​

NodeCaret<"next"> | null

The NodeCaret pointing to the location of the split (or null if a split is not possible)


$splitNode()​

$splitNode(node, offset): [ElementNode | null, ElementNode]

Defined in: packages/lexical/src/LexicalUtils.ts:2582

Splits an ElementNode at the given child offset, returning [original, newCopy]. The original is mutated (children after offset moved out); the first element may be null per the return type contract. Recursively splits ancestors up to the nearest root or shadow root.

Parameters​

node​

ElementNode

offset​

number

Returns​

[ElementNode | null, ElementNode]


$updateRangeSelectionFromCaretRange()​

$updateRangeSelectionFromCaretRange(selection, caretRange): void

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:148

Update the points of a RangeSelection based on the given PointCaret.

Parameters​

selection​

RangeSelection

caretRange​

CaretRange

Returns​

void


$withCompactExport()​

$withCompactExport<T>(compact, f, ...reject): T

Defined in: packages/lexical/src/LexicalSerializedExport.ts:64

Experimental

Run f writing the compact form of the document (or, with false, the legacy form), for any export it performs: the @lexical/clipboard selection export, a serialization walk of your own, and the nested editors those serialize. A whole document states its form at the call site instead — editorState.toJSON(true) — which is what lets its return type say which shape it is; this is for the walks that have no such argument to take.

The compact form omits every property parsing would restore anyway — one whose value is its schema default, one the parser derives rather than reads, and the deprecated version — so the two forms describe the same document. It can only be read by a Lexical new enough to restore them, so keep writing the legacy form until every reader is upgraded.

f must be synchronous. The form is restored as soon as it returns, so an async callback would give up the form at its first await and export in whatever form is ambient when it resumes. A callback whose return type is a promise is rejected at the call site by the trailing parameter, which is an empty tuple for every other type; the runtime check behind it is for an untyped caller, and runs in every build, because the failure it catches is a document written in the wrong form rather than a degraded experience.

Type Parameters​

T​

T

Parameters​

compact​

boolean

f​

() => T

reject​

...T extends PromiseLike<unknown> ? [never] : []

Returns​

T

Example​

const selectionJSON = $withCompactExport(true, () =>
$generateJSONFromSelectedNodes(editor, $getSelection()),
);

addClassNamesToElement()​

addClassNamesToElement(element, ...classNames): void

Defined in: packages/lexical/src/utils/classNames.ts:32

Takes an HTML element and adds the classNames passed within an array, ignoring any non-string types. A space can be used to add multiple classes eg. addClassNamesToElement(element, ['element-inner active', true, null]) will add both 'element-inner' and 'active' as classes to that element.

Parameters​

element​

HTMLElement

The element in which the classes are added

classNames​

...(string | boolean | null | undefined)[]

An array defining the class names to add to the element

Returns​

void


aliasedValue()​

aliasedValue<T, A, In>(inner, aliases): SerializationSchema<T, never, In | Extract<keyof A, string>>

Defined in: packages/lexical/src/LexicalSchema.ts:2604

Combinator for a value that older documents may spell as one of a fixed set of names — TextNode's format: 'bold' for the numeric bit it stands for. A string matching one of aliases yields the value it names; anything else is inner's to validate, so the domain, the default and the equality all stay inner's and only the accepted input is wider.

This is transformValue narrowed to the case where the normalization is a lookup, and the reason to prefer it is that the lookup is data: it goes into the schema's meta, where a tool can see it. A transformValue keeps its function to itself, so its meta can say only that a transform happens: example generation still reaches the inner domain, and a code generator refuses the property rather than compile a parse that stores the alias where the schema stores what it names.

Type Parameters​

T​

T

A​

A extends object

In​

In = T

Parameters​

inner​

SerializationSchema<T, never, In>

aliases​

A

Returns​

SerializationSchema<T, never, In | Extract<keyof A, string>>

Example​

const parseFormat = aliasedValue(numberValue(), TEXT_TYPE_TO_FORMAT);
// ^? SerializationSchema<number>
parseFormat(1); // 1
parseFormat('bold'); // IS_BOLD
parseFormat('42'); // 42 (not an alias, so numberValue reads it)
parseFormat('junk'); // 0 (numberValue falls back to its default)

@NO_SIDE_EFFECTS


arrayValue()​

arrayValue<T, In>(item): SerializationSchema<T[], never, readonly In[]>

Defined in: packages/lexical/src/LexicalSchema.ts:2794

Build a SerializationSchema for an array whose entries are each coerced by item. A non-array value (including undefined) yields the empty array, which is the recoverable default.

Type Parameters​

T​

T

In​

In = T

Parameters​

item​

SerializationSchema<T, never, In>

Returns​

SerializationSchema<T[], never, readonly In[]>

Example​

const parseIds = arrayValue(stringValue());
// ^? SerializationSchema<string[]>
parseIds(['a', 'b']); // ['a', 'b']
parseIds('nope'); // []

@NO_SIDE_EFFECTS


booleanValue()​

booleanValue(defaultValue?): SerializationSchema<boolean>

Defined in: packages/lexical/src/LexicalSchema.ts:1941

Build a SerializationSchema that returns value when it is a boolean, otherwise returns defaultValue (false by default). @NO_SIDE_EFFECTS

Parameters​

defaultValue?​

boolean = false

Returns​

SerializationSchema<boolean>


buildImportMap()​

buildImportMap<K>(importMap): DOMConversionMap

Defined in: packages/lexical/src/LexicalNode.ts:849

An identity function that will infer the type of DOM nodes based on tag names to make it easier to construct a DOMConversionMap.

Type Parameters​

K​

K extends string

Parameters​

importMap​

{ [NodeName in string]: DOMConversionPropByTagName<NodeName> }

Returns​

DOMConversionMap


configExtension()​

configExtension<Config, Name, Output, Init>(...args): NormalizedLexicalExtensionArgument<Config, Name, Output, Init>

Defined in: packages/lexical/src/extension-core/defineExtension.ts:93

Override a partial of the configuration of an Extension, to be used in the dependencies array of another extension, or as an argument to buildEditorFromExtensions.

Before building the editor, configurations will be merged using extension.mergeConfig(extension, config) or shallowMergeConfig if this is not directly implemented by the Extension.

Type Parameters​

Config​

Config extends ExtensionConfigBase

Name​

Name extends string

Output​

Output

Init​

Init

Parameters​

args​

...NormalizedLexicalExtensionArgument<Config, Name, Output, Init>

An extension followed by one or more config partials for that extension

Returns​

NormalizedLexicalExtensionArgument<Config, Name, Output, Init>

[extension, config, ...configs]

Example​

export const ReactDecoratorExtension = defineExtension({
name: "react-decorator",
dependencies: [
configExtension(ReactExtension, {
decorators: [<ReactDecorator />]
}),
],
});

@NO_SIDE_EFFECTS

Lexical-inline​

args


createCommand()​

createCommand<T>(type?): LexicalCommand<T>

Defined in: packages/lexical/src/LexicalCommands.ts:27

Crete a command that can be used with editor.dispatchCommand and editor.registerCommand. Commands are used by unique reference, not by name.

Type Parameters​

T​

T

Parameters​

type?​

string

A string to identify the command, very helpful for debugging

Returns​

LexicalCommand<T>

A new LexicalCommand

@NO_SIDE_EFFECTS


createEditor()​

createEditor(editorConfig?): LexicalEditor

Defined in: packages/lexical/src/LexicalEditor.ts:954

Creates a new LexicalEditor attached to a single contentEditable (provided in the config). This is the lowest-level initialization API for a LexicalEditor. If you're using React or another framework, consider using the appropriate abstractions, such as LexicalComposer

Parameters​

editorConfig?​

CreateEditorArgs

the editor configuration.

Returns​

LexicalEditor

a LexicalEditor instance


createRefCountedRegistry()​

createRefCountedRegistry<Key, Options>(activate): RefCountedRegistry<Key, Options>

Defined in: packages/lexical/src/LexicalRefCountedRegistry.ts:45

Creates a RefCountedRegistry.

Type Parameters​

Key​

Key

Options​

Options = void

Parameters​

activate​

(key, options) => () => void

Wires key and returns its teardown. Called on the first registration of each key. @NO_SIDE_EFFECTS

Returns​

RefCountedRegistry<Key, Options>


createState()​

createState<K, V>(key, valueConfig): StateConfig<K, V>

Defined in: packages/lexical/src/LexicalNodeState.ts:537

Create a StateConfig for the given string key and StateValueConfig.

The key must be locally unique. In dev you will get a key collision error when you use two separate StateConfig on the same node with the same key.

The returned StateConfig value should be used with $getState and $setState.

Type Parameters​

K​

K extends string | symbol

V​

V

Parameters​

key​

K

The key to use

valueConfig​

StateValueConfig<V>

Configuration for the value type

Returns​

StateConfig<K, V>

a StateConfig

@NO_SIDE_EFFECTS


declarePeerDependency()​

declarePeerDependency<Extension>(...args): NormalizedPeerDependency<Extension>

Defined in: packages/lexical/src/extension-core/defineExtension.ts:130

Used to declare a peer dependency of an extension in a type-safe way, requires the type parameter. The most common use case for peer dependencies is to avoid a direct import dependency, so you would want to use a type import or the import type (shown in below examples).

Type Parameters​

Extension​

Extension extends AnyLexicalExtension = never

Parameters​

args​

...[Extension["name"], Partial<LexicalExtensionConfig<Extension>>]

Returns​

NormalizedPeerDependency<Extension>

NormalizedPeerDependency

Example​

import type {FooExtension} from "foo";

export const PeerExtension = defineExtension({
name: 'PeerExtension',
peerDependencies: [
declarePeerDependency<FooExtension>("foo"),
declarePeerDependency<typeof import("bar").BarExtension>("bar", {config: "bar"}),
],
});

@NO_SIDE_EFFECTS

Lexical-inline​

args


defineExtension()​

defineExtension<Config, Name, Output, Init>(extension): LexicalExtension<Config, Name, Output, Init>

Defined in: packages/lexical/src/extension-core/defineExtension.ts:55

Define a LexicalExtension from the given object literal. TypeScript will infer Config and Name in most cases, but you may want to use safeCast for config if there are default fields or varying types.

Type Parameters​

Config​

Config extends ExtensionConfigBase

Name​

Name extends string

Output​

Output

Init​

Init

Parameters​

extension​

LexicalExtension<Config, Name, Output, Init>

The LexicalExtension

Returns​

LexicalExtension<Config, Name, Output, Init>

The unmodified extension argument (this is only an inference helper)

Examples​

Basic example

export const MyExtension = defineExtension({
// Extension names must be unique in an editor
name: "my",
nodes: [MyNode],
});

Extension with optional configuration

export interface ConfigurableConfig {
optional?: string;
required: number;
}
export const ConfigurableExtension = defineExtension({
name: "configurable",
// The Extension's config must satisfy the full config type,
// but using the Extension as a dependency never requires
// configuration and any partial of the config can be specified
config: safeCast<ConfigurableConfig>({ required: 1 }),
});

@NO_SIDE_EFFECTS

Lexical-inline​

identity


enumValue()​

enumValue<T, D>(values, ...args): SerializationSchema<T>

Defined in: packages/lexical/src/LexicalSchema.ts:1987

Build a SerializationSchema for a fixed set of allowed values (an enumeration or a union of literals such as the mode of a TextNode). Returns value when it is strictly equal to one of values, otherwise returns defaultValue, which defaults to the first entry of values.

The type parameter is const, so the literal types of values are inferred directly — the caller does not need an as const assertion. (Pass an explicit type argument, e.g. enumValue<TextModeType>([...]), to instead assert the values against a known domain type.)

undefined may be a member of the domain, and a declared undefined default is taken as declared: enumValue([undefined, 'middle', 'bottom']) and enumValue(['middle', undefined], undefined) both default to undefined.

values must be non-empty, which the type states as a tuple: an empty domain admits nothing, so every value — including one the caller believes is in the enum — would parse to a default that came from nowhere. A list built at runtime is checked as well in a development build, since a type can be asserted past.

Type Parameters​

T​

T

D​

D = T

Parameters​

values​

readonly [T, T]

args​

[] | [D]

Returns​

SerializationSchema<T>

Example​

const parseMode = enumValue(['normal', 'token', 'segmented']);
// ^? SerializationSchema<'normal' | 'token' | 'segmented'>, default 'normal'

@NO_SIDE_EFFECTS


flipDirection()​

flipDirection<D>(direction): FlipDirection<D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:581

Flip a direction ('next' -> 'previous'; 'previous' -> 'next').

Note that TypeScript can't prove that FlipDirection is its own inverse (but if you have a concrete 'next' or 'previous' it will simplify accordingly).

Type Parameters​

D​

D extends CaretDirection

Parameters​

direction​

D

A direction

Returns​

FlipDirection<D>

The opposite direction


getActiveElement()​

getActiveElement(node): Element | null

Defined in: packages/lexical/src/LexicalUtils.ts:2511

Experimental

Returns the focused element within the same Document or ShadowRoot as node, using the standard DocumentOrShadowRoot.activeElement.

Unlike document.activeElement — which is retargeted to the outermost shadow host when focus is inside a shadow tree — this returns the focused element within node's own tree (e.g. the editor's contentEditable when it lives inside a shadow root).

Parameters​

node​

Node

A node whose tree's active element is wanted.

Returns​

Element | null

The active element, or null.

Shape may change as shadow DOM support stabilizes.


getActiveElementDeep()​

getActiveElementDeep(root): Element | null

Defined in: packages/lexical/src/LexicalUtils.ts:2529

Experimental

Descends from root.activeElement through nested open ShadowRoots to the deepest focused element. document.activeElement only reports the outermost shadow host; this walks into the shadow trees via ShadowRoot.activeElement to find the element that actually has focus.

Parameters​

root​

Document | ShadowRoot

The Document or ShadowRoot to start from.

Returns​

Element | null

The deepest active element, or null.

Shape may change as shadow DOM support stabilizes.


getComposedEventTarget()​

getComposedEventTarget(event): EventTarget | null

Defined in: packages/lexical/src/LexicalUtils.ts:2565

Experimental

Returns the un-retargeted event target — the real element the user interacted with — for events observed by a listener above an enclosing DOM shadow root. Event.target is retargeted to the outermost shadow host in that case, hiding the actual element; composedPath()[0] returns the original target for composed: true events (most user-agent UI events: click, mousedown, pointerdown, focusin, etc.). Falls back to event.target when composedPath is unavailable or returns an empty array (e.g. the event has already finished dispatching).

Pairs with the shadow-aware helpers above (getDOMSelectionPoints, getActiveElement) for the event side of the shadow boundary — useful when an Element.contains(target) check needs to test against an editor root inside a shadow tree.

Parameters​

event​

Event

The dispatched event.

Returns​

EventTarget | null

The un-retargeted target, or null when the event has none.

Shape may change as shadow DOM support stabilizes.


getComposedStaticRange()​

getComposedStaticRange(domSelection, rootElement): StaticRange | null

Defined in: packages/lexical/src/LexicalUtils.ts:2297

Experimental

Resolves a DOM Selection's range through any DOM ShadowRoots enclosing rootElement, using the standard Selection.getComposedRanges platform API.

When a selection is inside a shadow tree the browser retargets Selection.getRangeAt/anchorNode/focusNode to the shadow host, which hides the real nodes Lexical needs to resolve. Passing the enclosing shadow roots to getComposedRanges returns the un-retargeted boundary points as a StaticRange (in tree order, i.e. start before end).

Parameters​

domSelection​

Selection

rootElement​

HTMLElement | null

Returns​

StaticRange | null

The composed StaticRange, or null when rootElement is in the light DOM, the platform does not implement getComposedRanges, or there is no selection.

Shape may change as shadow DOM support stabilizes.


getDeclaredSlots()​

getDeclaredSlots(klass): readonly string[]

Defined in: packages/lexical/src/LexicalSlot.ts:307

Experimental

Returns the canonical slot declaration for a node class: the slots array from the nearest StaticNodeConfigValue in its prototype chain (a subclass redeclaration overrides its ancestors'), or an empty array when nothing is declared. The declaration is an ordering vocabulary, not a schema — occupied names outside it are still valid and sort after the declared names in code-unit order.

named-slots

Parameters​

klass​

KlassConstructor<typeof LexicalNode>

Returns​

readonly string[]


getDOMOwnerDocument()​

getDOMOwnerDocument(target): Document | null

Defined in: packages/lexical/src/LexicalUtils.ts:1646

Returns the owner Document of the given EventTarget, or the target itself if it is a Document.

Parameters​

target​

EventTarget | null

Returns​

Document | null


getDOMSelection()​

getDOMSelection(targetWindow): Selection | null

Defined in: packages/lexical/src/LexicalUtils.ts:2125

Returns the selection for the given window, or the global window if null. Will return null if CAN_USE_DOM is false.

Parameters​

targetWindow​

Window | null

The window to get the selection from

Returns​

Selection | null

a Selection or null


getDOMSelectionFromTarget()​

getDOMSelectionFromTarget(eventTarget): Selection | null

Defined in: packages/lexical/src/LexicalUtils.ts:2135

Returns the selection for the defaultView of the ownerDocument of given EventTarget.

Parameters​

eventTarget​

EventTarget | null

The node to get the selection from

Returns​

Selection | null

a Selection or null


getDOMSelectionPoints()​

getDOMSelectionPoints(domSelection, rootElement): DOMSelectionBoundaryPoints

Defined in: packages/lexical/src/LexicalUtils.ts:2400

Experimental

Resolves a DOM Selection's anchor/focus boundary points through any DOM ShadowRoots enclosing rootElement. Inside a shadow tree the boundary points come from getComposedStaticRange mapped back onto anchor/focus with the standard Selection.direction; in the light DOM (or when getComposedRanges is unavailable) the Selection's own anchorNode/focusNode are already correct, so the Selection is returned as-is (it satisfies DOMSelectionBoundaryPoints).

Use this instead of reading Selection.anchorNode/focusNode directly, which are retargeted to the shadow host inside a shadow tree.

Parameters​

domSelection​

Selection

rootElement​

HTMLElement | null

Returns​

DOMSelectionBoundaryPoints

Remarks​

The two return paths have different read semantics:

  • light DOM: the return aliases domSelection, so subsequent reads reflect any post-call selection changes. The aliasing is intentional; each Selection property read forces a synchronous style/layout recalculation, so $updateDOMSelection defers these reads until they are actually needed.
  • shadow DOM: the return is a snapshot taken at call time, including direction. If a future engine ships getComposedRanges without Selection.direction (no current shipping configuration matches), the snapshot's direction is undefined and anchor/focus default to the StaticRange's tree order — a backward selection will appear forward.

Read the four points immediately after the call, or compare identity via points === domSelection to detect when the return aliases domSelection, rather than caching the returned reference across selection mutations.

Shape may change as shadow DOM support stabilizes.


getDOMSelectionRange()​

getDOMSelectionRange(domSelection, rootElement): Range | null

Defined in: packages/lexical/src/LexicalUtils.ts:2352

Experimental

Returns a live DOM Range for the Selection, resolved through any DOM ShadowRoots enclosing rootElement. Inside a shadow tree Selection.getRangeAt(0) is retargeted to the shadow host, so this builds a Range from the composed boundary points instead (see getComposedStaticRange); in the light DOM it returns getRangeAt(0) unchanged. Use this instead of getRangeAt(0) when the Range is needed for layout (e.g. getBoundingClientRect), which a StaticRange cannot provide.

Parameters​

domSelection​

Selection

rootElement​

HTMLElement | null

Returns​

Range | null

A live Range, or null when the selection has no ranges.

Shape may change as shadow DOM support stabilizes.


getDOMSelectionRangeAndPoints()​

getDOMSelectionRangeAndPoints(domSelection, rootElement): object

Defined in: packages/lexical/src/LexicalUtils.ts:2423

Experimental

Resolves the live DOM Range (for layout reads like getBoundingClientRect) and the anchor/focus boundary points in one pass, sharing a single getComposedStaticRange read rather than computing it twice as a call to getDOMSelectionRange followed by getDOMSelectionPoints would. Use this at sites that need both shapes from the same selection.

Parameters​

domSelection​

Selection

rootElement​

HTMLElement | null

Returns​

object

The composed Range plus the boundary points; the Range is null when the selection has no ranges.

Shape may change as shadow DOM support stabilizes.

points​

points: DOMSelectionBoundaryPoints

range​

range: Range | null


getDOMShadowRoots()​

getDOMShadowRoots(node): ShadowRoot[]

Defined in: packages/lexical/src/LexicalUtils.ts:2168

Parameters​

node​

Node

Returns​

ShadowRoot[]


getDOMTextNode()​

getDOMTextNode(element): Text | null

Defined in: packages/lexical/src/LexicalUtils.ts:361

Returns the first DOM Text node found by descending the firstChild chain from the given node, or null.

Parameters​

element​

Node | null

Returns​

Text | null


getNearestEditorFromDOMNode()​

getNearestEditorFromDOMNode(node): LexicalEditor | null

Defined in: packages/lexical/src/LexicalUtils.ts:299

Returns the nearest LexicalEditor instance by walking up the DOM tree from the given node, or null if none is found.

Parameters​

node​

Node | null

Returns​

LexicalEditor | null


getParentElement()​

getParentElement(node): HTMLElement | null

Defined in: packages/lexical/src/LexicalUtils.ts:1631

Returns the parent element of a DOM node, crossing shadow root boundaries and following slot assignments.

Parameters​

node​

Node

Returns​

HTMLElement | null


getRegisteredSubtypeMap()​

getRegisteredSubtypeMap(nodes): Map<string, Set<string>>

Defined in: packages/lexical/src/LexicalUtils.ts:5312

Experimental

Build a map from each registered node type to the set of registered node types that are it or extend it (including the type itself). For every node class in nodes, its prototype chain is walked and the class's own type is added to the bucket of each registered ancestor type it inherits from.

The result lets callers expand a base node type to all of its registered subclass types up front, so a subclass instance can be matched by type without a runtime instanceof.

Parameters​

nodes​

Iterable<KlassConstructor<typeof LexicalNode>>

Returns​

Map<string, Set<string>>


getStyleObjectFromCSS()​

getStyleObjectFromCSS(css): Record<string, string>

Defined in: packages/lexical/src/utils/setDOMStyle.ts:18

Parses inline CSS text into an object that is compatible with CSSStyleDeclaration.setProperty().

Property names are expected to be kebab-case, such as font-size, and values are expected to include explicit units where needed, such as 12px.

Parameters​

css​

string

Returns​

Record<string, string>


getTextDirection()​

getTextDirection(text): "ltr" | "rtl" | null

Defined in: packages/lexical/src/LexicalUtils.ts:320

Returns the text direction ('ltr' or 'rtl') of the given string, or null if it contains no strong directional characters.

Parameters​

text​

string

Returns​

"ltr" | "rtl" | null


INTERNAL_$expandSelectionToWholeDocument()​

INTERNAL_$expandSelectionToWholeDocument(selection): void

Defined in: packages/lexical/src/LexicalSelection.ts:2503

When selection covers the whole document, widen it to the root's own element points, so the range describes the top-level blocks themselves rather than only the text inside them.

A delete over that range then removes the blocks outright and leaves the editor on a fresh empty paragraph, instead of gutting them and leaving an empty heading, quote or list behind that keeps its type and styles the next character typed (#5835). It also keeps a cut honest: what lands on the clipboard is what leaves the document, so Cmd+X then Cmd+V restores the blocks rather than their bare text.

Widening rather than deleting-then-repairing is what makes this safe for every block type. The range simply contains the blocks, so nothing has to decide whether a heading, a nested list, a code block or a third-party node should dissolve, and no node is destroyed that the user did not select.

A no-op for anything else: a range that stops short of either end is an ordinary edit inside the blocks it touches, and a select-all scoped to a named slot never covers the root.

Parameters​

selection​

RangeSelection

Returns​

void


isBlockDomNode()​

isBlockDomNode(node): node is HTMLElement & { [BlockDOMBrand]: never }

Defined in: packages/lexical/src/LexicalUtils.ts:2711

Parameters​

node​

Node

the Dom Node to check

Returns​

node is HTMLElement & { [BlockDOMBrand]: never }

if the Dom Node is a block node


isCurrentlyReadOnlyMode()​

isCurrentlyReadOnlyMode(): boolean

Defined in: packages/lexical/src/LexicalUpdates.ts:107

Returns true if the current editor update context is read-only.

Returns​

boolean


isDocumentFragment()​

isDocumentFragment(x): x is DocumentFragment

Defined in: packages/lexical/src/LexicalUtils.ts:2680

Parameters​

x​

unknown

The element being testing

Returns​

x is DocumentFragment

Returns true if x is a document fragment, false otherwise.


isDOMCapturingSelection()​

isDOMCapturingSelection(elementDom, editor): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:3206

Experimental

True if the DOM node sits inside a subtree marked with {captureSelection: true} via setDOMUnmanaged. Walks ancestors so any descendant of a marked subtree (e.g. an <input> inside a marked <div>) reports as captured too.

The walk aborts at the first DOM node that corresponds to a Lexical node in editor — that boundary is the implicit owner of the subtree's selection, so a captureSelection marker above it (in non-Lexical scaffolding around the editor) does not leak in.

DecoratorNode DOM is marked with setDOMUnmanaged({captureSelection: true}) by the reconciler, so decorator subtrees also report as captured here.

Parameters​

elementDom​

Node & LexicalPrivateDOM

editor​

LexicalEditor

Returns​

boolean


isDOMDocumentNode()​

isDOMDocumentNode(node): node is Document

Defined in: packages/lexical/src/LexicalUtils.ts:356

Parameters​

node​

unknown

The element being tested

Returns​

node is Document

Returns true if node is an DOM Document node, false otherwise.


isDOMNode()​

isDOMNode(x): x is Node

Defined in: packages/lexical/src/LexicalUtils.ts:2667

Parameters​

x​

unknown

The element being tested

Returns​

x is Node

Returns true if x is a DOM Node, false otherwise.


isDOMShadowRoot()​

isDOMShadowRoot(node): node is ShadowRoot

Defined in: packages/lexical/src/LexicalUtils.ts:2149

Experimental

Parameters​

node​

unknown

A value that may be a DOM ShadowRoot.

Returns​

node is ShadowRoot

True if node is a DOM ShadowRoot (an open or closed shadow tree root), false otherwise. A ShadowRoot is a DocumentFragment with a host.

Shape may change as shadow DOM support stabilizes.


isDOMTextNode()​

isDOMTextNode(node): node is Text

Defined in: packages/lexical/src/LexicalUtils.ts:348

Parameters​

node​

unknown

The element being tested

Returns​

node is Text

Returns true if node is an DOM Text node, false otherwise.


isDOMUnmanaged()​

isDOMUnmanaged(elementDom): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:3161

Experimental

True if this DOM node was marked with setDOMUnmanaged.

Parameters​

elementDom​

Node & LexicalPrivateDOM

Returns​

boolean


isExactShortcutMatch()​

isExactShortcutMatch(event, expectedKey, mask): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:1255

Match a KeyboardEvent with its expected state

Parameters​

event​

KeyboardEventModifiers

A KeyboardEvent, or structurally similar object

expectedKey​

string

The string to compare with event.key (case insensitive)

mask​

KeyboardEventModifierMask

An object specifying the expected state of the modifiers

Returns​

boolean

true if the event matches


isHTMLAnchorElement()​

isHTMLAnchorElement(x): x is HTMLAnchorElement

Defined in: packages/lexical/src/LexicalUtils.ts:2634

Parameters​

x​

unknown

The element being tested

Returns​

x is HTMLAnchorElement

Returns true if x is an HTML anchor tag, false otherwise


isHTMLElement()​

isHTMLElement(x): x is HTMLElement

Defined in: packages/lexical/src/LexicalUtils.ts:2659

Parameters​

x​

unknown

The element being tested

Returns​

x is HTMLElement

Returns true if x is an HTML element, false otherwise.


isHTMLTableCellElement()​

isHTMLTableCellElement(x): x is HTMLTableCellElement

Defined in: packages/lexical/src/LexicalUtils.ts:2651

Parameters​

x​

unknown

The element being tested

Returns​

x is HTMLTableCellElement

Returns true if x is an HTML <td> or <th> element, false otherwise


isHTMLTableRowElement()​

isHTMLTableRowElement(x): x is HTMLTableRowElement

Defined in: packages/lexical/src/LexicalUtils.ts:2642

Parameters​

x​

unknown

The element being tested

Returns​

x is HTMLTableRowElement

Returns true if x is an HTML <tr> element, false otherwise


isInlineDomNode()​

isInlineDomNode(node): node is (HTMLElement | Text) & { [InlineDOMBrand]: never }

Defined in: packages/lexical/src/LexicalUtils.ts:2692

Parameters​

node​

Node

the Dom Node to check

Returns​

node is (HTMLElement | Text) & { [InlineDOMBrand]: never }

if the Dom Node is an inline node


isLastChildInBlockNode()​

isLastChildInBlockNode(node): boolean

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:119

Experimental

True when node is the trailing non-whitespace child of a block DOM element (excluding the only-child case). Used by the LineBreak importer to drop trailing <br> elements like the Apple-interchange clipboard artifact (matches LineBreakNode.importDOM).

Parameters​

node​

Node

Returns​

boolean


isLexicalEditor()​

isLexicalEditor(editor): editor is LexicalEditor

Defined in: packages/lexical/src/LexicalUtils.ts:293

Parameters​

editor​

unknown

Returns​

editor is LexicalEditor

true if the given argument is a LexicalEditor instance from this build of Lexical


isModifierMatch()​

isModifierMatch(event, mask): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:1235

Match a KeyboardEvent with its expected modifier state

Parameters​

event​

KeyboardEventModifiers

A KeyboardEvent, or structurally similar object

mask​

KeyboardEventModifierMask

An object specifying the expected state of the modifiers

Returns​

boolean

true if the event matches


isOnlyChildInBlockNode()​

isOnlyChildInBlockNode(node): boolean

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:90

Experimental

True when node is the sole non-whitespace child of a block DOM element. Used by the LineBreak importer to drop stray <br> elements that the legacy $generateNodesFromDOM also skipped (matches the behavior of LineBreakNode.importDOM).

Parameters​

node​

Node

Returns​

boolean


isSchemaField()​

isSchemaField<T>(accessor): accessor is T

Defined in: packages/lexical/src/LexicalSchema.ts:926

Whether an accessor names a node field rather than a method.

Generic in the field type so it narrows to the direction it was handed: given a SchemaGetterAccessor it yields a SchemaGetterField, whose getterTable is then the only table in scope.

Type Parameters​

T​

T extends SchemaFieldBase

Parameters​

accessor​

string | T | null | undefined

Returns​

accessor is T


isSelectionWithinEditor()​

isSelectionWithinEditor(editor, anchorDOM, focusDOM): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:261

Returns true if the given DOM anchor and focus nodes are inside the editor's root element and not captured by a decorator input.

Parameters​

editor​

LexicalEditor

anchorDOM​

Node | null

focusDOM​

Node | null

Returns​

boolean


makeStepwiseIterator()​

makeStepwiseIterator<State, Stop, Value>(config): IterableIterator<Value>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1228

A generalized utility for creating a stepwise iterator based on:

  • an initial state
  • a stop guard that returns true if the iteration is over, this is typically used to detect a sentinel value such as null or undefined from the state but may return true for other conditions as well
  • a step function that advances the state (this will be called after map each time next() is called to prepare the next state)
  • a map function that will be called that may transform the state before returning it. It will only be called once for each next() call when stop(state) === false

Type Parameters​

State​

State

Stop​

Stop

Value​

Value

Parameters​

config​

StepwiseIteratorConfig<State, Stop, Value>

Returns​

IterableIterator<Value>

An IterableIterator


mergeRegister()​

mergeRegister(...func): () => void

Defined in: packages/lexical/src/utils/mergeRegister.ts:34

Returns a function that will execute all functions passed when called. It is generally used to register multiple lexical listeners and then tear them down with a single function call, such as React's useEffect hook.

Parameters​

func​

...() => void[]

An array of cleanup functions meant to be executed by the returned function.

Returns​

the function which executes all the passed cleanup functions.

() => void

Example​

useEffect(() => {
return mergeRegister(
editor.registerCommand(...registerCommand1 logic),
editor.registerCommand(...registerCommand2 logic),
editor.registerCommand(...registerCommand3 logic)
)
}, [editor])

In this case, useEffect is returning the function returned by mergeRegister as a cleanup function to be executed after either the useEffect runs again (due to one of its dependencies updating) or the component it resides in unmounts. Note the functions don't necessarily need to be in an array as all arguments are considered to be the func argument and spread from there. The order of cleanup is the reverse of the argument order. Generally it is expected that the first "acquire" will be "released" last (LIFO order), because a later step may have some dependency on an earlier one.


mountSlotContainer()​

mountSlotContainer(editor, nodeKey, slotName, target): HTMLElement | null

Defined in: packages/lexical/src/LexicalUtils.ts:2853

Experimental

Attach a host's named-slot container to target and make it visible. The reconciler renders every slot subtree synchronously into a hidden (display: 'none') placeholder container parked slots-first in the host DOM; nothing is visible until the host explicitly attaches the container somewhere — mirroring how getDOMSlot gives an element control over where its linked-list children render. This helper moves the container into target (a no-op when it is already there, so mounting in place just reveals it) and clears the inline display so the container renders as a normal block that stylesheets may restyle. It deliberately does NOT use display: 'contents': Chromium cannot reliably edit inside a boxless contenteditable subtree (caret hit-testing resolves clicks to a neighboring box and native text insertion is dropped).

Idempotent and framework-independent: lexical-react's useLexicalSlotRef wraps it, and a node class or extension can call it directly (e.g. from a mutation listener) to control slot placement without React.

Parameters​

editor​

LexicalEditor

nodeKey​

string

slotName​

string

target​

HTMLElement

Returns​

HTMLElement | null

the container, or null when the slot (or its DOM) does not exist yet — e.g. before the host's first reconciliation.


nodeSchema()​

nodeSchema<N>(): <F>(fields) => NodeSerializationSchema<N, { readonly [K in string | number | symbol]?: SchemaInput<F[K]> }>

Defined in: packages/lexical/src/LexicalSchema.ts:2530

A node's serialization schema, checked against the node it is for.

The same shape objectValue takes, with one type argument naming the node — which is what lets every field, accessor method and when predicate be verified to exist. A name the node does not have is a compile error at the property that declares it, with the correction suggested:

const codeNodeSchema = nodeSchema<CodeNode>()({
language: withField(optional(nullable(stringValue())), {
field: '__langauge',
}),
});
// ~~~~~~~~~~~~
// Type '"field:__langauge"' is not assignable to type '... | TaggedNamesOf<CodeNode> | ObligationsOf<CodeNode>'.
// Did you mean '"field:__language"'?

Where the schema is written does not change what is checked: a module-scope const above the class — a class's type is in scope before its definition, and this is what every built-in node does — or inline in $config(), as TabNode spells it. Checking a declaration means resolving the class's members, and an unannotated $config() has a return type inferred from this very schema; the members whose types come from it are skipped (ScannableKeys), and what a setter returns is compared against the brand every node carries rather than all of LexicalNode (SetterReturn), so that neither position asks the check for its own answer.

The result reports no outstanding names, which is what $config's json requires — so a schema that names anything has to come through here, and the check cannot be skipped by declaring the properties some other way.

@NO_SIDE_EFFECTS

Type Parameters​

N​

N extends unknown

Returns​

<F>(fields) => NodeSerializationSchema<N, { readonly [K in string | number | symbol]?: SchemaInput<F[K]> }>


nullable()​

nullable<T, In>(inner, options?): SerializationSchema<T | null, never, In | null | undefined>

Defined in: packages/lexical/src/LexicalSchema.ts:2080

Combinator that makes any SerializationSchema nullable. The returned schema yields null when the value is null or undefined (so null is its recoverable default) and otherwise delegates to inner. This guarantees a T | null result for an untrusted value, unlike value || null, which can pass a non-T (or falsy) value straight through with the wrong type.

Pass {defaultAsNull: true} when an in-band value equal to inner's default also means "no value" — the historical serializedNode.rel || null idiom, where an empty string is not a real rel. Equality is inner's own (see SerializationSchema.isEqual), so a reference-typed default is compared by content: nullable(arrayValue(...), {defaultAsNull: true}) reads an explicitly empty array as null.

Type Parameters​

T​

T

In​

In = T

Parameters​

inner​

SerializationSchema<T, never, In>

options?​
defaultAsNull?​

boolean

Returns​

SerializationSchema<T | null, never, In | null | undefined>

Example​

const parseRel = nullable(stringValue(), {defaultAsNull: true});
// ^? SerializationSchema<string | null>
parseRel('noopener'); // 'noopener'
parseRel(''); // null ('' is stringValue's default)
parseRel(null); // null
parseRel(undefined); // null (the recoverable default)

@NO_SIDE_EFFECTS


numberValue()​

numberValue(defaultValue?, options?): SerializationSchema<number, never, string | number>

Defined in: packages/lexical/src/LexicalSchema.ts:1861

Build a SerializationSchema that returns value when it is a finite number, otherwise returns defaultValue (0 by default). NaN, Infinity, and -Infinity are all treated as out of domain since they can not be round-tripped through JSON.

A string spelled as a JSON number is accepted and converted, so a document that stored "120" where Lexical writes 120 — a hand-authored fixture, a converter, or a backend that stringified its numbers — keeps its value instead of silently falling back to the default. The domain is still numbers: that is what the schema reports and what parsing returns, a string is only an input encoding of it. Only the JSON grammar is read, so notations that JSON itself can not produce ("0x10", "1_000", "+1", "Infinity") stay out of domain.

@NO_SIDE_EFFECTS

Parameters​

defaultValue?​

number = 0

options?​

NumberValueOptions = {}

Returns​

SerializationSchema<number, never, string | number>


objectValue()​

objectValue<S>(fields): ObjectSchema<S>

Defined in: packages/lexical/src/LexicalSchema.ts:2884

Compose per-property SerializationSchemas into a single SerializationSchema for an object-valued property. Calling it coerces each known property in turn (ignoring any extra properties), so objectValue(...) applied to a partial or untrusted object returns a fully-populated, validated object; objectValue(...)(undefined) returns the all-defaults object. Its fields name no accessor: an object's field is not a node's property, which is what nodeSchema — the same record, checked against a node — is for.

Type Parameters​

S​

S extends InnerSerializationSchemaFields

Parameters​

fields​

S

Returns​

ObjectSchema<S>

Example​

// A property whose value is an object of its own; a node's own schema is
// nodeSchema<MyNode>()({...}), whose fields may name accessors.
const dimensions = objectValue({
height: numberValue(),
width: numberValue(),
});

@NO_SIDE_EFFECTS


optional()​

optional<T, In>(inner, options?): SerializationSchema<T | undefined, never, In | undefined>

Defined in: packages/lexical/src/LexicalSchema.ts:2132

Combinator that makes any SerializationSchema optional. The returned schema yields undefined when the value is undefined (so undefined is its recoverable default) and otherwise delegates to inner. Use it for serialized properties that may be absent and, when absent, should stay absent (an exported T | undefined property is omitted from the JSON rather than persisted).

Pass {omitDefault: true} when an in-band value equal to inner's default means "absent" rather than "explicitly this value" — the historical serializedNode.width || undefined idiom, where a falsy 0 is not a real width. Such a value (and any out-of-domain input, which inner coerces to its default) yields undefined, so it is omitted from the exported JSON instead of being persisted as the default. Equality is inner's own (see SerializationSchema.isEqual), so a reference-typed default is compared by content: optional(arrayValue(...), {omitDefault: true}) omits an explicitly empty array rather than persisting it.

Type Parameters​

T​

T

In​

In = T

Parameters​

inner​

SerializationSchema<T, never, In>

options?​
omitDefault?​

boolean

Returns​

SerializationSchema<T | undefined, never, In | undefined>

Example​

const parseWidth = optional(numberValue());
// ^? SerializationSchema<number | undefined>
parseWidth(120); // 120
parseWidth(undefined); // undefined (the recoverable default)

const parseCellWidth = optional(numberValue(), {omitDefault: true});
parseCellWidth(0); // undefined (0 is not a real width)
parseCellWidth('x'); // undefined (coerced to the default, then omitted)

@NO_SIDE_EFFECTS


rawValue()​

rawValue<T>(): SerializationSchema<T | undefined, never, unknown>

Defined in: packages/lexical/src/LexicalSchema.ts:2754

Build a SerializationSchema for a value this schema deliberately does not validate, because something else owns its domain — the motivating case is a nested SerializedEditor, which the nested editor's own parseEditorState validates when the property is applied.

The value is passed through unchanged and undefined is the recoverable default, so declaring the property still routes it through the node's setter (and keeps it visible to schema-walking tooling) without pretending to validate its contents. @NO_SIDE_EFFECTS

Type Parameters​

T​

T

Returns​

SerializationSchema<T | undefined, never, unknown>


registerEventListener()​

Call Signature​

registerEventListener<T, K>(target, type, listener, options?): () => void

Defined in: packages/lexical/src/utils/registerEventListener.ts:62

Add an event listener to target and return a function that removes it.

This is a thin, strongly typed wrapper around EventTarget.addEventListener that mirrors its overloads but returns a dispose function instead of void. It removes the addEventListener/removeEventListener boilerplate that every DOM subscription would otherwise duplicate, and composes cleanly with mergeRegister or as the return value of an effect.

The same options value is forwarded to both addEventListener and removeEventListener so that the capture flag always matches, which is required for the listener to be removed correctly.

Type Parameters​
T​

T extends EventTarget

K​

K extends string

Parameters​
target​

T

The EventTarget to subscribe to

type​

K

The event type to listen for (e.g. 'keydown')

listener​

(this, ev) => unknown

The listener invoked when a matching event is dispatched

options?​

boolean | AddEventListenerOptions

Options forwarded to add/removeEventListener

Returns​

A function that removes the listener when called

() => void

Examples​
// Returned directly from a React effect
useEffect(
() => registerEventListener(container, 'keydown', handler),
[container],
);
// Composed with other teardown via mergeRegister
return mergeRegister(
registerEventListener(window, 'resize', onResize),
registerEventListener(document, 'selectionchange', onSelectionChange),
);

Call Signature​

registerEventListener(target, type, listener, options?): () => void

Defined in: packages/lexical/src/utils/registerEventListener.ts:73

Add an event listener to target and return a function that removes it.

This is a thin, strongly typed wrapper around EventTarget.addEventListener that mirrors its overloads but returns a dispose function instead of void. It removes the addEventListener/removeEventListener boilerplate that every DOM subscription would otherwise duplicate, and composes cleanly with mergeRegister or as the return value of an effect.

The same options value is forwarded to both addEventListener and removeEventListener so that the capture flag always matches, which is required for the listener to be removed correctly.

Parameters​
target​

EventTarget

The EventTarget to subscribe to

type​

string

The event type to listen for (e.g. 'keydown')

listener​

EventListenerOrEventListenerObject

The listener invoked when a matching event is dispatched

options?​

boolean | AddEventListenerOptions

Options forwarded to add/removeEventListener

Returns​

A function that removes the listener when called

() => void

Examples​
// Returned directly from a React effect
useEffect(
() => registerEventListener(container, 'keydown', handler),
[container],
);
// Composed with other teardown via mergeRegister
return mergeRegister(
registerEventListener(window, 'resize', onResize),
registerEventListener(document, 'selectionchange', onSelectionChange),
);

registerEventListeners()​

registerEventListeners<T>(target, listeners, options?): () => void

Defined in: packages/lexical/src/utils/registerEventListeners.ts:56

Add several event listeners to a single target and return one function that removes all of them.

This is the batch form of registerEventListener: it takes a {type: listener} object (strongly typed per event type) and shares one options value across every listener. The returned dispose function removes the listeners in reverse registration order (via mergeRegister).

Because options is shared, register listeners that need a different options value (e.g. a different capture flag) with a separate call and combine the results with mergeRegister.

Type Parameters​

T​

T extends EventTarget

Parameters​

target​

T

The EventTarget to subscribe to

listeners​

EventListenerMap<T>

A map of event type to listener

options?​

boolean | AddEventListenerOptions

Options forwarded to add/removeEventListener for every listener

Returns​

A function that removes every listener when called

() => void

Example​

// All five listeners share {capture: true}
return registerEventListeners(
window,
{
beforeinput: report,
cut: report,
keydown: report,
paste: report,
selectionchange: report,
},
{capture: true},
);

removeClassNamesFromElement()​

removeClassNamesFromElement(element, ...classNames): void

Defined in: packages/lexical/src/utils/classNames.ts:50

Takes an HTML element and removes the classNames passed within an array, ignoring any non-string types. A space can be used to remove multiple classes eg. removeClassNamesFromElement(element, ['active small', true, null]) will remove both the 'active' and 'small' classes from that element.

Parameters​

element​

HTMLElement

The element in which the classes are removed

classNames​

...(string | boolean | null | undefined)[]

An array defining the class names to remove from the element

Returns​

void


resetRandomKey()​

resetRandomKey(): void

Defined in: packages/lexical/src/LexicalUtils.ts:178

Resets the internal key counter, primarily for deterministic test output.

Returns​

void


safeCast()​

safeCast<T>(value): T

Defined in: packages/lexical/src/extension-core/safeCast.ts:17

Explicitly and safely cast a value to a specific type when inference or satisfies isn't going to work as expected (often useful for the config property with defineExtension)

@NO_SIDE_EFFECTS

Type Parameters​

T​

T

Parameters​

value​

T

Returns​

T

Lexical-inline​

identity


setDOMStyleFromCSS()​

setDOMStyleFromCSS(domStyle, cssText, prevCSSText?): void

Defined in: packages/lexical/src/utils/setDOMStyle.ts:222

Applies inline CSS text to a DOM style declaration using CSSStyleDeclaration.setProperty().

Property names are expected to be kebab-case, such as font-size, and values are expected to include explicit units where needed, such as 12px.

Parameters​

domStyle​

CSSStyleDeclaration

cssText​

string

prevCSSText?​

string = ''

Returns​

void


setDOMStyleObject()​

setDOMStyleObject(domStyle, styleObject): void

Defined in: packages/lexical/src/utils/setDOMStyle.ts:201

Applies a style object to a DOM style declaration using CSSStyleDeclaration.setProperty().

Property names are expected to be kebab-case, such as font-size, and values are expected to include explicit units where needed, such as 12px.

Parameters​

domStyle​

CSSStyleDeclaration

styleObject​

Record<string, string | null | undefined>

Returns​

void


setDOMUnmanaged()​

setDOMUnmanaged(elementDom, options?): void

Defined in: packages/lexical/src/LexicalUtils.ts:3146

Experimental

Mark this DOM element as unmanaged by lexical's mutation observer (like decorator nodes are). Extensions that inject non-lexical decoration elements into a node's DOM should mark them so the mutation observer doesn't evict them as "unknown DOM children" during cleanup.

Pass {captureSelection: true} to additionally treat the subtree's window selection as decorator-like, so resolution does not force-sync the caret out of unmanaged DOM (see isDOMCapturingSelection).

Parameters​

elementDom​

HTMLElement & LexicalPrivateDOM

options?​

SetDOMUnmanagedOptions

Returns​

void


setNodeIndentFromDOM()​

setNodeIndentFromDOM(elementDom, elementNode): void

Defined in: packages/lexical/src/LexicalUtils.ts:3055

Reads the indent level from a DOM element's data-lexical-indent attribute or paddingInlineStart style, and applies it to the given ElementNode.

Parameters​

elementDom​

HTMLElement

elementNode​

ElementNode

Returns​

void


shallowMergeConfig()​

shallowMergeConfig<T>(config, overrides?): T

Defined in: packages/lexical/src/extension-core/shallowMergeConfig.ts:17

The default merge strategy for extension configuration is a shallow merge.

Type Parameters​

T​

T extends ExtensionConfigBase

Parameters​

config​

T

A full config

overrides?​

Partial<T>

A partial config of overrides

Returns​

T

config if there are no overrides, otherwise {...config, ...overrides}


stringValue()​

stringValue(defaultValue?): SerializationSchema<string>

Defined in: packages/lexical/src/LexicalSchema.ts:1819

Build a SerializationSchema that returns value when it is a string, otherwise returns defaultValue (the empty string by default). @NO_SIDE_EFFECTS

Parameters​

defaultValue?​

string = ''

Returns​

SerializationSchema<string>


toggleTextFormatType()​

toggleTextFormatType(format, type, alignWithFormat): number

Defined in: packages/lexical/src/LexicalUtils.ts:373

Toggles the given text format type on a format bitmask, clearing mutually exclusive formats (subscript/superscript, lowercase/uppercase/capitalize).

Parameters​

format​

number

type​

TextFormatType

alignWithFormat​

number | null

Returns​

number


tokenizeRawText()​

tokenizeRawText(text, visitor): void

Defined in: packages/lexical/src/LexicalSelection.ts:4404

Push-lex a raw text string into linebreak (\n / \r\n), tab (\t), and text (everything else) tokens, dispatching each to the matching callback on visitor in source order.

Shared by $generateNodesFromRawText (which builds LineBreakNode / TabNode / TextNode siblings) and by @lexical/clipboard's default text/plain clipboard importer (which maps linebreak to a real paragraph break via insertParagraph so multi-line plain text becomes multi-paragraph rich text). Empty text runs are dropped so callers don't need to special-case them.

Parameters​

text​

string

visitor​

RawTextVisitor

Returns​

void


transformValue()​

transformValue<Inner, Out, In>(inner, transform, options?): SerializationSchema<Out, never, In>

Defined in: packages/lexical/src/LexicalSchema.ts:2692

Combinator that normalizes the value another SerializationSchema parsed, for serialized properties whose accepted domain is wider than the stored one — the motivating case is a legacy shorthand that older documents carry (format: 'bold') being folded into the stored numeric form. inner still owns the domain: it validates the untrusted input (falling back to its default as usual), and transform then maps every value it can produce into the target domain, so the node's setter only ever sees normalized values.

transform must be pure and total over inner's outputs: it runs once when the schema is built to derive the SerializationSchema.defaultValue (the transform of inner's default) and once per parsed value. The meta is a transform kind holding inner, so introspection still reaches the accepted input domain — tooling that generates example JSON keeps generating the legacy forms, which is exactly what a parser test wants to exercise. Like every combinator, this takes a schema that names no accessor; see withAccessors.

inner's isEqual is not inherited: it compares values of inner's domain, and the transformed domain may be a different type entirely. Pass {isEqual} when the output domain is reference-typed, or a transformed array/object property can never compact away and, used as a createState parse, dirties its node on every write of an equal value.

A comparator passed here is used wherever this schema is used directly, but is not consulted when the schema is a unionValue member: a union selects by what a member accepts, and this accepts inner's domain while producing another, so it cannot tell which member made a value and compares structurally instead. The effect is a stricter answer than yours — a value you would call the default is written out rather than compacted away — never a looser one.

Only then: an equality is for a domain === cannot compare, so declaring one over a primitive output is an error. === already answers there, and a comparator can only widen it — call two distinct serialized values equal — after which the compact form omits whichever is not the default and parsing restores the default in its place. A rotation compared modulo 360 serializes 360 as nothing and reads back as 0. Normalize in the transform instead, where the value that reaches storage is the one that round-trips.

Type Parameters​

Inner​

Inner

Out​

Out

In​

In = Inner

Parameters​

inner​

SerializationSchema<Inner, never, In>

transform​

(value) => Out

options?​
isEqual?​

(a, b) => boolean

Returns​

SerializationSchema<Out, never, In>

Example​

const parseFormat = transformValue(
unionValue(
[numberValue(), enumValue(['bold', 'italic', 'underline'])],
0,
),
value => (typeof value === 'string' ? TEXT_TYPE_TO_FORMAT[value] : value),
);
// ^? SerializationSchema<number>
parseFormat(1); // 1
parseFormat('bold'); // IS_BOLD
parseFormat('junk'); // 0 (inner falls back to its default)

@NO_SIDE_EFFECTS


unionValue()​

unionValue<M>(members, ...args): SerializationSchema<SerializationSchemaValue<M[number]>, never, SchemaInput<M[number]>>

Defined in: packages/lexical/src/LexicalSchema.ts:2313

Combinator for a value whose domain is the union of several schemas, such as a dimension that is either a number or the literal 'inherit'. The domain is inferred as the union of the members' value types; annotate the result when you want to assert a narrower intended domain instead.

A SerializationSchema is total — it always returns a value, falling back to its own default rather than reporting a rejection — so a member is considered to accept value when parsing it lands anywhere other than that member's default, or when the value is itself that default (the one case a total schema cannot distinguish from a fallback).

Selection is in two passes. The first asks every member whether it accepts the value entirely — every element of an array, every declared field of an object — and the first such member wins. Only if none does are the members asked again for a partial match, where the first accepting one wins and the union yields what it parsed. So a member that normalizes its input (numberValue reading a stringified number) composes here the same way it behaves alone, and a value that belongs entirely to a later member is not taken by an earlier one that would only partly coerce it — declaration order decides between members that fit equally well, not between a complete fit and a partial one. If no member accepts at all, the result is defaultValue when given, otherwise the first member's default.

The inference above is only the fallback. A member that declares its own domain — which every combinator here does — is asked directly, and that is the only way to recognize a value it normalizes into its own default (numberValue() reading '0'). A member whose defaultValue lies outside its own constrained domain (numberValue(0, {min: 1})) is therefore declined for that value rather than accepting it, and the union falls through to the next member.

The result is itself a member of the union in both respects: it declares an accepts that asks each member in turn, so a union nested in another union (or reached through a wrapper) keeps its domain, and an isEqual, so a union over a reference-typed member still compares by content.

That equality is a structural comparison, not a member's own: a union picks a member by what each accepts, and transformValue accepts one domain and produces another, so which member produced a value is not something a union can recover. arrayValue and objectValue compare element-wise and field-wise, which is what this does, so a union over either is unaffected. A custom isEqual passed to transformValue is not consulted through a union — two values it would call equal are reported as different, so a property holding one is written out instead of compacted away, optional({omitDefault}) around the union keeps it instead of dropping it, and as a createState parse its NodeState.toJSON() writes the value rather than omitting it, $getStateChange reports a change, and an updater-form $setState performs the write. (A plain-value $setState compares nothing either way.) Never the reverse, which would discard the difference. Outside a union the comparator is used as declared.

Type Parameters​

M​

M extends readonly InnerSerializationSchema[]

Parameters​

members​

M

args​

[] | [SerializationSchemaValue<M[number]>]

Returns​

SerializationSchema<SerializationSchemaValue<M[number]>, never, SchemaInput<M[number]>>

Example​

const parseDimension = unionValue([numberValue(), enumValue(['inherit'])], 'inherit');
// ^? SerializationSchema<number | 'inherit'>
parseDimension(640); // 640
parseDimension('640'); // 640 (numberValue reads a stringified number)
parseDimension('inherit'); // 'inherit'
parseDimension('banana'); // 'inherit' (no member accepts it)

@NO_SIDE_EFFECTS


unmountSlotContainer()​

unmountSlotContainer(editor, nodeKey, container): void

Defined in: packages/lexical/src/LexicalUtils.ts:2881

Experimental

Reverse of mountSlotContainer: hide container again and park it back in the host's DOM as the leading hidden placeholder, where the reconciler manages it. Call when the mount target goes away while the host remains (e.g. chrome unmount) so the slot subtree stays in the document instead of leaving with the detached target.

Parameters​

editor​

LexicalEditor

nodeKey​

string

container​

HTMLElement

Returns​

void


withAccessors()​

withAccessors<T, A, In>(schema, accessors): SerializationSchema<T, AccessorNames<A, T>, In>

Defined in: packages/lexical/src/LexicalSchema.ts:3137

Return a copy of schema that records both accessor names at once, which is the common case for a property whose node methods do not follow the default get<Prop>/set<Prop> naming. Either direction may be omitted to keep the conventional name for that one.

This and withField go outside every other combinator, because an accessor answers for the property as a whole and each combinator widens what the property holds: nullable admits null, optional admits an absent value, transformValue produces a type of its own, and a union produces any member's. nullable(withAccessors(stringValue(), {setter: 'setLabel'})) obliged setLabel to take a string while the parser hands it null for a document that omits the property. Written the other way round — withAccessors(nullable(stringValue()), {setter: 'setNullableLabel'}) — the obligation is stated for what the property really parses to, and the compiler checks it. Exactly once per property: a second layer would name a direction the first already named, and the walk calls only the outer one — an obligation checked for an accessor that is never called — so both directions are named in one call, and every combinator, this one included, refuses a schema that already names an accessor. A development build holds the rule at run time too, for a caller the types do not reach.

Type Parameters​

T​

T

A​

A extends SchemaAccessors

In​

In = T

Parameters​

schema​

SerializationSchema<T, never, In>

accessors​

A

Returns​

SerializationSchema<T, AccessorNames<A, T>, In>

Example​

nodeSchema<TextNode>()({
text: withAccessors(stringValue(), {
getter: 'getTextContent',
setter: 'setTextContent',
}),
});

@NO_SIDE_EFFECTS


withField()​

withField<T, F, In>(schema, field): SerializationSchema<T, FieldOptionNames<F, T>, In>

Defined in: packages/lexical/src/LexicalSchema.ts:3079

Return a copy of schema that declares the serialized property to be a node field rather than a pair of accessor methods.

This is the fast path in both directions: exporting reads the field, and importing assigns it, with no method call on either side — and no version resolution either way, since the node being parsed into is writable by construction and the node being exported is one the walk already resolved from the EditorState. Because the name is recorded on the schema, an introspecting tool (a codegen pass emitting a specialized parser for a hot node type) can see that a property is a plain field and compile it to a direct assignment. Use withAccessors with a {field} on one side only when the two directions differ — reading the field but writing through a method that normalizes, as TableCellNode's headerState does.

The trade-off is that a field access is exactly that: normalization, validation or bookkeeping a set<Prop> method would do is skipped, and a subclass override of that method is not consulted. Use it when the property really is the field — which is also what makes it safe to compile away.

Each direction still stands in for an accessor, so a subclass that overrode one still decides; see SchemaFieldBase.method. That accessor is the conventional get<Prop>/set<Prop> unless getter/setter name a different one, so most declarations need neither — name one only where the accessor is spelled differently, as TextNode's text is (getTextContent). A node with no such method defers to nothing, which needs no declaring.

getterTable/setterTable declare a property whose stored and serialized forms differ (SchemaGetterField.getterTable / SchemaSetterField.setterTable), and when names the predicate gating the export direction (SchemaGetterField.when).

Type Parameters​

T​

T

F​

F extends FieldOptions

In​

In = T

Parameters​

schema​

SerializationSchema<T, never, In>

field​

F

Returns​

SerializationSchema<T, FieldOptionNames<F, T>, In>

Example​

nodeSchema<TextNode>()({
// TextNode's own field in both directions, deferring to getStyle/setStyle
// for a subclass that overrides either — neither is spelled here, since
// both are the conventional name for a `style` property.
style: withField(stringValue(), {field: '__style'}),
// LinkNode's own field, standing in for getURL/setURL rather than the
// getUrl/setUrl the property name would derive.
url: withField(stringValue(), {
field: '__url',
getter: 'getURL',
setter: 'setURL',
}),
});

@NO_SIDE_EFFECTS