@lexical/react 0.1.9 → 0.1.10
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 -38
- package/DEPRECATED_useLexical.prod.js +1 -2
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +4 -4
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +8 -7
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +2 -2
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +3 -3
- package/DEPRECATED_useLexicalEditor.dev.js +1 -25
- package/DEPRECATED_useLexicalEditor.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +1 -1
- package/DEPRECATED_useLexicalHistory.prod.js +2 -2
- package/DEPRECATED_useLexicalPlainText.dev.js +15 -32
- package/DEPRECATED_useLexicalPlainText.prod.js +14 -15
- package/DEPRECATED_useLexicalRichText.dev.js +57 -209
- package/DEPRECATED_useLexicalRichText.prod.js +26 -29
- package/LexicalAutoFormatterPlugin.dev.js +4 -4
- package/LexicalAutoFormatterPlugin.prod.js +8 -7
- package/LexicalCharacterLimitPlugin.dev.js +2 -2
- package/LexicalCharacterLimitPlugin.prod.js +3 -3
- package/LexicalComposer.dev.js +1 -6
- package/LexicalComposer.prod.js +2 -3
- package/LexicalHistoryPlugin.dev.js +1 -1
- package/LexicalHistoryPlugin.prod.js +2 -2
- package/LexicalPlainTextPlugin.dev.js +12 -8
- package/LexicalPlainTextPlugin.prod.js +7 -7
- package/LexicalRichTextPlugin.dev.js +54 -185
- package/LexicalRichTextPlugin.prod.js +22 -25
- package/LexicalTablePlugin.dev.js +1 -1
- package/LexicalTablePlugin.prod.js +1 -1
- package/LexicalTreeView.dev.js +10 -2
- package/LexicalTreeView.prod.js +9 -8
- package/package.json +5 -5
- package/useLexicalNodeSelection.dev.js +70 -0
- package/useLexicalNodeSelection.js +9 -0
- package/useLexicalNodeSelection.prod.js +8 -0
package/LexicalComposer.dev.js
CHANGED
|
@@ -18,11 +18,6 @@ var React = require('react');
|
|
|
18
18
|
*
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
-
|
|
22
|
-
function defaultOnError(e) {
|
|
23
|
-
throw e;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
21
|
function LexicalComposer({
|
|
27
22
|
initialConfig = {},
|
|
28
23
|
children
|
|
@@ -58,10 +53,10 @@ function LexicalComposer({
|
|
|
58
53
|
context,
|
|
59
54
|
namespace,
|
|
60
55
|
nodes,
|
|
56
|
+
onError,
|
|
61
57
|
parentEditor,
|
|
62
58
|
theme: composerTheme
|
|
63
59
|
});
|
|
64
|
-
editor.addListener('error', onError || defaultOnError);
|
|
65
60
|
}
|
|
66
61
|
|
|
67
62
|
return [editor, context];
|
package/LexicalComposer.prod.js
CHANGED
|
@@ -4,6 +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
|
-
module.exports=function({initialConfig:
|
|
9
|
-
{value:u},n)};
|
|
7
|
+
var d=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),k=require("react");
|
|
8
|
+
module.exports=function({initialConfig:l={},children:m}){const b=k.useContext(d.LexicalComposerContext),t=k.useMemo(()=>{let c,g;const {theme:h,namespace:n,editor:p,nodes:q,onError:r}=l;if(null!=h)c=h;else if(null!=b){g=b[0];var a=b[1].getTheme();null!=a&&(c=a)}a=d.createLexicalComposerContext(b,c);let f=p||null;null===f&&(f=e.createEditor({context:a,namespace:n,nodes:q,onError:r,parentEditor:g,theme:c}));return[f,a]},[]);return k.createElement(d.LexicalComposerContext.Provider,{value:t},m)};
|
|
@@ -74,7 +74,7 @@ function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyEl
|
|
|
74
74
|
return COMPOSING_CHARACTER;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
if (nextSelection
|
|
77
|
+
if (!lexical.$isRangeSelection(nextSelection) || !lexical.$isRangeSelection(prevSelection) || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
|
|
78
78
|
return OTHER;
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
var n=require("@lexical/react/LexicalComposerContext"),t=require("@lexical/react/withSubscriptions"),v=require("lexical"),w=require("react");
|
|
8
|
-
function x(b,d,l,a,h){if(null===b||0===l.size&&0===a.size)return 0;var g=d._selection,c=b._selection;if(h)return 1;if(
|
|
9
|
-
c&&!b._nodeMap.has(d.__key)&&v.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=h[0];b=b._nodeMap.get(d.__key);if(!v.$isTextNode(b)||!v.$isTextNode(d)||b.__mode!==d.__mode)return 0;b=b.__text;d=d.__text;if(b===d)return 0;g=g.anchor;c=c.anchor;if(g.key!==c.key||"text"!==g.type)return 0;g=g.offset;c=c.offset;b=d.length-b.length;return 1===b&&c===g-1?2:-1===b&&c===g+1?3:-1===b&&c===g?4:0}
|
|
8
|
+
function x(b,d,l,a,h){if(null===b||0===l.size&&0===a.size)return 0;var g=d._selection,c=b._selection;if(h)return 1;if(!(v.$isRangeSelection(g)&&v.$isRangeSelection(c)&&c.isCollapsed()&&g.isCollapsed()))return 0;var e=Array.from(l);a=Array.from(a);l=d._nodeMap;h=[];for(var f=0;f<e.length;f++){const k=l.get(e[f]);void 0!==k&&h.push(k)}for(e=0;e<a.length;e++)a[e][1]&&(f=l.get(a[e][0]),void 0===f||v.$isRootNode(f)||h.push(f));if(0===h.length)return 0;if(1<h.length)return a=d._nodeMap,d=a.get(g.anchor.key),
|
|
9
|
+
c=a.get(c.anchor.key),d&&c&&!b._nodeMap.has(d.__key)&&v.$isTextNode(d)&&1===d.__text.length&&1===g.anchor.offset?2:0;d=h[0];b=b._nodeMap.get(d.__key);if(!v.$isTextNode(b)||!v.$isTextNode(d)||b.__mode!==d.__mode)return 0;b=b.__text;d=d.__text;if(b===d)return 0;g=g.anchor;c=c.anchor;if(g.key!==c.key||"text"!==g.type)return 0;g=g.offset;c=c.offset;b=d.length-b.length;return 1===b&&c===g-1?2:-1===b&&c===g+1?3:-1===b&&c===g?4:0}
|
|
10
10
|
function y(b,d){let l=Date.now(),a=0;return(h,g,c,e,f,k)=>{const p=Date.now();if(k.has("historic"))return a=0,l=p,2;const m=x(h,g,e,f,b.isComposing()),u=(()=>{const r=k.has("history-push");if(!r&&k.has("history-merge"))return 0;if(null===h)return 1;var q=g._selection;const A=h._selection;if(!(0<e.size||0<f.size))return null===A&&null!==q?0:2;q=null===c||c.editor===b;return!1===r&&0!==m&&m===a&&p<l+d&&q?0:1})();l=p;a=m;return u}}
|
|
11
11
|
function z(b,d,l=1E3){const a=w.useMemo(()=>d||B(),[d]),h=w.useCallback(()=>{a.undoStack=[];a.redoStack=[];a.current=null},[a]);w.useEffect(()=>{const g=y(b,l);return t(b.addListener("command",c=>{switch(c){case "undo":c=a.redoStack;var e=a.undoStack;if(0!==e.length){var f=a.current;const k=e.pop();null!==f&&(c.push(f),b.execCommand("canRedo",!0));0===e.length&&b.execCommand("canUndo",!1);a.current=k;k.editor.setEditorState(k.editorState.clone(k.undoSelection),{tag:"historic"})}return!0;case "redo":return c=
|
|
12
12
|
a.redoStack,e=a.undoStack,0!==c.length&&(f=a.current,null!==f&&(e.push(f),b.execCommand("canUndo",!0)),e=c.pop(),0===c.length&&b.execCommand("canRedo",!1),a.current=e,e.editor.setEditorState(e.editorState,{tag:"historic"})),!0;case "clearEditor":return h(),!1;case "clearHistory":return h(),!0;default:return!1}},0),b.addListener("update",({editorState:c,prevEditorState:e,dirtyLeaves:f,dirtyElements:k,tags:p})=>{const m=a.current,u=a.redoStack,r=a.undoStack,q=null===m?null:m.editorState;if(null===m||
|
|
@@ -256,7 +256,7 @@ function onPasteForPlainText(event, editor) {
|
|
|
256
256
|
const selection = lexical.$getSelection();
|
|
257
257
|
const clipboardData = event.clipboardData;
|
|
258
258
|
|
|
259
|
-
if (clipboardData != null && selection
|
|
259
|
+
if (clipboardData != null && lexical.$isRangeSelection(selection)) {
|
|
260
260
|
$insertDataTransferForPlainText(clipboardData, selection);
|
|
261
261
|
}
|
|
262
262
|
});
|
|
@@ -266,7 +266,7 @@ function onCutForPlainText(event, editor) {
|
|
|
266
266
|
editor.update(() => {
|
|
267
267
|
const selection = lexical.$getSelection();
|
|
268
268
|
|
|
269
|
-
if (selection
|
|
269
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
270
270
|
selection.removeText();
|
|
271
271
|
}
|
|
272
272
|
});
|
|
@@ -339,7 +339,7 @@ function useLexicalDragonSupport(editor) {
|
|
|
339
339
|
editor.update(() => {
|
|
340
340
|
const selection = lexical.$getSelection();
|
|
341
341
|
|
|
342
|
-
if (selection
|
|
342
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
343
343
|
const anchor = selection.anchor;
|
|
344
344
|
let anchorNode = anchor.getNode();
|
|
345
345
|
let setSelStart = 0;
|
|
@@ -396,13 +396,12 @@ function useLexicalDragonSupport(editor) {
|
|
|
396
396
|
*
|
|
397
397
|
*
|
|
398
398
|
*/
|
|
399
|
-
const EditorPriority = 0;
|
|
400
399
|
function usePlainTextSetup(editor) {
|
|
401
|
-
|
|
400
|
+
React.useEffect(() => {
|
|
402
401
|
const removeListener = editor.addListener('command', (type, payload) => {
|
|
403
402
|
const selection = lexical.$getSelection();
|
|
404
403
|
|
|
405
|
-
if (selection
|
|
404
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
406
405
|
return false;
|
|
407
406
|
}
|
|
408
407
|
|
|
@@ -556,8 +555,13 @@ function usePlainTextSetup(editor) {
|
|
|
556
555
|
}
|
|
557
556
|
|
|
558
557
|
return false;
|
|
559
|
-
},
|
|
560
|
-
editor.execCommand('bootstrapEditor');
|
|
558
|
+
}, 0);
|
|
559
|
+
const bootstrapCommandHandled = editor.execCommand('bootstrapEditor');
|
|
560
|
+
|
|
561
|
+
if (!bootstrapCommandHandled) {
|
|
562
|
+
console.warn('bootstrapEditor command was not handled. Did you forget to add <BootstrapPlugin />?');
|
|
563
|
+
}
|
|
564
|
+
|
|
561
565
|
return removeListener;
|
|
562
566
|
}, [editor]);
|
|
563
567
|
useLexicalDragonSupport(editor);
|
|
@@ -8,11 +8,11 @@ var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),t=requ
|
|
|
8
8
|
function w(a){if(!v(a,!1))return!1;a=t.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let c=0;c<e;c++){var b=a[c];if(t.$isElementNode(b)){if("paragraph"!==b.__type||0!==b.__indent)return!1;b=b.getChildren();const d=b.length;for(let f=0;f<d;f++)if(!t.$isTextNode(b[c]))return!1}}return!0}function x(a){return()=>w(a)}var y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
|
|
9
9
|
function z(a){const [e,b]=h.useState(a.getEditorState().read(x(a.isComposing())));y(()=>a.addListener("update",({editorState:c})=>{const d=a.isComposing();c=c.read(x(d));b(c)}),[a]);return e}function A(a){const [e,b]=h.useState(()=>a.getDecorators());y(()=>a.addListener("decorator",c=>{u.flushSync(()=>{b(c)})}),[a]);return h.useMemo(()=>{const c=[],d=Object.keys(e);for(let p=0;p<d.length;p++){var f=d[p];const r=e[f];f=a.getElementByKey(f);null!==f&&c.push(u.createPortal(r,f))}return c},[e,a])}
|
|
10
10
|
function C(a){a=a.anchor.getNode();return"rtl"===(t.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function D(a,e,b){const c=a.getParent();let d=b;null!==c&&(e&&0===b?(d=a.getIndexWithinParent(),a=c):e||b!==a.getChildrenSize()||(d=a.getIndexWithinParent()+1,a=c));return a.getChildAtIndex(e?d-1:d)}function E(a,e){a=a.getData("text/plain");null!=a&&e.insertRawText(a)}
|
|
11
|
-
function F(a,e){var b=a.focus;a=b.offset;"element"===b.type?(b=b.getNode(),e=D(b,e,a)):(b=b.getNode(),e&&0===a||!e&&a===b.getTextContentSize()?(a=e?b.getPreviousSibling():b.getNextSibling(),e=null===a?D(b.getParentOrThrow(),e,b.getIndexWithinParent()+(e?0:1)):a):e=null);return t.$isDecoratorNode(e)&&!e.isIsolated()}function G(a,e){a.preventDefault();e.update(()=>{const b=t.$getSelection(),c=a.clipboardData;null!=c&&
|
|
12
|
-
function H(a,e){I(a,e);e.update(()=>{const b=t.$getSelection();
|
|
13
|
-
function J(a){h.useEffect(()=>{const e=b=>{var c=a.getRootElement();if(document.activeElement===c&&(c=b.data,"string"===typeof c)){try{var d=JSON.parse(c)}catch(f){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [f,p,r,B,K]=d;a.update(()=>{const q=t.$getSelection();if(
|
|
14
|
-
k=n.getNode();t.$isTextNode(k)&&(l=B,m=B+K,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));b.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
|
|
15
|
-
function L(a){
|
|
16
|
-
!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b=c.shiftKey;if(F(d,!0))return c.preventDefault(),c=b,b=C(d),d.modify(c?"extend":"move",!b,"character"),!0;break;case "keyArrowRight":b=c.shiftKey;if(F(d,!1))return c.preventDefault(),c=b,b=C(d),d.modify(c?"extend":"move",b,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
|
|
17
|
-
|
|
11
|
+
function F(a,e){var b=a.focus;a=b.offset;"element"===b.type?(b=b.getNode(),e=D(b,e,a)):(b=b.getNode(),e&&0===a||!e&&a===b.getTextContentSize()?(a=e?b.getPreviousSibling():b.getNextSibling(),e=null===a?D(b.getParentOrThrow(),e,b.getIndexWithinParent()+(e?0:1)):a):e=null);return t.$isDecoratorNode(e)&&!e.isIsolated()}function G(a,e){a.preventDefault();e.update(()=>{const b=t.$getSelection(),c=a.clipboardData;null!=c&&t.$isRangeSelection(b)&&E(c,b)})}
|
|
12
|
+
function H(a,e){I(a,e);e.update(()=>{const b=t.$getSelection();t.$isRangeSelection(b)&&b.removeText()})}function I(a,e){a.preventDefault();e.update(()=>{const b=a.clipboardData,c=t.$getSelection();if(null!==c&&null!=b){var d=window.getSelection();if(!d.isCollapsed){var f=d.getRangeAt(0);f&&(d=document.createElement("div"),f=f.cloneContents(),d.appendChild(f),b.setData("text/html",d.innerHTML));b.setData("text/plain",c.getTextContent())}}})}
|
|
13
|
+
function J(a){h.useEffect(()=>{const e=b=>{var c=a.getRootElement();if(document.activeElement===c&&(c=b.data,"string"===typeof c)){try{var d=JSON.parse(c)}catch(f){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [f,p,r,B,K]=d;a.update(()=>{const q=t.$getSelection();if(t.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;t.$isTextNode(k)&&0<=f&&0<=p&&(l=f,m=f+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
|
|
14
|
+
r)q.insertRawText(r),k=n.getNode();t.$isTextNode(k)&&(l=B,m=B+K,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));b.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
|
|
15
|
+
function L(a){h.useEffect(()=>{const e=a.addListener("command",(b,c)=>{const d=t.$getSelection();if(!t.$isRangeSelection(d))return!1;switch(b){case "deleteCharacter":return d.deleteCharacter(c),!0;case "deleteWord":return d.deleteWord(c),!0;case "deleteLine":return d.deleteLine(c),!0;case "insertText":return"string"===typeof c?d.insertText(c):(b=c.dataTransfer,null!=b?E(b,d):(c=c.data)&&d.insertText(c)),!0;case "removeText":return d.removeText(),!0;case "insertLineBreak":return d.insertLineBreak(c),
|
|
16
|
+
!0;case "insertParagraph":return d.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b=c.shiftKey;if(F(d,!0))return c.preventDefault(),c=b,b=C(d),d.modify(c?"extend":"move",!b,"character"),!0;break;case "keyArrowRight":b=c.shiftKey;if(F(d,!1))return c.preventDefault(),c=b,b=C(d),d.modify(c?"extend":"move",b,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
|
|
17
|
+
a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "copy":return I(c,a),!0;case "cut":return H(c,a),!0;case "paste":return G(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return e},[a]);J(a)}
|
|
18
18
|
module.exports=function({contentEditable:a,placeholder:e}){var [b]=g.useLexicalComposerContext();const c=z(b);L(b);b=A(b);return h.createElement(h.Fragment,null,a,c&&e,b)};
|
|
@@ -10,10 +10,6 @@ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
|
10
10
|
var React = require('react');
|
|
11
11
|
var lexical = require('lexical');
|
|
12
12
|
var reactDom = require('react-dom');
|
|
13
|
-
var list = require('@lexical/list');
|
|
14
|
-
var CodeNode = require('lexical/CodeNode');
|
|
15
|
-
var HeadingNode = require('lexical/HeadingNode');
|
|
16
|
-
var LinkNode = require('lexical/LinkNode');
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
15
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -261,6 +257,12 @@ function $copyLeafNodeBranchToRoot(leaf, startingOffset, isLeftSide, range, node
|
|
|
261
257
|
}
|
|
262
258
|
|
|
263
259
|
function $cloneContents(selection) {
|
|
260
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
261
|
+
{
|
|
262
|
+
throw Error(`TODO`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
264
266
|
const anchor = selection.anchor;
|
|
265
267
|
const focus = selection.focus;
|
|
266
268
|
const anchorOffset = anchor.getCharacterOffset();
|
|
@@ -420,170 +422,6 @@ function getPossibleDecoratorNode(focus, isBackward) {
|
|
|
420
422
|
*
|
|
421
423
|
*/
|
|
422
424
|
|
|
423
|
-
const isCodeElement = div => {
|
|
424
|
-
return div.style.fontFamily.match('monospace') !== null;
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
const DOM_NODE_NAME_TO_LEXICAL_NODE = {
|
|
428
|
-
'#text': domNode => ({
|
|
429
|
-
node: lexical.$createTextNode(domNode.textContent)
|
|
430
|
-
}),
|
|
431
|
-
a: domNode => {
|
|
432
|
-
let node;
|
|
433
|
-
|
|
434
|
-
if (domNode instanceof HTMLAnchorElement) {
|
|
435
|
-
node = LinkNode.$createLinkNode(domNode.href);
|
|
436
|
-
} else {
|
|
437
|
-
node = lexical.$createTextNode(domNode.textContent);
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
return {
|
|
441
|
-
node
|
|
442
|
-
};
|
|
443
|
-
},
|
|
444
|
-
b: domNode => {
|
|
445
|
-
// $FlowFixMe[incompatible-type] domNode is a <b> since we matched it by nodeName
|
|
446
|
-
const b = domNode; // Google Docs wraps all copied HTML in a <b> with font-weight normal
|
|
447
|
-
|
|
448
|
-
const hasNormalFontWeight = b.style.fontWeight === 'normal';
|
|
449
|
-
return {
|
|
450
|
-
forChild: lexicalNode => {
|
|
451
|
-
if (lexical.$isTextNode(lexicalNode) && !hasNormalFontWeight) {
|
|
452
|
-
lexicalNode.toggleFormat('bold');
|
|
453
|
-
}
|
|
454
|
-
},
|
|
455
|
-
node: null
|
|
456
|
-
};
|
|
457
|
-
},
|
|
458
|
-
br: () => ({
|
|
459
|
-
node: lexical.$createLineBreakNode()
|
|
460
|
-
}),
|
|
461
|
-
div: domNode => {
|
|
462
|
-
// $FlowFixMe[incompatible-type] domNode is a <div> since we matched it by nodeName
|
|
463
|
-
const div = domNode;
|
|
464
|
-
return {
|
|
465
|
-
after: childLexicalNodes => {
|
|
466
|
-
const domParent = domNode.parentNode;
|
|
467
|
-
|
|
468
|
-
if (domParent != null && domNode !== domParent.lastChild) {
|
|
469
|
-
childLexicalNodes.push(lexical.$createLineBreakNode());
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
return childLexicalNodes;
|
|
473
|
-
},
|
|
474
|
-
node: isCodeElement(div) ? CodeNode.$createCodeNode() : null
|
|
475
|
-
};
|
|
476
|
-
},
|
|
477
|
-
em: domNode => {
|
|
478
|
-
return {
|
|
479
|
-
forChild: lexicalNode => {
|
|
480
|
-
if (lexical.$isTextNode(lexicalNode)) {
|
|
481
|
-
lexicalNode.toggleFormat('italic');
|
|
482
|
-
}
|
|
483
|
-
},
|
|
484
|
-
node: null
|
|
485
|
-
};
|
|
486
|
-
},
|
|
487
|
-
h1: () => ({
|
|
488
|
-
node: HeadingNode.$createHeadingNode('h1')
|
|
489
|
-
}),
|
|
490
|
-
h2: () => ({
|
|
491
|
-
node: HeadingNode.$createHeadingNode('h2')
|
|
492
|
-
}),
|
|
493
|
-
h3: () => ({
|
|
494
|
-
node: HeadingNode.$createHeadingNode('h3')
|
|
495
|
-
}),
|
|
496
|
-
h4: () => ({
|
|
497
|
-
node: HeadingNode.$createHeadingNode('h4')
|
|
498
|
-
}),
|
|
499
|
-
h5: () => ({
|
|
500
|
-
node: HeadingNode.$createHeadingNode('h5')
|
|
501
|
-
}),
|
|
502
|
-
i: domNode => {
|
|
503
|
-
return {
|
|
504
|
-
forChild: lexicalNode => {
|
|
505
|
-
if (lexical.$isTextNode(lexicalNode)) {
|
|
506
|
-
lexicalNode.toggleFormat('italic');
|
|
507
|
-
}
|
|
508
|
-
},
|
|
509
|
-
node: null
|
|
510
|
-
};
|
|
511
|
-
},
|
|
512
|
-
li: () => ({
|
|
513
|
-
node: list.$createListItemNode()
|
|
514
|
-
}),
|
|
515
|
-
ol: () => ({
|
|
516
|
-
node: list.$createListNode('ol')
|
|
517
|
-
}),
|
|
518
|
-
p: () => ({
|
|
519
|
-
node: lexical.$createParagraphNode()
|
|
520
|
-
}),
|
|
521
|
-
pre: domNode => ({
|
|
522
|
-
node: CodeNode.$createCodeNode()
|
|
523
|
-
}),
|
|
524
|
-
span: domNode => {
|
|
525
|
-
// $FlowFixMe[incompatible-type] domNode is a <span> since we matched it by nodeName
|
|
526
|
-
const span = domNode; // Google Docs uses span tags + font-weight for bold text
|
|
527
|
-
|
|
528
|
-
const hasBoldFontWeight = span.style.fontWeight === '700';
|
|
529
|
-
return {
|
|
530
|
-
forChild: lexicalNode => {
|
|
531
|
-
if (lexical.$isTextNode(lexicalNode) && hasBoldFontWeight) {
|
|
532
|
-
lexicalNode.toggleFormat('bold');
|
|
533
|
-
}
|
|
534
|
-
},
|
|
535
|
-
node: null
|
|
536
|
-
};
|
|
537
|
-
},
|
|
538
|
-
strong: domNode => {
|
|
539
|
-
return {
|
|
540
|
-
forChild: lexicalNode => {
|
|
541
|
-
if (lexical.$isTextNode(lexicalNode)) {
|
|
542
|
-
lexicalNode.toggleFormat('bold');
|
|
543
|
-
}
|
|
544
|
-
},
|
|
545
|
-
node: null
|
|
546
|
-
};
|
|
547
|
-
},
|
|
548
|
-
table: domNode => {
|
|
549
|
-
// $FlowFixMe[incompatible-type] domNode is a <table> since we matched it by nodeName
|
|
550
|
-
const table = domNode;
|
|
551
|
-
const isGitHubCodeTable = table.classList.contains('js-file-line-container');
|
|
552
|
-
return {
|
|
553
|
-
node: isGitHubCodeTable ? CodeNode.$createCodeNode() : null
|
|
554
|
-
};
|
|
555
|
-
},
|
|
556
|
-
td: domNode => {
|
|
557
|
-
// $FlowFixMe[incompatible-type] domNode is a <table> since we matched it by nodeName
|
|
558
|
-
const cell = domNode;
|
|
559
|
-
const isGitHubCodeCell = cell.classList.contains('js-file-line');
|
|
560
|
-
return {
|
|
561
|
-
after: childLexicalNodes => {
|
|
562
|
-
if (isGitHubCodeCell && cell.parentNode && cell.parentNode.nextSibling) {
|
|
563
|
-
// Append newline between code lines
|
|
564
|
-
childLexicalNodes.push(lexical.$createLineBreakNode());
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
return childLexicalNodes;
|
|
568
|
-
},
|
|
569
|
-
node: null
|
|
570
|
-
};
|
|
571
|
-
},
|
|
572
|
-
u: domNode => {
|
|
573
|
-
return {
|
|
574
|
-
forChild: lexicalNode => {
|
|
575
|
-
if (lexical.$isTextNode(lexicalNode)) {
|
|
576
|
-
lexicalNode.toggleFormat('underline');
|
|
577
|
-
}
|
|
578
|
-
},
|
|
579
|
-
node: null
|
|
580
|
-
};
|
|
581
|
-
},
|
|
582
|
-
ul: () => ({
|
|
583
|
-
node: list.$createListNode('ul')
|
|
584
|
-
})
|
|
585
|
-
};
|
|
586
|
-
|
|
587
425
|
function $generateNodes(nodeRange) {
|
|
588
426
|
const {
|
|
589
427
|
range,
|
|
@@ -605,12 +443,34 @@ function $generateNodes(nodeRange) {
|
|
|
605
443
|
return nodes;
|
|
606
444
|
}
|
|
607
445
|
|
|
608
|
-
function
|
|
446
|
+
function getConversionFunction(domNode, editor) {
|
|
447
|
+
const {
|
|
448
|
+
nodeName
|
|
449
|
+
} = domNode;
|
|
450
|
+
|
|
451
|
+
const cachedConversions = editor._htmlConversions.get(nodeName.toLowerCase());
|
|
452
|
+
|
|
453
|
+
let currentConversion = null;
|
|
454
|
+
|
|
455
|
+
if (cachedConversions !== undefined) {
|
|
456
|
+
cachedConversions.forEach(cachedConversion => {
|
|
457
|
+
const domConversion = cachedConversion(domNode);
|
|
458
|
+
|
|
459
|
+
if (domConversion !== null) {
|
|
460
|
+
if (currentConversion === null || currentConversion.priority < domConversion.priority) {
|
|
461
|
+
currentConversion = domConversion;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
return currentConversion !== null ? currentConversion.conversion : null;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function $createNodesFromDOM(node, editor, forChildMap = new Map()) {
|
|
609
471
|
let lexicalNodes = [];
|
|
610
472
|
let currentLexicalNode = null;
|
|
611
|
-
const
|
|
612
|
-
const customHtmlTransforms = editor._config.htmlTransforms || {};
|
|
613
|
-
const transformFunction = customHtmlTransforms[nodeName] || conversionMap[nodeName];
|
|
473
|
+
const transformFunction = getConversionFunction(node, editor);
|
|
614
474
|
const transformOutput = transformFunction ? transformFunction(node) : null;
|
|
615
475
|
let postTransform = null;
|
|
616
476
|
|
|
@@ -628,7 +488,7 @@ function $createNodesFromDOM(node, conversionMap, editor, forChildMap = new Map(
|
|
|
628
488
|
}
|
|
629
489
|
|
|
630
490
|
if (transformOutput.forChild != null) {
|
|
631
|
-
forChildMap.set(nodeName, transformOutput.forChild);
|
|
491
|
+
forChildMap.set(node.nodeName, transformOutput.forChild);
|
|
632
492
|
}
|
|
633
493
|
} // If the DOM node doesn't have a transformer, we don't know what
|
|
634
494
|
// to do with it but we still need to process any childNodes.
|
|
@@ -638,7 +498,7 @@ function $createNodesFromDOM(node, conversionMap, editor, forChildMap = new Map(
|
|
|
638
498
|
let childLexicalNodes = [];
|
|
639
499
|
|
|
640
500
|
for (let i = 0; i < children.length; i++) {
|
|
641
|
-
childLexicalNodes.push(...$createNodesFromDOM(children[i],
|
|
501
|
+
childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, forChildMap));
|
|
642
502
|
}
|
|
643
503
|
|
|
644
504
|
if (postTransform != null) {
|
|
@@ -660,13 +520,13 @@ function $createNodesFromDOM(node, conversionMap, editor, forChildMap = new Map(
|
|
|
660
520
|
return lexicalNodes;
|
|
661
521
|
}
|
|
662
522
|
|
|
663
|
-
function $generateNodesFromDOM(dom,
|
|
523
|
+
function $generateNodesFromDOM(dom, editor) {
|
|
664
524
|
let lexicalNodes = [];
|
|
665
525
|
const elements = dom.body ? Array.from(dom.body.childNodes) : [];
|
|
666
526
|
const elementsLength = elements.length;
|
|
667
527
|
|
|
668
528
|
for (let i = 0; i < elementsLength; i++) {
|
|
669
|
-
const lexicalNode = $createNodesFromDOM(elements[i],
|
|
529
|
+
const lexicalNode = $createNodesFromDOM(elements[i], editor);
|
|
670
530
|
|
|
671
531
|
if (lexicalNode !== null) {
|
|
672
532
|
lexicalNodes = lexicalNodes.concat(lexicalNode);
|
|
@@ -701,7 +561,7 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
|
|
|
701
561
|
if (htmlString) {
|
|
702
562
|
const parser = new DOMParser();
|
|
703
563
|
const dom = parser.parseFromString(htmlString, textHtmlMimeType);
|
|
704
|
-
const nodes = $generateNodesFromDOM(dom,
|
|
564
|
+
const nodes = $generateNodesFromDOM(dom, editor); // Wrap text and inline nodes in paragraph nodes so we have all blocks at the top-level
|
|
705
565
|
|
|
706
566
|
const topLevelBlocks = [];
|
|
707
567
|
let currentBlock = null;
|
|
@@ -747,7 +607,7 @@ function onPasteForRichText(event, editor) {
|
|
|
747
607
|
const selection = lexical.$getSelection();
|
|
748
608
|
const clipboardData = event.clipboardData;
|
|
749
609
|
|
|
750
|
-
if (clipboardData != null && selection
|
|
610
|
+
if (clipboardData != null && lexical.$isRangeSelection(selection)) {
|
|
751
611
|
$insertDataTransferForRichText(clipboardData, selection, editor);
|
|
752
612
|
}
|
|
753
613
|
});
|
|
@@ -757,7 +617,7 @@ function onCutForRichText(event, editor) {
|
|
|
757
617
|
editor.update(() => {
|
|
758
618
|
const selection = lexical.$getSelection();
|
|
759
619
|
|
|
760
|
-
if (selection
|
|
620
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
761
621
|
selection.removeText();
|
|
762
622
|
}
|
|
763
623
|
});
|
|
@@ -835,7 +695,7 @@ function useLexicalDragonSupport(editor) {
|
|
|
835
695
|
editor.update(() => {
|
|
836
696
|
const selection = lexical.$getSelection();
|
|
837
697
|
|
|
838
|
-
if (selection
|
|
698
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
839
699
|
const anchor = selection.anchor;
|
|
840
700
|
let anchorNode = anchor.getNode();
|
|
841
701
|
let setSelStart = 0;
|
|
@@ -892,13 +752,17 @@ function useLexicalDragonSupport(editor) {
|
|
|
892
752
|
*
|
|
893
753
|
*
|
|
894
754
|
*/
|
|
895
|
-
const EditorPriority = 0;
|
|
896
755
|
function useRichTextSetup(editor) {
|
|
897
|
-
|
|
756
|
+
React.useEffect(() => {
|
|
898
757
|
const removeListener = editor.addListener('command', (type, payload) => {
|
|
899
758
|
const selection = lexical.$getSelection();
|
|
900
759
|
|
|
901
|
-
if (
|
|
760
|
+
if (type === 'click' && lexical.$isNodeSelection(selection)) {
|
|
761
|
+
selection.clear();
|
|
762
|
+
return true;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
902
766
|
return false;
|
|
903
767
|
}
|
|
904
768
|
|
|
@@ -1127,8 +991,13 @@ function useRichTextSetup(editor) {
|
|
|
1127
991
|
}
|
|
1128
992
|
|
|
1129
993
|
return false;
|
|
1130
|
-
},
|
|
1131
|
-
editor.execCommand('bootstrapEditor');
|
|
994
|
+
}, 0);
|
|
995
|
+
const bootstrapCommandHandled = editor.execCommand('bootstrapEditor');
|
|
996
|
+
|
|
997
|
+
if (!bootstrapCommandHandled) {
|
|
998
|
+
console.warn('bootstrapEditor command was not handled. Did you forget to add <BootstrapPlugin />?');
|
|
999
|
+
}
|
|
1000
|
+
|
|
1132
1001
|
return removeListener;
|
|
1133
1002
|
}, [editor]);
|
|
1134
1003
|
useLexicalDragonSupport(editor);
|
|
@@ -4,28 +4,25 @@
|
|
|
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 g=require("@lexical/react/LexicalComposerContext"),
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
f.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=e}}function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
({
|
|
16
|
-
|
|
17
|
-
function
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
c.canInsertTab()?"\t"===b.getTextContent()[d.offset-1]&&a.execCommand("deleteCharacter",!0):0!==c.getIndent()&&c.setIndent(c.getIndent()-1),!0;case "keyArrowLeft":c=b.shiftKey;if(R(d,!0))return b.preventDefault(),b=c,c=M(d),d.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(R(d,!1))return b.preventDefault(),b=c,c=M(d),d.modify(b?"extend":"move",c,"character"),!0;break;case "keyBackspace":return b.preventDefault(),{anchor:b}=d,d.isCollapsed()&&0===b.offset&&0<
|
|
30
|
-
("element"===b.type?b.getNode():b.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),b.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return b.preventDefault(),a.execCommand(b.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),!0;case "copy":return U(b,a),
|
|
31
|
-
!0;case "cut":return T(b,a),!0;case "paste":return S(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return e},[a]);W(a)}module.exports=function({contentEditable:a,placeholder:e}){var [c]=g.useLexicalComposerContext();const b=I(c);X(c);c=J(c);return v.createElement(v.Fragment,null,a,b&&e,c)};
|
|
7
|
+
var g=require("@lexical/react/LexicalComposerContext"),u=require("react"),y=require("lexical"),z=require("react-dom");function A(a,e=!0){if(a)return!1;a=y.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
|
|
8
|
+
function B(a){if(!A(a,!1))return!1;a=y.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let b=0;b<e;b++){var d=a[b];if(y.$isElementNode(d)){if("paragraph"!==d.__type||0!==d.__indent)return!1;d=d.getChildren();const c=d.length;for(let f=0;f<c;f++)if(!y.$isTextNode(d[b]))return!1}}return!0}function C(a){return()=>B(a)}var D="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?u.useLayoutEffect:u.useEffect;
|
|
9
|
+
function E(a){const [e,d]=u.useState(a.getEditorState().read(C(a.isComposing())));D(()=>a.addListener("update",({editorState:b})=>{const c=a.isComposing();b=b.read(C(c));d(b)}),[a]);return e}function F(a){const [e,d]=u.useState(()=>a.getDecorators());D(()=>a.addListener("decorator",b=>{z.flushSync(()=>{d(b)})}),[a]);return u.useMemo(()=>{const b=[],c=Object.keys(e);for(let k=0;k<c.length;k++){var f=c[k];const h=e[f];f=a.getElementByKey(f);null!==f&&b.push(z.createPortal(h,f))}return b},[e,a])}
|
|
10
|
+
function G(a){a=a.getLatest();const e=a.constructor.clone(a);e.__parent=a.__parent;y.$isElementNode(a)&&y.$isElementNode(e)?(e.__children=Array.from(a.__children),e.__format=a.__format,e.__indent=a.__indent,e.__dir=a.__dir):y.$isTextNode(a)&&y.$isTextNode(e)?(e.__format=a.__format,e.__style=a.__style,e.__mode=a.__mode,e.__detail=a.__detail):y.$isDecoratorNode(a)&&y.$isDecoratorNode(e)&&(e.__state=a.__state);return e}
|
|
11
|
+
function H(a,e,d,b,c){for(var f=e;null!==a;){for(e=a.getParent();null!==e&&e.excludeFromCopy();)e=e.getParent();if(null===e)break;if(!y.$isElementNode(a)||!a.excludeFromCopy()){const k=a.getKey();let h=c.get(k);const l=void 0===h;l&&(h=G(a),c.set(k,h));!y.$isTextNode(h)||h.isSegmented()||h.isToken()?y.$isElementNode(h)&&(h.__children=h.__children.slice(d?f:0,d?void 0:f+1)):h.__text=h.__text.slice(d?f:0,d?void 0:f);if(y.$isRootNode(e)){l&&b.push(k);break}}f=c.get(e.getKey());f=y.$isElementNode(f)?
|
|
12
|
+
f.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=e}}function I(a){a=a.anchor.getNode();return"rtl"===(y.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function J(a,e,d){const b=a.getParent();let c=d;null!==b&&(e&&0===d?(c=a.getIndexWithinParent(),a=b):e||d!==a.getChildrenSize()||(c=a.getIndexWithinParent()+1,a=b));return a.getChildAtIndex(e?c-1:c)}
|
|
13
|
+
function K(a,e){const {nodeName:d}=a;e=e._htmlConversions.get(d.toLowerCase());let b=null;void 0!==e&&e.forEach(c=>{c=c(a);null!==c&&(null===b||b.priority<c.priority)&&(b=c)});return null!==b?b.conversion:null}
|
|
14
|
+
function L(a,e,d=new Map){let b=[],c=null;var f=K(a,e),k=f?f(a):null;f=null;if(null!==k){f=k.after;c=k.node;if(null!==c){b.push(c);var h=Array.from(d.values());for(let l=0;l<h.length;l++)h[l](c)}null!=k.forChild&&d.set(a.nodeName,k.forChild)}a=a.childNodes;k=[];for(h=0;h<a.length;h++)k.push(...L(a[h],e,d));null!=f&&(k=f(k));null==c?b=b.concat(k):y.$isElementNode(c)&&c.append(...k);return b}
|
|
15
|
+
function M(a,e,d){var b=a.getData("application/x-lexical-editor");if(b){var c=d._config.namespace;try{const l=JSON.parse(b);if(l.namespace===c){const {range:t,nodeMap:m}=l.state;var f=new Map(m);b=[];for(c=0;c<t.length;c++){var k=f.get(t[c]);if(void 0!==k){var h=y.$createNodeFromParse(k,f);b.push(h)}}e.insertNodes(b);return}}catch(l){}}if(f=a.getData("text/html")){f=(new DOMParser).parseFromString(f,"text/html");a=[];f=f.body?Array.from(f.body.childNodes):[];k=f.length;for(h=0;h<k;h++)b=L(f[h],d),
|
|
16
|
+
null!==b&&(a=a.concat(b));d=a;a=[];f=null;for(k=0;k<d.length;k++)h=d[k],!y.$isElementNode(h)||h.isInline()?(null===f&&(f=y.$createParagraphNode(),a.push(f)),null!==f&&f.append(h)):(a.push(h),f=null);e.insertNodes(a)}else d=a.getData("text/plain"),null!=d&&e.insertRawText(d)}
|
|
17
|
+
function N(a,e){var d=a.focus;a=d.offset;"element"===d.type?(d=d.getNode(),e=J(d,e,a)):(d=d.getNode(),e&&0===a||!e&&a===d.getTextContentSize()?(a=e?d.getPreviousSibling():d.getNextSibling(),e=null===a?J(d.getParentOrThrow(),e,d.getIndexWithinParent()+(e?0:1)):a):e=null);return y.$isDecoratorNode(e)&&!e.isIsolated()}function O(a,e){a.preventDefault();e.update(()=>{const d=y.$getSelection(),b=a.clipboardData;null!=b&&y.$isRangeSelection(d)&&M(b,d,e)})}
|
|
18
|
+
function P(a,e){Q(a,e);e.update(()=>{const d=y.$getSelection();y.$isRangeSelection(d)&&d.removeText()})}
|
|
19
|
+
function Q(a,e){a.preventDefault();e.update(()=>{const d=a.clipboardData;var b=y.$getSelection();if(null!==b&&null!=d){var c=window.getSelection();if(!c.isCollapsed){var f=c.getRangeAt(0);f&&(c=document.createElement("div"),f=f.cloneContents(),c.appendChild(f),d.setData("text/html",c.innerHTML));d.setData("text/plain",b.getTextContent());c=e._config.namespace;f=d.setData;var k=JSON,h=k.stringify;{if(!y.$isRangeSelection(b))throw Error("Minified Lexical error #68; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");
|
|
20
|
+
var l=b.anchor,t=b.focus;var m=l.getCharacterOffset();const x=t.getCharacterOffset();var n=l.getNode(),q=t.getNode(),p=n.getParentOrThrow();if(n===q&&y.$isTextNode(n)&&(p.canBeEmpty()||1<p.getChildrenSize()))b=G(n),n=x>m,b.__text=b.__text.slice(n?m:x,n?x:m),m=b.getKey(),m={nodeMap:[[m,b]],range:[m]};else if(b=b.getNodes(),0===b.length)m={nodeMap:[],range:[]};else{n=b.length;q=b[0];p=q.getParent();if(null!==p&&(!p.canBeEmpty()||y.$isRootNode(p))){var r=p.__children;if(r.length===n){var v=!0;for(var w=
|
|
21
|
+
0;w<r.length;w++)if(r[w]!==b[w].__key){v=!1;break}v&&(n++,b.push(p))}}p=b[n-1];l=l.isBefore(t);t=new Map;r=[];H(q,l?m:x,!0,r,t);for(q=0;q<n;q++)if(v=b[q],w=v.getKey(),!(t.has(w)||y.$isElementNode(v)&&v.excludeFromCopy())){const R=G(v);y.$isRootNode(v.getParent())&&r.push(v.getKey());t.set(w,R)}H(p,l?x:m,!1,r,t);m={nodeMap:Array.from(t.entries()),range:r}}}f.call(d,"application/x-lexical-editor",h.call(k,{namespace:c,state:m}))}}})}
|
|
22
|
+
function S(a){u.useEffect(()=>{const e=d=>{var b=a.getRootElement();if(document.activeElement===b&&(b=d.data,"string"===typeof b)){try{var c=JSON.parse(b)}catch(f){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [f,k,h,l,t]=c;a.update(()=>{const m=y.$getSelection();if(y.$isRangeSelection(m)){var n=m.anchor;let q=n.getNode(),p=0,r=0;y.$isTextNode(q)&&0<=f&&0<=k&&(p=f,r=f+k,m.setTextNodeRange(q,p,q,r));if(p!==r||""!==
|
|
23
|
+
h)m.insertRawText(h),q=n.getNode();y.$isTextNode(q)&&(p=l,r=l+t,n=q.getTextContentSize(),p=p>n?n:p,r=r>n?n:r,m.setTextNodeRange(q,p,q,r));d.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
|
|
24
|
+
function T(a){u.useEffect(()=>{const e=a.addListener("command",(d,b)=>{var c=y.$getSelection();if("click"===d&&y.$isNodeSelection(c))return c.clear(),!0;if(!y.$isRangeSelection(c))return!1;switch(d){case "deleteCharacter":return c.deleteCharacter(b),!0;case "deleteWord":return c.deleteWord(b),!0;case "deleteLine":return c.deleteLine(b),!0;case "insertText":return"string"===typeof b?c.insertText(b):(d=b.dataTransfer,null!=d?M(d,c,a):(b=b.data)&&c.insertText(b)),!0;case "removeText":return c.removeText(),
|
|
25
|
+
!0;case "formatText":return c.formatText(b),!0;case "formatElement":return c=c.anchor.getNode(),(y.$isElementNode(c)?c:c.getParentOrThrow()).setFormat(b),!0;case "insertLineBreak":return c.insertLineBreak(b),!0;case "insertParagraph":return c.insertParagraph(),!0;case "indentContent":return c=c.anchor,c="element"===c.type?c.getNode():c.getNode().getParentOrThrow(),c.canInsertTab()?a.execCommand("insertText","\t"):10!==c.getIndent()&&c.setIndent(c.getIndent()+1),!0;case "outdentContent":return c=c.anchor,
|
|
26
|
+
b=c.getNode(),d="element"===c.type?c.getNode():c.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===b.getTextContent()[c.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=b.shiftKey;if(N(c,!0))return b.preventDefault(),b=d,d=I(c),c.modify(b?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=b.shiftKey;if(N(c,!1))return b.preventDefault(),b=d,d=I(c),c.modify(b?"extend":"move",d,"character"),!0;break;case "keyBackspace":return b.preventDefault(),
|
|
27
|
+
{anchor:b}=c,c.isCollapsed()&&0===b.offset&&0<("element"===b.type?b.getNode():b.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),b.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return b.preventDefault(),a.execCommand(b.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
|
|
28
|
+
!0;case "copy":return Q(b,a),!0;case "cut":return P(b,a),!0;case "paste":return O(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return e},[a]);S(a)}module.exports=function({contentEditable:a,placeholder:e}){var [d]=g.useLexicalComposerContext();const b=E(d);T(d);d=F(d);return u.createElement(u.Fragment,null,a,b&&e,d)};
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
var d=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/table"),g=require("lexical"),h=require("react");
|
|
8
|
-
module.exports=function(){const [f]=d.useLexicalComposerContext();h.useEffect(()=>{if(!f.hasNodes([e.TableNode,e.TableCellNode,e.TableRowNode]))throw Error("Minified Lexical error #54; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return f.addListener("command",(a,b)=>{if("insertTable"===a){const {columns:k,rows:l}=b;a=g.$getSelection();if(
|
|
8
|
+
module.exports=function(){const [f]=d.useLexicalComposerContext();h.useEffect(()=>{if(!f.hasNodes([e.TableNode,e.TableCellNode,e.TableRowNode]))throw Error("Minified Lexical error #54; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return f.addListener("command",(a,b)=>{if("insertTable"===a){const {columns:k,rows:l}=b;a=g.$getSelection();if(!g.$isRangeSelection(a))return!0;var c=a.focus;a=c.getNode();null!==a&&(b=e.$createTableNodeWithDimensions(l,
|
|
9
9
|
k),g.$isRootNode(a)?(c=a.getChildAtIndex(c.offset),null!==c?c.insertBefore(b):a.append(b)):a.getTopLevelElementOrThrow().insertAfter(b),b.insertAfter(g.$createParagraphNode()),b.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0}return!1},0)},[f]);return null};
|