@lexical/text 0.44.1-nightly.20260519.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +30 -15
- package/src/canShowPlaceholder.ts +78 -0
- package/src/findTextIntersectionFromCharacters.ts +61 -0
- package/src/index.ts +27 -0
- package/src/isRootTextContentEmpty.ts +44 -0
- package/src/registerLexicalTextEntity.ts +220 -0
- package/src/rootTextContent.ts +18 -0
- /package/{LexicalText.dev.js → dist/LexicalText.dev.js} +0 -0
- /package/{LexicalText.dev.mjs → dist/LexicalText.dev.mjs} +0 -0
- /package/{LexicalText.js → dist/LexicalText.js} +0 -0
- /package/{LexicalText.js.flow → dist/LexicalText.js.flow} +0 -0
- /package/{LexicalText.mjs → dist/LexicalText.mjs} +0 -0
- /package/{LexicalText.node.mjs → dist/LexicalText.node.mjs} +0 -0
- /package/{LexicalText.prod.js → dist/LexicalText.prod.js} +0 -0
- /package/{LexicalText.prod.mjs → dist/LexicalText.prod.mjs} +0 -0
- /package/{canShowPlaceholder.d.ts → dist/canShowPlaceholder.d.ts} +0 -0
- /package/{findTextIntersectionFromCharacters.d.ts → dist/findTextIntersectionFromCharacters.d.ts} +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{isRootTextContentEmpty.d.ts → dist/isRootTextContentEmpty.d.ts} +0 -0
- /package/{registerLexicalTextEntity.d.ts → dist/registerLexicalTextEntity.d.ts} +0 -0
- /package/{rootTextContent.d.ts → dist/rootTextContent.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -9,34 +9,49 @@
|
|
|
9
9
|
"text"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.
|
|
13
|
-
"main": "LexicalText.js",
|
|
14
|
-
"types": "index.d.ts",
|
|
12
|
+
"version": "0.45.0",
|
|
13
|
+
"main": "./dist/LexicalText.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
17
|
"url": "git+https://github.com/facebook/lexical.git",
|
|
18
18
|
"directory": "packages/lexical-text"
|
|
19
19
|
},
|
|
20
|
-
"module": "LexicalText.mjs",
|
|
20
|
+
"module": "./dist/LexicalText.mjs",
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
+
"source": "./src/index.ts",
|
|
24
25
|
"import": {
|
|
25
|
-
"types": "./index.d.ts",
|
|
26
|
-
"development": "./LexicalText.dev.mjs",
|
|
27
|
-
"production": "./LexicalText.prod.mjs",
|
|
28
|
-
"node": "./LexicalText.node.mjs",
|
|
29
|
-
"default": "./LexicalText.mjs"
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"development": "./dist/LexicalText.dev.mjs",
|
|
28
|
+
"production": "./dist/LexicalText.prod.mjs",
|
|
29
|
+
"node": "./dist/LexicalText.node.mjs",
|
|
30
|
+
"default": "./dist/LexicalText.mjs"
|
|
30
31
|
},
|
|
31
32
|
"require": {
|
|
32
|
-
"types": "./index.d.ts",
|
|
33
|
-
"development": "./LexicalText.dev.js",
|
|
34
|
-
"production": "./LexicalText.prod.js",
|
|
35
|
-
"default": "./LexicalText.js"
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"development": "./dist/LexicalText.dev.js",
|
|
35
|
+
"production": "./dist/LexicalText.prod.js",
|
|
36
|
+
"default": "./dist/LexicalText.js"
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"lexical": "0.
|
|
41
|
-
|
|
41
|
+
"@lexical/internal": "0.45.0",
|
|
42
|
+
"lexical": "0.45.0"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"src",
|
|
47
|
+
"!src/__tests__",
|
|
48
|
+
"!src/__bench__",
|
|
49
|
+
"!src/__mocks__",
|
|
50
|
+
"!src/**/*.test.ts",
|
|
51
|
+
"!src/**/*.test.tsx",
|
|
52
|
+
"!src/**/*.bench.ts",
|
|
53
|
+
"!src/**/*.bench.tsx",
|
|
54
|
+
"README.md",
|
|
55
|
+
"LICENSE"
|
|
56
|
+
]
|
|
42
57
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
$getRoot,
|
|
10
|
+
$isDecoratorNode,
|
|
11
|
+
$isElementNode,
|
|
12
|
+
$isParagraphNode,
|
|
13
|
+
$isTextNode,
|
|
14
|
+
} from 'lexical';
|
|
15
|
+
|
|
16
|
+
import {$isRootTextContentEmpty} from './isRootTextContentEmpty';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Determines if the input should show the placeholder. If anything is in
|
|
20
|
+
* in the root the placeholder should not be shown.
|
|
21
|
+
* @param isComposing - Is the editor in composition mode due to an active Input Method Editor?
|
|
22
|
+
* @returns true if the input should show the placeholder, false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
export function $canShowPlaceholder(isComposing: boolean): boolean {
|
|
25
|
+
if (!$isRootTextContentEmpty(isComposing, false)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const root = $getRoot();
|
|
30
|
+
const children = root.getChildren();
|
|
31
|
+
const childrenLength = children.length;
|
|
32
|
+
|
|
33
|
+
if (childrenLength > 1) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for (let i = 0; i < childrenLength; i++) {
|
|
38
|
+
const topBlock = children[i];
|
|
39
|
+
|
|
40
|
+
if ($isDecoratorNode(topBlock)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if ($isElementNode(topBlock)) {
|
|
45
|
+
if (!$isParagraphNode(topBlock)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (topBlock.__indent !== 0) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const topBlockChildren = topBlock.getChildren();
|
|
54
|
+
const topBlockChildrenLength = topBlockChildren.length;
|
|
55
|
+
|
|
56
|
+
for (let s = 0; s < topBlockChildrenLength; s++) {
|
|
57
|
+
const child = topBlockChildren[i];
|
|
58
|
+
|
|
59
|
+
if (!$isTextNode(child)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns a function that executes {@link $canShowPlaceholder}
|
|
71
|
+
* @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
|
|
72
|
+
* @returns A function that executes $canShowPlaceholder with arguments.
|
|
73
|
+
*/
|
|
74
|
+
export function $canShowPlaceholderCurry(
|
|
75
|
+
isEditorComposing: boolean,
|
|
76
|
+
): () => boolean {
|
|
77
|
+
return () => $canShowPlaceholder(isEditorComposing);
|
|
78
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import {$isElementNode, $isTextNode, RootNode, TextNode} from 'lexical';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Finds a TextNode with a size larger than targetCharacters and returns
|
|
12
|
+
* the node along with the remaining length of the text.
|
|
13
|
+
* @param root - The RootNode.
|
|
14
|
+
* @param targetCharacters - The number of characters whose TextNode must be larger than.
|
|
15
|
+
* @returns The TextNode and the intersections offset, or null if no TextNode is found.
|
|
16
|
+
* @deprecated $findTextIntersectionFromCharacters has never worked correctly and will be removed
|
|
17
|
+
*/
|
|
18
|
+
export function $findTextIntersectionFromCharacters(
|
|
19
|
+
root: RootNode,
|
|
20
|
+
targetCharacters: number,
|
|
21
|
+
): null | {node: TextNode; offset: number} {
|
|
22
|
+
let node = root.getFirstChild();
|
|
23
|
+
let currentCharacters = 0;
|
|
24
|
+
|
|
25
|
+
mainLoop: while (node !== null) {
|
|
26
|
+
if ($isElementNode(node)) {
|
|
27
|
+
const child = node.getFirstChild();
|
|
28
|
+
|
|
29
|
+
if (child !== null) {
|
|
30
|
+
node = child;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
} else if ($isTextNode(node)) {
|
|
34
|
+
const characters = node.getTextContentSize();
|
|
35
|
+
|
|
36
|
+
if (currentCharacters + characters > targetCharacters) {
|
|
37
|
+
return {node, offset: targetCharacters - currentCharacters};
|
|
38
|
+
}
|
|
39
|
+
currentCharacters += characters;
|
|
40
|
+
}
|
|
41
|
+
const sibling = node.getNextSibling();
|
|
42
|
+
|
|
43
|
+
if (sibling !== null) {
|
|
44
|
+
node = sibling;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
let parent = node.getParent();
|
|
48
|
+
while (parent !== null) {
|
|
49
|
+
const parentSibling = parent.getNextSibling();
|
|
50
|
+
|
|
51
|
+
if (parentSibling !== null) {
|
|
52
|
+
node = parentSibling;
|
|
53
|
+
continue mainLoop;
|
|
54
|
+
}
|
|
55
|
+
parent = parent.getParent();
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return null;
|
|
61
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {TextNode} from 'lexical';
|
|
10
|
+
|
|
11
|
+
export type TextNodeWithOffset = {
|
|
12
|
+
node: TextNode;
|
|
13
|
+
offset: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
$canShowPlaceholder,
|
|
18
|
+
$canShowPlaceholderCurry,
|
|
19
|
+
} from './canShowPlaceholder';
|
|
20
|
+
export {$findTextIntersectionFromCharacters} from './findTextIntersectionFromCharacters';
|
|
21
|
+
export {
|
|
22
|
+
$isRootTextContentEmpty,
|
|
23
|
+
$isRootTextContentEmptyCurry,
|
|
24
|
+
} from './isRootTextContentEmpty';
|
|
25
|
+
export type {EntityMatch} from './registerLexicalTextEntity';
|
|
26
|
+
export {registerLexicalTextEntity} from './registerLexicalTextEntity';
|
|
27
|
+
export {$rootTextContent} from './rootTextContent';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import {$rootTextContent} from './rootTextContent';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Determines if the root has any text content and can trim any whitespace if it does.
|
|
12
|
+
* @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
|
|
13
|
+
* @param trim - Should the root text have its whitespaced trimmed? Defaults to true.
|
|
14
|
+
* @returns true if text content is empty, false if there is text or isEditorComposing is true.
|
|
15
|
+
*/
|
|
16
|
+
export function $isRootTextContentEmpty(
|
|
17
|
+
isEditorComposing: boolean,
|
|
18
|
+
trim = true,
|
|
19
|
+
): boolean {
|
|
20
|
+
if (isEditorComposing) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let text = $rootTextContent();
|
|
25
|
+
|
|
26
|
+
if (trim) {
|
|
27
|
+
text = text.trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return text === '';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns a function that executes {@link $isRootTextContentEmpty}
|
|
35
|
+
* @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
|
|
36
|
+
* @param trim - Should the root text have its whitespaced trimmed? Defaults to true.
|
|
37
|
+
* @returns A function that executes $isRootTextContentEmpty based on arguments.
|
|
38
|
+
*/
|
|
39
|
+
export function $isRootTextContentEmptyCurry(
|
|
40
|
+
isEditorComposing: boolean,
|
|
41
|
+
trim?: boolean,
|
|
42
|
+
): () => boolean {
|
|
43
|
+
return () => $isRootTextContentEmpty(isEditorComposing, trim);
|
|
44
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import invariant from '@lexical/internal/invariant';
|
|
10
|
+
import {
|
|
11
|
+
$createTextNode,
|
|
12
|
+
$isTextNode,
|
|
13
|
+
Klass,
|
|
14
|
+
LexicalEditor,
|
|
15
|
+
LexicalNode,
|
|
16
|
+
TextNode,
|
|
17
|
+
} from 'lexical';
|
|
18
|
+
|
|
19
|
+
export type EntityMatch = {end: number; start: number};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns a tuple that can be rested (...) into mergeRegister to clean up
|
|
23
|
+
* node transforms listeners that transforms text into another node, eg. a HashtagNode.
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* useEffect(() => {
|
|
27
|
+
return mergeRegister(
|
|
28
|
+
...registerLexicalTextEntity(editor, getMatch, targetNode, createNode),
|
|
29
|
+
);
|
|
30
|
+
}, [createNode, editor, getMatch, targetNode]);
|
|
31
|
+
* ```
|
|
32
|
+
* Where targetNode is the type of node containing the text you want to transform (like a text input),
|
|
33
|
+
* then getMatch uses a regex to find a matching text and creates the proper node to include the matching text.
|
|
34
|
+
* @param editor - The lexical editor.
|
|
35
|
+
* @param getMatch - Finds a matching string that satisfies a regex expression.
|
|
36
|
+
* @param targetNode - The node type that contains text to match with. eg. HashtagNode
|
|
37
|
+
* @param createNode - A function that creates a new node to contain the matched text. eg createHashtagNode
|
|
38
|
+
* @returns An array containing the plain text and reverse node transform listeners.
|
|
39
|
+
*/
|
|
40
|
+
export function registerLexicalTextEntity<T extends TextNode>(
|
|
41
|
+
editor: LexicalEditor,
|
|
42
|
+
getMatch: (text: string) => null | EntityMatch,
|
|
43
|
+
targetNode: Klass<T>,
|
|
44
|
+
createNode: (textNode: TextNode) => T,
|
|
45
|
+
): Array<() => void> {
|
|
46
|
+
const isTargetNode = (node: LexicalNode | null | undefined): node is T => {
|
|
47
|
+
return node instanceof targetNode;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const $replaceWithSimpleText = (node: TextNode): void => {
|
|
51
|
+
const textNode = $createTextNode(node.getTextContent());
|
|
52
|
+
textNode.setFormat(node.getFormat());
|
|
53
|
+
node.replace(textNode);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const getMode = (node: TextNode): number => {
|
|
57
|
+
return node.getLatest().__mode;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const $textNodeTransform = (node: TextNode) => {
|
|
61
|
+
if (!node.isSimpleText()) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let prevSibling = node.getPreviousSibling();
|
|
66
|
+
let text = node.getTextContent();
|
|
67
|
+
let currentNode = node;
|
|
68
|
+
let match;
|
|
69
|
+
|
|
70
|
+
if ($isTextNode(prevSibling)) {
|
|
71
|
+
const previousText = prevSibling.getTextContent();
|
|
72
|
+
const combinedText = previousText + text;
|
|
73
|
+
const prevMatch = getMatch(combinedText);
|
|
74
|
+
|
|
75
|
+
if (isTargetNode(prevSibling)) {
|
|
76
|
+
if (prevMatch === null || getMode(prevSibling) !== 0) {
|
|
77
|
+
$replaceWithSimpleText(prevSibling);
|
|
78
|
+
|
|
79
|
+
return;
|
|
80
|
+
} else {
|
|
81
|
+
const diff = prevMatch.end - previousText.length;
|
|
82
|
+
|
|
83
|
+
if (diff > 0) {
|
|
84
|
+
const concatText = text.slice(0, diff);
|
|
85
|
+
const newTextContent = previousText + concatText;
|
|
86
|
+
prevSibling.select();
|
|
87
|
+
prevSibling.setTextContent(newTextContent);
|
|
88
|
+
|
|
89
|
+
if (diff === text.length) {
|
|
90
|
+
node.remove();
|
|
91
|
+
} else {
|
|
92
|
+
const remainingText = text.slice(diff);
|
|
93
|
+
node.setTextContent(remainingText);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} else if (prevMatch === null || prevMatch.start < previousText.length) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let prevMatchLengthToSkip = 0;
|
|
105
|
+
|
|
106
|
+
while (true) {
|
|
107
|
+
match = getMatch(text);
|
|
108
|
+
let nextText = match === null ? '' : text.slice(match.end);
|
|
109
|
+
text = nextText;
|
|
110
|
+
|
|
111
|
+
if (nextText === '') {
|
|
112
|
+
const nextSibling = currentNode.getNextSibling();
|
|
113
|
+
|
|
114
|
+
if ($isTextNode(nextSibling)) {
|
|
115
|
+
nextText =
|
|
116
|
+
currentNode.getTextContent() + nextSibling.getTextContent();
|
|
117
|
+
const nextMatch = getMatch(nextText);
|
|
118
|
+
|
|
119
|
+
if (nextMatch === null) {
|
|
120
|
+
if (isTargetNode(nextSibling)) {
|
|
121
|
+
$replaceWithSimpleText(nextSibling);
|
|
122
|
+
} else {
|
|
123
|
+
nextSibling.markDirty();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return;
|
|
127
|
+
} else if (nextMatch.start !== 0) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (match === null) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (
|
|
138
|
+
match.start === 0 &&
|
|
139
|
+
$isTextNode(prevSibling) &&
|
|
140
|
+
prevSibling.isTextEntity()
|
|
141
|
+
) {
|
|
142
|
+
prevMatchLengthToSkip += match.end;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let nodeToReplace;
|
|
147
|
+
if (match.start === 0) {
|
|
148
|
+
[nodeToReplace, currentNode] = currentNode.splitText(match.end);
|
|
149
|
+
} else {
|
|
150
|
+
[, nodeToReplace, currentNode] = currentNode.splitText(
|
|
151
|
+
match.start + prevMatchLengthToSkip,
|
|
152
|
+
match.end + prevMatchLengthToSkip,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
invariant(
|
|
157
|
+
nodeToReplace !== undefined,
|
|
158
|
+
'%s should not be undefined. You may want to check splitOffsets passed to the splitText.',
|
|
159
|
+
'nodeToReplace',
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const replacementNode = createNode(nodeToReplace);
|
|
163
|
+
replacementNode.setFormat(nodeToReplace.getFormat());
|
|
164
|
+
nodeToReplace.replace(replacementNode);
|
|
165
|
+
|
|
166
|
+
if (currentNode == null) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
prevMatchLengthToSkip = 0;
|
|
170
|
+
prevSibling = replacementNode;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const $reverseNodeTransform = (node: T) => {
|
|
175
|
+
const text = node.getTextContent();
|
|
176
|
+
const match = getMatch(text);
|
|
177
|
+
|
|
178
|
+
if (match === null || match.start !== 0) {
|
|
179
|
+
$replaceWithSimpleText(node);
|
|
180
|
+
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (text.length > match.end) {
|
|
185
|
+
// This will split out the rest of the text as simple text
|
|
186
|
+
node.splitText(match.end);
|
|
187
|
+
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const prevSibling = node.getPreviousSibling();
|
|
192
|
+
|
|
193
|
+
if ($isTextNode(prevSibling) && prevSibling.isTextEntity()) {
|
|
194
|
+
$replaceWithSimpleText(prevSibling);
|
|
195
|
+
$replaceWithSimpleText(node);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const nextSibling = node.getNextSibling();
|
|
199
|
+
|
|
200
|
+
if ($isTextNode(nextSibling) && nextSibling.isTextEntity()) {
|
|
201
|
+
$replaceWithSimpleText(nextSibling);
|
|
202
|
+
|
|
203
|
+
// This may have already been converted in the previous block
|
|
204
|
+
if (isTargetNode(node)) {
|
|
205
|
+
$replaceWithSimpleText(node);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const removePlainTextTransform = editor.registerNodeTransform(
|
|
211
|
+
TextNode,
|
|
212
|
+
$textNodeTransform,
|
|
213
|
+
);
|
|
214
|
+
const removeReverseNodeTransform = editor.registerNodeTransform<T>(
|
|
215
|
+
targetNode,
|
|
216
|
+
$reverseNodeTransform,
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
return [removePlainTextTransform, removeReverseNodeTransform];
|
|
220
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import {$getRoot} from 'lexical';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns the root's text content.
|
|
12
|
+
* @returns The root's text content.
|
|
13
|
+
*/
|
|
14
|
+
export function $rootTextContent(): string {
|
|
15
|
+
const root = $getRoot();
|
|
16
|
+
|
|
17
|
+
return root.getTextContent();
|
|
18
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{findTextIntersectionFromCharacters.d.ts → dist/findTextIntersectionFromCharacters.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|