@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.
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +283 -295
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -21
- package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +3 -72
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -2
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +11 -63
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +6 -7
- package/DEPRECATED_useLexicalPlainText.dev.js +16 -41
- package/DEPRECATED_useLexicalPlainText.prod.js +13 -14
- package/DEPRECATED_useLexicalRichText.dev.js +24 -49
- package/DEPRECATED_useLexicalRichText.prod.js +15 -15
- package/LexicalAutoFormatterPlugin.dev.js +283 -295
- package/LexicalAutoFormatterPlugin.prod.js +19 -21
- package/LexicalAutoLinkPlugin.dev.js +2 -2
- package/LexicalAutoLinkPlugin.prod.js +2 -2
- package/LexicalCharacterLimitPlugin.dev.js +11 -63
- package/LexicalCharacterLimitPlugin.prod.js +8 -9
- package/LexicalCollaborationPlugin.d.ts +5 -1
- package/LexicalCollaborationPlugin.dev.js +77 -16
- package/LexicalCollaborationPlugin.js.flow +7 -2
- package/LexicalCollaborationPlugin.prod.js +9 -7
- package/LexicalComposer.d.ts +1 -1
- package/LexicalComposer.dev.js +1 -1
- package/LexicalComposer.js.flow +3 -3
- package/LexicalComposer.prod.js +1 -1
- package/LexicalHashtagPlugin.dev.js +61 -3
- package/LexicalHashtagPlugin.prod.js +7 -4
- package/LexicalNestedComposer.d.ts +4 -7
- package/LexicalNestedComposer.dev.js +21 -11
- package/LexicalNestedComposer.js.flow +3 -6
- package/LexicalNestedComposer.prod.js +3 -2
- package/LexicalOnChangePlugin.dev.js +15 -2
- package/LexicalOnChangePlugin.prod.js +2 -1
- package/LexicalPlainTextPlugin.dev.js +20 -113
- package/LexicalPlainTextPlugin.prod.js +11 -12
- package/LexicalRichTextPlugin.dev.js +28 -121
- package/LexicalRichTextPlugin.prod.js +12 -13
- package/LexicalTablePlugin.dev.js +9 -5
- package/LexicalTablePlugin.prod.js +2 -2
- package/package.json +11 -6
- package/useLexicalIsTextContentEmpty.dev.js +3 -32
- 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
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
{...
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
a.append(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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(
|
|
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 =
|
|
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
|
|
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
|
|
8
|
-
function F(b,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
|
|
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:
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
[
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
function
|
|
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;
|
package/LexicalComposer.d.ts
CHANGED
package/LexicalComposer.dev.js
CHANGED
package/LexicalComposer.js.flow
CHANGED
|
@@ -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?:
|
|
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
|
|
package/LexicalComposer.prod.js
CHANGED
|
@@ -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
|
|
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)};
|