@lexical/react 0.1.10 → 0.1.13

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 (86) hide show
  1. package/DEPRECATED_useLexical.dev.js +3 -7
  2. package/DEPRECATED_useLexical.prod.js +1 -1
  3. package/DEPRECATED_useLexicalAutoFormatter.dev.js +83 -37
  4. package/DEPRECATED_useLexicalAutoFormatter.prod.js +20 -19
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +20 -17
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
  7. package/DEPRECATED_useLexicalList.dev.js +6 -0
  8. package/DEPRECATED_useLexicalList.prod.js +1 -1
  9. package/DEPRECATED_useLexicalPlainText.dev.js +84 -75
  10. package/DEPRECATED_useLexicalPlainText.prod.js +15 -15
  11. package/DEPRECATED_useLexicalRichText.dev.js +96 -438
  12. package/DEPRECATED_useLexicalRichText.prod.js +17 -26
  13. package/LexicalAutoFormatterPlugin.d.ts +9 -0
  14. package/LexicalAutoFormatterPlugin.dev.js +83 -37
  15. package/LexicalAutoFormatterPlugin.js.flow +10 -0
  16. package/LexicalAutoFormatterPlugin.prod.js +21 -20
  17. package/LexicalAutoLinkPlugin.d.ts +20 -0
  18. package/LexicalAutoLinkPlugin.js.flow +23 -0
  19. package/LexicalCharacterLimitPlugin.d.ts +11 -0
  20. package/LexicalCharacterLimitPlugin.dev.js +20 -17
  21. package/LexicalCharacterLimitPlugin.js.flow +12 -0
  22. package/LexicalCharacterLimitPlugin.prod.js +9 -8
  23. package/LexicalClearEditorPlugin.d.ts +14 -0
  24. package/LexicalClearEditorPlugin.dev.js +73 -0
  25. package/LexicalClearEditorPlugin.js +9 -0
  26. package/LexicalClearEditorPlugin.js.flow +14 -0
  27. package/LexicalClearEditorPlugin.prod.js +8 -0
  28. package/LexicalCollaborationPlugin.d.ts +49 -0
  29. package/LexicalCollaborationPlugin.dev.js +21 -13
  30. package/LexicalCollaborationPlugin.js.flow +55 -0
  31. package/LexicalCollaborationPlugin.prod.js +7 -7
  32. package/LexicalComposer.d.ts +22 -0
  33. package/LexicalComposer.dev.js +32 -3
  34. package/LexicalComposer.js.flow +24 -0
  35. package/LexicalComposer.prod.js +3 -2
  36. package/LexicalComposerContext.d.ts +24 -0
  37. package/LexicalComposerContext.js.flow +27 -0
  38. package/LexicalContentEditable.d.ts +32 -0
  39. package/LexicalContentEditable.dev.js +35 -8
  40. package/LexicalContentEditable.js.flow +35 -0
  41. package/LexicalContentEditable.prod.js +3 -3
  42. package/LexicalHashtagPlugin.d.ts +9 -0
  43. package/LexicalHashtagPlugin.js.flow +10 -0
  44. package/LexicalHistoryPlugin.d.ts +29 -0
  45. package/LexicalHistoryPlugin.js.flow +34 -0
  46. package/LexicalHorizontalRuleNode.d.ts +23 -0
  47. package/LexicalHorizontalRuleNode.js.flow +25 -0
  48. package/LexicalLinkPlugin.d.ts +9 -0
  49. package/LexicalLinkPlugin.js.flow +10 -0
  50. package/LexicalListPlugin.d.ts +9 -0
  51. package/LexicalListPlugin.dev.js +6 -0
  52. package/LexicalListPlugin.js.flow +10 -0
  53. package/LexicalListPlugin.prod.js +2 -2
  54. package/LexicalNestedComposer.d.ts +17 -0
  55. package/LexicalNestedComposer.dev.js +21 -11
  56. package/LexicalNestedComposer.js.flow +18 -0
  57. package/LexicalNestedComposer.prod.js +3 -2
  58. package/LexicalOnChangePlugin.d.ts +12 -0
  59. package/LexicalOnChangePlugin.js.flow +14 -0
  60. package/LexicalPlainTextPlugin.d.ts +15 -0
  61. package/LexicalPlainTextPlugin.dev.js +73 -84
  62. package/LexicalPlainTextPlugin.js.flow +18 -0
  63. package/LexicalPlainTextPlugin.prod.js +12 -12
  64. package/LexicalRichTextPlugin.d.ts +15 -0
  65. package/LexicalRichTextPlugin.dev.js +85 -447
  66. package/LexicalRichTextPlugin.js.flow +18 -0
  67. package/LexicalRichTextPlugin.prod.js +13 -22
  68. package/LexicalTablePlugin.d.ts +9 -0
  69. package/LexicalTablePlugin.dev.js +22 -0
  70. package/LexicalTablePlugin.js.flow +10 -0
  71. package/LexicalTablePlugin.prod.js +4 -3
  72. package/LexicalTreeView.d.ts +17 -0
  73. package/LexicalTreeView.js.flow +19 -0
  74. package/README.md +0 -1
  75. package/package.json +9 -5
  76. package/useLexicalDecoratorMap.d.ts +14 -0
  77. package/useLexicalDecoratorMap.js.flow +16 -0
  78. package/useLexicalIsTextContentEmpty.d.ts +13 -0
  79. package/useLexicalIsTextContentEmpty.js.flow +15 -0
  80. package/useLexicalNodeSelection.d.ts +12 -0
  81. package/useLexicalNodeSelection.js.flow +14 -0
  82. package/withSubscriptions.d.ts +12 -0
  83. package/withSubscriptions.js.flow +13 -0
  84. package/LexicalBootstrapPlugin.dev.js +0 -122
  85. package/LexicalBootstrapPlugin.js +0 -9
  86. package/LexicalBootstrapPlugin.prod.js +0 -8
@@ -10,6 +10,7 @@ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
10
  var React = require('react');
11
11
  var lexical = require('lexical');
12
12
  var reactDom = require('react-dom');
13
+ var clipboard = require('@lexical/clipboard');
13
14
 
14
15
  /**
15
16
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -181,54 +182,9 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
181
182
  const isRTL = $isParentElementRTL(selection);
182
183
  $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
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;
185
+ function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
186
+ const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
187
+ return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
232
188
  }
233
189
 
234
190
  /**
@@ -239,17 +195,6 @@ function getPossibleDecoratorNode(focus, isBackward) {
239
195
  *
240
196
  *
241
197
  */
242
- function $insertDataTransferForPlainText(dataTransfer, selection) {
243
- const text = dataTransfer.getData('text/plain');
244
-
245
- if (text != null) {
246
- selection.insertRawText(text);
247
- }
248
- }
249
- function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
250
- const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
251
- return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
252
- }
253
198
  function onPasteForPlainText(event, editor) {
254
199
  event.preventDefault();
255
200
  editor.update(() => {
@@ -257,7 +202,7 @@ function onPasteForPlainText(event, editor) {
257
202
  const clipboardData = event.clipboardData;
258
203
 
259
204
  if (clipboardData != null && lexical.$isRangeSelection(selection)) {
260
- $insertDataTransferForPlainText(clipboardData, selection);
205
+ clipboard.$insertDataTransferForPlainText(clipboardData, selection);
261
206
  }
262
207
  });
263
208
  }
@@ -279,19 +224,10 @@ function onCopyForPlainText(event, editor) {
279
224
 
280
225
  if (selection !== null) {
281
226
  if (clipboardData != null) {
282
- const domSelection = window.getSelection(); // If we haven't selected a range, then don't copy anything
283
-
284
- if (domSelection.isCollapsed) {
285
- return;
286
- }
227
+ const htmlString = clipboard.getHtmlContent(editor);
287
228
 
288
- const range = domSelection.getRangeAt(0);
289
-
290
- if (range) {
291
- const container = document.createElement('div');
292
- const frag = range.cloneContents();
293
- container.appendChild(frag);
294
- clipboardData.setData('text/html', container.innerHTML);
229
+ if (htmlString !== null) {
230
+ clipboardData.setData('text/html', htmlString);
295
231
  }
296
232
 
297
233
  clipboardData.setData('text/plain', selection.getTextContent());
@@ -300,6 +236,62 @@ function onCopyForPlainText(event, editor) {
300
236
  });
301
237
  }
302
238
 
239
+ /**
240
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
241
+ *
242
+ * This source code is licensed under the MIT license found in the
243
+ * LICENSE file in the root directory of this source tree.
244
+ *
245
+ *
246
+ */
247
+ // Convoluted logic to make this work with Flow. Order matters.
248
+ const options = {
249
+ tag: 'history-merge'
250
+ };
251
+ const setEditorOptions = options;
252
+ const updateOptions = options;
253
+ function initializeEditor(editor, initialEditorState) {
254
+ if (initialEditorState === null) {
255
+ return;
256
+ } else if (initialEditorState === undefined) {
257
+ editor.update(() => {
258
+ const root = lexical.$getRoot();
259
+ const firstChild = root.getFirstChild();
260
+
261
+ if (firstChild === null) {
262
+ const paragraph = lexical.$createParagraphNode();
263
+ root.append(paragraph);
264
+ const activeElement = document.activeElement;
265
+
266
+ if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
267
+ paragraph.select();
268
+ }
269
+ }
270
+ }, updateOptions);
271
+ } else if (initialEditorState !== null) {
272
+ switch (typeof initialEditorState) {
273
+ case 'string':
274
+ {
275
+ const parsedEditorState = editor.parseEditorState(initialEditorState);
276
+ editor.setEditorState(parsedEditorState, setEditorOptions);
277
+ break;
278
+ }
279
+
280
+ case 'object':
281
+ {
282
+ editor.setEditorState(initialEditorState, setEditorOptions);
283
+ break;
284
+ }
285
+
286
+ case 'function':
287
+ {
288
+ editor.update(initialEditorState, updateOptions);
289
+ break;
290
+ }
291
+ }
292
+ }
293
+ }
294
+
303
295
  /**
304
296
  * Copyright (c) Meta Platforms, Inc. and affiliates.
305
297
  *
@@ -396,8 +388,8 @@ function useLexicalDragonSupport(editor) {
396
388
  *
397
389
  *
398
390
  */
399
- function usePlainTextSetup(editor) {
400
- React.useEffect(() => {
391
+ function usePlainTextSetup(editor, initialEditorState) {
392
+ useLayoutEffect(() => {
401
393
  const removeListener = editor.addListener('command', (type, payload) => {
402
394
  const selection = lexical.$getSelection();
403
395
 
@@ -437,7 +429,7 @@ function usePlainTextSetup(editor) {
437
429
  const dataTransfer = eventOrText.dataTransfer;
438
430
 
439
431
  if (dataTransfer != null) {
440
- $insertDataTransferForPlainText(dataTransfer, selection);
432
+ clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
441
433
  } else {
442
434
  const data = eventOrText.data;
443
435
 
@@ -556,13 +548,9 @@ function usePlainTextSetup(editor) {
556
548
 
557
549
  return false;
558
550
  }, 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;
551
+ initializeEditor(editor, initialEditorState);
552
+ return removeListener; // We only do this for init
553
+ // eslint-disable-next-line react-hooks/exhaustive-deps
566
554
  }, [editor]);
567
555
  useLexicalDragonSupport(editor);
568
556
  }
@@ -577,11 +565,12 @@ function usePlainTextSetup(editor) {
577
565
  */
578
566
  function PlainTextPlugin({
579
567
  contentEditable,
580
- placeholder
568
+ placeholder,
569
+ initialEditorState
581
570
  }) {
582
571
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
583
572
  const showPlaceholder = useLexicalCanShowPlaceholder(editor);
584
- usePlainTextSetup(editor);
573
+ usePlainTextSetup(editor, initialEditorState);
585
574
  const decorators = useDecorators(editor);
586
575
  return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
587
576
  }
@@ -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"),v=require("@lexical/clipboard");function w(a,d=!0){if(a)return!1;a=t.$getRoot().getTextContent();d&&(a=a.trim());return""===a}
8
+ function x(a){if(!w(a,!1))return!1;a=t.$getRoot().getChildren();const d=a.length;if(1<d)return!1;for(let c=0;c<d;c++){var e=a[c];if(t.$isElementNode(e)){if("paragraph"!==e.__type||0!==e.__indent)return!1;e=e.getChildren();const b=e.length;for(let f=0;f<b;f++)if(!t.$isTextNode(e[c]))return!1}}return!0}function y(a){return()=>x(a)}var z="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
9
+ function A(a){const [d,e]=h.useState(a.getEditorState().read(y(a.isComposing())));z(()=>a.addListener("update",({editorState:c})=>{const b=a.isComposing();c=c.read(y(b));e(c)}),[a]);return d}function C(a){const [d,e]=h.useState(()=>a.getDecorators());z(()=>a.addListener("decorator",c=>{u.flushSync(()=>{e(c)})}),[a]);return h.useMemo(()=>{const c=[],b=Object.keys(d);for(let p=0;p<b.length;p++){var f=b[p];const r=d[f];f=a.getElementByKey(f);null!==f&&c.push(u.createPortal(r,f))}return c},[d,a])}
10
+ function D(a){a=a.anchor.getNode();return"rtl"===(t.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function E(a,d){a=t.$getDecoratorNode(a.focus,d);return t.$isDecoratorNode(a)&&!a.isIsolated()}function F(a,d){a.preventDefault();d.update(()=>{const e=t.$getSelection(),c=a.clipboardData;null!=c&&t.$isRangeSelection(e)&&v.$insertDataTransferForPlainText(c,e)})}function G(a,d){H(a,d);d.update(()=>{const e=t.$getSelection();t.$isRangeSelection(e)&&e.removeText()})}
11
+ function H(a,d){a.preventDefault();d.update(()=>{const e=a.clipboardData,c=t.$getSelection();if(null!==c&&null!=e){const b=v.getHtmlContent(d);null!==b&&e.setData("text/html",b);e.setData("text/plain",c.getTextContent())}})}const I={tag:"history-merge"};
12
+ function J(a,d){if(null!==d)if(void 0===d)a.update(()=>{var e=t.$getRoot();if(null===e.getFirstChild()){const c=t.$createParagraphNode();e.append(c);e=document.activeElement;(null!==t.$getSelection()||null!==e&&e===a.getRootElement())&&c.select()}},I);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,I);break;case "object":a.setEditorState(d,I);break;case "function":a.update(d,I)}}
13
+ function K(a){h.useEffect(()=>{const d=e=>{var c=a.getRootElement();if(document.activeElement===c&&(c=e.data,"string"===typeof c)){try{var b=JSON.parse(c)}catch(f){return}if(b&&"nuanria_messaging"===b.protocol&&"request"===b.type&&(b=b.payload)&&"makeChanges"===b.functionId&&(b=b.args)){const [f,p,r,B,L]=b;a.update(()=>{const q=t.$getSelection();if(t.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;t.$isTextNode(k)&&0<=f&&0<=p&&(l=f,m=f+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
14
+ r)q.insertRawText(r),k=n.getNode();t.$isTextNode(k)&&(l=B,m=B+L,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));e.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
15
+ function M(a,d){z(()=>{const e=a.addListener("command",(c,b)=>{const f=t.$getSelection();if(!t.$isRangeSelection(f))return!1;switch(c){case "deleteCharacter":return f.deleteCharacter(b),!0;case "deleteWord":return f.deleteWord(b),!0;case "deleteLine":return f.deleteLine(b),!0;case "insertText":return"string"===typeof b?f.insertText(b):(c=b.dataTransfer,null!=c?v.$insertDataTransferForPlainText(c,f):(b=b.data)&&f.insertText(b)),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(b),
16
+ !0;case "insertParagraph":return f.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(E(f,!0))return b.preventDefault(),b=c,c=D(f),f.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(E(f,!1))return b.preventDefault(),b=c,c=D(f),f.modify(b?"extend":"move",c,"character"),!0;break;case "keyBackspace":return b.preventDefault(),
17
+ a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(b,a),!0;case "cut":return G(b,a),!0;case "paste":return F(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);J(a,d);return e},[a]);K(a)}
18
+ module.exports=function({contentEditable:a,placeholder:d,initialEditorState:e}){const [c]=g.useLexicalComposerContext(),b=A(c);M(c,e);e=C(c);return h.createElement(h.Fragment,null,a,b&&d,e)};
@@ -0,0 +1,15 @@
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
+ */
8
+
9
+ import type {EditorState} from 'lexical';
10
+ type InitialEditorStateType = null | string | EditorState | (() => void);
11
+ export default function RichTextPlugin(arg0: {
12
+ contentEditable: React.ReactNode;
13
+ initialEditorState?: InitialEditorStateType;
14
+ placeholder: React.ReactNode;
15
+ }): React.ReactNode;