Skip to main content

lexical

Classes​

DecoratorNode​

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

Extends​

Extended by​

Type Parameters​

T​

T

Constructors​

Constructor​

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

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

Parameters​
key?​

string

Returns​

DecoratorNode<T>

Properties​

importDOM?​

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

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

Returns​

DOMConversionMap<any> | null

Methods​

$config()​

$config(): BaseStaticNodeConfig

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

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/LexicalNode.ts:604

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

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

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

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

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

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

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

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

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

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

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

getIndexWithinParent()​

getIndexWithinParent(): number

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

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

Returns this nodes key.

Returns​

string

Inherited from​

LexicalNode.getKey

getLatest()​

getLatest(): this

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

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

getNextSibling<T>(): T | null

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

Returns the "next" siblings - that is, the node that comes after this one in the same parent

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Inherited from​

LexicalNode.getNextSibling

getNextSiblings()​

getNextSiblings<T>(): T[]

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

Returns all "next" siblings - that is, the nodes that come between this one and the last child of it's parent, inclusive.

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Inherited from​

LexicalNode.getNextSiblings

getNodesBetween()​

getNodesBetween(targetNode): LexicalNode[]

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

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

getParent<T>(): T | null

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

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

Type Parameters​
T​

T extends ElementNode

Returns​

T | null

Inherited from​

LexicalNode.getParent

getParentKeys()​

getParentKeys(): string[]

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

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

getParentOrThrow<T>(): T

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

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

Type Parameters​
T​

T extends ElementNode

Returns​

T

Inherited from​

LexicalNode.getParentOrThrow

getParents()​

getParents(): ElementNode[]

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

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

Returns​

ElementNode[]

Inherited from​

LexicalNode.getParents

getPreviousSibling()​

getPreviousSibling<T>(): T | null

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

Returns the "previous" siblings - that is, the node that comes before this one in the same parent.

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Inherited from​

LexicalNode.getPreviousSibling

getPreviousSiblings()​

getPreviousSiblings<T>(): T[]

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

Returns the "previous" siblings - that is, the nodes that come between this one and the first child of it's parent, inclusive.

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Inherited from​

LexicalNode.getPreviousSiblings

getTextContent()​

getTextContent(): string

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

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

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

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

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

Returns the string type of this node.

Returns​

string

Inherited from​

LexicalNode.getType

getWritable()​

getWritable(): this

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

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

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

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

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

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

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

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

Returns​

boolean

Inherited from​

LexicalNode.isInline

isIsolated()​

isIsolated(): boolean

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

Returns​

boolean

isKeyboardSelectable()​

isKeyboardSelectable(): boolean

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

Returns​

boolean

isParentOf()​

isParentOf(targetNode): boolean

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

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

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

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

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

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

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

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

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

Returns​

RangeSelection

Inherited from​

LexicalNode.selectEnd

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

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

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

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

Returns​

RangeSelection

Inherited from​

LexicalNode.selectStart

updateDOM()​

updateDOM(_prevNode, _dom, _config): boolean

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

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

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

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

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

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

Returns​

LexicalNode

transform()​

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

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

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

Extends​

Extended by​

Constructors​

Constructor​

new ElementNode(key?): ElementNode

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

Parameters​
key?​

string

Returns​

ElementNode

Properties​

importDOM?​

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

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

Returns​

DOMConversionMap<any> | null

Methods​

$config()​

$config(): BaseStaticNodeConfig

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

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

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

Parameters​
nodesToAppend​

...LexicalNode[]

Returns​

this

canBeEmpty()​

canBeEmpty(): boolean

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

Returns​

boolean

canIndent()​

canIndent(): boolean

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

Returns​

boolean

canInsertTextAfter()​

canInsertTextAfter(): boolean

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

Returns​

boolean

canInsertTextBefore()​

canInsertTextBefore(): boolean

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

Returns​

boolean

canMergeWhenEmpty()​

canMergeWhenEmpty(): boolean

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

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

Returns​

this

collapseAtStart()​

collapseAtStart(selection): boolean

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

Parameters​
selection​

RangeSelection

Returns​

boolean

config()​

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

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

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

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

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

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

Parameters​
destination?​

"clone" | "html"

Returns​

boolean

exportDOM()​

exportDOM(editor): DOMExportOutput

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

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

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

Parameters​
child​

LexicalNode

selection​

BaseSelection | null

destination​

"clone" | "html"

Returns​

boolean

getAllTextNodes()​

getAllTextNodes(): TextNode[]

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

Returns​

TextNode[]

getChildAtIndex()​

getChildAtIndex<T>(index): T | null

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

Type Parameters​
T​

T extends LexicalNode

Parameters​
index​

number

Returns​

T | null

getChildren()​

getChildren<T>(): T[]

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

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

getChildrenKeys()​

getChildrenKeys(): string[]

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

Returns​

string[]

getChildrenSize()​

getChildrenSize(): number

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

Returns​

number

getCommonAncestor()​

getCommonAncestor<T>(node): T | null

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

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

getDescendantByIndex<T>(index): T | null

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

Type Parameters​
T​

T extends LexicalNode

Parameters​
index​

number

Returns​

T | null

getDirection()​

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

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

Returns​

"ltr" | "rtl" | null

getFirstChild()​

getFirstChild<T>(): T | null

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

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

getFirstChildOrThrow()​

getFirstChildOrThrow<T>(): T

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

Type Parameters​
T​

T extends LexicalNode

Returns​

T

getFirstDescendant()​

getFirstDescendant<T>(): T | null

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

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

getFormat()​

getFormat(): number

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

Returns​

number

getFormatFlags()​

getFormatFlags(type, alignWithFormat): number

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

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

Returns​

ElementFormatType

getIndent()​

getIndent(): number

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

Returns​

number

getIndexWithinParent()​

getIndexWithinParent(): number

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

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

Returns this nodes key.

Returns​

string

Inherited from​

LexicalNode.getKey

getLastChild()​

getLastChild<T>(): T | null

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

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

getLastChildOrThrow()​

getLastChildOrThrow<T>(): T

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

Type Parameters​
T​

T extends LexicalNode

Returns​

T

getLastDescendant()​

getLastDescendant<T>(): T | null

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

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

getLatest()​

getLatest(): this

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

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

getNextSibling<T>(): T | null

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

Returns the "next" siblings - that is, the node that comes after this one in the same parent

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Inherited from​

LexicalNode.getNextSibling

getNextSiblings()​

getNextSiblings<T>(): T[]

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

Returns all "next" siblings - that is, the nodes that come between this one and the last child of it's parent, inclusive.

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Inherited from​

LexicalNode.getNextSiblings

getNodesBetween()​

getNodesBetween(targetNode): LexicalNode[]

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

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

getParent<T>(): T | null

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

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

Type Parameters​
T​

T extends ElementNode

Returns​

T | null

Inherited from​

LexicalNode.getParent

getParentKeys()​

getParentKeys(): string[]

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

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

getParentOrThrow<T>(): T

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

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

Type Parameters​
T​

T extends ElementNode

Returns​

T

Inherited from​

LexicalNode.getParentOrThrow

getParents()​

getParents(): ElementNode[]

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

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

Returns​

ElementNode[]

Inherited from​

LexicalNode.getParents

getPreviousSibling()​

getPreviousSibling<T>(): T | null

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

Returns the "previous" siblings - that is, the node that comes before this one in the same parent.

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Inherited from​

LexicalNode.getPreviousSibling

getPreviousSiblings()​

getPreviousSiblings<T>(): T[]

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

Returns the "previous" siblings - that is, the nodes that come between this one and the first child of it's parent, inclusive.

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Inherited from​

LexicalNode.getPreviousSiblings

getStyle()​

getStyle(): string

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

Returns​

string

getTextContent()​

getTextContent(): string

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

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

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

Returns​

number

getTextStyle()​

getTextStyle(): string

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

Returns​

string

getTopLevelElement()​

getTopLevelElement(): ElementNode | null

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

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

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

Returns the string type of this node.

Returns​

string

Inherited from​

LexicalNode.getType

getWritable()​

getWritable(): this

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

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

Parameters​
type​

ElementFormatType

Returns​

boolean

hasTextFormat()​

hasTextFormat(type): boolean

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

Parameters​
type​

TextFormatType

Returns​

boolean

insertAfter()​

insertAfter(nodeToInsert, restoreSelection?): LexicalNode

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

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

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

Parameters​
selection​

RangeSelection

restoreSelection?​

boolean

Returns​

LexicalNode | null

is()​

is(object): boolean

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

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

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

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

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

Returns​

boolean

isInline()​

isInline(): boolean

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

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

Returns​

boolean

isParentOf()​

isParentOf(targetNode): boolean

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

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

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

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

Returns​

boolean

markDirty()​

markDirty(): void

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

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

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

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

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

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

Parameters​
_anchorOffset?​

number

_focusOffset?​

number

Returns​

RangeSelection

selectEnd()​

selectEnd(): RangeSelection

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

Returns​

RangeSelection

Inherited from​

LexicalNode.selectEnd

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

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

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

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

Returns​

RangeSelection

Inherited from​

LexicalNode.selectStart

setDirection()​

setDirection(direction): this

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

Parameters​
direction​

"ltr" | "rtl" | null

Returns​

this

setFormat()​

setFormat(type): this

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

Parameters​
type​

ElementFormatType

Returns​

this

setIndent()​

setIndent(indentLevel): this

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

Parameters​
indentLevel​

number

Returns​

this

setStyle()​

setStyle(style): this

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

Parameters​
style​

string

Returns​

this

setTextFormat()​

setTextFormat(type): this

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

Parameters​
type​

number

Returns​

this

setTextStyle()​

setTextStyle(style): this

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

Parameters​
style​

string

Returns​

this

splice()​

splice(start, deleteCount, nodesToInsert): this

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

Parameters​
start​

number

deleteCount​

number

nodesToInsert​

LexicalNode[]

Returns​

this

updateDOM()​

updateDOM(_prevNode, _dom, _config): boolean

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

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

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

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

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

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

Returns​

LexicalNode

transform()​

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

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

Experimental

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

Experimental - use at your own risk.

Returns​

((node) => void) | null


LineBreakNode​

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

Extends​

Constructors​

Constructor​

new LineBreakNode(key?): LineBreakNode

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

Parameters​
key?​

string

Returns​

LineBreakNode

Overrides​

LexicalNode.constructor

Methods​

createDOM()​

createDOM(): HTMLElement

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

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

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

Returns​

true

Overrides​

LexicalNode.isInline

updateDOM()​

updateDOM(): false

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

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

clone()​

static clone(node): LineBreakNode

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

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

LineBreakNode

Returns​

LineBreakNode

Overrides​

LexicalNode.clone

getType()​

static getType(): string

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

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

Overrides​

LexicalNode.getType

importDOM()​

static importDOM(): DOMConversionMap | null

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

Returns​

DOMConversionMap | null

Overrides​

LexicalNode.importDOM

importJSON()​

static importJSON(serializedLineBreakNode): LineBreakNode

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

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

SerializedLexicalNode

Returns​

LineBreakNode

Overrides​

LexicalNode.importJSON


ParagraphNode​

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

Extends​

Methods​

collapseAtStart()​

collapseAtStart(): boolean

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

Returns​

boolean

Overrides​

ElementNode.collapseAtStart

createDOM()​

createDOM(config): HTMLElement

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

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

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

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

Parameters​
config​

EditorConfig

Returns​

HTMLElement

Overrides​

ElementNode.createDOM

exportDOM()​

exportDOM(editor): DOMExportOutput

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

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

Parameters​
editor​

LexicalEditor

Returns​

DOMExportOutput

Overrides​

ElementNode.exportDOM

exportJSON()​

exportJSON(): SerializedParagraphNode

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

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

insertNewAfter()​

insertNewAfter(rangeSelection, restoreSelection): ParagraphNode

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

Parameters​
rangeSelection​

RangeSelection

restoreSelection​

boolean

Returns​

ParagraphNode

Overrides​

ElementNode.insertNewAfter

updateDOM()​

updateDOM(prevNode, dom, config): boolean

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

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

clone()​

static clone(node): ParagraphNode

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

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

ParagraphNode

Returns​

ParagraphNode

Overrides​

ElementNode.clone

getType()​

static getType(): string

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

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

Overrides​

ElementNode.getType

importDOM()​

static importDOM(): DOMConversionMap | null

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

Returns​

DOMConversionMap | null

Overrides​

ElementNode.importDOM

importJSON()​

static importJSON(serializedNode): ParagraphNode

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

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​

SerializedParagraphNode

Returns​

ParagraphNode

Overrides​

ElementNode.importJSON


RootNode​

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

Extends​

Constructors​

Constructor​

new RootNode(): RootNode

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

Returns​

RootNode

Overrides​

ElementNode.constructor

Methods​

collapseAtStart()​

collapseAtStart(): true

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

Returns​

true

Overrides​

ElementNode.collapseAtStart

getTextContent()​

getTextContent(): string

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

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

Returns​

string

Overrides​

ElementNode.getTextContent

getTopLevelElementOrThrow()​

getTopLevelElementOrThrow(): never

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

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

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

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

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

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

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

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

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

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

Parameters​
prevNode​

this

dom​

HTMLElement

Returns​

false

Overrides​

ElementNode.updateDOM

clone()​

static clone(): RootNode

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

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.

Returns​

RootNode

Overrides​

ElementNode.clone

getType()​

static getType(): string

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

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

Overrides​

ElementNode.getType

importJSON()​

static importJSON(serializedNode): RootNode

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

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

Extends​

Constructors​

Constructor​

new TabNode(key?): TabNode

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

Parameters​
key?​

string

Returns​

TabNode

Overrides​

TextNode.constructor

Methods​

canInsertTextAfter()​

canInsertTextAfter(): boolean

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

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

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

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

Sets the mode of the node.

Parameters​
type​

TextModeType

Returns​

this

this TextNode.

Overrides​

TextNode.setMode

setTextContent()​

setTextContent(text): this

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

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.

Overrides​

TextNode.setTextContent

spliceText()​

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

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

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

clone()​

static clone(node): TabNode

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

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

TabNode

Returns​

TabNode

Overrides​

TextNode.clone

getType()​

static getType(): string

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

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

Overrides​

TextNode.getType

importDOM()​

static importDOM(): DOMConversionMap | null

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

Returns​

DOMConversionMap | null

Overrides​

TextNode.importDOM

importJSON()​

static importJSON(serializedTabNode): TabNode

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

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

SerializedTextNode

Returns​

TabNode

Overrides​

TextNode.importJSON


TextNode​

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

Extends​

Extended by​

Constructors​

Constructor​

new TextNode(text?, key?): TextNode

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

Parameters​
text?​

string = ''

key?​

string

Returns​

TextNode

Properties​

__text​

__text: string

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

Methods​

$config()​

$config(): BaseStaticNodeConfig

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

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

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

Returns​

boolean

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

canInsertTextAfter()​

canInsertTextAfter(): boolean

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

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

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

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

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

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

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

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

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

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

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

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

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.

getFormat()​

getFormat(): number

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

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

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

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

Returns this nodes key.

Returns​

string

Inherited from​

LexicalNode.getKey

getLatest()​

getLatest(): this

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

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

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

Returns​

TextModeType

TextModeType.

getNextSibling()​

getNextSibling<T>(): T | null

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

Returns the "next" siblings - that is, the node that comes after this one in the same parent

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Inherited from​

LexicalNode.getNextSibling

getNextSiblings()​

getNextSiblings<T>(): T[]

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

Returns all "next" siblings - that is, the nodes that come between this one and the last child of it's parent, inclusive.

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Inherited from​

LexicalNode.getNextSiblings

getNodesBetween()​

getNodesBetween(targetNode): LexicalNode[]

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

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

getParent<T>(): T | null

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

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

Type Parameters​
T​

T extends ElementNode

Returns​

T | null

Inherited from​

LexicalNode.getParent

getParentKeys()​

getParentKeys(): string[]

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

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

getParentOrThrow<T>(): T

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

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

Type Parameters​
T​

T extends ElementNode

Returns​

T

Inherited from​

LexicalNode.getParentOrThrow

getParents()​

getParents(): ElementNode[]

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

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

Returns​

ElementNode[]

Inherited from​

LexicalNode.getParents

getPreviousSibling()​

getPreviousSibling<T>(): T | null

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

Returns the "previous" siblings - that is, the node that comes before this one in the same parent.

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

Inherited from​

LexicalNode.getPreviousSibling

getPreviousSiblings()​

getPreviousSiblings<T>(): T[]

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

Returns the "previous" siblings - that is, the nodes that come between this one and the first child of it's parent, inclusive.

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

Inherited from​

LexicalNode.getPreviousSiblings

getStyle()​

getStyle(): string

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

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

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

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

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

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

Returns the string type of this node.

Returns​

string

Inherited from​

LexicalNode.getType

getWritable()​

getWritable(): this

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Returns​

RangeSelection

Inherited from​

LexicalNode.selectEnd

selectionTransform()​

selectionTransform(prevSelection, nextSelection): void

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

Parameters​
prevSelection​

BaseSelection | null

nextSelection​

RangeSelection

Returns​

void

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

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

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

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

Returns​

RangeSelection

Inherited from​

LexicalNode.selectStart

setDetail()​

setDetail(detail): this

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

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

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

Sets the mode of the node.

Parameters​
type​

TextModeType

Returns​

this

this TextNode.

setStyle()​

setStyle(style): this

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

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

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

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

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

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

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

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

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

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(node): TextNode

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

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

TextNode

Returns​

TextNode

getType()​

static getType(): string

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

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

importDOM()​

static importDOM(): DOMConversionMap | null

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

Returns​

DOMConversionMap | null

importJSON()​

static importJSON(serializedNode): TextNode

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

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​

SerializedTextNode

Returns​

TextNode

transform()​

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

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

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

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

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

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

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

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

Get a new SiblingCaret with this same node

Returns​

SiblingCaret<T, D>

insert​

insert: (node) => this

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

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

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

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

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

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

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

Properties​

_cachedNodes​

_cachedNodes: LexicalNode[] | null

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

dirty​

dirty: boolean

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

Methods​

clone()​

clone(): BaseSelection

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

Returns​

BaseSelection

extract()​

extract(): LexicalNode[]

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

Returns​

LexicalNode[]

getCachedNodes()​

getCachedNodes(): LexicalNode[] | null

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

Returns​

LexicalNode[] | null

getNodes()​

getNodes(): LexicalNode[]

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

Returns​

LexicalNode[]

getStartEndPoints()​

getStartEndPoints(): [PointType, PointType] | null

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

Returns​

[PointType, PointType] | null

getTextContent()​

getTextContent(): string

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

Returns​

string

insertNodes()​

insertNodes(nodes): void

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

Parameters​
nodes​

LexicalNode[]

Returns​

void

insertRawText()​

insertRawText(text): void

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

Parameters​
text​

string

Returns​

void

insertText()​

insertText(text): void

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

Parameters​
text​

string

Returns​

void

is()​

is(selection): boolean

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

Parameters​
selection​

BaseSelection | null

Returns​

boolean

isBackward()​

isBackward(): boolean

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

Returns​

boolean

isCollapsed()​

isCollapsed(): boolean

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

Returns​

boolean

setCachedNodes()​

setCachedNodes(nodes): void

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

Parameters​
nodes​

LexicalNode[] | null

Returns​

void


CaretRange​

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

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

direction​

readonly direction: D

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

focus​

focus: PointCaret<D>

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

getTextSlices​

getTextSlices: () => TextPointCaretSliceTuple<D>

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

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

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

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

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

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

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

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

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

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

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

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

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

Parameters​
mode?​

RootMode

Returns​

SiblingCaret<T, D> | null

getSiblingCaret​

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

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

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

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

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

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

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

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

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

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

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

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

type​

readonly type: "ancestor"

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


CommonAncestorResultBranch​

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

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

The ancestor of a that is a child of commonAncestor

b​

readonly b: ElementNode | B

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

The ancestor of b that is a child of commonAncestor

commonAncestor​

readonly commonAncestor: ElementNode

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

type​

readonly type: "branch"

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


CommonAncestorResultDescendant​

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

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

type​

readonly type: "descendant"

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


CommonAncestorResultSame​

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

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

type​

readonly type: "same"

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


CreateEditorArgs​

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

Properties​

disableEvents?​

optional disableEvents?: boolean

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

dom?​

optional dom?: Partial<EditorDOMRenderConfig>

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

editable?​

optional editable?: boolean

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

editorState?​

optional editorState?: EditorState

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

html?​

optional html?: HTMLConfig

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

namespace?​

optional namespace?: string

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

nodes?​

optional nodes?: readonly LexicalNodeConfig[]

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

onError?​

optional onError?: ErrorHandler

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

parentEditor?​

optional parentEditor?: LexicalEditor

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

theme?​

optional theme?: EditorThemeClasses

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


DOMExportOutput​

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

Properties​

$getChildNodes?​

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

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

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

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

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

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


EditorConfig​

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

Properties​

disableEvents?​

optional disableEvents?: boolean

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

dom?​

optional dom?: EditorDOMRenderConfig

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

namespace​

namespace: string

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

theme​

theme: EditorThemeClasses

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


EditorState​

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

Properties​

_flushSync​

_flushSync: boolean

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

_nodeMap​

_nodeMap: NodeMap

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

_readOnly​

_readOnly: boolean

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

_selection​

_selection: BaseSelection | null

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

Methods​

clone()​

clone(selection?): EditorState

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

Parameters​
selection?​

BaseSelection | null

Returns​

EditorState

isEmpty()​

isEmpty(): boolean

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

Returns​

boolean

read()​

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

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

Type Parameters​
V​

V

Parameters​
callbackFn​

() => V

options?​

EditorStateReadOptions

Returns​

V

toJSON()​

toJSON(): SerializedEditorState

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

Returns​

SerializedEditorState


EditorStateReadOptions​

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

Properties​

editor?​

optional editor?: LexicalEditor | null

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


EditorThemeClasses​

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

Indexable​

[key: string]: any

Properties​

blockCursor?​

optional blockCursor?: string

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

characterLimit?​

optional characterLimit?: string

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

code?​

optional code?: string

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

codeHighlight?​

optional codeHighlight?: Record<string, string>

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

collaboration?​

optional collaboration?: object

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

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

base?​

optional base?: string

focus?​

optional focus?: string

hashtag?​

optional hashtag?: string

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

heading?​

optional heading?: object

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

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

hrSelected?​

optional hrSelected?: string

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

image?​

optional image?: string

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

indent?​

optional indent?: string

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

optional link?: string

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

list?​

optional list?: object

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

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

mark?​

optional mark?: string

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

markOverlap?​

optional markOverlap?: string

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

paragraph?​

optional paragraph?: string

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

quote?​

optional quote?: string

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

root?​

optional root?: string

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

rtl?​

optional rtl?: string

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

specialText?​

optional specialText?: string

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

tab?​

optional tab?: string

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

table?​

optional table?: string

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

tableAddColumns?​

optional tableAddColumns?: string

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

tableAddRows?​

optional tableAddRows?: string

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

tableCell?​

optional tableCell?: string

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

tableCellActionButton?​

optional tableCellActionButton?: string

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

tableCellActionButtonContainer?​

optional tableCellActionButtonContainer?: string

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

tableCellHeader?​

optional tableCellHeader?: string

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

tableCellResizer?​

optional tableCellResizer?: string

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

tableCellSelected?​

optional tableCellSelected?: string

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

tableRow?​

optional tableRow?: string

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

tableScrollableWrapper?​

optional tableScrollableWrapper?: string

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

tableSelected?​

optional tableSelected?: string

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

tableSelection?​

optional tableSelection?: string

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

text?​

optional text?: TextNodeThemeClasses

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


ElementDOMSlot​

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

A utility class for managing the DOM children of an ElementNode

Type Parameters​

T​

T extends HTMLElement = HTMLElement

Properties​

after​

readonly after: Node | null

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

before​

readonly before: Node | null

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

element​

readonly element: T

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

Methods​

getFirstChild()​

getFirstChild(): ChildNode | null

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

Returns the first managed child of this node, which will either be this.after.nextSibling or this.element.firstChild, and will never be this.before if it is defined.

Returns​

ChildNode | null

insertChild()​

insertChild(dom): this

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

Insert the given child before this.before and any reconciler managed line break node, or append it if this.before is not defined

Parameters​
dom​

Node

Returns​

this

removeChild()​

removeChild(dom): this

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

Remove the managed child from this container, will throw if it was not already there

Parameters​
dom​

Node

Returns​

this

replaceChild()​

replaceChild(dom, prevDom): this

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

Replace managed child prevDom with dom. Will throw if prevDom is not a child

Parameters​
dom​

Node

The new node to replace prevDom

prevDom​

Node

the node that will be replaced

Returns​

this

withAfter()​

withAfter(after): ElementDOMSlot<T>

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

Return a new ElementDOMSlot where all managed children will be inserted after this node

Parameters​
after​

Node | null | undefined

Returns​

ElementDOMSlot<T>

withBefore()​

withBefore(before): ElementDOMSlot<T>

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

Return a new ElementDOMSlot where all managed children will be inserted before this node

Parameters​
before​

Node | null | undefined

Returns​

ElementDOMSlot<T>

withElement()​

withElement<ElementType>(element): ElementDOMSlot<ElementType>

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

Return a new ElementDOMSlot with an updated root element

Type Parameters​
ElementType​

ElementType extends HTMLElement

Parameters​
element​

ElementType

Returns​

ElementDOMSlot<ElementType>


ExtensionBuildState​

Defined in: packages/lexical/src/extension-core/types.ts:100

Extends​

Extended by​

Type Parameters​

Init​

Init

Properties​

getDependency​

getDependency: <Dependency>(dep) => LexicalExtensionDependency<Dependency>

Defined in: packages/lexical/src/extension-core/types.ts:115

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

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

The result of the init function

Returns​

Init

getPeer​

getPeer: <Dependency>(name) => LexicalExtensionDependency<Dependency> | undefined

Defined in: packages/lexical/src/extension-core/types.ts:108

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

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

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

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

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

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

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

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

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

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

The result of the init function

Returns​

Init

Inherited from​

ExtensionBuildState.getInitResult

getOutput​

getOutput: () => Output

Defined in: packages/lexical/src/extension-core/types.ts:137

The result of the output function

Returns​

Output

getPeer​

getPeer: <Dependency>(name) => LexicalExtensionDependency<Dependency> | undefined

Defined in: packages/lexical/src/extension-core/types.ts:108

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

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

An AbortSignal that is aborted when this LexicalEditor registration is disposed

Returns​

AbortSignal


InitialEditorConfig​

Defined in: packages/lexical/src/extension-core/types.ts:361

Extended by​

Properties​

$initialEditorState?​

optional $initialEditorState?: InitialEditorStateType

Defined in: packages/lexical/src/extension-core/types.ts:417

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

Whether the initial state of the editor is editable or not

html?​

optional html?: HTMLConfig

Defined in: packages/lexical/src/extension-core/types.ts:399

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

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

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

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

parentEditor?​

optional parentEditor?: LexicalEditor

Defined in: packages/lexical/src/extension-core/types.ts:373

Used when this editor is nested inside of another editor

theme?​

optional theme?: EditorThemeClasses

Defined in: packages/lexical/src/extension-core/types.ts:393

EditorThemeClasses that will be deep merged with other Extensions


LexicalEditor​

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

Extended by​

Methods​

blur()​

blur(): void

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

Removes focus from the editor.

Returns​

void

dispatchCommand()​

dispatchCommand<TCommand>(type, payload): boolean

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

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

Parameters​
type​

TCommand

the type of command listeners to trigger.

payload​

CommandPayloadType<TCommand>

the data to pass as an argument to the command listeners.

Returns​

boolean

focus()​

focus(callbackFn?, options?): void

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

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

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

Gets the active editor state.

Returns​

EditorState

The editor state

getElementByKey()​

getElementByKey(key): HTMLElement | null

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

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

Gets the key of the editor

Returns​

string

The editor key

getRootElement()​

getRootElement(): HTMLElement | null

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

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

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

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

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

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

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

read<T>(callbackFn): T

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

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. Any pending updates will be flushed immediately before the read.

Type Parameters​
T​

T

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

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

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

Registers a listener for 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:1228

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

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

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

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

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

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

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

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

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

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

A handle to the editor with an attached dispose function

Extends​

Properties​

dispose​

dispose: () => void

Defined in: packages/lexical/src/extension-core/types.ts:345

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

Removes focus from the editor.

Returns​

void

Inherited from​

LexicalEditor.blur

dispatchCommand()​

dispatchCommand<TCommand>(type, payload): boolean

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

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

Parameters​
type​

TCommand

the type of command listeners to trigger.

payload​

CommandPayloadType<TCommand>

the data to pass as an argument to the command listeners.

Returns​

boolean

Inherited from​

LexicalEditor.dispatchCommand

focus()​

focus(callbackFn?, options?): void

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

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

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

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

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

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

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

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

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

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

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

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

read<T>(callbackFn): T

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

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. Any pending updates will be flushed immediately before the read.

Type Parameters​
T​

T

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

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

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

Registers a listener for 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:1228

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The name of the Extension, must be unique

namespace?​

optional namespace?: string

Defined in: packages/lexical/src/extension-core/types.ts:379

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

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

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

parentEditor?​

optional parentEditor?: LexicalEditor

Defined in: packages/lexical/src/extension-core/types.ts:373

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

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

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

EditorThemeClasses that will be deep merged with other Extensions

Inherited from​

InitialEditorConfig.theme


LexicalExtensionDependency​

Defined in: packages/lexical/src/extension-core/types.ts:152

Type Parameters​

Dependency​

Dependency extends AnyLexicalExtension

Properties​

config​

config: LexicalExtensionConfig<Dependency>

Defined in: packages/lexical/src/extension-core/types.ts:156

init​

init: LexicalExtensionInit<Dependency>

Defined in: packages/lexical/src/extension-core/types.ts:155

output​

output: LexicalExtensionOutput<Dependency>

Defined in: packages/lexical/src/extension-core/types.ts:157


LexicalNode​

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

Extended by​

Methods​

$config()​

$config(): BaseStaticNodeConfig

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

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

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

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

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

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

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

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

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

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

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

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.

getIndexWithinParent()​

getIndexWithinParent(): number

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

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

Returns​

number

getKey()​

getKey(): string

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

Returns this nodes key.

Returns​

string

getLatest()​

getLatest(): this

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

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

getNextSibling<T>(): T | null

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

Returns the "next" siblings - that is, the node that comes after this one in the same parent

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

getNextSiblings()​

getNextSiblings<T>(): T[]

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

Returns all "next" siblings - that is, the nodes that come between this one and the last child of it's parent, inclusive.

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

getNodesBetween()​

getNodesBetween(targetNode): LexicalNode[]

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

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

getParent<T>(): T | null

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

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

Type Parameters​
T​

T extends ElementNode

Returns​

T | null

getParentKeys()​

getParentKeys(): string[]

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

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

Returns​

string[]

getParentOrThrow()​

getParentOrThrow<T>(): T

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

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

Type Parameters​
T​

T extends ElementNode

Returns​

T

getParents()​

getParents(): ElementNode[]

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

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

Returns​

ElementNode[]

getPreviousSibling()​

getPreviousSibling<T>(): T | null

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

Returns the "previous" siblings - that is, the node that comes before this one in the same parent.

Type Parameters​
T​

T extends LexicalNode

Returns​

T | null

getPreviousSiblings()​

getPreviousSiblings<T>(): T[]

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

Returns the "previous" siblings - that is, the nodes that come between this one and the first child of it's parent, inclusive.

Type Parameters​
T​

T extends LexicalNode

Returns​

T[]

getTextContent()​

getTextContent(): string

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

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

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

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

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

Returns the string type of this node.

Returns​

string

getWritable()​

getWritable(): this

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

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

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

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

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

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

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

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

Returns​

boolean

isParentOf()​

isParentOf(targetNode): boolean

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

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

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

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

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

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

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

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

Reset state in this copy of originalNode, if necessary

Parameters​
originalNode​

this

Returns​

void

selectEnd()​

selectEnd(): RangeSelection

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

Returns​

RangeSelection

selectNext()​

selectNext(anchorOffset?, focusOffset?): RangeSelection

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

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

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

Returns​

RangeSelection

updateDOM()​

updateDOM(_prevNode, _dom, _config): boolean

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

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

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

Implements​

Properties​

_cachedNodes​

_cachedNodes: LexicalNode[] | null

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

Implementation of​

BaseSelection._cachedNodes

_nodes​

_nodes: Set<string>

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

dirty​

dirty: boolean

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

Implementation of​

BaseSelection.dirty

Methods​

add()​

add(key): void

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

Parameters​
key​

string

Returns​

void

clear()​

clear(): void

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

Returns​

void

clone()​

clone(): NodeSelection

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

Returns​

NodeSelection

Implementation of​

BaseSelection.clone

delete()​

delete(key): void

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

Parameters​
key​

string

Returns​

void

deleteNodes()​

deleteNodes(): void

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

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

Returns​

LexicalNode[]

Implementation of​

BaseSelection.extract

getCachedNodes()​

getCachedNodes(): LexicalNode[] | null

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

Returns​

LexicalNode[] | null

Implementation of​

BaseSelection.getCachedNodes

getNodes()​

getNodes(): LexicalNode[]

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

Returns​

LexicalNode[]

Implementation of​

BaseSelection.getNodes

getStartEndPoints()​

getStartEndPoints(): null

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

Returns​

null

Implementation of​

BaseSelection.getStartEndPoints

getTextContent()​

getTextContent(): string

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

Returns​

string

Implementation of​

BaseSelection.getTextContent

has()​

has(key): boolean

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

Parameters​
key​

string

Returns​

boolean

insertNodes()​

insertNodes(nodes): void

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

Parameters​
nodes​

LexicalNode[]

Returns​

void

Implementation of​

BaseSelection.insertNodes

insertRawText()​

insertRawText(text): void

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

Parameters​
text​

string

Returns​

void

Implementation of​

BaseSelection.insertRawText

insertText()​

insertText(): void

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

Returns​

void

Implementation of​

BaseSelection.insertText

is()​

is(selection): boolean

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

Parameters​
selection​

BaseSelection | null

Returns​

boolean

Implementation of​

BaseSelection.is

isBackward()​

isBackward(): boolean

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

Returns​

boolean

Implementation of​

BaseSelection.isBackward

isCollapsed()​

isCollapsed(): boolean

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

Returns​

boolean

Implementation of​

BaseSelection.isCollapsed

setCachedNodes()​

setCachedNodes(nodes): void

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

Parameters​
nodes​

LexicalNode[] | null

Returns​

void

Implementation of​

BaseSelection.setCachedNodes


Point​

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

Properties​

_selection​

_selection: BaseSelection | null

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

key​

key: string

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

offset​

offset: number

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

type​

type: "element" | "text"

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

Methods​

getNode()​

getNode(): LexicalNode

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

Returns​

LexicalNode

is()​

is(point): boolean

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

Parameters​
point​

PointType

Returns​

boolean

isBefore()​

isBefore(b): boolean

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

Parameters​
b​

PointType

Returns​

boolean

set()​

set(key, offset, type, onlyIfChanged?): void

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

Parameters​
key​

string

offset​

number

type​

"element" | "text"

onlyIfChanged?​

boolean

Returns​

void


RangeSelection​

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

Implements​

Properties​

_cachedNodes​

_cachedNodes: LexicalNode[] | null

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

Implementation of​

BaseSelection._cachedNodes

anchor​

anchor: PointType

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

dirty​

dirty: boolean

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

Implementation of​

BaseSelection.dirty

focus​

focus: PointType

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

format​

format: number

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

style​

style: string

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

Methods​

applyDOMRange()​

applyDOMRange(range): void

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

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

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

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

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

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

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

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

Helper for handling forward character and word deletion that prevents element nodes like a table, columns layout being destroyed

Parameters​
anchor​

PointType

the anchor

anchorNode​

ElementNode | TextNode

the anchor node in the selection

isBackward​

boolean

whether or not selection is backwards

Returns​

boolean

getCachedNodes()​

getCachedNodes(): LexicalNode[] | null

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

Returns​

LexicalNode[] | null

Implementation of​

BaseSelection.getCachedNodes

getNodes()​

getNodes(): LexicalNode[]

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

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

Returns​

[PointType, PointType]

Implementation of​

BaseSelection.getStartEndPoints

getTextContent()​

getTextContent(): string

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

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

Returns whether the provided TextFormatType is present on the Selection. This will be true if any node in the Selection has the specified format.

Parameters​
type​

TextFormatType

the TextFormatType to check for.

Returns​

boolean

true if the provided format is currently toggled on on the Selection, false otherwise.

insertLineBreak()​

insertLineBreak(selectStart?): void

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

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

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

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

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

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

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

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

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

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

Removes the text in the Selection, adjusting the EditorState accordingly.

Returns​

void

setCachedNodes()​

setCachedNodes(nodes): void

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

Parameters​
nodes​

LexicalNode[] | null

Returns​

void

Implementation of​

BaseSelection.setCachedNodes

setFormat()​

setFormat(format): void

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

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

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

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

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


SerializedEditorState​

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

Type Parameters​

T​

T extends SerializedLexicalNode = SerializedLexicalNode

Properties​

root​

root: SerializedRootNode<T>

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


SiblingCaret​

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


SplitAtPointCaretNextOptions​

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:669

Properties​

$copyElementNode?​

optional $copyElementNode?: (node) => ElementNode

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:671

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

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

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

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

If the parent matches rootMode a split will not occur, default is 'shadowRoot'


StateConfig​

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

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

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

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

The string key used when serializing this state to JSON

parse​

readonly parse: (value?) => V

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

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

unparse​

readonly unparse: (value) => unknown

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

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

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

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

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

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

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

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

Properties​

$importJSON?​

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

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

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

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

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

An alternative to the static importDOM() method

stateConfigs?​

readonly optional stateConfigs?: readonly RequiredNodeStateConfig[]

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

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

The exact type of T.getType(), e.g. 'text' - the method itself must have a more generic 'string' type to be compatible wtih subclassing.


StepwiseIteratorConfig​

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

Type Parameters​

State​

State

Stop​

Stop

Value​

Value

Properties​

hasNext​

readonly hasNext: (value) => value is State

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

Parameters​
value​

State | Stop

Returns​

value is State

initial​

readonly initial: State | Stop

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

map​

readonly map: (value) => Value

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

Parameters​
value​

State

Returns​

Value

step​

readonly step: (value) => State | Stop

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

Parameters​
value​

State

Returns​

State | Stop


TextPointCaret​

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

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

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

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

A TextPointCaret can not have a ChildCaret.

Returns​

null

getFlipped​

getFlipped: () => TextPointCaret<T, FlipDirection<D>>

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

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

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

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

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

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

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

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

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

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

The offset into the string

origin​

readonly origin: T

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

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

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

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

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

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

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

distance​

readonly distance: number

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

getSliceIndices​

getSliceIndices: () => [number, number]

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

Returns​

[number, number]

absolute coordinates into the text (for use with text.slice(...))

getTextContent​

getTextContent: () => string

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

Returns​

string

The text represented by the slice

getTextContentSize​

getTextContentSize: () => number

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

Returns​

number

The size of the text represented by the slice

type​

readonly type: "slice"

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

Methods​

removeTextSlice()​

removeTextSlice(): TextPointCaret<T, D>

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

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

The payload passed to an UpdateListener

Properties​

dirtyElements​

dirtyElements: Map<string, boolean>

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

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

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

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

mutatedNodes​

mutatedNodes: MutatedNodes | null

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

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

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

The previous EditorState that is being discarded

tags​

tags: Set<string>

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

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​

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

Any NormalizedLexicalExtensionArgument


AnyStateConfig​

AnyStateConfig = StateConfig<any, any>

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

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]?: StaticNodeConfigValue<LexicalNode, string> }

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

This is the type of LexicalNode.$config() that can be overridden by subclasses.


CaretDirection​

CaretDirection = "next" | "previous"

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

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

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

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


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


CommandPayloadType​

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

Defined in: packages/lexical/src/LexicalEditor.ts:538

Type helper for extracting the payload type from a command.

Type Parameters​

TCommand​

TCommand extends LexicalCommand<unknown>

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:1333

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:377

Parameters​

lexicalNode​

LexicalNode

parentLexicalNode​

LexicalNode | null | undefined

Returns​

LexicalNode | null | undefined


DOMConversion​

DOMConversion<T> = object

Defined in: packages/lexical/src/LexicalNode.ts:368

Type Parameters​

T​

T extends HTMLElement = HTMLElement

Properties​

conversion​

conversion: DOMConversionFn<T>

Defined in: packages/lexical/src/LexicalNode.ts:369

priority?​

optional priority?: 0 | 1 | 2 | 3 | 4

Defined in: packages/lexical/src/LexicalNode.ts:370


DOMConversionFn​

DOMConversionFn<T> = (element) => DOMConversionOutput | null

Defined in: packages/lexical/src/LexicalNode.ts:373

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:382

Type Parameters​

T​

T extends HTMLElement = HTMLElement


DOMConversionOutput​

DOMConversionOutput = object

Defined in: packages/lexical/src/LexicalNode.ts:388

Properties​

after?​

optional after?: (childLexicalNodes) => LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:389

Parameters​
childLexicalNodes​

LexicalNode[]

Returns​

LexicalNode[]

forChild?​

optional forChild?: DOMChildConversion

Defined in: packages/lexical/src/LexicalNode.ts:390

node​

node: null | LexicalNode | LexicalNode[]

Defined in: packages/lexical/src/LexicalNode.ts:391


DOMConversionProp​

DOMConversionProp<T> = (node) => DOMConversion<T> | null

Defined in: packages/lexical/src/LexicalNode.ts:345

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:349

Type Parameters​

K​

K extends string


DOMConversionTagNameMap​

DOMConversionTagNameMap<K> = { [NodeName in K]?: DOMConversionPropByTagName<NodeName> }

Defined in: packages/lexical/src/LexicalNode.ts:353

Type Parameters​

K​

K extends string


DOMExportOutputMap​

DOMExportOutputMap = Map<Klass<LexicalNode>, (editor, target) => DOMExportOutput>

Defined in: packages/lexical/src/LexicalNode.ts:394


EditableListener​

EditableListener = (editable) => void | (() => void)

Defined in: packages/lexical/src/LexicalEditor.ts:454

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)


EditorSetOptions​

EditorSetOptions = object

Defined in: packages/lexical/src/LexicalEditor.ts:131

Properties​

tag?​

optional tag?: string

Defined in: packages/lexical/src/LexicalEditor.ts:132


EditorThemeClassName​

EditorThemeClassName = string

Defined in: packages/lexical/src/LexicalEditor.ts:87


EditorUpdateOptions​

EditorUpdateOptions = object

Defined in: packages/lexical/src/LexicalEditor.ts:106

Properties​

discrete?​

optional discrete?: true

Defined in: packages/lexical/src/LexicalEditor.ts:126

If true, prevents this update from being batched, forcing it to run synchronously.

onUpdate?​

optional onUpdate?: () => void

Defined in: packages/lexical/src/LexicalEditor.ts:110

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:116

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:121

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:69


ElementPoint​

ElementPoint = object

Defined in: packages/lexical/src/LexicalSelection.ts:115

Properties​

_selection​

_selection: BaseSelection

Defined in: packages/lexical/src/LexicalSelection.ts:116

getNode​

getNode: () => ElementNode

Defined in: packages/lexical/src/LexicalSelection.ts:117

Returns​

ElementNode

is​

is: (point) => boolean

Defined in: packages/lexical/src/LexicalSelection.ts:118

Parameters​
point​

PointType

Returns​

boolean

isBefore​

isBefore: (point) => boolean

Defined in: packages/lexical/src/LexicalSelection.ts:119

Parameters​
point​

PointType

Returns​

boolean

key​

key: NodeKey

Defined in: packages/lexical/src/LexicalSelection.ts:120

offset​

offset: number

Defined in: packages/lexical/src/LexicalSelection.ts:121

set​

set: (key, offset, type, onlyIfChanged?) => void

Defined in: packages/lexical/src/LexicalSelection.ts:122

Parameters​
key​

NodeKey

offset​

number

type​

"text" | "element"

onlyIfChanged?​

boolean

Returns​

void

type​

type: "element"

Defined in: packages/lexical/src/LexicalSelection.ts:128


EventHandler​

EventHandler = (event, editor) => void

Defined in: packages/lexical/src/LexicalEvents.ts:1525

Parameters​

event​

Event

editor​

LexicalEditor

Returns​

void


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:26

A type utility to flip next and previous

Type Parameters​

D​

D extends CaretDirection


HTMLConfig​

HTMLConfig = object

Defined in: packages/lexical/src/LexicalEditor.ts:251

Properties​

export?​

optional export?: DOMExportOutputMap

Defined in: packages/lexical/src/LexicalEditor.ts:252

import?​

optional import?: DOMConversionMap

Defined in: packages/lexical/src/LexicalEditor.ts:253


InitialEditorStateType​

InitialEditorStateType = null | string | EditorState | ((editor) => void)

Defined in: packages/lexical/src/extension-core/types.ts:355

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

Klass​

Klass<T> = InstanceType<T["constructor"]> extends T ? T["constructor"] : GenericConstructor<T> & T["constructor"]

Defined in: packages/lexical/src/LexicalEditor.ts:82

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:77

Type Parameters​

Cls​

Cls extends GenericConstructor<any>


LexicalCommand​

LexicalCommand<TPayload> = object

Defined in: packages/lexical/src/LexicalEditor.ts:514

Type Parameters​

TPayload​

TPayload

Properties​

type?​

optional type?: string

Defined in: packages/lexical/src/LexicalEditor.ts:515


LexicalExportJSON​

LexicalExportJSON<T> = Prettify<Omit<ReturnType<T["exportJSON"]>, "type"> & object & NodeStateJSON<T>>

Defined in: packages/lexical/src/LexicalNode.ts:228

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:143

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:296

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:314

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:302

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:308

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:259

A LexicalNode class or LexicalNodeReplacement configuration


LexicalNodeReplacement​

LexicalNodeReplacement = object

Defined in: packages/lexical/src/LexicalEditor.ts:227

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:231

The core node class whose instances should be replaced.

with​

with: <T>(node) => LexicalNode

Defined in: packages/lexical/src/LexicalEditor.ts:238

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:248

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:237

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:438

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:151

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:432


NodeMap​

NodeMap = Map<NodeKey, LexicalNode>

Defined in: packages/lexical/src/LexicalNode.ts:69


NodeMutation​

NodeMutation = "created" | "updated" | "destroyed"

Defined in: packages/lexical/src/LexicalEditor.ts:350


NodeStateJSON​

NodeStateJSON<T> = Prettify<object & CollectStateJSON<GetNodeStateConfig<T>, true>>

Defined in: packages/lexical/src/LexicalNodeState.ts:142

The NodeState JSON produced by this LexicalNode

Type Parameters​

T​

T extends LexicalNode


NormalizedLexicalExtensionArgument​

NormalizedLexicalExtensionArgument<Config, Name, Output, Init> = [LexicalExtension<Config, Name, Output, Init>, ...Partial<Config>[]]

Defined in: packages/lexical/src/extension-core/types.ts:45

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>> | undefined] & object

Defined in: packages/lexical/src/extension-core/types.ts:37

The result of declarePeerDependency, a tuple of a peer dependency name and its associated configuration.

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:320

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:327

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:167

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:131


RootListener​

RootListener = (rootElement, prevRootElement) => void | (() => void)

Defined in: packages/lexical/src/LexicalEditor.ts:431

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:39

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:585

Properties​

editorState​

editorState: SerializedEditorState

Defined in: packages/lexical/src/LexicalEditor.ts:586


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:55

Type Parameters​

T​

T extends SerializedLexicalNode = SerializedLexicalNode


SerializedLexicalNode​

SerializedLexicalNode = object

Defined in: packages/lexical/src/LexicalNode.ts:74

The base type for all serialized nodes

Properties​

$?​

optional $?: Record<string, unknown>

Defined in: packages/lexical/src/LexicalNode.ts:83

Any state persisted with the NodeState API that is not configured for flat storage

type​

type: string

Defined in: packages/lexical/src/LexicalNode.ts:76

The type string used by the Node class

version​

version: number

Defined in: packages/lexical/src/LexicalNode.ts:78

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:24


SerializedParagraphNode​

SerializedParagraphNode = Spread<{ textFormat: number; textStyle: string; }, SerializedElementNode>

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:39


SerializedRootNode​

SerializedRootNode<T> = SerializedElementNode<T>

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:20

Type Parameters​

T​

T extends SerializedLexicalNode = SerializedLexicalNode


SerializedTabNode​

SerializedTabNode = SerializedTextNode

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:25


SerializedTextNode​

SerializedTextNode = Spread<{ detail: number; format: number; mode: TextModeType; style: string; text: string; }, SerializedLexicalNode>

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:78


Spread​

Spread<T1, T2> = Omit<T2, keyof T1> & T1

Defined in: packages/lexical/src/LexicalEditor.ts:73

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:34

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:29

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:57

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:178

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:99

Properties​

_selection​

_selection: BaseSelection

Defined in: packages/lexical/src/LexicalSelection.ts:100

getNode​

getNode: () => TextNode

Defined in: packages/lexical/src/LexicalSelection.ts:101

Returns​

TextNode

is​

is: (point) => boolean

Defined in: packages/lexical/src/LexicalSelection.ts:102

Parameters​
point​

PointType

Returns​

boolean

isBefore​

isBefore: (point) => boolean

Defined in: packages/lexical/src/LexicalSelection.ts:103

Parameters​
point​

PointType

Returns​

boolean

key​

key: NodeKey

Defined in: packages/lexical/src/LexicalSelection.ts:104

offset​

offset: number

Defined in: packages/lexical/src/LexicalSelection.ts:105

set​

set: (key, offset, type, onlyIfChanged?) => void

Defined in: packages/lexical/src/LexicalSelection.ts:106

Parameters​
key​

NodeKey

offset​

number

type​

"text" | "element"

onlyIfChanged?​

boolean

Returns​

void

type​

type: "text"

Defined in: packages/lexical/src/LexicalSelection.ts:112


TextPointCaretSliceTuple​

TextPointCaretSliceTuple<D> = readonly [null | TextPointCaretSlice<TextNode, D>, null | TextPointCaretSlice<TextNode, D>]

Defined in: packages/lexical/src/caret/LexicalCaret.ts:372

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:342

Type Parameters​

T​

T extends LexicalNode

Parameters​

node​

T

Returns​

void


UpdateListener​

UpdateListener = (payload) => void

Defined in: packages/lexical/src/LexicalEditor.ts:420

A listener that gets called after the editor is updated

Parameters​

payload​

UpdateListenerPayload

Returns​

void


UpdateTag​

UpdateTag = typeof COLLABORATION_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:79

The set of known update tags to help with TypeScript suggestions.


ValueOrUpdater​

ValueOrUpdater<V> = V | ((prevValue) => V)

Defined in: packages/lexical/src/LexicalNodeState.ts:41

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:2349

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​

The node where the search starts.

Param​

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:40


BLUR_COMMAND​

const BLUR_COMMAND: LexicalCommand<FocusEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:231


CAN_REDO_COMMAND​

const CAN_REDO_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:225


CAN_UNDO_COMMAND​

const CAN_UNDO_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:227


CLEAR_EDITOR_COMMAND​

const CLEAR_EDITOR_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:219


CLEAR_HISTORY_COMMAND​

const CLEAR_HISTORY_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:222


CLICK_COMMAND​

const CLICK_COMMAND: LexicalCommand<MouseEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:38


COLLABORATION_TAG​

const COLLABORATION_TAG: "collaboration" = 'collaboration'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:37

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:503

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:487

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:499

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:491

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:495

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:483

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:467

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:479

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:471

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:475

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:47


COMPOSITION_END_TAG​

const COMPOSITION_END_TAG: "composition-end" = 'composition-end'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:74

The update was triggered by composition-end


COMPOSITION_START_COMMAND​

const COMPOSITION_START_COMMAND: LexicalCommand<CompositionEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:45


COMPOSITION_START_TAG​

const COMPOSITION_START_TAG: "composition-start" = 'composition-start'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:69

The update was triggered by composition-start


CONTROLLED_TEXT_INSERTION_COMMAND​

const CONTROLLED_TEXT_INSERTION_COMMAND: LexicalCommand<InputEvent | string>

Defined in: packages/lexical/src/LexicalCommands.ts:68


COPY_COMMAND​

const COPY_COMMAND: LexicalCommand<ClipboardEvent | KeyboardEvent | null>

Defined in: packages/lexical/src/LexicalCommands.ts:203

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:210

Dispatched on a cut event, either via the clipboard or a KeyboardEvent (Cmd+X on macOS, Ctrl+X elsewhere).


DELETE_CHARACTER_COMMAND​

const DELETE_CHARACTER_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:54

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:88

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:80

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:197


DRAGOVER_COMMAND​

const DRAGOVER_COMMAND: LexicalCommand<DragEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:195


DRAGSTART_COMMAND​

const DRAGSTART_COMMAND: LexicalCommand<DragEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:193


DROP_COMMAND​

const DROP_COMMAND: LexicalCommand<DragEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:189


FOCUS_COMMAND​

const FOCUS_COMMAND: LexicalCommand<FocusEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:229


FORMAT_ELEMENT_COMMAND​

const FORMAT_ELEMENT_COMMAND: LexicalCommand<ElementFormatType>

Defined in: packages/lexical/src/LexicalCommands.ts:191


FORMAT_TEXT_COMMAND​

const FORMAT_TEXT_COMMAND: LexicalCommand<TextFormatType>

Defined in: packages/lexical/src/LexicalCommands.ts:94

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:183


INPUT_COMMAND​

const INPUT_COMMAND: LexicalCommand<InputEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:43


INSERT_LINE_BREAK_COMMAND​

const INSERT_LINE_BREAK_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical/src/LexicalCommands.ts:62

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:65


INSERT_TAB_COMMAND​

const INSERT_TAB_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:181


IS_ALL_FORMATTING​

const IS_ALL_FORMATTING: number

Defined in: packages/lexical/src/LexicalConstants.ts:53


IS_BOLD​

const IS_BOLD: 1 = 1

Defined in: packages/lexical/src/LexicalConstants.ts:41


IS_CODE​

const IS_CODE: number

Defined in: packages/lexical/src/LexicalConstants.ts:45


IS_HIGHLIGHT​

const IS_HIGHLIGHT: number

Defined in: packages/lexical/src/LexicalConstants.ts:48


IS_ITALIC​

const IS_ITALIC: number

Defined in: packages/lexical/src/LexicalConstants.ts:42


IS_STRIKETHROUGH​

const IS_STRIKETHROUGH: number

Defined in: packages/lexical/src/LexicalConstants.ts:43


IS_SUBSCRIPT​

const IS_SUBSCRIPT: number

Defined in: packages/lexical/src/LexicalConstants.ts:46


IS_SUPERSCRIPT​

const IS_SUPERSCRIPT: number

Defined in: packages/lexical/src/LexicalConstants.ts:47


IS_UNDERLINE​

const IS_UNDERLINE: number

Defined in: packages/lexical/src/LexicalConstants.ts:44


KEY_ARROW_DOWN_COMMAND​

const KEY_ARROW_DOWN_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:143

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:125

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:113

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:137

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:162

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:173

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:107

Dispatched when any key is pressed.


KEY_ENTER_COMMAND​

const KEY_ENTER_COMMAND: LexicalCommand<KeyboardEvent | null>

Defined in: packages/lexical/src/LexicalCommands.ts:150

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:168

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:239

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:156

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:179

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:119

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:131

Dispatched when the move to start keyboard shortcut is pressed, (Cmd+Left on macOS; Ctrl+Left elsewhere).


NODE_STATE_KEY​

const NODE_STATE_KEY: "$" = '$'

Defined in: packages/lexical/src/LexicalConstants.ts:158


OUTDENT_CONTENT_COMMAND​

const OUTDENT_CONTENT_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:186


PASTE_COMMAND​

const PASTE_COMMAND: LexicalCommand<PasteCommandType>

Defined in: packages/lexical/src/LexicalCommands.ts:71


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:103

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:73


SELECT_ALL_COMMAND​

const SELECT_ALL_COMMAND: LexicalCommand<KeyboardEvent>

Defined in: packages/lexical/src/LexicalCommands.ts:217

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:31


SELECTION_INSERT_CLIPBOARD_NODES_COMMAND​

const SELECTION_INSERT_CLIPBOARD_NODES_COMMAND: LexicalCommand<{ nodes: LexicalNode[]; selection: BaseSelection; }>

Defined in: packages/lexical/src/LexicalCommands.ts:34


SKIP_COLLAB_TAG​

const SKIP_COLLAB_TAG: "skip-collab" = 'skip-collab'

Defined in: packages/lexical/src/LexicalUpdateTags.ts:42

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:53

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


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:47

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:59

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:106


UNDO_COMMAND​

const UNDO_COMMAND: LexicalCommand<void>

Defined in: packages/lexical/src/LexicalCommands.ts:99

Dispatched on undo (Cmd+Z on macOS, Ctrl+Z elsewhere).

Functions​

$addUpdateTag()​

$addUpdateTag(tag): void

Defined in: packages/lexical/src/LexicalUtils.ts:1502

Parameters​

tag​

UpdateTag

Returns​

void


$applyNodeReplacement()​

$applyNodeReplacement<N>(node): N

Defined in: packages/lexical/src/LexicalUtils.ts:1632

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:61

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:156

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:2062

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:2097

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:1230

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:1619

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:2332

Create an node from its class.

Note that this will directly construct the final withKlass node type, and will ignore the deprecated with functions. This allows $create to skip any intermediate steps where the replaced node would be created and then immediately discarded (once per configured replacement of that node).

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:2375

Parameters​

element​

ElementNode

nodeMap​

NodeMap | null

Returns​

string[]


$createLineBreakNode()​

$createLineBreakNode(): LineBreakNode

Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:83

Returns​

LineBreakNode


$createNodeSelection()​

$createNodeSelection(): NodeSelection

Defined in: packages/lexical/src/LexicalSelection.ts:2624

Returns​

NodeSelection


$createParagraphNode()​

$createParagraphNode(): ParagraphNode

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:189

Returns​

ParagraphNode


$createPoint()​

$createPoint(key, offset, type): PointType

Defined in: packages/lexical/src/LexicalSelection.ts:224

Parameters​

key​

string

offset​

number

type​

"element" | "text"

Returns​

PointType


$createRangeSelection()​

$createRangeSelection(): RangeSelection

Defined in: packages/lexical/src/LexicalSelection.ts:2618

Returns​

RangeSelection


$createRangeSelectionFromDom()​

$createRangeSelectionFromDom(domSelection, editor): RangeSelection | null

Defined in: packages/lexical/src/LexicalSelection.ts:2647

Parameters​

domSelection​

Selection | null

editor​

LexicalEditor

Returns​

RangeSelection | null


$createTabNode()​

$createTabNode(): TabNode

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:102

Returns​

TabNode


$createTextNode()​

$createTextNode(text?): TextNode

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1376

Parameters​

text?​

string = ''

Returns​

TextNode


$extendCaretToRange()​

$extendCaretToRange<D>(anchor): CaretRange<D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:1128

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>


$getAdjacentChildCaret()​

$getAdjacentChildCaret<D>(caret): NodeCaret<D> | null

Defined in: packages/lexical/src/caret/LexicalCaret.ts:977

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:1340

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:603

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/LexicalCaretUtils.ts:526

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:1157

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:555

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:2025

Parameters​

selection​

BaseSelection

Returns​

[number, number]


$getChildCaret()​

$getChildCaret<T, D>(origin, direction): ChildCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:950

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:577

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:964

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:1137

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:1368

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:1273

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


$getEditor()​

$getEditor(): LexicalEditor

Defined in: packages/lexical/src/LexicalUtils.ts:1990

Utility function for accessing current active editor instance.

Returns​

LexicalEditor

Current active editor


$getNearestNodeFromDOMNode()​

$getNearestNodeFromDOMNode(startingDOM, editorState?): LexicalNode | null

Defined in: packages/lexical/src/LexicalUtils.ts:566

Parameters​

startingDOM​

Node

editorState?​

EditorState

Returns​

LexicalNode | null


$getNearestRootOrShadowRoot()​

$getNearestRootOrShadowRoot(node): ElementNode | RootNode

Defined in: packages/lexical/src/LexicalUtils.ts:1582

Parameters​

node​

LexicalNode

Returns​

ElementNode | RootNode


$getNodeByKey()​

$getNodeByKey<T>(key, _editorState?): T | null

Defined in: packages/lexical/src/LexicalUtils.ts:525

Type Parameters​

T​

T extends LexicalNode

Parameters​

key​

string

_editorState?​

EditorState

Returns​

T | null


$getNodeByKeyOrThrow()​

$getNodeByKeyOrThrow<N>(key): N

Defined in: packages/lexical/src/LexicalUtils.ts:1698

Type Parameters​

N​

N extends LexicalNode

Parameters​

key​

string

Returns​

N


$getNodeFromDOMNode()​

$getNodeFromDOMNode(dom, editorState?): LexicalNode | null

Defined in: packages/lexical/src/LexicalUtils.ts:537

Parameters​

dom​

Node

editorState?​

EditorState

Returns​

LexicalNode | null


$getPreviousSelection()​

$getPreviousSelection(): BaseSelection | null

Defined in: packages/lexical/src/LexicalSelection.ts:2798

Returns​

BaseSelection | null


$getRoot()​

$getRoot(): RootNode

Defined in: packages/lexical/src/LexicalUtils.ts:634

Returns​

RootNode


$getSelection()​

$getSelection(): BaseSelection | null

Defined in: packages/lexical/src/LexicalSelection.ts:2793

Returns​

BaseSelection | null


$getSiblingCaret()​

Call Signature​

$getSiblingCaret<T, D>(origin, direction): SiblingCaret<T, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:843

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:847

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


$getState()​

$getState<K, V>(node, stateConfig, version?): V

Defined in: packages/lexical/src/LexicalNodeState.ts:331

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 '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 'direct' to read the state from a previous version of the node.

For very advanced use cases, you can expect that '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?​

"latest" | "direct"

The default value 'latest' will read the latest version of the 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:359

Given two versions of a node and a stateConfig, compare their state values using $getState(nodeVersion, stateConfig, '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 '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:3245

Returns​

string


$getTextNodeOffset()​

$getTextNodeOffset(origin, offset, mode?): number

Defined in: packages/lexical/src/caret/LexicalCaret.ts:902

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:866

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:874

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:935

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:1540

Parameters​

child​

LexicalNode

targetNode​

LexicalNode

Returns​

boolean


$hasUpdateTag()​

$hasUpdateTag(tag): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:1497

Parameters​

tag​

UpdateTag

Returns​

boolean


$insertNodes()​

$insertNodes(nodes): void

Defined in: packages/lexical/src/LexicalSelection.ts:3236

Parameters​

nodes​

LexicalNode[]

Returns​

void


$isBlockElementNode()​

$isBlockElementNode(node): node is ElementNode

Defined in: packages/lexical/src/LexicalSelection.ts:2588

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is ElementNode


$isChildCaret()​

$isChildCaret<D>(caret): caret is ChildCaret<ElementNode, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:759

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:47

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:102

Type guard that returns true if the argument is an EditorState

Parameters​

x​

unknown

Returns​

x is EditorState


$isElementNode()​

$isElementNode(node): node is ElementNode

Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1028

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:507

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:1569

Type Parameters​

T​

T

Parameters​

node​

LexicalNode

Returns​

node is (ElementNode | DecoratorNode<T>) & { [InlineNodeBrand]: never; isInline: any }


$isLeafNode()​

$isLeafNode(node): node is DecoratorNode<unknown> | TextNode | LineBreakNode

Defined in: packages/lexical/src/LexicalUtils.ts:303

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is DecoratorNode<unknown> | TextNode | LineBreakNode


$isLexicalNode()​

$isLexicalNode(node): node is LexicalNode

Defined in: packages/lexical/src/LexicalNode.ts:1689

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:87

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:735

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:2009

Parameters​

x​

unknown

Returns​

x is NodeSelection


$isParagraphNode()​

$isParagraphNode(node): node is ParagraphNode

Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:193

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is ParagraphNode


$isRangeSelection()​

$isRangeSelection(x): x is RangeSelection

Defined in: packages/lexical/src/LexicalSelection.ts:467

Parameters​

x​

unknown

Returns​

x is RangeSelection


$isRootNode()​

$isRootNode(node): node is RootNode

Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:113

Parameters​

node​

LexicalNode | RootNode | null | undefined

Returns​

node is RootNode


$isRootOrShadowRoot()​

$isRootOrShadowRoot(node): node is RootNode | ShadowRootNode

Defined in: packages/lexical/src/LexicalUtils.ts:1602

Parameters​

node​

LexicalNode | null

Returns​

node is RootNode | ShadowRootNode


$isSiblingCaret()​

$isSiblingCaret<D>(caret): caret is SiblingCaret<LexicalNode, D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:747

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


$isTabNode()​

$isTabNode(node): node is TabNode

Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:106

Parameters​

node​

LexicalNode | null | undefined

Returns​

node is TabNode


$isTextNode()​

$isTextNode(node): node is TextNode

Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1380

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:723

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:1114

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:242

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:235

Return true if the TextNode is a TabNode or is in token mode.

Parameters​

node​

TextNode

Returns​

boolean


$nodesOfType()​

$nodesOfType<T>(klass): T[]

Defined in: packages/lexical/src/LexicalUtils.ts:1297

Type Parameters​

T​

T extends LexicalNode

Parameters​

klass​

Klass<T>

Returns​

T[]

Deprecated​

Use LexicalEditor.registerMutationListener with skipInitialization: false instead.


$normalizeCaret()​

$normalizeCaret<D>(initialCaret): PointCaret<D>

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:482

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:95

Parameters​

selection​

RangeSelection

Returns​

RangeSelection


$onUpdate()​

$onUpdate(updateFn): void

Defined in: packages/lexical/src/LexicalUtils.ts:1515

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:357

Parameters​

serializedNode​

SerializedLexicalNode

Returns​

LexicalNode


$removeTextFromCaretRange()​

$removeTextFromCaretRange<D>(initialRange, sliceMode?): CaretRange<D>

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:232

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:183

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:1215

Parameters​

selection?​

RangeSelection | null

Returns​

RangeSelection


$setCompositionKey()​

$setCompositionKey(compositionKey): void

Defined in: packages/lexical/src/LexicalUtils.ts:496

Parameters​

compositionKey​

string | null

Returns​

void


$setDirectionFromDOM()​

$setDirectionFromDOM<T>(node, domNode): T

Defined in: packages/lexical/src/LexicalUtils.ts:2134

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:2153

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:91

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:642

Parameters​

selection​

BaseSelection | null

Returns​

void


$setSelectionFromCaretRange()​

$setSelectionFromCaretRange(caretRange): RangeSelection

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:127

Set a RangeSelection on the editor from the given CaretRange

Parameters​

caretRange​

CaretRange

Returns​

RangeSelection

The new RangeSelection


$setState()​

$setState<Node, K, V>(node, stateConfig, valueOrUpdater): Node

Defined in: packages/lexical/src/LexicalNodeState.ts:392

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);

$splitAtPointCaretNext()​

$splitAtPointCaretNext(pointCaret, __namedParameters?): NodeCaret<"next"> | null

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:701

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:1831

Parameters​

node​

ElementNode

offset​

number

Returns​

[ElementNode | null, ElementNode]


$updateRangeSelectionFromCaretRange()​

$updateRangeSelectionFromCaretRange(selection, caretRange): void

Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:142

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:362

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:91

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


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:761

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


createState()​

createState<K, V>(key, valueConfig): StateConfig<K, V>

Defined in: packages/lexical/src/LexicalNodeState.ts:305

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>(name, config?): NormalizedPeerDependency<Extension>

Defined in: packages/lexical/src/extension-core/defineExtension.ts:127

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​

name​

Extension["name"]

The extension's name

config?​

Partial<LexicalExtensionConfig<Extension>>

An optional config override

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


defineExtension()​

defineExtension<Config, Name, Output, Init>(extension): LexicalExtension<Config, Name, Output, Init>

Defined in: packages/lexical/src/extension-core/defineExtension.ts:54

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


flipDirection()​

flipDirection<D>(direction): FlipDirection<D>

Defined in: packages/lexical/src/caret/LexicalCaret.ts:580

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


getDOMOwnerDocument()​

getDOMOwnerDocument(target): Document | null

Defined in: packages/lexical/src/LexicalUtils.ts:1412

Parameters​

target​

EventTarget | null

Returns​

Document | null


getDOMSelection()​

getDOMSelection(targetWindow): Selection | null

Defined in: packages/lexical/src/LexicalUtils.ts:1814

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:1824

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


getDOMTextNode()​

getDOMTextNode(element): Text | null

Defined in: packages/lexical/src/LexicalUtils.ts:262

Parameters​

element​

Node | null

Returns​

Text | null


getNearestEditorFromDOMNode()​

getNearestEditorFromDOMNode(node): LexicalEditor | null

Defined in: packages/lexical/src/LexicalUtils.ts:202

Parameters​

node​

Node | null

Returns​

LexicalEditor | null


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:222

Parameters​

text​

string

Returns​

"ltr" | "rtl" | null


isBlockDomNode()​

isBlockDomNode(node): node is HTMLElement & { [BlockDOMBrand]: never }

Defined in: packages/lexical/src/LexicalUtils.ts:1943

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:79

Returns​

boolean


isDocumentFragment()​

isDocumentFragment(x): x is DocumentFragment

Defined in: packages/lexical/src/LexicalUtils.ts:1912

Parameters​

x​

unknown

The element being testing

Returns​

x is DocumentFragment

Returns true if x is a document fragment, false otherwise.


isDOMDocumentNode()​

isDOMDocumentNode(node): node is Document

Defined in: packages/lexical/src/LexicalUtils.ts:258

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:1899

Parameters​

x​

unknown

The element being tested

Returns​

x is Node

Returns true if x is a DOM Node, false otherwise.


isDOMTextNode()​

isDOMTextNode(node): node is Text

Defined in: packages/lexical/src/LexicalUtils.ts:250

Parameters​

node​

unknown

The element being tested

Returns​

node is Text

Returns true if node is an DOM Text node, false otherwise.


isExactShortcutMatch()​

isExactShortcutMatch(event, expectedKey, mask): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:1007

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:1883

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:1891

Parameters​

x​

unknown

The element being tested

Returns​

x is HTMLElement

Returns true if x is an HTML element, false otherwise.


isInlineDomNode()​

isInlineDomNode(node): node is (HTMLElement | Text) & { [InlineDOMBrand]: never }

Defined in: packages/lexical/src/LexicalUtils.ts:1924

Parameters​

node​

Node

the Dom Node to check

Returns​

node is (HTMLElement | Text) & { [InlineDOMBrand]: never }

if the Dom Node is an inline node


isLexicalEditor()​

isLexicalEditor(editor): editor is LexicalEditor

Defined in: packages/lexical/src/LexicalUtils.ts:197

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:987

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


isSelectionCapturedInDecoratorInput()​

isSelectionCapturedInDecoratorInput(anchorDOM): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:156

Parameters​

anchorDOM​

Node

Returns​

boolean


isSelectionWithinEditor()​

isSelectionWithinEditor(editor, anchorDOM, focusDOM): boolean

Defined in: packages/lexical/src/LexicalUtils.ts:173

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:1186

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.


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:109

Returns​

void


safeCast()​

safeCast<T>(value): T

Defined in: packages/lexical/src/extension-core/safeCast.ts:16

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


setDOMStyleFromCSS()​

setDOMStyleFromCSS(domStyle, cssText, prevCSSText?): void

Defined in: packages/lexical/src/utils/setDOMStyle.ts:182

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:161

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


setNodeIndentFromDOM()​

setNodeIndentFromDOM(elementDom, elementNode): void

Defined in: packages/lexical/src/LexicalUtils.ts:2103

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:273

Parameters​

format​

number

type​

TextFormatType

alignWithFormat​

number | null

Returns​

number