Skip to main content

Module: @lexical/text

Type Aliases

EntityMatch

Ƭ EntityMatch: Object

Type declaration

NameType
endnumber
startnumber

Defined in

lexical-text/src/index.ts:187


TextNodeWithOffset

Ƭ TextNodeWithOffset: Object

Type declaration

NameType
nodeTextNode
offsetnumber

Defined in

lexical-text/src/index.ts:22

Functions

$canShowPlaceholder

$canShowPlaceholder(isComposing): boolean

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

Parameters

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

Returns

boolean

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

Defined in

lexical-text/src/index.ts:131


$canShowPlaceholderCurry

$canShowPlaceholderCurry(isEditorComposing): () => boolean

Returns a function that executes $canShowPlaceholder

Parameters

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

Returns

fn

A function that executes $canShowPlaceholder with arguments.

▸ (): boolean

Returns

boolean

Defined in

lexical-text/src/index.ts:181


$findTextIntersectionFromCharacters

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

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

Parameters

NameTypeDescription
rootRootNodeThe RootNode.
targetCharactersnumberThe number of characters whose TextNode must be larger than.

Returns

null | { node: TextNode ; offset: number }

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

Defined in

lexical-text/src/index.ts:34


$isRootTextContentEmpty

$isRootTextContentEmpty(isEditorComposing, trim?): boolean

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

Parameters

NameTypeDefault valueDescription
isEditorComposingbooleanundefinedIs the editor in composition mode due to an active Input Method Editor?
trimbooleantrueShould 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.

Defined in

lexical-text/src/index.ts:85


$isRootTextContentEmptyCurry

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

Returns a function that executes $isRootTextContentEmpty

Parameters

NameTypeDescription
isEditorComposingbooleanIs the editor in composition mode due to an active Input Method Editor?
trim?booleanShould the root text have its whitespaced trimmed? Defaults to true.

Returns

fn

A function that executes $isRootTextContentEmpty based on arguments.

▸ (): boolean

Returns

boolean

Defined in

lexical-text/src/index.ts:108


$rootTextContent

$rootTextContent(): string

Returns the root's text content.

Returns

string

The root's text content.

Defined in

lexical-text/src/index.ts:119


registerLexicalTextEntity

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

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

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.

Type parameters

NameType
Textends TextNode

Parameters

NameTypeDescription
editorLexicalEditorThe lexical editor.
getMatch(text: string) => null | EntityMatchFinds a matching string that satisfies a regex expression.
targetNodeKlass<T>The node type that contains text to match with. eg. HashtagNode
createNode(textNode: TextNode) => TA 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.

Defined in

lexical-text/src/index.ts:208