@lexical/react 0.1.11 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPRECATED_useLexical.dev.js +3 -7
- package/DEPRECATED_useLexical.prod.js +1 -1
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +14 -9
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +18 -18
- package/DEPRECATED_useLexicalPlainText.dev.js +33 -27
- package/DEPRECATED_useLexicalPlainText.prod.js +12 -12
- package/DEPRECATED_useLexicalRichText.dev.js +43 -388
- package/DEPRECATED_useLexicalRichText.prod.js +17 -25
- package/LexicalAutoFormatterPlugin.d.ts +9 -0
- package/LexicalAutoFormatterPlugin.dev.js +14 -9
- package/LexicalAutoFormatterPlugin.prod.js +18 -18
- package/LexicalAutoLinkPlugin.d.ts +20 -0
- package/LexicalCharacterLimitPlugin.d.ts +11 -0
- package/LexicalClearEditorPlugin.d.ts +14 -0
- package/LexicalClearEditorPlugin.dev.js +22 -1
- package/LexicalClearEditorPlugin.prod.js +2 -1
- package/LexicalCollaborationPlugin.d.ts +51 -0
- package/LexicalCollaborationPlugin.dev.js +39 -12
- package/LexicalCollaborationPlugin.js.flow +4 -2
- package/LexicalCollaborationPlugin.prod.js +8 -7
- package/LexicalComposer.d.ts +22 -0
- package/LexicalComposer.dev.js +28 -6
- package/LexicalComposer.js.flow +5 -4
- package/LexicalComposer.prod.js +3 -3
- package/LexicalComposerContext.d.ts +24 -0
- package/LexicalComposerContext.js.flow +1 -1
- package/LexicalContentEditable.d.ts +32 -0
- package/LexicalContentEditable.dev.js +22 -1
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalHashtagPlugin.d.ts +9 -0
- package/LexicalHashtagPlugin.dev.js +56 -1
- package/LexicalHashtagPlugin.js.flow +0 -10
- package/LexicalHashtagPlugin.prod.js +7 -4
- package/LexicalHistoryPlugin.d.ts +29 -0
- package/LexicalHorizontalRuleNode.d.ts +23 -0
- package/LexicalLinkPlugin.d.ts +9 -0
- package/LexicalListPlugin.d.ts +9 -0
- package/LexicalNestedComposer.d.ts +17 -0
- package/LexicalNestedComposer.dev.js +21 -11
- package/LexicalNestedComposer.js.flow +3 -6
- package/LexicalNestedComposer.prod.js +3 -2
- package/LexicalOnChangePlugin.d.ts +12 -0
- package/LexicalPlainTextPlugin.d.ts +15 -0
- package/LexicalPlainTextPlugin.dev.js +11 -26
- package/LexicalPlainTextPlugin.prod.js +8 -8
- package/LexicalRichTextPlugin.d.ts +15 -0
- package/LexicalRichTextPlugin.dev.js +24 -390
- package/LexicalRichTextPlugin.prod.js +13 -21
- package/LexicalTablePlugin.d.ts +9 -0
- package/LexicalTreeView.d.ts +17 -0
- package/package.json +9 -5
- package/useLexicalDecoratorMap.d.ts +14 -0
- package/useLexicalIsTextContentEmpty.d.ts +13 -0
- package/useLexicalNodeSelection.d.ts +12 -0
- package/withSubscriptions.d.ts +12 -0
|
@@ -35,13 +35,9 @@ function useLexicalEditor(editor) {
|
|
|
35
35
|
*
|
|
36
36
|
*/
|
|
37
37
|
function useLexical(editorConfig) {
|
|
38
|
-
const editor = react.useMemo(() =>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return lexical.createEditor(editorConfig);
|
|
44
|
-
}, [editorConfig]);
|
|
38
|
+
const editor = react.useMemo(() => lexical.createEditor(editorConfig), // Init
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
[]);
|
|
45
41
|
const [rootElementRef, showPlaceholder] = useLexicalEditor(editor);
|
|
46
42
|
return [editor, rootElementRef, showPlaceholder];
|
|
47
43
|
}
|
|
@@ -4,4 +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 d=require("lexical"),e=require("react"),f=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder");function g(a){const b=f(a);return[e.useCallback(c=>{a.setRootElement(c)},[a]),b]}module.exports=function(a){const b=e.useMemo(()=>d.createEditor(a),[
|
|
7
|
+
var d=require("lexical"),e=require("react"),f=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder");function g(a){const b=f(a);return[e.useCallback(c=>{a.setRootElement(c)},[a]),b]}module.exports=function(a){const b=e.useMemo(()=>d.createEditor(a),[]),[c,h]=g(b);return[b,c,h]};
|
|
@@ -132,31 +132,31 @@ const paragraphStartBase = { ...autoFormatBase,
|
|
|
132
132
|
};
|
|
133
133
|
const markdownHeader1 = { ...paragraphStartBase,
|
|
134
134
|
nodeTransformationKind: 'paragraphH1',
|
|
135
|
-
regEx:
|
|
135
|
+
regEx: /^(?:# )/
|
|
136
136
|
};
|
|
137
137
|
const markdownHeader2 = { ...paragraphStartBase,
|
|
138
138
|
nodeTransformationKind: 'paragraphH2',
|
|
139
|
-
regEx:
|
|
139
|
+
regEx: /^(?:## )/
|
|
140
140
|
};
|
|
141
141
|
const markdownHeader3 = { ...paragraphStartBase,
|
|
142
142
|
nodeTransformationKind: 'paragraphH2',
|
|
143
|
-
regEx:
|
|
143
|
+
regEx: /^(?:### )/
|
|
144
144
|
};
|
|
145
145
|
const markdownBlockQuote = { ...paragraphStartBase,
|
|
146
146
|
nodeTransformationKind: 'paragraphBlockQuote',
|
|
147
|
-
regEx:
|
|
147
|
+
regEx: /^(?:> )/
|
|
148
148
|
};
|
|
149
149
|
const markdownUnorderedListDash = { ...paragraphStartBase,
|
|
150
150
|
nodeTransformationKind: 'paragraphUnorderedList',
|
|
151
|
-
regEx:
|
|
151
|
+
regEx: /^(?:- )/
|
|
152
152
|
};
|
|
153
153
|
const markdownUnorderedListAsterisk = { ...paragraphStartBase,
|
|
154
154
|
nodeTransformationKind: 'paragraphUnorderedList',
|
|
155
|
-
regEx:
|
|
155
|
+
regEx: /^(?:\* )/
|
|
156
156
|
};
|
|
157
157
|
const markdownCodeBlock = { ...paragraphStartBase,
|
|
158
158
|
nodeTransformationKind: 'paragraphCodeBlock',
|
|
159
|
-
regEx:
|
|
159
|
+
regEx: /^(```)([a-z]*)( )/
|
|
160
160
|
};
|
|
161
161
|
const markdownOrderedList = { ...paragraphStartBase,
|
|
162
162
|
nodeTransformationKind: 'paragraphOrderedList',
|
|
@@ -164,11 +164,11 @@ const markdownOrderedList = { ...paragraphStartBase,
|
|
|
164
164
|
};
|
|
165
165
|
const markdownHorizontalRule = { ...paragraphStartBase,
|
|
166
166
|
nodeTransformationKind: 'horizontalRule',
|
|
167
|
-
regEx:
|
|
167
|
+
regEx: /^(?:\*\*\* )/
|
|
168
168
|
};
|
|
169
169
|
const markdownHorizontalRuleUsingDashes = { ...paragraphStartBase,
|
|
170
170
|
nodeTransformationKind: 'horizontalRule',
|
|
171
|
-
regEx:
|
|
171
|
+
regEx: /^(?:--- )/
|
|
172
172
|
};
|
|
173
173
|
const markdownItalic = { ...autoFormatBase,
|
|
174
174
|
nodeTransformationKind: 'italic',
|
|
@@ -358,6 +358,11 @@ function getNewNodeForCriteria(scanningContext, element) {
|
|
|
358
358
|
newNode = lexical.$createParagraphNode();
|
|
359
359
|
} else {
|
|
360
360
|
newNode = CodeNode.$createCodeNode();
|
|
361
|
+
const codingLanguage = matchResultContext.regExCaptureGroups.length >= 3 ? matchResultContext.regExCaptureGroups[2].text : null;
|
|
362
|
+
|
|
363
|
+
if (codingLanguage != null && codingLanguage.length > 0) {
|
|
364
|
+
newNode.setLanguage(codingLanguage);
|
|
365
|
+
}
|
|
361
366
|
}
|
|
362
367
|
|
|
363
368
|
newNode.append(...children);
|
|
@@ -5,23 +5,23 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
var k=require("@lexical/list"),q=require("lexical"),r=require("lexical/CodeNode"),t=require("react"),u=require("@lexical/react/LexicalHorizontalRuleNode"),x=require("lexical/HeadingNode"),y=require("lexical/QuoteNode");function C(g){throw Error(`Minified Lexical error #${g}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
|
8
|
-
function D(g,f,a,
|
|
8
|
+
function D(g,f,a,c){g=g.getChildren();const b=g.length;let d=0,e=!1;for(let p=0;p<b&&!(d>f);++p){const m=g[p],n=q.$isTextNode(m);var h=n?m.getTextContent().length:c;h=d+h;if((!1===e&&d===a||0===d&&d===a||d<a&&a<=h)&&q.$isTextNode(m))return{node:m,offset:a-d};d=h;e=n}return null}
|
|
9
9
|
const E={nodeTransformationKind:null,regEx:/(?:)/,requiresParagraphStart:!1},F={...E,requiresParagraphStart:!0},H=[{...E,nodeTransformationKind:"bold_italic",regEx:/(\*\*\*)(\s*\b)([^\*\*\*]*)(\b\s*)(\*\*\*\s)$/},{...E,nodeTransformationKind:"italic",regEx:/(\*)(\s*\b)([^\*]*)(\b\s*)(\*\s)$/},{...E,nodeTransformationKind:"bold",regEx:/(\*\*)(\s*\b)([^\*\*]*)(\b\s*)(\*\*\s)$/},{...E,nodeTransformationKind:"bold",regEx:/(__)(\s*)([^__]*)(\s*)(__\s)$/},{...E,nodeTransformationKind:"underline",regEx:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>\s)$/},
|
|
10
|
-
{...E,nodeTransformationKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/}],I=[{...F,nodeTransformationKind:"paragraphH1",regEx
|
|
11
|
-
regEx:/^(\d+)\.\s/},{...F,nodeTransformationKind:"paragraphCodeBlock",regEx
|
|
12
|
-
function J(g,f,a,
|
|
13
|
-
function K(g,f,a,b
|
|
14
|
-
function L(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,
|
|
15
|
-
x.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=x.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=y.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=k.$createListNode("ul");
|
|
16
|
-
a.append(
|
|
17
|
-
["bold","italic"];break a}a=null}if(null!=a){d=[1,5];
|
|
18
|
-
h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=
|
|
19
|
-
e=d[3];
|
|
20
|
-
|
|
21
|
-
function M(g,f){let a=null;g.read(()=>{var
|
|
22
|
-
l=
|
|
23
|
-
h.getChildren();const N=h.length;for(let B=0;B<N;++B){const v=h[B];if(q.$isTextNode(v)){const G=v.getTextContent();if(v.is(m.node)){m.offset>G.length&&C(50,v.__key);w+=v.getTextContent().substr(0,m.offset);break}else w+=G}else w+="\u0004"}p.joinedText=w}}else C(52,h.__key)}d=J(e.joinedText,!1,!0,d.regEx)}if(null!=d){
|
|
24
|
-
|
|
25
|
-
function O(g){let f=null;g.read(()=>{const a=q.$getSelection();if(q.$isRangeSelection(a)&&a.isCollapsed()){var
|
|
26
|
-
function P(g){t.useEffect(()=>{let f=null;return g.addListener("update",({tags:a})=>{if(!1===a.has("historic")){var
|
|
10
|
+
{...E,nodeTransformationKind:"strikethrough",regEx:/(~~)(\s*\b)([^~~]*)(\b\s*)(~~\s)$/}],I=[{...F,nodeTransformationKind:"paragraphH1",regEx:/^(?:# )/},{...F,nodeTransformationKind:"paragraphH2",regEx:/^(?:## )/},{...F,nodeTransformationKind:"paragraphH2",regEx:/^(?:### )/},{...F,nodeTransformationKind:"paragraphBlockQuote",regEx:/^(?:> )/},{...F,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:- )/},{...F,nodeTransformationKind:"paragraphUnorderedList",regEx:/^(?:\* )/},{...F,nodeTransformationKind:"paragraphOrderedList",
|
|
11
|
+
regEx:/^(\d+)\.\s/},{...F,nodeTransformationKind:"paragraphCodeBlock",regEx:/^(```)([a-z]*)( )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/^(?:\*\*\* )/},{...F,nodeTransformationKind:"horizontalRule",regEx:/^(?:--- )/},...H];
|
|
12
|
+
function J(g,f,a,c){const b={offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]};c=g.match(c);if(null!==c&&0<c.length&&(!1===f||0===c.index)&&(!1===a||c.index+c[0].length===g.length)){b.offsetInJoinedTextForCollapsedSelection=g.length;g=c.length;f=c.index;for(a=0;a<g;a++){const d=c[a];b.regExCaptureGroups.push({anchorTextNodeWithOffset:null,focusTextNodeWithOffset:null,offsetInParent:f,text:d,textLength:d.length-(a+1===g?1:0)});0<a&&(f+=d.length)}return b}return null}
|
|
13
|
+
function K(g,f,a,c,b){b.offsetInJoinedTextForCollapsedSelection+=g;0<b.offsetInJoinedTextForCollapsedSelection||C(67);b=b.regExCaptureGroups;const d=b.length;for(c+=1;c<d;c++){const e=b[c];null!=e.anchorTextNodeWithOffset&&e.anchorTextNodeWithOffset.offset>=f&&e.anchorTextNodeWithOffset.node.is(a)&&(e.anchorTextNodeWithOffset.offset+=g);null!=e.focusTextNodeWithOffset&&e.focusTextNodeWithOffset.offset>=f&&e.focusTextNodeWithOffset.node.is(a)&&(e.focusTextNodeWithOffset.offset+=g)}}
|
|
14
|
+
function L(g,f){g.update(()=>{if(f.autoFormatCriteria.requiresParagraphStart){var a=f.textNodeWithOffset,c=a.node.getParentOrThrow();a=a.node.spliceText(0,f.matchResultContext.regExCaptureGroups[0].text.length,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove());var b=c;a=null;var d=b.getChildren(),e=f.autoFormatCriteria,h=f.matchResultContext;if(null!=e.nodeTransformationKind)switch(e.nodeTransformationKind){case "paragraphH1":a=x.$createHeadingNode("h1");a.append(...d);break;case "paragraphH2":a=
|
|
15
|
+
x.$createHeadingNode("h2");a.append(...d);break;case "paragraphH3":a=x.$createHeadingNode("h3");a.append(...d);break;case "paragraphBlockQuote":a=y.$createQuoteNode();a.append(...d);break;case "paragraphUnorderedList":a=k.$createListNode("ul");b=k.$createListItemNode();b.append(...d);a.append(b);break;case "paragraphOrderedList":a=parseInt(1<h.regExCaptureGroups.length?h.regExCaptureGroups[h.regExCaptureGroups.length-1].text:"1",10);a=k.$createListNode("ol",a);b=k.$createListItemNode();b.append(...d);
|
|
16
|
+
a.append(b);break;case "paragraphCodeBlock":null!=f.triggerState&&f.triggerState.isCodeBlock?a=q.$createParagraphNode():(a=r.$createCodeNode(),b=3<=h.regExCaptureGroups.length?h.regExCaptureGroups[2].text:null,null!=b&&0<b.length&&a.setLanguage(b));a.append(...d);break;case "horizontalRule":d=u.$createHorizontalRuleNode(),b.insertBefore(d)}null!==a&&c.replace(a)}else if(a=f.autoFormatCriteria,c=f.matchResultContext,null!=a.nodeTransformationKind&&6===c.regExCaptureGroups.length){a:{a=a.nodeTransformationKind;
|
|
17
|
+
switch(a){case "italic":case "bold":case "underline":case "strikethrough":a=[a];break a;case "bold_italic":a=["bold","italic"];break a}a=null}if(null!=a){d=[1,5];b=f.autoFormatCriteria;e=f.matchResultContext.regExCaptureGroups;h=e.length;var p=f.textNodeWithOffset.node.getParentOrThrow();null==f.joinedText&&C(62);var m=f.joinedText.length;for(var n=1;n<h;n++){var l=e[n];l.anchorTextNodeWithOffset=D(p,m,l.offsetInParent,1);l.focusTextNodeWithOffset=D(p,m,l.offsetInParent+l.textLength,1);0>l.textLength&&
|
|
18
|
+
C(63,b.nodeTransformationKind)}c.regExCaptureGroups=e;if(0<d.length)for(b=c.regExCaptureGroups,e=b.length,h=d.length-1;0<=h;h--)h<e&&(p=d[h],l=b[p],n=l.anchorTextNodeWithOffset,m=l.focusTextNodeWithOffset,null!=n&&null!=m&&0<l.textLength&&(l=q.$createRangeSelection(),l.anchor.set(n.node.getKey(),n.offset,"text"),l.focus.set(m.node.getKey(),m.offset,"text"),q.$setSelection(l),l=q.$getSelection(),q.$isRangeSelection(l)&&(l.removeText(),n.node.getKey()===m.node.getKey()?(l=m.offset-n.offset,0<l||C(64),
|
|
19
|
+
K(-l,m.offset,n.node,p,c)):(n=m.offset,0<n&&K(-n,n,m.node,p,c)))));d=c.regExCaptureGroups;3<d.length||C(65);e=d[3];b=e.anchorTextNodeWithOffset;d=e.focusTextNodeWithOffset;if(null!=b&&null!=d&&0<e.textLength&&(e=q.$createRangeSelection(),e.anchor.set(b.node.getKey(),b.offset,"text"),e.focus.set(d.node.getKey(),d.offset,"text"),q.$setSelection(e),b=q.$getSelection(),q.$isRangeSelection(b))){for(e=0;e<a.length;e++)b.formatText(a[e]);a=q.$createRangeSelection();a.anchor.set(d.node.getKey(),d.offset+
|
|
20
|
+
1,"text");a.focus.set(d.node.getKey(),d.offset+1,"text");q.$setSelection(a)}a=f.textNodeWithOffset.node.getParentOrThrow();c=D(a,c.offsetInJoinedTextForCollapsedSelection+1,c.offsetInJoinedTextForCollapsedSelection,1);null!=c&&(a=q.$createRangeSelection(),a.anchor.set(c.node.getKey(),c.offset,"text"),a.focus.set(c.node.getKey(),c.offset,"text"),q.$setSelection(a))}}},{tag:"history-push"})}
|
|
21
|
+
function M(g,f){let a=null;g.read(()=>{var c=q.$getSelection();if(q.$isRangeSelection(c)){var b=c.anchor.getNode();c=q.$isTextNode(b)?{node:b,offset:c.anchor.offset}:null}else c=null;if(null!==c){c={autoFormatCriteria:{nodeTransformationKind:"noTransformation",regEx:/(?:)/,requiresParagraphStart:null},joinedText:null,matchResultContext:{offsetInJoinedTextForCollapsedSelection:0,regExCaptureGroups:[]},textNodeWithOffset:c,triggerState:f};a:{b=!1===f.isParentAListItemNode?I:H;const n=c.triggerState,
|
|
22
|
+
l=b.length;for(let z=0;z<l;z++){const A=b[z];if(null!=n&&!1===n.isCodeBlock||"paragraphCodeBlock"===A.nodeTransformationKind){var d=A,e=c;if(null!==d.requiresParagraphStart&&!0===d.requiresParagraphStart)null===e.textNodeWithOffset.node.getPreviousSibling()?(e=e.textNodeWithOffset.node.getTextContent(),d=J(e,!0,!1,d.regEx)):d=null;else{if(null==e.joinedText){var h=e.textNodeWithOffset.node.getParentOrThrow();if(q.$isElementNode(h)){if(null==e.joinedText){var p=e,m=e.textNodeWithOffset;let w="";h=
|
|
23
|
+
h.getChildren();const N=h.length;for(let B=0;B<N;++B){const v=h[B];if(q.$isTextNode(v)){const G=v.getTextContent();if(v.is(m.node)){m.offset>G.length&&C(50,v.__key);w+=v.getTextContent().substr(0,m.offset);break}else w+=G}else w+="\u0004"}p.joinedText=w}}else C(52,h.__key)}d=J(e.joinedText,!1,!0,d.regEx)}if(null!=d){b={autoFormatCriteria:A,matchResultContext:d};break a}}}b={autoFormatCriteria:null,matchResultContext:null}}null!==b.autoFormatCriteria&&null!==b.matchResultContext&&(a=c,a.autoFormatCriteria=
|
|
24
|
+
b.autoFormatCriteria,a.matchResultContext=b.matchResultContext)}});return a}
|
|
25
|
+
function O(g){let f=null;g.read(()=>{const a=q.$getSelection();if(q.$isRangeSelection(a)&&a.isCollapsed()){var c=a.anchor.getNode(),b=c.getParent(),d=null!==b&&k.$isListItemNode(b);f={anchorOffset:a.anchor.offset,hasParentNode:null!==b,isCodeBlock:r.$isCodeNode(c),isParentAListItemNode:d,isSelectionCollapsed:a.isCollapsed(),isSimpleText:q.$isTextNode(c)&&c.isSimpleText(),nodeKey:c.getKey(),textContent:c.getTextContent()}}});return f}
|
|
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
27
|
null})},[g])}module.exports=function(g){P(g)};
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
var withSubscriptions = require('@lexical/react/withSubscriptions');
|
|
10
10
|
var lexical = require('lexical');
|
|
11
11
|
var react = require('react');
|
|
12
|
+
var clipboard = require('@lexical/clipboard');
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -359,6 +360,10 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
359
360
|
const isRTL = $isParentElementRTL(selection);
|
|
360
361
|
$moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
|
|
361
362
|
}
|
|
363
|
+
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
364
|
+
const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
|
|
365
|
+
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
366
|
+
}
|
|
362
367
|
|
|
363
368
|
/**
|
|
364
369
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -368,17 +373,27 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
368
373
|
*
|
|
369
374
|
*
|
|
370
375
|
*/
|
|
371
|
-
|
|
372
|
-
const text = dataTransfer.getData('text/plain');
|
|
376
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
373
377
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
378
|
+
/**
|
|
379
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
380
|
+
*
|
|
381
|
+
* This source code is licensed under the MIT license found in the
|
|
382
|
+
* LICENSE file in the root directory of this source tree.
|
|
383
|
+
*
|
|
384
|
+
*
|
|
385
|
+
*/
|
|
386
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
387
|
+
var useLayoutEffect = useLayoutEffectImpl;
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
391
|
+
*
|
|
392
|
+
* This source code is licensed under the MIT license found in the
|
|
393
|
+
* LICENSE file in the root directory of this source tree.
|
|
394
|
+
*
|
|
395
|
+
*
|
|
396
|
+
*/
|
|
382
397
|
function onPasteForPlainText(event, editor) {
|
|
383
398
|
event.preventDefault();
|
|
384
399
|
editor.update(() => {
|
|
@@ -386,7 +401,7 @@ function onPasteForPlainText(event, editor) {
|
|
|
386
401
|
const clipboardData = event.clipboardData;
|
|
387
402
|
|
|
388
403
|
if (clipboardData != null && lexical.$isRangeSelection(selection)) {
|
|
389
|
-
|
|
404
|
+
clipboard.$insertDataTransferForPlainText(clipboardData, selection);
|
|
390
405
|
}
|
|
391
406
|
});
|
|
392
407
|
}
|
|
@@ -408,19 +423,10 @@ function onCopyForPlainText(event, editor) {
|
|
|
408
423
|
|
|
409
424
|
if (selection !== null) {
|
|
410
425
|
if (clipboardData != null) {
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
if (domSelection.isCollapsed) {
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
426
|
+
const htmlString = clipboard.getHtmlContent(editor);
|
|
416
427
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
if (range) {
|
|
420
|
-
const container = document.createElement('div');
|
|
421
|
-
const frag = range.cloneContents();
|
|
422
|
-
container.appendChild(frag);
|
|
423
|
-
clipboardData.setData('text/html', container.innerHTML);
|
|
428
|
+
if (htmlString !== null) {
|
|
429
|
+
clipboardData.setData('text/html', htmlString);
|
|
424
430
|
}
|
|
425
431
|
|
|
426
432
|
clipboardData.setData('text/plain', selection.getTextContent());
|
|
@@ -582,7 +588,7 @@ function useLexicalDragonSupport(editor) {
|
|
|
582
588
|
*
|
|
583
589
|
*/
|
|
584
590
|
function usePlainTextSetup(editor, initialEditorState) {
|
|
585
|
-
|
|
591
|
+
useLayoutEffect(() => {
|
|
586
592
|
const removeListener = editor.addListener('command', (type, payload) => {
|
|
587
593
|
const selection = lexical.$getSelection();
|
|
588
594
|
|
|
@@ -622,7 +628,7 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
622
628
|
const dataTransfer = eventOrText.dataTransfer;
|
|
623
629
|
|
|
624
630
|
if (dataTransfer != null) {
|
|
625
|
-
|
|
631
|
+
clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
|
|
626
632
|
} else {
|
|
627
633
|
const data = eventOrText.data;
|
|
628
634
|
|
|
@@ -756,8 +762,8 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
756
762
|
*
|
|
757
763
|
*
|
|
758
764
|
*/
|
|
759
|
-
function useLexicalPlainText(editor, externalHistoryState) {
|
|
760
|
-
usePlainTextSetup(editor);
|
|
765
|
+
function useLexicalPlainText(editor, externalHistoryState, initialEditorState) {
|
|
766
|
+
usePlainTextSetup(editor, initialEditorState);
|
|
761
767
|
useLexicalHistory(editor, externalHistoryState);
|
|
762
768
|
}
|
|
763
769
|
|
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var k=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react");
|
|
8
|
-
function
|
|
7
|
+
var k=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react"),w=require("@lexical/clipboard");
|
|
8
|
+
function x(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 l=0;l<h.length;l++){const n=f.get(h[l]);void 0!==n&&c.push(n)}for(h=0;h<b.length;h++)b[h][1]&&(l=f.get(b[h][0]),void 0===l||u.$isRootNode(l)||c.push(l));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
|
|
10
|
+
function y(a,d){let f=Date.now(),b=0;return(c,e,g,h,l,n)=>{const t=Date.now();if(n.has("historic"))return b=0,f=t,2;const m=x(c,e,h,l,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 D=c._selection;if(!(0<h.size||0<l.size))return null===D&&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 z(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=y(a,f);return k(a.addListener("command",g=>{switch(g){case "undo":g=b.redoStack;var h=b.undoStack;if(0!==h.length){var l=b.current;const n=h.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);b.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
|
|
12
12
|
{tag:"historic"})}return!0;case "redo":return g=b.redoStack,h=b.undoStack,0!==g.length&&(l=b.current,null!==l&&(h.push(l),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:l,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){l=e(h,g,m,l,n,t);if(1===l)0!==r.length&&(b.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;b.current={editor:a,editorState:g}}}))},[c,f,a,b])}function
|
|
14
|
-
function C(a,d){a=u.$getDecoratorNode(a.focus,d);return u.$isDecoratorNode(a)&&!a.isIsolated()}function
|
|
15
|
-
function G(a,d){a.preventDefault();d.update(()=>{const f=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=f){
|
|
16
|
-
function
|
|
17
|
-
function
|
|
13
|
+
p=null===m?null:m.editorState;if(null===m||g!==p){l=e(h,g,m,l,n,t);if(1===l)0!==r.length&&(b.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;b.current={editor:a,editorState:g}}}))},[c,f,a,b])}function A(a,d,f=1E3){return z(a,d,f)}function B(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
|
|
14
|
+
function C(a,d){a=u.$getDecoratorNode(a.focus,d);return u.$isDecoratorNode(a)&&!a.isIsolated()}var E="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;function F(a,d){a.preventDefault();d.update(()=>{const f=u.$getSelection(),b=a.clipboardData;null!=b&&u.$isRangeSelection(f)&&w.$insertDataTransferForPlainText(b,f)})}
|
|
15
|
+
function G(a,d){H(a,d);d.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}function H(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())}})}const I={tag:"history-merge"};
|
|
16
|
+
function J(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()}},I);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,I);break;case "object":a.setEditorState(d,I);break;case "function":a.update(d,I)}}
|
|
17
|
+
function K(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,l,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||""!==
|
|
18
18
|
h)t.insertRawText(h),r=m.getNode();u.$isTextNode(r)&&(q=l,p=l+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])}
|
|
19
|
-
function
|
|
20
|
-
!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(C(e,!0))return c.preventDefault(),c=b,b=
|
|
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
|
|
19
|
+
function L(a,d){E(()=>{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),
|
|
20
|
+
!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(C(e,!0))return c.preventDefault(),c=b,b=B(e),e.modify(c?"extend":"move",!b,"character"),!0;break;case "keyArrowRight":b=c.shiftKey;if(C(e,!1))return c.preventDefault(),c=b,b=B(e),e.modify(c?"extend":"move",b,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
|
|
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)};
|