Class: TextNode
lexical.TextNode
Hierarchy
-
↳
TextNode
↳↳
TabNode
↳↳
HashtagNode
Constructors
constructor
• new TextNode(text
, key?
): TextNode
Parameters
Name | Type |
---|---|
text | string |
key? | string |
Returns
Overrides
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:298
Properties
__text
• __text: string
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:280
constructor
• constructor: KlassConstructor
<typeof TextNode
>
Overrides
LexicalNode.constructor
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:279
Methods
canHaveFormat
▸ canHaveFormat(): boolean
Returns
boolean
true if the text node supports font styling, false otherwise.
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:448
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
packages/lexical/src/nodes/LexicalTextNode.ts:891
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
packages/lexical/src/nodes/LexicalTextNode.ts:880
createDOM
▸ createDOM(config
, editor?
): 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. |
editor? | LexicalEditor | allows access to the editor for context during reconciliation. |
Returns
HTMLElement
Overrides
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:454
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
packages/lexical/src/nodes/LexicalTextNode.ts:605
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
packages/lexical/src/nodes/LexicalTextNode.ts:633
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
packages/lexical/src/nodes/LexicalTextNode.ts:325
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
packages/lexical/src/nodes/LexicalTextNode.ts:313
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
packages/lexical/src/nodes/LexicalTextNode.ts:438
getMode
▸ getMode(): TextModeType
Returns the mode (TextModeType) of the TextNode, which may be "normal", "token", or "segmented"
Returns
TextModeType.
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:335
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
packages/lexical/src/nodes/LexicalTextNode.ts:345
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
packages/lexical/src/nodes/LexicalTextNode.ts:428
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
packages/lexical/src/nodes/LexicalTextNode.ts:408
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
packages/lexical/src/nodes/LexicalTextNode.ts:366
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
packages/lexical/src/nodes/LexicalTextNode.ts:385
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
packages/lexical/src/nodes/LexicalTextNode.ts:376
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
packages/lexical/src/nodes/LexicalTextNode.ts:419
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
packages/lexical/src/nodes/LexicalTextNode.ts:1086
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
packages/lexical/src/nodes/LexicalTextNode.ts:356
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
packages/lexical/src/nodes/LexicalTextNode.ts:395
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
packages/lexical/src/nodes/LexicalTextNode.ts:1029
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
packages/lexical/src/nodes/LexicalTextNode.ts:778
selectEnd
▸ selectEnd(): RangeSelection
Returns
Overrides
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:823
selectStart
▸ selectStart(): RangeSelection
Returns
Overrides
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:819
selectionTransform
▸ selectionTransform(prevSelection
, nextSelection
): void
Parameters
Name | Type |
---|---|
prevSelection | null | BaseSelection |
nextSelection | RangeSelection |
Returns
void
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:646
setDetail
▸ setDetail(detail
): this
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 TextNode.toggleDirectionless or TextNode.toggleUnmergeable
Parameters
Name | Type | Description |
---|---|---|
detail | number | TextDetailType | TextDetailType or 32-bit integer representing the node detail. |
Returns
this
this TextNode.
// TODO 0.12 This should just be a string
.
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:681
setFormat
▸ setFormat(format
): this
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 TextNode.toggleFormat
Parameters
Name | Type | Description |
---|---|---|
format | number | TextFormatType | TextFormatType or 32-bit integer representing the node format. |
Returns
this
this TextNode.
// TODO 0.12 This should just be a string
.
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:663
setMode
▸ setMode(type
): this
Sets the mode of the node.
Parameters
Name | Type |
---|---|
type | TextModeType |
Returns
this
this TextNode.
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:744
setStyle
▸ setStyle(style
): this
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
this TextNode.
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:696
setTextContent
▸ setTextContent(text
): this
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
this TextNode.
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:761
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
packages/lexical/src/nodes/LexicalTextNode.ts:839
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
packages/lexical/src/nodes/LexicalTextNode.ts:903
toggleDirectionless
▸ toggleDirectionless(): this
Toggles the directionless detail value of the node. Prefer using this method over setDetail.
Returns
this
this TextNode.
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:722
toggleFormat
▸ toggleFormat(type
): this
Applies the provided format to this TextNode if it's not present. Removes it if it's present. The subscript and superscript formats are mutually exclusive. Prefer using this method to turn specific formats on and off.
Parameters
Name | Type | Description |
---|---|---|
type | TextFormatType | TextFormatType to toggle. |
Returns
this
this TextNode.
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:711
toggleUnmergeable
▸ toggleUnmergeable(): this
Toggles the unmergeable detail value of the node. Prefer using this method over setDetail.
Returns
this
this TextNode.
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:733
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
packages/lexical/src/nodes/LexicalTextNode.ts:477
clone
▸ 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
packages/lexical/src/nodes/LexicalTextNode.ts:294
getType
▸ 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
packages/lexical/src/nodes/LexicalTextNode.ts:290
importDOM
▸ importDOM(): null
| DOMConversionMap
Returns
null
| DOMConversionMap
Overrides
LexicalNode.importDOM
Defined in
packages/lexical/src/nodes/LexicalTextNode.ts:544
importJSON
▸ 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 |