@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
@@ -4,29 +4,20 @@
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 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)};
7
+ var h=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react"),w=require("@lexical/clipboard");
8
+ function x(a,e,f,d,c){if(null===a||0===f.size&&0===d.size)return 0;var b=e._selection,g=a._selection;if(c)return 1;if(!(u.$isRangeSelection(b)&&u.$isRangeSelection(g)&&g.isCollapsed()&&b.isCollapsed()))return 0;var k=Array.from(f);d=Array.from(d);f=e._nodeMap;c=[];for(var l=0;l<k.length;l++){const n=f.get(k[l]);void 0!==n&&c.push(n)}for(k=0;k<d.length;k++)d[k][1]&&(l=f.get(d[k][0]),void 0===l||u.$isRootNode(l)||c.push(l));if(0===c.length)return 0;if(1<c.length)return d=e._nodeMap,e=d.get(b.anchor.key),
9
+ g=d.get(g.anchor.key),e&&g&&!a._nodeMap.has(e.__key)&&u.$isTextNode(e)&&1===e.__text.length&&1===b.anchor.offset?2:0;e=c[0];a=a._nodeMap.get(e.__key);if(!u.$isTextNode(a)||!u.$isTextNode(e)||a.__mode!==e.__mode)return 0;a=a.__text;e=e.__text;if(a===e)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=e.length-a.length;return 1===a&&g===b-1?2:-1===a&&g===b+1?3:-1===a&&g===b?4:0}
10
+ function y(a,e){let f=Date.now(),d=0;return(c,b,g,k,l,n)=>{const t=Date.now();if(n.has("historic"))return d=0,f=t,2;const m=x(c,b,k,l,a.isComposing()),r=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===c)return 1;var p=b._selection;const D=c._selection;if(!(0<k.size||0<l.size))return null===D&&null!==p?0:2;p=null===g||g.editor===a;return!1===q&&0!==m&&m===d&&t<f+e&&p?0:1})();f=t;d=m;return r}}
11
+ function z(a,e,f=1E3){const d=v.useMemo(()=>e||{current:null,redoStack:[],undoStack:[]},[e]),c=v.useCallback(()=>{d.undoStack=[];d.redoStack=[];d.current=null},[d]);v.useEffect(()=>{const b=y(a,f);return h(a.addListener("command",g=>{switch(g){case "undo":g=d.redoStack;var k=d.undoStack;if(0!==k.length){var l=d.current;const n=k.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===k.length&&a.execCommand("canUndo",!1);d.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
12
+ {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 c(),!1;case "clearHistory":return c(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:k,dirtyLeaves:l,dirtyElements:n,tags:t})=>{const m=d.current,r=d.redoStack,q=d.undoStack,
13
+ p=null===m?null:m.editorState;if(null===m||g!==p){l=b(k,g,m,l,n,t);if(1===l)0!==r.length&&(d.redoStack=[]),null!==m&&(q.push({...m,undoSelection:k.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;d.current={editor:a,editorState:g}}}))},[c,f,a,d])}function A(a,e,f=1E3){return z(a,e,f)}function B(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
14
+ function C(a,e){a=u.$getDecoratorNode(a.focus,e);return u.$isDecoratorNode(a)&&!a.isIsolated()}var E="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;function F(a,e){G(a,e);e.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}
15
+ function G(a,e){a.preventDefault();e.update(()=>{const f=a.clipboardData,d=u.$getSelection();if(null!==d&&null!=f){const c=w.getHtmlContent(e),b=w.$getLexicalContent(e);null!==c&&f.setData("text/html",c);null!==b&&f.setData("application/x-lexical-editor",b);f.setData("text/plain",d.getTextContent())}})}function H(a,e){a.preventDefault();e.update(()=>{const f=u.$getSelection(),d=a.clipboardData;null!=d&&u.$isRangeSelection(f)&&w.$insertDataTransferForRichText(d,f,e)})}const I={tag:"history-merge"};
16
+ function J(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=u.$getRoot();if(null===f.getFirstChild()){const d=u.$createParagraphNode();f.append(d);f=document.activeElement;(null!==u.$getSelection()||null!==f&&f===a.getRootElement())&&d.select()}},I);else if(null!==e)switch(typeof e){case "string":e=a.parseEditorState(e);a.setEditorState(e,I);break;case "object":a.setEditorState(e,I);break;case "function":a.update(e,I)}}
17
+ function K(a){v.useEffect(()=>{const e=f=>{var d=a.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var c=JSON.parse(d)}catch(b){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [b,g,k,l,n]=c;a.update(()=>{const t=u.$getSelection();if(u.$isRangeSelection(t)){var m=t.anchor;let r=m.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=b&&0<=g&&(q=b,p=b+g,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
18
+ k)t.insertRawText(k),r=m.getNode();u.$isTextNode(r)&&(q=l,p=l+n,m=r.getTextContentSize(),q=q>m?m:q,p=p>m?m:p,t.setTextNodeRange(r,q,r,p));f.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
19
+ function L(a,e){E(()=>{const f=a.addListener("command",(d,c)=>{var b=u.$getSelection();if("click"===d&&u.$isNodeSelection(b))return b.clear(),!0;if(!u.$isRangeSelection(b))return!1;switch(d){case "deleteCharacter":return b.deleteCharacter(c),!0;case "deleteWord":return b.deleteWord(c),!0;case "deleteLine":return b.deleteLine(c),!0;case "insertText":return"string"===typeof c?b.insertText(c):(d=c.dataTransfer,null!=d?w.$insertDataTransferForRichText(d,b,a):(c=c.data)&&b.insertText(c)),!0;case "removeText":return b.removeText(),
20
+ !0;case "formatText":return b.formatText(c),!0;case "formatElement":return b=b.anchor.getNode(),(u.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(c),!0;case "insertLineBreak":return b.insertLineBreak(c),!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,
21
+ c=b.getNode(),d="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===c.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=c.shiftKey;if(C(b,!0))return c.preventDefault(),c=d,d=B(b),b.modify(c?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=c.shiftKey;if(C(b,!1))return c.preventDefault(),c=d,d=B(b),b.modify(c?"extend":"move",d,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
22
+ {anchor:c}=b,b.isCollapsed()&&0===c.offset&&0<("element"===c.type?c.getNode():c.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),c.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return c.preventDefault(),a.execCommand(c.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
23
+ !0;case "copy":return G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return H(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);J(a,e);return f},[a]);K(a)}module.exports=function(a,e,f){L(a,f);A(a,e)};
@@ -0,0 +1,9 @@
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
+ export default function LexicalAutoFormatterPlugin(): React.ReactNode;
@@ -133,31 +133,31 @@ const paragraphStartBase = { ...autoFormatBase,
133
133
  };
134
134
  const markdownHeader1 = { ...paragraphStartBase,
135
135
  nodeTransformationKind: 'paragraphH1',
136
- regEx: /(?:# )/
136
+ regEx: /^(?:# )/
137
137
  };
138
138
  const markdownHeader2 = { ...paragraphStartBase,
139
139
  nodeTransformationKind: 'paragraphH2',
140
- regEx: /(?:## )/
140
+ regEx: /^(?:## )/
141
141
  };
142
142
  const markdownHeader3 = { ...paragraphStartBase,
143
143
  nodeTransformationKind: 'paragraphH2',
144
- regEx: /(?:### )/
144
+ regEx: /^(?:### )/
145
145
  };
146
146
  const markdownBlockQuote = { ...paragraphStartBase,
147
147
  nodeTransformationKind: 'paragraphBlockQuote',
148
- regEx: /(?:> )/
148
+ regEx: /^(?:> )/
149
149
  };
150
150
  const markdownUnorderedListDash = { ...paragraphStartBase,
151
151
  nodeTransformationKind: 'paragraphUnorderedList',
152
- regEx: /(?:- )/
152
+ regEx: /^(?:- )/
153
153
  };
154
154
  const markdownUnorderedListAsterisk = { ...paragraphStartBase,
155
155
  nodeTransformationKind: 'paragraphUnorderedList',
156
- regEx: /(?:\* )/
156
+ regEx: /^(?:\* )/
157
157
  };
158
158
  const markdownCodeBlock = { ...paragraphStartBase,
159
159
  nodeTransformationKind: 'paragraphCodeBlock',
160
- regEx: /(?:``` )/
160
+ regEx: /^(```)([a-z]*)( )/
161
161
  };
162
162
  const markdownOrderedList = { ...paragraphStartBase,
163
163
  nodeTransformationKind: 'paragraphOrderedList',
@@ -165,20 +165,39 @@ const markdownOrderedList = { ...paragraphStartBase,
165
165
  };
166
166
  const markdownHorizontalRule = { ...paragraphStartBase,
167
167
  nodeTransformationKind: 'horizontalRule',
168
- regEx: /(?:\*\*\* )/
168
+ regEx: /^(?:\*\*\* )/
169
169
  };
170
170
  const markdownHorizontalRuleUsingDashes = { ...paragraphStartBase,
171
171
  nodeTransformationKind: 'horizontalRule',
172
- regEx: /(?:--- )/
172
+ regEx: /^(?:--- )/
173
+ };
174
+ const markdownItalic = { ...autoFormatBase,
175
+ nodeTransformationKind: 'italic',
176
+ regEx: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/
173
177
  };
174
178
  const markdownBold = { ...autoFormatBase,
175
- nodeTransformationKind: 'textBold',
176
- // regEx: /(\*)(?:\s*\b)(?:[^\*]*)(?:\b\s*)(\*\s)$/, // The $ will find the target at the end of the string.
177
- regEx: /(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/ // Remove the first and last capture groups. Remeber, the 0th capture group is the entire string.
178
- // e.g. "*Hello* " requires removing both "*" as well as bolding "Hello".
179
-
179
+ nodeTransformationKind: 'bold',
180
+ regEx: /(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*\s)$/
181
+ };
182
+ const markdownBoldWithUnderlines = { ...autoFormatBase,
183
+ nodeTransformationKind: 'bold',
184
+ regEx: /(__)(\s*)([^__]*)(\s*)(__\s)$/
185
+ };
186
+ const markdownBoldItalic = { ...autoFormatBase,
187
+ nodeTransformationKind: 'bold_italic',
188
+ regEx: /(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*\s)$/
189
+ }; // Markdown does not support underline, but we can allow folks to use
190
+ // the HTML tags for underline.
191
+
192
+ const fakeMarkdownUnderline = { ...autoFormatBase,
193
+ nodeTransformationKind: 'underline',
194
+ regEx: /(\<u\>)(\s*\b)([^\<]*)(\b\s*)(\<\/u\>\s)$/
180
195
  };
181
- const allAutoFormatCriteriaForTextNodes = [markdownBold];
196
+ const markdownStrikethrough = { ...autoFormatBase,
197
+ nodeTransformationKind: 'strikethrough',
198
+ regEx: /(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/
199
+ };
200
+ const allAutoFormatCriteriaForTextNodes = [markdownBoldItalic, markdownItalic, markdownBold, markdownBoldWithUnderlines, fakeMarkdownUnderline, markdownStrikethrough];
182
201
  const allAutoFormatCriteria = [markdownHeader1, markdownHeader2, markdownHeader3, markdownBlockQuote, markdownUnorderedListDash, markdownUnorderedListAsterisk, markdownOrderedList, markdownCodeBlock, markdownHorizontalRule, markdownHorizontalRuleUsingDashes, ...allAutoFormatCriteriaForTextNodes];
183
202
  function getAllAutoFormatCriteriaForTextNodes() {
184
203
  return allAutoFormatCriteriaForTextNodes;
@@ -259,17 +278,14 @@ function getMatchResultContextForText(autoFormatCriteria, scanningContext) {
259
278
  // Lazy calculate the text to search.
260
279
  scanningContext.joinedText = $joinTextNodesInElementNode(parentNode, SEPARATOR_BETWEEN_TEXT_AND_NON_TEXT_NODES, scanningContext.textNodeWithOffset);
261
280
  }
262
-
263
- return getMatchResultContextWithRegEx(scanningContext.joinedText, false, true, autoFormatCriteria.regEx);
264
281
  } else {
265
282
  {
266
283
  throw Error(`Expected node ${parentNode.__key} to to be a ElementNode.`);
267
284
  }
268
285
  }
269
- } // This is a placeholder function for following PR's related to character based transformations.
270
-
286
+ }
271
287
 
272
- return null;
288
+ return getMatchResultContextWithRegEx(scanningContext.joinedText, false, true, autoFormatCriteria.regEx);
273
289
  }
274
290
 
275
291
  function getMatchResultContextForCriteria(autoFormatCriteria, scanningContext) {
@@ -343,6 +359,11 @@ function getNewNodeForCriteria(scanningContext, element) {
343
359
  newNode = lexical.$createParagraphNode();
344
360
  } else {
345
361
  newNode = CodeNode.$createCodeNode();
362
+ const codingLanguage = matchResultContext.regExCaptureGroups.length >= 3 ? matchResultContext.regExCaptureGroups[2].text : null;
363
+
364
+ if (codingLanguage != null && codingLanguage.length > 0) {
365
+ newNode.setLanguage(codingLanguage);
366
+ }
346
367
  }
347
368
 
348
369
  newNode.append(...children);
@@ -391,28 +412,50 @@ function transformTextNodeForParagraphs(scanningContext) {
391
412
  }
392
413
  }
393
414
 
415
+ function getTextFormatType(nodeTransformationKind) {
416
+ switch (nodeTransformationKind) {
417
+ case 'italic':
418
+ case 'bold':
419
+ case 'underline':
420
+ case 'strikethrough':
421
+ return [nodeTransformationKind];
422
+
423
+ case 'bold_italic':
424
+ {
425
+ return ['bold', 'italic'];
426
+ }
427
+ }
428
+
429
+ return null;
430
+ }
431
+
394
432
  function transformTextNodeForText(scanningContext) {
395
433
  const autoFormatCriteria = scanningContext.autoFormatCriteria;
396
434
  const matchResultContext = scanningContext.matchResultContext;
397
435
 
398
436
  if (autoFormatCriteria.nodeTransformationKind != null) {
399
- switch (autoFormatCriteria.nodeTransformationKind) {
400
- case 'textBold':
401
- {
402
- if (matchResultContext.regExCaptureGroups.length !== 6) {
403
- // The expected reg ex pattern for bold should have 6 groups.
404
- // If it does not, then break and fail silently.
405
- // e2e tests validate the regEx pattern.
406
- break;
407
- }
437
+ if (matchResultContext.regExCaptureGroups.length !== 6) {
438
+ // For BIUS and other formatts which have a pattern + text + pattern,
439
+ // the expected reg ex pattern should have 6 groups.
440
+ // If it does not, then break and fail silently.
441
+ // e2e tests validate the regEx pattern.
442
+ return;
443
+ }
408
444
 
409
- matchResultContext.regExCaptureGroups = getCaptureGroupsByResolvingAllDetails(scanningContext); // Remove unwanted text in reg ex pattern.
445
+ const formatting = getTextFormatType(autoFormatCriteria.nodeTransformationKind);
410
446
 
411
- removeTextInCaptureGroups([1, 5], matchResultContext);
412
- formatTextInCaptureGroupIndex('bold', 3, matchResultContext);
413
- makeCollapsedSelectionAtOffsetInJoinedText(matchResultContext.offsetInJoinedTextForCollapsedSelection, matchResultContext.offsetInJoinedTextForCollapsedSelection + 1, scanningContext.textNodeWithOffset.node.getParentOrThrow());
414
- break;
415
- }
447
+ if (formatting != null) {
448
+ const captureGroupsToDelete = [1, 5];
449
+ const formatCaptureGroup = 3;
450
+ matchResultContext.regExCaptureGroups = getCaptureGroupsByResolvingAllDetails(scanningContext);
451
+
452
+ if (captureGroupsToDelete.length > 0) {
453
+ // Remove unwanted text in reg ex pattern.
454
+ removeTextInCaptureGroups(captureGroupsToDelete, matchResultContext);
455
+ }
456
+
457
+ formatTextInCaptureGroupIndex(formatting, formatCaptureGroup, matchResultContext);
458
+ makeCollapsedSelectionAtOffsetInJoinedText(matchResultContext.offsetInJoinedTextForCollapsedSelection, matchResultContext.offsetInJoinedTextForCollapsedSelection + 1, scanningContext.textNodeWithOffset.node.getParentOrThrow());
416
459
  }
417
460
  }
418
461
  } // Some Capture Group Details were left lazily unresolved as their calculation
@@ -516,7 +559,7 @@ function shiftCaptureGroupOffsets(delta, applyAtOrAfterOffset, node, startingCap
516
559
  }
517
560
  }
518
561
 
519
- function formatTextInCaptureGroupIndex(formatType, captureGroupIndex, matchResultContext) {
562
+ function formatTextInCaptureGroupIndex(formatTypes, captureGroupIndex, matchResultContext) {
520
563
  const regExCaptureGroups = matchResultContext.regExCaptureGroups;
521
564
  const regExCaptureGroupsCount = regExCaptureGroups.length;
522
565
 
@@ -536,7 +579,10 @@ function formatTextInCaptureGroupIndex(formatType, captureGroupIndex, matchResul
536
579
  const currentSelection = lexical.$getSelection();
537
580
 
538
581
  if (lexical.$isRangeSelection(currentSelection)) {
539
- currentSelection.formatText(formatType);
582
+ for (let i = 0; i < formatTypes.length; i++) {
583
+ currentSelection.formatText(formatTypes[i]);
584
+ }
585
+
540
586
  const finalSelection = lexical.$createRangeSelection();
541
587
  finalSelection.anchor.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
542
588
  finalSelection.focus.set(focusTextNodeWithOffset.node.getKey(), focusTextNodeWithOffset.offset + 1, 'text');
@@ -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 LexicalAutoFormatterPlugin(): React$Node;
@@ -4,23 +4,24 @@
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 l=require("@lexical/react/LexicalComposerContext"),p=require("@lexical/list"),q=require("lexical"),r=require("lexical/CodeNode"),v=require("react"),w=require("@lexical/react/LexicalHorizontalRuleNode"),A=require("lexical/HeadingNode"),B=require("lexical/QuoteNode");function C(g){throw Error(`Minified Lexical error #${g}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- function D(g,f,a,b){g=g.getChildren();const c=g.length;let d=0,e=!1;for(let n=0;n<c&&!(d>f);++n){const h=g[n],m=q.$isTextNode(h);var k=m?h.getTextContent().length:b;k=d+k;if((!1===e&&d===a||0===d&&d===a||d<a&&a<=k)&&q.$isTextNode(h))return{node:h,offset:a-d};d=k;e=m}return null}
9
- const E={nodeTransformationKind:null,regEx:/(?:)/,requiresParagraphStart:!1},G={...E,requiresParagraphStart:!0},H=[{...E,nodeTransformationKind:"textBold",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/}],I=[{...G,nodeTransformationKind:"paragraphH1",regEx:/(?:# )/},{...G,nodeTransformationKind:"paragraphH2",regEx:/(?:## )/},{...G,nodeTransformationKind:"paragraphH2",regEx:/(?:### )/},{...G,nodeTransformationKind:"paragraphBlockQuote",regEx:/(?:> )/},{...G,nodeTransformationKind:"paragraphUnorderedList",
10
- regEx:/(?:- )/},{...G,nodeTransformationKind:"paragraphUnorderedList",regEx:/(?:\* )/},{...G,nodeTransformationKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/},{...G,nodeTransformationKind:"paragraphCodeBlock",regEx:/(?:``` )/},{...G,nodeTransformationKind:"horizontalRule",regEx:/(?:\*\*\* )/},{...G,nodeTransformationKind:"horizontalRule",regEx:/(?:--- )/},...H];
11
- function J(g,f,a,b){const c={offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]};b=g.match(b);if(null!==b&&0<b.length&&(!1===f||0===b.index)&&(!1===a||b.index+b[0].length===g.length)){c.offsetInJoinedTextForCollapsedSelection=g.length;g=b.length;f=b.index;for(a=0;a<g;a++){const d=b[a];c.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:f,text:d,textLength:d.length-(a+1===g?1:0)});0<a&&(f+=d.length)}return c}return null}
12
- function K(g,f,a,b,c){c.offsetInJoinedTextForCollapsedSelection+=g;0<c.offsetInJoinedTextForCollapsedSelection||C(67);c=c.regExCaptureGroups;const d=c.length;for(b+=1;b<d;b++){const e=c[b];null!=e.anchorTextNodeWithOffset&&e.anchorTextNodeWithOffset.offset>=f&&e.anchorTextNodeWithOffset.node.is(a)&&(e.anchorTextNodeWithOffset.offset+=g);null!=e.focusTextNodeWithOffset&&e.focusTextNodeWithOffset.offset>=f&&e.focusTextNodeWithOffset.node.is(a)&&(e.focusTextNodeWithOffset.offset+=g)}}
13
- function L(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,b=a.node.getParentOrThrow();a=a.node.spliceText(0,f.matchResultContext.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var c=b;a=null;var d=c.getChildren(),e=f.autoFormatCriteria,k=f.matchResultContext;if(null!=e.nodeTransformationKind)switch(e.nodeTransformationKind){case "paragraphH1":a=A.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=
14
- A.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=A.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=B.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=p.$createListNode("ul");c=p.$createListItemNode();c.append(...d);a.append(c);break;case "paragraphOrderedList":a=parseInt(1<k.regExCaptureGroups.length?k.regExCaptureGroups[k.regExCaptureGroups.length-1].text:"1",10);a=p.$createListNode("ol",a);c=p.$createListItemNode();c.append(...d);
15
- a.append(c);break;case "paragraphCodeBlock":a=null!=f.triggerState&&f.triggerState.isCodeBlock?q.$createParagraphNode():r.$createCodeNode();a.append(...d);break;case "horizontalRule":d=w.$createHorizontalRuleNode(),c.insertBefore(d)}null!==a&&b.replace(a)}else if(a=f.autoFormatCriteria,b=f.matchResultContext,null!=a.nodeTransformationKind)switch(a.nodeTransformationKind){case "textBold":if(6===b.regExCaptureGroups.length){a=f.autoFormatCriteria;d=f.matchResultContext.regExCaptureGroups;c=d.length;
16
- e=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&C(62);k=f.joinedText.length;for(var n=1;n<c;n++){var h=d[n];h.anchorTextNodeWithOffset=D(e,k,h.offsetInParent,1);h.focusTextNodeWithOffset=D(e,k,h.offsetInParent+h.textLength,1);0>h.textLength&&C(63,a.nodeTransformationKind)}b.regExCaptureGroups=d;a=[1,5];d=b.regExCaptureGroups;c=d.length;for(e=a.length-1;0<=e;e--)if(e<c){k=a[e];var m=d[k];h=m.anchorTextNodeWithOffset;n=m.focusTextNodeWithOffset;null!=h&&null!=n&&0<m.textLength&&(m=
17
- q.$createRangeSelection(),m.anchor.set(h.node.getKey(),h.offset,"text"),m.focus.set(n.node.getKey(),n.offset,"text"),q.$setSelection(m),m=q.$getSelection(),q.$isRangeSelection(m)&&(m.removeText(),h.node.getKey()===n.node.getKey()?(m=n.offset-h.offset,0<m||C(64),K(-m,n.offset,h.node,k,b)):(h=n.offset,0<h&&K(-h,h,n.node,k,b))))}a=b.regExCaptureGroups;3<a.length||C(65);c=a[3];d=c.anchorTextNodeWithOffset;a=c.focusTextNodeWithOffset;null!=d&&null!=a&&0<c.textLength&&(c=q.$createRangeSelection(),c.anchor.set(d.node.getKey(),
18
- d.offset,"text"),c.focus.set(a.node.getKey(),a.offset,"text"),q.$setSelection(c),d=q.$getSelection(),q.$isRangeSelection(d)&&(d.formatText("bold"),d=q.$createRangeSelection(),d.anchor.set(a.node.getKey(),a.offset+1,"text"),d.focus.set(a.node.getKey(),a.offset+1,"text"),q.$setSelection(d)));a=f.textNodeWithOffset.node.getParentOrThrow();b=D(a,b.offsetInJoinedTextForCollapsedSelection+1,b.offsetInJoinedTextForCollapsedSelection,1);null!=b&&(a=q.$createRangeSelection(),a.anchor.set(b.node.getKey(),b.offset,
19
- "text"),a.focus.set(b.node.getKey(),b.offset,"text"),q.$setSelection(a))}}},{tag:"history-push"})}
20
- function M(g,f){let a=null;g.read(()=>{var b=q.$getSelection();if(q.$isRangeSelection(b)){var c=b.anchor.getNode();b=q.$isTextNode(c)?{node:c,offset:b.anchor.offset}:null}else b=null;if(null!==b){b={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:b,triggerState:f};a:{c=!1===f.isParentAListItemNode?I:H;const m=b.triggerState,
21
- N=c.length;for(let x=0;x<N;x++){const y=c[x];if(null!=m&&!1===m.isCodeBlock||"paragraphCodeBlock"===y.nodeTransformationKind){var d=y,e=b;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=J(e,!0,!1,d.regEx)):d=null;else b:{if(null==e.joinedText){var k=e.textNodeWithOffset.node.getParentOrThrow();if(q.$isElementNode(k)){if(null==e.joinedText){var n=e,h=e.textNodeWithOffset;let u="";
22
- k=k.getChildren();const O=k.length;for(let z=0;z<O;++z){const t=k[z];if(q.$isTextNode(t)){const F=t.getTextContent();if(t.is(h.node)){h.offset>F.length&&C(50,t.__key);u+=t.getTextContent().substr(0,h.offset);break}else u+=F}else u+="\u0004"}n.joinedText=u}d=J(e.joinedText,!1,!0,d.regEx);break b}C(52,k.__key)}d=null}if(null!=d){c={autoFormatCriteria:y,matchResultContext:d};break a}}}c={autoFormatCriteria:null,matchResultContext:null}}null!==c.autoFormatCriteria&&null!==c.matchResultContext&&(a=b,a.autoFormatCriteria=
23
- c.autoFormatCriteria,a.matchResultContext=c.matchResultContext)}});return a}
24
- function P(g){let f=null;g.read(()=>{const a=q.$getSelection();if(q.$isRangeSelection(a)&&a.isCollapsed()){var b=a.anchor.getNode(),c=b.getParent(),d=null!==c&&p.$isListItemNode(c);f={anchorOffset:a.anchor.offset,hasParentNode:null!==c,isCodeBlock:r.$isCodeNode(b),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:q.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return f}
25
- function Q(g){v.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var b=g.getEditorState();a=P(b);if(null==a)b=null;else{var c=a,d=f;if(null==c||null==d)b=null;else{var e=c.textContent.length,k=c.anchorOffset-1;b=!1===(!0===c.hasParentNode&&c.isSimpleText&&c.isSelectionCollapsed&&c.nodeKey===d.nodeKey&&c.anchorOffset!==d.anchorOffset&&0<=k&&k+1<=e&&" "===c.textContent.substr(k,1)&&c.textContent!==d.textContent)?null:M(b,c)}}null!=b&&L(g,b);f=a}else f=
26
- null})},[g])}module.exports=function(){const [g]=l.useLexicalComposerContext();Q(g);return null};
7
+ var k=require("@lexical/react/LexicalComposerContext"),q=require("@lexical/list"),r=require("lexical"),t=require("lexical/CodeNode"),u=require("react"),x=require("@lexical/react/LexicalHorizontalRuleNode"),y=require("lexical/HeadingNode"),C=require("lexical/QuoteNode");function D(g){throw Error(`Minified Lexical error #${g}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
+ function E(g,f,a,c){g=g.getChildren();const b=g.length;let d=0,e=!1;for(let p=0;p<b&&!(d>f);++p){const m=g[p],n=r.$isTextNode(m);var h=n?m.getTextContent().length:c;h=d+h;if((!1===e&&d===a||0===d&&d===a||d<a&&a<=h)&&r.$isTextNode(m))return{node:m,offset:a-d};d=h;e=n}return null}
9
+ const F={nodeTransformationKind:null,regEx:/(?:)/,requiresParagraphStart:!1},H={...F,requiresParagraphStart:!0},I=[{...F,nodeTransformationKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*\s)$/},{...F,nodeTransformationKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/},{...F,nodeTransformationKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*\s)$/},{...F,nodeTransformationKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__\s)$/},{...F,nodeTransformationKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>\s)$/},
10
+ {...F,nodeTransformationKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/}],J=[{...H,nodeTransformationKind:"paragraphH1",regEx:/^(?:# )/},{...H,nodeTransformationKind:"paragraphH2",regEx:/^(?:## )/},{...H,nodeTransformationKind:"paragraphH2",regEx:/^(?:### )/},{...H,nodeTransformationKind:"paragraphBlockQuote",regEx:/^(?:> )/},{...H,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:- )/},{...H,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:\* )/},{...H,nodeTransformationKind:"paragraphOrderedList",
11
+ regEx:/^(\d+)\.\s/},{...H,nodeTransformationKind:"paragraphCodeBlock",regEx:/^(```)([a-z]*)( )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/^(?:\*\*\* )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/^(?:--- )/},...I];
12
+ function K(g,f,a,c){const b={offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]};c=g.match(c);if(null!==c&&0<c.length&&(!1===f||0===c.index)&&(!1===a||c.index+c[0].length===g.length)){b.offsetInJoinedTextForCollapsedSelection=g.length;g=c.length;f=c.index;for(a=0;a<g;a++){const d=c[a];b.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:f,text:d,textLength:d.length-(a+1===g?1:0)});0<a&&(f+=d.length)}return b}return null}
13
+ function L(g,f,a,c,b){b.offsetInJoinedTextForCollapsedSelection+=g;0<b.offsetInJoinedTextForCollapsedSelection||D(67);b=b.regExCaptureGroups;const d=b.length;for(c+=1;c<d;c++){const e=b[c];null!=e.anchorTextNodeWithOffset&&e.anchorTextNodeWithOffset.offset>=f&&e.anchorTextNodeWithOffset.node.is(a)&&(e.anchorTextNodeWithOffset.offset+=g);null!=e.focusTextNodeWithOffset&&e.focusTextNodeWithOffset.offset>=f&&e.focusTextNodeWithOffset.node.is(a)&&(e.focusTextNodeWithOffset.offset+=g)}}
14
+ function M(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,c=a.node.getParentOrThrow();a=a.node.spliceText(0,f.matchResultContext.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var b=c;a=null;var d=b.getChildren(),e=f.autoFormatCriteria,h=f.matchResultContext;if(null!=e.nodeTransformationKind)switch(e.nodeTransformationKind){case "paragraphH1":a=y.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=
15
+ y.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=y.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=C.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=q.$createListNode("ul");b=q.$createListItemNode();b.append(...d);a.append(b);break;case "paragraphOrderedList":a=parseInt(1<h.regExCaptureGroups.length?h.regExCaptureGroups[h.regExCaptureGroups.length-1].text:"1",10);a=q.$createListNode("ol",a);b=q.$createListItemNode();b.append(...d);
16
+ a.append(b);break;case "paragraphCodeBlock":null!=f.triggerState&&f.triggerState.isCodeBlock?a=r.$createParagraphNode():(a=t.$createCodeNode(),b=3<=h.regExCaptureGroups.length?h.regExCaptureGroups[2].text:null,null!=b&&0<b.length&&a.setLanguage(b));a.append(...d);break;case "horizontalRule":d=x.$createHorizontalRuleNode(),b.insertBefore(d)}null!==a&&c.replace(a)}else if(a=f.autoFormatCriteria,c=f.matchResultContext,null!=a.nodeTransformationKind&&6===c.regExCaptureGroups.length){a:{a=a.nodeTransformationKind;
17
+ switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=["bold","italic"];break a}a=null}if(null!=a){d=[1,5];b=f.autoFormatCriteria;e=f.matchResultContext.regExCaptureGroups;h=e.length;var p=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&D(62);var m=f.joinedText.length;for(var n=1;n<h;n++){var l=e[n];l.anchorTextNodeWithOffset=E(p,m,l.offsetInParent,1);l.focusTextNodeWithOffset=E(p,m,l.offsetInParent+l.textLength,1);0>l.textLength&&
18
+ D(63,b.nodeTransformationKind)}c.regExCaptureGroups=e;if(0<d.length)for(b=c.regExCaptureGroups,e=b.length,h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=b[p],n=l.anchorTextNodeWithOffset,m=l.focusTextNodeWithOffset,null!=n&&null!=m&&0<l.textLength&&(l=r.$createRangeSelection(),l.anchor.set(n.node.getKey(),n.offset,"text"),l.focus.set(m.node.getKey(),m.offset,"text"),r.$setSelection(l),l=r.$getSelection(),r.$isRangeSelection(l)&&(l.removeText(),n.node.getKey()===m.node.getKey()?(l=m.offset-n.offset,0<l||D(64),
19
+ L(-l,m.offset,n.node,p,c)):(n=m.offset,0<n&&L(-n,n,m.node,p,c)))));d=c.regExCaptureGroups;3<d.length||D(65);e=d[3];b=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=b&&null!=d&&0<e.textLength&&(e=r.$createRangeSelection(),e.anchor.set(b.node.getKey(),b.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),r.$setSelection(e),b=r.$getSelection(),r.$isRangeSelection(b))){for(e=0;e<a.length;e++)b.formatText(a[e]);a=r.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+
20
+ 1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");r.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();c=E(a,c.offsetInJoinedTextForCollapsedSelection+1,c.offsetInJoinedTextForCollapsedSelection,1);null!=c&&(a=r.$createRangeSelection(),a.anchor.set(c.node.getKey(),c.offset,"text"),a.focus.set(c.node.getKey(),c.offset,"text"),r.$setSelection(a))}}},{tag:"history-push"})}
21
+ function N(g,f){let a=null;g.read(()=>{var c=r.$getSelection();if(r.$isRangeSelection(c)){var b=c.anchor.getNode();c=r.$isTextNode(b)?{node:b,offset:c.anchor.offset}:null}else c=null;if(null!==c){c={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:c,triggerState:f};a:{b=!1===f.isParentAListItemNode?J:I;const n=c.triggerState,
22
+ l=b.length;for(let z=0;z<l;z++){const A=b[z];if(null!=n&&!1===n.isCodeBlock||"paragraphCodeBlock"===A.nodeTransformationKind){var d=A,e=c;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=K(e,!0,!1,d.regEx)):d=null;else{if(null==e.joinedText){var h=e.textNodeWithOffset.node.getParentOrThrow();if(r.$isElementNode(h)){if(null==e.joinedText){var p=e,m=e.textNodeWithOffset;let w="";h=
23
+ h.getChildren();const O=h.length;for(let B=0;B<O;++B){const v=h[B];if(r.$isTextNode(v)){const G=v.getTextContent();if(v.is(m.node)){m.offset>G.length&&D(50,v.__key);w+=v.getTextContent().substr(0,m.offset);break}else w+=G}else w+="\u0004"}p.joinedText=w}}else D(52,h.__key)}d=K(e.joinedText,!1,!0,d.regEx)}if(null!=d){b={autoFormatCriteria:A,matchResultContext:d};break a}}}b={autoFormatCriteria:null,matchResultContext:null}}null!==b.autoFormatCriteria&&null!==b.matchResultContext&&(a=c,a.autoFormatCriteria=
24
+ b.autoFormatCriteria,a.matchResultContext=b.matchResultContext)}});return a}
25
+ function P(g){let f=null;g.read(()=>{const a=r.$getSelection();if(r.$isRangeSelection(a)&&a.isCollapsed()){var c=a.anchor.getNode(),b=c.getParent(),d=null!==b&&q.$isListItemNode(b);f={anchorOffset:a.anchor.offset,hasParentNode:null!==b,isCodeBlock:t.$isCodeNode(c),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:r.$isTextNode(c)&&c.isSimpleText(),nodeKey:c.getKey(),textContent:c.getTextContent()}}});return f}
26
+ function Q(g){u.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var c=g.getEditorState();a=P(c);if(null==a)c=null;else{var b=a,d=f;if(null==b||null==d)c=null;else{var e=b.textContent.length,h=b.anchorOffset-1;c=!1===(!0===b.hasParentNode&&b.isSimpleText&&b.isSelectionCollapsed&&b.nodeKey===d.nodeKey&&b.anchorOffset!==d.anchorOffset&&0<=h&&h+1<=e&&" "===b.textContent.substr(h,1)&&b.textContent!==d.textContent)?null:N(c,b)}}null!=c&&M(g,c);f=a}else f=
27
+ null})},[g])}module.exports=function(){const [g]=k.useLexicalComposerContext();Q(g);return null};
@@ -0,0 +1,20 @@
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
+ type ChangeHandler = (url: string | null, prevUrl: string | null) => void;
10
+ type LinkMatcherResult = {
11
+ text: string;
12
+ url: string;
13
+ length: number;
14
+ index: number;
15
+ };
16
+ export type LinkMatcher = (text: string) => LinkMatcherResult | null;
17
+ export default function LexicalAutoLinkPlugin(props: {
18
+ matchers: Array<LinkMatcher>;
19
+ onChange?: ChangeHandler;
20
+ }): React.ReactNode;
@@ -0,0 +1,23 @@
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
+ type ChangeHandler = (url: string | null, prevUrl: string | null) => void;
11
+
12
+ type LinkMatcherResult = {
13
+ text: string,
14
+ url: string,
15
+ length: number,
16
+ index: number,
17
+ };
18
+ export type LinkMatcher = (text: string) => LinkMatcherResult | null;
19
+
20
+ declare export default function LexicalAutoLinkPlugin(props: {
21
+ matchers: Array<LinkMatcher>,
22
+ onChange?: ChangeHandler,
23
+ }): React$Node;
@@ -0,0 +1,11 @@
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
+ export default function LexicalCharacterLimitPlugin(props: {
10
+ charset: 'UTF-8' | 'UTF-16';
11
+ }): React.ReactNode;
@@ -20,11 +20,15 @@ var OverflowNode = require('lexical/OverflowNode');
20
20
  *
21
21
  *
22
22
  */
23
- function $dfs__DEPRECATED(startingNode, nextNode) {
24
- let node = startingNode;
25
- nextNode(node);
23
+ function $dfs(startingNode, endingNode) {
24
+ const nodes = [];
25
+ const start = (startingNode || lexical.$getRoot()).getLatest();
26
+ const end = endingNode || (lexical.$isElementNode(start) ? start.getLastDescendant() : start);
27
+ let node = start;
28
+
29
+ while (node !== null && !node.is(end)) {
30
+ nodes.push(node);
26
31
 
27
- while (node !== null) {
28
32
  if (lexical.$isElementNode(node) && node.getChildrenSize() > 0) {
29
33
  node = node.getFirstChild();
30
34
  } else {
@@ -41,11 +45,13 @@ function $dfs__DEPRECATED(startingNode, nextNode) {
41
45
  }
42
46
  }
43
47
  }
48
+ }
44
49
 
45
- if (node !== null) {
46
- node = nextNode(node);
47
- }
50
+ if (node !== null && node.is(end)) {
51
+ nodes.push(node);
48
52
  }
53
+
54
+ return nodes;
49
55
  }
50
56
 
51
57
  /**
@@ -159,10 +165,13 @@ function findOffset(text, maxCharacters, strlen) {
159
165
  }
160
166
 
161
167
  function $wrapOverflowedNodes(offset) {
162
- const root = lexical.$getRoot();
168
+ const dfsNodes = $dfs();
169
+ const dfsNodesLength = dfsNodes.length;
163
170
  let accumulatedLength = 0;
164
- let previousNode = root;
165
- $dfs__DEPRECATED(root, node => {
171
+
172
+ for (let i = 0; i < dfsNodesLength; i += 1) {
173
+ const node = dfsNodes[i];
174
+
166
175
  if (OverflowNode.$isOverflowNode(node)) {
167
176
  const previousLength = accumulatedLength;
168
177
  const nextLength = accumulatedLength + node.getTextContentSize();
@@ -183,8 +192,6 @@ function $wrapOverflowedNodes(offset) {
183
192
  parent.select();
184
193
  }
185
194
  }
186
-
187
- return previousNode;
188
195
  } else if (previousLength < offset) {
189
196
  const descendant = node.getFirstDescendant();
190
197
  const descendantLength = descendant !== null ? descendant.getTextContentSize() : 0;
@@ -196,7 +203,6 @@ function $wrapOverflowedNodes(offset) {
196
203
 
197
204
  if (firstDescendantIsSimpleText || firstDescendantDoesNotOverflow) {
198
205
  $unwrapNode(node);
199
- return previousNode;
200
206
  }
201
207
  }
202
208
  } else if (lexical.$isLeafNode(node)) {
@@ -222,10 +228,7 @@ function $wrapOverflowedNodes(offset) {
222
228
  mergePrevious(overflowNode);
223
229
  }
224
230
  }
225
-
226
- previousNode = node;
227
- return node;
228
- });
231
+ }
229
232
  }
230
233
 
231
234
  function $wrapNode(node) {
@@ -0,0 +1,12 @@
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 LexicalCharacterLimitPlugin(props: {
11
+ charset: 'UTF-8' | 'UTF-16',
12
+ }): React$Node;