@lexical/react 0.1.8 → 0.1.9

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 (53) hide show
  1. package/DEPRECATED_useLexical.prod.js +1 -1
  2. package/DEPRECATED_useLexicalAutoFormatter.dev.js +142 -55
  3. package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -16
  4. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +1 -2
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +3 -3
  7. package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
  8. package/DEPRECATED_useLexicalEditor.prod.js +1 -1
  9. package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
  10. package/DEPRECATED_useLexicalHistory.dev.js +17 -14
  11. package/DEPRECATED_useLexicalHistory.prod.js +7 -7
  12. package/DEPRECATED_useLexicalList.prod.js +1 -1
  13. package/DEPRECATED_useLexicalPlainText.dev.js +46 -23
  14. package/DEPRECATED_useLexicalPlainText.prod.js +16 -16
  15. package/DEPRECATED_useLexicalRichText.dev.js +47 -24
  16. package/DEPRECATED_useLexicalRichText.prod.js +27 -27
  17. package/LexicalAutoFormatterPlugin.dev.js +142 -55
  18. package/LexicalAutoFormatterPlugin.prod.js +19 -17
  19. package/LexicalAutoLinkPlugin.prod.js +4 -4
  20. package/LexicalBootstrapPlugin.dev.js +0 -2
  21. package/LexicalBootstrapPlugin.prod.js +2 -2
  22. package/LexicalCharacterLimitPlugin.dev.js +1 -2
  23. package/LexicalCharacterLimitPlugin.prod.js +3 -3
  24. package/LexicalCollaborationPlugin.dev.js +11 -26
  25. package/LexicalCollaborationPlugin.prod.js +7 -8
  26. package/LexicalComposer.prod.js +1 -1
  27. package/LexicalComposerContext.prod.js +1 -1
  28. package/LexicalContentEditable.prod.js +1 -1
  29. package/LexicalHashtagPlugin.prod.js +1 -1
  30. package/LexicalHistoryPlugin.dev.js +17 -14
  31. package/LexicalHistoryPlugin.prod.js +6 -6
  32. package/LexicalHorizontalRuleNode.dev.js +66 -0
  33. package/LexicalHorizontalRuleNode.js +9 -0
  34. package/LexicalHorizontalRuleNode.prod.js +8 -0
  35. package/LexicalLinkPlugin.dev.js +0 -1
  36. package/LexicalLinkPlugin.prod.js +3 -3
  37. package/LexicalListPlugin.prod.js +1 -1
  38. package/LexicalNestedComposer.prod.js +1 -1
  39. package/LexicalOnChangePlugin.prod.js +1 -1
  40. package/LexicalPlainTextPlugin.dev.js +29 -9
  41. package/LexicalPlainTextPlugin.prod.js +12 -11
  42. package/LexicalRichTextPlugin.dev.js +30 -10
  43. package/LexicalRichTextPlugin.prod.js +16 -16
  44. package/LexicalTablePlugin.dev.js +20 -38
  45. package/LexicalTablePlugin.prod.js +3 -3
  46. package/LexicalTreeView.prod.js +1 -1
  47. package/package.json +5 -4
  48. package/useLexicalDecoratorMap.prod.js +1 -1
  49. package/useLexicalIsTextContentEmpty.prod.js +1 -1
  50. package/withSubscriptions.prod.js +1 -1
  51. package/LexicalHorizontalRulePlugin.dev.js +0 -51
  52. package/LexicalHorizontalRulePlugin.js +0 -9
  53. package/LexicalHorizontalRulePlugin.prod.js +0 -7
@@ -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
- 'use strict';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(" ")}
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
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
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("LexicalAutoLinkPlugin: AutoLinkNode, TableCellNode or TableRowNode not registered on editor");const d=(...e)=>{c&&c(...e)};return n(a.addTransform(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=z+t;const p=g.length;let A;A=0<l?" "===f[l-1]:y(e);let B;B=l+p<G?
11
- " "===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.addTransform(v.AutoLinkNode,e=>{D(e,b,d)}))},[a,b,c])}
12
- module.exports=function({matchers:a,onChange:b}){const [c]=h.useLexicalComposerContext();F(c,a,b);return null};
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.addTransform(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=z+t;
11
+ 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.addTransform(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};
@@ -72,14 +72,12 @@ function defaultClearEditor(editor) {
72
72
 
73
73
  function initEditor(editor, initialPayloadFn) {
74
74
  editor.update(() => {
75
- lexical.$log('initEditor');
76
75
  initialPayloadFn(editor);
77
76
  });
78
77
  }
79
78
 
80
79
  function clearEditor(editor, clearEditorFn, callbackFn) {
81
80
  editor.update(() => {
82
- lexical.$log('clearEditor');
83
81
  clearEditorFn(editor);
84
82
  }, {
85
83
  onUpdate: callbackFn
@@ -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 d=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),f=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;function k(a,b){const c=e.$createParagraphNode();a.append(c);a=document.activeElement;(null!==e.$getSelection()||null!==a&&a===b.getRootElement())&&c.select()}function l(a){const b=e.$getRoot();null===b.getFirstChild()&&k(b,a)}
8
- function m(a){const b=e.$getRoot();b.clear();k(b,a)}function n(a,b){a.update(()=>{e.$log("initEditor");b(a)})}function p(a,b,c){a.update(()=>{e.$log("clearEditor");b(a)},{onUpdate:c})}function q(a,b,c){h(()=>a.addListener("command",g=>"bootstrapEditor"===g?(n(a,null!=b?b:l),!0):"clearEditor"===g?(p(a,null!=c?c:m),!0):!1,0),[c,a,b])}module.exports=function({initialPayloadFn:a,clearEditorFn:b}){const [c]=d.useLexicalComposerContext();q(c,a,b);return null};
7
+ var d=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),f=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;function k(a,b){const c=e.$createParagraphNode();a.append(c);a=document.activeElement;(null!==e.$getSelection()||null!==a&&a===b.getRootElement())&&c.select()}function l(a){const b=e.$getRoot();null===b.getFirstChild()&&k(b,a)}
8
+ function m(a){const b=e.$getRoot();b.clear();k(b,a)}function n(a,b){a.update(()=>{b(a)})}function p(a,b,c){a.update(()=>{b(a)},{onUpdate:c})}function q(a,b,c){h(()=>a.addListener("command",g=>"bootstrapEditor"===g?(n(a,null!=b?b:l),!0):"clearEditor"===g?(p(a,null!=c?c:m),!0):!1,0),[c,a,b])}module.exports=function({initialPayloadFn:a,clearEditorFn:b}){const [c]=d.useLexicalComposerContext();q(c,a,b);return null};
@@ -106,10 +106,9 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
106
106
  if (lastComputedTextLength === null || textLengthAboveThreshold) {
107
107
  const offset = findOffset(text, maxCharacters, strlen);
108
108
  editor.update(() => {
109
- lexical.$log('CharacterLimit');
110
109
  $wrapOverflowedNodes(offset);
111
110
  }, {
112
- tag: 'without-history'
111
+ tag: 'history-merge'
113
112
  });
114
113
  }
115
114
 
@@ -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
- 'use strict';var l=require("@lexical/react/LexicalComposerContext"),p=require("react"),q=require("lexical"),r=require("@lexical/react/withSubscriptions"),t=require("lexical/OverflowNode");function u(a,e){for(e(a);null!==a;){if(q.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild();else{let f=null;for(;null===f&&null!==a;)f=a.getNextSibling(),a=null===f?a.getParent():f}null!==a&&(a=e(a))}}function w(){return q.$getRoot().getTextContent()}
8
- function x(a,e,f=Object.freeze({})){const {strlen:h=c=>c.length,remainingCharacters:d=()=>{}}=f;p.useEffect(()=>{if(!a.hasNodes([t.OverflowNode]))throw Error("useCharacterLimit: OverflowNode not registered on editor");},[a]);p.useEffect(()=>{let c=a.getEditorState().read(w),b=0;return r(a.addListener("textcontent",g=>{c=g}),a.addListener("update",({dirtyLeaves:g})=>{var k=a.isComposing();g=0<g.size;if(!k&&g){k=h(c);g=k>e||null!==b&&b>e;d(e-k);if(null===b||g){const n=y(c,e,h);a.update(()=>{q.$log("CharacterLimit");
9
- z(n)},{tag:"without-history"})}b=k}}))},[a,e,d,h])}function y(a,e,f){var h=Intl.Segmenter;let d=0;var c=0;if("function"===typeof h){a=(new h).segment(a);for(var {segment:b}of a){c+=f(b);if(c>e)break;d+=b.length}}else for(b=Array.from(a),a=b.length,h=0;h<a;h++){const g=b[h];c+=f(g);if(c>e)break;d+=g.length}return d}
7
+ var l=require("@lexical/react/LexicalComposerContext"),p=require("react"),q=require("lexical"),r=require("@lexical/react/withSubscriptions"),t=require("lexical/OverflowNode");function u(a,e){for(e(a);null!==a;){if(q.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild();else{let f=null;for(;null===f&&null!==a;)f=a.getNextSibling(),a=null===f?a.getParent():f}null!==a&&(a=e(a))}}function w(){return q.$getRoot().getTextContent()}
8
+ function x(a,e,f=Object.freeze({})){const {strlen:h=c=>c.length,remainingCharacters:d=()=>{}}=f;p.useEffect(()=>{if(!a.hasNodes([t.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]);p.useEffect(()=>{let c=a.getEditorState().read(w),b=0;return r(a.addListener("textcontent",g=>{c=g}),a.addListener("update",({dirtyLeaves:g})=>{var k=a.isComposing();g=0<g.size;if(!k&&
9
+ g){k=h(c);g=k>e||null!==b&&b>e;d(e-k);if(null===b||g){const n=y(c,e,h);a.update(()=>{z(n)},{tag:"history-merge"})}b=k}}))},[a,e,d,h])}function y(a,e,f){var h=Intl.Segmenter;let d=0;var c=0;if("function"===typeof h){a=(new h).segment(a);for(var {segment:b}of a){c+=f(b);if(c>e)break;d+=b.length}}else for(b=Array.from(a),a=b.length,h=0;h<a;h++){const g=b[h];c+=f(g);if(c>e)break;d+=g.length}return d}
10
10
  function z(a){const e=q.$getRoot();let f=0,h=e;u(e,d=>{if(t.$isOverflowNode(d)){var c=f;if(f+d.getTextContentSize()<=a){var b=d.getParent();c=d.getPreviousSibling();var g=d.getNextSibling();A(d);d=q.$getSelection();null===d||d.anchor.getNode().isAttached()&&d.focus.getNode().isAttached()||(q.$isTextNode(c)?c.select():q.$isTextNode(g)?g.select():null!==b&&b.select());return h}if(c<a&&(b=d.getFirstDescendant(),g=null!==b?b.getTextContentSize():0,c+=g,b=q.$isTextNode(b)&&b.isSimpleText(),c=c<=a,b||c))return A(d),
11
11
  h}else if(q.$isLeafNode(d)&&(c=f,f+=d.getTextContentSize(),f>a&&!t.$isOverflowNode(d.getParent())&&(b=q.$getSelection(),c<a&&q.$isTextNode(d)&&d.isSimpleText()?([,c]=d.splitText(a-c),c=B(c)):c=B(d),null!==b&&q.$setSelection(b),b=c,g=b.getPreviousSibling(),t.$isOverflowNode(g)))){var k=b.getFirstChild(),n=g.getChildren();c=n.length;if(null===k)b.append(...n);else for(var m=0;m<c;m++)k.insertBefore(n[m]);m=q.$getSelection();if(null!==m){k=m.anchor;n=k.getNode();m=m.focus;const v=k.getNode();n.is(g)?
12
12
  k.set(b.getKey(),k.offset,"element"):n.is(b)&&k.set(b.getKey(),c+k.offset,"element");v.is(g)?m.set(b.getKey(),m.offset,"element"):v.is(b)&&m.set(b.getKey(),c+m.offset,"element")}g.remove()}return h=d})}function B(a){const e=t.$createOverflowNode();a.insertBefore(e);e.append(a);return e}function A(a){const e=a.getChildren(),f=e.length;for(let h=0;h<f;h++)a.insertBefore(e[h]);a.remove();return 0<f?e[f-1]:null}let C=null;
@@ -32,11 +32,11 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
32
32
  } catch (e) {// Do nothing
33
33
  }
34
34
  }, [provider]);
35
- const isInitialized = React.useRef(false);
35
+ const bootstrapPropagationRef = React.useRef(true);
36
36
  React.useLayoutEffect(() => {
37
37
  return editor.addListener('command', type => {
38
38
  if (type === 'bootstrapEditor') {
39
- return !isInitialized.current;
39
+ return bootstrapPropagationRef.current;
40
40
  }
41
41
 
42
42
  return false;
@@ -58,7 +58,7 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
58
58
 
59
59
  const onSync = isSynced => {
60
60
  if (shouldBootstrap && isSynced && root.isEmpty() && root._xmlText._length === 0) {
61
- isInitialized.current = true;
61
+ bootstrapPropagationRef.current = false;
62
62
  editor.execCommand('bootstrapEditor');
63
63
  }
64
64
  };
@@ -132,31 +132,16 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
132
132
  }
133
133
  function useYjsFocusTracking(editor, provider) {
134
134
  React.useEffect(() => {
135
- const onBlur = () => {
136
- yjs.setLocalStateFocus(provider, false);
137
- };
138
-
139
- const onFocus = () => {
140
- yjs.setLocalStateFocus(provider, true);
141
- };
142
-
143
- return editor.addListener('root', (rootElement, prevRootElement) => {
144
- // Clear our old listener if the root element changes
145
- if (prevRootElement !== null) {
146
- prevRootElement.removeEventListener('blur', onBlur);
147
- prevRootElement.removeEventListener('focus', onFocus);
135
+ return editor.addListener('command', (type, payload) => {
136
+ if (type === 'focus') {
137
+ yjs.setLocalStateFocus(provider, true);
138
+ } else if (type === 'blur') {
139
+ yjs.setLocalStateFocus(provider, false);
148
140
  }
149
141
 
150
- if (rootElement !== null) {
151
- if (document.activeElement === rootElement) {
152
- onFocus();
153
- }
154
-
155
- rootElement.addEventListener('blur', onBlur);
156
- rootElement.addEventListener('focus', onFocus);
157
- }
158
- });
159
- }, [editor, provider, provider.awareness]);
142
+ return false;
143
+ }, EditorPriority);
144
+ }, [editor, provider]);
160
145
  }
161
146
  function useYjsHistory(editor, binding) {
162
147
  const undoManager = React.useMemo(() => yjs.createUndoManager(binding, binding.root.getSharedType()), [binding]);
@@ -4,11 +4,10 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var c=require("@lexical/react/LexicalComposerContext"),k=require("react"),z=require("@lexical/yjs"),A=require("react-dom");
8
- function B(b,d,a,f,g,l,r){const e=k.useMemo(()=>z.createBinding(b,a,d,f),[b,a,d,f]),m=k.useCallback(()=>{a.connect()},[a]),n=k.useCallback(()=>{try{a.disconnect()}catch(h){}},[a]),q=k.useRef(!1);k.useLayoutEffect(()=>b.addListener("command",h=>"bootstrapEditor"===h?!q.current:!1,1),[b]);k.useEffect(()=>{const {root:h}=e,{awareness:t}=a,v=({status:p})=>{b.execCommand("connected","connected"===p)},w=p=>{r&&p&&h.isEmpty()&&0===h._xmlText._length&&(q.current=!0,b.execCommand("bootstrapEditor"))},x=()=>
9
- {z.syncCursorPositions(e,a)},y=(p,u)=>{u.origin!==e&&z.syncYjsChangesToLexical(e,a,p)};z.initLocalState(a,g,l,document.activeElement===b.getRootElement());a.on("status",v);a.on("sync",w);t.on("update",x);h.getSharedType().observeDeep(y);const K=b.addListener("update",({prevEditorState:p,editorState:u,dirtyLeaves:G,dirtyElements:H,normalizedNodes:I,tags:J})=>{z.syncLexicalUpdateToYjs(e,a,p,u,H,G,I,J)});m();return()=>{n();a.off("sync",w);a.off("status",v);t.off("update",x);h.getSharedType().unobserveDeep(y);
10
- K()}},[e,l,m,n,b,g,a,r]);const L=k.useMemo(()=>A.createPortal(k.createElement("div",{ref:h=>{e.cursorsContainer=h}}),document.body),[e]);k.useEffect(()=>b.addListener("command",(h,t)=>{"toggleConnect"===h&&void 0!==m&&void 0!==n&&(t?(console.log("Collaboration connected!"),m()):(console.log("Collaboration disconnected!"),n()));return!1},0),[m,n,b]);return[L,e]}
11
- function C(b,d){k.useEffect(()=>{const a=()=>{z.setLocalStateFocus(d,!1)},f=()=>{z.setLocalStateFocus(d,!0)};return b.addListener("root",(g,l)=>{null!==l&&(l.removeEventListener("blur",a),l.removeEventListener("focus",f));null!==g&&(document.activeElement===g&&z.setLocalStateFocus(d,!0),g.addEventListener("blur",a),g.addEventListener("focus",f))})},[b,d,d.awareness])}
12
- function D(b,d){const a=k.useMemo(()=>z.createUndoManager(d,d.root.getSharedType()),[d]);k.useEffect(()=>b.addListener("command",f=>"undo"===f?(a.undo(),!0):"redo"===f?(a.redo(),!0):!1,0));return k.useCallback(()=>{a.clear()},[a])}
13
- const E=[["Cat","255,165,0"],["Dog","0,200,55"],["Rabbit","160,0,200"],["Frog","0,172,200"],["Fox","197,200,0"],["Hedgehog","31,200,0"],["Pigeon","200,0,0"],["Squirrel","200,0,148"],["Bear","255,235,0"],["Tiger","86,255,0"],["Leopard","0,255,208"],["Zebra","0,243,255"],["Wolf","0,102,255"],["Owl","147,0,255"],["Gull","255,0,153"],["Squid","0,220,255"]],F=E[Math.floor(Math.random()*(E.length-1+1))],M=k.createContext({clientID:0,color:F[1],name:F[0],yjsDocMap:new Map});
14
- function N(){return k.useContext(M)}exports.CollaborationContext=M;exports.CollaborationPlugin=function({id:b,providerFactory:d,shouldBootstrap:a}){const f=N(),{yjsDocMap:g,name:l,color:r}=f,[e]=c.useLexicalComposerContext(),m=k.useMemo(()=>d(b,g),[b,d,g]),[n,q]=B(e,b,m,g,l,r,a);f.clientID=q.clientID;D(e,q);C(e,m);return n};exports.useCollaborationContext=N;
7
+ var c=require("@lexical/react/LexicalComposerContext"),g=require("react"),z=require("@lexical/yjs"),A=require("react-dom");
8
+ function B(b,d,a,h,n,q,r){const e=g.useMemo(()=>z.createBinding(b,a,d,h),[b,a,d,h]),k=g.useCallback(()=>{a.connect()},[a]),l=g.useCallback(()=>{try{a.disconnect()}catch(f){}},[a]),p=g.useRef(!0);g.useLayoutEffect(()=>b.addListener("command",f=>"bootstrapEditor"===f?p.current:!1,1),[b]);g.useEffect(()=>{const {root:f}=e,{awareness:t}=a,v=({status:m})=>{b.execCommand("connected","connected"===m)},w=m=>{r&&m&&f.isEmpty()&&0===f._xmlText._length&&(p.current=!1,b.execCommand("bootstrapEditor"))},x=()=>
9
+ {z.syncCursorPositions(e,a)},y=(m,u)=>{u.origin!==e&&z.syncYjsChangesToLexical(e,a,m)};z.initLocalState(a,n,q,document.activeElement===b.getRootElement());a.on("status",v);a.on("sync",w);t.on("update",x);f.getSharedType().observeDeep(y);const K=b.addListener("update",({prevEditorState:m,editorState:u,dirtyLeaves:G,dirtyElements:H,normalizedNodes:I,tags:J})=>{z.syncLexicalUpdateToYjs(e,a,m,u,H,G,I,J)});k();return()=>{l();a.off("sync",w);a.off("status",v);t.off("update",x);f.getSharedType().unobserveDeep(y);
10
+ K()}},[e,q,k,l,b,n,a,r]);const L=g.useMemo(()=>A.createPortal(g.createElement("div",{ref:f=>{e.cursorsContainer=f}}),document.body),[e]);g.useEffect(()=>b.addListener("command",(f,t)=>{"toggleConnect"===f&&void 0!==k&&void 0!==l&&(t?(console.log("Collaboration connected!"),k()):(console.log("Collaboration disconnected!"),l()));return!1},0),[k,l,b]);return[L,e]}
11
+ function C(b,d){g.useEffect(()=>b.addListener("command",a=>{"focus"===a?z.setLocalStateFocus(d,!0):"blur"===a&&z.setLocalStateFocus(d,!1);return!1},0),[b,d])}function D(b,d){const a=g.useMemo(()=>z.createUndoManager(d,d.root.getSharedType()),[d]);g.useEffect(()=>b.addListener("command",h=>"undo"===h?(a.undo(),!0):"redo"===h?(a.redo(),!0):!1,0));return g.useCallback(()=>{a.clear()},[a])}
12
+ const E=[["Cat","255,165,0"],["Dog","0,200,55"],["Rabbit","160,0,200"],["Frog","0,172,200"],["Fox","197,200,0"],["Hedgehog","31,200,0"],["Pigeon","200,0,0"],["Squirrel","200,0,148"],["Bear","255,235,0"],["Tiger","86,255,0"],["Leopard","0,255,208"],["Zebra","0,243,255"],["Wolf","0,102,255"],["Owl","147,0,255"],["Gull","255,0,153"],["Squid","0,220,255"]],F=E[Math.floor(Math.random()*(E.length-1+1))],M=g.createContext({clientID:0,color:F[1],name:F[0],yjsDocMap:new Map});
13
+ function N(){return g.useContext(M)}exports.CollaborationContext=M;exports.CollaborationPlugin=function({id:b,providerFactory:d,shouldBootstrap:a}){const h=N(),{yjsDocMap:n,name:q,color:r}=h,[e]=c.useLexicalComposerContext(),k=g.useMemo(()=>d(b,n),[b,d,n]),[l,p]=B(e,b,k,n,q,r,a);h.clientID=p.clientID;D(e,p);C(e,k);return l};exports.useCollaborationContext=N;
@@ -4,6 +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
- 'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),l=require("react");function m(g){throw g;}
7
+ var e=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),l=require("react");function m(g){throw g;}
8
8
  module.exports=function({initialConfig:g={},children:n}){const b=l.useContext(e.LexicalComposerContext),u=l.useMemo(()=>{let c,h;const {theme:k,namespace:p,editor:q,nodes:r,onError:t}=g;if(null!=k)c=k;else if(null!=b){h=b[0];var a=b[1].getTheme();null!=a&&(c=a)}a=e.createLexicalComposerContext(b,c);let d=q||null;null===d&&(d=f.createEditor({context:a,namespace:p,nodes:r,parentEditor:h,theme:c}),d.addListener("error",t||m));return[d,a]},[]);return l.createElement(e.LexicalComposerContext.Provider,
9
9
  {value:u},n)};
@@ -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 c=require("react");const d=c.createContext(null);exports.LexicalComposerContext=d;exports.createLexicalComposerContext=function(a,e){let b=null;null!=a&&(b=a[1]);return{getTheme:function(){return null!=e?e:null!=b?b.getTheme():null}}};exports.useLexicalComposerContext=function(){const a=c.useContext(d);if(null==a)throw Error("Minified Lexical error #0; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return a};
7
+ var c=require("react");const d=c.createContext(null);exports.LexicalComposerContext=d;exports.createLexicalComposerContext=function(a,e){let b=null;null!=a&&(b=a[1]);return{getTheme:function(){return null!=e?e:null!=b?b.getTheme():null}}};exports.useLexicalComposerContext=function(){const a=c.useContext(d);if(null==a)throw Error("Minified Lexical error #0; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return a};
@@ -4,6 +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
- 'use strict';var b=require("@lexical/react/LexicalComposerContext"),e=require("react");
7
+ var b=require("@lexical/react/LexicalComposerContext"),e=require("react");
8
8
  module.exports=function({ariaActiveDescendantID:f,ariaAutoComplete:g,ariaControls:h,ariaDescribedBy:k,ariaExpanded:l,ariaLabel:m,ariaLabelledBy:n,ariaMultiline:p,ariaOwneeID:q,ariaRequired:r,autoCapitalize:t,autoComplete:u,autoCorrect:v,className:w,readOnly:a=!1,role:c="textbox",spellCheck:x=!0,style:y,tabIndex:z,testid:A}){const [d]=b.useLexicalComposerContext(),C=e.useCallback(B=>{d.setRootElement(B)},[d]);return e.createElement("div",{"aria-activedescendant":a?null:f,"aria-autocomplete":a?null:
9
9
  g,"aria-controls":a?null:h,"aria-describedby":k,"aria-expanded":a?null:"combobox"===c?!!l:null,"aria-label":m,"aria-labelledby":n,"aria-multiline":p,"aria-owns":a?null:q,"aria-required":r,autoCapitalize:t,autoComplete:u,autoCorrect:v,className:w,contentEditable:!a,"data-testid":A,ref:C,role:a?null:c,spellCheck:x,style:y,tabIndex:z})};
@@ -4,7 +4,7 @@
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("@lexical/react/LexicalComposerContext"),f=require("lexical"),g=require("lexical/HashtagNode"),h=require("react"),l=RegExp;
7
+ var c=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),g=require("lexical/HashtagNode"),h=require("react"),l=RegExp;
8
8
  const m=String.fromCharCode,n="A-Za-z\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u0241\u0250-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ee\u037a\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03ce\u03d0-\u03f5\u03f7-\u0481\u048a-\u04ce\u04d0-\u04f9\u0500-\u050f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0621-\u063a\u0640-\u064a\u066e-\u066f\u0671-\u06d3\u06d5\u06e5-\u06e6\u06ee-\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u076d\u0780-\u07a5\u07b1\u0904-\u0939\u093d\u0950\u0958-\u0961\u097d\u0985-\u098c\u098f-\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc-\u09dd\u09df-\u09e1\u09f0-\u09f1\u0a05-\u0a0a\u0a0f-\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32-\u0a33\u0a35-\u0a36\u0a38-\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2-\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0-\u0ae1\u0b05-\u0b0c\u0b0f-\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32-\u0b33\u0b35-\u0b39\u0b3d\u0b5c-\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99-\u0b9a\u0b9c\u0b9e-\u0b9f\u0ba3-\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c60-\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0-\u0ce1\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d28\u0d2a-\u0d39\u0d60-\u0d61\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32-\u0e33\u0e40-\u0e46\u0e81-\u0e82\u0e84\u0e87-\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa-\u0eab\u0ead-\u0eb0\u0eb2-\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edd\u0f00\u0f40-\u0f47\u0f49-\u0f6a\u0f88-\u0f8b\u1000-\u1021\u1023-\u1027\u1029-\u102a\u1050-\u1055\u10a0-\u10c5\u10d0-\u10fa\u10fc\u1100-\u1159\u115f-\u11a2\u11a8-\u11f9\u1200-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u1676\u1681-\u169a\u16a0-\u16ea\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19a9\u19c1-\u19c7\u1a00-\u1a16\u1d00-\u1dbf\u1e00-\u1e9b\u1ea0-\u1ef9\u1f00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u2094\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2131\u2133-\u2139\u213c-\u213f\u2145-\u2149\u2c00-\u2c2e\u2c30-\u2c5e\u2c80-\u2ce4\u2d00-\u2d25\u2d30-\u2d65\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3006\u3031-\u3035\u303b-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312c\u3131-\u318e\u31a0-\u31b7\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fbb\ua000-\ua48c\ua800-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\uac00-\ud7a3\uf900-\ufa2d\ufa30-\ufa6a\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc\u0300-\u036f\u0483-\u0486\u0591-\u05b9\u05bb-\u05bd\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u0610-\u0615\u064b-\u065e\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u0901-\u0903\u093c\u093e-\u094d\u0951-\u0954\u0962-\u0963\u0981-\u0983\u09bc\u09be-\u09c4\u09c7-\u09c8\u09cb-\u09cd\u09d7\u09e2-\u09e3\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a70-\u0a71\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0b01-\u0b03\u0b3c\u0b3e-\u0b43\u0b47-\u0b48\u0b4b-\u0b4d\u0b56-\u0b57\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0c01-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56\u0c82-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5-\u0cd6\u0d02-\u0d03\u0d3e-\u0d43\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d82-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2-\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f3e-\u0f3f\u0f71-\u0f84\u0f86-\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102c-\u1032\u1036-\u1039\u1056-\u1059\u135f\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17b6-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u192b\u1930-\u193b\u19b0-\u19c0\u19c8-\u19c9\u1a17-\u1a1b\u1dc0-\u1dc3\u20d0-\u20dc\u20e1\u20e5-\u20eb\u302a-\u302f\u3099-\u309a\ua802\ua806\ua80b\ua823-\ua827\ufb1e\ufe00-\ufe0f\ufe20-\ufe23\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0100-\u024f\u0253-\u0254\u0256-\u0257\u0259\u025b\u0263\u0268\u026f\u0272\u0289\u028b\u02bb\u0300-\u036f\u1e00-\u1eff\u0400-\u04ff\u0500-\u0527\u2de0-\u2dff\ua640-\ua69f\u0591-\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u05d0-\u05ea\u05f0-\u05f4\ufb12-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4f\u0610-\u061a\u0620-\u065f\u066e-\u06d3\u06d5-\u06dc\u06de-\u06e8\u06ea-\u06ef\u06fa-\u06fc\u06ff\u0750-\u077f\u08a0\u08a2-\u08ac\u08e4-\u08fe\ufb50-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\u200c-\u200c\u0e01-\u0e3a\u0e40-\u0e4e\u1100-\u11ff\u3130-\u3185\ua960-\ua97f\uac00-\ud7af\ud7b0-\ud7ff\uffa1-\uffdc\u30a1-\u30fa\u30fc-\u30fe\uff66-\uff9f\uff10-\uff19\uff21-\uff3a\uff41-\uff5a\u3041-\u3096\u3099-\u309e\u3400-\u4dbf\u4e00-\u9fff"+(m(173824)+
9
9
  "-"+m(177983)+m(177984)+"-"+m(178207)+m(194560)+"-"+m(195103)+"\u3003\u3005\u303b"),{alpha:p,alphanumeric:q,hashChars:r}={alpha:n,alphanumeric:n+"0-9\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0be6-\u0bef\u0c66-\u0c6f\u0ce6-\u0cef\u0d66-\u0d6f\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29\u1040-\u1049\u17e0-\u17e9\u1810-\u1819\u1946-\u194f\u19d0-\u19d9\uff10-\uff19_",hashChars:"#\\uFF03"},t="["+q+"]",u=new l("(^|$|[^&/"+(q+"])([")+(r+"])(")+t+"*["+(p+"]")+
10
10
  t+"*)","ig");function v(a){if(a.isSimpleText())for(var w=a.getTextContent(),k=0;;){var b=u.exec(w);if(null===b)break;const d=b.index+b[1].length-k;b=d+(b[3].length+1);let e;0===d?[e,a]=a.splitText(b):[,e,a]=a.splitText(d,b);k+=b;g.$toggleHashtag(e)}}function x(a){h.useEffect(()=>a.addTransform(f.TextNode,v),[a])}module.exports=function(){const [a]=c.useLexicalComposerContext();x(a);return null};
@@ -19,9 +19,9 @@ var react = require('react');
19
19
  *
20
20
  *
21
21
  */
22
- const MERGE = 0;
23
- const NO_MERGE = 1;
24
- const DISCARD = 2;
22
+ const HISTORY_MERGE = 0;
23
+ const HISTORY_PUSH = 1;
24
+ const DISCARD_HISTORY_CANDIDATE = 2;
25
25
  const OTHER = 0;
26
26
  const COMPOSING_CHARACTER = 1;
27
27
  const INSERT_CHARACTER_AFTER_SELECTION = 2;
@@ -149,18 +149,21 @@ function createMergeActionGetter(editor, delay) {
149
149
  if (tags.has('historic')) {
150
150
  prevChangeType = OTHER;
151
151
  prevChangeTime = changeTime;
152
- return DISCARD;
152
+ return DISCARD_HISTORY_CANDIDATE;
153
153
  }
154
154
 
155
155
  const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
156
156
 
157
157
  const mergeAction = (() => {
158
- if (tags.has('without-history')) {
159
- return MERGE;
158
+ const shouldPushHistory = tags.has('history-push');
159
+ const shouldMergeHistory = !shouldPushHistory && tags.has('history-merge');
160
+
161
+ if (shouldMergeHistory) {
162
+ return HISTORY_MERGE;
160
163
  }
161
164
 
162
165
  if (prevEditorState === null) {
163
- return NO_MERGE;
166
+ return HISTORY_PUSH;
164
167
  }
165
168
 
166
169
  const selection = nextEditorState._selection;
@@ -169,19 +172,19 @@ function createMergeActionGetter(editor, delay) {
169
172
 
170
173
  if (!hasDirtyNodes) {
171
174
  if (prevSelection === null && selection !== null) {
172
- return MERGE;
175
+ return HISTORY_MERGE;
173
176
  }
174
177
 
175
- return DISCARD;
178
+ return DISCARD_HISTORY_CANDIDATE;
176
179
  }
177
180
 
178
181
  const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
179
182
 
180
- if (changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
181
- return MERGE;
183
+ if (shouldPushHistory === false && changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
184
+ return HISTORY_MERGE;
182
185
  }
183
186
 
184
- return NO_MERGE;
187
+ return HISTORY_PUSH;
185
188
  })();
186
189
 
187
190
  prevChangeTime = changeTime;
@@ -218,7 +221,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
218
221
 
219
222
  const mergeAction = getMergeAction(prevEditorState, editorState, current, dirtyLeaves, dirtyElements, tags);
220
223
 
221
- if (mergeAction === NO_MERGE) {
224
+ if (mergeAction === HISTORY_PUSH) {
222
225
  if (redoStack.length !== 0) {
223
226
  historyState.redoStack = [];
224
227
  }
@@ -229,7 +232,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
229
232
  });
230
233
  editor.execCommand('canUndo', true);
231
234
  }
232
- } else if (mergeAction === DISCARD) {
235
+ } else if (mergeAction === DISCARD_HISTORY_CANDIDATE) {
233
236
  return;
234
237
  } // Else we merge
235
238
 
@@ -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/LexicalComposerContext"),r=require("@lexical/react/withSubscriptions"),v=require("lexical"),w=require("react");
8
- function x(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||v.$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&&
7
+ var n=require("@lexical/react/LexicalComposerContext"),t=require("@lexical/react/withSubscriptions"),v=require("lexical"),w=require("react");
8
+ function x(b,d,l,a,h){if(null===b||0===l.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(l);a=Array.from(a);l=d._nodeMap;h=[];for(var f=0;f<e.length;f++){const k=l.get(e[f]);void 0!==k&&h.push(k)}for(e=0;e<a.length;e++)a[e][1]&&(f=l.get(a[e][0]),void 0===f||v.$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
9
  c&&!b._nodeMap.has(d.__key)&&v.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=h[0];b=b._nodeMap.get(d.__key);if(!v.$isTextNode(b)||!v.$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 y(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=x(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 z(b,d,k=1E3){const a=w.useMemo(()=>d||A(),[d]),h=w.useCallback(()=>{a.undoStack=[];a.redoStack=[];a.current=null},[a]);w.useEffect(()=>{const g=y(b,k);return r(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(v.$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.HistoryPlugin=function({externalHistoryState:b}){const [d]=n.useLexicalComposerContext();z(d,b);return null};exports.createEmptyHistoryState=A;
10
+ function y(b,d){let l=Date.now(),a=0;return(h,g,c,e,f,k)=>{const p=Date.now();if(k.has("historic"))return a=0,l=p,2;const m=x(h,g,e,f,b.isComposing()),u=(()=>{const r=k.has("history-push");if(!r&&k.has("history-merge"))return 0;if(null===h)return 1;var q=g._selection;const A=h._selection;if(!(0<e.size||0<f.size))return null===A&&null!==q?0:2;q=null===c||c.editor===b;return!1===r&&0!==m&&m===a&&p<l+d&&q?0:1})();l=p;a=m;return u}}
11
+ function z(b,d,l=1E3){const a=w.useMemo(()=>d||B(),[d]),h=w.useCallback(()=>{a.undoStack=[];a.redoStack=[];a.current=null},[a]);w.useEffect(()=>{const g=y(b,l);return t(b.addListener("command",c=>{switch(c){case "undo":c=a.redoStack;var e=a.undoStack;if(0!==e.length){var f=a.current;const k=e.pop();null!==f&&(c.push(f),b.execCommand("canRedo",!0));0===e.length&&b.execCommand("canUndo",!1);a.current=k;k.editor.setEditorState(k.editorState.clone(k.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:k,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,k,p);if(1===f)0!==u.length&&(a.redoStack=[]),null!==m&&(r.push({...m,undoSelection:e.read(v.$getSelection)}),b.execCommand("canUndo",!0));else if(2===f)return;a.current={editor:b,editorState:c}}}))},[h,l,b,a])}function B(){return{current:null,redoStack:[],undoStack:[]}}exports.HistoryPlugin=function({externalHistoryState:b}){const [d]=n.useLexicalComposerContext();z(d,b);return null};exports.createEmptyHistoryState=B;
@@ -0,0 +1,66 @@
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 lexical = require('lexical');
10
+ var React = require('react');
11
+
12
+ /**
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ *
19
+ */
20
+
21
+ function HorizontalRuleComponent() {
22
+ return /*#__PURE__*/React.createElement("hr", null);
23
+ }
24
+
25
+ class HorizontalRuleNode extends lexical.DecoratorNode {
26
+ static getType() {
27
+ return 'horizontalrule';
28
+ }
29
+
30
+ static clone(node) {
31
+ return new HorizontalRuleNode(node.__state, node.__key);
32
+ }
33
+
34
+ createDOM() {
35
+ const div = document.createElement('div');
36
+ div.style.display = 'contents';
37
+ return div;
38
+ }
39
+
40
+ getTextContent() {
41
+ return '\n';
42
+ }
43
+
44
+ isTopLevel() {
45
+ return true;
46
+ }
47
+
48
+ updateDOM() {
49
+ return false;
50
+ }
51
+
52
+ decorate() {
53
+ return /*#__PURE__*/React.createElement(HorizontalRuleComponent, null);
54
+ }
55
+
56
+ }
57
+ function $createHorizontalRuleNode() {
58
+ return new HorizontalRuleNode();
59
+ }
60
+ function $isHorizontalRuleNode(node) {
61
+ return node instanceof HorizontalRuleNode;
62
+ }
63
+
64
+ exports.$createHorizontalRuleNode = $createHorizontalRuleNode;
65
+ exports.$isHorizontalRuleNode = $isHorizontalRuleNode;
66
+ exports.HorizontalRuleNode = HorizontalRuleNode;
@@ -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 LexicalHorizontalRuleNode = process.env.NODE_ENV === 'development' ? require('./LexicalHorizontalRuleNode.dev.js') : require('./LexicalHorizontalRuleNode.prod.js')
9
+ module.exports = LexicalHorizontalRuleNode;
@@ -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 b=require("lexical"),c=require("react");function d(){return c.createElement("hr",null)}class e extends b.DecoratorNode{static getType(){return"horizontalrule"}static clone(a){return new e(a.__state,a.__key)}createDOM(){const a=document.createElement("div");a.style.display="contents";return a}getTextContent(){return"\n"}isTopLevel(){return!0}updateDOM(){return!1}decorate(){return c.createElement(d,null)}}exports.$createHorizontalRuleNode=function(){return new e};
8
+ exports.$isHorizontalRuleNode=function(a){return a instanceof e};exports.HorizontalRuleNode=e;
@@ -23,7 +23,6 @@ const EditorPriority = 0;
23
23
 
24
24
  function toggleLink(url) {
25
25
  const selection = lexical.$getSelection();
26
- lexical.$log('toggleLink');
27
26
 
28
27
  if (selection !== null) {
29
28
  lexical.$setSelection(selection);
@@ -4,6 +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
- 'use strict';var h=require("@lexical/react/LexicalComposerContext"),k=require("lexical"),m=require("lexical/LinkNode"),n=require("react");
8
- function p(g){var b=k.$getSelection();k.$log("toggleLink");null!==b&&k.$setSelection(b);b=k.$getSelection();if(null!==b)if(b=b.extract(),null===g)b.forEach(e=>{e=e.getParent();if(m.$isLinkNode(e)){const a=e.getChildren();for(let c=0;c<a.length;c++)e.insertBefore(a[c]);e.remove()}});else{let e=null,a=null;if(1===b.length){var f=b[0];if(m.$isLinkNode(f)){f.setURL(g);return}f=f.getParent();if(m.$isLinkNode(f)){a=f;f.setURL(g);return}}b.forEach(c=>{var d=c.getParent();if(d!==a&&null!==d)if(d.is(e)||(e=
9
- d,a=m.$createLinkNode(g),m.$isLinkNode(d)?null===c.getPreviousSibling()?d.insertBefore(a):d.insertAfter(a):c.insertBefore(a)),m.$isLinkNode(c)){if(null!==a){d=c.getChildren();for(let l=0;l<d.length;l++)a.append(d[l])}c.remove()}else null!==a&&a.append(c)})}}module.exports=function(){const [g]=h.useLexicalComposerContext();n.useEffect(()=>g.addListener("command",(b,f)=>"toggleLink"===b?(p(f),!0):!1,0),[g]);return null};
7
+ var h=require("@lexical/react/LexicalComposerContext"),k=require("lexical"),m=require("lexical/LinkNode"),n=require("react");
8
+ function p(g){var b=k.$getSelection();null!==b&&k.$setSelection(b);b=k.$getSelection();if(null!==b)if(b=b.extract(),null===g)b.forEach(e=>{e=e.getParent();if(m.$isLinkNode(e)){const a=e.getChildren();for(let c=0;c<a.length;c++)e.insertBefore(a[c]);e.remove()}});else{let e=null,a=null;if(1===b.length){var f=b[0];if(m.$isLinkNode(f)){f.setURL(g);return}f=f.getParent();if(m.$isLinkNode(f)){a=f;f.setURL(g);return}}b.forEach(c=>{var d=c.getParent();if(d!==a&&null!==d)if(d.is(e)||(e=d,a=m.$createLinkNode(g),
9
+ m.$isLinkNode(d)?null===c.getPreviousSibling()?d.insertBefore(a):d.insertAfter(a):c.insertBefore(a)),m.$isLinkNode(c)){if(null!==a){d=c.getChildren();for(let l=0;l<d.length;l++)a.append(d[l])}c.remove()}else null!==a&&a.append(c)})}}module.exports=function(){const [g]=h.useLexicalComposerContext();n.useEffect(()=>g.addListener("command",(b,f)=>"toggleLink"===b?(p(f),!0):!1,0),[g]);return null};
@@ -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 b=require("@lexical/react/LexicalComposerContext"),d=require("@lexical/list"),e=require("react");function f(a){e.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(d.indentList())return!0}else if("outdentContent"===c){if(d.outdentList())return!0}else{if("insertOrderedList"===c)return d.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return d.insertList(a,"ul"),!0;if("removeList"===c)return d.removeList(a),!0}return!1},1),[a])}
7
+ var b=require("@lexical/react/LexicalComposerContext"),d=require("@lexical/list"),e=require("react");function f(a){e.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(d.indentList())return!0}else if("outdentContent"===c){if(d.outdentList())return!0}else{if("insertOrderedList"===c)return d.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return d.insertList(a,"ul"),!0;if("removeList"===c)return d.removeList(a),!0}return!1},1),[a])}
8
8
  module.exports=function(){const [a]=b.useLexicalComposerContext();f(a);return null};
@@ -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 a=require("@lexical/react/LexicalComposer"),f=require("@lexical/react/LexicalOnChangePlugin"),g=require("react");
7
+ var a=require("@lexical/react/LexicalComposer"),f=require("@lexical/react/LexicalOnChangePlugin"),g=require("react");
8
8
  module.exports=function({initialConfig:c={},children:h}){const [d,k]=g.useState(null),{decoratorEditor:b,namespace:l,theme:m,nodes:n,onError:p}=c;g.useEffect(()=>{b.isEmpty()||null===d||b.init(d)},[d]);c=g.useCallback((q,e)=>{q.isEmpty()?k(e):b.set(e)},[]);return g.createElement(a,{initialConfig:{editor:b.editor,namespace:l,nodes:n,onError:p,theme:m}},g.createElement(f,{onChange:c}),h)};
@@ -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 c=require("@lexical/react/LexicalComposerContext"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;module.exports=function({onChange:a}){const [b]=c.useLexicalComposerContext();e(()=>{if(a)return b.addListener("update",({editorState:f})=>{a(f,b)})},[b,a]);return null};
7
+ var c=require("@lexical/react/LexicalComposerContext"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;module.exports=function({onChange:a}){const [b]=c.useLexicalComposerContext();e(()=>{if(a)return b.addListener("update",({editorState:f})=>{a(f,b)})},[b,a]);return null};
@@ -174,7 +174,7 @@ function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity)
174
174
  }
175
175
  function $isParentElementRTL(selection) {
176
176
  const anchorNode = selection.anchor.getNode();
177
- const parent = anchorNode.getParentOrThrow();
177
+ const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
178
178
  return parent.getDirection() === 'rtl';
179
179
  }
180
180
  function $moveCharacter(selection, isHoldingShift, isBackward) {
@@ -190,17 +190,41 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
190
190
  *
191
191
  *
192
192
  */
193
+ function resolveElement(element, isBackward, focusOffset) {
194
+ const parent = element.getParent();
195
+ let offset = focusOffset;
196
+ let block = element;
197
+
198
+ if (parent !== null) {
199
+ if (isBackward && focusOffset === 0) {
200
+ offset = block.getIndexWithinParent();
201
+ block = parent;
202
+ } else if (!isBackward && focusOffset === block.getChildrenSize()) {
203
+ offset = block.getIndexWithinParent() + 1;
204
+ block = parent;
205
+ }
206
+ }
207
+
208
+ return block.getChildAtIndex(isBackward ? offset - 1 : offset);
209
+ }
210
+
193
211
  function getPossibleDecoratorNode(focus, isBackward) {
194
212
  const focusOffset = focus.offset;
195
213
 
196
214
  if (focus.type === 'element') {
197
215
  const block = focus.getNode();
198
- return block.getChildAtIndex(isBackward ? focusOffset - 1 : focusOffset);
216
+ return resolveElement(block, isBackward, focusOffset);
199
217
  } else {
200
218
  const focusNode = focus.getNode();
201
219
 
202
220
  if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
203
- return isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
221
+ const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
222
+
223
+ if (possibleNode === null) {
224
+ return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
225
+ }
226
+
227
+ return possibleNode;
204
228
  }
205
229
  }
206
230
 
@@ -223,13 +247,12 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
223
247
  }
224
248
  }
225
249
  function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
226
- const possibleDecoratorNode = getPossibleDecoratorNode(selection.focus, isBackward);
227
- return lexical.$isDecoratorNode(possibleDecoratorNode);
250
+ const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
251
+ return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
228
252
  }
229
253
  function onPasteForPlainText(event, editor) {
230
254
  event.preventDefault();
231
255
  editor.update(() => {
232
- lexical.$log('onPasteForPlainText');
233
256
  const selection = lexical.$getSelection();
234
257
  const clipboardData = event.clipboardData;
235
258
 
@@ -241,7 +264,6 @@ function onPasteForPlainText(event, editor) {
241
264
  function onCutForPlainText(event, editor) {
242
265
  onCopyForPlainText(event, editor);
243
266
  editor.update(() => {
244
- lexical.$log('onCutForPlainText');
245
267
  const selection = lexical.$getSelection();
246
268
 
247
269
  if (selection !== null) {
@@ -252,7 +274,6 @@ function onCutForPlainText(event, editor) {
252
274
  function onCopyForPlainText(event, editor) {
253
275
  event.preventDefault();
254
276
  editor.update(() => {
255
- lexical.$log('onCopyForPlainText');
256
277
  const clipboardData = event.clipboardData;
257
278
  const selection = lexical.$getSelection();
258
279
 
@@ -316,7 +337,6 @@ function useLexicalDragonSupport(editor) {
316
337
  if (args) {
317
338
  const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
318
339
  editor.update(() => {
319
- lexical.$log('useLexicalDragonSupport');
320
340
  const selection = lexical.$getSelection();
321
341
 
322
342
  if (selection !== null) {