@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
@@ -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
- 'use strict';var c=require("@lexical/react/LexicalComposerContext"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;module.exports=function({onChange:a}){const [b]=c.useLexicalComposerContext();e(()=>{if(a)return b.addListener("update",({editorState:f})=>{a(f,b)})},[b,a]);return null};
7
+ var c=require("@lexical/react/LexicalComposerContext"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;module.exports=function({onChange:a}){const [b]=c.useLexicalComposerContext();e(()=>{if(a)return b.addListener("update",({editorState:f})=>{a(f,b)})},[b,a]);return null};
@@ -174,7 +174,7 @@ function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity)
174
174
  }
175
175
  function $isParentElementRTL(selection) {
176
176
  const anchorNode = selection.anchor.getNode();
177
- const parent = anchorNode.getParentOrThrow();
177
+ const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
178
178
  return parent.getDirection() === 'rtl';
179
179
  }
180
180
  function $moveCharacter(selection, isHoldingShift, isBackward) {
@@ -182,31 +182,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
182
182
  $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
183
183
  }
184
184
 
185
- /**
186
- * Copyright (c) Meta Platforms, Inc. and affiliates.
187
- *
188
- * This source code is licensed under the MIT license found in the
189
- * LICENSE file in the root directory of this source tree.
190
- *
191
- *
192
- */
193
- function getPossibleDecoratorNode(focus, isBackward) {
194
- const focusOffset = focus.offset;
195
-
196
- if (focus.type === 'element') {
197
- const block = focus.getNode();
198
- return block.getChildAtIndex(isBackward ? focusOffset - 1 : focusOffset);
199
- } else {
200
- const focusNode = focus.getNode();
201
-
202
- if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
203
- return isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
204
- }
205
- }
206
-
207
- return null;
208
- }
209
-
210
185
  /**
211
186
  * Copyright (c) Meta Platforms, Inc. and affiliates.
212
187
  *
@@ -223,17 +198,16 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
223
198
  }
224
199
  }
225
200
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
226
- const possibleDecoratorNode = getPossibleDecoratorNode(selection.focus, isBackward);
227
- return lexical.$isDecoratorNode(possibleDecoratorNode);
201
+ const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
202
+ return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
228
203
  }
229
204
  function onPasteForPlainText(event, editor) {
230
205
  event.preventDefault();
231
206
  editor.update(() => {
232
- lexical.$log('onPasteForPlainText');
233
207
  const selection = lexical.$getSelection();
234
208
  const clipboardData = event.clipboardData;
235
209
 
236
- if (clipboardData != null && selection !== null) {
210
+ if (clipboardData != null && lexical.$isRangeSelection(selection)) {
237
211
  $insertDataTransferForPlainText(clipboardData, selection);
238
212
  }
239
213
  });
@@ -241,10 +215,9 @@ function onPasteForPlainText(event, editor) {
241
215
  function onCutForPlainText(event, editor) {
242
216
  onCopyForPlainText(event, editor);
243
217
  editor.update(() => {
244
- lexical.$log('onCutForPlainText');
245
218
  const selection = lexical.$getSelection();
246
219
 
247
- if (selection !== null) {
220
+ if (lexical.$isRangeSelection(selection)) {
248
221
  selection.removeText();
249
222
  }
250
223
  });
@@ -252,7 +225,6 @@ function onCutForPlainText(event, editor) {
252
225
  function onCopyForPlainText(event, editor) {
253
226
  event.preventDefault();
254
227
  editor.update(() => {
255
- lexical.$log('onCopyForPlainText');
256
228
  const clipboardData = event.clipboardData;
257
229
  const selection = lexical.$getSelection();
258
230
 
@@ -279,6 +251,62 @@ function onCopyForPlainText(event, editor) {
279
251
  });
280
252
  }
281
253
 
254
+ /**
255
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
256
+ *
257
+ * This source code is licensed under the MIT license found in the
258
+ * LICENSE file in the root directory of this source tree.
259
+ *
260
+ *
261
+ */
262
+ // Convoluted logic to make this work with Flow. Order matters.
263
+ const options = {
264
+ tag: 'history-merge'
265
+ };
266
+ const setEditorOptions = options;
267
+ const updateOptions = options;
268
+ function initializeEditor(editor, initialEditorState) {
269
+ if (initialEditorState === null) {
270
+ return;
271
+ } else if (initialEditorState === undefined) {
272
+ editor.update(() => {
273
+ const root = lexical.$getRoot();
274
+ const firstChild = root.getFirstChild();
275
+
276
+ if (firstChild === null) {
277
+ const paragraph = lexical.$createParagraphNode();
278
+ root.append(paragraph);
279
+ const activeElement = document.activeElement;
280
+
281
+ if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
282
+ paragraph.select();
283
+ }
284
+ }
285
+ }, updateOptions);
286
+ } else if (initialEditorState !== null) {
287
+ switch (typeof initialEditorState) {
288
+ case 'string':
289
+ {
290
+ const parsedEditorState = editor.parseEditorState(initialEditorState);
291
+ editor.setEditorState(parsedEditorState, setEditorOptions);
292
+ break;
293
+ }
294
+
295
+ case 'object':
296
+ {
297
+ editor.setEditorState(initialEditorState, setEditorOptions);
298
+ break;
299
+ }
300
+
301
+ case 'function':
302
+ {
303
+ editor.update(initialEditorState, updateOptions);
304
+ break;
305
+ }
306
+ }
307
+ }
308
+ }
309
+
282
310
  /**
283
311
  * Copyright (c) Meta Platforms, Inc. and affiliates.
284
312
  *
@@ -316,10 +344,9 @@ function useLexicalDragonSupport(editor) {
316
344
  if (args) {
317
345
  const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
318
346
  editor.update(() => {
319
- lexical.$log('useLexicalDragonSupport');
320
347
  const selection = lexical.$getSelection();
321
348
 
322
- if (selection !== null) {
349
+ if (lexical.$isRangeSelection(selection)) {
323
350
  const anchor = selection.anchor;
324
351
  let anchorNode = anchor.getNode();
325
352
  let setSelStart = 0;
@@ -376,13 +403,12 @@ function useLexicalDragonSupport(editor) {
376
403
  *
377
404
  *
378
405
  */
379
- const EditorPriority = 0;
380
- function usePlainTextSetup(editor) {
381
- useLayoutEffect(() => {
406
+ function usePlainTextSetup(editor, initialEditorState) {
407
+ React.useEffect(() => {
382
408
  const removeListener = editor.addListener('command', (type, payload) => {
383
409
  const selection = lexical.$getSelection();
384
410
 
385
- if (selection === null) {
411
+ if (!lexical.$isRangeSelection(selection)) {
386
412
  return false;
387
413
  }
388
414
 
@@ -536,9 +562,10 @@ function usePlainTextSetup(editor) {
536
562
  }
537
563
 
538
564
  return false;
539
- }, EditorPriority);
540
- editor.execCommand('bootstrapEditor');
541
- return removeListener;
565
+ }, 0);
566
+ initializeEditor(editor, initialEditorState);
567
+ return removeListener; // We only do this for init
568
+ // eslint-disable-next-line react-hooks/exhaustive-deps
542
569
  }, [editor]);
543
570
  useLexicalDragonSupport(editor);
544
571
  }
@@ -553,11 +580,12 @@ function usePlainTextSetup(editor) {
553
580
  */
554
581
  function PlainTextPlugin({
555
582
  contentEditable,
556
- placeholder
583
+ placeholder,
584
+ initialEditorState
557
585
  }) {
558
586
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
559
587
  const showPlaceholder = useLexicalCanShowPlaceholder(editor);
560
- usePlainTextSetup(editor);
588
+ usePlainTextSetup(editor, initialEditorState);
561
589
  const decorators = useDecorators(editor);
562
590
  return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
563
591
  }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type {EditorState} from 'lexical';
11
+
12
+ type InitialEditorStateType = null | string | EditorState | (() => void);
13
+
14
+ declare export default function PlainTextPlugin({
15
+ contentEditable: React$Node,
16
+ initialEditorState?: InitialEditorStateType,
17
+ placeholder: React$Node,
18
+ }): React$Node;
@@ -4,14 +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
- 'use strict';var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),t=require("lexical"),u=require("react-dom");function v(a,e=!0){if(a)return!1;a=t.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
8
- function w(a){if(!v(a,!1))return!1;a=t.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let b=0;b<e;b++){var c=a[b];if(t.$isElementNode(c)){if("paragraph"!==c.__type||0!==c.__indent)return!1;c=c.getChildren();const d=c.length;for(let f=0;f<d;f++)if(!t.$isTextNode(c[b]))return!1}}return!0}function x(a){return()=>w(a)}var y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
9
- function A(a){const [e,c]=h.useState(a.getEditorState().read(x(a.isComposing())));y(()=>a.addListener("update",({editorState:b})=>{const d=a.isComposing();b=b.read(x(d));c(b)}),[a]);return e}function B(a){const [e,c]=h.useState(()=>a.getDecorators());y(()=>a.addListener("decorator",b=>{u.flushSync(()=>{c(b)})}),[a]);return h.useMemo(()=>{const b=[],d=Object.keys(e);for(let p=0;p<d.length;p++){var f=d[p];const r=e[f];f=a.getElementByKey(f);null!==f&&b.push(u.createPortal(r,f))}return b},[e,a])}
10
- function C(a,e){a=a.getData("text/plain");null!=a&&e.insertRawText(a)}function D(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 t.$isDecoratorNode(e)}function E(a,e){a.preventDefault();e.update(()=>{t.$log("onPasteForPlainText");const c=t.$getSelection(),b=a.clipboardData;null!=b&&null!==c&&C(b,c)})}
11
- function F(a,e){G(a,e);e.update(()=>{t.$log("onCutForPlainText");const c=t.$getSelection();null!==c&&c.removeText()})}function G(a,e){a.preventDefault();e.update(()=>{t.$log("onCopyForPlainText");const c=a.clipboardData,b=t.$getSelection();if(null!==b&&null!=c){var d=window.getSelection();if(!d.isCollapsed){var f=d.getRangeAt(0);f&&(d=document.createElement("div"),f=f.cloneContents(),d.appendChild(f),c.setData("text/html",d.innerHTML));c.setData("text/plain",b.getTextContent())}}})}
12
- function H(a){h.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(f){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [f,p,r,z,I]=d;a.update(()=>{t.$log("useLexicalDragonSupport");const q=t.$getSelection();if(null!==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,
13
- m));if(l!==m||""!==r)q.insertRawText(r),k=n.getNode();t.$isTextNode(k)&&(l=z,m=z+I,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));c.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
14
- function J(a){y(()=>{const e=a.addListener("command",(c,b)=>{const d=t.$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?C(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(),
15
- !0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(D(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(D(d,!1))return b.preventDefault(),b=c,c="rtl"===d.anchor.getNode().getParentOrThrow().getDirection(),d.modify(b?"extend":
16
- "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 G(b,a),!0;case "cut":return F(b,a),!0;case "paste":return E(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return e},[a]);H(a)}
17
- module.exports=function({contentEditable:a,placeholder:e}){var [c]=g.useLexicalComposerContext();const b=A(c);J(c);c=B(c);return h.createElement(h.Fragment,null,a,b&&e,c)};
7
+ var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),t=require("lexical"),u=require("react-dom");function v(a,d=!0){if(a)return!1;a=t.$getRoot().getTextContent();d&&(a=a.trim());return""===a}
8
+ function w(a){if(!v(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 x(a){return()=>w(a)}var y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
9
+ function z(a){const [d,e]=h.useState(a.getEditorState().read(x(a.isComposing())));y(()=>a.addListener("update",({editorState:c})=>{const b=a.isComposing();c=c.read(x(b));e(c)}),[a]);return d}function A(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 r=d[f];f=a.getElementByKey(f);null!==f&&c.push(u.createPortal(r,f))}return c},[d,a])}
10
+ function C(a){a=a.anchor.getNode();return"rtl"===(t.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function D(a,d){a=a.getData("text/plain");null!=a&&d.insertRawText(a)}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)&&D(c,e)})}
11
+ function G(a,d){H(a,d);d.update(()=>{const e=t.$getSelection();t.$isRangeSelection(e)&&e.removeText()})}function H(a,d){a.preventDefault();d.update(()=>{const e=a.clipboardData,c=t.$getSelection();if(null!==c&&null!=e){var b=window.getSelection();if(!b.isCollapsed){var f=b.getRangeAt(0);f&&(b=document.createElement("div"),f=f.cloneContents(),b.appendChild(f),e.setData("text/html",b.innerHTML));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){h.useEffect(()=>{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?D(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=C(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=C(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=z(c);M(c,e);e=A(c);return h.createElement(h.Fragment,null,a,b&&d,e)};