lexical
Classes
DecoratorNode<T>
Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:18
Extends
Extended by
Type Parameters
T
T
Constructors
Constructor
new DecoratorNode<
T
>(key?
):DecoratorNode
<T
>
Defined in: packages/lexical/src/LexicalNode.ts:537
Parameters
key?
string
Returns
Properties
importDOM()?
static
optional
importDOM: () =>null
|DOMConversionMap
<any
>
Defined in: packages/lexical/src/LexicalNode.ts:535
Returns
null
| DOMConversionMap
<any
>
Methods
$config()
$config():
BaseStaticNodeConfig
Defined in: packages/lexical/src/LexicalNode.ts:454
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
Example
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Inherited from
afterCloneFrom()
afterCloneFrom(
prevNode
):void
Defined in: packages/lexical/src/LexicalNode.ts:523
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
config()
config<
Type
,Config
>(type
,config
):StaticNodeConfigRecord
<Type
,Config
>
Defined in: packages/lexical/src/LexicalNode.ts:463
This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.
Type Parameters
Type
Type
extends string
Config
Config
extends StaticNodeConfigValue
<DecoratorNode
<T
>, Type
>
Parameters
type
Type
config
Config
Returns
StaticNodeConfigRecord
<Type
, Config
>
Inherited from
createDOM()
createDOM(
_config
,_editor
):HTMLElement
Defined in: packages/lexical/src/LexicalNode.ts:1057
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
allows access to things like the EditorTheme (to apply classes) during reconciliation.
_editor
allows access to the editor for context during reconciliation.
Returns
HTMLElement
Inherited from
createParentElementNode()
createParentElementNode():
ElementNode
Defined in: packages/lexical/src/LexicalNode.ts:1377
The creation logic for any required parent. Should be implemented if isParentRequired returns true.
Returns
Inherited from
LexicalNode
.createParentElementNode
decorate()
decorate(
editor
,config
):T
Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:32
The returned value is added to the LexicalEditor._decorators
Parameters
editor
config
Returns
T
exportDOM()
exportDOM(
editor
):DOMExportOutput
Defined in: packages/lexical/src/LexicalNode.ts:1087
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
Returns
Inherited from
exportJSON()
exportJSON():
SerializedLexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1099
Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.
Returns
Inherited from
getCommonAncestor()
getCommonAncestor<
T
>(node
):null
|T
Defined in: packages/lexical/src/LexicalNode.ts:830
Type Parameters
T
T
extends ElementNode
= ElementNode
Parameters
node
the other node to find the common ancestor of.
Returns
null
| T
Deprecated
Returns the closest common ancestor of this node and the provided one or null if one cannot be found.
Inherited from
getIndexWithinParent()
getIndexWithinParent():
number
Defined in: packages/lexical/src/LexicalNode.ts:656
Returns the zero-based index of this node within the parent.
Returns
number
Inherited from
LexicalNode
.getIndexWithinParent
getKey()
getKey():
string
Defined in: packages/lexical/src/LexicalNode.ts:648
Returns this nodes key.
Returns
string
Inherited from
getLatest()
getLatest():
this
Defined in: packages/lexical/src/LexicalNode.ts:981
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
getNextSibling()
getNextSibling<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:801
Returns the "next" siblings - that is, the node that comes after this one in the same parent
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
Inherited from
getNextSiblings()
getNextSiblings<
T
>():T
[]
Defined in: packages/lexical/src/LexicalNode.ts:812
Returns all "next" siblings - that is, the nodes that come between this one and the last child of it's parent, inclusive.
Type Parameters
T
T
extends LexicalNode
Returns
T
[]
Inherited from
getNodesBetween()
getNodesBetween(
targetNode
):LexicalNode
[]
Defined in: packages/lexical/src/LexicalNode.ts:900
Returns a list of nodes that are between this node and the target node in the EditorState.
Parameters
targetNode
the node that marks the other end of the range of nodes to be returned.
Returns
Inherited from
getParent()
getParent<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:676
Returns the parent of this node, or null if none is found.
Type Parameters
T
T
extends ElementNode
Returns
null
| T
Inherited from
getParentKeys()
getParentKeys():
string
[]
Defined in: packages/lexical/src/LexicalNode.ts:753
Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.
Returns
string
[]
Inherited from
getParentOrThrow()
getParentOrThrow<
T
>():T
Defined in: packages/lexical/src/LexicalNode.ts:687
Returns the parent of this node, or throws if none is found.
Type Parameters
T
T
extends ElementNode
Returns
T
Inherited from
getParents()
getParents():
ElementNode
[]
Defined in: packages/lexical/src/LexicalNode.ts:738
Returns a list of the every ancestor of this node, all the way up to the RootNode.
Returns
Inherited from
getPreviousSibling()
getPreviousSibling<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:768
Returns the "previous" siblings - that is, the node that comes before this one in the same parent.
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
Inherited from
LexicalNode
.getPreviousSibling
getPreviousSiblings()
getPreviousSiblings<
T
>():T
[]
Defined in: packages/lexical/src/LexicalNode.ts:779
Returns the "previous" siblings - that is, the nodes that come between this one and the first child of it's parent, inclusive.
Type Parameters
T
T
extends LexicalNode
Returns
T
[]
Inherited from
LexicalNode
.getPreviousSiblings
getTextContent()
getTextContent():
string
Defined in: packages/lexical/src/LexicalNode.ts:1031
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
getTextContentSize()
getTextContentSize():
number
Defined in: packages/lexical/src/LexicalNode.ts:1039
Returns the length of the string produced by calling getTextContent on this node.
Returns
number
Inherited from
LexicalNode
.getTextContentSize
getTopLevelElement()
getTopLevelElement():
null
|ElementNode
|DecoratorNode
<T
>
Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:19
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
null
| ElementNode
| DecoratorNode
<T
>
Inherited from
LexicalNode
.getTopLevelElement
getTopLevelElementOrThrow()
getTopLevelElementOrThrow():
ElementNode
|DecoratorNode
<T
>
Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:20
Returns the highest (in the EditorState tree) non-root ancestor of this node, or throws if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".
Returns
ElementNode
| DecoratorNode
<T
>
Inherited from
LexicalNode
.getTopLevelElementOrThrow
getType()
getType():
string
Defined in: packages/lexical/src/LexicalNode.ts:562
Returns the string type of this node.
Returns
string
Inherited from
getWritable()
getWritable():
this
Defined in: packages/lexical/src/LexicalNode.ts:998
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
insertAfter()
insertAfter(
nodeToInsert
,restoreSelection
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1262
Inserts a node after this LexicalNode (as the next sibling).
Parameters
nodeToInsert
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
Inherited from
insertBefore()
insertBefore(
nodeToInsert
,restoreSelection
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1329
Inserts a node before this LexicalNode (as the previous sibling).
Parameters
nodeToInsert
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
Inherited from
is()
is(
object
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:847
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
the node to perform the equality comparison on.
undefined
| null
| LexicalNode
Returns
boolean
Inherited from
isAttached()
isAttached():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:579
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
isBefore()
isBefore(
targetNode
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:865
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
the node we're testing to see if it's after this one.
Returns
boolean
Inherited from
isDirty()
isDirty():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:970
Returns true if this node has been marked dirty during this update cycle.
Returns
boolean
Inherited from
isInline()
isInline():
boolean
Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:40
Returns
boolean
Inherited from
isIsolated()
isIsolated():
boolean
Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:36
Returns
boolean
isKeyboardSelectable()
isKeyboardSelectable():
boolean
Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:44
Returns
boolean
isParentOf()
isParentOf(
targetNode
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:888
Returns true if this node is an ancestor of and distinct from the target node, false otherwise.
Parameters
targetNode
the would-be child node.
Returns
boolean
Inherited from
isParentRequired()
isParentRequired():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:1369
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
isSelected()
isSelected(
selection?
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:603
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?
The selection that we want to determine if the node is in.
null
| BaseSelection
Returns
boolean
Inherited from
markDirty()
markDirty():
void
Defined in: packages/lexical/src/LexicalNode.ts:1438
Marks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.
Returns
void
Inherited from
remove()
remove(
preserveEmptyParent?
):void
Defined in: packages/lexical/src/LexicalNode.ts:1181
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
replace()
replace<
N
>(replaceWith
,includeChildren?
):N
Defined in: packages/lexical/src/LexicalNode.ts:1192
Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.
Type Parameters
N
N
extends LexicalNode
Parameters
replaceWith
N
The node to replace this one with.
includeChildren?
boolean
Whether or not to transfer the children of this node to the replacing node.
Returns
N
Inherited from
selectEnd()
selectEnd():
RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1385
Returns
Inherited from
selectNext()
selectNext(
anchorOffset?
,focusOffset?
):RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1417
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
Inherited from
selectPrevious()
selectPrevious(
anchorOffset?
,focusOffset?
):RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1395
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
Inherited from
selectStart()
selectStart():
RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1381
Returns
Inherited from
updateDOM()
updateDOM(
_prevNode
,_dom
,_config
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:1071
Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.
Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.
Parameters
_prevNode
unknown
_dom
HTMLElement
_config
Returns
boolean
Inherited from
updateFromJSON()
updateFromJSON(
serializedNode
):this
Defined in: packages/lexical/src/LexicalNode.ts:1152
Update this LexicalNode instance from serialized JSON. It's recommended to implement as much logic as possible in this method instead of the static importJSON method, so that the functionality can be inherited in subclasses.
The LexicalUpdateJSON utility type should be used to ignore any type, version, or children properties in the JSON so that the extended JSON from subclasses are acceptable parameters for the super call.
If overridden, this method must call super.
Parameters
serializedNode
LexicalUpdateJSON
<SerializedLexicalNode
>
Returns
this
Example
class MyTextNode extends TextNode {
// ...
static importJSON(serializedNode: SerializedMyTextNode): MyTextNode {
return $createMyTextNode()
.updateFromJSON(serializedNode);
}
updateFromJSON(
serializedNode: LexicalUpdateJSON<SerializedMyTextNode>,
): this {
return super.updateFromJSON(serializedNode)
.setMyProperty(serializedNode.myProperty);
}
}
Inherited from
clone()
static
clone(_data
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:431
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
getType()
static
getType():string
Defined in: packages/lexical/src/LexicalNode.ts:415
Returns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.
Returns
string
importJSON()
static
importJSON(_serializedNode
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1116
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
Returns
transform()
static
transform():null
| (node
) =>void
Defined in: packages/lexical/src/LexicalNode.ts:1167
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
null
| (node
) => void
ElementNode
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:78
Extends
Extended by
LinkNode
OverflowNode
QuoteNode
HeadingNode
ParagraphNode
RootNode
CodeNode
ListItemNode
ListNode
MarkNode
TableCellNode
TableNode
TableRowNode
Constructors
Constructor
new ElementNode(
key?
):ElementNode
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:331
Parameters
key?
string
Returns
Properties
importDOM()?
static
optional
importDOM: () =>null
|DOMConversionMap
<any
>
Defined in: packages/lexical/src/LexicalNode.ts:535
Returns
null
| DOMConversionMap
<any
>
Methods
$config()
$config():
BaseStaticNodeConfig
Defined in: packages/lexical/src/LexicalNode.ts:454
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
Example
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Inherited from
afterCloneFrom()
afterCloneFrom(
prevNode
):void
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:344
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
append()
append(...
nodesToAppend
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:648
Parameters
nodesToAppend
...LexicalNode
[]
Returns
this
canBeEmpty()
canBeEmpty():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:919
Returns
boolean
canIndent()
canIndent():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:891
Returns
boolean
canInsertTextAfter()
canInsertTextAfter():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:925
Returns
boolean
canInsertTextBefore()
canInsertTextBefore():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:922
Returns
boolean
canMergeWhenEmpty()
canMergeWhenEmpty():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:963
Determines whether this node, when empty, can merge with a first block of nodes being inserted.
This method is specifically called in RangeSelection.insertNodes to determine merging behavior during nodes insertion.
Returns
boolean
Example
// In a ListItemNode or QuoteNode implementation:
canMergeWhenEmpty(): true {
return true;
}
clear()
clear():
this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:642
Returns
this
collapseAtStart()
collapseAtStart(
selection
):boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:905
Parameters
selection
Returns
boolean
config()
config<
Type
,Config
>(type
,config
):StaticNodeConfigRecord
<Type
,Config
>
Defined in: packages/lexical/src/LexicalNode.ts:463
This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.
Type Parameters
Type
Type
extends string
Config
Config
extends StaticNodeConfigValue
<ElementNode
, Type
>
Parameters
type
Type
config
Config
Returns
StaticNodeConfigRecord
<Type
, Config
>
Inherited from
createDOM()
createDOM(
_config
,_editor
):HTMLElement
Defined in: packages/lexical/src/LexicalNode.ts:1057
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
allows access to things like the EditorTheme (to apply classes) during reconciliation.
_editor
allows access to the editor for context during reconciliation.
Returns
HTMLElement
Inherited from
createParentElementNode()
createParentElementNode():
ElementNode
Defined in: packages/lexical/src/LexicalNode.ts:1377
The creation logic for any required parent. Should be implemented if isParentRequired returns true.
Returns
Inherited from
LexicalNode
.createParentElementNode
excludeFromCopy()
excludeFromCopy(
destination?
):boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:908
Parameters
destination?
"clone"
| "html"
Returns
boolean
exportDOM()
exportDOM(
editor
):DOMExportOutput
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:829
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
Returns
Inherited from
exportJSON()
exportJSON():
SerializedElementNode
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:852
Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.
Returns
Inherited from
extractWithChild()
extractWithChild(
child
,selection
,destination
):boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:942
Parameters
child
selection
null
| BaseSelection
destination
"clone"
| "html"
Returns
boolean
getAllTextNodes()
getAllTextNodes():
TextNode
[]
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:410
Returns
TextNode
[]
getChildAtIndex()
getChildAtIndex<
T
>(index
):null
|T
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:491
Type Parameters
T
T
extends LexicalNode
Parameters
index
number
Returns
null
| T
getChildren()
getChildren<
T
>():T
[]
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:375
Type Parameters
T
T
extends LexicalNode
Returns
T
[]
getChildrenKeys()
getChildrenKeys():
string
[]
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:384
Returns
string
[]
getChildrenSize()
getChildrenSize():
number
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:393
Returns
number
getCommonAncestor()
getCommonAncestor<
T
>(node
):null
|T
Defined in: packages/lexical/src/LexicalNode.ts:830
Type Parameters
T
T
extends ElementNode
= ElementNode
Parameters
node
the other node to find the common ancestor of.
Returns
null
| T
Deprecated
Returns the closest common ancestor of this node and the provided one or null if one cannot be found.
Inherited from
getDescendantByIndex()
getDescendantByIndex<
T
>(index
):null
|T
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:447
Type Parameters
T
T
extends LexicalNode
Parameters
index
number
Returns
null
| T
getDirection()
getDirection():
null
|"ltr"
|"rtl"
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:552
Returns
null
| "ltr"
| "rtl"
getFirstChild()
getFirstChild<
T
>():null
|T
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:467
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
getFirstChildOrThrow()
getFirstChildOrThrow<
T
>():T
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:472
Type Parameters
T
T
extends LexicalNode
Returns
T
getFirstDescendant()
getFirstDescendant<
T
>():null
|T
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:425
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
getFormat()
getFormat():
number
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:359
Returns
number
getFormatFlags()
getFormatFlags(
type
,alignWithFormat
):number
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:576
Returns the format flags applied to the node as a 32-bit integer.
Parameters
type
alignWithFormat
null
| number
Returns
number
a number representing the TextFormatTypes applied to the node.
getFormatType()
getFormatType():
ElementFormatType
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:363
Returns
getIndent()
getIndent():
number
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:371
Returns
number
getIndexWithinParent()
getIndexWithinParent():
number
Defined in: packages/lexical/src/LexicalNode.ts:656
Returns the zero-based index of this node within the parent.
Returns
number
Inherited from
LexicalNode
.getIndexWithinParent
getKey()
getKey():
string
Defined in: packages/lexical/src/LexicalNode.ts:648
Returns this nodes key.
Returns
string
Inherited from
getLastChild()
getLastChild<
T
>():null
|T
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:479
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
getLastChildOrThrow()
getLastChildOrThrow<
T
>():T
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:484
Type Parameters
T
T
extends LexicalNode
Returns
T
getLastDescendant()
getLastDescendant<
T
>():null
|T
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:436
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
getLatest()
getLatest():
this
Defined in: packages/lexical/src/LexicalNode.ts:981
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
getNextSibling()
getNextSibling<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:801
Returns the "next" siblings - that is, the node that comes after this one in the same parent
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
Inherited from
getNextSiblings()
getNextSiblings<
T
>():T
[]
Defined in: packages/lexical/src/LexicalNode.ts:812
Returns all "next" siblings - that is, the nodes that come between this one and the last child of it's parent, inclusive.
Type Parameters
T
T
extends LexicalNode
Returns
T
[]
Inherited from
getNodesBetween()
getNodesBetween(
targetNode
):LexicalNode
[]
Defined in: packages/lexical/src/LexicalNode.ts:900
Returns a list of nodes that are between this node and the target node in the EditorState.
Parameters
targetNode
the node that marks the other end of the range of nodes to be returned.
Returns
Inherited from
getParent()
getParent<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:676
Returns the parent of this node, or null if none is found.
Type Parameters
T
T
extends ElementNode
Returns
null
| T
Inherited from
getParentKeys()
getParentKeys():
string
[]
Defined in: packages/lexical/src/LexicalNode.ts:753
Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.
Returns
string
[]
Inherited from
getParentOrThrow()
getParentOrThrow<
T
>():T
Defined in: packages/lexical/src/LexicalNode.ts:687
Returns the parent of this node, or throws if none is found.
Type Parameters
T
T
extends ElementNode
Returns
T
Inherited from
getParents()
getParents():
ElementNode
[]
Defined in: packages/lexical/src/LexicalNode.ts:738
Returns a list of the every ancestor of this node, all the way up to the RootNode.
Returns
Inherited from
getPreviousSibling()
getPreviousSibling<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:768
Returns the "previous" siblings - that is, the node that comes before this one in the same parent.
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
Inherited from
LexicalNode
.getPreviousSibling
getPreviousSiblings()
getPreviousSiblings<
T
>():T
[]
Defined in: packages/lexical/src/LexicalNode.ts:779
Returns the "previous" siblings - that is, the nodes that come between this one and the first child of it's parent, inclusive.
Type Parameters
T
T
extends LexicalNode
Returns
T
[]
Inherited from
LexicalNode
.getPreviousSiblings
getStyle()
getStyle():
string
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:367
Returns
string
getTextContent()
getTextContent():
string
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:518
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
getTextContentSize()
getTextContentSize():
number
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:535
Returns the length of the string produced by calling getTextContent on this node.
Returns
number
Inherited from
LexicalNode
.getTextContentSize
getTextFormat()
getTextFormat():
number
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:556
Returns
number
getTextStyle()
getTextStyle():
string
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:582
Returns
string
getTopLevelElement()
getTopLevelElement():
null
|ElementNode
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:79
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
null
| ElementNode
Inherited from
LexicalNode
.getTopLevelElement
getTopLevelElementOrThrow()
getTopLevelElementOrThrow():
ElementNode
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:80
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
Inherited from
LexicalNode
.getTopLevelElementOrThrow
getType()
getType():
string
Defined in: packages/lexical/src/LexicalNode.ts:562
Returns the string type of this node.
Returns
string
Inherited from
getWritable()
getWritable():
this
Defined in: packages/lexical/src/LexicalNode.ts:998
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
hasFormat()
hasFormat(
type
):boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:560
Parameters
type
Returns
boolean
hasTextFormat()
hasTextFormat(
type
):boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:567
Parameters
type
Returns
boolean
insertAfter()
insertAfter(
nodeToInsert
,restoreSelection
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1262
Inserts a node after this LexicalNode (as the next sibling).
Parameters
nodeToInsert
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
Inherited from
insertBefore()
insertBefore(
nodeToInsert
,restoreSelection
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1329
Inserts a node before this LexicalNode (as the previous sibling).
Parameters
nodeToInsert
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
Inherited from
insertNewAfter()
insertNewAfter(
selection
,restoreSelection?
):null
|LexicalNode
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:885
Parameters
selection
restoreSelection?
boolean
Returns
null
| LexicalNode
is()
is(
object
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:847
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
the node to perform the equality comparison on.
undefined
| null
| LexicalNode
Returns
boolean
Inherited from
isAttached()
isAttached():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:579
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
isBefore()
isBefore(
targetNode
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:865
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
the node we're testing to see if it's after this one.
Returns
boolean
Inherited from
isDirty()
isDirty():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:400
Returns true if this node has been marked dirty during this update cycle.
Returns
boolean
Inherited from
isEmpty()
isEmpty():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:397
Returns
boolean
isInline()
isInline():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:928
Returns
boolean
Inherited from
isLastChild()
isLastChild():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:405
Returns
boolean
isParentOf()
isParentOf(
targetNode
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:888
Returns true if this node is an ancestor of and distinct from the target node, false otherwise.
Parameters
targetNode
the would-be child node.
Returns
boolean
Inherited from
isParentRequired()
isParentRequired():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:1369
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
isSelected()
isSelected(
selection?
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:603
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?
The selection that we want to determine if the node is in.
null
| BaseSelection
Returns
boolean
Inherited from
isShadowRoot()
isShadowRoot():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:935
Returns
boolean
markDirty()
markDirty():
void
Defined in: packages/lexical/src/LexicalNode.ts:1438
Marks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.
Returns
void
Inherited from
remove()
remove(
preserveEmptyParent?
):void
Defined in: packages/lexical/src/LexicalNode.ts:1181
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
replace()
replace<
N
>(replaceWith
,includeChildren?
):N
Defined in: packages/lexical/src/LexicalNode.ts:1192
Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.
Type Parameters
N
N
extends LexicalNode
Parameters
replaceWith
N
The node to replace this one with.
includeChildren?
boolean
Whether or not to transfer the children of this node to the replacing node.
Returns
N
Inherited from
select()
select(
_anchorOffset?
,_focusOffset?
):RangeSelection
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:589
Parameters
_anchorOffset?
number
_focusOffset?
number
Returns
selectEnd()
selectEnd():
RangeSelection
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:638
Returns
Inherited from
selectNext()
selectNext(
anchorOffset?
,focusOffset?
):RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1417
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
Inherited from
selectPrevious()
selectPrevious(
anchorOffset?
,focusOffset?
):RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1395
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
Inherited from
selectStart()
selectStart():
RangeSelection
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:634
Returns
Inherited from
setDirection()
setDirection(
direction
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:651
Parameters
direction
null
| "ltr"
| "rtl"
Returns
this
setFormat()
setFormat(
type
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:656
Parameters
type
Returns
this
setIndent()
setIndent(
indentLevel
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:676
Parameters
indentLevel
number
Returns
this
setStyle()
setStyle(
style
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:661
Parameters
style
string
Returns
this
setTextFormat()
setTextFormat(
type
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:666
Parameters
type
number
Returns
this
setTextStyle()
setTextStyle(
style
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:671
Parameters
style
string
Returns
this
splice()
splice(
start
,deleteCount
,nodesToInsert
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:681
Parameters
start
number
deleteCount
number
nodesToInsert
Returns
this
updateDOM()
updateDOM(
_prevNode
,_dom
,_config
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:1071
Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.
Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.
Parameters
_prevNode
unknown
_dom
HTMLElement
_config
Returns
boolean
Inherited from
updateFromJSON()
updateFromJSON(
serializedNode
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:873
Update this LexicalNode instance from serialized JSON. It's recommended to implement as much logic as possible in this method instead of the static importJSON method, so that the functionality can be inherited in subclasses.
The LexicalUpdateJSON utility type should be used to ignore any type, version, or children properties in the JSON so that the extended JSON from subclasses are acceptable parameters for the super call.
If overridden, this method must call super.
Parameters
serializedNode
LexicalUpdateJSON
<SerializedElementNode
>
Returns
this
Example
class MyTextNode extends TextNode {
// ...
static importJSON(serializedNode: SerializedMyTextNode): MyTextNode {
return $createMyTextNode()
.updateFromJSON(serializedNode);
}
updateFromJSON(
serializedNode: LexicalUpdateJSON<SerializedMyTextNode>,
): this {
return super.updateFromJSON(serializedNode)
.setMyProperty(serializedNode.myProperty);
}
}
Inherited from
clone()
static
clone(_data
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:431
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
getType()
static
getType():string
Defined in: packages/lexical/src/LexicalNode.ts:415
Returns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.
Returns
string
importJSON()
static
importJSON(_serializedNode
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1116
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
Returns
transform()
static
transform():null
| (node
) =>void
Defined in: packages/lexical/src/LexicalNode.ts:1167
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
null
| (node
) => void
LineBreakNode
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:27
Extends
Constructors
Constructor
new LineBreakNode(
key?
):LineBreakNode
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:38
Parameters
key?
string
Returns
Overrides
LexicalNode.constructor
Methods
createDOM()
createDOM():
HTMLElement
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:46
Called during the reconciliation process to determine which nodes to insert into the DOM for this Lexical Node.
This method must return exactly one HTMLElement. Nested elements are not supported.
Do not attempt to update the Lexical EditorState during this phase of the update lifecycle.
Returns
HTMLElement
Overrides
getTextContent()
getTextContent(): "\n"
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:42
Returns the text content of the node. Override this for custom nodes that should have a representation in plain text format (for copy + paste, for example)
Returns
"\n"
Overrides
isInline()
isInline():
true
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:54
Returns
true
Overrides
updateDOM()
updateDOM():
false
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:50
Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.
Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.
Returns
false
Overrides
clone()
static
clone(node
):LineBreakNode
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:34
Clones this node, creating a new node with a different key and adding it to the EditorState (but not attaching it anywhere!). All nodes must implement this method.
Parameters
node
Returns
Overrides
LexicalNode.clone
getType()
static
getType():string
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:30
Returns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.
Returns
string
Overrides
LexicalNode.getType
importDOM()
static
importDOM():null
|DOMConversionMap
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:58
Returns
null
| DOMConversionMap
Overrides
LexicalNode.importDOM
importJSON()
static
importJSON(serializedLineBreakNode
):LineBreakNode
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:72
Controls how the this node is deserialized from JSON. This is usually boilerplate, but provides an abstraction between the node implementation and serialized interface that can be important if you ever make breaking changes to a node schema (by adding or removing properties). See Serialization & Deserialization.
Parameters
serializedLineBreakNode
Returns
Overrides
LexicalNode.importJSON
ParagraphNode
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:45
Extends
Methods
collapseAtStart()
collapseAtStart():
boolean
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:134
Returns
boolean
Overrides
createDOM()
createDOM(
config
):HTMLElement
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:59
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
Returns
HTMLElement
Overrides
exportDOM()
exportDOM(
editor
):DOMExportOutput
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:85
Controls how the this node is serialized to HTML. This is important for copy and paste between Lexical and non-Lexical editors, or Lexical editors with different namespaces, in which case the primary transfer format is HTML. It's also important if you're serializing to HTML for any other reason via $generateHtmlFromNodes. You could also use this method to build your own HTML renderer.
Parameters
editor
Returns
Overrides
exportJSON()
exportJSON():
SerializedParagraphNode
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:108
Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.
Returns
Overrides
insertNewAfter()
insertNewAfter(
rangeSelection
,restoreSelection
):ParagraphNode
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:119
Parameters
rangeSelection
restoreSelection
boolean
Returns
Overrides
updateDOM()
updateDOM(
prevNode
,dom
,config
):boolean
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:68
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
dom
HTMLElement
config
Returns
boolean
Overrides
clone()
static
clone(node
):ParagraphNode
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:53
Clones this node, creating a new node with a different key and adding it to the EditorState (but not attaching it anywhere!). All nodes must implement this method.
Parameters
node
Returns
Overrides
getType()
static
getType():string
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:49
Returns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.
Returns
string
Overrides
importDOM()
static
importDOM():null
|DOMConversionMap
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:76
Returns
null
| DOMConversionMap
Overrides
ElementNode.importDOM
importJSON()
static
importJSON(serializedNode
):ParagraphNode
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:104
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
Returns
Overrides
RootNode
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:25
Extends
Constructors
Constructor
new RootNode():
RootNode
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:37
Returns
Overrides
Methods
collapseAtStart()
collapseAtStart():
true
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:104
Returns
true
Overrides
getTextContent()
getTextContent():
string
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:49
Returns the text content of the node. Override this for custom nodes that should have a representation in plain text format (for copy + paste, for example)
Returns
string
Overrides
getTopLevelElementOrThrow()
getTopLevelElementOrThrow():
never
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:42
Returns the highest (in the EditorState tree) non-root ancestor of this node, or throws if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".
Returns
never
Overrides
ElementNode
.getTopLevelElementOrThrow
insertAfter()
insertAfter(
nodeToInsert
):LexicalNode
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:74
Inserts a node after this LexicalNode (as the next sibling).
Parameters
nodeToInsert
The node to insert after this one.
Returns
Overrides
insertBefore()
insertBefore(
nodeToInsert
):LexicalNode
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:70
Inserts a node before this LexicalNode (as the previous sibling).
Parameters
nodeToInsert
The node to insert before this one.
Returns
Overrides
remove()
remove():
never
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:62
Removes this LexicalNode from the EditorState. If the node isn't re-inserted somewhere, the Lexical garbage collector will eventually clean it up.
Returns
never
Overrides
replace()
replace<
N
>(node
):never
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:66
Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.
Type Parameters
N
N
= LexicalNode
Parameters
node
N
Returns
never
Overrides
splice()
splice(
start
,deleteCount
,nodesToInsert
):this
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:85
Parameters
start
number
deleteCount
number
nodesToInsert
Returns
this
Overrides
updateDOM()
updateDOM(
prevNode
,dom
):false
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:80
Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.
Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.
Parameters
prevNode
this
dom
HTMLElement
Returns
false
Overrides
clone()
static
clone():RootNode
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:33
Clones this node, creating a new node with a different key and adding it to the EditorState (but not attaching it anywhere!). All nodes must implement this method.
Returns
Overrides
getType()
static
getType():string
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:29
Returns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.
Returns
string
Overrides
importJSON()
static
importJSON(serializedNode
):RootNode
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:99
Controls how the this node is deserialized from JSON. This is usually boilerplate, but provides an abstraction between the node implementation and serialized interface that can be important if you ever make breaking changes to a node schema (by adding or removing properties). See Serialization & Deserialization.
Parameters
serializedNode
Returns
Overrides
TabNode
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:27
Extends
Constructors
Constructor
new TabNode(
key?
):TabNode
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:36
Parameters
key?
string
Returns
Overrides
Methods
canInsertTextAfter()
canInsertTextAfter():
boolean
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:96
This method is meant to be overridden by TextNode subclasses to control the behavior of those nodes when a user event would cause text to be inserted after them in the editor. If true, Lexical will attempt to insert text into this node. If false, it will insert the text in a new sibling node.
Returns
boolean
true if text can be inserted after the node, false otherwise.
Overrides
canInsertTextBefore()
canInsertTextBefore():
boolean
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:92
This method is meant to be overridden by TextNode subclasses to control the behavior of those nodes when a user event would cause text to be inserted before them in the editor. If true, Lexical will attempt to insert text into this node. If false, it will insert the text in a new sibling node.
Returns
boolean
true if text can be inserted before the node, false otherwise.
Overrides
createDOM()
createDOM(
config
):HTMLElement
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:45
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
Returns
HTMLElement
Overrides
setDetail()
setDetail(
detail
):this
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:82
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
TextDetailType or 32-bit integer representing the node detail.
number
| TextDetailType
Returns
this
this TextNode.
// TODO 0.12 This should just be a string
.
Overrides
setMode()
setMode(
type
):this
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:87
Sets the mode of the node.
Parameters
type
Returns
this
this TextNode.
Overrides
setTextContent()
setTextContent(
text
):this
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:60
Sets the text content of the node.
Parameters
text
string
the string to set as the text value of the node.
Returns
this
this TextNode.
Overrides
spliceText()
spliceText(
offset
,delCount
,newText
,moveSelection?
):TextNode
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:68
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
this TextNode.
Overrides
clone()
static
clone(node
):TabNode
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:32
Clones this node, creating a new node with a different key and adding it to the EditorState (but not attaching it anywhere!). All nodes must implement this method.
Parameters
node
Returns
Overrides
getType()
static
getType():string
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:28
Returns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.
Returns
string
Overrides
importDOM()
static
importDOM():null
|DOMConversionMap
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:41
Returns
null
| DOMConversionMap
Overrides
importJSON()
static
importJSON(serializedTabNode
):TabNode
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:56
Controls how the this node is deserialized from JSON. This is usually boilerplate, but provides an abstraction between the node implementation and serialized interface that can be important if you ever make breaking changes to a node schema (by adding or removing properties). See Serialization & Deserialization.
Parameters
serializedTabNode
Returns
Overrides
TextNode
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:287
Extends
Extended by
Constructors
Constructor
new TextNode(
text
,key?
):TextNode
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:324
Parameters
text
string
= ''
key?
string
Returns
Properties
__text
__text:
string
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:297
Methods
$config()
$config():
BaseStaticNodeConfig
Defined in: packages/lexical/src/LexicalNode.ts:454
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
Example
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Inherited from
afterCloneFrom()
afterCloneFrom(
prevNode
):void
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:315
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
canHaveFormat()
canHaveFormat():
boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:474
Returns
boolean
true if the text node supports font styling, false otherwise.
canInsertTextAfter()
canInsertTextAfter():
boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:941
This method is meant to be overridden by TextNode subclasses to control the behavior of those nodes when a user event would cause text to be inserted after them in the editor. If true, Lexical will attempt to insert text into this node. If false, it will insert the text in a new sibling node.
Returns
boolean
true if text can be inserted after the node, false otherwise.
canInsertTextBefore()
canInsertTextBefore():
boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:930
This method is meant to be overridden by TextNode subclasses to control the behavior of those nodes when a user event would cause text to be inserted before them in the editor. If true, Lexical will attempt to insert text into this node. If false, it will insert the text in a new sibling node.
Returns
boolean
true if text can be inserted before the node, false otherwise.
config()
config<
Type
,Config
>(type
,config
):StaticNodeConfigRecord
<Type
,Config
>
Defined in: packages/lexical/src/LexicalNode.ts:463
This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.
Type Parameters
Type
Type
extends string
Config
Config
extends StaticNodeConfigValue
<TextNode
, Type
>
Parameters
type
Type
config
Config
Returns
StaticNodeConfigRecord
<Type
, Config
>
Inherited from
createDOM()
createDOM(
config
,editor?
):HTMLElement
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:487
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
editor?
Returns
HTMLElement
Inherited from
createParentElementNode()
createParentElementNode():
ElementNode
Defined in: packages/lexical/src/LexicalNode.ts:1377
The creation logic for any required parent. Should be implemented if isParentRequired returns true.
Returns
Inherited from
LexicalNode
.createParentElementNode
exportDOM()
exportDOM(
editor
):DOMExportOutput
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:643
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
Returns
Inherited from
exportJSON()
exportJSON():
SerializedTextNode
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:681
Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.
Returns
Inherited from
getCommonAncestor()
getCommonAncestor<
T
>(node
):null
|T
Defined in: packages/lexical/src/LexicalNode.ts:830
Type Parameters
T
T
extends ElementNode
= ElementNode
Parameters
node
the other node to find the common ancestor of.
Returns
null
| T
Deprecated
Returns the closest common ancestor of this node and the provided one or null if one cannot be found.
Inherited from
getDetail()
getDetail():
number
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:351
Returns a 32-bit integer that represents the TextDetailTypes currently applied to the TextNode. You probably don't want to use this method directly - consider using TextNode.isDirectionless or TextNode.isUnmergeable instead.
Returns
number
a number representing the detail of the text node.
getFormat()
getFormat():
number
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:339
Returns a 32-bit integer that represents the TextFormatTypes currently applied to the TextNode. You probably don't want to use this method directly - consider using TextNode.hasFormat instead.
Returns
number
a number representing the format of the text node.
getFormatFlags()
getFormatFlags(
type
,alignWithFormat
):number
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:464
Returns the format flags applied to the node as a 32-bit integer.
Parameters
type
alignWithFormat
null
| number
Returns
number
a number representing the TextFormatTypes applied to the node.
getIndexWithinParent()
getIndexWithinParent():
number
Defined in: packages/lexical/src/LexicalNode.ts:656
Returns the zero-based index of this node within the parent.
Returns
number
Inherited from
LexicalNode
.getIndexWithinParent
getKey()
getKey():
string
Defined in: packages/lexical/src/LexicalNode.ts:648
Returns this nodes key.
Returns
string
Inherited from
getLatest()
getLatest():
this
Defined in: packages/lexical/src/LexicalNode.ts:981
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
getMode()
getMode():
TextModeType
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:361
Returns the mode (TextModeType) of the TextNode, which may be "normal", "token", or "segmented"
Returns
TextModeType.
getNextSibling()
getNextSibling<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:801
Returns the "next" siblings - that is, the node that comes after this one in the same parent
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
Inherited from
getNextSiblings()
getNextSiblings<
T
>():T
[]
Defined in: packages/lexical/src/LexicalNode.ts:812
Returns all "next" siblings - that is, the nodes that come between this one and the last child of it's parent, inclusive.
Type Parameters
T
T
extends LexicalNode
Returns
T
[]
Inherited from
getNodesBetween()
getNodesBetween(
targetNode
):LexicalNode
[]
Defined in: packages/lexical/src/LexicalNode.ts:900
Returns a list of nodes that are between this node and the target node in the EditorState.
Parameters
targetNode
the node that marks the other end of the range of nodes to be returned.
Returns
Inherited from
getParent()
getParent<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:676
Returns the parent of this node, or null if none is found.
Type Parameters
T
T
extends ElementNode
Returns
null
| T
Inherited from
getParentKeys()
getParentKeys():
string
[]
Defined in: packages/lexical/src/LexicalNode.ts:753
Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.
Returns
string
[]
Inherited from
getParentOrThrow()
getParentOrThrow<
T
>():T
Defined in: packages/lexical/src/LexicalNode.ts:687
Returns the parent of this node, or throws if none is found.
Type Parameters
T
T
extends ElementNode
Returns
T
Inherited from
getParents()
getParents():
ElementNode
[]
Defined in: packages/lexical/src/LexicalNode.ts:738
Returns a list of the every ancestor of this node, all the way up to the RootNode.
Returns
Inherited from
getPreviousSibling()
getPreviousSibling<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:768
Returns the "previous" siblings - that is, the node that comes before this one in the same parent.
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
Inherited from
LexicalNode
.getPreviousSibling
getPreviousSiblings()
getPreviousSiblings<
T
>():T
[]
Defined in: packages/lexical/src/LexicalNode.ts:779
Returns the "previous" siblings - that is, the nodes that come between this one and the first child of it's parent, inclusive.
Type Parameters
T
T
extends LexicalNode
Returns
T
[]
Inherited from
LexicalNode
.getPreviousSiblings
getStyle()
getStyle():
string
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:371
Returns the styles currently applied to the node. This is analogous to CSSText in the DOM.
Returns
string
CSSText-like string of styles applied to the underlying DOM node.
getTextContent()
getTextContent():
string
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:454
Returns the text content of the node as a string.
Returns
string
a string representing the text content of the node.
Inherited from
getTextContentSize()
getTextContentSize():
number
Defined in: packages/lexical/src/LexicalNode.ts:1039
Returns the length of the string produced by calling getTextContent on this node.
Returns
number
Inherited from
LexicalNode
.getTextContentSize
getTopLevelElement()
getTopLevelElement():
null
|ElementNode
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:288
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
null
| ElementNode
Inherited from
LexicalNode
.getTopLevelElement
getTopLevelElementOrThrow()
getTopLevelElementOrThrow():
ElementNode
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:289
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
Inherited from
LexicalNode
.getTopLevelElementOrThrow
getType()
getType():
string
Defined in: packages/lexical/src/LexicalNode.ts:562
Returns the string type of this node.
Returns
string
Inherited from
getWritable()
getWritable():
this
Defined in: packages/lexical/src/LexicalNode.ts:998
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
hasFormat()
hasFormat(
type
):boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:434
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
the TextFormatType to check for.
Returns
boolean
true if the node has the provided format, false otherwise.
insertAfter()
insertAfter(
nodeToInsert
,restoreSelection
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1262
Inserts a node after this LexicalNode (as the next sibling).
Parameters
nodeToInsert
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
Inherited from
insertBefore()
insertBefore(
nodeToInsert
,restoreSelection
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1329
Inserts a node before this LexicalNode (as the previous sibling).
Parameters
nodeToInsert
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
Inherited from
is()
is(
object
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:847
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
the node to perform the equality comparison on.
undefined
| null
| LexicalNode
Returns
boolean
Inherited from
isAttached()
isAttached():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:579
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
isBefore()
isBefore(
targetNode
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:865
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
the node we're testing to see if it's after this one.
Returns
boolean
Inherited from
isComposing()
isComposing():
boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:392
Returns
boolean
true if Lexical detects that an IME or other 3rd-party script is attempting to mutate the TextNode, false otherwise.
isDirectionless()
isDirectionless():
boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:411
Returns whether or not the node is "directionless". Directionless nodes don't respect changes between RTL and LTR modes.
Returns
boolean
true if the node is directionless, false otherwise.
isDirty()
isDirty():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:970
Returns true if this node has been marked dirty during this update cycle.
Returns
boolean
Inherited from
isInline()
isInline():
true
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:481
Returns
true
true if the text node is inline, false otherwise.
Inherited from
isParentOf()
isParentOf(
targetNode
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:888
Returns true if this node is an ancestor of and distinct from the target node, false otherwise.
Parameters
targetNode
the would-be child node.
Returns
boolean
Inherited from
isParentRequired()
isParentRequired():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:1369
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
isSegmented()
isSegmented():
boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:402
Returns whether or not the node is in "segmented" mode. TextNodes in segmented mode can be navigated through character-by-character with a RangeSelection, but are deleted in space-delimited "segments".
Returns
boolean
true if the node is in segmented mode, false otherwise.
isSelected()
isSelected(
selection?
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:603
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?
The selection that we want to determine if the node is in.
null
| BaseSelection
Returns
boolean
Inherited from
isSimpleText()
isSimpleText():
boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:445
Returns whether or not the node is simple text. Simple text is defined as a TextNode that has the string type "text" (i.e., not a subclass) and has no mode applied to it (i.e., not segmented or token).
Returns
boolean
true if the node is simple text, false otherwise.
isTextEntity()
isTextEntity():
boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1173
This method is meant to be overridden by TextNode subclasses to control the behavior of those nodes when used with the registerLexicalTextEntity function. If you're using registerLexicalTextEntity, the node class that you create and replace matched text with should return true from this method.
Returns
boolean
true if the node is to be treated as a "text entity", false otherwise.
isToken()
isToken():
boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:382
Returns whether or not the node is in "token" mode. TextNodes in token mode can be navigated through character-by-character with a RangeSelection, but are deleted as a single entity (not individually by character).
Returns
boolean
true if the node is in token mode, false otherwise.
isUnmergeable()
isUnmergeable():
boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:421
Returns whether or not the node is unmergeable. In some scenarios, Lexical tries to merge adjacent TextNodes into a single TextNode. If a TextNode is unmergeable, this won't happen.
Returns
boolean
true if the node is unmergeable, false otherwise.
markDirty()
markDirty():
void
Defined in: packages/lexical/src/LexicalNode.ts:1438
Marks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.
Returns
void
Inherited from
mergeWithSibling()
mergeWithSibling(
target
):TextNode
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1118
Merges the target TextNode into this TextNode, removing the target node.
Parameters
target
the TextNode to merge into this one.
Returns
this TextNode.
remove()
remove(
preserveEmptyParent?
):void
Defined in: packages/lexical/src/LexicalNode.ts:1181
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
replace()
replace<
N
>(replaceWith
,includeChildren?
):N
Defined in: packages/lexical/src/LexicalNode.ts:1192
Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.
Type Parameters
N
N
extends LexicalNode
Parameters
replaceWith
N
The node to replace this one with.
includeChildren?
boolean
Whether or not to transfer the children of this node to the replacing node.
Returns
N
Inherited from
select()
select(
_anchorOffset?
,_focusOffset?
):RangeSelection
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:828
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
the new RangeSelection.
selectEnd()
selectEnd():
RangeSelection
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:873
Returns
Inherited from
selectionTransform()
selectionTransform(
prevSelection
,nextSelection
):void
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:696
Parameters
prevSelection
null
| BaseSelection
nextSelection
Returns
void
selectNext()
selectNext(
anchorOffset?
,focusOffset?
):RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1417
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
Inherited from
selectPrevious()
selectPrevious(
anchorOffset?
,focusOffset?
):RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1395
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
Inherited from
selectStart()
selectStart():
RangeSelection
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:869
Returns
Inherited from
setDetail()
setDetail(
detail
):this
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:731
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
TextDetailType or 32-bit integer representing the node detail.
number
| TextDetailType
Returns
this
this TextNode.
// TODO 0.12 This should just be a string
.
setFormat()
setFormat(
format
):this
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:713
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
TextFormatType or 32-bit integer representing the node format.
number
| TextFormatType
Returns
this
this TextNode.
// TODO 0.12 This should just be a string
.
setMode()
setMode(
type
):this
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:794
Sets the mode of the node.
Parameters
type
Returns
this
this TextNode.
setStyle()
setStyle(
style
):this
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:746
Sets the node style to the provided CSSText-like string. Set this property as you would an HTMLElement style attribute to apply inline styles to the underlying DOM Element.
Parameters
style
string
CSSText to be applied to the underlying HTMLElement.
Returns
this
this TextNode.
setTextContent()
setTextContent(
text
):this
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:811
Sets the text content of the node.
Parameters
text
string
the string to set as the text value of the node.
Returns
this
this TextNode.
spliceText()
spliceText(
offset
,delCount
,newText
,moveSelection?
):TextNode
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:889
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
this TextNode.
splitText()
splitText(...
splitOffsets
):TextNode
[]
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:953
Splits this TextNode at the provided character offsets, forming new TextNodes from the substrings formed by the split, and inserting those new TextNodes into the editor, replacing the one that was split.
Parameters
splitOffsets
...number
[]
rest param of the text content character offsets at which this node should be split.
Returns
TextNode
[]
an Array containing the newly-created TextNodes.
toggleDirectionless()
toggleDirectionless():
this
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:772
Toggles the directionless detail value of the node. Prefer using this method over setDetail.
Returns
this
this TextNode.
toggleFormat()
toggleFormat(
type
):this
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:761
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 to toggle.
Returns
this
this TextNode.
toggleUnmergeable()
toggleUnmergeable():
this
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:783
Toggles the unmergeable detail value of the node. Prefer using this method over setDetail.
Returns
this
this TextNode.
updateDOM()
updateDOM(
prevNode
,dom
,config
):boolean
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:510
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
Returns
boolean
Inherited from
updateFromJSON()
updateFromJSON(
serializedNode
):this
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:630
Update this LexicalNode instance from serialized JSON. It's recommended to implement as much logic as possible in this method instead of the static importJSON method, so that the functionality can be inherited in subclasses.
The LexicalUpdateJSON utility type should be used to ignore any type, version, or children properties in the JSON so that the extended JSON from subclasses are acceptable parameters for the super call.
If overridden, this method must call super.
Parameters
serializedNode
LexicalUpdateJSON
<SerializedTextNode
>
Returns
this
Example
class MyTextNode extends TextNode {
// ...
static importJSON(serializedNode: SerializedMyTextNode): MyTextNode {
return $createMyTextNode()
.updateFromJSON(serializedNode);
}
updateFromJSON(
serializedNode: LexicalUpdateJSON<SerializedMyTextNode>,
): this {
return super.updateFromJSON(serializedNode)
.setMyProperty(serializedNode.myProperty);
}
}
Inherited from
clone()
static
clone(node
):TextNode
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:311
Clones this node, creating a new node with a different key and adding it to the EditorState (but not attaching it anywhere!). All nodes must implement this method.
Parameters
node
Returns
getType()
static
getType():string
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:307
Returns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.
Returns
string
importDOM()
static
importDOM():null
|DOMConversionMap
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:573
Returns
null
| DOMConversionMap
importJSON()
static
importJSON(serializedNode
):TextNode
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:626
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
Returns
transform()
static
transform():null
| (node
) =>void
Defined in: packages/lexical/src/LexicalNode.ts:1167
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
null
| (node
) => void
Interfaces
BaseCaret<T, D, Type>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:47
Extends
Iterable
<SiblingCaret
<LexicalNode
,D
>>
Extended by
Type Parameters
T
T
extends LexicalNode
D
D
extends CaretDirection
Type
Type
Properties
direction
readonly
direction:D
Defined in: packages/lexical/src/caret/LexicalCaret.ts:57
next if pointing at the next sibling or first child, previous if pointing at the previous sibling or last child
getAdjacentCaret()
getAdjacentCaret: () =>
null
|SiblingCaret
<LexicalNode
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:63
Get a new SiblingCaret from getNodeAtCaret() in the same direction.
Returns
null
| SiblingCaret
<LexicalNode
, D
>
getNodeAtCaret()
getNodeAtCaret: () =>
null
|LexicalNode
Defined in: packages/lexical/src/caret/LexicalCaret.ts:61
Get the node connected to the origin in the caret's direction, or null if there is no node
Returns
null
| LexicalNode
getParentAtCaret()
getParentAtCaret: () =>
null
|ElementNode
Defined in: packages/lexical/src/caret/LexicalCaret.ts:59
Get the ElementNode that is the logical parent (origin
for ChildCaret
, origin.getParent()
for SiblingCaret
)
Returns
null
| ElementNode
getSiblingCaret()
getSiblingCaret: () =>
SiblingCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:67
Get a new SiblingCaret with this same node
Returns
SiblingCaret
<T
, D
>
insert()
insert: (
node
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:75
Insert a node connected to origin in this direction (before the node that this caret is pointing towards, if any existed).
For a SiblingCaret
this is origin.insertAfter(node)
for next, or origin.insertBefore(node)
for previous.
For a ChildCaret
this is origin.splice(0, 0, [node])
for next or origin.append(node)
for previous.
Parameters
node
Returns
this
origin
readonly
origin:T
Defined in: packages/lexical/src/caret/LexicalCaret.ts:53
The origin node of this caret, typically this is what you will use in traversals
remove()
remove: () =>
this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:69
Remove the getNodeAtCaret() node that this caret is pointing towards, if it exists
Returns
this
replaceOrInsert()
replaceOrInsert: (
node
,includeChildren?
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:77
If getNodeAtCaret() is not null then replace it with node, otherwise insert node
Parameters
node
includeChildren?
boolean
Returns
this
splice()
splice: (
deleteCount
,nodes
,nodesDirection?
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:85
Splice an iterable (typically an Array) of nodes into this location.
Parameters
deleteCount
number
The number of existing nodes to replace or delete
nodes
Iterable
<LexicalNode
>
An iterable of nodes that will be inserted in this location, using replace instead of insert for the first deleteCount nodes
nodesDirection?
The direction of the nodes iterable, defaults to 'next'
Returns
this
type
readonly
type:Type
Defined in: packages/lexical/src/caret/LexicalCaret.ts:55
sibling for a SiblingCaret (pointing at the next or previous sibling) or child for a ChildCaret (pointing at the first or last child)
BaseSelection
Defined in: packages/lexical/src/LexicalSelection.ts:344
Properties
_cachedNodes
_cachedNodes:
null
|LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:345
dirty
dirty:
boolean
Defined in: packages/lexical/src/LexicalSelection.ts:346
Methods
clone()
clone():
BaseSelection
Defined in: packages/lexical/src/LexicalSelection.ts:348
Returns
extract()
extract():
LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:349
Returns
getCachedNodes()
getCachedNodes():
null
|LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:359
Returns
null
| LexicalNode
[]
getNodes()
getNodes():
LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:350
Returns
getStartEndPoints()
Defined in: packages/lexical/src/LexicalSelection.ts:356
Returns
getTextContent()
getTextContent():
string
Defined in: packages/lexical/src/LexicalSelection.ts:351
Returns
string
insertNodes()
insertNodes(
nodes
):void
Defined in: packages/lexical/src/LexicalSelection.ts:355
Parameters
nodes
Returns
void
insertRawText()
insertRawText(
text
):void
Defined in: packages/lexical/src/LexicalSelection.ts:353
Parameters
text
string
Returns
void
insertText()
insertText(
text
):void
Defined in: packages/lexical/src/LexicalSelection.ts:352
Parameters
text
string
Returns
void
is()
is(
selection
):boolean
Defined in: packages/lexical/src/LexicalSelection.ts:354
Parameters
selection
null
| BaseSelection
Returns
boolean
isBackward()
isBackward():
boolean
Defined in: packages/lexical/src/LexicalSelection.ts:358
Returns
boolean
isCollapsed()
isCollapsed():
boolean
Defined in: packages/lexical/src/LexicalSelection.ts:357
Returns
boolean
setCachedNodes()
setCachedNodes(
nodes
):void
Defined in: packages/lexical/src/LexicalSelection.ts:360
Parameters
nodes
null
| LexicalNode
[]
Returns
void
CaretRange<D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:95
A RangeSelection expressed as a pair of Carets
Extends
Iterable
<NodeCaret
<D
>>
Type Parameters
D
D
extends CaretDirection
= CaretDirection
Properties
anchor
anchor:
PointCaret
<D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:99
direction
readonly
direction:D
Defined in: packages/lexical/src/caret/LexicalCaret.ts:98
focus
focus:
PointCaret
<D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:100
getTextSlices()
getTextSlices: () =>
TextPointCaretSliceTuple
<D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:122
There are between zero and two non-null TextSliceCarets for a CaretRange. Note that when anchor and focus share an origin node the second element will be null because the slice is entirely represented by the first element.
[slice, slice]
: anchor and focus are TextPointCaret with distinct origin nodes
[slice, null]
: anchor is a TextPointCaret
[null, slice]
: focus is a TextPointCaret
[null, null]
: Neither anchor nor focus are TextPointCarets
Returns
isCollapsed()
isCollapsed: () =>
boolean
Defined in: packages/lexical/src/caret/LexicalCaret.ts:102
Return true if anchor and focus are the same caret
Returns
boolean
iterNodeCarets()
iterNodeCarets: (
rootMode?
) =>IterableIterator
<NodeCaret
<D
>>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:111
Iterate the carets between anchor and focus in a pre-order fashion, note that this does not include any text slices represented by the anchor and/or focus. Those are accessed separately from getTextSlices.
An ElementNode origin will be yielded as a ChildCaret on enter, and a SiblingCaret on leave.
Parameters
rootMode?
Returns
IterableIterator
<NodeCaret
<D
>>
type
readonly
type:"node-caret-range"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:97
Methods
[iterator]()
[iterator]():
Iterator
<NodeCaret
<D
>,any
,any
>
Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:49
Returns
Iterator
<NodeCaret
<D
>, any
, any
>
Inherited from
Iterable.[iterator]
ChildCaret<T, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:227
A ChildCaret points from an origin ElementNode towards its first or last child.
Extends
BaseCaret
<T
,D
,"child"
>
Type Parameters
T
T
extends ElementNode
= ElementNode
D
D
extends CaretDirection
= CaretDirection
Properties
direction
readonly
direction:D
Defined in: packages/lexical/src/caret/LexicalCaret.ts:57
next if pointing at the next sibling or first child, previous if pointing at the previous sibling or last child
Inherited from
getAdjacentCaret()
getAdjacentCaret: () =>
null
|SiblingCaret
<LexicalNode
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:63
Get a new SiblingCaret from getNodeAtCaret() in the same direction.
Returns
null
| SiblingCaret
<LexicalNode
, D
>
Inherited from
getChildCaret()
getChildCaret: () =>
this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:236
Return this, the ChildCaret is already a child caret of its origin
Returns
this
getFlipped()
getFlipped: () =>
NodeCaret
<FlipDirection
<D
>>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:264
Get a new NodeCaret with the head and tail of its directional arrow flipped, such that flipping twice is the identity. For example, given a non-empty parent with a firstChild and lastChild, and a second emptyParent node with no children:
Returns
Example
caret.getFlipped().getFlipped().is(caret) === true;
$getChildCaret(parent, 'next').getFlipped().is($getSiblingCaret(firstChild, 'previous')) === true;
$getSiblingCaret(lastChild, 'next').getFlipped().is($getChildCaret(parent, 'previous')) === true;
$getSiblingCaret(firstChild, 'next).getFlipped().is($getSiblingCaret(lastChild, 'previous')) === true;
$getChildCaret(emptyParent, 'next').getFlipped().is($getChildCaret(emptyParent, 'previous')) === true;
getLatest()
getLatest: () =>
ChildCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:232
Get a new caret with the latest origin pointer
Returns
ChildCaret
<T
, D
>
getNodeAtCaret()
getNodeAtCaret: () =>
null
|LexicalNode
Defined in: packages/lexical/src/caret/LexicalCaret.ts:61
Get the node connected to the origin in the caret's direction, or null if there is no node
Returns
null
| LexicalNode
Inherited from
getParentAtCaret()
getParentAtCaret: () =>
T
Defined in: packages/lexical/src/caret/LexicalCaret.ts:234
Get the ElementNode that is the logical parent (origin
for ChildCaret
, origin.getParent()
for SiblingCaret
)
Returns
T
Overrides
getParentCaret()
getParentCaret: (
mode?
) =>null
|SiblingCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:233
Parameters
mode?
Returns
null
| SiblingCaret
<T
, D
>
getSiblingCaret()
getSiblingCaret: () =>
SiblingCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:67
Get a new SiblingCaret with this same node
Returns
SiblingCaret
<T
, D
>
Inherited from
insert()
insert: (
node
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:75
Insert a node connected to origin in this direction (before the node that this caret is pointing towards, if any existed).
For a SiblingCaret
this is origin.insertAfter(node)
for next, or origin.insertBefore(node)
for previous.
For a ChildCaret
this is origin.splice(0, 0, [node])
for next or origin.append(node)
for previous.
Parameters
node
Returns
this
Inherited from
isSameNodeCaret()
isSameNodeCaret: (
other
) =>other is ChildCaret<T, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:241
Return true if other is a ChildCaret with the same origin (by node key comparison) and direction.
Parameters
other
undefined
| null
| PointCaret
<CaretDirection
>
Returns
other is ChildCaret<T, D>
isSamePointCaret()
isSamePointCaret: (
other
) =>other is ChildCaret<T, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:248
Return true if other is a ChildCaret with the same origin (by node key comparison) and direction.
Parameters
other
undefined
| null
| PointCaret
<CaretDirection
>
Returns
other is ChildCaret<T, D>
origin
readonly
origin:T
Defined in: packages/lexical/src/caret/LexicalCaret.ts:53
The origin node of this caret, typically this is what you will use in traversals
Inherited from
remove()
remove: () =>
this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:69
Remove the getNodeAtCaret() node that this caret is pointing towards, if it exists
Returns
this
Inherited from
replaceOrInsert()
replaceOrInsert: (
node
,includeChildren?
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:77
If getNodeAtCaret() is not null then replace it with node, otherwise insert node
Parameters
node
includeChildren?
boolean
Returns
this
Inherited from
splice()
splice: (
deleteCount
,nodes
,nodesDirection?
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:85
Splice an iterable (typically an Array) of nodes into this location.
Parameters
deleteCount
number
The number of existing nodes to replace or delete
nodes
Iterable
<LexicalNode
>
An iterable of nodes that will be inserted in this location, using replace instead of insert for the first deleteCount nodes
nodesDirection?
The direction of the nodes iterable, defaults to 'next'
Returns
this
Inherited from
type
readonly
type:"child"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:55
sibling for a SiblingCaret (pointing at the next or previous sibling) or child for a ChildCaret (pointing at the first or last child)
Inherited from
CommonAncestorResultAncestor<A>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1308
Node a is an ancestor of node b, and not the same node
Type Parameters
A
A
extends ElementNode
Properties
commonAncestor
readonly
commonAncestor:A
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1310
type
readonly
type:"ancestor"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1309
CommonAncestorResultBranch<A, B>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1318
Node a and node b have a common ancestor but are on different branches,
the a
and b
properties of this result are the ancestors of a and b
that are children of the commonAncestor. Since they are siblings, their
positions are comparable to determine order in the document.
Type Parameters
A
A
extends LexicalNode
B
B
extends LexicalNode
Properties
a
readonly
a:ElementNode
|A
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1325
The ancestor of a
that is a child of commonAncestor
b
readonly
b:ElementNode
|B
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1327
The ancestor of b
that is a child of commonAncestor
commonAncestor
readonly
commonAncestor:ElementNode
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1323
type
readonly
type:"branch"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1322
CommonAncestorResultDescendant<B>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1301
Node a was a descendant of node b, and not the same node
Type Parameters
B
B
extends ElementNode
Properties
commonAncestor
readonly
commonAncestor:B
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1303
type
readonly
type:"descendant"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1302
CommonAncestorResultSame<A>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1294
The two compared nodes are the same
Type Parameters
A
A
extends LexicalNode
Properties
commonAncestor
readonly
commonAncestor:A
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1296
type
readonly
type:"same"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1295
EditorState
Defined in: packages/lexical/src/LexicalEditorState.ts:98
Properties
_flushSync
_flushSync:
boolean
Defined in: packages/lexical/src/LexicalEditorState.ts:101
_nodeMap
_nodeMap:
NodeMap
Defined in: packages/lexical/src/LexicalEditorState.ts:99
_readOnly
_readOnly:
boolean
Defined in: packages/lexical/src/LexicalEditorState.ts:102
_selection
_selection:
null
|BaseSelection
Defined in: packages/lexical/src/LexicalEditorState.ts:100
Methods
clone()
clone(
selection?
):EditorState
Defined in: packages/lexical/src/LexicalEditorState.ts:123
Parameters
selection?
null
| BaseSelection
Returns
isEmpty()
isEmpty():
boolean
Defined in: packages/lexical/src/LexicalEditorState.ts:111
Returns
boolean
read()
read<
V
>(callbackFn
,options?
):V
Defined in: packages/lexical/src/LexicalEditorState.ts:115
Type Parameters
V
V
Parameters
callbackFn
() => V
options?
Returns
V
toJSON()
toJSON():
SerializedEditorState
Defined in: packages/lexical/src/LexicalEditorState.ts:132
Returns
EditorStateReadOptions
Defined in: packages/lexical/src/LexicalEditorState.ts:94
Properties
editor?
optional
editor:null
|LexicalEditor
Defined in: packages/lexical/src/LexicalEditorState.ts:95
ElementDOMSlot<T>
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:86
A utility class for managing the DOM children of an ElementNode
Type Parameters
T
T
extends HTMLElement
= HTMLElement
Properties
after
readonly
after:null
|Node
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:89
before
readonly
before:null
|Node
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:88
element
readonly
element:T
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:87
Methods
getFirstChild()
getFirstChild():
null
|ChildNode
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:168
Returns the first managed child of this node, which will either be this.after.nextSibling or this.element.firstChild, and will never be this.before if it is defined.
Returns
null
| ChildNode
insertChild()
insertChild(
dom
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:129
Insert the given child before this.before and any reconciler managed line break node, or append it if this.before is not defined
Parameters
dom
Node
Returns
this
removeChild()
removeChild(
dom
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:141
Remove the managed child from this container, will throw if it was not already there
Parameters
dom
Node
Returns
this
replaceChild()
replaceChild(
dom
,prevDom
):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:155
Replace managed child prevDom with dom. Will throw if prevDom is not a child
Parameters
dom
Node
The new node to replace prevDom
prevDom
Node
the node that will be replaced
Returns
this
withAfter()
withAfter(
after
):ElementDOMSlot
<T
>
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:111
Return a new ElementDOMSlot where all managed children will be inserted after this node
Parameters
after
undefined
| null
| Node
Returns
withBefore()
withBefore(
before
):ElementDOMSlot
<T
>
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:105
Return a new ElementDOMSlot where all managed children will be inserted before this node
Parameters
before
undefined
| null
| Node
Returns
withElement()
withElement<
ElementType
>(element
):ElementDOMSlot
<ElementType
>
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:117
Return a new ElementDOMSlot with an updated root element
Type Parameters
ElementType
ElementType
extends HTMLElement
Parameters
element
ElementType
Returns
ElementDOMSlot
<ElementType
>
GetComposedRangesOptions
Defined in: packages/lexical/src/LexicalSelection.ts:105
Options for the getComposedRanges() method. Allows specifying which shadow roots should be included when computing composed ranges.
Properties
shadowRoots?
optional
shadowRoots:ShadowRoot
[]
Defined in: packages/lexical/src/LexicalSelection.ts:106
LexicalEditor
Defined in: packages/lexical/src/LexicalEditor.ts:644
Methods
blur()
blur():
void
Defined in: packages/lexical/src/LexicalEditor.ts:1377
Removes focus from the editor.
Returns
void
dispatchCommand()
dispatchCommand<
TCommand
>(type
,payload
):boolean
Defined in: packages/lexical/src/LexicalEditor.ts:1109
Dispatches a command of the specified type with the specified payload. This triggers all command listeners (set by LexicalEditor.registerCommand) for this type, passing them the provided payload. The command listeners will be triggered in an implicit LexicalEditor.update, unless this was invoked from inside an update in which case that update context will be re-used (as if this was a dollar function itself).
Type Parameters
TCommand
TCommand
extends LexicalCommand
<unknown
>
Parameters
type
TCommand
the type of command listeners to trigger.
payload
CommandPayloadType
<TCommand
>
the data to pass as an argument to the command listeners.
Returns
boolean
focus()
focus(
callbackFn?
,options?
):void
Defined in: packages/lexical/src/LexicalEditor.ts:1336
Focuses the editor by marking the existing selection as dirty, or by
creating a new selection at defaultSelection
if one does not already
exist. If you want to force a specific selection, you should call
root.selectStart()
or root.selectEnd()
in an update.
Parameters
callbackFn?
() => void
A function to run after the editor is focused.
options?
EditorFocusOptions
= {}
A bag of options
Returns
void
getDecorators()
getDecorators<
T
>():Record
<NodeKey
,T
>
Defined in: packages/lexical/src/LexicalEditor.ts:1120
Gets a map of all decorators in the editor.
Type Parameters
T
T
Returns
Record
<NodeKey
, T
>
A mapping of call decorator keys to their decorated content
getEditorState()
getEditorState():
EditorState
Defined in: packages/lexical/src/LexicalEditor.ts:1229
Gets the active editor state.
Returns
The editor state
getElementByKey()
getElementByKey(
key
):null
|HTMLElement
Defined in: packages/lexical/src/LexicalEditor.ts:1221
Gets the underlying HTMLElement associated with the LexicalNode for the given key.
Parameters
key
string
the key of the LexicalNode.
Returns
null
| HTMLElement
the HTMLElement rendered by the LexicalNode associated with the key.
getKey()
getKey():
string
Defined in: packages/lexical/src/LexicalEditor.ts:1138
Gets the key of the editor
Returns
string
The editor key
getRootElement()
getRootElement():
null
|HTMLElement
Defined in: packages/lexical/src/LexicalEditor.ts:1130
Returns
null
| HTMLElement
the current root element of the editor. If you want to register an event listener, do it via LexicalEditor.registerRootListener, since this reference may not be stable.
hasNode()
hasNode<
T
>(node
):boolean
Defined in: packages/lexical/src/LexicalEditor.ts:1086
Used to assert that a certain node is registered, usually by plugins to ensure nodes that they depend on have been registered.
Type Parameters
T
T
extends KlassConstructor
<typeof LexicalNode
>
Parameters
node
T
Returns
boolean
True if the editor has registered the provided node type, false otherwise.
hasNodes()
hasNodes<
T
>(nodes
):boolean
Defined in: packages/lexical/src/LexicalEditor.ts:1095
Used to assert that certain nodes are registered, usually by plugins to ensure nodes that they depend on have been registered.
Type Parameters
T
T
extends KlassConstructor
<typeof LexicalNode
>
Parameters
nodes
T
[]
Returns
boolean
True if the editor has registered all of the provided node types, false otherwise.
isComposing()
isComposing():
boolean
Defined in: packages/lexical/src/LexicalEditor.ts:781
Returns
boolean
true if the editor is currently in "composition" mode due to receiving input through an IME, or 3P extension, for example. Returns false otherwise.
isEditable()
isEditable():
boolean
Defined in: packages/lexical/src/LexicalEditor.ts:1394
Returns true if the editor is editable, false otherwise.
Returns
boolean
True if the editor is editable, false otherwise.
parseEditorState()
parseEditorState(
maybeStringifiedEditorState
,updateFn?
):EditorState
Defined in: packages/lexical/src/LexicalEditor.ts:1293
Parses a SerializedEditorState (usually produced by EditorState.toJSON) and returns and EditorState object that can be, for example, passed to LexicalEditor.setEditorState. Typically, deserialization from JSON stored in a database uses this method.
Parameters
maybeStringifiedEditorState
string
| SerializedEditorState
<SerializedLexicalNode
>
updateFn?
() => void
Returns
read()
read<
T
>(callbackFn
):T
Defined in: packages/lexical/src/LexicalEditor.ts:1312
Executes a read of the editor's state, with the editor context available (useful for exporting and read-only DOM operations). Much like update, but prevents any mutation of the editor's state. Any pending updates will be flushed immediately before the read.
Type Parameters
T
T
Parameters
callbackFn
() => T
A function that has access to read-only editor state.
Returns
T
registerCommand()
registerCommand<
P
>(command
,listener
,priority
): () =>void
Defined in: packages/lexical/src/LexicalEditor.ts:887
Registers a listener that will trigger anytime the provided command is dispatched with LexicalEditor.dispatch, subject to priority. Listeners that run at a higher priority can "intercept" commands and prevent them from propagating to other handlers by returning true.
Listeners are always invoked in an LexicalEditor.update and can call dollar functions.
Listeners registered at the same priority level will run deterministically in the order of registration.
Type Parameters
P
P
Parameters
command
the command that will trigger the callback.
listener
the function that will execute when the command is dispatched.
priority
the relative priority of the listener. 0 | 1 | 2 | 3 | 4 (or COMMAND_PRIORITY_EDITOR | COMMAND_PRIORITY_LOW | COMMAND_PRIORITY_NORMAL | COMMAND_PRIORITY_HIGH | COMMAND_PRIORITY_CRITICAL)
Returns
a teardown function that can be used to cleanup the listener.
():
void
Returns
void
registerDecoratorListener()
registerDecoratorListener<
T
>(listener
): () =>void
Defined in: packages/lexical/src/LexicalEditor.ts:821
Registers a listener for when the editor's decorator object changes. The decorator object contains all DecoratorNode keys -> their decorated value. This is primarily used with external UI frameworks.
Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.
Type Parameters
T
T
Parameters
listener
DecoratorListener
<T
>
Returns
a teardown function that can be used to cleanup the listener.
():
void
Returns
void
registerEditableListener()
registerEditableListener(
listener
): () =>void
Defined in: packages/lexical/src/LexicalEditor.ts:805
Registers a listener for for when the editor changes between editable and non-editable states. Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.
Parameters
listener
Returns
a teardown function that can be used to cleanup the listener.
():
void
Returns
void
registerMutationListener()
registerMutationListener(
klass
,listener
,options?
): () =>void
Defined in: packages/lexical/src/LexicalEditor.ts:951
Registers a listener that will run when a Lexical node of the provided class is mutated. The listener will receive a list of nodes along with the type of mutation that was performed on each: created, destroyed, or updated.
One common use case for this is to attach DOM event listeners to the underlying DOM nodes as Lexical nodes are created. LexicalEditor.getElementByKey can be used for this.
If any existing nodes are in the DOM, and skipInitialization is not true, the listener will be called immediately with an updateTag of 'registerMutationListener' where all nodes have the 'created' NodeMutation. This can be controlled with the skipInitialization option (whose default was previously true for backwards compatibility with <=0.16.1 but has been changed to false as of 0.21.0).
Parameters
klass
KlassConstructor
<typeof LexicalNode
>
The class of the node that you want to listen to mutations on.
listener
The logic you want to run when the node is mutated.
options?
MutationListenerOptions
see MutationListenerOptions
Returns
a teardown function that can be used to cleanup the listener.
():
void
Returns
void
registerNodeTransform()
registerNodeTransform<
T
>(klass
,listener
): () =>void
Defined in: packages/lexical/src/LexicalEditor.ts:1054
Registers a listener that will run when a Lexical node of the provided class is marked dirty during an update. The listener will continue to run as long as the node is marked dirty. There are no guarantees around the order of transform execution!
Watch out for infinite loops. See Node Transforms
Type Parameters
T
T
extends LexicalNode
Parameters
klass
Klass
<T
>
The class of the node that you want to run transforms on.
listener
Transform
<T
>
The logic you want to run when the node is updated.
Returns
a teardown function that can be used to cleanup the listener.
():
void
Returns
void
registerRootListener()
registerRootListener(
listener
): () =>void
Defined in: packages/lexical/src/LexicalEditor.ts:856
Registers a listener for when the editor's root DOM element (the content editable Lexical attaches to) changes. This is primarily used to attach event listeners to the root element. The root listener function is executed directly upon registration and then on any subsequent update.
Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.
Parameters
listener
Returns
a teardown function that can be used to cleanup the listener.
():
void
Returns
void
registerTextContentListener()
registerTextContentListener(
listener
): () =>void
Defined in: packages/lexical/src/LexicalEditor.ts:838
Registers a listener for when Lexical commits an update to the DOM and the text content of the editor changes from the previous state of the editor. If the text content is the same between updates, no notifications to the listeners will happen.
Will trigger the provided callback each time the editor transitions between these states until the teardown function is called.
Parameters
listener
TextContentListener
Returns
a teardown function that can be used to cleanup the listener.
():
void
Returns
void
registerUpdateListener()
registerUpdateListener(
listener
): () =>void
Defined in: packages/lexical/src/LexicalEditor.ts:791
Registers a listener for Editor update event. Will trigger the provided callback each time the editor goes through an update (via LexicalEditor.update) until the teardown function is called.
Parameters
listener
Returns
a teardown function that can be used to cleanup the listener.
():
void
Returns
void
setEditable()
setEditable(
editable
):void
Defined in: packages/lexical/src/LexicalEditor.ts:1402
Sets the editable property of the editor. When false, the editor will not listen for user events on the underling contenteditable.
Parameters
editable
boolean
the value to set the editable mode to.
Returns
void
setEditorState()
setEditorState(
editorState
,options?
):void
Defined in: packages/lexical/src/LexicalEditor.ts:1238
Imperatively set the EditorState. Triggers reconciliation like an update.
Parameters
editorState
the state to set the editor
options?
options for the update.
Returns
void
setRootElement()
setRootElement(
nextRootElement
):void
Defined in: packages/lexical/src/LexicalEditor.ts:1146
Imperatively set the root contenteditable element that Lexical listens for events on.
Parameters
nextRootElement
null
| HTMLElement
Returns
void
toJSON()
toJSON():
SerializedEditor
Defined in: packages/lexical/src/LexicalEditor.ts:1417
Returns a JSON-serializable javascript object NOT a JSON string. You still must call JSON.stringify (or something else) to turn the state into a string you can transfer over the wire and store in a database.
Returns
A JSON-serializable javascript object
update()
update(
updateFn
,options?
):void
Defined in: packages/lexical/src/LexicalEditor.ts:1323
Executes an update to the editor state. The updateFn callback is the ONLY place where Lexical editor state can be safely mutated.
Parameters
updateFn
() => void
A function that has access to writable editor state.
options?
A bag of options to control the behavior of the update.
Returns
void
LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:384
Extended by
Methods
$config()
$config():
BaseStaticNodeConfig
Defined in: packages/lexical/src/LexicalNode.ts:454
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
Example
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
afterCloneFrom()
afterCloneFrom(
prevNode
):void
Defined in: packages/lexical/src/LexicalNode.ts:523
Perform any state updates on the clone of prevNode that are not already
handled by the constructor call in the static clone method. If you have
state to update in your clone that is not handled directly by the
constructor, it is advisable to override this method but it is required
to include a call to super.afterCloneFrom(prevNode)
in your
implementation. This is only intended to be called by
$cloneWithProperties function or via a super call.
Parameters
prevNode
this
Returns
void
Example
class ClassesTextNode extends TextNode {
// Not shown: static getType, static importJSON, exportJSON, createDOM, updateDOM
__classes = new Set<string>();
static clone(node: ClassesTextNode): ClassesTextNode {
// The inherited TextNode constructor is used here, so
// classes is not set by this method.
return new ClassesTextNode(node.__text, node.__key);
}
afterCloneFrom(node: this): void {
// This calls TextNode.afterCloneFrom and LexicalNode.afterCloneFrom
// for necessary state updates
super.afterCloneFrom(node);
this.__addClasses(node.__classes);
}
// This method is a private implementation detail, it is not
// suitable for the public API because it does not call getWritable
__addClasses(classNames: Iterable<string>): this {
for (const className of classNames) {
this.__classes.add(className);
}
return this;
}
addClass(...classNames: string[]): this {
return this.getWritable().__addClasses(classNames);
}
removeClass(...classNames: string[]): this {
const node = this.getWritable();
for (const className of classNames) {
this.__classes.delete(className);
}
return this;
}
getClasses(): Set<string> {
return this.getLatest().__classes;
}
}
config()
config<
Type
,Config
>(type
,config
):StaticNodeConfigRecord
<Type
,Config
>
Defined in: packages/lexical/src/LexicalNode.ts:463
This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.
Type Parameters
Type
Type
extends string
Config
Config
extends StaticNodeConfigValue
<LexicalNode
, Type
>
Parameters
type
Type
config
Config
Returns
StaticNodeConfigRecord
<Type
, Config
>
createDOM()
createDOM(
_config
,_editor
):HTMLElement
Defined in: packages/lexical/src/LexicalNode.ts:1057
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
allows access to things like the EditorTheme (to apply classes) during reconciliation.
_editor
allows access to the editor for context during reconciliation.
Returns
HTMLElement
createParentElementNode()
createParentElementNode():
ElementNode
Defined in: packages/lexical/src/LexicalNode.ts:1377
The creation logic for any required parent. Should be implemented if isParentRequired returns true.
Returns
exportDOM()
exportDOM(
editor
):DOMExportOutput
Defined in: packages/lexical/src/LexicalNode.ts:1087
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
Returns
exportJSON()
exportJSON():
SerializedLexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1099
Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.
Returns
getCommonAncestor()
getCommonAncestor<
T
>(node
):null
|T
Defined in: packages/lexical/src/LexicalNode.ts:830
Type Parameters
T
T
extends ElementNode
= ElementNode
Parameters
node
the other node to find the common ancestor of.
Returns
null
| T
Deprecated
Returns the closest common ancestor of this node and the provided one or null if one cannot be found.
getIndexWithinParent()
getIndexWithinParent():
number
Defined in: packages/lexical/src/LexicalNode.ts:656
Returns the zero-based index of this node within the parent.
Returns
number
getKey()
getKey():
string
Defined in: packages/lexical/src/LexicalNode.ts:648
Returns this nodes key.
Returns
string
getLatest()
getLatest():
this
Defined in: packages/lexical/src/LexicalNode.ts:981
Returns the latest version of the node from the active EditorState. This is used to avoid getting values from stale node references.
Returns
this
getNextSibling()
getNextSibling<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:801
Returns the "next" siblings - that is, the node that comes after this one in the same parent
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
getNextSiblings()
getNextSiblings<
T
>():T
[]
Defined in: packages/lexical/src/LexicalNode.ts:812
Returns all "next" siblings - that is, the nodes that come between this one and the last child of it's parent, inclusive.
Type Parameters
T
T
extends LexicalNode
Returns
T
[]
getNodesBetween()
getNodesBetween(
targetNode
):LexicalNode
[]
Defined in: packages/lexical/src/LexicalNode.ts:900
Returns a list of nodes that are between this node and the target node in the EditorState.
Parameters
targetNode
the node that marks the other end of the range of nodes to be returned.
Returns
getParent()
getParent<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:676
Returns the parent of this node, or null if none is found.
Type Parameters
T
T
extends ElementNode
Returns
null
| T
getParentKeys()
getParentKeys():
string
[]
Defined in: packages/lexical/src/LexicalNode.ts:753
Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.
Returns
string
[]
getParentOrThrow()
getParentOrThrow<
T
>():T
Defined in: packages/lexical/src/LexicalNode.ts:687
Returns the parent of this node, or throws if none is found.
Type Parameters
T
T
extends ElementNode
Returns
T
getParents()
getParents():
ElementNode
[]
Defined in: packages/lexical/src/LexicalNode.ts:738
Returns a list of the every ancestor of this node, all the way up to the RootNode.
Returns
getPreviousSibling()
getPreviousSibling<
T
>():null
|T
Defined in: packages/lexical/src/LexicalNode.ts:768
Returns the "previous" siblings - that is, the node that comes before this one in the same parent.
Type Parameters
T
T
extends LexicalNode
Returns
null
| T
getPreviousSiblings()
getPreviousSiblings<
T
>():T
[]
Defined in: packages/lexical/src/LexicalNode.ts:779
Returns the "previous" siblings - that is, the nodes that come between this one and the first child of it's parent, inclusive.
Type Parameters
T
T
extends LexicalNode
Returns
T
[]
getTextContent()
getTextContent():
string
Defined in: packages/lexical/src/LexicalNode.ts:1031
Returns the text content of the node. Override this for custom nodes that should have a representation in plain text format (for copy + paste, for example)
Returns
string
getTextContentSize()
getTextContentSize():
number
Defined in: packages/lexical/src/LexicalNode.ts:1039
Returns the length of the string produced by calling getTextContent on this node.
Returns
number
getTopLevelElement()
getTopLevelElement():
null
|ElementNode
|DecoratorNode
<unknown
>
Defined in: packages/lexical/src/LexicalNode.ts:700
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
null
| ElementNode
| DecoratorNode
<unknown
>
getTopLevelElementOrThrow()
getTopLevelElementOrThrow():
ElementNode
|DecoratorNode
<unknown
>
Defined in: packages/lexical/src/LexicalNode.ts:721
Returns the highest (in the EditorState tree) non-root ancestor of this node, or throws if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".
Returns
ElementNode
| DecoratorNode
<unknown
>
getType()
getType():
string
Defined in: packages/lexical/src/LexicalNode.ts:562
Returns the string type of this node.
Returns
string
getWritable()
getWritable():
this
Defined in: packages/lexical/src/LexicalNode.ts:998
Returns a mutable version of the node using $cloneWithProperties if necessary. Will throw an error if called outside of a Lexical Editor LexicalEditor.update callback.
Returns
this
insertAfter()
insertAfter(
nodeToInsert
,restoreSelection
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1262
Inserts a node after this LexicalNode (as the next sibling).
Parameters
nodeToInsert
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
insertBefore()
insertBefore(
nodeToInsert
,restoreSelection
):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1329
Inserts a node before this LexicalNode (as the previous sibling).
Parameters
nodeToInsert
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
is()
is(
object
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:847
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
the node to perform the equality comparison on.
undefined
| null
| LexicalNode
Returns
boolean
isAttached()
isAttached():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:579
Returns true if there is a path between this node and the RootNode, false otherwise. This is a way of determining if the node is "attached" EditorState. Unattached nodes won't be reconciled and will ultimately be cleaned up by the Lexical GC.
Returns
boolean
isBefore()
isBefore(
targetNode
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:865
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
the node we're testing to see if it's after this one.
Returns
boolean
isDirty()
isDirty():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:970
Returns true if this node has been marked dirty during this update cycle.
Returns
boolean
isInline()
isInline():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:566
Returns
boolean
isParentOf()
isParentOf(
targetNode
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:888
Returns true if this node is an ancestor of and distinct from the target node, false otherwise.
Parameters
targetNode
the would-be child node.
Returns
boolean
isParentRequired()
isParentRequired():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:1369
Whether or not this node has a required parent. Used during copy + paste operations to normalize nodes that would otherwise be orphaned. For example, ListItemNodes without a ListNode parent or TextNodes with a ParagraphNode parent.
Returns
boolean
isSelected()
isSelected(
selection?
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:603
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?
The selection that we want to determine if the node is in.
null
| BaseSelection
Returns
boolean
markDirty()
markDirty():
void
Defined in: packages/lexical/src/LexicalNode.ts:1438
Marks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.
Returns
void
remove()
remove(
preserveEmptyParent?
):void
Defined in: packages/lexical/src/LexicalNode.ts:1181
Removes this LexicalNode from the EditorState. If the node isn't re-inserted somewhere, the Lexical garbage collector will eventually clean it up.
Parameters
preserveEmptyParent?
boolean
If falsy, the node's parent will be removed if it's empty after the removal operation. This is the default behavior, subject to other node heuristics such as ElementNode#canBeEmpty
Returns
void
replace()
replace<
N
>(replaceWith
,includeChildren?
):N
Defined in: packages/lexical/src/LexicalNode.ts:1192
Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.
Type Parameters
N
N
extends LexicalNode
Parameters
replaceWith
N
The node to replace this one with.
includeChildren?
boolean
Whether or not to transfer the children of this node to the replacing node.
Returns
N
selectEnd()
selectEnd():
RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1385
Returns
selectNext()
selectNext(
anchorOffset?
,focusOffset?
):RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1417
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
selectPrevious()
selectPrevious(
anchorOffset?
,focusOffset?
):RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1395
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
selectStart()
selectStart():
RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:1381
Returns
updateDOM()
updateDOM(
_prevNode
,_dom
,_config
):boolean
Defined in: packages/lexical/src/LexicalNode.ts:1071
Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.
Returning "true" here will cause lexical to unmount and recreate the DOM node (by calling createDOM). You would need to do this if the element tag changes, for instance.
Parameters
_prevNode
unknown
_dom
HTMLElement
_config
Returns
boolean
updateFromJSON()
updateFromJSON(
serializedNode
):this
Defined in: packages/lexical/src/LexicalNode.ts:1152
Update this LexicalNode instance from serialized JSON. It's recommended to implement as much logic as possible in this method instead of the static importJSON method, so that the functionality can be inherited in subclasses.
The LexicalUpdateJSON utility type should be used to ignore any type, version, or children properties in the JSON so that the extended JSON from subclasses are acceptable parameters for the super call.
If overridden, this method must call super.
Parameters
serializedNode
LexicalUpdateJSON
<SerializedLexicalNode
>
Returns
this
Example
class MyTextNode extends TextNode {
// ...
static importJSON(serializedNode: SerializedMyTextNode): MyTextNode {
return $createMyTextNode()
.updateFromJSON(serializedNode);
}
updateFromJSON(
serializedNode: LexicalUpdateJSON<SerializedMyTextNode>,
): this {
return super.updateFromJSON(serializedNode)
.setMyProperty(serializedNode.myProperty);
}
}
NodeSelection
Defined in: packages/lexical/src/LexicalSelection.ts:363
Implements
Properties
_cachedNodes
_cachedNodes:
null
|LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:365
Implementation of
BaseSelection._cachedNodes
_nodes
_nodes:
Set
<string
>
Defined in: packages/lexical/src/LexicalSelection.ts:364
dirty
dirty:
boolean
Defined in: packages/lexical/src/LexicalSelection.ts:366
Implementation of
BaseSelection.dirty
Methods
add()
add(
key
):void
Defined in: packages/lexical/src/LexicalSelection.ts:403
Parameters
key
string
Returns
void
clear()
clear():
void
Defined in: packages/lexical/src/LexicalSelection.ts:415
Returns
void
clone()
clone():
NodeSelection
Defined in: packages/lexical/src/LexicalSelection.ts:425
Returns
Implementation of
BaseSelection.clone
delete()
delete(
key
):void
Defined in: packages/lexical/src/LexicalSelection.ts:409
Parameters
key
string
Returns
void
deleteNodes()
deleteNodes():
void
Defined in: packages/lexical/src/LexicalSelection.ts:493
Remove all nodes in the NodeSelection. If there were any nodes, replace the selection with a new RangeSelection at the previous location of the first node.
Returns
void
extract()
extract():
LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:429
Returns
Implementation of
BaseSelection.extract
getCachedNodes()
getCachedNodes():
null
|LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:374
Returns
null
| LexicalNode
[]
Implementation of
BaseSelection.getCachedNodes
getNodes()
getNodes():
LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:460
Returns
Implementation of
BaseSelection.getNodes
getStartEndPoints()
getStartEndPoints():
null
Defined in: packages/lexical/src/LexicalSelection.ts:399
Returns
null
Implementation of
BaseSelection.getStartEndPoints
getTextContent()
getTextContent():
string
Defined in: packages/lexical/src/LexicalSelection.ts:479
Returns
string
Implementation of
BaseSelection.getTextContent
has()
has(
key
):boolean
Defined in: packages/lexical/src/LexicalSelection.ts:421
Parameters
key
string
Returns
boolean
insertNodes()
insertNodes(
nodes
):void
Defined in: packages/lexical/src/LexicalSelection.ts:441
Parameters
nodes
Returns
void
Implementation of
BaseSelection.insertNodes
insertRawText()
insertRawText(
text
):void
Defined in: packages/lexical/src/LexicalSelection.ts:433
Parameters
text
string
Returns
void
Implementation of
BaseSelection.insertRawText
insertText()
insertText():
void
Defined in: packages/lexical/src/LexicalSelection.ts:437
Returns
void
Implementation of
BaseSelection.insertText
is()
is(
selection
):boolean
Defined in: packages/lexical/src/LexicalSelection.ts:382
Parameters
selection
null
| BaseSelection
Returns
boolean
Implementation of
BaseSelection.is
isBackward()
isBackward():
boolean
Defined in: packages/lexical/src/LexicalSelection.ts:395
Returns
boolean
Implementation of
BaseSelection.isBackward
isCollapsed()
isCollapsed():
boolean
Defined in: packages/lexical/src/LexicalSelection.ts:391
Returns
boolean
Implementation of
BaseSelection.isCollapsed
setCachedNodes()
setCachedNodes(
nodes
):void
Defined in: packages/lexical/src/LexicalSelection.ts:378
Parameters
nodes
null
| LexicalNode
[]
Returns
void
Implementation of
BaseSelection.setCachedNodes
Point
Defined in: packages/lexical/src/LexicalSelection.ts:174
Properties
_selection
_selection:
null
|BaseSelection
Defined in: packages/lexical/src/LexicalSelection.ts:178
key
key:
string
Defined in: packages/lexical/src/LexicalSelection.ts:175
offset
offset:
number
Defined in: packages/lexical/src/LexicalSelection.ts:176
type
type:
"text"
|"element"
Defined in: packages/lexical/src/LexicalSelection.ts:177
Methods
getNode()
getNode():
LexicalNode
Defined in: packages/lexical/src/LexicalSelection.ts:212
Returns
is()
is(
point
):boolean
Defined in: packages/lexical/src/LexicalSelection.ts:195
Parameters
point
Returns
boolean
isBefore()
isBefore(
b
):boolean
Defined in: packages/lexical/src/LexicalSelection.ts:203
Parameters
b
Returns
boolean
set()
set(
key
,offset
,type
,onlyIfChanged?
):void
Defined in: packages/lexical/src/LexicalSelection.ts:221
Parameters
key
string
offset
number
type
"text"
| "element"
onlyIfChanged?
boolean
Returns
void
RangeSelection
Defined in: packages/lexical/src/LexicalSelection.ts:509
Implements
Properties
_cachedNodes
_cachedNodes:
null
|LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:514
Implementation of
BaseSelection._cachedNodes
anchor
anchor:
PointType
Defined in: packages/lexical/src/LexicalSelection.ts:512
dirty
dirty:
boolean
Defined in: packages/lexical/src/LexicalSelection.ts:515
Implementation of
BaseSelection.dirty
focus
focus:
PointType
Defined in: packages/lexical/src/LexicalSelection.ts:513
format
format:
number
Defined in: packages/lexical/src/LexicalSelection.ts:510
style
style:
string
Defined in: packages/lexical/src/LexicalSelection.ts:511
Methods
applyDOMRange()
applyDOMRange(
range
):void
Defined in: packages/lexical/src/LexicalSelection.ts:696
Attempts to map a DOM selection range onto this Lexical Selection, setting the anchor, focus, and type accordingly
Parameters
range
StaticRange
a DOM Selection range conforming to the StaticRange interface.
Returns
void
clone()
clone():
RangeSelection
Defined in: packages/lexical/src/LexicalSelection.ts:729
Creates a new RangeSelection, copying over all the property values from this one.
Returns
a new RangeSelection with the same property values as this one.
Implementation of
BaseSelection.clone
deleteCharacter()
deleteCharacter(
isBackward
):void
Defined in: packages/lexical/src/LexicalSelection.ts:1779
Performs one logical character deletion operation on the EditorState based on the current Selection. Handles different node types.
Parameters
isBackward
boolean
whether or not the selection is backwards.
Returns
void
deleteLine()
deleteLine(
isBackward
):void
Defined in: packages/lexical/src/LexicalSelection.ts:1964
Performs one logical line deletion operation on the EditorState based on the current Selection. Handles different node types.
Parameters
isBackward
boolean
whether or not the selection is backwards.
Returns
void
deleteWord()
deleteWord(
isBackward
):void
Defined in: packages/lexical/src/LexicalSelection.ts:1994
Performs one logical word deletion operation on the EditorState based on the current Selection. Handles different node types.
Parameters
isBackward
boolean
whether or not the selection is backwards.
Returns
void
extract()
extract():
LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:1538
Extracts the nodes in the Selection, splitting nodes where necessary to get offset-level precision.
Returns
The nodes in the Selection
Implementation of
BaseSelection.extract
formatText()
formatText(
formatType
,alignWithFormat
):void
Defined in: packages/lexical/src/LexicalSelection.ts:1223
Applies the provided format to the TextNodes in the Selection, splitting or merging nodes as necessary.
Parameters
formatType
the format type to apply to the nodes in the Selection.
alignWithFormat
a 32-bit integer representing formatting flags to align with.
null
| number
Returns
void
forwardDeletion()
forwardDeletion(
anchor
,anchorNode
,isBackward
):boolean
Defined in: packages/lexical/src/LexicalSelection.ts:1747
Helper for handling forward character and word deletion that prevents element nodes like a table, columns layout being destroyed
Parameters
anchor
the anchor
anchorNode
the anchor node in the selection
isBackward
boolean
whether or not selection is backwards
Returns
boolean
getCachedNodes()
getCachedNodes():
null
|LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:533
Returns
null
| LexicalNode
[]
Implementation of
BaseSelection.getCachedNodes
getNodes()
getNodes():
LexicalNode
[]
Defined in: packages/lexical/src/LexicalSelection.ts:580
Gets all the nodes in the Selection. Uses caching to make it generally suitable for use in hot paths.
See also the CaretRange APIs (starting with $caretRangeFromSelection), which are likely to provide a better foundation for any operation where partial selection is relevant (e.g. the anchor or focus are inside an ElementNode and TextNode)
Returns
an Array containing all the nodes in the Selection
Implementation of
BaseSelection.getNodes
getStartEndPoints()
Defined in: packages/lexical/src/LexicalSelection.ts:2026
Returns
Implementation of
BaseSelection.getStartEndPoints
getTextContent()
getTextContent():
string
Defined in: packages/lexical/src/LexicalSelection.ts:628
Gets the (plain) text content of all the nodes in the selection.
Returns
string
a string representing the text content of all the nodes in the Selection
Implementation of
BaseSelection.getTextContent
hasFormat()
hasFormat(
type
):boolean
Defined in: packages/lexical/src/LexicalSelection.ts:778
Returns whether the provided TextFormatType is present on the Selection. This will be true if any node in the Selection has the specified format.
Parameters
type
the TextFormatType to check for.
Returns
boolean
true if the provided format is currently toggled on on the Selection, false otherwise.
insertLineBreak()
insertLineBreak(
selectStart?
):void
Defined in: packages/lexical/src/LexicalSelection.ts:1521
Inserts a logical linebreak, which may be a new LineBreakNode or a new ParagraphNode, into the EditorState at the current Selection.
Parameters
selectStart?
boolean
Returns
void
insertNodes()
insertNodes(
nodes
):void
Defined in: packages/lexical/src/LexicalSelection.ts:1374
Attempts to "intelligently" insert an arbitrary list of Lexical nodes into the EditorState at the current Selection according to a set of heuristics that determine how surrounding nodes should be changed, replaced, or moved to accommodate the incoming ones.
Parameters
nodes
the nodes to insert
Returns
void
Implementation of
BaseSelection.insertNodes
insertParagraph()
insertParagraph():
null
|ElementNode
Defined in: packages/lexical/src/LexicalSelection.ts:1490
Inserts a new ParagraphNode into the EditorState at the current Selection
Returns
null
| ElementNode
the newly inserted node.
insertRawText()
insertRawText(
text
):void
Defined in: packages/lexical/src/LexicalSelection.ts:789
Attempts to insert the provided text into the EditorState at the current Selection. converts tabs, newlines, and carriage returns into LexicalNodes.
Parameters
text
string
the text to insert into the Selection
Returns
void
Implementation of
BaseSelection.insertRawText
insertText()
insertText(
text
):void
Defined in: packages/lexical/src/LexicalSelection.ts:811
Insert the provided text into the EditorState at the current Selection.
Parameters
text
string
the text to insert into the Selection
Returns
void
Implementation of
BaseSelection.insertText
is()
is(
selection
):boolean
Defined in: packages/lexical/src/LexicalSelection.ts:547
Used to check if the provided selections is equal to this one by value, including anchor, focus, format, and style properties.
Parameters
selection
the Selection to compare this one to.
null
| BaseSelection
Returns
boolean
true if the Selections are equal, false otherwise.
Implementation of
BaseSelection.is
isBackward()
isBackward():
boolean
Defined in: packages/lexical/src/LexicalSelection.ts:2022
Returns whether the Selection is "backwards", meaning the focus logically precedes the anchor in the EditorState.
Returns
boolean
true if the Selection is backwards, false otherwise.
Implementation of
BaseSelection.isBackward
isCollapsed()
isCollapsed():
boolean
Defined in: packages/lexical/src/LexicalSelection.ts:565
Returns whether the Selection is "collapsed", meaning the anchor and focus are the same node and have the same offset.
Returns
boolean
true if the Selection is collapsed, false otherwise.
Implementation of
BaseSelection.isCollapsed
modify()
modify(
alter
,isBackward
,granularity
):void
Defined in: packages/lexical/src/LexicalSelection.ts:1600
Modifies the Selection according to the parameters and a set of heuristics that account for various node types. Can be used to safely move or extend selection by one logical "unit" without dealing explicitly with all the possible node types.
Parameters
alter
the type of modification to perform
"move"
| "extend"
isBackward
boolean
whether or not selection is backwards
granularity
the granularity at which to apply the modification
"character"
| "word"
| "lineboundary"
Returns
void
removeText()
removeText():
void
Defined in: packages/lexical/src/LexicalSelection.ts:1206
Removes the text in the Selection, adjusting the EditorState accordingly.
Returns
void
setCachedNodes()
setCachedNodes(
nodes
):void
Defined in: packages/lexical/src/LexicalSelection.ts:537
Parameters
nodes
null
| LexicalNode
[]
Returns
void
Implementation of
BaseSelection.setCachedNodes
setFormat()
setFormat(
format
):void
Defined in: packages/lexical/src/LexicalSelection.ts:756
Sets the value of the format property on the Selection
Parameters
format
number
the format to set at the value of the format property.
Returns
void
setStyle()
setStyle(
style
):void
Defined in: packages/lexical/src/LexicalSelection.ts:766
Sets the value of the style property on the Selection
Parameters
style
string
the style to set at the value of the style property.
Returns
void
setTextNodeRange()
setTextNodeRange(
anchorNode
,anchorOffset
,focusNode
,focusOffset
):void
Defined in: packages/lexical/src/LexicalSelection.ts:613
Sets this Selection to be of type "text" at the provided anchor and focus values.
Parameters
anchorNode
the anchor node to set on the Selection
anchorOffset
number
the offset to set on the Selection
focusNode
the focus node to set on the Selection
focusOffset
number
the focus offset to set on the Selection
Returns
void
toggleFormat()
toggleFormat(
format
):void
Defined in: packages/lexical/src/LexicalSelection.ts:746
Toggles the provided format on all the TextNodes in the Selection.
Parameters
format
a string TextFormatType to toggle on the TextNodes in the selection
Returns
void
SelectionWithComposedRanges
Defined in: packages/lexical/src/LexicalSelection.ts:114
Extended Selection interface that includes the modern getComposedRanges() method. This API is available in Chrome 125+, Firefox 132+, and other modern browsers. It provides a standardized way to get selection ranges across shadow DOM boundaries.
Extends
Selection
Properties
anchorNode
readonly
anchorNode:null
|Node
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30373
The Selection.anchorNode
read-only property returns the Node in which the selection begins.
Inherited from
Selection.anchorNode
anchorOffset
readonly
anchorOffset:number
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30379
The Selection.anchorOffset
read-only property returns the number of characters that the selection's anchor is offset within the In the case of Selection.anchorNode being another type of node, Selection.anchorOffset
returns the number of Node.childNodes the selection's anchor is offset within the Selection.anchorNode.
Inherited from
Selection.anchorOffset
direction
readonly
direction:string
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30385
The direction
read-only property of the Selection interface is a string that provides the direction of the current selection.
Inherited from
Selection.direction
focusNode
readonly
focusNode:null
|Node
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30391
The Selection.focusNode
read-only property returns the Node in which the selection ends.
Inherited from
Selection.focusNode
focusOffset
readonly
focusOffset:number
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30397
The Selection.focusOffset
read-only property returns the number of characters that the selection's focus is offset within the In the case of Selection.focusNode being another type of node, Selection.focusOffset
returns the number of Node.childNodes the selection's focus is offset within the Selection.focusNode.
Inherited from
Selection.focusOffset
isCollapsed
readonly
isCollapsed:boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30403
The Selection.isCollapsed
read-only property returns a boolean value which indicates whether or not there is currently any text selected.
Inherited from
Selection.isCollapsed
rangeCount
readonly
rangeCount:number
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30409
The Selection.rangeCount
read-only property returns the number of ranges in the selection.
Inherited from
Selection.rangeCount
type
readonly
type:string
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30415
The type
read-only property of the type of the current selection.
Inherited from
Selection.type
Methods
addRange()
addRange(
range
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30421
The Selection.addRange()
method adds a js-nolint addRange(range)
- range
- : A Range object that will be added to the Selection.
Parameters
range
Range
Returns
void
Inherited from
Selection.addRange
collapse()
collapse(
node
,offset?
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30427
The Selection.collapse()
method collapses the current selection to a single point.
Parameters
node
null
| Node
offset?
number
Returns
void
Inherited from
Selection.collapse
collapseToEnd()
collapseToEnd():
void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30433
The Selection.collapseToEnd()
method collapses the selection to the end of the last range in the selection.
Returns
void
Inherited from
Selection.collapseToEnd
collapseToStart()
collapseToStart():
void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30439
The Selection.collapseToStart()
method collapses the selection to the start of the first range in the selection.
Returns
void
Inherited from
Selection.collapseToStart
containsNode()
containsNode(
node
,allowPartialContainment?
):boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30445
The Selection.containsNode()
method indicates whether a specified node is part of the selection.
Parameters
node
Node
allowPartialContainment?
boolean
Returns
boolean
Inherited from
Selection.containsNode
deleteFromDocument()
deleteFromDocument():
void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30451
The deleteFromDocument()
method of the js-nolint deleteFromDocument()
None.
Returns
void
Inherited from
Selection.deleteFromDocument
empty()
empty():
void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30457
The Selection.empty()
method removes all ranges from the selection, leaving the Selection.anchorNode and Selection.focusNode properties equal to null
and nothing selected.
Returns
void
Inherited from
Selection.empty
extend()
extend(
node
,offset?
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30463
The Selection.extend()
method moves the focus of the selection to a specified point.
Parameters
node
Node
offset?
number
Returns
void
Inherited from
Selection.extend
getComposedRanges()
getComposedRanges(
options?
):StaticRange
[]
Defined in: packages/lexical/src/LexicalSelection.ts:123
Returns an array of StaticRange objects representing the current selection across shadow DOM boundaries. This is the modern replacement for the experimental ShadowRoot.getSelection() method.
Parameters
options?
Configuration options for the composed ranges
Returns
StaticRange
[]
Array of StaticRange objects representing the selection
Overrides
Selection.getComposedRanges
getRangeAt()
getRangeAt(
index
):Range
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30475
The getRangeAt()
method of the Selection interface returns a range object representing a currently selected range.
Parameters
index
number
Returns
Range
Inherited from
Selection.getRangeAt
modify()
modify(
alter?
,direction?
,granularity?
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30481
The Selection.modify()
method applies a change to the current selection or cursor position, using simple textual commands.
Parameters
alter?
string
direction?
string
granularity?
string
Returns
void
Inherited from
Selection.modify
removeAllRanges()
removeAllRanges():
void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30487
The Selection.removeAllRanges()
method removes all ranges from the selection, leaving the Selection.anchorNode and Selection.focusNode properties equal to null
and nothing selected.
Returns
void
Inherited from
Selection.removeAllRanges
removeRange()
removeRange(
range
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30493
The Selection.removeRange()
method removes a range from a selection.
Parameters
range
Range
Returns
void
Inherited from
Selection.removeRange
selectAllChildren()
selectAllChildren(
node
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30499
The Selection.selectAllChildren()
method adds all the children of the specified node to the selection.
Parameters
node
Node
Returns
void
Inherited from
Selection.selectAllChildren
setBaseAndExtent()
setBaseAndExtent(
anchorNode
,anchorOffset
,focusNode
,focusOffset
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30505
The setBaseAndExtent()
method of the Selection interface sets the selection to be a range including all or parts of two specified DOM nodes, and any content located between them.
Parameters
anchorNode
Node
anchorOffset
number
focusNode
Node
focusOffset
number
Returns
void
Inherited from
Selection.setBaseAndExtent
setPosition()
setPosition(
node
,offset?
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30511
The Selection.setPosition()
method collapses the current selection to a single point.
Parameters
node
null
| Node
offset?
number
Returns
void
Inherited from
Selection.setPosition
toString()
toString():
string
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30512
Returns
string
Inherited from
Selection.toString
SerializedEditorState<T>
Defined in: packages/lexical/src/LexicalEditorState.ts:22
Type Parameters
T
T
extends SerializedLexicalNode
= SerializedLexicalNode
Properties
root
root:
SerializedRootNode
<T
>
Defined in: packages/lexical/src/LexicalEditorState.ts:25
ShadowRootWithSelection
Defined in: packages/lexical/src/LexicalSelection.ts:130
Extension for ShadowRoot with experimental getSelection method. This is a fallback for browsers that don't support getComposedRanges yet.
Extends
ShadowRoot
Properties
activeElement
readonly
activeElement:null
|Element
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10439
Returns the deepest element in the document through which or to which key events are being routed. This is, roughly speaking, the focused element in the document.
For the purposes of this API, when a child browsing context is focused, its container is focused in the parent browsing context. For example, if the user moves the focus to a text control in an iframe, the iframe is the element returned by the activeElement API in the iframe's node document.
Similarly, when the focused element is in a different node tree than documentOrShadowRoot, the element returned will be the host that's located in the same node tree as documentOrShadowRoot if documentOrShadowRoot is a shadow-including inclusive ancestor of the focused element, and null if not.
Inherited from
ShadowRoot.activeElement
adoptedStyleSheets
adoptedStyleSheets:
CSSStyleSheet
[]
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10441
Inherited from
ShadowRoot.adoptedStyleSheets
ATTRIBUTE_NODE
readonly
ATTRIBUTE_NODE:2
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21835
Inherited from
ShadowRoot.ATTRIBUTE_NODE
baseURI
readonly
baseURI:string
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21664
The read-only baseURI
property of the Node interface returns the absolute base URL of the document containing the node.
Inherited from
ShadowRoot.baseURI
CDATA_SECTION_NODE
readonly
CDATA_SECTION_NODE:4
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21839
node is a CDATASection node.
Inherited from
ShadowRoot.CDATA_SECTION_NODE
childElementCount
readonly
childElementCount:number
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22668
Inherited from
ShadowRoot.childElementCount
childNodes
readonly
childNodes:NodeListOf
<ChildNode
>
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21670
The read-only childNodes
property of the Node interface returns a live the first child node is assigned index 0
.
Inherited from
ShadowRoot.childNodes
children
readonly
children:HTMLCollection
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22674
Returns the child elements.
Inherited from
ShadowRoot.children
clonable
readonly
clonable:boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30740
The clonable
read-only property of the ShadowRoot interface returns true
if the shadow root is clonable, and false
otherwise.
Inherited from
ShadowRoot.clonable
COMMENT_NODE
readonly
COMMENT_NODE:8
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21845
node is a Comment node.
Inherited from
ShadowRoot.COMMENT_NODE
delegatesFocus
readonly
delegatesFocus:boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30746
The delegatesFocus
read-only property of the ShadowRoot interface returns true
if the shadow root delegates focus, and false
otherwise.
Inherited from
ShadowRoot.delegatesFocus
DOCUMENT_FRAGMENT_NODE
readonly
DOCUMENT_FRAGMENT_NODE:11
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21851
node is a DocumentFragment node.
Inherited from
ShadowRoot.DOCUMENT_FRAGMENT_NODE
DOCUMENT_NODE
readonly
DOCUMENT_NODE:9
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21847
node is a document.
Inherited from
ShadowRoot.DOCUMENT_NODE
DOCUMENT_POSITION_CONTAINED_BY
readonly
DOCUMENT_POSITION_CONTAINED_BY:16
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21862
Set when other is a descendant of node.
Inherited from
ShadowRoot.DOCUMENT_POSITION_CONTAINED_BY
DOCUMENT_POSITION_CONTAINS
readonly
DOCUMENT_POSITION_CONTAINS:8
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21860
Set when other is an ancestor of node.
Inherited from
ShadowRoot.DOCUMENT_POSITION_CONTAINS
DOCUMENT_POSITION_DISCONNECTED
readonly
DOCUMENT_POSITION_DISCONNECTED:1
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21854
Set when node and other are not in the same tree.
Inherited from
ShadowRoot.DOCUMENT_POSITION_DISCONNECTED
DOCUMENT_POSITION_FOLLOWING
readonly
DOCUMENT_POSITION_FOLLOWING:4
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21858
Set when other is following node.
Inherited from
ShadowRoot.DOCUMENT_POSITION_FOLLOWING
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
readonly
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC:32
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21863
Inherited from
ShadowRoot.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
DOCUMENT_POSITION_PRECEDING
readonly
DOCUMENT_POSITION_PRECEDING:2
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21856
Set when other is preceding node.
Inherited from
ShadowRoot.DOCUMENT_POSITION_PRECEDING
DOCUMENT_TYPE_NODE
readonly
DOCUMENT_TYPE_NODE:10
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21849
node is a doctype.
Inherited from
ShadowRoot.DOCUMENT_TYPE_NODE
ELEMENT_NODE
readonly
ELEMENT_NODE:1
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21834
node is an element.
Inherited from
ShadowRoot.ELEMENT_NODE
ENTITY_NODE
readonly
ENTITY_NODE:6
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21841
Inherited from
ShadowRoot.ENTITY_NODE
ENTITY_REFERENCE_NODE
readonly
ENTITY_REFERENCE_NODE:5
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21840
Inherited from
ShadowRoot.ENTITY_REFERENCE_NODE
firstChild
readonly
firstChild:null
|ChildNode
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21676
The read-only firstChild
property of the Node interface returns the node's first child in the tree, or null
if the node has no children.
Inherited from
ShadowRoot.firstChild
firstElementChild
readonly
firstElementChild:null
|Element
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22680
Returns the first child that is an element, and null otherwise.
Inherited from
ShadowRoot.firstElementChild
fullscreenElement
readonly
fullscreenElement:null
|Element
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10447
Returns document's fullscreen element.
Inherited from
ShadowRoot.fullscreenElement
host
readonly
host:Element
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30752
The host
read-only property of the ShadowRoot returns a reference to the DOM element the ShadowRoot
is attached to.
Inherited from
ShadowRoot.host
innerHTML
innerHTML:
string
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30758
The innerHTML
property of the ShadowRoot interface sets gets or sets the HTML markup to the DOM tree inside the ShadowRoot
.
Inherited from
ShadowRoot.innerHTML
isConnected
readonly
isConnected:boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21682
The read-only isConnected
property of the Node interface returns a boolean indicating whether the node is connected (directly or indirectly) to a Document object.
Inherited from
ShadowRoot.isConnected
lastChild
readonly
lastChild:null
|ChildNode
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21688
The read-only lastChild
property of the Node interface returns the last child of the node, or null
if there are no child nodes.
Inherited from
ShadowRoot.lastChild
lastElementChild
readonly
lastElementChild:null
|Element
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22686
Returns the last child that is an element, and null otherwise.
Inherited from
ShadowRoot.lastElementChild
mode
readonly
mode:ShadowRootMode
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30764
The mode
read-only property of the ShadowRoot specifies its mode — either open
or closed
.
Inherited from
ShadowRoot.mode
nextSibling
readonly
nextSibling:null
|ChildNode
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21694
The read-only nextSibling
property of the Node interface returns the node immediately following the specified one in their parent's Node.childNodes, or returns null
if the specified node is the last child in the parent element.
Inherited from
ShadowRoot.nextSibling
nodeName
readonly
nodeName:string
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21700
The read-only nodeName
property of Node returns the name of the current node as a string.
Inherited from
ShadowRoot.nodeName
nodeType
readonly
nodeType:number
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21706
The read-only nodeType
property of a Node interface is an integer that identifies what the node is.
Inherited from
ShadowRoot.nodeType
nodeValue
nodeValue:
null
|string
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21712
The nodeValue
property of the Node interface returns or sets the value of the current node.
Inherited from
ShadowRoot.nodeValue
NOTATION_NODE
readonly
NOTATION_NODE:12
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21852
Inherited from
ShadowRoot.NOTATION_NODE
onslotchange
onslotchange:
null
| (this
,ev
) =>any
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30765
Inherited from
ShadowRoot.onslotchange
ownerDocument
readonly
ownerDocument:Document
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10417
The read-only ownerDocument
property of the Node interface returns the top-level document object of the node.
Inherited from
ShadowRoot.ownerDocument
parentElement
readonly
parentElement:null
|HTMLElement
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21724
The read-only parentElement
property of Node interface returns the DOM node's parent Element, or null
if the node either has no parent, or its parent isn't a DOM Element.
Inherited from
ShadowRoot.parentElement
parentNode
readonly
parentNode:null
|ParentNode
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21730
The read-only parentNode
property of the Node interface returns the parent of the specified node in the DOM tree.
Inherited from
ShadowRoot.parentNode
pictureInPictureElement
readonly
pictureInPictureElement:null
|Element
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10449
Inherited from
ShadowRoot.pictureInPictureElement
pointerLockElement
readonly
pointerLockElement:null
|Element
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10451
Inherited from
ShadowRoot.pointerLockElement
previousSibling
readonly
previousSibling:null
|ChildNode
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21736
The read-only previousSibling
property of the Node interface returns the node immediately preceding the specified one in its parent's or null
if the specified node is the first in that list.
Inherited from
ShadowRoot.previousSibling
PROCESSING_INSTRUCTION_NODE
readonly
PROCESSING_INSTRUCTION_NODE:7
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21843
node is a ProcessingInstruction node.
Inherited from
ShadowRoot.PROCESSING_INSTRUCTION_NODE
serializable
readonly
serializable:boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30771
The serializable
read-only property of the ShadowRoot interface returns true
if the shadow root is serializable.
Inherited from
ShadowRoot.serializable
slotAssignment
readonly
slotAssignment:SlotAssignmentMode
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30777
The read-only slotAssignment
property of the ShadowRoot interface returns the slot assignment mode for the shadow DOM tree.
Inherited from
ShadowRoot.slotAssignment
styleSheets
readonly
styleSheets:StyleSheetList
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10453
Inherited from
ShadowRoot.styleSheets
TEXT_NODE
readonly
TEXT_NODE:3
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21837
node is a Text node.
Inherited from
ShadowRoot.TEXT_NODE
Accessors
textContent
Get Signature
get textContent():
string
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10420
Returns
string
Set Signature
set textContent(
value
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10421
The textContent
property of the Node interface represents the text content of the node and its descendants.
Parameters
value
null
| string
Returns
void
Inherited from
ShadowRoot.textContent
Methods
addEventListener()
Call Signature
addEventListener<
K
>(type
,listener
,options?
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30790
The addEventListener()
method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
Type Parameters
K
K
extends "slotchange"
Parameters
type
K
listener
(this
, ev
) => any
options?
boolean
| AddEventListenerOptions
Returns
void
Inherited from
ShadowRoot.addEventListener
Call Signature
addEventListener(
type
,listener
,options?
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30791
The addEventListener()
method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
Parameters
type
string
listener
EventListenerOrEventListenerObject
options?
boolean
| AddEventListenerOptions
Returns
void
Inherited from
ShadowRoot.addEventListener
append()
append(...
nodes
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22694
Inserts nodes after the last child of node, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
Parameters
nodes
...(string
| Node
)[]
Returns
void
Inherited from
ShadowRoot.append
appendChild()
appendChild<
T
>(node
):T
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21748
The appendChild()
method of the Node interface adds a node to the end of the list of children of a specified parent node.
Type Parameters
T
T
extends Node
Parameters
node
T
Returns
T
Inherited from
ShadowRoot.appendChild
cloneNode()
cloneNode(
subtree?
):Node
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21754
The cloneNode()
method of the Node interface returns a duplicate of the node on which this method was called.
Parameters
subtree?
boolean
Returns
Node
Inherited from
ShadowRoot.cloneNode
compareDocumentPosition()
compareDocumentPosition(
other
):number
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21760
The compareDocumentPosition()
method of the Node interface reports the position of its argument node relative to the node on which it is called.
Parameters
other
Node
Returns
number
Inherited from
ShadowRoot.compareDocumentPosition
contains()
contains(
other
):boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21766
The contains()
method of the Node interface returns a boolean value indicating whether a node is a descendant of a given node, that is the node itself, one of its direct children (Node.childNodes), one of the children's direct children, and so on.
Parameters
other
null
| Node
Returns
boolean
Inherited from
ShadowRoot.contains
dispatchEvent()
dispatchEvent(
event
):boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:11575
The dispatchEvent()
method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.
Parameters
event
Event
Returns
boolean
Inherited from
ShadowRoot.dispatchEvent
elementFromPoint()
elementFromPoint(
x
,y
):null
|Element
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10454
Parameters
x
number
y
number
Returns
null
| Element
Inherited from
ShadowRoot.elementFromPoint
elementsFromPoint()
elementsFromPoint(
x
,y
):Element
[]
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10455
Parameters
x
number
y
number
Returns
Element
[]
Inherited from
ShadowRoot.elementsFromPoint
getAnimations()
getAnimations():
Animation
[]
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10457
Returns
Animation
[]
Inherited from
ShadowRoot.getAnimations
getElementById()
getElementById(
elementId
):null
|HTMLElement
Defined in: node_modules/typescript/lib/lib.dom.d.ts:10418
Returns the first element within node's descendants whose ID is elementId.
Parameters
elementId
string
Returns
null
| HTMLElement
Inherited from
ShadowRoot.getElementById
getHTML()
getHTML(
options?
):string
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30783
The getHTML()
method of the ShadowRoot interface is used to serialize a shadow root's DOM to an HTML string.
Parameters
options?
GetHTMLOptions
Returns
string
Inherited from
ShadowRoot.getHTML
getRootNode()
getRootNode(
options?
):Node
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21772
The getRootNode()
method of the Node interface returns the context object's root, which optionally includes the shadow root if it is available.
Parameters
options?
GetRootNodeOptions
Returns
Node
Inherited from
ShadowRoot.getRootNode
getSelection()
getSelection():
null
|Selection
Defined in: packages/lexical/src/LexicalSelection.ts:137
Experimental API for getting selection within shadow DOM. Available in some browsers as experimental feature.
Returns
null
| Selection
Selection object or null if no selection
hasChildNodes()
hasChildNodes():
boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21778
The hasChildNodes()
method of the Node interface returns a boolean value indicating whether the given Node has child nodes or not.
Returns
boolean
Inherited from
ShadowRoot.hasChildNodes
insertBefore()
insertBefore<
T
>(node
,child
):T
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21784
The insertBefore()
method of the Node interface inserts a node before a reference node as a child of a specified parent node.
Type Parameters
T
T
extends Node
Parameters
node
T
child
null
| Node
Returns
T
Inherited from
ShadowRoot.insertBefore
isDefaultNamespace()
isDefaultNamespace(
namespace
):boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21790
The isDefaultNamespace()
method of the Node interface accepts a namespace URI as an argument.
Parameters
namespace
null
| string
Returns
boolean
Inherited from
ShadowRoot.isDefaultNamespace
isEqualNode()
isEqualNode(
otherNode
):boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21796
The isEqualNode()
method of the Node interface tests whether two nodes are equal.
Parameters
otherNode
null
| Node
Returns
boolean
Inherited from
ShadowRoot.isEqualNode
isSameNode()
isSameNode(
otherNode
):boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21802
The isSameNode()
method of the Node interface is a legacy alias the for the ===
strict equality operator.
Parameters
otherNode
null
| Node
Returns
boolean
Inherited from
ShadowRoot.isSameNode
lookupNamespaceURI()
lookupNamespaceURI(
prefix
):null
|string
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21808
The lookupNamespaceURI()
method of the Node interface takes a prefix as parameter and returns the namespace URI associated with it on the given node if found (and null
if not).
Parameters
prefix
null
| string
Returns
null
| string
Inherited from
ShadowRoot.lookupNamespaceURI
lookupPrefix()
lookupPrefix(
namespace
):null
|string
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21814
The lookupPrefix()
method of the Node interface returns a string containing the prefix for a given namespace URI, if present, and null
if not.
Parameters
namespace
null
| string
Returns
null
| string
Inherited from
ShadowRoot.lookupPrefix
normalize()
normalize():
void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21820
The normalize()
method of the Node interface puts the specified node and all of its sub-tree into a normalized form.
Returns
void
Inherited from
ShadowRoot.normalize
prepend()
prepend(...
nodes
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22702
Inserts nodes before the first child of node, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
Parameters
nodes
...(string
| Node
)[]
Returns
void
Inherited from
ShadowRoot.prepend
querySelector()
Call Signature
querySelector<
K
>(selectors
):null
|HTMLElementTagNameMap
[K
]
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22708
Returns the first element that is a descendant of node that matches selectors.
Type Parameters
K
K
extends keyof HTMLElementTagNameMap
Parameters
selectors
K
Returns
null
| HTMLElementTagNameMap
[K
]
Inherited from
ShadowRoot.querySelector
Call Signature
querySelector<
K
>(selectors
):null
|SVGElementTagNameMap
[K
]
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22709
Type Parameters
K
K
extends keyof SVGElementTagNameMap
Parameters
selectors
K
Returns
null
| SVGElementTagNameMap
[K
]
Inherited from
ShadowRoot.querySelector
Call Signature
querySelector<
K
>(selectors
):null
|MathMLElementTagNameMap
[K
]
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22710
Type Parameters
K
K
extends keyof MathMLElementTagNameMap
Parameters
selectors
K
Returns
null
| MathMLElementTagNameMap
[K
]
Inherited from
ShadowRoot.querySelector
Call Signature
querySelector<
K
>(selectors
):null
|HTMLElementDeprecatedTagNameMap
[K
]
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22712
Type Parameters
K
K
extends keyof HTMLElementDeprecatedTagNameMap
Parameters
selectors
K
Returns
null
| HTMLElementDeprecatedTagNameMap
[K
]
Deprecated
Inherited from
ShadowRoot.querySelector
Call Signature
querySelector<
E
>(selectors
):null
|E
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22713
Type Parameters
E
E
extends Element
= Element
Parameters
selectors
string
Returns
null
| E
Inherited from
ShadowRoot.querySelector
querySelectorAll()
Call Signature
querySelectorAll<
K
>(selectors
):NodeListOf
<HTMLElementTagNameMap
[K
]>
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22719
Returns all element descendants of node that match selectors.
Type Parameters
K
K
extends keyof HTMLElementTagNameMap
Parameters
selectors
K
Returns
NodeListOf
<HTMLElementTagNameMap
[K
]>
Inherited from
ShadowRoot.querySelectorAll
Call Signature
querySelectorAll<
K
>(selectors
):NodeListOf
<SVGElementTagNameMap
[K
]>
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22720
Type Parameters
K
K
extends keyof SVGElementTagNameMap
Parameters
selectors
K
Returns
NodeListOf
<SVGElementTagNameMap
[K
]>
Inherited from
ShadowRoot.querySelectorAll
Call Signature
querySelectorAll<
K
>(selectors
):NodeListOf
<MathMLElementTagNameMap
[K
]>
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22721
Type Parameters
K
K
extends keyof MathMLElementTagNameMap
Parameters
selectors
K
Returns
NodeListOf
<MathMLElementTagNameMap
[K
]>
Inherited from
ShadowRoot.querySelectorAll
Call Signature
querySelectorAll<
K
>(selectors
):NodeListOf
<HTMLElementDeprecatedTagNameMap
[K
]>
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22723
Type Parameters
K
K
extends keyof HTMLElementDeprecatedTagNameMap
Parameters
selectors
K
Returns
NodeListOf
<HTMLElementDeprecatedTagNameMap
[K
]>
Deprecated
Inherited from
ShadowRoot.querySelectorAll
Call Signature
querySelectorAll<
E
>(selectors
):NodeListOf
<E
>
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22724
Type Parameters
E
E
extends Element
= Element
Parameters
selectors
string
Returns
NodeListOf
<E
>
Inherited from
ShadowRoot.querySelectorAll
removeChild()
removeChild<
T
>(child
):T
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21826
The removeChild()
method of the Node interface removes a child node from the DOM and returns the removed node.
Type Parameters
T
T
extends Node
Parameters
child
T
Returns
T
Inherited from
ShadowRoot.removeChild
removeEventListener()
Call Signature
removeEventListener<
K
>(type
,listener
,options?
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30792
The removeEventListener()
method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.
Type Parameters
K
K
extends "slotchange"
Parameters
type
K
listener
(this
, ev
) => any
options?
boolean
| EventListenerOptions
Returns
void
Inherited from
ShadowRoot.removeEventListener
Call Signature
removeEventListener(
type
,listener
,options?
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30793
The removeEventListener()
method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.
Parameters
type
string
listener
EventListenerOrEventListenerObject
options?
boolean
| EventListenerOptions
Returns
void
Inherited from
ShadowRoot.removeEventListener
replaceChild()
replaceChild<
T
>(node
,child
):T
Defined in: node_modules/typescript/lib/lib.dom.d.ts:21832
The replaceChild()
method of the Node interface replaces a child node within the given (parent) node.
Type Parameters
T
T
extends Node
Parameters
node
Node
child
T
Returns
T
Inherited from
ShadowRoot.replaceChild
replaceChildren()
replaceChildren(...
nodes
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:22732
Replace all children of node with nodes, while replacing strings in nodes with equivalent Text nodes.
Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
Parameters
nodes
...(string
| Node
)[]
Returns
void
Inherited from
ShadowRoot.replaceChildren
setHTMLUnsafe()
setHTMLUnsafe(
html
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:30789
The setHTMLUnsafe()
method of the ShadowRoot interface can be used to parse a string of HTML into a DocumentFragment, optionally filtering out unwanted elements and attributes, and then use it to replace the existing tree in the Shadow DOM.
Parameters
html
string
Returns
void
Inherited from
ShadowRoot.setHTMLUnsafe
SiblingCaret<T, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:174
A SiblingCaret points from an origin LexicalNode towards its next or previous sibling.
Extends
BaseCaret
<T
,D
,"sibling"
>
Type Parameters
T
T
extends LexicalNode
= LexicalNode
D
D
extends CaretDirection
= CaretDirection
Properties
direction
readonly
direction:D
Defined in: packages/lexical/src/caret/LexicalCaret.ts:57
next if pointing at the next sibling or first child, previous if pointing at the previous sibling or last child
Inherited from
getAdjacentCaret()
getAdjacentCaret: () =>
null
|SiblingCaret
<LexicalNode
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:63
Get a new SiblingCaret from getNodeAtCaret() in the same direction.
Returns
null
| SiblingCaret
<LexicalNode
, D
>
Inherited from
getChildCaret()
getChildCaret: () =>
null
|ChildCaret
<T
&ElementNode
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:184
If the origin of this node is an ElementNode, return the ChildCaret of this origin in the same direction. If the origin is not an ElementNode, this will return null.
Returns
null
| ChildCaret
<T
& ElementNode
, D
>
getFlipped()
getFlipped: () =>
NodeCaret
<FlipDirection
<D
>>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:221
Get a new NodeCaret with the head and tail of its directional arrow flipped, such that flipping twice is the identity. For example, given a non-empty parent with a firstChild and lastChild, and a second emptyParent node with no children:
Returns
Example
caret.getFlipped().getFlipped().is(caret) === true;
$getChildCaret(parent, 'next').getFlipped().is($getSiblingCaret(firstChild, 'previous')) === true;
$getSiblingCaret(lastChild, 'next').getFlipped().is($getChildCaret(parent, 'previous')) === true;
$getSiblingCaret(firstChild, 'next).getFlipped().is($getSiblingCaret(lastChild, 'previous')) === true;
$getChildCaret(emptyParent, 'next').getFlipped().is($getChildCaret(emptyParent, 'previous')) === true;
getLatest()
getLatest: () =>
SiblingCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:179
Get a new caret with the latest origin pointer
Returns
SiblingCaret
<T
, D
>
getNodeAtCaret()
getNodeAtCaret: () =>
null
|LexicalNode
Defined in: packages/lexical/src/caret/LexicalCaret.ts:61
Get the node connected to the origin in the caret's direction, or null if there is no node
Returns
null
| LexicalNode
Inherited from
getParentAtCaret()
getParentAtCaret: () =>
null
|ElementNode
Defined in: packages/lexical/src/caret/LexicalCaret.ts:59
Get the ElementNode that is the logical parent (origin
for ChildCaret
, origin.getParent()
for SiblingCaret
)
Returns
null
| ElementNode
Inherited from
getParentCaret()
getParentCaret: (
mode?
) =>null
|SiblingCaret
<ElementNode
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:191
Get the caret in the same direction from the parent of this origin.
Parameters
mode?
'root' to return null at the root, 'shadowRoot' to return null at the root or any shadow root
Returns
null
| SiblingCaret
<ElementNode
, D
>
A SiblingCaret with the parent of this origin, or null if the parent is a root according to mode.
getSiblingCaret()
getSiblingCaret: () =>
SiblingCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:67
Get a new SiblingCaret with this same node
Returns
SiblingCaret
<T
, D
>
Inherited from
insert()
insert: (
node
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:75
Insert a node connected to origin in this direction (before the node that this caret is pointing towards, if any existed).
For a SiblingCaret
this is origin.insertAfter(node)
for next, or origin.insertBefore(node)
for previous.
For a ChildCaret
this is origin.splice(0, 0, [node])
for next or origin.append(node)
for previous.
Parameters
node
Returns
this
Inherited from
isSameNodeCaret()
isSameNodeCaret: (
other
) => other is (SiblingCaret<T, D> | T) extends TextNode ? TextPointCaret<T & TextNode, D> : never
Defined in: packages/lexical/src/caret/LexicalCaret.ts:196
Return true if other is a SiblingCaret or TextPointCaret with the same origin (by node key comparison) and direction.
Parameters
other
undefined
| null
| PointCaret
<CaretDirection
>
Returns
other is (SiblingCaret<T, D> | T) extends TextNode ? TextPointCaret<T & TextNode, D> : never
isSamePointCaret()
isSamePointCaret: (
other
) =>other is SiblingCaret<T, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:205
Return true if other is a SiblingCaret with the same origin (by node key comparison) and direction.
Parameters
other
undefined
| null
| PointCaret
<CaretDirection
>
Returns
other is SiblingCaret<T, D>
origin
readonly
origin:T
Defined in: packages/lexical/src/caret/LexicalCaret.ts:53
The origin node of this caret, typically this is what you will use in traversals
Inherited from
remove()
remove: () =>
this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:69
Remove the getNodeAtCaret() node that this caret is pointing towards, if it exists
Returns
this
Inherited from
replaceOrInsert()
replaceOrInsert: (
node
,includeChildren?
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:77
If getNodeAtCaret() is not null then replace it with node, otherwise insert node
Parameters
node
includeChildren?
boolean
Returns
this
Inherited from
splice()
splice: (
deleteCount
,nodes
,nodesDirection?
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:85
Splice an iterable (typically an Array) of nodes into this location.
Parameters
deleteCount
number
The number of existing nodes to replace or delete
nodes
Iterable
<LexicalNode
>
An iterable of nodes that will be inserted in this location, using replace instead of insert for the first deleteCount nodes
nodesDirection?
The direction of the nodes iterable, defaults to 'next'
Returns
this
Inherited from
type
readonly
type:"sibling"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:55
sibling for a SiblingCaret (pointing at the next or previous sibling) or child for a ChildCaret (pointing at the first or last child)
Inherited from
SplitAtPointCaretNextOptions
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:662
Properties
$copyElementNode()?
optional
$copyElementNode: (node
) =>ElementNode
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:664
The function to create the right side of a split ElementNode (default $copyNode)
Parameters
node
Returns
$shouldSplit()?
optional
$shouldSplit: (node
,edge
) =>boolean
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:676
If element.canBeEmpty() and would create an empty split, this function will be
called with the element and 'first' | 'last'. If it returns false, the empty
split will not be created. Default is () => true
to always split when possible.
Parameters
node
edge
"first"
| "last"
Returns
boolean
$splitTextPointCaretNext()?
optional
$splitTextPointCaretNext: (caret
) =>NodeCaret
<"next"
>
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:666
The function to split a TextNode (default $splitTextPointCaret)
Parameters
caret
TextPointCaret
<TextNode
, "next"
>
Returns
NodeCaret
<"next"
>
rootMode?
optional
rootMode:RootMode
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:670
If the parent matches rootMode a split will not occur, default is 'shadowRoot'
StateConfig<K, V>
Defined in: packages/lexical/src/LexicalNodeState.ts:232
The return value of createState, for use with $getState and $setState.
Type Parameters
K
K
extends string
V
V
Properties
defaultValue
readonly
defaultValue:V
Defined in: packages/lexical/src/LexicalNodeState.ts:253
The result of stateValueConfig.parse(undefined)
, which is computed only
once and used as the default value. When the current value isEqual
to
the defaultValue
, it will not be serialized to JSON.
isEqual()
readonly
isEqual: (a
,b
) =>boolean
Defined in: packages/lexical/src/LexicalNodeState.ts:247
An equality function from the StateValueConfig, with a default of Object.is.
Parameters
a
V
b
V
Returns
boolean
key
readonly
key:K
Defined in: packages/lexical/src/LexicalNodeState.ts:234
The string key used when serializing this state to JSON
parse()
readonly
parse: (value?
) =>V
Defined in: packages/lexical/src/LexicalNodeState.ts:236
The parse function from the StateValueConfig passed to createState
Parameters
value?
unknown
Returns
V
unparse()
readonly
unparse: (value
) =>unknown
Defined in: packages/lexical/src/LexicalNodeState.ts:242
The unparse function from the StateValueConfig passed to createState, with a default that is simply a pass-through that assumes the value is JSON serializable.
Parameters
value
V
Returns
unknown
StateValueConfig<V>
Defined in: packages/lexical/src/LexicalNodeState.ts:188
Configure a value to be used with StateConfig.
The value type should be inferred from the definition of parse.
If the value type is not JSON serializable, then unparse must also be provided.
Values should be treated as immutable, much like React.useState. Mutating stored values directly will cause unpredictable behavior, is not supported, and may trigger errors in the future.
Examples
const numberOrNullState = createState('numberOrNull', {parse: (v) => typeof v === 'number' ? v : null});
// ^? State<'numberOrNull', StateValueConfig<number | null>>
const numberState = createState('number', {parse: (v) => typeof v === 'number' ? v : 0});
// ^? State<'number', StateValueConfig<number>>
Only the parse option is required, it is generally not useful to
override unparse
or isEqual
. However, if you are using
non-primitive types such as Array, Object, Date, or something
more exotic then you would want to override this. In these
cases you might want to reach for third party libraries.
const isoDateState = createState('isoDate', {
parse: (v): null | Date => {
const date = typeof v === 'string' ? new Date(v) : null;
return date && !isNaN(date.valueOf()) ? date : null;
}
isEqual: (a, b) => a === b || (a && b && a.valueOf() === b.valueOf()),
unparse: (v) => v && v.toString()
});
You may find it easier to write a parse function using libraries like zod, valibot, ajv, Effect, TypeBox, etc. perhaps with a wrapper function.
Type Parameters
V
V
Properties
isEqual()?
optional
isEqual: (a
,b
) =>boolean
Defined in: packages/lexical/src/LexicalNodeState.ts:225
This is optional and for advanced use cases only.
Used to define the equality function so you can use an Array or Object as V and still omit default values from the exported JSON.
The default is Object.is
, but something like fast-deep-equal
might be
more appropriate for your use case.
Parameters
a
V
b
V
Returns
boolean
parse()
parse: (
jsonValue
) =>V
Defined in: packages/lexical/src/LexicalNodeState.ts:208
This function must return a default value when called with undefined, otherwise it should parse the given JSON value to your type V. Note that it is not required to copy or clone the given value, you can pass it directly through if it matches the expected type.
When you encounter an invalid value, it's up to you to decide as to whether to ignore it and return the default value, return some non-default error value, or throw an error.
It is possible for V to include undefined, but if it does, then it should also be considered the default value since undefined can not be serialized to JSON so it is indistinguishable from the default.
Similarly, if your V is a function, then usage of $setState must use an updater function because your type will be indistinguishable from an updater function.
Parameters
jsonValue
unknown
Returns
V
unparse()?
optional
unparse: (parsed
) =>unknown
Defined in: packages/lexical/src/LexicalNodeState.ts:215
This is optional and for advanced use cases only.
You may specify a function that converts V back to JSON. This is mandatory when V is not a JSON serializable type.
Parameters
parsed
V
Returns
unknown
StaticNodeConfigValue<T, Type>
Defined in: packages/lexical/src/LexicalNode.ts:99
EXPERIMENTAL The configuration of a node returned by LexicalNode.$config()
Example
class CustomText extends TextNode {
$config() {
return this.config('custom-text', {extends: TextNode}};
}
}
Type Parameters
T
T
extends LexicalNode
Type
Type
extends string
Properties
$importJSON()?
readonly
optional
$importJSON: (serializedNode
) =>T
Defined in: packages/lexical/src/LexicalNode.ts:117
An alternative to the static importJSON() method that provides better type inference.
Parameters
serializedNode
Returns
T
$transform()?
readonly
optional
$transform: (node
) =>void
Defined in: packages/lexical/src/LexicalNode.ts:112
An alternative to the internal static transform() method that provides better type inference.
Parameters
node
T
Returns
void
extends?
readonly
optional
extends:KlassConstructor
<typeofLexicalNode
>
Defined in: packages/lexical/src/LexicalNode.ts:163
If specified, this must be the exact superclass of the node. It is not checked at compile time and it is provided automatically at runtime.
You would want to specify this when you are extending a node that has non-trivial configuration in its $config such as required state. If you do not specify this, the inferred types for your node class might be missing some of that.
importDOM?
readonly
optional
importDOM:DOMConversionMap
<HTMLElement
>
Defined in: packages/lexical/src/LexicalNode.ts:121
An alternative to the static importDOM() method
stateConfigs?
readonly
optional
stateConfigs: readonlyRequiredNodeStateConfig
[]
Defined in: packages/lexical/src/LexicalNode.ts:153
EXPERIMENTAL
An array of RequiredNodeStateConfig to initialize your node with its state requirements. This may be used to configure serialization of that state.
This function will be called (at most) once per editor initialization, directly on your node's prototype. It must not depend on any state initialized in the constructor.
Example
const flatState = createState("flat", {parse: parseNumber});
const nestedState = createState("nested", {parse: parseNumber});
class MyNode extends TextNode {
$config() {
return this.config(
'my-node',
{
extends: TextNode,
stateConfigs: [
{ stateConfig: flatState, flat: true},
nestedState,
]
},
);
}
}
type?
readonly
optional
type:Type
Defined in: packages/lexical/src/LexicalNode.ts:107
The exact type of T.getType(), e.g. 'text' - the method itself must have a more generic 'string' type to be compatible wtih subclassing.
StepwiseIteratorConfig<State, Stop, Value>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:125
Type Parameters
State
State
Stop
Stop
Value
Value
Properties
hasNext()
readonly
hasNext: (value
) =>value is State
Defined in: packages/lexical/src/caret/LexicalCaret.ts:127
Parameters
value
State
| Stop
Returns
value is State
initial
readonly
initial:State
|Stop
Defined in: packages/lexical/src/caret/LexicalCaret.ts:126
map()
readonly
map: (value
) =>Value
Defined in: packages/lexical/src/caret/LexicalCaret.ts:129
Parameters
value
State
Returns
Value
step()
readonly
step: (value
) =>State
|Stop
Defined in: packages/lexical/src/caret/LexicalCaret.ts:128
Parameters
value
State
Returns
State
| Stop
TextPointCaret<T, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:280
A TextPointCaret is a special case of a SiblingCaret that also carries an offset used for representing partially selected TextNode at the edges of a CaretRange.
The direction determines which part of the text is adjacent to the caret, if next it's all of the text after offset. If previous, it's all of the text before offset.
While this can be used in place of any SiblingCaret of a TextNode, the offset into the text will be ignored except in contexts that specifically use the TextPointCaret or PointCaret types.
Extends
BaseCaret
<T
,D
,"text"
>
Type Parameters
T
D
D
extends CaretDirection
= CaretDirection
Properties
direction
readonly
direction:D
Defined in: packages/lexical/src/caret/LexicalCaret.ts:57
next if pointing at the next sibling or first child, previous if pointing at the previous sibling or last child
Inherited from
getAdjacentCaret()
getAdjacentCaret: () =>
null
|SiblingCaret
<LexicalNode
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:63
Get a new SiblingCaret from getNodeAtCaret() in the same direction.
Returns
null
| SiblingCaret
<LexicalNode
, D
>
Inherited from
getChildCaret()
getChildCaret: () =>
null
Defined in: packages/lexical/src/caret/LexicalCaret.ts:291
A TextPointCaret can not have a ChildCaret.
Returns
null
getFlipped()
getFlipped: () =>
TextPointCaret
<T
,FlipDirection
<D
>>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:322
Get a new TextPointCaret with the head and tail of its directional arrow flipped, such that flipping twice is the identity. For a TextPointCaret this merely flips the direction because the arrow is internal to the node.
Returns
TextPointCaret
<T
, FlipDirection
<D
>>
Example
caret.getFlipped().getFlipped().is(caret) === true;
getLatest()
getLatest: () =>
TextPointCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:287
Get a new caret with the latest origin pointer
Returns
TextPointCaret
<T
, D
>
getNodeAtCaret()
getNodeAtCaret: () =>
null
|LexicalNode
Defined in: packages/lexical/src/caret/LexicalCaret.ts:61
Get the node connected to the origin in the caret's direction, or null if there is no node
Returns
null
| LexicalNode
Inherited from
getParentAtCaret()
getParentAtCaret: () =>
null
|ElementNode
Defined in: packages/lexical/src/caret/LexicalCaret.ts:59
Get the ElementNode that is the logical parent (origin
for ChildCaret
, origin.getParent()
for SiblingCaret
)
Returns
null
| ElementNode
Inherited from
getParentCaret()
getParentCaret: (
mode?
) =>null
|SiblingCaret
<ElementNode
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:298
Get the caret in the same direction from the parent of this origin.
Parameters
mode?
'root' to return null at the root, 'shadowRoot' to return null at the root or any shadow root
Returns
null
| SiblingCaret
<ElementNode
, D
>
A SiblingCaret with the parent of this origin, or null if the parent is a root according to mode.
getSiblingCaret()
getSiblingCaret: () =>
SiblingCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:67
Get a new SiblingCaret with this same node
Returns
SiblingCaret
<T
, D
>
Inherited from
insert()
insert: (
node
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:75
Insert a node connected to origin in this direction (before the node that this caret is pointing towards, if any existed).
For a SiblingCaret
this is origin.insertAfter(node)
for next, or origin.insertBefore(node)
for previous.
For a ChildCaret
this is origin.splice(0, 0, [node])
for next or origin.append(node)
for previous.
Parameters
node
Returns
this
Inherited from
isSameNodeCaret()
isSameNodeCaret: (
other
) => other is TextPointCaret<T, D> | SiblingCaret<T, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:303
Return true if other is a TextPointCaret or SiblingCaret with the same origin (by node key comparison) and direction.
Parameters
other
undefined
| null
| PointCaret
<CaretDirection
>
Returns
other is TextPointCaret<T, D> | SiblingCaret<T, D>
isSamePointCaret()
isSamePointCaret: (
other
) =>other is TextPointCaret<T, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:310
Return true if other is a ChildCaret with the same origin (by node key comparison) and direction.
Parameters
other
undefined
| null
| PointCaret
<CaretDirection
>
Returns
other is TextPointCaret<T, D>
offset
readonly
offset:number
Defined in: packages/lexical/src/caret/LexicalCaret.ts:285
The offset into the string
origin
readonly
origin:T
Defined in: packages/lexical/src/caret/LexicalCaret.ts:53
The origin node of this caret, typically this is what you will use in traversals
Inherited from
remove()
remove: () =>
this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:69
Remove the getNodeAtCaret() node that this caret is pointing towards, if it exists
Returns
this
Inherited from
replaceOrInsert()
replaceOrInsert: (
node
,includeChildren?
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:77
If getNodeAtCaret() is not null then replace it with node, otherwise insert node
Parameters
node
includeChildren?
boolean
Returns
this
Inherited from
splice()
splice: (
deleteCount
,nodes
,nodesDirection?
) =>this
Defined in: packages/lexical/src/caret/LexicalCaret.ts:85
Splice an iterable (typically an Array) of nodes into this location.
Parameters
deleteCount
number
The number of existing nodes to replace or delete
nodes
Iterable
<LexicalNode
>
An iterable of nodes that will be inserted in this location, using replace instead of insert for the first deleteCount nodes
nodesDirection?
The direction of the nodes iterable, defaults to 'next'
Returns
this
Inherited from
type
readonly
type:"text"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:55
sibling for a SiblingCaret (pointing at the next or previous sibling) or child for a ChildCaret (pointing at the first or last child)
Inherited from
TextPointCaretSlice<T, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:332
A TextPointCaretSlice is a wrapper for a TextPointCaret that carries a signed distance representing the direction and amount of text selected from the given caret. A negative distance means that text before offset is selected, a positive distance means that text after offset is selected. The offset+distance pair is not affected in any way by the direction of the caret.
Type Parameters
T
D
D
extends CaretDirection
= CaretDirection
Properties
caret
readonly
caret:TextPointCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:337
distance
readonly
distance:number
Defined in: packages/lexical/src/caret/LexicalCaret.ts:338
getSliceIndices()
getSliceIndices: () => [
number
,number
]
Defined in: packages/lexical/src/caret/LexicalCaret.ts:342
Returns
[number
, number
]
absolute coordinates into the text (for use with text.slice(...)
)
getTextContent()
getTextContent: () =>
string
Defined in: packages/lexical/src/caret/LexicalCaret.ts:346
Returns
string
The text represented by the slice
getTextContentSize()
getTextContentSize: () =>
number
Defined in: packages/lexical/src/caret/LexicalCaret.ts:350
Returns
number
The size of the text represented by the slice
type
readonly
type:"slice"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:336
Methods
removeTextSlice()
removeTextSlice():
TextPointCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:362
Remove the slice of text from the contained caret, returning a new TextPointCaret without the wrapper (since the size would be zero).
Note that this is a lower-level utility that does not have any specific behavior for 'segmented' or 'token' modes and it will not remove an empty TextNode.
Returns
TextPointCaret
<T
, D
>
The inner TextPointCaret with the same offset and direction and the latest TextNode origin after mutation
UpdateListenerPayload
Defined in: packages/lexical/src/LexicalEditor.ts:268
The payload passed to an UpdateListener
Properties
dirtyElements
dirtyElements:
Map
<string
,boolean
>
Defined in: packages/lexical/src/LexicalEditor.ts:274
A Map of NodeKeys of ElementNodes to a boolean that is true if the node was intentionally mutated ('unintentional' mutations are triggered when an indirect descendant is marked dirty)
dirtyLeaves
dirtyLeaves:
Set
<string
>
Defined in: packages/lexical/src/LexicalEditor.ts:279
A Set of NodeKeys of all nodes that were marked dirty that do not inherit from ElementNode.
editorState
editorState:
EditorState
Defined in: packages/lexical/src/LexicalEditor.ts:284
The new EditorState after all updates have been processed,
equivalent to editor.getEditorState()
mutatedNodes
mutatedNodes:
null
|MutatedNodes
Defined in: packages/lexical/src/LexicalEditor.ts:296
The Map of LexicalNode constructors to a Map<NodeKey, NodeMutation>
,
this is useful when you have a mutation listener type use cases that
should apply to all or most nodes. Will be null if no DOM was mutated,
such as when only the selection changed. Note that this will be empty
unless at least one MutationListener is explicitly registered
(any MutationListener is sufficient to compute the mutatedNodes Map
for all nodes).
Added in v0.28.0
normalizedNodes
normalizedNodes:
Set
<string
>
Defined in: packages/lexical/src/LexicalEditor.ts:305
For advanced use cases only.
Tracks the keys of TextNode descendants that have been merged with their siblings by normalization. Note that these keys may not exist in either editorState or prevEditorState and generally this is only used for conflict resolution edge cases in collab.
prevEditorState
prevEditorState:
EditorState
Defined in: packages/lexical/src/LexicalEditor.ts:309
The previous EditorState that is being discarded
tags
tags:
Set
<string
>
Defined in: packages/lexical/src/LexicalEditor.ts:315
The set of tags added with update options or $addUpdateTag, node that this includes all tags that were processed in this reconciliation which may have been added by separate updates.
Type Aliases
AnyStateConfig
AnyStateConfig =
StateConfig
<any
,any
>
Defined in: packages/lexical/src/LexicalNodeState.ts:281
For advanced use cases, using this type is not recommended unless it is required (due to TypeScript's lack of features like higher-kinded types).
A StateConfig type with any key and any value that can be used in situations where the key and value type can not be known, such as in a generic constraint when working with a collection of StateConfig.
StateConfigKey and StateConfigValue will be useful when this is used as a generic constraint.
BaseStaticNodeConfig
BaseStaticNodeConfig =
{ readonly [K in string]?: StaticNodeConfigValue<LexicalNode, string> }
Defined in: packages/lexical/src/LexicalNode.ts:170
This is the type of LexicalNode.$config() that can be overridden by subclasses.
CaretDirection
CaretDirection =
"next"
|"previous"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:22
The direction of a caret, 'next' points towards the end of the document and 'previous' points towards the beginning
CaretType
CaretType =
"sibling"
|"child"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:32
A sibling caret type points from a LexicalNode origin to its next or previous sibling, and a child caret type points from an ElementNode origin to its first or last child.
CommandListener()<P>
CommandListener<
P
> = (payload
,editor
) =>boolean
Defined in: packages/lexical/src/LexicalEditor.ts:343
Type Parameters
P
P
Parameters
payload
P
editor
Returns
boolean
CommandListenerPriority
CommandListenerPriority =
0
|1
|2
|3
|4
Defined in: packages/lexical/src/LexicalEditor.ts:347
CommandPayloadType<TCommand>
CommandPayloadType<
TCommand
> =TCommand
extendsLexicalCommand
<infer TPayload> ?TPayload
:never
Defined in: packages/lexical/src/LexicalEditor.ts:380
Type helper for extracting the payload type from a command.
Type Parameters
TCommand
TCommand
extends LexicalCommand
<unknown
>
Example
const MY_COMMAND = createCommand<SomeType>();
// ...
editor.registerCommand(MY_COMMAND, payload => {
// Type of `payload` is inferred here. But lets say we want to extract a function to delegate to
$handleMyCommand(editor, payload);
return true;
});
function $handleMyCommand(editor: LexicalEditor, payload: CommandPayloadType<typeof MY_COMMAND>) {
// `payload` is of type `SomeType`, extracted from the command.
}
CommonAncestorResult<A, B>
CommonAncestorResult<
A
,B
> =CommonAncestorResultSame
<A
> |CommonAncestorResultAncestor
<A
&ElementNode
> |CommonAncestorResultDescendant
<B
&ElementNode
> |CommonAncestorResultBranch
<A
,B
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1332
The result of comparing two nodes that share some common ancestor
Type Parameters
A
A
extends LexicalNode
B
B
extends LexicalNode
CreateEditorArgs
CreateEditorArgs =
object
Defined in: packages/lexical/src/LexicalEditor.ts:217
Properties
disableEvents?
optional
disableEvents:boolean
Defined in: packages/lexical/src/LexicalEditor.ts:218
editable?
optional
editable:boolean
Defined in: packages/lexical/src/LexicalEditor.ts:224
editorState?
optional
editorState:EditorState
Defined in: packages/lexical/src/LexicalEditor.ts:219
html?
optional
html:HTMLConfig
Defined in: packages/lexical/src/LexicalEditor.ts:226
namespace?
optional
namespace:string
Defined in: packages/lexical/src/LexicalEditor.ts:220
nodes?
optional
nodes:ReadonlyArray
<LexicalNodeConfig
>
Defined in: packages/lexical/src/LexicalEditor.ts:221
onError?
optional
onError:ErrorHandler
Defined in: packages/lexical/src/LexicalEditor.ts:222
parentEditor?
optional
parentEditor:LexicalEditor
Defined in: packages/lexical/src/LexicalEditor.ts:223
theme?
optional
theme:EditorThemeClasses
Defined in: packages/lexical/src/LexicalEditor.ts:225
DOMChildConversion()
DOMChildConversion = (
lexicalNode
,parentLexicalNode
) =>LexicalNode
|null
|undefined
Defined in: packages/lexical/src/LexicalNode.ts:353
Parameters
lexicalNode
parentLexicalNode
LexicalNode
| null
| undefined
Returns
LexicalNode
| null
| undefined
DOMConversion<T>
DOMConversion<
T
> =object
Defined in: packages/lexical/src/LexicalNode.ts:344
Type Parameters
T
T
extends HTMLElement
= HTMLElement
Properties
conversion
conversion:
DOMConversionFn
<T
>
Defined in: packages/lexical/src/LexicalNode.ts:345
priority?
optional
priority:0
|1
|2
|3
|4
Defined in: packages/lexical/src/LexicalNode.ts:346
DOMConversionFn()<T>
DOMConversionFn<
T
> = (element
) =>DOMConversionOutput
|null
Defined in: packages/lexical/src/LexicalNode.ts:349
Type Parameters
T
T
extends HTMLElement
= HTMLElement
Parameters
element
T
Returns
DOMConversionOutput
| null
DOMConversionMap<T>
DOMConversionMap<
T
> =Record
<NodeName
,DOMConversionProp
<T
>>
Defined in: packages/lexical/src/LexicalNode.ts:358
Type Parameters
T
T
extends HTMLElement
= HTMLElement
DOMConversionOutput
DOMConversionOutput =
object
Defined in: packages/lexical/src/LexicalNode.ts:364
Properties
after()?
optional
after: (childLexicalNodes
) =>LexicalNode
[]
Defined in: packages/lexical/src/LexicalNode.ts:365
Parameters
childLexicalNodes
Returns
forChild?
optional
forChild:DOMChildConversion
Defined in: packages/lexical/src/LexicalNode.ts:366
node
node:
null
|LexicalNode
|LexicalNode
[]
Defined in: packages/lexical/src/LexicalNode.ts:367
DOMExportOutput
DOMExportOutput =
object
Defined in: packages/lexical/src/LexicalNode.ts:375
Properties
after()?
optional
after: (generatedElement
) =>HTMLElement
|DocumentFragment
|Text
|null
|undefined
Defined in: packages/lexical/src/LexicalNode.ts:376
Parameters
generatedElement
HTMLElement
| DocumentFragment
| Text
| null
| undefined
Returns
HTMLElement
| DocumentFragment
| Text
| null
| undefined
element
element:
HTMLElement
|DocumentFragment
|Text
|null
Defined in: packages/lexical/src/LexicalNode.ts:379
DOMExportOutputMap
DOMExportOutputMap =
Map
<Klass
<LexicalNode
>, (editor
,target
) =>DOMExportOutput
>
Defined in: packages/lexical/src/LexicalNode.ts:370
EditableListener()
EditableListener = (
editable
) =>void
Defined in: packages/lexical/src/LexicalEditor.ts:345
Parameters
editable
boolean
Returns
void
EditorConfig
EditorConfig =
object
Defined in: packages/lexical/src/LexicalEditor.ts:192
Properties
disableEvents?
optional
disableEvents:boolean
Defined in: packages/lexical/src/LexicalEditor.ts:193
namespace
namespace:
string
Defined in: packages/lexical/src/LexicalEditor.ts:194
theme
theme:
EditorThemeClasses
Defined in: packages/lexical/src/LexicalEditor.ts:195
EditorSetOptions
EditorSetOptions =
object
Defined in: packages/lexical/src/LexicalEditor.ts:116
Properties
tag?
optional
tag:string
Defined in: packages/lexical/src/LexicalEditor.ts:117
EditorThemeClasses
EditorThemeClasses =
object
Defined in: packages/lexical/src/LexicalEditor.ts:128
Indexable
[key
: string
]: any
Properties
blockCursor?
optional
blockCursor:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:129
characterLimit?
optional
characterLimit:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:130
code?
optional
code:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:131
codeHighlight?
optional
codeHighlight:Record
<string
,EditorThemeClassName
>
Defined in: packages/lexical/src/LexicalEditor.ts:132
embedBlock?
optional
embedBlock:object
Defined in: packages/lexical/src/LexicalEditor.ts:183
base?
optional
base:EditorThemeClassName
focus?
optional
focus:EditorThemeClassName
hashtag?
optional
hashtag:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:133
heading?
optional
heading:object
Defined in: packages/lexical/src/LexicalEditor.ts:135
h1?
optional
h1:EditorThemeClassName
h2?
optional
h2:EditorThemeClassName
h3?
optional
h3:EditorThemeClassName
h4?
optional
h4:EditorThemeClassName
h5?
optional
h5:EditorThemeClassName
h6?
optional
h6:EditorThemeClassName
hr?
optional
hr:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:143
hrSelected?
optional
hrSelected:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:144
image?
optional
image:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:145
indent?
optional
indent:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:187
link?
optional
link:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:146
list?
optional
list:object
Defined in: packages/lexical/src/LexicalEditor.ts:147
checklist?
optional
checklist:EditorThemeClassName
listitem?
optional
listitem:EditorThemeClassName
listitemChecked?
optional
listitemChecked:EditorThemeClassName
listitemUnchecked?
optional
listitemUnchecked:EditorThemeClassName
nested?
optional
nested:object
nested.list?
optional
list:EditorThemeClassName
nested.listitem?
optional
listitem:EditorThemeClassName
ol?
optional
ol:EditorThemeClassName
olDepth?
optional
olDepth:EditorThemeClassName
[]
ul?
optional
ul:EditorThemeClassName
ulDepth?
optional
ulDepth:EditorThemeClassName
[]
ltr?
optional
ltr:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:161
mark?
optional
mark:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:162
markOverlap?
optional
markOverlap:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:163
paragraph?
optional
paragraph:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:164
quote?
optional
quote:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:165
root?
optional
root:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:166
rtl?
optional
rtl:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:167
specialText?
optional
specialText:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:134
tab?
optional
tab:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:168
table?
optional
table:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:169
tableAddColumns?
optional
tableAddColumns:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:170
tableAddRows?
optional
tableAddRows:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:171
tableCell?
optional
tableCell:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:175
tableCellActionButton?
optional
tableCellActionButton:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:172
tableCellActionButtonContainer?
optional
tableCellActionButtonContainer:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:173
tableCellHeader?
optional
tableCellHeader:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:176
tableCellResizer?
optional
tableCellResizer:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:177
tableCellSelected?
optional
tableCellSelected:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:174
tableRow?
optional
tableRow:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:178
tableScrollableWrapper?
optional
tableScrollableWrapper:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:179
tableSelected?
optional
tableSelected:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:180
tableSelection?
optional
tableSelection:EditorThemeClassName
Defined in: packages/lexical/src/LexicalEditor.ts:181
text?
optional
text:TextNodeThemeClasses
Defined in: packages/lexical/src/LexicalEditor.ts:182
EditorThemeClassName
EditorThemeClassName =
string
Defined in: packages/lexical/src/LexicalEditor.ts:72
EditorUpdateOptions
EditorUpdateOptions =
object
Defined in: packages/lexical/src/LexicalEditor.ts:91
Properties
discrete?
optional
discrete:true
Defined in: packages/lexical/src/LexicalEditor.ts:111
If true, prevents this update from being batched, forcing it to run synchronously.
onUpdate()?
optional
onUpdate: () =>void
Defined in: packages/lexical/src/LexicalEditor.ts:95
A function to run once the update is complete. See also $onUpdate.
Returns
void
skipTransforms?
optional
skipTransforms:true
Defined in: packages/lexical/src/LexicalEditor.ts:101
Setting this to true will suppress all node transforms for this update cycle. Useful for synchronizing updates in some cases.
tag?
Defined in: packages/lexical/src/LexicalEditor.ts:106
A tag to identify this update, in an update listener, for instance. See also $addUpdateTag.
ElementFormatType
ElementFormatType =
"left"
|"start"
|"center"
|"right"
|"end"
|"justify"
|""
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:68
ElementPoint
ElementPoint =
object
Defined in: packages/lexical/src/LexicalSelection.ts:156
Properties
_selection
_selection:
BaseSelection
Defined in: packages/lexical/src/LexicalSelection.ts:157
getNode()
getNode: () =>
ElementNode
Defined in: packages/lexical/src/LexicalSelection.ts:158
Returns
is()
is: (
point
) =>boolean
Defined in: packages/lexical/src/LexicalSelection.ts:159
Parameters
point
Returns
boolean
isBefore()
isBefore: (
point
) =>boolean
Defined in: packages/lexical/src/LexicalSelection.ts:160
Parameters
point
Returns
boolean
key
key:
NodeKey
Defined in: packages/lexical/src/LexicalSelection.ts:161
offset
offset:
number
Defined in: packages/lexical/src/LexicalSelection.ts:162
set()
set: (
key
,offset
,type
,onlyIfChanged?
) =>void
Defined in: packages/lexical/src/LexicalSelection.ts:163
Parameters
key
offset
number
type
"text"
| "element"
onlyIfChanged?
boolean
Returns
void
type
type:
"element"
Defined in: packages/lexical/src/LexicalSelection.ts:169
EventHandler()
EventHandler = (
event
,editor
) =>void
Defined in: packages/lexical/src/LexicalEvents.ts:1317
Parameters
event
Event
editor
Returns
void
FlipDirection<D>
FlipDirection<
D
> = typeofFLIP_DIRECTION
[D
]
Defined in: packages/lexical/src/caret/LexicalCaret.ts:26
A type utility to flip next and previous
Type Parameters
D
D
extends CaretDirection
HTMLConfig
HTMLConfig =
object
Defined in: packages/lexical/src/LexicalEditor.ts:207
Properties
export?
optional
export:DOMExportOutputMap
Defined in: packages/lexical/src/LexicalEditor.ts:208
import?
optional
import:DOMConversionMap
Defined in: packages/lexical/src/LexicalEditor.ts:209
Klass<T>
Klass<
T
> =InstanceType
<T
["constructor"
]> extendsT
?T
["constructor"
] :GenericConstructor
<T
> &T
["constructor"
]
Defined in: packages/lexical/src/LexicalEditor.ts:67
Type Parameters
T
T
extends LexicalNode
KlassConstructor<Cls>
KlassConstructor<
Cls
> =GenericConstructor
<InstanceType
<Cls
>> &{ [k in keyof Cls]: Cls[k] }
Defined in: packages/lexical/src/LexicalEditor.ts:62
Type Parameters
Cls
Cls
extends GenericConstructor
<any
>
LexicalCommand<TPayload>
LexicalCommand<
TPayload
> =object
Defined in: packages/lexical/src/LexicalEditor.ts:356
Type Parameters
TPayload
TPayload
Properties
type?
optional
type:string
Defined in: packages/lexical/src/LexicalEditor.ts:357
LexicalExportJSON<T>
LexicalExportJSON<
T
> =Prettify
<Omit
<ReturnType
<T
["exportJSON"
]>,"type"
> &object
&NodeStateJSON
<T
>>
Defined in: packages/lexical/src/LexicalNode.ts:227
The most precise type we can infer for the JSON that will be produced by T.exportJSON().
Do not use this for the return type of T.exportJSON()! It must be a more generic type to be compatible with subclassing.
Type Parameters
T
T
extends LexicalNode
LexicalNodeConfig
LexicalNodeConfig =
Klass
<LexicalNode
> |LexicalNodeReplacement
Defined in: packages/lexical/src/LexicalEditor.ts:215
A LexicalNode class or LexicalNodeReplacement configuration
LexicalNodeReplacement
LexicalNodeReplacement =
object
Defined in: packages/lexical/src/LexicalEditor.ts:198
Properties
replace
replace:
Klass
<LexicalNode
>
Defined in: packages/lexical/src/LexicalEditor.ts:199
with()
with: <
T
>(node
) =>LexicalNode
Defined in: packages/lexical/src/LexicalEditor.ts:201
Type Parameters
T
T
extends (...args
) => any
Parameters
node
InstanceType
<T
>
Returns
withKlass?
optional
withKlass:Klass
<LexicalNode
>
Defined in: packages/lexical/src/LexicalEditor.ts:204
LexicalUpdateJSON<T>
LexicalUpdateJSON<
T
> =Omit
<T
,"children"
|"type"
|"version"
>
Defined in: packages/lexical/src/LexicalNode.ts:236
Omit the children, type, and version properties from the given SerializedLexicalNode definition.
Type Parameters
T
T
extends SerializedLexicalNode
MutationListener()
MutationListener = (
nodes
,payload
) =>void
Defined in: packages/lexical/src/LexicalEditor.ts:334
Parameters
nodes
Map
<NodeKey
, NodeMutation
>
payload
dirtyLeaves
Set
<string
>
prevEditorState
updateTags
Set
<string
>
Returns
void
NodeCaret<D>
NodeCaret<
D
> =SiblingCaret
<LexicalNode
,D
> |ChildCaret
<ElementNode
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:150
A NodeCaret is the combination of an origin node and a direction that points towards where a connected node will be fetched, inserted, or replaced. A SiblingCaret points from a node to its next or previous sibling, and a ChildCaret points to its first or last child (using next or previous as direction, for symmetry with SiblingCaret).
The differences between NodeCaret and PointType are:
- NodeCaret can only be used to refer to an entire node (PointCaret is used when a full analog is needed). A PointType of text type can be used to refer to a specific location inside of a TextNode.
- NodeCaret stores an origin node, type (sibling or child), and direction (next or previous). A PointType stores a type (text or element), the key of a node, and a text or child offset within that node.
- NodeCaret is directional and always refers to a very specific node, eliminating all ambiguity. PointType can refer to the location before or at a node depending on context.
- NodeCaret is more robust to nearby mutations, as it relies only on a node's direct connections. An element Any change to the count of previous siblings in an element PointType will invalidate it.
- NodeCaret is designed to work more directly with the internal representation of the document tree, making it suitable for use in traversals without performing any redundant work.
The caret does not update in response to any mutations, you should not persist it across editor updates, and using a caret after its origin node has been removed or replaced may result in runtime errors.
Type Parameters
D
D
extends CaretDirection
= CaretDirection
NodeKey
NodeKey =
string
Defined in: packages/lexical/src/LexicalNode.ts:382
NodeMap
NodeMap =
Map
<NodeKey
,LexicalNode
>
Defined in: packages/lexical/src/LexicalNode.ts:69
NodeMutation
NodeMutation =
"created"
|"updated"
|"destroyed"
Defined in: packages/lexical/src/LexicalEditor.ts:251
NodeStateJSON<T>
NodeStateJSON<
T
> =Prettify
<object
&CollectStateJSON
<GetNodeStateConfig
<T
>,true
>>
Defined in: packages/lexical/src/LexicalNodeState.ts:142
The NodeState JSON produced by this LexicalNode
Type Parameters
T
T
extends LexicalNode
PasteCommandType
PasteCommandType =
ClipboardEvent
|InputEvent
|KeyboardEvent
Defined in: packages/lexical/src/LexicalCommands.ts:15
PointCaret<D>
PointCaret<
D
> =TextPointCaret
<TextNode
,D
> |SiblingCaret
<LexicalNode
,D
> |ChildCaret
<ElementNode
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:166
A PointCaret is a NodeCaret that also includes a TextPointCaret type which refers to a specific offset of a TextNode. This type is separate because it is not relevant to general node traversal so it doesn't make sense to have it show up except when defining a CaretRange and in those cases there will be at most two of them only at the boundaries.
The addition of TextPointCaret allows this type to represent any location that is representable by PointType, as the TextPointCaret refers to a specific offset within a TextNode.
Type Parameters
D
D
extends CaretDirection
= CaretDirection
PointType
PointType =
TextPoint
|ElementPoint
Defined in: packages/lexical/src/LexicalSelection.ts:172
RootListener()
RootListener = (
rootElement
,prevRootElement
) =>void
Defined in: packages/lexical/src/LexicalEditor.ts:327
Parameters
rootElement
null
| HTMLElement
prevRootElement
null
| HTMLElement
Returns
void
RootMode
RootMode =
"root"
|"shadowRoot"
Defined in: packages/lexical/src/caret/LexicalCaret.ts:39
The RootMode is specified in all caret traversals where the traversal can go up towards the root. 'root' means that it will stop at the document root, and 'shadowRoot' will stop at the document root or any shadow root (per $isRootOrShadowRoot).
SerializedEditor
SerializedEditor =
object
Defined in: packages/lexical/src/LexicalEditor.ts:418
Properties
editorState
editorState:
SerializedEditorState
Defined in: packages/lexical/src/LexicalEditor.ts:419
SerializedElementNode<T>
SerializedElementNode<
T
> =Spread
<{children
:T
[];direction
:"ltr"
|"rtl"
|null
;format
:ElementFormatType
;indent
:number
;textFormat?
:number
;textStyle?
:string
; },SerializedLexicalNode
>
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:54
Type Parameters
T
T
extends SerializedLexicalNode
= SerializedLexicalNode
SerializedLexicalNode
SerializedLexicalNode =
object
Defined in: packages/lexical/src/LexicalNode.ts:74
The base type for all serialized nodes
Properties
$?
optional
$:Record
<string
,unknown
>
Defined in: packages/lexical/src/LexicalNode.ts:83
Any state persisted with the NodeState API that is not configured for flat storage
type
type:
string
Defined in: packages/lexical/src/LexicalNode.ts:76
The type string used by the Node class
version
version:
number
Defined in: packages/lexical/src/LexicalNode.ts:78
A numeric version for this schema, defaulting to 1, but not generally recommended for use
SerializedLineBreakNode
SerializedLineBreakNode =
SerializedLexicalNode
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:24
SerializedParagraphNode
SerializedParagraphNode =
Spread
<{textFormat
:number
;textStyle
:string
; },SerializedElementNode
>
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:36
SerializedRootNode<T>
SerializedRootNode<
T
> =SerializedElementNode
<T
>
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:20
Type Parameters
T
T
extends SerializedLexicalNode
= SerializedLexicalNode
SerializedTabNode
SerializedTabNode =
SerializedTextNode
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:24
SerializedTextNode
SerializedTextNode =
Spread
<{detail
:number
;format
:number
;mode
:TextModeType
;style
:string
;text
:string
; },SerializedLexicalNode
>
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:77
Spread<T1, T2>
Spread<
T1
,T2
> =Omit
<T2
, keyofT1
> &T1
Defined in: packages/lexical/src/LexicalEditor.ts:58
Type Parameters
T1
T1
T2
T2
StateConfigKey<S>
StateConfigKey<
S
> =S
extendsStateConfig
<infer K, infer _V> ?K
:never
Defined in: packages/lexical/src/LexicalNodeState.ts:34
Get the key type (K) from a StateConfig
Type Parameters
S
S
extends AnyStateConfig
StateConfigValue<S>
StateConfigValue<
S
> =S
extendsStateConfig
<infer _K, infer V> ?V
:never
Defined in: packages/lexical/src/LexicalNodeState.ts:29
Get the value type (V) from a StateConfig
Type Parameters
S
S
extends AnyStateConfig
StateValueOrUpdater<Cfg>
StateValueOrUpdater<
Cfg
> =ValueOrUpdater
<StateConfigValue
<Cfg
>>
Defined in: packages/lexical/src/LexicalNodeState.ts:57
A type alias to make it easier to define setter methods on your node class
Type Parameters
Cfg
Cfg
extends AnyStateConfig
Example
const fooState = createState("foo", { parse: ... });
class MyClass extends TextNode {
// ...
setFoo(valueOrUpdater: StateValueOrUpdater<typeof fooState>): this {
return $setState(this, fooState, valueOrUpdater);
}
}
StaticNodeConfig<T, Type>
StaticNodeConfig<
T
,Type
> =BaseStaticNodeConfig
&{ readonly [K in Type]?: StaticNodeConfigValue<T, Type> }
Defined in: packages/lexical/src/LexicalNode.ts:177
Used to extract the node and type from a StaticNodeConfigRecord
Type Parameters
T
T
extends LexicalNode
Type
Type
extends string
TextFormatType
TextFormatType =
"bold"
|"underline"
|"strikethrough"
|"italic"
|"highlight"
|"code"
|"subscript"
|"superscript"
|"lowercase"
|"uppercase"
|"capitalize"
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:90
TextModeType
TextModeType =
"normal"
|"token"
|"segmented"
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:103
TextPoint
TextPoint =
object
Defined in: packages/lexical/src/LexicalSelection.ts:140
Properties
_selection
_selection:
BaseSelection
Defined in: packages/lexical/src/LexicalSelection.ts:141
getNode()
getNode: () =>
TextNode
Defined in: packages/lexical/src/LexicalSelection.ts:142
Returns
is()
is: (
point
) =>boolean
Defined in: packages/lexical/src/LexicalSelection.ts:143
Parameters
point
Returns
boolean
isBefore()
isBefore: (
point
) =>boolean
Defined in: packages/lexical/src/LexicalSelection.ts:144
Parameters
point
Returns
boolean
key
key:
NodeKey
Defined in: packages/lexical/src/LexicalSelection.ts:145
offset
offset:
number
Defined in: packages/lexical/src/LexicalSelection.ts:146
set()
set: (
key
,offset
,type
,onlyIfChanged?
) =>void
Defined in: packages/lexical/src/LexicalSelection.ts:147
Parameters
key
offset
number
type
"text"
| "element"
onlyIfChanged?
boolean
Returns
void
type
type:
"text"
Defined in: packages/lexical/src/LexicalSelection.ts:153
TextPointCaretSliceTuple<D>
TextPointCaretSliceTuple<
D
> = readonly [null
|TextPointCaretSlice
<TextNode
,D
>,null
|TextPointCaretSlice
<TextNode
,D
>]
Defined in: packages/lexical/src/caret/LexicalCaret.ts:371
A utility type to specify that a CaretRange may have zero, one, or two associated TextPointCaretSlice. If the anchor and focus are on the same node, the anchorSlice will contain the slice and focusSlie will be null.
Type Parameters
D
D
extends CaretDirection
Transform()<T>
Transform<
T
> = (node
) =>void
Defined in: packages/lexical/src/LexicalEditor.ts:243
Type Parameters
T
T
extends LexicalNode
Parameters
node
T
Returns
void
UpdateListener()
UpdateListener = (
payload
) =>void
Defined in: packages/lexical/src/LexicalEditor.ts:321
A listener that gets called after the editor is updated
Parameters
payload
Returns
void
UpdateTag
UpdateTag = typeof
COLLABORATION_TAG
| typeofFOCUS_TAG
| typeofHISTORIC_TAG
| typeofHISTORY_MERGE_TAG
| typeofHISTORY_PUSH_TAG
| typeofPASTE_TAG
| typeofSKIP_COLLAB_TAG
| typeofSKIP_DOM_SELECTION_TAG
| typeofSKIP_SCROLL_INTO_VIEW_TAG
|string
&object
Defined in: packages/lexical/src/LexicalUpdateTags.ts:63
The set of known update tags to help with TypeScript suggestions.
ValueOrUpdater<V>
ValueOrUpdater<
V
> =V
| (prevValue
) =>V
Defined in: packages/lexical/src/LexicalNodeState.ts:41
A value type, or an updater for that value type. For use with $setState or any user-defined wrappers around it.
Type Parameters
V
V
Variables
$findMatchingParent()
const
$findMatchingParent: {<T
>(startingNode
,findFn
):null
|T
; (startingNode
,findFn
):null
|LexicalNode
; }
Defined in: packages/lexical/src/LexicalUtils.ts:2821
Starts with a node and moves up the tree (toward the root node) to find a matching node based on the search parameters of the findFn. (Consider JavaScripts' .find() function where a testing function must be passed as an argument. eg. if( (node) => node.__type === 'div') ) return true; otherwise return false
Call Signature
<
T
>(startingNode
,findFn
):null
|T
Type Parameters
T
T
extends LexicalNode
Parameters
startingNode
findFn
(node
) => node is T
Returns
null
| T
Call Signature
(
startingNode
,findFn
):null
|LexicalNode
Parameters
startingNode
findFn
(node
) => boolean
Returns
null
| LexicalNode
Param
The node where the search starts.
Param
A testing function that returns true if the current node satisfies the testing parameters.
Returns
startingNode
or one of its ancestors that matches the findFn
predicate and is not the RootNode
, or null
if no match was found.
BLUR_COMMAND
const
BLUR_COMMAND:LexicalCommand
<FocusEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:212
CAN_REDO_COMMAND
const
CAN_REDO_COMMAND:LexicalCommand
<boolean
>
Defined in: packages/lexical/src/LexicalCommands.ts:206
CAN_UNDO_COMMAND
const
CAN_UNDO_COMMAND:LexicalCommand
<boolean
>
Defined in: packages/lexical/src/LexicalCommands.ts:208
CLEAR_EDITOR_COMMAND
const
CLEAR_EDITOR_COMMAND:LexicalCommand
<void
>
Defined in: packages/lexical/src/LexicalCommands.ts:200
CLEAR_HISTORY_COMMAND
const
CLEAR_HISTORY_COMMAND:LexicalCommand
<void
>
Defined in: packages/lexical/src/LexicalCommands.ts:203
CLICK_COMMAND
const
CLICK_COMMAND:LexicalCommand
<MouseEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:28
COLLABORATION_TAG
const
COLLABORATION_TAG:"collaboration"
='collaboration'
Defined in: packages/lexical/src/LexicalUpdateTags.ts:37
Indicates that the update is related to collaborative editing
COMMAND_PRIORITY_CRITICAL
const
COMMAND_PRIORITY_CRITICAL:4
=4
Defined in: packages/lexical/src/LexicalEditor.ts:353
COMMAND_PRIORITY_EDITOR
const
COMMAND_PRIORITY_EDITOR:0
=0
Defined in: packages/lexical/src/LexicalEditor.ts:349
COMMAND_PRIORITY_HIGH
const
COMMAND_PRIORITY_HIGH:3
=3
Defined in: packages/lexical/src/LexicalEditor.ts:352
COMMAND_PRIORITY_LOW
const
COMMAND_PRIORITY_LOW:1
=1
Defined in: packages/lexical/src/LexicalEditor.ts:350
COMMAND_PRIORITY_NORMAL
const
COMMAND_PRIORITY_NORMAL:2
=2
Defined in: packages/lexical/src/LexicalEditor.ts:351
CONTROLLED_TEXT_INSERTION_COMMAND
const
CONTROLLED_TEXT_INSERTION_COMMAND:LexicalCommand
<InputEvent
|string
>
Defined in: packages/lexical/src/LexicalCommands.ts:49
COPY_COMMAND
const
COPY_COMMAND:LexicalCommand
<ClipboardEvent
|KeyboardEvent
|null
>
Defined in: packages/lexical/src/LexicalCommands.ts:184
Dispatched on a copy event, either via the clipboard or a KeyboardEvent (Cmd+C on macOS, Ctrl+C elsewhere).
CUT_COMMAND
const
CUT_COMMAND:LexicalCommand
<ClipboardEvent
|KeyboardEvent
|null
>
Defined in: packages/lexical/src/LexicalCommands.ts:191
Dispatched on a cut event, either via the clipboard or a KeyboardEvent (Cmd+X on macOS, Ctrl+X elsewhere).
DELETE_CHARACTER_COMMAND
const
DELETE_CHARACTER_COMMAND:LexicalCommand
<boolean
>
Defined in: packages/lexical/src/LexicalCommands.ts:35
Dispatched to delete a character, the payload will be true
if the deletion
is backwards (backspace or delete on macOS) and false
if forwards
(delete or Fn+Delete on macOS).
DELETE_LINE_COMMAND
const
DELETE_LINE_COMMAND:LexicalCommand
<boolean
>
Defined in: packages/lexical/src/LexicalCommands.ts:69
Dispatched to delete a line, the payload will be true
if the deletion is
backwards (Cmd+Delete on macOS), and false
if forwards
(Fn+Cmd+Delete on macOS).
DELETE_WORD_COMMAND
const
DELETE_WORD_COMMAND:LexicalCommand
<boolean
>
Defined in: packages/lexical/src/LexicalCommands.ts:61
Dispatched to delete a word, the payload will be true
if the deletion is
backwards (Ctrl+Backspace or Opt+Delete on macOS), and false
if
forwards (Ctrl+Delete or Fn+Opt+Delete on macOS).
DRAGEND_COMMAND
const
DRAGEND_COMMAND:LexicalCommand
<DragEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:178
DRAGOVER_COMMAND
const
DRAGOVER_COMMAND:LexicalCommand
<DragEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:176
DRAGSTART_COMMAND
const
DRAGSTART_COMMAND:LexicalCommand
<DragEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:174
DROP_COMMAND
const
DROP_COMMAND:LexicalCommand
<DragEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:170
FOCUS_COMMAND
const
FOCUS_COMMAND:LexicalCommand
<FocusEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:210
FORMAT_ELEMENT_COMMAND
const
FORMAT_ELEMENT_COMMAND:LexicalCommand
<ElementFormatType
>
Defined in: packages/lexical/src/LexicalCommands.ts:172
FORMAT_TEXT_COMMAND
const
FORMAT_TEXT_COMMAND:LexicalCommand
<TextFormatType
>
Defined in: packages/lexical/src/LexicalCommands.ts:75
Dispatched to format the selected text.
HISTORIC_TAG
const
HISTORIC_TAG:"historic"
='historic'
Defined in: packages/lexical/src/LexicalUpdateTags.ts:17
Indicates that the update is related to history operations (undo/redo)
HISTORY_MERGE_TAG
const
HISTORY_MERGE_TAG:"history-merge"
='history-merge'
Defined in: packages/lexical/src/LexicalUpdateTags.ts:27
Indicates that the current update should be merged with the previous history entry
HISTORY_PUSH_TAG
const
HISTORY_PUSH_TAG:"history-push"
='history-push'
Defined in: packages/lexical/src/LexicalUpdateTags.ts:22
Indicates that a new history entry should be pushed to the history stack
INDENT_CONTENT_COMMAND
const
INDENT_CONTENT_COMMAND:LexicalCommand
<void
>
Defined in: packages/lexical/src/LexicalCommands.ts:164
INSERT_LINE_BREAK_COMMAND
const
INSERT_LINE_BREAK_COMMAND:LexicalCommand
<boolean
>
Defined in: packages/lexical/src/LexicalCommands.ts:43
Dispatched to insert a line break. With a false payload the cursor moves to the new line (Shift+Enter), with a true payload the cursor does not move (Ctrl+O on macOS).
INSERT_PARAGRAPH_COMMAND
const
INSERT_PARAGRAPH_COMMAND:LexicalCommand
<void
>
Defined in: packages/lexical/src/LexicalCommands.ts:46
INSERT_TAB_COMMAND
const
INSERT_TAB_COMMAND:LexicalCommand
<void
>
Defined in: packages/lexical/src/LexicalCommands.ts:162
IS_ALL_FORMATTING
const
IS_ALL_FORMATTING:number
Defined in: packages/lexical/src/LexicalConstants.ts:53
IS_BOLD
const
IS_BOLD:1
=1
Defined in: packages/lexical/src/LexicalConstants.ts:41
IS_CODE
const
IS_CODE:number
Defined in: packages/lexical/src/LexicalConstants.ts:45
IS_HIGHLIGHT
const
IS_HIGHLIGHT:number
Defined in: packages/lexical/src/LexicalConstants.ts:48
IS_ITALIC
const
IS_ITALIC:number
Defined in: packages/lexical/src/LexicalConstants.ts:42
IS_STRIKETHROUGH
const
IS_STRIKETHROUGH:number
Defined in: packages/lexical/src/LexicalConstants.ts:43
IS_SUBSCRIPT
const
IS_SUBSCRIPT:number
Defined in: packages/lexical/src/LexicalConstants.ts:46
IS_SUPERSCRIPT
const
IS_SUPERSCRIPT:number
Defined in: packages/lexical/src/LexicalConstants.ts:47
IS_UNDERLINE
const
IS_UNDERLINE:number
Defined in: packages/lexical/src/LexicalConstants.ts:44
KEY_ARROW_DOWN_COMMAND
const
KEY_ARROW_DOWN_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:124
Dispatched when the 'ArrowDown'
key is pressed.
The shift and/or alt (option) modifier keys may also be down.
KEY_ARROW_LEFT_COMMAND
const
KEY_ARROW_LEFT_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:106
Dispatched when the 'ArrowLeft'
key is pressed.
The shift modifier key may also be down.
KEY_ARROW_RIGHT_COMMAND
const
KEY_ARROW_RIGHT_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:94
Dispatched when the 'ArrowRight'
key is pressed.
The shift modifier key may also be down.
KEY_ARROW_UP_COMMAND
const
KEY_ARROW_UP_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:118
Dispatched when the 'ArrowUp'
key is pressed.
The shift and/or alt (option) modifier keys may also be down.
KEY_BACKSPACE_COMMAND
const
KEY_BACKSPACE_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:143
Dispatched whenever the 'Backspace'
key is pressed, the shift
modifier key may be down.
KEY_DELETE_COMMAND
const
KEY_DELETE_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:154
Dispatched whenever the 'Delete'
key is pressed (Fn+Delete on macOS).
KEY_DOWN_COMMAND
const
KEY_DOWN_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:88
Dispatched when any key is pressed.
KEY_ENTER_COMMAND
const
KEY_ENTER_COMMAND:LexicalCommand
<KeyboardEvent
|null
>
Defined in: packages/lexical/src/LexicalCommands.ts:131
Dispatched when the enter key is pressed, may also be called with a null payload when the intent is to insert a newline. The shift modifier key must be down, any other modifier keys may also be down.
KEY_ESCAPE_COMMAND
const
KEY_ESCAPE_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:149
Dispatched whenever the 'Escape'
key is pressed, any modifier
keys may be down.
KEY_MODIFIER_COMMAND
const
KEY_MODIFIER_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:220
Deprecated
in v0.31.0, use KEY_DOWN_COMMAND and check for modifiers directly.
Dispatched after any KeyboardEvent when modifiers are pressed
KEY_SPACE_COMMAND
const
KEY_SPACE_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:137
Dispatched whenever the space (' '
) key is pressed, any modifier
keys may be down.
KEY_TAB_COMMAND
const
KEY_TAB_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:160
Dispatched whenever the 'Tab'
key is pressed. The shift modifier key
may be down.
MOVE_TO_END
const
MOVE_TO_END:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:100
Dispatched when the move to end keyboard shortcut is pressed, (Cmd+Right on macOS; Ctrl+Right elsewhere).
MOVE_TO_START
const
MOVE_TO_START:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:112
Dispatched when the move to start keyboard shortcut is pressed, (Cmd+Left on macOS; Ctrl+Left elsewhere).
NODE_STATE_KEY
const
NODE_STATE_KEY:"$"
='$'
Defined in: packages/lexical/src/LexicalConstants.ts:158
OUTDENT_CONTENT_COMMAND
const
OUTDENT_CONTENT_COMMAND:LexicalCommand
<void
>
Defined in: packages/lexical/src/LexicalCommands.ts:167
PASTE_COMMAND
const
PASTE_COMMAND:LexicalCommand
<PasteCommandType
>
Defined in: packages/lexical/src/LexicalCommands.ts:52
PASTE_TAG
const
PASTE_TAG:"paste"
='paste'
Defined in: packages/lexical/src/LexicalUpdateTags.ts:32
Indicates that the update is related to a paste operation
REDO_COMMAND
const
REDO_COMMAND:LexicalCommand
<void
>
Defined in: packages/lexical/src/LexicalCommands.ts:84
Dispatched on redo (Shift+Cmd+Z on macOS, Shift+Ctrl+Z or Ctrl+Y elsewhere).
REMOVE_TEXT_COMMAND
const
REMOVE_TEXT_COMMAND:LexicalCommand
<InputEvent
|null
>
Defined in: packages/lexical/src/LexicalCommands.ts:54
SELECT_ALL_COMMAND
const
SELECT_ALL_COMMAND:LexicalCommand
<KeyboardEvent
>
Defined in: packages/lexical/src/LexicalCommands.ts:198
Dispatched on the select all keyboard shortcut (Cmd+A on macOS, Ctrl+A elsehwere).
SELECTION_CHANGE_COMMAND
const
SELECTION_CHANGE_COMMAND:LexicalCommand
<void
>
Defined in: packages/lexical/src/LexicalCommands.ts:21
SELECTION_INSERT_CLIPBOARD_NODES_COMMAND
const
SELECTION_INSERT_CLIPBOARD_NODES_COMMAND:LexicalCommand
<{nodes
:LexicalNode
[];selection
:BaseSelection
; }>
Defined in: packages/lexical/src/LexicalCommands.ts:24
SKIP_COLLAB_TAG
const
SKIP_COLLAB_TAG:"skip-collab"
='skip-collab'
Defined in: packages/lexical/src/LexicalUpdateTags.ts:42
Indicates that the update should skip collaborative sync
SKIP_DOM_SELECTION_TAG
const
SKIP_DOM_SELECTION_TAG:"skip-dom-selection"
='skip-dom-selection'
Defined in: packages/lexical/src/LexicalUpdateTags.ts:53
Indicates that the update should skip updating the DOM selection This is useful when you want to make updates without changing the selection or focus
SKIP_SCROLL_INTO_VIEW_TAG
const
SKIP_SCROLL_INTO_VIEW_TAG:"skip-scroll-into-view"
='skip-scroll-into-view'
Defined in: packages/lexical/src/LexicalUpdateTags.ts:47
Indicates that the update should skip scrolling the selection into view
TEXT_TYPE_TO_FORMAT
const
TEXT_TYPE_TO_FORMAT:Record
<TextFormatType
|string
,number
>
Defined in: packages/lexical/src/LexicalConstants.ts:106
UNDO_COMMAND
const
UNDO_COMMAND:LexicalCommand
<void
>
Defined in: packages/lexical/src/LexicalCommands.ts:80
Dispatched on undo (Cmd+Z on macOS, Ctrl+Z elsewhere).
Functions
$addUpdateTag()
$addUpdateTag(
tag
):void
Defined in: packages/lexical/src/LexicalUtils.ts:1427
Parameters
tag
Returns
void
$applyNodeReplacement()
$applyNodeReplacement<
N
>(node
):N
Defined in: packages/lexical/src/LexicalUtils.ts:1542
Type Parameters
N
N
extends LexicalNode
Parameters
node
N
Returns
N
$caretFromPoint()
$caretFromPoint<
D
>(point
,direction
):PointCaret
<D
>
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:61
Type Parameters
D
D
extends CaretDirection
Parameters
point
Pick
<PointType
, "type"
| "key"
| "offset"
>
direction
D
Returns
PointCaret
<D
>
a PointCaret for the point
$caretRangeFromSelection()
$caretRangeFromSelection(
selection
):CaretRange
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:156
Get a pair of carets for a RangeSelection.
If the focus is before the anchor, then the direction will be 'previous', otherwise the direction will be 'next'.
Parameters
selection
Returns
$cloneWithProperties()
$cloneWithProperties<
T
>(latestNode
):T
Defined in: packages/lexical/src/LexicalUtils.ts:2603
Returns a clone of a node using node.constructor.clone()
followed by
clone.afterCloneFrom(node)
. The resulting clone must have the same key,
parent/next/prev pointers, and other properties that are not set by
node.constructor.clone
(format, style, etc.). This is primarily used by
LexicalNode.getWritable to create a writable version of an
existing node. The clone is the same logical node as the original node,
do not try and use this function to duplicate or copy an existing node.
Does not mutate the EditorState.
Type Parameters
T
T
extends LexicalNode
Parameters
latestNode
T
The node to be cloned.
Returns
T
The clone of the node.
$comparePointCaretNext()
$comparePointCaretNext(
a
,b
):-1
|0
|1
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1229
A total ordering for PointCaret<'next'>
, based on
the same order that a CaretRange would iterate
them.
For a given origin node:
- ChildCaret comes before SiblingCaret
- TextPointCaret comes before SiblingCaret
An exception is thrown when a and b do not have any common ancestor.
This ordering is a sort of mix of pre-order and post-order because each ElementNode will show up as a ChildCaret on 'enter' (pre-order) and a SiblingCaret on 'leave' (post-order).
Parameters
a
PointCaret
<"next"
>
b
PointCaret
<"next"
>
Returns
-1
| 0
| 1
-1 if a comes before b, 0 if a and b are the same, or 1 if a comes after b
$copyNode()
$copyNode<
T
>(node
):T
Defined in: packages/lexical/src/LexicalUtils.ts:1535
Returns a shallow clone of node with a new key. All properties of the node
will be copied to the new node (by clone
and then afterCloneFrom
),
except those related to parent/sibling/child
relationships in the EditorState
. This means that the copy must be
separately added to the document, and it will not have any children.
Type Parameters
T
T
extends LexicalNode
Parameters
node
T
The node to be copied.
Returns
T
The copy of the node.
$create()
$create<
T
>(klass
):T
Defined in: packages/lexical/src/LexicalUtils.ts:2804
Create an node from its class.
Note that this will directly construct the final withKlass
node type,
and will ignore the deprecated with
functions. This allows $create
to
skip any intermediate steps where the replaced node would be created and
then immediately discarded (once per configured replacement of that node).
This does not support any arguments to the constructor. Setters can be used to initialize your node, and they can be chained. You can of course write your own mutliple-argument functions to wrap that.
Type Parameters
T
T
extends LexicalNode
Parameters
klass
Klass
<T
>
Returns
T
Example
function $createTokenText(text: string): TextNode {
return $create(TextNode).setTextContent(text).setMode('token');
}
$createLineBreakNode()
$createLineBreakNode():
LineBreakNode
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:83
Returns
$createNodeSelection()
$createNodeSelection():
NodeSelection
Defined in: packages/lexical/src/LexicalSelection.ts:2743
Returns
$createParagraphNode()
$createParagraphNode():
ParagraphNode
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:168
Returns
$createPoint()
$createPoint(
key
,offset
,type
):PointType
Defined in: packages/lexical/src/LexicalSelection.ts:262
Parameters
key
string
offset
number
type
"text"
| "element"
Returns
$createRangeSelection()
$createRangeSelection():
RangeSelection
Defined in: packages/lexical/src/LexicalSelection.ts:2737
Returns
$createRangeSelectionFromDom()
$createRangeSelectionFromDom(
domSelection
,editor
):null
|RangeSelection
Defined in: packages/lexical/src/LexicalSelection.ts:2766
Parameters
domSelection
null
| Selection
editor
Returns
null
| RangeSelection
$createTabNode()
$createTabNode():
TabNode
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:101
Returns
$createTextNode()
$createTextNode(
text
):TextNode
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1375
Parameters
text
string
= ''
Returns
$extendCaretToRange()
$extendCaretToRange<
D
>(anchor
):CaretRange
<D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1127
Construct a CaretRange that starts at anchor and goes to the end of the document in the anchor caret's direction.
Type Parameters
D
D
extends CaretDirection
Parameters
anchor
PointCaret
<D
>
Returns
CaretRange
<D
>
$getAdjacentChildCaret()
$getAdjacentChildCaret<
D
>(caret
):null
|NodeCaret
<D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:977
Gets the adjacent caret, if not-null and if the origin of the adjacent caret is an ElementNode, then return the ChildCaret. This can be used along with the getParentAdjacentCaret method to perform a full DFS style traversal of the tree.
Type Parameters
D
D
extends CaretDirection
Parameters
caret
The caret to start at
null
| NodeCaret
<D
>
Returns
null
| NodeCaret
<D
>
$getAdjacentNode()
$getAdjacentNode(
focus
,isBackward
):null
|LexicalNode
Defined in: packages/lexical/src/LexicalUtils.ts:1267
Parameters
focus
isBackward
boolean
Returns
null
| LexicalNode
$getAdjacentSiblingOrParentSiblingCaret()
$getAdjacentSiblingOrParentSiblingCaret<
D
>(startCaret
,rootMode
):null
| [NodeCaret
<D
>,number
]
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:596
Returns the Node sibling when this exists, otherwise the closest parent sibling. For example R -> P -> T1, T2 -> P2 returns T2 for node T1, P2 for node T2, and null for node P2.
Type Parameters
D
D
extends CaretDirection
Parameters
startCaret
NodeCaret
<D
>
The initial caret
rootMode
RootMode
= 'root'
The root mode, 'root' (default) or 'shadowRoot'
Returns
null
| [NodeCaret
<D
>, number
]
An array (tuple) containing the found caret and the depth difference, or null, if this node doesn't exist.
$getCaretInDirection()
$getCaretInDirection<
Caret
,D
>(caret
,direction
):NodeCaret
<D
> |Caret
extendsTextPointCaret
<TextNode
,CaretDirection
> ?TextPointCaret
<TextNode
,D
> :never
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:519
Return the caret if it's in the given direction, otherwise return caret.getFlipped().
Type Parameters
Caret
Caret
extends PointCaret
<CaretDirection
>
D
D
extends CaretDirection
Parameters
caret
Caret
Any PointCaret
direction
D
The desired direction
Returns
NodeCaret
<D
> | Caret
extends TextPointCaret
<TextNode
, CaretDirection
> ? TextPointCaret
<TextNode
, D
> : never
A PointCaret in direction
$getCaretRange()
$getCaretRange<
D
>(anchor
,focus
):CaretRange
<D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1156
Construct a CaretRange from anchor and focus carets pointing in the same direction. In order to get the expected behavior, the anchor must point towards the focus or be the same point.
In the 'next' direction the anchor should be at or before the focus in the document. In the 'previous' direction the anchor should be at or after the focus in the document (similar to a backwards RangeSelection).
Type Parameters
D
D
extends CaretDirection
Parameters
anchor
PointCaret
<D
>
focus
PointCaret
<D
>
Returns
CaretRange
<D
>
a CaretRange
$getCaretRangeInDirection()
$getCaretRangeInDirection<
D
>(range
,direction
):CaretRange
<D
>
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:548
Return the range if it's in the given direction, otherwise construct a new range using a flipped focus as the anchor and a flipped anchor as the focus. This transformation preserves the section of the document that it's working with, but reverses the order of iteration.
Type Parameters
D
D
extends CaretDirection
Parameters
range
Any CaretRange
direction
D
The desired direction
Returns
CaretRange
<D
>
A CaretRange in direction
$getCharacterOffsets()
$getCharacterOffsets(
selection
): [number
,number
]
Defined in: packages/lexical/src/LexicalSelection.ts:2047
Parameters
selection
Returns
[number
, number
]
$getChildCaret()
$getChildCaret<
T
,D
>(origin
,direction
):ChildCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:950
Get a caret that points at the first or last child of the given origin node, which must be an ElementNode.
Type Parameters
T
T
extends ElementNode
D
D
extends CaretDirection
Parameters
origin
T
The origin ElementNode
direction
D
'next' for first child or 'previous' for last child
Returns
ChildCaret
<T
, D
>
null if origin is null or not an ElementNode, otherwise a ChildCaret for this origin and direction
$getChildCaretAtIndex()
$getChildCaretAtIndex<
D
>(parent
,index
,direction
):NodeCaret
<D
>
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:570
Get a caret pointing at the child at the given index, or the last caret in that node if out of bounds.
Type Parameters
D
D
extends CaretDirection
Parameters
parent
An ElementNode
index
number
The index of the origin for the caret
direction
D
Returns
NodeCaret
<D
>
A caret pointing towards the node at that index
$getChildCaretOrSelf()
$getChildCaretOrSelf<
Caret
>(caret
):Caret
|ChildCaret
<ElementNode
,NonNullable
<Caret
>["direction"
]>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:964
Gets the ChildCaret if one is possible at this caret origin, otherwise return the caret
Type Parameters
Caret
Caret
extends null
| PointCaret
<CaretDirection
>
Parameters
caret
Caret
Returns
Caret
| ChildCaret
<ElementNode
, NonNullable
<Caret
>["direction"
]>
$getCollapsedCaretRange()
$getCollapsedCaretRange<
D
>(anchor
):CaretRange
<D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1136
Construct a collapsed CaretRange that starts and ends at anchor.
Type Parameters
D
D
extends CaretDirection
Parameters
anchor
PointCaret
<D
>
Returns
CaretRange
<D
>
$getCommonAncestor()
$getCommonAncestor<
A
,B
>(a
,b
):null
|CommonAncestorResult
<A
,B
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1367
Find a common ancestor of a and b and return a detailed result object, or null if there is no common ancestor between the two nodes.
The result object will have a commonAncestor property, and the other properties can be used to quickly compare these positions in the tree.
Type Parameters
A
A
extends LexicalNode
B
B
extends LexicalNode
Parameters
a
A
A LexicalNode
b
B
A LexicalNode
Returns
null
| CommonAncestorResult
<A
, B
>
A comparison result between the two nodes or null if they have no common ancestor
$getCommonAncestorResultBranchOrder()
$getCommonAncestorResultBranchOrder<
A
,B
>(compare
):-1
|1
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1272
Return the ordering of siblings in a CommonAncestorResultBranch
Type Parameters
A
A
extends LexicalNode
B
B
extends LexicalNode
Parameters
compare
CommonAncestorResultBranch
<A
, B
>
Returns -1 if a precedes b, 1 otherwise
Returns
-1
| 1
$getEditor()
$getEditor():
LexicalEditor
Defined in: packages/lexical/src/LexicalUtils.ts:2540
Utility function for accessing current active editor instance.
Returns
Current active editor
$getNearestNodeFromDOMNode()
$getNearestNodeFromDOMNode(
startingDOM
,editorState?
):null
|LexicalNode
Defined in: packages/lexical/src/LexicalUtils.ts:555
Parameters
startingDOM
Node
editorState?
Returns
null
| LexicalNode
$getNearestRootOrShadowRoot()
$getNearestRootOrShadowRoot(
node
):ElementNode
|RootNode
Defined in: packages/lexical/src/LexicalUtils.ts:1499
Parameters
node
Returns
$getNodeByKey()
$getNodeByKey<
T
>(key
,_editorState?
):null
|T
Defined in: packages/lexical/src/LexicalUtils.ts:514
Type Parameters
T
T
extends LexicalNode
Parameters
key
string
_editorState?
Returns
null
| T
$getNodeByKeyOrThrow()
$getNodeByKeyOrThrow<
N
>(key
):N
Defined in: packages/lexical/src/LexicalUtils.ts:1608
Type Parameters
N
N
extends LexicalNode
Parameters
key
string
Returns
N
$getPreviousSelection()
$getPreviousSelection():
null
|BaseSelection
Defined in: packages/lexical/src/LexicalSelection.ts:2899
Returns
null
| BaseSelection
$getRoot()
$getRoot():
RootNode
Defined in: packages/lexical/src/LexicalUtils.ts:623
Returns
$getSelection()
$getSelection():
null
|BaseSelection
Defined in: packages/lexical/src/LexicalSelection.ts:2894
Returns
null
| BaseSelection
$getSiblingCaret()
Call Signature
$getSiblingCaret<
T
,D
>(origin
,direction
):SiblingCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:843
Get a caret that points at the next or previous sibling of the given origin node.
Type Parameters
T
T
extends LexicalNode
D
D
extends CaretDirection
Parameters
origin
T
The origin node
direction
D
'next' or 'previous'
Returns
SiblingCaret
<T
, D
>
null if origin is null, otherwise a SiblingCaret for this origin and direction
Call Signature
$getSiblingCaret<
T
,D
>(origin
,direction
):null
|SiblingCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:847
Get a caret that points at the next or previous sibling of the given origin node.
Type Parameters
T
T
extends LexicalNode
D
D
extends CaretDirection
Parameters
origin
The origin node
null
| T
direction
D
'next' or 'previous'
Returns
null
| SiblingCaret
<T
, D
>
null if origin is null, otherwise a SiblingCaret for this origin and direction
$getState()
$getState<
K
,V
>(node
,stateConfig
,version
):V
Defined in: packages/lexical/src/LexicalNodeState.ts:322
The accessor for working with node state. This will read the value for the
state on the given node, and will return stateConfig.defaultValue
if the
state has never been set on this node.
The version
parameter is optional and should generally be 'latest'
,
consistent with the behavior of other node methods and functions,
but for certain use cases such as updateDOM
you may have a need to
use 'direct'
to read the state from a previous version of the node.
For very advanced use cases, you can expect that 'direct' does not
require an editor state, just like directly accessing other properties
of a node without an accessor (e.g. textNode.__text
).
Type Parameters
K
K
extends string
V
V
Parameters
node
Any LexicalNode
stateConfig
StateConfig
<K
, V
>
The configuration of the state to read
version
The default value 'latest' will read the latest version of the node state, 'direct' will read the version that is stored on this LexicalNode which not reflect the version used in the current editor state
"latest"
| "direct"
Returns
V
The current value from the state, or the default value provided by the configuration.
$getStateChange()
$getStateChange<
T
,K
,V
>(node
,prevNode
,stateConfig
):null
| [V
,V
]
Defined in: packages/lexical/src/LexicalNodeState.ts:350
Given two versions of a node and a stateConfig, compare their state values
using $getState(nodeVersion, stateConfig, 'direct')
.
If the values are equal according to stateConfig.isEqual
, return null
,
otherwise return [value, prevValue]
.
This is useful for implementing updateDOM. Note that the 'direct'
version argument is used for both nodes.
Type Parameters
T
T
extends LexicalNode
K
K
extends string
V
V
Parameters
node
T
Any LexicalNode
prevNode
T
A previous version of node
stateConfig
StateConfig
<K
, V
>
The configuration of the state to read
Returns
null
| [V
, V
]
[value, prevValue]
if changed, otherwise null
$getTextContent()
$getTextContent():
string
Defined in: packages/lexical/src/LexicalSelection.ts:3296
Returns
string
$getTextNodeOffset()
$getTextNodeOffset(
origin
,offset
,mode
):number
Defined in: packages/lexical/src/caret/LexicalCaret.ts:902
Get a normalized offset into a TextNode given a numeric offset or a direction for which end of the string to use. Throws in dev if the offset is not in the bounds of the text content size.
Parameters
origin
a TextNode
offset
An absolute offset into the TextNode string, or a direction for which end to use as the offset
number
| CaretDirection
mode
If 'error' (the default) out of bounds offsets will be an error in dev. Otherwise it will clamp to a valid offset.
"error"
| "clamp"
Returns
number
An absolute offset into the TextNode string
$getTextPointCaret()
Call Signature
$getTextPointCaret<
T
,D
>(origin
,direction
,offset
):TextPointCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:866
Construct a TextPointCaret
Type Parameters
T
T
extends TextNode
D
D
extends CaretDirection
Parameters
origin
T
The TextNode
direction
D
The direction (next points to the end of the text, previous points to the beginning)
offset
The offset into the text in absolute positive string coordinates (0 is the start)
number
| CaretDirection
Returns
TextPointCaret
<T
, D
>
a TextPointCaret
Call Signature
$getTextPointCaret<
T
,D
>(origin
,direction
,offset
):null
|TextPointCaret
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:874
Construct a TextPointCaret
Type Parameters
T
T
extends TextNode
D
D
extends CaretDirection
Parameters
origin
The TextNode
null
| T
direction
D
The direction (next points to the end of the text, previous points to the beginning)
offset
The offset into the text in absolute positive string coordinates (0 is the start)
number
| CaretDirection
Returns
null
| TextPointCaret
<T
, D
>
a TextPointCaret
$getTextPointCaretSlice()
$getTextPointCaretSlice<
T
,D
>(caret
,distance
):TextPointCaretSlice
<T
,D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:935
Construct a TextPointCaretSlice given a TextPointCaret and a signed distance. The distance should be negative to slice text before the caret's offset, and positive to slice text after the offset. The direction of the caret itself is not relevant to the string coordinates when working with a TextPointCaretSlice but mutation operations will preserve the direction.
Type Parameters
T
T
extends TextNode
D
D
extends CaretDirection
Parameters
caret
TextPointCaret
<T
, D
>
distance
number
Returns
TextPointCaretSlice
<T
, D
>
TextPointCaretSlice
$hasAncestor()
$hasAncestor(
child
,targetNode
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:1465
Parameters
child
targetNode
Returns
boolean
$hasUpdateTag()
$hasUpdateTag(
tag
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:1422
Parameters
tag
Returns
boolean
$insertNodes()
$insertNodes(
nodes
):void
Defined in: packages/lexical/src/LexicalSelection.ts:3287
Parameters
nodes
Returns
void
$isBlockElementNode()
$isBlockElementNode(
node
):node is ElementNode
Defined in: packages/lexical/src/LexicalSelection.ts:2707
Parameters
node
undefined
| null
| LexicalNode
Returns
node is ElementNode
$isChildCaret()
$isChildCaret<
D
>(caret
):caret is ChildCaret<ElementNode, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:759
Guard to check if the given argument is specifically a ChildCaret
Type Parameters
D
D
extends CaretDirection
Parameters
caret
undefined
| null
| PointCaret
<D
>
Returns
caret is ChildCaret<ElementNode, D>
true if caret is a ChildCaret
$isDecoratorNode()
$isDecoratorNode<
T
>(node
):node is DecoratorNode<T>
Defined in: packages/lexical/src/nodes/LexicalDecoratorNode.ts:49
Type Parameters
T
T
Parameters
node
undefined
| null
| LexicalNode
Returns
node is DecoratorNode<T>
$isElementNode()
$isElementNode(
node
):node is ElementNode
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:994
Parameters
node
undefined
| null
| LexicalNode
Returns
node is ElementNode
$isExtendableTextPointCaret()
$isExtendableTextPointCaret<
D
>(caret
):caret is TextPointCaret<TextNode, D> & { [PointCaretIsExtendableBrand]: never }
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:500
Determine whether the TextPointCaret's offset can be extended further without leaving the TextNode. Returns false if the given caret is not a TextPointCaret or the offset can not be moved further in direction.
Type Parameters
D
D
extends CaretDirection
Parameters
caret
PointCaret
<D
>
A PointCaret
Returns
caret is TextPointCaret<TextNode, D> & { [PointCaretIsExtendableBrand]: never }
true if caret is a TextPointCaret with an offset that is not at the end of the text given the direction.
$isInlineElementOrDecoratorNode()
$isInlineElementOrDecoratorNode(
node
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:1492
Parameters
node
Returns
boolean
$isInShadowDOMContext()
$isInShadowDOMContext(
editor
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:1990
Checks if the Lexical editor is running within a Shadow DOM context.
This function determines whether the editor's root element is contained within a ShadowRoot, which is essential for enabling Shadow DOM-specific functionality like specialized deletion commands and selection handling.
Parameters
editor
The Lexical editor instance to check
Returns
boolean
true
if the editor is in Shadow DOM, false
otherwise
$isLeafNode()
$isLeafNode(
node
): node is DecoratorNode<unknown> | TextNode | LineBreakNode
Defined in: packages/lexical/src/LexicalUtils.ts:303
Parameters
node
undefined
| null
| LexicalNode
Returns
node is DecoratorNode<unknown> | TextNode | LineBreakNode
$isLineBreakNode()
$isLineBreakNode(
node
):node is LineBreakNode
Defined in: packages/lexical/src/nodes/LexicalLineBreakNode.ts:87
Parameters
node
undefined
| null
| LexicalNode
Returns
node is LineBreakNode
$isNodeCaret()
$isNodeCaret<
D
>(caret
):caret is PointCaret<D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:735
Guard to check if the given argument is any type of caret
Type Parameters
D
D
extends CaretDirection
Parameters
caret
undefined
| null
| PointCaret
<D
>
Returns
caret is PointCaret<D>
true if caret is any type of caret
$isNodeSelection()
$isNodeSelection(
x
):x is NodeSelection
Defined in: packages/lexical/src/LexicalSelection.ts:2031
Parameters
x
unknown
Returns
x is NodeSelection
$isParagraphNode()
$isParagraphNode(
node
):node is ParagraphNode
Defined in: packages/lexical/src/nodes/LexicalParagraphNode.ts:172
Parameters
node
undefined
| null
| LexicalNode
Returns
node is ParagraphNode
$isRangeSelection()
$isRangeSelection(
x
):x is RangeSelection
Defined in: packages/lexical/src/LexicalSelection.ts:505
Parameters
x
unknown
Returns
x is RangeSelection
$isRootNode()
$isRootNode(
node
):node is RootNode
Defined in: packages/lexical/src/nodes/LexicalRootNode.ts:113
Parameters
node
undefined
| null
| LexicalNode
| RootNode
Returns
node is RootNode
$isRootOrShadowRoot()
$isRootOrShadowRoot(
node
): node is RootNode | ShadowRootNode
Defined in: packages/lexical/src/LexicalUtils.ts:1519
Parameters
node
null
| LexicalNode
Returns
node is RootNode | ShadowRootNode
$isSiblingCaret()
$isSiblingCaret<
D
>(caret
):caret is SiblingCaret<LexicalNode, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:747
Guard to check if the given argument is specifically a SiblingCaret (or TextPointCaret)
Type Parameters
D
D
extends CaretDirection
Parameters
caret
undefined
| null
| PointCaret
<D
>
Returns
caret is SiblingCaret<LexicalNode, D>
true if caret is a SiblingCaret
$isTabNode()
$isTabNode(
node
):node is TabNode
Defined in: packages/lexical/src/nodes/LexicalTabNode.ts:105
Parameters
node
undefined
| null
| LexicalNode
Returns
node is TabNode
$isTextNode()
$isTextNode(
node
):node is TextNode
Defined in: packages/lexical/src/nodes/LexicalTextNode.ts:1379
Parameters
node
undefined
| null
| LexicalNode
Returns
node is TextNode
$isTextPointCaret()
$isTextPointCaret<
D
>(caret
):caret is TextPointCaret<TextNode, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:723
Guard to check if the given caret is specifically a TextPointCaret
Type Parameters
D
D
extends CaretDirection
Parameters
caret
Any caret
undefined
| null
| PointCaret
<D
>
Returns
caret is TextPointCaret<TextNode, D>
true if it is a TextPointCaret
$isTextPointCaretSlice()
$isTextPointCaretSlice<
D
>(caretOrSlice
):caretOrSlice is TextPointCaretSlice<TextNode, D>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1113
Guard to check for a TextPointCaretSlice
Type Parameters
D
D
extends CaretDirection
Parameters
caretOrSlice
A caret or slice
undefined
| null
| PointCaret
<D
> | TextPointCaretSlice
<TextNode
, D
>
Returns
caretOrSlice is TextPointCaretSlice<TextNode, D>
true if caretOrSlice is a TextPointCaretSlice
$isTokenOrSegmented()
$isTokenOrSegmented(
node
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:242
Return true if the TextNode is a TabNode, or is in token or segmented mode.
Parameters
node
Returns
boolean
$isTokenOrTab()
$isTokenOrTab(
node
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:235
Return true if the TextNode is a TabNode or is in token mode.
Parameters
node
Returns
boolean
$nodesOfType()
$nodesOfType<
T
>(klass
):T
[]
Defined in: packages/lexical/src/LexicalUtils.ts:1224
Type Parameters
T
T
extends LexicalNode
Parameters
klass
Klass
<T
>
Returns
T
[]
Deprecated
Use LexicalEditor.registerMutationListener with skipInitialization: false
instead.
$normalizeCaret()
$normalizeCaret<
D
>(initialCaret
):PointCaret
<D
>
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:475
Normalize a caret to the deepest equivalent PointCaret. This will return a TextPointCaret with the offset set according to the direction if given a caret with a TextNode origin or a caret with an ElementNode origin with the deepest ChildCaret having an adjacent TextNode.
If given a TextPointCaret, it will be returned, as no normalization is required when an offset is already present.
Type Parameters
D
D
extends CaretDirection
Parameters
initialCaret
PointCaret
<D
>
Returns
PointCaret
<D
>
The normalized PointCaret
$normalizeSelection__EXPERIMENTAL()
$normalizeSelection__EXPERIMENTAL(
selection
):RangeSelection
Defined in: packages/lexical/src/LexicalNormalization.ts:95
Parameters
selection
Returns
$onUpdate()
$onUpdate(
updateFn
):void
Defined in: packages/lexical/src/LexicalUtils.ts:1440
Add a function to run after the current update. This will run after any
onUpdate
function already supplied to editor.update()
, as well as any
functions added with previous calls to $onUpdate
.
Parameters
updateFn
() => void
The function to run after the current update.
Returns
void
$parseSerializedNode()
$parseSerializedNode(
serializedNode
):LexicalNode
Defined in: packages/lexical/src/LexicalUpdates.ts:355
Parameters
serializedNode
Returns
$removeTextFromCaretRange()
$removeTextFromCaretRange<
D
>(initialRange
,sliceMode
):CaretRange
<D
>
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:232
Remove all text and nodes in the given range. If the range spans multiple blocks then the remaining contents of the later block will be merged with the earlier block.
Type Parameters
D
D
extends CaretDirection
Parameters
initialRange
CaretRange
<D
>
The range to remove text and nodes from
sliceMode
If 'preserveEmptyTextPointCaret' it will leave an empty TextPointCaret at the anchor for insert if one exists, otherwise empty slices will be removed
"removeEmptySlices"
| "preserveEmptyTextSliceCaret"
Returns
CaretRange
<D
>
The new collapsed range (biased towards the earlier node)
$rewindSiblingCaret()
$rewindSiblingCaret<
T
,D
>(caret
):NodeCaret
<D
>
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:183
Given a SiblingCaret we can always compute a caret that points to the origin of that caret in the same direction. The adjacent caret of the returned caret will be equivalent to the given caret.
Type Parameters
T
T
extends LexicalNode
D
D
extends CaretDirection
Parameters
caret
SiblingCaret
<T
, D
>
The caret to "rewind"
Returns
NodeCaret
<D
>
A new caret (ChildCaret or SiblingCaret) with the same direction
Example
siblingCaret.is($rewindSiblingCaret(siblingCaret).getAdjacentCaret())
$selectAll()
$selectAll(
selection?
):RangeSelection
Defined in: packages/lexical/src/LexicalUtils.ts:1142
Parameters
selection?
null
| RangeSelection
Returns
$setCompositionKey()
$setCompositionKey(
compositionKey
):void
Defined in: packages/lexical/src/LexicalUtils.ts:485
Parameters
compositionKey
null
| string
Returns
void
$setPointFromCaret()
$setPointFromCaret<
D
>(point
,caret
):void
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:91
Update the given point in-place from the PointCaret
Type Parameters
D
D
extends CaretDirection
Parameters
point
the point to set
caret
PointCaret
<D
>
the caret to set the point from
Returns
void
$setSelection()
$setSelection(
selection
):void
Defined in: packages/lexical/src/LexicalUtils.ts:631
Parameters
selection
null
| BaseSelection
Returns
void
$setSelectionFromCaretRange()
$setSelectionFromCaretRange(
caretRange
):RangeSelection
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:127
Set a RangeSelection on the editor from the given CaretRange
Parameters
caretRange
Returns
The new RangeSelection
$setState()
$setState<
Node
,K
,V
>(node
,stateConfig
,valueOrUpdater
):Node
Defined in: packages/lexical/src/LexicalNodeState.ts:383
Set the state defined by stateConfig on node. Like with React.useState
you may directly specify the value or use an updater function that will
be called with the previous value of the state on that node (which will
be the stateConfig.defaultValue
if not set).
When an updater function is used, the node will only be marked dirty if
stateConfig.isEqual(prevValue, value)
is false.
Type Parameters
Node
Node
extends LexicalNode
K
K
extends string
V
V
Parameters
node
Node
The LexicalNode to set the state on
stateConfig
StateConfig
<K
, V
>
The configuration for this state
valueOrUpdater
The value or updater function
Returns
Node
node
Example
const toggle = createState('toggle', {parse: Boolean});
// set it direction
$setState(node, counterState, true);
// use an updater
$setState(node, counterState, (prev) => !prev);
$splitAtPointCaretNext()
$splitAtPointCaretNext(
pointCaret
,__namedParameters
):null
|NodeCaret
<"next"
>
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:689
Split a node at a PointCaret and return a NodeCaret at that point, or null if the node can't be split. This is non-recursive and will only perform at most one split.
Parameters
pointCaret
PointCaret
<"next"
>
__namedParameters
SplitAtPointCaretNextOptions
= {}
Returns
null
| NodeCaret
<"next"
>
The NodeCaret pointing to the location of the split (or null if a split is not possible)
$splitNode()
$splitNode(
node
,offset
): [null
|ElementNode
,ElementNode
]
Defined in: packages/lexical/src/LexicalUtils.ts:2381
Parameters
node
offset
number
Returns
[null
| ElementNode
, ElementNode
]
$updateRangeSelectionFromCaretRange()
$updateRangeSelectionFromCaretRange(
selection
,caretRange
):void
Defined in: packages/lexical/src/caret/LexicalCaretUtils.ts:142
Update the points of a RangeSelection based on the given PointCaret.
Parameters
selection
caretRange
Returns
void
buildImportMap()
buildImportMap<
K
>(importMap
):DOMConversionMap
Defined in: packages/lexical/src/LexicalNode.ts:338
An identity function that will infer the type of DOM nodes based on tag names to make it easier to construct a DOMConversionMap.
Type Parameters
K
K
extends string
Parameters
importMap
{ [NodeName in string]: DOMConversionPropByTagName<NodeName> }
Returns
createCommand()
createCommand<
T
>(type?
):LexicalCommand
<T
>
Defined in: packages/lexical/src/LexicalCommands.ts:17
Type Parameters
T
T
Parameters
type?
string
Returns
createEditor()
createEditor(
editorConfig?
):LexicalEditor
Defined in: packages/lexical/src/LexicalEditor.ts:505
Creates a new LexicalEditor attached to a single contentEditable (provided in the config). This is the lowest-level initialization API for a LexicalEditor. If you're using React or another framework, consider using the appropriate abstractions, such as LexicalComposer
Parameters
editorConfig?
the editor configuration.
Returns
a LexicalEditor instance
createState()
createState<
K
,V
>(key
,valueConfig
):StateConfig
<K
,V
>
Defined in: packages/lexical/src/LexicalNodeState.ts:296
Create a StateConfig for the given string key and StateValueConfig.
The key must be locally unique. In dev you will get a key collision error when you use two separate StateConfig on the same node with the same key.
The returned StateConfig value should be used with $getState and $setState.
Type Parameters
K
K
extends string
V
V
Parameters
key
K
The key to use
valueConfig
Configuration for the value type
Returns
StateConfig
<K
, V
>
a StateConfig
flipDirection()
flipDirection<
D
>(direction
):FlipDirection
<D
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:580
Flip a direction ('next' -> 'previous'; 'previous' -> 'next').
Note that TypeScript can't prove that FlipDirection is its own inverse (but if you have a concrete 'next' or 'previous' it will simplify accordingly).
Type Parameters
D
D
extends CaretDirection
Parameters
direction
D
A direction
Returns
The opposite direction
getDocumentFromElement()
getDocumentFromElement(
element
):Document
Defined in: packages/lexical/src/LexicalUtils.ts:2321
Gets the appropriate Document object for an element, accounting for shadow DOM. Returns the ownerDocument of the ShadowRoot if the element is in shadow DOM, otherwise returns the element's ownerDocument or the global document.
Parameters
element
The HTMLElement to get the document for
null
| HTMLElement
Returns
Document
The Document object that should be used for DOM operations
getDOMOwnerDocument()
getDOMOwnerDocument(
target
):null
|Document
Defined in: packages/lexical/src/LexicalUtils.ts:1359
Parameters
target
null
| EventTarget
Returns
null
| Document
getDOMSelection()
getDOMSelection(
targetWindow
,rootElement?
):null
|Selection
Defined in: packages/lexical/src/LexicalUtils.ts:1787
Returns the selection for the given window, or the global window if null. Enhanced with Shadow DOM support using modern getComposedRanges() API when available, with fallback to checking if the selection is within the shadow DOM. Will return null if CAN_USE_DOM is false.
Parameters
targetWindow
The window to get the selection from
null
| Window
rootElement?
The root element to check for shadow DOM context (optional)
null
| HTMLElement
Returns
null
| Selection
A Selection object or null if selection cannot be retrieved
getDOMSelectionForEditor()
getDOMSelectionForEditor(
editor
):null
|Selection
Defined in: packages/lexical/src/LexicalUtils.ts:1954
Parameters
editor
Returns
null
| Selection
getDOMSelectionFromShadowRoot()
getDOMSelectionFromShadowRoot(
shadowRoot
):null
|Selection
Defined in: packages/lexical/src/LexicalUtils.ts:1737
Returns a Selection object from a ShadowRoot using the best available API.
This function implements a progressive enhancement strategy for getting selection from Shadow DOM contexts, trying modern APIs first and gracefully falling back to older or experimental APIs when needed.
Selection Proxy: When getComposedRanges returns valid ranges, this function creates a Selection proxy that uses the composed ranges data. This ensures proper text node resolution and range handling across Shadow DOM boundaries.
Error Handling: The function includes comprehensive error handling for all API calls, ensuring graceful degradation even when modern APIs throw exceptions.
Parameters
shadowRoot
ShadowRoot
The ShadowRoot to get selection from
Returns
null
| Selection
Selection object from the most appropriate API, or null if no selection available
getDOMSelectionFromTarget()
getDOMSelectionFromTarget(
eventTarget
):null
|Selection
Defined in: packages/lexical/src/LexicalUtils.ts:2361
Returns the selection for the defaultView of the ownerDocument of given EventTarget. Enhanced with Shadow DOM support using modern getComposedRanges() API when available, with fallback to experimental ShadowRoot.getSelection() for compatibility.
Parameters
eventTarget
The EventTarget (typically a DOM node) to get the selection from
null
| EventTarget
Returns
null
| Selection
A Selection object from the appropriate context or null if unavailable
getDOMTextNode()
getDOMTextNode(
element
):null
|Text
Defined in: packages/lexical/src/LexicalUtils.ts:262
Parameters
element
null
| Node
Returns
null
| Text
getNearestEditorFromDOMNode()
getNearestEditorFromDOMNode(
node
):null
|LexicalEditor
Defined in: packages/lexical/src/LexicalUtils.ts:202
Parameters
node
null
| Node
Returns
null
| LexicalEditor
getShadowRootOrDocument()
getShadowRootOrDocument(
element
):Document
|ShadowRoot
Defined in: packages/lexical/src/LexicalUtils.ts:1968
Traverses up the DOM tree to find a ShadowRoot if the element is inside a shadow DOM. This function helps determine whether the given element is rendered within Shadow DOM encapsulation.
Parameters
element
HTMLElement
The HTMLElement to start traversing from
Returns
Document
| ShadowRoot
The ShadowRoot if found, or Document if the element is not in shadow DOM
getWindow()
getWindow(
editor
):Window
Defined in: packages/lexical/src/LexicalUtils.ts:1484
Parameters
editor
Returns
Window
isBlockDomNode()
isBlockDomNode(
node
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:2484
Parameters
node
Node
the Dom Node to check
Returns
boolean
if the Dom Node is a block node
isCurrentlyReadOnlyMode()
isCurrentlyReadOnlyMode():
boolean
Defined in: packages/lexical/src/LexicalUpdates.ts:78
Returns
boolean
isDocumentFragment()
isDocumentFragment(
x
):x is DocumentFragment
Defined in: packages/lexical/src/LexicalUtils.ts:2462
Parameters
x
unknown
The element being testing
Returns
x is DocumentFragment
Returns true if x is a document fragment, false otherwise.
isDOMDocumentNode()
isDOMDocumentNode(
node
):node is Document
Defined in: packages/lexical/src/LexicalUtils.ts:258
Parameters
node
unknown
The element being tested
Returns
node is Document
Returns true if node is an DOM Document node, false otherwise.
isDOMNode()
isDOMNode(
x
):x is Node
Defined in: packages/lexical/src/LexicalUtils.ts:2449
Parameters
x
unknown
The element being tested
Returns
x is Node
Returns true if x is a DOM Node, false otherwise.
isDOMTextNode()
isDOMTextNode(
node
):node is Text
Defined in: packages/lexical/src/LexicalUtils.ts:250
Parameters
node
unknown
The element being tested
Returns
node is Text
Returns true if node is an DOM Text node, false otherwise.
isExactShortcutMatch()
isExactShortcutMatch(
event
,expectedKey
,mask
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:965
Match a KeyboardEvent with its expected state
Parameters
event
KeyboardEventModifiers
A KeyboardEvent, or structurally similar object
expectedKey
string
The string to compare with event.key (case insensitive)
mask
KeyboardEventModifierMask
An object specifying the expected state of the modifiers
Returns
boolean
true if the event matches
isHTMLAnchorElement()
isHTMLAnchorElement(
x
):x is HTMLAnchorElement
Defined in: packages/lexical/src/LexicalUtils.ts:2433
Parameters
x
unknown
The element being tested
Returns
x is HTMLAnchorElement
Returns true if x is an HTML anchor tag, false otherwise
isHTMLElement()
isHTMLElement(
x
):x is HTMLElement
Defined in: packages/lexical/src/LexicalUtils.ts:2441
Parameters
x
unknown
The element being tested
Returns
x is HTMLElement
Returns true if x is an HTML element, false otherwise.
isInlineDomNode()
isInlineDomNode(
node
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:2471
Parameters
node
Node
the Dom Node to check
Returns
boolean
if the Dom Node is an inline node
isLexicalEditor()
isLexicalEditor(
editor
):editor is LexicalEditor
Defined in: packages/lexical/src/LexicalUtils.ts:197
Parameters
editor
unknown
Returns
editor is LexicalEditor
true if the given argument is a LexicalEditor instance from this build of Lexical
isModifierMatch()
isModifierMatch(
event
,mask
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:945
Match a KeyboardEvent with its expected modifier state
Parameters
event
KeyboardEventModifiers
A KeyboardEvent, or structurally similar object
mask
KeyboardEventModifierMask
An object specifying the expected state of the modifiers
Returns
boolean
true if the event matches
isSelectionCapturedInDecoratorInput()
isSelectionCapturedInDecoratorInput(
anchorDOM
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:151
Parameters
anchorDOM
Node
Returns
boolean
isSelectionWithinEditor()
isSelectionWithinEditor(
editor
,anchorDOM
,focusDOM
):boolean
Defined in: packages/lexical/src/LexicalUtils.ts:173
Parameters
editor
anchorDOM
null
| Node
focusDOM
null
| Node
Returns
boolean
isShadowRoot()
isShadowRoot(
node
):node is ShadowRoot
Defined in: packages/lexical/src/LexicalUtils.ts:1347
Type guard function that checks if a node is a ShadowRoot. This function performs runtime validation to safely narrow types and enable type-safe Shadow DOM operations. It checks both the nodeType and the presence of the 'host' property to distinguish ShadowRoot from regular DocumentFragment nodes.
Parameters
node
The Node to check (can be null)
null
| Node
Returns
node is ShadowRoot
True if the node is a ShadowRoot, false otherwise. When true, TypeScript will narrow the type to ShadowRoot for subsequent operations.
makeStepwiseIterator()
makeStepwiseIterator<
State
,Stop
,Value
>(config
):IterableIterator
<Value
>
Defined in: packages/lexical/src/caret/LexicalCaret.ts:1185
A generalized utility for creating a stepwise iterator based on:
- an initial state
- a stop guard that returns true if the iteration is over, this is typically used to detect a sentinel value such as null or undefined from the state but may return true for other conditions as well
- a step function that advances the state (this will be called after map each time next() is called to prepare the next state)
- a map function that will be called that may transform the state before returning it. It will only be called once for each next() call when stop(state) === false
Type Parameters
State
State
Stop
Stop
Value
Value
Parameters
config
StepwiseIteratorConfig
<State
, Stop
, Value
>
Returns
IterableIterator
<Value
>
An IterableIterator
resetRandomKey()
resetRandomKey():
void
Defined in: packages/lexical/src/LexicalUtils.ts:105
Returns
void
setNodeIndentFromDOM()
setNodeIndentFromDOM(
elementDom
,elementNode
):void
Defined in: packages/lexical/src/LexicalUtils.ts:2626
Parameters
elementDom
HTMLElement
elementNode
Returns
void