@lexical/react 0.1.8 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPRECATED_useLexical.dev.js +3 -38
- package/DEPRECATED_useLexical.prod.js +1 -2
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +202 -74
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +21 -16
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +23 -21
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
- package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
- package/DEPRECATED_useLexicalEditor.dev.js +1 -25
- package/DEPRECATED_useLexicalEditor.prod.js +1 -1
- package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +18 -15
- package/DEPRECATED_useLexicalHistory.prod.js +7 -7
- package/DEPRECATED_useLexicalList.dev.js +6 -0
- package/DEPRECATED_useLexicalList.prod.js +1 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +79 -70
- package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
- package/DEPRECATED_useLexicalRichText.dev.js +124 -250
- package/DEPRECATED_useLexicalRichText.prod.js +25 -29
- package/LexicalAutoFormatterPlugin.dev.js +202 -74
- package/LexicalAutoFormatterPlugin.js.flow +10 -0
- package/LexicalAutoFormatterPlugin.prod.js +21 -17
- package/LexicalAutoLinkPlugin.js.flow +23 -0
- package/LexicalAutoLinkPlugin.prod.js +4 -4
- package/LexicalCharacterLimitPlugin.dev.js +23 -21
- package/LexicalCharacterLimitPlugin.js.flow +12 -0
- package/LexicalCharacterLimitPlugin.prod.js +9 -8
- package/LexicalClearEditorPlugin.dev.js +52 -0
- package/LexicalClearEditorPlugin.js +9 -0
- package/LexicalClearEditorPlugin.js.flow +14 -0
- package/LexicalClearEditorPlugin.prod.js +7 -0
- package/LexicalCollaborationPlugin.dev.js +31 -36
- package/LexicalCollaborationPlugin.js.flow +55 -0
- package/LexicalCollaborationPlugin.prod.js +7 -8
- package/LexicalComposer.dev.js +8 -6
- package/LexicalComposer.js.flow +23 -0
- package/LexicalComposer.prod.js +3 -3
- package/LexicalComposerContext.js.flow +27 -0
- package/LexicalComposerContext.prod.js +1 -1
- package/LexicalContentEditable.dev.js +14 -8
- package/LexicalContentEditable.js.flow +35 -0
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalHashtagPlugin.js.flow +20 -0
- package/LexicalHashtagPlugin.prod.js +1 -1
- package/LexicalHistoryPlugin.dev.js +18 -15
- package/LexicalHistoryPlugin.js.flow +34 -0
- package/LexicalHistoryPlugin.prod.js +7 -7
- package/LexicalHorizontalRuleNode.dev.js +66 -0
- package/LexicalHorizontalRuleNode.js +9 -0
- package/LexicalHorizontalRuleNode.js.flow +25 -0
- package/LexicalHorizontalRuleNode.prod.js +8 -0
- package/LexicalLinkPlugin.dev.js +0 -1
- package/LexicalLinkPlugin.js.flow +10 -0
- package/LexicalLinkPlugin.prod.js +3 -3
- package/LexicalListPlugin.dev.js +6 -0
- package/LexicalListPlugin.js.flow +10 -0
- package/LexicalListPlugin.prod.js +2 -2
- package/LexicalNestedComposer.js.flow +21 -0
- package/LexicalNestedComposer.prod.js +1 -1
- package/LexicalOnChangePlugin.js.flow +14 -0
- package/LexicalOnChangePlugin.prod.js +1 -1
- package/LexicalPlainTextPlugin.dev.js +72 -44
- package/LexicalPlainTextPlugin.js.flow +18 -0
- package/LexicalPlainTextPlugin.prod.js +12 -11
- package/LexicalRichTextPlugin.dev.js +115 -222
- package/LexicalRichTextPlugin.js.flow +18 -0
- package/LexicalRichTextPlugin.prod.js +21 -25
- package/LexicalTablePlugin.dev.js +43 -39
- package/LexicalTablePlugin.js.flow +10 -0
- package/LexicalTablePlugin.prod.js +4 -3
- package/LexicalTreeView.dev.js +10 -2
- package/LexicalTreeView.js.flow +19 -0
- package/LexicalTreeView.prod.js +9 -8
- package/README.md +0 -1
- package/package.json +5 -4
- package/useLexicalDecoratorMap.js.flow +16 -0
- package/useLexicalDecoratorMap.prod.js +1 -1
- package/useLexicalIsTextContentEmpty.js.flow +15 -0
- package/useLexicalIsTextContentEmpty.prod.js +1 -1
- package/useLexicalNodeSelection.dev.js +70 -0
- package/useLexicalNodeSelection.js +9 -0
- package/useLexicalNodeSelection.js.flow +14 -0
- package/useLexicalNodeSelection.prod.js +8 -0
- package/withSubscriptions.js.flow +13 -0
- package/withSubscriptions.prod.js +1 -1
- package/LexicalBootstrapPlugin.dev.js +0 -124
- package/LexicalBootstrapPlugin.js +0 -9
- package/LexicalBootstrapPlugin.prod.js +0 -8
- package/LexicalHorizontalRulePlugin.dev.js +0 -51
- package/LexicalHorizontalRulePlugin.js +0 -9
- package/LexicalHorizontalRulePlugin.prod.js +0 -7
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare export default function LexicalAutoFormatterPlugin(): React$Node;
|
|
@@ -4,20 +4,24 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
{...
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
(f
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
a
|
|
18
|
-
|
|
19
|
-
e=d
|
|
20
|
-
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
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,b){g=g.getChildren();const c=g.length;let d=0,e=!1;for(let p=0;p<c&&!(d>f);++p){const m=g[p],n=r.$isTextNode(m);var h=n?m.getTextContent().length:b;h=d+h;if((!1===e&&d===a||0===d&&d===a||d<a&&a<=h)&&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:/(?:``` )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/(?:\*\*\* )/},{...H,nodeTransformationKind:"horizontalRule",regEx:/(?:--- )/},...I];
|
|
12
|
+
function K(g,f,a,b){const c={offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]};b=g.match(b);if(null!==b&&0<b.length&&(!1===f||0===b.index)&&(!1===a||b.index+b[0].length===g.length)){c.offsetInJoinedTextForCollapsedSelection=g.length;g=b.length;f=b.index;for(a=0;a<g;a++){const d=b[a];c.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:f,text:d,textLength:d.length-(a+1===g?1:0)});0<a&&(f+=d.length)}return c}return null}
|
|
13
|
+
function L(g,f,a,b,c){c.offsetInJoinedTextForCollapsedSelection+=g;0<c.offsetInJoinedTextForCollapsedSelection||D(67);c=c.regExCaptureGroups;const d=c.length;for(b+=1;b<d;b++){const e=c[b];null!=e.anchorTextNodeWithOffset&&e.anchorTextNodeWithOffset.offset>=f&&e.anchorTextNodeWithOffset.node.is(a)&&(e.anchorTextNodeWithOffset.offset+=g);null!=e.focusTextNodeWithOffset&&e.focusTextNodeWithOffset.offset>=f&&e.focusTextNodeWithOffset.node.is(a)&&(e.focusTextNodeWithOffset.offset+=g)}}
|
|
14
|
+
function M(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,b=a.node.getParentOrThrow();a=a.node.spliceText(0,f.matchResultContext.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var c=b;a=null;var d=c.getChildren(),e=f.autoFormatCriteria,h=f.matchResultContext;if(null!=e.nodeTransformationKind)switch(e.nodeTransformationKind){case "paragraphH1":a=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");c=q.$createListItemNode();c.append(...d);a.append(c);break;case "paragraphOrderedList":a=parseInt(1<h.regExCaptureGroups.length?h.regExCaptureGroups[h.regExCaptureGroups.length-1].text:"1",10);a=q.$createListNode("ol",a);c=q.$createListItemNode();c.append(...d);
|
|
16
|
+
a.append(c);break;case "paragraphCodeBlock":a=null!=f.triggerState&&f.triggerState.isCodeBlock?r.$createParagraphNode():t.$createCodeNode();a.append(...d);break;case "horizontalRule":d=x.$createHorizontalRuleNode(),c.insertBefore(d)}null!==a&&b.replace(a)}else if(a=f.autoFormatCriteria,b=f.matchResultContext,null!=a.nodeTransformationKind&&6===b.regExCaptureGroups.length){a:{a=a.nodeTransformationKind;switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=
|
|
17
|
+
["bold","italic"];break a}a=null}if(null!=a){d=[1,5];c=f.autoFormatCriteria;e=f.matchResultContext.regExCaptureGroups;h=e.length;var p=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&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&&D(63,c.nodeTransformationKind)}b.regExCaptureGroups=e;if(0<d.length)for(c=b.regExCaptureGroups,e=c.length,
|
|
18
|
+
h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=c[p],n=l.anchorTextNodeWithOffset,m=l.focusTextNodeWithOffset,null!=n&&null!=m&&0<l.textLength&&(l=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),L(-l,m.offset,n.node,p,b)):(n=m.offset,0<n&&L(-n,n,m.node,p,b)))));d=b.regExCaptureGroups;3<d.length||D(65);
|
|
19
|
+
e=d[3];c=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=c&&null!=d&&0<e.textLength&&(e=r.$createRangeSelection(),e.anchor.set(c.node.getKey(),c.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),r.$setSelection(e),c=r.$getSelection(),r.$isRangeSelection(c))){for(e=0;e<a.length;e++)c.formatText(a[e]);a=r.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");r.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();
|
|
20
|
+
b=E(a,b.offsetInJoinedTextForCollapsedSelection+1,b.offsetInJoinedTextForCollapsedSelection,1);null!=b&&(a=r.$createRangeSelection(),a.anchor.set(b.node.getKey(),b.offset,"text"),a.focus.set(b.node.getKey(),b.offset,"text"),r.$setSelection(a))}}},{tag:"history-push"})}
|
|
21
|
+
function N(g,f){let a=null;g.read(()=>{var b=r.$getSelection();if(r.$isRangeSelection(b)){var c=b.anchor.getNode();b=r.$isTextNode(c)?{node:c,offset:b.anchor.offset}:null}else b=null;if(null!==b){b={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:b,triggerState:f};a:{c=!1===f.isParentAListItemNode?J:I;const n=b.triggerState,
|
|
22
|
+
l=c.length;for(let z=0;z<l;z++){const A=c[z];if(null!=n&&!1===n.isCodeBlock||"paragraphCodeBlock"===A.nodeTransformationKind){var d=A,e=b;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=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){c={autoFormatCriteria:A,matchResultContext:d};break a}}}c={autoFormatCriteria:null,matchResultContext:null}}null!==c.autoFormatCriteria&&null!==c.matchResultContext&&(a=b,a.autoFormatCriteria=
|
|
24
|
+
c.autoFormatCriteria,a.matchResultContext=c.matchResultContext)}});return a}
|
|
25
|
+
function P(g){let f=null;g.read(()=>{const a=r.$getSelection();if(r.$isRangeSelection(a)&&a.isCollapsed()){var b=a.anchor.getNode(),c=b.getParent(),d=null!==c&&q.$isListItemNode(c);f={anchorOffset:a.anchor.offset,hasParentNode:null!==c,isCodeBlock:t.$isCodeNode(b),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:r.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return f}
|
|
26
|
+
function Q(g){u.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var b=g.getEditorState();a=P(b);if(null==a)b=null;else{var c=a,d=f;if(null==c||null==d)b=null;else{var e=c.textContent.length,h=c.anchorOffset-1;b=!1===(!0===c.hasParentNode&&c.isSimpleText&&c.isSelectionCollapsed&&c.nodeKey===d.nodeKey&&c.anchorOffset!==d.anchorOffset&&0<=h&&h+1<=e&&" "===c.textContent.substr(h,1)&&c.textContent!==d.textContent)?null:N(b,c)}}null!=b&&M(g,b);f=a}else f=
|
|
27
|
+
null})},[g])}module.exports=function(){const [g]=k.useLexicalComposerContext();Q(g);return null};
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
type ChangeHandler = (url: string | null, prevUrl: string | null) => void;
|
|
11
|
+
|
|
12
|
+
type LinkMatcherResult = {
|
|
13
|
+
text: string,
|
|
14
|
+
url: string,
|
|
15
|
+
length: number,
|
|
16
|
+
index: number,
|
|
17
|
+
};
|
|
18
|
+
export type LinkMatcher = (text: string) => LinkMatcherResult | null;
|
|
19
|
+
|
|
20
|
+
declare export default function LexicalAutoLinkPlugin(props: {
|
|
21
|
+
matchers: Array<LinkMatcher>,
|
|
22
|
+
onChange?: ChangeHandler,
|
|
23
|
+
}): React$Node;
|
|
@@ -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
|
-
|
|
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("
|
|
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,
|
|
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};
|
|
@@ -20,11 +20,15 @@ var OverflowNode = require('lexical/OverflowNode');
|
|
|
20
20
|
*
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
|
-
function $
|
|
24
|
-
|
|
25
|
-
|
|
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);
|
|
26
31
|
|
|
27
|
-
while (node !== null) {
|
|
28
32
|
if (lexical.$isElementNode(node) && node.getChildrenSize() > 0) {
|
|
29
33
|
node = node.getFirstChild();
|
|
30
34
|
} else {
|
|
@@ -41,11 +45,13 @@ function $dfs__DEPRECATED(startingNode, nextNode) {
|
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
}
|
|
48
|
+
}
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
50
|
+
if (node !== null && node.is(end)) {
|
|
51
|
+
nodes.push(node);
|
|
48
52
|
}
|
|
53
|
+
|
|
54
|
+
return nodes;
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
/**
|
|
@@ -106,10 +112,9 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
|
|
|
106
112
|
if (lastComputedTextLength === null || textLengthAboveThreshold) {
|
|
107
113
|
const offset = findOffset(text, maxCharacters, strlen);
|
|
108
114
|
editor.update(() => {
|
|
109
|
-
lexical.$log('CharacterLimit');
|
|
110
115
|
$wrapOverflowedNodes(offset);
|
|
111
116
|
}, {
|
|
112
|
-
tag: '
|
|
117
|
+
tag: 'history-merge'
|
|
113
118
|
});
|
|
114
119
|
}
|
|
115
120
|
|
|
@@ -160,10 +165,13 @@ function findOffset(text, maxCharacters, strlen) {
|
|
|
160
165
|
}
|
|
161
166
|
|
|
162
167
|
function $wrapOverflowedNodes(offset) {
|
|
163
|
-
const
|
|
168
|
+
const dfsNodes = $dfs();
|
|
169
|
+
const dfsNodesLength = dfsNodes.length;
|
|
164
170
|
let accumulatedLength = 0;
|
|
165
|
-
|
|
166
|
-
|
|
171
|
+
|
|
172
|
+
for (let i = 0; i < dfsNodesLength; i += 1) {
|
|
173
|
+
const node = dfsNodes[i];
|
|
174
|
+
|
|
167
175
|
if (OverflowNode.$isOverflowNode(node)) {
|
|
168
176
|
const previousLength = accumulatedLength;
|
|
169
177
|
const nextLength = accumulatedLength + node.getTextContentSize();
|
|
@@ -175,7 +183,7 @@ function $wrapOverflowedNodes(offset) {
|
|
|
175
183
|
$unwrapNode(node);
|
|
176
184
|
const selection = lexical.$getSelection(); // Restore selection when the overflow children are removed
|
|
177
185
|
|
|
178
|
-
if (selection
|
|
186
|
+
if (lexical.$isRangeSelection(selection) && (!selection.anchor.getNode().isAttached() || !selection.focus.getNode().isAttached())) {
|
|
179
187
|
if (lexical.$isTextNode(previousSibling)) {
|
|
180
188
|
previousSibling.select();
|
|
181
189
|
} else if (lexical.$isTextNode(nextSibling)) {
|
|
@@ -184,8 +192,6 @@ function $wrapOverflowedNodes(offset) {
|
|
|
184
192
|
parent.select();
|
|
185
193
|
}
|
|
186
194
|
}
|
|
187
|
-
|
|
188
|
-
return previousNode;
|
|
189
195
|
} else if (previousLength < offset) {
|
|
190
196
|
const descendant = node.getFirstDescendant();
|
|
191
197
|
const descendantLength = descendant !== null ? descendant.getTextContentSize() : 0;
|
|
@@ -197,7 +203,6 @@ function $wrapOverflowedNodes(offset) {
|
|
|
197
203
|
|
|
198
204
|
if (firstDescendantIsSimpleText || firstDescendantDoesNotOverflow) {
|
|
199
205
|
$unwrapNode(node);
|
|
200
|
-
return previousNode;
|
|
201
206
|
}
|
|
202
207
|
}
|
|
203
208
|
} else if (lexical.$isLeafNode(node)) {
|
|
@@ -223,10 +228,7 @@ function $wrapOverflowedNodes(offset) {
|
|
|
223
228
|
mergePrevious(overflowNode);
|
|
224
229
|
}
|
|
225
230
|
}
|
|
226
|
-
|
|
227
|
-
previousNode = node;
|
|
228
|
-
return node;
|
|
229
|
-
});
|
|
231
|
+
}
|
|
230
232
|
}
|
|
231
233
|
|
|
232
234
|
function $wrapNode(node) {
|
|
@@ -269,7 +271,7 @@ function mergePrevious(overflowNode) {
|
|
|
269
271
|
|
|
270
272
|
const selection = lexical.$getSelection();
|
|
271
273
|
|
|
272
|
-
if (selection
|
|
274
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
273
275
|
const anchor = selection.anchor;
|
|
274
276
|
const anchorNode = anchor.getNode();
|
|
275
277
|
const focus = selection.focus;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare export default function LexicalCharacterLimitPlugin(props: {
|
|
11
|
+
charset: 'UTF-8' | 'UTF-16',
|
|
12
|
+
}): React$Node;
|
|
@@ -4,11 +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
|
-
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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)};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
|
+
var lexical = require('lexical');
|
|
11
|
+
var react = require('react');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
+
*
|
|
16
|
+
* This source code is licensed under the MIT license found in the
|
|
17
|
+
* LICENSE file in the root directory of this source tree.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
function LexicalClearEditorPlugin({
|
|
22
|
+
onClear
|
|
23
|
+
}) {
|
|
24
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
25
|
+
react.useLayoutEffect(() => {
|
|
26
|
+
return editor.addListener('command', (type, payload) => {
|
|
27
|
+
if (type === 'clearEditor') {
|
|
28
|
+
editor.update(() => {
|
|
29
|
+
if (onClear == null) {
|
|
30
|
+
const root = lexical.$getRoot();
|
|
31
|
+
const selection = lexical.$getSelection();
|
|
32
|
+
const paragraph = lexical.$createParagraphNode();
|
|
33
|
+
root.clear();
|
|
34
|
+
root.append(paragraph);
|
|
35
|
+
|
|
36
|
+
if (selection !== null) {
|
|
37
|
+
paragraph.select();
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
onClear();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return false;
|
|
47
|
+
}, 0);
|
|
48
|
+
}, [editor, onClear]);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = LexicalClearEditorPlugin;
|
|
@@ -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 LexicalClearEditorPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalClearEditorPlugin.dev.js') : require('./LexicalClearEditorPlugin.prod.js')
|
|
9
|
+
module.exports = LexicalClearEditorPlugin;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
type Props = $ReadOnly<{
|
|
11
|
+
onClear?: () => void,
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
declare export default function LexicalClearEditorPlugin(Props): React$Node;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
var a=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),g=require("react");module.exports=function({onClear:b}){const [c]=a.useLexicalComposerContext();g.useLayoutEffect(()=>c.addListener("command",h=>"clearEditor"===h?(c.update(()=>{if(null==b){const d=f.$getRoot(),k=f.$getSelection(),e=f.$createParagraphNode();d.clear();d.append(e);null!==k&&e.select()}else b()}),!0):!1,0),[c,b]);return null};
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
10
|
var React = require('react');
|
|
11
11
|
var yjs = require('@lexical/yjs');
|
|
12
|
+
var lexical = require('lexical');
|
|
12
13
|
var reactDom = require('react-dom');
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -20,7 +21,6 @@ var reactDom = require('react-dom');
|
|
|
20
21
|
*
|
|
21
22
|
*/
|
|
22
23
|
const EditorPriority = 0;
|
|
23
|
-
const BootstrapPriority = 1;
|
|
24
24
|
function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBootstrap) {
|
|
25
25
|
const binding = React.useMemo(() => yjs.createBinding(editor, provider, id, docMap), [editor, provider, id, docMap]);
|
|
26
26
|
const connect = React.useCallback(() => {
|
|
@@ -32,16 +32,7 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
32
32
|
} catch (e) {// Do nothing
|
|
33
33
|
}
|
|
34
34
|
}, [provider]);
|
|
35
|
-
const
|
|
36
|
-
React.useLayoutEffect(() => {
|
|
37
|
-
return editor.addListener('command', type => {
|
|
38
|
-
if (type === 'bootstrapEditor') {
|
|
39
|
-
return !isInitialized.current;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return false;
|
|
43
|
-
}, BootstrapPriority);
|
|
44
|
-
}, [editor]);
|
|
35
|
+
const bootstrapPropagationRef = React.useRef(true);
|
|
45
36
|
React.useEffect(() => {
|
|
46
37
|
const {
|
|
47
38
|
root
|
|
@@ -58,8 +49,8 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
58
49
|
|
|
59
50
|
const onSync = isSynced => {
|
|
60
51
|
if (shouldBootstrap && isSynced && root.isEmpty() && root._xmlText._length === 0) {
|
|
61
|
-
|
|
62
|
-
editor
|
|
52
|
+
bootstrapPropagationRef.current = false;
|
|
53
|
+
initializeEditor(editor);
|
|
63
54
|
}
|
|
64
55
|
};
|
|
65
56
|
|
|
@@ -132,31 +123,16 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
132
123
|
}
|
|
133
124
|
function useYjsFocusTracking(editor, provider) {
|
|
134
125
|
React.useEffect(() => {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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);
|
|
126
|
+
return editor.addListener('command', (type, payload) => {
|
|
127
|
+
if (type === 'focus') {
|
|
128
|
+
yjs.setLocalStateFocus(provider, true);
|
|
129
|
+
} else if (type === 'blur') {
|
|
130
|
+
yjs.setLocalStateFocus(provider, false);
|
|
148
131
|
}
|
|
149
132
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
rootElement.addEventListener('blur', onBlur);
|
|
156
|
-
rootElement.addEventListener('focus', onFocus);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}, [editor, provider, provider.awareness]);
|
|
133
|
+
return false;
|
|
134
|
+
}, EditorPriority);
|
|
135
|
+
}, [editor, provider]);
|
|
160
136
|
}
|
|
161
137
|
function useYjsHistory(editor, binding) {
|
|
162
138
|
const undoManager = React.useMemo(() => yjs.createUndoManager(binding, binding.root.getSharedType()), [binding]);
|
|
@@ -191,6 +167,25 @@ function useYjsHistory(editor, binding) {
|
|
|
191
167
|
return clearHistory;
|
|
192
168
|
}
|
|
193
169
|
|
|
170
|
+
function initializeEditor(editor) {
|
|
171
|
+
editor.update(() => {
|
|
172
|
+
const root = lexical.$getRoot();
|
|
173
|
+
const firstChild = root.getFirstChild();
|
|
174
|
+
|
|
175
|
+
if (firstChild === null) {
|
|
176
|
+
const paragraph = lexical.$createParagraphNode();
|
|
177
|
+
root.append(paragraph);
|
|
178
|
+
const activeElement = document.activeElement;
|
|
179
|
+
|
|
180
|
+
if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
|
|
181
|
+
paragraph.select();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}, {
|
|
185
|
+
tag: 'history-merge'
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
194
189
|
/**
|
|
195
190
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
196
191
|
*
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {Doc, RelativePosition} from 'yjs';
|
|
11
|
+
|
|
12
|
+
export type UserState = {
|
|
13
|
+
anchorPos: null | RelativePosition,
|
|
14
|
+
focusPos: null | RelativePosition,
|
|
15
|
+
name: string,
|
|
16
|
+
color: string,
|
|
17
|
+
focusing: boolean,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ProviderAwareness = {
|
|
21
|
+
getLocalState: () => UserState,
|
|
22
|
+
setLocalState: (UserState) => void,
|
|
23
|
+
getStates: () => Array<UserState>,
|
|
24
|
+
on: (type: 'update', cb: () => void) => void,
|
|
25
|
+
off: (type: 'update', cb: () => void) => void,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export interface Provider {
|
|
29
|
+
connect(): void | Promise<void>;
|
|
30
|
+
disconnect(): void;
|
|
31
|
+
awareness: ProviderAwareness;
|
|
32
|
+
on(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
33
|
+
on(type: 'status', cb: ({status: string}) => void): void;
|
|
34
|
+
// $FlowFixMe: temp
|
|
35
|
+
on(type: 'update', cb: (any) => void): void;
|
|
36
|
+
off(type: 'sync', cb: (isSynced: boolean) => void): void;
|
|
37
|
+
// $FlowFixMe: temp
|
|
38
|
+
off(type: 'update', cb: (any) => void): void;
|
|
39
|
+
off(type: 'status', cb: ({status: string}) => void): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type CollaborationContextType = {
|
|
43
|
+
clientID: number,
|
|
44
|
+
color: string,
|
|
45
|
+
name: string,
|
|
46
|
+
yjsDocMap: Map<string, Doc>,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
declare export function CollaborationPlugin(arg0: {
|
|
50
|
+
id: string,
|
|
51
|
+
providerFactory: (id: string, yjsDocMap: Map<string, Doc>) => Provider,
|
|
52
|
+
shouldBootstrap: boolean,
|
|
53
|
+
}): React$Node;
|
|
54
|
+
declare export var CollaborationContext: React$Context<CollaborationContextType>;
|
|
55
|
+
declare export function useCollaborationContext(): CollaborationContextType;
|
|
@@ -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
|
-
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
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 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;
|