@lexical/react 0.1.9 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/DEPRECATED_useLexical.dev.js +5 -44
  2. package/DEPRECATED_useLexical.prod.js +1 -2
  3. package/DEPRECATED_useLexicalAutoFormatter.dev.js +87 -41
  4. package/DEPRECATED_useLexicalAutoFormatter.prod.js +20 -18
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +22 -19
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
  7. package/DEPRECATED_useLexicalEditor.dev.js +1 -25
  8. package/DEPRECATED_useLexicalEditor.prod.js +1 -1
  9. package/DEPRECATED_useLexicalHistory.dev.js +1 -1
  10. package/DEPRECATED_useLexicalHistory.prod.js +2 -2
  11. package/DEPRECATED_useLexicalList.dev.js +6 -0
  12. package/DEPRECATED_useLexicalList.prod.js +1 -1
  13. package/DEPRECATED_useLexicalPlainText.dev.js +81 -89
  14. package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
  15. package/DEPRECATED_useLexicalRichText.dev.js +98 -592
  16. package/DEPRECATED_useLexicalRichText.prod.js +17 -29
  17. package/LexicalAutoFormatterPlugin.d.ts +9 -0
  18. package/LexicalAutoFormatterPlugin.dev.js +87 -41
  19. package/LexicalAutoFormatterPlugin.js.flow +10 -0
  20. package/LexicalAutoFormatterPlugin.prod.js +21 -19
  21. package/LexicalAutoLinkPlugin.d.ts +20 -0
  22. package/LexicalAutoLinkPlugin.js.flow +23 -0
  23. package/LexicalCharacterLimitPlugin.d.ts +11 -0
  24. package/LexicalCharacterLimitPlugin.dev.js +22 -19
  25. package/LexicalCharacterLimitPlugin.js.flow +12 -0
  26. package/LexicalCharacterLimitPlugin.prod.js +9 -8
  27. package/LexicalClearEditorPlugin.d.ts +14 -0
  28. package/LexicalClearEditorPlugin.dev.js +73 -0
  29. package/LexicalClearEditorPlugin.js +9 -0
  30. package/LexicalClearEditorPlugin.js.flow +14 -0
  31. package/LexicalClearEditorPlugin.prod.js +8 -0
  32. package/LexicalCollaborationPlugin.d.ts +49 -0
  33. package/LexicalCollaborationPlugin.dev.js +21 -11
  34. package/LexicalCollaborationPlugin.js.flow +55 -0
  35. package/LexicalCollaborationPlugin.prod.js +7 -7
  36. package/LexicalComposer.d.ts +22 -0
  37. package/LexicalComposer.dev.js +29 -5
  38. package/LexicalComposer.js.flow +24 -0
  39. package/LexicalComposer.prod.js +3 -3
  40. package/LexicalComposerContext.d.ts +24 -0
  41. package/LexicalComposerContext.js.flow +27 -0
  42. package/LexicalContentEditable.d.ts +32 -0
  43. package/LexicalContentEditable.dev.js +35 -8
  44. package/LexicalContentEditable.js.flow +35 -0
  45. package/LexicalContentEditable.prod.js +3 -3
  46. package/LexicalHashtagPlugin.d.ts +9 -0
  47. package/LexicalHashtagPlugin.js.flow +10 -0
  48. package/LexicalHistoryPlugin.d.ts +29 -0
  49. package/LexicalHistoryPlugin.dev.js +1 -1
  50. package/LexicalHistoryPlugin.js.flow +34 -0
  51. package/LexicalHistoryPlugin.prod.js +2 -2
  52. package/LexicalHorizontalRuleNode.d.ts +23 -0
  53. package/LexicalHorizontalRuleNode.js.flow +25 -0
  54. package/LexicalLinkPlugin.d.ts +9 -0
  55. package/LexicalLinkPlugin.js.flow +10 -0
  56. package/LexicalListPlugin.d.ts +9 -0
  57. package/LexicalListPlugin.dev.js +6 -0
  58. package/LexicalListPlugin.js.flow +10 -0
  59. package/LexicalListPlugin.prod.js +2 -2
  60. package/LexicalNestedComposer.d.ts +20 -0
  61. package/LexicalNestedComposer.js.flow +21 -0
  62. package/LexicalOnChangePlugin.d.ts +12 -0
  63. package/LexicalOnChangePlugin.js.flow +14 -0
  64. package/LexicalPlainTextPlugin.d.ts +15 -0
  65. package/LexicalPlainTextPlugin.dev.js +77 -84
  66. package/LexicalPlainTextPlugin.js.flow +18 -0
  67. package/LexicalPlainTextPlugin.prod.js +12 -12
  68. package/LexicalRichTextPlugin.d.ts +15 -0
  69. package/LexicalRichTextPlugin.dev.js +93 -586
  70. package/LexicalRichTextPlugin.js.flow +18 -0
  71. package/LexicalRichTextPlugin.prod.js +13 -25
  72. package/LexicalTablePlugin.d.ts +9 -0
  73. package/LexicalTablePlugin.dev.js +23 -1
  74. package/LexicalTablePlugin.js.flow +10 -0
  75. package/LexicalTablePlugin.prod.js +4 -3
  76. package/LexicalTreeView.d.ts +17 -0
  77. package/LexicalTreeView.dev.js +10 -2
  78. package/LexicalTreeView.js.flow +19 -0
  79. package/LexicalTreeView.prod.js +9 -8
  80. package/README.md +0 -1
  81. package/package.json +6 -5
  82. package/useLexicalDecoratorMap.d.ts +14 -0
  83. package/useLexicalDecoratorMap.js.flow +16 -0
  84. package/useLexicalIsTextContentEmpty.d.ts +13 -0
  85. package/useLexicalIsTextContentEmpty.js.flow +15 -0
  86. package/useLexicalNodeSelection.d.ts +12 -0
  87. package/useLexicalNodeSelection.dev.js +70 -0
  88. package/useLexicalNodeSelection.js +9 -0
  89. package/useLexicalNodeSelection.js.flow +14 -0
  90. package/useLexicalNodeSelection.prod.js +8 -0
  91. package/withSubscriptions.d.ts +12 -0
  92. package/withSubscriptions.js.flow +13 -0
  93. package/LexicalBootstrapPlugin.dev.js +0 -122
  94. package/LexicalBootstrapPlugin.js +0 -9
  95. package/LexicalBootstrapPlugin.prod.js +0 -8
@@ -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,25 +195,14 @@ 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(() => {
256
201
  const selection = lexical.$getSelection();
257
202
  const clipboardData = event.clipboardData;
258
203
 
259
- if (clipboardData != null && selection !== null) {
260
- $insertDataTransferForPlainText(clipboardData, selection);
204
+ if (clipboardData != null && lexical.$isRangeSelection(selection)) {
205
+ clipboard.$insertDataTransferForPlainText(clipboardData, selection);
261
206
  }
262
207
  });
263
208
  }
@@ -266,7 +211,7 @@ function onCutForPlainText(event, editor) {
266
211
  editor.update(() => {
267
212
  const selection = lexical.$getSelection();
268
213
 
269
- if (selection !== null) {
214
+ if (lexical.$isRangeSelection(selection)) {
270
215
  selection.removeText();
271
216
  }
272
217
  });
@@ -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
  *
@@ -339,7 +331,7 @@ function useLexicalDragonSupport(editor) {
339
331
  editor.update(() => {
340
332
  const selection = lexical.$getSelection();
341
333
 
342
- if (selection !== null) {
334
+ if (lexical.$isRangeSelection(selection)) {
343
335
  const anchor = selection.anchor;
344
336
  let anchorNode = anchor.getNode();
345
337
  let setSelStart = 0;
@@ -396,13 +388,12 @@ function useLexicalDragonSupport(editor) {
396
388
  *
397
389
  *
398
390
  */
399
- const EditorPriority = 0;
400
- function usePlainTextSetup(editor) {
391
+ function usePlainTextSetup(editor, initialEditorState) {
401
392
  useLayoutEffect(() => {
402
393
  const removeListener = editor.addListener('command', (type, payload) => {
403
394
  const selection = lexical.$getSelection();
404
395
 
405
- if (selection === null) {
396
+ if (!lexical.$isRangeSelection(selection)) {
406
397
  return false;
407
398
  }
408
399
 
@@ -438,7 +429,7 @@ function usePlainTextSetup(editor) {
438
429
  const dataTransfer = eventOrText.dataTransfer;
439
430
 
440
431
  if (dataTransfer != null) {
441
- $insertDataTransferForPlainText(dataTransfer, selection);
432
+ clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
442
433
  } else {
443
434
  const data = eventOrText.data;
444
435
 
@@ -556,9 +547,10 @@ function usePlainTextSetup(editor) {
556
547
  }
557
548
 
558
549
  return false;
559
- }, EditorPriority);
560
- editor.execCommand('bootstrapEditor');
561
- return removeListener;
550
+ }, 0);
551
+ initializeEditor(editor, initialEditorState);
552
+ return removeListener; // We only do this for init
553
+ // eslint-disable-next-line react-hooks/exhaustive-deps
562
554
  }, [editor]);
563
555
  useLexicalDragonSupport(editor);
564
556
  }
@@ -573,11 +565,12 @@ function usePlainTextSetup(editor) {
573
565
  */
574
566
  function PlainTextPlugin({
575
567
  contentEditable,
576
- placeholder
568
+ placeholder,
569
+ initialEditorState
577
570
  }) {
578
571
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
579
572
  const showPlaceholder = useLexicalCanShowPlaceholder(editor);
580
- usePlainTextSetup(editor);
573
+ usePlainTextSetup(editor, initialEditorState);
581
574
  const decorators = useDecorators(editor);
582
575
  return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
583
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&&null!==b&&E(c,b)})}
12
- function H(a,e){I(a,e);e.update(()=>{const b=t.$getSelection();null!==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(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,m));if(l!==m||""!==r)q.insertRawText(r),
14
- 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){y(()=>{const e=a.addListener("command",(b,c)=>{const d=t.$getSelection();if(null===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),!0;case "insertParagraph":return d.insertLineBreak(),
16
- !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(),a.execCommand("deleteCharacter",
17
- !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;