@lexical/react 0.1.14 → 0.1.15

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.
Files changed (33) hide show
  1. package/DEPRECATED_useLexicalAutoFormatter.dev.js +283 -295
  2. package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -21
  3. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +3 -72
  4. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -2
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +11 -63
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +6 -7
  7. package/DEPRECATED_useLexicalPlainText.dev.js +16 -41
  8. package/DEPRECATED_useLexicalPlainText.prod.js +13 -14
  9. package/DEPRECATED_useLexicalRichText.dev.js +24 -49
  10. package/DEPRECATED_useLexicalRichText.prod.js +15 -15
  11. package/LexicalAutoFormatterPlugin.dev.js +283 -295
  12. package/LexicalAutoFormatterPlugin.prod.js +19 -21
  13. package/LexicalAutoLinkPlugin.dev.js +2 -2
  14. package/LexicalAutoLinkPlugin.prod.js +2 -2
  15. package/LexicalCharacterLimitPlugin.dev.js +11 -63
  16. package/LexicalCharacterLimitPlugin.prod.js +8 -9
  17. package/LexicalCollaborationPlugin.d.ts +3 -1
  18. package/LexicalCollaborationPlugin.dev.js +40 -6
  19. package/LexicalCollaborationPlugin.js.flow +4 -1
  20. package/LexicalCollaborationPlugin.prod.js +8 -7
  21. package/LexicalHashtagPlugin.dev.js +16 -13
  22. package/LexicalHashtagPlugin.prod.js +7 -7
  23. package/LexicalOnChangePlugin.dev.js +15 -2
  24. package/LexicalOnChangePlugin.prod.js +2 -1
  25. package/LexicalPlainTextPlugin.dev.js +20 -113
  26. package/LexicalPlainTextPlugin.prod.js +11 -12
  27. package/LexicalRichTextPlugin.dev.js +28 -121
  28. package/LexicalRichTextPlugin.prod.js +12 -13
  29. package/LexicalTablePlugin.dev.js +9 -5
  30. package/LexicalTablePlugin.prod.js +2 -2
  31. package/package.json +9 -7
  32. package/useLexicalIsTextContentEmpty.dev.js +3 -32
  33. package/useLexicalIsTextContentEmpty.prod.js +1 -2
@@ -8,78 +8,11 @@
8
8
 
9
9
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
10
  var React = require('react');
11
- var lexical = require('lexical');
11
+ var text = require('@lexical/text');
12
12
  var reactDom = require('react-dom');
13
13
  var clipboard = require('@lexical/clipboard');
14
-
15
- /**
16
- * Copyright (c) Meta Platforms, Inc. and affiliates.
17
- *
18
- * This source code is licensed under the MIT license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- *
21
- *
22
- */
23
- function $textContent() {
24
- const root = lexical.$getRoot();
25
- return root.getTextContent();
26
- }
27
- function $isTextContentEmpty(isEditorComposing, trim = true) {
28
- if (isEditorComposing) {
29
- return false;
30
- }
31
-
32
- let text = $textContent();
33
-
34
- if (trim) {
35
- text = text.trim();
36
- }
37
-
38
- return text === '';
39
- }
40
- function $canShowPlaceholder(isComposing) {
41
- if (!$isTextContentEmpty(isComposing, false)) {
42
- return false;
43
- }
44
-
45
- const root = lexical.$getRoot();
46
- const children = root.getChildren();
47
- const childrenLength = children.length;
48
-
49
- if (childrenLength > 1) {
50
- return false;
51
- }
52
-
53
- for (let i = 0; i < childrenLength; i++) {
54
- const topBlock = children[i];
55
-
56
- if (lexical.$isElementNode(topBlock)) {
57
- if (topBlock.__type !== 'paragraph') {
58
- return false;
59
- }
60
-
61
- if (topBlock.__indent !== 0) {
62
- return false;
63
- }
64
-
65
- const topBlockChildren = topBlock.getChildren();
66
- const topBlockChildrenLength = topBlockChildren.length;
67
-
68
- for (let s = 0; s < topBlockChildrenLength; s++) {
69
- const child = topBlockChildren[i];
70
-
71
- if (!lexical.$isTextNode(child)) {
72
- return false;
73
- }
74
- }
75
- }
76
- }
77
-
78
- return true;
79
- }
80
- function $canShowPlaceholderCurry(isEditorComposing) {
81
- return () => $canShowPlaceholder(isEditorComposing);
82
- }
14
+ var selection = require('@lexical/selection');
15
+ var lexical = require('lexical');
83
16
 
84
17
  /**
85
18
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -111,13 +44,13 @@ var useLayoutEffect = useLayoutEffectImpl;
111
44
  *
112
45
  */
113
46
  function useLexicalCanShowPlaceholder(editor) {
114
- const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing())));
47
+ const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
115
48
  useLayoutEffect(() => {
116
49
  return editor.addListener('update', ({
117
50
  editorState
118
51
  }) => {
119
52
  const isComposing = editor.isComposing();
120
- const currentCanShowPlaceholder = editorState.read($canShowPlaceholderCurry(isComposing));
53
+ const currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
121
54
  setCanShowPlaceholder(currentCanShowPlaceholder);
122
55
  });
123
56
  }, [editor]);
@@ -161,32 +94,6 @@ function useDecorators(editor) {
161
94
  }, [decorators, editor]);
162
95
  }
163
96
 
164
- /**
165
- * Copyright (c) Meta Platforms, Inc. and affiliates.
166
- *
167
- * This source code is licensed under the MIT license found in the
168
- * LICENSE file in the root directory of this source tree.
169
- *
170
- *
171
- */
172
-
173
- function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity) {
174
- selection.modify(isHoldingShift ? 'extend' : 'move', isBackward, granularity);
175
- }
176
- function $isParentElementRTL(selection) {
177
- const anchorNode = selection.anchor.getNode();
178
- const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
179
- return parent.getDirection() === 'rtl';
180
- }
181
- function $moveCharacter(selection, isHoldingShift, isBackward) {
182
- const isRTL = $isParentElementRTL(selection);
183
- $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
184
- }
185
- function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
186
- const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
187
- return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
188
- }
189
-
190
97
  /**
191
98
  * Copyright (c) Meta Platforms, Inc. and affiliates.
192
99
  *
@@ -391,9 +298,9 @@ function useLexicalDragonSupport(editor) {
391
298
  function usePlainTextSetup(editor, initialEditorState) {
392
299
  useLayoutEffect(() => {
393
300
  const removeListener = editor.addListener('command', (type, payload) => {
394
- const selection = lexical.$getSelection();
301
+ const selection$1 = lexical.$getSelection();
395
302
 
396
- if (!lexical.$isRangeSelection(selection)) {
303
+ if (!lexical.$isRangeSelection(selection$1)) {
397
304
  return false;
398
305
  }
399
306
 
@@ -401,21 +308,21 @@ function usePlainTextSetup(editor, initialEditorState) {
401
308
  case 'deleteCharacter':
402
309
  {
403
310
  const isBackward = payload;
404
- selection.deleteCharacter(isBackward);
311
+ selection$1.deleteCharacter(isBackward);
405
312
  return true;
406
313
  }
407
314
 
408
315
  case 'deleteWord':
409
316
  {
410
317
  const isBackward = payload;
411
- selection.deleteWord(isBackward);
318
+ selection$1.deleteWord(isBackward);
412
319
  return true;
413
320
  }
414
321
 
415
322
  case 'deleteLine':
416
323
  {
417
324
  const isBackward = payload;
418
- selection.deleteLine(isBackward);
325
+ selection$1.deleteLine(isBackward);
419
326
  return true;
420
327
  }
421
328
 
@@ -424,17 +331,17 @@ function usePlainTextSetup(editor, initialEditorState) {
424
331
  const eventOrText = payload;
425
332
 
426
333
  if (typeof eventOrText === 'string') {
427
- selection.insertText(eventOrText);
334
+ selection$1.insertText(eventOrText);
428
335
  } else {
429
336
  const dataTransfer = eventOrText.dataTransfer;
430
337
 
431
338
  if (dataTransfer != null) {
432
- clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
339
+ clipboard.$insertDataTransferForPlainText(dataTransfer, selection$1);
433
340
  } else {
434
341
  const data = eventOrText.data;
435
342
 
436
343
  if (data) {
437
- selection.insertText(data);
344
+ selection$1.insertText(data);
438
345
  }
439
346
  }
440
347
  }
@@ -443,16 +350,16 @@ function usePlainTextSetup(editor, initialEditorState) {
443
350
  }
444
351
 
445
352
  case 'removeText':
446
- selection.removeText();
353
+ selection$1.removeText();
447
354
  return true;
448
355
 
449
356
  case 'insertLineBreak':
450
357
  const selectStart = payload;
451
- selection.insertLineBreak(selectStart);
358
+ selection$1.insertLineBreak(selectStart);
452
359
  return true;
453
360
 
454
361
  case 'insertParagraph':
455
- selection.insertLineBreak();
362
+ selection$1.insertLineBreak();
456
363
  return true;
457
364
 
458
365
  case 'indentContent':
@@ -471,9 +378,9 @@ function usePlainTextSetup(editor, initialEditorState) {
471
378
  const event = payload;
472
379
  const isHoldingShift = event.shiftKey;
473
380
 
474
- if ($shouldOverrideDefaultCharacterSelection(selection, true)) {
381
+ if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
475
382
  event.preventDefault();
476
- $moveCharacter(selection, isHoldingShift, true);
383
+ selection.$moveCharacter(selection$1, isHoldingShift, true);
477
384
  return true;
478
385
  }
479
386
 
@@ -485,9 +392,9 @@ function usePlainTextSetup(editor, initialEditorState) {
485
392
  const event = payload;
486
393
  const isHoldingShift = event.shiftKey;
487
394
 
488
- if ($shouldOverrideDefaultCharacterSelection(selection, false)) {
395
+ if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
489
396
  event.preventDefault();
490
- $moveCharacter(selection, isHoldingShift, false);
397
+ selection.$moveCharacter(selection$1, isHoldingShift, false);
491
398
  return true;
492
399
  }
493
400
 
@@ -4,15 +4,14 @@
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
- var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),t=require("lexical"),u=require("react-dom"),v=require("@lexical/clipboard");function w(a,d=!0){if(a)return!1;a=t.$getRoot().getTextContent();d&&(a=a.trim());return""===a}
8
- function x(a){if(!w(a,!1))return!1;a=t.$getRoot().getChildren();const d=a.length;if(1<d)return!1;for(let c=0;c<d;c++){var e=a[c];if(t.$isElementNode(e)){if("paragraph"!==e.__type||0!==e.__indent)return!1;e=e.getChildren();const b=e.length;for(let f=0;f<b;f++)if(!t.$isTextNode(e[c]))return!1}}return!0}function y(a){return()=>x(a)}var z="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
9
- function A(a){const [d,e]=h.useState(a.getEditorState().read(y(a.isComposing())));z(()=>a.addListener("update",({editorState:c})=>{const b=a.isComposing();c=c.read(y(b));e(c)}),[a]);return d}function C(a){const [d,e]=h.useState(()=>a.getDecorators());z(()=>a.addListener("decorator",c=>{u.flushSync(()=>{e(c)})}),[a]);return h.useMemo(()=>{const c=[],b=Object.keys(d);for(let p=0;p<b.length;p++){var f=b[p];const r=d[f];f=a.getElementByKey(f);null!==f&&c.push(u.createPortal(r,f))}return c},[d,a])}
10
- function D(a){a=a.anchor.getNode();return"rtl"===(t.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function E(a,d){a=t.$getDecoratorNode(a.focus,d);return t.$isDecoratorNode(a)&&!a.isIsolated()}function F(a,d){a.preventDefault();d.update(()=>{const e=t.$getSelection(),c=a.clipboardData;null!=c&&t.$isRangeSelection(e)&&v.$insertDataTransferForPlainText(c,e)})}function G(a,d){H(a,d);d.update(()=>{const e=t.$getSelection();t.$isRangeSelection(e)&&e.removeText()})}
11
- function H(a,d){a.preventDefault();d.update(()=>{const e=a.clipboardData,c=t.$getSelection();if(null!==c&&null!=e){const b=v.getHtmlContent(d);null!==b&&e.setData("text/html",b);e.setData("text/plain",c.getTextContent())}})}const I={tag:"history-merge"};
12
- function J(a,d){if(null!==d)if(void 0===d)a.update(()=>{var e=t.$getRoot();if(null===e.getFirstChild()){const c=t.$createParagraphNode();e.append(c);e=document.activeElement;(null!==t.$getSelection()||null!==e&&e===a.getRootElement())&&c.select()}},I);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,I);break;case "object":a.setEditorState(d,I);break;case "function":a.update(d,I)}}
13
- function K(a){h.useEffect(()=>{const d=e=>{var c=a.getRootElement();if(document.activeElement===c&&(c=e.data,"string"===typeof c)){try{var b=JSON.parse(c)}catch(f){return}if(b&&"nuanria_messaging"===b.protocol&&"request"===b.type&&(b=b.payload)&&"makeChanges"===b.functionId&&(b=b.args)){const [f,p,r,B,L]=b;a.update(()=>{const q=t.$getSelection();if(t.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;t.$isTextNode(k)&&0<=f&&0<=p&&(l=f,m=f+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
14
- r)q.insertRawText(r),k=n.getNode();t.$isTextNode(k)&&(l=B,m=B+L,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));e.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
15
- function M(a,d){z(()=>{const e=a.addListener("command",(c,b)=>{const f=t.$getSelection();if(!t.$isRangeSelection(f))return!1;switch(c){case "deleteCharacter":return f.deleteCharacter(b),!0;case "deleteWord":return f.deleteWord(b),!0;case "deleteLine":return f.deleteLine(b),!0;case "insertText":return"string"===typeof b?f.insertText(b):(c=b.dataTransfer,null!=c?v.$insertDataTransferForPlainText(c,f):(b=b.data)&&f.insertText(b)),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(b),
16
- !0;case "insertParagraph":return f.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(E(f,!0))return b.preventDefault(),b=c,c=D(f),f.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(E(f,!1))return b.preventDefault(),b=c,c=D(f),f.modify(b?"extend":"move",c,"character"),!0;break;case "keyBackspace":return b.preventDefault(),
17
- a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(b,a),!0;case "cut":return G(b,a),!0;case "paste":return F(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);J(a,d);return e},[a]);K(a)}
18
- module.exports=function({contentEditable:a,placeholder:d,initialEditorState:e}){const [c]=g.useLexicalComposerContext(),b=A(c);M(c,e);e=C(c);return h.createElement(h.Fragment,null,a,b&&d,e)};
7
+ var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),r=require("@lexical/text"),u=require("react-dom"),v=require("@lexical/clipboard"),w=require("@lexical/selection"),x=require("lexical"),y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
8
+ function z(a){const [d,e]=h.useState(a.getEditorState().read(r.$canShowPlaceholderCurry(a.isComposing())));y(()=>a.addListener("update",({editorState:c})=>{const b=a.isComposing();c=c.read(r.$canShowPlaceholderCurry(b));e(c)}),[a]);return d}
9
+ function B(a){const [d,e]=h.useState(()=>a.getDecorators());y(()=>a.addListener("decorator",c=>{u.flushSync(()=>{e(c)})}),[a]);return h.useMemo(()=>{const c=[],b=Object.keys(d);for(let p=0;p<b.length;p++){var f=b[p];const t=d[f];f=a.getElementByKey(f);null!==f&&c.push(u.createPortal(t,f))}return c},[d,a])}function C(a,d){a.preventDefault();d.update(()=>{const e=x.$getSelection(),c=a.clipboardData;null!=c&&x.$isRangeSelection(e)&&v.$insertDataTransferForPlainText(c,e)})}
10
+ function D(a,d){E(a,d);d.update(()=>{const e=x.$getSelection();x.$isRangeSelection(e)&&e.removeText()})}function E(a,d){a.preventDefault();d.update(()=>{const e=a.clipboardData,c=x.$getSelection();if(null!==c&&null!=e){const b=v.getHtmlContent(d);null!==b&&e.setData("text/html",b);e.setData("text/plain",c.getTextContent())}})}const F={tag:"history-merge"};
11
+ function G(a,d){if(null!==d)if(void 0===d)a.update(()=>{var e=x.$getRoot();if(null===e.getFirstChild()){const c=x.$createParagraphNode();e.append(c);e=document.activeElement;(null!==x.$getSelection()||null!==e&&e===a.getRootElement())&&c.select()}},F);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,F);break;case "object":a.setEditorState(d,F);break;case "function":a.update(d,F)}}
12
+ function H(a){h.useEffect(()=>{const d=e=>{var c=a.getRootElement();if(document.activeElement===c&&(c=e.data,"string"===typeof c)){try{var b=JSON.parse(c)}catch(f){return}if(b&&"nuanria_messaging"===b.protocol&&"request"===b.type&&(b=b.payload)&&"makeChanges"===b.functionId&&(b=b.args)){const [f,p,t,A,I]=b;a.update(()=>{const q=x.$getSelection();if(x.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;x.$isTextNode(k)&&0<=f&&0<=p&&(l=f,m=f+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
13
+ t)q.insertRawText(t),k=n.getNode();x.$isTextNode(k)&&(l=A,m=A+I,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));e.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
14
+ function J(a,d){y(()=>{const e=a.addListener("command",(c,b)=>{const f=x.$getSelection();if(!x.$isRangeSelection(f))return!1;switch(c){case "deleteCharacter":return f.deleteCharacter(b),!0;case "deleteWord":return f.deleteWord(b),!0;case "deleteLine":return f.deleteLine(b),!0;case "insertText":return"string"===typeof b?f.insertText(b):(c=b.dataTransfer,null!=c?v.$insertDataTransferForPlainText(c,f):(b=b.data)&&f.insertText(b)),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(b),
15
+ !0;case "insertParagraph":return f.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(w.$shouldOverrideDefaultCharacterSelection(f,!0))return b.preventDefault(),w.$moveCharacter(f,c,!0),!0;break;case "keyArrowRight":c=b.shiftKey;if(w.$shouldOverrideDefaultCharacterSelection(f,!1))return b.preventDefault(),w.$moveCharacter(f,c,!1),!0;break;
16
+ case "keyBackspace":return b.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "copy":return E(b,a),!0;case "cut":return D(b,a),!0;case "paste":return C(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);G(a,d);return e},[a]);H(a)}
17
+ module.exports=function({contentEditable:a,placeholder:d,initialEditorState:e}){const [c]=g.useLexicalComposerContext(),b=z(c);J(c,e);e=B(c);return h.createElement(h.Fragment,null,a,b&&d,e)};
@@ -8,78 +8,11 @@
8
8
 
9
9
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
10
  var React = require('react');
11
- var lexical = require('lexical');
11
+ var text = require('@lexical/text');
12
12
  var reactDom = require('react-dom');
13
13
  var clipboard = require('@lexical/clipboard');
14
-
15
- /**
16
- * Copyright (c) Meta Platforms, Inc. and affiliates.
17
- *
18
- * This source code is licensed under the MIT license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- *
21
- *
22
- */
23
- function $textContent() {
24
- const root = lexical.$getRoot();
25
- return root.getTextContent();
26
- }
27
- function $isTextContentEmpty(isEditorComposing, trim = true) {
28
- if (isEditorComposing) {
29
- return false;
30
- }
31
-
32
- let text = $textContent();
33
-
34
- if (trim) {
35
- text = text.trim();
36
- }
37
-
38
- return text === '';
39
- }
40
- function $canShowPlaceholder(isComposing) {
41
- if (!$isTextContentEmpty(isComposing, false)) {
42
- return false;
43
- }
44
-
45
- const root = lexical.$getRoot();
46
- const children = root.getChildren();
47
- const childrenLength = children.length;
48
-
49
- if (childrenLength > 1) {
50
- return false;
51
- }
52
-
53
- for (let i = 0; i < childrenLength; i++) {
54
- const topBlock = children[i];
55
-
56
- if (lexical.$isElementNode(topBlock)) {
57
- if (topBlock.__type !== 'paragraph') {
58
- return false;
59
- }
60
-
61
- if (topBlock.__indent !== 0) {
62
- return false;
63
- }
64
-
65
- const topBlockChildren = topBlock.getChildren();
66
- const topBlockChildrenLength = topBlockChildren.length;
67
-
68
- for (let s = 0; s < topBlockChildrenLength; s++) {
69
- const child = topBlockChildren[i];
70
-
71
- if (!lexical.$isTextNode(child)) {
72
- return false;
73
- }
74
- }
75
- }
76
- }
77
-
78
- return true;
79
- }
80
- function $canShowPlaceholderCurry(isEditorComposing) {
81
- return () => $canShowPlaceholder(isEditorComposing);
82
- }
14
+ var selection = require('@lexical/selection');
15
+ var lexical = require('lexical');
83
16
 
84
17
  /**
85
18
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -111,13 +44,13 @@ var useLayoutEffect = useLayoutEffectImpl;
111
44
  *
112
45
  */
113
46
  function useLexicalCanShowPlaceholder(editor) {
114
- const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing())));
47
+ const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
115
48
  useLayoutEffect(() => {
116
49
  return editor.addListener('update', ({
117
50
  editorState
118
51
  }) => {
119
52
  const isComposing = editor.isComposing();
120
- const currentCanShowPlaceholder = editorState.read($canShowPlaceholderCurry(isComposing));
53
+ const currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
121
54
  setCanShowPlaceholder(currentCanShowPlaceholder);
122
55
  });
123
56
  }, [editor]);
@@ -161,32 +94,6 @@ function useDecorators(editor) {
161
94
  }, [decorators, editor]);
162
95
  }
163
96
 
164
- /**
165
- * Copyright (c) Meta Platforms, Inc. and affiliates.
166
- *
167
- * This source code is licensed under the MIT license found in the
168
- * LICENSE file in the root directory of this source tree.
169
- *
170
- *
171
- */
172
-
173
- function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity) {
174
- selection.modify(isHoldingShift ? 'extend' : 'move', isBackward, granularity);
175
- }
176
- function $isParentElementRTL(selection) {
177
- const anchorNode = selection.anchor.getNode();
178
- const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
179
- return parent.getDirection() === 'rtl';
180
- }
181
- function $moveCharacter(selection, isHoldingShift, isBackward) {
182
- const isRTL = $isParentElementRTL(selection);
183
- $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
184
- }
185
- function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
186
- const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
187
- return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
188
- }
189
-
190
97
  /**
191
98
  * Copyright (c) Meta Platforms, Inc. and affiliates.
192
99
  *
@@ -396,14 +303,14 @@ function useLexicalDragonSupport(editor) {
396
303
  function useRichTextSetup(editor, initialEditorState) {
397
304
  useLayoutEffect(() => {
398
305
  const removeListener = editor.addListener('command', (type, payload) => {
399
- const selection = lexical.$getSelection();
306
+ const selection$1 = lexical.$getSelection();
400
307
 
401
- if (type === 'click' && lexical.$isNodeSelection(selection)) {
402
- selection.clear();
308
+ if (type === 'click' && lexical.$isNodeSelection(selection$1)) {
309
+ selection$1.clear();
403
310
  return true;
404
311
  }
405
312
 
406
- if (!lexical.$isRangeSelection(selection)) {
313
+ if (!lexical.$isRangeSelection(selection$1)) {
407
314
  return false;
408
315
  }
409
316
 
@@ -411,21 +318,21 @@ function useRichTextSetup(editor, initialEditorState) {
411
318
  case 'deleteCharacter':
412
319
  {
413
320
  const isBackward = payload;
414
- selection.deleteCharacter(isBackward);
321
+ selection$1.deleteCharacter(isBackward);
415
322
  return true;
416
323
  }
417
324
 
418
325
  case 'deleteWord':
419
326
  {
420
327
  const isBackward = payload;
421
- selection.deleteWord(isBackward);
328
+ selection$1.deleteWord(isBackward);
422
329
  return true;
423
330
  }
424
331
 
425
332
  case 'deleteLine':
426
333
  {
427
334
  const isBackward = payload;
428
- selection.deleteLine(isBackward);
335
+ selection$1.deleteLine(isBackward);
429
336
  return true;
430
337
  }
431
338
 
@@ -434,17 +341,17 @@ function useRichTextSetup(editor, initialEditorState) {
434
341
  const eventOrText = payload;
435
342
 
436
343
  if (typeof eventOrText === 'string') {
437
- selection.insertText(eventOrText);
344
+ selection$1.insertText(eventOrText);
438
345
  } else {
439
346
  const dataTransfer = eventOrText.dataTransfer;
440
347
 
441
348
  if (dataTransfer != null) {
442
- clipboard.$insertDataTransferForRichText(dataTransfer, selection, editor);
349
+ clipboard.$insertDataTransferForRichText(dataTransfer, selection$1, editor);
443
350
  } else {
444
351
  const data = eventOrText.data;
445
352
 
446
353
  if (data) {
447
- selection.insertText(data);
354
+ selection$1.insertText(data);
448
355
  }
449
356
  }
450
357
  }
@@ -453,20 +360,20 @@ function useRichTextSetup(editor, initialEditorState) {
453
360
  }
454
361
 
455
362
  case 'removeText':
456
- selection.removeText();
363
+ selection$1.removeText();
457
364
  return true;
458
365
 
459
366
  case 'formatText':
460
367
  {
461
368
  const format = payload;
462
- selection.formatText(format);
369
+ selection$1.formatText(format);
463
370
  return true;
464
371
  }
465
372
 
466
373
  case 'formatElement':
467
374
  {
468
375
  const format = payload;
469
- const node = selection.anchor.getNode();
376
+ const node = selection$1.anchor.getNode();
470
377
  const element = lexical.$isElementNode(node) ? node : node.getParentOrThrow();
471
378
  element.setFormat(format);
472
379
  return true;
@@ -474,17 +381,17 @@ function useRichTextSetup(editor, initialEditorState) {
474
381
 
475
382
  case 'insertLineBreak':
476
383
  const selectStart = payload;
477
- selection.insertLineBreak(selectStart);
384
+ selection$1.insertLineBreak(selectStart);
478
385
  return true;
479
386
 
480
387
  case 'insertParagraph':
481
- selection.insertParagraph();
388
+ selection$1.insertParagraph();
482
389
  return true;
483
390
 
484
391
  case 'indentContent':
485
392
  {
486
393
  // Handle code blocks
487
- const anchor = selection.anchor;
394
+ const anchor = selection$1.anchor;
488
395
  const parentBlock = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
489
396
 
490
397
  if (parentBlock.canInsertTab()) {
@@ -501,7 +408,7 @@ function useRichTextSetup(editor, initialEditorState) {
501
408
  case 'outdentContent':
502
409
  {
503
410
  // Handle code blocks
504
- const anchor = selection.anchor;
411
+ const anchor = selection$1.anchor;
505
412
  const anchorNode = anchor.getNode();
506
413
  const parentBlock = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
507
414
 
@@ -526,9 +433,9 @@ function useRichTextSetup(editor, initialEditorState) {
526
433
  const event = payload;
527
434
  const isHoldingShift = event.shiftKey;
528
435
 
529
- if ($shouldOverrideDefaultCharacterSelection(selection, true)) {
436
+ if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
530
437
  event.preventDefault();
531
- $moveCharacter(selection, isHoldingShift, true);
438
+ selection.$moveCharacter(selection$1, isHoldingShift, true);
532
439
  return true;
533
440
  }
534
441
 
@@ -540,9 +447,9 @@ function useRichTextSetup(editor, initialEditorState) {
540
447
  const event = payload;
541
448
  const isHoldingShift = event.shiftKey;
542
449
 
543
- if ($shouldOverrideDefaultCharacterSelection(selection, false)) {
450
+ if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
544
451
  event.preventDefault();
545
- $moveCharacter(selection, isHoldingShift, false);
452
+ selection.$moveCharacter(selection$1, isHoldingShift, false);
546
453
  return true;
547
454
  }
548
455
 
@@ -555,9 +462,9 @@ function useRichTextSetup(editor, initialEditorState) {
555
462
  event.preventDefault();
556
463
  const {
557
464
  anchor
558
- } = selection;
465
+ } = selection$1;
559
466
 
560
- if (selection.isCollapsed() && anchor.offset === 0) {
467
+ if (selection$1.isCollapsed() && anchor.offset === 0) {
561
468
  const element = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
562
469
 
563
470
  if (element.getIndent() > 0) {
@@ -4,16 +4,15 @@
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
- var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),r=require("lexical"),u=require("react-dom"),v=require("@lexical/clipboard");function w(a,e=!0){if(a)return!1;a=r.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
8
- function x(a){if(!w(a,!1))return!1;a=r.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let d=0;d<e;d++){var f=a[d];if(r.$isElementNode(f)){if("paragraph"!==f.__type||0!==f.__indent)return!1;f=f.getChildren();const c=f.length;for(let b=0;b<c;b++)if(!r.$isTextNode(f[d]))return!1}}return!0}function y(a){return()=>x(a)}var z="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
9
- function A(a){const [e,f]=h.useState(a.getEditorState().read(y(a.isComposing())));z(()=>a.addListener("update",({editorState:d})=>{const c=a.isComposing();d=d.read(y(c));f(d)}),[a]);return e}function C(a){const [e,f]=h.useState(()=>a.getDecorators());z(()=>a.addListener("decorator",d=>{u.flushSync(()=>{f(d)})}),[a]);return h.useMemo(()=>{const d=[],c=Object.keys(e);for(let p=0;p<c.length;p++){var b=c[p];const t=e[b];b=a.getElementByKey(b);null!==b&&d.push(u.createPortal(t,b))}return d},[e,a])}
10
- function D(a){a=a.anchor.getNode();return"rtl"===(r.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function E(a,e){a=r.$getDecoratorNode(a.focus,e);return r.$isDecoratorNode(a)&&!a.isIsolated()}function F(a,e){G(a,e);e.update(()=>{const f=r.$getSelection();r.$isRangeSelection(f)&&f.removeText()})}
11
- function G(a,e){a.preventDefault();e.update(()=>{const f=a.clipboardData,d=r.$getSelection();if(null!==d&&null!=f){const c=v.getHtmlContent(e),b=v.$getLexicalContent(e);null!==c&&f.setData("text/html",c);null!==b&&f.setData("application/x-lexical-editor",b);f.setData("text/plain",d.getTextContent())}})}function H(a,e){a.preventDefault();e.update(()=>{const f=r.$getSelection(),d=a.clipboardData;null!=d&&r.$isRangeSelection(f)&&v.$insertDataTransferForRichText(d,f,e)})}const I={tag:"history-merge"};
12
- function J(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=r.$getRoot();if(null===f.getFirstChild()){const d=r.$createParagraphNode();f.append(d);f=document.activeElement;(null!==r.$getSelection()||null!==f&&f===a.getRootElement())&&d.select()}},I);else if(null!==e)switch(typeof e){case "string":e=a.parseEditorState(e);a.setEditorState(e,I);break;case "object":a.setEditorState(e,I);break;case "function":a.update(e,I)}}
13
- function K(a){h.useEffect(()=>{const e=f=>{var d=a.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var c=JSON.parse(d)}catch(b){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [b,p,t,B,L]=c;a.update(()=>{const q=r.$getSelection();if(r.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;r.$isTextNode(k)&&0<=b&&0<=p&&(l=b,m=b+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
14
- t)q.insertRawText(t),k=n.getNode();r.$isTextNode(k)&&(l=B,m=B+L,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));f.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
15
- function M(a,e){z(()=>{const f=a.addListener("command",(d,c)=>{var b=r.$getSelection();if("click"===d&&r.$isNodeSelection(b))return b.clear(),!0;if(!r.$isRangeSelection(b))return!1;switch(d){case "deleteCharacter":return b.deleteCharacter(c),!0;case "deleteWord":return b.deleteWord(c),!0;case "deleteLine":return b.deleteLine(c),!0;case "insertText":return"string"===typeof c?b.insertText(c):(d=c.dataTransfer,null!=d?v.$insertDataTransferForRichText(d,b,a):(c=c.data)&&b.insertText(c)),!0;case "removeText":return b.removeText(),
16
- !0;case "formatText":return b.formatText(c),!0;case "formatElement":return b=b.anchor.getNode(),(r.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(c),!0;case "insertLineBreak":return b.insertLineBreak(c),!0;case "insertParagraph":return b.insertParagraph(),!0;case "indentContent":return b=b.anchor,b="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),b.canInsertTab()?a.execCommand("insertText","\t"):10!==b.getIndent()&&b.setIndent(b.getIndent()+1),!0;case "outdentContent":return b=b.anchor,
17
- c=b.getNode(),d="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===c.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=c.shiftKey;if(E(b,!0))return c.preventDefault(),c=d,d=D(b),b.modify(c?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=c.shiftKey;if(E(b,!1))return c.preventDefault(),c=d,d=D(b),b.modify(c?"extend":"move",d,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
18
- {anchor:c}=b,b.isCollapsed()&&0===c.offset&&0<("element"===c.type?c.getNode():c.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),c.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return c.preventDefault(),a.execCommand(c.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
19
- !0;case "copy":return G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return H(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);J(a,e);return f},[a]);K(a)}module.exports=function({contentEditable:a,placeholder:e,initialEditorState:f}){const [d]=g.useLexicalComposerContext(),c=A(d);M(d,f);f=C(d);return h.createElement(h.Fragment,null,a,c&&e,f)};
7
+ var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),r=require("@lexical/text"),t=require("react-dom"),v=require("@lexical/clipboard"),w=require("@lexical/selection"),x=require("lexical"),y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
8
+ function z(c){const [e,f]=h.useState(c.getEditorState().read(r.$canShowPlaceholderCurry(c.isComposing())));y(()=>c.addListener("update",({editorState:d})=>{const b=c.isComposing();d=d.read(r.$canShowPlaceholderCurry(b));f(d)}),[c]);return e}
9
+ function B(c){const [e,f]=h.useState(()=>c.getDecorators());y(()=>c.addListener("decorator",d=>{t.flushSync(()=>{f(d)})}),[c]);return h.useMemo(()=>{const d=[],b=Object.keys(e);for(let p=0;p<b.length;p++){var a=b[p];const u=e[a];a=c.getElementByKey(a);null!==a&&d.push(t.createPortal(u,a))}return d},[e,c])}function C(c,e){D(c,e);e.update(()=>{const f=x.$getSelection();x.$isRangeSelection(f)&&f.removeText()})}
10
+ function D(c,e){c.preventDefault();e.update(()=>{const f=c.clipboardData,d=x.$getSelection();if(null!==d&&null!=f){const b=v.getHtmlContent(e),a=v.$getLexicalContent(e);null!==b&&f.setData("text/html",b);null!==a&&f.setData("application/x-lexical-editor",a);f.setData("text/plain",d.getTextContent())}})}function E(c,e){c.preventDefault();e.update(()=>{const f=x.$getSelection(),d=c.clipboardData;null!=d&&x.$isRangeSelection(f)&&v.$insertDataTransferForRichText(d,f,e)})}const F={tag:"history-merge"};
11
+ function G(c,e){if(null!==e)if(void 0===e)c.update(()=>{var f=x.$getRoot();if(null===f.getFirstChild()){const d=x.$createParagraphNode();f.append(d);f=document.activeElement;(null!==x.$getSelection()||null!==f&&f===c.getRootElement())&&d.select()}},F);else if(null!==e)switch(typeof e){case "string":e=c.parseEditorState(e);c.setEditorState(e,F);break;case "object":c.setEditorState(e,F);break;case "function":c.update(e,F)}}
12
+ function H(c){h.useEffect(()=>{const e=f=>{var d=c.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var b=JSON.parse(d)}catch(a){return}if(b&&"nuanria_messaging"===b.protocol&&"request"===b.type&&(b=b.payload)&&"makeChanges"===b.functionId&&(b=b.args)){const [a,p,u,A,I]=b;c.update(()=>{const q=x.$getSelection();if(x.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;x.$isTextNode(k)&&0<=a&&0<=p&&(l=a,m=a+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
13
+ u)q.insertRawText(u),k=n.getNode();x.$isTextNode(k)&&(l=A,m=A+I,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));f.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[c])}
14
+ function J(c,e){y(()=>{const f=c.addListener("command",(d,b)=>{var a=x.$getSelection();if("click"===d&&x.$isNodeSelection(a))return a.clear(),!0;if(!x.$isRangeSelection(a))return!1;switch(d){case "deleteCharacter":return a.deleteCharacter(b),!0;case "deleteWord":return a.deleteWord(b),!0;case "deleteLine":return a.deleteLine(b),!0;case "insertText":return"string"===typeof b?a.insertText(b):(d=b.dataTransfer,null!=d?v.$insertDataTransferForRichText(d,a,c):(b=b.data)&&a.insertText(b)),!0;case "removeText":return a.removeText(),
15
+ !0;case "formatText":return a.formatText(b),!0;case "formatElement":return a=a.anchor.getNode(),(x.$isElementNode(a)?a:a.getParentOrThrow()).setFormat(b),!0;case "insertLineBreak":return a.insertLineBreak(b),!0;case "insertParagraph":return a.insertParagraph(),!0;case "indentContent":return a=a.anchor,a="element"===a.type?a.getNode():a.getNode().getParentOrThrow(),a.canInsertTab()?c.execCommand("insertText","\t"):10!==a.getIndent()&&a.setIndent(a.getIndent()+1),!0;case "outdentContent":return a=a.anchor,
16
+ b=a.getNode(),d="element"===a.type?a.getNode():a.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===b.getTextContent()[a.offset-1]&&c.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=b.shiftKey;if(w.$shouldOverrideDefaultCharacterSelection(a,!0))return b.preventDefault(),w.$moveCharacter(a,d,!0),!0;break;case "keyArrowRight":d=b.shiftKey;if(w.$shouldOverrideDefaultCharacterSelection(a,!1))return b.preventDefault(),w.$moveCharacter(a,d,!1),
17
+ !0;break;case "keyBackspace":return b.preventDefault(),{anchor:b}=a,a.isCollapsed()&&0===b.offset&&0<("element"===b.type?b.getNode():b.getNode().getParentOrThrow()).getIndent()?c.execCommand("outdentContent"):c.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),c.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),b.shiftKey?c.execCommand("insertLineBreak"):c.execCommand("insertParagraph");case "keyTab":return b.preventDefault(),c.execCommand(b.shiftKey?
18
+ "outdentContent":"indentContent");case "keyEscape":return c.blur(),!0;case "copy":return D(b,c),!0;case "cut":return C(b,c),!0;case "paste":return E(b,c),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);G(c,e);return f},[c]);H(c)}module.exports=function({contentEditable:c,placeholder:e,initialEditorState:f}){const [d]=g.useLexicalComposerContext(),b=z(d);J(d,f);f=B(d);return h.createElement(h.Fragment,null,c,b&&e,f)};