跳至主要内容

Module: @lexical/text

類型別名

EntityMatch

Ƭ EntityMatch: Object

類型聲明

名稱類型
endnumber
startnumber

定義於

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


TextNodeWithOffset

Ƭ TextNodeWithOffset: Object

類型聲明

名稱類型
nodeTextNode
offsetnumber

定義於

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

函數

$canShowPlaceholder

$canShowPlaceholder(isComposing): boolean

確定輸入框是否應顯示佔位符。如果根節點中有內容,則不應顯示佔位符。

參數

名稱類型說明
isComposingboolean編輯器是否因為活動中的輸入法編輯器而處於編輯模式?

返回

boolean

如果輸入框應顯示佔位符則為 true,否則為 false。

定義於

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


$canShowPlaceholderCurry

$canShowPlaceholderCurry(isEditorComposing): () => boolean

返回一個執行 $canShowPlaceholder 的函數。

參數

名稱類型說明
isEditorComposingboolean編輯器是否因為活動中的輸入法編輯器而處於編輯模式?

返回

fn

一個根據參數執行 $canShowPlaceholder 的函數。

▸ (): boolean

返回

boolean

定義於

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


$findTextIntersectionFromCharacters

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

尋找一個大小大於 targetCharacters 的 TextNode,並返回該節點及剩餘文本的長度。

參數

名稱類型說明
rootRootNode根節點。
targetCharactersnumberTextNode 必須大於的字符數量。

返回

null | { node: TextNode ; offset: number }

找到的 TextNode 和交集偏移量,如果未找到 TextNode 則返回 null。

定義於

packages/lexical-text/src/findTextIntersectionFromCharacters.ts:17


$isRootTextContentEmpty

$isRootTextContentEmpty(isEditorComposing, trim?): boolean

確定根節點是否有文本內容,並在有內容時修剪任何空白。

參數

名稱類型預設值說明
isEditorComposingbooleanundefined編輯器是否因為活動中的輸入法編輯器而處於編輯模式?
trimbooleantrue根文本是否應修剪空白?預設為 true。

返回

boolean

如果文本內容為空則為 true,若有文本或 isEditorComposing 為 true 則為 false。

定義於

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


$isRootTextContentEmptyCurry

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

返回一個執行 $isRootTextContentEmpty 的函數。

參數

名稱類型說明
isEditorComposingboolean編輯器是否因為活動中的輸入法編輯器而處於編輯模式?
trim?boolean根文本是否應修剪空白?預設為 true。

返回

fn

一個根據參數執行 $isRootTextContentEmpty 的函數。

▸ (): boolean

返回

boolean

定義於

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


$rootTextContent

$rootTextContent(): string

返回根節點的文本內容。

返回

string

根節點的文本內容。

定義於

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


registerLexicalTextEntity

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

返回一個元組,可以用於 mergeRegister 來清理將文本轉換為另一個節點的節點轉換監聽器,例如 HashtagNode。

類型參數

名稱類型
T擴展 TextNode

參數

名稱類型說明
editorLexicalEditorLexical 編輯器。
getMatch(text: string) => null | EntityMatch查找滿足正則表達式的匹配字串。
targetNodeKlass<T>包含要匹配文本的節點類型。例如 HashtagNode
createNode(textNode: TextNode) => T創建新節點以包含匹配文本的函數。例如 createHashtagNode

返回

() => void[]

包含純文本和反向節點轉換監聽器的數組。

示例

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

其中 targetNode 是包含要轉換文本的節點類型(如文本輸入),然後 getMatch 使用正則表達式查找匹配文本並創建適當的節點以包含匹配文本。

定義於

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