@lexical/react 0.1.16 → 0.1.17

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 (87) hide show
  1. package/DEPRECATED_useLexicalAutoFormatter.dev.js +5 -729
  2. package/DEPRECATED_useLexicalAutoFormatter.prod.js +1 -19
  3. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +1 -1
  4. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +9 -10
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +7 -7
  7. package/DEPRECATED_useLexicalDecorators.dev.js +1 -1
  8. package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
  9. package/DEPRECATED_useLexicalEditorEvents.dev.js +1 -1
  10. package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
  11. package/DEPRECATED_useLexicalHistory.dev.js +5 -307
  12. package/DEPRECATED_useLexicalHistory.prod.js +1 -7
  13. package/DEPRECATED_useLexicalList.dev.js +29 -25
  14. package/DEPRECATED_useLexicalList.prod.js +3 -1
  15. package/DEPRECATED_useLexicalPlainText.dev.js +8 -662
  16. package/DEPRECATED_useLexicalPlainText.prod.js +2 -14
  17. package/DEPRECATED_useLexicalRichText.dev.js +8 -747
  18. package/DEPRECATED_useLexicalRichText.prod.js +2 -17
  19. package/LICENSE +1 -1
  20. package/{withSubscriptions.prod.js → LexicalAutoFocusPlugin.d.ts} +3 -1
  21. package/{withSubscriptions.dev.js → LexicalAutoFocusPlugin.dev.js} +10 -5
  22. package/LexicalAutoFocusPlugin.js +9 -0
  23. package/{LexicalAutoFormatterPlugin.js.flow → LexicalAutoFocusPlugin.js.flow} +1 -1
  24. package/LexicalAutoFocusPlugin.prod.js +7 -0
  25. package/LexicalAutoLinkPlugin.dev.js +12 -15
  26. package/LexicalAutoLinkPlugin.prod.js +6 -6
  27. package/LexicalAutoScrollPlugin.d.ts +13 -0
  28. package/LexicalAutoScrollPlugin.dev.js +82 -0
  29. package/LexicalAutoScrollPlugin.js +9 -0
  30. package/{withSubscriptions.d.ts → LexicalAutoScrollPlugin.js.flow} +5 -5
  31. package/LexicalAutoScrollPlugin.prod.js +8 -0
  32. package/LexicalCharacterLimitPlugin.dev.js +9 -10
  33. package/LexicalCharacterLimitPlugin.prod.js +7 -7
  34. package/LexicalClearEditorPlugin.dev.js +15 -19
  35. package/LexicalClearEditorPlugin.prod.js +1 -1
  36. package/LexicalCollaborationPlugin.d.ts +6 -3
  37. package/LexicalCollaborationPlugin.dev.js +30 -41
  38. package/LexicalCollaborationPlugin.js.flow +7 -4
  39. package/LexicalCollaborationPlugin.prod.js +10 -9
  40. package/LexicalComposer.d.ts +2 -2
  41. package/LexicalComposer.dev.js +3 -19
  42. package/LexicalComposer.js.flow +2 -2
  43. package/LexicalComposer.prod.js +2 -3
  44. package/LexicalContentEditable.dev.js +3 -1
  45. package/LexicalContentEditable.prod.js +2 -2
  46. package/LexicalHashtagPlugin.dev.js +20 -94
  47. package/LexicalHashtagPlugin.prod.js +4 -7
  48. package/LexicalHistoryPlugin.dev.js +5 -307
  49. package/LexicalHistoryPlugin.prod.js +1 -7
  50. package/LexicalHorizontalRuleNode.d.ts +3 -1
  51. package/LexicalHorizontalRuleNode.dev.js +2 -0
  52. package/LexicalHorizontalRuleNode.js.flow +6 -2
  53. package/LexicalHorizontalRuleNode.prod.js +2 -2
  54. package/LexicalLinkPlugin.dev.js +19 -20
  55. package/LexicalLinkPlugin.prod.js +4 -3
  56. package/LexicalListPlugin.dev.js +29 -25
  57. package/LexicalListPlugin.prod.js +3 -2
  58. package/{LexicalAutoFormatterPlugin.d.ts → LexicalMarkdownShortcutPlugin.d.ts} +1 -1
  59. package/LexicalMarkdownShortcutPlugin.dev.js +42 -0
  60. package/LexicalMarkdownShortcutPlugin.js +9 -0
  61. package/{withSubscriptions.js.flow → LexicalMarkdownShortcutPlugin.js.flow} +1 -4
  62. package/LexicalMarkdownShortcutPlugin.prod.js +7 -0
  63. package/LexicalNestedComposer.dev.js +20 -15
  64. package/LexicalNestedComposer.prod.js +3 -3
  65. package/LexicalOnChangePlugin.dev.js +1 -1
  66. package/LexicalOnChangePlugin.prod.js +1 -1
  67. package/LexicalPlainTextPlugin.dev.js +6 -359
  68. package/LexicalPlainTextPlugin.prod.js +4 -11
  69. package/LexicalRichTextPlugin.dev.js +6 -444
  70. package/LexicalRichTextPlugin.prod.js +4 -12
  71. package/LexicalTablePlugin.dev.js +27 -30
  72. package/LexicalTablePlugin.prod.js +3 -3
  73. package/LexicalTreeView.dev.js +1 -1
  74. package/LexicalTreeView.prod.js +1 -1
  75. package/package.json +17 -14
  76. package/useLexicalIsTextContentEmpty.dev.js +1 -1
  77. package/useLexicalIsTextContentEmpty.prod.js +1 -1
  78. package/useLexicalNodeSelection.dev.js +1 -1
  79. package/useLexicalNodeSelection.prod.js +1 -1
  80. package/useLexicalTextEntity.d.ts +19 -0
  81. package/useLexicalTextEntity.dev.js +29 -0
  82. package/{withSubscriptions.js → useLexicalTextEntity.js} +2 -2
  83. package/useLexicalTextEntity.js.flow +18 -0
  84. package/useLexicalTextEntity.prod.js +7 -0
  85. package/LexicalAutoFormatterPlugin.dev.js +0 -766
  86. package/LexicalAutoFormatterPlugin.js +0 -9
  87. package/LexicalAutoFormatterPlugin.prod.js +0 -25
@@ -4,22 +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 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)};
7
+ var b=require("@lexical/markdown"),c=require("@lexical/react/LexicalHorizontalRuleNode"),d=require("react");function e(a){d.useEffect(()=>b.registerMarkdownShortcuts(a,c.$createHorizontalRuleNode),[a])}module.exports=function(a){e(a)};
@@ -41,7 +41,7 @@ var useLayoutEffect = useLayoutEffectImpl;
41
41
  function useLexicalCanShowPlaceholder$1(editor) {
42
42
  const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
43
43
  useLayoutEffect(() => {
44
- return editor.addListener('update', ({
44
+ return editor.registerUpdateListener(({
45
45
  editorState
46
46
  }) => {
47
47
  const isComposing = editor.isComposing();
@@ -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
- 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)};
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.registerUpdateListener(({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,11 +6,10 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
- var withSubscriptions = require('@lexical/react/withSubscriptions');
9
+ var overflow = require('@lexical/overflow');
10
10
  var text = require('@lexical/text');
11
11
  var utils = require('@lexical/utils');
12
12
  var lexical = require('lexical');
13
- var OverflowNode = require('lexical/OverflowNode');
14
13
  var react = require('react');
15
14
 
16
15
  /**
@@ -28,7 +27,7 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
28
27
  remainingCharacters = characters => {}
29
28
  } = optional;
30
29
  react.useEffect(() => {
31
- if (!editor.hasNodes([OverflowNode.OverflowNode])) {
30
+ if (!editor.hasNodes([overflow.OverflowNode])) {
32
31
  {
33
32
  throw Error(`useCharacterLimit: OverflowNode not registered on editor`);
34
33
  }
@@ -37,9 +36,9 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
37
36
  react.useEffect(() => {
38
37
  let text$1 = editor.getEditorState().read(text.$rootTextContentCurry);
39
38
  let lastComputedTextLength = 0;
40
- return withSubscriptions(editor.addListener('textcontent', currentText => {
39
+ return utils.mergeRegister(editor.registerTextContentListener(currentText => {
41
40
  text$1 = currentText;
42
- }), editor.addListener('update', ({
41
+ }), editor.registerUpdateListener(({
43
42
  dirtyLeaves
44
43
  }) => {
45
44
  const isComposing = editor.isComposing();
@@ -75,7 +74,7 @@ function findOffset(text, maxCharacters, strlen) {
75
74
 
76
75
  if (typeof Segmenter === 'function') {
77
76
  const segmenter = new Segmenter();
78
- const graphemes = segmenter.segment(text); // eslint-disable-next-line no-for-of-loops/no-for-of-loops
77
+ const graphemes = segmenter.segment(text);
79
78
 
80
79
  for (const {
81
80
  segment: grapheme
@@ -119,7 +118,7 @@ function $wrapOverflowedNodes(offset) {
119
118
  node
120
119
  } = dfsNodes[i];
121
120
 
122
- if (OverflowNode.$isOverflowNode(node)) {
121
+ if (overflow.$isOverflowNode(node)) {
123
122
  const previousLength = accumulatedLength;
124
123
  const nextLength = accumulatedLength + node.getTextContentSize();
125
124
 
@@ -156,7 +155,7 @@ function $wrapOverflowedNodes(offset) {
156
155
  const previousAccumulatedLength = accumulatedLength;
157
156
  accumulatedLength += node.getTextContentSize();
158
157
 
159
- if (accumulatedLength > offset && !OverflowNode.$isOverflowNode(node.getParent())) {
158
+ if (accumulatedLength > offset && !overflow.$isOverflowNode(node.getParent())) {
160
159
  const previousSelection = lexical.$getSelection();
161
160
  let overflowNode; // For simple text we can improve the limit accuracy by splitting the TextNode
162
161
  // on the split point
@@ -179,7 +178,7 @@ function $wrapOverflowedNodes(offset) {
179
178
  }
180
179
 
181
180
  function $wrapNode(node) {
182
- const overflowNode = OverflowNode.$createOverflowNode();
181
+ const overflowNode = overflow.$createOverflowNode();
183
182
  node.insertBefore(overflowNode);
184
183
  overflowNode.append(node);
185
184
  return overflowNode;
@@ -200,7 +199,7 @@ function $unwrapNode(node) {
200
199
  function mergePrevious(overflowNode) {
201
200
  const previousNode = overflowNode.getPreviousSibling();
202
201
 
203
- if (!OverflowNode.$isOverflowNode(previousNode)) {
202
+ if (!overflow.$isOverflowNode(previousNode)) {
204
203
  return;
205
204
  }
206
205
 
@@ -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
- 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
- exports.mergePrevious=E;
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])};
7
+ var k=require("@lexical/overflow"),q=require("@lexical/text"),w=require("@lexical/utils"),x=require("lexical"),y=require("react");function z(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}function A(a){const d=k.$createOverflowNode();a.insertBefore(d);d.append(a);return d}
8
+ function C(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 D(a){const d=a.getPreviousSibling();if(k.$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
+ exports.mergePrevious=D;
11
+ exports.useCharacterLimit=function(a,d,f=Object.freeze({})){const {strlen:e=c=>c.length,remainingCharacters:m=()=>{}}=f;y.useEffect(()=>{if(!a.hasNodes([k.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]);y.useEffect(()=>{let c=a.getEditorState().read(q.$rootTextContentCurry),g=0;return w.mergeRegister(a.registerTextContentListener(n=>{c=n}),a.registerUpdateListener(({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=z(c,d,e);a.update(()=>{const B=w.$dfs(),E=B.length;let t=0;for(let v=0;v<E;v+=1){var {node:b}=B[v];if(k.$isOverflowNode(b)){var l=t;if(t+b.getTextContentSize()<=p){var h=b.getParent();l=b.getPreviousSibling();var u=b.getNextSibling();C(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)&&C(b))}else x.$isLeafNode(b)&&(l=t,t+=b.getTextContentSize(),t>p&&!k.$isOverflowNode(b.getParent())&&(h=x.$getSelection(),l<p&&x.$isTextNode(b)&&b.isSimpleText()?([,b]=b.splitText(p-l),b=A(b)):b=A(b),null!==h&&x.$setSelection(h),D(b)))}},{tag:"history-merge"})}g=r}}))},[a,d,m,e])};
@@ -42,7 +42,7 @@ function useDecorators(editor) {
42
42
  const [decorators, setDecorators] = react.useState(() => editor.getDecorators()); // Subscribe to changes
43
43
 
44
44
  useLayoutEffect(() => {
45
- return editor.addListener('decorator', nextDecorators => {
45
+ return editor.registerDecoratorListener(nextDecorators => {
46
46
  reactDom.flushSync(() => {
47
47
  setDecorators(nextDecorators);
48
48
  });
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
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
- 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)};
8
+ function l(a){const [e,m]=c.useState(()=>a.getDecorators());k(()=>a.registerDecoratorListener(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)};
@@ -69,7 +69,7 @@ function useEditorEvents(events, editor) {
69
69
  });
70
70
  }
71
71
 
72
- return editor.addListener('root', (rootElement, prevRootElement) => {
72
+ return editor.registerRootListener((rootElement, prevRootElement) => {
73
73
  if (prevRootElement !== null) {
74
74
  destroy.forEach(fn => fn(prevRootElement));
75
75
  }
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
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
- 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)};
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.registerRootListener((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)};
@@ -6,8 +6,7 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
- var withSubscriptions = require('@lexical/react/withSubscriptions');
10
- var lexical = require('lexical');
9
+ var history = require('@lexical/history');
11
10
  var react = require('react');
12
11
 
13
12
  /**
@@ -18,312 +17,11 @@ var react = require('react');
18
17
  *
19
18
  *
20
19
  */
21
- const HISTORY_MERGE = 0;
22
- const HISTORY_PUSH = 1;
23
- const DISCARD_HISTORY_CANDIDATE = 2;
24
- const OTHER = 0;
25
- const COMPOSING_CHARACTER = 1;
26
- const INSERT_CHARACTER_AFTER_SELECTION = 2;
27
- const DELETE_CHARACTER_BEFORE_SELECTION = 3;
28
- const DELETE_CHARACTER_AFTER_SELECTION = 4;
29
- const EditorPriority = 0;
30
-
31
- function getDirtyNodes(editorState, dirtyLeavesSet, dirtyElementsSet) {
32
- const dirtyLeaves = Array.from(dirtyLeavesSet);
33
- const dirtyElements = Array.from(dirtyElementsSet);
34
- const nodeMap = editorState._nodeMap;
35
- const nodes = [];
36
-
37
- for (let i = 0; i < dirtyLeaves.length; i++) {
38
- const dirtyLeafKey = dirtyLeaves[i];
39
- const dirtyLeaf = nodeMap.get(dirtyLeafKey);
40
-
41
- if (dirtyLeaf !== undefined) {
42
- nodes.push(dirtyLeaf);
43
- }
44
- }
45
-
46
- for (let i = 0; i < dirtyElements.length; i++) {
47
- const intentionallyMarkedAsDirty = dirtyElements[i][1];
48
-
49
- if (!intentionallyMarkedAsDirty) {
50
- continue;
51
- }
52
-
53
- const dirtyElementKey = dirtyElements[i][0];
54
- const dirtyElement = nodeMap.get(dirtyElementKey);
55
-
56
- if (dirtyElement !== undefined && !lexical.$isRootNode(dirtyElement)) {
57
- nodes.push(dirtyElement);
58
- }
59
- }
60
-
61
- return nodes;
62
- }
63
-
64
- function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyElementsSet, isComposing) {
65
- if (prevEditorState === null || dirtyLeavesSet.size === 0 && dirtyElementsSet.size === 0) {
66
- return OTHER;
67
- }
68
-
69
- const nextSelection = nextEditorState._selection;
70
- const prevSelection = prevEditorState._selection;
71
-
72
- if (isComposing) {
73
- return COMPOSING_CHARACTER;
74
- }
75
-
76
- if (!lexical.$isRangeSelection(nextSelection) || !lexical.$isRangeSelection(prevSelection) || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
77
- return OTHER;
78
- }
79
-
80
- const dirtyNodes = getDirtyNodes(nextEditorState, dirtyLeavesSet, dirtyElementsSet);
81
-
82
- if (dirtyNodes.length === 0) {
83
- return OTHER;
84
- } // Catching the case when inserting new text node into an element (e.g. first char in paragraph/list),
85
- // or after existing node.
86
-
87
-
88
- if (dirtyNodes.length > 1) {
89
- const nextNodeMap = nextEditorState._nodeMap;
90
- const nextAnchorNode = nextNodeMap.get(nextSelection.anchor.key);
91
- const prevAnchorNode = nextNodeMap.get(prevSelection.anchor.key);
92
-
93
- if (nextAnchorNode && prevAnchorNode && !prevEditorState._nodeMap.has(nextAnchorNode.__key) && lexical.$isTextNode(nextAnchorNode) && nextAnchorNode.__text.length === 1 && nextSelection.anchor.offset === 1) {
94
- return INSERT_CHARACTER_AFTER_SELECTION;
95
- }
96
-
97
- return OTHER;
98
- }
99
-
100
- const nextDirtyNode = dirtyNodes[0];
101
-
102
- const prevDirtyNode = prevEditorState._nodeMap.get(nextDirtyNode.__key);
103
-
104
- if (!lexical.$isTextNode(prevDirtyNode) || !lexical.$isTextNode(nextDirtyNode) || prevDirtyNode.__mode !== nextDirtyNode.__mode) {
105
- return OTHER;
106
- }
107
-
108
- const prevText = prevDirtyNode.__text;
109
- const nextText = nextDirtyNode.__text;
110
-
111
- if (prevText === nextText) {
112
- return OTHER;
113
- }
114
-
115
- const nextAnchor = nextSelection.anchor;
116
- const prevAnchor = prevSelection.anchor;
117
-
118
- if (nextAnchor.key !== prevAnchor.key || nextAnchor.type !== 'text') {
119
- return OTHER;
120
- }
121
-
122
- const nextAnchorOffset = nextAnchor.offset;
123
- const prevAnchorOffset = prevAnchor.offset;
124
- const textDiff = nextText.length - prevText.length;
125
-
126
- if (textDiff === 1 && prevAnchorOffset === nextAnchorOffset - 1) {
127
- return INSERT_CHARACTER_AFTER_SELECTION;
128
- }
129
-
130
- if (textDiff === -1 && prevAnchorOffset === nextAnchorOffset + 1) {
131
- return DELETE_CHARACTER_BEFORE_SELECTION;
132
- }
133
-
134
- if (textDiff === -1 && prevAnchorOffset === nextAnchorOffset) {
135
- return DELETE_CHARACTER_AFTER_SELECTION;
136
- }
137
-
138
- return OTHER;
139
- }
140
-
141
- function createMergeActionGetter(editor, delay) {
142
- let prevChangeTime = Date.now();
143
- let prevChangeType = OTHER;
144
- return (prevEditorState, nextEditorState, currentHistoryEntry, dirtyLeaves, dirtyElements, tags) => {
145
- const changeTime = Date.now(); // If applying changes from history stack there's no need
146
- // to run history logic again, as history entries already calculated
147
-
148
- if (tags.has('historic')) {
149
- prevChangeType = OTHER;
150
- prevChangeTime = changeTime;
151
- return DISCARD_HISTORY_CANDIDATE;
152
- }
153
-
154
- const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
155
-
156
- const mergeAction = (() => {
157
- const shouldPushHistory = tags.has('history-push');
158
- const shouldMergeHistory = !shouldPushHistory && tags.has('history-merge');
159
-
160
- if (shouldMergeHistory) {
161
- return HISTORY_MERGE;
162
- }
163
-
164
- if (prevEditorState === null) {
165
- return HISTORY_PUSH;
166
- }
167
-
168
- const selection = nextEditorState._selection;
169
- const prevSelection = prevEditorState._selection;
170
- const hasDirtyNodes = dirtyLeaves.size > 0 || dirtyElements.size > 0;
171
-
172
- if (!hasDirtyNodes) {
173
- if (prevSelection === null && selection !== null) {
174
- return HISTORY_MERGE;
175
- }
176
-
177
- return DISCARD_HISTORY_CANDIDATE;
178
- }
179
-
180
- const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
181
-
182
- if (shouldPushHistory === false && changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
183
- return HISTORY_MERGE;
184
- }
185
-
186
- return HISTORY_PUSH;
187
- })();
188
-
189
- prevChangeTime = changeTime;
190
- prevChangeType = changeType;
191
- return mergeAction;
192
- };
193
- }
194
-
195
20
  function useHistory(editor, externalHistoryState, delay = 1000) {
196
- const historyState = react.useMemo(() => externalHistoryState || createEmptyHistoryState(), [externalHistoryState]);
197
- const clearHistory = react.useCallback(() => {
198
- historyState.undoStack = [];
199
- historyState.redoStack = [];
200
- historyState.current = null;
201
- }, [historyState]);
21
+ const historyState = react.useMemo(() => externalHistoryState || history.createEmptyHistoryState(), [externalHistoryState]);
202
22
  react.useEffect(() => {
203
- const getMergeAction = createMergeActionGetter(editor, delay);
204
-
205
- const applyChange = ({
206
- editorState,
207
- prevEditorState,
208
- dirtyLeaves,
209
- dirtyElements,
210
- tags
211
- }) => {
212
- const current = historyState.current;
213
- const redoStack = historyState.redoStack;
214
- const undoStack = historyState.undoStack;
215
- const currentEditorState = current === null ? null : current.editorState;
216
-
217
- if (current !== null && editorState === currentEditorState) {
218
- return;
219
- }
220
-
221
- const mergeAction = getMergeAction(prevEditorState, editorState, current, dirtyLeaves, dirtyElements, tags);
222
-
223
- if (mergeAction === HISTORY_PUSH) {
224
- if (redoStack.length !== 0) {
225
- historyState.redoStack = [];
226
- }
227
-
228
- if (current !== null) {
229
- undoStack.push({ ...current,
230
- undoSelection: prevEditorState.read(lexical.$getSelection)
231
- });
232
- editor.execCommand('canUndo', true);
233
- }
234
- } else if (mergeAction === DISCARD_HISTORY_CANDIDATE) {
235
- return;
236
- } // Else we merge
237
-
238
-
239
- historyState.current = {
240
- editor,
241
- editorState
242
- };
243
- };
244
-
245
- const undo = () => {
246
- const redoStack = historyState.redoStack;
247
- const undoStack = historyState.undoStack;
248
- const undoStackLength = undoStack.length;
249
-
250
- if (undoStackLength !== 0) {
251
- const current = historyState.current;
252
- const historyStateEntry = undoStack.pop();
253
-
254
- if (current !== null) {
255
- redoStack.push(current);
256
- editor.execCommand('canRedo', true);
257
- }
258
-
259
- if (undoStack.length === 0) {
260
- editor.execCommand('canUndo', false);
261
- }
262
-
263
- historyState.current = historyStateEntry;
264
- historyStateEntry.editor.setEditorState(historyStateEntry.editorState.clone(historyStateEntry.undoSelection), {
265
- tag: 'historic'
266
- });
267
- }
268
- };
269
-
270
- const redo = () => {
271
- const redoStack = historyState.redoStack;
272
- const undoStack = historyState.undoStack;
273
-
274
- if (redoStack.length !== 0) {
275
- const current = historyState.current;
276
-
277
- if (current !== null) {
278
- undoStack.push(current);
279
- editor.execCommand('canUndo', true);
280
- }
281
-
282
- const historyStateEntry = redoStack.pop();
283
-
284
- if (redoStack.length === 0) {
285
- editor.execCommand('canRedo', false);
286
- }
287
-
288
- historyState.current = historyStateEntry;
289
- historyStateEntry.editor.setEditorState(historyStateEntry.editorState, {
290
- tag: 'historic'
291
- });
292
- }
293
- };
294
-
295
- const applyCommand = type => {
296
- switch (type) {
297
- case 'undo':
298
- undo();
299
- return true;
300
-
301
- case 'redo':
302
- redo();
303
- return true;
304
-
305
- case 'clearEditor':
306
- clearHistory();
307
- return false;
308
-
309
- case 'clearHistory':
310
- clearHistory();
311
- return true;
312
-
313
- default:
314
- return false;
315
- }
316
- };
317
-
318
- return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority), editor.addListener('update', applyChange));
319
- }, [clearHistory, delay, editor, historyState]);
320
- }
321
- function createEmptyHistoryState() {
322
- return {
323
- current: null,
324
- redoStack: [],
325
- undoStack: []
326
- };
23
+ return history.registerHistory(editor, historyState, delay);
24
+ }, [delay, editor, historyState]);
327
25
  }
328
26
 
329
27
  /**
@@ -338,5 +36,5 @@ function useLexicalHistory(editor, externalHistoryState, delay = 1000) {
338
36
  return useHistory(editor, externalHistoryState, delay);
339
37
  }
340
38
 
341
- exports.createEmptyHistoryState = createEmptyHistoryState;
39
+ exports.createEmptyHistoryState = history.createEmptyHistoryState;
342
40
  exports.useLexicalHistory = useLexicalHistory;
@@ -4,10 +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 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)};
7
+ var d=require("@lexical/history"),e=require("react");function g(a,b,c=1E3){const f=e.useMemo(()=>b||d.createEmptyHistoryState(),[b]);e.useEffect(()=>d.registerHistory(a,f,c),[c,a,f])}exports.createEmptyHistoryState=d.createEmptyHistoryState;exports.useLexicalHistory=function(a,b,c=1E3){return g(a,b,c)};
@@ -7,6 +7,8 @@
7
7
  'use strict';
8
8
 
9
9
  var list = require('@lexical/list');
10
+ var utils = require('@lexical/utils');
11
+ var lexical = require('lexical');
10
12
  var react = require('react');
11
13
 
12
14
  /**
@@ -20,38 +22,40 @@ var react = require('react');
20
22
  const LowPriority = 1;
21
23
  function useList(editor) {
22
24
  react.useEffect(() => {
23
- return editor.addListener('command', type => {
24
- if (type === 'indentContent') {
25
- const hasHandledIndention = list.indentList();
25
+ return utils.mergeRegister(editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, () => {
26
+ const hasHandledIndention = list.indentList();
26
27
 
27
- if (hasHandledIndention) {
28
- return true;
29
- }
30
- } else if (type === 'outdentContent') {
31
- const hasHandledIndention = list.outdentList();
32
-
33
- if (hasHandledIndention) {
34
- return true;
35
- }
36
- } else if (type === 'insertOrderedList') {
37
- list.insertList(editor, 'ol');
38
- return true;
39
- } else if (type === 'insertUnorderedList') {
40
- list.insertList(editor, 'ul');
28
+ if (hasHandledIndention) {
41
29
  return true;
42
- } else if (type === 'removeList') {
43
- list.removeList(editor);
30
+ }
31
+
32
+ return false;
33
+ }, LowPriority), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, () => {
34
+ const hasHandledIndention = list.outdentList();
35
+
36
+ if (hasHandledIndention) {
44
37
  return true;
45
- } else if (type === 'insertParagraph') {
46
- const hasHandledInsertParagraph = list.$handleListInsertParagraph();
38
+ }
47
39
 
48
- if (hasHandledInsertParagraph) {
49
- return true;
50
- }
40
+ return false;
41
+ }, LowPriority), editor.registerCommand(list.INSERT_ORDERED_LIST_COMMAND, () => {
42
+ list.insertList(editor, 'ol');
43
+ return true;
44
+ }, LowPriority), editor.registerCommand(list.INSERT_UNORDERED_LIST_COMMAND, () => {
45
+ list.insertList(editor, 'ul');
46
+ return true;
47
+ }, LowPriority), editor.registerCommand(list.REMOVE_LIST_COMMAND, () => {
48
+ list.removeList(editor);
49
+ return true;
50
+ }, LowPriority), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, () => {
51
+ const hasHandledInsertParagraph = list.$handleListInsertParagraph();
52
+
53
+ if (hasHandledInsertParagraph) {
54
+ return true;
51
55
  }
52
56
 
53
57
  return false;
54
- }, LowPriority);
58
+ }, LowPriority));
55
59
  }, [editor]);
56
60
  }
57
61
 
@@ -4,4 +4,6 @@
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 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)};
7
+ var b=require("@lexical/list"),c=require("@lexical/utils"),d=require("lexical"),e=require("react");
8
+ function f(a){e.useEffect(()=>c.mergeRegister(a.registerCommand(d.INDENT_CONTENT_COMMAND,()=>b.indentList()?!0:!1,1),a.registerCommand(d.OUTDENT_CONTENT_COMMAND,()=>b.outdentList()?!0:!1,1),a.registerCommand(b.INSERT_ORDERED_LIST_COMMAND,()=>{b.insertList(a,"ol");return!0},1),a.registerCommand(b.INSERT_UNORDERED_LIST_COMMAND,()=>{b.insertList(a,"ul");return!0},1),a.registerCommand(b.REMOVE_LIST_COMMAND,()=>{b.removeList(a);return!0},1),a.registerCommand(d.INSERT_PARAGRAPH_COMMAND,()=>b.$handleListInsertParagraph()?
9
+ !0:!1,1)),[a])}module.exports=function(a){f(a)};