Class: ElementNode
lexical.ElementNode
Hierarchy
-
↳
ElementNode
↳↳
LinkNode
↳↳
OverflowNode
↳↳
QuoteNode
↳↳
HeadingNode
↳↳
RootNode
↳↳
CodeNode
↳↳
ListItemNode
↳↳
ListNode
↳↳
MarkNode
↳↳
TableNode
↳↳
TableRowNode
Constructors
constructor
• new ElementNode(key?
): ElementNode
Parameters
Name | Type |
---|---|
key? | string |
Returns
Inherited from
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:85
Properties
constructor
• constructor: KlassConstructor
<typeof ElementNode
>
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:69
importDOM
▪ Static
Optional
importDOM: () => null
| DOMConversionMap
<any
>
Type declaration
▸ (): null
| DOMConversionMap
<any
>
Returns
null
| DOMConversionMap
<any
>
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:209
Methods
append
▸ append(...nodesToAppend
): this
Parameters
Name | Type |
---|---|
...nodesToAppend | LexicalNode [] |
Returns
this
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:362
canBeEmpty
▸ canBeEmpty(): boolean
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:555
canIndent
▸ canIndent(): boolean
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:533
canInsertTextAfter
▸ canInsertTextAfter(): boolean
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:561
canInsertTextBefore
▸ canInsertTextBefore(): boolean
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:558
canMergeWhenEmpty
▸ canMergeWhenEmpty(): boolean
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;
}
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:599
clear
▸ clear(): this
Returns
this
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:356
collapseAtStart
▸ collapseAtStart(selection
): boolean
Parameters
Name | Type |
---|---|
selection | RangeSelection |
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:541
createDOM
▸ createDOM(_config
, _editor
): HTMLElement
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 lifecyle.
Parameters
Name | Type | Description |
---|---|---|
_config | EditorConfig | allows access to things like the EditorTheme (to apply classes) during reconciliation. |
_editor | LexicalEditor | allows access to the editor for context during reconciliation. |
Returns
HTMLElement
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:758
createParentElementNode
▸ createParentElementNode(): ElementNode
The creation logic for any required parent. Should be implemented if isParentRequired returns true.
Returns
Inherited from
LexicalNode.createParentElementNode
Defined in
packages/lexical/src/LexicalNode.ts:1037
excludeFromCopy
▸ excludeFromCopy(destination?
): boolean
Parameters
Name | Type |
---|---|
destination? | "clone" | "html" |
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:544
exportDOM
▸ exportDOM(editor
): DOMExportOutput
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
Name | Type |
---|---|
editor | LexicalEditor |
Returns
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:788
exportJSON
▸ exportJSON(): SerializedElementNode
<SerializedLexicalNode
>
Controls how the this node is serialized to JSON. This is important for copy and paste between Lexical editors sharing the same namespace. It's also important if you're serializing to JSON for persistent storage somewhere. See Serialization & Deserialization.
Returns
SerializedElementNode
<SerializedLexicalNode
>
Inherited from
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:516
extractWithChild
▸ extractWithChild(child
, selection
, destination
): boolean
Parameters
Name | Type |
---|---|
child | LexicalNode |
selection | null | BaseSelection |
destination | "clone" | "html" |
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:578
getAllTextNodes
▸ getAllTextNodes(): TextNode
[]
Returns
TextNode
[]
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:147
getChildAtIndex
▸ getChildAtIndex<T
>(index
): null
| T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Parameters
Name | Type |
---|---|
index | number |
Returns
null
| T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:228
getChildren
▸ getChildren<T
>(): T
[]
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
T
[]
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:112
getChildrenKeys
▸ getChildrenKeys(): string
[]
Returns
string
[]
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:121
getChildrenSize
▸ getChildrenSize(): number
Returns
number
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:130
getCommonAncestor
▸ getCommonAncestor<T
>(node
): null
| T
Returns the closest common ancestor of this node and the provided one or null if one cannot be found.
Type parameters
Name | Type |
---|---|
T | extends ElementNode = ElementNode |
Parameters
Name | Type | Description |
---|---|---|
node | LexicalNode | the other node to find the common ancestor of. |
Returns
null
| T
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:497
getDescendantByIndex
▸ getDescendantByIndex<T
>(index
): null
| T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Parameters
Name | Type |
---|---|
index | number |
Returns
null
| T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:184
getDirection
▸ getDirection(): null
| "ltr"
| "rtl"
Returns
null
| "ltr"
| "rtl"
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:289
getFirstChild
▸ getFirstChild<T
>(): null
| T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
null
| T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:204
getFirstChildOrThrow
▸ getFirstChildOrThrow<T
>(): T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:209
getFirstDescendant
▸ getFirstDescendant<T
>(): null
| T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
null
| T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:162
getFormat
▸ getFormat(): number
Returns
number
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:96
getFormatType
▸ getFormatType(): ElementFormatType
Returns
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:100
getIndent
▸ getIndent(): number
Returns
number
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:108
getIndexWithinParent
▸ getIndexWithinParent(): number
Returns the zero-based index of this node within the parent.
Returns
number
Inherited from
LexicalNode.getIndexWithinParent
Defined in
packages/lexical/src/LexicalNode.ts:325
getKey
▸ getKey(): string
Returns this nodes key.
Returns
string
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:317
getLastChild
▸ getLastChild<T
>(): null
| T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
null
| T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:216
getLastChildOrThrow
▸ getLastChildOrThrow<T
>(): T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:221
getLastDescendant
▸ getLastDescendant<T
>(): null
| T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
null
| T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:173
getLatest
▸ getLatest(): this
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
Defined in
packages/lexical/src/LexicalNode.ts:683
getNextSibling
▸ getNextSibling<T
>(): null
| T
Returns the "next" siblings - that is, the node that comes after this one in the same parent
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
null
| T
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:470
getNextSiblings
▸ getNextSiblings<T
>(): T
[]
Returns all "next" siblings - that is, the nodes that come between this one and the last child of it's parent, inclusive.
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
T
[]
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:481
getNodesBetween
▸ getNodesBetween(targetNode
): LexicalNode
[]
Returns a list of nodes that are between this node and the target node in the EditorState.
Parameters
Name | Type | Description |
---|---|---|
targetNode | LexicalNode | the node that marks the other end of the range of nodes to be returned. |
Returns
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:602
getParent
▸ getParent<T
>(): null
| T
Returns the parent of this node, or null if none is found.
Type parameters
Name | Type |
---|---|
T | extends ElementNode |
Returns
null
| T
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:345
getParentKeys
▸ getParentKeys(): string
[]
Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.
Returns
string
[]
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:422
getParentOrThrow
▸ getParentOrThrow<T
>(): T
Returns the parent of this node, or throws if none is found.
Type parameters
Name | Type |
---|---|
T | extends ElementNode |
Returns
T
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:356
getParents
▸ getParents(): ElementNode
[]
Returns a list of the every ancestor of this node, all the way up to the RootNode.
Returns
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:407
getPreviousSibling
▸ getPreviousSibling<T
>(): null
| T
Returns the "previous" siblings - that is, the node that comes before this one in the same parent.
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
null
| T
Inherited from
LexicalNode.getPreviousSibling
Defined in
packages/lexical/src/LexicalNode.ts:437
getPreviousSiblings
▸ getPreviousSiblings<T
>(): T
[]
Returns the "previous" siblings - that is, the nodes that come between this one and the first child of it's parent, inclusive.
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
T
[]
Inherited from
LexicalNode.getPreviousSiblings
Defined in
packages/lexical/src/LexicalNode.ts:448
getStyle
▸ getStyle(): string
Returns
string
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:104
getTextContent
▸ getTextContent(): string
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
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:255
getTextContentSize
▸ getTextContentSize(): number
Returns the length of the string produced by calling getTextContent on this node.
Returns
number
Inherited from
LexicalNode.getTextContentSize
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:272
getTopLevelElement
▸ getTopLevelElement(): null
| ElementNode
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
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:62
getTopLevelElementOrThrow
▸ getTopLevelElementOrThrow(): ElementNode
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
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:63
getType
▸ getType(): string
Returns the string type of this node.
Returns
string
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:230
getWritable
▸ getWritable(): this
Returns a mutable version of the node. Will throw an error if called outside of a Lexical Editor LexicalEditor.update callback.
Returns
this
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:699
hasFormat
▸ hasFormat(type
): boolean
Parameters
Name | Type |
---|---|
type | ElementFormatType |
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:293
insertAfter
▸ insertAfter(nodeToInsert
, restoreSelection?
): LexicalNode
Inserts a node after this LexicalNode (as the next sibling).
Parameters
Name | Type | Default value | Description |
---|---|---|---|
nodeToInsert | LexicalNode | undefined | 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
Defined in
packages/lexical/src/LexicalNode.ts:922
insertBefore
▸ insertBefore(nodeToInsert
, restoreSelection?
): LexicalNode
Inserts a node before this LexicalNode (as the previous sibling).
Parameters
Name | Type | Default value | Description |
---|---|---|---|
nodeToInsert | LexicalNode | undefined | 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
Defined in
packages/lexical/src/LexicalNode.ts:989
insertNewAfter
▸ insertNewAfter(selection
, restoreSelection?
): null
| LexicalNode
Parameters
Name | Type |
---|---|
selection | RangeSelection |
restoreSelection? | boolean |
Returns
null
| LexicalNode
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:527
is
▸ is(object
): boolean
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
Name | Type | Description |
---|---|---|
object | undefined | null | LexicalNode | the node to perform the equality comparison on. |
Returns
boolean
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:529
isAttached
▸ isAttached(): boolean
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 ultimatelt be cleaned up by the Lexical GC.
Returns
boolean
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:247
isBefore
▸ isBefore(targetNode
): boolean
Returns true if this node logical precedes the target node in the editor state.
Parameters
Name | Type | Description |
---|---|---|
targetNode | LexicalNode | the node we're testing to see if it's after this one. |
Returns
boolean
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:541
isDirty
▸ isDirty(): boolean
Returns true if this node has been marked dirty during this update cycle.
Returns
boolean
Inherited from
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:137
isEmpty
▸ isEmpty(): boolean
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:134
isInline
▸ isInline(): boolean
Returns
boolean
Inherited from
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:564
isLastChild
▸ isLastChild(): boolean
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:142
isParentOf
▸ isParentOf(targetNode
): boolean
Returns true if this node is the parent of the target node, false otherwise.
Parameters
Name | Type | Description |
---|---|---|
targetNode | LexicalNode | the would-be child node. |
Returns
boolean
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:580
isParentRequired
▸ isParentRequired(): boolean
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
Defined in
packages/lexical/src/LexicalNode.ts:1029
isSelected
▸ isSelected(selection?
): boolean
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
Name | Type | Description |
---|---|---|
selection? | null | BaseSelection | The selection that we want to determine if the node is in. |
Returns
boolean
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:271
isShadowRoot
▸ isShadowRoot(): boolean
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:571
markDirty
▸ markDirty(): void
Marks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.
Returns
void
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:1098
remove
▸ remove(preserveEmptyParent?
): void
Removes this LexicalNode from the EditorState. If the node isn't re-inserted somewhere, the Lexical garbage collector will eventually clean it up.
Parameters
Name | Type | Description |
---|---|---|
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
Defined in
packages/lexical/src/LexicalNode.ts:841
replace
▸ replace<N
>(replaceWith
, includeChildren?
): N
Replaces this LexicalNode with the provided node, optionally transferring the children of the replaced node to the replacing node.
Type parameters
Name | Type |
---|---|
N | extends LexicalNode |
Parameters
Name | Type | Description |
---|---|---|
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
Defined in
packages/lexical/src/LexicalNode.ts:852
select
▸ select(_anchorOffset?
, _focusOffset?
): RangeSelection
Parameters
Name | Type |
---|---|
_anchorOffset? | number |
_focusOffset? | number |
Returns
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:303
selectEnd
▸ selectEnd(): RangeSelection
Returns
Inherited from
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:352
selectNext
▸ selectNext(anchorOffset?
, focusOffset?
): RangeSelection
Moves selection to the next sibling of this node, at the specified offsets.
Parameters
Name | Type | Description |
---|---|---|
anchorOffset? | number | The anchor offset for selection. |
focusOffset? | number | The focus offset for selection |
Returns
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:1077
selectPrevious
▸ selectPrevious(anchorOffset?
, focusOffset?
): RangeSelection
Moves selection to the previous sibling of this node, at the specified offsets.
Parameters
Name | Type | Description |
---|---|---|
anchorOffset? | number | The anchor offset for selection. |
focusOffset? | number | The focus offset for selection |
Returns
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:1055
selectStart
▸ selectStart(): RangeSelection
Returns
Inherited from
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:348
setDirection
▸ setDirection(direction
): this
Parameters
Name | Type |
---|---|
direction | null | "ltr" | "rtl" |
Returns
this
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:365
setFormat
▸ setFormat(type
): this
Parameters
Name | Type |
---|---|
type | ElementFormatType |
Returns
this
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:370
setIndent
▸ setIndent(indentLevel
): this
Parameters
Name | Type |
---|---|
indentLevel | number |
Returns
this
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:380
setStyle
▸ setStyle(style
): this
Parameters
Name | Type |
---|---|
style | string |
Returns
this
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:375
splice
▸ splice(start
, deleteCount
, nodesToInsert
): this
Parameters
Name | Type |
---|---|
start | number |
deleteCount | number |
nodesToInsert | LexicalNode [] |
Returns
this
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:385
updateDOM
▸ updateDOM(_prevNode
, _dom
, _config
): boolean
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
Name | Type |
---|---|
_prevNode | unknown |
_dom | HTMLElement |
_config | EditorConfig |
Returns
boolean
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:772
clone
▸ clone(_data
): LexicalNode
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
Name | Type |
---|---|
_data | unknown |
Returns
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:200
getType
▸ getType(): string
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
Defined in
packages/lexical/src/LexicalNode.ts:186
importJSON
▸ importJSON(_serializedNode
): LexicalNode
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
Name | Type |
---|---|
_serializedNode | SerializedLexicalNode |
Returns
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:811
transform
▸ transform(): null
| (node
: LexicalNode
) => void
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
: LexicalNode
) => void