Skip to main content

Module: @lexical/text

Type Aliases

EntityMatch

Ƭ EntityMatch: Object

Type declaration

NameType
endnumber
startnumber

Defined in

lexical-text/src/registerLexicalTextEntity.ts:18


TextNodeWithOffset

Ƭ TextNodeWithOffset: Object

Type declaration

NameType
nodeTextNode
offsetnumber

Defined in

lexical-text/src/index.ts:12

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/canShowPlaceholder.ts:24


$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/canShowPlaceholder.ts:74


$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/findTextIntersectionFromCharacters.ts:17


$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/isRootTextContentEmpty.ts:16


$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/isRootTextContentEmpty.ts:39


$rootTextContent

$rootTextContent(): string

Returns the root's text content.

Returns

string

The root's text content.

Defined in

lexical-text/src/rootTextContent.ts:14


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.

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.

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.

Defined in

lexical-text/src/registerLexicalTextEntity.ts:39