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:151
Properties
constructor
• constructor: KlassConstructor
<typeof ElementNode
>
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:135
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:278
Methods
afterCloneFrom
▸ afterCloneFrom(prevNode
): void
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
Name | Type |
---|---|
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
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:170
append
▸ append(...nodesToAppend
): this
Parameters
Name | Type |
---|---|
...nodesToAppend | LexicalNode [] |
Returns
this
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:447
canBeEmpty
▸ canBeEmpty(): boolean
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:662
canIndent
▸ canIndent(): boolean
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:640
canInsertTextAfter
▸ canInsertTextAfter(): boolean
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:668
canInsertTextBefore
▸ canInsertTextBefore(): boolean
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:665
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:706
clear
▸ clear(): this
Returns
this
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:441
collapseAtStart
▸ collapseAtStart(selection
): boolean
Parameters
Name | Type |
---|---|
selection | RangeSelection |
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:648
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:828
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:1107
excludeFromCopy
▸ excludeFromCopy(destination?
): boolean
Parameters
Name | Type |
---|---|
destination? | "clone" | "html" |
Returns
boolean
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:651
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/nodes/LexicalElementNode.ts:604
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:623
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:685
getAllTextNodes
▸ getAllTextNodes(): TextNode
[]
Returns
TextNode
[]
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:232
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:313
getChildren
▸ getChildren<T
>(): T
[]
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
T
[]
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:197
getChildrenKeys
▸ getChildrenKeys(): string
[]
Returns
string
[]
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:206
getChildrenSize
▸ getChildrenSize(): number
Returns
number
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:215
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:566
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:269
getDirection
▸ getDirection(): null
| "ltr"
| "rtl"
Returns
null
| "ltr"
| "rtl"
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:374
getFirstChild
▸ getFirstChild<T
>(): null
| T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
null
| T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:289
getFirstChildOrThrow
▸ getFirstChildOrThrow<T
>(): T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:294
getFirstDescendant
▸ getFirstDescendant<T
>(): null
| T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
null
| T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:247
getFormat
▸ getFormat(): number
Returns
number
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:181
getFormatType
▸ getFormatType(): ElementFormatType
Returns
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:185
getIndent
▸ getIndent(): number
Returns
number
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:193
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:394
getKey
▸ getKey(): string
Returns this nodes key.
Returns
string
Inherited from
Defined in
packages/lexical/src/LexicalNode.ts:386
getLastChild
▸ getLastChild<T
>(): null
| T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
null
| T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:301
getLastChildOrThrow
▸ getLastChildOrThrow<T
>(): T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:306
getLastDescendant
▸ getLastDescendant<T
>(): null
| T
Type parameters
Name | Type |
---|---|
T | extends LexicalNode |
Returns
null
| T
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:258
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:752
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:539
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:550
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:671
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:414
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:491
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:425
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:476
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:506
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:517
getStyle
▸ getStyle(): string
Returns
string
Defined in
packages/lexical/src/nodes/LexicalElementNode.ts:189
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:340
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:357
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:68
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".