Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
33 lines
1.5 KiB
Plaintext
33 lines
1.5 KiB
Plaintext
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
*/
|
|
import { Klass, LexicalEditor, TextNode } from 'lexical';
|
|
export type EntityMatch = {
|
|
end: number;
|
|
start: number;
|
|
};
|
|
/**
|
|
* 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
|
|
* ```ts
|
|
* 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.
|
|
* @param editor - The lexical editor.
|
|
* @param getMatch - Finds a matching string that satisfies a regex expression.
|
|
* @param targetNode - The node type that contains text to match with. eg. HashtagNode
|
|
* @param createNode - A function that creates a new node to contain the matched text. eg createHashtagNode
|
|
* @returns An array containing the plain text and reverse node transform listeners.
|
|
*/
|
|
export declare function registerLexicalTextEntity<T extends TextNode>(editor: LexicalEditor, getMatch: (text: string) => null | EntityMatch, targetNode: Klass<T>, createNode: (textNode: TextNode) => T): Array<() => void>;
|