@lexical/mark
Classes
MarkNode
Defined in: packages/lexical-mark/src/MarkNode.ts:55
Extends
Constructors
Constructor
new MarkNode(
ids?,key?):MarkNode
Defined in: packages/lexical-mark/src/MarkNode.ts:77
Parameters
ids?
readonly string[] = NO_IDS
key?
string
Returns
Inherited from
Properties
importDOM?
staticoptionalimportDOM?: () =>DOMConversionMap<any> |null
Defined in: packages/lexical/src/LexicalNode.ts:1243
Returns
DOMConversionMap<any> | null
Inherited from
Methods
$config()
$config():
BaseStaticNodeConfig&StaticNodeConfigAccessor<{$transform: { };extends: typeofLexicalNode;generated:GeneratedJSONFactory;json:NodeSerializationSchema<ElementNode, {direction?:"ltr"|"rtl"|null;format?:""|"left"|"start"|"center"|"right"|"end"|"justify";indent?:string|number;textFormat?:string|number;textStyle?:string; }>; }> &object&StaticNodeTypeAccessor<"mark"> &StaticNodeConfigAccessor<{children:"inline";extends: typeofElementNode;generated:GeneratedJSONFactory;inline:true;json:NodeSerializationSchema<MarkNode, {ids?: readonlystring[]; }>; }>
Defined in: packages/lexical-mark/src/MarkNode.ts:67
Override this to implement the new static node configuration protocol, this method is called directly on the prototype and must not depend on anything initialized in the constructor. Generally it should be a trivial implementation.
Returns
BaseStaticNodeConfig & StaticNodeConfigAccessor<{ $transform: { }; extends: typeof LexicalNode; generated: GeneratedJSONFactory; json: NodeSerializationSchema<ElementNode, { direction?: "ltr" | "rtl" | null; format?: "" | "left" | "start" | "center" | "right" | "end" | "justify"; indent?: string | number; textFormat?: string | number; textStyle?: string; }>; }> & object & StaticNodeTypeAccessor<"mark"> & StaticNodeConfigAccessor<{ children: "inline"; extends: typeof ElementNode; generated: GeneratedJSONFactory; inline: true; json: NodeSerializationSchema<MarkNode, { ids?: readonly string[]; }>; }>
Example
class MyNode extends TextNode {
$config() {
return this.config('my-node', {extends: TextNode});
}
}
Inherited from
addID()
addID(
id):this
Defined in: packages/lexical-mark/src/MarkNode.ts:131
Parameters
id
string
Returns
this
afterCloneFrom()
afterCloneFrom(
prevNode):void
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:345
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:777
Parameters
nodesToAppend
...LexicalNode[]
Returns
this
Inherited from
canBeEmpty()
canBeEmpty():
false
Defined in: packages/lexical-mark/src/MarkNode.ts:164
Returns
false
Inherited from
canIndent()
canIndent():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1019
Returns
boolean
Inherited from
canInsertTextAfter()
canInsertTextAfter():
boolean
Defined in: packages/lexical-mark/src/MarkNode.ts:160
Returns
boolean
Inherited from
ElementNode.canInsertTextAfter
canInsertTextBefore()
canInsertTextBefore():
boolean
Defined in: packages/lexical-mark/src/MarkNode.ts:156
Returns
boolean
Inherited from
ElementNode.canInsertTextBefore
canMergeWhenEmpty()
canMergeWhenEmpty():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1096
Determines whether this node, when empty, can merge with a first block of nodes being inserted.
This method is specifically called in RangeSelection.insertNodes to determine merging behavior during nodes insertion.
Returns
boolean
Example
// In a ListItemNode or QuoteNode implementation:
canMergeWhenEmpty(): true {
return true;
}
Inherited from
clear()
clear():
this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:771
Returns
this
Inherited from
collapseAtStart()
collapseAtStart(
selection):boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1033
Parameters
selection
Returns
boolean
Inherited from
config()
Call Signature
config<
Config>(type,config):AbstractStaticNodeConfigRecord<Config>
Defined in: packages/lexical/src/LexicalNode.ts:1147
This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.
An abstract base class that has no concrete node type may pass a
well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of
a string type to declare configuration shared with its subclasses.
Type Parameters
Config
Config extends StaticNodeConfigValue<MarkNode, string>
Parameters
type
symbol
config
Config
Returns
AbstractStaticNodeConfigRecord<Config>
Inherited from
Call Signature
config<
Type,Config>(type,config):StaticNodeConfigRecord<Type,Config>
Defined in: packages/lexical/src/LexicalNode.ts:1151
This is a convenience method for $config that aids in type inference. See LexicalNode.$config for example usage.
An abstract base class that has no concrete node type may pass a
well-known symbol (by convention Symbol.for(<NodeClassName>)) instead of
a string type to declare configuration shared with its subclasses.
Type Parameters
Type
Type extends string
Config
Config extends StaticNodeConfigValue<MarkNode, Type>
Parameters
type
Type
config
Config
Returns
StaticNodeConfigRecord<Type, Config>
Inherited from
createDOM()
createDOM(
config):HTMLElement
Defined in: packages/lexical-mark/src/MarkNode.ts:82
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
Inherited from
createParentElementNode()
createParentElementNode():
ElementNode
Defined in: packages/lexical/src/LexicalNode.ts:2117
The creation logic for any required parent. Should be implemented if isParentRequired returns true.
Returns
Inherited from
ElementNode.createParentElementNode
deleteID()
deleteID(
id):this
Defined in: packages/lexical-mark/src/MarkNode.ts:136
Parameters
id
string
Returns
this
excludeFromCopy()
excludeFromCopy(
destination):boolean
Defined in: packages/lexical-mark/src/MarkNode.ts:195
Parameters
destination
"clone" | "html"
Returns
boolean
Inherited from
exportDOM()
exportDOM(
editor):DOMExportOutput
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:942
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()
Call Signature
exportJSON(
compact?):SerializedMarkNode
Defined in: packages/lexical-mark/src/MarkNode.ts:56
Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.
The base implementation writes every property the node's schema declares
(its own and those it inherits), reading each through its getter —
get<Prop> by default, or the name recorded with withAccessors. A getter
that returns undefined omits its property. Override this only for output
a schema can not describe, and call super.exportJSON(compact) when you do.
This may serialize the instance as-is, without resolving the latest version. A property declared with withField is read straight off the node, which is the optimization the serialization walk is built on — every node the walk reaches comes from the EditorState's node map and is already current, so it resolves nothing per node.
So on a reference that a getWritable() (any set<Prop>) has since
superseded, this writes pre-mutation values. Which properties do is not
something to rely on: a property whose accessor a subclass overrode still
goes through that accessor and resolves the latest, so one node can write
a current text beside a stale style. Call
node.getLatest().exportJSON() whenever you hold such a reference rather
than reasoning about which properties resolve.
This is a breaking change. Every property previously went through an
accessor, and every accessor resolves getLatest(), so a stale reference
exported current values.
Parameters
compact?
false
Write the compact form: omit a property the parser derives
rather than reads, one whose value is the schema default parsing would
restore, and the deprecated version. The two forms describe the same
document. A node that overrides this and ignores the flag simply keeps
writing the full form, which still parses.
Returns
Inherited from
Call Signature
exportJSON(
compact):SerializedPartial<SerializedMarkNode>
Defined in: packages/lexical-mark/src/MarkNode.ts:57
The compact form omits properties, so what it returns is the partial
serialized type — every node-specific property optional — rather than the
full one. Passing a boolean whose value is not statically known selects
this overload too, which is right: neither form can be promised then.
Parameters
compact
boolean
Returns
SerializedPartial<SerializedMarkNode>
See
Inherited from
extractWithChild()
extractWithChild(
child,selection,destination):boolean
Defined in: packages/lexical-mark/src/MarkNode.ts:172
Parameters
child
selection
destination
"clone" | "html"
Returns
boolean
Inherited from
getAllTextNodes()
getAllTextNodes():
TextNode[]
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:430
Returns
TextNode[]
Inherited from
getChildAtIndex()
Call Signature
getChildAtIndex(
index):LexicalNode|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:604
Returns the child of this node at the given index, or null if the index is out of range.
Parameters
index
number
Returns
LexicalNode | null
Inherited from
Call Signature
getChildAtIndex<
T>(index):T|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:611
Type Parameters
T
T extends LexicalNode
Parameters
index
number
Returns
T | null
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to element.getChildAtIndex(index) as T | null, and will
be removed in a future release. Call this method without a type
argument and narrow the result with a type guard instead.
Inherited from
getChildren()
Call Signature
getChildren():
LexicalNode[]
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:390
Returns the children of this node, in document order.
Returns
Inherited from
Call Signature
getChildren<
T>():T[]
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:397
Type Parameters
T
T extends LexicalNode
Returns
T[]
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to element.getChildren() as T[], and will be
removed in a future release. Call this method without a type argument
and narrow the results with a type guard instead.
Inherited from
getChildrenKeys()
getChildrenKeys():
string[]
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:401
Returns
string[]
Inherited from
getChildrenSize()
getChildrenSize():
number
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:410
Returns
number
Inherited from
getDescendantByIndex()
Call Signature
getDescendantByIndex(
index):LexicalNode|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:515
Returns the deepest descendant corresponding to the child at the given index, or null if this node has no children.
Parameters
index
number
Returns
LexicalNode | null
Inherited from
ElementNode.getDescendantByIndex
Call Signature
getDescendantByIndex<
T>(index):T|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:522
Type Parameters
T
T extends LexicalNode
Parameters
index
number
Returns
T | null
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to element.getDescendantByIndex(index) as T | null, and
will be removed in a future release. Call this method without a type
argument and narrow the result with a type guard instead.
Inherited from
ElementNode.getDescendantByIndex
getDirection()
getDirection():
"ltr"|"rtl"|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:681
Returns
"ltr" | "rtl" | null
Inherited from
getDOMSlot()
getDOMSlot(
element):ElementDOMSlot<HTMLElement>
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:939
Experimental
An ElementNode subclass can override this to control where its children are inserted into the DOM, e.g. to add a wrapping node or accessory nodes before or after the children. The root of the node returned by createDOM must still be exactly one HTMLElement.
Parameters
element
Returns
Inherited from
getFirstChild()
Call Signature
getFirstChild():
LexicalNode|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:535
Returns the first child of this node, or null if it has no children.
Returns
LexicalNode | null
Inherited from
Call Signature
getFirstChild<
T>():T|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:542
Type Parameters
T
T extends LexicalNode
Returns
T | null
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to element.getFirstChild() as T | null, and will be
removed in a future release. Call this method without a type argument
and narrow the result with a type guard instead.
Inherited from
getFirstChildOrThrow()
Call Signature
getFirstChildOrThrow():
LexicalNode
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:551
Returns the first child of this node, or throws if it has no children.
Returns
Inherited from
ElementNode.getFirstChildOrThrow
Call Signature
getFirstChildOrThrow<
T>():T
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:558
Type Parameters
T
T extends LexicalNode
Returns
T
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to element.getFirstChildOrThrow() as T, and will be
removed in a future release. Call this method without a type argument
and narrow the result with a type guard instead.
Inherited from
ElementNode.getFirstChildOrThrow
getFirstDescendant()
Call Signature
getFirstDescendant():
LexicalNode|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:469
Returns the deepest first descendant of this node, or null if it has no children.
Descendant navigation is children-only by design: it feeds selectStart / selectEnd and selection, which must not see slots (slots are isolated).
Returns
LexicalNode | null
Inherited from
ElementNode.getFirstDescendant
Call Signature
getFirstDescendant<
T>():T|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:476
Type Parameters
T
T extends LexicalNode
Returns
T | null
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to element.getFirstDescendant() as T | null, and will be
removed in a future release. Call this method without a type argument
and narrow the result with a type guard instead.
Inherited from
ElementNode.getFirstDescendant
getFormat()
getFormat():
number
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:371
Returns
number
Inherited from
getFormatFlags()
getFormatFlags(
type,alignWithFormat):number
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:705
Returns the format flags applied to the node as a 32-bit integer.
Parameters
type
alignWithFormat
number | null
Returns
number
a number representing the TextFormatTypes applied to the node.
Inherited from
getFormatType()
getFormatType():
ElementFormatType
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:375
Returns
Inherited from
getIDs()
getIDs():
string[]
Defined in: packages/lexical-mark/src/MarkNode.ts:121
Returns
string[]
getIndent()
getIndent():
number
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:383
Returns
number
Inherited from
getIndexWithinParent()
getIndexWithinParent():
number
Defined in: packages/lexical/src/LexicalNode.ts:1365
Returns the zero-based index of this node within the parent.
Returns
number
Inherited from
ElementNode.getIndexWithinParent
getKey()
getKey():
string
Defined in: packages/lexical/src/LexicalNode.ts:1357
Returns this nodes key.
Returns
string
Inherited from
getLastChild()
Call Signature
getLastChild():
LexicalNode|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:569
Returns the last child of this node, or null if it has no children.
Returns
LexicalNode | null
Inherited from
Call Signature
getLastChild<
T>():T|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:576
Type Parameters
T
T extends LexicalNode
Returns
T | null
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to element.getLastChild() as T | null, and will be
removed in a future release. Call this method without a type argument
and narrow the result with a type guard instead.
Inherited from
getLastChildOrThrow()
Call Signature
getLastChildOrThrow():
LexicalNode
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:585
Returns the last child of this node, or throws if it has no children.
Returns
Inherited from
ElementNode.getLastChildOrThrow
Call Signature
getLastChildOrThrow<
T>():T
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:592
Type Parameters
T
T extends LexicalNode
Returns
T
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to element.getLastChildOrThrow() as T, and will be
removed in a future release. Call this method without a type argument
and narrow the result with a type guard instead.
Inherited from
ElementNode.getLastChildOrThrow
getLastDescendant()
Call Signature
getLastDescendant():
LexicalNode|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:492
Returns the deepest last descendant of this node, or null if it has no children.
Returns
LexicalNode | null
Inherited from
Call Signature
getLastDescendant<
T>():T|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:499
Type Parameters
T
T extends LexicalNode
Returns
T | null
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to element.getLastDescendant() as T | null, and will be
removed in a future release. Call this method without a type argument
and narrow the result with a type guard instead.
Inherited from
getLatest()
getLatest():
this
Defined in: packages/lexical/src/LexicalNode.ts:1671
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()
Call Signature
getNextSibling():
LexicalNode|null
Defined in: packages/lexical/src/LexicalNode.ts:1534
Returns the node after this one in the same parent, or null if there is no such node.
Returns
LexicalNode | null
Inherited from
Call Signature
getNextSibling<
T>():T|null
Defined in: packages/lexical/src/LexicalNode.ts:1541
Type Parameters
T
T extends LexicalNode
Returns
T | null
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to node.getNextSibling() as T | null, and will be
removed in a future release. Call this method without a type argument
and narrow the result with a type guard instead.
Inherited from
getNextSiblings()
Call Signature
getNextSiblings():
LexicalNode[]
Defined in: packages/lexical/src/LexicalNode.ts:1552
Returns all nodes after this one in the same parent, in document order.
Returns
Inherited from
Call Signature
getNextSiblings<
T>():T[]
Defined in: packages/lexical/src/LexicalNode.ts:1559
Type Parameters
T
T extends LexicalNode
Returns
T[]
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to node.getNextSiblings() as T[], and will be
removed in a future release. Call this method without a type argument
and narrow the results with a type guard instead.
Inherited from
getNodesBetween()
getNodesBetween(
targetNode):LexicalNode[]
Defined in: packages/lexical/src/LexicalNode.ts:1621
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()
Call Signature
getParent():
ElementNode|null
Defined in: packages/lexical/src/LexicalNode.ts:1385
Returns the parent of this node, or null if none is found.
Returns
ElementNode | null
Inherited from
Call Signature
getParent<
T>():T|null
Defined in: packages/lexical/src/LexicalNode.ts:1392
Type Parameters
T
T extends ElementNode
Returns
T | null
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to node.getParent() as T | null, and will be removed
in a future release. Call this method without a type argument and
narrow the result with a type guard instead.
Inherited from
getParentKeys()
getParentKeys():
string[]
Defined in: packages/lexical/src/LexicalNode.ts:1483
Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.
Returns
string[]
Inherited from
getParentOrThrow()
Call Signature
getParentOrThrow():
ElementNode
Defined in: packages/lexical/src/LexicalNode.ts:1405
Returns the parent of this node, or throws if none is found.
Returns
Inherited from
Call Signature
getParentOrThrow<
T>():T
Defined in: packages/lexical/src/LexicalNode.ts:1412
Type Parameters
T
T extends ElementNode
Returns
T
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to node.getParentOrThrow() as T, and will be removed
in a future release. Call this method without a type argument and
narrow the result with a type guard instead.
Inherited from
getParents()
getParents():
ElementNode[]
Defined in: packages/lexical/src/LexicalNode.ts:1468
Returns a list of the every ancestor of this node, all the way up to the RootNode.
Returns
Inherited from
getPreviousSibling()
Call Signature
getPreviousSibling():
LexicalNode|null
Defined in: packages/lexical/src/LexicalNode.ts:1497
Returns the node before this one in the same parent, or null if there is no such node.
Returns
LexicalNode | null
Inherited from
ElementNode.getPreviousSibling
Call Signature
getPreviousSibling<
T>():T|null
Defined in: packages/lexical/src/LexicalNode.ts:1504
Type Parameters
T
T extends LexicalNode
Returns
T | null
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to node.getPreviousSibling() as T | null, and will be
removed in a future release. Call this method without a type argument
and narrow the result with a type guard instead.
Inherited from
ElementNode.getPreviousSibling
getPreviousSiblings()
Call Signature
getPreviousSiblings():
LexicalNode[]
Defined in: packages/lexical/src/LexicalNode.ts:1515
Returns all nodes before this one in the same parent, in document order.
Returns
Inherited from
ElementNode.getPreviousSiblings
Call Signature
getPreviousSiblings<
T>():T[]
Defined in: packages/lexical/src/LexicalNode.ts:1522
Type Parameters
T
T extends LexicalNode
Returns
T[]
Deprecated
The type parameter is an unchecked and unsafe cast,
equivalent to node.getPreviousSiblings() as T[], and will be
removed in a future release. Call this method without a type argument
and narrow the results with a type guard instead.
Inherited from
ElementNode.getPreviousSiblings
getStyle()
getStyle():
string
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:379
Returns
string
Inherited from
getTextContent()
getTextContent():
string
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:639
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:658
Returns the length of the string produced by calling getTextContent on this node.
Returns
number
Inherited from
ElementNode.getTextContentSize
getTextFormat()
getTextFormat():
number
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:685
Returns
number
Inherited from
getTextStyle()
getTextStyle():
string
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:711
Returns
string
Inherited from
getTopLevelElement()
getTopLevelElement():
ElementNode|null
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:257
Returns the highest (in the EditorState tree) non-root ancestor of this node, or null if none is found. See $isRootOrShadowRoot for more information on which Elements comprise "roots".
Returns
ElementNode | null
Inherited from
ElementNode.getTopLevelElement
getTopLevelElementOrThrow()
getTopLevelElementOrThrow():
ElementNode
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:258
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
ElementNode.getTopLevelElementOrThrow
getType()
getType():
string
Defined in: packages/lexical/src/LexicalNode.ts:1268
Returns the string type of this node.
Returns
string
Inherited from
getWritable()
getWritable():
this
Defined in: packages/lexical/src/LexicalNode.ts:1694
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:689
Parameters
type
Returns
boolean
Inherited from
hasID()
hasID(
id):boolean
Defined in: packages/lexical-mark/src/MarkNode.ts:117
Parameters
id
string
Returns
boolean
hasTextFormat()
hasTextFormat(
type):boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:696
Parameters
type
Returns
boolean
Inherited from
insertAfter()
insertAfter(
nodeToInsert,restoreSelection?):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:2085
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:2096
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?):ElementNode|null
Defined in: packages/lexical-mark/src/MarkNode.ts:147
Parameters
selection
restoreSelection?
boolean = true
Returns
ElementNode | null
Inherited from
is()
is(
object):boolean
Defined in: packages/lexical/src/LexicalNode.ts:1570
Returns true if the provided node is the exact same one as this node, from Lexical's perspective. Always use this instead of referential equality.
Parameters
object
LexicalNode | null | undefined
the node to perform the equality comparison on.
Returns
boolean
Inherited from
isAttached()
isAttached():
boolean
Defined in: packages/lexical/src/LexicalNode.ts:1285
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:1588
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:420
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:414
Returns
boolean
Inherited from
isInline()
isInline():
true
Defined in: packages/lexical-mark/src/MarkNode.ts:168
If the method is overridden and returns true, ensure that canBeEmpty()
returns false for the inline node to work correctly
Returns
true
Inherited from
isLastChild()
isLastChild():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:425
Returns
boolean
Inherited from
isParentOf()
isParentOf(
targetNode):boolean
Defined in: packages/lexical/src/LexicalNode.ts:1611
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:2109
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:1312
Returns true if this node is contained within the provided Selection., false otherwise. Relies on the algorithms implemented in BaseSelection.getNodes to determine what's included.
Parameters
selection?
BaseSelection | null
The selection that we want to determine if the node is in.
Returns
boolean
Inherited from
isShadowRoot()
isShadowRoot():
boolean
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:1068
Returns
boolean
Inherited from
markDirty()
markDirty():
void
Defined in: packages/lexical/src/LexicalNode.ts:2162
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:1967
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:1984
Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.
Named slots are bound to their host node and are never transferred: this
node keeps its slot map, so if it is reattached elsewhere (as
$wrapNodeInElement does) its slots come with it, and if it stays
detached the slot subtrees are garbage-collected along with it. To move a
slot value onto another host, use $setSlot explicitly.
Type Parameters
N
N extends LexicalNode
Parameters
replaceWith
N
The node to replace this one with.
includeChildren?
boolean
Whether or not to transfer the children of this node to the replacing node.
Returns
N
Inherited from
resetOnCopyNodeFrom()
resetOnCopyNodeFrom(
originalNode):void
Defined in: packages/lexical/src/LexicalNode.ts:1236
Reset state in this copy of originalNode, if necessary
Parameters
originalNode
this
Returns
void
Inherited from
ElementNode.resetOnCopyNodeFrom
select()
select(
_anchorOffset?,_focusOffset?):RangeSelection
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:718
Parameters
_anchorOffset?
number
_focusOffset?
number
Returns
Inherited from
selectEnd()
selectEnd():
RangeSelection
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:767
Returns
Inherited from
selectNext()
selectNext(
anchorOffset?,focusOffset?):RangeSelection
Defined in: packages/lexical/src/LexicalNode.ts:2149
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:2135
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:763
Returns
Inherited from
setDirection()
setDirection(
direction):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:780
Parameters
direction
"ltr" | "rtl" | null
Returns
this
Inherited from
setFormat()
setFormat(
type):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:785
Parameters
type
Returns
this
Inherited from
setIDs()
setIDs(
ids):this
Defined in: packages/lexical-mark/src/MarkNode.ts:125
Parameters
ids
readonly string[]
Returns
this
setIndent()
setIndent(
indentLevel):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:805
Parameters
indentLevel
number
Returns
this
Inherited from
setStyle()
setStyle(
style):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:790
Parameters
style
string
Returns
this
Inherited from
setTextFormat()
setTextFormat(
type):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:795
Parameters
type
number
Returns
this
Inherited from
setTextStyle()
setTextStyle(
style):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:800
Parameters
style
string
Returns
this
Inherited from
splice()
splice(
start,deleteCount,nodesToInsert):this
Defined in: packages/lexical/src/nodes/LexicalElementNode.ts:810
Parameters
start
number
deleteCount
number
nodesToInsert
Returns
this
Inherited from
updateDOM()
updateDOM(
prevNode,element,config):boolean
Defined in: packages/lexical-mark/src/MarkNode.ts:91
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
element
config
Returns
boolean
Inherited from
updateFromJSON()
updateFromJSON(
serializedNode):this
Defined in: packages/lexical-mark/src/MarkNode.ts:58
Update this LexicalNode instance from serialized JSON. It's recommended to implement as much logic as possible in this method instead of the static importJSON method, so that the functionality can be inherited in subclasses.
The LexicalUpdateJSON utility type should be used to ignore any type, version, or children properties in the JSON so that the extended JSON from subclasses are acceptable parameters for the super call.
If overridden, this method must call super.
Parameters
serializedNode
LexicalParseJSON<SerializedMarkNode>
Returns
this
Example
class MyTextNode extends TextNode {
// ...
static importJSON(serializedNode: SerializedMyTextNode): MyTextNode {
return $createMyTextNode()
.updateFromJSON(serializedNode);
}
updateFromJSON(
serializedNode: LexicalUpdateJSON<SerializedMyTextNode>,
): this {
return super.updateFromJSON(serializedNode)
.setMyProperty(serializedNode.myProperty);
}
}
The whole schema is applied, so a property the JSON omits is set to its schema default rather than left as it is — that is what lets the compact form omit a default-valued property and have parsing restore it. (A flat NodeState is the exception: it is applied only when present.) Pass the node's complete serialized form unless you mean to reset what you leave out.
Inherited from
clone()
staticclone(_data):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1111
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
Inherited from
getType()
staticgetType():string
Defined in: packages/lexical/src/LexicalNode.ts:1095
Returns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.
Returns
string
Inherited from
importJSON()
staticimportJSON(_serializedNode):LexicalNode
Defined in: packages/lexical/src/LexicalNode.ts:1889
Controls how the this node is deserialized from JSON. This is usually boilerplate, but provides an abstraction between the node implementation and serialized interface that can be important if you ever make breaking changes to a node schema (by adding or removing properties). See Serialization & Deserialization.
Parameters
_serializedNode
Omit<SerializedLexicalNode & Partial<SerializedLexicalNode>, "$slots" | "children" | "version"> & object & Record<string, unknown>
Returns
Inherited from
transform()
statictransform(): ((node) =>void) |null
Defined in: packages/lexical/src/LexicalNode.ts:1953
Experimental
Registers the returned function as a transform on the node during Editor initialization. Most such use cases should be addressed via the LexicalEditor.registerNodeTransform API.
Experimental - use at your own risk.
Returns
((node) => void) | null
Inherited from
Interfaces
MarkStateConfig
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:113
Experimental
Configuration for MarkStateExtension.
Properties
disabled
disabled:
boolean
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:122
Experimental
When true, mark ids are not rendered in the editor DOM, the
markIDNodeKeys output is emptied and no longer maintained, and text
inserted next to a marked run no longer has its ids adjusted (it keeps
whatever ids the TextNode it lands in has). The ids stay in the document,
the $ functions keep working, and HTML export (with exportIDsToHTML)
and import still write and read the ids.
exportIDsToHTML
exportIDsToHTML:
boolean
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:130
Experimental
When true, HTML export ($generateHtmlFromNodes, and so copying to the
clipboard as text/html) writes the data-lexical-mark-ids attribute on
marked leaves, so that the ids survive an HTML round trip. Default
false, like MarkNode, which exports no ids: they are often internal
thread ids that should not leak into other applications.
markableNodes
markableNodes: readonly
MarkableNodeMatch[]
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:145
Experimental
The nodes that carry mark ids: a node is markable when it is an instance
of one of these classes or one of these guards returns true for it.
Marking a range marks the markable nodes in it, and the ElementNodes and
slot hosts in it are looked through (their children and their slots).
Use it for leaves: TextNode, LineBreakNode and DecoratorNode subclasses.
The default is [TextNode, LineBreakNode, $isInlineDecoratorNode]:
TextNode and its subclasses, LineBreakNode, and every inline DecoratorNode
(which includes DecoratorTextNode from @lexical/extension). To extend
it, spread the default:
[...DEFAULT_MARKABLE_NODES, MyBlockDecoratorNode].
Every editor that edits the same document should use the same set.
MarkStateOutput
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:153
Experimental
Output of MarkStateExtension.
Properties
disabled
disabled:
Signal<boolean>
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:154
Experimental
exportIDsToHTML
exportIDsToHTML:
Signal<boolean>
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:155
Experimental
markIDNodeKeys
markIDNodeKeys:
ReadonlySignal<ReadonlyMap<string, readonlystring[]>>
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:161
Experimental
Every mark id in the document, mapped to the keys of the leaves that carry it (in no particular order). A new Map is published after each update that changes it. Empty while the extension is disabled.
Type Aliases
MarkableNodeMatch
MarkableNodeMatch =
Klass<LexicalNode> | ((node) =>boolean)
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:95
Experimental
A node class, matched with instanceof, or a guard function, as used in
the markableNodes config of MarkStateExtension.
SerializedMarkNode
SerializedMarkNode =
Spread<{ids:string[]; },SerializedElementNode>
Defined in: packages/lexical-mark/src/MarkNode.ts:33
Variables
DEFAULT_MARKABLE_NODES
constDEFAULT_MARKABLE_NODES: readonlyMarkableNodeMatch[]
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:231
Experimental
The default markableNodes of MarkStateExtension: TextNode,
LineBreakNode and inline DecoratorNodes (including DecoratorTextNode).
MARK_STATE_IDS_ATTRIBUTE
constMARK_STATE_IDS_ATTRIBUTE:"data-lexical-mark-ids"='data-lexical-mark-ids'
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:106
Experimental
The attribute that MarkStateExtension renders on the element of each
marked leaf in the editor, holding its space separated ids. HTML export
writes it when exportIDsToHTML is set, and HTML import reads it back.
MARK_STATE_KEY
constMARK_STATE_KEY:"markIds"='markIds'
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:87
Experimental
The NodeState key that MarkStateExtension stores mark ids under: a
leaf covered by c1 and c2 has {"markIds": ["c1", "c2"]} (sorted) in
the $ record of its JSON.
The state is an arraySetValue (see lexical), so its schema marks it as
a set whose members are independent: code that stores or merges NodeState
can treat each id separately.
MarkExtension
constMarkExtension:LexicalExtension<ExtensionConfigBase,"@lexical/mark",unknown,unknown>
Defined in: packages/lexical-mark/src/index.ts:166
Configures MarkNode
MarkStateExtension
constMarkStateExtension:MarkStateExtensionType
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:2067
Experimental
An experimental alternative to MarkNode for comments and other
annotations: the mark ids are stored as a set-valued NodeState
(markIds, a sorted array in JSON) on the leaves they cover (TextNode,
LineBreakNode and inline DecoratorNode by default, see markableNodes),
instead of wrapping them in a MarkNode.
- Marks overlap freely: text covered by two comments is one TextNode with both ids, not a MarkNode split into sibling wrappers.
- Adding or removing an id changes NodeState only; it never moves, re-creates or wraps text. (Adding or removing it on part of a TextNode splits that TextNode, and TextNodes left with the same ids merge back.)
- The ids live on the leaves, so they travel with the text: typing inside a marked run, copying, cutting or deleting text keeps its ids with it.
- Marked leaves are rendered with the
mark(and, for more than one id,markOverlap) theme classes and adata-lexical-mark-idsattribute. WithexportIDsToHTML, HTML export writes that attribute too; the@lexical/htmlimport pipeline reads it back. - Text inserted at the edge of a marked run does not join it, like MarkNode; text inserted inside a run does. Text that replaces a selection also gets the ids all of the replaced text had, and pasted content keeps its own ids (pasted marked text stays marked). Text that the edit moves into a new TextNode (a hashtag, a segmented node turned into text) keeps its ids, except an id removed with $removeMarkID in the same update. A TextNode is split where its text gets different ids when its pieces stay of its own class (TextNode, or the class that replaces it); other TextNodes (a token or segmented node, a hashtag) get every id their text had.
Use $addMarkID, $removeMarkID,
$getMarkIDsAtSelection and $getNodeMarkIDs to work with
the ids, the markIDNodeKeys output to find the nodes of an id, and
$migrateMarkNodesToMarkState to convert MarkNode documents.
Functions
$addMarkID()
$addMarkID(
id,selection):LexicalNode[]
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:391
Experimental
Add the mark id to every markable node in selection (TextNode,
LineBreakNode and inline DecoratorNode by default, see markableNodes),
including the content of the slots of the nodes in it, splitting the
TextNodes at its boundaries. Ids already on those nodes are kept, so marks
can overlap freely. A collapsed selection marks nothing.
Parameters
id
string
The mark id, for example a comment thread id. It must be a non-empty string without whitespace, otherwise this throws.
selection
The selection to mark
Returns
The nodes that now carry the id
$createMarkNode()
$createMarkNode(
ids?):MarkNode
Defined in: packages/lexical-mark/src/MarkNode.ts:200
Parameters
ids?
readonly string[] = NO_IDS
Returns
$getMarkIDs()
$getMarkIDs(
node,offset):string[] |null
Defined in: packages/lexical-mark/src/index.ts:144
Parameters
node
offset
number
Returns
string[] | null
$getMarkIDsAtSelection()
$getMarkIDsAtSelection(
selection?,mode?):string[]
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:534
Experimental
Get the mark ids at a selection, sorted. For a collapsed RangeSelection
these are the ids of the leaf holding the caret (or of the next leaf, when
the caret is at the end of an unmarked TextNode), like $getMarkIDs does
for MarkNode. Otherwise, mode 'any' (the default) returns the ids on
any selected leaf, and 'all' the ids shared by every selected leaf. The
TextNodes that a RangeSelection only touches at an edge are ignored.
Parameters
selection?
BaseSelection | null
The selection, defaults to the current selection
mode?
"any" | "all"
'any' or 'all', for a selection that is not collapsed
Returns
string[]
The ids, sorted
$getNodeMarkIDs()
$getNodeMarkIDs(
node):string[]
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:293
Experimental
Get the mark ids stored on a node by MarkStateExtension, sorted. Nodes that cannot carry ids return an empty array.
Parameters
node
The node
Returns
string[]
A new array of the ids, sorted, which the caller may change
$isInlineDecoratorNode()
$isInlineDecoratorNode(
node):node is DecoratorNode<unknown>
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:219
Experimental
Inline DecoratorNodes, one of the default markableNodes of
MarkStateExtension. This includes DecoratorTextNode.
Parameters
node
LexicalNode | null | undefined
Returns
node is DecoratorNode<unknown>
$isMarkNode()
$isMarkNode(
node):node is MarkNode
Defined in: packages/lexical-mark/src/MarkNode.ts:204
Parameters
node
LexicalNode | null
Returns
node is MarkNode
$migrateMarkNodesToMarkState()
$migrateMarkNodesToMarkState(
node?):number
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:590
Experimental
Convert a document that uses MarkNode into one that uses MarkStateExtension: the ids of every MarkNode (including the ids of MarkNodes it is nested in) are added to the leaves inside it, and the MarkNode is unwrapped.
Run this once per document, before anything else edits it (for example in a headless editor): the unwrap is a structural change, and an edit made at the same time by another writer races with it as with any MarkNode edit. Like $addMarkID, it throws on an id that is empty or contains whitespace.
Parameters
node?
LexicalNode = ...
The subtree to convert, defaults to the root
Returns
number
The number of MarkNodes that were unwrapped
$removeMarkID()
$removeMarkID(
id,selection?):void
Defined in: packages/lexical-mark/src/MarkStateExtension.ts:479
Experimental
Remove the mark id. With a selection it is removed from the nodes in
that selection only (splitting the TextNodes at its boundaries), otherwise
from the whole document (found through the markIDNodeKeys output, or by
walking the document when the extension is not active). Text that no
longer differs from its neighbors is merged back by normalization.
Parameters
id
string
The mark id
selection?
BaseSelection | null
Limit the removal to this selection
Returns
void
$unwrapMarkNode()
$unwrapMarkNode(
node):void
Defined in: packages/lexical-mark/src/index.ts:28
Parameters
node
Returns
void
$wrapSelectionInMarkNode()
$wrapSelectionInMarkNode(
selection,isBackward,id,createNode?):void
Defined in: packages/lexical-mark/src/index.ts:43
Parameters
selection
isBackward
boolean
id
string
createNode?
(ids) => MarkNode
Returns
void