Skip to main content

ParagraphNode

class
class ParagraphNode

Import

import { ParagraphNode } from '@modular/sdk/editor';

Members95

importDOMoptional
() => DOMConversionMap<any> | null
$config()
() => import("../index.js").BaseStaticNodeConfig & import("../index.js").StaticNodeConfigAccessor<{ readonly $transform: (node: ElementNode) => void; readonly extends: typeof LexicalNode; readonly generated: import("../index.js").GeneratedJSONFactory; readonly json: import("../index.js").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; }>; }> & { readonly paragraph?: { readonly extends: typeof ElementNode; readonly generated: import("../index.js").GeneratedJSONFactory; readonly importDOM: { readonly p: () => { conversion: typeof $convertParagraphElement; priority: 0; }; }; } | undefined; } & import("../index.js").StaticNodeTypeAccessor<"paragraph"> & import("../index.js").StaticNodeConfigAccessor<{ readonly extends: typeof ElementNode; readonly generated: import("../index.js").GeneratedJSONFactory; readonly importDOM: { readonly p: () => { conversion: typeof $convertParagraphElement; priority: 0; }; }; }>

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) => 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.

append()
(...nodesToAppend: LexicalNode[]) => this
canBeEmpty()
() => boolean
canIndent()
() => boolean
canInsertTextAfter()
() => boolean
canInsertTextBefore()
() => boolean
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.

clear()
() => this
clone()
(_data: unknown) => 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.

collapseAtStart()
() => 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) => 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 lifecycle.

createParentElementNode()
() => ElementNode

The creation logic for any required parent. Should be implemented if isParentRequired returns true.

excludeFromCopy()
(destination?: 'clone' | 'html') => boolean
exportDOM()
(editor: LexicalEditor) => 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 @lexical/html!$generateHtmlFromNodes. You could also use this method to build your own HTML renderer.

exportJSON()
(compact?: false) => SerializedParagraphNode | (compact: boolean) => SerializedPartial<SerializedParagraphNode>

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 | T

Returns 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 | T

Returns 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 | T

Returns the first child of this node, or null if it has no children.

getFirstChildOrThrow()
() => LexicalNode | <T extends LexicalNode>() => T

Returns the first child of this node, or throws if it has no children.

getFirstDescendant()
() => null | LexicalNode | <T extends LexicalNode>() => null | T

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).

getFormat()
() => number
getFormatFlags()
(type: TextFormatType, alignWithFormat: null | number) => number

Returns the format flags applied to the node as a 32-bit integer.

getFormatType()
() => ElementFormatType
getIndent()
() => number
getIndexWithinParent()
() => number

Returns the zero-based index of this node within the parent.

getKey()
() => NodeKey

Returns this nodes key.

getLastChild()
() => null | LexicalNode | <T extends LexicalNode>() => null | T

Returns the last child of this node, or null if it has no children.

getLastChildOrThrow()
() => LexicalNode | <T extends LexicalNode>() => T

Returns the last child of this node, or throws if it has no children.

getLastDescendant()
() => null | LexicalNode | <T extends LexicalNode>() => null | T

Returns the deepest last descendant of this node, or null if it has no children.

getLatest()
() => this

Returns 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 | null

Returns 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 | null

Returns 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>() => T

Returns 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 | null

Returns 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()
() => 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)

getTextContentSize()
() => number

Returns the length of the string produced by calling getTextContent on this node.

getTextFormat()
() => number
getTextStyle()
() => string
getTopLevelElement()
() => ElementNode | null

Returns 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

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()
() => string

Returns the string type of this node.

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.

getWritable()
() => this

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.

hasFormat()
(type: ElementFormatType) => boolean
hasTextFormat()
(type: TextFormatType) => boolean
importJSON()
(_serializedNode: SerializedPartial<SerializedLexicalNode> & Record<string, unknown>) => 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](https://lexical.dev/docs/serialization/serialization#json).

insertAfter()
(nodeToInsert: LexicalNode, restoreSelection?: boolean) => LexicalNode

Inserts a node after this LexicalNode (as the next sibling).

insertBefore()
(nodeToInsert: LexicalNode, restoreSelection?: boolean) => LexicalNode

Inserts a node before this LexicalNode (as the previous sibling).

insertNewAfter()
(rangeSelection: RangeSelection, restoreSelection: boolean) => ParagraphNode
is()
(object: LexicalNode | null | undefined) => 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.

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 ultimately be cleaned up by the Lexical GC.

isBefore()
(targetNode: LexicalNode) => boolean

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.

isDirty()
() => boolean

Returns true if this node has been marked dirty during this update cycle.

isEmpty()
() => boolean
isInline()
() => boolean

If the method is overridden and returns true, ensure that `canBeEmpty()` returns false for the inline node to work correctly

isLastChild()
() => boolean
isParentOf()
(targetNode: LexicalNode) => boolean

Returns true if this node is an ancestor of and distinct from the target node, false otherwise.

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.

isSelected()
(selection?: null | BaseSelection) => 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.

isShadowRoot()
() => boolean
markDirty()
() => void

Marks a node dirty, triggering transforms and forcing it to be reconciled during the update cycle.

remove()
(preserveEmptyParent?: boolean) => void

Removes 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) => N

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.

resetOnCopyNodeFrom()
(originalNode: this) => void

Reset state in this copy of originalNode, if necessary

select()
(_anchorOffset?: number, _focusOffset?: number) => RangeSelection
selectEnd()
() => RangeSelection
selectNext()
(anchorOffset?: number, focusOffset?: number) => RangeSelection

Moves selection to the next sibling of this node, at the specified offsets.

selectPrevious()
(anchorOffset?: number, focusOffset?: number) => RangeSelection

Moves 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
transform()
() => ((node: LexicalNode) => void) | null
updateDOM()
(prevNode: ParagraphNode, dom: HTMLElement, config: EditorConfig) => 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.

updateFromJSON()
(serializedNode: LexicalParseJSON<SerializedElementNode>) => this

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.

Notes

noInheritDoc