@lexical/react 0.1.14 → 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 +3 -1
- package/LexicalCollaborationPlugin.dev.js +40 -6
- package/LexicalCollaborationPlugin.js.flow +4 -1
- package/LexicalCollaborationPlugin.prod.js +8 -7
- package/LexicalHashtagPlugin.dev.js +16 -13
- package/LexicalHashtagPlugin.prod.js +7 -7
- 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 +9 -7
- 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)};
|
|
@@ -42,10 +42,12 @@ type CollaborationContextType = {
|
|
|
42
42
|
name: string;
|
|
43
43
|
yjsDocMap: Map<string, Doc>;
|
|
44
44
|
};
|
|
45
|
+
export type ProviderFactory = (id: string, yjsDocMap: Map<string, Doc>) => Provider;
|
|
45
46
|
export function CollaborationPlugin(arg0: {
|
|
46
47
|
id: string;
|
|
47
|
-
providerFactory:
|
|
48
|
+
providerFactory: ProviderFactory;
|
|
48
49
|
shouldBootstrap: boolean;
|
|
50
|
+
username?: string;
|
|
49
51
|
}): React.ReactNode;
|
|
50
52
|
export declare var CollaborationContext: React.Context<CollaborationContextType>;
|
|
51
53
|
export function useCollaborationContext(): CollaborationContextType;
|
|
@@ -69,7 +69,7 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
69
69
|
yjs.initLocalState(provider, name, color, document.activeElement === editor.getRootElement());
|
|
70
70
|
|
|
71
71
|
const onProviderDocReload = ydoc => {
|
|
72
|
-
clearEditorSkipCollab(editor);
|
|
72
|
+
clearEditorSkipCollab(editor, binding);
|
|
73
73
|
setDoc(ydoc);
|
|
74
74
|
docMap.set(id, ydoc);
|
|
75
75
|
isReloadingDoc.current = true;
|
|
@@ -203,7 +203,8 @@ function initializeEditor(editor) {
|
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
function clearEditorSkipCollab(editor) {
|
|
206
|
+
function clearEditorSkipCollab(editor, binding) {
|
|
207
|
+
// reset editor state
|
|
207
208
|
editor.update(() => {
|
|
208
209
|
const root = lexical.$getRoot();
|
|
209
210
|
root.clear();
|
|
@@ -211,6 +212,32 @@ function clearEditorSkipCollab(editor) {
|
|
|
211
212
|
}, {
|
|
212
213
|
tag: 'skip-collab'
|
|
213
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
|
+
}
|
|
214
241
|
}
|
|
215
242
|
|
|
216
243
|
/**
|
|
@@ -226,9 +253,10 @@ const randomEntry = entries[Math.floor(Math.random() * (entries.length - 1 - 0 +
|
|
|
226
253
|
function CollaborationPlugin({
|
|
227
254
|
id,
|
|
228
255
|
providerFactory,
|
|
229
|
-
shouldBootstrap
|
|
256
|
+
shouldBootstrap,
|
|
257
|
+
username
|
|
230
258
|
}) {
|
|
231
|
-
const collabContext = useCollaborationContext();
|
|
259
|
+
const collabContext = useCollaborationContext(username);
|
|
232
260
|
const {
|
|
233
261
|
yjsDocMap,
|
|
234
262
|
name,
|
|
@@ -248,8 +276,14 @@ const CollaborationContext = /*#__PURE__*/React.createContext({
|
|
|
248
276
|
name: randomEntry[0],
|
|
249
277
|
yjsDocMap: new Map()
|
|
250
278
|
});
|
|
251
|
-
function useCollaborationContext() {
|
|
252
|
-
|
|
279
|
+
function useCollaborationContext(username) {
|
|
280
|
+
const collabContext = React.useContext(CollaborationContext);
|
|
281
|
+
|
|
282
|
+
if (username != null) {
|
|
283
|
+
collabContext.name = username;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return collabContext;
|
|
253
287
|
}
|
|
254
288
|
|
|
255
289
|
exports.CollaborationContext = CollaborationContext;
|
|
@@ -48,10 +48,13 @@ type CollaborationContextType = {
|
|
|
48
48
|
yjsDocMap: Map<string, Doc>,
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
+
export type ProviderFactory = (id: string, yjsDocMap: Map<string, Doc>) => Provider;
|
|
52
|
+
|
|
51
53
|
declare export function CollaborationPlugin(arg0: {
|
|
52
54
|
id: string,
|
|
53
|
-
providerFactory:
|
|
55
|
+
providerFactory: ProviderFactory,
|
|
54
56
|
shouldBootstrap: boolean,
|
|
57
|
+
username?: string
|
|
55
58
|
}): React$Node;
|
|
56
59
|
declare export var CollaborationContext: React$Context<CollaborationContextType>;
|
|
57
60
|
declare export function useCollaborationContext(): CollaborationContextType;
|
|
@@ -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
|
-
var
|
|
8
|
-
function G(c,b,a,
|
|
9
|
-
a,
|
|
10
|
-
v.off("update",A);k.getSharedType().unobserveDeep(B);Q()}},[f,n,r,t,
|
|
11
|
-
function J(c,b,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"})}
|
|
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])}}}}
|
|
13
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});
|
|
14
|
-
function T(){
|
|
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;
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var hashtag = require('@lexical/hashtag');
|
|
9
10
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
11
|
var lexical = require('lexical');
|
|
11
|
-
var
|
|
12
|
+
var OverflowNode = require('lexical/OverflowNode');
|
|
12
13
|
var react = require('react');
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -129,13 +130,15 @@ function textNodeTransform(node) {
|
|
|
129
130
|
while (true) {
|
|
130
131
|
const matchArr = REGEX.exec(text);
|
|
131
132
|
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
if (currentNode == null) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
135
136
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
const nextSibling = currentNode.getNextSibling();
|
|
138
|
+
|
|
139
|
+
if (matchArr === null) {
|
|
140
|
+
if (hashtag.$isHashtagNode(nextSibling) && !endsWithValidChar(text) && !isNextNodeValid(currentNode)) {
|
|
141
|
+
hashtag.$toggleHashtag(nextSibling);
|
|
139
142
|
}
|
|
140
143
|
|
|
141
144
|
return;
|
|
@@ -147,7 +150,7 @@ function textNodeTransform(node) {
|
|
|
147
150
|
const prevChar = text[startOffset - 1] || '';
|
|
148
151
|
const nextChar = text[endOffset] || '';
|
|
149
152
|
|
|
150
|
-
if (startOffset === 0 &&
|
|
153
|
+
if (startOffset === 0 && hashtag.$isHashtagNode(currentNode.getPreviousSibling()) || !isValidCharacter(prevChar) || !isValidCharacter(nextChar) || nextChar === '' && lexical.$isTextNode(nextSibling) && !nextSibling.isSimpleText()) {
|
|
151
154
|
continue;
|
|
152
155
|
}
|
|
153
156
|
|
|
@@ -160,18 +163,18 @@ function textNodeTransform(node) {
|
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
adjustedOffset += endOffset;
|
|
163
|
-
|
|
166
|
+
hashtag.$toggleHashtag(targetNode);
|
|
164
167
|
}
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
function isPreviousNodeValid(node) {
|
|
168
171
|
const previousNode = node.getPreviousSibling();
|
|
169
|
-
return previousNode === null || lexical.$isLineBreakNode(previousNode) || lexical.$isTextNode(previousNode) && !
|
|
172
|
+
return previousNode === null || lexical.$isLineBreakNode(previousNode) || OverflowNode.$isOverflowNode(previousNode) || lexical.$isTextNode(previousNode) && !hashtag.$isHashtagNode(previousNode) && endsWithValidChar(previousNode.getTextContent());
|
|
170
173
|
}
|
|
171
174
|
|
|
172
175
|
function isNextNodeValid(node) {
|
|
173
176
|
const nextNode = node.getNextSibling();
|
|
174
|
-
return nextNode === null || lexical.$isLineBreakNode(nextNode) || lexical.$isTextNode(nextNode) && !
|
|
177
|
+
return nextNode === null || lexical.$isLineBreakNode(nextNode) || OverflowNode.$isOverflowNode(nextNode) || lexical.$isTextNode(nextNode) && !hashtag.$isHashtagNode(nextNode) && startsWithValidChar(nextNode.getTextContent());
|
|
175
178
|
}
|
|
176
179
|
|
|
177
180
|
function $hashtagToPlainTextTransform(hashtagNode) {
|
|
@@ -189,8 +192,8 @@ function $convertHashtagNodeToPlainTextNode(node) {
|
|
|
189
192
|
|
|
190
193
|
function useHashtags(editor) {
|
|
191
194
|
react.useEffect(() => {
|
|
192
|
-
const removePlainTextTransform = editor.
|
|
193
|
-
const removeHashtagToPlainTextTransform = editor.
|
|
195
|
+
const removePlainTextTransform = editor.addNodeTransform(lexical.TextNode, textNodeTransform);
|
|
196
|
+
const removeHashtagToPlainTextTransform = editor.addNodeTransform(hashtag.HashtagNode, $hashtagToPlainTextTransform);
|
|
194
197
|
return () => {
|
|
195
198
|
removePlainTextTransform();
|
|
196
199
|
removeHashtagToPlainTextTransform();
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var e=require("@lexical/react/LexicalComposerContext"),
|
|
8
|
-
const
|
|
9
|
-
"-"+
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
function
|
|
7
|
+
var e=require("@lexical/hashtag"),f=require("@lexical/react/LexicalComposerContext"),g=require("lexical"),h=require("lexical/OverflowNode"),n=require("react"),p=RegExp;
|
|
8
|
+
const q=String.fromCharCode,r="A-Za-z\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u0241\u0250-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ee\u037a\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03ce\u03d0-\u03f5\u03f7-\u0481\u048a-\u04ce\u04d0-\u04f9\u0500-\u050f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0621-\u063a\u0640-\u064a\u066e-\u066f\u0671-\u06d3\u06d5\u06e5-\u06e6\u06ee-\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u076d\u0780-\u07a5\u07b1\u0904-\u0939\u093d\u0950\u0958-\u0961\u097d\u0985-\u098c\u098f-\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc-\u09dd\u09df-\u09e1\u09f0-\u09f1\u0a05-\u0a0a\u0a0f-\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32-\u0a33\u0a35-\u0a36\u0a38-\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2-\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0-\u0ae1\u0b05-\u0b0c\u0b0f-\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32-\u0b33\u0b35-\u0b39\u0b3d\u0b5c-\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99-\u0b9a\u0b9c\u0b9e-\u0b9f\u0ba3-\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c60-\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0-\u0ce1\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d28\u0d2a-\u0d39\u0d60-\u0d61\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32-\u0e33\u0e40-\u0e46\u0e81-\u0e82\u0e84\u0e87-\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa-\u0eab\u0ead-\u0eb0\u0eb2-\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edd\u0f00\u0f40-\u0f47\u0f49-\u0f6a\u0f88-\u0f8b\u1000-\u1021\u1023-\u1027\u1029-\u102a\u1050-\u1055\u10a0-\u10c5\u10d0-\u10fa\u10fc\u1100-\u1159\u115f-\u11a2\u11a8-\u11f9\u1200-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u1676\u1681-\u169a\u16a0-\u16ea\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19a9\u19c1-\u19c7\u1a00-\u1a16\u1d00-\u1dbf\u1e00-\u1e9b\u1ea0-\u1ef9\u1f00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u2094\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2131\u2133-\u2139\u213c-\u213f\u2145-\u2149\u2c00-\u2c2e\u2c30-\u2c5e\u2c80-\u2ce4\u2d00-\u2d25\u2d30-\u2d65\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3006\u3031-\u3035\u303b-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312c\u3131-\u318e\u31a0-\u31b7\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fbb\ua000-\ua48c\ua800-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\uac00-\ud7a3\uf900-\ufa2d\ufa30-\ufa6a\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc\u0300-\u036f\u0483-\u0486\u0591-\u05b9\u05bb-\u05bd\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u0610-\u0615\u064b-\u065e\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u0901-\u0903\u093c\u093e-\u094d\u0951-\u0954\u0962-\u0963\u0981-\u0983\u09bc\u09be-\u09c4\u09c7-\u09c8\u09cb-\u09cd\u09d7\u09e2-\u09e3\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a70-\u0a71\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0b01-\u0b03\u0b3c\u0b3e-\u0b43\u0b47-\u0b48\u0b4b-\u0b4d\u0b56-\u0b57\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0c01-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56\u0c82-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5-\u0cd6\u0d02-\u0d03\u0d3e-\u0d43\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d82-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2-\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f3e-\u0f3f\u0f71-\u0f84\u0f86-\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102c-\u1032\u1036-\u1039\u1056-\u1059\u135f\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17b6-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u192b\u1930-\u193b\u19b0-\u19c0\u19c8-\u19c9\u1a17-\u1a1b\u1dc0-\u1dc3\u20d0-\u20dc\u20e1\u20e5-\u20eb\u302a-\u302f\u3099-\u309a\ua802\ua806\ua80b\ua823-\ua827\ufb1e\ufe00-\ufe0f\ufe20-\ufe23\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0100-\u024f\u0253-\u0254\u0256-\u0257\u0259\u025b\u0263\u0268\u026f\u0272\u0289\u028b\u02bb\u0300-\u036f\u1e00-\u1eff\u0400-\u04ff\u0500-\u0527\u2de0-\u2dff\ua640-\ua69f\u0591-\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u05d0-\u05ea\u05f0-\u05f4\ufb12-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4f\u0610-\u061a\u0620-\u065f\u066e-\u06d3\u06d5-\u06dc\u06de-\u06e8\u06ea-\u06ef\u06fa-\u06fc\u06ff\u0750-\u077f\u08a0\u08a2-\u08ac\u08e4-\u08fe\ufb50-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\u200c-\u200c\u0e01-\u0e3a\u0e40-\u0e4e\u1100-\u11ff\u3130-\u3185\ua960-\ua97f\uac00-\ud7af\ud7b0-\ud7ff\uffa1-\uffdc\u30a1-\u30fa\u30fc-\u30fe\uff66-\uff9f\uff10-\uff19\uff21-\uff3a\uff41-\uff5a\u3041-\u3096\u3099-\u309e\u3400-\u4dbf\u4e00-\u9fff"+(q(173824)+
|
|
9
|
+
"-"+q(177983)+q(177984)+"-"+q(178207)+q(194560)+"-"+q(195103)+"\u3003\u3005\u303b"),{alpha:t,alphanumeric:v,hashChars:w}={alpha:r,alphanumeric:r+"0-9\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0be6-\u0bef\u0c66-\u0c6f\u0ce6-\u0cef\u0d66-\u0d6f\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29\u1040-\u1049\u17e0-\u17e9\u1810-\u1819\u1946-\u194f\u19d0-\u19d9\uff10-\uff19_",hashChars:"#\\uFF03"},x="["+v+"]",y=new p("(^|$|[^&/"+(v+"])([")+(w+"])(")+x+"*["+(t+"]")+
|
|
10
|
+
x+"*)","ig");function z(a){return""===a||-1<a.search(/[\s.,\\\/#!$%\^&\*;:{}=\-`~()@]/)}
|
|
11
|
+
function A(a){if(a.isSimpleText())for(var b=a.getTextContent(),c=0;;){var d=y.exec(b);if(null==a)break;const l=a.getNextSibling();if(null===d){!e.$isHashtagNode(l)||z(b[b.length-1])||B(a)||e.$toggleHashtag(l);break}const k=d.index+d[1].length-c;d=k+(d[3].length+1);const C=b[k-1]||"",u=b[d]||"";if(0===k&&e.$isHashtagNode(a.getPreviousSibling())||!z(C)||!z(u)||""===u&&g.$isTextNode(l)&&!l.isSimpleText())continue;let m;0===k?[m,a]=a.splitText(d):[,m,a]=a.splitText(k,d);c+=d;e.$toggleHashtag(m)}}
|
|
12
|
+
function B(a){a=a.getNextSibling();return null===a||g.$isLineBreakNode(a)||h.$isOverflowNode(a)||g.$isTextNode(a)&&!e.$isHashtagNode(a)&&z(a.getTextContent()[0])}function D(a){var b=a.getPreviousSibling(),c;!(c=null===b||g.$isLineBreakNode(b)||h.$isOverflowNode(b))&&(c=g.$isTextNode(b)&&!e.$isHashtagNode(b))&&(b=b.getTextContent(),c=z(b[b.length-1]));c&&B(a)||(b=g.$createTextNode(a.getTextContent()),a.replace(b))}
|
|
13
|
+
function E(a){n.useEffect(()=>{const b=a.addNodeTransform(g.TextNode,A),c=a.addNodeTransform(e.HashtagNode,D);return()=>{b();c()}},[a])}module.exports=function(){const [a]=f.useLexicalComposerContext();E(a);return null};
|
|
@@ -39,18 +39,31 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
39
39
|
*
|
|
40
40
|
*/
|
|
41
41
|
function OnChangePlugin({
|
|
42
|
+
ignoreInitialChange = true,
|
|
43
|
+
ignoreSelectionChange = false,
|
|
42
44
|
onChange
|
|
43
45
|
}) {
|
|
44
46
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
45
47
|
useLayoutEffect(() => {
|
|
46
48
|
if (onChange) {
|
|
47
49
|
return editor.addListener('update', ({
|
|
48
|
-
editorState
|
|
50
|
+
editorState,
|
|
51
|
+
dirtyElements,
|
|
52
|
+
dirtyLeaves,
|
|
53
|
+
prevEditorState
|
|
49
54
|
}) => {
|
|
55
|
+
if (ignoreSelectionChange && dirtyElements.size === 0 && dirtyLeaves.size === 0) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (ignoreInitialChange && prevEditorState.isEmpty()) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
50
63
|
onChange(editorState, editor);
|
|
51
64
|
});
|
|
52
65
|
}
|
|
53
|
-
}, [editor, onChange]);
|
|
66
|
+
}, [editor, ignoreInitialChange, ignoreSelectionChange, onChange]);
|
|
54
67
|
return null;
|
|
55
68
|
}
|
|
56
69
|
|
|
@@ -4,4 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var c=require("@lexical/react/LexicalComposerContext"),
|
|
7
|
+
var c=require("@lexical/react/LexicalComposerContext"),f=require("react"),g="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;
|
|
8
|
+
module.exports=function({ignoreInitialChange:d=!0,ignoreSelectionChange:e=!1,onChange:a}){const [b]=c.useLexicalComposerContext();g(()=>{if(a)return b.addListener("update",({editorState:h,dirtyElements:k,dirtyLeaves:l,prevEditorState:m})=>{e&&0===k.size&&0===l.size||d&&m.isEmpty()||a(h,b)})},[b,d,e,a]);return null};
|