ShadowRootNode
interfaceImport
import { ShadowRootNode } from '@modular/sdk/editor';Members91
- __@ShadowRootNodeBrand@37374
never- $config()
() => import("lexical").BaseStaticNodeConfig & import("lexical").StaticNodeConfigAccessor<{ readonly $transform: typeof $normalizeShadowRootChildren; readonly extends: typeof LexicalNode; readonly generated: import("lexical").GeneratedJSONFactory; readonly json: import("lexical").NodeSerializationSchema<ElementNode, { readonly direction?: "ltr" | "rtl" | null | undefined; readonly format?: "" | "left" | "start" | "center" | "right" | "end" | "justify" | undefined; readonly indent?: string | number | undefined; readonly textFormat?: string | number | undefined; readonly textStyle?: string | undefined; }>; }>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.
- afterCloneFrom()
(prevNode: this) => voidPerform 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.
- append()
(...nodesToAppend: LexicalNode[]) => this- canBeEmpty()
() => boolean- canIndent()
() => boolean- canInsertTextAfter()
() => boolean- canInsertTextBefore()
() => boolean- canMergeWhenEmpty()
() => booleanDetermines 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.
- clear()
() => this- collapseAtStart()
(selection: RangeSelection) => boolean- config()
<const Config extends StaticNodeConfigValue<this, string>>(type: symbol, config: Config) => AbstractStaticNodeConfigRecord<Config> | <Type extends string, const Config extends StaticNodeConfigValue<this, Type>>(type: Type, config: Config) => StaticNodeConfigRecord<Type, Config>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.
- createDOM()
(_config: EditorConfig, _editor: LexicalEditor) => HTMLElementCalled 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.
- createParentElementNode()
() => ElementNodeThe creation logic for any required parent. Should be implemented if isParentRequired returns true.
- excludeFromCopy()
(destination?: 'clone' | 'html') => boolean- exportDOM()
(editor: LexicalEditor) => DOMExportOutputControls 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 @lexical/html!$generateHtmlFromNodes. You could also use this method to build your own HTML renderer.
- exportJSON()
(compact?: false) => SerializedElementNode | (compact: boolean) => SerializedPartial<SerializedElementNode>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](https://lexical.dev/docs/serialization/serialization#json). 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.
- extractWithChild()
(child: LexicalNode, selection: BaseSelection | null, destination: 'clone' | 'html') => boolean- getAllTextNodes()
() => TextNode[]- getChildAtIndex()
(index: number) => null | LexicalNode | <T extends LexicalNode>(index: number) => null | TReturns the child of this node at the given index, or null if the index is out of range.
- getChildren()
() => LexicalNode[] | <T extends LexicalNode>() => T[]Returns the children of this node, in document order.
- getChildrenKeys()
() => NodeKey[]- getChildrenSize()
() => number- getDescendantByIndex()
(index: number) => null | LexicalNode | <T extends LexicalNode>(index: number) => null | TReturns the deepest descendant corresponding to the child at the given index, or null if this node has no children.
- getDirection()
() => 'ltr' | 'rtl' | null- getDOMSlot()
(element: HTMLElement) => ElementDOMSlot<HTMLElement>- getFirstChild()
() => null | LexicalNode | <T extends LexicalNode>() => null | TReturns the first child of this node, or null if it has no children.
- getFirstChildOrThrow()
() => LexicalNode | <T extends LexicalNode>() => TReturns the first child of this node, or throws if it has no children.
- getFirstDescendant()
() => null | LexicalNode | <T extends LexicalNode>() => null | TReturns 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).
- getFormat()
() => number- getFormatFlags()
(type: TextFormatType, alignWithFormat: null | number) => numberReturns the format flags applied to the node as a 32-bit integer.
- getFormatType()
() => ElementFormatType- getIndent()
() => number- getIndexWithinParent()
() => numberReturns the zero-based index of this node within the parent.
- getKey()
() => NodeKeyReturns this nodes key.
- getLastChild()
() => null | LexicalNode | <T extends LexicalNode>() => null | TReturns the last child of this node, or null if it has no children.
- getLastChildOrThrow()
() => LexicalNode | <T extends LexicalNode>() => TReturns the last child of this node, or throws if it has no children.
- getLastDescendant()
() => null | LexicalNode | <T extends LexicalNode>() => null | TReturns the deepest last descendant of this node, or null if it has no children.
- getLatest()
() => thisReturns the latest version of the node from the active EditorState. This is used to avoid getting values from stale node references.
- getNextSibling()
() => LexicalNode | null | <T extends LexicalNode>() => T | nullReturns the node after this one in the same parent, or null if there is no such node.
- getNextSiblings()
() => LexicalNode[] | <T extends LexicalNode>() => T[]Returns all nodes after this one in the same parent, in document order.
- getNodesBetween()
(targetNode: LexicalNode) => LexicalNode[]Returns a list of nodes that are between this node and the target node in the EditorState.
- getParent()
() => ElementNode | null | <T extends ElementNode>() => T | nullReturns the parent of this node, or null if none is found.
- getParentKeys()
() => NodeKey[]Returns a list of the keys of every ancestor of this node, all the way up to the RootNode.
- getParentOrThrow()
() => ElementNode | <T extends ElementNode>() => TReturns the parent of this node, or throws if none is found.
- getParents()
() => ElementNode[]Returns a list of the every ancestor of this node, all the way up to the RootNode.
- getPreviousSibling()
() => LexicalNode | null | <T extends LexicalNode>() => T | nullReturns the node before this one in the same parent, or null if there is no such node.
- getPreviousSiblings()
() => LexicalNode[] | <T extends LexicalNode>() => T[]Returns all nodes before this one in the same parent, in document order.
- getStyle()
() => string- getTextContent()
() => stringReturns 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)
- getTextContentSize()
() => numberReturns the length of the string produced by calling getTextContent on this node.
- getTextFormat()
() => number- getTextStyle()
() => string- getTopLevelElement()
() => ElementNode | nullReturns the highest (in the EditorState tree) non-root ancestor of this node, or null if none is found. See lexical !$isRootOrShadowRoot for more information on which Elements comprise "roots".
- getTopLevelElementOrThrow()
() => ElementNodeReturns the highest (in the EditorState tree) non-root ancestor of this node, or throws if none is found. See lexical !$isRootOrShadowRoot for more information on which Elements comprise "roots".
- getType()
() => stringReturns the string type of this node.
- getWritable()
() => thisReturns a mutable version of the node using $cloneWithProperties if necessary. Will throw an error if called outside of a Lexical Editor LexicalEditor.update callback.
- hasFormat()
(type: ElementFormatType) => boolean- hasTextFormat()
(type: TextFormatType) => boolean- insertAfter()
(nodeToInsert: LexicalNode, restoreSelection?: boolean) => LexicalNodeInserts a node after this LexicalNode (as the next sibling).
- insertBefore()
(nodeToInsert: LexicalNode, restoreSelection?: boolean) => LexicalNodeInserts a node before this LexicalNode (as the previous sibling).
- insertNewAfter()
(selection: RangeSelection, restoreSelection?: boolean) => null | LexicalNode- is()
(object: LexicalNode | null | undefined) => booleanReturns true if the provided node is the exact same one as this node, from Lexical's perspective. Always use this instead of referential equality.
- isAttached()
() => booleanReturns 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.
- isBefore()
(targetNode: LexicalNode) => booleanReturns 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.
- isDirty()
() => booleanReturns true if this node has been marked dirty during this update cycle.
- isEmpty()
() => boolean- isInline()
() => booleanIf the method is overridden and returns true, ensure that `canBeEmpty()` returns false for the inline node to work correctly
- isLastChild()
() => boolean- isParentOf()
(targetNode: LexicalNode) => booleanReturns true if this node is an ancestor of and distinct from the target node, false otherwise.
- isParentRequired()
() => booleanWhether 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.
- isSelected()
(selection?: null | BaseSelection) => booleanReturns 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.
- isShadowRoot()
() => true- markDirty()
() => voidMarks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.
- remove()
(preserveEmptyParent?: boolean) => voidRemoves this LexicalNode from the EditorState. If the node isn't re-inserted somewhere, the Lexical garbage collector will eventually clean it up.
- replace()
<N extends LexicalNode>(replaceWith: N, includeChildren?: boolean) => NReplaces 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.
- resetOnCopyNodeFrom()
(originalNode: this) => voidReset state in this copy of originalNode, if necessary
- select()
(_anchorOffset?: number, _focusOffset?: number) => RangeSelection- selectEnd()
() => RangeSelection- selectNext()
(anchorOffset?: number, focusOffset?: number) => RangeSelectionMoves selection to the next sibling of this node, at the specified offsets.
- selectPrevious()
(anchorOffset?: number, focusOffset?: number) => RangeSelectionMoves selection to the previous sibling of this node, at the specified offsets.
- selectStart()
() => RangeSelection- setDirection()
(direction: 'ltr' | 'rtl' | null) => this- setFormat()
(type: ElementFormatType) => this- setIndent()
(indentLevel: number) => this- setStyle()
(style: string) => this- setTextFormat()
(type: number) => this- setTextStyle()
(style: string) => this- splice()
(start: number, deleteCount: number, nodesToInsert: LexicalNode[]) => this- updateDOM()
(_prevNode: unknown, _dom: HTMLElement, _config: EditorConfig) => booleanCalled 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.
- updateFromJSON()
(serializedNode: LexicalParseJSON<SerializedElementNode>) => thisUpdate 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.