@lexical/react 0.1.8 → 0.1.9
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.prod.js +1 -1
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +142 -55
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -16
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +1 -2
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +3 -3
- package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
- package/DEPRECATED_useLexicalEditor.prod.js +1 -1
- package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +17 -14
- package/DEPRECATED_useLexicalHistory.prod.js +7 -7
- package/DEPRECATED_useLexicalList.prod.js +1 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +46 -23
- package/DEPRECATED_useLexicalPlainText.prod.js +16 -16
- package/DEPRECATED_useLexicalRichText.dev.js +47 -24
- package/DEPRECATED_useLexicalRichText.prod.js +27 -27
- package/LexicalAutoFormatterPlugin.dev.js +142 -55
- package/LexicalAutoFormatterPlugin.prod.js +19 -17
- package/LexicalAutoLinkPlugin.prod.js +4 -4
- package/LexicalBootstrapPlugin.dev.js +0 -2
- package/LexicalBootstrapPlugin.prod.js +2 -2
- package/LexicalCharacterLimitPlugin.dev.js +1 -2
- package/LexicalCharacterLimitPlugin.prod.js +3 -3
- package/LexicalCollaborationPlugin.dev.js +11 -26
- package/LexicalCollaborationPlugin.prod.js +7 -8
- package/LexicalComposer.prod.js +1 -1
- package/LexicalComposerContext.prod.js +1 -1
- package/LexicalContentEditable.prod.js +1 -1
- package/LexicalHashtagPlugin.prod.js +1 -1
- package/LexicalHistoryPlugin.dev.js +17 -14
- package/LexicalHistoryPlugin.prod.js +6 -6
- package/LexicalHorizontalRuleNode.dev.js +66 -0
- package/LexicalHorizontalRuleNode.js +9 -0
- package/LexicalHorizontalRuleNode.prod.js +8 -0
- package/LexicalLinkPlugin.dev.js +0 -1
- package/LexicalLinkPlugin.prod.js +3 -3
- package/LexicalListPlugin.prod.js +1 -1
- package/LexicalNestedComposer.prod.js +1 -1
- package/LexicalOnChangePlugin.prod.js +1 -1
- package/LexicalPlainTextPlugin.dev.js +29 -9
- package/LexicalPlainTextPlugin.prod.js +12 -11
- package/LexicalRichTextPlugin.dev.js +30 -10
- package/LexicalRichTextPlugin.prod.js +16 -16
- package/LexicalTablePlugin.dev.js +20 -38
- package/LexicalTablePlugin.prod.js +3 -3
- package/LexicalTreeView.prod.js +1 -1
- package/package.json +5 -4
- package/useLexicalDecoratorMap.prod.js +1 -1
- package/useLexicalIsTextContentEmpty.prod.js +1 -1
- package/withSubscriptions.prod.js +1 -1
- package/LexicalHorizontalRulePlugin.dev.js +0 -51
- package/LexicalHorizontalRulePlugin.js +0 -9
- package/LexicalHorizontalRulePlugin.prod.js +0 -7
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
function w(a){if(!v(a,!1))return!1;a=t.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let
|
|
9
|
-
function
|
|
10
|
-
function C(a
|
|
11
|
-
function F(a,e){
|
|
12
|
-
function H(a){
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
7
|
+
var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),t=require("lexical"),u=require("react-dom");function v(a,e=!0){if(a)return!1;a=t.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
|
|
8
|
+
function w(a){if(!v(a,!1))return!1;a=t.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let c=0;c<e;c++){var b=a[c];if(t.$isElementNode(b)){if("paragraph"!==b.__type||0!==b.__indent)return!1;b=b.getChildren();const d=b.length;for(let f=0;f<d;f++)if(!t.$isTextNode(b[c]))return!1}}return!0}function x(a){return()=>w(a)}var y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
|
|
9
|
+
function z(a){const [e,b]=h.useState(a.getEditorState().read(x(a.isComposing())));y(()=>a.addListener("update",({editorState:c})=>{const d=a.isComposing();c=c.read(x(d));b(c)}),[a]);return e}function A(a){const [e,b]=h.useState(()=>a.getDecorators());y(()=>a.addListener("decorator",c=>{u.flushSync(()=>{b(c)})}),[a]);return h.useMemo(()=>{const c=[],d=Object.keys(e);for(let p=0;p<d.length;p++){var f=d[p];const r=e[f];f=a.getElementByKey(f);null!==f&&c.push(u.createPortal(r,f))}return c},[e,a])}
|
|
10
|
+
function C(a){a=a.anchor.getNode();return"rtl"===(t.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function D(a,e,b){const c=a.getParent();let d=b;null!==c&&(e&&0===b?(d=a.getIndexWithinParent(),a=c):e||b!==a.getChildrenSize()||(d=a.getIndexWithinParent()+1,a=c));return a.getChildAtIndex(e?d-1:d)}function E(a,e){a=a.getData("text/plain");null!=a&&e.insertRawText(a)}
|
|
11
|
+
function F(a,e){var b=a.focus;a=b.offset;"element"===b.type?(b=b.getNode(),e=D(b,e,a)):(b=b.getNode(),e&&0===a||!e&&a===b.getTextContentSize()?(a=e?b.getPreviousSibling():b.getNextSibling(),e=null===a?D(b.getParentOrThrow(),e,b.getIndexWithinParent()+(e?0:1)):a):e=null);return t.$isDecoratorNode(e)&&!e.isIsolated()}function G(a,e){a.preventDefault();e.update(()=>{const b=t.$getSelection(),c=a.clipboardData;null!=c&&null!==b&&E(c,b)})}
|
|
12
|
+
function H(a,e){I(a,e);e.update(()=>{const b=t.$getSelection();null!==b&&b.removeText()})}function I(a,e){a.preventDefault();e.update(()=>{const b=a.clipboardData,c=t.$getSelection();if(null!==c&&null!=b){var d=window.getSelection();if(!d.isCollapsed){var f=d.getRangeAt(0);f&&(d=document.createElement("div"),f=f.cloneContents(),d.appendChild(f),b.setData("text/html",d.innerHTML));b.setData("text/plain",c.getTextContent())}}})}
|
|
13
|
+
function J(a){h.useEffect(()=>{const e=b=>{var c=a.getRootElement();if(document.activeElement===c&&(c=b.data,"string"===typeof c)){try{var d=JSON.parse(c)}catch(f){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [f,p,r,B,K]=d;a.update(()=>{const q=t.$getSelection();if(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,m));if(l!==m||""!==r)q.insertRawText(r),
|
|
14
|
+
k=n.getNode();t.$isTextNode(k)&&(l=B,m=B+K,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));b.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
|
|
15
|
+
function L(a){y(()=>{const e=a.addListener("command",(b,c)=>{const d=t.$getSelection();if(null===d)return!1;switch(b){case "deleteCharacter":return d.deleteCharacter(c),!0;case "deleteWord":return d.deleteWord(c),!0;case "deleteLine":return d.deleteLine(c),!0;case "insertText":return"string"===typeof c?d.insertText(c):(b=c.dataTransfer,null!=b?E(b,d):(c=c.data)&&d.insertText(c)),!0;case "removeText":return d.removeText(),!0;case "insertLineBreak":return d.insertLineBreak(c),!0;case "insertParagraph":return d.insertLineBreak(),
|
|
16
|
+
!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b=c.shiftKey;if(F(d,!0))return c.preventDefault(),c=b,b=C(d),d.modify(c?"extend":"move",!b,"character"),!0;break;case "keyArrowRight":b=c.shiftKey;if(F(d,!1))return c.preventDefault(),c=b,b=C(d),d.modify(c?"extend":"move",b,"character"),!0;break;case "keyBackspace":return c.preventDefault(),a.execCommand("deleteCharacter",
|
|
17
|
+
!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "copy":return I(c,a),!0;case "cut":return H(c,a),!0;case "paste":return G(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return e},[a]);J(a)}
|
|
18
|
+
module.exports=function({contentEditable:a,placeholder:e}){var [b]=g.useLexicalComposerContext();const c=z(b);L(b);b=A(b);return h.createElement(h.Fragment,null,a,c&&e,b)};
|
|
@@ -298,7 +298,7 @@ function $cloneContents(selection) {
|
|
|
298
298
|
const firstNode = nodes[0];
|
|
299
299
|
const firstNodeParent = firstNode.getParent();
|
|
300
300
|
|
|
301
|
-
if (firstNodeParent !== null && !firstNodeParent.canBeEmpty()) {
|
|
301
|
+
if (firstNodeParent !== null && (!firstNodeParent.canBeEmpty() || lexical.$isRootNode(firstNodeParent))) {
|
|
302
302
|
const parentChildren = firstNodeParent.__children;
|
|
303
303
|
const parentChildrenLength = parentChildren.length;
|
|
304
304
|
|
|
@@ -354,7 +354,7 @@ function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity)
|
|
|
354
354
|
}
|
|
355
355
|
function $isParentElementRTL(selection) {
|
|
356
356
|
const anchorNode = selection.anchor.getNode();
|
|
357
|
-
const parent = anchorNode.getParentOrThrow();
|
|
357
|
+
const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
|
|
358
358
|
return parent.getDirection() === 'rtl';
|
|
359
359
|
}
|
|
360
360
|
function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
@@ -370,17 +370,41 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
370
370
|
*
|
|
371
371
|
*
|
|
372
372
|
*/
|
|
373
|
+
function resolveElement(element, isBackward, focusOffset) {
|
|
374
|
+
const parent = element.getParent();
|
|
375
|
+
let offset = focusOffset;
|
|
376
|
+
let block = element;
|
|
377
|
+
|
|
378
|
+
if (parent !== null) {
|
|
379
|
+
if (isBackward && focusOffset === 0) {
|
|
380
|
+
offset = block.getIndexWithinParent();
|
|
381
|
+
block = parent;
|
|
382
|
+
} else if (!isBackward && focusOffset === block.getChildrenSize()) {
|
|
383
|
+
offset = block.getIndexWithinParent() + 1;
|
|
384
|
+
block = parent;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return block.getChildAtIndex(isBackward ? offset - 1 : offset);
|
|
389
|
+
}
|
|
390
|
+
|
|
373
391
|
function getPossibleDecoratorNode(focus, isBackward) {
|
|
374
392
|
const focusOffset = focus.offset;
|
|
375
393
|
|
|
376
394
|
if (focus.type === 'element') {
|
|
377
395
|
const block = focus.getNode();
|
|
378
|
-
return block
|
|
396
|
+
return resolveElement(block, isBackward, focusOffset);
|
|
379
397
|
} else {
|
|
380
398
|
const focusNode = focus.getNode();
|
|
381
399
|
|
|
382
400
|
if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
|
|
383
|
-
|
|
401
|
+
const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
|
|
402
|
+
|
|
403
|
+
if (possibleNode === null) {
|
|
404
|
+
return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return possibleNode;
|
|
384
408
|
}
|
|
385
409
|
}
|
|
386
410
|
|
|
@@ -714,13 +738,12 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
|
|
|
714
738
|
}
|
|
715
739
|
}
|
|
716
740
|
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
717
|
-
const
|
|
718
|
-
return lexical.$isDecoratorNode(
|
|
741
|
+
const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
|
|
742
|
+
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
719
743
|
}
|
|
720
744
|
function onPasteForRichText(event, editor) {
|
|
721
745
|
event.preventDefault();
|
|
722
746
|
editor.update(() => {
|
|
723
|
-
lexical.$log('onPasteForRichText');
|
|
724
747
|
const selection = lexical.$getSelection();
|
|
725
748
|
const clipboardData = event.clipboardData;
|
|
726
749
|
|
|
@@ -732,7 +755,6 @@ function onPasteForRichText(event, editor) {
|
|
|
732
755
|
function onCutForRichText(event, editor) {
|
|
733
756
|
onCopyForRichText(event, editor);
|
|
734
757
|
editor.update(() => {
|
|
735
|
-
lexical.$log('onCutForRichText');
|
|
736
758
|
const selection = lexical.$getSelection();
|
|
737
759
|
|
|
738
760
|
if (selection !== null) {
|
|
@@ -743,7 +765,6 @@ function onCutForRichText(event, editor) {
|
|
|
743
765
|
function onCopyForRichText(event, editor) {
|
|
744
766
|
event.preventDefault();
|
|
745
767
|
editor.update(() => {
|
|
746
|
-
lexical.$log('onCopyForRichText');
|
|
747
768
|
const clipboardData = event.clipboardData;
|
|
748
769
|
const selection = lexical.$getSelection();
|
|
749
770
|
|
|
@@ -812,7 +833,6 @@ function useLexicalDragonSupport(editor) {
|
|
|
812
833
|
if (args) {
|
|
813
834
|
const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
|
|
814
835
|
editor.update(() => {
|
|
815
|
-
lexical.$log('useLexicalDragonSupport');
|
|
816
836
|
const selection = lexical.$getSelection();
|
|
817
837
|
|
|
818
838
|
if (selection !== null) {
|
|
@@ -4,28 +4,28 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
var g=require("@lexical/react/LexicalComposerContext"),v=require("react"),x=require("lexical"),z=require("react-dom"),A=require("@lexical/list"),B=require("lexical/CodeNode"),C=require("lexical/HeadingNode"),D=require("lexical/LinkNode");function E(a,e=!0){if(a)return!1;a=x.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
|
|
8
8
|
function F(a){if(!E(a,!1))return!1;a=x.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let b=0;b<e;b++){var c=a[b];if(x.$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(!x.$isTextNode(c[b]))return!1}}return!0}function G(a){return()=>F(a)}var H="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;
|
|
9
9
|
function I(a){const [e,c]=v.useState(a.getEditorState().read(G(a.isComposing())));H(()=>a.addListener("update",({editorState:b})=>{const d=a.isComposing();b=b.read(G(d));c(b)}),[a]);return e}function J(a){const [e,c]=v.useState(()=>a.getDecorators());H(()=>a.addListener("decorator",b=>{z.flushSync(()=>{c(b)})}),[a]);return v.useMemo(()=>{const b=[],d=Object.keys(e);for(let k=0;k<d.length;k++){var f=d[k];const h=e[f];f=a.getElementByKey(f);null!==f&&b.push(z.createPortal(h,f))}return b},[e,a])}
|
|
10
10
|
function K(a){a=a.getLatest();const e=a.constructor.clone(a);e.__parent=a.__parent;x.$isElementNode(a)&&x.$isElementNode(e)?(e.__children=Array.from(a.__children),e.__format=a.__format,e.__indent=a.__indent,e.__dir=a.__dir):x.$isTextNode(a)&&x.$isTextNode(e)?(e.__format=a.__format,e.__style=a.__style,e.__mode=a.__mode,e.__detail=a.__detail):x.$isDecoratorNode(a)&&x.$isDecoratorNode(e)&&(e.__state=a.__state);return e}
|
|
11
11
|
function L(a,e,c,b,d){for(var f=e;null!==a;){for(e=a.getParent();null!==e&&e.excludeFromCopy();)e=e.getParent();if(null===e)break;if(!x.$isElementNode(a)||!a.excludeFromCopy()){const k=a.getKey();let h=d.get(k);const l=void 0===h;l&&(h=K(a),d.set(k,h));!x.$isTextNode(h)||h.isSegmented()||h.isToken()?x.$isElementNode(h)&&(h.__children=h.__children.slice(c?f:0,c?void 0:f+1)):h.__text=h.__text.slice(c?f:0,c?void 0:f);if(x.$isRootNode(e)){l&&b.push(k);break}}f=d.get(e.getKey());f=x.$isElementNode(f)?
|
|
12
|
-
f.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=e}}
|
|
13
|
-
const
|
|
12
|
+
f.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=e}}function M(a){a=a.anchor.getNode();return"rtl"===(x.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function N(a,e,c){const b=a.getParent();let d=c;null!==b&&(e&&0===c?(d=a.getIndexWithinParent(),a=b):e||c!==a.getChildrenSize()||(d=a.getIndexWithinParent()+1,a=b));return a.getChildAtIndex(e?d-1:d)}
|
|
13
|
+
const O={"#text":a=>({node:x.$createTextNode(a.textContent)}),a:a=>({node:a instanceof HTMLAnchorElement?D.$createLinkNode(a.href):x.$createTextNode(a.textContent)}),b:a=>{const e="normal"===a.style.fontWeight;return{forChild:c=>{x.$isTextNode(c)&&!e&&c.toggleFormat("bold")},node:null}},br:()=>({node:x.$createLineBreakNode()}),div:a=>({after:e=>{const c=a.parentNode;null!=c&&a!==c.lastChild&&e.push(x.$createLineBreakNode());return e},node:null!==a.style.fontFamily.match("monospace")?B.$createCodeNode():
|
|
14
14
|
null}),em:()=>({forChild:a=>{x.$isTextNode(a)&&a.toggleFormat("italic")},node:null}),h1:()=>({node:C.$createHeadingNode("h1")}),h2:()=>({node:C.$createHeadingNode("h2")}),h3:()=>({node:C.$createHeadingNode("h3")}),h4:()=>({node:C.$createHeadingNode("h4")}),h5:()=>({node:C.$createHeadingNode("h5")}),i:()=>({forChild:a=>{x.$isTextNode(a)&&a.toggleFormat("italic")},node:null}),li:()=>({node:A.$createListItemNode()}),ol:()=>({node:A.$createListNode("ol")}),p:()=>({node:x.$createParagraphNode()}),pre:()=>
|
|
15
15
|
({node:B.$createCodeNode()}),span:a=>{const e="700"===a.style.fontWeight;return{forChild:c=>{x.$isTextNode(c)&&e&&c.toggleFormat("bold")},node:null}},strong:()=>({forChild:a=>{x.$isTextNode(a)&&a.toggleFormat("bold")},node:null}),table:a=>({node:a.classList.contains("js-file-line-container")?B.$createCodeNode():null}),td:a=>{const e=a.classList.contains("js-file-line");return{after:c=>{e&&a.parentNode&&a.parentNode.nextSibling&&c.push(x.$createLineBreakNode());return c},node:null}},u:()=>({forChild:a=>
|
|
16
16
|
{x.$isTextNode(a)&&a.toggleFormat("underline")},node:null}),ul:()=>({node:A.$createListNode("ul")})};
|
|
17
|
-
function
|
|
18
|
-
function
|
|
17
|
+
function P(a,e,c,b=new Map){let d=[],f=null;var k=a.nodeName.toLowerCase(),h=(c._config.htmlTransforms||{})[k]||e[k],l=h?h(a):null;h=null;if(null!==l){h=l.after;f=l.node;if(null!==f){d.push(f);const q=Array.from(b.values());for(let m=0;m<q.length;m++)q[m](f)}null!=l.forChild&&b.set(k,l.forChild)}a=a.childNodes;k=[];for(l=0;l<a.length;l++)k.push(...P(a[l],e,c,b));null!=h&&(k=h(k));null==f?d=d.concat(k):x.$isElementNode(f)&&f.append(...k);return d}
|
|
18
|
+
function Q(a,e,c){var b=a.getData("application/x-lexical-editor");if(b){var d=c._config.namespace;try{const l=JSON.parse(b);if(l.namespace===d){const {range:q,nodeMap:m}=l.state;var f=new Map(m);b=[];for(d=0;d<q.length;d++){var k=f.get(q[d]);if(void 0!==k){var h=x.$createNodeFromParse(k,f);b.push(h)}}e.insertNodes(b);return}}catch(l){}}if(f=a.getData("text/html")){f=(new DOMParser).parseFromString(f,"text/html");a=[];f=f.body?Array.from(f.body.childNodes):[];k=f.length;for(h=0;h<k;h++)b=P(f[h],O,
|
|
19
19
|
c),null!==b&&(a=a.concat(b));c=a;a=[];f=null;for(k=0;k<c.length;k++)h=c[k],!x.$isElementNode(h)||h.isInline()?(null===f&&(f=x.$createParagraphNode(),a.push(f)),null!==f&&f.append(h)):(a.push(h),f=null);e.insertNodes(a)}else c=a.getData("text/plain"),null!=c&&e.insertRawText(c)}
|
|
20
|
-
function
|
|
21
|
-
function
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
t=[];L(r,l?m:y,!0,t,q);for(r=0;r<n;r++)if(u=b[r],w=u.getKey(),!(q.has(w)||x.$isElementNode(u)&&u.excludeFromCopy())){const
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
function
|
|
20
|
+
function R(a,e){var c=a.focus;a=c.offset;"element"===c.type?(c=c.getNode(),e=N(c,e,a)):(c=c.getNode(),e&&0===a||!e&&a===c.getTextContentSize()?(a=e?c.getPreviousSibling():c.getNextSibling(),e=null===a?N(c.getParentOrThrow(),e,c.getIndexWithinParent()+(e?0:1)):a):e=null);return x.$isDecoratorNode(e)&&!e.isIsolated()}function S(a,e){a.preventDefault();e.update(()=>{const c=x.$getSelection(),b=a.clipboardData;null!=b&&null!==c&&Q(b,c,e)})}
|
|
21
|
+
function T(a,e){U(a,e);e.update(()=>{const c=x.$getSelection();null!==c&&c.removeText()})}
|
|
22
|
+
function U(a,e){a.preventDefault();e.update(()=>{const c=a.clipboardData;var b=x.$getSelection();if(null!==b&&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",b.getTextContent());d=e._config.namespace;f=c.setData;var k=JSON,h=k.stringify;{var l=b.anchor,q=b.focus;var m=l.getCharacterOffset();const y=q.getCharacterOffset();var n=l.getNode(),
|
|
23
|
+
r=q.getNode(),p=n.getParentOrThrow();if(n===r&&x.$isTextNode(n)&&(p.canBeEmpty()||1<p.getChildrenSize()))b=K(n),n=y>m,b.__text=b.__text.slice(n?m:y,n?y:m),m=b.getKey(),m={nodeMap:[[m,b]],range:[m]};else if(b=b.getNodes(),0===b.length)m={nodeMap:[],range:[]};else{n=b.length;r=b[0];p=r.getParent();if(null!==p&&(!p.canBeEmpty()||x.$isRootNode(p))){var t=p.__children;if(t.length===n){var u=!0;for(var w=0;w<t.length;w++)if(t[w]!==b[w].__key){u=!1;break}u&&(n++,b.push(p))}}p=b[n-1];l=l.isBefore(q);q=new Map;
|
|
24
|
+
t=[];L(r,l?m:y,!0,t,q);for(r=0;r<n;r++)if(u=b[r],w=u.getKey(),!(q.has(w)||x.$isElementNode(u)&&u.excludeFromCopy())){const V=K(u);x.$isRootNode(u.getParent())&&t.push(u.getKey());q.set(w,V)}L(p,l?y:m,!1,t,q);m={nodeMap:Array.from(q.entries()),range:t}}}f.call(c,"application/x-lexical-editor",h.call(k,{namespace:d,state:m}))}}})}
|
|
25
|
+
function W(a){v.useEffect(()=>{const e=c=>{var b=a.getRootElement();if(document.activeElement===b&&(b=c.data,"string"===typeof b)){try{var d=JSON.parse(b)}catch(f){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [f,k,h,l,q]=d;a.update(()=>{const m=x.$getSelection();if(null!==m){var n=m.anchor;let r=n.getNode(),p=0,t=0;x.$isTextNode(r)&&0<=f&&0<=k&&(p=f,t=f+k,m.setTextNodeRange(r,p,r,t));if(p!==t||""!==h)m.insertRawText(h),
|
|
26
|
+
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));c.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
|
|
27
|
+
function X(a){H(()=>{const e=a.addListener("command",(c,b)=>{var d=x.$getSelection();if(null===d)return!1;switch(c){case "deleteCharacter":return d.deleteCharacter(b),!0;case "deleteWord":return d.deleteWord(b),!0;case "deleteLine":return d.deleteLine(b),!0;case "insertText":return"string"===typeof b?d.insertText(b):(c=b.dataTransfer,null!=c?Q(c,d,a):(b=b.data)&&d.insertText(b)),!0;case "removeText":return d.removeText(),!0;case "formatText":return d.formatText(b),!0;case "formatElement":return d=
|
|
28
28
|
d.anchor.getNode(),(x.$isElementNode(d)?d:d.getParentOrThrow()).setFormat(b),!0;case "insertLineBreak":return d.insertLineBreak(b),!0;case "insertParagraph":return d.insertParagraph(),!0;case "indentContent":return d=d.anchor,d="element"===d.type?d.getNode():d.getNode().getParentOrThrow(),d.canInsertTab()?a.execCommand("insertText","\t"):10!==d.getIndent()&&d.setIndent(d.getIndent()+1),!0;case "outdentContent":return d=d.anchor,b=d.getNode(),c="element"===d.type?d.getNode():d.getNode().getParentOrThrow(),
|
|
29
|
-
c.canInsertTab()?"\t"===b.getTextContent()[d.offset-1]&&a.execCommand("deleteCharacter",!0):0!==c.getIndent()&&c.setIndent(c.getIndent()-1),!0;case "keyArrowLeft":c=b.shiftKey;if(
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
c.canInsertTab()?"\t"===b.getTextContent()[d.offset-1]&&a.execCommand("deleteCharacter",!0):0!==c.getIndent()&&c.setIndent(c.getIndent()-1),!0;case "keyArrowLeft":c=b.shiftKey;if(R(d,!0))return b.preventDefault(),b=c,c=M(d),d.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(R(d,!1))return b.preventDefault(),b=c,c=M(d),d.modify(b?"extend":"move",c,"character"),!0;break;case "keyBackspace":return b.preventDefault(),{anchor:b}=d,d.isCollapsed()&&0===b.offset&&0<
|
|
30
|
+
("element"===b.type?b.getNode():b.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),b.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return b.preventDefault(),a.execCommand(b.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),!0;case "copy":return U(b,a),
|
|
31
|
+
!0;case "cut":return T(b,a),!0;case "paste":return S(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return e},[a]);W(a)}module.exports=function({contentEditable:a,placeholder:e}){var [c]=g.useLexicalComposerContext();const b=I(c);X(c);c=J(c);return v.createElement(v.Fragment,null,a,b&&e,c)};
|
|
@@ -6,41 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
var lexical = require('lexical');
|
|
10
|
-
var TableCellNode = require('lexical/TableCellNode');
|
|
11
|
-
var TableNode = require('lexical/TableNode');
|
|
12
|
-
var TableRowNode = require('lexical/TableRowNode');
|
|
13
9
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
|
+
var table = require('@lexical/table');
|
|
11
|
+
var lexical = require('lexical');
|
|
14
12
|
var react = require('react');
|
|
15
13
|
|
|
16
|
-
/**
|
|
17
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the MIT license found in the
|
|
20
|
-
* LICENSE file in the root directory of this source tree.
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
function $createTableNodeWithDimensions(rowCount, columnCount, includeHeader = true) {
|
|
25
|
-
const tableNode = TableNode.$createTableNode();
|
|
26
|
-
|
|
27
|
-
for (let iRow = 0; iRow < rowCount; iRow++) {
|
|
28
|
-
const tableRowNode = TableRowNode.$createTableRowNode();
|
|
29
|
-
|
|
30
|
-
for (let iColumn = 0; iColumn < columnCount; iColumn++) {
|
|
31
|
-
const tableCellNode = TableCellNode.$createTableCellNode(iRow === 0 && includeHeader);
|
|
32
|
-
const paragraphNode = lexical.$createParagraphNode();
|
|
33
|
-
paragraphNode.append(lexical.$createTextNode());
|
|
34
|
-
tableCellNode.append(paragraphNode);
|
|
35
|
-
tableRowNode.append(tableCellNode);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
tableNode.append(tableRowNode);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return tableNode;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
14
|
/**
|
|
45
15
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
46
16
|
*
|
|
@@ -53,7 +23,7 @@ const EditorPriority = 0;
|
|
|
53
23
|
function TablePlugin() {
|
|
54
24
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
55
25
|
react.useEffect(() => {
|
|
56
|
-
if (!editor.hasNodes([
|
|
26
|
+
if (!editor.hasNodes([table.TableNode, table.TableCellNode, table.TableRowNode])) {
|
|
57
27
|
{
|
|
58
28
|
throw Error(`TablePlugin: TableNode, TableCellNode or TableRowNode not registered on editor`);
|
|
59
29
|
}
|
|
@@ -65,19 +35,31 @@ function TablePlugin() {
|
|
|
65
35
|
columns,
|
|
66
36
|
rows
|
|
67
37
|
} = payload;
|
|
68
|
-
lexical.$log('handleAddTable');
|
|
69
38
|
const selection = lexical.$getSelection();
|
|
70
39
|
|
|
71
40
|
if (selection === null) {
|
|
72
41
|
return true;
|
|
73
42
|
}
|
|
74
43
|
|
|
75
|
-
const
|
|
44
|
+
const focus = selection.focus;
|
|
45
|
+
const focusNode = focus.getNode();
|
|
76
46
|
|
|
77
47
|
if (focusNode !== null) {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
48
|
+
const tableNode = table.$createTableNodeWithDimensions(rows, columns);
|
|
49
|
+
|
|
50
|
+
if (lexical.$isRootNode(focusNode)) {
|
|
51
|
+
const target = focusNode.getChildAtIndex(focus.offset);
|
|
52
|
+
|
|
53
|
+
if (target !== null) {
|
|
54
|
+
target.insertBefore(tableNode);
|
|
55
|
+
} else {
|
|
56
|
+
focusNode.append(tableNode);
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
const topLevelNode = focusNode.getTopLevelElementOrThrow();
|
|
60
|
+
topLevelNode.insertAfter(tableNode);
|
|
61
|
+
}
|
|
62
|
+
|
|
81
63
|
tableNode.insertAfter(lexical.$createParagraphNode());
|
|
82
64
|
const firstCell = tableNode.getFirstChildOrThrow().getFirstChildOrThrow();
|
|
83
65
|
firstCell.select();
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
module.exports=function(){const [
|
|
9
|
-
b.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0}return!1},0)},[
|
|
7
|
+
var d=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/table"),g=require("lexical"),h=require("react");
|
|
8
|
+
module.exports=function(){const [f]=d.useLexicalComposerContext();h.useEffect(()=>{if(!f.hasNodes([e.TableNode,e.TableCellNode,e.TableRowNode]))throw Error("Minified Lexical error #54; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return f.addListener("command",(a,b)=>{if("insertTable"===a){const {columns:k,rows:l}=b;a=g.$getSelection();if(null===a)return!0;var c=a.focus;a=c.getNode();null!==a&&(b=e.$createTableNodeWithDimensions(l,
|
|
9
|
+
k),g.$isRootNode(a)?(c=a.getChildAtIndex(c.offset),null!==c?c.insertBefore(b):a.append(b)):a.getTopLevelElementOrThrow().insertAfter(b),b.insertAfter(g.$createParagraphNode()),b.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0}return!1},0)},[f]);return null};
|
package/LexicalTreeView.prod.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
var k=require("lexical"),q=require("react");const w=Object.freeze({"\t":"\\t","\n":"\\n"}),D=new RegExp(Object.keys(w).join("|"),"g"),E=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
|
|
8
8
|
function F(a){let b="";const c=G(a),e=a.anchor;a=a.focus;const d=e.offset,f=a.offset;b=b+`: range ${""!==c?`{ ${c} }`:""}`+`\n \u251c anchor { key: ${e.key}, offset: ${null===d?"null":d}, type: ${e.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===f?"null":f}, type: ${a.type} }`}
|
|
9
9
|
function H(a){let b=" root\n";a=a.read(()=>{const c=k.$getSelection();J(k.$getRoot(),(e,d)=>{const f=`(${e.getKey()})`,g=e.getType()||"",m=e.isSelected();var u=b,t=m?E.selectedLine:" ",r=d.join(" ");if(k.$isTextNode(e)){var l=e.getTextContent(!0);const n=0===l.length?"(empty)":`"${K(l)}"`;l=[G(e),L(e),M(e)].filter(Boolean).join(", ");l=[n,0!==l.length?`{ ${l} }`:null].filter(Boolean).join(" ").trim()}else l="";b=u+`${t} ${r} ${f} ${g} ${l}\n`;b+=N({indent:d,isSelected:m,node:e,nodeKeyDisplay:f,selection:c,
|
|
10
10
|
typeDisplay:g})});return null===c?": null":F(c)});return b+"\n selection"+a}function J(a,b,c=[]){a=a.getChildren();const e=a.length;a.forEach((d,f)=>{b(d,c.concat(f===e-1?E.isLastChild:E.hasNextSibling));k.$isElementNode(d)&&J(d,b,c.concat(f===e-1?E.ancestorIsLastChild:E.ancestorHasNextSibling))})}function K(a){return Object.entries(w).reduce((b,[c,e])=>b.replace(new RegExp(c,"g"),String(e)),a)}
|
package/package.json
CHANGED
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
"rich-text"
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"version": "0.1.
|
|
15
|
+
"version": "0.1.9",
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"lexical": "0.1.
|
|
18
|
-
"@lexical/helpers": "0.1.
|
|
19
|
-
"@lexical/
|
|
17
|
+
"lexical": "0.1.9",
|
|
18
|
+
"@lexical/helpers": "0.1.9",
|
|
19
|
+
"@lexical/table": "0.1.9",
|
|
20
|
+
"@lexical/yjs": "0.1.9",
|
|
20
21
|
"react": ">=17.x",
|
|
21
22
|
"react-dom": ">=17.x"
|
|
22
23
|
},
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
var e=require("lexical"),f=require("react"),l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;
|
|
8
8
|
module.exports=function(a,d,g){const [b,h]=f.useState(()=>{var c=a.get(d);c=void 0!==c?c:"function"===typeof g?g():g;return c}),[,m]=f.useState();l(()=>{a.get(d)!==b&&a.set(d,b)},[d,b,a]);l(()=>{if(e.isDecoratorArray(b))return b.observe(()=>{m({})})},[b]);l(()=>a.observe((c,k)=>{c===d&&(a._map.set(c,k),h(k))}),[a,d]);return[b,h]};
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
var c=require("lexical"),e=require("react");function f(a,b=!0){if(a)return!1;a=c.$getRoot().getTextContent();b&&(a=a.trim());return""===a}function g(a,b){return()=>f(a,b)}var h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;
|
|
8
8
|
module.exports=function(a,b){const [k,l]=e.useState(a.getEditorState().read(g(a.isComposing(),b)));h(()=>a.addListener("update",({editorState:d})=>{const m=a.isComposing();d=d.read(g(m,b));l(d)}),[a,b]);return k};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
|
-
var lexical = require('lexical');
|
|
11
|
-
var react = require('react');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
-
*
|
|
16
|
-
* This source code is licensed under the MIT license found in the
|
|
17
|
-
* LICENSE file in the root directory of this source tree.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
const EditorPriority = 0;
|
|
22
|
-
function HorizontalRulePlugin() {
|
|
23
|
-
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
24
|
-
react.useEffect(() => {
|
|
25
|
-
return editor.addListener('command', type => {
|
|
26
|
-
if (type === 'insertHorizontalRule') {
|
|
27
|
-
lexical.$log('insertHorizontalRule');
|
|
28
|
-
const selection = lexical.$getSelection();
|
|
29
|
-
|
|
30
|
-
if (selection === null) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const focusNode = selection.focus.getNode();
|
|
35
|
-
|
|
36
|
-
if (focusNode !== null) {
|
|
37
|
-
const horizontalRuleNode = lexical.$createHorizontalRuleNode();
|
|
38
|
-
selection.insertParagraph();
|
|
39
|
-
selection.focus.getNode().getTopLevelElementOrThrow().insertBefore(horizontalRuleNode);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return false;
|
|
46
|
-
}, EditorPriority);
|
|
47
|
-
}, [editor]);
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = HorizontalRulePlugin;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
'use strict'
|
|
8
|
-
const LexicalHorizontalRulePlugin = process.env.NODE_ENV === 'development' ? require('./LexicalHorizontalRulePlugin.dev.js') : require('./LexicalHorizontalRulePlugin.prod.js')
|
|
9
|
-
module.exports = LexicalHorizontalRulePlugin;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
'use strict';var b=require("@lexical/react/LexicalComposerContext"),d=require("lexical"),e=require("react");module.exports=function(){const [c]=b.useLexicalComposerContext();e.useEffect(()=>c.addListener("command",a=>{if("insertHorizontalRule"===a){d.$log("insertHorizontalRule");a=d.$getSelection();if(null===a)return!1;if(null!==a.focus.getNode()){const f=d.$createHorizontalRuleNode();a.insertParagraph();a.focus.getNode().getTopLevelElementOrThrow().insertBefore(f)}return!0}return!1},0),[c]);return null};
|