Skip to main content

@lexical/code

Classes

CodeHighlightNode

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:53

Extends

Constructors

Constructor

new CodeHighlightNode(text?, highlightType?, key?): CodeHighlightNode

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:67

Parameters
text?

string = ''

highlightType?

string | null

key?

string

Returns

CodeHighlightNode

Inherited from

TextNode.constructor

Properties

__text

__text: string

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

Inherited from

TextNode.__text

importDOM?

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

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

Returns

DOMConversionMap<any> | null

Inherited from

TextNode.importDOM

Methods

$config()

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

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:76

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

Returns

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

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

TextNode.$config

afterCloneFrom()

afterCloneFrom(prevNode): void

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

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

TextNode.afterCloneFrom

canHaveFormat()

canHaveFormat(): boolean

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:95

Returns

boolean

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

Inherited from

TextNode.canHaveFormat

canInsertTextAfter()

canInsertTextAfter(): boolean

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

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

Returns

boolean

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

Inherited from

TextNode.canInsertTextAfter

canInsertTextBefore()

canInsertTextBefore(): boolean

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

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

Returns

boolean

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

Inherited from

TextNode.canInsertTextBefore

config()
Call Signature

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

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

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

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

Type Parameters
Config

Config extends StaticNodeConfigValue<CodeHighlightNode, string>

Parameters
type

symbol

config

Config

Returns

AbstractStaticNodeConfigRecord<Config>

Inherited from

TextNode.config

Call Signature

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

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

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

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

Type Parameters
Type

Type extends string

Config

Config extends StaticNodeConfigValue<CodeHighlightNode, Type>

Parameters
type

Type

config

Config

Returns

StaticNodeConfigRecord<Type, Config>

Inherited from

TextNode.config

createDOM()

createDOM(config): HTMLElement

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:99

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

Inherited from

TextNode.createDOM

createParentElementNode()

createParentElementNode(): ElementNode

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:139

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

Returns

ElementNode

Inherited from

TextNode.createParentElementNode

exportDOM()

exportDOM(editor): DOMExportOutput

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

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

Parameters
editor

LexicalEditor

Returns

DOMExportOutput

Inherited from

TextNode.exportDOM

exportJSON()
Call Signature

exportJSON(compact?): SerializedCodeHighlightNode

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:54

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

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

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

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

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

Parameters
compact?

false

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

Returns

SerializedCodeHighlightNode

Inherited from

TextNode.exportJSON

Call Signature

exportJSON(compact): SerializedPartial<SerializedCodeHighlightNode>

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:55

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

Parameters
compact

boolean

Returns

SerializedPartial<SerializedCodeHighlightNode>

See

SerializedPartial

Inherited from

TextNode.exportJSON

getCommonAncestor()

getCommonAncestor<T>(node): T | null

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

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

TextNode.getCommonAncestor

getDetail()

getDetail(): number

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

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

Returns

number

a number representing the detail of the text node.

Inherited from

TextNode.getDetail

getDOMSlot()

getDOMSlot(element): DOMSlot<HTMLElement>

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

Experimental

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

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

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

Parameters
element

HTMLElement

Returns

DOMSlot<HTMLElement>

Inherited from

TextNode.getDOMSlot

getFormat()

getFormat(): number

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

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

Returns

number

a number representing the format of the text node.

Inherited from

TextNode.getFormat

getFormatFlags()

getFormatFlags(type, alignWithFormat): number

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

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

Parameters
type

TextFormatType

alignWithFormat

number | null

Returns

number

a number representing the TextFormatTypes applied to the node.

Inherited from

TextNode.getFormatFlags

getHighlightType()

getHighlightType(): string | null | undefined

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:84

Returns

string | null | undefined

getIndexWithinParent()

getIndexWithinParent(): number

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

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

Returns

number

Inherited from

TextNode.getIndexWithinParent

getKey()

getKey(): string

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

Returns this nodes key.

Returns

string

Inherited from

TextNode.getKey

getLatest()

getLatest(): this

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

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

TextNode.getLatest

getMode()

getMode(): TextModeType

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

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

Returns

TextModeType

TextModeType.

Inherited from

TextNode.getMode

getNextSibling()
Call Signature

getNextSibling(): LexicalNode | null

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

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

Returns

LexicalNode | null

Inherited from

TextNode.getNextSibling

Call Signature

getNextSibling<T>(): T | null

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

Type Parameters
T

T extends LexicalNode

Returns

T | null

Deprecated

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

Inherited from

TextNode.getNextSibling

getNextSiblings()
Call Signature

getNextSiblings(): LexicalNode[]

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

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

Returns

LexicalNode[]

Inherited from

TextNode.getNextSiblings

Call Signature

getNextSiblings<T>(): T[]

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

Type Parameters
T

T extends LexicalNode

Returns

T[]

Deprecated

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

Inherited from

TextNode.getNextSiblings

getNodesBetween()

getNodesBetween(targetNode): LexicalNode[]

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

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

TextNode.getNodesBetween

getParent()
Call Signature

getParent(): ElementNode | null

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

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

Returns

ElementNode | null

Inherited from

TextNode.getParent

Call Signature

getParent<T>(): T | null

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

Type Parameters
T

T extends ElementNode

Returns

T | null

Deprecated

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

Inherited from

TextNode.getParent

getParentKeys()

getParentKeys(): string[]

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

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

Returns

string[]

Inherited from

TextNode.getParentKeys

getParentOrThrow()
Call Signature

getParentOrThrow(): ElementNode

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

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

Returns

ElementNode

Inherited from

TextNode.getParentOrThrow

Call Signature

getParentOrThrow<T>(): T

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

Type Parameters
T

T extends ElementNode

Returns

T

Deprecated

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

Inherited from

TextNode.getParentOrThrow

getParents()

getParents(): ElementNode[]

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

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

Returns

ElementNode[]

Inherited from

TextNode.getParents

getPreviousSibling()
Call Signature

getPreviousSibling(): LexicalNode | null

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

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

Returns

LexicalNode | null

Inherited from

TextNode.getPreviousSibling

Call Signature

getPreviousSibling<T>(): T | null

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

Type Parameters
T

T extends LexicalNode

Returns

T | null

Deprecated

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

Inherited from

TextNode.getPreviousSibling

getPreviousSiblings()
Call Signature

getPreviousSiblings(): LexicalNode[]

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

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

Returns

LexicalNode[]

Inherited from

TextNode.getPreviousSiblings

Call Signature

getPreviousSiblings<T>(): T[]

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

Type Parameters
T

T extends LexicalNode

Returns

T[]

Deprecated

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

Inherited from

TextNode.getPreviousSiblings

getStyle()

getStyle(): string

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

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

Returns

string

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

Inherited from

TextNode.getStyle

getTextContent()

getTextContent(): string

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

Returns the text content of the node as a string.

Returns

string

a string representing the text content of the node.

Inherited from

TextNode.getTextContent

getTextContentSize()

getTextContentSize(): number

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

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

Returns

number

Inherited from

TextNode.getTextContentSize

getTopLevelElement()

getTopLevelElement(): ElementNode | null

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

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

Returns

ElementNode | null

Inherited from

TextNode.getTopLevelElement

getTopLevelElementOrThrow()

getTopLevelElementOrThrow(): ElementNode

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

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

Returns

ElementNode

Inherited from

TextNode.getTopLevelElementOrThrow

getType()

getType(): string

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

Returns the string type of this node.

Returns

string

Inherited from

TextNode.getType

getWritable()

getWritable(): this

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

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

TextNode.getWritable

hasFormat()

hasFormat(type): boolean

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

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

Parameters
type

TextFormatType

the TextFormatType to check for.

Returns

boolean

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

Inherited from

TextNode.hasFormat

insertAfter()

insertAfter(nodeToInsert, restoreSelection?): LexicalNode

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

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

TextNode.insertAfter

insertBefore()

insertBefore(nodeToInsert, restoreSelection?): LexicalNode

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

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

TextNode.insertBefore

is()

is(object): boolean

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

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

TextNode.is

isAttached()

isAttached(): boolean

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

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

TextNode.isAttached

isBefore()

isBefore(targetNode): boolean

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

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

TextNode.isBefore

isComposing()

isComposing(): boolean

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

Returns

boolean

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

Inherited from

TextNode.isComposing

isDirectionless()

isDirectionless(): boolean

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

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

Returns

boolean

true if the node is directionless, false otherwise.

Inherited from

TextNode.isDirectionless

isDirty()

isDirty(): boolean

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

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

Returns

boolean

Inherited from

TextNode.isDirty

isInline()

isInline(): true

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

Returns

true

true if the text node is inline, false otherwise.

Inherited from

TextNode.isInline

isParentOf()

isParentOf(targetNode): boolean

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

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

TextNode.isParentOf

isParentRequired()

isParentRequired(): true

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:135

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

true

Inherited from

TextNode.isParentRequired

isSegmented()

isSegmented(): boolean

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

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

Returns

boolean

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

Inherited from

TextNode.isSegmented

isSelected()

isSelected(selection?): boolean

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

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

TextNode.isSelected

isSimpleText()

isSimpleText(): boolean

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

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

Returns

boolean

true if the node is simple text, false otherwise.

Inherited from

TextNode.isSimpleText

isTextEntity()

isTextEntity(): boolean

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

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

Returns

boolean

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

Inherited from

TextNode.isTextEntity

isToken()

isToken(): boolean

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

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

Returns

boolean

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

Inherited from

TextNode.isToken

isUnmergeable()

isUnmergeable(): boolean

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

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

Returns

boolean

true if the node is unmergeable, false otherwise.

Inherited from

TextNode.isUnmergeable

markDirty()

markDirty(): void

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

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

Returns

void

Inherited from

TextNode.markDirty

mergeWithSibling()

mergeWithSibling(target): TextNode

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

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

Parameters
target

TextNode

the TextNode to merge into this one.

Returns

TextNode

this TextNode.

Inherited from

TextNode.mergeWithSibling

remove()

remove(preserveEmptyParent?): void

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

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

TextNode.remove

replace()

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

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

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

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

Type Parameters
N

N extends LexicalNode

Parameters
replaceWith

N

The node to replace this one with.

includeChildren?

boolean

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

Returns

N

Inherited from

TextNode.replace

resetOnCopyNodeFrom()

resetOnCopyNodeFrom(originalNode): void

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

Reset state in this copy of originalNode, if necessary

Parameters
originalNode

this

Returns

void

Inherited from

TextNode.resetOnCopyNodeFrom

select()

select(_anchorOffset?, _focusOffset?): RangeSelection

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

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

Parameters
_anchorOffset?

number

the offset at which the Selection anchor will be placed.

_focusOffset?

number

the offset at which the Selection focus will be placed.

Returns

RangeSelection

the new RangeSelection.

Inherited from

TextNode.select

selectEnd()

selectEnd(): RangeSelection

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

Returns

RangeSelection

Inherited from

TextNode.selectEnd

selectionTransform()

selectionTransform(prevSelection, nextSelection): void

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

Parameters
prevSelection

BaseSelection | null

nextSelection

RangeSelection

Returns

void

Inherited from

TextNode.selectionTransform

selectNext()

selectNext(anchorOffset?, focusOffset?): RangeSelection

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

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

TextNode.selectNext

selectPrevious()

selectPrevious(anchorOffset?, focusOffset?): RangeSelection

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

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

TextNode.selectPrevious

selectStart()

selectStart(): RangeSelection

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

Returns

RangeSelection

Inherited from

TextNode.selectStart

setDetail()

setDetail(detail): this

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

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

Parameters
detail

number | TextDetailType

TextDetailType or 32-bit integer representing the node detail.

Returns

this

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

Inherited from

TextNode.setDetail

setFormat()

setFormat(format): this

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:131

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 or 32-bit integer representing the node format.

Returns

this

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

Inherited from

TextNode.setFormat

setHighlightType()

setHighlightType(highlightType?): this

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:89

Parameters
highlightType?

string | null

Returns

this

setMode()

setMode(type): this

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

Sets the mode of the node.

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

Parameters
type

TextModeType

Returns

this

this TextNode.

Inherited from

TextNode.setMode

setStyle()

setStyle(style): this

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

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

Parameters
style

string

CSSText to be applied to the underlying HTMLElement.

Returns

this

this TextNode.

Inherited from

TextNode.setStyle

setTextContent()

setTextContent(text): this

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

Sets the text content of the node.

Parameters
text

string

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

Returns

this

this TextNode.

Inherited from

TextNode.setTextContent

spliceText()

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

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

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

Parameters
offset

number

the offset at which the splice operation should begin.

delCount

number

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

newText

string

the text to insert into the TextNode at the offset.

moveSelection?

boolean

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

Returns

TextNode

this TextNode.

Inherited from

TextNode.spliceText

splitText()

splitText(...splitOffsets): TextNode[]

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

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

Parameters
splitOffsets

...number[]

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

Returns

TextNode[]

an Array containing the newly-created TextNodes.

Inherited from

TextNode.splitText

toggleDirectionless()

toggleDirectionless(): this

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

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

Returns

this

this TextNode.

Inherited from

TextNode.toggleDirectionless

toggleFormat()

toggleFormat(type): this

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

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

Parameters
type

TextFormatType

TextFormatType to toggle.

Returns

this

this TextNode.

Inherited from

TextNode.toggleFormat

toggleUnmergeable()

toggleUnmergeable(): this

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

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

Returns

this

this TextNode.

Inherited from

TextNode.toggleUnmergeable

updateDOM()

updateDOM(prevNode, dom, config): boolean

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:109

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

TextNode.updateDOM

updateFromJSON()

updateFromJSON(serializedNode): this

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:56

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

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

If overridden, this method must call super.

Parameters
serializedNode

LexicalParseJSON<SerializedCodeHighlightNode>

Returns

this

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

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

Inherited from

TextNode.updateFromJSON

clone()

static clone(_data): LexicalNode

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

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

Inherited from

TextNode.clone

getType()

static getType(): string

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

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

Inherited from

TextNode.getType

importJSON()

static importJSON(_serializedNode): LexicalNode

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

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

Parameters
_serializedNode

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

Returns

LexicalNode

Inherited from

TextNode.importJSON

transform()

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

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

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

Inherited from

TextNode.transform


CodeNode

Defined in: packages/lexical-code-core/src/CodeNode.ts:104

Extends

Constructors

Constructor

new CodeNode(language?, key?): CodeNode

Defined in: packages/lexical-code-core/src/CodeNode.ts:195

Parameters
language?

string | null | undefined

key?

string

Returns

CodeNode

Inherited from

ElementNode.constructor

Properties

importDOM?

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

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

Returns

DOMConversionMap<any> | null

Inherited from

ElementNode.importDOM

Methods

$config()

$config(): BaseStaticNodeConfig & StaticNodeConfigAccessor<{ $transform: { }; extends: typeof LexicalNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<ElementNode, { direction?: "ltr" | "rtl" | null; format?: "" | "left" | "start" | "center" | "right" | "end" | "justify"; indent?: string | number; textFormat?: string | number; textStyle?: string; }>; }> & object & StaticNodeTypeAccessor<"code"> & StaticNodeConfigAccessor<{ extends: typeof ElementNode; generated: GeneratedJSONFactory; importDOM: { code: (node) => { conversion: (domNode) => DOMConversionOutput; priority: 1; } | null; div: () => object; pre: () => object; table: (node) => { conversion: () => DOMConversionOutput; priority: 3; } | null; td: (node) => { conversion: () => DOMConversionOutput; priority: 3; } | null; tr: (node) => { conversion: () => DOMConversionOutput; priority: 3; } | null; }; json: NodeSerializationSchema<CodeNode, { language?: string | null; theme?: string; }>; }>

Defined in: packages/lexical-code-core/src/CodeNode.ts:120

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

Returns

BaseStaticNodeConfig & StaticNodeConfigAccessor<{ $transform: { }; extends: typeof LexicalNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<ElementNode, { direction?: "ltr" | "rtl" | null; format?: "" | "left" | "start" | "center" | "right" | "end" | "justify"; indent?: string | number; textFormat?: string | number; textStyle?: string; }>; }> & object & StaticNodeTypeAccessor<"code"> & StaticNodeConfigAccessor<{ extends: typeof ElementNode; generated: GeneratedJSONFactory; importDOM: { code: (node) => { conversion: (domNode) => DOMConversionOutput; priority: 1; } | null; div: () => object; pre: () => object; table: (node) => { conversion: () => DOMConversionOutput; priority: 3; } | null; td: (node) => { conversion: () => DOMConversionOutput; priority: 3; } | null; tr: (node) => { conversion: () => DOMConversionOutput; priority: 3; } | null; }; json: NodeSerializationSchema<CodeNode, { language?: string | null; theme?: string; }>; }>

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

ElementNode.$config

afterCloneFrom()

afterCloneFrom(prevNode): void

Defined in: packages/lexical-code-core/src/CodeNode.ts:212

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

Parameters
prevNode

this

Returns

void

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

ElementNode.afterCloneFrom

append()

append(...nodesToAppend): this

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

Parameters
nodesToAppend

...LexicalNode[]

Returns

this

Inherited from

ElementNode.append

canBeEmpty()

canBeEmpty(): boolean

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

Returns

boolean

Inherited from

ElementNode.canBeEmpty

canIndent()

canIndent(): false

Defined in: packages/lexical-code-core/src/CodeNode.ts:389

Returns

false

Inherited from

ElementNode.canIndent

canInsertTextAfter()

canInsertTextAfter(): boolean

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

Returns

boolean

Inherited from

ElementNode.canInsertTextAfter

canInsertTextBefore()

canInsertTextBefore(): boolean

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

Returns

boolean

Inherited from

ElementNode.canInsertTextBefore

canMergeWhenEmpty()

canMergeWhenEmpty(): boolean

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

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

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

Returns

boolean

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

ElementNode.canMergeWhenEmpty

clear()

clear(): this

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

Returns

this

Inherited from

ElementNode.clear

collapseAtStart()

collapseAtStart(): boolean

Defined in: packages/lexical-code-core/src/CodeNode.ts:393

Returns

boolean

Inherited from

ElementNode.collapseAtStart

config()
Call Signature

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

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

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

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

Type Parameters
Config

Config extends StaticNodeConfigValue<CodeNode, string>

Parameters
type

symbol

config

Config

Returns

AbstractStaticNodeConfigRecord<Config>

Inherited from

ElementNode.config

Call Signature

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

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

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

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

Type Parameters
Type

Type extends string

Config

Config extends StaticNodeConfigValue<CodeNode, Type>

Parameters
type

Type

config

Config

Returns

StaticNodeConfigRecord<Type, Config>

Inherited from

ElementNode.config

createDOM()

createDOM(config): HTMLElement

Defined in: packages/lexical-code-core/src/CodeNode.ts:219

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

Inherited from

ElementNode.createDOM

createParentElementNode()

createParentElementNode(): ElementNode

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

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

Returns

ElementNode

Inherited from

ElementNode.createParentElementNode

excludeFromCopy()

excludeFromCopy(destination?): boolean

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

Parameters
destination?

"clone" | "html"

Returns

boolean

Inherited from

ElementNode.excludeFromCopy

exportDOM()

exportDOM(editor): DOMExportOutput

Defined in: packages/lexical-code-core/src/CodeNode.ts:290

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

Parameters
editor

LexicalEditor

Returns

DOMExportOutput

Inherited from

ElementNode.exportDOM

exportJSON()
Call Signature

exportJSON(compact?): SerializedCodeNode

Defined in: packages/lexical-code-core/src/CodeNode.ts:105

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

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

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

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

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

Parameters
compact?

false

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

Returns

SerializedCodeNode

Inherited from

ElementNode.exportJSON

Call Signature

exportJSON(compact): SerializedPartial<SerializedCodeNode>

Defined in: packages/lexical-code-core/src/CodeNode.ts:106

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

Parameters
compact

boolean

Returns

SerializedPartial<SerializedCodeNode>

See

SerializedPartial

Inherited from

ElementNode.exportJSON

extractWithChild()

extractWithChild(child, selection, destination): boolean

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

Parameters
child

LexicalNode

selection

BaseSelection | null

destination

"clone" | "html"

Returns

boolean

Inherited from

ElementNode.extractWithChild

getAllTextNodes()

getAllTextNodes(): TextNode[]

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

Returns

TextNode[]

Inherited from

ElementNode.getAllTextNodes

getChildAtIndex()
Call Signature

getChildAtIndex(index): LexicalNode | null

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

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

Parameters
index

number

Returns

LexicalNode | null

Inherited from

ElementNode.getChildAtIndex

Call Signature

getChildAtIndex<T>(index): T | null

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

Type Parameters
T

T extends LexicalNode

Parameters
index

number

Returns

T | null

Deprecated

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

Inherited from

ElementNode.getChildAtIndex

getChildren()
Call Signature

getChildren(): LexicalNode[]

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

Returns the children of this node, in document order.

Returns

LexicalNode[]

Inherited from

ElementNode.getChildren

Call Signature

getChildren<T>(): T[]

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

Type Parameters
T

T extends LexicalNode

Returns

T[]

Deprecated

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

Inherited from

ElementNode.getChildren

getChildrenKeys()

getChildrenKeys(): string[]

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

Returns

string[]

Inherited from

ElementNode.getChildrenKeys

getChildrenSize()

getChildrenSize(): number

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

Returns

number

Inherited from

ElementNode.getChildrenSize

getCommonAncestor()

getCommonAncestor<T>(node): T | null

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

Type Parameters
T

T extends ElementNode = ElementNode

Parameters
node

LexicalNode

the other node to find the common ancestor of.

Returns

T | null

Deprecated

use $getCommonAncestor

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

Inherited from

ElementNode.getCommonAncestor

getDescendantByIndex()
Call Signature

getDescendantByIndex(index): LexicalNode | null

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

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

Parameters
index

number

Returns

LexicalNode | null

Inherited from

ElementNode.getDescendantByIndex

Call Signature

getDescendantByIndex<T>(index): T | null

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

Type Parameters
T

T extends LexicalNode

Parameters
index

number

Returns

T | null

Deprecated

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

Inherited from

ElementNode.getDescendantByIndex

getDirection()

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

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

Returns

"ltr" | "rtl" | null

Inherited from

ElementNode.getDirection

getDOMSlot()

getDOMSlot(element): ElementDOMSlot<HTMLElement>

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

Experimental

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

Parameters
element

HTMLElement

Returns

ElementDOMSlot<HTMLElement>

Inherited from

ElementNode.getDOMSlot

getFirstChild()
Call Signature

getFirstChild(): LexicalNode | null

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

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

Returns

LexicalNode | null

Inherited from

ElementNode.getFirstChild

Call Signature

getFirstChild<T>(): T | null

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

Type Parameters
T

T extends LexicalNode

Returns

T | null

Deprecated

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

Inherited from

ElementNode.getFirstChild

getFirstChildOrThrow()
Call Signature

getFirstChildOrThrow(): LexicalNode

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

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

Returns

LexicalNode

Inherited from

ElementNode.getFirstChildOrThrow

Call Signature

getFirstChildOrThrow<T>(): T

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

Type Parameters
T

T extends LexicalNode

Returns

T

Deprecated

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

Inherited from

ElementNode.getFirstChildOrThrow

getFirstDescendant()
Call Signature

getFirstDescendant(): LexicalNode | null

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

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

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

Returns

LexicalNode | null

Inherited from

ElementNode.getFirstDescendant

Call Signature

getFirstDescendant<T>(): T | null

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

Type Parameters
T

T extends LexicalNode

Returns

T | null

Deprecated

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

Inherited from

ElementNode.getFirstDescendant

getFormat()

getFormat(): number

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

Returns

number

Inherited from

ElementNode.getFormat

getFormatFlags()

getFormatFlags(type, alignWithFormat): number

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

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

Parameters
type

TextFormatType

alignWithFormat

number | null

Returns

number

a number representing the TextFormatTypes applied to the node.

Inherited from

ElementNode.getFormatFlags

getFormatType()

getFormatType(): ElementFormatType

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

Returns

ElementFormatType

Inherited from

ElementNode.getFormatType

getIndent()

getIndent(): number

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

Returns

number

Inherited from

ElementNode.getIndent

getIndexWithinParent()

getIndexWithinParent(): number

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

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

Returns

number

Inherited from

ElementNode.getIndexWithinParent

getIsSyntaxHighlightSupported()

getIsSyntaxHighlightSupported(): boolean

Defined in: packages/lexical-code-core/src/CodeNode.ts:417

Returns

boolean

getKey()

getKey(): string

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

Returns this nodes key.

Returns

string

Inherited from

ElementNode.getKey

getLanguage()

getLanguage(): string | null | undefined

Defined in: packages/lexical-code-core/src/CodeNode.ts:407

Returns

string | null | undefined

getLastChild()
Call Signature

getLastChild(): LexicalNode | null

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

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

Returns

LexicalNode | null

Inherited from

ElementNode.getLastChild

Call Signature

getLastChild<T>(): T | null

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

Type Parameters
T

T extends LexicalNode

Returns

T | null

Deprecated

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

Inherited from

ElementNode.getLastChild

getLastChildOrThrow()
Call Signature

getLastChildOrThrow(): LexicalNode

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

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

Returns

LexicalNode

Inherited from

ElementNode.getLastChildOrThrow

Call Signature

getLastChildOrThrow<T>(): T

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

Type Parameters
T

T extends LexicalNode

Returns

T

Deprecated

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

Inherited from

ElementNode.getLastChildOrThrow

getLastDescendant()
Call Signature

getLastDescendant(): LexicalNode | null

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

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

Returns

LexicalNode | null

Inherited from

ElementNode.getLastDescendant

Call Signature

getLastDescendant<T>(): T | null

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

Type Parameters
T

T extends LexicalNode

Returns

T | null

Deprecated

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

Inherited from

ElementNode.getLastDescendant

getLatest()

getLatest(): this

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

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

Returns

this

Inherited from

ElementNode.getLatest

getNextSibling()
Call Signature

getNextSibling(): LexicalNode | null

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

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

Returns

LexicalNode | null

Inherited from

ElementNode.getNextSibling

Call Signature

getNextSibling<T>(): T | null

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

Type Parameters
T

T extends LexicalNode

Returns

T | null

Deprecated

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

Inherited from

ElementNode.getNextSibling

getNextSiblings()
Call Signature

getNextSiblings(): LexicalNode[]

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

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

Returns

LexicalNode[]

Inherited from

ElementNode.getNextSiblings

Call Signature

getNextSiblings<T>(): T[]

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

Type Parameters
T

T extends LexicalNode

Returns

T[]

Deprecated

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

Inherited from

ElementNode.getNextSiblings

getNodesBetween()

getNodesBetween(targetNode): LexicalNode[]

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

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

Parameters
targetNode

LexicalNode

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

Returns

LexicalNode[]

Inherited from

ElementNode.getNodesBetween

getParent()
Call Signature

getParent(): ElementNode | null

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

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

Returns

ElementNode | null

Inherited from

ElementNode.getParent

Call Signature

getParent<T>(): T | null

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

Type Parameters
T

T extends ElementNode

Returns

T | null

Deprecated

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

Inherited from

ElementNode.getParent

getParentKeys()

getParentKeys(): string[]

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

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

Returns

string[]

Inherited from

ElementNode.getParentKeys

getParentOrThrow()
Call Signature

getParentOrThrow(): ElementNode

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

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

Returns

ElementNode

Inherited from

ElementNode.getParentOrThrow

Call Signature

getParentOrThrow<T>(): T

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

Type Parameters
T

T extends ElementNode

Returns

T

Deprecated

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

Inherited from

ElementNode.getParentOrThrow

getParents()

getParents(): ElementNode[]

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

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

Returns

ElementNode[]

Inherited from

ElementNode.getParents

getPreviousSibling()
Call Signature

getPreviousSibling(): LexicalNode | null

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

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

Returns

LexicalNode | null

Inherited from

ElementNode.getPreviousSibling

Call Signature

getPreviousSibling<T>(): T | null

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

Type Parameters
T

T extends LexicalNode

Returns

T | null

Deprecated

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

Inherited from

ElementNode.getPreviousSibling

getPreviousSiblings()
Call Signature

getPreviousSiblings(): LexicalNode[]

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

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

Returns

LexicalNode[]

Inherited from

ElementNode.getPreviousSiblings

Call Signature

getPreviousSiblings<T>(): T[]

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

Type Parameters
T

T extends LexicalNode

Returns

T[]

Deprecated

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

Inherited from

ElementNode.getPreviousSiblings

getStyle()

getStyle(): string

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

Returns

string

Inherited from

ElementNode.getStyle

getTextContent()

getTextContent(): string

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

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

Returns

string

Inherited from

ElementNode.getTextContent

getTextContentSize()

getTextContentSize(): number

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

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

Returns

number

Inherited from

ElementNode.getTextContentSize

getTextFormat()

getTextFormat(): number

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

Returns

number

Inherited from

ElementNode.getTextFormat

getTextStyle()

getTextStyle(): string

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

Returns

string

Inherited from

ElementNode.getTextStyle

getTheme()

getTheme(): string | undefined

Defined in: packages/lexical-code-core/src/CodeNode.ts:427

Returns

string | undefined

getTopLevelElement()

getTopLevelElement(): ElementNode | null

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

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

Returns

ElementNode | null

Inherited from

ElementNode.getTopLevelElement

getTopLevelElementOrThrow()

getTopLevelElementOrThrow(): ElementNode

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

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

Returns

ElementNode

Inherited from

ElementNode.getTopLevelElementOrThrow

getType()

getType(): string

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

Returns the string type of this node.

Returns

string

Inherited from

ElementNode.getType

getWritable()

getWritable(): this

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

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

Returns

this

Inherited from

ElementNode.getWritable

hasFormat()

hasFormat(type): boolean

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

Parameters
type

ElementFormatType

Returns

boolean

Inherited from

ElementNode.hasFormat

hasTextFormat()

hasTextFormat(type): boolean

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

Parameters
type

TextFormatType

Returns

boolean

Inherited from

ElementNode.hasTextFormat

insertAfter()

insertAfter(nodeToInsert, restoreSelection?): LexicalNode

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

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

Parameters
nodeToInsert

LexicalNode

The node to insert after this one.

restoreSelection?

boolean = true

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

Returns

LexicalNode

Inherited from

ElementNode.insertAfter

insertBefore()

insertBefore(nodeToInsert, restoreSelection?): LexicalNode

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

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

Parameters
nodeToInsert

LexicalNode

The node to insert before this one.

restoreSelection?

boolean = true

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

Returns

LexicalNode

Inherited from

ElementNode.insertBefore

insertNewAfter()

insertNewAfter(selection, restoreSelection?): TabNode | ParagraphNode | CodeHighlightNode | null

Defined in: packages/lexical-code-core/src/CodeNode.ts:316

Parameters
selection

RangeSelection

restoreSelection?

boolean = true

Returns

TabNode | ParagraphNode | CodeHighlightNode | null

Inherited from

ElementNode.insertNewAfter

is()

is(object): boolean

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

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

Parameters
object

LexicalNode | null | undefined

the node to perform the equality comparison on.

Returns

boolean

Inherited from

ElementNode.is

isAttached()

isAttached(): boolean

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

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

Returns

boolean

Inherited from

ElementNode.isAttached

isBefore()

isBefore(targetNode): boolean

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

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

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

Parameters
targetNode

LexicalNode

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

Returns

boolean

Inherited from

ElementNode.isBefore

isDirty()

isDirty(): boolean

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

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

Returns

boolean

Inherited from

ElementNode.isDirty

isEmpty()

isEmpty(): boolean

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

Returns

boolean

Inherited from

ElementNode.isEmpty

isInline()

isInline(): boolean

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

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

Returns

boolean

Inherited from

ElementNode.isInline

isLastChild()

isLastChild(): boolean

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

Returns

boolean

Inherited from

ElementNode.isLastChild

isParentOf()

isParentOf(targetNode): boolean

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

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

Parameters
targetNode

LexicalNode

the would-be child node.

Returns

boolean

Inherited from

ElementNode.isParentOf

isParentRequired()

isParentRequired(): boolean

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

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

Returns

boolean

Inherited from

ElementNode.isParentRequired

isSelected()

isSelected(selection?): boolean

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

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

Parameters
selection?

BaseSelection | null

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

Returns

boolean

Inherited from

ElementNode.isSelected

isShadowRoot()

isShadowRoot(): boolean

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

Returns

boolean

Inherited from

ElementNode.isShadowRoot

markDirty()

markDirty(): void

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

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

Returns

void

Inherited from

ElementNode.markDirty

remove()

remove(preserveEmptyParent?): void

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

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

Parameters
preserveEmptyParent?

boolean

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

Returns

void

Inherited from

ElementNode.remove

replace()

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

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

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

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

Type Parameters
N

N extends LexicalNode

Parameters
replaceWith

N

The node to replace this one with.

includeChildren?

boolean

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

Returns

N

Inherited from

ElementNode.replace

resetOnCopyNodeFrom()

resetOnCopyNodeFrom(originalNode): void

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

Reset state in this copy of originalNode, if necessary

Parameters
originalNode

this

Returns

void

Inherited from

ElementNode.resetOnCopyNodeFrom

select()

select(_anchorOffset?, _focusOffset?): RangeSelection

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

Parameters
_anchorOffset?

number

_focusOffset?

number

Returns

RangeSelection

Inherited from

ElementNode.select

selectEnd()

selectEnd(): RangeSelection

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

Returns

RangeSelection

Inherited from

ElementNode.selectEnd

selectNext()

selectNext(anchorOffset?, focusOffset?): RangeSelection

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

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

Parameters
anchorOffset?

number

The anchor offset for selection.

focusOffset?

number

The focus offset for selection

Returns

RangeSelection

Inherited from

ElementNode.selectNext

selectPrevious()

selectPrevious(anchorOffset?, focusOffset?): RangeSelection

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

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

Parameters
anchorOffset?

number

The anchor offset for selection.

focusOffset?

number

The focus offset for selection

Returns

RangeSelection

Inherited from

ElementNode.selectPrevious

selectStart()

selectStart(): RangeSelection

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

Returns

RangeSelection

Inherited from

ElementNode.selectStart

setDirection()

setDirection(direction): this

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

Parameters
direction

"ltr" | "rtl" | null

Returns

this

Inherited from

ElementNode.setDirection

setFormat()

setFormat(type): this

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

Parameters
type

ElementFormatType

Returns

this

Inherited from

ElementNode.setFormat

setIndent()

setIndent(indentLevel): this

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

Parameters
indentLevel

number

Returns

this

Inherited from

ElementNode.setIndent

setIsSyntaxHighlightSupported()

setIsSyntaxHighlightSupported(isSupported): this

Defined in: packages/lexical-code-core/src/CodeNode.ts:411

Parameters
isSupported

boolean

Returns

this

setLanguage()

setLanguage(language): this

Defined in: packages/lexical-code-core/src/CodeNode.ts:401

Parameters
language

string | null | undefined

Returns

this

setStyle()

setStyle(style): this

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

Parameters
style

string

Returns

this

Inherited from

ElementNode.setStyle

setTextFormat()

setTextFormat(type): this

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

Parameters
type

number

Returns

this

Inherited from

ElementNode.setTextFormat

setTextStyle()

setTextStyle(style): this

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

Parameters
style

string

Returns

this

Inherited from

ElementNode.setTextStyle

setTheme()

setTheme(theme): this

Defined in: packages/lexical-code-core/src/CodeNode.ts:421

Parameters
theme

string | null | undefined

Returns

this

splice()

splice(start, deleteCount, nodesToInsert): this

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

Parameters
start

number

deleteCount

number

nodesToInsert

LexicalNode[]

Returns

this

Inherited from

ElementNode.splice

updateDOM()

updateDOM(prevNode, dom, config): boolean

Defined in: packages/lexical-code-core/src/CodeNode.ts:242

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

ElementNode.updateDOM

updateFromJSON()

updateFromJSON(serializedNode): this

Defined in: packages/lexical-code-core/src/CodeNode.ts:107

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

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

If overridden, this method must call super.

Parameters
serializedNode

LexicalParseJSON<SerializedCodeNode>

Returns

this

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

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

Inherited from

ElementNode.updateFromJSON

clone()

static clone(_data): LexicalNode

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

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

Inherited from

ElementNode.clone

getType()

static getType(): string

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

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

Inherited from

ElementNode.getType

importJSON()

static importJSON(_serializedNode): LexicalNode

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

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

Parameters
_serializedNode

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

Returns

LexicalNode

Inherited from

ElementNode.importJSON

transform()

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

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

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

Inherited from

ElementNode.transform

Interfaces

CodeIndentConfig

Defined in: packages/lexical-code-core/src/CodeIndentation.ts:681

Properties

disabled

disabled: boolean

Defined in: packages/lexical-code-core/src/CodeIndentation.ts:687

When true, the indent commands are not registered on the editor. This signal can be flipped at runtime to enable or disable indent handling without rebuilding the editor.

escapeWithArrows

escapeWithArrows: boolean

Defined in: packages/lexical-code-core/src/CodeIndentation.ts:706

When true, this enables the ability to exit a code block that has no adjacent elements using the ArrowLeft/ArrowUp keys if the cursor is at the beginning, or the ArrowRight/ArrowDown keys if the cursor is at the end. When false (default), pressing the arrow keys will not move the cursor if there are no adjacent elements around the code block

tabSize

tabSize: number | undefined

Defined in: packages/lexical-code-core/src/CodeIndentation.ts:697

When set, treats that many leading spaces on a code line as one indent level for the OUTDENT_CONTENT_COMMAND (Shift+Tab). See registerCodeIndentation. When undefined (the default), only TabNode removal is supported on outdent.

Tab and INSERT_TAB_COMMAND continue to insert a TabNode regardless of this option.

Type Aliases

SerializedCodeNode

SerializedCodeNode = Spread<{ language: string | null | undefined; theme?: string; }, SerializedElementNode>

Defined in: packages/lexical-code-core/src/CodeNode.ts:58

Variables

CodeExtension

const CodeExtension: LexicalExtension<ExtensionConfigBase, "@lexical/code", unknown, unknown>

Defined in: packages/lexical-code-core/src/CodeExtension.ts:31

Add code blocks to the editor (syntax highlighting provided separately)


CodeIndentExtension

const CodeIndentExtension: LexicalExtension<CodeIndentConfig, "@lexical/code-indent", NamedSignalsOutput<CodeIndentConfig>, unknown>

Defined in: packages/lexical-code-core/src/CodeIndentation.ts:720

Adds keyboard-driven indentation to code blocks (Tab / Shift+Tab, alt+arrow line shifts, Home/End within a line). Both "@lexical/code-shiki".CodeShikiExtension and "@lexical/code-prism".CodePrismExtension declare this as a dependency, so it is activated automatically alongside either highlighter.

Code blocks without syntax highlighting can use this extension on its own.


DEFAULT_CODE_LANGUAGE

const DEFAULT_CODE_LANGUAGE: "javascript" = 'javascript'

Defined in: packages/lexical-code-core/src/CodeNode.ts:79

Functions

$createCodeHighlightNode()

$createCodeHighlightNode(text?, highlightType?): CodeHighlightNode

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:156

Parameters

text?

string = ''

highlightType?

string | null

Returns

CodeHighlightNode


$createCodeNode()

$createCodeNode(language?, theme?): CodeNode

Defined in: packages/lexical-code-core/src/CodeNode.ts:432

Parameters

language?

string | null

theme?

string | null

Returns

CodeNode


$getCodeLineDirection()

$getCodeLineDirection(anchor): "ltr" | "rtl" | null

Defined in: packages/lexical-code-core/src/FlatStructureUtils.ts:76

Determines the visual writing direction of a code line.

Scans the line segments (CodeHighlightNode/TabNode) from start to end and returns the first strong direction found ("ltr" or "rtl"). If no strong character is found, falls back to the parent element's direction. Returns null if indeterminate.

Parameters

anchor

LineBreakNode | TabNode | CodeHighlightNode

Returns

"ltr" | "rtl" | null


$getEndOfCodeInLine()

$getEndOfCodeInLine(anchor): TabNode | CodeHighlightNode

Defined in: packages/lexical-code-core/src/FlatStructureUtils.ts:226

Parameters

anchor

TabNode | CodeHighlightNode

Returns

TabNode | CodeHighlightNode


$getFirstCodeNodeOfLine()

$getFirstCodeNodeOfLine<T>(anchor): TabNode | CodeHighlightNode | T

Defined in: packages/lexical-code-core/src/FlatStructureUtils.ts:56

Type Parameters

T

T extends TextNode | LineBreakNode

Parameters

anchor

T

Returns

TabNode | CodeHighlightNode | T


$getLastCodeNodeOfLine()

$getLastCodeNodeOfLine<T>(anchor): TabNode | CodeHighlightNode | T

Defined in: packages/lexical-code-core/src/FlatStructureUtils.ts:62

Type Parameters

T

T extends TextNode | LineBreakNode

Parameters

anchor

T

Returns

TabNode | CodeHighlightNode | T


$getStartOfCodeInLine()

$getStartOfCodeInLine(anchor, offset): { node: LineBreakNode | TabNode | CodeHighlightNode; offset: number; } | null

Defined in: packages/lexical-code-core/src/FlatStructureUtils.ts:109

Parameters

anchor

TabNode | CodeHighlightNode

offset

number

Returns

{ node: LineBreakNode | TabNode | CodeHighlightNode; offset: number; } | null


$isCodeHighlightNode()

$isCodeHighlightNode(node): node is CodeHighlightNode

Defined in: packages/lexical-code-core/src/CodeHighlightNode.ts:163

Parameters

node

LexicalNode | CodeHighlightNode | null | undefined

Returns

node is CodeHighlightNode


$isCodeNode()

$isCodeNode(node): node is CodeNode

Defined in: packages/lexical-code-core/src/CodeNode.ts:439

Parameters

node

LexicalNode | null | undefined

Returns

node is CodeNode


$outdentLeadingSpaces()

$outdentLeadingSpaces(node, tabSize, selection): boolean

Defined in: packages/lexical-code-core/src/FlatStructureUtils.ts:269

Strip up to tabSize leading spaces from a CodeHighlightNode that starts a code line, to support outdenting space-indented code lines (e.g. code formatted with prettier). Returns true if any spaces were stripped.

Best-effort: a line with fewer than tabSize leading spaces has all of them stripped, matching VS Code / IntelliJ behavior.

Selection is preserved relative to line content. Anchor/focus offsets pointing into node shift left by the number of stripped characters (clamped to 0). The underlying TextNode mutation does not adjust selection offsets that already point into the old text, so we patch them up explicitly.

Parameters

node

CodeHighlightNode

tabSize

number

selection

RangeSelection

Returns

boolean