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:896

Returns​

DOMConversionMap<any> | null

Methods​

$config()​

$config(): BaseStaticNodeConfig

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

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:47

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:800

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:804

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:1477

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:1984

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:68

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:1525

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()​

exportJSON(): SerializedLexicalNode

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

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.

Returns​

SerializedLexicalNode

Inherited from​

LexicalNode.exportJSON

getCommonAncestor()​

getCommonAncestor<T>(node): T | null

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

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:1513

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:1018

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:1010

Returns this nodes key.

Returns​

string

Inherited from​

LexicalNode.getKey

getLatest()​

getLatest(): this

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

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:1197

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:1204

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:1215

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:1222

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:1310

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:1038

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:1045

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:1136

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:1058

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:1065

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:1121

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:1150

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:1157

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:1168

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:1175

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:1448

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:1456

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

Returns​

number

Inherited from​

LexicalNode.getTextContentSize

getTopLevelElement()​

getTopLevelElement(): ElementNode | DecoratorNode<T> | 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​

ElementNode | DecoratorNode<T> | null

Inherited from​

LexicalNode.getTopLevelElement

getTopLevelElementOrThrow()​

getTopLevelElementOrThrow(): ElementNode | DecoratorNode<T>

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​

ElementNode | DecoratorNode<T>

Inherited from​

LexicalNode.getTopLevelElementOrThrow

getType()​

getType(): string

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

Returns the string type of this node.

Returns​

string

Inherited from​

LexicalNode.getType

getWritable()​

getWritable(): this

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

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:1788

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:1895

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:1258

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:938

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:1276

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:1380

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:85

Returns​

boolean

Inherited from​

LexicalNode.isInline

isIsolated()​

isIsolated(): boolean

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

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:89

Returns​

boolean

isParentOf()​

isParentOf(targetNode): boolean

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

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:1976

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:965

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:2059

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:1620

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:1637

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:889

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:1992

Returns​

RangeSelection

Inherited from​

LexicalNode.selectEnd

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

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

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:2002

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:1988

Returns​

RangeSelection

Inherited from​

LexicalNode.selectStart

updateDOM()​

updateDOM(_prevNode, _dom, _config): boolean

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

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:1591

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​

LexicalUpdateJSON<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);
}
}
Inherited from​

LexicalNode.updateFromJSON

clone()​

static clone(_data): LexicalNode

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

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:748

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:1553

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​

SerializedLexicalNode & Record<string, unknown>

Returns​

LexicalNode

transform()​

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

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

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:114

Extends​

Extended by​

Implements​

Constructors​

Constructor​

new ElementNode(key?): ElementNode

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

Parameters​
key?​

string

Returns​

ElementNode

Properties​

importDOM?​

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

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

Returns​

DOMConversionMap<any> | null

Methods​

$config()​

$config(): BaseStaticNodeConfig

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

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/LexicalElementNode.ts:188

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:634

Parameters​
nodesToAppend​

...LexicalNode[]

Returns​

this

canBeEmpty()​

canBeEmpty(): boolean

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

Returns​

boolean

canIndent()​

canIndent(): boolean

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

Returns​

boolean

canInsertTextAfter()​

canInsertTextAfter(): boolean

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

Returns​

boolean

canInsertTextBefore()​

canInsertTextBefore(): boolean

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

Returns​

boolean

canMergeWhenEmpty()​

canMergeWhenEmpty(): boolean

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

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:628

Returns​

this

collapseAtStart()​

collapseAtStart(selection): boolean

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

Parameters​
selection​

RangeSelection

Returns​

boolean

config()​
Call Signature​

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

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

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:804

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:1477

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:1984

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:919

Parameters​
destination?​

"clone" | "html"

Returns​

boolean

exportDOM()​

exportDOM(editor): DOMExportOutput

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

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()​

exportJSON(): SerializedElementNode

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

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.

Returns​

SerializedElementNode

Inherited from​

LexicalNode.exportJSON

extractWithChild()​

extractWithChild(child, selection, destination): boolean

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

Parameters​
child​

LexicalNode

selection​

BaseSelection | null

destination​

"clone" | "html"

Returns​

boolean

getAllTextNodes()​

getAllTextNodes(): TextNode[]

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

Returns​

TextNode[]

getChildAtIndex()​
Call Signature​

getChildAtIndex(index): LexicalNode | null

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

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:472

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:234

Returns the children of this node, in document order.

Returns​

LexicalNode[]

Call Signature​

getChildren<T>(): T[]

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

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:251

Returns​

string[]

getChildrenSize()​

getChildrenSize(): number

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

Returns​

number

getCommonAncestor()​

getCommonAncestor<T>(node): T | null

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

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:365

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:372

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:538

Returns​

"ltr" | "rtl" | null

getDOMSlot()​

getDOMSlot(element): ElementDOMSlot<HTMLElement>

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

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:396

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:403

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:412

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:419

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:319

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:326

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:215

Returns​

number

getFormatFlags()​

getFormatFlags(type, alignWithFormat): number

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

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:219

Returns​

ElementFormatType

getIndent()​

getIndent(): number

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

Returns​

number

getIndexWithinParent()​

getIndexWithinParent(): number

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

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:1010

Returns this nodes key.

Returns​

string

Inherited from​

LexicalNode.getKey

getLastChild()​
Call Signature​

getLastChild(): LexicalNode | null

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

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:437

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:446

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:453

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:342

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:349

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:1391

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:1197

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:1204

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:1215

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:1222

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:1310

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:1038

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:1045

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:1136

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:1058

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:1065

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:1121

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:1150

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:1157

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:1168

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:1175

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:223

Returns​

string

getTextContent()​

getTextContent(): string

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

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:519

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:542

Returns​

number

getTextStyle()​

getTextStyle(): string

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

Returns​

string

getTopLevelElement()​

getTopLevelElement(): ElementNode | null

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

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:116

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:921

Returns the string type of this node.

Returns​

string

Inherited from​

LexicalNode.getType

getWritable()​

getWritable(): this

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

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:546

Parameters​
type​

ElementFormatType

Returns​

boolean

hasTextFormat()​

hasTextFormat(type): boolean

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

Parameters​
type​

TextFormatType

Returns​

boolean

insertAfter()​

insertAfter(nodeToInsert, restoreSelection?): LexicalNode

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

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:1895

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:896

Parameters​
selection​

RangeSelection

restoreSelection?​

boolean

Returns​

LexicalNode | null

is()​

is(object): boolean

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

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:938

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:1276

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:270

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:264

Returns​

boolean

isInline()​

isInline(): boolean

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

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:275

Returns​

boolean

isParentOf()​

isParentOf(targetNode): boolean

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

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:1976

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:965

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:951

Returns​

boolean

markDirty()​

markDirty(): void

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

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:1620

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:1637

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:889

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:575

Parameters​
_anchorOffset?​

number

_focusOffset?​

number

Returns​

RangeSelection

selectEnd()​

selectEnd(): RangeSelection

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

Returns​

RangeSelection

Inherited from​

LexicalNode.selectEnd

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

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

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:2002

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:620

Returns​

RangeSelection

Inherited from​

LexicalNode.selectStart

setDirection()​

setDirection(direction): this

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

Parameters​
direction​

"ltr" | "rtl" | null

Returns​

this

setFormat()​

setFormat(type): this

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

Parameters​
type​

ElementFormatType

Returns​

this

setIndent()​

setIndent(indentLevel): this

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

Parameters​
indentLevel​

number

Returns​

this

setStyle()​

setStyle(style): this

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

Parameters​
style​

string

Returns​

this

setTextFormat()​

setTextFormat(type): this

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

Parameters​
type​

number

Returns​

this

setTextStyle()​

setTextStyle(style): this

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

Parameters​
style​

string

Returns​

this

splice()​

splice(start, deleteCount, nodesToInsert): this

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

Parameters​
start​

number

deleteCount​

number

nodesToInsert​

LexicalNode[]

Returns​

this

updateDOM()​

updateDOM(_prevNode, _dom, _config): boolean

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

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:884

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​

LexicalUpdateJSON<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);
}
}
Inherited from​

LexicalNode.updateFromJSON

clone()​

static clone(_data): LexicalNode

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

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:748

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:1553

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​

SerializedLexicalNode & Record<string, unknown>

Returns​

LexicalNode

transform()​

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

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

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:26

Extends​

Methods​

$config()​

$config(): BaseStaticNodeConfig & object

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.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 & object

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:50

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: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​

"\n"

Overrides​

LexicalNode.getTextContent

isInline()​

isInline(): true

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

Returns​

true

Overrides​

LexicalNode.isInline

updateDOM()​

updateDOM(): false

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

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:50

Extends​

Methods​

$config()​

$config(): BaseStaticNodeConfig & object & StaticNodeTypeAccessor<"paragraph"> & StaticNodeConfigAccessor<{ extends: typeof ElementNode; importDOM: { p: () => object; }; }>

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

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<"paragraph"> & StaticNodeConfigAccessor<{ extends: typeof ElementNode; 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:169

Returns​

boolean

Overrides​

ElementNode.collapseAtStart

createDOM()​

createDOM(config): HTMLElement

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

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:85

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()​

exportJSON(): SerializedParagraphNode

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

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.

Returns​

SerializedParagraphNode

Overrides​

ElementNode.exportJSON

extractWithChild()​

extractWithChild(child, selection, destination): boolean

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

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:154

Parameters​
rangeSelection​

RangeSelection

restoreSelection​

boolean

Returns​

ParagraphNode

Overrides​

ElementNode.insertNewAfter

updateDOM()​

updateDOM(prevNode, dom, config): boolean

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

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:28

Extends​

Constructors​

Constructor​

new RootNode(): RootNode

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

Returns​

RootNode

Overrides​

ElementNode.constructor

Methods​

$config()​

$config(): BaseStaticNodeConfig & object & StaticNodeTypeAccessor<"root"> & StaticNodeConfigAccessor<{ extends: typeof ElementNode; }>

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

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<"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:48

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:41

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:69

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:65

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:57

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:61

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:80

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:75

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:94

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​

SerializedRootNode

Returns​

RootNode

Overrides​

ElementNode.importJSON


TabNode​

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

Extends​

Constructors​

Constructor​

new TabNode(key?): TabNode

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

Parameters​
key?​

string | undefined

Returns​

TabNode

Overrides​

TextNode.constructor

Methods​

$config()​

$config(): BaseStaticNodeConfig & object & object & StaticNodeTypeAccessor<"tab"> & StaticNodeConfigAccessor<{ extends: typeof TextNode; }>

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

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 & object & StaticNodeTypeAccessor<"tab"> & StaticNodeConfigAccessor<{ extends: typeof TextNode; }>

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:93

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:89

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:39

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:79

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:84

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:54

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:65

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:304

Extends​

Extended by​

Implements​

Constructors​

Constructor​

new TextNode(text?, key?): TextNode

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

Parameters​
text?​

string = ''

key?​

string

Returns​

TextNode

Properties​

__text​

__text: string

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

importDOM?​

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

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

Returns​

DOMConversionMap<any> | null

Methods​

$config()​

$config(): BaseStaticNodeConfig & object

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

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

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/LexicalTextNode.ts:401

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:560

Returns​

boolean

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

canInsertTextAfter()​

canInsertTextAfter(): boolean

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

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:966

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:800

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:804

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:573

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:1984

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:673

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()​

exportJSON(): SerializedTextNode

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

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.

Returns​

SerializedTextNode

Inherited from​

LexicalNode.exportJSON

getCommonAncestor()​

getCommonAncestor<T>(node): T | null

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

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:437

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:1513

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:425

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:550

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:1018

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:1010

Returns this nodes key.

Returns​

string

Inherited from​

LexicalNode.getKey

getLatest()​

getLatest(): this

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

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:447

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:1197

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:1204

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:1215

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:1222

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:1310

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:1038

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:1045

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:1136

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:1058

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:1065

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:1121

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:1150

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:1157

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:1168

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:1175

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:457

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:540

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:1456

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:305

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:306

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:921

Returns the string type of this node.

Returns​

string

Inherited from​

LexicalNode.getType

getWritable()​

getWritable(): this

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

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:520

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:1788

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:1895

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:1258

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:938

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:1276

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:478

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:497

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:1380

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:567

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:1299

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:1976

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:488

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:965

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:531

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:1209

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:468

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:507

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:2059

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:1154

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:1620

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:1637

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:889

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:864

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:909

Returns​

RangeSelection

Inherited from​

LexicalNode.selectEnd

selectionTransform()​

selectionTransform(prevSelection, nextSelection): void

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

Parameters​
prevSelection​

BaseSelection | null

nextSelection​

RangeSelection

Returns​

void

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

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

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:2002

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:905

Returns​

RangeSelection

Inherited from​

LexicalNode.selectStart

setDetail()​

setDetail(detail): this

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

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:743

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:830

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:776

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:847

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:925

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:989

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:802

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:791

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:813

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:596

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:660

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​

LexicalUpdateJSON<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);
}
}
Inherited from​

LexicalNode.updateFromJSON

clone()​

static clone(_data): LexicalNode

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

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:748

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:1553

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​

SerializedLexicalNode & Record<string, unknown>

Returns​

LexicalNode

transform()​

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

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

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: node_modules/.pnpm/typescript@6.0.3/node_modules/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


CreateEditorArgs​

Defined in: packages/lexical/src/LexicalEditor.ts:465

Properties​

disableEvents?​

optional disableEvents?: boolean

Defined in: packages/lexical/src/LexicalEditor.ts:466

dom?​

optional dom?: Partial<EditorDOMRenderConfig>

Defined in: packages/lexical/src/LexicalEditor.ts:484

editable?​

optional editable?: boolean

Defined in: packages/lexical/src/LexicalEditor.ts:481

editorState?​

optional editorState?: EditorState

Defined in: packages/lexical/src/LexicalEditor.ts:467

html?​

optional html?: HTMLConfig

Defined in: packages/lexical/src/LexicalEditor.ts:483

namespace?​

optional namespace?: string

Defined in: packages/lexical/src/LexicalEditor.ts:468

nodes?​

optional nodes?: readonly LexicalNodeConfig[]

Defined in: packages/lexical/src/LexicalEditor.ts:469

onError?​

optional onError?: ErrorHandler

Defined in: packages/lexical/src/LexicalEditor.ts:470

onWarn?​

optional onWarn?: ErrorHandler

Defined in: packages/lexical/src/LexicalEditor.ts:479

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:480

theme?​

optional theme?: EditorThemeClasses

Defined in: packages/lexical/src/LexicalEditor.ts:482


DOMExportOutput​

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

Properties​

$getChildNodes?​

optional $getChildNodes?: () => Iterable<LexicalNode>

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

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 | DocumentFragment | Text | null | undefined

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

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 | DocumentFragment | Text | null | undefined

element after children are appended

Returns​

HTMLElement | DocumentFragment | Text | null | undefined

The final representation of this node in the exported DOM

append?​

optional append?: (element) => void

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

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 | DocumentFragment | Text

The DOM of a child node to append

Returns​

void

element​

element: HTMLElement | DocumentFragment | Text | null

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

A DOM node for this lexical node, or null to skip it


DOMSelectionBoundaryPoints​

Defined in: packages/lexical/src/LexicalUtils.ts:2251

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:2252

Experimental

anchorOffset​

anchorOffset: number

Defined in: packages/lexical/src/LexicalUtils.ts:2253

Experimental

direction?​

optional direction?: "none" | "forward" | "backward"

Defined in: packages/lexical/src/LexicalUtils.ts:2254

Experimental

focusNode​

focusNode: Node | null

Defined in: packages/lexical/src/LexicalUtils.ts:2255

Experimental

focusOffset​

focusOffset: number

Defined in: packages/lexical/src/LexicalUtils.ts:2256

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:249

Properties​

disableEvents?​

optional disableEvents?: boolean

Defined in: packages/lexical/src/LexicalEditor.ts:251

dom?​

optional dom?: EditorDOMRenderConfig

Defined in: packages/lexical/src/LexicalEditor.ts:250

namespace​

namespace: string

Defined in: packages/lexical/src/LexicalEditor.ts:252

theme​

theme: EditorThemeClasses

Defined in: packages/lexical/src/LexicalEditor.ts:253


EditorState​

Defined in: packages/lexical/src/LexicalEditorState.ts:133

Properties​

_flushSync​

_flushSync: boolean

Defined in: packages/lexical/src/LexicalEditorState.ts:136

_nodeMap​

_nodeMap: NodeMap

Defined in: packages/lexical/src/LexicalEditorState.ts:134

_parsed​

_parsed: boolean

Defined in: packages/lexical/src/LexicalEditorState.ts:141

True if this EditorState was parsed without running transforms

_readOnly​

_readOnly: boolean

Defined in: packages/lexical/src/LexicalEditorState.ts:137

_selection​

_selection: BaseSelection | null

Defined in: packages/lexical/src/LexicalEditorState.ts:135

_slotsUsed​

_slotsUsed: boolean

Defined in: packages/lexical/src/LexicalEditorState.ts:146

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:177

Parameters​
selection?​

BaseSelection | null

Returns​

EditorState

isEmpty()​

isEmpty(): boolean

Defined in: packages/lexical/src/LexicalEditorState.ts:161

Returns​

boolean

read()​

read<V>(callbackFn, options?): V

Defined in: packages/lexical/src/LexicalEditorState.ts:169

Type Parameters​
V​

V

Parameters​
callbackFn​

() => V

options?​

EditorStateReadOptions

Returns​

V

toJSON()​

toJSON(): SerializedEditorState

Defined in: packages/lexical/src/LexicalEditorState.ts:193

Returns​

SerializedEditorState


EditorStateReadOptions​

Defined in: packages/lexical/src/LexicalEditorState.ts:122

Properties​

editor?​

optional editor?: LexicalEditor | null

Defined in: packages/lexical/src/LexicalEditorState.ts:123


EditorThemeClasses​

Defined in: packages/lexical/src/LexicalEditor.ts:178

Indexable​

[key: string]: any

Properties​

blockCursor?​

optional blockCursor?: string

Defined in: packages/lexical/src/LexicalEditor.ts:179

characterLimit?​

optional characterLimit?: string

Defined in: packages/lexical/src/LexicalEditor.ts:180

code?​

optional code?: string

Defined in: packages/lexical/src/LexicalEditor.ts:181

codeHighlight?​

optional codeHighlight?: Record<string, string>

Defined in: packages/lexical/src/LexicalEditor.ts:182

collaboration?​

optional collaboration?: object

Defined in: packages/lexical/src/LexicalEditor.ts:234

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:240

base?​

optional base?: string

focus?​

optional focus?: string

hashtag?​

optional hashtag?: string

Defined in: packages/lexical/src/LexicalEditor.ts:183

heading?​

optional heading?: object

Defined in: packages/lexical/src/LexicalEditor.ts:185

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:193

hrSelected?​

optional hrSelected?: string

Defined in: packages/lexical/src/LexicalEditor.ts:194

image?​

optional image?: string

Defined in: packages/lexical/src/LexicalEditor.ts:195

indent?​

optional indent?: string

Defined in: packages/lexical/src/LexicalEditor.ts:244

optional link?: string

Defined in: packages/lexical/src/LexicalEditor.ts:196

list?​

optional list?: object

Defined in: packages/lexical/src/LexicalEditor.ts:197

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:211

mark?​

optional mark?: string

Defined in: packages/lexical/src/LexicalEditor.ts:212

markOverlap?​

optional markOverlap?: string

Defined in: packages/lexical/src/LexicalEditor.ts:213

paragraph?​

optional paragraph?: string

Defined in: packages/lexical/src/LexicalEditor.ts:214

quote?​

optional quote?: string

Defined in: packages/lexical/src/LexicalEditor.ts:215

root?​

optional root?: string

Defined in: packages/lexical/src/LexicalEditor.ts:216

rtl?​

optional rtl?: string

Defined in: packages/lexical/src/LexicalEditor.ts:217

specialText?​

optional specialText?: string

Defined in: packages/lexical/src/LexicalEditor.ts:184

tab?​

optional tab?: string

Defined in: packages/lexical/src/LexicalEditor.ts:218

table?​

optional table?: string

Defined in: packages/lexical/src/LexicalEditor.ts:219

tableAddColumns?​

optional tableAddColumns?: string

Defined in: packages/lexical/src/LexicalEditor.ts:220

tableAddRows?​

optional tableAddRows?: string

Defined in: packages/lexical/src/LexicalEditor.ts:221

tableCell?​

optional tableCell?: string

Defined in: packages/lexical/src/LexicalEditor.ts:225

tableCellActionButton?​

optional tableCellActionButton?: string

Defined in: packages/lexical/src/LexicalEditor.ts:222

tableCellActionButtonContainer?​

optional tableCellActionButtonContainer?: string

Defined in: packages/lexical/src/LexicalEditor.ts:223

tableCellHeader?​

optional tableCellHeader?: string

Defined in: packages/lexical/src/LexicalEditor.ts:226

tableCellResizer?​

optional tableCellResizer?: string

Defined in: packages/lexical/src/LexicalEditor.ts:227

tableCellSelected?​

optional tableCellSelected?: string

Defined in: packages/lexical/src/LexicalEditor.ts:224

tableRow?​

optional tableRow?: string

Defined in: packages/lexical/src/LexicalEditor.ts:228

tableScrollableWrapper?​

optional tableScrollableWrapper?: string

Defined in: packages/lexical/src/LexicalEditor.ts:229

tableSelected?​

optional tableSelected?: string

Defined in: packages/lexical/src/LexicalEditor.ts:230

tableSelection?​

optional tableSelection?: string

Defined in: packages/lexical/src/LexicalEditor.ts:231

tableStickyScrollbar?​

optional tableStickyScrollbar?: string

Defined in: packages/lexical/src/LexicalEditor.ts:232

text?​

optional text?: TextNodeThemeClasses

Defined in: packages/lexical/src/LexicalEditor.ts:233


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


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:309

Methods​

getFormat()​

getFormat(): number

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

Returns​

number

getFormatFlags()​

getFormatFlags(type, alignWithFormat): number

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

Parameters​
type​

TextFormatType

alignWithFormat​

number | null

Returns​

number

hasFormat()​

hasFormat(type): boolean

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

Parameters​
type​

TextFormatType

Returns​

boolean

setFormat()​

setFormat(format): unknown

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

Parameters​
format​

number

Returns​

unknown

toggleFormat()​

toggleFormat(type): unknown

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

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:689

Type Parameters​

TPayload​

TPayload

Properties​

[LexicalCommandBrand]?​

readonly optional [LexicalCommandBrand]?: (payload) => TPayload

Defined in: packages/lexical/src/LexicalEditor.ts:692

Parameters​
payload​

TPayload

Returns​

TPayload

type?​

optional type?: string

Defined in: packages/lexical/src/LexicalEditor.ts:690


LexicalEditor​

Defined in: packages/lexical/src/LexicalEditor.ts:1118

Extended by​

Methods​

blur()​

blur(): void

Defined in: packages/lexical/src/LexicalEditor.ts:1924

Removes focus from the editor.

Returns​

void

dispatchCommand()​

dispatchCommand<TCommand>(type, ...args): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1604

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:1883

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:1615

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:1726

Gets the active editor state.

Returns​

EditorState

The editor state

getElementByKey()​

getElementByKey(key): HTMLElement | null

Defined in: packages/lexical/src/LexicalEditor.ts:1718

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:1633

Gets the key of the editor

Returns​

string

The editor key

getRootElement()​

getRootElement(): HTMLElement | null

Defined in: packages/lexical/src/LexicalEditor.ts:1625

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:1581

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:1590

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:1280

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:1941

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:1817

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.

Parameters​
maybeStringifiedEditorState​

string | SerializedEditorState<SerializedLexicalNode>

updateFn?​

() => void

Returns​

EditorState

read()​
Call Signature​

read<T>(callbackFn): T

Defined in: packages/lexical/src/LexicalEditor.ts:1841

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:1848

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:1378

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:1315

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:1303

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:1446

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:1549

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:1345

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:1328

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:1290

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:1949

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:1735

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:1641

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:1975

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

Returns​

SerializedEditor

A JSON-serializable javascript object

update()​

update(updateFn, options?): void

Defined in: packages/lexical/src/LexicalEditor.ts:1870

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: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.esnext.disposable.d.ts:34

Returns​

void

Inherited from​

Disposable.[dispose]

blur()​

blur(): void

Defined in: packages/lexical/src/LexicalEditor.ts:1924

Removes focus from the editor.

Returns​

void

Inherited from​

LexicalEditor.blur

dispatchCommand()​

dispatchCommand<TCommand>(type, ...args): boolean

Defined in: packages/lexical/src/LexicalEditor.ts:1604

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:1883

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:1615

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:1726

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:1718

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:1633

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:1625

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:1581

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:1590

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:1280

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:1941

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:1817

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.

Parameters​
maybeStringifiedEditorState​

string | SerializedEditorState<SerializedLexicalNode>

updateFn?​

() => void

Returns​

EditorState

Inherited from​

LexicalEditor.parseEditorState

read()​
Call Signature​

read<T>(callbackFn): T

Defined in: packages/lexical/src/LexicalEditor.ts:1841

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:1848

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:1378

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:1315

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:1303

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:1446

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:1549

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:1345

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:1328

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:1290

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:1949

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:1735

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:1641

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:1975

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

Returns​

SerializedEditor

A JSON-serializable javascript object

Inherited from​

LexicalEditor.toJSON

update()​

update(updateFn, options?): void

Defined in: packages/lexical/src/LexicalEditor.ts:1870

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:716

Extended by​

Methods​

$config()​

$config(): BaseStaticNodeConfig

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

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:873

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:800

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:804

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:1477

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:1984

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:1525

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()​

exportJSON(): SerializedLexicalNode

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

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.

Returns​

SerializedLexicalNode

getCommonAncestor()​

getCommonAncestor<T>(node): T | null

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

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:1513

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:1018

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

Returns​

number

getKey()​

getKey(): string

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

Returns this nodes key.

Returns​

string

getLatest()​

getLatest(): this

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

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:1197

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:1204

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:1215

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:1222

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:1310

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:1038

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:1045

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:1136

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:1058

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:1065

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:1121

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:1150

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:1157

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:1168

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:1175

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:1448

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:1456

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

Returns​

number

getTopLevelElement()​

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

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

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 | DecoratorNode<unknown> | null

getTopLevelElementOrThrow()​

getTopLevelElementOrThrow(): ElementNode | DecoratorNode<unknown>

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

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 | DecoratorNode<unknown>

getType()​

getType(): string

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

Returns the string type of this node.

Returns​

string

getWritable()​

getWritable(): this

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

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:1788

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:1895

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:1258

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:938

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:1276

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:1380

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:925

Returns​

boolean

isParentOf()​

isParentOf(targetNode): boolean

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

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:1976

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:965

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:2059

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:1620

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:1637

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:889

Reset state in this copy of originalNode, if necessary

Parameters​
originalNode​

this

Returns​

void

selectEnd()​

selectEnd(): RangeSelection

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

Returns​

RangeSelection

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

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

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:2002

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:1988

Returns​

RangeSelection

updateDOM()​

updateDOM(_prevNode, _dom, _config): boolean

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

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:1591

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​

LexicalUpdateJSON<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);
}
}

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


OwnStaticNodeConfig​

Defined in: packages/lexical/src/LexicalUtils.ts:3262

Properties​

klass​

klass: KlassConstructor<typeof LexicalNode>

Defined in: packages/lexical/src/LexicalUtils.ts:3263

ownNodeConfig​

ownNodeConfig: StaticNodeConfigValue<LexicalNode, string | symbol> | undefined

Defined in: packages/lexical/src/LexicalUtils.ts:3265

ownNodeType​

ownNodeType: string | undefined

Defined in: packages/lexical/src/LexicalUtils.ts:3264


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: "element" | "text"

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​

"element" | "text"

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​

TextNode | ElementNode

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


SerializedEditorState​

Defined in: packages/lexical/src/LexicalEditorState.ts:28

Type Parameters​

T​

T extends SerializedLexicalNode = SerializedLexicalNode

Properties​

root​

root: SerializedRootNode<T>

Defined in: packages/lexical/src/LexicalEditorState.ts:31


SetDOMUnmanagedOptions​

Defined in: packages/lexical/src/LexicalUtils.ts:3101

Experimental

Options accepted by setDOMUnmanaged.

Properties​

captureSelection?​

optional captureSelection?: boolean

Defined in: packages/lexical/src/LexicalUtils.ts:3112

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:1840

Extends​

Properties​

[ShadowRootNodeBrand]​

[ShadowRootNodeBrand]: never

Defined in: packages/lexical/src/LexicalUtils.ts:1841

Methods​

$config()​

$config(): BaseStaticNodeConfig

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

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​

ElementNode.$config

afterCloneFrom()​

afterCloneFrom(prevNode): void

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

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:634

Parameters​
nodesToAppend​

...LexicalNode[]

Returns​

this

Inherited from​

ElementNode.append

canBeEmpty()​

canBeEmpty(): boolean

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

Returns​

boolean

Inherited from​

ElementNode.canBeEmpty

canIndent()​

canIndent(): boolean

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

Returns​

boolean

Inherited from​

ElementNode.canIndent

canInsertTextAfter()​

canInsertTextAfter(): boolean

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

Returns​

boolean

Inherited from​

ElementNode.canInsertTextAfter

canInsertTextBefore()​

canInsertTextBefore(): boolean

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

Returns​

boolean

Inherited from​

ElementNode.canInsertTextBefore

canMergeWhenEmpty()​

canMergeWhenEmpty(): boolean

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

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:628

Returns​

this

Inherited from​

ElementNode.clear

collapseAtStart()​

collapseAtStart(selection): boolean

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

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:800

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:804

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:1477

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:1984

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:919

Parameters​
destination?​

"clone" | "html"

Returns​

boolean

Inherited from​

ElementNode.excludeFromCopy

exportDOM()​

exportDOM(editor): DOMExportOutput

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

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()​

exportJSON(): SerializedElementNode

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

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.

Returns​

SerializedElementNode

Inherited from​

ElementNode.exportJSON

extractWithChild()​

extractWithChild(child, selection, destination): boolean

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

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:280

Returns​

TextNode[]

Inherited from​

ElementNode.getAllTextNodes

getChildAtIndex()​
Call Signature​

getChildAtIndex(index): LexicalNode | null

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

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:472

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:234

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:241

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:251

Returns​

string[]

Inherited from​

ElementNode.getChildrenKeys

getChildrenSize()​

getChildrenSize(): number

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

Returns​

number

Inherited from​

ElementNode.getChildrenSize

getCommonAncestor()​

getCommonAncestor<T>(node): T | null

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

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:365

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:372

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:538

Returns​

"ltr" | "rtl" | null

Inherited from​

ElementNode.getDirection

getDOMSlot()​

getDOMSlot(element): ElementDOMSlot<HTMLElement>

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

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:396

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:403

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:412

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:419

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:319

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:326

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:215

Returns​

number

Inherited from​

ElementNode.getFormat

getFormatFlags()​

getFormatFlags(type, alignWithFormat): number

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

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:219

Returns​

ElementFormatType

Inherited from​

ElementNode.getFormatType

getIndent()​

getIndent(): number

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

Returns​

number

Inherited from​

ElementNode.getIndent

getIndexWithinParent()​

getIndexWithinParent(): number

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

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:1010

Returns this nodes key.

Returns​

string

Inherited from​

ElementNode.getKey

getLastChild()​
Call Signature​

getLastChild(): LexicalNode | null

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

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:437

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:446

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:453

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:342

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:349

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:1391

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:1197

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:1204

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:1215

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:1222

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:1310

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:1038

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:1045

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:1136

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:1058

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:1065

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:1121

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:1150

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:1157

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:1168

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:1175

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:223

Returns​

string

Inherited from​

ElementNode.getStyle

getTextContent()​

getTextContent(): string

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

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:519

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:542

Returns​

number

Inherited from​

ElementNode.getTextFormat

getTextStyle()​

getTextStyle(): string

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

Returns​

string

Inherited from​

ElementNode.getTextStyle

getTopLevelElement()​

getTopLevelElement(): ElementNode | null

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

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:116

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:921

Returns the string type of this node.

Returns​

string

Inherited from​

ElementNode.getType

getWritable()​

getWritable(): this

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

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:546

Parameters​
type​

ElementFormatType

Returns​

boolean

Inherited from​

ElementNode.hasFormat

hasTextFormat()​

hasTextFormat(type): boolean

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

Parameters​
type​

TextFormatType

Returns​

boolean

Inherited from​

ElementNode.hasTextFormat

insertAfter()​

insertAfter(nodeToInsert, restoreSelection?): LexicalNode

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

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:1895

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:896

Parameters​
selection​

RangeSelection

restoreSelection?​

boolean

Returns​

LexicalNode | null

Inherited from​

ElementNode.insertNewAfter

is()​

is(object): boolean

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

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:938

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:1276

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:270

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:264

Returns​

boolean

Inherited from​

ElementNode.isEmpty

isInline()​

isInline(): boolean

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

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:275

Returns​

boolean

Inherited from​

ElementNode.isLastChild

isParentOf()​

isParentOf(targetNode): boolean

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

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:1976

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:965

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:1842

Returns​

true

Overrides​

ElementNode.isShadowRoot

markDirty()​

markDirty(): void

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

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:1620

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:1637

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:889

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:575

Parameters​
_anchorOffset?​

number

_focusOffset?​

number

Returns​

RangeSelection

Inherited from​

ElementNode.select

selectEnd()​

selectEnd(): RangeSelection

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

Returns​

RangeSelection

Inherited from​

ElementNode.selectEnd

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

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

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:2002

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:620

Returns​

RangeSelection

Inherited from​

ElementNode.selectStart

setDirection()​

setDirection(direction): this

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

Parameters​
direction​

"ltr" | "rtl" | null

Returns​

this

Inherited from​

ElementNode.setDirection

setFormat()​

setFormat(type): this

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

Parameters​
type​

ElementFormatType

Returns​

this

Inherited from​

ElementNode.setFormat

setIndent()​

setIndent(indentLevel): this

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

Parameters​
indentLevel​

number

Returns​

this

Inherited from​

ElementNode.setIndent

setStyle()​

setStyle(style): this

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

Parameters​
style​

string

Returns​

this

Inherited from​

ElementNode.setStyle

setTextFormat()​

setTextFormat(type): this

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

Parameters​
type​

number

Returns​

this

Inherited from​

ElementNode.setTextFormat

setTextStyle()​

setTextStyle(style): this

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

Parameters​
style​

string

Returns​

this

Inherited from​

ElementNode.setTextStyle

splice()​

splice(start, deleteCount, nodesToInsert): this

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

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:1491

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:884

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​

LexicalUpdateJSON<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);
}
}
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:711

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:698

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:287

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:308

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:302

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:289

The string key used when serializing this state to JSON

parse​

readonly parse: (value?) => V

Defined in: packages/lexical/src/LexicalNodeState.ts:291

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:309

unparse​

readonly unparse: (value) => unknown

Defined in: packages/lexical/src/LexicalNodeState.ts:297

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:238

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>>

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:275

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:258

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:280

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:265

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:121

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​

$importJSON?​

readonly optional $importJSON?: (serializedNode) => T

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

An alternative to the static importJSON() method that provides better type inference.

Parameters​
serializedNode​

SerializedLexicalNode

Returns​

T

$transform?​

readonly optional $transform?: (node) => void

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

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:208

If specified, this must be the exact superclass of the node. It is not checked at compile time and it is provided automatically at runtime.

You would want to specify this when you are extending a node that has non-trivial configuration in its $config such as required state. If you do not specify this, the inferred types for your node class might be missing some of that.

importDOM?​

readonly optional importDOM?: DOMConversionMap<HTMLElement>

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

An alternative to the static importDOM() method

slots?​

readonly optional slots?: readonly string[]

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

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:181

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:134

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.


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:541

The payload passed to an UpdateListener

Properties​

dirtyElements​

dirtyElements: Map<string, boolean>

Defined in: packages/lexical/src/LexicalEditor.ts:547

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:552

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:557

The new EditorState after all updates have been processed, equivalent to editor.getEditorState()

mutatedNodes​

mutatedNodes: MutatedNodes | null

Defined in: packages/lexical/src/LexicalEditor.ts:569

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:578

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:582

The previous EditorState that is being discarded

tags​

tags: Set<string>

Defined in: packages/lexical/src/LexicalEditor.ts:588

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:696


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


AnyStateConfig​

AnyStateConfig = StateConfig<any, any>

Defined in: packages/lexical/src/LexicalNodeState.ts:338

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:224

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:621

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:630


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:631


CommandPayloadArgs​

CommandPayloadArgs<TPayload> = [TPayload extends undefined ? true : never] extends [never] ? [TPayload] : [TPayload]

Defined in: packages/lexical/src/LexicalEditor.ts:721

Type Parameters​

TPayload​

TPayload


CommandPayloadType​

CommandPayloadType<TCommand> = TCommand extends LexicalCommand<infer TPayload> ? TPayload : never

Defined in: packages/lexical/src/LexicalEditor.ts:718

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:600

Parameters​

lexicalNode​

LexicalNode

parentLexicalNode​

LexicalNode | null | undefined

Returns​

LexicalNode | null | undefined


DOMConversion​

DOMConversion<T> = object

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

Type Parameters​

T​

T extends HTMLElement = HTMLElement

Properties​

conversion​

conversion: DOMConversionFn<T>

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

priority?​

optional priority?: 0 | 1 | 2 | 3 | 4

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


DOMConversionFn​

DOMConversionFn<T> = (element) => DOMConversionOutput | null

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

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:605

Type Parameters​

T​

T extends HTMLElement = HTMLElement


DOMConversionOutput​

DOMConversionOutput = object

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

Properties​

after?​

optional after?: (childLexicalNodes) => LexicalNode[]

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

Parameters​
childLexicalNodes​

LexicalNode[]

Returns​

LexicalNode[]

forChild?​

optional forChild?: DOMChildConversion

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

node​

node: null | LexicalNode | LexicalNode[]

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


DOMConversionProp​

DOMConversionProp<T> = (node) => DOMConversion<T> | null

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

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:572

Type Parameters​

K​

K extends string


DOMConversionTagNameMap​

DOMConversionTagNameMap<K> = { [NodeName in K]?: DOMConversionPropByTagName<NodeName> }

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

Type Parameters​

K​

K extends string


DOMExportOutputMap​

DOMExportOutputMap = Map<Klass<LexicalNode>, (editor, target) => DOMExportOutput>

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


DOMSlotForNode​

DOMSlotForNode<N> = N extends ElementNode ? ElementDOMSlot<HTMLElement> : DOMSlot<HTMLElement>

Defined in: packages/lexical/src/LexicalEditor.ts:377

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:628

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:168

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:150

Properties​

tag?​

optional tag?: string

Defined in: packages/lexical/src/LexicalEditor.ts:151


EditorThemeClassName​

EditorThemeClassName = string

Defined in: packages/lexical/src/LexicalEditor.ts:106


EditorUpdateOptions​

EditorUpdateOptions = object

Defined in: packages/lexical/src/LexicalEditor.ts:125

Properties​

discrete?​

optional discrete?: true

Defined in: packages/lexical/src/LexicalEditor.ts:145

If true, prevents this update from being batched, forcing it to run synchronously.

onUpdate?​

optional onUpdate?: () => void

Defined in: packages/lexical/src/LexicalEditor.ts:129

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:135

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:140

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:77


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:2008

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:358

Properties​

export?​

optional export?: DOMExportOutputMap

Defined in: packages/lexical/src/LexicalEditor.ts:359

import?​

optional import?: DOMConversionMap

Defined in: packages/lexical/src/LexicalEditor.ts:360


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

KeyboardEventModifierMask​

KeyboardEventModifierMask = { [K in Exclude<keyof KeyboardEventModifiers, "key" | "code">]?: boolean | "any" }

Defined in: packages/lexical/src/LexicalUtils.ts:1175

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:1163

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:101

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:96

Type Parameters​

Cls​

Cls extends GenericConstructor<any>


LexicalExportJSON​

LexicalExportJSON<T> = Prettify<Omit<ReturnType<T["exportJSON"]>, "type"> & object & NodeStateJSON<T>>

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

The most precise type we can infer for the JSON that will be produced by T.exportJSON().

Do not use this for the return type of T.exportJSON()! It must be a more generic type to be compatible with subclassing.

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:366

A LexicalNode class or LexicalNodeReplacement configuration


LexicalNodeReplacement​

LexicalNodeReplacement = object

Defined in: packages/lexical/src/LexicalEditor.ts:334

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:338

The core node class whose instances should be replaced.

with​

with: <T>(node) => LexicalNode

Defined in: packages/lexical/src/LexicalEditor.ts:345

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:355

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.


LexicalUpdateJSON​

LexicalUpdateJSON<T> = Omit<T, "children" | "type" | "version">

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

Omit the children, type, and version properties from the given SerializedLexicalNode definition.

Type Parameters​

T​

T extends SerializedLexicalNode


MutationListener​

MutationListener = (nodes, payload) => void

Defined in: packages/lexical/src/LexicalEditor.ts:612

Parameters​

nodes​

Map<NodeKey, NodeMutation>

payload​
dirtyLeaves​

Set<string>

prevEditorState​

EditorState

updateTags​

Set<string>

Returns​

void


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:655


NodeMap​

NodeMap = Map<NodeKey, LexicalNode>

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


NodeMutation​

NodeMutation = "created" | "updated" | "destroyed"

Defined in: packages/lexical/src/LexicalEditor.ts:524


NodeStateJSON​

NodeStateJSON<T> = Prettify<object & CollectStateJSON<GetNodeStateConfig<T>, true>>

Defined in: packages/lexical/src/LexicalNodeState.ts:192

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:48


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


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:605

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).


SerializedEditor​

SerializedEditor = object

Defined in: packages/lexical/src/LexicalEditor.ts:765

Properties​

editorState​

editorState: SerializedEditorState

Defined in: packages/lexical/src/LexicalEditor.ts:766


SerializedElementNode​

SerializedElementNode<T> = Spread<{ children: T[]; direction: "ltr" | "rtl" | null; format: ElementFormatType; indent: number; textFormat?: number; textStyle?: string; }, SerializedLexicalNode>

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

Type Parameters​

T​

T extends SerializedLexicalNode = SerializedLexicalNode


SerializedLexicalNode​

SerializedLexicalNode = object

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

The base type for all serialized nodes

Properties​

$?​

optional $?: Record<string, unknown>

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

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:105

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:89

The type string used by the Node class

version​

version: number

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

A numeric version for this schema, defaulting to 1, but not generally recommended for use


SerializedLineBreakNode​

SerializedLineBreakNode = SerializedLexicalNode

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


SerializedParagraphNode​

SerializedParagraphNode = Spread<{ textFormat: number; textStyle: string; }, SerializedElementNode>

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


SerializedRootNode​

SerializedRootNode<T> = SerializedElementNode<T>

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

Type Parameters​

T​

T extends SerializedLexicalNode = SerializedLexicalNode


SerializedTabNode​

SerializedTabNode = SerializedTextNode

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


SerializedTextNode​

SerializedTextNode = Spread<{ detail: number; format: number; mode: TextModeType; style: string; text: string; }, SerializedLexicalNode>

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


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:92

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:60

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:55

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:83

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:233

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:91


TextModeType​

TextModeType = "normal" | "token" | "segmented"

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


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:501

Type Parameters​

T​

T extends LexicalNode

Parameters​

node​

T

Returns​

void


UpdateListener​

UpdateListener = (payload) => void

Defined in: packages/lexical/src/LexicalEditor.ts:594

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:67

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:3554

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:44

Dispatched on a beforeinput event.


BLUR_COMMAND​

const BLUR_COMMAND: LexicalCommand<FocusEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:280

Dispatched when the editor loses focus.


CAN_REDO_COMMAND​

const CAN_REDO_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:263

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:274

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:247

Dispatched to clear all editor content.


CLEAR_HISTORY_COMMAND​

const CLEAR_HISTORY_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:251

Dispatched to clear the undo/redo history stack.


CLICK_COMMAND​

const CLICK_COMMAND: LexicalCommand<MouseEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:41

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:677

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:661

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:673

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:665

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:669

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:657

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:641

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:653

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:645

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:649

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:54

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:51

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:77

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:230

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:237

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:61

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:99

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:91

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:224

Dispatched when a drag operation ends.


DRAGOVER_COMMAND​

const DRAGOVER_COMMAND: LexicalCommand<DragEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:221

Dispatched when a dragged element is over the editor.


DRAGSTART_COMMAND​

const DRAGSTART_COMMAND: LexicalCommand<DragEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:218

Dispatched when a drag operation starts.


DROP_COMMAND​

const DROP_COMMAND: LexicalCommand<DragEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:212

Dispatched on a drop event.


FOCUS_COMMAND​

const FOCUS_COMMAND: LexicalCommand<FocusEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:277

Dispatched when the editor receives focus.


FORMAT_ELEMENT_COMMAND​

const FORMAT_ELEMENT_COMMAND: LexicalCommand<ElementFormatType>

Defined in: packages/lexical/src/LexicalCommands.ts:215

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:105

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:204

Dispatched to indent the selected content.


INPUT_COMMAND​

const INPUT_COMMAND: LexicalCommand<InputEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:48

Dispatched on an input event.


INSERT_LINE_BREAK_COMMAND​

const INSERT_LINE_BREAK_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:69

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:73

Dispatched to insert a new paragraph (Enter key).


INSERT_TAB_COMMAND​

const INSERT_TAB_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:201

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:238

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:162

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:144

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:132

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:156

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:181

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:192

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:126

Dispatched when any key is pressed.


KEY_ENTER_COMMAND​

const KEY_ENTER_COMMAND: LexicalCommand<KeyboardEvent | null>

Defined in: packages/lexical/src/LexicalCommands.ts:169

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:187

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:288

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:175

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:198

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:138

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:150

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:41

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:46

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:208

Dispatched to outdent the selected content.


PASTE_COMMAND​

const PASTE_COMMAND: LexicalCommand<PasteCommandType>

Defined in: packages/lexical/src/LexicalCommands.ts:81

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:122

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:84

Dispatched to remove the currently selected text.


removeFromParent​

const removeFromParent: object = $removeFromParent

Defined in: packages/lexical/src/LexicalUtils.ts:575

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:244

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:32

Dispatched whenever the editor selection changes.


SELECTION_INSERT_CLIPBOARD_NODES_COMMAND​

const SELECTION_INSERT_CLIPBOARD_NODES_COMMAND: LexicalCommand<{ nodes: LexicalNode[]; selection: BaseSelection; }>

Defined in: packages/lexical/src/LexicalCommands.ts:36

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:112

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:118

Dispatched on undo (Cmd+Z on macOS, Ctrl+Z elsewhere).

Functions​

$addUpdateTag()​

$addUpdateTag(tag): void

Defined in: packages/lexical/src/LexicalUtils.ts:1734

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:1889

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:2965

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:3029

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:1870

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:3531

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:3581

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:68

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:217

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​

"element" | "text"

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:99

Creates a TabNode representing a horizontal tab character.

Returns​

TabNode


$createTextNode()​

$createTextNode(text?): TextNode

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

Creates a TextNode initialized with the given text, defaulting to empty.

Parameters​

text?​

string = ''

Returns​

TextNode


$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:1119

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:1542

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:2229

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:2768

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:2897

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:2739

Utility function for accessing current active editor instance.

Returns​

LexicalEditor

Current active editor


$getEditorDOMRenderConfig()​

$getEditorDOMRenderConfig(editor?): EditorDOMRenderConfig

Defined in: packages/lexical/src/LexicalUtils.ts:2751

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:724

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:1817

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:662

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:672

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:1959

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:1966

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:689

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:793

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): ElementNode | DecoratorNode<unknown> | 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​

ElementNode | DecoratorNode<unknown> | 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:381

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:410

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:1773

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:1728

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


$isDecoratorNode()​

$isDecoratorNode<T>(node): node is DecoratorNode<T>

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

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:129

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:2881

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:1011

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:1803

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:320

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 TextNode | DecoratorNode<unknown> | LineBreakNode

Defined in: packages/lexical/src/LexicalUtils.ts:385

Returns true if the given node is a leaf (TextNode, LineBreakNode, or DecoratorNode).

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is TextNode | DecoratorNode<unknown> | LineBreakNode


$isLexicalNode()​

$isLexicalNode(node): node is LexicalNode

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

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:73

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:222

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:1853

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:203

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:1846

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:104

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:1404

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:321

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:314

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:3157

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:2005

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:1498

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:1747

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:402

Deserializes a SerializedLexicalNode JSON object into its corresponding LexicalNode instance.

Parameters​

serializedNode​

SerializedLexicalNode

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:1359

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:629

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:3067

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:3086

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:843

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:443

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:2563

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


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


buildImportMap()​

buildImportMap<K>(importMap): DOMConversionMap

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

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:943

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:355

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


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:2492

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:2510

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:2546

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:2278

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:1627

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:2106

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:2116

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:2381

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:2333

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:2404

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:2149

Parameters​

node​

Node

Returns​

ShadowRoot[]


getDOMTextNode()​

getDOMTextNode(element): Text | null

Defined in: packages/lexical/src/LexicalUtils.ts:342

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:280

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:1612

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:3484

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:301

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:2692

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:97

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:2661

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:3187

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:337

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:2648

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:2130

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:329

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:3142

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:1236

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:2615

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:2640

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:2632

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:2623

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:2673

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:116

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:274

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:1216

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:87

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


isSelectionWithinEditor()​

isSelectionWithinEditor(editor, anchorDOM, focusDOM): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:242

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:2834

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.


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:159

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:3127

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:3036

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}


toggleTextFormatType()​

toggleTextFormatType(format, type, alignWithFormat): number

Defined in: packages/lexical/src/LexicalUtils.ts:354

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


unmountSlotContainer()​

unmountSlotContainer(editor, nodeKey, container): void

Defined in: packages/lexical/src/LexicalUtils.ts:2862

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