LineBreakNode
classImport
import { LineBreakNode } from '@modular/sdk/editor';Members51
- importDOMoptional
() => DOMConversionMap<any> | null- $config()
() => import("../index.js").BaseStaticNodeConfig & { readonly linebreak?: { readonly extends: typeof LexicalNode; readonly generated: import("../index.js").GeneratedJSONFactory; readonly importDOM: { readonly br: (node: Node) => { conversion: typeof $convertLineBreakElement; priority: 0; } | null; }; } | undefined; } & import("../index.js").StaticNodeTypeAccessor<"linebreak"> & import("../index.js").StaticNodeConfigAccessor<{ readonly extends: typeof LexicalNode; readonly generated: import("../index.js").GeneratedJSONFactory; readonly importDOM: { readonly br: (node: Node) => { conversion: typeof $convertLineBreakElement; priority: 0; } | null; }; }>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.
- clone()
(_data: unknown) => LexicalNodeClones 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.
- 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()
() => 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.
- 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) => SerializedLexicalNode | (compact: boolean) => SerializedPartial<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](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. 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.
- getDOMSlot()
(element: HTMLElement) => DOMSlot<HTMLElement>Returns a DOMSlot pointing at the content-bearing element of this node's DOM. The default returns a slot wrapping the keyed DOM as-is. Override this when createDOM returns a wrapper around the content-bearing element (e.g. `<span><br/></span>` for a styled line break), so selection / reconciliation logic can target the inner element. ElementNode overrides this to return an ElementDOMSlot with children-management semantics (used by the reconciler to place managed children).
- getIndexWithinParent()
() => numberReturns the zero-based index of this node within the parent.
- getKey()
() => NodeKeyReturns this nodes key.
- 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.
- getTextContent()
() => '\n'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)
- getTextContentSize()
() => numberReturns the length of the string produced by calling getTextContent on this node.
- getTopLevelElement()
() => ElementNode | DecoratorNode<unknown> | 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()
() => ElementNode | DecoratorNode<unknown>Returns 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.
- getType()
() => stringReturns the string type of this node. Every node must implement this and it MUST BE UNIQUE amongst nodes registered on the editor.
- 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.
- importJSON()
(_serializedNode: SerializedPartial<SerializedLexicalNode> & Record<string, unknown>) => LexicalNodeControls 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](https://lexical.dev/docs/serialization/serialization#json).
- 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).
- 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.
- isInline()
() => true- 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.
- 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
- 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- transform()
() => ((node: LexicalNode) => void) | null- updateDOM()
() => falseCalled 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<SerializedLexicalNode>) => 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.
Notes
- noInheritDoc