Skip to main content

Class: TextNode

lexical.TextNode

Hierarchy

Constructors

constructor

new TextNode(text, key?)

Parameters

NameType
textstring
key?string

Overrides

LexicalNode.constructor

Defined in

lexical/src/nodes/LexicalTextNode.ts:293

Properties

__text

__text: string

Defined in

lexical/src/nodes/LexicalTextNode.ts:275

Methods

canInsertTextAfter

canInsertTextAfter(): boolean

Returns

boolean

Defined in

lexical/src/nodes/LexicalTextNode.ts:703


canInsertTextBefore

canInsertTextBefore(): boolean

Returns

boolean

Defined in

lexical/src/nodes/LexicalTextNode.ts:699


createDOM

createDOM(config): 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

NameTypeDescription
configEditorConfigallows access to things like the EditorTheme (to apply classes) during reconciliation.

Returns

HTMLElement

Overrides

LexicalNode.createDOM

Defined in

lexical/src/nodes/LexicalTextNode.ts:368


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

NameType
editorLexicalEditor

Returns

DOMExportOutput

Overrides

LexicalNode.exportDOM

Defined in

lexical/src/nodes/LexicalTextNode.ts:520


exportJSON

exportJSON(): SerializedTextNode

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

SerializedTextNode

Overrides

LexicalNode.exportJSON

Defined in

lexical/src/nodes/LexicalTextNode.ts:546


getDetail

getDetail(): number

Returns

number

Defined in

lexical/src/nodes/LexicalTextNode.ts:307


getFormat

getFormat(): number

Returns

number

Defined in

lexical/src/nodes/LexicalTextNode.ts:302


getFormatFlags

getFormatFlags(type, alignWithFormat): number

Parameters

NameType
typeTextFormatType
alignWithFormatnull | number

Returns

number

Defined in

lexical/src/nodes/LexicalTextNode.ts:360


getMode

getMode(): TextModeType

Returns

TextModeType

Defined in

lexical/src/nodes/LexicalTextNode.ts:312


getStyle

getStyle(): string

Returns

string

Defined in

lexical/src/nodes/LexicalTextNode.ts:317


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

Overrides

LexicalNode.getTextContent

Defined in

lexical/src/nodes/LexicalTextNode.ts:355


hasFormat

hasFormat(type): boolean

Parameters

NameType
typeTextFormatType

Returns

boolean

Defined in

lexical/src/nodes/LexicalTextNode.ts:346


isComposing

isComposing(): boolean

Returns

boolean

Defined in

lexical/src/nodes/LexicalTextNode.ts:327


isDirectionless

isDirectionless(): boolean

Returns

boolean

Defined in

lexical/src/nodes/LexicalTextNode.ts:336


isSegmented

isSegmented(): boolean

Returns

boolean

Defined in

lexical/src/nodes/LexicalTextNode.ts:331


isSimpleText

isSimpleText(): boolean

Returns

boolean

Defined in

lexical/src/nodes/LexicalTextNode.ts:351


isTextEntity

isTextEntity(): boolean

Returns

boolean

Defined in

lexical/src/nodes/LexicalTextNode.ts:876


isToken

isToken(): boolean

Returns

boolean

Defined in

lexical/src/nodes/LexicalTextNode.ts:322


isUnmergeable

isUnmergeable(): boolean

Returns

boolean

Defined in

lexical/src/nodes/LexicalTextNode.ts:341


mergeWithSibling

mergeWithSibling(target): TextNode

Parameters

NameType
targetTextNode

Returns

TextNode

Defined in

lexical/src/nodes/LexicalTextNode.ts:826


select

select(_anchorOffset?, _focusOffset?): RangeSelection

Parameters

NameType
_anchorOffset?number
_focusOffset?number

Returns

RangeSelection

Defined in

lexical/src/nodes/LexicalTextNode.ts:624


selectionTransform

selectionTransform(prevSelection, nextSelection): void

Parameters

NameType
prevSelectionnull | RangeSelection | NodeSelection | GridSelection
nextSelectionRangeSelection

Returns

void

Defined in

lexical/src/nodes/LexicalTextNode.ts:559


setDetail

setDetail(detail): TextNode

Parameters

NameType
detailnumber | TextDetailType

Returns

TextNode

Defined in

lexical/src/nodes/LexicalTextNode.ts:575


setFormat

setFormat(format): TextNode

Parameters

NameType
formatnumber | TextFormatType

Returns

TextNode

Defined in

lexical/src/nodes/LexicalTextNode.ts:567


setMode

setMode(type): TextNode

Parameters

NameType
typeTextModeType

Returns

TextNode

Defined in

lexical/src/nodes/LexicalTextNode.ts:605


setStyle

setStyle(style): TextNode

Parameters

NameType
stylestring

Returns

TextNode

Defined in

lexical/src/nodes/LexicalTextNode.ts:582


setTextContent

setTextContent(text): TextNode

Parameters

NameType
textstring

Returns

TextNode

Defined in

lexical/src/nodes/LexicalTextNode.ts:615


spliceText

spliceText(offset, delCount, newText, moveSelection?): TextNode

Parameters

NameType
offsetnumber
delCountnumber
newTextstring
moveSelection?boolean

Returns

TextNode

Defined in

lexical/src/nodes/LexicalTextNode.ts:665


splitText

splitText(...splitOffsets): TextNode[]

Parameters

NameType
...splitOffsetsnumber[]

Returns

TextNode[]

Defined in

lexical/src/nodes/LexicalTextNode.ts:707


toggleDirectionless

toggleDirectionless(): TextNode

Returns

TextNode

Defined in

lexical/src/nodes/LexicalTextNode.ts:593


toggleFormat

toggleFormat(type): TextNode

Parameters

NameType
typeTextFormatType

Returns

TextNode

Defined in

lexical/src/nodes/LexicalTextNode.ts:588


toggleUnmergeable

toggleUnmergeable(): TextNode

Returns

TextNode

Defined in

lexical/src/nodes/LexicalTextNode.ts:599


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

NameType
prevNodeTextNode
domHTMLElement
configEditorConfig

Returns

boolean

Overrides

LexicalNode.updateDOM

Defined in

lexical/src/nodes/LexicalTextNode.ts:388


clone

Static clone(node): TextNode

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

NameType
nodeTextNode

Returns

TextNode

Overrides

LexicalNode.clone

Defined in

lexical/src/nodes/LexicalTextNode.ts:289


getType

Static 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

Overrides

LexicalNode.getType

Defined in

lexical/src/nodes/LexicalTextNode.ts:285


importDOM

Static importDOM(): null | DOMConversionMap<HTMLElement>

Returns

null | DOMConversionMap<HTMLElement>

Defined in

lexical/src/nodes/LexicalTextNode.ts:455


importJSON

Static importJSON(serializedNode): TextNode

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

NameType
serializedNodeSerializedTextNode

Returns

TextNode

Overrides

LexicalNode.importJSON

Defined in

lexical/src/nodes/LexicalTextNode.ts:508