@lexical/react 0.1.13 → 0.1.16
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 -14
- package/LexicalCollaborationPlugin.js.flow +7 -2
- package/LexicalCollaborationPlugin.prod.js +9 -7
- package/LexicalHashtagPlugin.dev.js +61 -3
- package/LexicalHashtagPlugin.prod.js +7 -4
- 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 +10 -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
|
-
|
|
26
|
-
function P(g){t.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var c=g.getEditorState();a=O(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:M(c,b)}}null!=c&&L(g,c);f=a}else f=
|
|
27
|
-
null})},[g])}module.exports=function(g){P(g)};
|
|
7
|
+
var h=require("@lexical/list"),l=require("lexical"),m=require("lexical/CodeNode"),n=require("react"),p=require("@lexical/react/LexicalHorizontalRuleNode"),q=require("@lexical/text"),r=require("lexical/HeadingNode"),t=require("lexical/QuoteNode");function x(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 y={autoFormatKind:null,regEx:/(?:)/,requiresParagraphStart:!1},z={...y,requiresParagraphStart:!0},A=[{...y,autoFormatKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*)(\s)$/},{...y,autoFormatKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*)(\s)$/},{...y,autoFormatKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*)(\s)$/},{...y,autoFormatKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__)(\s)$/},{...y,autoFormatKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)(\s)$/},
|
|
9
|
+
{...y,autoFormatKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~)(\s)$/},{...y,autoFormatKind:"link",regEx:/(\[)(.+)(\]\()([^ ]+)(?: "(?:.+)")?(\))(\s)$/}],B=[{...z,autoFormatKind:"paragraphH1",regEx:/^(?:# )/},{...z,autoFormatKind:"paragraphH2",regEx:/^(?:## )/},{...z,autoFormatKind:"paragraphH2",regEx:/^(?:### )/},{...z,autoFormatKind:"paragraphBlockQuote",regEx:/^(?:> )/},{...z,autoFormatKind:"paragraphUnorderedList",regEx:/^(?:- )/},{...z,autoFormatKind:"paragraphUnorderedList",regEx:/^(?:\* )/},
|
|
10
|
+
{...z,autoFormatKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/},{...z,autoFormatKind:"paragraphCodeBlock",regEx:/^(```)([a-z]*)( )/},{...z,autoFormatKind:"horizontalRule",regEx:/^(?:\*\*\* )/},{...z,autoFormatKind:"horizontalRule",regEx:/^(?:--- )/},...A];
|
|
11
|
+
function C(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 D(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=q.$findNodeWithOffsetFromJoinedText(a?f.offsetInParent+f.text.length:f.offsetInParent,e,1,c);b=q.$findNodeWithOffsetFromJoinedText(b,e,1,c);if(null==
|
|
13
|
+
a||null==b)return null;c=l.$createRangeSelection();c.anchor.set(a.node.getKey(),a.offset,"text");c.focus.set(b.node.getKey(),b.offset,"text");return c}function E(f,d,a){const b=a.patternMatchResults.regExCaptureGroups;a=D(f,d,!1,!0,a);if(null!=a&&(l.$setSelection(a),a=l.$getSelection(),null!=a&&l.$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 F(f){var d=f.patternMatchResults.regExCaptureGroups.length;2>d||(--d,f=D(d,d,!0,!0,f),null!=f&&l.$setSelection(f))}
|
|
15
|
+
function G(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=r.$createHeadingNode("h1");a.append(...e);break;case "paragraphH2":a=
|
|
16
|
+
r.$createHeadingNode("h2");a.append(...e);break;case "paragraphH3":a=r.$createHeadingNode("h3");a.append(...e);break;case "paragraphBlockQuote":a=t.$createQuoteNode();a.append(...e);break;case "paragraphUnorderedList":a=h.$createListNode("ul");c=h.$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=h.$createListNode("ol",a);c=h.$createListItemNode();c.append(...e);
|
|
17
|
+
a.append(c);break;case "paragraphCodeBlock":null!=d.triggerState&&d.triggerState.isCodeBlock?a=l.$createParagraphNode():(a=m.$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=p.$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){E(5,5,d);E(1,1,d);a=d.patternMatchResults.regExCaptureGroups;3<a.length||x(65);if(0!==a[3].text.length&&(a=D(3,3,!1,!0,d),null!=a&&(l.$setSelection(a),a=l.$getSelection(),l.$isRangeSelection(a))))for(e=0;e<b.length;e++)a.formatText(b[e]);F(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))){E(1,5,d);a=d.patternMatchResults.regExCaptureGroups;if(!(1>=a.length)&&(e={offsetInParent:a[1].offsetInParent,text:e},c=D(1,1,!1,!1,d),null!=c&&(l.$setSelection(c),c=l.$getSelection(),null!=c&&l.$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=D(1,1,!1,!0,d);null!=a&&(l.$setSelection(a),d.editor.execCommand("toggleLink",b),F(d))}}},{tag:"history-push"})}
|
|
20
|
+
function H(f,d){let a=null;f.getEditorState().read(()=>{var b=l.$getSelection();if(l.$isRangeSelection(b)){var c=b.anchor.getNode();b=l.$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?B:A;const k=b.triggerState,I=c.length;for(let u=0;u<
|
|
21
|
+
I;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=C(g,!0,!1,e.regEx)):g=null;else{if(null==g.joinedText){const w=g.textNodeWithOffset.node.getParentOrThrow();l.$isElementNode(w)?null==g.joinedText&&(g.joinedText=q.$joinTextNodesInElementNode(w,"\u0004",g.textNodeWithOffset)):x(52,
|
|
22
|
+
w.__key)}g=C(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 J(f){let d=null;f.read(()=>{const a=l.$getSelection();if(l.$isRangeSelection(a)&&a.isCollapsed()){var b=a.anchor.getNode(),c=b.getParent(),e=null!==c&&h.$isListItemNode(c);d={anchorOffset:a.anchor.offset,hasParentNode:null!==c,isCodeBlock:m.$isCodeNode(b),isParentAListItemNode:e,isSelectionCollapsed:a.isCollapsed(),isSimpleText:l.$isTextNode(b)&&b.isSimpleText(),nodeKey:b.getKey(),textContent:b.getTextContent()}}});return d}
|
|
24
|
+
function K(f){n.useEffect(()=>{let d=null;return f.addListener("update",({tags:a})=>{if(!1===a.has("historic")){a=J(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:H(f,b)}}null!=b&&G(f,b);d=a}else d=null})},
|
|
25
|
+
[f])}module.exports=function(f){K(f)};
|
|
@@ -6,78 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var text = require('@lexical/text');
|
|
10
10
|
var react = require('react');
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
function $textContent() {
|
|
21
|
-
const root = lexical.$getRoot();
|
|
22
|
-
return root.getTextContent();
|
|
23
|
-
}
|
|
24
|
-
function $isTextContentEmpty(isEditorComposing, trim = true) {
|
|
25
|
-
if (isEditorComposing) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let text = $textContent();
|
|
30
|
-
|
|
31
|
-
if (trim) {
|
|
32
|
-
text = text.trim();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return text === '';
|
|
36
|
-
}
|
|
37
|
-
function $canShowPlaceholder(isComposing) {
|
|
38
|
-
if (!$isTextContentEmpty(isComposing, false)) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const root = lexical.$getRoot();
|
|
43
|
-
const children = root.getChildren();
|
|
44
|
-
const childrenLength = children.length;
|
|
45
|
-
|
|
46
|
-
if (childrenLength > 1) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
for (let i = 0; i < childrenLength; i++) {
|
|
51
|
-
const topBlock = children[i];
|
|
52
|
-
|
|
53
|
-
if (lexical.$isElementNode(topBlock)) {
|
|
54
|
-
if (topBlock.__type !== 'paragraph') {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (topBlock.__indent !== 0) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const topBlockChildren = topBlock.getChildren();
|
|
63
|
-
const topBlockChildrenLength = topBlockChildren.length;
|
|
64
|
-
|
|
65
|
-
for (let s = 0; s < topBlockChildrenLength; s++) {
|
|
66
|
-
const child = topBlockChildren[i];
|
|
67
|
-
|
|
68
|
-
if (!lexical.$isTextNode(child)) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
function $canShowPlaceholderCurry(isEditorComposing) {
|
|
78
|
-
return () => $canShowPlaceholder(isEditorComposing);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
12
|
/**
|
|
82
13
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
83
14
|
*
|
|
@@ -108,13 +39,13 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
108
39
|
*
|
|
109
40
|
*/
|
|
110
41
|
function useLexicalCanShowPlaceholder$1(editor) {
|
|
111
|
-
const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(editor.getEditorState().read(
|
|
42
|
+
const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
|
|
112
43
|
useLayoutEffect(() => {
|
|
113
44
|
return editor.addListener('update', ({
|
|
114
45
|
editorState
|
|
115
46
|
}) => {
|
|
116
47
|
const isComposing = editor.isComposing();
|
|
117
|
-
const currentCanShowPlaceholder = editorState.read(
|
|
48
|
+
const currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
|
|
118
49
|
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
119
50
|
});
|
|
120
51
|
}, [editor]);
|
|
@@ -4,5 +4,4 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
var n="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;function p(a){const [d,b]=f.useState(a.getEditorState().read(m(a.isComposing())));n(()=>a.addListener("update",({editorState:c})=>{const g=a.isComposing();c=c.read(m(g));b(c)}),[a]);return d}module.exports=function(a){return p(a)};
|
|
7
|
+
var b=require("@lexical/text"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;function f(a){const [g,h]=d.useState(a.getEditorState().read(b.$canShowPlaceholderCurry(a.isComposing())));e(()=>a.addListener("update",({editorState:c})=>{const k=a.isComposing();c=c.read(b.$canShowPlaceholderCurry(k));h(c)}),[a]);return g}module.exports=function(a){return f(a)};
|
|
@@ -6,67 +6,13 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
var lexical = require('lexical');
|
|
10
9
|
var withSubscriptions = require('@lexical/react/withSubscriptions');
|
|
10
|
+
var text = require('@lexical/text');
|
|
11
|
+
var utils = require('@lexical/utils');
|
|
12
|
+
var lexical = require('lexical');
|
|
11
13
|
var OverflowNode = require('lexical/OverflowNode');
|
|
12
14
|
var react = require('react');
|
|
13
15
|
|
|
14
|
-
/**
|
|
15
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
-
*
|
|
17
|
-
* This source code is licensed under the MIT license found in the
|
|
18
|
-
* LICENSE file in the root directory of this source tree.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
function $dfs(startingNode, endingNode) {
|
|
23
|
-
const nodes = [];
|
|
24
|
-
const start = (startingNode || lexical.$getRoot()).getLatest();
|
|
25
|
-
const end = endingNode || (lexical.$isElementNode(start) ? start.getLastDescendant() : start);
|
|
26
|
-
let node = start;
|
|
27
|
-
|
|
28
|
-
while (node !== null && !node.is(end)) {
|
|
29
|
-
nodes.push(node);
|
|
30
|
-
|
|
31
|
-
if (lexical.$isElementNode(node) && node.getChildrenSize() > 0) {
|
|
32
|
-
node = node.getFirstChild();
|
|
33
|
-
} else {
|
|
34
|
-
// Find immediate sibling or nearest parent sibling
|
|
35
|
-
let sibling = null;
|
|
36
|
-
|
|
37
|
-
while (sibling === null && node !== null) {
|
|
38
|
-
sibling = node.getNextSibling();
|
|
39
|
-
|
|
40
|
-
if (sibling === null) {
|
|
41
|
-
node = node.getParent();
|
|
42
|
-
} else {
|
|
43
|
-
node = sibling;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (node !== null && node.is(end)) {
|
|
50
|
-
nodes.push(node);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return nodes;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
58
|
-
*
|
|
59
|
-
* This source code is licensed under the MIT license found in the
|
|
60
|
-
* LICENSE file in the root directory of this source tree.
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*/
|
|
64
|
-
function $textContent() {
|
|
65
|
-
const root = lexical.$getRoot();
|
|
66
|
-
return root.getTextContent();
|
|
67
|
-
}
|
|
68
|
-
const $textContentCurry = $textContent;
|
|
69
|
-
|
|
70
16
|
/**
|
|
71
17
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
72
18
|
*
|
|
@@ -89,10 +35,10 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
|
|
|
89
35
|
}
|
|
90
36
|
}, [editor]);
|
|
91
37
|
react.useEffect(() => {
|
|
92
|
-
let text = editor.getEditorState().read(
|
|
38
|
+
let text$1 = editor.getEditorState().read(text.$rootTextContentCurry);
|
|
93
39
|
let lastComputedTextLength = 0;
|
|
94
40
|
return withSubscriptions(editor.addListener('textcontent', currentText => {
|
|
95
|
-
text = currentText;
|
|
41
|
+
text$1 = currentText;
|
|
96
42
|
}), editor.addListener('update', ({
|
|
97
43
|
dirtyLeaves
|
|
98
44
|
}) => {
|
|
@@ -103,13 +49,13 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
|
|
|
103
49
|
return;
|
|
104
50
|
}
|
|
105
51
|
|
|
106
|
-
const textLength = strlen(text);
|
|
52
|
+
const textLength = strlen(text$1);
|
|
107
53
|
const textLengthAboveThreshold = textLength > maxCharacters || lastComputedTextLength !== null && lastComputedTextLength > maxCharacters;
|
|
108
54
|
const diff = maxCharacters - textLength;
|
|
109
55
|
remainingCharacters(diff);
|
|
110
56
|
|
|
111
57
|
if (lastComputedTextLength === null || textLengthAboveThreshold) {
|
|
112
|
-
const offset = findOffset(text, maxCharacters, strlen);
|
|
58
|
+
const offset = findOffset(text$1, maxCharacters, strlen);
|
|
113
59
|
editor.update(() => {
|
|
114
60
|
$wrapOverflowedNodes(offset);
|
|
115
61
|
}, {
|
|
@@ -164,12 +110,14 @@ function findOffset(text, maxCharacters, strlen) {
|
|
|
164
110
|
}
|
|
165
111
|
|
|
166
112
|
function $wrapOverflowedNodes(offset) {
|
|
167
|
-
const dfsNodes =
|
|
113
|
+
const dfsNodes = utils.$dfs();
|
|
168
114
|
const dfsNodesLength = dfsNodes.length;
|
|
169
115
|
let accumulatedLength = 0;
|
|
170
116
|
|
|
171
117
|
for (let i = 0; i < dfsNodesLength; i += 1) {
|
|
172
|
-
const
|
|
118
|
+
const {
|
|
119
|
+
node
|
|
120
|
+
} = dfsNodes[i];
|
|
173
121
|
|
|
174
122
|
if (OverflowNode.$isOverflowNode(node)) {
|
|
175
123
|
const previousLength = accumulatedLength;
|
|
@@ -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
|
-
var
|
|
8
|
-
function C(a){const
|
|
9
|
-
function E(a){const
|
|
7
|
+
var k=require("@lexical/react/withSubscriptions"),q=require("@lexical/text"),w=require("@lexical/utils"),x=require("lexical"),y=require("lexical/OverflowNode"),z=require("react");function B(a,d,f){var e=Intl.Segmenter;let m=0;var c=0;if("function"===typeof e){a=(new e).segment(a);for(var {segment:g}of a){c+=f(g);if(c>d)break;m+=g.length}}else for(g=Array.from(a),a=g.length,e=0;e<a;e++){const n=g[e];c+=f(n);if(c>d)break;m+=n.length}return m}
|
|
8
|
+
function C(a){const d=y.$createOverflowNode();a.insertBefore(d);d.append(a);return d}function D(a){const d=a.getChildren(),f=d.length;for(let e=0;e<f;e++)a.insertBefore(d[e]);a.remove();return 0<f?d[f-1]:null}
|
|
9
|
+
function E(a){const d=a.getPreviousSibling();if(y.$isOverflowNode(d)){var f=a.getFirstChild(),e=d.getChildren(),m=e.length;if(null===f)a.append(...e);else for(var c=0;c<m;c++)f.insertBefore(e[c]);c=x.$getSelection();if(x.$isRangeSelection(c)){f=c.anchor;e=f.getNode();c=c.focus;const g=f.getNode();e.is(d)?f.set(a.getKey(),f.offset,"element"):e.is(a)&&f.set(a.getKey(),m+f.offset,"element");g.is(d)?c.set(a.getKey(),c.offset,"element"):g.is(a)&&c.set(a.getKey(),m+c.offset,"element")}d.remove()}}
|
|
10
10
|
exports.mergePrevious=E;
|
|
11
|
-
exports.useCharacterLimit=function(a,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
m<r&&h.$isTextNode(b)&&b.isSimpleText()?([,b]=b.splitText(r-m),b=C(b)):b=C(b),null!==l&&h.$setSelection(l),E(b)))}},{tag:"history-merge"})}k=u}}))},[a,e,n,f])};
|
|
11
|
+
exports.useCharacterLimit=function(a,d,f=Object.freeze({})){const {strlen:e=c=>c.length,remainingCharacters:m=()=>{}}=f;z.useEffect(()=>{if(!a.hasNodes([y.OverflowNode]))throw Error("Minified Lexical error #58; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");},[a]);z.useEffect(()=>{let c=a.getEditorState().read(q.$rootTextContentCurry),g=0;return k(a.addListener("textcontent",n=>{c=n}),a.addListener("update",({dirtyLeaves:n})=>
|
|
12
|
+
{var r=a.isComposing();n=0<n.size;if(!r&&n){r=e(c);n=r>d||null!==g&&g>d;m(d-r);if(null===g||n){const p=B(c,d,e);a.update(()=>{const A=w.$dfs(),F=A.length;let t=0;for(let v=0;v<F;v+=1){var {node:b}=A[v];if(y.$isOverflowNode(b)){var l=t;if(t+b.getTextContentSize()<=p){var h=b.getParent();l=b.getPreviousSibling();var u=b.getNextSibling();D(b);b=x.$getSelection();!x.$isRangeSelection(b)||b.anchor.getNode().isAttached()&&b.focus.getNode().isAttached()||(x.$isTextNode(l)?l.select():x.$isTextNode(u)?u.select():
|
|
13
|
+
null!==h&&h.select())}else l<p&&(h=b.getFirstDescendant(),u=null!==h?h.getTextContentSize():0,l+=u,h=x.$isTextNode(h)&&h.isSimpleText(),l=l<=p,(h||l)&&D(b))}else x.$isLeafNode(b)&&(l=t,t+=b.getTextContentSize(),t>p&&!y.$isOverflowNode(b.getParent())&&(h=x.$getSelection(),l<p&&x.$isTextNode(b)&&b.isSimpleText()?([,b]=b.splitText(p-l),b=C(b)):b=C(b),null!==h&&x.$setSelection(h),E(b)))}},{tag:"history-merge"})}g=r}}))},[a,d,m,e])};
|
|
@@ -10,6 +10,7 @@ var withSubscriptions = require('@lexical/react/withSubscriptions');
|
|
|
10
10
|
var lexical = require('lexical');
|
|
11
11
|
var react = require('react');
|
|
12
12
|
var clipboard = require('@lexical/clipboard');
|
|
13
|
+
var selection = require('@lexical/selection');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -339,32 +340,6 @@ function useLexicalHistory(editor, externalHistoryState, delay = 1000) {
|
|
|
339
340
|
return useHistory(editor, externalHistoryState, delay);
|
|
340
341
|
}
|
|
341
342
|
|
|
342
|
-
/**
|
|
343
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
344
|
-
*
|
|
345
|
-
* This source code is licensed under the MIT license found in the
|
|
346
|
-
* LICENSE file in the root directory of this source tree.
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*/
|
|
350
|
-
|
|
351
|
-
function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity) {
|
|
352
|
-
selection.modify(isHoldingShift ? 'extend' : 'move', isBackward, granularity);
|
|
353
|
-
}
|
|
354
|
-
function $isParentElementRTL(selection) {
|
|
355
|
-
const anchorNode = selection.anchor.getNode();
|
|
356
|
-
const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
|
|
357
|
-
return parent.getDirection() === 'rtl';
|
|
358
|
-
}
|
|
359
|
-
function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
360
|
-
const isRTL = $isParentElementRTL(selection);
|
|
361
|
-
$moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
|
|
362
|
-
}
|
|
363
|
-
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
364
|
-
const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
|
|
365
|
-
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
366
|
-
}
|
|
367
|
-
|
|
368
343
|
/**
|
|
369
344
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
370
345
|
*
|
|
@@ -590,9 +565,9 @@ function useLexicalDragonSupport(editor) {
|
|
|
590
565
|
function usePlainTextSetup(editor, initialEditorState) {
|
|
591
566
|
useLayoutEffect(() => {
|
|
592
567
|
const removeListener = editor.addListener('command', (type, payload) => {
|
|
593
|
-
const selection = lexical.$getSelection();
|
|
568
|
+
const selection$1 = lexical.$getSelection();
|
|
594
569
|
|
|
595
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
570
|
+
if (!lexical.$isRangeSelection(selection$1)) {
|
|
596
571
|
return false;
|
|
597
572
|
}
|
|
598
573
|
|
|
@@ -600,21 +575,21 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
600
575
|
case 'deleteCharacter':
|
|
601
576
|
{
|
|
602
577
|
const isBackward = payload;
|
|
603
|
-
selection.deleteCharacter(isBackward);
|
|
578
|
+
selection$1.deleteCharacter(isBackward);
|
|
604
579
|
return true;
|
|
605
580
|
}
|
|
606
581
|
|
|
607
582
|
case 'deleteWord':
|
|
608
583
|
{
|
|
609
584
|
const isBackward = payload;
|
|
610
|
-
selection.deleteWord(isBackward);
|
|
585
|
+
selection$1.deleteWord(isBackward);
|
|
611
586
|
return true;
|
|
612
587
|
}
|
|
613
588
|
|
|
614
589
|
case 'deleteLine':
|
|
615
590
|
{
|
|
616
591
|
const isBackward = payload;
|
|
617
|
-
selection.deleteLine(isBackward);
|
|
592
|
+
selection$1.deleteLine(isBackward);
|
|
618
593
|
return true;
|
|
619
594
|
}
|
|
620
595
|
|
|
@@ -623,17 +598,17 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
623
598
|
const eventOrText = payload;
|
|
624
599
|
|
|
625
600
|
if (typeof eventOrText === 'string') {
|
|
626
|
-
selection.insertText(eventOrText);
|
|
601
|
+
selection$1.insertText(eventOrText);
|
|
627
602
|
} else {
|
|
628
603
|
const dataTransfer = eventOrText.dataTransfer;
|
|
629
604
|
|
|
630
605
|
if (dataTransfer != null) {
|
|
631
|
-
clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
|
|
606
|
+
clipboard.$insertDataTransferForPlainText(dataTransfer, selection$1);
|
|
632
607
|
} else {
|
|
633
608
|
const data = eventOrText.data;
|
|
634
609
|
|
|
635
610
|
if (data) {
|
|
636
|
-
selection.insertText(data);
|
|
611
|
+
selection$1.insertText(data);
|
|
637
612
|
}
|
|
638
613
|
}
|
|
639
614
|
}
|
|
@@ -642,16 +617,16 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
642
617
|
}
|
|
643
618
|
|
|
644
619
|
case 'removeText':
|
|
645
|
-
selection.removeText();
|
|
620
|
+
selection$1.removeText();
|
|
646
621
|
return true;
|
|
647
622
|
|
|
648
623
|
case 'insertLineBreak':
|
|
649
624
|
const selectStart = payload;
|
|
650
|
-
selection.insertLineBreak(selectStart);
|
|
625
|
+
selection$1.insertLineBreak(selectStart);
|
|
651
626
|
return true;
|
|
652
627
|
|
|
653
628
|
case 'insertParagraph':
|
|
654
|
-
selection.insertLineBreak();
|
|
629
|
+
selection$1.insertLineBreak();
|
|
655
630
|
return true;
|
|
656
631
|
|
|
657
632
|
case 'indentContent':
|
|
@@ -670,9 +645,9 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
670
645
|
const event = payload;
|
|
671
646
|
const isHoldingShift = event.shiftKey;
|
|
672
647
|
|
|
673
|
-
if (
|
|
648
|
+
if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
|
|
674
649
|
event.preventDefault();
|
|
675
|
-
|
|
650
|
+
selection.$moveCharacter(selection$1, isHoldingShift, true);
|
|
676
651
|
return true;
|
|
677
652
|
}
|
|
678
653
|
|
|
@@ -684,9 +659,9 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
684
659
|
const event = payload;
|
|
685
660
|
const isHoldingShift = event.shiftKey;
|
|
686
661
|
|
|
687
|
-
if (
|
|
662
|
+
if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
|
|
688
663
|
event.preventDefault();
|
|
689
|
-
|
|
664
|
+
selection.$moveCharacter(selection$1, isHoldingShift, false);
|
|
690
665
|
return true;
|
|
691
666
|
}
|
|
692
667
|
|
|
@@ -4,18 +4,17 @@
|
|
|
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
|
|
7
|
+
var l=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react"),w=require("@lexical/clipboard"),x=require("@lexical/selection");
|
|
8
|
+
function y(a,d,f,b,c){if(null===a||0===f.size&&0===b.size)return 0;var e=d._selection,g=a._selection;if(c)return 1;if(!(u.$isRangeSelection(e)&&u.$isRangeSelection(g)&&g.isCollapsed()&&e.isCollapsed()))return 0;var h=Array.from(f);b=Array.from(b);f=d._nodeMap;c=[];for(var k=0;k<h.length;k++){const n=f.get(h[k]);void 0!==n&&c.push(n)}for(h=0;h<b.length;h++)b[h][1]&&(k=f.get(b[h][0]),void 0===k||u.$isRootNode(k)||c.push(k));if(0===c.length)return 0;if(1<c.length)return b=d._nodeMap,d=b.get(e.anchor.key),
|
|
9
9
|
g=b.get(g.anchor.key),d&&g&&!a._nodeMap.has(d.__key)&&u.$isTextNode(d)&&1===d.__text.length&&1===e.anchor.offset?2:0;d=c[0];a=a._nodeMap.get(d.__key);if(!u.$isTextNode(a)||!u.$isTextNode(d)||a.__mode!==d.__mode)return 0;a=a.__text;d=d.__text;if(a===d)return 0;e=e.anchor;g=g.anchor;if(e.key!==g.key||"text"!==e.type)return 0;e=e.offset;g=g.offset;a=d.length-a.length;return 1===a&&g===e-1?2:-1===a&&g===e+1?3:-1===a&&g===e?4:0}
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
{tag:"historic"})}return!0;case "redo":return g=b.redoStack,h=b.undoStack,0!==g.length&&(
|
|
13
|
-
p=null===m?null:m.editorState;if(null===m||g!==p){
|
|
14
|
-
function
|
|
15
|
-
function
|
|
16
|
-
function J(a
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(c,a),!0;case "cut":return G(c,a),!0;case "paste":return F(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);J(a,d);return f},[a]);K(a)}module.exports=function(a,d,f){L(a,f);A(a,d)};
|
|
10
|
+
function z(a,d){let f=Date.now(),b=0;return(c,e,g,h,k,n)=>{const t=Date.now();if(n.has("historic"))return b=0,f=t,2;const m=y(c,e,h,k,a.isComposing()),r=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===c)return 1;var p=e._selection;const C=c._selection;if(!(0<h.size||0<k.size))return null===C&&null!==p?0:2;p=null===g||g.editor===a;return!1===q&&0!==m&&m===b&&t<f+d&&p?0:1})();f=t;b=m;return r}}
|
|
11
|
+
function A(a,d,f=1E3){const b=v.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),c=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const e=z(a,f);return l(a.addListener("command",g=>{switch(g){case "undo":g=b.redoStack;var h=b.undoStack;if(0!==h.length){var k=b.current;const n=h.pop();null!==k&&(g.push(k),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);b.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
|
|
12
|
+
{tag:"historic"})}return!0;case "redo":return g=b.redoStack,h=b.undoStack,0!==g.length&&(k=b.current,null!==k&&(h.push(k),a.execCommand("canUndo",!0)),h=g.pop(),0===g.length&&a.execCommand("canRedo",!1),b.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return c(),!1;case "clearHistory":return c(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:h,dirtyLeaves:k,dirtyElements:n,tags:t})=>{const m=b.current,r=b.redoStack,q=b.undoStack,
|
|
13
|
+
p=null===m?null:m.editorState;if(null===m||g!==p){k=e(h,g,m,k,n,t);if(1===k)0!==r.length&&(b.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;b.current={editor:a,editorState:g}}}))},[c,f,a,b])}function B(a,d,f=1E3){return A(a,d,f)}var D="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;
|
|
14
|
+
function E(a,d){a.preventDefault();d.update(()=>{const f=u.$getSelection(),b=a.clipboardData;null!=b&&u.$isRangeSelection(f)&&w.$insertDataTransferForPlainText(b,f)})}function F(a,d){G(a,d);d.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}function G(a,d){a.preventDefault();d.update(()=>{const f=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=f){const c=w.getHtmlContent(d);null!==c&&f.setData("text/html",c);f.setData("text/plain",b.getTextContent())}})}
|
|
15
|
+
const H={tag:"history-merge"};function I(a,d){if(null!==d)if(void 0===d)a.update(()=>{var f=u.$getRoot();if(null===f.getFirstChild()){const b=u.$createParagraphNode();f.append(b);f=document.activeElement;(null!==u.$getSelection()||null!==f&&f===a.getRootElement())&&b.select()}},H);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,H);break;case "object":a.setEditorState(d,H);break;case "function":a.update(d,H)}}
|
|
16
|
+
function J(a){v.useEffect(()=>{const d=f=>{var b=a.getRootElement();if(document.activeElement===b&&(b=f.data,"string"===typeof b)){try{var c=JSON.parse(b)}catch(e){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [e,g,h,k,n]=c;a.update(()=>{const t=u.$getSelection();if(u.$isRangeSelection(t)){var m=t.anchor;let r=m.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=e&&0<=g&&(q=e,p=e+g,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
|
|
17
|
+
h)t.insertRawText(h),r=m.getNode();u.$isTextNode(r)&&(q=k,p=k+n,m=r.getTextContentSize(),q=q>m?m:q,p=p>m?m:p,t.setTextNodeRange(r,q,r,p));f.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
|
|
18
|
+
function K(a,d){D(()=>{const f=a.addListener("command",(b,c)=>{const e=u.$getSelection();if(!u.$isRangeSelection(e))return!1;switch(b){case "deleteCharacter":return e.deleteCharacter(c),!0;case "deleteWord":return e.deleteWord(c),!0;case "deleteLine":return e.deleteLine(c),!0;case "insertText":return"string"===typeof c?e.insertText(c):(b=c.dataTransfer,null!=b?w.$insertDataTransferForPlainText(b,e):(c=c.data)&&e.insertText(c)),!0;case "removeText":return e.removeText(),!0;case "insertLineBreak":return e.insertLineBreak(c),
|
|
19
|
+
!0;case "insertParagraph":return e.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b=c.shiftKey;if(x.$shouldOverrideDefaultCharacterSelection(e,!0))return c.preventDefault(),x.$moveCharacter(e,b,!0),!0;break;case "keyArrowRight":b=c.shiftKey;if(x.$shouldOverrideDefaultCharacterSelection(e,!1))return c.preventDefault(),x.$moveCharacter(e,b,!1),!0;break;
|
|
20
|
+
case "keyBackspace":return c.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "copy":return G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return E(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);I(a,d);return f},[a]);J(a)}module.exports=function(a,d,f){K(a,f);B(a,d)};
|