@lexical/react 0.1.16 → 0.1.19

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,20 +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
- var l=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react"),w=require("@lexical/clipboard"),x=require("@lexical/selection");
8
- function y(a,e,f,d,c){if(null===a||0===f.size&&0===d.size)return 0;var b=e._selection,g=a._selection;if(c)return 1;if(!(u.$isRangeSelection(b)&&u.$isRangeSelection(g)&&g.isCollapsed()&&b.isCollapsed()))return 0;var h=Array.from(f);d=Array.from(d);f=e._nodeMap;c=[];for(var k=0;k<h.length;k++){const n=f.get(h[k]);void 0!==n&&c.push(n)}for(h=0;h<d.length;h++)d[h][1]&&(k=f.get(d[h][0]),void 0===k||u.$isRootNode(k)||c.push(k));if(0===c.length)return 0;if(1<c.length)return d=e._nodeMap,e=d.get(b.anchor.key),
9
- g=d.get(g.anchor.key),e&&g&&!a._nodeMap.has(e.__key)&&u.$isTextNode(e)&&1===e.__text.length&&1===b.anchor.offset?2:0;e=c[0];a=a._nodeMap.get(e.__key);if(!u.$isTextNode(a)||!u.$isTextNode(e)||a.__mode!==e.__mode)return 0;a=a.__text;e=e.__text;if(a===e)return 0;b=b.anchor;g=g.anchor;if(b.key!==g.key||"text"!==b.type)return 0;b=b.offset;g=g.offset;a=e.length-a.length;return 1===a&&g===b-1?2:-1===a&&g===b+1?3:-1===a&&g===b?4:0}
10
- function z(a,e){let f=Date.now(),d=0;return(c,b,g,h,k,n)=>{const t=Date.now();if(n.has("historic"))return d=0,f=t,2;const m=y(c,b,h,k,a.isComposing()),r=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===c)return 1;var p=b._selection;const C=c._selection;if(!(0<h.size||0<k.size))return null===C&&null!==p?0:2;p=null===g||g.editor===a;return!1===q&&0!==m&&m===d&&t<f+e&&p?0:1})();f=t;d=m;return r}}
11
- function A(a,e,f=1E3){const d=v.useMemo(()=>e||{current:null,redoStack:[],undoStack:[]},[e]),c=v.useCallback(()=>{d.undoStack=[];d.redoStack=[];d.current=null},[d]);v.useEffect(()=>{const b=z(a,f);return l(a.addListener("command",g=>{switch(g){case "undo":g=d.redoStack;var h=d.undoStack;if(0!==h.length){var k=d.current;const n=h.pop();null!==k&&(g.push(k),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);d.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
12
- {tag:"historic"})}return!0;case "redo":return g=d.redoStack,h=d.undoStack,0!==g.length&&(k=d.current,null!==k&&(h.push(k),a.execCommand("canUndo",!0)),h=g.pop(),0===g.length&&a.execCommand("canRedo",!1),d.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return c(),!1;case "clearHistory":return c(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:h,dirtyLeaves:k,dirtyElements:n,tags:t})=>{const m=d.current,r=d.redoStack,q=d.undoStack,
13
- p=null===m?null:m.editorState;if(null===m||g!==p){k=b(h,g,m,k,n,t);if(1===k)0!==r.length&&(d.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;d.current={editor:a,editorState:g}}}))},[c,f,a,d])}function B(a,e,f=1E3){return A(a,e,f)}var D="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;
14
- function E(a,e){F(a,e);e.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}function F(a,e){a.preventDefault();e.update(()=>{const f=a.clipboardData,d=u.$getSelection();if(null!==d&&null!=f){const c=w.getHtmlContent(e),b=w.$getLexicalContent(e);null!==c&&f.setData("text/html",c);null!==b&&f.setData("application/x-lexical-editor",b);f.setData("text/plain",d.getTextContent())}})}
15
- function G(a,e){a.preventDefault();e.update(()=>{const f=u.$getSelection(),d=a.clipboardData;null!=d&&u.$isRangeSelection(f)&&w.$insertDataTransferForRichText(d,f,e)})}const H={tag:"history-merge"};
16
- function I(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=u.$getRoot();if(null===f.getFirstChild()){const d=u.$createParagraphNode();f.append(d);f=document.activeElement;(null!==u.$getSelection()||null!==f&&f===a.getRootElement())&&d.select()}},H);else if(null!==e)switch(typeof e){case "string":e=a.parseEditorState(e);a.setEditorState(e,H);break;case "object":a.setEditorState(e,H);break;case "function":a.update(e,H)}}
17
- function J(a){v.useEffect(()=>{const e=f=>{var d=a.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var c=JSON.parse(d)}catch(b){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [b,g,h,k,n]=c;a.update(()=>{const t=u.$getSelection();if(u.$isRangeSelection(t)){var m=t.anchor;let r=m.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=b&&0<=g&&(q=b,p=b+g,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
18
- h)t.insertRawText(h),r=m.getNode();u.$isTextNode(r)&&(q=k,p=k+n,m=r.getTextContentSize(),q=q>m?m:q,p=p>m?m:p,t.setTextNodeRange(r,q,r,p));f.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
19
- function K(a,e){D(()=>{const f=a.addListener("command",(d,c)=>{var b=u.$getSelection();if("click"===d&&u.$isNodeSelection(b))return b.clear(),!0;if(!u.$isRangeSelection(b))return!1;switch(d){case "deleteCharacter":return b.deleteCharacter(c),!0;case "deleteWord":return b.deleteWord(c),!0;case "deleteLine":return b.deleteLine(c),!0;case "insertText":return"string"===typeof c?b.insertText(c):(d=c.dataTransfer,null!=d?w.$insertDataTransferForRichText(d,b,a):(c=c.data)&&b.insertText(c)),!0;case "removeText":return b.removeText(),
20
- !0;case "formatText":return b.formatText(c),!0;case "formatElement":return b=b.anchor.getNode(),(u.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(c),!0;case "insertLineBreak":return b.insertLineBreak(c),!0;case "insertParagraph":return b.insertParagraph(),!0;case "indentContent":return b=b.anchor,b="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),b.canInsertTab()?a.execCommand("insertText","\t"):10!==b.getIndent()&&b.setIndent(b.getIndent()+1),!0;case "outdentContent":return b=b.anchor,
21
- c=b.getNode(),d="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===c.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=c.shiftKey;if(x.$shouldOverrideDefaultCharacterSelection(b,!0))return c.preventDefault(),x.$moveCharacter(b,d,!0),!0;break;case "keyArrowRight":d=c.shiftKey;if(x.$shouldOverrideDefaultCharacterSelection(b,!1))return c.preventDefault(),x.$moveCharacter(b,d,!1),
22
- !0;break;case "keyBackspace":return c.preventDefault(),{anchor:c}=b,b.isCollapsed()&&0===c.offset&&0<("element"===c.type?c.getNode():c.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),c.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return c.preventDefault(),a.execCommand(c.shiftKey?
23
- "outdentContent":"indentContent");case "keyEscape":return a.blur(),!0;case "copy":return F(c,a),!0;case "cut":return E(c,a),!0;case "paste":return G(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);I(a,e);return f},[a]);J(a)}module.exports=function(a,e,f){K(a,f);B(a,e)};
7
+ var d=require("@lexical/history"),e=require("react"),g=require("@lexical/dragon"),h=require("@lexical/rich-text"),k=require("@lexical/utils");function l(a,b,c=1E3){const f=e.useMemo(()=>b||d.createEmptyHistoryState(),[b]);e.useEffect(()=>d.registerHistory(a,f,c),[c,a,f])}function m(a,b,c=1E3){return l(a,b,c)}var n="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;
8
+ function p(a,b){n(()=>k.mergeRegister(h.registerRichText(a,b),g.registerDragonSupport(a)),[a])}module.exports=function(a,b,c){p(a,c);m(a,b)};
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Dominic Gannaway
3
+ Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -3,5 +3,7 @@
3
3
  *
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
  */
7
- module.exports=function(...a){return()=>{a.forEach(b=>b())}};
8
+
9
+ export default function LexicalAutoFocusPlugin(): null;
@@ -6,6 +6,9 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
+ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
+ var react = require('react');
11
+
9
12
  /**
10
13
  * Copyright (c) Meta Platforms, Inc. and affiliates.
11
14
  *
@@ -14,10 +17,12 @@
14
17
  *
15
18
  *
16
19
  */
17
- function withSubscriptions(...func) {
18
- return () => {
19
- func.forEach(f => f());
20
- };
20
+ function LexicalAutoFocusPlugin() {
21
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
22
+ react.useEffect(() => {
23
+ editor.focus();
24
+ }, [editor]);
25
+ return null;
21
26
  }
22
27
 
23
- module.exports = withSubscriptions;
28
+ module.exports = LexicalAutoFocusPlugin;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict'
8
+ const LexicalAutoFocusPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalAutoFocusPlugin.dev.js') : require('./LexicalAutoFocusPlugin.prod.js')
9
+ module.exports = LexicalAutoFocusPlugin;
@@ -7,4 +7,4 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- declare export default function LexicalAutoFormatterPlugin(): React$Node;
10
+ declare export default function LexicalAutoFocusPlugin(): null;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ var b=require("@lexical/react/LexicalComposerContext"),c=require("react");module.exports=function(){const [a]=b.useLexicalComposerContext();c.useEffect(()=>{a.focus()},[a]);return null};
@@ -6,10 +6,10 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
+ var link = require('@lexical/link');
9
10
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
- var withSubscriptions = require('@lexical/react/withSubscriptions');
11
+ var utils = require('@lexical/utils');
11
12
  var lexical = require('lexical');
12
- var AutoLinkNode = require('lexical/AutoLinkNode');
13
13
  var react = require('react');
14
14
 
15
15
  /**
@@ -59,7 +59,6 @@ function handleLinkCreation(node, matchers, onChange) {
59
59
  let text = nodeText;
60
60
  let textOffset = 0;
61
61
  let lastNode = node;
62
- let lastNodeOffset = 0;
63
62
  let match;
64
63
 
65
64
  while ((match = findFirstMatch(text, matchers)) && match !== null) {
@@ -92,18 +91,16 @@ function handleLinkCreation(node, matchers, onChange) {
92
91
 
93
92
  if (contentBeforeMatchIsValid && contentAfterMatchIsValid) {
94
93
  let middleNode;
95
- const lastNodeMatchOffset = offset - lastNodeOffset;
96
94
 
97
- if (lastNodeMatchOffset === 0) {
95
+ if (matchOffset === 0) {
98
96
  [middleNode, lastNode] = lastNode.splitText(matchLength);
99
97
  } else {
100
- [, middleNode, lastNode] = lastNode.splitText(lastNodeMatchOffset, lastNodeMatchOffset + matchLength);
98
+ [, middleNode, lastNode] = lastNode.splitText(matchOffset, matchOffset + matchLength);
101
99
  }
102
100
 
103
- const linkNode = AutoLinkNode.$createAutoLinkNode(match.url);
101
+ const linkNode = link.$createAutoLinkNode(match.url);
104
102
  linkNode.append(lexical.$createTextNode(match.text));
105
103
  middleNode.replace(linkNode);
106
- lastNodeOffset = lastNodeMatchOffset + matchLength;
107
104
  onChange(match.url, null);
108
105
  }
109
106
 
@@ -160,12 +157,12 @@ function handleBadNeighbors(textNode, onChange) {
160
157
  const nextSibling = textNode.getNextSibling();
161
158
  const text = textNode.getTextContent();
162
159
 
163
- if (AutoLinkNode.$isAutoLinkNode(previousSibling) && !text.startsWith(' ')) {
160
+ if (link.$isAutoLinkNode(previousSibling) && !text.startsWith(' ')) {
164
161
  replaceWithChildren(previousSibling);
165
162
  onChange(null, previousSibling.getURL());
166
163
  }
167
164
 
168
- if (AutoLinkNode.$isAutoLinkNode(nextSibling) && !text.endsWith(' ')) {
165
+ if (link.$isAutoLinkNode(nextSibling) && !text.endsWith(' ')) {
169
166
  replaceWithChildren(nextSibling);
170
167
  onChange(null, nextSibling.getURL());
171
168
  }
@@ -185,7 +182,7 @@ function replaceWithChildren(node) {
185
182
 
186
183
  function useAutoLink(editor, matchers, onChange) {
187
184
  react.useEffect(() => {
188
- if (!editor.hasNodes([AutoLinkNode.AutoLinkNode])) {
185
+ if (!editor.hasNodes([link.AutoLinkNode])) {
189
186
  {
190
187
  throw Error(`LexicalAutoLinkPlugin: AutoLinkNode, TableCellNode or TableRowNode not registered on editor`);
191
188
  }
@@ -197,19 +194,19 @@ function useAutoLink(editor, matchers, onChange) {
197
194
  }
198
195
  };
199
196
 
200
- return withSubscriptions(editor.addNodeTransform(lexical.TextNode, textNode => {
197
+ return utils.mergeRegister(editor.registerNodeTransform(lexical.TextNode, textNode => {
201
198
  const parent = textNode.getParentOrThrow();
202
199
 
203
- if (AutoLinkNode.$isAutoLinkNode(parent)) {
200
+ if (link.$isAutoLinkNode(parent)) {
204
201
  handleLinkEdit(parent, matchers, onChangeWrapped);
205
- } else {
202
+ } else if (!link.$isLinkNode(parent)) {
206
203
  if (textNode.isSimpleText()) {
207
204
  handleLinkCreation(textNode, matchers, onChangeWrapped);
208
205
  }
209
206
 
210
207
  handleBadNeighbors(textNode, onChangeWrapped);
211
208
  }
212
- }), editor.addNodeTransform(AutoLinkNode.AutoLinkNode, linkNode => {
209
+ }), editor.registerNodeTransform(link.AutoLinkNode, linkNode => {
213
210
  handleLinkEdit(linkNode, matchers, onChangeWrapped);
214
211
  }));
215
212
  }, [editor, matchers, onChange]);
@@ -4,9 +4,9 @@
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/react/LexicalComposerContext"),n=require("@lexical/react/withSubscriptions"),q=require("lexical"),v=require("lexical/AutoLinkNode"),w=require("react");function x(a,b){for(let c=0;c<b.length;c++){const d=b[c](a);if(d)return d}return null}function y(a){a=a.getPreviousSibling();q.$isElementNode(a)&&(a=a.getLastDescendant());return null===a||q.$isLineBreakNode(a)||q.$isTextNode(a)&&a.getTextContent().endsWith(" ")}
8
- function C(a){a=a.getNextSibling();q.$isElementNode(a)&&(a=a.getFirstDescendant());return null===a||q.$isLineBreakNode(a)||q.$isTextNode(a)&&a.getTextContent().startsWith(" ")}
9
- function D(a,b,c){var d=a.getChildren();const e=d.length;for(let f=0;f<e;f++){const k=d[f];if(!q.$isTextNode(k)||!k.isSimpleText()){E(a);c(null,a.getURL());return}}d=a.getTextContent();b=x(d,b);null===b||b.text!==d?(E(a),c(null,a.getURL())):y(a)&&C(a)?(d=a.getURL(),null!==b&&d!==b.url&&(a.setURL(b.url),c(b.url,d))):(E(a),c(null,a.getURL()))}function E(a){const b=a.getChildren();var c=b.length;for(--c;0<=c;c--)a.insertAfter(b[c]);a.remove();return b.map(d=>d.getLatest())}
10
- function F(a,b,c){w.useEffect(()=>{if(!a.hasNodes([v.AutoLinkNode]))throw Error("Minified Lexical error #53; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");const d=(...e)=>{c&&c(...e)};return n(a.addNodeTransform(q.TextNode,e=>{var f=e.getParentOrThrow();if(v.$isAutoLinkNode(f))D(f,b,d);else{if(e.isSimpleText()){f=e.getTextContent();const G=f.length;let u=f,z=0,r=e;for(var k=0,g;(g=x(u,b))&&null!==g;){var t=g.index,l=
11
- z+t;const p=g.length;let A;A=0<l?" "===f[l-1]:y(e);let B;B=l+p<G?" "===f[l+p]:C(e);if(A&&B){var m=void 0;k=l-k;0===k?[m,r]=r.splitText(p):[,m,r]=r.splitText(k,k+p);l=v.$createAutoLinkNode(g.url);l.append(q.$createTextNode(g.text));m.replace(l);k+=p;d(g.url,null)}t+=p;u=u.substring(t);z+=t}}g=e.getPreviousSibling();m=e.getNextSibling();e=e.getTextContent();v.$isAutoLinkNode(g)&&!e.startsWith(" ")&&(E(g),d(null,g.getURL()));v.$isAutoLinkNode(m)&&!e.endsWith(" ")&&(E(m),d(null,m.getURL()))}}),a.addNodeTransform(v.AutoLinkNode,
12
- e=>{D(e,b,d)}))},[a,b,c])}module.exports=function({matchers:a,onChange:b}){const [c]=h.useLexicalComposerContext();F(c,a,b);return null};
7
+ var h=require("@lexical/link"),k=require("@lexical/react/LexicalComposerContext"),p=require("@lexical/utils"),v=require("lexical"),w=require("react");function x(a,b){for(let c=0;c<b.length;c++){const d=b[c](a);if(d)return d}return null}function y(a){a=a.getPreviousSibling();v.$isElementNode(a)&&(a=a.getLastDescendant());return null===a||v.$isLineBreakNode(a)||v.$isTextNode(a)&&a.getTextContent().endsWith(" ")}
8
+ function A(a){a=a.getNextSibling();v.$isElementNode(a)&&(a=a.getFirstDescendant());return null===a||v.$isLineBreakNode(a)||v.$isTextNode(a)&&a.getTextContent().startsWith(" ")}
9
+ function B(a,b,c){var d=a.getChildren();const e=d.length;for(let g=0;g<e;g++){const f=d[g];if(!v.$isTextNode(f)||!f.isSimpleText()){C(a);c(null,a.getURL());return}}d=a.getTextContent();b=x(d,b);null===b||b.text!==d?(C(a),c(null,a.getURL())):y(a)&&A(a)?(d=a.getURL(),null!==b&&d!==b.url&&(a.setURL(b.url),c(b.url,d))):(C(a),c(null,a.getURL()))}function C(a){const b=a.getChildren();var c=b.length;for(--c;0<=c;c--)a.insertAfter(b[c]);a.remove();return b.map(d=>d.getLatest())}
10
+ function D(a,b,c){w.useEffect(()=>{if(!a.hasNodes([h.AutoLinkNode]))throw Error("Minified Lexical error #53; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");const d=(...e)=>{c&&c(...e)};return p.mergeRegister(a.registerNodeTransform(v.TextNode,e=>{var g=e.getParentOrThrow();if(h.$isAutoLinkNode(g))B(g,b,d);else if(!h.$isLinkNode(g)){if(e.isSimpleText()){g=e.getTextContent();const E=g.length;let u=g,z=0,t=e;for(var f;(f=
11
+ x(u,b))&&null!==f;){var l=f.index,n=z+l;const q=f.length;var r=void 0;r=0<n?" "===g[n-1]:y(e);n=n+q<E?" "===g[n+q]:A(e);if(r&&n){var m=void 0;0===l?[m,t]=t.splitText(q):[,m,t]=t.splitText(l,l+q);r=h.$createAutoLinkNode(f.url);r.append(v.$createTextNode(f.text));m.replace(r);d(f.url,null)}l+=q;u=u.substring(l);z+=l}}f=e.getPreviousSibling();m=e.getNextSibling();e=e.getTextContent();h.$isAutoLinkNode(f)&&!e.startsWith(" ")&&(C(f),d(null,f.getURL()));h.$isAutoLinkNode(m)&&!e.endsWith(" ")&&(C(m),d(null,
12
+ m.getURL()))}}),a.registerNodeTransform(h.AutoLinkNode,e=>{B(e,b,d)}))},[a,b,c])}module.exports=function({matchers:a,onChange:b}){const [c]=k.useLexicalComposerContext();D(c,a,b);return null};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ import {$ReadOnly} from 'utility-types';
10
+ type Props = $ReadOnly<{
11
+ scrollRef: { current: HTMLElement | null };
12
+ }>;
13
+ export default function LexicalAutoScrollPlugin(props: Props): null;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict';
8
+
9
+ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
+ var lexical = require('lexical');
11
+ var react = require('react');
12
+
13
+ /**
14
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ *
20
+ */
21
+ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
22
+
23
+ /**
24
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
25
+ *
26
+ * This source code is licensed under the MIT license found in the
27
+ * LICENSE file in the root directory of this source tree.
28
+ *
29
+ *
30
+ */
31
+ const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
32
+ var useLayoutEffect = useLayoutEffectImpl;
33
+
34
+ /**
35
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
36
+ *
37
+ * This source code is licensed under the MIT license found in the
38
+ * LICENSE file in the root directory of this source tree.
39
+ *
40
+ *
41
+ */
42
+ function LexicalAutoScrollPlugin({
43
+ scrollRef
44
+ }) {
45
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
46
+ useLayoutEffect(() => {
47
+ return editor.registerUpdateListener(({
48
+ tags,
49
+ editorState
50
+ }) => {
51
+ const scrollElement = scrollRef.current;
52
+
53
+ if (scrollElement === null || !tags.has('scroll-into-view')) {
54
+ return;
55
+ }
56
+
57
+ const selection = editorState.read(() => lexical.$getSelection());
58
+
59
+ if (!lexical.$isRangeSelection(selection) || !selection.isCollapsed()) {
60
+ return;
61
+ }
62
+
63
+ const anchorElement = editor.getElementByKey(selection.anchor.key);
64
+
65
+ if (anchorElement === null) {
66
+ return;
67
+ }
68
+
69
+ const scrollRect = scrollElement.getBoundingClientRect();
70
+ const rect = anchorElement.getBoundingClientRect();
71
+
72
+ if (rect.bottom > scrollRect.bottom) {
73
+ anchorElement.scrollIntoView(false);
74
+ } else if (rect.top < scrollRect.top) {
75
+ anchorElement.scrollIntoView();
76
+ }
77
+ });
78
+ }, [editor, scrollRef]);
79
+ return null;
80
+ }
81
+
82
+ module.exports = LexicalAutoScrollPlugin;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict'
8
+ const LexicalAutoScrollPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalAutoScrollPlugin.dev.js') : require('./LexicalAutoScrollPlugin.prod.js')
9
+ module.exports = LexicalAutoScrollPlugin;
@@ -4,9 +4,9 @@
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
+ * @flow strict
7
8
  */
8
-
9
- type UnsubscribeFn = () => void;
10
- export default function withSubscriptions(
11
- ...unsubscribe: Array<UnsubscribeFn>
12
- ): () => void;
9
+ type Props = $ReadOnly<{
10
+ scrollRef: {current: HTMLElement | null},
11
+ }>;
12
+ declare export default function LexicalAutoScrollPlugin(props: Props): React$Node;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ var e=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),h=require("react"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
8
+ module.exports=function({scrollRef:g}){const [d]=e.useLexicalComposerContext();k(()=>d.registerUpdateListener(({tags:a,editorState:c})=>{var b=g.current;null!==b&&a.has("scroll-into-view")&&(a=c.read(()=>f.$getSelection()),f.$isRangeSelection(a)&&a.isCollapsed()&&(a=d.getElementByKey(a.anchor.key),null!==a&&(b=b.getBoundingClientRect(),c=a.getBoundingClientRect(),c.bottom>b.bottom?a.scrollIntoView(!1):c.top<b.top&&a.scrollIntoView())))}),[d,g]);return null};
@@ -8,11 +8,10 @@
8
8
 
9
9
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
10
  var React = require('react');
11
- var withSubscriptions = require('@lexical/react/withSubscriptions');
11
+ var overflow = require('@lexical/overflow');
12
12
  var text = require('@lexical/text');
13
13
  var utils = require('@lexical/utils');
14
14
  var lexical = require('lexical');
15
- var OverflowNode = require('lexical/OverflowNode');
16
15
 
17
16
  /**
18
17
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -29,7 +28,7 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
29
28
  remainingCharacters = characters => {}
30
29
  } = optional;
31
30
  React.useEffect(() => {
32
- if (!editor.hasNodes([OverflowNode.OverflowNode])) {
31
+ if (!editor.hasNodes([overflow.OverflowNode])) {
33
32
  {
34
33
  throw Error(`useCharacterLimit: OverflowNode not registered on editor`);
35
34
  }
@@ -38,9 +37,9 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
38
37
  React.useEffect(() => {
39
38
  let text$1 = editor.getEditorState().read(text.$rootTextContentCurry);
40
39
  let lastComputedTextLength = 0;
41
- return withSubscriptions(editor.addListener('textcontent', currentText => {
40
+ return utils.mergeRegister(editor.registerTextContentListener(currentText => {
42
41
  text$1 = currentText;
43
- }), editor.addListener('update', ({
42
+ }), editor.registerUpdateListener(({
44
43
  dirtyLeaves
45
44
  }) => {
46
45
  const isComposing = editor.isComposing();
@@ -76,7 +75,7 @@ function findOffset(text, maxCharacters, strlen) {
76
75
 
77
76
  if (typeof Segmenter === 'function') {
78
77
  const segmenter = new Segmenter();
79
- const graphemes = segmenter.segment(text); // eslint-disable-next-line no-for-of-loops/no-for-of-loops
78
+ const graphemes = segmenter.segment(text);
80
79
 
81
80
  for (const {
82
81
  segment: grapheme
@@ -120,7 +119,7 @@ function $wrapOverflowedNodes(offset) {
120
119
  node
121
120
  } = dfsNodes[i];
122
121
 
123
- if (OverflowNode.$isOverflowNode(node)) {
122
+ if (overflow.$isOverflowNode(node)) {
124
123
  const previousLength = accumulatedLength;
125
124
  const nextLength = accumulatedLength + node.getTextContentSize();
126
125
 
@@ -157,7 +156,7 @@ function $wrapOverflowedNodes(offset) {
157
156
  const previousAccumulatedLength = accumulatedLength;
158
157
  accumulatedLength += node.getTextContentSize();
159
158
 
160
- if (accumulatedLength > offset && !OverflowNode.$isOverflowNode(node.getParent())) {
159
+ if (accumulatedLength > offset && !overflow.$isOverflowNode(node.getParent())) {
161
160
  const previousSelection = lexical.$getSelection();
162
161
  let overflowNode; // For simple text we can improve the limit accuracy by splitting the TextNode
163
162
  // on the split point
@@ -180,7 +179,7 @@ function $wrapOverflowedNodes(offset) {
180
179
  }
181
180
 
182
181
  function $wrapNode(node) {
183
- const overflowNode = OverflowNode.$createOverflowNode();
182
+ const overflowNode = overflow.$createOverflowNode();
184
183
  node.insertBefore(overflowNode);
185
184
  overflowNode.append(node);
186
185
  return overflowNode;
@@ -201,7 +200,7 @@ function $unwrapNode(node) {
201
200
  function mergePrevious(overflowNode) {
202
201
  const previousNode = overflowNode.getPreviousSibling();
203
202
 
204
- if (!OverflowNode.$isOverflowNode(previousNode)) {
203
+ if (!overflow.$isOverflowNode(previousNode)) {
205
204
  return;
206
205
  }
207
206
 
@@ -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
- var m=require("@lexical/react/LexicalComposerContext"),u=require("react"),v=require("@lexical/react/withSubscriptions"),z=require("@lexical/text"),B=require("@lexical/utils"),C=require("lexical"),E=require("lexical/OverflowNode");
8
- function F(b,c,n=Object.freeze({})){const {strlen:g=d=>d.length,remainingCharacters:q=()=>{}}=n;u.useEffect(()=>{if(!b.hasNodes([E.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.");},[b]);u.useEffect(()=>{let d=b.getEditorState().read(z.$rootTextContentCurry),e=0;return v(b.addListener("textcontent",p=>{d=p}),b.addListener("update",({dirtyLeaves:p})=>{var w=b.isComposing();
9
- p=0<p.size;if(!w&&p){w=g(d);p=w>c||null!==e&&e>c;q(c-w);if(null===e||p){const r=G(d,c,g);b.update(()=>{const A=B.$dfs(),K=A.length;let x=0;for(let y=0;y<K;y+=1){var {node:a}=A[y];if(E.$isOverflowNode(a)){var f=x;if(x+a.getTextContentSize()<=r){var h=a.getParent();f=a.getPreviousSibling();var k=a.getNextSibling();H(a);a=C.$getSelection();!C.$isRangeSelection(a)||a.anchor.getNode().isAttached()&&a.focus.getNode().isAttached()||(C.$isTextNode(f)?f.select():C.$isTextNode(k)?k.select():null!==h&&h.select())}else f<
10
- r&&(h=a.getFirstDescendant(),k=null!==h?h.getTextContentSize():0,f+=k,h=C.$isTextNode(h)&&h.isSimpleText(),f=f<=r,(h||f)&&H(a))}else if(C.$isLeafNode(a)&&(f=x,x+=a.getTextContentSize(),x>r&&!E.$isOverflowNode(a.getParent())&&(h=C.$getSelection(),f<r&&C.$isTextNode(a)&&a.isSimpleText()?([,a]=a.splitText(r-f),a=I(a)):a=I(a),null!==h&&C.$setSelection(h),f=a.getPreviousSibling(),E.$isOverflowNode(f)))){k=a.getFirstChild();var t=f.getChildren();h=t.length;if(null===k)a.append(...t);else for(var l=0;l<
11
- h;l++)k.insertBefore(t[l]);l=C.$getSelection();if(C.$isRangeSelection(l)){k=l.anchor;t=k.getNode();l=l.focus;const D=k.getNode();t.is(f)?k.set(a.getKey(),k.offset,"element"):t.is(a)&&k.set(a.getKey(),h+k.offset,"element");D.is(f)?l.set(a.getKey(),l.offset,"element"):D.is(a)&&l.set(a.getKey(),h+l.offset,"element")}f.remove()}}},{tag:"history-merge"})}e=w}}))},[b,c,q,g])}
12
- function G(b,c,n){var g=Intl.Segmenter;let q=0;var d=0;if("function"===typeof g){b=(new g).segment(b);for(var {segment:e}of b){d+=n(e);if(d>c)break;q+=e.length}}else for(e=Array.from(b),b=e.length,g=0;g<b;g++){const p=e[g];d+=n(p);if(d>c)break;q+=p.length}return q}function I(b){const c=E.$createOverflowNode();b.insertBefore(c);c.append(b);return c}function H(b){const c=b.getChildren(),n=c.length;for(let g=0;g<n;g++)b.insertBefore(c[g]);b.remove();return 0<n?c[n-1]:null}let J=null;
13
- module.exports=function({charset:b="UTF-16"}){const [c]=m.useLexicalComposerContext(),[n,g]=u.useState(0),q=u.useMemo(()=>({remainingCharacters:g,strlen:d=>{if("UTF-8"===b){if(void 0===window.TextEncoder)var e=null;else null===J&&(J=new window.TextEncoder),e=J;null===e?(e=encodeURIComponent(d).match(/%[89ABab]/g),d=d.length+(e?e.length:0)):d=e.encode(d).length;return d}if("UTF-16"===b)return d.length;throw Error("Unrecognized charset");}}),[b]);F(c,5,q);return u.createElement("span",{className:`characters-limit ${0>
7
+ var m=require("@lexical/react/LexicalComposerContext"),u=require("react"),v=require("@lexical/overflow"),z=require("@lexical/text"),A=require("@lexical/utils"),C=require("lexical");
8
+ function D(b,c,n=Object.freeze({})){const {strlen:g=d=>d.length,remainingCharacters:q=()=>{}}=n;u.useEffect(()=>{if(!b.hasNodes([v.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.");},[b]);u.useEffect(()=>{let d=b.getEditorState().read(z.$rootTextContentCurry),e=0;return A.mergeRegister(b.registerTextContentListener(p=>{d=p}),b.registerUpdateListener(({dirtyLeaves:p})=>
9
+ {var w=b.isComposing();p=0<p.size;if(!w&&p){w=g(d);p=w>c||null!==e&&e>c;q(c-w);if(null===e||p){const r=F(d,c,g);b.update(()=>{const B=A.$dfs(),J=B.length;let x=0;for(let y=0;y<J;y+=1){var {node:a}=B[y];if(v.$isOverflowNode(a)){var f=x;if(x+a.getTextContentSize()<=r){var h=a.getParent();f=a.getPreviousSibling();var k=a.getNextSibling();G(a);a=C.$getSelection();!C.$isRangeSelection(a)||a.anchor.getNode().isAttached()&&a.focus.getNode().isAttached()||(C.$isTextNode(f)?f.select():C.$isTextNode(k)?k.select():
10
+ null!==h&&h.select())}else f<r&&(h=a.getFirstDescendant(),k=null!==h?h.getTextContentSize():0,f+=k,h=C.$isTextNode(h)&&h.isSimpleText(),f=f<=r,(h||f)&&G(a))}else if(C.$isLeafNode(a)&&(f=x,x+=a.getTextContentSize(),x>r&&!v.$isOverflowNode(a.getParent())&&(h=C.$getSelection(),f<r&&C.$isTextNode(a)&&a.isSimpleText()?([,a]=a.splitText(r-f),a=H(a)):a=H(a),null!==h&&C.$setSelection(h),f=a.getPreviousSibling(),v.$isOverflowNode(f)))){k=a.getFirstChild();var t=f.getChildren();h=t.length;if(null===k)a.append(...t);
11
+ else for(var l=0;l<h;l++)k.insertBefore(t[l]);l=C.$getSelection();if(C.$isRangeSelection(l)){k=l.anchor;t=k.getNode();l=l.focus;const E=k.getNode();t.is(f)?k.set(a.getKey(),k.offset,"element"):t.is(a)&&k.set(a.getKey(),h+k.offset,"element");E.is(f)?l.set(a.getKey(),l.offset,"element"):E.is(a)&&l.set(a.getKey(),h+l.offset,"element")}f.remove()}}},{tag:"history-merge"})}e=w}}))},[b,c,q,g])}
12
+ function F(b,c,n){var g=Intl.Segmenter;let q=0;var d=0;if("function"===typeof g){b=(new g).segment(b);for(var {segment:e}of b){d+=n(e);if(d>c)break;q+=e.length}}else for(e=Array.from(b),b=e.length,g=0;g<b;g++){const p=e[g];d+=n(p);if(d>c)break;q+=p.length}return q}function H(b){const c=v.$createOverflowNode();b.insertBefore(c);c.append(b);return c}function G(b){const c=b.getChildren(),n=c.length;for(let g=0;g<n;g++)b.insertBefore(c[g]);b.remove();return 0<n?c[n-1]:null}let I=null;
13
+ module.exports=function({charset:b="UTF-16"}){const [c]=m.useLexicalComposerContext(),[n,g]=u.useState(0),q=u.useMemo(()=>({remainingCharacters:g,strlen:d=>{if("UTF-8"===b){if(void 0===window.TextEncoder)var e=null;else null===I&&(I=new window.TextEncoder),e=I;null===e?(e=encodeURIComponent(d).match(/%[89ABab]/g),d=d.length+(e?e.length:0)):d=e.encode(d).length;return d}if("UTF-16"===b)return d.length;throw Error("Unrecognized charset");}}),[b]);D(c,5,q);return u.createElement("span",{className:`characters-limit ${0>
14
14
  n?"characters-limit-exceeded":""}`},n)};
@@ -44,27 +44,23 @@ function LexicalClearEditorPlugin({
44
44
  }) {
45
45
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
46
46
  useLayoutEffect(() => {
47
- return editor.addListener('command', (type, payload) => {
48
- if (type === 'clearEditor') {
49
- editor.update(() => {
50
- if (onClear == null) {
51
- const root = lexical.$getRoot();
52
- const selection = lexical.$getSelection();
53
- const paragraph = lexical.$createParagraphNode();
54
- root.clear();
55
- root.append(paragraph);
47
+ return editor.registerCommand(lexical.CLEAR_EDITOR_COMMAND, payload => {
48
+ editor.update(() => {
49
+ if (onClear == null) {
50
+ const root = lexical.$getRoot();
51
+ const selection = lexical.$getSelection();
52
+ const paragraph = lexical.$createParagraphNode();
53
+ root.clear();
54
+ root.append(paragraph);
56
55
 
57
- if (selection !== null) {
58
- paragraph.select();
59
- }
60
- } else {
61
- onClear();
56
+ if (selection !== null) {
57
+ paragraph.select();
62
58
  }
63
- });
64
- return true;
65
- }
66
-
67
- return false;
59
+ } else {
60
+ onClear();
61
+ }
62
+ });
63
+ return true;
68
64
  }, 0);
69
65
  }, [editor, onClear]);
70
66
  return null;
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var a=require("@lexical/react/LexicalComposerContext"),d=require("lexical"),g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;
8
- module.exports=function({onClear:b}){const [c]=a.useLexicalComposerContext();h(()=>c.addListener("command",k=>"clearEditor"===k?(c.update(()=>{if(null==b){const e=d.$getRoot(),l=d.$getSelection(),f=d.$createParagraphNode();e.clear();e.append(f);null!==l&&f.select()}else b()}),!0):!1,0),[c,b]);return null};
8
+ module.exports=function({onClear:b}){const [c]=a.useLexicalComposerContext();h(()=>c.registerCommand(d.CLEAR_EDITOR_COMMAND,()=>{c.update(()=>{if(null==b){const e=d.$getRoot(),k=d.$getSelection(),f=d.$createParagraphNode();e.clear();e.append(f);null!==k&&f.select()}else b()});return!0},0),[c,b]);return null};
@@ -29,12 +29,12 @@ export interface Provider {
29
29
  on(type: 'status', cb: (arg0: {status: string}) => void): void;
30
30
  // $FlowFixMe: temp
31
31
  on(type: 'update', cb: (arg0: any) => void): void;
32
- on(type: 'reload', cb: (doc: Doc) => boolean): void;
32
+ on(type: 'reload', cb: (doc: Doc) => boolean): void;
33
33
  off(type: 'sync', cb: (isSynced: boolean) => void): void;
34
34
  // $FlowFixMe: temp
35
35
  off(type: 'update', cb: (arg0: any) => void): void;
36
36
  off(type: 'status', cb: (arg0: {status: string}) => void): void;
37
- off(type: 'reload', cb: (doc: Doc) => boolean): void;
37
+ off(type: 'reload', cb: (doc: Doc) => boolean): void;
38
38
  }
39
39
  type CollaborationContextType = {
40
40
  clientID: number;
@@ -42,7 +42,10 @@ type CollaborationContextType = {
42
42
  name: string;
43
43
  yjsDocMap: Map<string, Doc>;
44
44
  };
45
- export type ProviderFactory = (id: string, yjsDocMap: Map<string, Doc>) => Provider;
45
+ export type ProviderFactory = (
46
+ id: string,
47
+ yjsDocMap: Map<string, Doc>,
48
+ ) => Provider;
46
49
  export function CollaborationPlugin(arg0: {
47
50
  id: string;
48
51
  providerFactory: ProviderFactory;