@lexical/react 0.1.6 → 0.1.10

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 (105) hide show
  1. package/DEPRECATED_useLexical.dev.js +49 -0
  2. package/DEPRECATED_useLexical.js +9 -2
  3. package/DEPRECATED_useLexical.prod.js +7 -0
  4. package/DEPRECATED_useLexicalAutoFormatter.dev.js +729 -0
  5. package/DEPRECATED_useLexicalAutoFormatter.js +9 -11
  6. package/DEPRECATED_useLexicalAutoFormatter.prod.js +26 -0
  7. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +136 -0
  8. package/DEPRECATED_useLexicalCanShowPlaceholder.js +9 -3
  9. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +8 -0
  10. package/DEPRECATED_useLexicalCharacterLimit.dev.js +293 -0
  11. package/DEPRECATED_useLexicalCharacterLimit.js +9 -9
  12. package/DEPRECATED_useLexicalCharacterLimit.prod.js +14 -0
  13. package/DEPRECATED_useLexicalDecorators.dev.js +82 -0
  14. package/DEPRECATED_useLexicalDecorators.js +9 -2
  15. package/DEPRECATED_useLexicalDecorators.prod.js +8 -0
  16. package/DEPRECATED_useLexicalEditor.dev.js +28 -0
  17. package/DEPRECATED_useLexicalEditor.js +9 -1
  18. package/DEPRECATED_useLexicalEditor.prod.js +7 -0
  19. package/DEPRECATED_useLexicalEditorEvents.dev.js +96 -0
  20. package/DEPRECATED_useLexicalEditorEvents.js +9 -2
  21. package/DEPRECATED_useLexicalEditorEvents.prod.js +8 -0
  22. package/DEPRECATED_useLexicalHistory.dev.js +342 -0
  23. package/DEPRECATED_useLexicalHistory.js +9 -7
  24. package/DEPRECATED_useLexicalHistory.prod.js +13 -0
  25. package/DEPRECATED_useLexicalList.dev.js +64 -0
  26. package/DEPRECATED_useLexicalList.js +9 -12
  27. package/DEPRECATED_useLexicalList.prod.js +7 -0
  28. package/DEPRECATED_useLexicalPlainText.dev.js +761 -0
  29. package/DEPRECATED_useLexicalPlainText.js +9 -17
  30. package/DEPRECATED_useLexicalPlainText.prod.js +21 -0
  31. package/DEPRECATED_useLexicalRichText.dev.js +1197 -0
  32. package/DEPRECATED_useLexicalRichText.js +9 -31
  33. package/DEPRECATED_useLexicalRichText.prod.js +32 -0
  34. package/LexicalAutoFormatterPlugin.dev.js +732 -0
  35. package/LexicalAutoFormatterPlugin.js +9 -12
  36. package/LexicalAutoFormatterPlugin.prod.js +26 -0
  37. package/LexicalAutoLinkPlugin.dev.js +227 -0
  38. package/LexicalAutoLinkPlugin.js +9 -5
  39. package/LexicalAutoLinkPlugin.prod.js +12 -0
  40. package/LexicalBootstrapPlugin.dev.js +122 -0
  41. package/LexicalBootstrapPlugin.js +9 -0
  42. package/LexicalBootstrapPlugin.prod.js +8 -0
  43. package/LexicalCharacterLimitPlugin.dev.js +351 -0
  44. package/LexicalCharacterLimitPlugin.js +9 -10
  45. package/LexicalCharacterLimitPlugin.prod.js +14 -0
  46. package/LexicalCollaborationPlugin.dev.js +220 -0
  47. package/LexicalCollaborationPlugin.js +9 -8
  48. package/LexicalCollaborationPlugin.prod.js +13 -0
  49. package/LexicalComposer.dev.js +71 -0
  50. package/LexicalComposer.js +9 -2
  51. package/LexicalComposer.prod.js +8 -0
  52. package/LexicalComposerContext.dev.js +53 -0
  53. package/LexicalComposerContext.js +9 -1
  54. package/LexicalComposerContext.prod.js +7 -0
  55. package/LexicalContentEditable.dev.js +71 -0
  56. package/LexicalContentEditable.js +9 -3
  57. package/LexicalContentEditable.prod.js +9 -0
  58. package/LexicalHashtagPlugin.dev.js +152 -0
  59. package/LexicalHashtagPlugin.js +9 -4
  60. package/LexicalHashtagPlugin.prod.js +10 -0
  61. package/LexicalHistoryPlugin.dev.js +347 -0
  62. package/LexicalHistoryPlugin.js +9 -7
  63. package/LexicalHistoryPlugin.prod.js +13 -0
  64. package/LexicalHorizontalRuleNode.dev.js +66 -0
  65. package/LexicalHorizontalRuleNode.js +9 -0
  66. package/LexicalHorizontalRuleNode.prod.js +8 -0
  67. package/LexicalLinkPlugin.dev.js +136 -0
  68. package/LexicalLinkPlugin.js +9 -3
  69. package/LexicalLinkPlugin.prod.js +9 -0
  70. package/LexicalListPlugin.dev.js +67 -0
  71. package/LexicalListPlugin.js +9 -12
  72. package/LexicalListPlugin.prod.js +8 -0
  73. package/LexicalNestedComposer.dev.js +60 -0
  74. package/LexicalNestedComposer.js +9 -1
  75. package/LexicalNestedComposer.prod.js +8 -0
  76. package/LexicalOnChangePlugin.dev.js +57 -0
  77. package/LexicalOnChangePlugin.js +9 -1
  78. package/LexicalOnChangePlugin.prod.js +7 -0
  79. package/LexicalPlainTextPlugin.dev.js +589 -0
  80. package/LexicalPlainTextPlugin.js +9 -13
  81. package/LexicalPlainTextPlugin.prod.js +18 -0
  82. package/LexicalRichTextPlugin.dev.js +1025 -0
  83. package/LexicalRichTextPlugin.js +9 -27
  84. package/LexicalRichTextPlugin.prod.js +28 -0
  85. package/LexicalTablePlugin.dev.js +77 -0
  86. package/LexicalTablePlugin.js +9 -3
  87. package/LexicalTablePlugin.prod.js +9 -0
  88. package/LexicalTreeView.dev.js +348 -0
  89. package/LexicalTreeView.js +9 -12
  90. package/LexicalTreeView.prod.js +20 -0
  91. package/README.md +10 -5
  92. package/package.json +5 -4
  93. package/useLexicalDecoratorMap.dev.js +83 -0
  94. package/useLexicalDecoratorMap.js +9 -2
  95. package/useLexicalDecoratorMap.prod.js +8 -0
  96. package/useLexicalIsTextContentEmpty.dev.js +84 -0
  97. package/useLexicalIsTextContentEmpty.js +9 -2
  98. package/useLexicalIsTextContentEmpty.prod.js +8 -0
  99. package/useLexicalNodeSelection.dev.js +70 -0
  100. package/useLexicalNodeSelection.js +9 -0
  101. package/useLexicalNodeSelection.prod.js +8 -0
  102. package/withSubscriptions.dev.js +23 -0
  103. package/withSubscriptions.js +9 -1
  104. package/withSubscriptions.prod.js +7 -0
  105. package/LexicalHorizontalRulePlugin.js +0 -1
@@ -1,31 +1,9 @@
1
- 'use strict';var h=require("lexical"),w=require("lexical/HeadingNode"),x=require("lexical/ListNode"),z=require("lexical/QuoteNode"),A=require("lexical/CodeNode"),B=require("lexical/ListItemNode"),C=require("react"),D=require("lexical/LinkNode"),E=require("@lexical/react/withSubscriptions");
2
- function F(a){C.useEffect(()=>{const c=f=>{var d=a.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var e=JSON.parse(d)}catch(b){return}if(e&&"nuanria_messaging"===e.protocol&&"request"===e.type&&(e=e.payload)&&"makeChanges"===e.functionId&&(e=e.args)){const [b,g,k,l,p]=e;a.update(()=>{h.$log("useLexicalDragonSupport");const n=h.$getSelection();if(null!==n){var m=n.anchor;let r=m.getNode(),q=0,t=0;h.$isTextNode(r)&&0<=b&&0<=g&&(q=b,t=b+g,n.setTextNodeRange(r,q,r,
3
- t));if(q!==t||""!==k)n.insertRawText(k),r=m.getNode();h.$isTextNode(r)&&(q=l,t=l+p,m=r.getTextContentSize(),q=q>m?m:q,t=t>m?m:t,n.setTextNodeRange(r,q,r,t));f.stopImmediatePropagation()}})}}};window.addEventListener("message",c,!0);return()=>{window.removeEventListener("message",c,!0)}},[a])}
4
- function G(a){a=a.getLatest();const c=a.constructor.clone(a);c.__parent=a.__parent;h.$isElementNode(a)&&h.$isElementNode(c)?(c.__children=Array.from(a.__children),c.__format=a.__format,c.__indent=a.__indent,c.__dir=a.__dir):h.$isTextNode(a)&&h.$isTextNode(c)?(c.__format=a.__format,c.__style=a.__style,c.__mode=a.__mode,c.__detail=a.__detail):h.$isDecoratorNode(a)&&h.$isDecoratorNode(c)&&(c.__state=a.__state);return c}
5
- function H(a,c,f,d,e){for(var b=c;null!==a;){for(c=a.getParent();null!==c&&c.excludeFromCopy();)c=c.getParent();if(null===c)break;if(!h.$isElementNode(a)||!a.excludeFromCopy()){const g=a.getKey();let k=e.get(g);const l=void 0===k;l&&(k=G(a),e.set(g,k));!h.$isTextNode(k)||k.isSegmented()||k.isToken()?h.$isElementNode(k)&&(k.__children=k.__children.slice(f?b:0,f?void 0:b+1)):k.__text=k.__text.slice(f?b:0,f?void 0:b);if(h.$isRootNode(c)){l&&d.push(g);break}}b=e.get(c.getKey());b=h.$isElementNode(b)?
6
- b.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=c}}
7
- const I={ul:()=>({node:x.$createListNode("ul")}),ol:()=>({node:x.$createListNode("ol")}),li:()=>({node:B.$createListItemNode()}),h1:()=>({node:w.$createHeadingNode("h1")}),h2:()=>({node:w.$createHeadingNode("h2")}),h3:()=>({node:w.$createHeadingNode("h3")}),h4:()=>({node:w.$createHeadingNode("h4")}),h5:()=>({node:w.$createHeadingNode("h5")}),p:()=>({node:h.$createParagraphNode()}),br:()=>({node:h.$createLineBreakNode()}),a:a=>({node:a instanceof HTMLAnchorElement?D.$createLinkNode(a.href):h.$createTextNode(a.textContent)}),
8
- u:()=>({node:null,forChild:a=>{h.$isTextNode(a)&&a.toggleFormat("underline")}}),b:a=>{const c="normal"===a.style.fontWeight;return{node:null,forChild:f=>{h.$isTextNode(f)&&!c&&f.toggleFormat("bold")}}},strong:()=>({node:null,forChild:a=>{h.$isTextNode(a)&&a.toggleFormat("bold")}}),i:()=>({node:null,forChild:a=>{h.$isTextNode(a)&&a.toggleFormat("italic")}}),em:()=>({node:null,forChild:a=>{h.$isTextNode(a)&&a.toggleFormat("italic")}}),td:a=>{const c=a.classList.contains("js-file-line");return{node:null,
9
- after:f=>{c&&a.parentNode&&a.parentNode.nextSibling&&f.push(h.$createLineBreakNode());return f}}},table:a=>({node:a.classList.contains("js-file-line-container")?A.$createCodeNode():null}),span:a=>{const c="700"===a.style.fontWeight;return{node:null,forChild:f=>{h.$isTextNode(f)&&c&&f.toggleFormat("bold")}}},"#text":a=>({node:h.$createTextNode(a.textContent)}),pre:()=>({node:A.$createCodeNode()}),div:a=>({node:null!==a.style.fontFamily.match("monospace")?A.$createCodeNode():null,after:c=>{const f=
10
- a.parentNode;null!=f&&a!==f.lastChild&&c.push(h.$createLineBreakNode());return c}})};
11
- function J(a,c,f,d=new Map){let e=[],b=null;var g=a.nodeName.toLowerCase(),k=(f._config.htmlTransforms||{})[g]||c[g],l=k?k(a):null;k=null;if(null!==l){k=l.after;b=l.node;if(null!==b){e.push(b);const p=Array.from(d.values());for(let n=0;n<p.length;n++)p[n](b)}null!=l.forChild&&d.set(g,l.forChild)}a=a.childNodes;g=[];for(l=0;l<a.length;l++)g.push(...J(a[l],c,f,d));null!=k&&(g=k(g));null==b?e=e.concat(g):h.$isElementNode(b)&&b.append(...g);return e}
12
- function K(a,c,f){var d=a.getData("application/x-lexical-editor");if(d){var e=f._config.namespace;try{const l=JSON.parse(d);if(l.namespace===e){const {range:p,nodeMap:n}=l.state;var b=new Map(n);d=[];for(e=0;e<p.length;e++){var g=b.get(p[e]);if(void 0!==g){var k=h.$createNodeFromParse(g,b);d.push(k)}}c.insertNodes(d);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):[];g=b.length;for(k=0;k<g;k++)d=J(b[k],I,
13
- f),null!==d&&(a=a.concat(d));f=a;a=[];b=null;for(g=0;g<f.length;g++)k=f[g],!h.$isElementNode(k)||k.isInline()?(null===b&&(b=h.$createParagraphNode(),a.push(b)),null!==b&&b.append(k)):(a.push(k),b=null);c.insertNodes(a)}else f=a.getData("text/plain"),null!=f&&c.insertRawText(f)}
14
- function L(a,c){var f=a.focus;a=f.offset;"element"===f.type?c=f.getNode().getChildAtIndex(c?a-1:a):(f=f.getNode(),c=c&&0===a||!c&&a===f.getTextContentSize()?c?f.getPreviousSibling():f.getNextSibling():null);return h.$isDecoratorNode(c)}function M(a,c){a.preventDefault();c.update(()=>{h.$log("onPasteForRichText");const f=h.$getSelection(),d=a.clipboardData;null!=d&&null!==f&&K(d,f,c)})}
15
- function N(a,c){O(a,c);c.update(()=>{h.$log("onCutForRichText");const f=h.$getSelection();null!==f&&f.removeText()})}
16
- function O(a,c){a.preventDefault();c.update(()=>{h.$log("onCopyForRichText");const f=a.clipboardData;var d=h.$getSelection();if(null!==d&&null!=f){var e=window.getSelection();if(!e.isCollapsed){var b=e.getRangeAt(0);b&&(e=document.createElement("div"),b=b.cloneContents(),e.appendChild(b),f.setData("text/html",e.innerHTML));f.setData("text/plain",d.getTextContent());e=c._config.namespace;b=f.setData;var g=JSON,k=g.stringify;{var l=d.anchor,p=d.focus;var n=l.getCharacterOffset();const y=p.getCharacterOffset();
17
- var m=l.getNode(),r=p.getNode(),q=m.getParentOrThrow();if(m===r&&h.$isTextNode(m)&&(q.canBeEmpty()||1<q.getChildrenSize()))d=G(m),m=y>n,d.__text=d.__text.slice(m?n:y,m?y:n),n=d.getKey(),n={range:[n],nodeMap:[[n,d]]};else if(d=d.getNodes(),0===d.length)n={range:[],nodeMap:[]};else{m=d.length;r=d[0];q=r.getParent();if(null!==q&&!q.canBeEmpty()){var t=q.__children;if(t.length===m){var u=!0;for(var v=0;v<t.length;v++)if(t[v]!==d[v].__key){u=!1;break}u&&(m++,d.push(q))}}q=d[m-1];l=l.isBefore(p);p=new Map;
18
- t=[];H(r,l?n:y,!0,t,p);for(r=0;r<m;r++)if(u=d[r],v=u.getKey(),!(p.has(v)||h.$isElementNode(u)&&u.excludeFromCopy())){const Q=G(u);h.$isRootNode(u.getParent())&&t.push(u.getKey());p.set(v,Q)}H(q,l?y:n,!1,t,p);n={range:t,nodeMap:Array.from(p.entries())}}}b.call(f,"application/x-lexical-editor",k.call(g,{namespace:e,state:n}))}}})}var P="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?C.useLayoutEffect:C.useEffect;
19
- function R(a,c){const f=h.$createParagraphNode();a.append(f);a=document.activeElement;(null!==h.$getSelection()||null!==a&&a===c.getRootElement())&&f.select()}function S(a){a.update(()=>{h.$log("initEditor");const c=h.$getRoot();null===c.getFirstChild()&&R(c,a)})}function T(a,c){a.update(()=>{h.$log("clearEditor");const f=h.$getRoot();f.clear();R(f,a)},{onUpdate:c})}
20
- function U(a,c){P(()=>{const f=E(a.registerNodes([w.HeadingNode,x.ListNode,z.QuoteNode,A.CodeNode,B.ListItemNode]),a.addListener("command",(d,e)=>{var b=h.$getSelection();if(null===b)return!1;switch(d){case "deleteCharacter":return b.deleteCharacter(e),!0;case "deleteWord":return b.deleteWord(e),!0;case "deleteLine":return b.deleteLine(e),!0;case "insertText":return"string"===typeof e?b.insertText(e):(d=e.dataTransfer,null!=d?K(d,b,a):(e=e.data)&&b.insertText(e)),!0;case "removeText":return b.removeText(),
21
- !0;case "formatText":return b.formatText(e),!0;case "formatElement":return b=b.anchor.getNode(),(h.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(e),!0;case "insertLineBreak":return b.insertLineBreak(e),!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,
22
- e=b.getNode(),d="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===e.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=e.shiftKey;if(L(b,!0))return e.preventDefault(),e=d,d="rtl"===b.anchor.getNode().getParentOrThrow().getDirection(),b.modify(e?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=e.shiftKey;if(L(b,!1))return e.preventDefault(),e=d,d="rtl"===b.anchor.getNode().getParentOrThrow().getDirection(),
23
- b.modify(e?"extend":"move",d,"character"),!0;break;case "keyBackspace":return e.preventDefault(),{anchor:e}=b,b.isCollapsed()&&0===e.offset&&0<("element"===e.type?e.getNode():e.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return e.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return e.preventDefault(),e.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return e.preventDefault(),
24
- a.execCommand(e.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),!0;case "clearEditor":T(a);break;case "copy":return O(e,a),!0;case "cut":return N(e,a),!0;case "paste":return M(e,a),!0;case "drop":case "dragstart":return e.preventDefault(),!0}return!1},0));c&&S(a);return f},[a,c]);F(a)}
25
- function V(a,c,f){c=Array.from(c);f=Array.from(f);a=a._nodeMap;const d=[];for(var e=0;e<c.length;e++){const b=a.get(c[e]);void 0!==b&&d.push(b)}for(c=0;c<f.length;c++)f[c][1]&&(e=a.get(f[c][0]),void 0===e||h.$isRootNode(e)||d.push(e));return d}
26
- function W(a,c,f,d,e){if(null===a||0===f.size&&0===d.size)return 0;var b=c._selection,g=a._selection;if(e)return 1;if(null===b||null===g||!g.isCollapsed()||!b.isCollapsed())return 0;f=V(c,f,d);if(0===f.length)return 0;if(1<f.length){c=c._nodeMap;g=c.get(g.anchor.key);const k=c.get(b.anchor.key);return h.$isTextNode(k)&&h.$isElementNode(g)&&!a._nodeMap.has(k.__key)&&1===k.__text.length&&1===b.anchor.offset?f.every(l=>l===k||!h.$isTextNode(l))?2:0:0}c=f[0];a=a._nodeMap.get(c.__key);if(!h.$isTextNode(a)||
27
- !h.$isTextNode(c)||a.__mode!==c.__mode)return 0;a=a.__text;c=c.__text;if(a===c)return 0;b=b.anchor;g=g.anchor;if(b.key!==g.key||"text"!==b.type)return 0;b=b.offset;g=g.offset;a=c.length-a.length;return 1===a&&g===b-1?2:-1===a&&g===b+1?3:-1===a&&g===b?4:0}
28
- function X(a,c){let f=Date.now(),d=0;return(e,b,g,k,l,p)=>{const n=Date.now();if(p.has("historic"))return d=0,f=n,2;const m=W(e,b,k,l,a.isComposing()),r=(()=>{if(p.has("without-history"))return 0;if(null===e)return 1;var q=b._selection;const t=e._selection;if(!(0<k.size||0<l.size))return null===t&&null!==q?0:2;q=null===g||g.editor===a;return 0!==m&&m===d&&n<f+c&&q?0:1})();f=n;d=m;return r}}
29
- function Y(a,c,f=1E3){const d=C.useMemo(()=>c||{current:null,redoStack:[],undoStack:[]},[c]),e=C.useCallback(()=>{d.undoStack=[];d.redoStack=[];d.current=null},[d]);C.useEffect(()=>{const b=X(a,f);return E(a.addListener("command",g=>{switch(g){case "undo":g=d.redoStack;var k=d.undoStack;if(0!==k.length){var l=d.current;const p=k.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===k.length&&a.execCommand("canUndo",!1);d.current=p;p.editor.setEditorState(p.editorState.clone(p.undoSelection),
30
- {tag:"historic"})}return!0;case "redo":return g=d.redoStack,k=d.undoStack,0!==g.length&&(l=d.current,null!==l&&(k.push(l),a.execCommand("canUndo",!0)),k=g.pop(),0===g.length&&a.execCommand("canRedo",!1),d.current=k,k.editor.setEditorState(k.editorState,{tag:"historic"})),!0;case "clearEditor":return e(),!1;case "clearHistory":return e(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:k,dirtyLeaves:l,dirtyElements:p,tags:n})=>{const m=d.current,r=d.redoStack,q=d.undoStack,
31
- t=null===m?null:m.editorState;if(null===m||g!==t){l=b(k,g,m,l,p,n);if(1===l)0!==r.length&&(d.redoStack=[]),null!==m&&(q.push({...m,undoSelection:k.read(h.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;d.current={editor:a,editorState:g}}}))},[e,f,a,d])}function Z(a,c,f=1E3){return Y(a,c,f)}module.exports=function(a,c){U(a,!0);Z(a,c)};
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
+ 'use strict'
8
+ const DEPRECATED_useLexicalRichText = process.env.NODE_ENV === 'development' ? require('./DEPRECATED_useLexicalRichText.dev.js') : require('./DEPRECATED_useLexicalRichText.prod.js')
9
+ module.exports = DEPRECATED_useLexicalRichText;
@@ -0,0 +1,32 @@
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
+ var k=require("@lexical/react/withSubscriptions"),w=require("lexical"),y=require("react");
8
+ function z(a,d,e,b,c){if(null===a||0===e.size&&0===b.size)return 0;var f=d._selection,g=a._selection;if(c)return 1;if(!(w.$isRangeSelection(f)&&w.$isRangeSelection(g)&&g.isCollapsed()&&f.isCollapsed()))return 0;var h=Array.from(e);b=Array.from(b);e=d._nodeMap;c=[];for(var l=0;l<h.length;l++){const n=e.get(h[l]);void 0!==n&&c.push(n)}for(h=0;h<b.length;h++)b[h][1]&&(l=e.get(b[h][0]),void 0===l||w.$isRootNode(l)||c.push(l));if(0===c.length)return 0;if(1<c.length)return b=d._nodeMap,d=b.get(f.anchor.key),
9
+ g=b.get(g.anchor.key),d&&g&&!a._nodeMap.has(d.__key)&&w.$isTextNode(d)&&1===d.__text.length&&1===f.anchor.offset?2:0;d=c[0];a=a._nodeMap.get(d.__key);if(!w.$isTextNode(a)||!w.$isTextNode(d)||a.__mode!==d.__mode)return 0;a=a.__text;d=d.__text;if(a===d)return 0;f=f.anchor;g=g.anchor;if(f.key!==g.key||"text"!==f.type)return 0;f=f.offset;g=g.offset;a=d.length-a.length;return 1===a&&g===f-1?2:-1===a&&g===f+1?3:-1===a&&g===f?4:0}
10
+ function A(a,d){let e=Date.now(),b=0;return(c,f,g,h,l,n)=>{const p=Date.now();if(n.has("historic"))return b=0,e=p,2;const m=z(c,f,h,l,a.isComposing()),t=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===c)return 1;var r=f._selection;const u=c._selection;if(!(0<h.size||0<l.size))return null===u&&null!==r?0:2;r=null===g||g.editor===a;return!1===q&&0!==m&&m===b&&p<e+d&&r?0:1})();e=p;b=m;return t}}
11
+ function B(a,d,e=1E3){const b=y.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),c=y.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);y.useEffect(()=>{const f=A(a,e);return k(a.addListener("command",g=>{switch(g){case "undo":g=b.redoStack;var h=b.undoStack;if(0!==h.length){var l=b.current;const n=h.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);b.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
12
+ {tag:"historic"})}return!0;case "redo":return g=b.redoStack,h=b.undoStack,0!==g.length&&(l=b.current,null!==l&&(h.push(l),a.execCommand("canUndo",!0)),h=g.pop(),0===g.length&&a.execCommand("canRedo",!1),b.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return c(),!1;case "clearHistory":return c(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:h,dirtyLeaves:l,dirtyElements:n,tags:p})=>{const m=b.current,t=b.redoStack,q=b.undoStack,
13
+ r=null===m?null:m.editorState;if(null===m||g!==r){l=f(h,g,m,l,n,p);if(1===l)0!==t.length&&(b.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(w.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;b.current={editor:a,editorState:g}}}))},[c,e,a,b])}function C(a,d,e=1E3){return B(a,d,e)}
14
+ function D(a){a=a.getLatest();const d=a.constructor.clone(a);d.__parent=a.__parent;w.$isElementNode(a)&&w.$isElementNode(d)?(d.__children=Array.from(a.__children),d.__format=a.__format,d.__indent=a.__indent,d.__dir=a.__dir):w.$isTextNode(a)&&w.$isTextNode(d)?(d.__format=a.__format,d.__style=a.__style,d.__mode=a.__mode,d.__detail=a.__detail):w.$isDecoratorNode(a)&&w.$isDecoratorNode(d)&&(d.__state=a.__state);return d}
15
+ function E(a,d,e,b,c){for(var f=d;null!==a;){for(d=a.getParent();null!==d&&d.excludeFromCopy();)d=d.getParent();if(null===d)break;if(!w.$isElementNode(a)||!a.excludeFromCopy()){const g=a.getKey();let h=c.get(g);const l=void 0===h;l&&(h=D(a),c.set(g,h));!w.$isTextNode(h)||h.isSegmented()||h.isToken()?w.$isElementNode(h)&&(h.__children=h.__children.slice(e?f:0,e?void 0:f+1)):h.__text=h.__text.slice(e?f:0,e?void 0:f);if(w.$isRootNode(d)){l&&b.push(g);break}}f=c.get(d.getKey());f=w.$isElementNode(f)?
16
+ f.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=d}}function F(a){a=a.anchor.getNode();return"rtl"===(w.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function G(a,d,e){const b=a.getParent();let c=e;null!==b&&(d&&0===e?(c=a.getIndexWithinParent(),a=b):d||e!==a.getChildrenSize()||(c=a.getIndexWithinParent()+1,a=b));return a.getChildAtIndex(d?c-1:c)}
17
+ function H(a,d){const {nodeName:e}=a;d=d._htmlConversions.get(e.toLowerCase());let b=null;void 0!==d&&d.forEach(c=>{c=c(a);null!==c&&(null===b||b.priority<c.priority)&&(b=c)});return null!==b?b.conversion:null}
18
+ function I(a,d,e=new Map){let b=[],c=null;var f=H(a,d),g=f?f(a):null;f=null;if(null!==g){f=g.after;c=g.node;if(null!==c){b.push(c);var h=Array.from(e.values());for(let l=0;l<h.length;l++)h[l](c)}null!=g.forChild&&e.set(a.nodeName,g.forChild)}a=a.childNodes;g=[];for(h=0;h<a.length;h++)g.push(...I(a[h],d,e));null!=f&&(g=f(g));null==c?b=b.concat(g):w.$isElementNode(c)&&c.append(...g);return b}
19
+ function J(a,d,e){var b=a.getData("application/x-lexical-editor");if(b){var c=e._config.namespace;try{const l=JSON.parse(b);if(l.namespace===c){const {range:n,nodeMap:p}=l.state;var f=new Map(p);b=[];for(c=0;c<n.length;c++){var g=f.get(n[c]);if(void 0!==g){var h=w.$createNodeFromParse(g,f);b.push(h)}}d.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):[];g=f.length;for(h=0;h<g;h++)b=I(f[h],e),
20
+ null!==b&&(a=a.concat(b));e=a;a=[];f=null;for(g=0;g<e.length;g++)h=e[g],!w.$isElementNode(h)||h.isInline()?(null===f&&(f=w.$createParagraphNode(),a.push(f)),null!==f&&f.append(h)):(a.push(h),f=null);d.insertNodes(a)}else e=a.getData("text/plain"),null!=e&&d.insertRawText(e)}
21
+ function K(a,d){var e=a.focus;a=e.offset;"element"===e.type?(e=e.getNode(),d=G(e,d,a)):(e=e.getNode(),d&&0===a||!d&&a===e.getTextContentSize()?(a=d?e.getPreviousSibling():e.getNextSibling(),d=null===a?G(e.getParentOrThrow(),d,e.getIndexWithinParent()+(d?0:1)):a):d=null);return w.$isDecoratorNode(d)&&!d.isIsolated()}function L(a,d){a.preventDefault();d.update(()=>{const e=w.$getSelection(),b=a.clipboardData;null!=b&&w.$isRangeSelection(e)&&J(b,e,d)})}
22
+ function M(a,d){N(a,d);d.update(()=>{const e=w.$getSelection();w.$isRangeSelection(e)&&e.removeText()})}
23
+ function N(a,d){a.preventDefault();d.update(()=>{const e=a.clipboardData;var b=w.$getSelection();if(null!==b&&null!=e){var c=window.getSelection();if(!c.isCollapsed){var f=c.getRangeAt(0);f&&(c=document.createElement("div"),f=f.cloneContents(),c.appendChild(f),e.setData("text/html",c.innerHTML));e.setData("text/plain",b.getTextContent());c=d._config.namespace;f=e.setData;var g=JSON,h=g.stringify;{if(!w.$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.");
24
+ var l=b.anchor,n=b.focus;var p=l.getCharacterOffset();const x=n.getCharacterOffset();var m=l.getNode(),t=n.getNode(),q=m.getParentOrThrow();if(m===t&&w.$isTextNode(m)&&(q.canBeEmpty()||1<q.getChildrenSize()))b=D(m),m=x>p,b.__text=b.__text.slice(m?p:x,m?x:p),p=b.getKey(),p={nodeMap:[[p,b]],range:[p]};else if(b=b.getNodes(),0===b.length)p={nodeMap:[],range:[]};else{m=b.length;t=b[0];q=t.getParent();if(null!==q&&(!q.canBeEmpty()||w.$isRootNode(q))){var r=q.__children;if(r.length===m){var u=!0;for(var v=
25
+ 0;v<r.length;v++)if(r[v]!==b[v].__key){u=!1;break}u&&(m++,b.push(q))}}q=b[m-1];l=l.isBefore(n);n=new Map;r=[];E(t,l?p:x,!0,r,n);for(t=0;t<m;t++)if(u=b[t],v=u.getKey(),!(n.has(v)||w.$isElementNode(u)&&u.excludeFromCopy())){const O=D(u);w.$isRootNode(u.getParent())&&r.push(u.getKey());n.set(v,O)}E(q,l?x:p,!1,r,n);p={nodeMap:Array.from(n.entries()),range:r}}}f.call(e,"application/x-lexical-editor",h.call(g,{namespace:c,state:p}))}}})}
26
+ function P(a){y.useEffect(()=>{const d=e=>{var b=a.getRootElement();if(document.activeElement===b&&(b=e.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,g,h,l,n]=c;a.update(()=>{const p=w.$getSelection();if(w.$isRangeSelection(p)){var m=p.anchor;let t=m.getNode(),q=0,r=0;w.$isTextNode(t)&&0<=f&&0<=g&&(q=f,r=f+g,p.setTextNodeRange(t,q,t,r));if(q!==r||""!==
27
+ h)p.insertRawText(h),t=m.getNode();w.$isTextNode(t)&&(q=l,r=l+n,m=t.getTextContentSize(),q=q>m?m:q,r=r>m?m:r,p.setTextNodeRange(t,q,t,r));e.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
28
+ function Q(a){y.useEffect(()=>{const d=a.addListener("command",(e,b)=>{var c=w.$getSelection();if("click"===e&&w.$isNodeSelection(c))return c.clear(),!0;if(!w.$isRangeSelection(c))return!1;switch(e){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):(e=b.dataTransfer,null!=e?J(e,c,a):(b=b.data)&&c.insertText(b)),!0;case "removeText":return c.removeText(),
29
+ !0;case "formatText":return c.formatText(b),!0;case "formatElement":return c=c.anchor.getNode(),(w.$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,
30
+ b=c.getNode(),e="element"===c.type?c.getNode():c.getNode().getParentOrThrow(),e.canInsertTab()?"\t"===b.getTextContent()[c.offset-1]&&a.execCommand("deleteCharacter",!0):0!==e.getIndent()&&e.setIndent(e.getIndent()-1),!0;case "keyArrowLeft":e=b.shiftKey;if(K(c,!0))return b.preventDefault(),b=e,e=F(c),c.modify(b?"extend":"move",!e,"character"),!0;break;case "keyArrowRight":e=b.shiftKey;if(K(c,!1))return b.preventDefault(),b=e,e=F(c),c.modify(b?"extend":"move",e,"character"),!0;break;case "keyBackspace":return b.preventDefault(),
31
+ {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(),
32
+ !0;case "copy":return N(b,a),!0;case "cut":return M(b,a),!0;case "paste":return L(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return d},[a]);P(a)}module.exports=function(a,d){Q(a);C(a,d)};