@lexical/react 0.1.8 → 0.1.11

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 (91) hide show
  1. package/DEPRECATED_useLexical.dev.js +3 -38
  2. package/DEPRECATED_useLexical.prod.js +1 -2
  3. package/DEPRECATED_useLexicalAutoFormatter.dev.js +202 -74
  4. package/DEPRECATED_useLexicalAutoFormatter.prod.js +21 -16
  5. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
  6. package/DEPRECATED_useLexicalCharacterLimit.dev.js +23 -21
  7. package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
  8. package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
  9. package/DEPRECATED_useLexicalEditor.dev.js +1 -25
  10. package/DEPRECATED_useLexicalEditor.prod.js +1 -1
  11. package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
  12. package/DEPRECATED_useLexicalHistory.dev.js +18 -15
  13. package/DEPRECATED_useLexicalHistory.prod.js +7 -7
  14. package/DEPRECATED_useLexicalList.dev.js +6 -0
  15. package/DEPRECATED_useLexicalList.prod.js +1 -1
  16. package/DEPRECATED_useLexicalPlainText.dev.js +79 -70
  17. package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
  18. package/DEPRECATED_useLexicalRichText.dev.js +124 -250
  19. package/DEPRECATED_useLexicalRichText.prod.js +25 -29
  20. package/LexicalAutoFormatterPlugin.dev.js +202 -74
  21. package/LexicalAutoFormatterPlugin.js.flow +10 -0
  22. package/LexicalAutoFormatterPlugin.prod.js +21 -17
  23. package/LexicalAutoLinkPlugin.js.flow +23 -0
  24. package/LexicalAutoLinkPlugin.prod.js +4 -4
  25. package/LexicalCharacterLimitPlugin.dev.js +23 -21
  26. package/LexicalCharacterLimitPlugin.js.flow +12 -0
  27. package/LexicalCharacterLimitPlugin.prod.js +9 -8
  28. package/LexicalClearEditorPlugin.dev.js +52 -0
  29. package/LexicalClearEditorPlugin.js +9 -0
  30. package/LexicalClearEditorPlugin.js.flow +14 -0
  31. package/LexicalClearEditorPlugin.prod.js +7 -0
  32. package/LexicalCollaborationPlugin.dev.js +31 -36
  33. package/LexicalCollaborationPlugin.js.flow +55 -0
  34. package/LexicalCollaborationPlugin.prod.js +7 -8
  35. package/LexicalComposer.dev.js +8 -6
  36. package/LexicalComposer.js.flow +23 -0
  37. package/LexicalComposer.prod.js +3 -3
  38. package/LexicalComposerContext.js.flow +27 -0
  39. package/LexicalComposerContext.prod.js +1 -1
  40. package/LexicalContentEditable.dev.js +14 -8
  41. package/LexicalContentEditable.js.flow +35 -0
  42. package/LexicalContentEditable.prod.js +3 -3
  43. package/LexicalHashtagPlugin.js.flow +20 -0
  44. package/LexicalHashtagPlugin.prod.js +1 -1
  45. package/LexicalHistoryPlugin.dev.js +18 -15
  46. package/LexicalHistoryPlugin.js.flow +34 -0
  47. package/LexicalHistoryPlugin.prod.js +7 -7
  48. package/LexicalHorizontalRuleNode.dev.js +66 -0
  49. package/LexicalHorizontalRuleNode.js +9 -0
  50. package/LexicalHorizontalRuleNode.js.flow +25 -0
  51. package/LexicalHorizontalRuleNode.prod.js +8 -0
  52. package/LexicalLinkPlugin.dev.js +0 -1
  53. package/LexicalLinkPlugin.js.flow +10 -0
  54. package/LexicalLinkPlugin.prod.js +3 -3
  55. package/LexicalListPlugin.dev.js +6 -0
  56. package/LexicalListPlugin.js.flow +10 -0
  57. package/LexicalListPlugin.prod.js +2 -2
  58. package/LexicalNestedComposer.js.flow +21 -0
  59. package/LexicalNestedComposer.prod.js +1 -1
  60. package/LexicalOnChangePlugin.js.flow +14 -0
  61. package/LexicalOnChangePlugin.prod.js +1 -1
  62. package/LexicalPlainTextPlugin.dev.js +72 -44
  63. package/LexicalPlainTextPlugin.js.flow +18 -0
  64. package/LexicalPlainTextPlugin.prod.js +12 -11
  65. package/LexicalRichTextPlugin.dev.js +115 -222
  66. package/LexicalRichTextPlugin.js.flow +18 -0
  67. package/LexicalRichTextPlugin.prod.js +21 -25
  68. package/LexicalTablePlugin.dev.js +43 -39
  69. package/LexicalTablePlugin.js.flow +10 -0
  70. package/LexicalTablePlugin.prod.js +4 -3
  71. package/LexicalTreeView.dev.js +10 -2
  72. package/LexicalTreeView.js.flow +19 -0
  73. package/LexicalTreeView.prod.js +9 -8
  74. package/README.md +0 -1
  75. package/package.json +5 -4
  76. package/useLexicalDecoratorMap.js.flow +16 -0
  77. package/useLexicalDecoratorMap.prod.js +1 -1
  78. package/useLexicalIsTextContentEmpty.js.flow +15 -0
  79. package/useLexicalIsTextContentEmpty.prod.js +1 -1
  80. package/useLexicalNodeSelection.dev.js +70 -0
  81. package/useLexicalNodeSelection.js +9 -0
  82. package/useLexicalNodeSelection.js.flow +14 -0
  83. package/useLexicalNodeSelection.prod.js +8 -0
  84. package/withSubscriptions.js.flow +13 -0
  85. package/withSubscriptions.prod.js +1 -1
  86. package/LexicalBootstrapPlugin.dev.js +0 -124
  87. package/LexicalBootstrapPlugin.js +0 -9
  88. package/LexicalBootstrapPlugin.prod.js +0 -8
  89. package/LexicalHorizontalRulePlugin.dev.js +0 -51
  90. package/LexicalHorizontalRulePlugin.js +0 -9
  91. package/LexicalHorizontalRulePlugin.prod.js +0 -7
@@ -4,19 +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
- 'use strict';var n=require("@lexical/list"),p=require("lexical"),r=require("lexical/CodeNode"),v=require("react"),x=require("lexical/HeadingNode"),y=require("lexical/QuoteNode");function z(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 A(g,k,b,a){g=g.getChildren();const d=g.length;let e=0;for(let h=0;h<d&&!(e>=k);++h){const f=g[h];var c=p.$isTextNode(f)?f.getTextContent().length:a;c=e+c;if(e<=b&&b<c&&p.$isTextNode(f))return{node:f,offset:b-e};e=c}return null}
9
- const B={nodeTransformationKind:null,regEx:/(?:)/,regExCaptureGroupsToDelete:null,regExExpectedCaptureGroupCount:1,requiresParagraphStart:!1},C={...B,requiresParagraphStart:!0},D=[{...B,nodeTransformationKind:"textBold",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/,regExCaptureGroupsToDelete:[1,5],regExExpectedCaptureGroupCount:6}],F=[{...C,nodeTransformationKind:"paragraphH1",regEx:/(?:# )/},{...C,nodeTransformationKind:"paragraphH2",regEx:/(?:## )/},{...C,nodeTransformationKind:"paragraphH2",regEx:/(?:### )/},
10
- {...C,nodeTransformationKind:"paragraphBlockQuote",regEx:/(?:> )/},{...C,nodeTransformationKind:"paragraphUnorderedList",regEx:/(?:- )/},{...C,nodeTransformationKind:"paragraphUnorderedList",regEx:/(?:\* )/},{...C,nodeTransformationKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/,regExExpectedCaptureGroupCount:2},{...C,nodeTransformationKind:"paragraphCodeBlock",regEx:/(?:``` )/},...D];
11
- function G(g,k,b,a,d){const e={regExCaptureGroups:[],triggerState:null};a=g.match(a);if(null!==a&&0<a.length&&a.length===d&&(!1===k||0===a.index)&&(!1===b||a.index+a[0].length===g.length)){g=a.length;k=a.index;for(b=0;b<g;b++)d=a[b],e.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:k,text:d,textLength:d.length-(b+1===g?1:0)}),0<b&&(k+=d.length);return e}return null}
12
- function H(g,k,b,a,d){d=d.regExCaptureGroups;const e=d.length;for(a+=1;a<e;a++){const c=d[a];null!=c.anchorTextNodeWithOffset&&c.anchorTextNodeWithOffset.offset>=k&&c.anchorTextNodeWithOffset.node.is(b)&&(c.anchorTextNodeWithOffset.offset+=g);null!=c.focusTextNodeWithOffset&&c.focusTextNodeWithOffset.offset>=k&&c.focusTextNodeWithOffset.node.is(b)&&(c.focusTextNodeWithOffset.offset+=g)}}
13
- function I(g,k){g.update(()=>{var b=p.$getSelection();if(null==b)b=null;else{var a=b.anchor.getNode();b=p.$isTextNode(a)?{node:a,offset:b.anchor.offset}:null}if(null!==b){b={joinedText:null,textNodeWithOffset:b};a:{a=!1===k.isParentAListItemNode?F:D;var d=a.length;for(var e=0;e<d;e++){var c=a[e];if(!1===k.isCodeBlock||"paragraphCodeBlock"===c.nodeTransformationKind){var h=c,f=b;if(null!==h.requiresParagraphStart&&!0===h.requiresParagraphStart)null===f.textNodeWithOffset.node.getPreviousSibling()?
14
- (f=f.textNodeWithOffset.node.getTextContent(),h=G(f,!0,!1,h.regEx,h.regExExpectedCaptureGroupCount)):h=null;else b:{if(null==f.joinedText){var q=f.textNodeWithOffset.node.getParentOrThrow();if(p.$isElementNode(q)){if(null==f.joinedText){var l=f,m=f.textNodeWithOffset;let u="";q=q.getChildren();const J=q.length;for(let w=0;w<J;++w){const t=q[w];if(p.$isTextNode(t)){const E=t.getTextContent();if(t.is(m.node)){m.offset>E.length&&z(50,t.__key);u+=t.getTextContent().substr(0,m.offset);break}else u+=E}else u+=
15
- "\u0004"}l.joinedText=u}h=G(f.joinedText,!1,!0,h.regEx,h.regExExpectedCaptureGroupCount);break b}z(52,q.__key)}h=null}if(null!=h){h.triggerState=k;a={autoFormatCriteria:c,matchResultContext:h};break a}}}a={autoFormatCriteria:null,matchResultContext:null}}if(null!==a.autoFormatCriteria&&null!==a.matchResultContext)if(d=a.autoFormatCriteria,a=a.matchResultContext,d.requiresParagraphStart){e=b.textNodeWithOffset;b=e.node.getParentOrThrow();e=e.node.spliceText(0,a.regExCaptureGroups[0].text.length,"",
16
- !0);""===e.getTextContent()&&(e.selectPrevious(),e.remove());e=b.getChildren();c=null;if(null!=d.nodeTransformationKind)switch(d.nodeTransformationKind){case "paragraphH1":c=x.$createHeadingNode("h1");c.append(...e);break;case "paragraphH2":c=x.$createHeadingNode("h2");c.append(...e);break;case "paragraphH3":c=x.$createHeadingNode("h3");c.append(...e);break;case "paragraphBlockQuote":c=y.$createQuoteNode();c.append(...e);break;case "paragraphUnorderedList":c=n.$createListNode("ul");a=n.$createListItemNode();
17
- a.append(...e);c.append(a);break;case "paragraphOrderedList":a=parseInt(1<a.regExCaptureGroups.length?a.regExCaptureGroups[a.regExCaptureGroups.length-1].text:"1",10);c=n.$createListNode("ol",a);a=n.$createListItemNode();a.append(...e);c.append(a);break;case "paragraphCodeBlock":c=null!=a.triggerState&&a.triggerState.isCodeBlock?p.$createParagraphNode():r.$createCodeNode(),c.append(...e)}a=c;null!==a&&b.replace(a)}else if(null!=d.nodeTransformationKind)switch(d.nodeTransformationKind){case "textBold":e=
18
- a.regExCaptureGroups;c=e.length;h=b.textNodeWithOffset.node.getParentOrThrow();if(null==b.joinedText)throw Error("joinedText was not calculated");b=b.joinedText.length;for(f=1;f<c;f++)if(l=e[f],l.anchorTextNodeWithOffset=A(h,b,l.offsetInParent,1),l.focusTextNodeWithOffset=A(h,b,l.offsetInParent+l.textLength,1),0>l.textLength)throw Error(`Bad regEx pattern found for ${d.nodeTransformationKind}`);a.regExCaptureGroups=e;if(null!=d.regExCaptureGroupsToDelete){b=d.regExCaptureGroupsToDelete;d=a.regExCaptureGroups;
19
- e=d.length;for(c=b.length-1;0<=c;c--)if(c<e&&(h=b[c],m=d[h],l=m.anchorTextNodeWithOffset,f=m.focusTextNodeWithOffset,null!=l&&null!=f&&0<m.textLength&&(m=p.$createRangeSelection(),m.anchor.set(l.node.getKey(),l.offset,"text"),m.focus.set(f.node.getKey(),f.offset,"text"),p.$setSelection(m),m=p.$getSelection(),null!=m)))if(m.removeText(),l.node.getKey()===f.node.getKey()){m=f.offset-l.offset;if(!(0<m))throw Error("Expected anchor and focus offsets to have ascending character order.");H(-m,f.offset,
20
- l.node,h,a)}else l=f.offset,0<l&&H(-l,l,f.node,h,a);b=a.regExCaptureGroups;if(!(3<b.length))throw Error("The capture group count in the RegEx does match the actual capture group count.");d=b[3];b=d.anchorTextNodeWithOffset;a=d.focusTextNodeWithOffset;null!=b&&null!=a&&0<d.textLength&&(d=p.$createRangeSelection(),d.anchor.set(b.node.getKey(),b.offset,"text"),d.focus.set(a.node.getKey(),a.offset,"text"),p.$setSelection(d),b=p.$getSelection(),null!=b&&b.formatText("bold"))}}}})}
21
- function K(g){let k=null;g.read(()=>{const b=p.$getSelection();if(null!=b&&b.isCollapsed()){var a=b.anchor.getNode(),d=a.getParent(),e=null!==d&&n.$isListItemNode(d);k={anchorOffset:b.anchor.offset,hasParentNode:null!==d,isCodeBlock:r.$isCodeNode(a),isParentAListItemNode:e,isSelectionCollapsed:b.isCollapsed(),isSimpleText:p.$isTextNode(a)&&a.isSimpleText(),nodeKey:a.getKey(),textContent:a.getTextContent()}}});return k}
22
- function L(g){v.useEffect(()=>{let k=null;g.addListener("update",({tags:b})=>{if(!1===b.has("historic")){b=K(g.getEditorState());var a=b;var d=k;if(null==a||null==d)a=!1;else{var e=a.textContent.length,c=a.anchorOffset-1;a=!0===a.hasParentNode&&a.isSimpleText&&a.isSelectionCollapsed&&a.nodeKey===d.nodeKey&&a.anchorOffset!==d.anchorOffset&&0<=c&&c+1<=e&&" "===a.textContent.substr(c,1)&&a.textContent!==d.textContent}a&&null!=b&&I(g,b);k=b}else k=null})},[g])}module.exports=function(g){L(g)};
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,b){g=g.getChildren();const c=g.length;let d=0,e=!1;for(let p=0;p<c&&!(d>f);++p){const m=g[p],n=q.$isTextNode(m);var h=n?m.getTextContent().length:b;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:/(?:``` )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/(?:\*\*\* )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/(?:--- )/},...H];
12
+ 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}
13
+ 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)}}
14
+ 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,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");c=k.$createListItemNode();c.append(...d);a.append(c);break;case "paragraphOrderedList":a=parseInt(1<h.regExCaptureGroups.length?h.regExCaptureGroups[h.regExCaptureGroups.length-1].text:"1",10);a=k.$createListNode("ol",a);c=k.$createListItemNode();c.append(...d);
16
+ a.append(c);break;case "paragraphCodeBlock":a=null!=f.triggerState&&f.triggerState.isCodeBlock?q.$createParagraphNode():r.$createCodeNode();a.append(...d);break;case "horizontalRule":d=u.$createHorizontalRuleNode(),c.insertBefore(d)}null!==a&&b.replace(a)}else if(a=f.autoFormatCriteria,b=f.matchResultContext,null!=a.nodeTransformationKind&&6===b.regExCaptureGroups.length){a:{a=a.nodeTransformationKind;switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=
17
+ ["bold","italic"];break a}a=null}if(null!=a){d=[1,5];c=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&&C(63,c.nodeTransformationKind)}b.regExCaptureGroups=e;if(0<d.length)for(c=b.regExCaptureGroups,e=c.length,
18
+ h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=c[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),K(-l,m.offset,n.node,p,b)):(n=m.offset,0<n&&K(-n,n,m.node,p,b)))));d=b.regExCaptureGroups;3<d.length||C(65);
19
+ e=d[3];c=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=c&&null!=d&&0<e.textLength&&(e=q.$createRangeSelection(),e.anchor.set(c.node.getKey(),c.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),q.$setSelection(e),c=q.$getSelection(),q.$isRangeSelection(c))){for(e=0;e<a.length;e++)c.formatText(a[e]);a=q.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");q.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();
20
+ b=D(a,b.offsetInJoinedTextForCollapsedSelection+1,b.offsetInJoinedTextForCollapsedSelection,1);null!=b&&(a=q.$createRangeSelection(),a.anchor.set(b.node.getKey(),b.offset,"text"),a.focus.set(b.node.getKey(),b.offset,"text"),q.$setSelection(a))}}},{tag:"history-push"})}
21
+ 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 n=b.triggerState,
22
+ l=c.length;for(let z=0;z<l;z++){const A=c[z];if(null!=n&&!1===n.isCodeBlock||"paragraphCodeBlock"===A.nodeTransformationKind){var d=A,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{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){c={autoFormatCriteria:A,matchResultContext:d};break a}}}c={autoFormatCriteria:null,matchResultContext:null}}null!==c.autoFormatCriteria&&null!==c.matchResultContext&&(a=b,a.autoFormatCriteria=
24
+ c.autoFormatCriteria,a.matchResultContext=c.matchResultContext)}});return a}
25
+ function O(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&&k.$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}
26
+ function P(g){t.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var b=g.getEditorState();a=O(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,h=c.anchorOffset-1;b=!1===(!0===c.hasParentNode&&c.isSimpleText&&c.isSelectionCollapsed&&c.nodeKey===d.nodeKey&&c.anchorOffset!==d.anchorOffset&&0<=h&&h+1<=e&&" "===c.textContent.substr(h,1)&&c.textContent!==d.textContent)?null:M(b,c)}}null!=b&&L(g,b);f=a}else f=
27
+ null})},[g])}module.exports=function(g){P(g)};
@@ -4,5 +4,5 @@
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
- 'use strict';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)}
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
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)};
@@ -19,11 +19,15 @@ var react = require('react');
19
19
  *
20
20
  *
21
21
  */
22
- function $dfs__DEPRECATED(startingNode, nextNode) {
23
- let node = startingNode;
24
- nextNode(node);
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);
25
30
 
26
- while (node !== null) {
27
31
  if (lexical.$isElementNode(node) && node.getChildrenSize() > 0) {
28
32
  node = node.getFirstChild();
29
33
  } else {
@@ -40,11 +44,13 @@ function $dfs__DEPRECATED(startingNode, nextNode) {
40
44
  }
41
45
  }
42
46
  }
47
+ }
43
48
 
44
- if (node !== null) {
45
- node = nextNode(node);
46
- }
49
+ if (node !== null && node.is(end)) {
50
+ nodes.push(node);
47
51
  }
52
+
53
+ return nodes;
48
54
  }
49
55
 
50
56
  /**
@@ -105,10 +111,9 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
105
111
  if (lastComputedTextLength === null || textLengthAboveThreshold) {
106
112
  const offset = findOffset(text, maxCharacters, strlen);
107
113
  editor.update(() => {
108
- lexical.$log('CharacterLimit');
109
114
  $wrapOverflowedNodes(offset);
110
115
  }, {
111
- tag: 'without-history'
116
+ tag: 'history-merge'
112
117
  });
113
118
  }
114
119
 
@@ -159,10 +164,13 @@ function findOffset(text, maxCharacters, strlen) {
159
164
  }
160
165
 
161
166
  function $wrapOverflowedNodes(offset) {
162
- const root = lexical.$getRoot();
167
+ const dfsNodes = $dfs();
168
+ const dfsNodesLength = dfsNodes.length;
163
169
  let accumulatedLength = 0;
164
- let previousNode = root;
165
- $dfs__DEPRECATED(root, node => {
170
+
171
+ for (let i = 0; i < dfsNodesLength; i += 1) {
172
+ const node = dfsNodes[i];
173
+
166
174
  if (OverflowNode.$isOverflowNode(node)) {
167
175
  const previousLength = accumulatedLength;
168
176
  const nextLength = accumulatedLength + node.getTextContentSize();
@@ -174,7 +182,7 @@ function $wrapOverflowedNodes(offset) {
174
182
  $unwrapNode(node);
175
183
  const selection = lexical.$getSelection(); // Restore selection when the overflow children are removed
176
184
 
177
- if (selection !== null && (!selection.anchor.getNode().isAttached() || !selection.focus.getNode().isAttached())) {
185
+ if (lexical.$isRangeSelection(selection) && (!selection.anchor.getNode().isAttached() || !selection.focus.getNode().isAttached())) {
178
186
  if (lexical.$isTextNode(previousSibling)) {
179
187
  previousSibling.select();
180
188
  } else if (lexical.$isTextNode(nextSibling)) {
@@ -183,8 +191,6 @@ function $wrapOverflowedNodes(offset) {
183
191
  parent.select();
184
192
  }
185
193
  }
186
-
187
- return previousNode;
188
194
  } else if (previousLength < offset) {
189
195
  const descendant = node.getFirstDescendant();
190
196
  const descendantLength = descendant !== null ? descendant.getTextContentSize() : 0;
@@ -196,7 +202,6 @@ function $wrapOverflowedNodes(offset) {
196
202
 
197
203
  if (firstDescendantIsSimpleText || firstDescendantDoesNotOverflow) {
198
204
  $unwrapNode(node);
199
- return previousNode;
200
205
  }
201
206
  }
202
207
  } else if (lexical.$isLeafNode(node)) {
@@ -222,10 +227,7 @@ function $wrapOverflowedNodes(offset) {
222
227
  mergePrevious(overflowNode);
223
228
  }
224
229
  }
225
-
226
- previousNode = node;
227
- return node;
228
- });
230
+ }
229
231
  }
230
232
 
231
233
  function $wrapNode(node) {
@@ -268,7 +270,7 @@ function mergePrevious(overflowNode) {
268
270
 
269
271
  const selection = lexical.$getSelection();
270
272
 
271
- if (selection !== null) {
273
+ if (lexical.$isRangeSelection(selection)) {
272
274
  const anchor = selection.anchor;
273
275
  const anchorNode = anchor.getNode();
274
276
  const focus = selection.focus;
@@ -4,11 +4,11 @@
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
- 'use strict';var k=require("lexical"),l=require("@lexical/react/withSubscriptions"),n=require("lexical/OverflowNode"),p=require("react");function q(a,e){for(e(a);null!==a;){if(k.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild();else{let d=null;for(;null===d&&null!==a;)d=a.getNextSibling(),a=null===d?a.getParent():d}null!==a&&(a=e(a))}}function r(){return k.$getRoot().getTextContent()}
8
- function t(a,e,d){var g=Intl.Segmenter;let c=0;var b=0;if("function"===typeof g){a=(new g).segment(a);for(var {segment:f}of a){b+=d(f);if(b>e)break;c+=f.length}}else for(f=Array.from(a),a=f.length,g=0;g<a;g++){const h=f[g];b+=d(h);if(b>e)break;c+=h.length}return c}
9
- function u(a){const e=k.$getRoot();let d=0,g=e;q(e,c=>{if(n.$isOverflowNode(c)){var b=d;if(d+c.getTextContentSize()<=a){var f=c.getParent();b=c.getPreviousSibling();var h=c.getNextSibling();v(c);c=k.$getSelection();null===c||c.anchor.getNode().isAttached()&&c.focus.getNode().isAttached()||(k.$isTextNode(b)?b.select():k.$isTextNode(h)?h.select():null!==f&&f.select());return g}if(b<a&&(f=c.getFirstDescendant(),h=null!==f?f.getTextContentSize():0,b+=h,f=k.$isTextNode(f)&&f.isSimpleText(),b=b<=a,f||b))return v(c),
10
- g}else k.$isLeafNode(c)&&(b=d,d+=c.getTextContentSize(),d>a&&!n.$isOverflowNode(c.getParent())&&(f=k.$getSelection(),b<a&&k.$isTextNode(c)&&c.isSimpleText()?([,b]=c.splitText(a-b),b=w(b)):b=w(c),null!==f&&k.$setSelection(f),x(b)));return g=c})}function w(a){const e=n.$createOverflowNode();a.insertBefore(e);e.append(a);return e}function v(a){const e=a.getChildren(),d=e.length;for(let g=0;g<d;g++)a.insertBefore(e[g]);a.remove();return 0<d?e[d-1]:null}
11
- function x(a){const e=a.getPreviousSibling();if(n.$isOverflowNode(e)){var d=a.getFirstChild(),g=e.getChildren(),c=g.length;if(null===d)a.append(...g);else for(var b=0;b<c;b++)d.insertBefore(g[b]);b=k.$getSelection();if(null!==b){d=b.anchor;g=d.getNode();b=b.focus;const f=d.getNode();g.is(e)?d.set(a.getKey(),d.offset,"element"):g.is(a)&&d.set(a.getKey(),c+d.offset,"element");f.is(e)?b.set(a.getKey(),b.offset,"element"):f.is(a)&&b.set(a.getKey(),c+b.offset,"element")}e.remove()}}
12
- exports.mergePrevious=x;
13
- exports.useCharacterLimit=function(a,e,d=Object.freeze({})){const {strlen:g=b=>b.length,remainingCharacters:c=()=>{}}=d;p.useEffect(()=>{if(!a.hasNodes([n.OverflowNode]))throw Error("useCharacterLimit: OverflowNode not registered on editor");},[a]);p.useEffect(()=>{let b=a.getEditorState().read(r),f=0;return l(a.addListener("textcontent",h=>{b=h}),a.addListener("update",({dirtyLeaves:h})=>{var m=a.isComposing();h=0<h.size;if(!m&&h){m=g(b);h=m>e||null!==f&&f>e;c(e-m);if(null===f||h){const y=t(b,e,
14
- g);a.update(()=>{k.$log("CharacterLimit");u(y)},{tag:"without-history"})}f=m}}))},[a,e,c,g])};
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()}}
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])};
@@ -4,5 +4,5 @@
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
- 'use strict';var c=require("react"),g=require("react-dom"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?c.useLayoutEffect:c.useEffect;
7
+ var c=require("react"),g=require("react-dom"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?c.useLayoutEffect:c.useEffect;
8
8
  function l(a){const [e,m]=c.useState(()=>a.getDecorators());k(()=>a.addListener("decorator",d=>{g.flushSync(()=>{m(d)})}),[a]);return c.useMemo(()=>{const d=[],h=Object.keys(e);for(let f=0;f<h.length;f++){var b=h[f];const n=e[b];b=a.getElementByKey(b);null!==b&&d.push(g.createPortal(n,b))}return d},[e,a])}module.exports=function(a){return l(a)};
@@ -17,35 +17,11 @@ var react = require('react');
17
17
  *
18
18
  *
19
19
  */
20
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
21
-
22
- /**
23
- * Copyright (c) Meta Platforms, Inc. and affiliates.
24
- *
25
- * This source code is licensed under the MIT license found in the
26
- * LICENSE file in the root directory of this source tree.
27
- *
28
- *
29
- */
30
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
31
- var useLayoutEffect = useLayoutEffectImpl;
32
-
33
- /**
34
- * Copyright (c) Meta Platforms, Inc. and affiliates.
35
- *
36
- * This source code is licensed under the MIT license found in the
37
- * LICENSE file in the root directory of this source tree.
38
- *
39
- *
40
- */
41
- function useLexicalEditor(editor, onError) {
20
+ function useLexicalEditor(editor) {
42
21
  const showPlaceholder = useLexicalCanShowPlaceholder(editor);
43
22
  const rootElementRef = react.useCallback(rootElement => {
44
23
  editor.setRootElement(rootElement);
45
24
  }, [editor]);
46
- useLayoutEffect(() => {
47
- return editor.addListener('error', onError);
48
- }, [editor, onError]);
49
25
  return [rootElementRef, showPlaceholder];
50
26
  }
51
27
 
@@ -4,4 +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
- 'use strict';var b=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;module.exports=function(a,c){const f=b(a),h=d.useCallback(g=>{a.setRootElement(g)},[a]);e(()=>a.addListener("error",c),[a,c]);return[h,f]};
7
+ var b=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),c=require("react");module.exports=function(a){const d=b(a);return[c.useCallback(e=>{a.setRootElement(e)},[a]),d]};
@@ -4,5 +4,5 @@
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
- 'use strict';var g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function p(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
7
+ var g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function p(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
8
8
  function q(a,b){h(()=>{const k=[],l=[];for(let d=0;d<a.length;d++){const [c,e]=a[d],n=f=>{const m=b.getRootElement();null!==m&&"true"===m.contentEditable&&e(f,b)};k.push(f=>{p(c,f).addEventListener(c,n)});l.push(f=>{p(c,f).removeEventListener(c,n)})}return b.addListener("root",(d,c)=>{null!==c&&l.forEach(e=>e(c));null!==d&&k.forEach(e=>e(d))})},[b,a])}module.exports=function(a,b){q(a,b)};
@@ -18,9 +18,9 @@ var react = require('react');
18
18
  *
19
19
  *
20
20
  */
21
- const MERGE = 0;
22
- const NO_MERGE = 1;
23
- const DISCARD = 2;
21
+ const HISTORY_MERGE = 0;
22
+ const HISTORY_PUSH = 1;
23
+ const DISCARD_HISTORY_CANDIDATE = 2;
24
24
  const OTHER = 0;
25
25
  const COMPOSING_CHARACTER = 1;
26
26
  const INSERT_CHARACTER_AFTER_SELECTION = 2;
@@ -73,7 +73,7 @@ function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyEl
73
73
  return COMPOSING_CHARACTER;
74
74
  }
75
75
 
76
- if (nextSelection === null || prevSelection === null || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
76
+ if (!lexical.$isRangeSelection(nextSelection) || !lexical.$isRangeSelection(prevSelection) || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
77
77
  return OTHER;
78
78
  }
79
79
 
@@ -148,18 +148,21 @@ function createMergeActionGetter(editor, delay) {
148
148
  if (tags.has('historic')) {
149
149
  prevChangeType = OTHER;
150
150
  prevChangeTime = changeTime;
151
- return DISCARD;
151
+ return DISCARD_HISTORY_CANDIDATE;
152
152
  }
153
153
 
154
154
  const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
155
155
 
156
156
  const mergeAction = (() => {
157
- if (tags.has('without-history')) {
158
- return MERGE;
157
+ const shouldPushHistory = tags.has('history-push');
158
+ const shouldMergeHistory = !shouldPushHistory && tags.has('history-merge');
159
+
160
+ if (shouldMergeHistory) {
161
+ return HISTORY_MERGE;
159
162
  }
160
163
 
161
164
  if (prevEditorState === null) {
162
- return NO_MERGE;
165
+ return HISTORY_PUSH;
163
166
  }
164
167
 
165
168
  const selection = nextEditorState._selection;
@@ -168,19 +171,19 @@ function createMergeActionGetter(editor, delay) {
168
171
 
169
172
  if (!hasDirtyNodes) {
170
173
  if (prevSelection === null && selection !== null) {
171
- return MERGE;
174
+ return HISTORY_MERGE;
172
175
  }
173
176
 
174
- return DISCARD;
177
+ return DISCARD_HISTORY_CANDIDATE;
175
178
  }
176
179
 
177
180
  const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
178
181
 
179
- if (changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
180
- return MERGE;
182
+ if (shouldPushHistory === false && changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
183
+ return HISTORY_MERGE;
181
184
  }
182
185
 
183
- return NO_MERGE;
186
+ return HISTORY_PUSH;
184
187
  })();
185
188
 
186
189
  prevChangeTime = changeTime;
@@ -217,7 +220,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
217
220
 
218
221
  const mergeAction = getMergeAction(prevEditorState, editorState, current, dirtyLeaves, dirtyElements, tags);
219
222
 
220
- if (mergeAction === NO_MERGE) {
223
+ if (mergeAction === HISTORY_PUSH) {
221
224
  if (redoStack.length !== 0) {
222
225
  historyState.redoStack = [];
223
226
  }
@@ -228,7 +231,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
228
231
  });
229
232
  editor.execCommand('canUndo', true);
230
233
  }
231
- } else if (mergeAction === DISCARD) {
234
+ } else if (mergeAction === DISCARD_HISTORY_CANDIDATE) {
232
235
  return;
233
236
  } // Else we merge
234
237
 
@@ -4,10 +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
- 'use strict';var n=require("@lexical/react/withSubscriptions"),r=require("lexical"),v=require("react");
8
- function w(b,d,k,a,h){if(null===b||0===k.size&&0===a.size)return 0;var g=d._selection,c=b._selection;if(h)return 1;if(null===g||null===c||!c.isCollapsed()||!g.isCollapsed())return 0;var e=Array.from(k);a=Array.from(a);k=d._nodeMap;h=[];for(var f=0;f<e.length;f++){const l=k.get(e[f]);void 0!==l&&h.push(l)}for(e=0;e<a.length;e++)a[e][1]&&(f=k.get(a[e][0]),void 0===f||r.$isRootNode(f)||h.push(f));if(0===h.length)return 0;if(1<h.length)return a=d._nodeMap,d=a.get(g.anchor.key),c=a.get(c.anchor.key),d&&
9
- c&&!b._nodeMap.has(d.__key)&&r.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=h[0];b=b._nodeMap.get(d.__key);if(!r.$isTextNode(b)||!r.$isTextNode(d)||b.__mode!==d.__mode)return 0;b=b.__text;d=d.__text;if(b===d)return 0;g=g.anchor;c=c.anchor;if(g.key!==c.key||"text"!==g.type)return 0;g=g.offset;c=c.offset;b=d.length-b.length;return 1===b&&c===g-1?2:-1===b&&c===g+1?3:-1===b&&c===g?4:0}
10
- function x(b,d){let k=Date.now(),a=0;return(h,g,c,e,f,l)=>{const p=Date.now();if(l.has("historic"))return a=0,k=p,2;const m=w(h,g,e,f,b.isComposing()),u=(()=>{if(l.has("without-history"))return 0;if(null===h)return 1;var q=g._selection;const t=h._selection;if(!(0<e.size||0<f.size))return null===t&&null!==q?0:2;q=null===c||c.editor===b;return 0!==m&&m===a&&p<k+d&&q?0:1})();k=p;a=m;return u}}
11
- function y(b,d,k=1E3){const a=v.useMemo(()=>d||z(),[d]),h=v.useCallback(()=>{a.undoStack=[];a.redoStack=[];a.current=null},[a]);v.useEffect(()=>{const g=x(b,k);return n(b.addListener("command",c=>{switch(c){case "undo":c=a.redoStack;var e=a.undoStack;if(0!==e.length){var f=a.current;const l=e.pop();null!==f&&(c.push(f),b.execCommand("canRedo",!0));0===e.length&&b.execCommand("canUndo",!1);a.current=l;l.editor.setEditorState(l.editorState.clone(l.undoSelection),{tag:"historic"})}return!0;case "redo":return c=
12
- a.redoStack,e=a.undoStack,0!==c.length&&(f=a.current,null!==f&&(e.push(f),b.execCommand("canUndo",!0)),e=c.pop(),0===c.length&&b.execCommand("canRedo",!1),a.current=e,e.editor.setEditorState(e.editorState,{tag:"historic"})),!0;case "clearEditor":return h(),!1;case "clearHistory":return h(),!0;default:return!1}},0),b.addListener("update",({editorState:c,prevEditorState:e,dirtyLeaves:f,dirtyElements:l,tags:p})=>{const m=a.current,u=a.redoStack,q=a.undoStack,t=null===m?null:m.editorState;if(null===m||
13
- c!==t){f=g(e,c,m,f,l,p);if(1===f)0!==u.length&&(a.redoStack=[]),null!==m&&(q.push({...m,undoSelection:e.read(r.$getSelection)}),b.execCommand("canUndo",!0));else if(2===f)return;a.current={editor:b,editorState:c}}}))},[h,k,b,a])}function z(){return{current:null,redoStack:[],undoStack:[]}}exports.createEmptyHistoryState=z;exports.useLexicalHistory=function(b,d,k=1E3){return y(b,d,k)};
7
+ var n=require("@lexical/react/withSubscriptions"),t=require("lexical"),v=require("react");
8
+ function w(b,d,k,a,h){if(null===b||0===k.size&&0===a.size)return 0;var g=d._selection,c=b._selection;if(h)return 1;if(!(t.$isRangeSelection(g)&&t.$isRangeSelection(c)&&c.isCollapsed()&&g.isCollapsed()))return 0;var e=Array.from(k);a=Array.from(a);k=d._nodeMap;h=[];for(var f=0;f<e.length;f++){const l=k.get(e[f]);void 0!==l&&h.push(l)}for(e=0;e<a.length;e++)a[e][1]&&(f=k.get(a[e][0]),void 0===f||t.$isRootNode(f)||h.push(f));if(0===h.length)return 0;if(1<h.length)return a=d._nodeMap,d=a.get(g.anchor.key),
9
+ c=a.get(c.anchor.key),d&&c&&!b._nodeMap.has(d.__key)&&t.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=h[0];b=b._nodeMap.get(d.__key);if(!t.$isTextNode(b)||!t.$isTextNode(d)||b.__mode!==d.__mode)return 0;b=b.__text;d=d.__text;if(b===d)return 0;g=g.anchor;c=c.anchor;if(g.key!==c.key||"text"!==g.type)return 0;g=g.offset;c=c.offset;b=d.length-b.length;return 1===b&&c===g-1?2:-1===b&&c===g+1?3:-1===b&&c===g?4:0}
10
+ function x(b,d){let k=Date.now(),a=0;return(h,g,c,e,f,l)=>{const p=Date.now();if(l.has("historic"))return a=0,k=p,2;const m=w(h,g,e,f,b.isComposing()),u=(()=>{const r=l.has("history-push");if(!r&&l.has("history-merge"))return 0;if(null===h)return 1;var q=g._selection;const z=h._selection;if(!(0<e.size||0<f.size))return null===z&&null!==q?0:2;q=null===c||c.editor===b;return!1===r&&0!==m&&m===a&&p<k+d&&q?0:1})();k=p;a=m;return u}}
11
+ function y(b,d,k=1E3){const a=v.useMemo(()=>d||A(),[d]),h=v.useCallback(()=>{a.undoStack=[];a.redoStack=[];a.current=null},[a]);v.useEffect(()=>{const g=x(b,k);return n(b.addListener("command",c=>{switch(c){case "undo":c=a.redoStack;var e=a.undoStack;if(0!==e.length){var f=a.current;const l=e.pop();null!==f&&(c.push(f),b.execCommand("canRedo",!0));0===e.length&&b.execCommand("canUndo",!1);a.current=l;l.editor.setEditorState(l.editorState.clone(l.undoSelection),{tag:"historic"})}return!0;case "redo":return c=
12
+ a.redoStack,e=a.undoStack,0!==c.length&&(f=a.current,null!==f&&(e.push(f),b.execCommand("canUndo",!0)),e=c.pop(),0===c.length&&b.execCommand("canRedo",!1),a.current=e,e.editor.setEditorState(e.editorState,{tag:"historic"})),!0;case "clearEditor":return h(),!1;case "clearHistory":return h(),!0;default:return!1}},0),b.addListener("update",({editorState:c,prevEditorState:e,dirtyLeaves:f,dirtyElements:l,tags:p})=>{const m=a.current,u=a.redoStack,r=a.undoStack,q=null===m?null:m.editorState;if(null===m||
13
+ c!==q){f=g(e,c,m,f,l,p);if(1===f)0!==u.length&&(a.redoStack=[]),null!==m&&(r.push({...m,undoSelection:e.read(t.$getSelection)}),b.execCommand("canUndo",!0));else if(2===f)return;a.current={editor:b,editorState:c}}}))},[h,k,b,a])}function A(){return{current:null,redoStack:[],undoStack:[]}}exports.createEmptyHistoryState=A;exports.useLexicalHistory=function(b,d,k=1E3){return y(b,d,k)};
@@ -42,6 +42,12 @@ function useList(editor) {
42
42
  } else if (type === 'removeList') {
43
43
  list.removeList(editor);
44
44
  return true;
45
+ } else if (type === 'insertParagraph') {
46
+ const hasHandledInsertParagraph = list.$handleListInsertParagraph();
47
+
48
+ if (hasHandledInsertParagraph) {
49
+ return true;
50
+ }
45
51
  }
46
52
 
47
53
  return false;
@@ -4,4 +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
- 'use strict';var b=require("@lexical/list"),d=require("react");function e(a){d.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(b.indentList())return!0}else if("outdentContent"===c){if(b.outdentList())return!0}else{if("insertOrderedList"===c)return b.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return b.insertList(a,"ul"),!0;if("removeList"===c)return b.removeList(a),!0}return!1},1),[a])}module.exports=function(a){e(a)};
7
+ var b=require("@lexical/list"),d=require("react");function e(a){d.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(b.indentList())return!0}else if("outdentContent"===c){if(b.outdentList())return!0}else{if("insertOrderedList"===c)return b.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return b.insertList(a,"ul"),!0;if("removeList"===c)return b.removeList(a),!0;if("insertParagraph"===c&&b.$handleListInsertParagraph())return!0}return!1},1),[a])}module.exports=function(a){e(a)};