@lexical/react 0.1.12 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/DEPRECATED_useLexicalAutoFormatter.dev.js +283 -295
  2. package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -21
  3. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +3 -72
  4. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -2
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +11 -63
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +6 -7
  7. package/DEPRECATED_useLexicalPlainText.dev.js +16 -41
  8. package/DEPRECATED_useLexicalPlainText.prod.js +13 -14
  9. package/DEPRECATED_useLexicalRichText.dev.js +24 -49
  10. package/DEPRECATED_useLexicalRichText.prod.js +15 -15
  11. package/LexicalAutoFormatterPlugin.dev.js +283 -295
  12. package/LexicalAutoFormatterPlugin.prod.js +19 -21
  13. package/LexicalAutoLinkPlugin.dev.js +2 -2
  14. package/LexicalAutoLinkPlugin.prod.js +2 -2
  15. package/LexicalCharacterLimitPlugin.dev.js +11 -63
  16. package/LexicalCharacterLimitPlugin.prod.js +8 -9
  17. package/LexicalCollaborationPlugin.d.ts +5 -1
  18. package/LexicalCollaborationPlugin.dev.js +77 -16
  19. package/LexicalCollaborationPlugin.js.flow +7 -2
  20. package/LexicalCollaborationPlugin.prod.js +9 -7
  21. package/LexicalComposer.d.ts +1 -1
  22. package/LexicalComposer.dev.js +1 -1
  23. package/LexicalComposer.js.flow +3 -3
  24. package/LexicalComposer.prod.js +1 -1
  25. package/LexicalHashtagPlugin.dev.js +61 -3
  26. package/LexicalHashtagPlugin.prod.js +7 -4
  27. package/LexicalNestedComposer.d.ts +4 -7
  28. package/LexicalNestedComposer.dev.js +21 -11
  29. package/LexicalNestedComposer.js.flow +3 -6
  30. package/LexicalNestedComposer.prod.js +3 -2
  31. package/LexicalOnChangePlugin.dev.js +15 -2
  32. package/LexicalOnChangePlugin.prod.js +2 -1
  33. package/LexicalPlainTextPlugin.dev.js +20 -113
  34. package/LexicalPlainTextPlugin.prod.js +11 -12
  35. package/LexicalRichTextPlugin.dev.js +28 -121
  36. package/LexicalRichTextPlugin.prod.js +12 -13
  37. package/LexicalTablePlugin.dev.js +9 -5
  38. package/LexicalTablePlugin.prod.js +2 -2
  39. package/package.json +11 -6
  40. package/useLexicalIsTextContentEmpty.dev.js +3 -32
  41. package/useLexicalIsTextContentEmpty.prod.js +1 -2
@@ -4,24 +4,22 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var k=require("@lexical/react/LexicalComposerContext"),q=require("@lexical/list"),r=require("lexical"),t=require("lexical/CodeNode"),u=require("react"),x=require("@lexical/react/LexicalHorizontalRuleNode"),y=require("lexical/HeadingNode"),C=require("lexical/QuoteNode");function D(g){throw Error(`Minified Lexical error #${g}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- function E(g,f,a,c){g=g.getChildren();const b=g.length;let d=0,e=!1;for(let p=0;p<b&&!(d>f);++p){const m=g[p],n=r.$isTextNode(m);var h=n?m.getTextContent().length:c;h=d+h;if((!1===e&&d===a||0===d&&d===a||d<a&&a<=h)&&r.$isTextNode(m))return{node:m,offset:a-d};d=h;e=n}return null}
9
- const F={nodeTransformationKind:null,regEx:/(?:)/,requiresParagraphStart:!1},H={...F,requiresParagraphStart:!0},I=[{...F,nodeTransformationKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*\s)$/},{...F,nodeTransformationKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/},{...F,nodeTransformationKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*\s)$/},{...F,nodeTransformationKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__\s)$/},{...F,nodeTransformationKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>\s)$/},
10
- {...F,nodeTransformationKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/}],J=[{...H,nodeTransformationKind:"paragraphH1",regEx:/^(?:# )/},{...H,nodeTransformationKind:"paragraphH2",regEx:/^(?:## )/},{...H,nodeTransformationKind:"paragraphH2",regEx:/^(?:### )/},{...H,nodeTransformationKind:"paragraphBlockQuote",regEx:/^(?:> )/},{...H,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:- )/},{...H,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:\* )/},{...H,nodeTransformationKind:"paragraphOrderedList",
11
- regEx:/^(\d+)\.\s/},{...H,nodeTransformationKind:"paragraphCodeBlock",regEx:/^(```)([a-z]*)( )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/^(?:\*\*\* )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/^(?:--- )/},...I];
12
- function K(g,f,a,c){const b={offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]};c=g.match(c);if(null!==c&&0<c.length&&(!1===f||0===c.index)&&(!1===a||c.index+c[0].length===g.length)){b.offsetInJoinedTextForCollapsedSelection=g.length;g=c.length;f=c.index;for(a=0;a<g;a++){const d=c[a];b.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:f,text:d,textLength:d.length-(a+1===g?1:0)});0<a&&(f+=d.length)}return b}return null}
13
- function L(g,f,a,c,b){b.offsetInJoinedTextForCollapsedSelection+=g;0<b.offsetInJoinedTextForCollapsedSelection||D(67);b=b.regExCaptureGroups;const d=b.length;for(c+=1;c<d;c++){const e=b[c];null!=e.anchorTextNodeWithOffset&&e.anchorTextNodeWithOffset.offset>=f&&e.anchorTextNodeWithOffset.node.is(a)&&(e.anchorTextNodeWithOffset.offset+=g);null!=e.focusTextNodeWithOffset&&e.focusTextNodeWithOffset.offset>=f&&e.focusTextNodeWithOffset.node.is(a)&&(e.focusTextNodeWithOffset.offset+=g)}}
14
- function M(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,c=a.node.getParentOrThrow();a=a.node.spliceText(0,f.matchResultContext.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var b=c;a=null;var d=b.getChildren(),e=f.autoFormatCriteria,h=f.matchResultContext;if(null!=e.nodeTransformationKind)switch(e.nodeTransformationKind){case "paragraphH1":a=y.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=
15
- y.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=y.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=C.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=q.$createListNode("ul");b=q.$createListItemNode();b.append(...d);a.append(b);break;case "paragraphOrderedList":a=parseInt(1<h.regExCaptureGroups.length?h.regExCaptureGroups[h.regExCaptureGroups.length-1].text:"1",10);a=q.$createListNode("ol",a);b=q.$createListItemNode();b.append(...d);
16
- a.append(b);break;case "paragraphCodeBlock":null!=f.triggerState&&f.triggerState.isCodeBlock?a=r.$createParagraphNode():(a=t.$createCodeNode(),b=3<=h.regExCaptureGroups.length?h.regExCaptureGroups[2].text:null,null!=b&&0<b.length&&a.setLanguage(b));a.append(...d);break;case "horizontalRule":d=x.$createHorizontalRuleNode(),b.insertBefore(d)}null!==a&&c.replace(a)}else if(a=f.autoFormatCriteria,c=f.matchResultContext,null!=a.nodeTransformationKind&&6===c.regExCaptureGroups.length){a:{a=a.nodeTransformationKind;
17
- switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=["bold","italic"];break a}a=null}if(null!=a){d=[1,5];b=f.autoFormatCriteria;e=f.matchResultContext.regExCaptureGroups;h=e.length;var p=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&D(62);var m=f.joinedText.length;for(var n=1;n<h;n++){var l=e[n];l.anchorTextNodeWithOffset=E(p,m,l.offsetInParent,1);l.focusTextNodeWithOffset=E(p,m,l.offsetInParent+l.textLength,1);0>l.textLength&&
18
- D(63,b.nodeTransformationKind)}c.regExCaptureGroups=e;if(0<d.length)for(b=c.regExCaptureGroups,e=b.length,h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=b[p],n=l.anchorTextNodeWithOffset,m=l.focusTextNodeWithOffset,null!=n&&null!=m&&0<l.textLength&&(l=r.$createRangeSelection(),l.anchor.set(n.node.getKey(),n.offset,"text"),l.focus.set(m.node.getKey(),m.offset,"text"),r.$setSelection(l),l=r.$getSelection(),r.$isRangeSelection(l)&&(l.removeText(),n.node.getKey()===m.node.getKey()?(l=m.offset-n.offset,0<l||D(64),
19
- L(-l,m.offset,n.node,p,c)):(n=m.offset,0<n&&L(-n,n,m.node,p,c)))));d=c.regExCaptureGroups;3<d.length||D(65);e=d[3];b=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=b&&null!=d&&0<e.textLength&&(e=r.$createRangeSelection(),e.anchor.set(b.node.getKey(),b.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),r.$setSelection(e),b=r.$getSelection(),r.$isRangeSelection(b))){for(e=0;e<a.length;e++)b.formatText(a[e]);a=r.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+
20
- 1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");r.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();c=E(a,c.offsetInJoinedTextForCollapsedSelection+1,c.offsetInJoinedTextForCollapsedSelection,1);null!=c&&(a=r.$createRangeSelection(),a.anchor.set(c.node.getKey(),c.offset,"text"),a.focus.set(c.node.getKey(),c.offset,"text"),r.$setSelection(a))}}},{tag:"history-push"})}
21
- function N(g,f){let a=null;g.read(()=>{var c=r.$getSelection();if(r.$isRangeSelection(c)){var b=c.anchor.getNode();c=r.$isTextNode(b)?{node:b,offset:c.anchor.offset}:null}else c=null;if(null!==c){c={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:c,triggerState:f};a:{b=!1===f.isParentAListItemNode?J:I;const n=c.triggerState,
22
- l=b.length;for(let z=0;z<l;z++){const A=b[z];if(null!=n&&!1===n.isCodeBlock||"paragraphCodeBlock"===A.nodeTransformationKind){var d=A,e=c;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=K(e,!0,!1,d.regEx)):d=null;else{if(null==e.joinedText){var h=e.textNodeWithOffset.node.getParentOrThrow();if(r.$isElementNode(h)){if(null==e.joinedText){var p=e,m=e.textNodeWithOffset;let w="";h=
23
- h.getChildren();const O=h.length;for(let B=0;B<O;++B){const v=h[B];if(r.$isTextNode(v)){const G=v.getTextContent();if(v.is(m.node)){m.offset>G.length&&D(50,v.__key);w+=v.getTextContent().substr(0,m.offset);break}else w+=G}else w+="\u0004"}p.joinedText=w}}else D(52,h.__key)}d=K(e.joinedText,!1,!0,d.regEx)}if(null!=d){b={autoFormatCriteria:A,matchResultContext:d};break a}}}b={autoFormatCriteria:null,matchResultContext:null}}null!==b.autoFormatCriteria&&null!==b.matchResultContext&&(a=c,a.autoFormatCriteria=
24
- b.autoFormatCriteria,a.matchResultContext=b.matchResultContext)}});return a}
25
- function P(g){let f=null;g.read(()=>{const a=r.$getSelection();if(r.$isRangeSelection(a)&&a.isCollapsed()){var c=a.anchor.getNode(),b=c.getParent(),d=null!==b&&q.$isListItemNode(b);f={anchorOffset:a.anchor.offset,hasParentNode:null!==b,isCodeBlock:t.$isCodeNode(c),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:r.$isTextNode(c)&&c.isSimpleText(),nodeKey:c.getKey(),textContent:c.getTextContent()}}});return f}
26
- function Q(g){u.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var c=g.getEditorState();a=P(c);if(null==a)c=null;else{var b=a,d=f;if(null==b||null==d)c=null;else{var e=b.textContent.length,h=b.anchorOffset-1;c=!1===(!0===b.hasParentNode&&b.isSimpleText&&b.isSelectionCollapsed&&b.nodeKey===d.nodeKey&&b.anchorOffset!==d.anchorOffset&&0<=h&&h+1<=e&&" "===b.textContent.substr(h,1)&&b.textContent!==d.textContent)?null:N(c,b)}}null!=c&&M(g,c);f=a}else f=
27
- null})},[g])}module.exports=function(){const [g]=k.useLexicalComposerContext();Q(g);return null};
7
+ var h=require("@lexical/react/LexicalComposerContext"),l=require("@lexical/list"),m=require("lexical"),n=require("lexical/CodeNode"),p=require("react"),q=require("@lexical/react/LexicalHorizontalRuleNode"),r=require("@lexical/text"),t=require("lexical/HeadingNode"),x=require("lexical/QuoteNode");function y(f){throw Error(`Minified Lexical error #${f}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
+ const z={autoFormatKind:null,regEx:/(?:)/,requiresParagraphStart:!1},A={...z,requiresParagraphStart:!0},B=[{...z,autoFormatKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*)(\s)$/},{...z,autoFormatKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*)(\s)$/},{...z,autoFormatKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/},{...z,autoFormatKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__)(\s)$/},{...z,autoFormatKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)(\s)$/},
9
+ {...z,autoFormatKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~)(\s)$/},{...z,autoFormatKind:"link",regEx:/(\[)(.+)(\]\()([^ ]+)(?: "(?:.+)")?(\))(\s)$/}],C=[{...A,autoFormatKind:"paragraphH1",regEx:/^(?:# )/},{...A,autoFormatKind:"paragraphH2",regEx:/^(?:## )/},{...A,autoFormatKind:"paragraphH2",regEx:/^(?:### )/},{...A,autoFormatKind:"paragraphBlockQuote",regEx:/^(?:> )/},{...A,autoFormatKind:"paragraphUnorderedList",regEx:/^(?:- )/},{...A,autoFormatKind:"paragraphUnorderedList",regEx:/^(?:\* )/},
10
+ {...A,autoFormatKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/},{...A,autoFormatKind:"paragraphCodeBlock",regEx:/^(```)([a-z]*)( )/},{...A,autoFormatKind:"horizontalRule",regEx:/^(?:\*\*\* )/},{...A,autoFormatKind:"horizontalRule",regEx:/^(?:--- )/},...B];
11
+ function D(f,d,a,b){const c={regExCaptureGroups:[]};b=f.match(b);if(null!==b&&0<b.length&&(!1===d||0===b.index)&&(!1===a||b.index+b[0].length===f.length)){f=b.length;d=b.index;for(a=0;a<f;a++){const e=b[a];c.regExCaptureGroups.push({offsetInParent:d,text:e});0<a&&(d+=e.length)}return c}return null}
12
+ function E(f,d,a,b,c){var e=c.patternMatchResults;const g=e.regExCaptureGroups;var k=g.length;if(f>=k||d>=k)return null;c=c.textNodeWithOffset.node.getParentOrThrow();k=e.regExCaptureGroups.length;2>k?e=0:(--k,e=e.regExCaptureGroups[k].offsetInParent+e.regExCaptureGroups[k].text.length);f=g[f];d=g[d];b=b?d.offsetInParent+d.text.length:d.offsetInParent;a=r.$findNodeWithOffsetFromJoinedText(a?f.offsetInParent+f.text.length:f.offsetInParent,e,1,c);b=r.$findNodeWithOffsetFromJoinedText(b,e,1,c);if(null==
13
+ a||null==b)return null;c=m.$createRangeSelection();c.anchor.set(a.node.getKey(),a.offset,"text");c.focus.set(b.node.getKey(),b.offset,"text");return c}function F(f,d,a){const b=a.patternMatchResults.regExCaptureGroups;a=E(f,d,!1,!0,a);if(null!=a&&(m.$setSelection(a),a=m.$getSelection(),null!=a&&m.$isRangeSelection(a)&&!1===a.isCollapsed())){a.removeText();a=0;const c=b.length;for(let e=f;e<c;e++){const g=b[e];e>f&&(g.offsetInParent-=a);e<=d&&(a+=g.text.length,g.text="")}}}
14
+ function G(f){var d=f.patternMatchResults.regExCaptureGroups.length;2>d||(--d,f=E(d,d,!0,!0,f),null!=f&&m.$setSelection(f))}
15
+ function H(f,d){f.update(()=>{if(d.autoFormatCriteria.requiresParagraphStart){var a=d.textNodeWithOffset,b=a.node.getParentOrThrow();a=a.node.spliceText(0,d.patternMatchResults.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var c=b;a=null;var e=c.getChildren(),g=d.autoFormatCriteria;const k=d.patternMatchResults;if(null!=g.autoFormatKind)switch(g.autoFormatKind){case "paragraphH1":a=t.$createHeadingNode("h1");a.append(...e);break;case "paragraphH2":a=
16
+ t.$createHeadingNode("h2");a.append(...e);break;case "paragraphH3":a=t.$createHeadingNode("h3");a.append(...e);break;case "paragraphBlockQuote":a=x.$createQuoteNode();a.append(...e);break;case "paragraphUnorderedList":a=l.$createListNode("ul");c=l.$createListItemNode();c.append(...e);a.append(c);break;case "paragraphOrderedList":a=parseInt(1<k.regExCaptureGroups.length?k.regExCaptureGroups[k.regExCaptureGroups.length-1].text:"1",10);a=l.$createListNode("ol",a);c=l.$createListItemNode();c.append(...e);
17
+ a.append(c);break;case "paragraphCodeBlock":null!=d.triggerState&&d.triggerState.isCodeBlock?a=m.$createParagraphNode():(a=n.$createCodeNode(),c=3<=k.regExCaptureGroups.length?k.regExCaptureGroups[2].text:null,null!=c&&0<c.length&&a.setLanguage(c));a.append(...e);break;case "horizontalRule":e=q.$createHorizontalRuleNode(),c.insertBefore(e)}null!==a&&b.replace(a)}else if(b=d.autoFormatCriteria,null!=b.autoFormatKind){a:{a=b.autoFormatKind;switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=
18
+ [a];break a;case "bold_italic":a=["bold","italic"];break a}a=null}if(null!=a){if(b=a,7===d.patternMatchResults.regExCaptureGroups.length){F(5,5,d);F(1,1,d);a=d.patternMatchResults.regExCaptureGroups;3<a.length||y(65);if(0!==a[3].text.length&&(a=E(3,3,!1,!0,d),null!=a&&(m.$setSelection(a),a=m.$getSelection(),m.$isRangeSelection(a))))for(e=0;e<b.length;e++)a.formatText(b[e]);G(d)}}else if("link"===b.autoFormatKind&&(b=d.patternMatchResults.regExCaptureGroups,7===b.length&&(e=b[2].text,b=b[4].text,0!==
19
+ e.length&&0!==b.length))){F(1,5,d);a=d.patternMatchResults.regExCaptureGroups;if(!(1>=a.length)&&(e={offsetInParent:a[1].offsetInParent,text:e},c=E(1,1,!1,!1,d),null!=c&&(m.$setSelection(c),c=m.$getSelection(),null!=c&&m.$isRangeSelection(c)&&c.isCollapsed())))for(c.insertText(e.text),a.splice(1,0,e),e=e.text.length,c=a.length,g=2;g<c;g++)a[g].offsetInParent+=e;a=E(1,1,!1,!0,d);null!=a&&(m.$setSelection(a),d.editor.execCommand("toggleLink",b),G(d))}}},{tag:"history-push"})}
20
+ function I(f,d){let a=null;f.getEditorState().read(()=>{var b=m.$getSelection();if(m.$isRangeSelection(b)){var c=b.anchor.getNode();b=m.$isTextNode(c)?{node:c,offset:b.anchor.offset}:null}else b=null;if(null!==b){b={autoFormatCriteria:{autoFormatKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},editor:f,joinedText:null,patternMatchResults:{regExCaptureGroups:[]},textNodeWithOffset:b,triggerState:d};a:{c=!1===d.isParentAListItemNode?C:B;const k=b.triggerState,J=c.length;for(let u=0;u<
21
+ J;u++){const v=c[u];if(null!=k&&!1===k.isCodeBlock||"paragraphCodeBlock"===v.autoFormatKind){var e=v,g=b;if(null!==e.requiresParagraphStart&&!0===e.requiresParagraphStart)null===g.textNodeWithOffset.node.getPreviousSibling()?(g=g.textNodeWithOffset.node.getTextContent(),g=D(g,!0,!1,e.regEx)):g=null;else{if(null==g.joinedText){const w=g.textNodeWithOffset.node.getParentOrThrow();m.$isElementNode(w)?null==g.joinedText&&(g.joinedText=r.$joinTextNodesInElementNode(w,"\u0004",g.textNodeWithOffset)):y(52,
22
+ w.__key)}g=D(g.joinedText,!1,!0,e.regEx)}if(null!=g){c={autoFormatCriteria:v,patternMatchResults:g};break a}}}c={autoFormatCriteria:null,patternMatchResults:null}}null!==c.autoFormatCriteria&&null!==c.patternMatchResults&&(a=b,a.autoFormatCriteria=c.autoFormatCriteria,a.patternMatchResults=c.patternMatchResults)}});return a}
23
+ function K(f){let d=null;f.read(()=>{const a=m.$getSelection();if(m.$isRangeSelection(a)&&a.isCollapsed()){var b=a.anchor.getNode(),c=b.getParent(),e=null!==c&&l.$isListItemNode(c);d={anchorOffset:a.anchor.offset,hasParentNode:null!==c,isCodeBlock:n.$isCodeNode(b),isParentAListItemNode:e,isSelectionCollapsed:a.isCollapsed(),isSimpleText:m.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return d}
24
+ function L(f){p.useEffect(()=>{let d=null;return f.addListener("update",({tags:a})=>{if(!1===a.has("historic")){a=K(f.getEditorState());if(null==a)var b=null;else{b=a;var c=d;if(null==b||null==c)b=null;else{var e=b.textContent.length,g=b.anchorOffset-1;b=!1===(!0===b.hasParentNode&&b.isSimpleText&&b.isSelectionCollapsed&&b.nodeKey===c.nodeKey&&b.anchorOffset!==c.anchorOffset&&0<=g&&g+1<=e&&" "===b.textContent.substr(g,1)&&b.textContent!==c.textContent)?null:I(f,b)}}null!=b&&H(f,b);d=a}else d=null})},
25
+ [f])}module.exports=function(){const [f]=h.useLexicalComposerContext();L(f);return null};
@@ -197,7 +197,7 @@ function useAutoLink(editor, matchers, onChange) {
197
197
  }
198
198
  };
199
199
 
200
- return withSubscriptions(editor.addTransform(lexical.TextNode, textNode => {
200
+ return withSubscriptions(editor.addNodeTransform(lexical.TextNode, textNode => {
201
201
  const parent = textNode.getParentOrThrow();
202
202
 
203
203
  if (AutoLinkNode.$isAutoLinkNode(parent)) {
@@ -209,7 +209,7 @@ function useAutoLink(editor, matchers, onChange) {
209
209
 
210
210
  handleBadNeighbors(textNode, onChangeWrapped);
211
211
  }
212
- }), editor.addTransform(AutoLinkNode.AutoLinkNode, linkNode => {
212
+ }), editor.addNodeTransform(AutoLinkNode.AutoLinkNode, linkNode => {
213
213
  handleLinkEdit(linkNode, matchers, onChangeWrapped);
214
214
  }));
215
215
  }, [editor, matchers, onChange]);
@@ -7,6 +7,6 @@
7
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("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,
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
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};
@@ -8,66 +8,12 @@
8
8
 
9
9
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
10
  var React = require('react');
11
- var lexical = require('lexical');
12
11
  var withSubscriptions = require('@lexical/react/withSubscriptions');
12
+ var text = require('@lexical/text');
13
+ var utils = require('@lexical/utils');
14
+ var lexical = require('lexical');
13
15
  var OverflowNode = require('lexical/OverflowNode');
14
16
 
15
- /**
16
- * Copyright (c) Meta Platforms, Inc. and affiliates.
17
- *
18
- * This source code is licensed under the MIT license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- *
21
- *
22
- */
23
- function $dfs(startingNode, endingNode) {
24
- const nodes = [];
25
- const start = (startingNode || lexical.$getRoot()).getLatest();
26
- const end = endingNode || (lexical.$isElementNode(start) ? start.getLastDescendant() : start);
27
- let node = start;
28
-
29
- while (node !== null && !node.is(end)) {
30
- nodes.push(node);
31
-
32
- if (lexical.$isElementNode(node) && node.getChildrenSize() > 0) {
33
- node = node.getFirstChild();
34
- } else {
35
- // Find immediate sibling or nearest parent sibling
36
- let sibling = null;
37
-
38
- while (sibling === null && node !== null) {
39
- sibling = node.getNextSibling();
40
-
41
- if (sibling === null) {
42
- node = node.getParent();
43
- } else {
44
- node = sibling;
45
- }
46
- }
47
- }
48
- }
49
-
50
- if (node !== null && node.is(end)) {
51
- nodes.push(node);
52
- }
53
-
54
- return nodes;
55
- }
56
-
57
- /**
58
- * Copyright (c) Meta Platforms, Inc. and affiliates.
59
- *
60
- * This source code is licensed under the MIT license found in the
61
- * LICENSE file in the root directory of this source tree.
62
- *
63
- *
64
- */
65
- function $textContent() {
66
- const root = lexical.$getRoot();
67
- return root.getTextContent();
68
- }
69
- const $textContentCurry = $textContent;
70
-
71
17
  /**
72
18
  * Copyright (c) Meta Platforms, Inc. and affiliates.
73
19
  *
@@ -90,10 +36,10 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
90
36
  }
91
37
  }, [editor]);
92
38
  React.useEffect(() => {
93
- let text = editor.getEditorState().read($textContentCurry);
39
+ let text$1 = editor.getEditorState().read(text.$rootTextContentCurry);
94
40
  let lastComputedTextLength = 0;
95
41
  return withSubscriptions(editor.addListener('textcontent', currentText => {
96
- text = currentText;
42
+ text$1 = currentText;
97
43
  }), editor.addListener('update', ({
98
44
  dirtyLeaves
99
45
  }) => {
@@ -104,13 +50,13 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
104
50
  return;
105
51
  }
106
52
 
107
- const textLength = strlen(text);
53
+ const textLength = strlen(text$1);
108
54
  const textLengthAboveThreshold = textLength > maxCharacters || lastComputedTextLength !== null && lastComputedTextLength > maxCharacters;
109
55
  const diff = maxCharacters - textLength;
110
56
  remainingCharacters(diff);
111
57
 
112
58
  if (lastComputedTextLength === null || textLengthAboveThreshold) {
113
- const offset = findOffset(text, maxCharacters, strlen);
59
+ const offset = findOffset(text$1, maxCharacters, strlen);
114
60
  editor.update(() => {
115
61
  $wrapOverflowedNodes(offset);
116
62
  }, {
@@ -165,12 +111,14 @@ function findOffset(text, maxCharacters, strlen) {
165
111
  }
166
112
 
167
113
  function $wrapOverflowedNodes(offset) {
168
- const dfsNodes = $dfs();
114
+ const dfsNodes = utils.$dfs();
169
115
  const dfsNodesLength = dfsNodes.length;
170
116
  let accumulatedLength = 0;
171
117
 
172
118
  for (let i = 0; i < dfsNodesLength; i += 1) {
173
- const node = dfsNodes[i];
119
+ const {
120
+ node
121
+ } = dfsNodes[i];
174
122
 
175
123
  if (OverflowNode.$isOverflowNode(node)) {
176
124
  const previousLength = accumulatedLength;
@@ -4,12 +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 l=require("@lexical/react/LexicalComposerContext"),w=require("react"),x=require("lexical"),B=require("@lexical/react/withSubscriptions"),C=require("lexical/OverflowNode");function D(){return x.$getRoot().getTextContent()}
8
- function F(b,d,p=Object.freeze({})){const {strlen:h=e=>e.length,remainingCharacters:r=()=>{}}=p;w.useEffect(()=>{if(!b.hasNodes([C.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]);w.useEffect(()=>{let e=b.getEditorState().read(D),f=0;return B(b.addListener("textcontent",q=>{e=q}),b.addListener("update",({dirtyLeaves:q})=>{var y=b.isComposing();q=0<q.size;if(!y&&
9
- q){y=h(e);q=y>d||null!==f&&f>d;r(d-y);if(null===f||q){const u=G(e,d,h);b.update(()=>{const z=[];for(var c=x.$getRoot().getLatest(),A=x.$isElementNode(c)?c.getLastDescendant():c;null!==c&&!c.is(A);)if(z.push(c),x.$isElementNode(c)&&0<c.getChildrenSize())c=c.getFirstChild();else for(var t=null;null===t&&null!==c;)t=c.getNextSibling(),c=null===t?c.getParent():t;null!==c&&c.is(A)&&z.push(c);A=z.length;c=0;for(t=0;t<A;t+=1){var a=z[t];if(C.$isOverflowNode(a)){var g=c;if(c+a.getTextContentSize()<=u){var k=
10
- a.getParent();g=a.getPreviousSibling();var m=a.getNextSibling();H(a);a=x.$getSelection();!x.$isRangeSelection(a)||a.anchor.getNode().isAttached()&&a.focus.getNode().isAttached()||(x.$isTextNode(g)?g.select():x.$isTextNode(m)?m.select():null!==k&&k.select())}else g<u&&(k=a.getFirstDescendant(),m=null!==k?k.getTextContentSize():0,g+=m,k=x.$isTextNode(k)&&k.isSimpleText(),g=g<=u,(k||g)&&H(a))}else if(x.$isLeafNode(a)&&(g=c,c+=a.getTextContentSize(),c>u&&!C.$isOverflowNode(a.getParent())&&(k=x.$getSelection(),
11
- g<u&&x.$isTextNode(a)&&a.isSimpleText()?([,a]=a.splitText(u-g),a=I(a)):a=I(a),null!==k&&x.$setSelection(k),g=a.getPreviousSibling(),C.$isOverflowNode(g)))){m=a.getFirstChild();var v=g.getChildren();k=v.length;if(null===m)a.append(...v);else for(var n=0;n<k;n++)m.insertBefore(v[n]);n=x.$getSelection();if(x.$isRangeSelection(n)){m=n.anchor;v=m.getNode();n=n.focus;const E=m.getNode();v.is(g)?m.set(a.getKey(),m.offset,"element"):v.is(a)&&m.set(a.getKey(),k+m.offset,"element");E.is(g)?n.set(a.getKey(),
12
- n.offset,"element"):E.is(a)&&n.set(a.getKey(),k+n.offset,"element")}g.remove()}}},{tag:"history-merge"})}f=y}}))},[b,d,r,h])}function G(b,d,p){var h=Intl.Segmenter;let r=0;var e=0;if("function"===typeof h){b=(new h).segment(b);for(var {segment:f}of b){e+=p(f);if(e>d)break;r+=f.length}}else for(f=Array.from(b),b=f.length,h=0;h<b;h++){const q=f[h];e+=p(q);if(e>d)break;r+=q.length}return r}function I(b){const d=C.$createOverflowNode();b.insertBefore(d);d.append(b);return d}
13
- function H(b){const d=b.getChildren(),p=d.length;for(let h=0;h<p;h++)b.insertBefore(d[h]);b.remove();return 0<p?d[p-1]:null}let J=null;
14
- module.exports=function({charset:b="UTF-16"}){const [d]=l.useLexicalComposerContext(),[p,h]=w.useState(0),r=w.useMemo(()=>({remainingCharacters:h,strlen:e=>{if("UTF-8"===b){if(void 0===window.TextEncoder)var f=null;else null===J&&(J=new window.TextEncoder),f=J;null===f?(f=encodeURIComponent(e).match(/%[89ABab]/g),e=e.length+(f?f.length:0)):e=f.encode(e).length;return e}if("UTF-16"===b)return e.length;throw Error("Unrecognized charset");}}),[b]);F(d,5,r);return w.createElement("span",{className:`characters-limit ${0>
15
- p?"characters-limit-exceeded":""}`},p)};
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>
14
+ n?"characters-limit-exceeded":""}`},n)};
@@ -29,10 +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
33
  off(type: 'sync', cb: (isSynced: boolean) => void): void;
33
34
  // $FlowFixMe: temp
34
35
  off(type: 'update', cb: (arg0: any) => void): void;
35
36
  off(type: 'status', cb: (arg0: {status: string}) => void): void;
37
+ off(type: 'reload', cb: (doc: Doc) => boolean): void;
36
38
  }
37
39
  type CollaborationContextType = {
38
40
  clientID: number;
@@ -40,10 +42,12 @@ type CollaborationContextType = {
40
42
  name: string;
41
43
  yjsDocMap: Map<string, Doc>;
42
44
  };
45
+ export type ProviderFactory = (id: string, yjsDocMap: Map<string, Doc>) => Provider;
43
46
  export function CollaborationPlugin(arg0: {
44
47
  id: string;
45
- providerFactory: (id: string, yjsDocMap: Map<string, Doc>) => Provider;
48
+ providerFactory: ProviderFactory;
46
49
  shouldBootstrap: boolean;
50
+ username?: string;
47
51
  }): React.ReactNode;
48
52
  export declare var CollaborationContext: React.Context<CollaborationContextType>;
49
53
  export function useCollaborationContext(): CollaborationContextType;
@@ -22,7 +22,9 @@ var reactDom = require('react-dom');
22
22
  */
23
23
  const EditorPriority = 0;
24
24
  function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBootstrap) {
25
- const binding = React.useMemo(() => yjs.createBinding(editor, provider, id, docMap), [editor, provider, id, docMap]);
25
+ const isReloadingDoc = React.useRef(false);
26
+ const [doc, setDoc] = React.useState(docMap.get(id));
27
+ const binding = React.useMemo(() => yjs.createBinding(editor, provider, id, doc, docMap), [editor, provider, id, docMap, doc]);
26
28
  const connect = React.useCallback(() => {
27
29
  provider.connect();
28
30
  }, [provider]);
@@ -32,7 +34,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
32
34
  } catch (e) {// Do nothing
33
35
  }
34
36
  }, [provider]);
35
- const bootstrapPropagationRef = React.useRef(true);
36
37
  React.useEffect(() => {
37
38
  const {
38
39
  root
@@ -48,10 +49,11 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
48
49
  };
49
50
 
50
51
  const onSync = isSynced => {
51
- if (shouldBootstrap && isSynced && root.isEmpty() && root._xmlText._length === 0) {
52
- bootstrapPropagationRef.current = false;
52
+ if (shouldBootstrap && isSynced && root.isEmpty() && root._xmlText._length === 0 && isReloadingDoc.current === false) {
53
53
  initializeEditor(editor);
54
54
  }
55
+
56
+ isReloadingDoc.current = false;
55
57
  };
56
58
 
57
59
  const onAwarenessUpdate = () => {
@@ -65,6 +67,15 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
65
67
  };
66
68
 
67
69
  yjs.initLocalState(provider, name, color, document.activeElement === editor.getRootElement());
70
+
71
+ const onProviderDocReload = ydoc => {
72
+ clearEditorSkipCollab(editor, binding);
73
+ setDoc(ydoc);
74
+ docMap.set(id, ydoc);
75
+ isReloadingDoc.current = true;
76
+ };
77
+
78
+ provider.on('reload', onProviderDocReload);
68
79
  provider.on('status', onStatus);
69
80
  provider.on('sync', onSync);
70
81
  awareness.on('update', onAwarenessUpdate);
@@ -77,18 +88,24 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
77
88
  normalizedNodes,
78
89
  tags
79
90
  }) => {
80
- yjs.syncLexicalUpdateToYjs(binding, provider, prevEditorState, editorState, dirtyElements, dirtyLeaves, normalizedNodes, tags);
91
+ if (tags.has('skip-collab') === false) {
92
+ yjs.syncLexicalUpdateToYjs(binding, provider, prevEditorState, editorState, dirtyElements, dirtyLeaves, normalizedNodes, tags);
93
+ }
81
94
  });
82
95
  connect();
83
96
  return () => {
84
- disconnect();
97
+ if (isReloadingDoc.current === false) {
98
+ disconnect();
99
+ }
100
+
85
101
  provider.off('sync', onSync);
86
102
  provider.off('status', onStatus);
103
+ provider.off('reload', onProviderDocReload);
87
104
  awareness.off('update', onAwarenessUpdate);
88
105
  root.getSharedType().unobserveDeep(onYjsTreeChanges);
89
106
  removeListener();
90
107
  };
91
- }, [binding, color, connect, disconnect, editor, name, provider, shouldBootstrap]);
108
+ }, [binding, color, connect, disconnect, docMap, editor, id, name, provider, shouldBootstrap]);
92
109
  const cursorsContainer = React.useMemo(() => {
93
110
  const ref = element => {
94
111
  binding.cursorsContainer = element;
@@ -121,18 +138,18 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
121
138
  }, [connect, disconnect, editor]);
122
139
  return [cursorsContainer, binding];
123
140
  }
124
- function useYjsFocusTracking(editor, provider) {
141
+ function useYjsFocusTracking(editor, provider, name, color) {
125
142
  React.useEffect(() => {
126
143
  return editor.addListener('command', (type, payload) => {
127
144
  if (type === 'focus') {
128
- yjs.setLocalStateFocus(provider, true);
145
+ yjs.setLocalStateFocus(provider, name, color, true);
129
146
  } else if (type === 'blur') {
130
- yjs.setLocalStateFocus(provider, false);
147
+ yjs.setLocalStateFocus(provider, name, color, false);
131
148
  }
132
149
 
133
150
  return false;
134
151
  }, EditorPriority);
135
- }, [editor, provider]);
152
+ }, [color, editor, name, provider]);
136
153
  }
137
154
  function useYjsHistory(editor, binding) {
138
155
  const undoManager = React.useMemo(() => yjs.createUndoManager(binding, binding.root.getSharedType()), [binding]);
@@ -186,6 +203,43 @@ function initializeEditor(editor) {
186
203
  });
187
204
  }
188
205
 
206
+ function clearEditorSkipCollab(editor, binding) {
207
+ // reset editor state
208
+ editor.update(() => {
209
+ const root = lexical.$getRoot();
210
+ root.clear();
211
+ root.select();
212
+ }, {
213
+ tag: 'skip-collab'
214
+ });
215
+
216
+ if (binding.cursors == null) {
217
+ return;
218
+ }
219
+
220
+ const cursorsContainer = binding.cursorsContainer;
221
+
222
+ if (cursorsContainer == null) {
223
+ return;
224
+ } // reset cursors in dom
225
+
226
+
227
+ const cursors = Array.from(binding.cursors.values());
228
+
229
+ for (let i = 0; i < cursors.length; i++) {
230
+ const cursor = cursors[i];
231
+ const selection = cursor.selection;
232
+
233
+ if (selection && selection.selections != null) {
234
+ const selections = selection.selections;
235
+
236
+ for (let j = 0; j < selections.length; j++) {
237
+ cursorsContainer.removeChild(selections[i]);
238
+ }
239
+ }
240
+ }
241
+ }
242
+
189
243
  /**
190
244
  * Copyright (c) Meta Platforms, Inc. and affiliates.
191
245
  *
@@ -199,9 +253,10 @@ const randomEntry = entries[Math.floor(Math.random() * (entries.length - 1 - 0 +
199
253
  function CollaborationPlugin({
200
254
  id,
201
255
  providerFactory,
202
- shouldBootstrap
256
+ shouldBootstrap,
257
+ username
203
258
  }) {
204
- const collabContext = useCollaborationContext();
259
+ const collabContext = useCollaborationContext(username);
205
260
  const {
206
261
  yjsDocMap,
207
262
  name,
@@ -212,7 +267,7 @@ function CollaborationPlugin({
212
267
  const [cursors, binding] = useYjsCollaboration(editor, id, provider, yjsDocMap, name, color, shouldBootstrap);
213
268
  collabContext.clientID = binding.clientID;
214
269
  useYjsHistory(editor, binding);
215
- useYjsFocusTracking(editor, provider);
270
+ useYjsFocusTracking(editor, provider, name, color);
216
271
  return cursors;
217
272
  }
218
273
  const CollaborationContext = /*#__PURE__*/React.createContext({
@@ -221,8 +276,14 @@ const CollaborationContext = /*#__PURE__*/React.createContext({
221
276
  name: randomEntry[0],
222
277
  yjsDocMap: new Map()
223
278
  });
224
- function useCollaborationContext() {
225
- return React.useContext(CollaborationContext);
279
+ function useCollaborationContext(username) {
280
+ const collabContext = React.useContext(CollaborationContext);
281
+
282
+ if (username != null) {
283
+ collabContext.name = username;
284
+ }
285
+
286
+ return collabContext;
226
287
  }
227
288
 
228
289
  exports.CollaborationContext = CollaborationContext;
@@ -18,7 +18,7 @@ export type UserState = {
18
18
  };
19
19
 
20
20
  export type ProviderAwareness = {
21
- getLocalState: () => UserState,
21
+ getLocalState: () => UserState | null,
22
22
  setLocalState: (UserState) => void,
23
23
  getStates: () => Map<number, UserState>,
24
24
  on: (type: 'update', cb: () => void) => void,
@@ -33,10 +33,12 @@ export interface Provider {
33
33
  on(type: 'status', cb: ({status: string}) => void): void;
34
34
  // $FlowFixMe: temp
35
35
  on(type: 'update', cb: (any) => void): void;
36
+ on(type: 'reload', cb: (doc: Doc) => void): void;
36
37
  off(type: 'sync', cb: (isSynced: boolean) => void): void;
37
38
  // $FlowFixMe: temp
38
39
  off(type: 'update', cb: (any) => void): void;
39
40
  off(type: 'status', cb: ({status: string}) => void): void;
41
+ off(type: 'reload', cb: (doc: Doc) => void): void;
40
42
  }
41
43
 
42
44
  type CollaborationContextType = {
@@ -46,10 +48,13 @@ type CollaborationContextType = {
46
48
  yjsDocMap: Map<string, Doc>,
47
49
  };
48
50
 
51
+ export type ProviderFactory = (id: string, yjsDocMap: Map<string, Doc>) => Provider;
52
+
49
53
  declare export function CollaborationPlugin(arg0: {
50
54
  id: string,
51
- providerFactory: (id: string, yjsDocMap: Map<string, Doc>) => Provider,
55
+ providerFactory: ProviderFactory,
52
56
  shouldBootstrap: boolean,
57
+ username?: string
53
58
  }): React$Node;
54
59
  declare export var CollaborationContext: React$Context<CollaborationContextType>;
55
60
  declare export function useCollaborationContext(): CollaborationContextType;
@@ -4,10 +4,12 @@
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 d=require("@lexical/react/LexicalComposerContext"),g=require("react"),u=require("@lexical/yjs"),A=require("lexical"),B=require("react-dom");
8
- function C(b,c,a,h,n,p,q){const e=g.useMemo(()=>u.createBinding(b,a,c,h),[b,a,c,h]),k=g.useCallback(()=>{a.connect()},[a]),l=g.useCallback(()=>{try{a.disconnect()}catch(f){}},[a]),r=g.useRef(!0);g.useEffect(()=>{const {root:f}=e,{awareness:t}=a,w=({status:m})=>{b.execCommand("connected","connected"===m)},x=m=>{q&&m&&f.isEmpty()&&0===f._xmlText._length&&(r.current=!1,D(b))},y=()=>{u.syncCursorPositions(e,a)},z=(m,v)=>{v.origin!==e&&u.syncYjsChangesToLexical(e,a,m)};u.initLocalState(a,n,p,document.activeElement===
9
- b.getRootElement());a.on("status",w);a.on("sync",x);t.on("update",y);f.getSharedType().observeDeep(z);const M=b.addListener("update",({prevEditorState:m,editorState:v,dirtyLeaves:I,dirtyElements:J,normalizedNodes:K,tags:L})=>{u.syncLexicalUpdateToYjs(e,a,m,v,J,I,K,L)});k();return()=>{l();a.off("sync",x);a.off("status",w);t.off("update",y);f.getSharedType().unobserveDeep(z);M()}},[e,p,k,l,b,n,a,q]);const N=g.useMemo(()=>B.createPortal(g.createElement("div",{ref:f=>{e.cursorsContainer=f}}),document.body),
10
- [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[N,e]}function E(b,c){g.useEffect(()=>b.addListener("command",a=>{"focus"===a?u.setLocalStateFocus(c,!0):"blur"===a&&u.setLocalStateFocus(c,!1);return!1},0),[b,c])}
11
- function F(b,c){const a=g.useMemo(()=>u.createUndoManager(c,c.root.getSharedType()),[c]);g.useEffect(()=>b.addListener("command",h=>"undo"===h?(a.undo(),!0):"redo"===h?(a.redo(),!0):!1,0));return g.useCallback(()=>{a.clear()},[a])}function D(b){b.update(()=>{var c=A.$getRoot();if(null===c.getFirstChild()){const a=A.$createParagraphNode();c.append(a);c=document.activeElement;(null!==A.$getSelection()||null!==c&&c===b.getRootElement())&&a.select()}},{tag:"history-merge"})}
12
- const G=[["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"]],H=G[Math.floor(Math.random()*(G.length-1+1))],O=g.createContext({clientID:0,color:H[1],name:H[0],yjsDocMap:new Map});
13
- function P(){return g.useContext(O)}exports.CollaborationContext=O;exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a}){const h=P(),{yjsDocMap:n,name:p,color:q}=h,[e]=d.useLexicalComposerContext(),k=g.useMemo(()=>c(b,n),[b,c,n]),[l,r]=C(e,b,k,n,p,q,a);h.clientID=r.clientID;F(e,r);E(e,k);return l};exports.useCollaborationContext=P;
7
+ var e=require("@lexical/react/LexicalComposerContext"),l=require("react"),u=require("@lexical/yjs"),E=require("lexical"),F=require("react-dom");
8
+ function G(c,b,a,d,g,n,p){const m=l.useRef(!1),[q,w]=l.useState(d.get(b)),f=l.useMemo(()=>u.createBinding(c,a,b,q,d),[c,a,b,d,q]),r=l.useCallback(()=>{a.connect()},[a]),t=l.useCallback(()=>{try{a.disconnect()}catch(k){}},[a]);l.useEffect(()=>{const {root:k}=f,{awareness:v}=a,y=({status:h})=>{c.execCommand("connected","connected"===h)},z=h=>{p&&h&&k.isEmpty()&&0===k._xmlText._length&&!1===m.current&&H(c);m.current=!1},A=()=>{u.syncCursorPositions(f,a)},B=(h,x)=>{x.origin!==f&&u.syncYjsChangesToLexical(f,
9
+ a,h)};u.initLocalState(a,g,n,document.activeElement===c.getRootElement());const C=h=>{I(c,f);w(h);d.set(b,h);m.current=!0};a.on("reload",C);a.on("status",y);a.on("sync",z);v.on("update",A);k.getSharedType().observeDeep(B);const Q=c.addListener("update",({prevEditorState:h,editorState:x,dirtyLeaves:N,dirtyElements:O,normalizedNodes:P,tags:D})=>{!1===D.has("skip-collab")&&u.syncLexicalUpdateToYjs(f,a,h,x,O,N,P,D)});r();return()=>{!1===m.current&&t();a.off("sync",z);a.off("status",y);a.off("reload",
10
+ C);v.off("update",A);k.getSharedType().unobserveDeep(B);Q()}},[f,n,r,t,d,c,b,g,a,p]);const R=l.useMemo(()=>F.createPortal(l.createElement("div",{ref:k=>{f.cursorsContainer=k}}),document.body),[f]);l.useEffect(()=>c.addListener("command",(k,v)=>{"toggleConnect"===k&&void 0!==r&&void 0!==t&&(v?(console.log("Collaboration connected!"),r()):(console.log("Collaboration disconnected!"),t()));return!1},0),[r,t,c]);return[R,f]}
11
+ function J(c,b,a,d){l.useEffect(()=>c.addListener("command",g=>{"focus"===g?u.setLocalStateFocus(b,a,d,!0):"blur"===g&&u.setLocalStateFocus(b,a,d,!1);return!1},0),[d,c,a,b])}function K(c,b){const a=l.useMemo(()=>u.createUndoManager(b,b.root.getSharedType()),[b]);l.useEffect(()=>c.addListener("command",d=>"undo"===d?(a.undo(),!0):"redo"===d?(a.redo(),!0):!1,0));return l.useCallback(()=>{a.clear()},[a])}
12
+ function H(c){c.update(()=>{var b=E.$getRoot();if(null===b.getFirstChild()){const a=E.$createParagraphNode();b.append(a);b=document.activeElement;(null!==E.$getSelection()||null!==b&&b===c.getRootElement())&&a.select()}},{tag:"history-merge"})}
13
+ function I(c,b){c.update(()=>{const d=E.$getRoot();d.clear();d.select()},{tag:"skip-collab"});if(null!=b.cursors&&(c=b.cursorsContainer,null!=c)){b=Array.from(b.cursors.values());for(let d=0;d<b.length;d++){var a=b[d].selection;if(a&&null!=a.selections){a=a.selections;for(let g=0;g<a.length;g++)c.removeChild(a[d])}}}}
14
+ const L=[["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"]],M=L[Math.floor(Math.random()*(L.length-1+1))],S=l.createContext({clientID:0,color:M[1],name:M[0],yjsDocMap:new Map});
15
+ function T(c){const b=l.useContext(S);null!=c&&(b.name=c);return b}exports.CollaborationContext=S;exports.CollaborationPlugin=function({id:c,providerFactory:b,shouldBootstrap:a,username:d}){d=T(d);const {yjsDocMap:g,name:n,color:p}=d,[m]=e.useLexicalComposerContext(),q=l.useMemo(()=>b(c,g),[c,b,g]),[w,f]=G(m,c,q,g,n,p,a);d.clientID=f.clientID;K(m,f);J(m,q,n,p);return w};exports.useCollaborationContext=T;
@@ -9,7 +9,7 @@
9
9
  import {Class} from 'utility-types';
10
10
  import type {EditorThemeClasses, LexicalEditor, LexicalNode} from 'lexical';
11
11
  type Props = {
12
- initialConfig?: {
12
+ initialConfig: {
13
13
  editor?: LexicalEditor | null;
14
14
  isReadOnly?: boolean;
15
15
  namespace?: string;
@@ -40,7 +40,7 @@ var useLayoutEffect = useLayoutEffectImpl;
40
40
  *
41
41
  */
42
42
  function LexicalComposer({
43
- initialConfig = {},
43
+ initialConfig,
44
44
  children
45
45
  }) {
46
46
  const parentContext = React.useContext(LexicalComposerContext.LexicalComposerContext);
@@ -10,14 +10,14 @@
10
10
  import type {EditorThemeClasses, LexicalEditor, LexicalNode} from 'lexical';
11
11
 
12
12
  type Props = {
13
- initialConfig?: {
13
+ initialConfig: $ReadOnly<{
14
14
  editor?: LexicalEditor | null,
15
15
  isReadOnly?: boolean,
16
16
  namespace?: string,
17
- nodes?: Array<Class<LexicalNode>>,
17
+ nodes?: $ReadOnlyArray<Class<LexicalNode>>,
18
18
  theme?: EditorThemeClasses,
19
19
  onError: (error: Error, editor: LexicalEditor) => void,
20
- },
20
+ }>,
21
21
  children: React$Node,
22
22
  };
23
23
 
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var b=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),n=require("react"),p="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?n.useLayoutEffect:n.useEffect;
8
- module.exports=function({initialConfig:h={},children:q}){const d=n.useContext(b.LexicalComposerContext),m=n.useMemo(()=>{let a,e;const {theme:k,namespace:r,editor:t,nodes:u,onError:v}=h;if(null!=k)a=k;else if(null!=d){e=d[0];var c=d[1].getTheme();null!=c&&(a=c)}c=b.createLexicalComposerContext(d,a);let g=t||null;if(null===g){const l=f.createEditor({context:c,namespace:r,nodes:u,onError:w=>v(w,l),parentEditor:e,readOnly:!0,theme:a});g=l}return[g,c]},[]);p(()=>{const a=h.readOnly,[e]=m;e.setReadOnly(a||
8
+ module.exports=function({initialConfig:h,children:q}){const d=n.useContext(b.LexicalComposerContext),m=n.useMemo(()=>{let a,e;const {theme:k,namespace:r,editor:t,nodes:u,onError:v}=h;if(null!=k)a=k;else if(null!=d){e=d[0];var c=d[1].getTheme();null!=c&&(a=c)}c=b.createLexicalComposerContext(d,a);let g=t||null;if(null===g){const l=f.createEditor({context:c,namespace:r,nodes:u,onError:w=>v(w,l),parentEditor:e,readOnly:!0,theme:a});g=l}return[g,c]},[]);p(()=>{const a=h.readOnly,[e]=m;e.setReadOnly(a||
9
9
  !1)},[]);return n.createElement(b.LexicalComposerContext.Provider,{value:m},q)};