@lexical/react 0.1.10 → 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 (59) hide show
  1. package/DEPRECATED_useLexicalAutoFormatter.dev.js +69 -28
  2. package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -18
  3. package/DEPRECATED_useLexicalCharacterLimit.dev.js +20 -17
  4. package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
  5. package/DEPRECATED_useLexicalList.dev.js +6 -0
  6. package/DEPRECATED_useLexicalList.prod.js +1 -1
  7. package/DEPRECATED_useLexicalPlainText.dev.js +61 -58
  8. package/DEPRECATED_useLexicalPlainText.prod.js +15 -15
  9. package/DEPRECATED_useLexicalRichText.dev.js +64 -61
  10. package/DEPRECATED_useLexicalRichText.prod.js +24 -25
  11. package/LexicalAutoFormatterPlugin.dev.js +69 -28
  12. package/LexicalAutoFormatterPlugin.js.flow +10 -0
  13. package/LexicalAutoFormatterPlugin.prod.js +20 -19
  14. package/LexicalAutoLinkPlugin.js.flow +23 -0
  15. package/LexicalCharacterLimitPlugin.dev.js +20 -17
  16. package/LexicalCharacterLimitPlugin.js.flow +12 -0
  17. package/LexicalCharacterLimitPlugin.prod.js +9 -8
  18. package/LexicalClearEditorPlugin.dev.js +52 -0
  19. package/LexicalClearEditorPlugin.js +9 -0
  20. package/LexicalClearEditorPlugin.js.flow +14 -0
  21. package/LexicalClearEditorPlugin.prod.js +7 -0
  22. package/LexicalCollaborationPlugin.dev.js +21 -11
  23. package/LexicalCollaborationPlugin.js.flow +55 -0
  24. package/LexicalCollaborationPlugin.prod.js +7 -7
  25. package/LexicalComposer.dev.js +7 -0
  26. package/LexicalComposer.js.flow +23 -0
  27. package/LexicalComposer.prod.js +3 -2
  28. package/LexicalComposerContext.js.flow +27 -0
  29. package/LexicalContentEditable.dev.js +14 -8
  30. package/LexicalContentEditable.js.flow +35 -0
  31. package/LexicalContentEditable.prod.js +3 -3
  32. package/LexicalHashtagPlugin.js.flow +20 -0
  33. package/LexicalHistoryPlugin.js.flow +34 -0
  34. package/LexicalHorizontalRuleNode.js.flow +25 -0
  35. package/LexicalLinkPlugin.js.flow +10 -0
  36. package/LexicalListPlugin.dev.js +6 -0
  37. package/LexicalListPlugin.js.flow +10 -0
  38. package/LexicalListPlugin.prod.js +2 -2
  39. package/LexicalNestedComposer.js.flow +21 -0
  40. package/LexicalOnChangePlugin.js.flow +14 -0
  41. package/LexicalPlainTextPlugin.dev.js +64 -60
  42. package/LexicalPlainTextPlugin.js.flow +18 -0
  43. package/LexicalPlainTextPlugin.prod.js +12 -12
  44. package/LexicalRichTextPlugin.dev.js +65 -61
  45. package/LexicalRichTextPlugin.js.flow +18 -0
  46. package/LexicalRichTextPlugin.prod.js +19 -20
  47. package/LexicalTablePlugin.dev.js +22 -0
  48. package/LexicalTablePlugin.js.flow +10 -0
  49. package/LexicalTablePlugin.prod.js +4 -3
  50. package/LexicalTreeView.js.flow +19 -0
  51. package/README.md +0 -1
  52. package/package.json +5 -5
  53. package/useLexicalDecoratorMap.js.flow +16 -0
  54. package/useLexicalIsTextContentEmpty.js.flow +15 -0
  55. package/useLexicalNodeSelection.js.flow +14 -0
  56. package/withSubscriptions.js.flow +13 -0
  57. package/LexicalBootstrapPlugin.dev.js +0 -122
  58. package/LexicalBootstrapPlugin.js +0 -9
  59. package/LexicalBootstrapPlugin.prod.js +0 -8
@@ -0,0 +1,10 @@
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
+ declare export default function LexicalLinkPlugin(): null;
@@ -43,6 +43,12 @@ function useList(editor) {
43
43
  } else if (type === 'removeList') {
44
44
  list.removeList(editor);
45
45
  return true;
46
+ } else if (type === 'insertParagraph') {
47
+ const hasHandledInsertParagraph = list.$handleListInsertParagraph();
48
+
49
+ if (hasHandledInsertParagraph) {
50
+ return true;
51
+ }
46
52
  }
47
53
 
48
54
  return false;
@@ -0,0 +1,10 @@
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
+ declare export default function ListPlugin(): null;
@@ -4,5 +4,5 @@
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/react/LexicalComposerContext"),d=require("@lexical/list"),e=require("react");function f(a){e.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(d.indentList())return!0}else if("outdentContent"===c){if(d.outdentList())return!0}else{if("insertOrderedList"===c)return d.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return d.insertList(a,"ul"),!0;if("removeList"===c)return d.removeList(a),!0}return!1},1),[a])}
8
- module.exports=function(){const [a]=b.useLexicalComposerContext();f(a);return null};
7
+ var b=require("@lexical/react/LexicalComposerContext"),d=require("@lexical/list"),e=require("react");
8
+ function f(a){e.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(d.indentList())return!0}else if("outdentContent"===c){if(d.outdentList())return!0}else{if("insertOrderedList"===c)return d.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return d.insertList(a,"ul"),!0;if("removeList"===c)return d.removeList(a),!0;if("insertParagraph"===c&&d.$handleListInsertParagraph())return!0}return!1},1),[a])}module.exports=function(){const [a]=b.useLexicalComposerContext();f(a);return null};
@@ -0,0 +1,21 @@
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 {DecoratorEditor, EditorThemeClasses, LexicalNode} from 'lexical';
11
+
12
+ declare export default function LexicalNestedComposer({
13
+ initialConfig?: {
14
+ namespace?: string,
15
+ decoratorEditor: DecoratorEditor,
16
+ nodes?: Array<Class<LexicalNode>>,
17
+ theme?: EditorThemeClasses,
18
+ onError?: (Error) => void,
19
+ },
20
+ children?: React$Node,
21
+ }): React$Node;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type {EditorState, LexicalEditor} from 'lexical';
11
+
12
+ declare export default function OnChangePlugin({
13
+ onChange: (editorState: EditorState, editor: LexicalEditor) => void,
14
+ }): null;
@@ -182,55 +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 resolveElement(element, isBackward, focusOffset) {
194
- const parent = element.getParent();
195
- let offset = focusOffset;
196
- let block = element;
197
-
198
- if (parent !== null) {
199
- if (isBackward && focusOffset === 0) {
200
- offset = block.getIndexWithinParent();
201
- block = parent;
202
- } else if (!isBackward && focusOffset === block.getChildrenSize()) {
203
- offset = block.getIndexWithinParent() + 1;
204
- block = parent;
205
- }
206
- }
207
-
208
- return block.getChildAtIndex(isBackward ? offset - 1 : offset);
209
- }
210
-
211
- function getPossibleDecoratorNode(focus, isBackward) {
212
- const focusOffset = focus.offset;
213
-
214
- if (focus.type === 'element') {
215
- const block = focus.getNode();
216
- return resolveElement(block, isBackward, focusOffset);
217
- } else {
218
- const focusNode = focus.getNode();
219
-
220
- if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
221
- const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
222
-
223
- if (possibleNode === null) {
224
- return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
225
- }
226
-
227
- return possibleNode;
228
- }
229
- }
230
-
231
- return null;
232
- }
233
-
234
185
  /**
235
186
  * Copyright (c) Meta Platforms, Inc. and affiliates.
236
187
  *
@@ -247,7 +198,7 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
247
198
  }
248
199
  }
249
200
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
250
- const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
201
+ const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
251
202
  return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
252
203
  }
253
204
  function onPasteForPlainText(event, editor) {
@@ -300,6 +251,62 @@ function onCopyForPlainText(event, editor) {
300
251
  });
301
252
  }
302
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
+
303
310
  /**
304
311
  * Copyright (c) Meta Platforms, Inc. and affiliates.
305
312
  *
@@ -396,7 +403,7 @@ function useLexicalDragonSupport(editor) {
396
403
  *
397
404
  *
398
405
  */
399
- function usePlainTextSetup(editor) {
406
+ function usePlainTextSetup(editor, initialEditorState) {
400
407
  React.useEffect(() => {
401
408
  const removeListener = editor.addListener('command', (type, payload) => {
402
409
  const selection = lexical.$getSelection();
@@ -556,13 +563,9 @@ function usePlainTextSetup(editor) {
556
563
 
557
564
  return false;
558
565
  }, 0);
559
- const bootstrapCommandHandled = editor.execCommand('bootstrapEditor');
560
-
561
- if (!bootstrapCommandHandled) {
562
- console.warn('bootstrapEditor command was not handled. Did you forget to add <BootstrapPlugin />?');
563
- }
564
-
565
- return removeListener;
566
+ initializeEditor(editor, initialEditorState);
567
+ return removeListener; // We only do this for init
568
+ // eslint-disable-next-line react-hooks/exhaustive-deps
566
569
  }, [editor]);
567
570
  useLexicalDragonSupport(editor);
568
571
  }
@@ -577,11 +580,12 @@ function usePlainTextSetup(editor) {
577
580
  */
578
581
  function PlainTextPlugin({
579
582
  contentEditable,
580
- placeholder
583
+ placeholder,
584
+ initialEditorState
581
585
  }) {
582
586
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
583
587
  const showPlaceholder = useLexicalCanShowPlaceholder(editor);
584
- usePlainTextSetup(editor);
588
+ usePlainTextSetup(editor, initialEditorState);
585
589
  const decorators = useDecorators(editor);
586
590
  return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
587
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,15 +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"),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 c=0;c<e;c++){var b=a[c];if(t.$isElementNode(b)){if("paragraph"!==b.__type||0!==b.__indent)return!1;b=b.getChildren();const d=b.length;for(let f=0;f<d;f++)if(!t.$isTextNode(b[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 [e,b]=h.useState(a.getEditorState().read(x(a.isComposing())));y(()=>a.addListener("update",({editorState:c})=>{const d=a.isComposing();c=c.read(x(d));b(c)}),[a]);return e}function A(a){const [e,b]=h.useState(()=>a.getDecorators());y(()=>a.addListener("decorator",c=>{u.flushSync(()=>{b(c)})}),[a]);return h.useMemo(()=>{const c=[],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&&c.push(u.createPortal(r,f))}return c},[e,a])}
10
- function C(a){a=a.anchor.getNode();return"rtl"===(t.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function D(a,e,b){const c=a.getParent();let d=b;null!==c&&(e&&0===b?(d=a.getIndexWithinParent(),a=c):e||b!==a.getChildrenSize()||(d=a.getIndexWithinParent()+1,a=c));return a.getChildAtIndex(e?d-1:d)}function E(a,e){a=a.getData("text/plain");null!=a&&e.insertRawText(a)}
11
- function F(a,e){var b=a.focus;a=b.offset;"element"===b.type?(b=b.getNode(),e=D(b,e,a)):(b=b.getNode(),e&&0===a||!e&&a===b.getTextContentSize()?(a=e?b.getPreviousSibling():b.getNextSibling(),e=null===a?D(b.getParentOrThrow(),e,b.getIndexWithinParent()+(e?0:1)):a):e=null);return t.$isDecoratorNode(e)&&!e.isIsolated()}function G(a,e){a.preventDefault();e.update(()=>{const b=t.$getSelection(),c=a.clipboardData;null!=c&&t.$isRangeSelection(b)&&E(c,b)})}
12
- function H(a,e){I(a,e);e.update(()=>{const b=t.$getSelection();t.$isRangeSelection(b)&&b.removeText()})}function I(a,e){a.preventDefault();e.update(()=>{const b=a.clipboardData,c=t.$getSelection();if(null!==c&&null!=b){var d=window.getSelection();if(!d.isCollapsed){var f=d.getRangeAt(0);f&&(d=document.createElement("div"),f=f.cloneContents(),d.appendChild(f),b.setData("text/html",d.innerHTML));b.setData("text/plain",c.getTextContent())}}})}
13
- function J(a){h.useEffect(()=>{const e=b=>{var c=a.getRootElement();if(document.activeElement===c&&(c=b.data,"string"===typeof c)){try{var d=JSON.parse(c)}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,B,K]=d;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+K,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));b.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
15
- function L(a){h.useEffect(()=>{const e=a.addListener("command",(b,c)=>{const d=t.$getSelection();if(!t.$isRangeSelection(d))return!1;switch(b){case "deleteCharacter":return d.deleteCharacter(c),!0;case "deleteWord":return d.deleteWord(c),!0;case "deleteLine":return d.deleteLine(c),!0;case "insertText":return"string"===typeof c?d.insertText(c):(b=c.dataTransfer,null!=b?E(b,d):(c=c.data)&&d.insertText(c)),!0;case "removeText":return d.removeText(),!0;case "insertLineBreak":return d.insertLineBreak(c),
16
- !0;case "insertParagraph":return d.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b=c.shiftKey;if(F(d,!0))return c.preventDefault(),c=b,b=C(d),d.modify(c?"extend":"move",!b,"character"),!0;break;case "keyArrowRight":b=c.shiftKey;if(F(d,!1))return c.preventDefault(),c=b,b=C(d),d.modify(c?"extend":"move",b,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
17
- a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "copy":return I(c,a),!0;case "cut":return H(c,a),!0;case "paste":return G(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return e},[a]);J(a)}
18
- module.exports=function({contentEditable:a,placeholder:e}){var [b]=g.useLexicalComposerContext();const c=z(b);L(b);b=A(b);return h.createElement(h.Fragment,null,a,c&&e,b)};
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)};
@@ -364,55 +364,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
364
364
  $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
365
365
  }
366
366
 
367
- /**
368
- * Copyright (c) Meta Platforms, Inc. and affiliates.
369
- *
370
- * This source code is licensed under the MIT license found in the
371
- * LICENSE file in the root directory of this source tree.
372
- *
373
- *
374
- */
375
- function resolveElement(element, isBackward, focusOffset) {
376
- const parent = element.getParent();
377
- let offset = focusOffset;
378
- let block = element;
379
-
380
- if (parent !== null) {
381
- if (isBackward && focusOffset === 0) {
382
- offset = block.getIndexWithinParent();
383
- block = parent;
384
- } else if (!isBackward && focusOffset === block.getChildrenSize()) {
385
- offset = block.getIndexWithinParent() + 1;
386
- block = parent;
387
- }
388
- }
389
-
390
- return block.getChildAtIndex(isBackward ? offset - 1 : offset);
391
- }
392
-
393
- function getPossibleDecoratorNode(focus, isBackward) {
394
- const focusOffset = focus.offset;
395
-
396
- if (focus.type === 'element') {
397
- const block = focus.getNode();
398
- return resolveElement(block, isBackward, focusOffset);
399
- } else {
400
- const focusNode = focus.getNode();
401
-
402
- if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
403
- const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
404
-
405
- if (possibleNode === null) {
406
- return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
407
- }
408
-
409
- return possibleNode;
410
- }
411
- }
412
-
413
- return null;
414
- }
415
-
416
367
  /**
417
368
  * Copyright (c) Meta Platforms, Inc. and affiliates.
418
369
  *
@@ -598,7 +549,7 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
598
549
  }
599
550
  }
600
551
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
601
- const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
552
+ const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
602
553
  return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
603
554
  }
604
555
  function onPasteForRichText(event, editor) {
@@ -656,6 +607,62 @@ function onCopyForRichText(event, editor) {
656
607
  });
657
608
  }
658
609
 
610
+ /**
611
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
612
+ *
613
+ * This source code is licensed under the MIT license found in the
614
+ * LICENSE file in the root directory of this source tree.
615
+ *
616
+ *
617
+ */
618
+ // Convoluted logic to make this work with Flow. Order matters.
619
+ const options = {
620
+ tag: 'history-merge'
621
+ };
622
+ const setEditorOptions = options;
623
+ const updateOptions = options;
624
+ function initializeEditor(editor, initialEditorState) {
625
+ if (initialEditorState === null) {
626
+ return;
627
+ } else if (initialEditorState === undefined) {
628
+ editor.update(() => {
629
+ const root = lexical.$getRoot();
630
+ const firstChild = root.getFirstChild();
631
+
632
+ if (firstChild === null) {
633
+ const paragraph = lexical.$createParagraphNode();
634
+ root.append(paragraph);
635
+ const activeElement = document.activeElement;
636
+
637
+ if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
638
+ paragraph.select();
639
+ }
640
+ }
641
+ }, updateOptions);
642
+ } else if (initialEditorState !== null) {
643
+ switch (typeof initialEditorState) {
644
+ case 'string':
645
+ {
646
+ const parsedEditorState = editor.parseEditorState(initialEditorState);
647
+ editor.setEditorState(parsedEditorState, setEditorOptions);
648
+ break;
649
+ }
650
+
651
+ case 'object':
652
+ {
653
+ editor.setEditorState(initialEditorState, setEditorOptions);
654
+ break;
655
+ }
656
+
657
+ case 'function':
658
+ {
659
+ editor.update(initialEditorState, updateOptions);
660
+ break;
661
+ }
662
+ }
663
+ }
664
+ }
665
+
659
666
  /**
660
667
  * Copyright (c) Meta Platforms, Inc. and affiliates.
661
668
  *
@@ -752,8 +759,8 @@ function useLexicalDragonSupport(editor) {
752
759
  *
753
760
  *
754
761
  */
755
- function useRichTextSetup(editor) {
756
- React.useEffect(() => {
762
+ function useRichTextSetup(editor, initialEditorState) {
763
+ React.useLayoutEffect(() => {
757
764
  const removeListener = editor.addListener('command', (type, payload) => {
758
765
  const selection = lexical.$getSelection();
759
766
 
@@ -992,13 +999,9 @@ function useRichTextSetup(editor) {
992
999
 
993
1000
  return false;
994
1001
  }, 0);
995
- const bootstrapCommandHandled = editor.execCommand('bootstrapEditor');
996
-
997
- if (!bootstrapCommandHandled) {
998
- console.warn('bootstrapEditor command was not handled. Did you forget to add <BootstrapPlugin />?');
999
- }
1000
-
1001
- return removeListener;
1002
+ initializeEditor(editor, initialEditorState);
1003
+ return removeListener; // We only do this for init
1004
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1002
1005
  }, [editor]);
1003
1006
  useLexicalDragonSupport(editor);
1004
1007
  }
@@ -1013,11 +1016,12 @@ function useRichTextSetup(editor) {
1013
1016
  */
1014
1017
  function RichTextPlugin({
1015
1018
  contentEditable,
1016
- placeholder
1019
+ placeholder,
1020
+ initialEditorState
1017
1021
  }) {
1018
1022
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
1019
1023
  const showPlaceholder = useLexicalCanShowPlaceholder(editor);
1020
- useRichTextSetup(editor);
1024
+ useRichTextSetup(editor, initialEditorState);
1021
1025
  const decorators = useDecorators(editor);
1022
1026
  return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
1023
1027
  }
@@ -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 RichTextPlugin({
15
+ contentEditable: React$Node,
16
+ initialEditorState?: InitialEditorStateType,
17
+ placeholder: React$Node,
18
+ }): React$Node;
@@ -5,24 +5,23 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var g=require("@lexical/react/LexicalComposerContext"),u=require("react"),y=require("lexical"),z=require("react-dom");function A(a,e=!0){if(a)return!1;a=y.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
8
- function B(a){if(!A(a,!1))return!1;a=y.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let b=0;b<e;b++){var d=a[b];if(y.$isElementNode(d)){if("paragraph"!==d.__type||0!==d.__indent)return!1;d=d.getChildren();const c=d.length;for(let f=0;f<c;f++)if(!y.$isTextNode(d[b]))return!1}}return!0}function C(a){return()=>B(a)}var D="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?u.useLayoutEffect:u.useEffect;
9
- function E(a){const [e,d]=u.useState(a.getEditorState().read(C(a.isComposing())));D(()=>a.addListener("update",({editorState:b})=>{const c=a.isComposing();b=b.read(C(c));d(b)}),[a]);return e}function F(a){const [e,d]=u.useState(()=>a.getDecorators());D(()=>a.addListener("decorator",b=>{z.flushSync(()=>{d(b)})}),[a]);return u.useMemo(()=>{const b=[],c=Object.keys(e);for(let k=0;k<c.length;k++){var f=c[k];const h=e[f];f=a.getElementByKey(f);null!==f&&b.push(z.createPortal(h,f))}return b},[e,a])}
8
+ function B(a){if(!A(a,!1))return!1;a=y.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let c=0;c<e;c++){var f=a[c];if(y.$isElementNode(f)){if("paragraph"!==f.__type||0!==f.__indent)return!1;f=f.getChildren();const d=f.length;for(let b=0;b<d;b++)if(!y.$isTextNode(f[c]))return!1}}return!0}function C(a){return()=>B(a)}var D="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?u.useLayoutEffect:u.useEffect;
9
+ function E(a){const [e,f]=u.useState(a.getEditorState().read(C(a.isComposing())));D(()=>a.addListener("update",({editorState:c})=>{const d=a.isComposing();c=c.read(C(d));f(c)}),[a]);return e}function F(a){const [e,f]=u.useState(()=>a.getDecorators());D(()=>a.addListener("decorator",c=>{z.flushSync(()=>{f(c)})}),[a]);return u.useMemo(()=>{const c=[],d=Object.keys(e);for(let k=0;k<d.length;k++){var b=d[k];const h=e[b];b=a.getElementByKey(b);null!==b&&c.push(z.createPortal(h,b))}return c},[e,a])}
10
10
  function G(a){a=a.getLatest();const e=a.constructor.clone(a);e.__parent=a.__parent;y.$isElementNode(a)&&y.$isElementNode(e)?(e.__children=Array.from(a.__children),e.__format=a.__format,e.__indent=a.__indent,e.__dir=a.__dir):y.$isTextNode(a)&&y.$isTextNode(e)?(e.__format=a.__format,e.__style=a.__style,e.__mode=a.__mode,e.__detail=a.__detail):y.$isDecoratorNode(a)&&y.$isDecoratorNode(e)&&(e.__state=a.__state);return e}
11
- function H(a,e,d,b,c){for(var f=e;null!==a;){for(e=a.getParent();null!==e&&e.excludeFromCopy();)e=e.getParent();if(null===e)break;if(!y.$isElementNode(a)||!a.excludeFromCopy()){const k=a.getKey();let h=c.get(k);const l=void 0===h;l&&(h=G(a),c.set(k,h));!y.$isTextNode(h)||h.isSegmented()||h.isToken()?y.$isElementNode(h)&&(h.__children=h.__children.slice(d?f:0,d?void 0:f+1)):h.__text=h.__text.slice(d?f:0,d?void 0:f);if(y.$isRootNode(e)){l&&b.push(k);break}}f=c.get(e.getKey());f=y.$isElementNode(f)?
12
- f.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=e}}function I(a){a=a.anchor.getNode();return"rtl"===(y.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function J(a,e,d){const b=a.getParent();let c=d;null!==b&&(e&&0===d?(c=a.getIndexWithinParent(),a=b):e||d!==a.getChildrenSize()||(c=a.getIndexWithinParent()+1,a=b));return a.getChildAtIndex(e?c-1:c)}
13
- function K(a,e){const {nodeName:d}=a;e=e._htmlConversions.get(d.toLowerCase());let b=null;void 0!==e&&e.forEach(c=>{c=c(a);null!==c&&(null===b||b.priority<c.priority)&&(b=c)});return null!==b?b.conversion:null}
14
- function L(a,e,d=new Map){let b=[],c=null;var f=K(a,e),k=f?f(a):null;f=null;if(null!==k){f=k.after;c=k.node;if(null!==c){b.push(c);var h=Array.from(d.values());for(let l=0;l<h.length;l++)h[l](c)}null!=k.forChild&&d.set(a.nodeName,k.forChild)}a=a.childNodes;k=[];for(h=0;h<a.length;h++)k.push(...L(a[h],e,d));null!=f&&(k=f(k));null==c?b=b.concat(k):y.$isElementNode(c)&&c.append(...k);return b}
15
- function M(a,e,d){var b=a.getData("application/x-lexical-editor");if(b){var c=d._config.namespace;try{const l=JSON.parse(b);if(l.namespace===c){const {range:t,nodeMap:m}=l.state;var f=new Map(m);b=[];for(c=0;c<t.length;c++){var k=f.get(t[c]);if(void 0!==k){var h=y.$createNodeFromParse(k,f);b.push(h)}}e.insertNodes(b);return}}catch(l){}}if(f=a.getData("text/html")){f=(new DOMParser).parseFromString(f,"text/html");a=[];f=f.body?Array.from(f.body.childNodes):[];k=f.length;for(h=0;h<k;h++)b=L(f[h],d),
16
- null!==b&&(a=a.concat(b));d=a;a=[];f=null;for(k=0;k<d.length;k++)h=d[k],!y.$isElementNode(h)||h.isInline()?(null===f&&(f=y.$createParagraphNode(),a.push(f)),null!==f&&f.append(h)):(a.push(h),f=null);e.insertNodes(a)}else d=a.getData("text/plain"),null!=d&&e.insertRawText(d)}
17
- function N(a,e){var d=a.focus;a=d.offset;"element"===d.type?(d=d.getNode(),e=J(d,e,a)):(d=d.getNode(),e&&0===a||!e&&a===d.getTextContentSize()?(a=e?d.getPreviousSibling():d.getNextSibling(),e=null===a?J(d.getParentOrThrow(),e,d.getIndexWithinParent()+(e?0:1)):a):e=null);return y.$isDecoratorNode(e)&&!e.isIsolated()}function O(a,e){a.preventDefault();e.update(()=>{const d=y.$getSelection(),b=a.clipboardData;null!=b&&y.$isRangeSelection(d)&&M(b,d,e)})}
18
- function P(a,e){Q(a,e);e.update(()=>{const d=y.$getSelection();y.$isRangeSelection(d)&&d.removeText()})}
19
- function Q(a,e){a.preventDefault();e.update(()=>{const d=a.clipboardData;var b=y.$getSelection();if(null!==b&&null!=d){var c=window.getSelection();if(!c.isCollapsed){var f=c.getRangeAt(0);f&&(c=document.createElement("div"),f=f.cloneContents(),c.appendChild(f),d.setData("text/html",c.innerHTML));d.setData("text/plain",b.getTextContent());c=e._config.namespace;f=d.setData;var k=JSON,h=k.stringify;{if(!y.$isRangeSelection(b))throw Error("Minified Lexical error #68; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");
20
- var l=b.anchor,t=b.focus;var m=l.getCharacterOffset();const x=t.getCharacterOffset();var n=l.getNode(),q=t.getNode(),p=n.getParentOrThrow();if(n===q&&y.$isTextNode(n)&&(p.canBeEmpty()||1<p.getChildrenSize()))b=G(n),n=x>m,b.__text=b.__text.slice(n?m:x,n?x:m),m=b.getKey(),m={nodeMap:[[m,b]],range:[m]};else if(b=b.getNodes(),0===b.length)m={nodeMap:[],range:[]};else{n=b.length;q=b[0];p=q.getParent();if(null!==p&&(!p.canBeEmpty()||y.$isRootNode(p))){var r=p.__children;if(r.length===n){var v=!0;for(var w=
21
- 0;w<r.length;w++)if(r[w]!==b[w].__key){v=!1;break}v&&(n++,b.push(p))}}p=b[n-1];l=l.isBefore(t);t=new Map;r=[];H(q,l?m:x,!0,r,t);for(q=0;q<n;q++)if(v=b[q],w=v.getKey(),!(t.has(w)||y.$isElementNode(v)&&v.excludeFromCopy())){const R=G(v);y.$isRootNode(v.getParent())&&r.push(v.getKey());t.set(w,R)}H(p,l?x:m,!1,r,t);m={nodeMap:Array.from(t.entries()),range:r}}}f.call(d,"application/x-lexical-editor",h.call(k,{namespace:c,state:m}))}}})}
22
- function S(a){u.useEffect(()=>{const e=d=>{var b=a.getRootElement();if(document.activeElement===b&&(b=d.data,"string"===typeof b)){try{var c=JSON.parse(b)}catch(f){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [f,k,h,l,t]=c;a.update(()=>{const m=y.$getSelection();if(y.$isRangeSelection(m)){var n=m.anchor;let q=n.getNode(),p=0,r=0;y.$isTextNode(q)&&0<=f&&0<=k&&(p=f,r=f+k,m.setTextNodeRange(q,p,q,r));if(p!==r||""!==
23
- h)m.insertRawText(h),q=n.getNode();y.$isTextNode(q)&&(p=l,r=l+t,n=q.getTextContentSize(),p=p>n?n:p,r=r>n?n:r,m.setTextNodeRange(q,p,q,r));d.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
24
- function T(a){u.useEffect(()=>{const e=a.addListener("command",(d,b)=>{var c=y.$getSelection();if("click"===d&&y.$isNodeSelection(c))return c.clear(),!0;if(!y.$isRangeSelection(c))return!1;switch(d){case "deleteCharacter":return c.deleteCharacter(b),!0;case "deleteWord":return c.deleteWord(b),!0;case "deleteLine":return c.deleteLine(b),!0;case "insertText":return"string"===typeof b?c.insertText(b):(d=b.dataTransfer,null!=d?M(d,c,a):(b=b.data)&&c.insertText(b)),!0;case "removeText":return c.removeText(),
25
- !0;case "formatText":return c.formatText(b),!0;case "formatElement":return c=c.anchor.getNode(),(y.$isElementNode(c)?c:c.getParentOrThrow()).setFormat(b),!0;case "insertLineBreak":return c.insertLineBreak(b),!0;case "insertParagraph":return c.insertParagraph(),!0;case "indentContent":return c=c.anchor,c="element"===c.type?c.getNode():c.getNode().getParentOrThrow(),c.canInsertTab()?a.execCommand("insertText","\t"):10!==c.getIndent()&&c.setIndent(c.getIndent()+1),!0;case "outdentContent":return c=c.anchor,
26
- b=c.getNode(),d="element"===c.type?c.getNode():c.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===b.getTextContent()[c.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=b.shiftKey;if(N(c,!0))return b.preventDefault(),b=d,d=I(c),c.modify(b?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=b.shiftKey;if(N(c,!1))return b.preventDefault(),b=d,d=I(c),c.modify(b?"extend":"move",d,"character"),!0;break;case "keyBackspace":return b.preventDefault(),
27
- {anchor:b}=c,c.isCollapsed()&&0===b.offset&&0<("element"===b.type?b.getNode():b.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),b.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return b.preventDefault(),a.execCommand(b.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
28
- !0;case "copy":return Q(b,a),!0;case "cut":return P(b,a),!0;case "paste":return O(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return e},[a]);S(a)}module.exports=function({contentEditable:a,placeholder:e}){var [d]=g.useLexicalComposerContext();const b=E(d);T(d);d=F(d);return u.createElement(u.Fragment,null,a,b&&e,d)};
11
+ function H(a,e,f,c,d){for(var b=e;null!==a;){for(e=a.getParent();null!==e&&e.excludeFromCopy();)e=e.getParent();if(null===e)break;if(!y.$isElementNode(a)||!a.excludeFromCopy()){const k=a.getKey();let h=d.get(k);const l=void 0===h;l&&(h=G(a),d.set(k,h));!y.$isTextNode(h)||h.isSegmented()||h.isToken()?y.$isElementNode(h)&&(h.__children=h.__children.slice(f?b:0,f?void 0:b+1)):h.__text=h.__text.slice(f?b:0,f?void 0:b);if(y.$isRootNode(e)){l&&c.push(k);break}}b=d.get(e.getKey());b=y.$isElementNode(b)?
12
+ b.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=e}}function I(a){a=a.anchor.getNode();return"rtl"===(y.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function J(a,e){const {nodeName:f}=a;e=e._htmlConversions.get(f.toLowerCase());let c=null;void 0!==e&&e.forEach(d=>{d=d(a);null!==d&&(null===c||c.priority<d.priority)&&(c=d)});return null!==c?c.conversion:null}
13
+ function K(a,e,f=new Map){let c=[],d=null;var b=J(a,e),k=b?b(a):null;b=null;if(null!==k){b=k.after;d=k.node;if(null!==d){c.push(d);var h=Array.from(f.values());for(let l=0;l<h.length;l++)h[l](d)}null!=k.forChild&&f.set(a.nodeName,k.forChild)}a=a.childNodes;k=[];for(h=0;h<a.length;h++)k.push(...K(a[h],e,f));null!=b&&(k=b(k));null==d?c=c.concat(k):y.$isElementNode(d)&&d.append(...k);return c}
14
+ function L(a,e,f){var c=a.getData("application/x-lexical-editor");if(c){var d=f._config.namespace;try{const l=JSON.parse(c);if(l.namespace===d){const {range:t,nodeMap:m}=l.state;var b=new Map(m);c=[];for(d=0;d<t.length;d++){var k=b.get(t[d]);if(void 0!==k){var h=y.$createNodeFromParse(k,b);c.push(h)}}e.insertNodes(c);return}}catch(l){}}if(b=a.getData("text/html")){b=(new DOMParser).parseFromString(b,"text/html");a=[];b=b.body?Array.from(b.body.childNodes):[];k=b.length;for(h=0;h<k;h++)c=K(b[h],f),
15
+ null!==c&&(a=a.concat(c));f=a;a=[];b=null;for(k=0;k<f.length;k++)h=f[k],!y.$isElementNode(h)||h.isInline()?(null===b&&(b=y.$createParagraphNode(),a.push(b)),null!==b&&b.append(h)):(a.push(h),b=null);e.insertNodes(a)}else f=a.getData("text/plain"),null!=f&&e.insertRawText(f)}function M(a,e){a=y.$getDecoratorNode(a.focus,e);return y.$isDecoratorNode(a)&&!a.isIsolated()}
16
+ function N(a,e){a.preventDefault();e.update(()=>{const f=y.$getSelection(),c=a.clipboardData;null!=c&&y.$isRangeSelection(f)&&L(c,f,e)})}function O(a,e){P(a,e);e.update(()=>{const f=y.$getSelection();y.$isRangeSelection(f)&&f.removeText()})}
17
+ function P(a,e){a.preventDefault();e.update(()=>{const f=a.clipboardData;var c=y.$getSelection();if(null!==c&&null!=f){var d=window.getSelection();if(!d.isCollapsed){var b=d.getRangeAt(0);b&&(d=document.createElement("div"),b=b.cloneContents(),d.appendChild(b),f.setData("text/html",d.innerHTML));f.setData("text/plain",c.getTextContent());d=e._config.namespace;b=f.setData;var k=JSON,h=k.stringify;{if(!y.$isRangeSelection(c))throw Error("Minified Lexical error #68; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");
18
+ var l=c.anchor,t=c.focus;var m=l.getCharacterOffset();const x=t.getCharacterOffset();var n=l.getNode(),q=t.getNode(),p=n.getParentOrThrow();if(n===q&&y.$isTextNode(n)&&(p.canBeEmpty()||1<p.getChildrenSize()))c=G(n),n=x>m,c.__text=c.__text.slice(n?m:x,n?x:m),m=c.getKey(),m={nodeMap:[[m,c]],range:[m]};else if(c=c.getNodes(),0===c.length)m={nodeMap:[],range:[]};else{n=c.length;q=c[0];p=q.getParent();if(null!==p&&(!p.canBeEmpty()||y.$isRootNode(p))){var r=p.__children;if(r.length===n){var v=!0;for(var w=
19
+ 0;w<r.length;w++)if(r[w]!==c[w].__key){v=!1;break}v&&(n++,c.push(p))}}p=c[n-1];l=l.isBefore(t);t=new Map;r=[];H(q,l?m:x,!0,r,t);for(q=0;q<n;q++)if(v=c[q],w=v.getKey(),!(t.has(w)||y.$isElementNode(v)&&v.excludeFromCopy())){const R=G(v);y.$isRootNode(v.getParent())&&r.push(v.getKey());t.set(w,R)}H(p,l?x:m,!1,r,t);m={nodeMap:Array.from(t.entries()),range:r}}}b.call(f,"application/x-lexical-editor",h.call(k,{namespace:d,state:m}))}}})}const Q={tag:"history-merge"};
20
+ function S(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=y.$getRoot();if(null===f.getFirstChild()){const c=y.$createParagraphNode();f.append(c);f=document.activeElement;(null!==y.$getSelection()||null!==f&&f===a.getRootElement())&&c.select()}},Q);else if(null!==e)switch(typeof e){case "string":e=a.parseEditorState(e);a.setEditorState(e,Q);break;case "object":a.setEditorState(e,Q);break;case "function":a.update(e,Q)}}
21
+ function T(a){u.useEffect(()=>{const e=f=>{var c=a.getRootElement();if(document.activeElement===c&&(c=f.data,"string"===typeof c)){try{var d=JSON.parse(c)}catch(b){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [b,k,h,l,t]=d;a.update(()=>{const m=y.$getSelection();if(y.$isRangeSelection(m)){var n=m.anchor;let q=n.getNode(),p=0,r=0;y.$isTextNode(q)&&0<=b&&0<=k&&(p=b,r=b+k,m.setTextNodeRange(q,p,q,r));if(p!==r||""!==
22
+ h)m.insertRawText(h),q=n.getNode();y.$isTextNode(q)&&(p=l,r=l+t,n=q.getTextContentSize(),p=p>n?n:p,r=r>n?n:r,m.setTextNodeRange(q,p,q,r));f.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
23
+ function U(a,e){u.useLayoutEffect(()=>{const f=a.addListener("command",(c,d)=>{var b=y.$getSelection();if("click"===c&&y.$isNodeSelection(b))return b.clear(),!0;if(!y.$isRangeSelection(b))return!1;switch(c){case "deleteCharacter":return b.deleteCharacter(d),!0;case "deleteWord":return b.deleteWord(d),!0;case "deleteLine":return b.deleteLine(d),!0;case "insertText":return"string"===typeof d?b.insertText(d):(c=d.dataTransfer,null!=c?L(c,b,a):(d=d.data)&&b.insertText(d)),!0;case "removeText":return b.removeText(),
24
+ !0;case "formatText":return b.formatText(d),!0;case "formatElement":return b=b.anchor.getNode(),(y.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(d),!0;case "insertLineBreak":return b.insertLineBreak(d),!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,
25
+ d=b.getNode(),c="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),c.canInsertTab()?"\t"===d.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==c.getIndent()&&c.setIndent(c.getIndent()-1),!0;case "keyArrowLeft":c=d.shiftKey;if(M(b,!0))return d.preventDefault(),d=c,c=I(b),b.modify(d?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=d.shiftKey;if(M(b,!1))return d.preventDefault(),d=c,c=I(b),b.modify(d?"extend":"move",c,"character"),!0;break;case "keyBackspace":return d.preventDefault(),
26
+ {anchor:d}=b,b.isCollapsed()&&0===d.offset&&0<("element"===d.type?d.getNode():d.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return d.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return d.preventDefault(),d.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return d.preventDefault(),a.execCommand(d.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
27
+ !0;case "copy":return P(d,a),!0;case "cut":return O(d,a),!0;case "paste":return N(d,a),!0;case "drop":case "dragstart":return d.preventDefault(),!0}return!1},0);S(a,e);return f},[a]);T(a)}module.exports=function({contentEditable:a,placeholder:e,initialEditorState:f}){const [c]=g.useLexicalComposerContext(),d=E(c);U(c,f);f=F(c);return u.createElement(u.Fragment,null,a,d&&e,f)};