@lexical/react 0.1.14 → 0.1.15

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 (33) hide show
  1. package/DEPRECATED_useLexicalAutoFormatter.dev.js +283 -295
  2. package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -21
  3. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +3 -72
  4. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -2
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +11 -63
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +6 -7
  7. package/DEPRECATED_useLexicalPlainText.dev.js +16 -41
  8. package/DEPRECATED_useLexicalPlainText.prod.js +13 -14
  9. package/DEPRECATED_useLexicalRichText.dev.js +24 -49
  10. package/DEPRECATED_useLexicalRichText.prod.js +15 -15
  11. package/LexicalAutoFormatterPlugin.dev.js +283 -295
  12. package/LexicalAutoFormatterPlugin.prod.js +19 -21
  13. package/LexicalAutoLinkPlugin.dev.js +2 -2
  14. package/LexicalAutoLinkPlugin.prod.js +2 -2
  15. package/LexicalCharacterLimitPlugin.dev.js +11 -63
  16. package/LexicalCharacterLimitPlugin.prod.js +8 -9
  17. package/LexicalCollaborationPlugin.d.ts +3 -1
  18. package/LexicalCollaborationPlugin.dev.js +40 -6
  19. package/LexicalCollaborationPlugin.js.flow +4 -1
  20. package/LexicalCollaborationPlugin.prod.js +8 -7
  21. package/LexicalHashtagPlugin.dev.js +16 -13
  22. package/LexicalHashtagPlugin.prod.js +7 -7
  23. package/LexicalOnChangePlugin.dev.js +15 -2
  24. package/LexicalOnChangePlugin.prod.js +2 -1
  25. package/LexicalPlainTextPlugin.dev.js +20 -113
  26. package/LexicalPlainTextPlugin.prod.js +11 -12
  27. package/LexicalRichTextPlugin.dev.js +28 -121
  28. package/LexicalRichTextPlugin.prod.js +12 -13
  29. package/LexicalTablePlugin.dev.js +9 -5
  30. package/LexicalTablePlugin.prod.js +2 -2
  31. package/package.json +9 -7
  32. package/useLexicalIsTextContentEmpty.dev.js +3 -32
  33. package/useLexicalIsTextContentEmpty.prod.js +1 -2
@@ -4,24 +4,22 @@
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/list"),q=require("lexical"),r=require("lexical/CodeNode"),t=require("react"),u=require("@lexical/react/LexicalHorizontalRuleNode"),x=require("lexical/HeadingNode"),y=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,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=q.$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)&&q.$isTextNode(m))return{node:m,offset:a-d};d=h;e=n}return null}
9
- const E={nodeTransformationKind:null,regEx:/(?:)/,requiresParagraphStart:!1},F={...E,requiresParagraphStart:!0},H=[{...E,nodeTransformationKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*\s)$/},{...E,nodeTransformationKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/},{...E,nodeTransformationKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*\s)$/},{...E,nodeTransformationKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__\s)$/},{...E,nodeTransformationKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>\s)$/},
10
- {...E,nodeTransformationKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/}],I=[{...F,nodeTransformationKind:"paragraphH1",regEx:/^(?:# )/},{...F,nodeTransformationKind:"paragraphH2",regEx:/^(?:## )/},{...F,nodeTransformationKind:"paragraphH2",regEx:/^(?:### )/},{...F,nodeTransformationKind:"paragraphBlockQuote",regEx:/^(?:> )/},{...F,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:- )/},{...F,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:\* )/},{...F,nodeTransformationKind:"paragraphOrderedList",
11
- regEx:/^(\d+)\.\s/},{...F,nodeTransformationKind:"paragraphCodeBlock",regEx:/^(```)([a-z]*)( )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/^(?:\*\*\* )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/^(?:--- )/},...H];
12
- function J(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 K(g,f,a,c,b){b.offsetInJoinedTextForCollapsedSelection+=g;0<b.offsetInJoinedTextForCollapsedSelection||C(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 L(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=x.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=
15
- x.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=x.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=y.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=k.$createListNode("ul");b=k.$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=k.$createListNode("ol",a);b=k.$createListItemNode();b.append(...d);
16
- a.append(b);break;case "paragraphCodeBlock":null!=f.triggerState&&f.triggerState.isCodeBlock?a=q.$createParagraphNode():(a=r.$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=u.$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&&C(62);var m=f.joinedText.length;for(var n=1;n<h;n++){var l=e[n];l.anchorTextNodeWithOffset=D(p,m,l.offsetInParent,1);l.focusTextNodeWithOffset=D(p,m,l.offsetInParent+l.textLength,1);0>l.textLength&&
18
- C(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=q.$createRangeSelection(),l.anchor.set(n.node.getKey(),n.offset,"text"),l.focus.set(m.node.getKey(),m.offset,"text"),q.$setSelection(l),l=q.$getSelection(),q.$isRangeSelection(l)&&(l.removeText(),n.node.getKey()===m.node.getKey()?(l=m.offset-n.offset,0<l||C(64),
19
- K(-l,m.offset,n.node,p,c)):(n=m.offset,0<n&&K(-n,n,m.node,p,c)))));d=c.regExCaptureGroups;3<d.length||C(65);e=d[3];b=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=b&&null!=d&&0<e.textLength&&(e=q.$createRangeSelection(),e.anchor.set(b.node.getKey(),b.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),q.$setSelection(e),b=q.$getSelection(),q.$isRangeSelection(b))){for(e=0;e<a.length;e++)b.formatText(a[e]);a=q.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+
20
- 1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");q.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();c=D(a,c.offsetInJoinedTextForCollapsedSelection+1,c.offsetInJoinedTextForCollapsedSelection,1);null!=c&&(a=q.$createRangeSelection(),a.anchor.set(c.node.getKey(),c.offset,"text"),a.focus.set(c.node.getKey(),c.offset,"text"),q.$setSelection(a))}}},{tag:"history-push"})}
21
- function M(g,f){let a=null;g.read(()=>{var c=q.$getSelection();if(q.$isRangeSelection(c)){var b=c.anchor.getNode();c=q.$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?I:H;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=J(e,!0,!1,d.regEx)):d=null;else{if(null==e.joinedText){var h=e.textNodeWithOffset.node.getParentOrThrow();if(q.$isElementNode(h)){if(null==e.joinedText){var p=e,m=e.textNodeWithOffset;let w="";h=
23
- h.getChildren();const N=h.length;for(let B=0;B<N;++B){const v=h[B];if(q.$isTextNode(v)){const G=v.getTextContent();if(v.is(m.node)){m.offset>G.length&&C(50,v.__key);w+=v.getTextContent().substr(0,m.offset);break}else w+=G}else w+="\u0004"}p.joinedText=w}}else C(52,h.__key)}d=J(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 O(g){let f=null;g.read(()=>{const a=q.$getSelection();if(q.$isRangeSelection(a)&&a.isCollapsed()){var c=a.anchor.getNode(),b=c.getParent(),d=null!==b&&k.$isListItemNode(b);f={anchorOffset:a.anchor.offset,hasParentNode:null!==b,isCodeBlock:r.$isCodeNode(c),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:q.$isTextNode(c)&&c.isSimpleText(),nodeKey:c.getKey(),textContent:c.getTextContent()}}});return f}
26
- function P(g){t.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var c=g.getEditorState();a=O(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:M(c,b)}}null!=c&&L(g,c);f=a}else f=
27
- null})},[g])}module.exports=function(g){P(g)};
7
+ var h=require("@lexical/list"),l=require("lexical"),m=require("lexical/CodeNode"),n=require("react"),p=require("@lexical/react/LexicalHorizontalRuleNode"),q=require("@lexical/text"),r=require("lexical/HeadingNode"),t=require("lexical/QuoteNode");function x(f){throw Error(`Minified Lexical error #${f}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
+ const y={autoFormatKind:null,regEx:/(?:)/,requiresParagraphStart:!1},z={...y,requiresParagraphStart:!0},A=[{...y,autoFormatKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*)(\s)$/},{...y,autoFormatKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*)(\s)$/},{...y,autoFormatKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/},{...y,autoFormatKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__)(\s)$/},{...y,autoFormatKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)(\s)$/},
9
+ {...y,autoFormatKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~)(\s)$/},{...y,autoFormatKind:"link",regEx:/(\[)(.+)(\]\()([^ ]+)(?: "(?:.+)")?(\))(\s)$/}],B=[{...z,autoFormatKind:"paragraphH1",regEx:/^(?:# )/},{...z,autoFormatKind:"paragraphH2",regEx:/^(?:## )/},{...z,autoFormatKind:"paragraphH2",regEx:/^(?:### )/},{...z,autoFormatKind:"paragraphBlockQuote",regEx:/^(?:> )/},{...z,autoFormatKind:"paragraphUnorderedList",regEx:/^(?:- )/},{...z,autoFormatKind:"paragraphUnorderedList",regEx:/^(?:\* )/},
10
+ {...z,autoFormatKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/},{...z,autoFormatKind:"paragraphCodeBlock",regEx:/^(```)([a-z]*)( )/},{...z,autoFormatKind:"horizontalRule",regEx:/^(?:\*\*\* )/},{...z,autoFormatKind:"horizontalRule",regEx:/^(?:--- )/},...A];
11
+ function C(f,d,a,b){const c={regExCaptureGroups:[]};b=f.match(b);if(null!==b&&0<b.length&&(!1===d||0===b.index)&&(!1===a||b.index+b[0].length===f.length)){f=b.length;d=b.index;for(a=0;a<f;a++){const e=b[a];c.regExCaptureGroups.push({offsetInParent:d,text:e});0<a&&(d+=e.length)}return c}return null}
12
+ function D(f,d,a,b,c){var e=c.patternMatchResults;const g=e.regExCaptureGroups;var k=g.length;if(f>=k||d>=k)return null;c=c.textNodeWithOffset.node.getParentOrThrow();k=e.regExCaptureGroups.length;2>k?e=0:(--k,e=e.regExCaptureGroups[k].offsetInParent+e.regExCaptureGroups[k].text.length);f=g[f];d=g[d];b=b?d.offsetInParent+d.text.length:d.offsetInParent;a=q.$findNodeWithOffsetFromJoinedText(a?f.offsetInParent+f.text.length:f.offsetInParent,e,1,c);b=q.$findNodeWithOffsetFromJoinedText(b,e,1,c);if(null==
13
+ a||null==b)return null;c=l.$createRangeSelection();c.anchor.set(a.node.getKey(),a.offset,"text");c.focus.set(b.node.getKey(),b.offset,"text");return c}function E(f,d,a){const b=a.patternMatchResults.regExCaptureGroups;a=D(f,d,!1,!0,a);if(null!=a&&(l.$setSelection(a),a=l.$getSelection(),null!=a&&l.$isRangeSelection(a)&&!1===a.isCollapsed())){a.removeText();a=0;const c=b.length;for(let e=f;e<c;e++){const g=b[e];e>f&&(g.offsetInParent-=a);e<=d&&(a+=g.text.length,g.text="")}}}
14
+ function F(f){var d=f.patternMatchResults.regExCaptureGroups.length;2>d||(--d,f=D(d,d,!0,!0,f),null!=f&&l.$setSelection(f))}
15
+ function G(f,d){f.update(()=>{if(d.autoFormatCriteria.requiresParagraphStart){var a=d.textNodeWithOffset,b=a.node.getParentOrThrow();a=a.node.spliceText(0,d.patternMatchResults.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var c=b;a=null;var e=c.getChildren(),g=d.autoFormatCriteria;const k=d.patternMatchResults;if(null!=g.autoFormatKind)switch(g.autoFormatKind){case "paragraphH1":a=r.$createHeadingNode("h1");a.append(...e);break;case "paragraphH2":a=
16
+ r.$createHeadingNode("h2");a.append(...e);break;case "paragraphH3":a=r.$createHeadingNode("h3");a.append(...e);break;case "paragraphBlockQuote":a=t.$createQuoteNode();a.append(...e);break;case "paragraphUnorderedList":a=h.$createListNode("ul");c=h.$createListItemNode();c.append(...e);a.append(c);break;case "paragraphOrderedList":a=parseInt(1<k.regExCaptureGroups.length?k.regExCaptureGroups[k.regExCaptureGroups.length-1].text:"1",10);a=h.$createListNode("ol",a);c=h.$createListItemNode();c.append(...e);
17
+ a.append(c);break;case "paragraphCodeBlock":null!=d.triggerState&&d.triggerState.isCodeBlock?a=l.$createParagraphNode():(a=m.$createCodeNode(),c=3<=k.regExCaptureGroups.length?k.regExCaptureGroups[2].text:null,null!=c&&0<c.length&&a.setLanguage(c));a.append(...e);break;case "horizontalRule":e=p.$createHorizontalRuleNode(),c.insertBefore(e)}null!==a&&b.replace(a)}else if(b=d.autoFormatCriteria,null!=b.autoFormatKind){a:{a=b.autoFormatKind;switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=
18
+ [a];break a;case "bold_italic":a=["bold","italic"];break a}a=null}if(null!=a){if(b=a,7===d.patternMatchResults.regExCaptureGroups.length){E(5,5,d);E(1,1,d);a=d.patternMatchResults.regExCaptureGroups;3<a.length||x(65);if(0!==a[3].text.length&&(a=D(3,3,!1,!0,d),null!=a&&(l.$setSelection(a),a=l.$getSelection(),l.$isRangeSelection(a))))for(e=0;e<b.length;e++)a.formatText(b[e]);F(d)}}else if("link"===b.autoFormatKind&&(b=d.patternMatchResults.regExCaptureGroups,7===b.length&&(e=b[2].text,b=b[4].text,0!==
19
+ e.length&&0!==b.length))){E(1,5,d);a=d.patternMatchResults.regExCaptureGroups;if(!(1>=a.length)&&(e={offsetInParent:a[1].offsetInParent,text:e},c=D(1,1,!1,!1,d),null!=c&&(l.$setSelection(c),c=l.$getSelection(),null!=c&&l.$isRangeSelection(c)&&c.isCollapsed())))for(c.insertText(e.text),a.splice(1,0,e),e=e.text.length,c=a.length,g=2;g<c;g++)a[g].offsetInParent+=e;a=D(1,1,!1,!0,d);null!=a&&(l.$setSelection(a),d.editor.execCommand("toggleLink",b),F(d))}}},{tag:"history-push"})}
20
+ function H(f,d){let a=null;f.getEditorState().read(()=>{var b=l.$getSelection();if(l.$isRangeSelection(b)){var c=b.anchor.getNode();b=l.$isTextNode(c)?{node:c,offset:b.anchor.offset}:null}else b=null;if(null!==b){b={autoFormatCriteria:{autoFormatKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},editor:f,joinedText:null,patternMatchResults:{regExCaptureGroups:[]},textNodeWithOffset:b,triggerState:d};a:{c=!1===d.isParentAListItemNode?B:A;const k=b.triggerState,I=c.length;for(let u=0;u<
21
+ I;u++){const v=c[u];if(null!=k&&!1===k.isCodeBlock||"paragraphCodeBlock"===v.autoFormatKind){var e=v,g=b;if(null!==e.requiresParagraphStart&&!0===e.requiresParagraphStart)null===g.textNodeWithOffset.node.getPreviousSibling()?(g=g.textNodeWithOffset.node.getTextContent(),g=C(g,!0,!1,e.regEx)):g=null;else{if(null==g.joinedText){const w=g.textNodeWithOffset.node.getParentOrThrow();l.$isElementNode(w)?null==g.joinedText&&(g.joinedText=q.$joinTextNodesInElementNode(w,"\u0004",g.textNodeWithOffset)):x(52,
22
+ w.__key)}g=C(g.joinedText,!1,!0,e.regEx)}if(null!=g){c={autoFormatCriteria:v,patternMatchResults:g};break a}}}c={autoFormatCriteria:null,patternMatchResults:null}}null!==c.autoFormatCriteria&&null!==c.patternMatchResults&&(a=b,a.autoFormatCriteria=c.autoFormatCriteria,a.patternMatchResults=c.patternMatchResults)}});return a}
23
+ function J(f){let d=null;f.read(()=>{const a=l.$getSelection();if(l.$isRangeSelection(a)&&a.isCollapsed()){var b=a.anchor.getNode(),c=b.getParent(),e=null!==c&&h.$isListItemNode(c);d={anchorOffset:a.anchor.offset,hasParentNode:null!==c,isCodeBlock:m.$isCodeNode(b),isParentAListItemNode:e,isSelectionCollapsed:a.isCollapsed(),isSimpleText:l.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return d}
24
+ function K(f){n.useEffect(()=>{let d=null;return f.addListener("update",({tags:a})=>{if(!1===a.has("historic")){a=J(f.getEditorState());if(null==a)var b=null;else{b=a;var c=d;if(null==b||null==c)b=null;else{var e=b.textContent.length,g=b.anchorOffset-1;b=!1===(!0===b.hasParentNode&&b.isSimpleText&&b.isSelectionCollapsed&&b.nodeKey===c.nodeKey&&b.anchorOffset!==c.anchorOffset&&0<=g&&g+1<=e&&" "===b.textContent.substr(g,1)&&b.textContent!==c.textContent)?null:H(f,b)}}null!=b&&G(f,b);d=a}else d=null})},
25
+ [f])}module.exports=function(f){K(f)};
@@ -6,78 +6,9 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
- var lexical = require('lexical');
9
+ var text = require('@lexical/text');
10
10
  var react = require('react');
11
11
 
12
- /**
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- *
18
- *
19
- */
20
- function $textContent() {
21
- const root = lexical.$getRoot();
22
- return root.getTextContent();
23
- }
24
- function $isTextContentEmpty(isEditorComposing, trim = true) {
25
- if (isEditorComposing) {
26
- return false;
27
- }
28
-
29
- let text = $textContent();
30
-
31
- if (trim) {
32
- text = text.trim();
33
- }
34
-
35
- return text === '';
36
- }
37
- function $canShowPlaceholder(isComposing) {
38
- if (!$isTextContentEmpty(isComposing, false)) {
39
- return false;
40
- }
41
-
42
- const root = lexical.$getRoot();
43
- const children = root.getChildren();
44
- const childrenLength = children.length;
45
-
46
- if (childrenLength > 1) {
47
- return false;
48
- }
49
-
50
- for (let i = 0; i < childrenLength; i++) {
51
- const topBlock = children[i];
52
-
53
- if (lexical.$isElementNode(topBlock)) {
54
- if (topBlock.__type !== 'paragraph') {
55
- return false;
56
- }
57
-
58
- if (topBlock.__indent !== 0) {
59
- return false;
60
- }
61
-
62
- const topBlockChildren = topBlock.getChildren();
63
- const topBlockChildrenLength = topBlockChildren.length;
64
-
65
- for (let s = 0; s < topBlockChildrenLength; s++) {
66
- const child = topBlockChildren[i];
67
-
68
- if (!lexical.$isTextNode(child)) {
69
- return false;
70
- }
71
- }
72
- }
73
- }
74
-
75
- return true;
76
- }
77
- function $canShowPlaceholderCurry(isEditorComposing) {
78
- return () => $canShowPlaceholder(isEditorComposing);
79
- }
80
-
81
12
  /**
82
13
  * Copyright (c) Meta Platforms, Inc. and affiliates.
83
14
  *
@@ -108,13 +39,13 @@ var useLayoutEffect = useLayoutEffectImpl;
108
39
  *
109
40
  */
110
41
  function useLexicalCanShowPlaceholder$1(editor) {
111
- const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing())));
42
+ const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
112
43
  useLayoutEffect(() => {
113
44
  return editor.addListener('update', ({
114
45
  editorState
115
46
  }) => {
116
47
  const isComposing = editor.isComposing();
117
- const currentCanShowPlaceholder = editorState.read($canShowPlaceholderCurry(isComposing));
48
+ const currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
118
49
  setCanShowPlaceholder(currentCanShowPlaceholder);
119
50
  });
120
51
  }, [editor]);
@@ -4,5 +4,4 @@
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 e=require("lexical"),f=require("react");function k(a,d=!0){if(a)return!1;a=e.$getRoot().getTextContent();d&&(a=a.trim());return""===a}function l(a){if(!k(a,!1))return!1;a=e.$getRoot().getChildren();const d=a.length;if(1<d)return!1;for(let c=0;c<d;c++){var b=a[c];if(e.$isElementNode(b)){if("paragraph"!==b.__type||0!==b.__indent)return!1;b=b.getChildren();const g=b.length;for(let h=0;h<g;h++)if(!e.$isTextNode(b[c]))return!1}}return!0}function m(a){return()=>l(a)}
8
- var n="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;function p(a){const [d,b]=f.useState(a.getEditorState().read(m(a.isComposing())));n(()=>a.addListener("update",({editorState:c})=>{const g=a.isComposing();c=c.read(m(g));b(c)}),[a]);return d}module.exports=function(a){return p(a)};
7
+ var b=require("@lexical/text"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;function f(a){const [g,h]=d.useState(a.getEditorState().read(b.$canShowPlaceholderCurry(a.isComposing())));e(()=>a.addListener("update",({editorState:c})=>{const k=a.isComposing();c=c.read(b.$canShowPlaceholderCurry(k));h(c)}),[a]);return g}module.exports=function(a){return f(a)};
@@ -6,67 +6,13 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
- var lexical = require('lexical');
10
9
  var withSubscriptions = require('@lexical/react/withSubscriptions');
10
+ var text = require('@lexical/text');
11
+ var utils = require('@lexical/utils');
12
+ var lexical = require('lexical');
11
13
  var OverflowNode = require('lexical/OverflowNode');
12
14
  var react = require('react');
13
15
 
14
- /**
15
- * Copyright (c) Meta Platforms, Inc. and affiliates.
16
- *
17
- * This source code is licensed under the MIT license found in the
18
- * LICENSE file in the root directory of this source tree.
19
- *
20
- *
21
- */
22
- function $dfs(startingNode, endingNode) {
23
- const nodes = [];
24
- const start = (startingNode || lexical.$getRoot()).getLatest();
25
- const end = endingNode || (lexical.$isElementNode(start) ? start.getLastDescendant() : start);
26
- let node = start;
27
-
28
- while (node !== null && !node.is(end)) {
29
- nodes.push(node);
30
-
31
- if (lexical.$isElementNode(node) && node.getChildrenSize() > 0) {
32
- node = node.getFirstChild();
33
- } else {
34
- // Find immediate sibling or nearest parent sibling
35
- let sibling = null;
36
-
37
- while (sibling === null && node !== null) {
38
- sibling = node.getNextSibling();
39
-
40
- if (sibling === null) {
41
- node = node.getParent();
42
- } else {
43
- node = sibling;
44
- }
45
- }
46
- }
47
- }
48
-
49
- if (node !== null && node.is(end)) {
50
- nodes.push(node);
51
- }
52
-
53
- return nodes;
54
- }
55
-
56
- /**
57
- * Copyright (c) Meta Platforms, Inc. and affiliates.
58
- *
59
- * This source code is licensed under the MIT license found in the
60
- * LICENSE file in the root directory of this source tree.
61
- *
62
- *
63
- */
64
- function $textContent() {
65
- const root = lexical.$getRoot();
66
- return root.getTextContent();
67
- }
68
- const $textContentCurry = $textContent;
69
-
70
16
  /**
71
17
  * Copyright (c) Meta Platforms, Inc. and affiliates.
72
18
  *
@@ -89,10 +35,10 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
89
35
  }
90
36
  }, [editor]);
91
37
  react.useEffect(() => {
92
- let text = editor.getEditorState().read($textContentCurry);
38
+ let text$1 = editor.getEditorState().read(text.$rootTextContentCurry);
93
39
  let lastComputedTextLength = 0;
94
40
  return withSubscriptions(editor.addListener('textcontent', currentText => {
95
- text = currentText;
41
+ text$1 = currentText;
96
42
  }), editor.addListener('update', ({
97
43
  dirtyLeaves
98
44
  }) => {
@@ -103,13 +49,13 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
103
49
  return;
104
50
  }
105
51
 
106
- const textLength = strlen(text);
52
+ const textLength = strlen(text$1);
107
53
  const textLengthAboveThreshold = textLength > maxCharacters || lastComputedTextLength !== null && lastComputedTextLength > maxCharacters;
108
54
  const diff = maxCharacters - textLength;
109
55
  remainingCharacters(diff);
110
56
 
111
57
  if (lastComputedTextLength === null || textLengthAboveThreshold) {
112
- const offset = findOffset(text, maxCharacters, strlen);
58
+ const offset = findOffset(text$1, maxCharacters, strlen);
113
59
  editor.update(() => {
114
60
  $wrapOverflowedNodes(offset);
115
61
  }, {
@@ -164,12 +110,14 @@ function findOffset(text, maxCharacters, strlen) {
164
110
  }
165
111
 
166
112
  function $wrapOverflowedNodes(offset) {
167
- const dfsNodes = $dfs();
113
+ const dfsNodes = utils.$dfs();
168
114
  const dfsNodesLength = dfsNodes.length;
169
115
  let accumulatedLength = 0;
170
116
 
171
117
  for (let i = 0; i < dfsNodesLength; i += 1) {
172
- const node = dfsNodes[i];
118
+ const {
119
+ node
120
+ } = dfsNodes[i];
173
121
 
174
122
  if (OverflowNode.$isOverflowNode(node)) {
175
123
  const previousLength = accumulatedLength;
@@ -4,11 +4,10 @@
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 h=require("lexical"),t=require("@lexical/react/withSubscriptions"),y=require("lexical/OverflowNode"),z=require("react");function A(){return h.$getRoot().getTextContent()}function B(a,e,g){var f=Intl.Segmenter;let n=0;var c=0;if("function"===typeof f){a=(new f).segment(a);for(var {segment:k}of a){c+=g(k);if(c>e)break;n+=k.length}}else for(k=Array.from(a),a=k.length,f=0;f<a;f++){const p=k[f];c+=g(p);if(c>e)break;n+=p.length}return n}
8
- function C(a){const e=y.$createOverflowNode();a.insertBefore(e);e.append(a);return e}function D(a){const e=a.getChildren(),g=e.length;for(let f=0;f<g;f++)a.insertBefore(e[f]);a.remove();return 0<g?e[g-1]:null}
9
- function E(a){const e=a.getPreviousSibling();if(y.$isOverflowNode(e)){var g=a.getFirstChild(),f=e.getChildren(),n=f.length;if(null===g)a.append(...f);else for(var c=0;c<n;c++)g.insertBefore(f[c]);c=h.$getSelection();if(h.$isRangeSelection(c)){g=c.anchor;f=g.getNode();c=c.focus;const k=g.getNode();f.is(e)?g.set(a.getKey(),g.offset,"element"):f.is(a)&&g.set(a.getKey(),n+g.offset,"element");k.is(e)?c.set(a.getKey(),c.offset,"element"):k.is(a)&&c.set(a.getKey(),n+c.offset,"element")}e.remove()}}
7
+ var k=require("@lexical/react/withSubscriptions"),q=require("@lexical/text"),w=require("@lexical/utils"),x=require("lexical"),y=require("lexical/OverflowNode"),z=require("react");function B(a,d,f){var e=Intl.Segmenter;let m=0;var c=0;if("function"===typeof e){a=(new e).segment(a);for(var {segment:g}of a){c+=f(g);if(c>d)break;m+=g.length}}else for(g=Array.from(a),a=g.length,e=0;e<a;e++){const n=g[e];c+=f(n);if(c>d)break;m+=n.length}return m}
8
+ function C(a){const d=y.$createOverflowNode();a.insertBefore(d);d.append(a);return d}function D(a){const d=a.getChildren(),f=d.length;for(let e=0;e<f;e++)a.insertBefore(d[e]);a.remove();return 0<f?d[f-1]:null}
9
+ function E(a){const d=a.getPreviousSibling();if(y.$isOverflowNode(d)){var f=a.getFirstChild(),e=d.getChildren(),m=e.length;if(null===f)a.append(...e);else for(var c=0;c<m;c++)f.insertBefore(e[c]);c=x.$getSelection();if(x.$isRangeSelection(c)){f=c.anchor;e=f.getNode();c=c.focus;const g=f.getNode();e.is(d)?f.set(a.getKey(),f.offset,"element"):e.is(a)&&f.set(a.getKey(),m+f.offset,"element");g.is(d)?c.set(a.getKey(),c.offset,"element"):g.is(a)&&c.set(a.getKey(),m+c.offset,"element")}d.remove()}}
10
10
  exports.mergePrevious=E;
11
- exports.useCharacterLimit=function(a,e,g=Object.freeze({})){const {strlen:f=c=>c.length,remainingCharacters:n=()=>{}}=g;z.useEffect(()=>{if(!a.hasNodes([y.OverflowNode]))throw Error("Minified Lexical error #58; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[a]);z.useEffect(()=>{let c=a.getEditorState().read(A),k=0;return t(a.addListener("textcontent",p=>{c=p}),a.addListener("update",({dirtyLeaves:p})=>{var u=a.isComposing();
12
- p=0<p.size;if(!u&&p){u=f(c);p=u>e||null!==k&&k>e;n(e-u);if(null===k||p){const r=B(c,e,f);a.update(()=>{const v=[];for(var d=h.$getRoot().getLatest(),w=h.$isElementNode(d)?d.getLastDescendant():d;null!==d&&!d.is(w);)if(v.push(d),h.$isElementNode(d)&&0<d.getChildrenSize())d=d.getFirstChild();else for(var q=null;null===q&&null!==d;)q=d.getNextSibling(),d=null===q?d.getParent():q;null!==d&&d.is(w)&&v.push(d);w=v.length;d=0;for(q=0;q<w;q+=1){var b=v[q];if(y.$isOverflowNode(b)){var m=d;if(d+b.getTextContentSize()<=
13
- r){var l=b.getParent();m=b.getPreviousSibling();var x=b.getNextSibling();D(b);b=h.$getSelection();!h.$isRangeSelection(b)||b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()||(h.$isTextNode(m)?m.select():h.$isTextNode(x)?x.select():null!==l&&l.select())}else m<r&&(l=b.getFirstDescendant(),x=null!==l?l.getTextContentSize():0,m+=x,l=h.$isTextNode(l)&&l.isSimpleText(),m=m<=r,(l||m)&&D(b))}else h.$isLeafNode(b)&&(m=d,d+=b.getTextContentSize(),d>r&&!y.$isOverflowNode(b.getParent())&&(l=h.$getSelection(),
14
- m<r&&h.$isTextNode(b)&&b.isSimpleText()?([,b]=b.splitText(r-m),b=C(b)):b=C(b),null!==l&&h.$setSelection(l),E(b)))}},{tag:"history-merge"})}k=u}}))},[a,e,n,f])};
11
+ exports.useCharacterLimit=function(a,d,f=Object.freeze({})){const {strlen:e=c=>c.length,remainingCharacters:m=()=>{}}=f;z.useEffect(()=>{if(!a.hasNodes([y.OverflowNode]))throw Error("Minified Lexical error #58; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[a]);z.useEffect(()=>{let c=a.getEditorState().read(q.$rootTextContentCurry),g=0;return k(a.addListener("textcontent",n=>{c=n}),a.addListener("update",({dirtyLeaves:n})=>
12
+ {var r=a.isComposing();n=0<n.size;if(!r&&n){r=e(c);n=r>d||null!==g&&g>d;m(d-r);if(null===g||n){const p=B(c,d,e);a.update(()=>{const A=w.$dfs(),F=A.length;let t=0;for(let v=0;v<F;v+=1){var {node:b}=A[v];if(y.$isOverflowNode(b)){var l=t;if(t+b.getTextContentSize()<=p){var h=b.getParent();l=b.getPreviousSibling();var u=b.getNextSibling();D(b);b=x.$getSelection();!x.$isRangeSelection(b)||b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()||(x.$isTextNode(l)?l.select():x.$isTextNode(u)?u.select():
13
+ null!==h&&h.select())}else l<p&&(h=b.getFirstDescendant(),u=null!==h?h.getTextContentSize():0,l+=u,h=x.$isTextNode(h)&&h.isSimpleText(),l=l<=p,(h||l)&&D(b))}else x.$isLeafNode(b)&&(l=t,t+=b.getTextContentSize(),t>p&&!y.$isOverflowNode(b.getParent())&&(h=x.$getSelection(),l<p&&x.$isTextNode(b)&&b.isSimpleText()?([,b]=b.splitText(p-l),b=C(b)):b=C(b),null!==h&&x.$setSelection(h),E(b)))}},{tag:"history-merge"})}g=r}}))},[a,d,m,e])};
@@ -10,6 +10,7 @@ var withSubscriptions = require('@lexical/react/withSubscriptions');
10
10
  var lexical = require('lexical');
11
11
  var react = require('react');
12
12
  var clipboard = require('@lexical/clipboard');
13
+ var selection = require('@lexical/selection');
13
14
 
14
15
  /**
15
16
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -339,32 +340,6 @@ function useLexicalHistory(editor, externalHistoryState, delay = 1000) {
339
340
  return useHistory(editor, externalHistoryState, delay);
340
341
  }
341
342
 
342
- /**
343
- * Copyright (c) Meta Platforms, Inc. and affiliates.
344
- *
345
- * This source code is licensed under the MIT license found in the
346
- * LICENSE file in the root directory of this source tree.
347
- *
348
- *
349
- */
350
-
351
- function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity) {
352
- selection.modify(isHoldingShift ? 'extend' : 'move', isBackward, granularity);
353
- }
354
- function $isParentElementRTL(selection) {
355
- const anchorNode = selection.anchor.getNode();
356
- const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
357
- return parent.getDirection() === 'rtl';
358
- }
359
- function $moveCharacter(selection, isHoldingShift, isBackward) {
360
- const isRTL = $isParentElementRTL(selection);
361
- $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
362
- }
363
- function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
364
- const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
365
- return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
366
- }
367
-
368
343
  /**
369
344
  * Copyright (c) Meta Platforms, Inc. and affiliates.
370
345
  *
@@ -590,9 +565,9 @@ function useLexicalDragonSupport(editor) {
590
565
  function usePlainTextSetup(editor, initialEditorState) {
591
566
  useLayoutEffect(() => {
592
567
  const removeListener = editor.addListener('command', (type, payload) => {
593
- const selection = lexical.$getSelection();
568
+ const selection$1 = lexical.$getSelection();
594
569
 
595
- if (!lexical.$isRangeSelection(selection)) {
570
+ if (!lexical.$isRangeSelection(selection$1)) {
596
571
  return false;
597
572
  }
598
573
 
@@ -600,21 +575,21 @@ function usePlainTextSetup(editor, initialEditorState) {
600
575
  case 'deleteCharacter':
601
576
  {
602
577
  const isBackward = payload;
603
- selection.deleteCharacter(isBackward);
578
+ selection$1.deleteCharacter(isBackward);
604
579
  return true;
605
580
  }
606
581
 
607
582
  case 'deleteWord':
608
583
  {
609
584
  const isBackward = payload;
610
- selection.deleteWord(isBackward);
585
+ selection$1.deleteWord(isBackward);
611
586
  return true;
612
587
  }
613
588
 
614
589
  case 'deleteLine':
615
590
  {
616
591
  const isBackward = payload;
617
- selection.deleteLine(isBackward);
592
+ selection$1.deleteLine(isBackward);
618
593
  return true;
619
594
  }
620
595
 
@@ -623,17 +598,17 @@ function usePlainTextSetup(editor, initialEditorState) {
623
598
  const eventOrText = payload;
624
599
 
625
600
  if (typeof eventOrText === 'string') {
626
- selection.insertText(eventOrText);
601
+ selection$1.insertText(eventOrText);
627
602
  } else {
628
603
  const dataTransfer = eventOrText.dataTransfer;
629
604
 
630
605
  if (dataTransfer != null) {
631
- clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
606
+ clipboard.$insertDataTransferForPlainText(dataTransfer, selection$1);
632
607
  } else {
633
608
  const data = eventOrText.data;
634
609
 
635
610
  if (data) {
636
- selection.insertText(data);
611
+ selection$1.insertText(data);
637
612
  }
638
613
  }
639
614
  }
@@ -642,16 +617,16 @@ function usePlainTextSetup(editor, initialEditorState) {
642
617
  }
643
618
 
644
619
  case 'removeText':
645
- selection.removeText();
620
+ selection$1.removeText();
646
621
  return true;
647
622
 
648
623
  case 'insertLineBreak':
649
624
  const selectStart = payload;
650
- selection.insertLineBreak(selectStart);
625
+ selection$1.insertLineBreak(selectStart);
651
626
  return true;
652
627
 
653
628
  case 'insertParagraph':
654
- selection.insertLineBreak();
629
+ selection$1.insertLineBreak();
655
630
  return true;
656
631
 
657
632
  case 'indentContent':
@@ -670,9 +645,9 @@ function usePlainTextSetup(editor, initialEditorState) {
670
645
  const event = payload;
671
646
  const isHoldingShift = event.shiftKey;
672
647
 
673
- if ($shouldOverrideDefaultCharacterSelection(selection, true)) {
648
+ if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
674
649
  event.preventDefault();
675
- $moveCharacter(selection, isHoldingShift, true);
650
+ selection.$moveCharacter(selection$1, isHoldingShift, true);
676
651
  return true;
677
652
  }
678
653
 
@@ -684,9 +659,9 @@ function usePlainTextSetup(editor, initialEditorState) {
684
659
  const event = payload;
685
660
  const isHoldingShift = event.shiftKey;
686
661
 
687
- if ($shouldOverrideDefaultCharacterSelection(selection, false)) {
662
+ if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
688
663
  event.preventDefault();
689
- $moveCharacter(selection, isHoldingShift, false);
664
+ selection.$moveCharacter(selection$1, isHoldingShift, false);
690
665
  return true;
691
666
  }
692
667
 
@@ -4,18 +4,17 @@
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"),u=require("lexical"),v=require("react"),w=require("@lexical/clipboard");
8
- function x(a,d,f,b,c){if(null===a||0===f.size&&0===b.size)return 0;var e=d._selection,g=a._selection;if(c)return 1;if(!(u.$isRangeSelection(e)&&u.$isRangeSelection(g)&&g.isCollapsed()&&e.isCollapsed()))return 0;var h=Array.from(f);b=Array.from(b);f=d._nodeMap;c=[];for(var l=0;l<h.length;l++){const n=f.get(h[l]);void 0!==n&&c.push(n)}for(h=0;h<b.length;h++)b[h][1]&&(l=f.get(b[h][0]),void 0===l||u.$isRootNode(l)||c.push(l));if(0===c.length)return 0;if(1<c.length)return b=d._nodeMap,d=b.get(e.anchor.key),
7
+ var l=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react"),w=require("@lexical/clipboard"),x=require("@lexical/selection");
8
+ function y(a,d,f,b,c){if(null===a||0===f.size&&0===b.size)return 0;var e=d._selection,g=a._selection;if(c)return 1;if(!(u.$isRangeSelection(e)&&u.$isRangeSelection(g)&&g.isCollapsed()&&e.isCollapsed()))return 0;var h=Array.from(f);b=Array.from(b);f=d._nodeMap;c=[];for(var k=0;k<h.length;k++){const n=f.get(h[k]);void 0!==n&&c.push(n)}for(h=0;h<b.length;h++)b[h][1]&&(k=f.get(b[h][0]),void 0===k||u.$isRootNode(k)||c.push(k));if(0===c.length)return 0;if(1<c.length)return b=d._nodeMap,d=b.get(e.anchor.key),
9
9
  g=b.get(g.anchor.key),d&&g&&!a._nodeMap.has(d.__key)&&u.$isTextNode(d)&&1===d.__text.length&&1===e.anchor.offset?2:0;d=c[0];a=a._nodeMap.get(d.__key);if(!u.$isTextNode(a)||!u.$isTextNode(d)||a.__mode!==d.__mode)return 0;a=a.__text;d=d.__text;if(a===d)return 0;e=e.anchor;g=g.anchor;if(e.key!==g.key||"text"!==e.type)return 0;e=e.offset;g=g.offset;a=d.length-a.length;return 1===a&&g===e-1?2:-1===a&&g===e+1?3:-1===a&&g===e?4:0}
10
- function y(a,d){let f=Date.now(),b=0;return(c,e,g,h,l,n)=>{const t=Date.now();if(n.has("historic"))return b=0,f=t,2;const m=x(c,e,h,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=e._selection;const D=c._selection;if(!(0<h.size||0<l.size))return null===D&&null!==p?0:2;p=null===g||g.editor===a;return!1===q&&0!==m&&m===b&&t<f+d&&p?0:1})();f=t;b=m;return r}}
11
- function z(a,d,f=1E3){const b=v.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),c=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const e=y(a,f);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:t})=>{const m=b.current,r=b.redoStack,q=b.undoStack,
13
- p=null===m?null:m.editorState;if(null===m||g!==p){l=e(h,g,m,l,n,t);if(1===l)0!==r.length&&(b.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;b.current={editor:a,editorState:g}}}))},[c,f,a,b])}function A(a,d,f=1E3){return z(a,d,f)}function B(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
14
- function C(a,d){a=u.$getDecoratorNode(a.focus,d);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,d){a.preventDefault();d.update(()=>{const f=u.$getSelection(),b=a.clipboardData;null!=b&&u.$isRangeSelection(f)&&w.$insertDataTransferForPlainText(b,f)})}
15
- function G(a,d){H(a,d);d.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}function H(a,d){a.preventDefault();d.update(()=>{const f=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=f){const c=w.getHtmlContent(d);null!==c&&f.setData("text/html",c);f.setData("text/plain",b.getTextContent())}})}const I={tag:"history-merge"};
16
- function J(a,d){if(null!==d)if(void 0===d)a.update(()=>{var f=u.$getRoot();if(null===f.getFirstChild()){const b=u.$createParagraphNode();f.append(b);f=document.activeElement;(null!==u.$getSelection()||null!==f&&f===a.getRootElement())&&b.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)}}
17
- function K(a){v.useEffect(()=>{const d=f=>{var b=a.getRootElement();if(document.activeElement===b&&(b=f.data,"string"===typeof b)){try{var c=JSON.parse(b)}catch(e){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [e,g,h,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<=e&&0<=g&&(q=e,p=e+g,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
18
- h)t.insertRawText(h),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",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
19
- function L(a,d){E(()=>{const f=a.addListener("command",(b,c)=>{const e=u.$getSelection();if(!u.$isRangeSelection(e))return!1;switch(b){case "deleteCharacter":return e.deleteCharacter(c),!0;case "deleteWord":return e.deleteWord(c),!0;case "deleteLine":return e.deleteLine(c),!0;case "insertText":return"string"===typeof c?e.insertText(c):(b=c.dataTransfer,null!=b?w.$insertDataTransferForPlainText(b,e):(c=c.data)&&e.insertText(c)),!0;case "removeText":return e.removeText(),!0;case "insertLineBreak":return e.insertLineBreak(c),
20
- !0;case "insertParagraph":return e.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b=c.shiftKey;if(C(e,!0))return c.preventDefault(),c=b,b=B(e),e.modify(c?"extend":"move",!b,"character"),!0;break;case "keyArrowRight":b=c.shiftKey;if(C(e,!1))return c.preventDefault(),c=b,b=B(e),e.modify(c?"extend":"move",b,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
21
- a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(c,a),!0;case "cut":return G(c,a),!0;case "paste":return F(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);J(a,d);return f},[a]);K(a)}module.exports=function(a,d,f){L(a,f);A(a,d)};
10
+ function z(a,d){let f=Date.now(),b=0;return(c,e,g,h,k,n)=>{const t=Date.now();if(n.has("historic"))return b=0,f=t,2;const m=y(c,e,h,k,a.isComposing()),r=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===c)return 1;var p=e._selection;const C=c._selection;if(!(0<h.size||0<k.size))return null===C&&null!==p?0:2;p=null===g||g.editor===a;return!1===q&&0!==m&&m===b&&t<f+d&&p?0:1})();f=t;b=m;return r}}
11
+ function A(a,d,f=1E3){const b=v.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),c=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const e=z(a,f);return l(a.addListener("command",g=>{switch(g){case "undo":g=b.redoStack;var h=b.undoStack;if(0!==h.length){var k=b.current;const n=h.pop();null!==k&&(g.push(k),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&&(k=b.current,null!==k&&(h.push(k),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:k,dirtyElements:n,tags:t})=>{const m=b.current,r=b.redoStack,q=b.undoStack,
13
+ p=null===m?null:m.editorState;if(null===m||g!==p){k=e(h,g,m,k,n,t);if(1===k)0!==r.length&&(b.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;b.current={editor:a,editorState:g}}}))},[c,f,a,b])}function B(a,d,f=1E3){return A(a,d,f)}var D="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;
14
+ function E(a,d){a.preventDefault();d.update(()=>{const f=u.$getSelection(),b=a.clipboardData;null!=b&&u.$isRangeSelection(f)&&w.$insertDataTransferForPlainText(b,f)})}function F(a,d){G(a,d);d.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}function G(a,d){a.preventDefault();d.update(()=>{const f=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=f){const c=w.getHtmlContent(d);null!==c&&f.setData("text/html",c);f.setData("text/plain",b.getTextContent())}})}
15
+ const H={tag:"history-merge"};function I(a,d){if(null!==d)if(void 0===d)a.update(()=>{var f=u.$getRoot();if(null===f.getFirstChild()){const b=u.$createParagraphNode();f.append(b);f=document.activeElement;(null!==u.$getSelection()||null!==f&&f===a.getRootElement())&&b.select()}},H);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,H);break;case "object":a.setEditorState(d,H);break;case "function":a.update(d,H)}}
16
+ function J(a){v.useEffect(()=>{const d=f=>{var b=a.getRootElement();if(document.activeElement===b&&(b=f.data,"string"===typeof b)){try{var c=JSON.parse(b)}catch(e){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [e,g,h,k,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<=e&&0<=g&&(q=e,p=e+g,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
17
+ h)t.insertRawText(h),r=m.getNode();u.$isTextNode(r)&&(q=k,p=k+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",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
18
+ function K(a,d){D(()=>{const f=a.addListener("command",(b,c)=>{const e=u.$getSelection();if(!u.$isRangeSelection(e))return!1;switch(b){case "deleteCharacter":return e.deleteCharacter(c),!0;case "deleteWord":return e.deleteWord(c),!0;case "deleteLine":return e.deleteLine(c),!0;case "insertText":return"string"===typeof c?e.insertText(c):(b=c.dataTransfer,null!=b?w.$insertDataTransferForPlainText(b,e):(c=c.data)&&e.insertText(c)),!0;case "removeText":return e.removeText(),!0;case "insertLineBreak":return e.insertLineBreak(c),
19
+ !0;case "insertParagraph":return e.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b=c.shiftKey;if(x.$shouldOverrideDefaultCharacterSelection(e,!0))return c.preventDefault(),x.$moveCharacter(e,b,!0),!0;break;case "keyArrowRight":b=c.shiftKey;if(x.$shouldOverrideDefaultCharacterSelection(e,!1))return c.preventDefault(),x.$moveCharacter(e,b,!1),!0;break;
20
+ case "keyBackspace":return c.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "copy":return G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return E(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);I(a,d);return f},[a]);J(a)}module.exports=function(a,d,f){K(a,f);B(a,d)};