@lexical/react 0.1.0 → 0.1.4
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.js +2 -0
- package/DEPRECATED_useLexicalAutoFormatter.js +12 -0
- package/DEPRECATED_useLexicalCanShowPlaceholder.js +3 -0
- package/{useLexicalCharacterLimit.js → DEPRECATED_useLexicalCharacterLimit.js} +0 -0
- package/DEPRECATED_useLexicalDecorators.js +2 -0
- package/DEPRECATED_useLexicalEditor.js +1 -0
- package/DEPRECATED_useLexicalEditorEvents.js +2 -0
- package/DEPRECATED_useLexicalHistory.js +7 -0
- package/{useLexicalList.js → DEPRECATED_useLexicalList.js} +2 -2
- package/DEPRECATED_useLexicalPlainText.js +17 -0
- package/DEPRECATED_useLexicalRichText.js +30 -0
- package/LexicalAutoFormatterPlugin.js +13 -1
- package/LexicalAutoLinkPlugin.js +5 -0
- package/LexicalCharacterLimitPlugin.js +10 -3
- package/LexicalCollaborationPlugin.js +8 -9
- package/LexicalComposer.js +2 -2
- package/LexicalContentEditable.js +3 -0
- package/LexicalHistoryPlugin.js +7 -1
- package/LexicalHorizontalRulePlugin.js +1 -0
- package/LexicalLinkPlugin.js +3 -0
- package/LexicalListPlugin.js +12 -0
- package/LexicalNestedComposer.js +1 -0
- package/LexicalOnChangePlugin.js +1 -0
- package/LexicalPlainTextPlugin.js +13 -29
- package/LexicalRichTextPlugin.js +26 -39
- package/LexicalTablePlugin.js +4 -0
- package/LexicalTreeView.js +11 -11
- package/README.md +76 -0
- package/package.json +4 -6
- package/useLexicalDecoratorMap.js +1 -0
- package/useLexicalIsTextContentEmpty.js +2 -2
- package/LexicalComposerContentEditable.js +0 -3
- package/useLexical.js +0 -2
- package/useLexicalAutoFormatter.js +0 -4
- package/useLexicalCanShowPlaceholder.js +0 -4
- package/useLexicalDecorators.js +0 -2
- package/useLexicalEditor.js +0 -2
- package/useLexicalEditorEvents.js +0 -3
- package/useLexicalHistory.js +0 -7
- package/useLexicalPlainText.js +0 -33
- package/useLexicalRichText.js +0 -43
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var b=require("lexical"),g=require("react"),h=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function l(a,c){const d=h(a),f=g.useCallback(e=>{a.setRootElement(e)},[a]);k(()=>a.addListener("error",c),[a,c]);return[f,d]}function m(a){throw a;}
|
|
2
|
+
module.exports=function(a){const c=void 0!==a&&a.onError||m,d=g.useMemo(()=>b.createEditor(a),[a]),[f,e]=l(d,c);return[d,f,e]};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';var l=require("lexical/CodeNode"),m=require("lexical/ListItemNode"),t=require("lexical"),u=require("react"),w=require("lexical/HeadingNode"),x=require("lexical/ListNode"),y=require("lexical/ParagraphNode"),z=require("lexical/QuoteNode");
|
|
2
|
+
const A={requiresParagraphStart:!1,nodeTransformationKind:null,regEx:/(?:)/,regExExpectedCaptureGroupCount:0},D={...A,requiresParagraphStart:!0},E=[{...A,nodeTransformationKind:"textBold",regEx:/(\*)(?:\s*\b)(?:[^\*]*)(?:\b\s*)(\*\s)$/,regExExpectedCaptureGroupCount:2}],F=[{...D,regEx:/(?:# )/,nodeTransformationKind:"paragraphH1"},{...D,regEx:/(?:## )/,nodeTransformationKind:"paragraphH2"},{...D,regEx:/(?:### )/,nodeTransformationKind:"paragraphH2"},{...D,regEx:/(?:> )/,nodeTransformationKind:"paragraphBlockQuote"},
|
|
3
|
+
{...D,regEx:/(?:- )/,nodeTransformationKind:"paragraphUnorderedList"},{...D,regEx:/(?:\* )/,nodeTransformationKind:"paragraphUnorderedList"},{...D,nodeTransformationKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/,regExExpectedCaptureGroupCount:1},{...D,regEx:/(?:``` )/,nodeTransformationKind:"paragraphCodeBlock"},...E];
|
|
4
|
+
function G(f,h,b){const a={regExCaptureGroups:[],text:"",textIndex:-1,triggerState:null};f=f.match(h);if(null!==f&&0===f.index&&f.length===b+1){a.textIndex=f.index;a.text=f[0];for(b=1;b<f.length;++b)a.regExCaptureGroups.push(f[b]);return a}return null}
|
|
5
|
+
function H(f,h){f.update(()=>{var b=t.$getSelection();if(null==b)b=null;else{var a=b.anchor.getNode();b=t.$isTextNode(a)?{node:a,offset:b.anchor.offset}:null}if(null!==b){b={textNodeWithOffset:b,trimmedParagraphText:null};a:{a=!1===h.isParentAListItemNode?F:E;var c=a.length;for(var e=0;e<c;++e){var d=a[e];if(!1===h.isCodeBlock||"paragraphCodeBlock"===d.nodeTransformationKind){var g=d,k=b;if(null!==g.requiresParagraphStart&&!0===g.requiresParagraphStart)b:{var n=k;k=n.textNodeWithOffset;if(null===
|
|
6
|
+
k.node.getPreviousSibling()&&(n=n.textNodeWithOffset.node.getTextContent(),g=G(n,g.regEx,g.regExExpectedCaptureGroupCount),null!=g&&0===g.textIndex&&g.textIndex+g.text.length===k.offset))break b;g=null}else{if(null==k.trimmedParagraphText){var p=k.textNodeWithOffset.node.getParentOrThrow();if(t.$isElementNode(p)){if(null==k.trimmedParagraphText){n=k;var I=k.textNodeWithOffset.node,B=k.textNodeWithOffset.offset;let r="";p=p.getChildren();const J=p.length;for(let v=0;v<J;++v){const q=p[v];if(t.$isTextNode(q)){const C=
|
|
7
|
+
q.getTextContent();if(q.is(I)){if(B>C.length)throw Error(`Node ${q.__key} and selection point do not match.`);r+=q.getTextContent().substr(0,B);break}else r+=C}else r+="\u0004"}n.trimmedParagraphText=r}G(k.trimmedParagraphText,g.regEx,g.regExExpectedCaptureGroupCount)}else throw Error(`Expected node ${p.__key} to to be a ElementNode.`);}g=null}if(null!=g){g.triggerState=h;a={autoFormatCriteria:d,matchResultContext:g};break a}}}a={autoFormatCriteria:null,matchResultContext:null}}c=a;if(null!==c.autoFormatCriteria&&
|
|
8
|
+
null!==c.matchResultContext&&(a=c.autoFormatCriteria,c=c.matchResultContext,a.requiresParagraphStart)){e=b.textNodeWithOffset;b=e.node.getParentOrThrow();e=e.node.spliceText(0,c.text.length,"",!0);""===e.getTextContent()&&(e.selectPrevious(),e.remove());e=b.getChildren();d=null;if(null!=a.nodeTransformationKind)switch(a.nodeTransformationKind){case "paragraphH1":d=w.$createHeadingNode("h1");d.append(...e);break;case "paragraphH2":d=w.$createHeadingNode("h2");d.append(...e);break;case "paragraphH3":d=
|
|
9
|
+
w.$createHeadingNode("h3");d.append(...e);break;case "paragraphBlockQuote":d=z.$createQuoteNode();d.append(...e);break;case "paragraphUnorderedList":d=x.$createListNode("ul");a=m.$createListItemNode();a.append(...e);d.append(a);break;case "paragraphOrderedList":a=parseInt(1===c.regExCaptureGroups.length?c.regExCaptureGroups[0]:"1",10);d=x.$createListNode("ol",a);a=m.$createListItemNode();a.append(...e);d.append(a);break;case "paragraphCodeBlock":d=null!=c.triggerState&&c.triggerState.isCodeBlock?
|
|
10
|
+
y.$createParagraphNode():l.$createCodeNode(),d.append(...e)}a=d;null!==a&&b.replace(a)}}})}
|
|
11
|
+
function K(f){let h=null;f.read(()=>{const b=t.$getSelection();if(null!=b&&b.isCollapsed()){var a=b.anchor.getNode(),c=a.getParent(),e=null!==c&&m.$isListItemNode(c);c=null!==c&&t.$isElementNode(c);h={anchorOffset:b.anchor.offset,isCodeBlock:l.$isCodeNode(a),isSelectionCollapsed:b.isCollapsed(),isSimpleText:t.$isTextNode(a)&&a.isSimpleText(),isParentAnElementNode:c,isParentAListItemNode:e,nodeKey:a.getKey(),textContent:a.getTextContent()}}});return h}
|
|
12
|
+
function L(f){u.useEffect(()=>{let h=null;f.addListener("update",({tags:b})=>{if(!1===b.has("historic")){b=K(f.getEditorState());var a=b;var c=h;if(null==a||null==c)a=!1;else{var e=a.textContent.length,d=a.anchorOffset-1;a=!0===a.isParentAnElementNode&&a.isSimpleText&&a.isSelectionCollapsed&&a.nodeKey===c.nodeKey&&a.anchorOffset!==c.anchorOffset&&0<=d&&d+1<=e&&" "===a.textContent.substr(d,1)&&a.textContent!==c.textContent}a&&null!=b&&H(f,b);h=b}else h=null})},[f])}module.exports=function(f){L(f)};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';var e=require("react"),f=require("lexical"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;function l(a,d=!0){if(a)return!1;a=f.$getRoot().getTextContent();d&&(a=a.trim());return""===a}
|
|
2
|
+
function m(a){if(!l(a,!1))return!1;a=f.$getRoot().getChildren();const d=a.length;if(1<d)return!1;for(let c=0;c<d;c++){var b=a[c];if(f.$isElementNode(b)){if("paragraph"!==b.__type||0!==b.__indent)return!1;b=b.getChildren();const g=b.length;for(let h=0;h<g;h++)if(!f.$isTextNode(b[c]))return!1}}return!0}function n(a){return()=>m(a)}
|
|
3
|
+
function p(a){const [d,b]=e.useState(a.getEditorState().read(n(a.isComposing())));k(()=>a.addListener("update",({editorState:c})=>{const g=a.isComposing();c=c.read(n(g));b(c)}),[a]);return d}module.exports=function(a){return p(a)};
|
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var c=require("react-dom"),g=require("react"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;
|
|
2
|
+
function l(a){const [e,m]=g.useState(()=>a.getDecorators());k(()=>a.addListener("decorator",d=>{c.flushSync(()=>{m(d)})}),[a]);return g.useMemo(()=>{const d=[],h=Object.keys(e);for(let f=0;f<h.length;f++){var b=h[f];const n=e[b];b=a.getElementByKey(b);null!==b&&d.push(c.createPortal(n,b))}return d},[e,a])}module.exports=function(a){return l(a)};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var b=require("react"),d=require("@lexical/react/DEPRECATED_useLexicalCanShowPlaceholder"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?b.useLayoutEffect:b.useEffect;module.exports=function(a,c){const f=d(a),h=b.useCallback(g=>{a.setRootElement(g)},[a]);e(()=>a.addListener("error",c),[a,c]);return[h,f]};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function p(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
|
|
2
|
+
function q(a,b){h(()=>{const k=[],l=[];for(let d=0;d<a.length;d++){const [c,e]=a[d],n=f=>{const m=b.getRootElement();null!==m&&"true"===m.contentEditable&&e(f,b)};k.push(f=>{p(c,f).addEventListener(c,n)});l.push(f=>{p(c,f).removeEventListener(c,n)})}return b.addListener("root",(d,c)=>{null!==c&&l.forEach(e=>e(c));null!==d&&k.forEach(e=>e(d))})},[b,a])}module.exports=function(a,b){q(a,b)};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';var n=require("lexical"),r=require("react"),v=require("@lexical/react/withSubscriptions");function w(a,b,e){b=Array.from(b);e=Array.from(e);a=a._nodeMap;const c=[];for(var h=0;h<b.length;h++){const f=a.get(b[h]);void 0!==f&&c.push(f)}for(b=0;b<e.length;b++)e[b][1]&&(h=a.get(e[b][0]),void 0===h||n.$isRootNode(h)||c.push(h));return c}
|
|
2
|
+
function x(a,b,e,c,h){if(null===a||0===e.size&&0===c.size)return 0;var f=b._selection,d=a._selection;if(h)return 1;if(null===f||null===d||!d.isCollapsed()||!f.isCollapsed())return 0;e=w(b,e,c);if(0===e.length)return 0;if(1<e.length){b=b._nodeMap;d=b.get(d.anchor.key);const g=b.get(f.anchor.key);return n.$isTextNode(g)&&n.$isElementNode(d)&&!a._nodeMap.has(g.__key)&&1===g.__text.length&&1===f.anchor.offset?e.every(k=>k===g||!n.$isTextNode(k))?2:0:0}b=e[0];a=a._nodeMap.get(b.__key);if(!n.$isTextNode(a)||
|
|
3
|
+
!n.$isTextNode(b)||a.__mode!==b.__mode)return 0;a=a.__text;b=b.__text;if(a===b)return 0;f=f.anchor;d=d.anchor;if(f.key!==d.key||"text"!==f.type)return 0;f=f.offset;d=d.offset;a=b.length-a.length;return 1===a&&d===f-1?2:-1===a&&d===f+1?3:-1===a&&d===f?4:0}
|
|
4
|
+
function y(a,b){let e=Date.now(),c=0;return(h,f,d,g,k,m)=>{const p=Date.now();if(m.has("historic"))return c=0,e=p,2;const l=x(h,f,g,k,a.isComposing()),u=(()=>{if(m.has("without-history"))return 0;if(null===h)return 1;var q=f._selection;const t=h._selection;if(!(0<g.size||0<k.size))return null===t&&null!==q?0:2;q=null===d||d.editor===a;return 0!==l&&l===c&&p<e+b&&q?0:1})();e=p;c=l;return u}}
|
|
5
|
+
function z(a,b,e=1E3){const c=r.useMemo(()=>b||A(),[b]),h=r.useCallback(()=>{c.undoStack=[];c.redoStack=[];c.current=null},[c]);r.useEffect(()=>{const f=y(a,e);return v(a.addListener("command",d=>{switch(d){case "undo":d=c.redoStack;var g=c.undoStack;if(0!==g.length){var k=c.current;const m=g.pop();null!==k&&(d.push(k),a.execCommand("canRedo",!0));0===g.length&&a.execCommand("canUndo",!1);c.current=m;m.editor.setEditorState(m.editorState.clone(m.undoSelection),{tag:"historic"})}return!0;case "redo":return d=
|
|
6
|
+
c.redoStack,g=c.undoStack,0!==d.length&&(k=c.current,null!==k&&(g.push(k),a.execCommand("canUndo",!0)),g=d.pop(),0===d.length&&a.execCommand("canRedo",!1),c.current=g,g.editor.setEditorState(g.editorState,{tag:"historic"})),!0;case "clearEditor":return h(),!1;case "clearHistory":return h(),!0;default:return!1}},0),a.addListener("update",({editorState:d,prevEditorState:g,dirtyLeaves:k,dirtyElements:m,tags:p})=>{const l=c.current,u=c.redoStack,q=c.undoStack,t=null===l?null:l.editorState;if(null===l||
|
|
7
|
+
d!==t){k=f(g,d,l,k,m,p);if(1===k)0!==u.length&&(c.redoStack=[]),null!==l&&(q.push({...l,undoSelection:g.read(n.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;c.current={editor:a,editorState:d}}}))},[h,e,a,c])}function A(){return{current:null,redoStack:[],undoStack:[]}}exports.createEmptyHistoryState=A;exports.useLexicalHistory=function(a,b,e=1E3){return z(a,b,e)};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';var g=require("react"),l=require("lexical"),m=require("lexical/ListItemNode"),p=require("lexical/ListNode"),q=require("lexical/ParagraphNode");function r(d){d=d.getParent();if(!p.$isListNode(d))throw Error("Minified Lexical error #2; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let a=d;for(;null!==a;)a=a.getParent(),p.$isListNode(a)&&(d=a);return d}
|
|
2
2
|
function t(d){let a=[];d=d.getChildren().filter(m.$isListItemNode);for(let b=0;b<d.length;b++){const c=d[b],e=c.getFirstChild();p.$isListNode(e)?a=a.concat(t(e)):a.push(c)}return a}function u(d,a){for(;null!=d&&!(d instanceof a);)d=d.getParent();return d}
|
|
3
3
|
function v(d){d.update(()=>{l.$log("removeList");var a=l.$getSelection();if(null!==a){const c=new Set,e=a.getNodes();a=a.anchor.getNode();if(0===e.length&&m.$isListItemNode(a))c.add(r(a));else for(a=0;a<e.length;a++){var b=e[a];l.$isLeafNode(b)&&(b=u(b,m.ListItemNode),null!=b&&c.add(r(b)))}c.forEach(f=>{let h=f;t(f).forEach(k=>{if(null!=k){const n=q.$createParagraphNode();n.append(...k.getChildren());h.insertAfter(n);h=n;k.remove()}});f.remove()})}})}
|
|
4
|
-
function w(d,a){if(p.$isListNode(d))return d;const b=d.getPreviousSibling(),c=d.getNextSibling(),e=m.$createListItemNode();if(p.$isListNode(b))return e.append(d),b.append(e),p.$isListNode(c)&&(b.append(...c.getChildren()),c.remove()),b;if(p.$isListNode(c))return e.append(d),c.getFirstChildOrThrow().insertBefore(e),c;a=p.$createListNode(a);a.append(e);d.replace(a);e.append(d);return a}
|
|
4
|
+
function w(d,a){if(p.$isListNode(d))return d;const b=d.getPreviousSibling(),c=d.getNextSibling(),e=m.$createListItemNode();if(p.$isListNode(b)&&a===b.getTag())return e.append(d),b.append(e),p.$isListNode(c)&&a===c.getTag()&&(b.append(...c.getChildren()),c.remove()),b;if(p.$isListNode(c)&&a===c.getTag())return e.append(d),c.getFirstChildOrThrow().insertBefore(e),c;a=p.$createListNode(a);a.append(e);d.replace(a);e.append(d);return a}
|
|
5
5
|
function x(d,a){d.update(()=>{l.$log("formatList");var b=l.$getSelection();if(null!==b){var c=b.getNodes();b=b.anchor.getNode();var e=b.getParent();if(0===c.length)c=p.$createListNode(a),l.$isRootNode(e)?(b.replace(c),b=m.$createListItemNode(),c.append(b)):m.$isListItemNode(b)&&(b=b.getParentOrThrow(),c.append(...b.getChildren()),b.replace(c));else for(b=new Set,e=0;e<c.length;e++){var f=c[e];if(l.$isElementNode(f)&&f.isEmpty()&&!b.has(f.getKey()))w(f,a);else if(l.$isLeafNode(f))for(f=f.getParent();null!=
|
|
6
6
|
f;){const k=f.getKey();if(p.$isListNode(f)){if(!b.has(k)){var h=p.$createListNode(a);h.append(...f.getChildren());f.replace(h);b.add(k)}break}else{h=f.getParent();if(l.$isRootNode(h)&&!b.has(k)){b.add(k);w(f,a);break}f=h}}}}})}
|
|
7
7
|
function y(d){var a=l.$getSelection();if(null===a)return!1;var b=a.getNodes(),c=[];0===b.length&&b.push(a.anchor.getNode());if(1===b.length){a:{for(b=b[0];null!==b;){if(m.$isListItemNode(b))break a;b=b.getParent()}b=null}null!==b&&(c=[b])}else{c=new Set;for(a=0;a<b.length;a++){const e=b[a];m.$isListItemNode(e)&&c.add(e)}c=Array.from(c)}return 0<c.length?("indent"===d?z(c):A(c),!0):!1}function B(d){return m.$isListItemNode(d)&&p.$isListNode(d.getFirstChild())}
|
|
@@ -9,4 +9,4 @@ function z(d){d.forEach(a=>{if(!B(a)){var b=a.getParent(),c=a.getNextSibling(),e
|
|
|
9
9
|
c.getChildren().forEach(f=>f.markDirty()));else if(p.$isListNode(b)){const f=m.$createListItemNode(),h=p.$createListNode(b.getTag());f.append(h);h.append(a);e?e.insertAfter(f):c?c.insertBefore(f):b.append(f)}p.$isListNode(b)&&b.getChildren().forEach(f=>f.markDirty())}})}
|
|
10
10
|
function A(d){d.forEach(a=>{if(!B(a)){var b=a.getParent(),c=b?b.getParent():void 0,e=c?c.getParent():void 0;if(p.$isListNode(e)&&m.$isListItemNode(c)&&p.$isListNode(b)){var f=b?b.getFirstChild():void 0,h=b?b.getLastChild():void 0;if(a.is(f))c.insertBefore(a),b.isEmpty()&&c.remove();else if(a.is(h))c.insertAfter(a),b.isEmpty()&&c.remove();else{var k=b.getTag();f=m.$createListItemNode();const n=p.$createListNode(k);f.append(n);a.getPreviousSiblings().forEach(C=>n.append(C));h=m.$createListItemNode();
|
|
11
11
|
k=p.$createListNode(k);h.append(k);k.append(...a.getNextSiblings());c.insertBefore(f);c.insertAfter(h);c.replace(a)}b.getChildren().forEach(n=>n.markDirty());e.getChildren().forEach(n=>n.markDirty())}}})}
|
|
12
|
-
|
|
12
|
+
function D(d){g.useEffect(()=>d.addListener("command",a=>{if("indentContent"===a){if(y("indent"))return!0}else if("outdentContent"===a){if(y("outdent"))return!0}else{if("insertOrderedList"===a)return x(d,"ol"),!0;if("insertUnorderedList"===a)return x(d,"ul"),!0;if("removeList"===a)return v(d),!0}return!1},1),[d])}module.exports=function(d){D(d)};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';var h=require("lexical"),u=require("lexical/ParagraphNode"),v=require("react"),w=require("@lexical/react/withSubscriptions");
|
|
2
|
+
function x(a){v.useEffect(()=>{const b=e=>{var d=a.getRootElement();if(document.activeElement===d&&(d=e.data,"string"===typeof d)){try{var c=JSON.parse(d)}catch(f){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [f,g,k,l,r]=c;a.update(()=>{h.$log("useLexicalDragonSupport");const t=h.$getSelection();if(null!==t){var m=t.anchor;let p=m.getNode(),n=0,q=0;h.$isTextNode(p)&&0<=f&&0<=g&&(n=f,q=f+g,t.setTextNodeRange(p,n,p,
|
|
3
|
+
q));if(n!==q||""!==k)t.insertRawText(k),p=m.getNode();h.$isTextNode(p)&&(n=l,q=l+r,m=p.getTextContentSize(),n=n>m?m:n,q=q>m?m:q,t.setTextNodeRange(p,n,p,q));e.stopImmediatePropagation()}})}}};window.addEventListener("message",b,!0);return()=>{window.removeEventListener("message",b,!0)}},[a])}function y(a,b){a=a.getData("text/plain");null!=a&&b.insertRawText(a)}
|
|
4
|
+
function z(a,b){var e=a.focus;a=e.offset;"element"===e.type?b=e.getNode().getChildAtIndex(b?a-1:a):(e=e.getNode(),b=b&&0===a||!b&&a===e.getTextContentSize()?b?e.getPreviousSibling():e.getNextSibling():null);return h.$isDecoratorNode(b)}function A(a,b){a.preventDefault();b.update(()=>{h.$log("onPasteForPlainText");const e=h.$getSelection(),d=a.clipboardData;null!=d&&null!==e&&y(d,e)})}
|
|
5
|
+
function B(a,b){C(a,b);b.update(()=>{h.$log("onCutForPlainText");const e=h.$getSelection();null!==e&&e.removeText()})}function C(a,b){a.preventDefault();b.update(()=>{h.$log("onCopyForPlainText");const e=a.clipboardData,d=h.$getSelection();if(null!==d&&null!=e){var c=window.getSelection();if(!c.isCollapsed){var f=c.getRangeAt(0);f&&(c=document.createElement("div"),f=f.cloneContents(),c.appendChild(f),e.setData("text/html",c.innerHTML));e.setData("text/plain",d.getTextContent())}}})}
|
|
6
|
+
var D="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;function E(a,b){const e=u.$createParagraphNode();a.append(e);a=document.activeElement;(null!==h.$getSelection()||null!==a&&a===b.getRootElement())&&e.select()}function F(a){a.update(()=>{h.$log("initEditor");const b=h.$getRoot();null===b.getFirstChild()&&E(b,a)})}
|
|
7
|
+
function G(a,b){a.update(()=>{h.$log("clearEditor");const e=h.$getRoot();e.clear();E(e,a)},{onUpdate:b})}
|
|
8
|
+
function H(a,b){D(()=>{const e=w(a.registerNodes([u.ParagraphNode]),a.addListener("command",(d,c)=>{const f=h.$getSelection();if(null===f)return!1;switch(d){case "deleteCharacter":return f.deleteCharacter(c),!0;case "deleteWord":return f.deleteWord(c),!0;case "deleteLine":return f.deleteLine(c),!0;case "insertText":return"string"===typeof c?f.insertText(c):(d=c.dataTransfer,null!=d?y(d,f):(c=c.data)&&f.insertText(c)),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(c),
|
|
9
|
+
!0;case "insertParagraph":return f.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":d=c.shiftKey;if(z(f,!0))return c.preventDefault(),c=d,d="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(c?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=c.shiftKey;if(z(f,!1))return c.preventDefault(),c=d,d="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),
|
|
10
|
+
f.modify(c?"extend":"move",d,"character"),!0;break;case "keyBackspace":return c.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "clearEditor":G(a);break;case "copy":return C(c,a),!0;case "cut":return B(c,a),!0;case "paste":return A(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0));b&&F(a);return e},[a,b]);
|
|
11
|
+
x(a)}function I(a,b,e){b=Array.from(b);e=Array.from(e);a=a._nodeMap;const d=[];for(var c=0;c<b.length;c++){const f=a.get(b[c]);void 0!==f&&d.push(f)}for(b=0;b<e.length;b++)e[b][1]&&(c=a.get(e[b][0]),void 0===c||h.$isRootNode(c)||d.push(c));return d}
|
|
12
|
+
function J(a,b,e,d,c){if(null===a||0===e.size&&0===d.size)return 0;var f=b._selection,g=a._selection;if(c)return 1;if(null===f||null===g||!g.isCollapsed()||!f.isCollapsed())return 0;e=I(b,e,d);if(0===e.length)return 0;if(1<e.length){b=b._nodeMap;g=b.get(g.anchor.key);const k=b.get(f.anchor.key);return h.$isTextNode(k)&&h.$isElementNode(g)&&!a._nodeMap.has(k.__key)&&1===k.__text.length&&1===f.anchor.offset?e.every(l=>l===k||!h.$isTextNode(l))?2:0:0}b=e[0];a=a._nodeMap.get(b.__key);if(!h.$isTextNode(a)||
|
|
13
|
+
!h.$isTextNode(b)||a.__mode!==b.__mode)return 0;a=a.__text;b=b.__text;if(a===b)return 0;f=f.anchor;g=g.anchor;if(f.key!==g.key||"text"!==f.type)return 0;f=f.offset;g=g.offset;a=b.length-a.length;return 1===a&&g===f-1?2:-1===a&&g===f+1?3:-1===a&&g===f?4:0}
|
|
14
|
+
function K(a,b){let e=Date.now(),d=0;return(c,f,g,k,l,r)=>{const t=Date.now();if(r.has("historic"))return d=0,e=t,2;const m=J(c,f,k,l,a.isComposing()),p=(()=>{if(r.has("without-history"))return 0;if(null===c)return 1;var n=f._selection;const q=c._selection;if(!(0<k.size||0<l.size))return null===q&&null!==n?0:2;n=null===g||g.editor===a;return 0!==m&&m===d&&t<e+b&&n?0:1})();e=t;d=m;return p}}
|
|
15
|
+
function L(a,b,e=1E3){const d=v.useMemo(()=>b||{current:null,redoStack:[],undoStack:[]},[b]),c=v.useCallback(()=>{d.undoStack=[];d.redoStack=[];d.current=null},[d]);v.useEffect(()=>{const f=K(a,e);return w(a.addListener("command",g=>{switch(g){case "undo":g=d.redoStack;var k=d.undoStack;if(0!==k.length){var l=d.current;const r=k.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===k.length&&a.execCommand("canUndo",!1);d.current=r;r.editor.setEditorState(r.editorState.clone(r.undoSelection),
|
|
16
|
+
{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:r,tags:t})=>{const m=d.current,p=d.redoStack,n=d.undoStack,
|
|
17
|
+
q=null===m?null:m.editorState;if(null===m||g!==q){l=f(k,g,m,l,r,t);if(1===l)0!==p.length&&(d.redoStack=[]),null!==m&&(n.push({...m,undoSelection:k.read(h.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;d.current={editor:a,editorState:g}}}))},[c,e,a,d])}function M(a,b,e=1E3){return L(a,b,e)}module.exports=function(a,b){H(a,!0);M(a,b)};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';var k=require("lexical"),w=require("lexical/HeadingNode"),x=require("lexical/ListNode"),z=require("lexical/QuoteNode"),A=require("lexical/CodeNode"),B=require("lexical/ParagraphNode"),C=require("lexical/ListItemNode"),D=require("react"),E=require("lexical/LinkNode"),F=require("@lexical/react/withSubscriptions");
|
|
2
|
+
function G(a){D.useEffect(()=>{const c=e=>{var d=a.getRootElement();if(document.activeElement===d&&(d=e.data,"string"===typeof d)){try{var f=JSON.parse(d)}catch(b){return}if(f&&"nuanria_messaging"===f.protocol&&"request"===f.type&&(f=f.payload)&&"makeChanges"===f.functionId&&(f=f.args)){const [b,g,h,l,p]=f;a.update(()=>{k.$log("useLexicalDragonSupport");const n=k.$getSelection();if(null!==n){var m=n.anchor;let r=m.getNode(),q=0,t=0;k.$isTextNode(r)&&0<=b&&0<=g&&(q=b,t=b+g,n.setTextNodeRange(r,q,r,
|
|
3
|
+
t));if(q!==t||""!==h)n.insertRawText(h),r=m.getNode();k.$isTextNode(r)&&(q=l,t=l+p,m=r.getTextContentSize(),q=q>m?m:q,t=t>m?m:t,n.setTextNodeRange(r,q,r,t));e.stopImmediatePropagation()}})}}};window.addEventListener("message",c,!0);return()=>{window.removeEventListener("message",c,!0)}},[a])}
|
|
4
|
+
function H(a){a=a.getLatest();const c=a.constructor.clone(a);c.__parent=a.__parent;k.$isElementNode(a)&&k.$isElementNode(c)?(c.__children=Array.from(a.__children),c.__format=a.__format,c.__indent=a.__indent,c.__dir=a.__dir):k.$isTextNode(a)&&k.$isTextNode(c)?(c.__format=a.__format,c.__style=a.__style,c.__mode=a.__mode,c.__detail=a.__detail):k.$isDecoratorNode(a)&&k.$isDecoratorNode(c)&&(c.__state=a.__state);return c}
|
|
5
|
+
function I(a,c,e,d,f){for(var b=c;null!==a;){for(c=a.getParent();null!==c&&c.excludeFromCopy();)c=c.getParent();if(null===c)break;if(!k.$isElementNode(a)||!a.excludeFromCopy()){const g=a.getKey();let h=f.get(g);const l=void 0===h;l&&(h=H(a),f.set(g,h));!k.$isTextNode(h)||h.isSegmented()||h.isToken()?k.$isElementNode(h)&&(h.__children=h.__children.slice(e?b:0,e?void 0:b+1)):h.__text=h.__text.slice(e?b:0,e?void 0:b);if(k.$isRootNode(c)){l&&d.push(g);break}}b=f.get(c.getKey());b=k.$isElementNode(b)?
|
|
6
|
+
b.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=c}}
|
|
7
|
+
const J={ul:()=>({node:x.$createListNode("ul")}),ol:()=>({node:x.$createListNode("ol")}),li:()=>({node:C.$createListItemNode()}),h1:()=>({node:w.$createHeadingNode("h1")}),h2:()=>({node:w.$createHeadingNode("h2")}),h3:()=>({node:w.$createHeadingNode("h3")}),h4:()=>({node:w.$createHeadingNode("h4")}),h5:()=>({node:w.$createHeadingNode("h5")}),p:()=>({node:B.$createParagraphNode()}),br:()=>({node:k.$createLineBreakNode()}),a:a=>({node:a instanceof HTMLAnchorElement?E.$createLinkNode(a.href):k.$createTextNode(a.textContent)}),
|
|
8
|
+
u:()=>({node:null,forChild:a=>{k.$isTextNode(a)&&a.toggleFormat("underline")}}),b:a=>{const c="normal"===a.style.fontWeight;return{node:null,forChild:e=>{k.$isTextNode(e)&&!c&&e.toggleFormat("bold")}}},strong:()=>({node:null,forChild:a=>{k.$isTextNode(a)&&a.toggleFormat("bold")}}),i:()=>({node:null,forChild:a=>{k.$isTextNode(a)&&a.toggleFormat("italic")}}),em:()=>({node:null,forChild:a=>{k.$isTextNode(a)&&a.toggleFormat("italic")}}),td:a=>{const c=a.classList.contains("js-file-line");return{node:null,
|
|
9
|
+
after:e=>{c&&a.parentNode&&a.parentNode.nextSibling&&e.push(k.$createLineBreakNode());return e}}},table:a=>({node:a.classList.contains("js-file-line-container")?A.$createCodeNode():null}),span:a=>{const c="700"===a.style.fontWeight;return{node:null,forChild:e=>{k.$isTextNode(e)&&c&&e.toggleFormat("bold")}}},"#text":a=>({node:k.$createTextNode(a.textContent)}),pre:()=>({node:A.$createCodeNode()}),div:a=>({node:null!==a.style.fontFamily.match("monospace")?A.$createCodeNode():null,after:c=>{const e=
|
|
10
|
+
a.parentNode;null!=e&&a!==e.lastChild&&c.push(k.$createLineBreakNode());return c}})};
|
|
11
|
+
function K(a,c,e,d=new Map){let f=[],b=null;var g=a.nodeName.toLowerCase(),h=(e._config.htmlTransforms||{})[g]||c[g],l=h?h(a):null;h=null;if(null!==l){h=l.after;b=l.node;if(null!==b){f.push(b);const p=Array.from(d.values());for(let n=0;n<p.length;n++)p[n](b)}null!=l.forChild&&d.set(g,l.forChild)}a=a.childNodes;g=[];for(l=0;l<a.length;l++)g.push(...K(a[l],c,e,d));null!=h&&(g=h(g));null==b?f=f.concat(g):k.$isElementNode(b)&&b.append(...g);return f}
|
|
12
|
+
function L(a,c,e){var d=a.getData("application/x-lexical-editor");if(d){var f=e._config.namespace;try{const l=JSON.parse(d);if(l.namespace===f){const {range:p,nodeMap:n}=l.state;var b=new Map(n);d=[];for(f=0;f<p.length;f++){var g=b.get(p[f]);if(void 0!==g){var h=k.$createNodeFromParse(g,b);d.push(h)}}c.insertNodes(d);return}}catch(l){}}if(b=a.getData("text/html")){b=(new DOMParser).parseFromString(b,"text/html");a=[];b=b.body?Array.from(b.body.childNodes):[];g=b.length;for(h=0;h<g;h++)d=K(b[h],J,
|
|
13
|
+
e),null!==d&&(a=a.concat(d));e=a;a=[];b=null;for(g=0;g<e.length;g++)h=e[g],!k.$isElementNode(h)||h.isInline()?(null===b&&(b=B.$createParagraphNode(),a.push(b)),null!==b&&b.append(h)):(a.push(h),b=null);c.insertNodes(a)}else e=a.getData("text/plain"),null!=e&&c.insertRawText(e)}
|
|
14
|
+
function M(a,c){var e=a.focus;a=e.offset;"element"===e.type?c=e.getNode().getChildAtIndex(c?a-1:a):(e=e.getNode(),c=c&&0===a||!c&&a===e.getTextContentSize()?c?e.getPreviousSibling():e.getNextSibling():null);return k.$isDecoratorNode(c)}function N(a,c){a.preventDefault();c.update(()=>{k.$log("onPasteForRichText");const e=k.$getSelection(),d=a.clipboardData;null!=d&&null!==e&&L(d,e,c)})}
|
|
15
|
+
function O(a,c){P(a,c);c.update(()=>{k.$log("onCutForRichText");const e=k.$getSelection();null!==e&&e.removeText()})}
|
|
16
|
+
function P(a,c){a.preventDefault();c.update(()=>{k.$log("onCopyForRichText");const e=a.clipboardData;var d=k.$getSelection();if(null!==d&&null!=e){var f=window.getSelection();if(!f.isCollapsed){var b=f.getRangeAt(0);b&&(f=document.createElement("div"),b=b.cloneContents(),f.appendChild(b),e.setData("text/html",f.innerHTML));e.setData("text/plain",d.getTextContent());f=c._config.namespace;b=e.setData;var g=JSON,h=g.stringify;{var l=d.anchor,p=d.focus;var n=l.getCharacterOffset();const y=p.getCharacterOffset();
|
|
17
|
+
var m=l.getNode(),r=p.getNode(),q=m.getParentOrThrow();if(m===r&&k.$isTextNode(m)&&(q.canBeEmpty()||1<q.getChildrenSize()))d=H(m),m=y>n,d.__text=d.__text.slice(m?n:y,m?y:n),n=d.getKey(),n={range:[n],nodeMap:[[n,d]]};else if(d=d.getNodes(),0===d.length)n={range:[],nodeMap:[]};else{m=d.length;r=d[0];q=r.getParent();if(null!==q&&!q.canBeEmpty()){var t=q.__children;if(t.length===m){var u=!0;for(var v=0;v<t.length;v++)if(t[v]!==d[v].__key){u=!1;break}u&&(m++,d.push(q))}}q=d[m-1];l=l.isBefore(p);p=new Map;
|
|
18
|
+
t=[];I(r,l?n:y,!0,t,p);for(r=0;r<m;r++)if(u=d[r],v=u.getKey(),!(p.has(v)||k.$isElementNode(u)&&u.excludeFromCopy())){const R=H(u);k.$isRootNode(u.getParent())&&t.push(u.getKey());p.set(v,R)}I(q,l?y:n,!1,t,p);n={range:t,nodeMap:Array.from(p.entries())}}}b.call(e,"application/x-lexical-editor",h.call(g,{namespace:f,state:n}))}}})}var Q="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?D.useLayoutEffect:D.useEffect;
|
|
19
|
+
function S(a,c){const e=B.$createParagraphNode();a.append(e);a=document.activeElement;(null!==k.$getSelection()||null!==a&&a===c.getRootElement())&&e.select()}function T(a){a.update(()=>{k.$log("initEditor");const c=k.$getRoot();null===c.getFirstChild()&&S(c,a)})}function U(a,c){a.update(()=>{k.$log("clearEditor");const e=k.$getRoot();e.clear();S(e,a)},{onUpdate:c})}
|
|
20
|
+
function V(a,c){Q(()=>{const e=F(a.registerNodes([w.HeadingNode,x.ListNode,z.QuoteNode,A.CodeNode,B.ParagraphNode,C.ListItemNode]),a.addListener("command",(d,f)=>{var b=k.$getSelection();if(null===b)return!1;switch(d){case "deleteCharacter":return b.deleteCharacter(f),!0;case "deleteWord":return b.deleteWord(f),!0;case "deleteLine":return b.deleteLine(f),!0;case "insertText":return"string"===typeof f?b.insertText(f):(d=f.dataTransfer,null!=d?L(d,b,a):(f=f.data)&&b.insertText(f)),!0;case "removeText":return b.removeText(),
|
|
21
|
+
!0;case "formatText":return b.formatText(f),!0;case "formatElement":return b=b.anchor.getNode(),(k.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(f),!0;case "insertLineBreak":return b.insertLineBreak(f),!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,
|
|
22
|
+
f=b.getNode(),d="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===f.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=f.shiftKey;if(M(b,!0))return f.preventDefault(),f=d,d="rtl"===b.anchor.getNode().getParentOrThrow().getDirection(),b.modify(f?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=f.shiftKey;if(M(b,!1))return f.preventDefault(),f=d,d="rtl"===b.anchor.getNode().getParentOrThrow().getDirection(),
|
|
23
|
+
b.modify(f?"extend":"move",d,"character"),!0;break;case "keyBackspace":return f.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return f.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return f.preventDefault(),f.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return f.preventDefault(),a.execCommand(f.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),!0;case "clearEditor":U(a);break;case "copy":return P(f,
|
|
24
|
+
a),!0;case "cut":return O(f,a),!0;case "paste":return N(f,a),!0;case "drop":case "dragstart":return f.preventDefault(),!0}return!1},0));c&&T(a);return e},[a,c]);G(a)}function W(a,c,e){c=Array.from(c);e=Array.from(e);a=a._nodeMap;const d=[];for(var f=0;f<c.length;f++){const b=a.get(c[f]);void 0!==b&&d.push(b)}for(c=0;c<e.length;c++)e[c][1]&&(f=a.get(e[c][0]),void 0===f||k.$isRootNode(f)||d.push(f));return d}
|
|
25
|
+
function X(a,c,e,d,f){if(null===a||0===e.size&&0===d.size)return 0;var b=c._selection,g=a._selection;if(f)return 1;if(null===b||null===g||!g.isCollapsed()||!b.isCollapsed())return 0;e=W(c,e,d);if(0===e.length)return 0;if(1<e.length){c=c._nodeMap;g=c.get(g.anchor.key);const h=c.get(b.anchor.key);return k.$isTextNode(h)&&k.$isElementNode(g)&&!a._nodeMap.has(h.__key)&&1===h.__text.length&&1===b.anchor.offset?e.every(l=>l===h||!k.$isTextNode(l))?2:0:0}c=e[0];a=a._nodeMap.get(c.__key);if(!k.$isTextNode(a)||
|
|
26
|
+
!k.$isTextNode(c)||a.__mode!==c.__mode)return 0;a=a.__text;c=c.__text;if(a===c)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=c.length-a.length;return 1===a&&g===b-1?2:-1===a&&g===b+1?3:-1===a&&g===b?4:0}
|
|
27
|
+
function Y(a,c){let e=Date.now(),d=0;return(f,b,g,h,l,p)=>{const n=Date.now();if(p.has("historic"))return d=0,e=n,2;const m=X(f,b,h,l,a.isComposing()),r=(()=>{if(p.has("without-history"))return 0;if(null===f)return 1;var q=b._selection;const t=f._selection;if(!(0<h.size||0<l.size))return null===t&&null!==q?0:2;q=null===g||g.editor===a;return 0!==m&&m===d&&n<e+c&&q?0:1})();e=n;d=m;return r}}
|
|
28
|
+
function Z(a,c,e=1E3){const d=D.useMemo(()=>c||{current:null,redoStack:[],undoStack:[]},[c]),f=D.useCallback(()=>{d.undoStack=[];d.redoStack=[];d.current=null},[d]);D.useEffect(()=>{const b=Y(a,e);return F(a.addListener("command",g=>{switch(g){case "undo":g=d.redoStack;var h=d.undoStack;if(0!==h.length){var l=d.current;const p=h.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);d.current=p;p.editor.setEditorState(p.editorState.clone(p.undoSelection),
|
|
29
|
+
{tag:"historic"})}return!0;case "redo":return g=d.redoStack,h=d.undoStack,0!==g.length&&(l=d.current,null!==l&&(h.push(l),a.execCommand("canUndo",!0)),h=g.pop(),0===g.length&&a.execCommand("canRedo",!1),d.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return f(),!1;case "clearHistory":return f(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:h,dirtyLeaves:l,dirtyElements:p,tags:n})=>{const m=d.current,r=d.redoStack,q=d.undoStack,
|
|
30
|
+
t=null===m?null:m.editorState;if(null===m||g!==t){l=b(h,g,m,l,p,n);if(1===l)0!==r.length&&(d.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(k.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;d.current={editor:a,editorState:g}}}))},[f,e,a,d])}function aa(a,c,e=1E3){return Z(a,c,e)}module.exports=function(a,c){V(a,!0);aa(a,c)};
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var l=require("@lexical/react/LexicalComposerContext"),m=require("lexical/CodeNode"),t=require("lexical/ListItemNode"),u=require("lexical"),w=require("react"),x=require("lexical/HeadingNode"),y=require("lexical/ListNode"),z=require("lexical/ParagraphNode"),A=require("lexical/QuoteNode");
|
|
2
|
+
const D={requiresParagraphStart:!1,nodeTransformationKind:null,regEx:/(?:)/,regExExpectedCaptureGroupCount:0},E={...D,requiresParagraphStart:!0},F=[{...D,nodeTransformationKind:"textBold",regEx:/(\*)(?:\s*\b)(?:[^\*]*)(?:\b\s*)(\*\s)$/,regExExpectedCaptureGroupCount:2}],G=[{...E,regEx:/(?:# )/,nodeTransformationKind:"paragraphH1"},{...E,regEx:/(?:## )/,nodeTransformationKind:"paragraphH2"},{...E,regEx:/(?:### )/,nodeTransformationKind:"paragraphH2"},{...E,regEx:/(?:> )/,nodeTransformationKind:"paragraphBlockQuote"},
|
|
3
|
+
{...E,regEx:/(?:- )/,nodeTransformationKind:"paragraphUnorderedList"},{...E,regEx:/(?:\* )/,nodeTransformationKind:"paragraphUnorderedList"},{...E,nodeTransformationKind:"paragraphOrderedList",regEx:/^(\d+)\.\s/,regExExpectedCaptureGroupCount:1},{...E,regEx:/(?:``` )/,nodeTransformationKind:"paragraphCodeBlock"},...F];
|
|
4
|
+
function H(f,h,b){const a={regExCaptureGroups:[],text:"",textIndex:-1,triggerState:null};f=f.match(h);if(null!==f&&0===f.index&&f.length===b+1){a.textIndex=f.index;a.text=f[0];for(b=1;b<f.length;++b)a.regExCaptureGroups.push(f[b]);return a}return null}
|
|
5
|
+
function I(f,h){f.update(()=>{var b=u.$getSelection();if(null==b)b=null;else{var a=b.anchor.getNode();b=u.$isTextNode(a)?{node:a,offset:b.anchor.offset}:null}if(null!==b){b={textNodeWithOffset:b,trimmedParagraphText:null};a:{a=!1===h.isParentAListItemNode?G:F;var c=a.length;for(var e=0;e<c;++e){var d=a[e];if(!1===h.isCodeBlock||"paragraphCodeBlock"===d.nodeTransformationKind){var g=d,k=b;if(null!==g.requiresParagraphStart&&!0===g.requiresParagraphStart)b:{var n=k;k=n.textNodeWithOffset;if(null===
|
|
6
|
+
k.node.getPreviousSibling()&&(n=n.textNodeWithOffset.node.getTextContent(),g=H(n,g.regEx,g.regExExpectedCaptureGroupCount),null!=g&&0===g.textIndex&&g.textIndex+g.text.length===k.offset))break b;g=null}else{if(null==k.trimmedParagraphText){var p=k.textNodeWithOffset.node.getParentOrThrow();if(u.$isElementNode(p)){if(null==k.trimmedParagraphText){n=k;var J=k.textNodeWithOffset.node,B=k.textNodeWithOffset.offset;let r="";p=p.getChildren();const K=p.length;for(let v=0;v<K;++v){const q=p[v];if(u.$isTextNode(q)){const C=
|
|
7
|
+
q.getTextContent();if(q.is(J)){if(B>C.length)throw Error(`Node ${q.__key} and selection point do not match.`);r+=q.getTextContent().substr(0,B);break}else r+=C}else r+="\u0004"}n.trimmedParagraphText=r}H(k.trimmedParagraphText,g.regEx,g.regExExpectedCaptureGroupCount)}else throw Error(`Expected node ${p.__key} to to be a ElementNode.`);}g=null}if(null!=g){g.triggerState=h;a={autoFormatCriteria:d,matchResultContext:g};break a}}}a={autoFormatCriteria:null,matchResultContext:null}}c=a;if(null!==c.autoFormatCriteria&&
|
|
8
|
+
null!==c.matchResultContext&&(a=c.autoFormatCriteria,c=c.matchResultContext,a.requiresParagraphStart)){e=b.textNodeWithOffset;b=e.node.getParentOrThrow();e=e.node.spliceText(0,c.text.length,"",!0);""===e.getTextContent()&&(e.selectPrevious(),e.remove());e=b.getChildren();d=null;if(null!=a.nodeTransformationKind)switch(a.nodeTransformationKind){case "paragraphH1":d=x.$createHeadingNode("h1");d.append(...e);break;case "paragraphH2":d=x.$createHeadingNode("h2");d.append(...e);break;case "paragraphH3":d=
|
|
9
|
+
x.$createHeadingNode("h3");d.append(...e);break;case "paragraphBlockQuote":d=A.$createQuoteNode();d.append(...e);break;case "paragraphUnorderedList":d=y.$createListNode("ul");a=t.$createListItemNode();a.append(...e);d.append(a);break;case "paragraphOrderedList":a=parseInt(1===c.regExCaptureGroups.length?c.regExCaptureGroups[0]:"1",10);d=y.$createListNode("ol",a);a=t.$createListItemNode();a.append(...e);d.append(a);break;case "paragraphCodeBlock":d=null!=c.triggerState&&c.triggerState.isCodeBlock?
|
|
10
|
+
z.$createParagraphNode():m.$createCodeNode(),d.append(...e)}a=d;null!==a&&b.replace(a)}}})}
|
|
11
|
+
function L(f){let h=null;f.read(()=>{const b=u.$getSelection();if(null!=b&&b.isCollapsed()){var a=b.anchor.getNode(),c=a.getParent(),e=null!==c&&t.$isListItemNode(c);c=null!==c&&u.$isElementNode(c);h={anchorOffset:b.anchor.offset,isCodeBlock:m.$isCodeNode(a),isSelectionCollapsed:b.isCollapsed(),isSimpleText:u.$isTextNode(a)&&a.isSimpleText(),isParentAnElementNode:c,isParentAListItemNode:e,nodeKey:a.getKey(),textContent:a.getTextContent()}}});return h}
|
|
12
|
+
function M(f){w.useEffect(()=>{let h=null;f.addListener("update",({tags:b})=>{if(!1===b.has("historic")){b=L(f.getEditorState());var a=b;var c=h;if(null==a||null==c)a=!1;else{var e=a.textContent.length,d=a.anchorOffset-1;a=!0===a.isParentAnElementNode&&a.isSimpleText&&a.isSelectionCollapsed&&a.nodeKey===c.nodeKey&&a.anchorOffset!==c.anchorOffset&&0<=d&&d+1<=e&&" "===a.textContent.substr(d,1)&&a.textContent!==c.textContent}a&&null!=b&&I(f,b);h=b}else h=null})},[f])}
|
|
13
|
+
module.exports=function(){const [f]=l.useLexicalComposerContext();M(f);return null};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
'use strict';var h=require("lexical"),n=require("@lexical/react/LexicalComposerContext"),q=require("@lexical/react/withSubscriptions"),v=require("react"),w=require("lexical/AutoLinkNode");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();h.$isElementNode(a)&&(a=a.getLastDescendant());return null===a||h.$isLineBreakNode(a)||h.$isTextNode(a)&&a.getTextContent().endsWith(" ")}
|
|
2
|
+
function C(a){a=a.getNextSibling();h.$isElementNode(a)&&(a=a.getFirstDescendant());return null===a||h.$isLineBreakNode(a)||h.$isTextNode(a)&&a.getTextContent().startsWith(" ")}
|
|
3
|
+
function D(a,b,c){var d=a.getChildren();const e=d.length;for(let f=0;f<e;f++){const k=d[f];if(!h.$isTextNode(k)||!k.isSimpleText()){E(a);c(null,a.getURL());return}}d=a.getTextContent();b=x(d,b);null===b||b.text!==d?(E(a),c(null,a.getURL())):y(a)&&C(a)?(d=a.getURL(),null!==b&&d!==b.url&&(a.setURL(b.url),c(b.url,d))):(E(a),c(null,a.getURL()))}function E(a){const b=a.getChildren();var c=b.length;for(--c;0<=c;c--)a.insertAfter(b[c]);a.remove();return b.map(d=>d.getLatest())}
|
|
4
|
+
function F(a,b,c){v.useEffect(()=>{const d=(...e)=>{c&&c(...e)};return q(a.registerNodes([w.AutoLinkNode]),a.addTransform(h.TextNode,e=>{var f=e.getParentOrThrow();if(w.$isAutoLinkNode(f))D(f,b,d);else{if(e.isSimpleText()){f=e.getTextContent();const G=f.length;let u=f,z=0,r=e;for(var k=0,g;(g=x(u,b))&&null!==g;){var t=g.index,l=z+t;const p=g.length;let A;A=0<l?" "===f[l-1]:y(e);let B;B=l+p<G?" "===f[l+p]:C(e);if(A&&B){var m=void 0;k=l-k;0===k?[m,r]=r.splitText(p):[,m,r]=r.splitText(k,k+p);l=w.$createAutoLinkNode(g.url);
|
|
5
|
+
l.append(h.$createTextNode(g.text));m.replace(l);k+=p;d(g.url,null)}t+=p;u=u.substring(t);z+=t}}g=e.getPreviousSibling();m=e.getNextSibling();e=e.getTextContent();w.$isAutoLinkNode(g)&&!e.startsWith(" ")&&(E(g),d(null,g.getURL()));w.$isAutoLinkNode(m)&&!e.endsWith(" ")&&(E(m),d(null,m.getURL()))}}),a.addTransform(w.AutoLinkNode,e=>{D(e,b,d)}))},[a,b,c])}module.exports=function({matchers:a,onChange:b}){const [c]=n.useLexicalComposerContext();F(c,a,b);return null};
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
|
|
3
|
-
{
|
|
1
|
+
'use strict';var l=require("@lexical/react/LexicalComposerContext"),p=require("lexical"),q=require("react"),r=require("@lexical/react/withSubscriptions");function t(a,e){for(e(a);null!==a;){if(p.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild();else{let f=null;for(;null===f&&null!==a;)f=a.getNextSibling(),a=null===f?a.getParent():f}null!==a&&(a=e(a))}}function u(){return p.$getRoot().getTextContent()}
|
|
2
|
+
function w(a,e,f={}){const {strlen:h=c=>c.length,remainingCharacters:d=()=>{}}=f;q.useEffect(()=>a.registerNodes([x]),[a]);q.useEffect(()=>{let c=a.getEditorState().read(u),b=0;return r(a.addListener("textcontent",g=>{c=g}),a.addListener("update",({dirtyLeaves:g})=>{var k=a.isComposing();g=0<g.size;if(!k&&g){k=h(c);g=k>e||null!==b&&b>e;d(e-k);if(null===b||g){const n=y(c,e,h);a.update(()=>{p.$log("CharacterLimit");z(n)},{tag:"without-history"})}b=k}}))},[a,e,d,h])}
|
|
3
|
+
function y(a,e,f){var h=Intl.Segmenter;let d=0;var c=0;if("function"===typeof h){a=(new h).segment(a);for(var {segment:b}of a){c+=f(b);if(c>e)break;d+=b.length}}else for(b=Array.from(a),a=b.length,h=0;h<a;h++){const g=b[h];c+=f(g);if(c>e)break;d+=g.length}return d}
|
|
4
|
+
function z(a){const e=p.$getRoot();let f=0,h=e;t(e,d=>{if(d instanceof x){var c=f;if(f+d.getTextContentSize()<=a){var b=d.getParent();c=d.getPreviousSibling();var g=d.getNextSibling();A(d);d=p.$getSelection();null===d||d.anchor.getNode().isAttached()&&d.focus.getNode().isAttached()||(p.$isTextNode(c)?c.select():p.$isTextNode(g)?g.select():null!==b&&b.select());return h}if(c<a&&(b=d.getFirstDescendant(),g=null!==b?b.getTextContentSize():0,c+=g,b=p.$isTextNode(b)&&b.isSimpleText(),c=c<=a,b||c))return A(d),
|
|
5
|
+
h}else if(p.$isLeafNode(d)&&(c=f,f+=d.getTextContentSize(),f>a&&!(d.getParent()instanceof x)&&(b=p.$getSelection(),c<a&&p.$isTextNode(d)&&d.isSimpleText()?([,c]=d.splitText(a-c),c=B(c)):c=B(d),null!==b&&p.$setSelection(b),b=c,g=b.getPreviousSibling(),g instanceof x))){var k=b.getFirstChild(),n=g.getChildren();c=n.length;if(null===k)b.append(...n);else for(var m=0;m<c;m++)k.insertBefore(n[m]);m=p.$getSelection();if(null!==m){k=m.anchor;n=k.getNode();m=m.focus;const v=k.getNode();n.is(g)?k.set(b.getKey(),
|
|
6
|
+
k.offset,"element"):n.is(b)&&k.set(b.getKey(),c+k.offset,"element");v.is(g)?m.set(b.getKey(),m.offset,"element"):v.is(b)&&m.set(b.getKey(),c+m.offset,"element")}g.remove()}return h=d})}
|
|
7
|
+
class x extends p.ElementNode{static getType(){return"overflow"}static clone(a){return new x(a.__key)}constructor(a){super(a);this.__type="overflow"}createDOM(a){const e=document.createElement("div");a=a.theme.characterLimit;"string"===typeof a&&(e.className=a);return e}updateDOM(){return!1}insertNewAfter(a){return this.getParentOrThrow().insertNewAfter(a)}excludeFromCopy(){return!0}}function B(a){const e=new x;a.insertBefore(e);e.append(a);return e}
|
|
8
|
+
function A(a){const e=a.getChildren(),f=e.length;for(let h=0;h<f;h++)a.insertBefore(e[h]);a.remove();return 0<f?e[f-1]:null}let C=null;
|
|
9
|
+
module.exports=function({charset:a="UTF-16"}){const [e]=l.useLexicalComposerContext(),[f,h]=q.useState(0),d=q.useMemo(()=>({remainingCharacters:h,strlen:c=>{if("UTF-8"===a){if(void 0===window.TextEncoder)var b=null;else null===C&&(C=new window.TextEncoder),b=C;null===b?(b=encodeURIComponent(c).match(/%[89ABab]/g),c=c.length+(b?b.length:0)):c=b.encode(c).length;return c}if("UTF-16"===a)return c.length;throw Error("Unrecognized charset");}}),[a]);w(e,5,d);return q.createElement("span",{className:`characters-limit ${0>
|
|
10
|
+
f?"characters-limit-exceeded":""}`},f)};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
'use strict';var d=require("react"),g=require("@lexical/react/LexicalComposerContext"),
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
b.addListener("
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.CollaborationContext=Q;exports.CollaborationPlugin=function({id:b,providerFactory:c,skipInit:a}){const {yjsDocMap:e,name:h,color:m}=R(),[r]=g.useLexicalComposerContext(),f=d.useMemo(()=>c(b,e),[b,c,e]),[n,p]=F(r,b,f,e,h,m,a||!1);H(r,p);G(r,f);return n};exports.useCollaborationContext=R;
|
|
1
|
+
'use strict';var d=require("react"),g=require("@lexical/react/LexicalComposerContext"),t=require("react-dom"),z=require("@lexical/yjs"),A=require("lexical"),B=require("lexical/ParagraphNode");function C(b){b.update(()=>{A.$log("initEditor");var c=A.$getRoot();if(null===c.getFirstChild()){const a=B.$createParagraphNode();c.append(a);c=document.activeElement;(null!==A.$getSelection()||null!==c&&c===b.getRootElement())&&a.select()}})}
|
|
2
|
+
function D(b,c,a,e,h,l,q){const f=d.useMemo(()=>z.createBinding(b,a,c,e),[b,a,c,e]),m=d.useCallback(()=>{a.connect()},[a]),n=d.useCallback(()=>{try{a.disconnect()}catch(k){}},[a]);d.useEffect(()=>{const {root:k}=f,{awareness:r}=a,v=({status:p})=>{b.execCommand("connected","connected"===p)},w=p=>{!q&&p&&k.isEmpty()&&0===k._xmlText._length&&C(b)},x=()=>{z.syncCursorPositions(f,a)},y=(p,u)=>{u.origin!==f&&z.syncYjsChangesToLexical(f,a,p)};z.initLocalState(a,h,l,document.activeElement===b.getRootElement());
|
|
3
|
+
a.on("status",v);a.on("sync",w);r.on("update",x);k.getSharedType().observeDeep(y);const M=b.addListener("update",({prevEditorState:p,editorState:u,dirtyLeaves:I,dirtyElements:J,normalizedNodes:K,tags:L})=>{z.syncLexicalUpdateToYjs(f,a,p,u,J,I,K,L)});m();return()=>{n();a.off("sync",w);a.off("status",v);r.off("update",x);k.getSharedType().unobserveDeep(y);M()}},[f,l,m,n,b,h,a,q]);const N=d.useMemo(()=>t.createPortal(d.createElement("div",{ref:k=>{f.cursorsContainer=k}}),document.body),[f]);d.useEffect(()=>
|
|
4
|
+
b.addListener("command",(k,r)=>{"toggleConnect"===k&&void 0!==m&&void 0!==n&&(r?(console.log("Collaboration connected!"),m()):(console.log("Collaboration disconnected!"),n()));return!1},0),[m,n,b]);return[N,f]}
|
|
5
|
+
function E(b,c){d.useEffect(()=>{const a=()=>{z.setLocalStateFocus(c,!1)},e=()=>{z.setLocalStateFocus(c,!0)};return b.addListener("root",(h,l)=>{null!==l&&(l.removeEventListener("blur",a),l.removeEventListener("focus",e));null!==h&&(document.activeElement===h&&z.setLocalStateFocus(c,!0),h.addEventListener("blur",a),h.addEventListener("focus",e))})},[b,c,c.awareness])}
|
|
6
|
+
function F(b,c){const a=d.useMemo(()=>z.createUndoManager(c,c.root.getSharedType()),[c]);d.useEffect(()=>b.addListener("command",e=>"undo"===e?(a.undo(),!0):"redo"===e?(a.redo(),!0):!1,0));return d.useCallback(()=>{a.clear()},[a])}
|
|
7
|
+
const G=[["Cat","255,165,0"],["Dog","0,200,55"],["Rabbit","160,0,200"],["Frog","0,172,200"],["Fox","197,200,0"],["Hedgehog","31,200,0"],["Pigeon","200,0,0"],["Squirrel","200,0,148"],["Bear","255,235,0"],["Tiger","86,255,0"],["Leopard","0,255,208"],["Zebra","0,243,255"],["Wolf","0,102,255"],["Owl","147,0,255"],["Gull","255,0,153"],["Squid","0,220,255"]],H=G[Math.floor(Math.random()*(G.length-1+1))],O=d.createContext({yjsDocMap:new Map,name:H[0],color:H[1]});function P(){return d.useContext(O)}
|
|
8
|
+
exports.CollaborationContext=O;exports.CollaborationPlugin=function({id:b,providerFactory:c,skipInit:a}){const {yjsDocMap:e,name:h,color:l}=P(),[q]=g.useLexicalComposerContext(),f=d.useMemo(()=>c(b,e),[b,c,e]),[m,n]=D(q,b,f,e,h,l,a||!1);F(q,n);E(q,f);return m};exports.useCollaborationContext=P;
|
package/LexicalComposer.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var e=require("lexical"),f=require("@lexical/react/LexicalComposerContext"),
|
|
2
|
-
module.exports=function({children:l,
|
|
1
|
+
'use strict';var e=require("lexical"),f=require("@lexical/react/LexicalComposerContext"),h=require("react");
|
|
2
|
+
module.exports=function({namespace:k,children:l,initialEditor:m,theme:g}){const c=h.useContext(f.LexicalComposerContext),n=h.useMemo(()=>{if(null!=g)var b=g;else if(null!=c){var d=c[0];var a=c[1].getTheme();null!=a&&(b=a)}d={theme:b||{},namespace:k,parentEditor:d};b=f.createLexicalComposerContext(c,b);a=m||null;null===a?a=e.createEditor({...d,context:b}):a._config={...a._config,...d,context:b};return[a,b]},[g]);return h.createElement(f.LexicalComposerContext.Provider,{value:n},l)};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';var b=require("react"),e=require("@lexical/react/LexicalComposerContext");
|
|
2
|
+
module.exports=function({ariaActiveDescendantID:f,ariaAutoComplete:g,ariaControls:h,ariaDescribedBy:k,ariaExpanded:l,ariaLabel:m,ariaLabelledBy:n,ariaMultiline:p,ariaOwneeID:q,ariaRequired:r,autoCapitalize:t,autoComplete:u,autoCorrect:v,className:w,readOnly:a=!1,role:c="textbox",spellCheck:x=!0,style:y,tabIndex:z,testid:A}){const [d]=e.useLexicalComposerContext(),C=b.useCallback(B=>{d.setRootElement(B)},[d]);return b.createElement("div",{"aria-activedescendant":a?null:f,"aria-autocomplete":a?null:
|
|
3
|
+
g,"aria-controls":a?null:h,"aria-describedby":k,"aria-expanded":a?null:"combobox"===c?!!l:null,"aria-label":m,"aria-labelledby":n,"aria-multiline":p,"aria-owns":a?null:q,"aria-required":r,autoCapitalize:t,autoComplete:u,autoCorrect:v,className:w,contentEditable:!a,"data-testid":A,ref:C,role:a?null:c,spellCheck:x,style:y,tabIndex:z})};
|
package/LexicalHistoryPlugin.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var n=require("@lexical/react/LexicalComposerContext"),r=require("lexical"),v=require("react"),w=require("@lexical/react/withSubscriptions");function x(a,b,f){b=Array.from(b);f=Array.from(f);a=a._nodeMap;const c=[];for(var h=0;h<b.length;h++){const e=a.get(b[h]);void 0!==e&&c.push(e)}for(b=0;b<f.length;b++)f[b][1]&&(h=a.get(f[b][0]),void 0===h||r.$isRootNode(h)||c.push(h));return c}
|
|
2
|
+
function y(a,b,f,c,h){if(null===a||0===f.size&&0===c.size)return 0;var e=b._selection,d=a._selection;if(h)return 1;if(null===e||null===d||!d.isCollapsed()||!e.isCollapsed())return 0;f=x(b,f,c);if(0===f.length)return 0;if(1<f.length){b=b._nodeMap;d=b.get(d.anchor.key);const g=b.get(e.anchor.key);return r.$isTextNode(g)&&r.$isElementNode(d)&&!a._nodeMap.has(g.__key)&&1===g.__text.length&&1===e.anchor.offset?f.every(k=>k===g||!r.$isTextNode(k))?2:0:0}b=f[0];a=a._nodeMap.get(b.__key);if(!r.$isTextNode(a)||
|
|
3
|
+
!r.$isTextNode(b)||a.__mode!==b.__mode)return 0;a=a.__text;b=b.__text;if(a===b)return 0;e=e.anchor;d=d.anchor;if(e.key!==d.key||"text"!==e.type)return 0;e=e.offset;d=d.offset;a=b.length-a.length;return 1===a&&d===e-1?2:-1===a&&d===e+1?3:-1===a&&d===e?4:0}
|
|
4
|
+
function z(a,b){let f=Date.now(),c=0;return(h,e,d,g,k,m)=>{const p=Date.now();if(m.has("historic"))return c=0,f=p,2;const l=y(h,e,g,k,a.isComposing()),u=(()=>{if(m.has("without-history"))return 0;if(null===h)return 1;var q=e._selection;const t=h._selection;if(!(0<g.size||0<k.size))return null===t&&null!==q?0:2;q=null===d||d.editor===a;return 0!==l&&l===c&&p<f+b&&q?0:1})();f=p;c=l;return u}}
|
|
5
|
+
function A(a,b,f=1E3){const c=v.useMemo(()=>b||B(),[b]),h=v.useCallback(()=>{c.undoStack=[];c.redoStack=[];c.current=null},[c]);v.useEffect(()=>{const e=z(a,f);return w(a.addListener("command",d=>{switch(d){case "undo":d=c.redoStack;var g=c.undoStack;if(0!==g.length){var k=c.current;const m=g.pop();null!==k&&(d.push(k),a.execCommand("canRedo",!0));0===g.length&&a.execCommand("canUndo",!1);c.current=m;m.editor.setEditorState(m.editorState.clone(m.undoSelection),{tag:"historic"})}return!0;case "redo":return d=
|
|
6
|
+
c.redoStack,g=c.undoStack,0!==d.length&&(k=c.current,null!==k&&(g.push(k),a.execCommand("canUndo",!0)),g=d.pop(),0===d.length&&a.execCommand("canRedo",!1),c.current=g,g.editor.setEditorState(g.editorState,{tag:"historic"})),!0;case "clearEditor":return h(),!1;case "clearHistory":return h(),!0;default:return!1}},0),a.addListener("update",({editorState:d,prevEditorState:g,dirtyLeaves:k,dirtyElements:m,tags:p})=>{const l=c.current,u=c.redoStack,q=c.undoStack,t=null===l?null:l.editorState;if(null===l||
|
|
7
|
+
d!==t){k=e(g,d,l,k,m,p);if(1===k)0!==u.length&&(c.redoStack=[]),null!==l&&(q.push({...l,undoSelection:g.read(r.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;c.current={editor:a,editorState:d}}}))},[h,f,a,c])}function B(){return{current:null,redoStack:[],undoStack:[]}}exports.HistoryPlugin=function({externalHistoryState:a}){const [b]=n.useLexicalComposerContext();A(b,a);return null};exports.createEmptyHistoryState=B;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var b=require("lexical"),d=require("@lexical/react/LexicalComposerContext"),e=require("react");module.exports=function(){const [c]=d.useLexicalComposerContext();e.useEffect(()=>c.addListener("command",a=>{if("insertHorizontalRule"===a){b.$log("insertHorizontalRule");a=b.$getSelection();if(null===a)return!1;if(null!==a.focus.getNode()){const f=b.$createHorizontalRuleNode();a.insertParagraph();a.focus.getNode().getTopLevelElementOrThrow().insertBefore(f)}return!0}return!1},0),[c]);return null};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';var h=require("@lexical/react/LexicalComposerContext"),k=require("react"),m=require("lexical"),n=require("lexical/LinkNode");
|
|
2
|
+
function p(g){var b=m.$getSelection();m.$log("toggleLink");null!==b&&m.$setSelection(b);b=m.$getSelection();if(null!==b)if(b=b.extract(),null===g)b.forEach(c=>{c=c.getParent();if(n.$isLinkNode(c)){const a=c.getChildren();for(let d=0;d<a.length;d++)c.insertBefore(a[d]);c.remove()}});else{let c=null,a=null;if(1===b.length){var f=b[0];if(n.$isLinkNode(f)){f.setURL(g);return}f=f.getParent();if(n.$isLinkNode(f)){a=f;f.setURL(g);return}}b.forEach(d=>{var e=d.getParent();if(e!==a&&null!==e)if(e.is(c)||(c=
|
|
3
|
+
e,a=n.$createLinkNode(g),n.$isLinkNode(e)?null===d.getPreviousSibling()?e.insertBefore(a):e.insertAfter(a):d.insertBefore(a)),n.$isLinkNode(d)){if(null!==a){e=d.getChildren();for(let l=0;l<e.length;l++)a.append(e[l])}d.remove()}else null!==a&&a.append(d)})}}module.exports=function(){const [g]=h.useLexicalComposerContext();k.useEffect(()=>{const b=g.addListener("command",(c,a)=>"toggleLink"===c?(p(a),!0):!1,0),f=g.registerNodes([n.LinkNode]);return()=>{b();f()}},[g]);return null};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';var g=require("@lexical/react/LexicalComposerContext"),l=require("react"),m=require("lexical"),p=require("lexical/ListItemNode"),q=require("lexical/ListNode"),r=require("lexical/ParagraphNode");function t(d){d=d.getParent();if(!q.$isListNode(d))throw Error("Minified Lexical error #2; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let a=d;for(;null!==a;)a=a.getParent(),q.$isListNode(a)&&(d=a);return d}
|
|
2
|
+
function u(d){let a=[];d=d.getChildren().filter(p.$isListItemNode);for(let b=0;b<d.length;b++){const c=d[b],e=c.getFirstChild();q.$isListNode(e)?a=a.concat(u(e)):a.push(c)}return a}function v(d,a){for(;null!=d&&!(d instanceof a);)d=d.getParent();return d}
|
|
3
|
+
function w(d){d.update(()=>{m.$log("removeList");var a=m.$getSelection();if(null!==a){const c=new Set,e=a.getNodes();a=a.anchor.getNode();if(0===e.length&&p.$isListItemNode(a))c.add(t(a));else for(a=0;a<e.length;a++){var b=e[a];m.$isLeafNode(b)&&(b=v(b,p.ListItemNode),null!=b&&c.add(t(b)))}c.forEach(f=>{let h=f;u(f).forEach(k=>{if(null!=k){const n=r.$createParagraphNode();n.append(...k.getChildren());h.insertAfter(n);h=n;k.remove()}});f.remove()})}})}
|
|
4
|
+
function x(d,a){if(q.$isListNode(d))return d;const b=d.getPreviousSibling(),c=d.getNextSibling(),e=p.$createListItemNode();if(q.$isListNode(b)&&a===b.getTag())return e.append(d),b.append(e),q.$isListNode(c)&&a===c.getTag()&&(b.append(...c.getChildren()),c.remove()),b;if(q.$isListNode(c)&&a===c.getTag())return e.append(d),c.getFirstChildOrThrow().insertBefore(e),c;a=q.$createListNode(a);a.append(e);d.replace(a);e.append(d);return a}
|
|
5
|
+
function y(d,a){d.update(()=>{m.$log("formatList");var b=m.$getSelection();if(null!==b){var c=b.getNodes();b=b.anchor.getNode();var e=b.getParent();if(0===c.length)c=q.$createListNode(a),m.$isRootNode(e)?(b.replace(c),b=p.$createListItemNode(),c.append(b)):p.$isListItemNode(b)&&(b=b.getParentOrThrow(),c.append(...b.getChildren()),b.replace(c));else for(b=new Set,e=0;e<c.length;e++){var f=c[e];if(m.$isElementNode(f)&&f.isEmpty()&&!b.has(f.getKey()))x(f,a);else if(m.$isLeafNode(f))for(f=f.getParent();null!=
|
|
6
|
+
f;){const k=f.getKey();if(q.$isListNode(f)){if(!b.has(k)){var h=q.$createListNode(a);h.append(...f.getChildren());f.replace(h);b.add(k)}break}else{h=f.getParent();if(m.$isRootNode(h)&&!b.has(k)){b.add(k);x(f,a);break}f=h}}}}})}
|
|
7
|
+
function z(d){var a=m.$getSelection();if(null===a)return!1;var b=a.getNodes(),c=[];0===b.length&&b.push(a.anchor.getNode());if(1===b.length){a:{for(b=b[0];null!==b;){if(p.$isListItemNode(b))break a;b=b.getParent()}b=null}null!==b&&(c=[b])}else{c=new Set;for(a=0;a<b.length;a++){const e=b[a];p.$isListItemNode(e)&&c.add(e)}c=Array.from(c)}return 0<c.length?("indent"===d?A(c):B(c),!0):!1}function C(d){return p.$isListItemNode(d)&&q.$isListNode(d.getFirstChild())}
|
|
8
|
+
function A(d){d.forEach(a=>{if(!C(a)){var b=a.getParent(),c=a.getNextSibling(),e=a.getPreviousSibling();if(C(c)&&C(e))e=e.getFirstChild(),q.$isListNode(e)&&(e.append(a),a=c.getFirstChild(),q.$isListNode(a)&&(c=a.getChildren(),e.append(...c),a.remove()),e.getChildren().forEach(f=>f.markDirty()));else if(C(c))c=c.getFirstChild(),q.$isListNode(c)&&(e=c.getFirstChild(),null!==e&&e.insertBefore(a),c.getChildren().forEach(f=>f.markDirty()));else if(C(e))c=e.getFirstChild(),q.$isListNode(c)&&(c.append(a),
|
|
9
|
+
c.getChildren().forEach(f=>f.markDirty()));else if(q.$isListNode(b)){const f=p.$createListItemNode(),h=q.$createListNode(b.getTag());f.append(h);h.append(a);e?e.insertAfter(f):c?c.insertBefore(f):b.append(f)}q.$isListNode(b)&&b.getChildren().forEach(f=>f.markDirty())}})}
|
|
10
|
+
function B(d){d.forEach(a=>{if(!C(a)){var b=a.getParent(),c=b?b.getParent():void 0,e=c?c.getParent():void 0;if(q.$isListNode(e)&&p.$isListItemNode(c)&&q.$isListNode(b)){var f=b?b.getFirstChild():void 0,h=b?b.getLastChild():void 0;if(a.is(f))c.insertBefore(a),b.isEmpty()&&c.remove();else if(a.is(h))c.insertAfter(a),b.isEmpty()&&c.remove();else{var k=b.getTag();f=p.$createListItemNode();const n=q.$createListNode(k);f.append(n);a.getPreviousSiblings().forEach(D=>n.append(D));h=p.$createListItemNode();
|
|
11
|
+
k=q.$createListNode(k);h.append(k);k.append(...a.getNextSiblings());c.insertBefore(f);c.insertAfter(h);c.replace(a)}b.getChildren().forEach(n=>n.markDirty());e.getChildren().forEach(n=>n.markDirty())}}})}
|
|
12
|
+
function E(d){l.useEffect(()=>d.addListener("command",a=>{if("indentContent"===a){if(z("indent"))return!0}else if("outdentContent"===a){if(z("outdent"))return!0}else{if("insertOrderedList"===a)return y(d,"ol"),!0;if("insertUnorderedList"===a)return y(d,"ul"),!0;if("removeList"===a)return w(d),!0}return!1},1),[d])}module.exports=function(){const [d]=g.useLexicalComposerContext();E(d);return null};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var b=require("react"),e=require("@lexical/react/LexicalComposer"),f=require("@lexical/react/LexicalOnChangePlugin");module.exports=function({namespace:g,children:h,initialDecoratorEditor:a,theme:k}){const [c,l]=b.useState(null);b.useEffect(()=>{a.isEmpty()||null===c||a.init(c)},[a,c]);const n=b.useCallback((m,d)=>{m.isEmpty()?l(d):a.set(d)},[a]);return b.createElement(e,{namespace:g,initialEditor:a.editor,theme:k},b.createElement(f,{onChange:n}),h)};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var c=require("@lexical/react/LexicalComposerContext"),d=require("react"),e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;module.exports=function({onChange:a}){const [b]=c.useLexicalComposerContext();e(()=>{if(a)return b.addListener("update",({editorState:f})=>{a(f,b)})},[b,a]);return null};
|
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
'use strict';var g=require("react"),
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
function
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
b.execCommand("insertParagraph");break;case "insertFromYank":case "insertFromDrop":case "insertReplacementText":case "insertFromPaste":f=a.dataTransfer;null!=f?L(f,e):d&&b.execCommand("insertText",d);break;case "deleteByComposition":f===h&&!m.$isElementNode(f)&&!m.$isElementNode(h)&&J(f)&&J(h)||b.execCommand("removeText");break;case "deleteByDrag":case "deleteByCut":b.execCommand("removeText");break;case "deleteContent":b.execCommand("deleteCharacter",!1);break;case "deleteWordBackward":b.execCommand("deleteWord",
|
|
15
|
-
!0);break;case "deleteWordForward":b.execCommand("deleteWord",!1);break;case "deleteHardLineBackward":case "deleteSoftLineBackward":b.execCommand("deleteLine",!0);break;case "deleteContentForward":case "deleteHardLineForward":case "deleteSoftLineForward":b.execCommand("deleteLine",!1);break;case "formatStrikeThrough":b.execCommand("formatText","strikethrough");break;case "formatBold":b.execCommand("formatText","bold");break;case "formatItalic":b.execCommand("formatText","italic");break;case "formatUnderline":b.execCommand("formatText",
|
|
16
|
-
"underline");break;case "historyUndo":b.execCommand("undo");break;case "historyRedo":b.execCommand("redo")}}})}function Q(a,b){a=window.getSelection();if(null!==a){var {anchorNode:c,anchorOffset:e,focusOffset:d}=a;null!==c&&3===c.nodeType&&(a=m.$getNearestNodeFromDOMNode(c),m.$isTextNode(a)&&S(a,c.nodeValue,e,d,b))}}function V(a){S(a.node,a.text,a.anchorOffset,a.focusOffset,!1)}
|
|
17
|
-
const W=[["selectionchange",function(a,b){a=window.getSelection();const c=b.getRootElement();c&&!c.contains(a.anchorNode)||b.update(()=>{m.$log("onSelectionChange");const e=m.$getSelection();if(null!==e&&e.isCollapsed()){var d=e.anchor;"text"===d.type?(d=d.getNode(),e.format=d.getFormat()):"element"===d.type&&(e.format=0)}b.execCommand("selectionChange")})}],["keydown",function(a,b){K="Unidentified"===a.key&&229===a.keyCode;b.isComposing()||b.update(()=>{m.$log("onKeyDown");if(null!==m.$getSelection()){var {keyCode:c,
|
|
18
|
-
shiftKey:e,ctrlKey:d,metaKey:f,altKey:h}=a;if(39!==c||d||f||h)if(37!==c||d||f||h)if(38!==c||d||f||h)if(40!==c||d||f||h)if(13===c&&e)b.execCommand("keyEnter",a);else if(B&&d&&79===c)a.preventDefault(),b.execCommand("insertLineBreak",!0);else if(13!==c||e){var k=B?h||f?!1:8===c||72===c&&d:d||h||f?!1:8===c;k?8===c?b.execCommand("keyBackspace",a):b.execCommand("deleteCharacter",!0):(k=B?e||h||f?!1:46===c||68===c&&d:d||h||f?!1:46===c,k?46===c?b.execCommand("keyDelete",a):b.execCommand("deleteCharacter",
|
|
19
|
-
!1):8===c&&(B?h:d)?(a.preventDefault(),b.execCommand("deleteWord",!0)):46===c&&(B?h:d)?(a.preventDefault(),b.execCommand("deleteWord",!1)):B&&f&&8===c?(a.preventDefault(),b.execCommand("deleteLine",!0)):B&&f&&46===c?(a.preventDefault(),b.execCommand("deleteLine",!1)):66===c&&(B?f:d)?(a.preventDefault(),b.execCommand("formatText","bold")):85===c&&(B?f:d)?(a.preventDefault(),b.execCommand("formatText","underline")):73===c&&(B?f:d)?(a.preventDefault(),b.execCommand("formatText","italic")):9!==c||h||
|
|
20
|
-
d||f?90===c&&!e&&(B?f:d)?(a.preventDefault(),b.execCommand("undo")):(k=B?90===c&&f&&e:89===c&&d||90===c&&d&&e,k&&(a.preventDefault(),b.execCommand("redo"))):b.execCommand("keyTab",a))}else b.execCommand("keyEnter",a);else b.execCommand("keyArrowDown",a);else b.execCommand("keyArrowUp",a);else b.execCommand("keyArrowLeft",a);else b.execCommand("keyArrowRight",a)}})}],["compositionstart",function(a,b){b.update(()=>{m.$log("onCompositionStart");const c=m.$getSelection();if(null!==c&&!b.isComposing()){const e=
|
|
21
|
-
c.anchor;m.$setCompositionKey(e.key);null==a.data||K&&"element"!==e.type&&c.isCollapsed()||b.execCommand("insertText"," ")}})}],["compositionend",function(a,b){C?setTimeout(()=>{P(a,b)},0):P(a,b)}],["cut",function(a,b){O(a,b);b.update(()=>{m.$log("onCutForPlainText");const c=m.$getSelection();null!==c&&c.removeText()})}],["copy",O],["dragstart",function(a){a.preventDefault()}],["paste",function(a,b){a.preventDefault();b.update(()=>{m.$log("onPasteForPlainText");const c=m.$getSelection(),e=a.clipboardData;
|
|
22
|
-
null!=e&&null!==c&&L(e,c)})}],["input",function(a,b){a.stopPropagation();b.update(()=>{m.$log("onInput");const c=m.$getSelection(),e=a.data;null!=e&&null!==c&&T(c,e,!1)?b.execCommand("insertText",e):Q(b,!1);m.$flushMutations()})}],["click",function(a,b){b.update(()=>{m.$log("onClick");const c=m.$getSelection();if(null!==c){var e=c.anchor;"element"===e.type&&0===e.offset&&c.isCollapsed()&&1===m.$getRoot().getChildrenSize()&&e.getNode().getTopLevelElementOrThrow().isEmpty()&&(e=R(b),null!==e&&c.is(e)&&
|
|
23
|
-
(window.getSelection().removeAllRanges(),c.dirty=!0))}})}]];D?W.push(["beforeinput",U]):W.push(["drop",N]);function X(a,b){const c=n.$createParagraphNode();a.append(c);a=document.activeElement;(null!==m.$getSelection()||null!==a&&a===b.getRootElement())&&c.select()}function Y(a){a.update(()=>{m.$log("initEditor");const b=m.$getRoot();null===b.getFirstChild()&&X(b,a)})}function aa(a,b){a.update(()=>{m.$log("clearEditor");const c=m.$getRoot();c.clear();X(c,a)},{onUpdate:b})}
|
|
24
|
-
function ba(a,b){E(()=>{const c=v(a.registerNodes([n.ParagraphNode]),a.addListener("textmutation",V),a.addListener("command",(e,d)=>{const f=m.$getSelection();if(null===f)return!1;switch(e){case "deleteCharacter":return f.deleteCharacter(d),!0;case "deleteWord":return f.deleteWord(d),!0;case "deleteLine":return f.deleteLine(d),!0;case "insertText":return f.insertText(d),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(d),!0;case "insertParagraph":return f.insertLineBreak(),
|
|
25
|
-
!0;case "indentContent":case "outdentContent":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":e=d.shiftKey;if(M(f,!0))return d.preventDefault(),d=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(d?"extend":"move",!e,"character"),!0;break;case "keyArrowRight":e=d.shiftKey;if(M(f,!1))return d.preventDefault(),d=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(d?"extend":"move",e,"character"),
|
|
26
|
-
!0;break;case "keyBackspace":return d.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return d.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return d.preventDefault(),a.execCommand("insertLineBreak");case "clearEditor":aa(a)}return!1},0));b&&Y(a);return c},[a,b]);G(W,a);I(a)}
|
|
27
|
-
function ca(a){const [b,c]=g.useState(()=>a.getDecorators());E(()=>a.addListener("decorator",e=>{y.flushSync(()=>{c(e)})}),[a]);return g.useMemo(()=>{const e=[],d=Object.keys(b);for(let h=0;h<d.length;h++){var f=d[h];const k=b[f];f=a.getElementByKey(f);null!==f&&e.push(y.createPortal(k,f))}return e},[b,a])}function da(a,b=!0){if(a)return!1;a=m.$getRoot().getTextContent();b&&(a=a.trim());return""===a}
|
|
28
|
-
function ea(a){if(!da(a,!1))return!1;a=m.$getRoot().getChildren();const b=a.length;if(1<b)return!1;for(let e=0;e<b;e++){var c=a[e];if(m.$isElementNode(c)){if("paragraph"!==c.__type||0!==c.__indent)return!1;c=c.getChildren();const d=c.length;for(let f=0;f<d;f++)if(!m.$isTextNode(c[e]))return!1}}return!0}function Z(a){return()=>ea(a)}
|
|
29
|
-
function fa(a){const [b,c]=g.useState(a.getEditorState().read(Z(a.isComposing())));E(()=>a.addListener("update",({editorState:e})=>{const d=a.isComposing();e=e.read(Z(d));c(e)}),[a]);return b}function ha(a){throw a;}module.exports=function({contentEditable:a,placeholder:b,skipInit:c,onError:e}){const [d]=l.useLexicalComposerContext(),f=fa(d);ba(d,!c);c=ca(d);E(()=>d.addListener("error",e||ha),[d,e]);return g.createElement(g.Fragment,null,a,f&&b,c)};
|
|
1
|
+
'use strict';var g=require("react"),h=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),u=require("lexical/ParagraphNode"),v=require("@lexical/react/withSubscriptions"),x=require("react-dom");
|
|
2
|
+
function y(a){g.useEffect(()=>{const d=c=>{var e=a.getRootElement();if(document.activeElement===e&&(e=c.data,"string"===typeof e)){try{var b=JSON.parse(e)}catch(f){return}if(b&&"nuanria_messaging"===b.protocol&&"request"===b.type&&(b=b.payload)&&"makeChanges"===b.functionId&&(b=b.args)){const [f,p,r,w,F]=b;a.update(()=>{t.$log("useLexicalDragonSupport");const q=t.$getSelection();if(null!==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,
|
|
3
|
+
m));if(l!==m||""!==r)q.insertRawText(r),k=n.getNode();t.$isTextNode(k)&&(l=w,m=w+F,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));c.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}function z(a,d){a=a.getData("text/plain");null!=a&&d.insertRawText(a)}
|
|
4
|
+
function A(a,d){var c=a.focus;a=c.offset;"element"===c.type?d=c.getNode().getChildAtIndex(d?a-1:a):(c=c.getNode(),d=d&&0===a||!d&&a===c.getTextContentSize()?d?c.getPreviousSibling():c.getNextSibling():null);return t.$isDecoratorNode(d)}function B(a,d){a.preventDefault();d.update(()=>{t.$log("onPasteForPlainText");const c=t.$getSelection(),e=a.clipboardData;null!=e&&null!==c&&z(e,c)})}
|
|
5
|
+
function C(a,d){D(a,d);d.update(()=>{t.$log("onCutForPlainText");const c=t.$getSelection();null!==c&&c.removeText()})}function D(a,d){a.preventDefault();d.update(()=>{t.$log("onCopyForPlainText");const c=a.clipboardData,e=t.$getSelection();if(null!==e&&null!=c){var b=window.getSelection();if(!b.isCollapsed){var f=b.getRangeAt(0);f&&(b=document.createElement("div"),f=f.cloneContents(),b.appendChild(f),c.setData("text/html",b.innerHTML));c.setData("text/plain",e.getTextContent())}}})}
|
|
6
|
+
var E="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function G(a,d){const c=u.$createParagraphNode();a.append(c);a=document.activeElement;(null!==t.$getSelection()||null!==a&&a===d.getRootElement())&&c.select()}function H(a){a.update(()=>{t.$log("initEditor");const d=t.$getRoot();null===d.getFirstChild()&&G(d,a)})}
|
|
7
|
+
function I(a,d){a.update(()=>{t.$log("clearEditor");const c=t.$getRoot();c.clear();G(c,a)},{onUpdate:d})}
|
|
8
|
+
function J(a,d){E(()=>{const c=v(a.registerNodes([u.ParagraphNode]),a.addListener("command",(e,b)=>{const f=t.$getSelection();if(null===f)return!1;switch(e){case "deleteCharacter":return f.deleteCharacter(b),!0;case "deleteWord":return f.deleteWord(b),!0;case "deleteLine":return f.deleteLine(b),!0;case "insertText":return"string"===typeof b?f.insertText(b):(e=b.dataTransfer,null!=e?z(e,f):(b=b.data)&&f.insertText(b)),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(b),
|
|
9
|
+
!0;case "insertParagraph":return f.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":e=b.shiftKey;if(A(f,!0))return b.preventDefault(),b=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(b?"extend":"move",!e,"character"),!0;break;case "keyArrowRight":e=b.shiftKey;if(A(f,!1))return b.preventDefault(),b=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),
|
|
10
|
+
f.modify(b?"extend":"move",e,"character"),!0;break;case "keyBackspace":return b.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "clearEditor":I(a);break;case "copy":return D(b,a),!0;case "cut":return C(b,a),!0;case "paste":return B(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0));d&&H(a);return c},[a,d]);
|
|
11
|
+
y(a)}function K(a){const [d,c]=g.useState(()=>a.getDecorators());E(()=>a.addListener("decorator",e=>{x.flushSync(()=>{c(e)})}),[a]);return g.useMemo(()=>{const e=[],b=Object.keys(d);for(let p=0;p<b.length;p++){var f=b[p];const r=d[f];f=a.getElementByKey(f);null!==f&&e.push(x.createPortal(r,f))}return e},[d,a])}function L(a,d=!0){if(a)return!1;a=t.$getRoot().getTextContent();d&&(a=a.trim());return""===a}
|
|
12
|
+
function M(a){if(!L(a,!1))return!1;a=t.$getRoot().getChildren();const d=a.length;if(1<d)return!1;for(let e=0;e<d;e++){var c=a[e];if(t.$isElementNode(c)){if("paragraph"!==c.__type||0!==c.__indent)return!1;c=c.getChildren();const b=c.length;for(let f=0;f<b;f++)if(!t.$isTextNode(c[e]))return!1}}return!0}function N(a){return()=>M(a)}
|
|
13
|
+
function O(a){const [d,c]=g.useState(a.getEditorState().read(N(a.isComposing())));E(()=>a.addListener("update",({editorState:e})=>{const b=a.isComposing();e=e.read(N(b));c(e)}),[a]);return d}function P(a){throw a;}module.exports=function({contentEditable:a,placeholder:d,skipInit:c,onError:e}){const [b]=h.useLexicalComposerContext(),f=O(b);J(b,!c);c=K(b);E(()=>b.addListener("error",e||P),[b,e]);return g.createElement(g.Fragment,null,a,f&&d,c)};
|
package/LexicalRichTextPlugin.js
CHANGED
|
@@ -1,39 +1,26 @@
|
|
|
1
|
-
'use strict';var g=require("react"),
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
function K(a){a=a.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
d||c?90===e&&!f&&(H?c:d)?(a.preventDefault(),b.execCommand("undo")):(k=H?90===e&&c&&f:89===e&&d||90===e&&d&&f,k&&(a.preventDefault(),b.execCommand("redo"))):b.execCommand("keyTab",a))}else b.execCommand("keyEnter",a);else b.execCommand("keyArrowDown",a);else b.execCommand("keyArrowUp",a);else b.execCommand("keyArrowLeft",a);else b.execCommand("keyArrowRight",a)}})}],["compositionstart",function(a,b){b.update(()=>{v.$log("onCompositionStart");const e=v.$getSelection();if(null!==e&&!b.isComposing()){const f=
|
|
28
|
-
e.anchor;v.$setCompositionKey(f.key);null==a.data||O&&"element"!==f.type&&e.isCollapsed()||b.execCommand("insertText"," ")}})}],["compositionend",function(a,b){ca?setTimeout(()=>{T(a,b)},0):T(a,b)}],["cut",function(a,b){S(a,b);b.update(()=>{v.$log("onCutForRichText");const e=v.$getSelection();null!==e&&e.removeText()})}],["copy",S],["dragstart",function(a){a.preventDefault()}],["paste",function(a,b){a.preventDefault();b.update(()=>{v.$log("onPasteForRichText");const e=v.$getSelection();var f=a.clipboardData;
|
|
29
|
-
if(null!=f&&null!==e)a:{var d=f.getData("application/x-lexical-nodes");if(d)try{var c=JSON.parse(d);const {range:m,nodeMap:n}=c;var h=new Map(n);d=[];for(c=0;c<m.length;c++){var k=h.get(m[c]);if(void 0!==k){var l=v.$createNodeFromParse(k,h);d.push(l)}}e.insertNodes(d);break a}catch(m){}if(h=f.getData("text/html")){h=(new DOMParser).parseFromString(h,"text/html");f=[];h=h.body?Array.from(h.body.childNodes):[];k=h.length;for(l=0;l<k;l++)d=P(h[l],ia,b),null!==d&&(f=f.concat(d));h=[];k=null;for(l=0;l<
|
|
30
|
-
f.length;l++)d=f[l],!v.$isElementNode(d)||d.isInline()?(null===k&&(k=C.$createParagraphNode(),h.push(k)),null!==k&&k.append(d)):(h.push(d),k=null);e.insertNodes(h)}else Q(f,e)}})}],["input",function(a,b){a.stopPropagation();b.update(()=>{v.$log("onInput");const e=v.$getSelection(),f=a.data;null!=f&&null!==e&&W(e,f,!1)?b.execCommand("insertText",f):U(b,!1);v.$flushMutations()})}],["click",function(a,b){b.update(()=>{v.$log("onClick");const e=v.$getSelection();if(null!==e){var f=e.anchor;"element"===
|
|
31
|
-
f.type&&0===f.offset&&e.isCollapsed()&&1===v.$getRoot().getChildrenSize()&&f.getNode().getTopLevelElementOrThrow().isEmpty()&&(f=la(b),null!==f&&e.is(f)&&(window.getSelection().removeAllRanges(),e.dirty=!0))}})}]];da?X.push(["beforeinput",ma]):X.push(["drop",ja]);function Y(a,b){const e=C.$createParagraphNode();a.append(e);a=document.activeElement;(null!==v.$getSelection()||null!==a&&a===b.getRootElement())&&e.select()}
|
|
32
|
-
function oa(a){a.update(()=>{v.$log("initEditor");const b=v.$getRoot();null===b.getFirstChild()&&Y(b,a)})}function pa(a,b){a.update(()=>{v.$log("clearEditor");const e=v.$getRoot();e.clear();Y(e,a)},{onUpdate:b})}
|
|
33
|
-
function qa(a,b){I(()=>{const e=aa(a.registerNodes([w.HeadingNode,y.ListNode,z.QuoteNode,B.CodeNode,C.ParagraphNode,D.ListItemNode]),a.addListener("textmutation",na),a.addListener("command",(f,d)=>{var c=v.$getSelection();if(null===c)return!1;switch(f){case "deleteCharacter":return c.deleteCharacter(d),!0;case "deleteWord":return c.deleteWord(d),!0;case "deleteLine":return c.deleteLine(d),!0;case "insertText":return c.insertText(d),!0;case "removeText":return c.removeText(),!0;case "formatText":return c.formatText(d),
|
|
34
|
-
!0;case "formatElement":return c=c.anchor.getNode(),(v.$isElementNode(c)?c:c.getParentOrThrow()).setFormat(d),!0;case "insertLineBreak":return c.insertLineBreak(d),!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,d=c.getNode(),f="element"===c.type?c.getNode():
|
|
35
|
-
c.getNode().getParentOrThrow(),f.canInsertTab()?"\t"===d.getTextContent()[c.offset-1]&&a.execCommand("deleteCharacter",!0):0!==f.getIndent()&&f.setIndent(f.getIndent()-1),!0;case "keyArrowLeft":f=d.shiftKey;if(R(c,!0))return d.preventDefault(),d=f,f="rtl"===c.anchor.getNode().getParentOrThrow().getDirection(),c.modify(d?"extend":"move",!f,"character"),!0;break;case "keyArrowRight":f=d.shiftKey;if(R(c,!1))return d.preventDefault(),d=f,f="rtl"===c.anchor.getNode().getParentOrThrow().getDirection(),
|
|
36
|
-
c.modify(d?"extend":"move",f,"character"),!0;break;case "keyBackspace":return d.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return d.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return d.preventDefault(),d.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return d.preventDefault(),a.execCommand(d.shiftKey?"outdentContent":"indentContent");case "clearEditor":pa(a)}return!1},0));b&&oa(a);return e},[a,b]);ea(X,a);
|
|
37
|
-
fa(a)}function ra(a){const [b,e]=g.useState(()=>a.getDecorators());I(()=>a.addListener("decorator",f=>{F.flushSync(()=>{e(f)})}),[a]);return g.useMemo(()=>{const f=[],d=Object.keys(b);for(let h=0;h<d.length;h++){var c=d[h];const k=b[c];c=a.getElementByKey(c);null!==c&&f.push(F.createPortal(k,c))}return f},[b,a])}function sa(a,b=!0){if(a)return!1;a=v.$getRoot().getTextContent();b&&(a=a.trim());return""===a}
|
|
38
|
-
function ta(a){if(!sa(a,!1))return!1;a=v.$getRoot().getChildren();const b=a.length;if(1<b)return!1;for(let f=0;f<b;f++){var e=a[f];if(v.$isElementNode(e)){if("paragraph"!==e.__type||0!==e.__indent)return!1;e=e.getChildren();const d=e.length;for(let c=0;c<d;c++)if(!v.$isTextNode(e[f]))return!1}}return!0}function Z(a){return()=>ta(a)}
|
|
39
|
-
function ua(a){const [b,e]=g.useState(a.getEditorState().read(Z(a.isComposing())));I(()=>a.addListener("update",({editorState:f})=>{const d=a.isComposing();f=f.read(Z(d));e(f)}),[a]);return b}function va(a){throw a;}module.exports=function({contentEditable:a,placeholder:b,skipInit:e,onError:f}){const [d]=u.useLexicalComposerContext(),c=ua(d);qa(d,!e);e=ra(d);I(()=>d.addListener("error",f||va),[d,f]);return g.createElement(g.Fragment,null,a,c&&b,e)};
|
|
1
|
+
'use strict';var g=require("react"),v=require("@lexical/react/LexicalComposerContext"),x=require("lexical"),z=require("lexical/HeadingNode"),A=require("lexical/ListNode"),B=require("lexical/QuoteNode"),C=require("lexical/CodeNode"),D=require("lexical/ParagraphNode"),E=require("lexical/ListItemNode"),F=require("lexical/LinkNode"),G=require("@lexical/react/withSubscriptions"),H=require("react-dom");
|
|
2
|
+
function I(a){g.useEffect(()=>{const c=e=>{var f=a.getRootElement();if(document.activeElement===f&&(f=e.data,"string"===typeof f)){try{var d=JSON.parse(f)}catch(b){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [b,k,h,l,q]=d;a.update(()=>{x.$log("useLexicalDragonSupport");const m=x.$getSelection();if(null!==m){var n=m.anchor;let r=n.getNode(),p=0,t=0;x.$isTextNode(r)&&0<=b&&0<=k&&(p=b,t=b+k,m.setTextNodeRange(r,p,r,
|
|
3
|
+
t));if(p!==t||""!==h)m.insertRawText(h),r=n.getNode();x.$isTextNode(r)&&(p=l,t=l+q,n=r.getTextContentSize(),p=p>n?n:p,t=t>n?n:t,m.setTextNodeRange(r,p,r,t));e.stopImmediatePropagation()}})}}};window.addEventListener("message",c,!0);return()=>{window.removeEventListener("message",c,!0)}},[a])}
|
|
4
|
+
function J(a){a=a.getLatest();const c=a.constructor.clone(a);c.__parent=a.__parent;x.$isElementNode(a)&&x.$isElementNode(c)?(c.__children=Array.from(a.__children),c.__format=a.__format,c.__indent=a.__indent,c.__dir=a.__dir):x.$isTextNode(a)&&x.$isTextNode(c)?(c.__format=a.__format,c.__style=a.__style,c.__mode=a.__mode,c.__detail=a.__detail):x.$isDecoratorNode(a)&&x.$isDecoratorNode(c)&&(c.__state=a.__state);return c}
|
|
5
|
+
function K(a,c,e,f,d){for(var b=c;null!==a;){for(c=a.getParent();null!==c&&c.excludeFromCopy();)c=c.getParent();if(null===c)break;if(!x.$isElementNode(a)||!a.excludeFromCopy()){const k=a.getKey();let h=d.get(k);const l=void 0===h;l&&(h=J(a),d.set(k,h));!x.$isTextNode(h)||h.isSegmented()||h.isToken()?x.$isElementNode(h)&&(h.__children=h.__children.slice(e?b:0,e?void 0:b+1)):h.__text=h.__text.slice(e?b:0,e?void 0:b);if(x.$isRootNode(c)){l&&f.push(k);break}}b=d.get(c.getKey());b=x.$isElementNode(b)?
|
|
6
|
+
b.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=c}}
|
|
7
|
+
const L={ul:()=>({node:A.$createListNode("ul")}),ol:()=>({node:A.$createListNode("ol")}),li:()=>({node:E.$createListItemNode()}),h1:()=>({node:z.$createHeadingNode("h1")}),h2:()=>({node:z.$createHeadingNode("h2")}),h3:()=>({node:z.$createHeadingNode("h3")}),h4:()=>({node:z.$createHeadingNode("h4")}),h5:()=>({node:z.$createHeadingNode("h5")}),p:()=>({node:D.$createParagraphNode()}),br:()=>({node:x.$createLineBreakNode()}),a:a=>({node:a instanceof HTMLAnchorElement?F.$createLinkNode(a.href):x.$createTextNode(a.textContent)}),
|
|
8
|
+
u:()=>({node:null,forChild:a=>{x.$isTextNode(a)&&a.toggleFormat("underline")}}),b:a=>{const c="normal"===a.style.fontWeight;return{node:null,forChild:e=>{x.$isTextNode(e)&&!c&&e.toggleFormat("bold")}}},strong:()=>({node:null,forChild:a=>{x.$isTextNode(a)&&a.toggleFormat("bold")}}),i:()=>({node:null,forChild:a=>{x.$isTextNode(a)&&a.toggleFormat("italic")}}),em:()=>({node:null,forChild:a=>{x.$isTextNode(a)&&a.toggleFormat("italic")}}),td:a=>{const c=a.classList.contains("js-file-line");return{node:null,
|
|
9
|
+
after:e=>{c&&a.parentNode&&a.parentNode.nextSibling&&e.push(x.$createLineBreakNode());return e}}},table:a=>({node:a.classList.contains("js-file-line-container")?C.$createCodeNode():null}),span:a=>{const c="700"===a.style.fontWeight;return{node:null,forChild:e=>{x.$isTextNode(e)&&c&&e.toggleFormat("bold")}}},"#text":a=>({node:x.$createTextNode(a.textContent)}),pre:()=>({node:C.$createCodeNode()}),div:a=>({node:null!==a.style.fontFamily.match("monospace")?C.$createCodeNode():null,after:c=>{const e=
|
|
10
|
+
a.parentNode;null!=e&&a!==e.lastChild&&c.push(x.$createLineBreakNode());return c}})};
|
|
11
|
+
function M(a,c,e,f=new Map){let d=[],b=null;var k=a.nodeName.toLowerCase(),h=(e._config.htmlTransforms||{})[k]||c[k],l=h?h(a):null;h=null;if(null!==l){h=l.after;b=l.node;if(null!==b){d.push(b);const q=Array.from(f.values());for(let m=0;m<q.length;m++)q[m](b)}null!=l.forChild&&f.set(k,l.forChild)}a=a.childNodes;k=[];for(l=0;l<a.length;l++)k.push(...M(a[l],c,e,f));null!=h&&(k=h(k));null==b?d=d.concat(k):x.$isElementNode(b)&&b.append(...k);return d}
|
|
12
|
+
function N(a,c,e){var f=a.getData("application/x-lexical-editor");if(f){var d=e._config.namespace;try{const l=JSON.parse(f);if(l.namespace===d){const {range:q,nodeMap:m}=l.state;var b=new Map(m);f=[];for(d=0;d<q.length;d++){var k=b.get(q[d]);if(void 0!==k){var h=x.$createNodeFromParse(k,b);f.push(h)}}c.insertNodes(f);return}}catch(l){}}if(b=a.getData("text/html")){b=(new DOMParser).parseFromString(b,"text/html");a=[];b=b.body?Array.from(b.body.childNodes):[];k=b.length;for(h=0;h<k;h++)f=M(b[h],L,
|
|
13
|
+
e),null!==f&&(a=a.concat(f));e=a;a=[];b=null;for(k=0;k<e.length;k++)h=e[k],!x.$isElementNode(h)||h.isInline()?(null===b&&(b=D.$createParagraphNode(),a.push(b)),null!==b&&b.append(h)):(a.push(h),b=null);c.insertNodes(a)}else e=a.getData("text/plain"),null!=e&&c.insertRawText(e)}
|
|
14
|
+
function O(a,c){var e=a.focus;a=e.offset;"element"===e.type?c=e.getNode().getChildAtIndex(c?a-1:a):(e=e.getNode(),c=c&&0===a||!c&&a===e.getTextContentSize()?c?e.getPreviousSibling():e.getNextSibling():null);return x.$isDecoratorNode(c)}function P(a,c){a.preventDefault();c.update(()=>{x.$log("onPasteForRichText");const e=x.$getSelection(),f=a.clipboardData;null!=f&&null!==e&&N(f,e,c)})}
|
|
15
|
+
function Q(a,c){R(a,c);c.update(()=>{x.$log("onCutForRichText");const e=x.$getSelection();null!==e&&e.removeText()})}
|
|
16
|
+
function R(a,c){a.preventDefault();c.update(()=>{x.$log("onCopyForRichText");const e=a.clipboardData;var f=x.$getSelection();if(null!==f&&null!=e){var d=window.getSelection();if(!d.isCollapsed){var b=d.getRangeAt(0);b&&(d=document.createElement("div"),b=b.cloneContents(),d.appendChild(b),e.setData("text/html",d.innerHTML));e.setData("text/plain",f.getTextContent());d=c._config.namespace;b=e.setData;var k=JSON,h=k.stringify;{var l=f.anchor,q=f.focus;var m=l.getCharacterOffset();const y=q.getCharacterOffset();
|
|
17
|
+
var n=l.getNode(),r=q.getNode(),p=n.getParentOrThrow();if(n===r&&x.$isTextNode(n)&&(p.canBeEmpty()||1<p.getChildrenSize()))f=J(n),n=y>m,f.__text=f.__text.slice(n?m:y,n?y:m),m=f.getKey(),m={range:[m],nodeMap:[[m,f]]};else if(f=f.getNodes(),0===f.length)m={range:[],nodeMap:[]};else{n=f.length;r=f[0];p=r.getParent();if(null!==p&&!p.canBeEmpty()){var t=p.__children;if(t.length===n){var u=!0;for(var w=0;w<t.length;w++)if(t[w]!==f[w].__key){u=!1;break}u&&(n++,f.push(p))}}p=f[n-1];l=l.isBefore(q);q=new Map;
|
|
18
|
+
t=[];K(r,l?m:y,!0,t,q);for(r=0;r<n;r++)if(u=f[r],w=u.getKey(),!(q.has(w)||x.$isElementNode(u)&&u.excludeFromCopy())){const V=J(u);x.$isRootNode(u.getParent())&&t.push(u.getKey());q.set(w,V)}K(p,l?y:m,!1,t,q);m={range:t,nodeMap:Array.from(q.entries())}}}b.call(e,"application/x-lexical-editor",h.call(k,{namespace:d,state:m}))}}})}var S="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;
|
|
19
|
+
function T(a,c){const e=D.$createParagraphNode();a.append(e);a=document.activeElement;(null!==x.$getSelection()||null!==a&&a===c.getRootElement())&&e.select()}function U(a){a.update(()=>{x.$log("initEditor");const c=x.$getRoot();null===c.getFirstChild()&&T(c,a)})}function W(a,c){a.update(()=>{x.$log("clearEditor");const e=x.$getRoot();e.clear();T(e,a)},{onUpdate:c})}
|
|
20
|
+
function X(a,c){S(()=>{const e=G(a.registerNodes([z.HeadingNode,A.ListNode,B.QuoteNode,C.CodeNode,D.ParagraphNode,E.ListItemNode]),a.addListener("command",(f,d)=>{var b=x.$getSelection();if(null===b)return!1;switch(f){case "deleteCharacter":return b.deleteCharacter(d),!0;case "deleteWord":return b.deleteWord(d),!0;case "deleteLine":return b.deleteLine(d),!0;case "insertText":return"string"===typeof d?b.insertText(d):(f=d.dataTransfer,null!=f?N(f,b,a):(d=d.data)&&b.insertText(d)),!0;case "removeText":return b.removeText(),
|
|
21
|
+
!0;case "formatText":return b.formatText(d),!0;case "formatElement":return b=b.anchor.getNode(),(x.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(d),!0;case "insertLineBreak":return b.insertLineBreak(d),!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,
|
|
22
|
+
d=b.getNode(),f="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),f.canInsertTab()?"\t"===d.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==f.getIndent()&&f.setIndent(f.getIndent()-1),!0;case "keyArrowLeft":f=d.shiftKey;if(O(b,!0))return d.preventDefault(),d=f,f="rtl"===b.anchor.getNode().getParentOrThrow().getDirection(),b.modify(d?"extend":"move",!f,"character"),!0;break;case "keyArrowRight":f=d.shiftKey;if(O(b,!1))return d.preventDefault(),d=f,f="rtl"===b.anchor.getNode().getParentOrThrow().getDirection(),
|
|
23
|
+
b.modify(d?"extend":"move",f,"character"),!0;break;case "keyBackspace":return d.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return d.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return d.preventDefault(),d.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return d.preventDefault(),a.execCommand(d.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),!0;case "clearEditor":W(a);break;case "copy":return R(d,
|
|
24
|
+
a),!0;case "cut":return Q(d,a),!0;case "paste":return P(d,a),!0;case "drop":case "dragstart":return d.preventDefault(),!0}return!1},0));c&&U(a);return e},[a,c]);I(a)}function Y(a){const [c,e]=g.useState(()=>a.getDecorators());S(()=>a.addListener("decorator",f=>{H.flushSync(()=>{e(f)})}),[a]);return g.useMemo(()=>{const f=[],d=Object.keys(c);for(let k=0;k<d.length;k++){var b=d[k];const h=c[b];b=a.getElementByKey(b);null!==b&&f.push(H.createPortal(h,b))}return f},[c,a])}
|
|
25
|
+
function aa(a,c=!0){if(a)return!1;a=x.$getRoot().getTextContent();c&&(a=a.trim());return""===a}function ba(a){if(!aa(a,!1))return!1;a=x.$getRoot().getChildren();const c=a.length;if(1<c)return!1;for(let f=0;f<c;f++){var e=a[f];if(x.$isElementNode(e)){if("paragraph"!==e.__type||0!==e.__indent)return!1;e=e.getChildren();const d=e.length;for(let b=0;b<d;b++)if(!x.$isTextNode(e[f]))return!1}}return!0}function Z(a){return()=>ba(a)}
|
|
26
|
+
function ca(a){const [c,e]=g.useState(a.getEditorState().read(Z(a.isComposing())));S(()=>a.addListener("update",({editorState:f})=>{const d=a.isComposing();f=f.read(Z(d));e(f)}),[a]);return c}function da(a){throw a;}module.exports=function({contentEditable:a,placeholder:c,skipInit:e,onError:f}){const [d]=v.useLexicalComposerContext(),b=ca(d);X(d,!e);e=Y(d);S(()=>d.addListener("error",f||da),[d,f]);return g.createElement(g.Fragment,null,a,b&&c,e)};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
'use strict';var f=require("react"),k=require("@lexical/react/LexicalComposerContext"),l=require("lexical"),m=require("lexical/TableNode"),n=require("lexical/TableCellNode"),r=require("lexical/TableRowNode"),t=require("lexical/ParagraphNode");
|
|
2
|
+
function u(c,g,h=!0){const a=m.$createTableNode();for(let b=0;b<c;b++){const d=r.$createTableRowNode();for(let e=0;e<g;e++){const p=n.$createTableCellNode(0===b&&h),q=t.$createParagraphNode();q.append(l.$createTextNode());p.append(q);d.append(p)}a.append(d)}return a}
|
|
3
|
+
module.exports=function(){const [c]=k.useLexicalComposerContext();f.useEffect(()=>{const g=c.addListener("command",(a,b)=>{if("insertTable"===a){const {columns:d,rows:e}=b;l.$log("handleAddTable");a=l.$getSelection();if(null===a)return!0;a=a.focus.getNode();null!==a&&(a=a.getTopLevelElementOrThrow(),b=u(e,d),a.insertAfter(b),b.insertAfter(t.$createParagraphNode()),b.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0}return!1},0),h=c.registerNodes([m.TableNode,n.TableCellNode,r.TableRowNode]);
|
|
4
|
+
return()=>{g();h()}},[c]);return null};
|
package/LexicalTreeView.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
'use strict';var k=require("lexical"),q=require("react");const w=Object.freeze({"\n":"\\n","\t":"\\t"}),
|
|
2
|
-
function
|
|
3
|
-
function
|
|
4
|
-
c?": null":
|
|
5
|
-
const
|
|
6
|
-
function
|
|
7
|
-
c===l?[d,b]=l.isBefore(u)?[
|
|
1
|
+
'use strict';var k=require("lexical"),q=require("react");const w=Object.freeze({"\n":"\\n","\t":"\\t"}),D=new RegExp(Object.keys(w).join("|"),"g"),E=Object.freeze({hasNextSibling:"\u251c",isLastChild:"\u2514",ancestorHasNextSibling:"|",ancestorIsLastChild:" ",selectedChar:"^",selectedLine:">"});
|
|
2
|
+
function F(a){let b="";const c=G(a),g=a.anchor;a=a.focus;const d=g.offset,e=a.offset;b=b+`${""!==c?" - "+c:""}`+`\n \u251c anchor { key: ${g.key}, offset: ${null===d?"null":d}, type: ${g.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===e?"null":e}, type: ${a.type} }`}
|
|
3
|
+
function H(a){let b=" root\n";a=a.read(()=>{const c=k.$getSelection();J(k.$getRoot(),(g,d)=>{const e=`(${g.getKey()})`,f=g.getType()||"",m=g.isSelected();var v=b,t=m?E.selectedLine:" ",r=d.join(" ");if(k.$isTextNode(g)){var n=g.getTextContent(!0);n=0===n.length?"(empty)":`"${K(n)}"`;const l=L(g);n=[n,0!==l.length?`- ${l}`:null].filter(Boolean).join(" ").trim()}else n="";b=v+`${t} ${r} ${e} ${f} ${n}\n`;b+=M({isSelected:m,indent:d,node:g,nodeKeyDisplay:e,selection:c,typeDisplay:f})});return null===
|
|
4
|
+
c?": null":F(c)});return b+"\n selection"+a}function J(a,b,c=[]){a=a.getChildren();const g=a.length;a.forEach((d,e)=>{b(d,c.concat(e===g-1?E.isLastChild:E.hasNextSibling));k.$isElementNode(d)&&J(d,b,c.concat(e===g-1?E.ancestorIsLastChild:E.ancestorHasNextSibling))})}function K(a){return Object.entries(w).reduce((b,[c,g])=>b.replace(new RegExp(c,"g"),String(g)),a)}
|
|
5
|
+
const N=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("underline")&&"Underline"],O=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented",a=>a.isInert()&&"Inert",a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"];function L(a){return[...N,...O].map(b=>b(a)).filter(Boolean).join(", ")}function G(a){return N.map(b=>b(a)).filter(Boolean).join(", ")}
|
|
6
|
+
function M({indent:a,isSelected:b,node:c,nodeKeyDisplay:g,selection:d,typeDisplay:e}){if(!k.$isTextNode(c)||null===d||!b||k.$isElementNode(c))return"";b=d.anchor;var f=d.focus;if(""===c.getTextContent()||b.getNode()===d.focus.getNode()&&b.offset===f.offset)return"";f=d.anchor;const m=d.focus,v=c.getTextContent(!0),t=v.length;b=d=-1;if("text"===f.type&&"text"===m.type){const l=f.getNode(),u=m.getNode();l===u&&c===l&&f.offset!==m.offset?[d,b]=f.offset<m.offset?[f.offset,m.offset]:[m.offset,f.offset]:
|
|
7
|
+
c===l?[d,b]=l.isBefore(u)?[f.offset,t]:[0,f.offset]:c===u?[d,b]=u.isBefore(l)?[m.offset,t]:[0,m.offset]:[d,b]=[0,t]}c=(v.slice(0,d).match(D)||[]).length;f=(v.slice(d,b).match(D)||[]).length;const [r,n]=[d+c,b+c+f];if(r===n)return"";c=a[a.length-1]===E.hasNextSibling?E.ancestorHasNextSibling:E.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(r).fill(" ");d=Array(n-r).fill(E.selectedChar);g=Array(g.length+(e.length+3)).fill(" ");return[E.selectedLine,a.join(" "),[...g,...c,...d].join("")].join(" ")+
|
|
8
8
|
"\n"}
|
|
9
|
-
module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:
|
|
10
|
-
m(A=>[...A,[Date.now(),h]])})},[r,
|
|
11
|
-
"Time Travel"),q.createElement("pre",
|
|
12
|
-
p&&(p.value=String(h));n(!1);
|
|
9
|
+
module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:g,timeTravelPanelClassName:d,editor:e}){const [f,m]=q.useState([]),[v,t]=q.useState(""),[r,n]=q.useState(!1),l=q.useRef(0),u=q.useRef(null),B=q.useRef(null),[z,C]=q.useState(!1);q.useEffect(()=>{t(H(e.getEditorState()));return e.addListener("update",({editorState:h})=>{const p=e._compositionKey,x=H(e.getEditorState());t([x,null!==p&&`Composition key: ${p}`].filter(Boolean).join("\n\n"));r||
|
|
10
|
+
m(A=>[...A,[Date.now(),h]])})},[r,e]);const y=f.length;q.useEffect(()=>{if(z){let h;const p=()=>{const x=l.current;x===y-1?C(!1):h=setTimeout(()=>{l.current++;const A=l.current,I=B.current;null!==I&&(I.value=String(A));e.setEditorState(f[A][1]);p()},f[x+1][0]-f[x][0])};p();return()=>{window.clearTimeout(h)}}},[f,z,e,y]);q.useEffect(()=>{u.current&&(u.current.__lexicalEditor=e)},[e]);return q.createElement("div",{className:g},!r&&2<y&&q.createElement("button",{onClick:()=>{const h=e.getRootElement();
|
|
11
|
+
null!==h&&(h.contentEditable="false",l.current=y-1,n(!0))},className:a},"Time Travel"),q.createElement("pre",{ref:u},v),r&&q.createElement("div",{className:d},q.createElement("button",{className:c,onClick:()=>{C(!z)}},z?"Pause":"Play"),q.createElement("input",{className:b,ref:B,onChange:h=>{h=Number(h.target.value);const p=f[h];p&&(l.current=h,e.setEditorState(p[1]))},type:"range",min:"1",max:y-1}),q.createElement("button",{className:c,onClick:()=>{var h=e.getRootElement();if(null!==h){h.contentEditable=
|
|
12
|
+
"true";h=f.length-1;e.setEditorState(f[h][1]);const p=B.current;null!==p&&(p.value=String(h));n(!1);C(!1)}}},"Exit")))};
|
package/README.md
CHANGED
|
@@ -1,3 +1,79 @@
|
|
|
1
1
|
# `@lexical/react`
|
|
2
2
|
|
|
3
3
|
This package provides a set of components and hooks for Lexical that allow for text editing in React applications.
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
Install `lexical` and `@lexical/react`:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install --save lexical @lexical/react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Below is an example of a basic plain text editor using `lexical` and `@lexical/react` ([try it yourself](https://codesandbox.io/s/lexical-plain-text-example-g932e)).
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
import {$getRoot, $getSelection} from 'lexical';
|
|
17
|
+
import {useEffect} from 'react';
|
|
18
|
+
|
|
19
|
+
import LexicalComposer from '@lexical/react/LexicalComposer';
|
|
20
|
+
import LexicalPlainTextPlugin from '@lexical/react/LexicalPlainTextPlugin';
|
|
21
|
+
import LexicalContentEditable from '@lexical/react/LexicalContentEditable';
|
|
22
|
+
import LexicalHistoryPlugin from '@lexical/react/LexicalHistoryPlugin';
|
|
23
|
+
import LexicalOnChangePlugin from '@lexical/react/LexicalOnChangePlugin';
|
|
24
|
+
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|
25
|
+
|
|
26
|
+
const theme = {
|
|
27
|
+
// Theme styling goes here
|
|
28
|
+
...
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// When the editor changes, you can get notified via the
|
|
32
|
+
// LexicalOnChangePlugin!
|
|
33
|
+
function onChange(editorState) {
|
|
34
|
+
editorState.read(() => {
|
|
35
|
+
// Read the contents of the EditorState here.
|
|
36
|
+
const root = $getRoot();
|
|
37
|
+
const selection = $getSelection();
|
|
38
|
+
|
|
39
|
+
console.log(root, selection);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Lexical React plugins are React components, which makes them
|
|
44
|
+
// highly composable. Furthermore, you can lazy load plugins if
|
|
45
|
+
// desired, so you don't pay the cost for plugins until you
|
|
46
|
+
// actually use them.
|
|
47
|
+
function MyCustomAutoFocusPlugin() {
|
|
48
|
+
const [editor] = useLexicalComposerContext();
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
// Focus the editor when the effect fires!
|
|
52
|
+
editor.focus();
|
|
53
|
+
}, [editor]);
|
|
54
|
+
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Catch any errors that occur during Lexical updates and log them
|
|
59
|
+
// or throw them as needed. If you don't throw them, Lexical will
|
|
60
|
+
// try to recover gracefully without losing user data.
|
|
61
|
+
function onError(error) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function Editor() {
|
|
66
|
+
return (
|
|
67
|
+
<LexicalComposer theme={theme}>
|
|
68
|
+
<LexicalPlainTextPlugin
|
|
69
|
+
contentEditable={<LexicalContentEditable className="editor-input" />}
|
|
70
|
+
placeholder={<div>Enter some text...</div>}
|
|
71
|
+
onError={onError}
|
|
72
|
+
/>
|
|
73
|
+
<LexicalOnChangePlugin onChange={onChange} />
|
|
74
|
+
<LexicalHistoryPlugin />
|
|
75
|
+
<MyCustomAutoFocusPlugin />
|
|
76
|
+
</LexicalComposer>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
package/package.json
CHANGED
|
@@ -12,13 +12,11 @@
|
|
|
12
12
|
"rich-text"
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"version": "0.1.
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"lexical": "0.1.0",
|
|
18
|
-
"@lexical/helpers": "0.1.0",
|
|
19
|
-
"@lexical/yjs": "0.1.0"
|
|
20
|
-
},
|
|
15
|
+
"version": "0.1.4",
|
|
21
16
|
"peerDependencies": {
|
|
17
|
+
"lexical": "0.1.4",
|
|
18
|
+
"@lexical/helpers": "0.1.4",
|
|
19
|
+
"@lexical/yjs": "0.1.4",
|
|
22
20
|
"react": ">=17.x",
|
|
23
21
|
"react-dom": ">=17.x"
|
|
24
22
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var e=require("react"),g="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;module.exports=function(a,c,f){const [d,h]=e.useState(()=>{var b=a.get(c);b=void 0!==b?b:"function"===typeof f?f():f;return b});g(()=>{a.get(c)!==d&&a.set(c,d)},[c,d,a]);g(()=>a.observe((b,k)=>{b===c&&(a._map.set(b,k),h(k))}),[a,c]);return[d,h]};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
|
|
1
|
+
'use strict';var c=require("react"),e=require("lexical"),f="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?c.useLayoutEffect:c.useEffect;function g(a,b=!0){if(a)return!1;a=e.$getRoot().getTextContent();b&&(a=a.trim());return""===a}function h(a,b){return()=>g(a,b)}
|
|
2
|
+
module.exports=function(a,b){const [k,l]=c.useState(a.getEditorState().read(h(a.isComposing(),b)));f(()=>a.addListener("update",({editorState:d})=>{const m=a.isComposing();d=d.read(h(m,b));l(d)}),[a,b]);return k};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
'use strict';var b=require("react"),e=require("@lexical/react/LexicalComposerContext");
|
|
2
|
-
module.exports=function({ariaActiveDescendantID:f,ariaAutoComplete:g,ariaControls:h,ariaDescribedBy:k,ariaExpanded:l,ariaLabel:m,ariaLabelledBy:n,ariaMultiline:p,ariaOwneeID:q,ariaRequired:r,autoCapitalize:t,autoComplete:u,autoCorrect:v,className:w,readOnly:a=!1,role:c="textbox",spellCheck:x=!1,tabIndex:y,testid:z}){const [d]=e.useLexicalComposerContext(),B=b.useCallback(A=>{d.setRootElement(A)},[d]);return b.createElement("div",{"aria-activedescendant":a?null:f,"aria-autocomplete":a?null:g,"aria-controls":a?
|
|
3
|
-
null:h,"aria-describedby":k,"aria-expanded":a?null:"combobox"===c?!!l:null,"aria-label":m,"aria-labelledby":n,"aria-multiline":p,"aria-owns":a?null:q,"aria-required":r,autoCapitalize:t,autoComplete:u,autoCorrect:v,className:w,contentEditable:!a,"data-testid":z,ref:B,role:a?null:c,spellCheck:x,tabIndex:y})};
|
package/useLexical.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var b=require("lexical"),c=require("react"),h=require("@lexical/react/useLexicalCanShowPlaceholder");const k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,l=k&&"documentMode"in document?document.documentMode:null;k&&/Win/.test(navigator.platform);k&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;k&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);k&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
2
|
-
k&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);k&&/^(?=.*Chrome).*/i.test(navigator.userAgent);k&&"InputEvent"in window&&!l?"getTargetRanges"in new window.InputEvent("input"):!1;var m=k?c.useLayoutEffect:c.useEffect;function n(a,d){const e=h(a),g=c.useCallback(f=>{a.setRootElement(f)},[a]);m(()=>a.addListener("error",d),[a,d]);return[g,e]}function p(a){throw a;}module.exports=function(a){const d=void 0!==a&&a.onError||p,e=c.useMemo(()=>b.createEditor(a),[a]),[g,f]=n(e,d);return[e,g,f]};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
'use strict';var e=require("react"),g=require("lexical"),h=require("lexical/ParagraphNode"),k=require("lexical/ListItemNode"),m=require("lexical/HeadingNode"),n=require("lexical/ListNode"),p=require("lexical/QuoteNode"),q=require("lexical/CodeNode");function r(a,c){a=a.spliceText(0,c,"",!0);""===a.getTextContent()&&(a.selectPrevious(),a.remove())}
|
|
2
|
-
function t(a){const c=a.getParentOrThrow();if(null!==c&&null===a.getPreviousSibling()&&h.$isParagraphNode(c)){var b=a.getTextContent(),d=b[0];const f=b[1],l=b[2];if(1<b.length&&" "===f)if("#"===d)r(a,2),a=m.$createHeadingNode("h1"),b=c.getChildren(),a.append(...b),c.replace(a);else if(">"===d)r(a,2),a=p.$createQuoteNode(),b=c.getChildren(),a.append(...b),c.replace(a);else{if("-"===d||"*"===d)r(a,2),a=n.$createListNode("ul"),b=k.$createListItemNode(),d=c.getChildren(),b.append(...d),a.append(b),c.replace(a)}else 2<
|
|
3
|
-
b.length&&("#"===d&&"#"===f&&" "===l?(r(a,3),a=m.$createHeadingNode("h2"),b=c.getChildren(),a.append(...b),c.replace(a)):parseInt(d,10)?(b=b.match(/^(\d+)\.\s/),null!==b&&0===b.index&&2===b.length&&(d=parseInt(b[1],10),r(a,b[0].length),a=n.$createListNode("ol",d),b=k.$createListItemNode(),d=c.getChildren(),b.append(...d),a.append(b),c.replace(a))):"`"===d&&"`"===f&&"`"===l&&(r(a,3),a=q.$createCodeNode(),a.append(...c.getChildren()),c.replace(a)))}}
|
|
4
|
-
module.exports=function(a){e.useEffect(()=>a.addTransform(g.TextNode,t),[a])};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
'use strict';var b=require("react"),f=require("lexical");const g="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,l=g&&"documentMode"in document?document.documentMode:null;g&&/Win/.test(navigator.platform);g&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;g&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);g&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);g&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
|
|
2
|
-
g&&/^(?=.*Chrome).*/i.test(navigator.userAgent);g&&"InputEvent"in window&&!l?"getTargetRanges"in new window.InputEvent("input"):!1;var m=g?b.useLayoutEffect:b.useEffect;function n(a,e=!0){if(a)return!1;a=f.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
|
|
3
|
-
function p(a){if(!n(a,!1))return!1;a=f.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let d=0;d<e;d++){var c=a[d];if(f.$isElementNode(c)){if("paragraph"!==c.__type||0!==c.__indent)return!1;c=c.getChildren();const h=c.length;for(let k=0;k<h;k++)if(!f.$isTextNode(c[d]))return!1}}return!0}function q(a){return()=>p(a)}
|
|
4
|
-
module.exports=function(a){const [e,c]=b.useState(a.getEditorState().read(q(a.isComposing())));m(()=>a.addListener("update",({editorState:d})=>{const h=a.isComposing();d=d.read(q(h));c(d)}),[a]);return e};
|
package/useLexicalDecorators.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var a=require("react-dom"),d=require("react");const h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,l=h&&"documentMode"in document?document.documentMode:null;h&&/Win/.test(navigator.platform);h&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;h&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);h&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);h&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
|
|
2
|
-
h&&/^(?=.*Chrome).*/i.test(navigator.userAgent);h&&"InputEvent"in window&&!l?"getTargetRanges"in new window.InputEvent("input"):!1;var m=h?d.useLayoutEffect:d.useEffect;module.exports=function(b){const [f,n]=d.useState(()=>b.getDecorators());m(()=>b.addListener("decorator",e=>{a.flushSync(()=>{n(e)})}),[b]);return d.useMemo(()=>{const e=[],k=Object.keys(f);for(let g=0;g<k.length;g++){var c=k[g];const p=f[c];c=b.getElementByKey(c);null!==c&&e.push(a.createPortal(p,c))}return e},[f,b])};
|
package/useLexicalEditor.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var a=require("react"),c=require("@lexical/react/useLexicalCanShowPlaceholder");const e="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,f=e&&"documentMode"in document?document.documentMode:null;e&&/Win/.test(navigator.platform);e&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;e&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);e&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);e&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
|
|
2
|
-
e&&/^(?=.*Chrome).*/i.test(navigator.userAgent);e&&"InputEvent"in window&&!f?"getTargetRanges"in new window.InputEvent("input"):!1;var g=e?a.useLayoutEffect:a.useEffect;module.exports=function(b,d){const h=c(b),l=a.useCallback(k=>{b.setRootElement(k)},[b]);g(()=>b.addListener("error",d),[b,d]);return[l,h]};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
'use strict';var a=require("react");const h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,k=h&&"documentMode"in document?document.documentMode:null;h&&/Win/.test(navigator.platform);h&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;h&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);h&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);h&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);h&&/^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
2
|
-
h&&"InputEvent"in window&&!k?"getTargetRanges"in new window.InputEvent("input"):!1;var q=h?a.useLayoutEffect:a.useEffect;function r(b,c){return"selectionchange"===b||"keyup"===b||"pointerup"===b||"pointercancel"===b?c.ownerDocument:c}
|
|
3
|
-
module.exports=function(b,c){q(()=>{const l=[],m=[];for(let e=0;e<b.length;e++){const [d,f]=b[e],p=g=>{const n=c.getRootElement();null!==n&&"true"===n.contentEditable&&f(g,c)};l.push(g=>{r(d,g).addEventListener(d,p)});m.push(g=>{r(d,g).removeEventListener(d,p)})}return c.addListener("root",(e,d)=>{null!==d&&m.forEach(f=>f(d));null!==e&&l.forEach(f=>f(e))})},[c,b])};
|
package/useLexicalHistory.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
'use strict';var n=require("lexical"),r=require("react"),v=require("@lexical/react/withSubscriptions");function w(a,b,f){b=Array.from(b);f=Array.from(f);a=a._nodeMap;const c=[];for(var h=0;h<b.length;h++){const e=a.get(b[h]);void 0!==e&&c.push(e)}for(b=0;b<f.length;b++)f[b][1]&&(h=a.get(f[b][0]),void 0===h||n.$isRootNode(h)||c.push(h));return c}
|
|
2
|
-
function x(a,b,f,c,h){if(null===a||0===f.size&&0===c.size)return 0;var e=b._selection,d=a._selection;if(h)return 1;if(null===e||null===d||!d.isCollapsed()||!e.isCollapsed())return 0;f=w(b,f,c);if(0===f.length)return 0;if(1<f.length){b=b._nodeMap;d=b.get(d.anchor.key);const g=b.get(e.anchor.key);return n.$isTextNode(g)&&n.$isElementNode(d)&&!a._nodeMap.has(g.__key)&&1===g.__text.length&&1===e.anchor.offset?f.every(k=>k===g||!n.$isTextNode(k))?2:0:0}b=f[0];a=a._nodeMap.get(b.__key);if(!n.$isTextNode(a)||
|
|
3
|
-
!n.$isTextNode(b)||a.__mode!==b.__mode)return 0;a=a.__text;b=b.__text;if(a===b)return 0;e=e.anchor;d=d.anchor;if(e.key!==d.key||"text"!==e.type)return 0;e=e.offset;d=d.offset;a=b.length-a.length;return 1===a&&d===e-1?2:-1===a&&d===e+1?3:-1===a&&d===e?4:0}
|
|
4
|
-
function y(a,b){let f=Date.now(),c=0;return(h,e,d,g,k,m)=>{const p=Date.now();if(m.has("historic"))return c=0,f=p,2;const l=x(h,e,g,k,a.isComposing()),u=(()=>{if(m.has("without-history"))return 0;if(null===h)return 1;var q=e._selection;const t=h._selection;if(!(0<g.size||0<k.size))return null===t&&null!==q?0:2;q=null===d||d.editor===a;return 0!==l&&l===c&&p<f+b&&q?0:1})();f=p;c=l;return u}}function z(){return{current:null,redoStack:[],undoStack:[]}}exports.createEmptyHistoryState=z;
|
|
5
|
-
exports.useLexicalHistory=function(a,b,f=1E3){const c=r.useMemo(()=>b||z(),[b]),h=r.useCallback(()=>{c.undoStack=[];c.redoStack=[];c.current=null},[c]);r.useEffect(()=>{const e=y(a,f);return v(a.addListener("command",d=>{switch(d){case "undo":d=c.redoStack;var g=c.undoStack;if(0!==g.length){var k=c.current;const m=g.pop();null!==k&&(d.push(k),a.execCommand("canRedo",!0));0===g.length&&a.execCommand("canUndo",!1);c.current=m;m.editor.setEditorState(m.editorState.clone(m.undoSelection),{tag:"historic"})}return!0;
|
|
6
|
-
case "redo":return d=c.redoStack,g=c.undoStack,0!==d.length&&(k=c.current,null!==k&&(g.push(k),a.execCommand("canUndo",!0)),g=d.pop(),0===d.length&&a.execCommand("canRedo",!1),c.current=g,g.editor.setEditorState(g.editorState,{tag:"historic"})),!0;case "clearEditor":case "clearHistory":return h(),!0;default:return!1}},0),a.addListener("update",({editorState:d,prevEditorState:g,dirtyLeaves:k,dirtyElements:m,tags:p})=>{const l=c.current,u=c.redoStack,q=c.undoStack,t=null===l?null:l.editorState;if(null===
|
|
7
|
-
l||d!==t){k=e(g,d,l,k,m,p);if(1===k)0!==u.length&&(c.redoStack=[]),null!==l&&(q.push({...l,undoSelection:g.read(n.$getSelection)}),a.execCommand("canUndo",!0));else if(2===k)return;c.current={editor:a,editorState:d}}}))},[h,f,a,c])};
|
package/useLexicalPlainText.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';var h=require("lexical"),q=require("react"),v=require("lexical/ParagraphNode"),w=require("@lexical/react/withSubscriptions");const x="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,y=x&&"documentMode"in document?document.documentMode:null;x&&/Win/.test(navigator.platform);x&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;const z=x&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),A=x&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
2
|
-
x&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);x&&/^(?=.*Chrome).*/i.test(navigator.userAgent);const B=x&&"InputEvent"in window&&!y?"getTargetRanges"in new window.InputEvent("input"):!1;var C=x?q.useLayoutEffect:q.useEffect;function D(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
|
|
3
|
-
function E(a,b){C(()=>{const c=[],e=[];for(let d=0;d<a.length;d++){const [f,g]=a[d],k=l=>{const n=b.getRootElement();null!==n&&"true"===n.contentEditable&&g(l,b)};c.push(l=>{D(f,l).addEventListener(f,k)});e.push(l=>{D(f,l).removeEventListener(f,k)})}return b.addListener("root",(d,f)=>{null!==f&&e.forEach(g=>g(f));null!==d&&c.forEach(g=>g(d))})},[b,a])}
|
|
4
|
-
function F(a,b){const c=b.split(/\r?\n/);if(1===c.length)a.insertText(b);else{b=[];const e=c.length;for(let d=0;d<e;d++){const f=c[d];""!==f&&b.push(h.$createTextNode(f));d!==e-1&&b.push(h.$createLineBreakNode())}a.insertNodes(b)}}
|
|
5
|
-
function G(a){q.useEffect(()=>{const b=c=>{var e=a.getRootElement();if(document.activeElement===e&&(e=c.data,"string"===typeof e)){try{var d=JSON.parse(e)}catch(f){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [f,g,k,l,n]=d;a.update(()=>{h.$log("useLexicalDragonSupport");const u=h.$getSelection();if(null!==u){var m=u.anchor;let r=m.getNode(),p=0,t=0;h.$isTextNode(r)&&0<=f&&0<=g&&(p=f,t=f+g,u.setTextNodeRange(r,p,r,
|
|
6
|
-
t));if(p!==t||""!==k)F(u,k),r=m.getNode();h.$isTextNode(r)&&(p=l,t=l+n,m=r.getTextContentSize(),p=p>m?m:p,t=t>m?m:t,u.setTextNodeRange(r,p,r,t));c.stopImmediatePropagation()}})}}};window.addEventListener("message",b,!0);return()=>{window.removeEventListener("message",b,!0)}},[a])}function H(a){return a.isToken()||a.isInert()}let I=!1;function J(a,b){a=a.getData("text/plain");null!=a&&F(b,a)}
|
|
7
|
-
function K(a,b){var c=a.focus;a=c.offset;"element"===c.type?b=c.getNode().getChildAtIndex(b?a-1:a):(c=c.getNode(),b=b&&0===a||!b&&a===c.getTextContentSize()?b?c.getPreviousSibling():c.getNextSibling():null);return h.$isDecoratorNode(b)}function L(a){a.preventDefault()}
|
|
8
|
-
function M(a,b){a.preventDefault();b.update(()=>{h.$log("onCopyForPlainText");const c=a.clipboardData,e=h.$getSelection();if(null!==e&&null!=c){var d=window.getSelection();if(!d.isCollapsed){var f=d.getRangeAt(0);f&&(d=document.createElement("div"),f=f.cloneContents(),d.appendChild(f),c.setData("text/html",d.innerHTML));c.setData("text/plain",e.getTextContent())}}})}function N(a,b){b.update(()=>{h.$log("onCompositionEnd");h.$setCompositionKey(null);O(b,!0)})}
|
|
9
|
-
function P(a){return a.getEditorState().read(()=>h.$getSelection())}
|
|
10
|
-
function Q(a,b,c,e,d){if(a.isAttached()&&(d||!a.isDirty())){const f=a.isComposing();let g=b;(f||d)&&"\u00a0"===b[b.length-1]&&(g=b.slice(0,-1));if(d||g!==a.getTextContent())""===g?(f&&h.$setCompositionKey(null),a.remove()):H(a)||null!==h.$getCompositionKey()&&!f?a.markDirty():(b=h.$getSelection(),null!==b&&null!==c&&null!==e&&(b.setTextNodeRange(a,c,a,e),a.isSegmented()&&(c=a.getTextContent(),c=h.$createTextNode(c),a.replace(c),a=c)),a.setTextContent(g))}}
|
|
11
|
-
function R(a,b,c){var e=a.anchor;const d=a.focus;var f=e.getNode();(b=e.key!==d.key||e.offset!==d.offset&&!f.isComposing()||(c||f.isDirty())&&1<b.length||!h.$isTextNode(f)||f.getFormat()!==a.format)||(f.isSegmented()?b=!0:a.isCollapsed()?(b=a.anchor.offset,c=f.getParentOrThrow(),e=f.isToken(),a=0===b&&(!f.canInsertTextBefore()||!c.canInsertTextBefore()||e),f=f.getTextContentSize()===b&&(!f.canInsertTextBefore()||!c.canInsertTextBefore()||e),b=a||f):b=!1);return b}
|
|
12
|
-
function S(a,b){const c=a.inputType;"deleteCompositionText"!==c&&"insertCompositionText"!==c&&b.update(()=>{h.$log("onBeforeInputForRichText");const e=h.$getSelection();if(null!==e)if("deleteContentBackward"===c)h.$setCompositionKey(null),a.preventDefault(),b.execCommand("deleteCharacter",!0);else{var d=a.data;if(!e.dirty&&e.isCollapsed()&&a.getTargetRanges){var f=a.getTargetRanges()[0];f&&e.applyDOMRange(f)}var g=e.focus;f=e.anchor.getNode();g=g.getNode();if("insertText"===c)"\n"===d?(a.preventDefault(),
|
|
13
|
-
b.execCommand("insertLineBreak")):"\n\n"===d?(a.preventDefault(),b.execCommand("insertParagraph")):null==d&&a.dataTransfer?(d=a.dataTransfer.getData("text/plain"),a.preventDefault(),F(e,d)):null!=d&&R(e,d,!0)&&(a.preventDefault(),b.execCommand("insertText",d));else switch(a.preventDefault(),c){case "insertFromComposition":d&&(h.$setCompositionKey(null),b.execCommand("insertText",d));break;case "insertLineBreak":h.$setCompositionKey(null);b.execCommand("insertLineBreak");break;case "insertParagraph":h.$setCompositionKey(null);
|
|
14
|
-
b.execCommand("insertParagraph");break;case "insertFromYank":case "insertFromDrop":case "insertReplacementText":case "insertFromPaste":f=a.dataTransfer;null!=f?J(f,e):d&&b.execCommand("insertText",d);break;case "deleteByComposition":f===g&&!h.$isElementNode(f)&&!h.$isElementNode(g)&&H(f)&&H(g)||b.execCommand("removeText");break;case "deleteByDrag":case "deleteByCut":b.execCommand("removeText");break;case "deleteContent":b.execCommand("deleteCharacter",!1);break;case "deleteWordBackward":b.execCommand("deleteWord",
|
|
15
|
-
!0);break;case "deleteWordForward":b.execCommand("deleteWord",!1);break;case "deleteHardLineBackward":case "deleteSoftLineBackward":b.execCommand("deleteLine",!0);break;case "deleteContentForward":case "deleteHardLineForward":case "deleteSoftLineForward":b.execCommand("deleteLine",!1);break;case "formatStrikeThrough":b.execCommand("formatText","strikethrough");break;case "formatBold":b.execCommand("formatText","bold");break;case "formatItalic":b.execCommand("formatText","italic");break;case "formatUnderline":b.execCommand("formatText",
|
|
16
|
-
"underline");break;case "historyUndo":b.execCommand("undo");break;case "historyRedo":b.execCommand("redo")}}})}function O(a,b){a=window.getSelection();if(null!==a){var {anchorNode:c,anchorOffset:e,focusOffset:d}=a;null!==c&&3===c.nodeType&&(a=h.$getNearestNodeFromDOMNode(c),h.$isTextNode(a)&&Q(a,c.nodeValue,e,d,b))}}function T(a){Q(a.node,a.text,a.anchorOffset,a.focusOffset,!1)}
|
|
17
|
-
const U=[["selectionchange",function(a,b){a=window.getSelection();const c=b.getRootElement();c&&!c.contains(a.anchorNode)||b.update(()=>{h.$log("onSelectionChange");const e=h.$getSelection();if(null!==e&&e.isCollapsed()){var d=e.anchor;"text"===d.type?(d=d.getNode(),e.format=d.getFormat()):"element"===d.type&&(e.format=0)}b.execCommand("selectionChange")})}],["keydown",function(a,b){I="Unidentified"===a.key&&229===a.keyCode;b.isComposing()||b.update(()=>{h.$log("onKeyDown");if(null!==h.$getSelection()){var {keyCode:c,
|
|
18
|
-
shiftKey:e,ctrlKey:d,metaKey:f,altKey:g}=a;if(39!==c||d||f||g)if(37!==c||d||f||g)if(38!==c||d||f||g)if(40!==c||d||f||g)if(13===c&&e)b.execCommand("keyEnter",a);else if(z&&d&&79===c)a.preventDefault(),b.execCommand("insertLineBreak",!0);else if(13!==c||e){var k=z?g||f?!1:8===c||72===c&&d:d||g||f?!1:8===c;k?8===c?b.execCommand("keyBackspace",a):b.execCommand("deleteCharacter",!0):(k=z?e||g||f?!1:46===c||68===c&&d:d||g||f?!1:46===c,k?46===c?b.execCommand("keyDelete",a):b.execCommand("deleteCharacter",
|
|
19
|
-
!1):8===c&&(z?g:d)?(a.preventDefault(),b.execCommand("deleteWord",!0)):46===c&&(z?g:d)?(a.preventDefault(),b.execCommand("deleteWord",!1)):z&&f&&8===c?(a.preventDefault(),b.execCommand("deleteLine",!0)):z&&f&&46===c?(a.preventDefault(),b.execCommand("deleteLine",!1)):66===c&&(z?f:d)?(a.preventDefault(),b.execCommand("formatText","bold")):85===c&&(z?f:d)?(a.preventDefault(),b.execCommand("formatText","underline")):73===c&&(z?f:d)?(a.preventDefault(),b.execCommand("formatText","italic")):9!==c||g||
|
|
20
|
-
d||f?90===c&&!e&&(z?f:d)?(a.preventDefault(),b.execCommand("undo")):(k=z?90===c&&f&&e:89===c&&d||90===c&&d&&e,k&&(a.preventDefault(),b.execCommand("redo"))):b.execCommand("keyTab",a))}else b.execCommand("keyEnter",a);else b.execCommand("keyArrowDown",a);else b.execCommand("keyArrowUp",a);else b.execCommand("keyArrowLeft",a);else b.execCommand("keyArrowRight",a)}})}],["compositionstart",function(a,b){b.update(()=>{h.$log("onCompositionStart");const c=h.$getSelection();if(null!==c&&!b.isComposing()){const e=
|
|
21
|
-
c.anchor;h.$setCompositionKey(e.key);null==a.data||I&&"element"!==e.type&&c.isCollapsed()||b.execCommand("insertText"," ")}})}],["compositionend",function(a,b){A?setTimeout(()=>{N(a,b)},0):N(a,b)}],["cut",function(a,b){M(a,b);b.update(()=>{h.$log("onCutForPlainText");const c=h.$getSelection();null!==c&&c.removeText()})}],["copy",M],["dragstart",function(a){a.preventDefault()}],["paste",function(a,b){a.preventDefault();b.update(()=>{h.$log("onPasteForPlainText");const c=h.$getSelection(),e=a.clipboardData;
|
|
22
|
-
null!=e&&null!==c&&J(e,c)})}],["input",function(a,b){a.stopPropagation();b.update(()=>{h.$log("onInput");const c=h.$getSelection(),e=a.data;null!=e&&null!==c&&R(c,e,!1)?b.execCommand("insertText",e):O(b,!1);h.$flushMutations()})}],["click",function(a,b){b.update(()=>{h.$log("onClick");const c=h.$getSelection();if(null!==c){var e=c.anchor;"element"===e.type&&0===e.offset&&c.isCollapsed()&&1===h.$getRoot().getChildrenSize()&&e.getNode().getTopLevelElementOrThrow().isEmpty()&&(e=P(b),null!==e&&c.is(e)&&
|
|
23
|
-
(window.getSelection().removeAllRanges(),c.dirty=!0))}})}]];B?U.push(["beforeinput",S]):U.push(["drop",L]);function V(a,b){const c=v.$createParagraphNode();a.append(c);a=document.activeElement;(null!==h.$getSelection()||null!==a&&a===b.getRootElement())&&c.select()}function W(a){a.update(()=>{h.$log("initEditor");const b=h.$getRoot();null===b.getFirstChild()&&V(b,a)})}function X(a,b){a.update(()=>{h.$log("clearEditor");const c=h.$getRoot();c.clear();V(c,a)},{onUpdate:b})}
|
|
24
|
-
function Y(a,b){C(()=>{const c=w(a.registerNodes([v.ParagraphNode]),a.addListener("textmutation",T),a.addListener("command",(e,d)=>{const f=h.$getSelection();if(null===f)return!1;switch(e){case "deleteCharacter":return f.deleteCharacter(d),!0;case "deleteWord":return f.deleteWord(d),!0;case "deleteLine":return f.deleteLine(d),!0;case "insertText":return f.insertText(d),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(d),!0;case "insertParagraph":return f.insertLineBreak(),
|
|
25
|
-
!0;case "indentContent":case "outdentContent":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":e=d.shiftKey;if(K(f,!0))return d.preventDefault(),d=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(d?"extend":"move",!e,"character"),!0;break;case "keyArrowRight":e=d.shiftKey;if(K(f,!1))return d.preventDefault(),d=e,e="rtl"===f.anchor.getNode().getParentOrThrow().getDirection(),f.modify(d?"extend":"move",e,"character"),
|
|
26
|
-
!0;break;case "keyBackspace":return d.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return d.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return d.preventDefault(),a.execCommand("insertLineBreak");case "clearEditor":X(a)}return!1},0));b&&W(a);return c},[a,b]);E(U,a);G(a)}
|
|
27
|
-
function Z(a,b,c){b=Array.from(b);c=Array.from(c);a=a._nodeMap;const e=[];for(var d=0;d<b.length;d++){const f=a.get(b[d]);void 0!==f&&e.push(f)}for(b=0;b<c.length;b++)c[b][1]&&(d=a.get(c[b][0]),void 0===d||h.$isRootNode(d)||e.push(d));return e}
|
|
28
|
-
function aa(a,b,c,e,d){if(null===a||0===c.size&&0===e.size)return 0;var f=b._selection,g=a._selection;if(d)return 1;if(null===f||null===g||!g.isCollapsed()||!f.isCollapsed())return 0;c=Z(b,c,e);if(0===c.length)return 0;if(1<c.length){b=b._nodeMap;g=b.get(g.anchor.key);const k=b.get(f.anchor.key);return h.$isTextNode(k)&&h.$isElementNode(g)&&!a._nodeMap.has(k.__key)&&1===k.__text.length&&1===f.anchor.offset?c.every(l=>l===k||!h.$isTextNode(l))?2:0:0}b=c[0];a=a._nodeMap.get(b.__key);if(!h.$isTextNode(a)||
|
|
29
|
-
!h.$isTextNode(b)||a.__mode!==b.__mode)return 0;a=a.__text;b=b.__text;if(a===b)return 0;f=f.anchor;g=g.anchor;if(f.key!==g.key||"text"!==f.type)return 0;f=f.offset;g=g.offset;a=b.length-a.length;return 1===a&&g===f-1?2:-1===a&&g===f+1?3:-1===a&&g===f?4:0}
|
|
30
|
-
function ba(a,b){let c=Date.now(),e=0;return(d,f,g,k,l,n)=>{const u=Date.now();if(n.has("historic"))return e=0,c=u,2;const m=aa(d,f,k,l,a.isComposing()),r=(()=>{if(n.has("without-history"))return 0;if(null===d)return 1;var p=f._selection;const t=d._selection;if(!(0<k.size||0<l.size))return null===t&&null!==p?0:2;p=null===g||g.editor===a;return 0!==m&&m===e&&u<c+b&&p?0:1})();c=u;e=m;return r}}
|
|
31
|
-
function ca(a,b,c=1E3){const e=q.useMemo(()=>b||{current:null,redoStack:[],undoStack:[]},[b]),d=q.useCallback(()=>{e.undoStack=[];e.redoStack=[];e.current=null},[e]);q.useEffect(()=>{const f=ba(a,c);return w(a.addListener("command",g=>{switch(g){case "undo":g=e.redoStack;var k=e.undoStack;if(0!==k.length){var l=e.current;const n=k.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===k.length&&a.execCommand("canUndo",!1);e.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
|
|
32
|
-
{tag:"historic"})}return!0;case "redo":return g=e.redoStack,k=e.undoStack,0!==g.length&&(l=e.current,null!==l&&(k.push(l),a.execCommand("canUndo",!0)),k=g.pop(),0===g.length&&a.execCommand("canRedo",!1),e.current=k,k.editor.setEditorState(k.editorState,{tag:"historic"})),!0;case "clearEditor":case "clearHistory":return d(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:k,dirtyLeaves:l,dirtyElements:n,tags:u})=>{const m=e.current,r=e.redoStack,p=e.undoStack,t=null===
|
|
33
|
-
m?null:m.editorState;if(null===m||g!==t){l=f(k,g,m,l,n,u);if(1===l)0!==r.length&&(e.redoStack=[]),null!==m&&(p.push({...m,undoSelection:k.read(h.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;e.current={editor:a,editorState:g}}}))},[d,c,a,e])}module.exports=function(a,b){Y(a,!0);ca(a,b)};
|
package/useLexicalRichText.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
'use strict';var h=require("lexical"),u=require("react"),v=require("lexical/HeadingNode"),x=require("lexical/ListNode"),y=require("lexical/QuoteNode"),A=require("lexical/CodeNode"),B=require("lexical/ParagraphNode"),C=require("lexical/ListItemNode"),D=require("lexical/LinkNode"),E=require("@lexical/react/withSubscriptions");
|
|
2
|
-
const F="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,G=F&&"documentMode"in document?document.documentMode:null;F&&/Win/.test(navigator.platform);F&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;const H=F&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),I=F&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);F&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);F&&/^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
3
|
-
const aa=F&&"InputEvent"in window&&!G?"getTargetRanges"in new window.InputEvent("input"):!1;var J=F?u.useLayoutEffect:u.useEffect;function K(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
|
|
4
|
-
function ba(a,b){J(()=>{const f=[],d=[];for(let e=0;e<a.length;e++){const [c,g]=a[e],k=l=>{const m=b.getRootElement();null!==m&&"true"===m.contentEditable&&g(l,b)};f.push(l=>{K(c,l).addEventListener(c,k)});d.push(l=>{K(c,l).removeEventListener(c,k)})}return b.addListener("root",(e,c)=>{null!==c&&d.forEach(g=>g(c));null!==e&&f.forEach(g=>g(e))})},[b,a])}
|
|
5
|
-
function L(a){a=a.getLatest();const b=a.constructor.clone(a);b.__parent=a.__parent;h.$isElementNode(a)&&h.$isElementNode(b)?(b.__children=Array.from(a.__children),b.__format=a.__format,b.__indent=a.__indent,b.__dir=a.__dir):h.$isTextNode(a)&&h.$isTextNode(b)?(b.__format=a.__format,b.__style=a.__style,b.__mode=a.__mode,b.__detail=a.__detail):h.$isDecoratorNode(a)&&h.$isDecoratorNode(b)&&(b.__ref=a.__ref);return b}
|
|
6
|
-
function M(a,b,f,d,e){for(var c=b;null!==a;){for(b=a.getParent();null!==b&&b.excludeFromCopy();)b=b.getParent();if(null===b)break;if(!h.$isElementNode(a)||!a.excludeFromCopy()){const g=a.getKey();let k=e.get(g);const l=void 0===k;l&&(k=L(a),e.set(g,k));!h.$isTextNode(k)||k.isSegmented()||k.isToken()?h.$isElementNode(k)&&(k.__children=k.__children.slice(f?c:0,f?void 0:c+1)):k.__text=k.__text.slice(f?c:0,f?void 0:c);if(h.$isRootNode(b)){l&&d.push(g);break}}c=e.get(b.getKey());c=h.$isElementNode(c)?
|
|
7
|
-
c.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=b}}function N(a,b){const f=b.split(/\r?\n/);if(1===f.length)a.insertText(b);else{b=[];const d=f.length;for(let e=0;e<d;e++){const c=f[e];""!==c&&b.push(h.$createTextNode(c));e!==d-1&&b.push(h.$createLineBreakNode())}a.insertNodes(b)}}
|
|
8
|
-
function ca(a){u.useEffect(()=>{const b=f=>{var d=a.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var e=JSON.parse(d)}catch(c){return}if(e&&"nuanria_messaging"===e.protocol&&"request"===e.type&&(e=e.payload)&&"makeChanges"===e.functionId&&(e=e.args)){const [c,g,k,l,m]=e;a.update(()=>{h.$log("useLexicalDragonSupport");const p=h.$getSelection();if(null!==p){var n=p.anchor;let r=n.getNode(),q=0,t=0;h.$isTextNode(r)&&0<=c&&0<=g&&(q=c,t=c+g,p.setTextNodeRange(r,q,
|
|
9
|
-
r,t));if(q!==t||""!==k)N(p,k),r=n.getNode();h.$isTextNode(r)&&(q=l,t=l+m,n=r.getTextContentSize(),q=q>n?n:q,t=t>n?n:t,p.setTextNodeRange(r,q,r,t));f.stopImmediatePropagation()}})}}};window.addEventListener("message",b,!0);return()=>{window.removeEventListener("message",b,!0)}},[a])}function O(a){return a.isToken()||a.isInert()}const da={bold:1,underline:8,strikethrough:4,italic:2,code:16,subscript:32,superscript:64};let P=!1;
|
|
10
|
-
const ea={ul:()=>({node:x.$createListNode("ul")}),ol:()=>({node:x.$createListNode("ol")}),li:()=>({node:C.$createListItemNode()}),h1:()=>({node:v.$createHeadingNode("h1")}),h2:()=>({node:v.$createHeadingNode("h2")}),h3:()=>({node:v.$createHeadingNode("h3")}),h4:()=>({node:v.$createHeadingNode("h4")}),h5:()=>({node:v.$createHeadingNode("h5")}),p:()=>({node:B.$createParagraphNode()}),br:()=>({node:h.$createLineBreakNode()}),a:a=>({node:a instanceof HTMLAnchorElement?D.$createLinkNode(a.href):h.$createTextNode(a.textContent)}),
|
|
11
|
-
u:()=>({node:null,format:"underline"}),b:()=>({node:null,format:"bold"}),strong:()=>({node:null,format:"bold"}),i:()=>({node:null,format:"italic"}),em:()=>({node:null,format:"italic"}),"#text":a=>({node:h.$createTextNode(a.textContent)})};
|
|
12
|
-
function Q(a,b,f,d){let e=[],c=null;var g=a.nodeName.toLowerCase();g=(g=(f._config.htmlTransforms||{})[g]||b[g])?g(a):null;null!==g&&(c=g.node,g.format&&(g=da[g.format],d=d?d^g:g),null!==c&&(h.$isTextNode(c)&&void 0!==d&&c.setFormat(d),e.push(c)));a=a.childNodes;for(g=0;g<a.length;g++){const k=Q(a[g],b,f,d);h.$isElementNode(c)?c.append(...k):null===c&&(e=e.concat(k))}return e}function R(a,b){a=a.getData("text/plain");null!=a&&N(b,a)}
|
|
13
|
-
function S(a,b){var f=a.focus;a=f.offset;"element"===f.type?b=f.getNode().getChildAtIndex(b?a-1:a):(f=f.getNode(),b=b&&0===a||!b&&a===f.getTextContentSize()?b?f.getPreviousSibling():f.getNextSibling():null);return h.$isDecoratorNode(b)}function fa(a){a.preventDefault()}
|
|
14
|
-
function T(a,b){a.preventDefault();b.update(()=>{h.$log("onCopyForRichText");const f=a.clipboardData;var d=h.$getSelection();if(null!==d&&null!=f){var e=window.getSelection();if(!e.isCollapsed){var c=e.getRangeAt(0);c&&(e=document.createElement("div"),c=c.cloneContents(),e.appendChild(c),f.setData("text/html",e.innerHTML));f.setData("text/plain",d.getTextContent());e=f.setData;c=JSON;var g=c.stringify;{var k=d.anchor,l=d.focus;var m=k.getCharacterOffset();const z=l.getCharacterOffset();var p=k.getNode(),
|
|
15
|
-
n=l.getNode(),r=p.getParentOrThrow();if(p===n&&h.$isTextNode(p)&&(r.canBeEmpty()||1<r.getChildrenSize()))d=L(p),p=z>m,d.__text=d.__text.slice(p?m:z,p?z:m),m=d.getKey(),m={range:[m],nodeMap:[[m,d]]};else if(d=d.getNodes(),0===d.length)m={range:[],nodeMap:[]};else{p=d.length;n=d[0];r=n.getParent();if(null!==r&&!r.canBeEmpty()){var q=r.__children;if(q.length===p){var t=!0;for(var w=0;w<q.length;w++)if(q[w]!==d[w].__key){t=!1;break}t&&(p++,d.push(r))}}r=d[p-1];k=k.isBefore(l);l=new Map;q=[];M(n,k?m:z,
|
|
16
|
-
!0,q,l);for(n=0;n<p;n++)if(t=d[n],w=t.getKey(),!(l.has(w)||h.$isElementNode(t)&&t.excludeFromCopy())){const ha=L(t);h.$isRootNode(t.getParent())&&q.push(t.getKey());l.set(w,ha)}M(r,k?z:m,!1,q,l);m={range:q,nodeMap:Array.from(l.entries())}}}e.call(f,"application/x-lexical-nodes",g.call(c,m))}}})}function U(a,b){b.update(()=>{h.$log("onCompositionEnd");h.$setCompositionKey(null);V(b,!0)})}function ia(a){return a.getEditorState().read(()=>h.$getSelection())}
|
|
17
|
-
function W(a,b,f,d,e){if(a.isAttached()&&(e||!a.isDirty())){const c=a.isComposing();let g=b;(c||e)&&"\u00a0"===b[b.length-1]&&(g=b.slice(0,-1));if(e||g!==a.getTextContent())""===g?(c&&h.$setCompositionKey(null),a.remove()):O(a)||null!==h.$getCompositionKey()&&!c?a.markDirty():(b=h.$getSelection(),null!==b&&null!==f&&null!==d&&(b.setTextNodeRange(a,f,a,d),a.isSegmented()&&(f=a.getTextContent(),f=h.$createTextNode(f),a.replace(f),a=f)),a.setTextContent(g))}}
|
|
18
|
-
function X(a,b,f){var d=a.anchor;const e=a.focus;var c=d.getNode();(b=d.key!==e.key||d.offset!==e.offset&&!c.isComposing()||(f||c.isDirty())&&1<b.length||!h.$isTextNode(c)||c.getFormat()!==a.format)||(c.isSegmented()?b=!0:a.isCollapsed()?(b=a.anchor.offset,f=c.getParentOrThrow(),d=c.isToken(),a=0===b&&(!c.canInsertTextBefore()||!f.canInsertTextBefore()||d),c=c.getTextContentSize()===b&&(!c.canInsertTextBefore()||!f.canInsertTextBefore()||d),b=a||c):b=!1);return b}
|
|
19
|
-
function ja(a,b){const f=a.inputType;"deleteCompositionText"!==f&&"insertCompositionText"!==f&&b.update(()=>{h.$log("onBeforeInputForRichText");const d=h.$getSelection();if(null!==d)if("deleteContentBackward"===f)h.$setCompositionKey(null),a.preventDefault(),b.execCommand("deleteCharacter",!0);else{var e=a.data;if(!d.dirty&&d.isCollapsed()&&a.getTargetRanges){var c=a.getTargetRanges()[0];c&&d.applyDOMRange(c)}var g=d.focus;c=d.anchor.getNode();g=g.getNode();if("insertText"===f)"\n"===e?(a.preventDefault(),
|
|
20
|
-
b.execCommand("insertLineBreak")):"\n\n"===e?(a.preventDefault(),b.execCommand("insertParagraph")):null==e&&a.dataTransfer?(e=a.dataTransfer.getData("text/plain"),a.preventDefault(),N(d,e)):null!=e&&X(d,e,!0)&&(a.preventDefault(),b.execCommand("insertText",e));else switch(a.preventDefault(),f){case "insertFromComposition":e&&(h.$setCompositionKey(null),b.execCommand("insertText",e));break;case "insertLineBreak":h.$setCompositionKey(null);b.execCommand("insertLineBreak");break;case "insertParagraph":h.$setCompositionKey(null);
|
|
21
|
-
b.execCommand("insertParagraph");break;case "insertFromYank":case "insertFromDrop":case "insertReplacementText":case "insertFromPaste":c=a.dataTransfer;null!=c?R(c,d):e&&b.execCommand("insertText",e);break;case "deleteByComposition":c===g&&!h.$isElementNode(c)&&!h.$isElementNode(g)&&O(c)&&O(g)||b.execCommand("removeText");break;case "deleteByDrag":case "deleteByCut":b.execCommand("removeText");break;case "deleteContent":b.execCommand("deleteCharacter",!1);break;case "deleteWordBackward":b.execCommand("deleteWord",
|
|
22
|
-
!0);break;case "deleteWordForward":b.execCommand("deleteWord",!1);break;case "deleteHardLineBackward":case "deleteSoftLineBackward":b.execCommand("deleteLine",!0);break;case "deleteContentForward":case "deleteHardLineForward":case "deleteSoftLineForward":b.execCommand("deleteLine",!1);break;case "formatStrikeThrough":b.execCommand("formatText","strikethrough");break;case "formatBold":b.execCommand("formatText","bold");break;case "formatItalic":b.execCommand("formatText","italic");break;case "formatUnderline":b.execCommand("formatText",
|
|
23
|
-
"underline");break;case "historyUndo":b.execCommand("undo");break;case "historyRedo":b.execCommand("redo")}}})}function V(a,b){a=window.getSelection();if(null!==a){var {anchorNode:f,anchorOffset:d,focusOffset:e}=a;null!==f&&3===f.nodeType&&(a=h.$getNearestNodeFromDOMNode(f),h.$isTextNode(a)&&W(a,f.nodeValue,d,e,b))}}function ka(a){W(a.node,a.text,a.anchorOffset,a.focusOffset,!1)}
|
|
24
|
-
const Y=[["selectionchange",function(a,b){a=window.getSelection();const f=b.getRootElement();f&&!f.contains(a.anchorNode)||b.update(()=>{h.$log("onSelectionChange");const d=h.$getSelection();if(null!==d&&d.isCollapsed()){var e=d.anchor;"text"===e.type?(e=e.getNode(),d.format=e.getFormat()):"element"===e.type&&(d.format=0)}b.execCommand("selectionChange")})}],["keydown",function(a,b){P="Unidentified"===a.key&&229===a.keyCode;b.isComposing()||b.update(()=>{h.$log("onKeyDown");if(null!==h.$getSelection()){var {keyCode:f,
|
|
25
|
-
shiftKey:d,ctrlKey:e,metaKey:c,altKey:g}=a;if(39!==f||e||c||g)if(37!==f||e||c||g)if(38!==f||e||c||g)if(40!==f||e||c||g)if(13===f&&d)b.execCommand("keyEnter",a);else if(H&&e&&79===f)a.preventDefault(),b.execCommand("insertLineBreak",!0);else if(13!==f||d){var k=H?g||c?!1:8===f||72===f&&e:e||g||c?!1:8===f;k?8===f?b.execCommand("keyBackspace",a):b.execCommand("deleteCharacter",!0):(k=H?d||g||c?!1:46===f||68===f&&e:e||g||c?!1:46===f,k?46===f?b.execCommand("keyDelete",a):b.execCommand("deleteCharacter",
|
|
26
|
-
!1):8===f&&(H?g:e)?(a.preventDefault(),b.execCommand("deleteWord",!0)):46===f&&(H?g:e)?(a.preventDefault(),b.execCommand("deleteWord",!1)):H&&c&&8===f?(a.preventDefault(),b.execCommand("deleteLine",!0)):H&&c&&46===f?(a.preventDefault(),b.execCommand("deleteLine",!1)):66===f&&(H?c:e)?(a.preventDefault(),b.execCommand("formatText","bold")):85===f&&(H?c:e)?(a.preventDefault(),b.execCommand("formatText","underline")):73===f&&(H?c:e)?(a.preventDefault(),b.execCommand("formatText","italic")):9!==f||g||
|
|
27
|
-
e||c?90===f&&!d&&(H?c:e)?(a.preventDefault(),b.execCommand("undo")):(k=H?90===f&&c&&d:89===f&&e||90===f&&e&&d,k&&(a.preventDefault(),b.execCommand("redo"))):b.execCommand("keyTab",a))}else b.execCommand("keyEnter",a);else b.execCommand("keyArrowDown",a);else b.execCommand("keyArrowUp",a);else b.execCommand("keyArrowLeft",a);else b.execCommand("keyArrowRight",a)}})}],["compositionstart",function(a,b){b.update(()=>{h.$log("onCompositionStart");const f=h.$getSelection();if(null!==f&&!b.isComposing()){const d=
|
|
28
|
-
f.anchor;h.$setCompositionKey(d.key);null==a.data||P&&"element"!==d.type&&f.isCollapsed()||b.execCommand("insertText"," ")}})}],["compositionend",function(a,b){I?setTimeout(()=>{U(a,b)},0):U(a,b)}],["cut",function(a,b){T(a,b);b.update(()=>{h.$log("onCutForRichText");const f=h.$getSelection();null!==f&&f.removeText()})}],["copy",T],["dragstart",function(a){a.preventDefault()}],["paste",function(a,b){a.preventDefault();b.update(()=>{h.$log("onPasteForRichText");const f=h.$getSelection();var d=a.clipboardData;
|
|
29
|
-
if(null!=d&&null!==f)a:{var e=d.getData("application/x-lexical-nodes");if(e)try{var c=JSON.parse(e);const {range:m,nodeMap:p}=c;var g=new Map(p);e=[];for(c=0;c<m.length;c++){var k=g.get(m[c]);if(void 0!==k){var l=h.$createNodeFromParse(k,g);e.push(l)}}f.insertNodes(e);break a}catch(m){}if(g=d.getData("text/html")){g=(new DOMParser).parseFromString(g,"text/html");d=[];g=g.body?Array.from(g.body.childNodes):[];k=g.length;for(l=0;l<k;l++)e=Q(g[l],ea,b),null!==e&&(d=d.concat(e));g=[];k=null;for(l=0;l<
|
|
30
|
-
d.length;l++)e=d[l],!h.$isElementNode(e)||e.isInline()?(null===k&&(k=B.$createParagraphNode(),g.push(k)),null!==k&&k.append(e)):(g.push(e),k=null);f.insertNodes(g)}else R(d,f)}})}],["input",function(a,b){a.stopPropagation();b.update(()=>{h.$log("onInput");const f=h.$getSelection(),d=a.data;null!=d&&null!==f&&X(f,d,!1)?b.execCommand("insertText",d):V(b,!1);h.$flushMutations()})}],["click",function(a,b){b.update(()=>{h.$log("onClick");const f=h.$getSelection();if(null!==f){var d=f.anchor;"element"===
|
|
31
|
-
d.type&&0===d.offset&&f.isCollapsed()&&1===h.$getRoot().getChildrenSize()&&d.getNode().getTopLevelElementOrThrow().isEmpty()&&(d=ia(b),null!==d&&f.is(d)&&(window.getSelection().removeAllRanges(),f.dirty=!0))}})}]];aa?Y.push(["beforeinput",ja]):Y.push(["drop",fa]);function Z(a,b){const f=B.$createParagraphNode();a.append(f);a=document.activeElement;(null!==h.$getSelection()||null!==a&&a===b.getRootElement())&&f.select()}
|
|
32
|
-
function la(a){a.update(()=>{h.$log("initEditor");const b=h.$getRoot();null===b.getFirstChild()&&Z(b,a)})}function ma(a,b){a.update(()=>{h.$log("clearEditor");const f=h.$getRoot();f.clear();Z(f,a)},{onUpdate:b})}
|
|
33
|
-
function na(a,b){J(()=>{const f=E(a.registerNodes([v.HeadingNode,x.ListNode,y.QuoteNode,A.CodeNode,B.ParagraphNode,C.ListItemNode]),a.addListener("textmutation",ka),a.addListener("command",(d,e)=>{var c=h.$getSelection();if(null===c)return!1;switch(d){case "deleteCharacter":return c.deleteCharacter(e),!0;case "deleteWord":return c.deleteWord(e),!0;case "deleteLine":return c.deleteLine(e),!0;case "insertText":return c.insertText(e),!0;case "removeText":return c.removeText(),!0;case "formatText":return c.formatText(e),
|
|
34
|
-
!0;case "formatElement":return c=c.anchor.getNode(),(h.$isElementNode(c)?c:c.getParentOrThrow()).setFormat(e),!0;case "insertLineBreak":return c.insertLineBreak(e),!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,e=c.getNode(),d="element"===c.type?c.getNode():
|
|
35
|
-
c.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===e.getTextContent()[c.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=e.shiftKey;if(S(c,!0))return e.preventDefault(),e=d,d="rtl"===c.anchor.getNode().getParentOrThrow().getDirection(),c.modify(e?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=e.shiftKey;if(S(c,!1))return e.preventDefault(),e=d,d="rtl"===c.anchor.getNode().getParentOrThrow().getDirection(),
|
|
36
|
-
c.modify(e?"extend":"move",d,"character"),!0;break;case "keyBackspace":return e.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return e.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return e.preventDefault(),e.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return e.preventDefault(),a.execCommand(e.shiftKey?"outdentContent":"indentContent");case "clearEditor":ma(a)}return!1},0));b&&la(a);return f},[a,b]);ba(Y,a);
|
|
37
|
-
ca(a)}function oa(a,b,f){b=Array.from(b);f=Array.from(f);a=a._nodeMap;const d=[];for(var e=0;e<b.length;e++){const c=a.get(b[e]);void 0!==c&&d.push(c)}for(b=0;b<f.length;b++)f[b][1]&&(e=a.get(f[b][0]),void 0===e||h.$isRootNode(e)||d.push(e));return d}
|
|
38
|
-
function pa(a,b,f,d,e){if(null===a||0===f.size&&0===d.size)return 0;var c=b._selection,g=a._selection;if(e)return 1;if(null===c||null===g||!g.isCollapsed()||!c.isCollapsed())return 0;f=oa(b,f,d);if(0===f.length)return 0;if(1<f.length){b=b._nodeMap;g=b.get(g.anchor.key);const k=b.get(c.anchor.key);return h.$isTextNode(k)&&h.$isElementNode(g)&&!a._nodeMap.has(k.__key)&&1===k.__text.length&&1===c.anchor.offset?f.every(l=>l===k||!h.$isTextNode(l))?2:0:0}b=f[0];a=a._nodeMap.get(b.__key);if(!h.$isTextNode(a)||
|
|
39
|
-
!h.$isTextNode(b)||a.__mode!==b.__mode)return 0;a=a.__text;b=b.__text;if(a===b)return 0;c=c.anchor;g=g.anchor;if(c.key!==g.key||"text"!==c.type)return 0;c=c.offset;g=g.offset;a=b.length-a.length;return 1===a&&g===c-1?2:-1===a&&g===c+1?3:-1===a&&g===c?4:0}
|
|
40
|
-
function qa(a,b){let f=Date.now(),d=0;return(e,c,g,k,l,m)=>{const p=Date.now();if(m.has("historic"))return d=0,f=p,2;const n=pa(e,c,k,l,a.isComposing()),r=(()=>{if(m.has("without-history"))return 0;if(null===e)return 1;var q=c._selection;const t=e._selection;if(!(0<k.size||0<l.size))return null===t&&null!==q?0:2;q=null===g||g.editor===a;return 0!==n&&n===d&&p<f+b&&q?0:1})();f=p;d=n;return r}}
|
|
41
|
-
function ra(a,b,f=1E3){const d=u.useMemo(()=>b||{current:null,redoStack:[],undoStack:[]},[b]),e=u.useCallback(()=>{d.undoStack=[];d.redoStack=[];d.current=null},[d]);u.useEffect(()=>{const c=qa(a,f);return E(a.addListener("command",g=>{switch(g){case "undo":g=d.redoStack;var k=d.undoStack;if(0!==k.length){var l=d.current;const m=k.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===k.length&&a.execCommand("canUndo",!1);d.current=m;m.editor.setEditorState(m.editorState.clone(m.undoSelection),
|
|
42
|
-
{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":case "clearHistory":return e(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:k,dirtyLeaves:l,dirtyElements:m,tags:p})=>{const n=d.current,r=d.redoStack,q=d.undoStack,t=null===
|
|
43
|
-
n?null:n.editorState;if(null===n||g!==t){l=c(k,g,n,l,m,p);if(1===l)0!==r.length&&(d.redoStack=[]),null!==n&&(q.push({...n,undoSelection:k.read(h.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;d.current={editor:a,editorState:g}}}))},[e,f,a,d])}module.exports=function(a,b){na(a,!0);ra(a,b)};
|