@lexical/react 0.1.14 → 0.1.17
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 +5 -741
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +1 -21
- package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +4 -73
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -2
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +19 -72
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +7 -8
- package/DEPRECATED_useLexicalDecorators.dev.js +1 -1
- package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
- package/DEPRECATED_useLexicalEditorEvents.dev.js +1 -1
- package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +5 -307
- package/DEPRECATED_useLexicalHistory.prod.js +1 -7
- package/DEPRECATED_useLexicalList.dev.js +29 -25
- package/DEPRECATED_useLexicalList.prod.js +3 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +8 -687
- package/DEPRECATED_useLexicalPlainText.prod.js +2 -15
- package/DEPRECATED_useLexicalRichText.dev.js +8 -772
- package/DEPRECATED_useLexicalRichText.prod.js +2 -17
- package/LICENSE +1 -1
- package/{withSubscriptions.prod.js → LexicalAutoFocusPlugin.d.ts} +3 -1
- package/{withSubscriptions.dev.js → LexicalAutoFocusPlugin.dev.js} +10 -5
- package/LexicalAutoFocusPlugin.js +9 -0
- package/{LexicalAutoFormatterPlugin.js.flow → LexicalAutoFocusPlugin.js.flow} +1 -1
- package/LexicalAutoFocusPlugin.prod.js +7 -0
- package/LexicalAutoLinkPlugin.dev.js +12 -15
- package/LexicalAutoLinkPlugin.prod.js +6 -6
- package/LexicalAutoScrollPlugin.d.ts +13 -0
- package/LexicalAutoScrollPlugin.dev.js +82 -0
- package/LexicalAutoScrollPlugin.js +9 -0
- package/{withSubscriptions.d.ts → LexicalAutoScrollPlugin.js.flow} +5 -5
- package/LexicalAutoScrollPlugin.prod.js +8 -0
- package/LexicalCharacterLimitPlugin.dev.js +19 -72
- package/LexicalCharacterLimitPlugin.prod.js +8 -9
- package/LexicalClearEditorPlugin.dev.js +15 -19
- package/LexicalClearEditorPlugin.prod.js +1 -1
- package/LexicalCollaborationPlugin.d.ts +8 -3
- package/LexicalCollaborationPlugin.dev.js +70 -47
- package/LexicalCollaborationPlugin.js.flow +9 -3
- package/LexicalCollaborationPlugin.prod.js +10 -8
- package/LexicalComposer.d.ts +2 -2
- package/LexicalComposer.dev.js +3 -19
- package/LexicalComposer.js.flow +2 -2
- package/LexicalComposer.prod.js +2 -3
- package/LexicalContentEditable.dev.js +3 -1
- package/LexicalContentEditable.prod.js +2 -2
- package/LexicalHashtagPlugin.dev.js +21 -92
- package/LexicalHashtagPlugin.prod.js +4 -7
- package/LexicalHistoryPlugin.dev.js +5 -307
- package/LexicalHistoryPlugin.prod.js +1 -7
- package/LexicalHorizontalRuleNode.d.ts +3 -1
- package/LexicalHorizontalRuleNode.dev.js +2 -0
- package/LexicalHorizontalRuleNode.js.flow +6 -2
- package/LexicalHorizontalRuleNode.prod.js +2 -2
- package/LexicalLinkPlugin.dev.js +19 -20
- package/LexicalLinkPlugin.prod.js +4 -3
- package/LexicalListPlugin.dev.js +29 -25
- package/LexicalListPlugin.prod.js +3 -2
- package/{LexicalAutoFormatterPlugin.d.ts → LexicalMarkdownShortcutPlugin.d.ts} +1 -1
- package/LexicalMarkdownShortcutPlugin.dev.js +42 -0
- package/LexicalMarkdownShortcutPlugin.js +9 -0
- package/{withSubscriptions.js.flow → LexicalMarkdownShortcutPlugin.js.flow} +1 -4
- package/LexicalMarkdownShortcutPlugin.prod.js +7 -0
- package/LexicalNestedComposer.dev.js +20 -15
- package/LexicalNestedComposer.prod.js +3 -3
- package/LexicalOnChangePlugin.dev.js +16 -3
- package/LexicalOnChangePlugin.prod.js +2 -1
- package/LexicalPlainTextPlugin.dev.js +9 -455
- package/LexicalPlainTextPlugin.prod.js +4 -12
- package/LexicalRichTextPlugin.dev.js +9 -540
- package/LexicalRichTextPlugin.prod.js +4 -13
- package/LexicalTablePlugin.dev.js +36 -35
- package/LexicalTablePlugin.prod.js +3 -3
- package/LexicalTreeView.dev.js +1 -1
- package/LexicalTreeView.prod.js +1 -1
- package/package.json +17 -11
- package/useLexicalIsTextContentEmpty.dev.js +4 -33
- package/useLexicalIsTextContentEmpty.prod.js +1 -2
- package/useLexicalNodeSelection.dev.js +1 -1
- package/useLexicalNodeSelection.prod.js +1 -1
- package/useLexicalTextEntity.d.ts +19 -0
- package/useLexicalTextEntity.dev.js +29 -0
- package/{withSubscriptions.js → useLexicalTextEntity.js} +2 -2
- package/useLexicalTextEntity.js.flow +18 -0
- package/useLexicalTextEntity.prod.js +7 -0
- package/LexicalAutoFormatterPlugin.dev.js +0 -778
- package/LexicalAutoFormatterPlugin.js +0 -9
- package/LexicalAutoFormatterPlugin.prod.js +0 -27
|
@@ -4,20 +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
|
|
8
|
-
function
|
|
9
|
-
g=d.get(g.anchor.key),e&&g&&!a._nodeMap.has(e.__key)&&u.$isTextNode(e)&&1===e.__text.length&&1===b.anchor.offset?2:0;e=c[0];a=a._nodeMap.get(e.__key);if(!u.$isTextNode(a)||!u.$isTextNode(e)||a.__mode!==e.__mode)return 0;a=a.__text;e=e.__text;if(a===e)return 0;b=b.anchor;g=g.anchor;if(b.key!==g.key||"text"!==b.type)return 0;b=b.offset;g=g.offset;a=e.length-a.length;return 1===a&&g===b-1?2:-1===a&&g===b+1?3:-1===a&&g===b?4:0}
|
|
10
|
-
function y(a,e){let f=Date.now(),d=0;return(c,b,g,k,l,n)=>{const t=Date.now();if(n.has("historic"))return d=0,f=t,2;const m=x(c,b,k,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=b._selection;const D=c._selection;if(!(0<k.size||0<l.size))return null===D&&null!==p?0:2;p=null===g||g.editor===a;return!1===q&&0!==m&&m===d&&t<f+e&&p?0:1})();f=t;d=m;return r}}
|
|
11
|
-
function z(a,e,f=1E3){const d=v.useMemo(()=>e||{current:null,redoStack:[],undoStack:[]},[e]),c=v.useCallback(()=>{d.undoStack=[];d.redoStack=[];d.current=null},[d]);v.useEffect(()=>{const b=y(a,f);return h(a.addListener("command",g=>{switch(g){case "undo":g=d.redoStack;var k=d.undoStack;if(0!==k.length){var l=d.current;const n=k.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===k.length&&a.execCommand("canUndo",!1);d.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
|
|
12
|
-
{tag:"historic"})}return!0;case "redo":return g=d.redoStack,k=d.undoStack,0!==g.length&&(l=d.current,null!==l&&(k.push(l),a.execCommand("canUndo",!0)),k=g.pop(),0===g.length&&a.execCommand("canRedo",!1),d.current=k,k.editor.setEditorState(k.editorState,{tag:"historic"})),!0;case "clearEditor":return c(),!1;case "clearHistory":return c(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:k,dirtyLeaves:l,dirtyElements:n,tags:t})=>{const m=d.current,r=d.redoStack,q=d.undoStack,
|
|
13
|
-
p=null===m?null:m.editorState;if(null===m||g!==p){l=b(k,g,m,l,n,t);if(1===l)0!==r.length&&(d.redoStack=[]),null!==m&&(q.push({...m,undoSelection:k.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;d.current={editor:a,editorState:g}}}))},[c,f,a,d])}function A(a,e,f=1E3){return z(a,e,f)}function B(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
|
|
14
|
-
function C(a,e){a=u.$getDecoratorNode(a.focus,e);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,e){G(a,e);e.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}
|
|
15
|
-
function G(a,e){a.preventDefault();e.update(()=>{const f=a.clipboardData,d=u.$getSelection();if(null!==d&&null!=f){const c=w.getHtmlContent(e),b=w.$getLexicalContent(e);null!==c&&f.setData("text/html",c);null!==b&&f.setData("application/x-lexical-editor",b);f.setData("text/plain",d.getTextContent())}})}function H(a,e){a.preventDefault();e.update(()=>{const f=u.$getSelection(),d=a.clipboardData;null!=d&&u.$isRangeSelection(f)&&w.$insertDataTransferForRichText(d,f,e)})}const I={tag:"history-merge"};
|
|
16
|
-
function J(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=u.$getRoot();if(null===f.getFirstChild()){const d=u.$createParagraphNode();f.append(d);f=document.activeElement;(null!==u.$getSelection()||null!==f&&f===a.getRootElement())&&d.select()}},I);else if(null!==e)switch(typeof e){case "string":e=a.parseEditorState(e);a.setEditorState(e,I);break;case "object":a.setEditorState(e,I);break;case "function":a.update(e,I)}}
|
|
17
|
-
function K(a){v.useEffect(()=>{const e=f=>{var d=a.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var c=JSON.parse(d)}catch(b){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [b,g,k,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<=b&&0<=g&&(q=b,p=b+g,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
|
|
18
|
-
k)t.insertRawText(k),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",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
|
|
19
|
-
function L(a,e){E(()=>{const f=a.addListener("command",(d,c)=>{var b=u.$getSelection();if("click"===d&&u.$isNodeSelection(b))return b.clear(),!0;if(!u.$isRangeSelection(b))return!1;switch(d){case "deleteCharacter":return b.deleteCharacter(c),!0;case "deleteWord":return b.deleteWord(c),!0;case "deleteLine":return b.deleteLine(c),!0;case "insertText":return"string"===typeof c?b.insertText(c):(d=c.dataTransfer,null!=d?w.$insertDataTransferForRichText(d,b,a):(c=c.data)&&b.insertText(c)),!0;case "removeText":return b.removeText(),
|
|
20
|
-
!0;case "formatText":return b.formatText(c),!0;case "formatElement":return b=b.anchor.getNode(),(u.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(c),!0;case "insertLineBreak":return b.insertLineBreak(c),!0;case "insertParagraph":return b.insertParagraph(),!0;case "indentContent":return b=b.anchor,b="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),b.canInsertTab()?a.execCommand("insertText","\t"):10!==b.getIndent()&&b.setIndent(b.getIndent()+1),!0;case "outdentContent":return b=b.anchor,
|
|
21
|
-
c=b.getNode(),d="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===c.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=c.shiftKey;if(C(b,!0))return c.preventDefault(),c=d,d=B(b),b.modify(c?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=c.shiftKey;if(C(b,!1))return c.preventDefault(),c=d,d=B(b),b.modify(c?"extend":"move",d,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
|
|
22
|
-
{anchor:c}=b,b.isCollapsed()&&0===c.offset&&0<("element"===c.type?c.getNode():c.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),c.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return c.preventDefault(),a.execCommand(c.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
|
|
23
|
-
!0;case "copy":return G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return H(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);J(a,e);return f},[a]);K(a)}module.exports=function(a,e,f){L(a,f);A(a,e)};
|
|
7
|
+
var d=require("@lexical/history"),e=require("react"),g=require("@lexical/dragon"),h=require("@lexical/rich-text"),k=require("@lexical/utils");function l(a,b,c=1E3){const f=e.useMemo(()=>b||d.createEmptyHistoryState(),[b]);e.useEffect(()=>d.registerHistory(a,f,c),[c,a,f])}function m(a,b,c=1E3){return l(a,b,c)}var n="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;
|
|
8
|
+
function p(a,b){n(()=>k.mergeRegister(h.registerRichText(a,b),g.registerDragonSupport(a)),[a])}module.exports=function(a,b,c){p(a,c);m(a,b)};
|
package/LICENSE
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
|
+
var react = require('react');
|
|
11
|
+
|
|
9
12
|
/**
|
|
10
13
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
11
14
|
*
|
|
@@ -14,10 +17,12 @@
|
|
|
14
17
|
*
|
|
15
18
|
*
|
|
16
19
|
*/
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
function LexicalAutoFocusPlugin() {
|
|
21
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
22
|
+
react.useEffect(() => {
|
|
23
|
+
editor.focus();
|
|
24
|
+
}, [editor]);
|
|
25
|
+
return null;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
module.exports =
|
|
28
|
+
module.exports = LexicalAutoFocusPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
'use strict'
|
|
8
|
+
const LexicalAutoFocusPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalAutoFocusPlugin.dev.js') : require('./LexicalAutoFocusPlugin.prod.js')
|
|
9
|
+
module.exports = LexicalAutoFocusPlugin;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
var b=require("@lexical/react/LexicalComposerContext"),c=require("react");module.exports=function(){const [a]=b.useLexicalComposerContext();c.useEffect(()=>{a.focus()},[a]);return null};
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var link = require('@lexical/link');
|
|
9
10
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
|
-
var
|
|
11
|
+
var utils = require('@lexical/utils');
|
|
11
12
|
var lexical = require('lexical');
|
|
12
|
-
var AutoLinkNode = require('lexical/AutoLinkNode');
|
|
13
13
|
var react = require('react');
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -59,7 +59,6 @@ function handleLinkCreation(node, matchers, onChange) {
|
|
|
59
59
|
let text = nodeText;
|
|
60
60
|
let textOffset = 0;
|
|
61
61
|
let lastNode = node;
|
|
62
|
-
let lastNodeOffset = 0;
|
|
63
62
|
let match;
|
|
64
63
|
|
|
65
64
|
while ((match = findFirstMatch(text, matchers)) && match !== null) {
|
|
@@ -92,18 +91,16 @@ function handleLinkCreation(node, matchers, onChange) {
|
|
|
92
91
|
|
|
93
92
|
if (contentBeforeMatchIsValid && contentAfterMatchIsValid) {
|
|
94
93
|
let middleNode;
|
|
95
|
-
const lastNodeMatchOffset = offset - lastNodeOffset;
|
|
96
94
|
|
|
97
|
-
if (
|
|
95
|
+
if (matchOffset === 0) {
|
|
98
96
|
[middleNode, lastNode] = lastNode.splitText(matchLength);
|
|
99
97
|
} else {
|
|
100
|
-
[, middleNode, lastNode] = lastNode.splitText(
|
|
98
|
+
[, middleNode, lastNode] = lastNode.splitText(matchOffset, matchOffset + matchLength);
|
|
101
99
|
}
|
|
102
100
|
|
|
103
|
-
const linkNode =
|
|
101
|
+
const linkNode = link.$createAutoLinkNode(match.url);
|
|
104
102
|
linkNode.append(lexical.$createTextNode(match.text));
|
|
105
103
|
middleNode.replace(linkNode);
|
|
106
|
-
lastNodeOffset = lastNodeMatchOffset + matchLength;
|
|
107
104
|
onChange(match.url, null);
|
|
108
105
|
}
|
|
109
106
|
|
|
@@ -160,12 +157,12 @@ function handleBadNeighbors(textNode, onChange) {
|
|
|
160
157
|
const nextSibling = textNode.getNextSibling();
|
|
161
158
|
const text = textNode.getTextContent();
|
|
162
159
|
|
|
163
|
-
if (
|
|
160
|
+
if (link.$isAutoLinkNode(previousSibling) && !text.startsWith(' ')) {
|
|
164
161
|
replaceWithChildren(previousSibling);
|
|
165
162
|
onChange(null, previousSibling.getURL());
|
|
166
163
|
}
|
|
167
164
|
|
|
168
|
-
if (
|
|
165
|
+
if (link.$isAutoLinkNode(nextSibling) && !text.endsWith(' ')) {
|
|
169
166
|
replaceWithChildren(nextSibling);
|
|
170
167
|
onChange(null, nextSibling.getURL());
|
|
171
168
|
}
|
|
@@ -185,7 +182,7 @@ function replaceWithChildren(node) {
|
|
|
185
182
|
|
|
186
183
|
function useAutoLink(editor, matchers, onChange) {
|
|
187
184
|
react.useEffect(() => {
|
|
188
|
-
if (!editor.hasNodes([
|
|
185
|
+
if (!editor.hasNodes([link.AutoLinkNode])) {
|
|
189
186
|
{
|
|
190
187
|
throw Error(`LexicalAutoLinkPlugin: AutoLinkNode, TableCellNode or TableRowNode not registered on editor`);
|
|
191
188
|
}
|
|
@@ -197,19 +194,19 @@ function useAutoLink(editor, matchers, onChange) {
|
|
|
197
194
|
}
|
|
198
195
|
};
|
|
199
196
|
|
|
200
|
-
return
|
|
197
|
+
return utils.mergeRegister(editor.registerNodeTransform(lexical.TextNode, textNode => {
|
|
201
198
|
const parent = textNode.getParentOrThrow();
|
|
202
199
|
|
|
203
|
-
if (
|
|
200
|
+
if (link.$isAutoLinkNode(parent)) {
|
|
204
201
|
handleLinkEdit(parent, matchers, onChangeWrapped);
|
|
205
|
-
} else {
|
|
202
|
+
} else if (!link.$isLinkNode(parent)) {
|
|
206
203
|
if (textNode.isSimpleText()) {
|
|
207
204
|
handleLinkCreation(textNode, matchers, onChangeWrapped);
|
|
208
205
|
}
|
|
209
206
|
|
|
210
207
|
handleBadNeighbors(textNode, onChangeWrapped);
|
|
211
208
|
}
|
|
212
|
-
}), editor.
|
|
209
|
+
}), editor.registerNodeTransform(link.AutoLinkNode, linkNode => {
|
|
213
210
|
handleLinkEdit(linkNode, matchers, onChangeWrapped);
|
|
214
211
|
}));
|
|
215
212
|
}, [editor, matchers, onChange]);
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var h=require("@lexical/
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
e=>{
|
|
7
|
+
var h=require("@lexical/link"),k=require("@lexical/react/LexicalComposerContext"),p=require("@lexical/utils"),v=require("lexical"),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();v.$isElementNode(a)&&(a=a.getLastDescendant());return null===a||v.$isLineBreakNode(a)||v.$isTextNode(a)&&a.getTextContent().endsWith(" ")}
|
|
8
|
+
function A(a){a=a.getNextSibling();v.$isElementNode(a)&&(a=a.getFirstDescendant());return null===a||v.$isLineBreakNode(a)||v.$isTextNode(a)&&a.getTextContent().startsWith(" ")}
|
|
9
|
+
function B(a,b,c){var d=a.getChildren();const e=d.length;for(let g=0;g<e;g++){const f=d[g];if(!v.$isTextNode(f)||!f.isSimpleText()){C(a);c(null,a.getURL());return}}d=a.getTextContent();b=x(d,b);null===b||b.text!==d?(C(a),c(null,a.getURL())):y(a)&&A(a)?(d=a.getURL(),null!==b&&d!==b.url&&(a.setURL(b.url),c(b.url,d))):(C(a),c(null,a.getURL()))}function C(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 D(a,b,c){w.useEffect(()=>{if(!a.hasNodes([h.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 p.mergeRegister(a.registerNodeTransform(v.TextNode,e=>{var g=e.getParentOrThrow();if(h.$isAutoLinkNode(g))B(g,b,d);else if(!h.$isLinkNode(g)){if(e.isSimpleText()){g=e.getTextContent();const E=g.length;let u=g,z=0,t=e;for(var f;(f=
|
|
11
|
+
x(u,b))&&null!==f;){var l=f.index,n=z+l;const q=f.length;var r=void 0;r=0<n?" "===g[n-1]:y(e);n=n+q<E?" "===g[n+q]:A(e);if(r&&n){var m=void 0;0===l?[m,t]=t.splitText(q):[,m,t]=t.splitText(l,l+q);r=h.$createAutoLinkNode(f.url);r.append(v.$createTextNode(f.text));m.replace(r);d(f.url,null)}l+=q;u=u.substring(l);z+=l}}f=e.getPreviousSibling();m=e.getNextSibling();e=e.getTextContent();h.$isAutoLinkNode(f)&&!e.startsWith(" ")&&(C(f),d(null,f.getURL()));h.$isAutoLinkNode(m)&&!e.endsWith(" ")&&(C(m),d(null,
|
|
12
|
+
m.getURL()))}}),a.registerNodeTransform(h.AutoLinkNode,e=>{B(e,b,d)}))},[a,b,c])}module.exports=function({matchers:a,onChange:b}){const [c]=k.useLexicalComposerContext();D(c,a,b);return null};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {$ReadOnly} from 'utility-types';
|
|
10
|
+
type Props = $ReadOnly<{
|
|
11
|
+
scrollRef: { current: HTMLElement | null };
|
|
12
|
+
}>;
|
|
13
|
+
export default function LexicalAutoScrollPlugin(props: Props): null;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
|
+
var lexical = require('lexical');
|
|
11
|
+
var react = require('react');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
+
*
|
|
16
|
+
* This source code is licensed under the MIT license found in the
|
|
17
|
+
* LICENSE file in the root directory of this source tree.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
25
|
+
*
|
|
26
|
+
* This source code is licensed under the MIT license found in the
|
|
27
|
+
* LICENSE file in the root directory of this source tree.
|
|
28
|
+
*
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
32
|
+
var useLayoutEffect = useLayoutEffectImpl;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
36
|
+
*
|
|
37
|
+
* This source code is licensed under the MIT license found in the
|
|
38
|
+
* LICENSE file in the root directory of this source tree.
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
function LexicalAutoScrollPlugin({
|
|
43
|
+
scrollRef
|
|
44
|
+
}) {
|
|
45
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
46
|
+
useLayoutEffect(() => {
|
|
47
|
+
return editor.registerUpdateListener(({
|
|
48
|
+
tags,
|
|
49
|
+
editorState
|
|
50
|
+
}) => {
|
|
51
|
+
const scrollElement = scrollRef.current;
|
|
52
|
+
|
|
53
|
+
if (scrollElement === null || !tags.has('scroll-into-view')) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const selection = editorState.read(() => lexical.$getSelection());
|
|
58
|
+
|
|
59
|
+
if (!lexical.$isRangeSelection(selection) || !selection.isCollapsed()) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const anchorElement = editor.getElementByKey(selection.anchor.key);
|
|
64
|
+
|
|
65
|
+
if (anchorElement === null) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const scrollRect = scrollElement.getBoundingClientRect();
|
|
70
|
+
const rect = anchorElement.getBoundingClientRect();
|
|
71
|
+
|
|
72
|
+
if (rect.bottom > scrollRect.bottom) {
|
|
73
|
+
anchorElement.scrollIntoView(false);
|
|
74
|
+
} else if (rect.top < scrollRect.top) {
|
|
75
|
+
anchorElement.scrollIntoView();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}, [editor, scrollRef]);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = LexicalAutoScrollPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
'use strict'
|
|
8
|
+
const LexicalAutoScrollPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalAutoScrollPlugin.dev.js') : require('./LexicalAutoScrollPlugin.prod.js')
|
|
9
|
+
module.exports = LexicalAutoScrollPlugin;
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
+
* @flow strict
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
): () => void;
|
|
9
|
+
type Props = $ReadOnly<{
|
|
10
|
+
scrollRef: {current: HTMLElement | null},
|
|
11
|
+
}>;
|
|
12
|
+
declare export default function LexicalAutoScrollPlugin(props: Props): React$Node;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
var e=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),h=require("react"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
|
|
8
|
+
module.exports=function({scrollRef:g}){const [d]=e.useLexicalComposerContext();k(()=>d.registerUpdateListener(({tags:a,editorState:c})=>{var b=g.current;null!==b&&a.has("scroll-into-view")&&(a=c.read(()=>f.$getSelection()),f.$isRangeSelection(a)&&a.isCollapsed()&&(a=d.getElementByKey(a.anchor.key),null!==a&&(b=b.getBoundingClientRect(),c=a.getBoundingClientRect(),c.bottom>b.bottom?a.scrollIntoView(!1):c.top<b.top&&a.scrollIntoView())))}),[d,g]);return null};
|
|
@@ -8,65 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
10
|
var React = require('react');
|
|
11
|
+
var overflow = require('@lexical/overflow');
|
|
12
|
+
var text = require('@lexical/text');
|
|
13
|
+
var utils = require('@lexical/utils');
|
|
11
14
|
var lexical = require('lexical');
|
|
12
|
-
var withSubscriptions = require('@lexical/react/withSubscriptions');
|
|
13
|
-
var OverflowNode = require('lexical/OverflowNode');
|
|
14
|
-
|
|
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
15
|
|
|
71
16
|
/**
|
|
72
17
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -83,18 +28,18 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
|
|
|
83
28
|
remainingCharacters = characters => {}
|
|
84
29
|
} = optional;
|
|
85
30
|
React.useEffect(() => {
|
|
86
|
-
if (!editor.hasNodes([
|
|
31
|
+
if (!editor.hasNodes([overflow.OverflowNode])) {
|
|
87
32
|
{
|
|
88
33
|
throw Error(`useCharacterLimit: OverflowNode not registered on editor`);
|
|
89
34
|
}
|
|
90
35
|
}
|
|
91
36
|
}, [editor]);
|
|
92
37
|
React.useEffect(() => {
|
|
93
|
-
let text = editor.getEditorState().read(
|
|
38
|
+
let text$1 = editor.getEditorState().read(text.$rootTextContentCurry);
|
|
94
39
|
let lastComputedTextLength = 0;
|
|
95
|
-
return
|
|
96
|
-
text = currentText;
|
|
97
|
-
}), editor.
|
|
40
|
+
return utils.mergeRegister(editor.registerTextContentListener(currentText => {
|
|
41
|
+
text$1 = currentText;
|
|
42
|
+
}), editor.registerUpdateListener(({
|
|
98
43
|
dirtyLeaves
|
|
99
44
|
}) => {
|
|
100
45
|
const isComposing = editor.isComposing();
|
|
@@ -104,13 +49,13 @@ function useCharacterLimit(editor, maxCharacters, optional = Object.freeze({}))
|
|
|
104
49
|
return;
|
|
105
50
|
}
|
|
106
51
|
|
|
107
|
-
const textLength = strlen(text);
|
|
52
|
+
const textLength = strlen(text$1);
|
|
108
53
|
const textLengthAboveThreshold = textLength > maxCharacters || lastComputedTextLength !== null && lastComputedTextLength > maxCharacters;
|
|
109
54
|
const diff = maxCharacters - textLength;
|
|
110
55
|
remainingCharacters(diff);
|
|
111
56
|
|
|
112
57
|
if (lastComputedTextLength === null || textLengthAboveThreshold) {
|
|
113
|
-
const offset = findOffset(text, maxCharacters, strlen);
|
|
58
|
+
const offset = findOffset(text$1, maxCharacters, strlen);
|
|
114
59
|
editor.update(() => {
|
|
115
60
|
$wrapOverflowedNodes(offset);
|
|
116
61
|
}, {
|
|
@@ -130,7 +75,7 @@ function findOffset(text, maxCharacters, strlen) {
|
|
|
130
75
|
|
|
131
76
|
if (typeof Segmenter === 'function') {
|
|
132
77
|
const segmenter = new Segmenter();
|
|
133
|
-
const graphemes = segmenter.segment(text);
|
|
78
|
+
const graphemes = segmenter.segment(text);
|
|
134
79
|
|
|
135
80
|
for (const {
|
|
136
81
|
segment: grapheme
|
|
@@ -165,14 +110,16 @@ function findOffset(text, maxCharacters, strlen) {
|
|
|
165
110
|
}
|
|
166
111
|
|
|
167
112
|
function $wrapOverflowedNodes(offset) {
|
|
168
|
-
const dfsNodes =
|
|
113
|
+
const dfsNodes = utils.$dfs();
|
|
169
114
|
const dfsNodesLength = dfsNodes.length;
|
|
170
115
|
let accumulatedLength = 0;
|
|
171
116
|
|
|
172
117
|
for (let i = 0; i < dfsNodesLength; i += 1) {
|
|
173
|
-
const
|
|
118
|
+
const {
|
|
119
|
+
node
|
|
120
|
+
} = dfsNodes[i];
|
|
174
121
|
|
|
175
|
-
if (
|
|
122
|
+
if (overflow.$isOverflowNode(node)) {
|
|
176
123
|
const previousLength = accumulatedLength;
|
|
177
124
|
const nextLength = accumulatedLength + node.getTextContentSize();
|
|
178
125
|
|
|
@@ -209,7 +156,7 @@ function $wrapOverflowedNodes(offset) {
|
|
|
209
156
|
const previousAccumulatedLength = accumulatedLength;
|
|
210
157
|
accumulatedLength += node.getTextContentSize();
|
|
211
158
|
|
|
212
|
-
if (accumulatedLength > offset && !
|
|
159
|
+
if (accumulatedLength > offset && !overflow.$isOverflowNode(node.getParent())) {
|
|
213
160
|
const previousSelection = lexical.$getSelection();
|
|
214
161
|
let overflowNode; // For simple text we can improve the limit accuracy by splitting the TextNode
|
|
215
162
|
// on the split point
|
|
@@ -232,7 +179,7 @@ function $wrapOverflowedNodes(offset) {
|
|
|
232
179
|
}
|
|
233
180
|
|
|
234
181
|
function $wrapNode(node) {
|
|
235
|
-
const overflowNode =
|
|
182
|
+
const overflowNode = overflow.$createOverflowNode();
|
|
236
183
|
node.insertBefore(overflowNode);
|
|
237
184
|
overflowNode.append(node);
|
|
238
185
|
return overflowNode;
|
|
@@ -253,7 +200,7 @@ function $unwrapNode(node) {
|
|
|
253
200
|
function mergePrevious(overflowNode) {
|
|
254
201
|
const previousNode = overflowNode.getPreviousSibling();
|
|
255
202
|
|
|
256
|
-
if (!
|
|
203
|
+
if (!overflow.$isOverflowNode(previousNode)) {
|
|
257
204
|
return;
|
|
258
205
|
}
|
|
259
206
|
|
|
@@ -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
|
|
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/overflow"),z=require("@lexical/text"),A=require("@lexical/utils"),C=require("lexical");
|
|
8
|
+
function D(b,c,n=Object.freeze({})){const {strlen:g=d=>d.length,remainingCharacters:q=()=>{}}=n;u.useEffect(()=>{if(!b.hasNodes([v.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 A.mergeRegister(b.registerTextContentListener(p=>{d=p}),b.registerUpdateListener(({dirtyLeaves:p})=>
|
|
9
|
+
{var w=b.isComposing();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=F(d,c,g);b.update(()=>{const B=A.$dfs(),J=B.length;let x=0;for(let y=0;y<J;y+=1){var {node:a}=B[y];if(v.$isOverflowNode(a)){var f=x;if(x+a.getTextContentSize()<=r){var h=a.getParent();f=a.getPreviousSibling();var k=a.getNextSibling();G(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():
|
|
10
|
+
null!==h&&h.select())}else f<r&&(h=a.getFirstDescendant(),k=null!==h?h.getTextContentSize():0,f+=k,h=C.$isTextNode(h)&&h.isSimpleText(),f=f<=r,(h||f)&&G(a))}else if(C.$isLeafNode(a)&&(f=x,x+=a.getTextContentSize(),x>r&&!v.$isOverflowNode(a.getParent())&&(h=C.$getSelection(),f<r&&C.$isTextNode(a)&&a.isSimpleText()?([,a]=a.splitText(r-f),a=H(a)):a=H(a),null!==h&&C.$setSelection(h),f=a.getPreviousSibling(),v.$isOverflowNode(f)))){k=a.getFirstChild();var t=f.getChildren();h=t.length;if(null===k)a.append(...t);
|
|
11
|
+
else for(var l=0;l<h;l++)k.insertBefore(t[l]);l=C.$getSelection();if(C.$isRangeSelection(l)){k=l.anchor;t=k.getNode();l=l.focus;const E=k.getNode();t.is(f)?k.set(a.getKey(),k.offset,"element"):t.is(a)&&k.set(a.getKey(),h+k.offset,"element");E.is(f)?l.set(a.getKey(),l.offset,"element"):E.is(a)&&l.set(a.getKey(),h+l.offset,"element")}f.remove()}}},{tag:"history-merge"})}e=w}}))},[b,c,q,g])}
|
|
12
|
+
function F(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 H(b){const c=v.$createOverflowNode();b.insertBefore(c);c.append(b);return c}function G(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 I=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===I&&(I=new window.TextEncoder),e=I;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]);D(c,5,q);return u.createElement("span",{className:`characters-limit ${0>
|
|
14
|
+
n?"characters-limit-exceeded":""}`},n)};
|
|
@@ -44,27 +44,23 @@ function LexicalClearEditorPlugin({
|
|
|
44
44
|
}) {
|
|
45
45
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
46
46
|
useLayoutEffect(() => {
|
|
47
|
-
return editor.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
root.append(paragraph);
|
|
47
|
+
return editor.registerCommand(lexical.CLEAR_EDITOR_COMMAND, payload => {
|
|
48
|
+
editor.update(() => {
|
|
49
|
+
if (onClear == null) {
|
|
50
|
+
const root = lexical.$getRoot();
|
|
51
|
+
const selection = lexical.$getSelection();
|
|
52
|
+
const paragraph = lexical.$createParagraphNode();
|
|
53
|
+
root.clear();
|
|
54
|
+
root.append(paragraph);
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
onClear();
|
|
56
|
+
if (selection !== null) {
|
|
57
|
+
paragraph.select();
|
|
62
58
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
59
|
+
} else {
|
|
60
|
+
onClear();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return true;
|
|
68
64
|
}, 0);
|
|
69
65
|
}, [editor, onClear]);
|
|
70
66
|
return null;
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
var a=require("@lexical/react/LexicalComposerContext"),d=require("lexical"),g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;
|
|
8
|
-
module.exports=function({onClear:b}){const [c]=a.useLexicalComposerContext();h(()=>c.
|
|
8
|
+
module.exports=function({onClear:b}){const [c]=a.useLexicalComposerContext();h(()=>c.registerCommand(d.CLEAR_EDITOR_COMMAND,()=>{c.update(()=>{if(null==b){const e=d.$getRoot(),k=d.$getSelection(),f=d.$createParagraphNode();e.clear();e.append(f);null!==k&&f.select()}else b()});return!0},0),[c,b]);return null};
|