Skip to main content

@lexical/text

Type Aliases​

EntityMatch​

EntityMatch = object

Defined in: packages/lexical-text/src/registerLexicalTextEntity.ts:19

Properties​

end​

end: number

Defined in: packages/lexical-text/src/registerLexicalTextEntity.ts:19

start​

start: number

Defined in: packages/lexical-text/src/registerLexicalTextEntity.ts:19


TextNodeWithOffset​

TextNodeWithOffset = object

Defined in: packages/lexical-text/src/index.ts:11

Properties​

node​

node: TextNode

Defined in: packages/lexical-text/src/index.ts:12

offset​

offset: number

Defined in: packages/lexical-text/src/index.ts:13

Functions​

$canShowPlaceholder()​

$canShowPlaceholder(isComposing): boolean

Defined in: packages/lexical-text/src/canShowPlaceholder.ts:24

Determines if the input should show the placeholder. If anything is in in the root the placeholder should not be shown.

Parameters​

isComposing​

boolean

Is the editor in composition mode due to an active Input Method Editor?

Returns​

boolean

true if the input should show the placeholder, false otherwise.


$canShowPlaceholderCurry()​

$canShowPlaceholderCurry(isEditorComposing): () => boolean

Defined in: packages/lexical-text/src/canShowPlaceholder.ts:74

Returns a function that executes $canShowPlaceholder

Parameters​

isEditorComposing​

boolean

Is the editor in composition mode due to an active Input Method Editor?

Returns​

A function that executes $canShowPlaceholder with arguments.

() => boolean


$findTextIntersectionFromCharacters()​

$findTextIntersectionFromCharacters(root, targetCharacters): { node: TextNode; offset: number; } | null

Defined in: packages/lexical-text/src/findTextIntersectionFromCharacters.ts:23

Finds a TextNode with a size larger than targetCharacters and returns the node along with the remaining length of the text.

Parameters​

root​

RootNode

The RootNode.

targetCharacters​

number

The number of characters whose TextNode must be larger than.

Returns​

{ node: TextNode; offset: number; } | null

The TextNode and the intersections offset, or null if no TextNode is found.

Deprecated​

$findTextIntersectionFromCharacters has never worked correctly and will be removed


$isRootTextContentEmpty()​

$isRootTextContentEmpty(isEditorComposing, trim?): boolean

Defined in: packages/lexical-text/src/isRootTextContentEmpty.ts:16

Determines if the root has any text content and can trim any whitespace if it does.

Parameters​

isEditorComposing​

boolean

Is the editor in composition mode due to an active Input Method Editor?

trim?​

boolean = true

Should the root text have its whitespaced trimmed? Defaults to true.

Returns​

boolean

true if text content is empty, false if there is text or isEditorComposing is true.


$isRootTextContentEmptyCurry()​

$isRootTextContentEmptyCurry(isEditorComposing, trim?): () => boolean

Defined in: packages/lexical-text/src/isRootTextContentEmpty.ts:39

Returns a function that executes $isRootTextContentEmpty

Parameters​

isEditorComposing​

boolean

Is the editor in composition mode due to an active Input Method Editor?

trim?​

boolean

Should the root text have its whitespaced trimmed? Defaults to true.

Returns​

A function that executes $isRootTextContentEmpty based on arguments.

() => boolean


$rootTextContent()​

$rootTextContent(): string

Defined in: packages/lexical-text/src/rootTextContent.ts:14

Returns the root's text content.

Returns​

string

The root's text content.


registerLexicalTextEntity()​

registerLexicalTextEntity<T>(editor, getMatch, targetNode, createNode): () => void[]

Defined in: packages/lexical-text/src/registerLexicalTextEntity.ts:40

Returns a tuple that can be rested (...) into mergeRegister to clean up node transforms listeners that transforms text into another node, eg. a HashtagNode.

Type Parameters​

T​

T extends TextNode

Parameters​

editor​

LexicalEditor

The lexical editor.

getMatch​

(text) => EntityMatch | null

Finds a matching string that satisfies a regex expression.

targetNode​

Klass<T>

The node type that contains text to match with. eg. HashtagNode

createNode​

(textNode) => T

A function that creates a new node to contain the matched text. eg createHashtagNode

Returns​

() => void[]

An array containing the plain text and reverse node transform listeners.

Example​

useEffect(() => {
return mergeRegister(
...registerLexicalTextEntity(editor, getMatch, targetNode, createNode),
);
}, [createNode, editor, getMatch, targetNode]);

Where targetNode is the type of node containing the text you want to transform (like a text input), then getMatch uses a regex to find a matching text and creates the proper node to include the matching text.