@lexical/react 0.1.9 → 0.1.12

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 (95) hide show
  1. package/DEPRECATED_useLexical.dev.js +5 -44
  2. package/DEPRECATED_useLexical.prod.js +1 -2
  3. package/DEPRECATED_useLexicalAutoFormatter.dev.js +87 -41
  4. package/DEPRECATED_useLexicalAutoFormatter.prod.js +20 -18
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +22 -19
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
  7. package/DEPRECATED_useLexicalEditor.dev.js +1 -25
  8. package/DEPRECATED_useLexicalEditor.prod.js +1 -1
  9. package/DEPRECATED_useLexicalHistory.dev.js +1 -1
  10. package/DEPRECATED_useLexicalHistory.prod.js +2 -2
  11. package/DEPRECATED_useLexicalList.dev.js +6 -0
  12. package/DEPRECATED_useLexicalList.prod.js +1 -1
  13. package/DEPRECATED_useLexicalPlainText.dev.js +81 -89
  14. package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
  15. package/DEPRECATED_useLexicalRichText.dev.js +98 -592
  16. package/DEPRECATED_useLexicalRichText.prod.js +17 -29
  17. package/LexicalAutoFormatterPlugin.d.ts +9 -0
  18. package/LexicalAutoFormatterPlugin.dev.js +87 -41
  19. package/LexicalAutoFormatterPlugin.js.flow +10 -0
  20. package/LexicalAutoFormatterPlugin.prod.js +21 -19
  21. package/LexicalAutoLinkPlugin.d.ts +20 -0
  22. package/LexicalAutoLinkPlugin.js.flow +23 -0
  23. package/LexicalCharacterLimitPlugin.d.ts +11 -0
  24. package/LexicalCharacterLimitPlugin.dev.js +22 -19
  25. package/LexicalCharacterLimitPlugin.js.flow +12 -0
  26. package/LexicalCharacterLimitPlugin.prod.js +9 -8
  27. package/LexicalClearEditorPlugin.d.ts +14 -0
  28. package/LexicalClearEditorPlugin.dev.js +73 -0
  29. package/LexicalClearEditorPlugin.js +9 -0
  30. package/LexicalClearEditorPlugin.js.flow +14 -0
  31. package/LexicalClearEditorPlugin.prod.js +8 -0
  32. package/LexicalCollaborationPlugin.d.ts +49 -0
  33. package/LexicalCollaborationPlugin.dev.js +21 -11
  34. package/LexicalCollaborationPlugin.js.flow +55 -0
  35. package/LexicalCollaborationPlugin.prod.js +7 -7
  36. package/LexicalComposer.d.ts +22 -0
  37. package/LexicalComposer.dev.js +29 -5
  38. package/LexicalComposer.js.flow +24 -0
  39. package/LexicalComposer.prod.js +3 -3
  40. package/LexicalComposerContext.d.ts +24 -0
  41. package/LexicalComposerContext.js.flow +27 -0
  42. package/LexicalContentEditable.d.ts +32 -0
  43. package/LexicalContentEditable.dev.js +35 -8
  44. package/LexicalContentEditable.js.flow +35 -0
  45. package/LexicalContentEditable.prod.js +3 -3
  46. package/LexicalHashtagPlugin.d.ts +9 -0
  47. package/LexicalHashtagPlugin.js.flow +10 -0
  48. package/LexicalHistoryPlugin.d.ts +29 -0
  49. package/LexicalHistoryPlugin.dev.js +1 -1
  50. package/LexicalHistoryPlugin.js.flow +34 -0
  51. package/LexicalHistoryPlugin.prod.js +2 -2
  52. package/LexicalHorizontalRuleNode.d.ts +23 -0
  53. package/LexicalHorizontalRuleNode.js.flow +25 -0
  54. package/LexicalLinkPlugin.d.ts +9 -0
  55. package/LexicalLinkPlugin.js.flow +10 -0
  56. package/LexicalListPlugin.d.ts +9 -0
  57. package/LexicalListPlugin.dev.js +6 -0
  58. package/LexicalListPlugin.js.flow +10 -0
  59. package/LexicalListPlugin.prod.js +2 -2
  60. package/LexicalNestedComposer.d.ts +20 -0
  61. package/LexicalNestedComposer.js.flow +21 -0
  62. package/LexicalOnChangePlugin.d.ts +12 -0
  63. package/LexicalOnChangePlugin.js.flow +14 -0
  64. package/LexicalPlainTextPlugin.d.ts +15 -0
  65. package/LexicalPlainTextPlugin.dev.js +77 -84
  66. package/LexicalPlainTextPlugin.js.flow +18 -0
  67. package/LexicalPlainTextPlugin.prod.js +12 -12
  68. package/LexicalRichTextPlugin.d.ts +15 -0
  69. package/LexicalRichTextPlugin.dev.js +93 -586
  70. package/LexicalRichTextPlugin.js.flow +18 -0
  71. package/LexicalRichTextPlugin.prod.js +13 -25
  72. package/LexicalTablePlugin.d.ts +9 -0
  73. package/LexicalTablePlugin.dev.js +23 -1
  74. package/LexicalTablePlugin.js.flow +10 -0
  75. package/LexicalTablePlugin.prod.js +4 -3
  76. package/LexicalTreeView.d.ts +17 -0
  77. package/LexicalTreeView.dev.js +10 -2
  78. package/LexicalTreeView.js.flow +19 -0
  79. package/LexicalTreeView.prod.js +9 -8
  80. package/README.md +0 -1
  81. package/package.json +6 -5
  82. package/useLexicalDecoratorMap.d.ts +14 -0
  83. package/useLexicalDecoratorMap.js.flow +16 -0
  84. package/useLexicalIsTextContentEmpty.d.ts +13 -0
  85. package/useLexicalIsTextContentEmpty.js.flow +15 -0
  86. package/useLexicalNodeSelection.d.ts +12 -0
  87. package/useLexicalNodeSelection.dev.js +70 -0
  88. package/useLexicalNodeSelection.js +9 -0
  89. package/useLexicalNodeSelection.js.flow +14 -0
  90. package/useLexicalNodeSelection.prod.js +8 -0
  91. package/withSubscriptions.d.ts +12 -0
  92. package/withSubscriptions.js.flow +13 -0
  93. package/LexicalBootstrapPlugin.dev.js +0 -122
  94. package/LexicalBootstrapPlugin.js +0 -9
  95. package/LexicalBootstrapPlugin.prod.js +0 -8
@@ -4,4 +4,4 @@
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 b=require("@lexical/list"),d=require("react");function e(a){d.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(b.indentList())return!0}else if("outdentContent"===c){if(b.outdentList())return!0}else{if("insertOrderedList"===c)return b.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return b.insertList(a,"ul"),!0;if("removeList"===c)return b.removeList(a),!0}return!1},1),[a])}module.exports=function(a){e(a)};
7
+ var b=require("@lexical/list"),d=require("react");function e(a){d.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(b.indentList())return!0}else if("outdentContent"===c){if(b.outdentList())return!0}else{if("insertOrderedList"===c)return b.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return b.insertList(a,"ul"),!0;if("removeList"===c)return b.removeList(a),!0;if("insertParagraph"===c&&b.$handleListInsertParagraph())return!0}return!1},1),[a])}module.exports=function(a){e(a)};
@@ -9,6 +9,7 @@
9
9
  var withSubscriptions = require('@lexical/react/withSubscriptions');
10
10
  var lexical = require('lexical');
11
11
  var react = require('react');
12
+ var clipboard = require('@lexical/clipboard');
12
13
 
13
14
  /**
14
15
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -26,7 +27,7 @@ const COMPOSING_CHARACTER = 1;
26
27
  const INSERT_CHARACTER_AFTER_SELECTION = 2;
27
28
  const DELETE_CHARACTER_BEFORE_SELECTION = 3;
28
29
  const DELETE_CHARACTER_AFTER_SELECTION = 4;
29
- const EditorPriority$1 = 0;
30
+ const EditorPriority = 0;
30
31
 
31
32
  function getDirtyNodes(editorState, dirtyLeavesSet, dirtyElementsSet) {
32
33
  const dirtyLeaves = Array.from(dirtyLeavesSet);
@@ -73,7 +74,7 @@ function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyEl
73
74
  return COMPOSING_CHARACTER;
74
75
  }
75
76
 
76
- if (nextSelection === null || prevSelection === null || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
77
+ if (!lexical.$isRangeSelection(nextSelection) || !lexical.$isRangeSelection(prevSelection) || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
77
78
  return OTHER;
78
79
  }
79
80
 
@@ -315,7 +316,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
315
316
  }
316
317
  };
317
318
 
318
- return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority$1), editor.addListener('update', applyChange));
319
+ return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority), editor.addListener('update', applyChange));
319
320
  }, [clearHistory, delay, editor, historyState]);
320
321
  }
321
322
  function createEmptyHistoryState() {
@@ -359,6 +360,10 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
359
360
  const isRTL = $isParentElementRTL(selection);
360
361
  $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
361
362
  }
363
+ function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
364
+ const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
365
+ return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
366
+ }
362
367
 
363
368
  /**
364
369
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -368,46 +373,7 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
368
373
  *
369
374
  *
370
375
  */
371
- function resolveElement(element, isBackward, focusOffset) {
372
- const parent = element.getParent();
373
- let offset = focusOffset;
374
- let block = element;
375
-
376
- if (parent !== null) {
377
- if (isBackward && focusOffset === 0) {
378
- offset = block.getIndexWithinParent();
379
- block = parent;
380
- } else if (!isBackward && focusOffset === block.getChildrenSize()) {
381
- offset = block.getIndexWithinParent() + 1;
382
- block = parent;
383
- }
384
- }
385
-
386
- return block.getChildAtIndex(isBackward ? offset - 1 : offset);
387
- }
388
-
389
- function getPossibleDecoratorNode(focus, isBackward) {
390
- const focusOffset = focus.offset;
391
-
392
- if (focus.type === 'element') {
393
- const block = focus.getNode();
394
- return resolveElement(block, isBackward, focusOffset);
395
- } else {
396
- const focusNode = focus.getNode();
397
-
398
- if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
399
- const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
400
-
401
- if (possibleNode === null) {
402
- return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
403
- }
404
-
405
- return possibleNode;
406
- }
407
- }
408
-
409
- return null;
410
- }
376
+ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
411
377
 
412
378
  /**
413
379
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -417,25 +383,25 @@ function getPossibleDecoratorNode(focus, isBackward) {
417
383
  *
418
384
  *
419
385
  */
420
- function $insertDataTransferForPlainText(dataTransfer, selection) {
421
- const text = dataTransfer.getData('text/plain');
386
+ const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
387
+ var useLayoutEffect = useLayoutEffectImpl;
422
388
 
423
- if (text != null) {
424
- selection.insertRawText(text);
425
- }
426
- }
427
- function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
428
- const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
429
- return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
430
- }
389
+ /**
390
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
391
+ *
392
+ * This source code is licensed under the MIT license found in the
393
+ * LICENSE file in the root directory of this source tree.
394
+ *
395
+ *
396
+ */
431
397
  function onPasteForPlainText(event, editor) {
432
398
  event.preventDefault();
433
399
  editor.update(() => {
434
400
  const selection = lexical.$getSelection();
435
401
  const clipboardData = event.clipboardData;
436
402
 
437
- if (clipboardData != null && selection !== null) {
438
- $insertDataTransferForPlainText(clipboardData, selection);
403
+ if (clipboardData != null && lexical.$isRangeSelection(selection)) {
404
+ clipboard.$insertDataTransferForPlainText(clipboardData, selection);
439
405
  }
440
406
  });
441
407
  }
@@ -444,7 +410,7 @@ function onCutForPlainText(event, editor) {
444
410
  editor.update(() => {
445
411
  const selection = lexical.$getSelection();
446
412
 
447
- if (selection !== null) {
413
+ if (lexical.$isRangeSelection(selection)) {
448
414
  selection.removeText();
449
415
  }
450
416
  });
@@ -457,19 +423,10 @@ function onCopyForPlainText(event, editor) {
457
423
 
458
424
  if (selection !== null) {
459
425
  if (clipboardData != null) {
460
- const domSelection = window.getSelection(); // If we haven't selected a range, then don't copy anything
426
+ const htmlString = clipboard.getHtmlContent(editor);
461
427
 
462
- if (domSelection.isCollapsed) {
463
- return;
464
- }
465
-
466
- const range = domSelection.getRangeAt(0);
467
-
468
- if (range) {
469
- const container = document.createElement('div');
470
- const frag = range.cloneContents();
471
- container.appendChild(frag);
472
- clipboardData.setData('text/html', container.innerHTML);
428
+ if (htmlString !== null) {
429
+ clipboardData.setData('text/html', htmlString);
473
430
  }
474
431
 
475
432
  clipboardData.setData('text/plain', selection.getTextContent());
@@ -486,18 +443,53 @@ function onCopyForPlainText(event, editor) {
486
443
  *
487
444
  *
488
445
  */
489
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
446
+ // Convoluted logic to make this work with Flow. Order matters.
447
+ const options = {
448
+ tag: 'history-merge'
449
+ };
450
+ const setEditorOptions = options;
451
+ const updateOptions = options;
452
+ function initializeEditor(editor, initialEditorState) {
453
+ if (initialEditorState === null) {
454
+ return;
455
+ } else if (initialEditorState === undefined) {
456
+ editor.update(() => {
457
+ const root = lexical.$getRoot();
458
+ const firstChild = root.getFirstChild();
459
+
460
+ if (firstChild === null) {
461
+ const paragraph = lexical.$createParagraphNode();
462
+ root.append(paragraph);
463
+ const activeElement = document.activeElement;
464
+
465
+ if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
466
+ paragraph.select();
467
+ }
468
+ }
469
+ }, updateOptions);
470
+ } else if (initialEditorState !== null) {
471
+ switch (typeof initialEditorState) {
472
+ case 'string':
473
+ {
474
+ const parsedEditorState = editor.parseEditorState(initialEditorState);
475
+ editor.setEditorState(parsedEditorState, setEditorOptions);
476
+ break;
477
+ }
490
478
 
491
- /**
492
- * Copyright (c) Meta Platforms, Inc. and affiliates.
493
- *
494
- * This source code is licensed under the MIT license found in the
495
- * LICENSE file in the root directory of this source tree.
496
- *
497
- *
498
- */
499
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
500
- var useLayoutEffect = useLayoutEffectImpl;
479
+ case 'object':
480
+ {
481
+ editor.setEditorState(initialEditorState, setEditorOptions);
482
+ break;
483
+ }
484
+
485
+ case 'function':
486
+ {
487
+ editor.update(initialEditorState, updateOptions);
488
+ break;
489
+ }
490
+ }
491
+ }
492
+ }
501
493
 
502
494
  /**
503
495
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -538,7 +530,7 @@ function useLexicalDragonSupport(editor) {
538
530
  editor.update(() => {
539
531
  const selection = lexical.$getSelection();
540
532
 
541
- if (selection !== null) {
533
+ if (lexical.$isRangeSelection(selection)) {
542
534
  const anchor = selection.anchor;
543
535
  let anchorNode = anchor.getNode();
544
536
  let setSelStart = 0;
@@ -595,13 +587,12 @@ function useLexicalDragonSupport(editor) {
595
587
  *
596
588
  *
597
589
  */
598
- const EditorPriority = 0;
599
- function usePlainTextSetup(editor) {
590
+ function usePlainTextSetup(editor, initialEditorState) {
600
591
  useLayoutEffect(() => {
601
592
  const removeListener = editor.addListener('command', (type, payload) => {
602
593
  const selection = lexical.$getSelection();
603
594
 
604
- if (selection === null) {
595
+ if (!lexical.$isRangeSelection(selection)) {
605
596
  return false;
606
597
  }
607
598
 
@@ -637,7 +628,7 @@ function usePlainTextSetup(editor) {
637
628
  const dataTransfer = eventOrText.dataTransfer;
638
629
 
639
630
  if (dataTransfer != null) {
640
- $insertDataTransferForPlainText(dataTransfer, selection);
631
+ clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
641
632
  } else {
642
633
  const data = eventOrText.data;
643
634
 
@@ -755,9 +746,10 @@ function usePlainTextSetup(editor) {
755
746
  }
756
747
 
757
748
  return false;
758
- }, EditorPriority);
759
- editor.execCommand('bootstrapEditor');
760
- return removeListener;
749
+ }, 0);
750
+ initializeEditor(editor, initialEditorState);
751
+ return removeListener; // We only do this for init
752
+ // eslint-disable-next-line react-hooks/exhaustive-deps
761
753
  }, [editor]);
762
754
  useLexicalDragonSupport(editor);
763
755
  }
@@ -770,8 +762,8 @@ function usePlainTextSetup(editor) {
770
762
  *
771
763
  *
772
764
  */
773
- function useLexicalPlainText(editor, externalHistoryState) {
774
- usePlainTextSetup(editor);
765
+ function useLexicalPlainText(editor, externalHistoryState, initialEditorState) {
766
+ usePlainTextSetup(editor, initialEditorState);
775
767
  useLexicalHistory(editor, externalHistoryState);
776
768
  }
777
769
 
@@ -4,19 +4,18 @@
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 n=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react");
8
- function w(a,d,c,b,e){if(null===a||0===c.size&&0===b.size)return 0;var g=d._selection,f=a._selection;if(e)return 1;if(null===g||null===f||!f.isCollapsed()||!g.isCollapsed())return 0;var h=Array.from(c);b=Array.from(b);c=d._nodeMap;e=[];for(var k=0;k<h.length;k++){const m=c.get(h[k]);void 0!==m&&e.push(m)}for(h=0;h<b.length;h++)b[h][1]&&(k=c.get(b[h][0]),void 0===k||u.$isRootNode(k)||e.push(k));if(0===e.length)return 0;if(1<e.length)return b=d._nodeMap,d=b.get(g.anchor.key),f=b.get(f.anchor.key),d&&
9
- f&&!a._nodeMap.has(d.__key)&&u.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=e[0];a=a._nodeMap.get(d.__key);if(!u.$isTextNode(a)||!u.$isTextNode(d)||a.__mode!==d.__mode)return 0;a=a.__text;d=d.__text;if(a===d)return 0;g=g.anchor;f=f.anchor;if(g.key!==f.key||"text"!==g.type)return 0;g=g.offset;f=f.offset;a=d.length-a.length;return 1===a&&f===g-1?2:-1===a&&f===g+1?3:-1===a&&f===g?4:0}
10
- function x(a,d){let c=Date.now(),b=0;return(e,g,f,h,k,m)=>{const t=Date.now();if(m.has("historic"))return b=0,c=t,2;const l=w(e,g,h,k,a.isComposing()),r=(()=>{const q=m.has("history-push");if(!q&&m.has("history-merge"))return 0;if(null===e)return 1;var p=g._selection;const D=e._selection;if(!(0<h.size||0<k.size))return null===D&&null!==p?0:2;p=null===f||f.editor===a;return!1===q&&0!==l&&l===b&&t<c+d&&p?0:1})();c=t;b=l;return r}}
11
- function y(a,d,c=1E3){const b=v.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),e=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const g=x(a,c);return n(a.addListener("command",f=>{switch(f){case "undo":f=b.redoStack;var h=b.undoStack;if(0!==h.length){var k=b.current;const m=h.pop();null!==k&&(f.push(k),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);b.current=m;m.editor.setEditorState(m.editorState.clone(m.undoSelection),
12
- {tag:"historic"})}return!0;case "redo":return f=b.redoStack,h=b.undoStack,0!==f.length&&(k=b.current,null!==k&&(h.push(k),a.execCommand("canUndo",!0)),h=f.pop(),0===f.length&&a.execCommand("canRedo",!1),b.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return e(),!1;case "clearHistory":return e(),!0;default:return!1}},0),a.addListener("update",({editorState:f,prevEditorState:h,dirtyLeaves:k,dirtyElements:m,tags:t})=>{const l=b.current,r=b.redoStack,q=b.undoStack,
13
- p=null===l?null:l.editorState;if(null===l||f!==p){k=g(h,f,l,k,m,t);if(1===k)0!==r.length&&(b.redoStack=[]),null!==l&&(q.push({...l,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;b.current={editor:a,editorState:f}}}))},[e,c,a,b])}function z(a,d,c=1E3){return y(a,d,c)}function A(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
14
- function B(a,d,c){const b=a.getParent();let e=c;null!==b&&(d&&0===c?(e=a.getIndexWithinParent(),a=b):d||c!==a.getChildrenSize()||(e=a.getIndexWithinParent()+1,a=b));return a.getChildAtIndex(d?e-1:e)}function C(a,d){a=a.getData("text/plain");null!=a&&d.insertRawText(a)}
15
- function E(a,d){var c=a.focus;a=c.offset;"element"===c.type?(c=c.getNode(),d=B(c,d,a)):(c=c.getNode(),d&&0===a||!d&&a===c.getTextContentSize()?(a=d?c.getPreviousSibling():c.getNextSibling(),d=null===a?B(c.getParentOrThrow(),d,c.getIndexWithinParent()+(d?0:1)):a):d=null);return u.$isDecoratorNode(d)&&!d.isIsolated()}function F(a,d){a.preventDefault();d.update(()=>{const c=u.$getSelection(),b=a.clipboardData;null!=b&&null!==c&&C(b,c)})}
16
- function G(a,d){H(a,d);d.update(()=>{const c=u.$getSelection();null!==c&&c.removeText()})}function H(a,d){a.preventDefault();d.update(()=>{const c=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=c){var e=window.getSelection();if(!e.isCollapsed){var g=e.getRangeAt(0);g&&(e=document.createElement("div"),g=g.cloneContents(),e.appendChild(g),c.setData("text/html",e.innerHTML));c.setData("text/plain",b.getTextContent())}}})}
17
- var I="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;
18
- function J(a){v.useEffect(()=>{const d=c=>{var b=a.getRootElement();if(document.activeElement===b&&(b=c.data,"string"===typeof b)){try{var e=JSON.parse(b)}catch(g){return}if(e&&"nuanria_messaging"===e.protocol&&"request"===e.type&&(e=e.payload)&&"makeChanges"===e.functionId&&(e=e.args)){const [g,f,h,k,m]=e;a.update(()=>{const t=u.$getSelection();if(null!==t){var l=t.anchor;let r=l.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=g&&0<=f&&(q=g,p=g+f,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==h)t.insertRawText(h),
19
- r=l.getNode();u.$isTextNode(r)&&(q=k,p=k+m,l=r.getTextContentSize(),q=q>l?l:q,p=p>l?l:p,t.setTextNodeRange(r,q,r,p));c.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
20
- function K(a){I(()=>{const d=a.addListener("command",(c,b)=>{const e=u.$getSelection();if(null===e)return!1;switch(c){case "deleteCharacter":return e.deleteCharacter(b),!0;case "deleteWord":return e.deleteWord(b),!0;case "deleteLine":return e.deleteLine(b),!0;case "insertText":return"string"===typeof b?e.insertText(b):(c=b.dataTransfer,null!=c?C(c,e):(b=b.data)&&e.insertText(b)),!0;case "removeText":return e.removeText(),!0;case "insertLineBreak":return e.insertLineBreak(b),!0;case "insertParagraph":return e.insertLineBreak(),
21
- !0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(E(e,!0))return b.preventDefault(),b=c,c=A(e),e.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(E(e,!1))return b.preventDefault(),b=c,c=A(e),e.modify(b?"extend":"move",c,"character"),!0;break;case "keyBackspace":return b.preventDefault(),a.execCommand("deleteCharacter",
22
- !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);a.execCommand("bootstrapEditor");return d},[a]);J(a)}module.exports=function(a,d){K(a);z(a,d)};
7
+ var k=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react"),w=require("@lexical/clipboard");
8
+ function x(a,d,f,b,c){if(null===a||0===f.size&&0===b.size)return 0;var e=d._selection,g=a._selection;if(c)return 1;if(!(u.$isRangeSelection(e)&&u.$isRangeSelection(g)&&g.isCollapsed()&&e.isCollapsed()))return 0;var h=Array.from(f);b=Array.from(b);f=d._nodeMap;c=[];for(var l=0;l<h.length;l++){const n=f.get(h[l]);void 0!==n&&c.push(n)}for(h=0;h<b.length;h++)b[h][1]&&(l=f.get(b[h][0]),void 0===l||u.$isRootNode(l)||c.push(l));if(0===c.length)return 0;if(1<c.length)return b=d._nodeMap,d=b.get(e.anchor.key),
9
+ g=b.get(g.anchor.key),d&&g&&!a._nodeMap.has(d.__key)&&u.$isTextNode(d)&&1===d.__text.length&&1===e.anchor.offset?2:0;d=c[0];a=a._nodeMap.get(d.__key);if(!u.$isTextNode(a)||!u.$isTextNode(d)||a.__mode!==d.__mode)return 0;a=a.__text;d=d.__text;if(a===d)return 0;e=e.anchor;g=g.anchor;if(e.key!==g.key||"text"!==e.type)return 0;e=e.offset;g=g.offset;a=d.length-a.length;return 1===a&&g===e-1?2:-1===a&&g===e+1?3:-1===a&&g===e?4:0}
10
+ function y(a,d){let f=Date.now(),b=0;return(c,e,g,h,l,n)=>{const t=Date.now();if(n.has("historic"))return b=0,f=t,2;const m=x(c,e,h,l,a.isComposing()),r=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===c)return 1;var p=e._selection;const D=c._selection;if(!(0<h.size||0<l.size))return null===D&&null!==p?0:2;p=null===g||g.editor===a;return!1===q&&0!==m&&m===b&&t<f+d&&p?0:1})();f=t;b=m;return r}}
11
+ function z(a,d,f=1E3){const b=v.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),c=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const e=y(a,f);return k(a.addListener("command",g=>{switch(g){case "undo":g=b.redoStack;var h=b.undoStack;if(0!==h.length){var l=b.current;const n=h.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);b.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
12
+ {tag:"historic"})}return!0;case "redo":return g=b.redoStack,h=b.undoStack,0!==g.length&&(l=b.current,null!==l&&(h.push(l),a.execCommand("canUndo",!0)),h=g.pop(),0===g.length&&a.execCommand("canRedo",!1),b.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return c(),!1;case "clearHistory":return c(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:h,dirtyLeaves:l,dirtyElements:n,tags:t})=>{const m=b.current,r=b.redoStack,q=b.undoStack,
13
+ p=null===m?null:m.editorState;if(null===m||g!==p){l=e(h,g,m,l,n,t);if(1===l)0!==r.length&&(b.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;b.current={editor:a,editorState:g}}}))},[c,f,a,b])}function A(a,d,f=1E3){return z(a,d,f)}function B(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
14
+ function C(a,d){a=u.$getDecoratorNode(a.focus,d);return u.$isDecoratorNode(a)&&!a.isIsolated()}var E="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;function F(a,d){a.preventDefault();d.update(()=>{const f=u.$getSelection(),b=a.clipboardData;null!=b&&u.$isRangeSelection(f)&&w.$insertDataTransferForPlainText(b,f)})}
15
+ function G(a,d){H(a,d);d.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}function H(a,d){a.preventDefault();d.update(()=>{const f=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=f){const c=w.getHtmlContent(d);null!==c&&f.setData("text/html",c);f.setData("text/plain",b.getTextContent())}})}const I={tag:"history-merge"};
16
+ function J(a,d){if(null!==d)if(void 0===d)a.update(()=>{var f=u.$getRoot();if(null===f.getFirstChild()){const b=u.$createParagraphNode();f.append(b);f=document.activeElement;(null!==u.$getSelection()||null!==f&&f===a.getRootElement())&&b.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)}}
17
+ function K(a){v.useEffect(()=>{const d=f=>{var b=a.getRootElement();if(document.activeElement===b&&(b=f.data,"string"===typeof b)){try{var c=JSON.parse(b)}catch(e){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [e,g,h,l,n]=c;a.update(()=>{const t=u.$getSelection();if(u.$isRangeSelection(t)){var m=t.anchor;let r=m.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=e&&0<=g&&(q=e,p=e+g,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
18
+ h)t.insertRawText(h),r=m.getNode();u.$isTextNode(r)&&(q=l,p=l+n,m=r.getTextContentSize(),q=q>m?m:q,p=p>m?m:p,t.setTextNodeRange(r,q,r,p));f.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
19
+ function L(a,d){E(()=>{const f=a.addListener("command",(b,c)=>{const e=u.$getSelection();if(!u.$isRangeSelection(e))return!1;switch(b){case "deleteCharacter":return e.deleteCharacter(c),!0;case "deleteWord":return e.deleteWord(c),!0;case "deleteLine":return e.deleteLine(c),!0;case "insertText":return"string"===typeof c?e.insertText(c):(b=c.dataTransfer,null!=b?w.$insertDataTransferForPlainText(b,e):(c=c.data)&&e.insertText(c)),!0;case "removeText":return e.removeText(),!0;case "insertLineBreak":return e.insertLineBreak(c),
20
+ !0;case "insertParagraph":return e.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b=c.shiftKey;if(C(e,!0))return c.preventDefault(),c=b,b=B(e),e.modify(c?"extend":"move",!b,"character"),!0;break;case "keyArrowRight":b=c.shiftKey;if(C(e,!1))return c.preventDefault(),c=b,b=B(e),e.modify(c?"extend":"move",b,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
21
+ a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(c,a),!0;case "cut":return G(c,a),!0;case "paste":return F(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);J(a,d);return f},[a]);K(a)}module.exports=function(a,d,f){L(a,f);A(a,d)};