Class: TextNode
lexical.TextNode
Hierarchy
↳
TextNode
↳↳
TabNode
↳↳
HashtagNode
Constructors
constructor
• new TextNode(text
, key?
)
Parameters
Name | Type |
---|---|
text | string |
key? | string |
Overrides
Defined in
lexical/src/nodes/LexicalTextNode.ts:295
Properties
__text
• __text: string
Defined in
lexical/src/nodes/LexicalTextNode.ts:277
Methods
canInsertTextAfter
▸ canInsertTextAfter(): boolean
This method is meant to be overriden by TextNode subclasses to control the behavior of those nodes when a user event would cause text to be inserted after them in the editor. If true, Lexical will attempt to insert text into this node. If false, it will insert the text in a new sibling node.
Returns
boolean
true if text can be inserted after the node, false otherwise.
Defined in
lexical/src/nodes/LexicalTextNode.ts:878
canInsertTextBefore
▸ canInsertTextBefore(): boolean
This method is meant to be overriden by TextNode subclasses to control the behavior of those nodes when a user event would cause text to be inserted before them in the editor. If true, Lexical will attempt to insert text into this node. If false, it will insert the text in a new sibling node.
Returns
boolean
true if text can be inserted before the node, false otherwise.
Defined in
lexical/src/nodes/LexicalTextNode.ts:867
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
Name | Type | Description |
---|---|---|
config | EditorConfig | allows access to things like the EditorTheme (to apply classes) during reconciliation. |
Returns
HTMLElement
Overrides
Defined in
lexical/src/nodes/LexicalTextNode.ts:443
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
Overrides
Defined in
lexical/src/nodes/LexicalTextNode.ts:594
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
Overrides
Defined in
lexical/src/nodes/LexicalTextNode.ts:622
getDetail
▸ getDetail(): number
Returns a 32-bit integer that represents the TextDetailTypes currently applied to the TextNode. You probably don't want to use this method directly - consider using TextNode.isDirectionless or TextNode.isUnmergeable instead.
Returns
number
a number representing the detail of the text node.
Defined in
lexical/src/nodes/LexicalTextNode.ts:322
getFormat
▸ getFormat(): number
Returns a 32-bit integer that represents the TextFormatTypes currently applied to the TextNode. You probably don't want to use this method directly - consider using TextNode.hasFormat instead.
Returns
number
a number representing the format of the text node.
Defined in
lexical/src/nodes/LexicalTextNode.ts:310
getFormatFlags
▸ getFormatFlags(type
, alignWithFormat
): number
Returns the format flags applied to the node as a 32-bit integer.
Parameters
Name | Type |
---|---|
type | TextFormatType |
alignWithFormat | null | number |
Returns
number
a number representing the TextFormatTypes applied to the node.
Defined in
lexical/src/nodes/LexicalTextNode.ts:435
getMode
▸ getMode(): TextModeType
Returns the mode (TextModeType) of the TextNode, which may be "normal", "token", or "segmented"
Returns
TextModeType.
Defined in
lexical/src/nodes/LexicalTextNode.ts:332
getStyle
▸ getStyle(): string
Returns the styles currently applied to the node. This is analogous to CSSText in the DOM.
Returns
string
CSSText-like string of styles applied to the underlying DOM node.
Defined in
lexical/src/nodes/LexicalTextNode.ts:342
getTextContent
▸ getTextContent(): string
Returns the text content of the node as a string.
Returns
string
a string representing the text content of the node.
Overrides
Defined in
lexical/src/nodes/LexicalTextNode.ts:425
hasFormat
▸ hasFormat(type
): boolean
Returns whether or not the node has the provided format applied. Use this with the human-readable TextFormatType string values to get the format of a TextNode.
Parameters
Name | Type | Description |
---|---|---|
type | TextFormatType | the TextFormatType to check for. |
Returns
boolean
true if the node has the provided format, false otherwise.
Defined in
lexical/src/nodes/LexicalTextNode.ts:405
isComposing
▸ isComposing(): boolean
Returns
boolean
true if Lexical detects that an IME or other 3rd-party script is attempting to mutate the TextNode, false otherwise.
Defined in
lexical/src/nodes/LexicalTextNode.ts:363
isDirectionless
▸ isDirectionless(): boolean
Returns whether or not the node is "directionless". Directionless nodes don't respect changes between RTL and LTR modes.
Returns
boolean
true if the node is directionless, false otherwise.
Defined in
lexical/src/nodes/LexicalTextNode.ts:382
isSegmented
▸ isSegmented(): boolean
Returns whether or not the node is in "segemented" mode. TextNodes in segemented mode can be navigated through character-by-character with a RangeSelection, but are deleted in space-delimited "segments".
Returns
boolean
true if the node is in segmented mode, false otherwise.
Defined in
lexical/src/nodes/LexicalTextNode.ts:373
isSimpleText
▸ isSimpleText(): boolean
Returns whether or not the node is simple text. Simple text is defined as a TextNode that has the string type "text" (i.e., not a subclass) and has no mode applied to it (i.e., not segmented or token).
Returns
boolean
true if the node is simple text, false otherwise.
Defined in
lexical/src/nodes/LexicalTextNode.ts:416
isTextEntity
▸ isTextEntity(): boolean
This method is meant to be overriden by TextNode subclasses to control the behavior of those nodes when used with the registerLexicalTextEntity function. If you're using registerLexicalTextEntity, the node class that you create and replace matched text with should return true from this method.
Returns
boolean
true if the node is to be treated as a "text entity", false otherwise.
Defined in
lexical/src/nodes/LexicalTextNode.ts:1073
isToken
▸ isToken(): boolean
Returns whether or not the node is in "token" mode. TextNodes in token mode can be navigated through character-by-character with a RangeSelection, but are deleted as a single entity (not invdividually by character).
Returns
boolean
true if the node is in token mode, false otherwise.
Defined in
lexical/src/nodes/LexicalTextNode.ts:353
isUnmergeable
▸ isUnmergeable(): boolean
Returns whether or not the node is unmergeable. In some scenarios, Lexical tries to merge adjacent TextNodes into a single TextNode. If a TextNode is unmergeable, this won't happen.
Returns
boolean
true if the node is unmergeable, false otherwise.
Defined in
lexical/src/nodes/LexicalTextNode.ts:392
mergeWithSibling
▸ mergeWithSibling(target
): TextNode
Merges the target TextNode into this TextNode, removing the target node.
Parameters
Name | Type | Description |
---|---|---|
target | TextNode | the TextNode to merge into this one. |
Returns
this TextNode.
Defined in
lexical/src/nodes/LexicalTextNode.ts:1016
select
▸ select(_anchorOffset?
, _focusOffset?
): RangeSelection
Sets the current Lexical selection to be a RangeSelection with anchor and focus on this TextNode at the provided offsets.
Parameters
Name | Type | Description |
---|---|---|
_anchorOffset? | number | the offset at which the Selection anchor will be placed. |
_focusOffset? | number | the offset at which the Selection focus will be placed. |
Returns
the new RangeSelection.
Defined in
lexical/src/nodes/LexicalTextNode.ts:765
selectEnd
▸ selectEnd(): RangeSelection
Returns
Overrides
Defined in
lexical/src/nodes/LexicalTextNode.ts:810
selectStart
▸ selectStart(): RangeSelection
Returns
Overrides
Defined in
lexical/src/nodes/LexicalTextNode.ts:806
selectionTransform
▸ selectionTransform(prevSelection
, nextSelection
): void
Parameters
Name | Type |
---|---|
prevSelection | null | BaseSelection |
nextSelection | RangeSelection |
Returns
void
Defined in
lexical/src/nodes/LexicalTextNode.ts:635
setDetail
▸ setDetail(detail
): TextNode
Sets the node detail to the provided TextDetailType or 32-bit integer. Note that the TextDetailType version of the argument can only specify one detail value and doing so will remove all other detail values that may be applied to the node. For toggling behavior, consider using toggleDirectionless or TextNode.togglerUnmergeable
Parameters
Name | Type | Description |
---|---|---|
detail | number | TextDetailType | TextDetailType or 32-bit integer representing the node detail. |
Returns
this TextNode.
// TODO 0.12 This should just be a string
.
Defined in
lexical/src/nodes/LexicalTextNode.ts:670
setFormat
▸ setFormat(format
): TextNode
Sets the node format to the provided TextFormatType or 32-bit integer. Note that the TextFormatType version of the argument can only specify one format and doing so will remove all other formats that may be applied to the node. For toggling behavior, consider using toggleFormat
Parameters
Name | Type | Description |
---|---|---|
format | number | TextFormatType | TextFormatType or 32-bit integer representing the node format. |
Returns
this TextNode.
// TODO 0.12 This should just be a string
.
Defined in
lexical/src/nodes/LexicalTextNode.ts:652
setMode
▸ setMode(type
): TextNode
Sets the mode of the node.
Parameters
Name | Type |
---|---|
type | TextModeType |
Returns
this TextNode.
Defined in
lexical/src/nodes/LexicalTextNode.ts:731
setStyle
▸ setStyle(style
): TextNode
Sets the node style to the provided CSSText-like string. Set this property as you would an HTMLElement style attribute to apply inline styles to the underlying DOM Element.
Parameters
Name | Type | Description |
---|---|---|
style | string | CSSText to be applied to the underlying HTMLElement. |
Returns
this TextNode.
Defined in
lexical/src/nodes/LexicalTextNode.ts:685
setTextContent
▸ setTextContent(text
): TextNode
Sets the text content of the node.
Parameters
Name | Type | Description |
---|---|---|
text | string | the string to set as the text value of the node. |
Returns
this TextNode.
Defined in
lexical/src/nodes/LexicalTextNode.ts:748
spliceText
▸ spliceText(offset
, delCount
, newText
, moveSelection?
): TextNode
Inserts the provided text into this TextNode at the provided offset, deleting the number of characters specified. Can optionally calculate a new selection after the operation is complete.
Parameters
Name | Type | Description |
---|---|---|
offset | number | the offset at which the splice operation should begin. |
delCount | number | the number of characters to delete, starting from the offset. |
newText | string | the text to insert into the TextNode at the offset. |
moveSelection? | boolean | optional, whether or not to move selection to the end of the inserted substring. |
Returns
this TextNode.
Defined in
lexical/src/nodes/LexicalTextNode.ts:826
splitText
▸ splitText(...splitOffsets
): TextNode
[]
Splits this TextNode at the provided character offsets, forming new TextNodes from the substrings formed by the split, and inserting those new TextNodes into the editor, replacing the one that was split.
Parameters
Name | Type | Description |
---|---|---|
...splitOffsets | number [] | rest param of the text content character offsets at which this node should be split. |
Returns
TextNode
[]
an Array containing the newly-created TextNodes.
Defined in
lexical/src/nodes/LexicalTextNode.ts:890
toggleDirectionless
▸ toggleDirectionless(): TextNode
Toggles the directionless detail value of the node. Prefer using this method over setDetail.
Returns
this TextNode.
Defined in
lexical/src/nodes/LexicalTextNode.ts:709
toggleFormat
▸ toggleFormat(type
): TextNode
Applies the provided format to this TextNode if it's not present. Removes it if it is present. Prefer using this method to turn specific formats on and off.
Parameters
Name | Type | Description |
---|---|---|
type | TextFormatType | TextFormatType to toggle. |
Returns
this TextNode.
Defined in
lexical/src/nodes/LexicalTextNode.ts:699
toggleUnmergeable
▸ toggleUnmergeable(): TextNode
Toggles the unmergeable detail value of the node. Prefer using this method over setDetail.
Returns
this TextNode.
Defined in
lexical/src/nodes/LexicalTextNode.ts:720
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
Name | Type |
---|---|
prevNode | TextNode |
dom | HTMLElement |
config | EditorConfig |
Returns
boolean
Overrides
Defined in
lexical/src/nodes/LexicalTextNode.ts:466
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
Name | Type |
---|---|
node | TextNode |
Returns
Overrides
Defined in
lexical/src/nodes/LexicalTextNode.ts:291
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
Defined in
lexical/src/nodes/LexicalTextNode.ts:287
importDOM
▸ Static
importDOM(): null
| DOMConversionMap
Returns
null
| DOMConversionMap
Defined in
lexical/src/nodes/LexicalTextNode.ts:533
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
Name | Type |
---|---|
serializedNode | SerializedTextNode |
Returns
Overrides
Defined in
lexical/src/nodes/LexicalTextNode.ts:582