@lexical/text 0.14.2 → 0.14.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,53 +8,31 @@
8
8
 
9
9
  var lexical = require('lexical');
10
10
 
11
- /** @module @lexical/text */
12
11
  /**
13
- * Finds a TextNode with a size larger than targetCharacters and returns
14
- * the node along with the remaining length of the text.
15
- * @param root - The RootNode.
16
- * @param targetCharacters - The number of characters whose TextNode must be larger than.
17
- * @returns The TextNode and the intersections offset, or null if no TextNode is found.
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
18
17
  */
19
- function $findTextIntersectionFromCharacters(root, targetCharacters) {
20
- let node = root.getFirstChild();
21
- let currentCharacters = 0;
22
- mainLoop: while (node !== null) {
23
- if (lexical.$isElementNode(node)) {
24
- const child = node.getFirstChild();
25
- if (child !== null) {
26
- node = child;
27
- continue;
28
- }
29
- } else if (lexical.$isTextNode(node)) {
30
- const characters = node.getTextContentSize();
31
- if (currentCharacters + characters > targetCharacters) {
32
- return {
33
- node,
34
- offset: targetCharacters - currentCharacters
35
- };
36
- }
37
- currentCharacters += characters;
38
- }
39
- const sibling = node.getNextSibling();
40
- if (sibling !== null) {
41
- node = sibling;
42
- continue;
43
- }
44
- let parent = node.getParent();
45
- while (parent !== null) {
46
- const parentSibling = parent.getNextSibling();
47
- if (parentSibling !== null) {
48
- node = parentSibling;
49
- continue mainLoop;
50
- }
51
- parent = parent.getParent();
52
- }
53
- break;
54
- }
55
- return null;
18
+
19
+ /**
20
+ * Returns the root's text content.
21
+ * @returns The root's text content.
22
+ */
23
+ function $rootTextContent() {
24
+ const root = lexical.$getRoot();
25
+ return root.getTextContent();
56
26
  }
57
27
 
28
+ /**
29
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
30
+ *
31
+ * This source code is licensed under the MIT license found in the
32
+ * LICENSE file in the root directory of this source tree.
33
+ *
34
+ */
35
+
58
36
  /**
59
37
  * Determines if the root has any text content and can trim any whitespace if it does.
60
38
  * @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
@@ -83,13 +61,12 @@ function $isRootTextContentEmptyCurry(isEditorComposing, trim) {
83
61
  }
84
62
 
85
63
  /**
86
- * Returns the root's text content.
87
- * @returns The root's text content.
64
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
65
+ *
66
+ * This source code is licensed under the MIT license found in the
67
+ * LICENSE file in the root directory of this source tree.
68
+ *
88
69
  */
89
- function $rootTextContent() {
90
- const root = lexical.$getRoot();
91
- return root.getTextContent();
92
- }
93
70
 
94
71
  /**
95
72
  * Determines if the input should show the placeholder. If anything is in
@@ -140,6 +117,68 @@ function $canShowPlaceholder(isComposing) {
140
117
  function $canShowPlaceholderCurry(isEditorComposing) {
141
118
  return () => $canShowPlaceholder(isEditorComposing);
142
119
  }
120
+
121
+ /**
122
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
123
+ *
124
+ * This source code is licensed under the MIT license found in the
125
+ * LICENSE file in the root directory of this source tree.
126
+ *
127
+ */
128
+
129
+ /**
130
+ * Finds a TextNode with a size larger than targetCharacters and returns
131
+ * the node along with the remaining length of the text.
132
+ * @param root - The RootNode.
133
+ * @param targetCharacters - The number of characters whose TextNode must be larger than.
134
+ * @returns The TextNode and the intersections offset, or null if no TextNode is found.
135
+ */
136
+ function $findTextIntersectionFromCharacters(root, targetCharacters) {
137
+ let node = root.getFirstChild();
138
+ let currentCharacters = 0;
139
+ mainLoop: while (node !== null) {
140
+ if (lexical.$isElementNode(node)) {
141
+ const child = node.getFirstChild();
142
+ if (child !== null) {
143
+ node = child;
144
+ continue;
145
+ }
146
+ } else if (lexical.$isTextNode(node)) {
147
+ const characters = node.getTextContentSize();
148
+ if (currentCharacters + characters > targetCharacters) {
149
+ return {
150
+ node,
151
+ offset: targetCharacters - currentCharacters
152
+ };
153
+ }
154
+ currentCharacters += characters;
155
+ }
156
+ const sibling = node.getNextSibling();
157
+ if (sibling !== null) {
158
+ node = sibling;
159
+ continue;
160
+ }
161
+ let parent = node.getParent();
162
+ while (parent !== null) {
163
+ const parentSibling = parent.getNextSibling();
164
+ if (parentSibling !== null) {
165
+ node = parentSibling;
166
+ continue mainLoop;
167
+ }
168
+ parent = parent.getParent();
169
+ }
170
+ break;
171
+ }
172
+ return null;
173
+ }
174
+
175
+ /**
176
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
177
+ *
178
+ * This source code is licensed under the MIT license found in the
179
+ * LICENSE file in the root directory of this source tree.
180
+ *
181
+ */
143
182
  /**
144
183
  * Returns a tuple that can be rested (...) into mergeRegister to clean up
145
184
  * node transforms listeners that transforms text into another node, eg. a HashtagNode.
@@ -4,55 +4,33 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { $isElementNode, $isTextNode, $getRoot, $isDecoratorNode, $isParagraphNode, TextNode, $createTextNode } from 'lexical';
7
+ import { $getRoot, $isDecoratorNode, $isElementNode, $isParagraphNode, $isTextNode, TextNode, $createTextNode } from 'lexical';
8
8
 
9
- /** @module @lexical/text */
10
9
  /**
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.
10
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
11
+ *
12
+ * This source code is licensed under the MIT license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ *
16
15
  */
17
- function $findTextIntersectionFromCharacters(root, targetCharacters) {
18
- let node = root.getFirstChild();
19
- let currentCharacters = 0;
20
- mainLoop: while (node !== null) {
21
- if ($isElementNode(node)) {
22
- const child = node.getFirstChild();
23
- if (child !== null) {
24
- node = child;
25
- continue;
26
- }
27
- } else if ($isTextNode(node)) {
28
- const characters = node.getTextContentSize();
29
- if (currentCharacters + characters > targetCharacters) {
30
- return {
31
- node,
32
- offset: targetCharacters - currentCharacters
33
- };
34
- }
35
- currentCharacters += characters;
36
- }
37
- const sibling = node.getNextSibling();
38
- if (sibling !== null) {
39
- node = sibling;
40
- continue;
41
- }
42
- let parent = node.getParent();
43
- while (parent !== null) {
44
- const parentSibling = parent.getNextSibling();
45
- if (parentSibling !== null) {
46
- node = parentSibling;
47
- continue mainLoop;
48
- }
49
- parent = parent.getParent();
50
- }
51
- break;
52
- }
53
- return null;
16
+
17
+ /**
18
+ * Returns the root's text content.
19
+ * @returns The root's text content.
20
+ */
21
+ function $rootTextContent() {
22
+ const root = $getRoot();
23
+ return root.getTextContent();
54
24
  }
55
25
 
26
+ /**
27
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
28
+ *
29
+ * This source code is licensed under the MIT license found in the
30
+ * LICENSE file in the root directory of this source tree.
31
+ *
32
+ */
33
+
56
34
  /**
57
35
  * Determines if the root has any text content and can trim any whitespace if it does.
58
36
  * @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
@@ -81,13 +59,12 @@ function $isRootTextContentEmptyCurry(isEditorComposing, trim) {
81
59
  }
82
60
 
83
61
  /**
84
- * Returns the root's text content.
85
- * @returns The root's text content.
62
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
63
+ *
64
+ * This source code is licensed under the MIT license found in the
65
+ * LICENSE file in the root directory of this source tree.
66
+ *
86
67
  */
87
- function $rootTextContent() {
88
- const root = $getRoot();
89
- return root.getTextContent();
90
- }
91
68
 
92
69
  /**
93
70
  * Determines if the input should show the placeholder. If anything is in
@@ -138,6 +115,68 @@ function $canShowPlaceholder(isComposing) {
138
115
  function $canShowPlaceholderCurry(isEditorComposing) {
139
116
  return () => $canShowPlaceholder(isEditorComposing);
140
117
  }
118
+
119
+ /**
120
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
121
+ *
122
+ * This source code is licensed under the MIT license found in the
123
+ * LICENSE file in the root directory of this source tree.
124
+ *
125
+ */
126
+
127
+ /**
128
+ * Finds a TextNode with a size larger than targetCharacters and returns
129
+ * the node along with the remaining length of the text.
130
+ * @param root - The RootNode.
131
+ * @param targetCharacters - The number of characters whose TextNode must be larger than.
132
+ * @returns The TextNode and the intersections offset, or null if no TextNode is found.
133
+ */
134
+ function $findTextIntersectionFromCharacters(root, targetCharacters) {
135
+ let node = root.getFirstChild();
136
+ let currentCharacters = 0;
137
+ mainLoop: while (node !== null) {
138
+ if ($isElementNode(node)) {
139
+ const child = node.getFirstChild();
140
+ if (child !== null) {
141
+ node = child;
142
+ continue;
143
+ }
144
+ } else if ($isTextNode(node)) {
145
+ const characters = node.getTextContentSize();
146
+ if (currentCharacters + characters > targetCharacters) {
147
+ return {
148
+ node,
149
+ offset: targetCharacters - currentCharacters
150
+ };
151
+ }
152
+ currentCharacters += characters;
153
+ }
154
+ const sibling = node.getNextSibling();
155
+ if (sibling !== null) {
156
+ node = sibling;
157
+ continue;
158
+ }
159
+ let parent = node.getParent();
160
+ while (parent !== null) {
161
+ const parentSibling = parent.getNextSibling();
162
+ if (parentSibling !== null) {
163
+ node = parentSibling;
164
+ continue mainLoop;
165
+ }
166
+ parent = parent.getParent();
167
+ }
168
+ break;
169
+ }
170
+ return null;
171
+ }
172
+
173
+ /**
174
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
175
+ *
176
+ * This source code is licensed under the MIT license found in the
177
+ * LICENSE file in the root directory of this source tree.
178
+ *
179
+ */
141
180
  /**
142
181
  * Returns a tuple that can be rested (...) into mergeRegister to clean up
143
182
  * node transforms listeners that transforms text into another node, eg. a HashtagNode.
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import * as modDev from './LexicalText.dev.esm.js';
8
- import * as modProd from './LexicalText.prod.esm.js';
7
+ import * as modDev from './LexicalText.dev.mjs';
8
+ import * as modProd from './LexicalText.prod.mjs';
9
9
  const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
10
  export const $canShowPlaceholder = mod.$canShowPlaceholder;
11
11
  export const $canShowPlaceholderCurry = mod.$canShowPlaceholderCurry;
@@ -0,0 +1,14 @@
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
+ const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalText.dev.mjs') : import('./LexicalText.prod.mjs'));
8
+ export const $canShowPlaceholder = mod.$canShowPlaceholder;
9
+ export const $canShowPlaceholderCurry = mod.$canShowPlaceholderCurry;
10
+ export const $findTextIntersectionFromCharacters = mod.$findTextIntersectionFromCharacters;
11
+ export const $isRootTextContentEmpty = mod.$isRootTextContentEmpty;
12
+ export const $isRootTextContentEmptyCurry = mod.$isRootTextContentEmptyCurry;
13
+ export const $rootTextContent = mod.$rootTextContent;
14
+ export const registerLexicalTextEntity = mod.registerLexicalTextEntity;
@@ -4,9 +4,9 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var g=require("lexical");function r(c,h=!0){if(c)return!1;c=t();h&&(c=c.trim());return""===c}function t(){return g.$getRoot().getTextContent()}function u(c){if(!r(c,!1))return!1;c=g.$getRoot().getChildren();let h=c.length;if(1<h)return!1;for(let e=0;e<h;e++){var b=c[e];if(g.$isDecoratorNode(b))return!1;if(g.$isElementNode(b)){if(!g.$isParagraphNode(b)||0!==b.__indent)return!1;b=b.getChildren();let n=b.length;for(let q=0;q<n;q++)if(!g.$isTextNode(b[e]))return!1}}return!0}
7
+ 'use strict';var g=require("lexical");function r(){return g.$getRoot().getTextContent()}function t(c,h=!0){if(c)return!1;c=r();h&&(c=c.trim());return""===c}function u(c){if(!t(c,!1))return!1;c=g.$getRoot().getChildren();let h=c.length;if(1<h)return!1;for(let e=0;e<h;e++){var b=c[e];if(g.$isDecoratorNode(b))return!1;if(g.$isElementNode(b)){if(!g.$isParagraphNode(b)||0!==b.__indent)return!1;b=b.getChildren();let n=b.length;for(let q=0;q<n;q++)if(!g.$isTextNode(b[e]))return!1}}return!0}
8
8
  exports.$canShowPlaceholder=u;exports.$canShowPlaceholderCurry=function(c){return()=>u(c)};exports.$findTextIntersectionFromCharacters=function(c,h){var b=c.getFirstChild();c=0;a:for(;null!==b;){if(g.$isElementNode(b)){var e=b.getFirstChild();if(null!==e){b=e;continue}}else if(g.$isTextNode(b)){e=b.getTextContentSize();if(c+e>h)return{node:b,offset:h-c};c+=e}e=b.getNextSibling();if(null!==e)b=e;else{for(b=b.getParent();null!==b;){e=b.getNextSibling();if(null!==e){b=e;continue a}b=b.getParent()}break}}return null};
9
- exports.$isRootTextContentEmpty=r;exports.$isRootTextContentEmptyCurry=function(c,h){return()=>r(c,h)};exports.$rootTextContent=t;
9
+ exports.$isRootTextContentEmpty=t;exports.$isRootTextContentEmptyCurry=function(c,h){return()=>t(c,h)};exports.$rootTextContent=r;
10
10
  exports.registerLexicalTextEntity=function(c,h,b,e){let n=a=>{const d=g.$createTextNode(a.getTextContent());d.setFormat(a.getFormat());a.replace(d)},q=c.registerNodeTransform(g.TextNode,a=>{if(a.isSimpleText()){var d=a.getPreviousSibling(),l=a.getTextContent(),m=a;if(g.$isTextNode(d)){var k=d.getTextContent(),f=h(k+l);if(d instanceof b){if(null===f||0!==d.getLatest().__mode){n(d);return}f=f.end-k.length;if(0<f){m=l.slice(0,f);m=k+m;d.select();d.setTextContent(m);f===l.length?a.remove():(d=l.slice(f),
11
11
  a.setTextContent(d));return}}else if(null===f||f.start<k.length)return}for(;;){a=h(l);l=f=null===a?"":l.slice(a.end);if(""===f){if(k=m.getNextSibling(),g.$isTextNode(k))if(f=m.getTextContent()+k.getTextContent(),f=h(f),null===f){k instanceof b?n(k):k.markDirty();break}else if(0!==f.start)break}else if(k=h(f),null!==k&&0===k.start)break;if(null===a)break;if(0===a.start&&g.$isTextNode(d)&&d.isTextEntity())continue;let p;0===a.start?[p,m]=m.splitText(a.end):[,p,m]=m.splitText(a.start,a.end);a=e(p);a.setFormat(p.getFormat());
12
12
  p.replace(a);if(null==m)break}}});c=c.registerNodeTransform(b,a=>{var d=a.getTextContent();const l=h(d);null===l||0!==l.start?n(a):d.length>l.end?a.splitText(l.end):(d=a.getPreviousSibling(),g.$isTextNode(d)&&d.isTextEntity()&&(n(d),n(a)),d=a.getNextSibling(),g.$isTextNode(d)&&d.isTextEntity()&&(n(d),a instanceof b&&n(a)))});return[q,c]}
@@ -0,0 +1,7 @@
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
+ import{$getRoot as t,$isDecoratorNode as e,$isElementNode as n,$isParagraphNode as r,$isTextNode as i,TextNode as o,$createTextNode as l}from"lexical";function s(){return t().getTextContent()}function u(t,e=!0){if(t)return!1;let n=s();return e&&(n=n.trim()),""===n}function f(t,e){return()=>u(t,e)}function c(o){if(!u(o,!1))return!1;const l=t().getChildren(),s=l.length;if(s>1)return!1;for(let t=0;t<s;t++){const o=l[t];if(e(o))return!1;if(n(o)){if(!r(o))return!1;if(0!==o.__indent)return!1;const e=o.getChildren(),n=e.length;for(let r=0;r<n;r++){const n=e[t];if(!i(n))return!1}}}return!0}function g(t){return()=>c(t)}function x(t,e){let r=t.getFirstChild(),o=0;t:for(;null!==r;){if(n(r)){const t=r.getFirstChild();if(null!==t){r=t;continue}}else if(i(r)){const t=r.getTextContentSize();if(o+t>e)return{node:r,offset:e-o};o+=t}const t=r.getNextSibling();if(null!==t){r=t;continue}let l=r.getParent();for(;null!==l;){const t=l.getNextSibling();if(null!==t){r=t;continue t}l=l.getParent()}break}return null}function a(t,e,n,r){const s=t=>t instanceof n,u=t=>{const e=l(t.getTextContent());e.setFormat(t.getFormat()),t.replace(e)};return[t.registerNodeTransform(o,(t=>{if(!t.isSimpleText())return;const n=t.getPreviousSibling();let o,l=t.getTextContent(),f=t;if(i(n)){const r=n.getTextContent(),i=e(r+l);if(s(n)){if(null===i||0!==(t=>t.getLatest().__mode)(n))return void u(n);{const e=i.end-r.length;if(e>0){const i=r+l.slice(0,e);if(n.select(),n.setTextContent(i),e===l.length)t.remove();else{const n=l.slice(e);t.setTextContent(n)}return}}}else if(null===i||i.start<r.length)return}for(;;){o=e(l);let t,c=null===o?"":l.slice(o.end);if(l=c,""===c){const t=f.getNextSibling();if(i(t)){c=f.getTextContent()+t.getTextContent();const n=e(c);if(null===n)return void(s(t)?u(t):t.markDirty());if(0!==n.start)return}}else{const t=e(c);if(null!==t&&0===t.start)return}if(null===o)return;if(0===o.start&&i(n)&&n.isTextEntity())continue;0===o.start?[t,f]=f.splitText(o.end):[,t,f]=f.splitText(o.start,o.end);const g=r(t);if(g.setFormat(t.getFormat()),t.replace(g),null==f)return}})),t.registerNodeTransform(n,(t=>{const n=t.getTextContent(),r=e(n);if(null===r||0!==r.start)return void u(t);if(n.length>r.end)return void t.splitText(r.end);const o=t.getPreviousSibling();i(o)&&o.isTextEntity()&&(u(o),u(t));const l=t.getNextSibling();i(l)&&l.isTextEntity()&&(u(l),s(t)&&u(t))}))]}export{c as $canShowPlaceholder,g as $canShowPlaceholderCurry,x as $findTextIntersectionFromCharacters,u as $isRootTextContentEmpty,f as $isRootTextContentEmptyCurry,s as $rootTextContent,a as registerLexicalTextEntity};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Determines if the input should show the placeholder. If anything is in
3
+ * in the root the placeholder should not be shown.
4
+ * @param isComposing - Is the editor in composition mode due to an active Input Method Editor?
5
+ * @returns true if the input should show the placeholder, false otherwise.
6
+ */
7
+ export declare function $canShowPlaceholder(isComposing: boolean): boolean;
8
+ /**
9
+ * Returns a function that executes {@link $canShowPlaceholder}
10
+ * @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
11
+ * @returns A function that executes $canShowPlaceholder with arguments.
12
+ */
13
+ export declare function $canShowPlaceholderCurry(isEditorComposing: boolean): () => boolean;
@@ -0,0 +1,19 @@
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 { RootNode, TextNode } from 'lexical';
9
+ /**
10
+ * Finds a TextNode with a size larger than targetCharacters and returns
11
+ * the node along with the remaining length of the text.
12
+ * @param root - The RootNode.
13
+ * @param targetCharacters - The number of characters whose TextNode must be larger than.
14
+ * @returns The TextNode and the intersections offset, or null if no TextNode is found.
15
+ */
16
+ export declare function $findTextIntersectionFromCharacters(root: RootNode, targetCharacters: number): null | {
17
+ node: TextNode;
18
+ offset: number;
19
+ };
package/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /** @module @lexical/text */
2
1
  /**
3
2
  * Copyright (c) Meta Platforms, Inc. and affiliates.
4
3
  *
@@ -6,76 +5,14 @@
6
5
  * LICENSE file in the root directory of this source tree.
7
6
  *
8
7
  */
9
- import type { Klass, LexicalEditor, RootNode } from 'lexical';
10
8
  import { TextNode } from 'lexical';
11
9
  export type TextNodeWithOffset = {
12
10
  node: TextNode;
13
11
  offset: number;
14
12
  };
15
- /**
16
- * Finds a TextNode with a size larger than targetCharacters and returns
17
- * the node along with the remaining length of the text.
18
- * @param root - The RootNode.
19
- * @param targetCharacters - The number of characters whose TextNode must be larger than.
20
- * @returns The TextNode and the intersections offset, or null if no TextNode is found.
21
- */
22
- export declare function $findTextIntersectionFromCharacters(root: RootNode, targetCharacters: number): null | {
23
- node: TextNode;
24
- offset: number;
25
- };
26
- /**
27
- * Determines if the root has any text content and can trim any whitespace if it does.
28
- * @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
29
- * @param trim - Should the root text have its whitespaced trimmed? Defaults to true.
30
- * @returns true if text content is empty, false if there is text or isEditorComposing is true.
31
- */
32
- export declare function $isRootTextContentEmpty(isEditorComposing: boolean, trim?: boolean): boolean;
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 declare function $isRootTextContentEmptyCurry(isEditorComposing: boolean, trim?: boolean): () => boolean;
40
- /**
41
- * Returns the root's text content.
42
- * @returns The root's text content.
43
- */
44
- export declare function $rootTextContent(): string;
45
- /**
46
- * Determines if the input should show the placeholder. If anything is in
47
- * in the root the placeholder should not be shown.
48
- * @param isComposing - Is the editor in composition mode due to an active Input Method Editor?
49
- * @returns true if the input should show the placeholder, false otherwise.
50
- */
51
- export declare function $canShowPlaceholder(isComposing: boolean): boolean;
52
- /**
53
- * Returns a function that executes {@link $canShowPlaceholder}
54
- * @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
55
- * @returns A function that executes $canShowPlaceholder with arguments.
56
- */
57
- export declare function $canShowPlaceholderCurry(isEditorComposing: boolean): () => boolean;
58
- export type EntityMatch = {
59
- end: number;
60
- start: number;
61
- };
62
- /**
63
- * Returns a tuple that can be rested (...) into mergeRegister to clean up
64
- * node transforms listeners that transforms text into another node, eg. a HashtagNode.
65
- * @example
66
- * ```ts
67
- * useEffect(() => {
68
- return mergeRegister(
69
- ...registerLexicalTextEntity(editor, getMatch, targetNode, createNode),
70
- );
71
- }, [createNode, editor, getMatch, targetNode]);
72
- * ```
73
- * Where targetNode is the type of node containing the text you want to transform (like a text input),
74
- * then getMatch uses a regex to find a matching text and creates the proper node to include the matching text.
75
- * @param editor - The lexical editor.
76
- * @param getMatch - Finds a matching string that satisfies a regex expression.
77
- * @param targetNode - The node type that contains text to match with. eg. HashtagNode
78
- * @param createNode - A function that creates a new node to contain the matched text. eg createHashtagNode
79
- * @returns An array containing the plain text and reverse node transform listeners.
80
- */
81
- export declare function registerLexicalTextEntity<T extends TextNode>(editor: LexicalEditor, getMatch: (text: string) => null | EntityMatch, targetNode: Klass<T>, createNode: (textNode: TextNode) => T): Array<() => void>;
13
+ export { $canShowPlaceholder, $canShowPlaceholderCurry, } from './canShowPlaceholder';
14
+ export { $findTextIntersectionFromCharacters } from './findTextIntersectionFromCharacters';
15
+ export { $isRootTextContentEmpty, $isRootTextContentEmptyCurry, } from './isRootTextContentEmpty';
16
+ export type { EntityMatch } from './registerLexicalTextEntity';
17
+ export { registerLexicalTextEntity } from './registerLexicalTextEntity';
18
+ export { $rootTextContent } from './rootTextContent';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Determines if the root has any text content and can trim any whitespace if it does.
3
+ * @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
4
+ * @param trim - Should the root text have its whitespaced trimmed? Defaults to true.
5
+ * @returns true if text content is empty, false if there is text or isEditorComposing is true.
6
+ */
7
+ export declare function $isRootTextContentEmpty(isEditorComposing: boolean, trim?: boolean): boolean;
8
+ /**
9
+ * Returns a function that executes {@link $isRootTextContentEmpty}
10
+ * @param isEditorComposing - Is the editor in composition mode due to an active Input Method Editor?
11
+ * @param trim - Should the root text have its whitespaced trimmed? Defaults to true.
12
+ * @returns A function that executes $isRootTextContentEmpty based on arguments.
13
+ */
14
+ export declare function $isRootTextContentEmptyCurry(isEditorComposing: boolean, trim?: boolean): () => boolean;
package/package.json CHANGED
@@ -9,16 +9,34 @@
9
9
  "text"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "0.14.2",
12
+ "version": "0.14.4",
13
13
  "main": "LexicalText.js",
14
- "peerDependencies": {
15
- "lexical": "0.14.2"
16
- },
14
+ "types": "index.d.ts",
17
15
  "repository": {
18
16
  "type": "git",
19
17
  "url": "https://github.com/facebook/lexical",
20
18
  "directory": "packages/lexical-text"
21
19
  },
22
- "module": "LexicalText.esm.js",
23
- "sideEffects": false
20
+ "module": "LexicalText.mjs",
21
+ "sideEffects": false,
22
+ "exports": {
23
+ ".": {
24
+ "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"
30
+ },
31
+ "require": {
32
+ "types": "./index.d.ts",
33
+ "development": "./LexicalText.dev.js",
34
+ "production": "./LexicalText.prod.js",
35
+ "default": "./LexicalText.js"
36
+ }
37
+ }
38
+ },
39
+ "dependencies": {
40
+ "lexical": "0.14.4"
41
+ }
24
42
  }
@@ -0,0 +1,32 @@
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 { Klass, LexicalEditor, TextNode } from 'lexical';
9
+ export type EntityMatch = {
10
+ end: number;
11
+ start: number;
12
+ };
13
+ /**
14
+ * Returns a tuple that can be rested (...) into mergeRegister to clean up
15
+ * node transforms listeners that transforms text into another node, eg. a HashtagNode.
16
+ * @example
17
+ * ```ts
18
+ * useEffect(() => {
19
+ return mergeRegister(
20
+ ...registerLexicalTextEntity(editor, getMatch, targetNode, createNode),
21
+ );
22
+ }, [createNode, editor, getMatch, targetNode]);
23
+ * ```
24
+ * Where targetNode is the type of node containing the text you want to transform (like a text input),
25
+ * then getMatch uses a regex to find a matching text and creates the proper node to include the matching text.
26
+ * @param editor - The lexical editor.
27
+ * @param getMatch - Finds a matching string that satisfies a regex expression.
28
+ * @param targetNode - The node type that contains text to match with. eg. HashtagNode
29
+ * @param createNode - A function that creates a new node to contain the matched text. eg createHashtagNode
30
+ * @returns An array containing the plain text and reverse node transform listeners.
31
+ */
32
+ export declare function registerLexicalTextEntity<T extends TextNode>(editor: LexicalEditor, getMatch: (text: string) => null | EntityMatch, targetNode: Klass<T>, createNode: (textNode: TextNode) => T): Array<() => void>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns the root's text content.
3
+ * @returns The root's text content.
4
+ */
5
+ export declare function $rootTextContent(): string;
@@ -1,7 +0,0 @@
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
- import{$isElementNode as t,$isTextNode as e,$getRoot as n,$isDecoratorNode as r,$isParagraphNode as i,TextNode as o,$createTextNode as l}from"lexical";function s(n,r){let i=n.getFirstChild(),o=0;t:for(;null!==i;){if(t(i)){const t=i.getFirstChild();if(null!==t){i=t;continue}}else if(e(i)){const t=i.getTextContentSize();if(o+t>r)return{node:i,offset:r-o};o+=t}const n=i.getNextSibling();if(null!==n){i=n;continue}let l=i.getParent();for(;null!==l;){const t=l.getNextSibling();if(null!==t){i=t;continue t}l=l.getParent()}break}return null}function u(t,e=!0){if(t)return!1;let n=c();return e&&(n=n.trim()),""===n}function f(t,e){return()=>u(t,e)}function c(){return n().getTextContent()}function g(o){if(!u(o,!1))return!1;const l=n().getChildren(),s=l.length;if(s>1)return!1;for(let n=0;n<s;n++){const o=l[n];if(r(o))return!1;if(t(o)){if(!i(o))return!1;if(0!==o.__indent)return!1;const t=o.getChildren(),r=t.length;for(let i=0;i<r;i++){const r=t[n];if(!e(r))return!1}}}return!0}function x(t){return()=>g(t)}function a(t,n,r,i){const s=t=>t instanceof r,u=t=>{const e=l(t.getTextContent());e.setFormat(t.getFormat()),t.replace(e)};return[t.registerNodeTransform(o,(t=>{if(!t.isSimpleText())return;const r=t.getPreviousSibling();let o,l=t.getTextContent(),f=t;if(e(r)){const e=r.getTextContent(),i=n(e+l);if(s(r)){if(null===i||0!==(t=>t.getLatest().__mode)(r))return void u(r);{const n=i.end-e.length;if(n>0){const i=e+l.slice(0,n);if(r.select(),r.setTextContent(i),n===l.length)t.remove();else{const e=l.slice(n);t.setTextContent(e)}return}}}else if(null===i||i.start<e.length)return}for(;;){o=n(l);let t,c=null===o?"":l.slice(o.end);if(l=c,""===c){const t=f.getNextSibling();if(e(t)){c=f.getTextContent()+t.getTextContent();const e=n(c);if(null===e)return void(s(t)?u(t):t.markDirty());if(0!==e.start)return}}else{const t=n(c);if(null!==t&&0===t.start)return}if(null===o)return;if(0===o.start&&e(r)&&r.isTextEntity())continue;0===o.start?[t,f]=f.splitText(o.end):[,t,f]=f.splitText(o.start,o.end);const g=i(t);if(g.setFormat(t.getFormat()),t.replace(g),null==f)return}})),t.registerNodeTransform(r,(t=>{const r=t.getTextContent(),i=n(r);if(null===i||0!==i.start)return void u(t);if(r.length>i.end)return void t.splitText(i.end);const o=t.getPreviousSibling();e(o)&&o.isTextEntity()&&(u(o),u(t));const l=t.getNextSibling();e(l)&&l.isTextEntity()&&(u(l),s(t)&&u(t))}))]}export{g as $canShowPlaceholder,x as $canShowPlaceholderCurry,s as $findTextIntersectionFromCharacters,u as $isRootTextContentEmpty,f as $isRootTextContentEmptyCurry,c as $rootTextContent,a as registerLexicalTextEntity};