New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@lexical/text

Package Overview
Dependencies
Maintainers
7
Versions
311
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/text - npm Package Compare versions

Comparing version

to
0.9.2

53

index.d.ts

@@ -15,2 +15,9 @@ /** @module @lexical/text */

};
/**
* Finds a TextNode with a size larger than targetCharacters and returns
* the node along with the remaining length of the text.
* @param root - The RootNode.
* @param targetCharacters - The number of characters whose TextNode must be larger than.
* @returns The TextNode and the intersections offset, or null if no TextNode is found.
*/
export declare function $findTextIntersectionFromCharacters(root: RootNode, targetCharacters: number): null | {

@@ -20,6 +27,33 @@ node: TextNode;

};
/**
* Determines if the root has any text content and can trim any whitespace if it does.
* @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
* @param trim - Should the root text have its whitespaced trimmed? Defaults to true.
* @returns true if text content is empty, false if there is text or isEditorComposing is true.
*/
export declare function $isRootTextContentEmpty(isEditorComposing: boolean, trim?: boolean): boolean;
/**
* Returns a function that executes {@link $isRootTextContentEmpty}
* @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
* @param trim - Should the root text have its whitespaced trimmed? Defaults to true.
* @returns A function that executes $isRootTextContentEmpty based on arguments.
*/
export declare function $isRootTextContentEmptyCurry(isEditorComposing: boolean, trim?: boolean): () => boolean;
/**
* Returns the root's text content.
* @returns The root's text content.
*/
export declare function $rootTextContent(): string;
/**
* Determines if the input should show the placeholder. If anything is in
* in the root the placeholder should not be shown.
* @param isComposing - Is the editor in composition mode due to an active Input Method Editor?
* @returns true if the input should show the placeholder, false otherwise.
*/
export declare function $canShowPlaceholder(isComposing: boolean): boolean;
/**
* Returns a function that executes {@link $canShowPlaceholder}
* @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
* @returns A function that executes $canShowPlaceholder with arguments.
*/
export declare function $canShowPlaceholderCurry(isEditorComposing: boolean): () => boolean;

@@ -30,2 +64,21 @@ export declare type EntityMatch = {

};
/**
* Returns a touple 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>;

@@ -12,2 +12,10 @@ /**

/** @module @lexical/text */
/**
* Finds a TextNode with a size larger than targetCharacters and returns
* the node along with the remaining length of the text.
* @param root - The RootNode.
* @param targetCharacters - The number of characters whose TextNode must be larger than.
* @returns The TextNode and the intersections offset, or null if no TextNode is found.
*/
function $findTextIntersectionFromCharacters(root, targetCharacters) {

@@ -63,2 +71,9 @@ let node = root.getFirstChild();

}
/**
* Determines if the root has any text content and can trim any whitespace if it does.
* @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
* @param trim - Should the root text have its whitespaced trimmed? Defaults to true.
* @returns true if text content is empty, false if there is text or isEditorComposing is true.
*/
function $isRootTextContentEmpty(isEditorComposing, trim = true) {

@@ -77,5 +92,17 @@ if (isEditorComposing) {

}
/**
* Returns a function that executes {@link $isRootTextContentEmpty}
* @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
* @param trim - Should the root text have its whitespaced trimmed? Defaults to true.
* @returns A function that executes $isRootTextContentEmpty based on arguments.
*/
function $isRootTextContentEmptyCurry(isEditorComposing, trim) {
return () => $isRootTextContentEmpty(isEditorComposing, trim);
}
/**
* Returns the root's text content.
* @returns The root's text content.
*/
function $rootTextContent() {

@@ -85,2 +112,9 @@ const root = lexical.$getRoot();

}
/**
* Determines if the input should show the placeholder. If anything is in
* in the root the placeholder should not be shown.
* @param isComposing - Is the editor in composition mode due to an active Input Method Editor?
* @returns true if the input should show the placeholder, false otherwise.
*/
function $canShowPlaceholder(isComposing) {

@@ -130,5 +164,31 @@ if (!$isRootTextContentEmpty(isComposing, false)) {

}
/**
* Returns a function that executes {@link $canShowPlaceholder}
* @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
* @returns A function that executes $canShowPlaceholder with arguments.
*/
function $canShowPlaceholderCurry(isEditorComposing) {
return () => $canShowPlaceholder(isEditorComposing);
}
/**
* Returns a touple 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.
*/
function registerLexicalTextEntity(editor, getMatch, targetNode, createNode) {

@@ -135,0 +195,0 @@ const isTargetNode = node => {

4

package.json

@@ -12,6 +12,6 @@ {

"license": "MIT",
"version": "0.9.1",
"version": "0.9.2",
"main": "LexicalText.js",
"peerDependencies": {
"lexical": "0.9.1"
"lexical": "0.9.2"
},

@@ -18,0 +18,0 @@ "repository": {