@lexical/react 0.1.8 → 0.1.11

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 (91) hide show
  1. package/DEPRECATED_useLexical.dev.js +3 -38
  2. package/DEPRECATED_useLexical.prod.js +1 -2
  3. package/DEPRECATED_useLexicalAutoFormatter.dev.js +202 -74
  4. package/DEPRECATED_useLexicalAutoFormatter.prod.js +21 -16
  5. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
  6. package/DEPRECATED_useLexicalCharacterLimit.dev.js +23 -21
  7. package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
  8. package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
  9. package/DEPRECATED_useLexicalEditor.dev.js +1 -25
  10. package/DEPRECATED_useLexicalEditor.prod.js +1 -1
  11. package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
  12. package/DEPRECATED_useLexicalHistory.dev.js +18 -15
  13. package/DEPRECATED_useLexicalHistory.prod.js +7 -7
  14. package/DEPRECATED_useLexicalList.dev.js +6 -0
  15. package/DEPRECATED_useLexicalList.prod.js +1 -1
  16. package/DEPRECATED_useLexicalPlainText.dev.js +79 -70
  17. package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
  18. package/DEPRECATED_useLexicalRichText.dev.js +124 -250
  19. package/DEPRECATED_useLexicalRichText.prod.js +25 -29
  20. package/LexicalAutoFormatterPlugin.dev.js +202 -74
  21. package/LexicalAutoFormatterPlugin.js.flow +10 -0
  22. package/LexicalAutoFormatterPlugin.prod.js +21 -17
  23. package/LexicalAutoLinkPlugin.js.flow +23 -0
  24. package/LexicalAutoLinkPlugin.prod.js +4 -4
  25. package/LexicalCharacterLimitPlugin.dev.js +23 -21
  26. package/LexicalCharacterLimitPlugin.js.flow +12 -0
  27. package/LexicalCharacterLimitPlugin.prod.js +9 -8
  28. package/LexicalClearEditorPlugin.dev.js +52 -0
  29. package/LexicalClearEditorPlugin.js +9 -0
  30. package/LexicalClearEditorPlugin.js.flow +14 -0
  31. package/LexicalClearEditorPlugin.prod.js +7 -0
  32. package/LexicalCollaborationPlugin.dev.js +31 -36
  33. package/LexicalCollaborationPlugin.js.flow +55 -0
  34. package/LexicalCollaborationPlugin.prod.js +7 -8
  35. package/LexicalComposer.dev.js +8 -6
  36. package/LexicalComposer.js.flow +23 -0
  37. package/LexicalComposer.prod.js +3 -3
  38. package/LexicalComposerContext.js.flow +27 -0
  39. package/LexicalComposerContext.prod.js +1 -1
  40. package/LexicalContentEditable.dev.js +14 -8
  41. package/LexicalContentEditable.js.flow +35 -0
  42. package/LexicalContentEditable.prod.js +3 -3
  43. package/LexicalHashtagPlugin.js.flow +20 -0
  44. package/LexicalHashtagPlugin.prod.js +1 -1
  45. package/LexicalHistoryPlugin.dev.js +18 -15
  46. package/LexicalHistoryPlugin.js.flow +34 -0
  47. package/LexicalHistoryPlugin.prod.js +7 -7
  48. package/LexicalHorizontalRuleNode.dev.js +66 -0
  49. package/LexicalHorizontalRuleNode.js +9 -0
  50. package/LexicalHorizontalRuleNode.js.flow +25 -0
  51. package/LexicalHorizontalRuleNode.prod.js +8 -0
  52. package/LexicalLinkPlugin.dev.js +0 -1
  53. package/LexicalLinkPlugin.js.flow +10 -0
  54. package/LexicalLinkPlugin.prod.js +3 -3
  55. package/LexicalListPlugin.dev.js +6 -0
  56. package/LexicalListPlugin.js.flow +10 -0
  57. package/LexicalListPlugin.prod.js +2 -2
  58. package/LexicalNestedComposer.js.flow +21 -0
  59. package/LexicalNestedComposer.prod.js +1 -1
  60. package/LexicalOnChangePlugin.js.flow +14 -0
  61. package/LexicalOnChangePlugin.prod.js +1 -1
  62. package/LexicalPlainTextPlugin.dev.js +72 -44
  63. package/LexicalPlainTextPlugin.js.flow +18 -0
  64. package/LexicalPlainTextPlugin.prod.js +12 -11
  65. package/LexicalRichTextPlugin.dev.js +115 -222
  66. package/LexicalRichTextPlugin.js.flow +18 -0
  67. package/LexicalRichTextPlugin.prod.js +21 -25
  68. package/LexicalTablePlugin.dev.js +43 -39
  69. package/LexicalTablePlugin.js.flow +10 -0
  70. package/LexicalTablePlugin.prod.js +4 -3
  71. package/LexicalTreeView.dev.js +10 -2
  72. package/LexicalTreeView.js.flow +19 -0
  73. package/LexicalTreeView.prod.js +9 -8
  74. package/README.md +0 -1
  75. package/package.json +5 -4
  76. package/useLexicalDecoratorMap.js.flow +16 -0
  77. package/useLexicalDecoratorMap.prod.js +1 -1
  78. package/useLexicalIsTextContentEmpty.js.flow +15 -0
  79. package/useLexicalIsTextContentEmpty.prod.js +1 -1
  80. package/useLexicalNodeSelection.dev.js +70 -0
  81. package/useLexicalNodeSelection.js +9 -0
  82. package/useLexicalNodeSelection.js.flow +14 -0
  83. package/useLexicalNodeSelection.prod.js +8 -0
  84. package/withSubscriptions.js.flow +13 -0
  85. package/withSubscriptions.prod.js +1 -1
  86. package/LexicalBootstrapPlugin.dev.js +0 -124
  87. package/LexicalBootstrapPlugin.js +0 -9
  88. package/LexicalBootstrapPlugin.prod.js +0 -8
  89. package/LexicalHorizontalRulePlugin.dev.js +0 -51
  90. package/LexicalHorizontalRulePlugin.js +0 -9
  91. package/LexicalHorizontalRulePlugin.prod.js +0 -7
@@ -18,15 +18,15 @@ var react = require('react');
18
18
  *
19
19
  *
20
20
  */
21
- const MERGE = 0;
22
- const NO_MERGE = 1;
23
- const DISCARD = 2;
21
+ const HISTORY_MERGE = 0;
22
+ const HISTORY_PUSH = 1;
23
+ const DISCARD_HISTORY_CANDIDATE = 2;
24
24
  const OTHER = 0;
25
25
  const COMPOSING_CHARACTER = 1;
26
26
  const INSERT_CHARACTER_AFTER_SELECTION = 2;
27
27
  const DELETE_CHARACTER_BEFORE_SELECTION = 3;
28
28
  const DELETE_CHARACTER_AFTER_SELECTION = 4;
29
- const EditorPriority$1 = 0;
29
+ const EditorPriority = 0;
30
30
 
31
31
  function getDirtyNodes(editorState, dirtyLeavesSet, dirtyElementsSet) {
32
32
  const dirtyLeaves = Array.from(dirtyLeavesSet);
@@ -73,7 +73,7 @@ function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyEl
73
73
  return COMPOSING_CHARACTER;
74
74
  }
75
75
 
76
- if (nextSelection === null || prevSelection === null || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
76
+ if (!lexical.$isRangeSelection(nextSelection) || !lexical.$isRangeSelection(prevSelection) || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
77
77
  return OTHER;
78
78
  }
79
79
 
@@ -148,18 +148,21 @@ function createMergeActionGetter(editor, delay) {
148
148
  if (tags.has('historic')) {
149
149
  prevChangeType = OTHER;
150
150
  prevChangeTime = changeTime;
151
- return DISCARD;
151
+ return DISCARD_HISTORY_CANDIDATE;
152
152
  }
153
153
 
154
154
  const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
155
155
 
156
156
  const mergeAction = (() => {
157
- if (tags.has('without-history')) {
158
- return MERGE;
157
+ const shouldPushHistory = tags.has('history-push');
158
+ const shouldMergeHistory = !shouldPushHistory && tags.has('history-merge');
159
+
160
+ if (shouldMergeHistory) {
161
+ return HISTORY_MERGE;
159
162
  }
160
163
 
161
164
  if (prevEditorState === null) {
162
- return NO_MERGE;
165
+ return HISTORY_PUSH;
163
166
  }
164
167
 
165
168
  const selection = nextEditorState._selection;
@@ -168,19 +171,19 @@ function createMergeActionGetter(editor, delay) {
168
171
 
169
172
  if (!hasDirtyNodes) {
170
173
  if (prevSelection === null && selection !== null) {
171
- return MERGE;
174
+ return HISTORY_MERGE;
172
175
  }
173
176
 
174
- return DISCARD;
177
+ return DISCARD_HISTORY_CANDIDATE;
175
178
  }
176
179
 
177
180
  const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
178
181
 
179
- if (changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
180
- return MERGE;
182
+ if (shouldPushHistory === false && changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
183
+ return HISTORY_MERGE;
181
184
  }
182
185
 
183
- return NO_MERGE;
186
+ return HISTORY_PUSH;
184
187
  })();
185
188
 
186
189
  prevChangeTime = changeTime;
@@ -217,7 +220,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
217
220
 
218
221
  const mergeAction = getMergeAction(prevEditorState, editorState, current, dirtyLeaves, dirtyElements, tags);
219
222
 
220
- if (mergeAction === NO_MERGE) {
223
+ if (mergeAction === HISTORY_PUSH) {
221
224
  if (redoStack.length !== 0) {
222
225
  historyState.redoStack = [];
223
226
  }
@@ -228,7 +231,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
228
231
  });
229
232
  editor.execCommand('canUndo', true);
230
233
  }
231
- } else if (mergeAction === DISCARD) {
234
+ } else if (mergeAction === DISCARD_HISTORY_CANDIDATE) {
232
235
  return;
233
236
  } // Else we merge
234
237
 
@@ -312,7 +315,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
312
315
  }
313
316
  };
314
317
 
315
- return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority$1), editor.addListener('update', applyChange));
318
+ return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority), editor.addListener('update', applyChange));
316
319
  }, [clearHistory, delay, editor, historyState]);
317
320
  }
318
321
  function createEmptyHistoryState() {
@@ -349,7 +352,7 @@ function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity)
349
352
  }
350
353
  function $isParentElementRTL(selection) {
351
354
  const anchorNode = selection.anchor.getNode();
352
- const parent = anchorNode.getParentOrThrow();
355
+ const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
353
356
  return parent.getDirection() === 'rtl';
354
357
  }
355
358
  function $moveCharacter(selection, isHoldingShift, isBackward) {
@@ -357,31 +360,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
357
360
  $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
358
361
  }
359
362
 
360
- /**
361
- * Copyright (c) Meta Platforms, Inc. and affiliates.
362
- *
363
- * This source code is licensed under the MIT license found in the
364
- * LICENSE file in the root directory of this source tree.
365
- *
366
- *
367
- */
368
- function getPossibleDecoratorNode(focus, isBackward) {
369
- const focusOffset = focus.offset;
370
-
371
- if (focus.type === 'element') {
372
- const block = focus.getNode();
373
- return block.getChildAtIndex(isBackward ? focusOffset - 1 : focusOffset);
374
- } else {
375
- const focusNode = focus.getNode();
376
-
377
- if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
378
- return isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
379
- }
380
- }
381
-
382
- return null;
383
- }
384
-
385
363
  /**
386
364
  * Copyright (c) Meta Platforms, Inc. and affiliates.
387
365
  *
@@ -398,17 +376,16 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
398
376
  }
399
377
  }
400
378
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
401
- const possibleDecoratorNode = getPossibleDecoratorNode(selection.focus, isBackward);
402
- return lexical.$isDecoratorNode(possibleDecoratorNode);
379
+ const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
380
+ return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
403
381
  }
404
382
  function onPasteForPlainText(event, editor) {
405
383
  event.preventDefault();
406
384
  editor.update(() => {
407
- lexical.$log('onPasteForPlainText');
408
385
  const selection = lexical.$getSelection();
409
386
  const clipboardData = event.clipboardData;
410
387
 
411
- if (clipboardData != null && selection !== null) {
388
+ if (clipboardData != null && lexical.$isRangeSelection(selection)) {
412
389
  $insertDataTransferForPlainText(clipboardData, selection);
413
390
  }
414
391
  });
@@ -416,10 +393,9 @@ function onPasteForPlainText(event, editor) {
416
393
  function onCutForPlainText(event, editor) {
417
394
  onCopyForPlainText(event, editor);
418
395
  editor.update(() => {
419
- lexical.$log('onCutForPlainText');
420
396
  const selection = lexical.$getSelection();
421
397
 
422
- if (selection !== null) {
398
+ if (lexical.$isRangeSelection(selection)) {
423
399
  selection.removeText();
424
400
  }
425
401
  });
@@ -427,7 +403,6 @@ function onCutForPlainText(event, editor) {
427
403
  function onCopyForPlainText(event, editor) {
428
404
  event.preventDefault();
429
405
  editor.update(() => {
430
- lexical.$log('onCopyForPlainText');
431
406
  const clipboardData = event.clipboardData;
432
407
  const selection = lexical.$getSelection();
433
408
 
@@ -462,18 +437,53 @@ function onCopyForPlainText(event, editor) {
462
437
  *
463
438
  *
464
439
  */
465
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
440
+ // Convoluted logic to make this work with Flow. Order matters.
441
+ const options = {
442
+ tag: 'history-merge'
443
+ };
444
+ const setEditorOptions = options;
445
+ const updateOptions = options;
446
+ function initializeEditor(editor, initialEditorState) {
447
+ if (initialEditorState === null) {
448
+ return;
449
+ } else if (initialEditorState === undefined) {
450
+ editor.update(() => {
451
+ const root = lexical.$getRoot();
452
+ const firstChild = root.getFirstChild();
453
+
454
+ if (firstChild === null) {
455
+ const paragraph = lexical.$createParagraphNode();
456
+ root.append(paragraph);
457
+ const activeElement = document.activeElement;
458
+
459
+ if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
460
+ paragraph.select();
461
+ }
462
+ }
463
+ }, updateOptions);
464
+ } else if (initialEditorState !== null) {
465
+ switch (typeof initialEditorState) {
466
+ case 'string':
467
+ {
468
+ const parsedEditorState = editor.parseEditorState(initialEditorState);
469
+ editor.setEditorState(parsedEditorState, setEditorOptions);
470
+ break;
471
+ }
466
472
 
467
- /**
468
- * Copyright (c) Meta Platforms, Inc. and affiliates.
469
- *
470
- * This source code is licensed under the MIT license found in the
471
- * LICENSE file in the root directory of this source tree.
472
- *
473
- *
474
- */
475
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
476
- var useLayoutEffect = useLayoutEffectImpl;
473
+ case 'object':
474
+ {
475
+ editor.setEditorState(initialEditorState, setEditorOptions);
476
+ break;
477
+ }
478
+
479
+ case 'function':
480
+ {
481
+ editor.update(initialEditorState, updateOptions);
482
+ break;
483
+ }
484
+ }
485
+ }
486
+ }
477
487
 
478
488
  /**
479
489
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -512,10 +522,9 @@ function useLexicalDragonSupport(editor) {
512
522
  if (args) {
513
523
  const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
514
524
  editor.update(() => {
515
- lexical.$log('useLexicalDragonSupport');
516
525
  const selection = lexical.$getSelection();
517
526
 
518
- if (selection !== null) {
527
+ if (lexical.$isRangeSelection(selection)) {
519
528
  const anchor = selection.anchor;
520
529
  let anchorNode = anchor.getNode();
521
530
  let setSelStart = 0;
@@ -572,13 +581,12 @@ function useLexicalDragonSupport(editor) {
572
581
  *
573
582
  *
574
583
  */
575
- const EditorPriority = 0;
576
- function usePlainTextSetup(editor) {
577
- useLayoutEffect(() => {
584
+ function usePlainTextSetup(editor, initialEditorState) {
585
+ react.useEffect(() => {
578
586
  const removeListener = editor.addListener('command', (type, payload) => {
579
587
  const selection = lexical.$getSelection();
580
588
 
581
- if (selection === null) {
589
+ if (!lexical.$isRangeSelection(selection)) {
582
590
  return false;
583
591
  }
584
592
 
@@ -732,9 +740,10 @@ function usePlainTextSetup(editor) {
732
740
  }
733
741
 
734
742
  return false;
735
- }, EditorPriority);
736
- editor.execCommand('bootstrapEditor');
737
- return removeListener;
743
+ }, 0);
744
+ initializeEditor(editor, initialEditorState);
745
+ return removeListener; // We only do this for init
746
+ // eslint-disable-next-line react-hooks/exhaustive-deps
738
747
  }, [editor]);
739
748
  useLexicalDragonSupport(editor);
740
749
  }
@@ -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
- 'use strict';var m=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react");
8
- function w(a,e,c,b,d){if(null===a||0===c.size&&0===b.size)return 0;var g=e._selection,f=a._selection;if(d)return 1;if(null===g||null===f||!f.isCollapsed()||!g.isCollapsed())return 0;var h=Array.from(c);b=Array.from(b);c=e._nodeMap;d=[];for(var k=0;k<h.length;k++){const n=c.get(h[k]);void 0!==n&&d.push(n)}for(h=0;h<b.length;h++)b[h][1]&&(k=c.get(b[h][0]),void 0===k||u.$isRootNode(k)||d.push(k));if(0===d.length)return 0;if(1<d.length)return b=e._nodeMap,e=b.get(g.anchor.key),f=b.get(f.anchor.key),e&&
9
- f&&!a._nodeMap.has(e.__key)&&u.$isTextNode(e)&&1===e.__text.length&&1===g.anchor.offset?2:0;e=d[0];a=a._nodeMap.get(e.__key);if(!u.$isTextNode(a)||!u.$isTextNode(e)||a.__mode!==e.__mode)return 0;a=a.__text;e=e.__text;if(a===e)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=e.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,e){let c=Date.now(),b=0;return(d,g,f,h,k,n)=>{const t=Date.now();if(n.has("historic"))return b=0,c=t,2;const l=w(d,g,h,k,a.isComposing()),r=(()=>{if(n.has("without-history"))return 0;if(null===d)return 1;var p=g._selection;const q=d._selection;if(!(0<h.size||0<k.size))return null===q&&null!==p?0:2;p=null===f||f.editor===a;return 0!==l&&l===b&&t<c+e&&p?0:1})();c=t;b=l;return r}}
11
- function y(a,e,c=1E3){const b=v.useMemo(()=>e||{current:null,redoStack:[],undoStack:[]},[e]),d=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const g=x(a,c);return m(a.addListener("command",f=>{switch(f){case "undo":f=b.redoStack;var h=b.undoStack;if(0!==h.length){var k=b.current;const n=h.pop();null!==k&&(f.push(k),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 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 d(),!1;case "clearHistory":return d(),!0;default:return!1}},0),a.addListener("update",({editorState:f,prevEditorState:h,dirtyLeaves:k,dirtyElements:n,tags:t})=>{const l=b.current,r=b.redoStack,p=b.undoStack,
13
- q=null===l?null:l.editorState;if(null===l||f!==q){k=g(h,f,l,k,n,t);if(1===k)0!==r.length&&(b.redoStack=[]),null!==l&&(p.push({...l,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;b.current={editor:a,editorState:f}}}))},[d,c,a,b])}function z(a,e,c=1E3){return y(a,e,c)}function A(a,e){a=a.getData("text/plain");null!=a&&e.insertRawText(a)}
14
- function B(a,e){var c=a.focus;a=c.offset;"element"===c.type?e=c.getNode().getChildAtIndex(e?a-1:a):(c=c.getNode(),e=e&&0===a||!e&&a===c.getTextContentSize()?e?c.getPreviousSibling():c.getNextSibling():null);return u.$isDecoratorNode(e)}function C(a,e){a.preventDefault();e.update(()=>{u.$log("onPasteForPlainText");const c=u.$getSelection(),b=a.clipboardData;null!=b&&null!==c&&A(b,c)})}
15
- function D(a,e){E(a,e);e.update(()=>{u.$log("onCutForPlainText");const c=u.$getSelection();null!==c&&c.removeText()})}function E(a,e){a.preventDefault();e.update(()=>{u.$log("onCopyForPlainText");const c=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=c){var d=window.getSelection();if(!d.isCollapsed){var g=d.getRangeAt(0);g&&(d=document.createElement("div"),g=g.cloneContents(),d.appendChild(g),c.setData("text/html",d.innerHTML));c.setData("text/plain",b.getTextContent())}}})}
16
- var F="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;
17
- function G(a){v.useEffect(()=>{const e=c=>{var b=a.getRootElement();if(document.activeElement===b&&(b=c.data,"string"===typeof b)){try{var d=JSON.parse(b)}catch(g){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [g,f,h,k,n]=d;a.update(()=>{u.$log("useLexicalDragonSupport");const t=u.$getSelection();if(null!==t){var l=t.anchor;let r=l.getNode(),p=0,q=0;u.$isTextNode(r)&&0<=g&&0<=f&&(p=g,q=g+f,t.setTextNodeRange(r,p,r,
18
- q));if(p!==q||""!==h)t.insertRawText(h),r=l.getNode();u.$isTextNode(r)&&(p=k,q=k+n,l=r.getTextContentSize(),p=p>l?l:p,q=q>l?l:q,t.setTextNodeRange(r,p,r,q));c.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
19
- function H(a){F(()=>{const e=a.addListener("command",(c,b)=>{const d=u.$getSelection();if(null===d)return!1;switch(c){case "deleteCharacter":return d.deleteCharacter(b),!0;case "deleteWord":return d.deleteWord(b),!0;case "deleteLine":return d.deleteLine(b),!0;case "insertText":return"string"===typeof b?d.insertText(b):(c=b.dataTransfer,null!=c?A(c,d):(b=b.data)&&d.insertText(b)),!0;case "removeText":return d.removeText(),!0;case "insertLineBreak":return d.insertLineBreak(b),!0;case "insertParagraph":return d.insertLineBreak(),
20
- !0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(B(d,!0))return b.preventDefault(),b=c,c="rtl"===d.anchor.getNode().getParentOrThrow().getDirection(),d.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(B(d,!1))return b.preventDefault(),b=c,c="rtl"===d.anchor.getNode().getParentOrThrow().getDirection(),d.modify(b?"extend":
21
- "move",c,"character"),!0;break;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);a.execCommand("bootstrapEditor");return e},[a]);G(a)}
22
- module.exports=function(a,e){H(a);z(a,e)};
7
+ var k=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react");
8
+ function w(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 x(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=w(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 y(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=x(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 z(a,d,f=1E3){return y(a,d,f)}function A(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function B(a,d){a=a.getData("text/plain");null!=a&&d.insertRawText(a)}
14
+ function C(a,d){a=u.$getDecoratorNode(a.focus,d);return u.$isDecoratorNode(a)&&!a.isIsolated()}function E(a,d){a.preventDefault();d.update(()=>{const f=u.$getSelection(),b=a.clipboardData;null!=b&&u.$isRangeSelection(f)&&B(b,f)})}function F(a,d){G(a,d);d.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}
15
+ function G(a,d){a.preventDefault();d.update(()=>{const f=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=f){var c=window.getSelection();if(!c.isCollapsed){var e=c.getRangeAt(0);e&&(c=document.createElement("div"),e=e.cloneContents(),c.appendChild(e),f.setData("text/html",c.innerHTML));f.setData("text/plain",b.getTextContent())}}})}const H={tag:"history-merge"};
16
+ function I(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()}},H);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,H);break;case "object":a.setEditorState(d,H);break;case "function":a.update(d,H)}}
17
+ function J(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 K(a,d){v.useEffect(()=>{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?B(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=A(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=A(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 G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return E(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);I(a,d);return f},[a]);J(a)}module.exports=function(a,d){K(a);z(a,d)};