@lexical/react 0.1.9 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPRECATED_useLexical.dev.js +5 -44
- package/DEPRECATED_useLexical.prod.js +1 -2
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +87 -41
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +20 -18
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +22 -19
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
- package/DEPRECATED_useLexicalEditor.dev.js +1 -25
- package/DEPRECATED_useLexicalEditor.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +1 -1
- package/DEPRECATED_useLexicalHistory.prod.js +2 -2
- package/DEPRECATED_useLexicalList.dev.js +6 -0
- package/DEPRECATED_useLexicalList.prod.js +1 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +81 -89
- package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
- package/DEPRECATED_useLexicalRichText.dev.js +98 -592
- package/DEPRECATED_useLexicalRichText.prod.js +17 -29
- package/LexicalAutoFormatterPlugin.d.ts +9 -0
- package/LexicalAutoFormatterPlugin.dev.js +87 -41
- package/LexicalAutoFormatterPlugin.js.flow +10 -0
- package/LexicalAutoFormatterPlugin.prod.js +21 -19
- package/LexicalAutoLinkPlugin.d.ts +20 -0
- package/LexicalAutoLinkPlugin.js.flow +23 -0
- package/LexicalCharacterLimitPlugin.d.ts +11 -0
- package/LexicalCharacterLimitPlugin.dev.js +22 -19
- package/LexicalCharacterLimitPlugin.js.flow +12 -0
- package/LexicalCharacterLimitPlugin.prod.js +9 -8
- package/LexicalClearEditorPlugin.d.ts +14 -0
- package/LexicalClearEditorPlugin.dev.js +73 -0
- package/LexicalClearEditorPlugin.js +9 -0
- package/LexicalClearEditorPlugin.js.flow +14 -0
- package/LexicalClearEditorPlugin.prod.js +8 -0
- package/LexicalCollaborationPlugin.d.ts +49 -0
- package/LexicalCollaborationPlugin.dev.js +21 -11
- package/LexicalCollaborationPlugin.js.flow +55 -0
- package/LexicalCollaborationPlugin.prod.js +7 -7
- package/LexicalComposer.d.ts +22 -0
- package/LexicalComposer.dev.js +29 -5
- package/LexicalComposer.js.flow +24 -0
- package/LexicalComposer.prod.js +3 -3
- package/LexicalComposerContext.d.ts +24 -0
- package/LexicalComposerContext.js.flow +27 -0
- package/LexicalContentEditable.d.ts +32 -0
- package/LexicalContentEditable.dev.js +35 -8
- package/LexicalContentEditable.js.flow +35 -0
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalHashtagPlugin.d.ts +9 -0
- package/LexicalHashtagPlugin.js.flow +10 -0
- package/LexicalHistoryPlugin.d.ts +29 -0
- package/LexicalHistoryPlugin.dev.js +1 -1
- package/LexicalHistoryPlugin.js.flow +34 -0
- package/LexicalHistoryPlugin.prod.js +2 -2
- package/LexicalHorizontalRuleNode.d.ts +23 -0
- package/LexicalHorizontalRuleNode.js.flow +25 -0
- package/LexicalLinkPlugin.d.ts +9 -0
- package/LexicalLinkPlugin.js.flow +10 -0
- package/LexicalListPlugin.d.ts +9 -0
- package/LexicalListPlugin.dev.js +6 -0
- package/LexicalListPlugin.js.flow +10 -0
- package/LexicalListPlugin.prod.js +2 -2
- package/LexicalNestedComposer.d.ts +20 -0
- package/LexicalNestedComposer.js.flow +21 -0
- package/LexicalOnChangePlugin.d.ts +12 -0
- package/LexicalOnChangePlugin.js.flow +14 -0
- package/LexicalPlainTextPlugin.d.ts +15 -0
- package/LexicalPlainTextPlugin.dev.js +77 -84
- package/LexicalPlainTextPlugin.js.flow +18 -0
- package/LexicalPlainTextPlugin.prod.js +12 -12
- package/LexicalRichTextPlugin.d.ts +15 -0
- package/LexicalRichTextPlugin.dev.js +93 -586
- package/LexicalRichTextPlugin.js.flow +18 -0
- package/LexicalRichTextPlugin.prod.js +13 -25
- package/LexicalTablePlugin.d.ts +9 -0
- package/LexicalTablePlugin.dev.js +23 -1
- package/LexicalTablePlugin.js.flow +10 -0
- package/LexicalTablePlugin.prod.js +4 -3
- package/LexicalTreeView.d.ts +17 -0
- package/LexicalTreeView.dev.js +10 -2
- package/LexicalTreeView.js.flow +19 -0
- package/LexicalTreeView.prod.js +9 -8
- package/README.md +0 -1
- package/package.json +6 -5
- package/useLexicalDecoratorMap.d.ts +14 -0
- package/useLexicalDecoratorMap.js.flow +16 -0
- package/useLexicalIsTextContentEmpty.d.ts +13 -0
- package/useLexicalIsTextContentEmpty.js.flow +15 -0
- package/useLexicalNodeSelection.d.ts +12 -0
- package/useLexicalNodeSelection.dev.js +70 -0
- package/useLexicalNodeSelection.js +9 -0
- package/useLexicalNodeSelection.js.flow +14 -0
- package/useLexicalNodeSelection.prod.js +8 -0
- package/withSubscriptions.d.ts +12 -0
- package/withSubscriptions.js.flow +13 -0
- package/LexicalBootstrapPlugin.dev.js +0 -122
- package/LexicalBootstrapPlugin.js +0 -9
- package/LexicalBootstrapPlugin.prod.js +0 -8
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {EditorState} from 'lexical';
|
|
11
|
+
|
|
12
|
+
type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
13
|
+
|
|
14
|
+
declare export default function RichTextPlugin({
|
|
15
|
+
contentEditable: React$Node,
|
|
16
|
+
initialEditorState?: InitialEditorStateType,
|
|
17
|
+
placeholder: React$Node,
|
|
18
|
+
}): React$Node;
|
|
@@ -4,28 +4,16 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var g=require("@lexical/react/LexicalComposerContext"),
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
c
|
|
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
|
-
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(R(d,!0))return b.preventDefault(),b=c,c=M(d),d.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(R(d,!1))return b.preventDefault(),b=c,c=M(d),d.modify(b?"extend":"move",c,"character"),!0;break;case "keyBackspace":return b.preventDefault(),{anchor:b}=d,d.isCollapsed()&&0===b.offset&&0<
|
|
30
|
-
("element"===b.type?b.getNode():b.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),b.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return b.preventDefault(),a.execCommand(b.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),!0;case "copy":return U(b,a),
|
|
31
|
-
!0;case "cut":return T(b,a),!0;case "paste":return S(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return e},[a]);W(a)}module.exports=function({contentEditable:a,placeholder:e}){var [c]=g.useLexicalComposerContext();const b=I(c);X(c);c=J(c);return v.createElement(v.Fragment,null,a,b&&e,c)};
|
|
7
|
+
var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),r=require("lexical"),u=require("react-dom"),v=require("@lexical/clipboard");function w(a,e=!0){if(a)return!1;a=r.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
|
|
8
|
+
function x(a){if(!w(a,!1))return!1;a=r.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let d=0;d<e;d++){var f=a[d];if(r.$isElementNode(f)){if("paragraph"!==f.__type||0!==f.__indent)return!1;f=f.getChildren();const c=f.length;for(let b=0;b<c;b++)if(!r.$isTextNode(f[d]))return!1}}return!0}function y(a){return()=>x(a)}var z="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
|
|
9
|
+
function A(a){const [e,f]=h.useState(a.getEditorState().read(y(a.isComposing())));z(()=>a.addListener("update",({editorState:d})=>{const c=a.isComposing();d=d.read(y(c));f(d)}),[a]);return e}function C(a){const [e,f]=h.useState(()=>a.getDecorators());z(()=>a.addListener("decorator",d=>{u.flushSync(()=>{f(d)})}),[a]);return h.useMemo(()=>{const d=[],c=Object.keys(e);for(let p=0;p<c.length;p++){var b=c[p];const t=e[b];b=a.getElementByKey(b);null!==b&&d.push(u.createPortal(t,b))}return d},[e,a])}
|
|
10
|
+
function D(a){a=a.anchor.getNode();return"rtl"===(r.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function E(a,e){a=r.$getDecoratorNode(a.focus,e);return r.$isDecoratorNode(a)&&!a.isIsolated()}function F(a,e){G(a,e);e.update(()=>{const f=r.$getSelection();r.$isRangeSelection(f)&&f.removeText()})}
|
|
11
|
+
function G(a,e){a.preventDefault();e.update(()=>{const f=a.clipboardData,d=r.$getSelection();if(null!==d&&null!=f){const c=v.getHtmlContent(e),b=v.$getLexicalContent(e);null!==c&&f.setData("text/html",c);null!==b&&f.setData("application/x-lexical-editor",b);f.setData("text/plain",d.getTextContent())}})}function H(a,e){a.preventDefault();e.update(()=>{const f=r.$getSelection(),d=a.clipboardData;null!=d&&r.$isRangeSelection(f)&&v.$insertDataTransferForRichText(d,f,e)})}const I={tag:"history-merge"};
|
|
12
|
+
function J(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=r.$getRoot();if(null===f.getFirstChild()){const d=r.$createParagraphNode();f.append(d);f=document.activeElement;(null!==r.$getSelection()||null!==f&&f===a.getRootElement())&&d.select()}},I);else if(null!==e)switch(typeof e){case "string":e=a.parseEditorState(e);a.setEditorState(e,I);break;case "object":a.setEditorState(e,I);break;case "function":a.update(e,I)}}
|
|
13
|
+
function K(a){h.useEffect(()=>{const e=f=>{var d=a.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var c=JSON.parse(d)}catch(b){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [b,p,t,B,L]=c;a.update(()=>{const q=r.$getSelection();if(r.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;r.$isTextNode(k)&&0<=b&&0<=p&&(l=b,m=b+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
|
|
14
|
+
t)q.insertRawText(t),k=n.getNode();r.$isTextNode(k)&&(l=B,m=B+L,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));f.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
|
|
15
|
+
function M(a,e){z(()=>{const f=a.addListener("command",(d,c)=>{var b=r.$getSelection();if("click"===d&&r.$isNodeSelection(b))return b.clear(),!0;if(!r.$isRangeSelection(b))return!1;switch(d){case "deleteCharacter":return b.deleteCharacter(c),!0;case "deleteWord":return b.deleteWord(c),!0;case "deleteLine":return b.deleteLine(c),!0;case "insertText":return"string"===typeof c?b.insertText(c):(d=c.dataTransfer,null!=d?v.$insertDataTransferForRichText(d,b,a):(c=c.data)&&b.insertText(c)),!0;case "removeText":return b.removeText(),
|
|
16
|
+
!0;case "formatText":return b.formatText(c),!0;case "formatElement":return b=b.anchor.getNode(),(r.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(c),!0;case "insertLineBreak":return b.insertLineBreak(c),!0;case "insertParagraph":return b.insertParagraph(),!0;case "indentContent":return b=b.anchor,b="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),b.canInsertTab()?a.execCommand("insertText","\t"):10!==b.getIndent()&&b.setIndent(b.getIndent()+1),!0;case "outdentContent":return b=b.anchor,
|
|
17
|
+
c=b.getNode(),d="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===c.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=c.shiftKey;if(E(b,!0))return c.preventDefault(),c=d,d=D(b),b.modify(c?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=c.shiftKey;if(E(b,!1))return c.preventDefault(),c=d,d=D(b),b.modify(c?"extend":"move",d,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
|
|
18
|
+
{anchor:c}=b,b.isCollapsed()&&0===c.offset&&0<("element"===c.type?c.getNode():c.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),c.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return c.preventDefault(),a.execCommand(c.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
|
|
19
|
+
!0;case "copy":return G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return H(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);J(a,e);return f},[a]);K(a)}module.exports=function({contentEditable:a,placeholder:e,initialEditorState:f}){const [d]=g.useLexicalComposerContext(),c=A(d);M(d,f);f=C(d);return h.createElement(h.Fragment,null,a,c&&e,f)};
|
|
@@ -37,7 +37,7 @@ function TablePlugin() {
|
|
|
37
37
|
} = payload;
|
|
38
38
|
const selection = lexical.$getSelection();
|
|
39
39
|
|
|
40
|
-
if (selection
|
|
40
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
41
41
|
return true;
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -71,6 +71,28 @@ function TablePlugin() {
|
|
|
71
71
|
return false;
|
|
72
72
|
}, EditorPriority);
|
|
73
73
|
}, [editor]);
|
|
74
|
+
react.useEffect(() => {
|
|
75
|
+
const listeners = new Map();
|
|
76
|
+
return editor.addListener('mutation', table.TableNode, nodeMutations => {
|
|
77
|
+
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
|
78
|
+
for (const [nodeKey, mutation] of nodeMutations) {
|
|
79
|
+
if (mutation === 'created') {
|
|
80
|
+
editor.update(() => {
|
|
81
|
+
const tableElement = editor.getElementByKey(nodeKey);
|
|
82
|
+
const tableNode = lexical.$getNodeByKey(nodeKey);
|
|
83
|
+
|
|
84
|
+
if (tableElement && tableNode) {
|
|
85
|
+
const removeListeners = table.$applyCustomTableHandlers(tableNode, tableElement, editor);
|
|
86
|
+
listeners.set(nodeKey, removeListeners);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
} else if (mutation === 'destroyed') {
|
|
90
|
+
const cleanup = listeners.get(nodeKey);
|
|
91
|
+
if (cleanup) cleanup();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}, [editor]);
|
|
74
96
|
return null;
|
|
75
97
|
}
|
|
76
98
|
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare export default function LexicalTablePlugin(): null;
|
|
@@ -4,6 +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
|
-
var
|
|
8
|
-
module.exports=function(){const [
|
|
9
|
-
|
|
7
|
+
var e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/table"),k=require("lexical"),m=require("react");
|
|
8
|
+
module.exports=function(){const [d]=e.useLexicalComposerContext();m.useEffect(()=>{if(!d.hasNodes([g.TableNode,g.TableCellNode,g.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 d.addListener("command",(a,b)=>{if("insertTable"===a){const {columns:h,rows:f}=b;a=k.$getSelection();if(!k.$isRangeSelection(a))return!0;var c=a.focus;a=c.getNode();null!==a&&(b=g.$createTableNodeWithDimensions(f,
|
|
9
|
+
h),k.$isRootNode(a)?(c=a.getChildAtIndex(c.offset),null!==c?c.insertBefore(b):a.append(b)):a.getTopLevelElementOrThrow().insertAfter(b),b.insertAfter(k.$createParagraphNode()),b.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0}return!1},0)},[d]);m.useEffect(()=>{const a=new Map;return d.addListener("mutation",g.TableNode,b=>{for(const [c,h]of b)"created"===h?d.update(()=>{var f=d.getElementByKey(c);const l=k.$getNodeByKey(c);f&&l&&(f=g.$applyCustomTableHandlers(l,f,d),a.set(c,f))}):
|
|
10
|
+
"destroyed"===h&&(b=a.get(c))&&b()})},[d]);return null};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {LexicalEditor} from 'lexical';
|
|
10
|
+
export default function TreeView(props: {
|
|
11
|
+
timeTravelPanelClassName: string;
|
|
12
|
+
timeTravelPanelSliderClassName: string;
|
|
13
|
+
timeTravelPanelButtonClassName: string;
|
|
14
|
+
timeTravelButtonClassName: string;
|
|
15
|
+
viewClassName: string;
|
|
16
|
+
editor: LexicalEditor;
|
|
17
|
+
}): React.ReactNode;
|
package/LexicalTreeView.dev.js
CHANGED
|
@@ -181,6 +181,14 @@ function printRangeSelection(selection) {
|
|
|
181
181
|
return res;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
function printObjectSelection(selection) {
|
|
185
|
+
return `: node\n └ [${Array.from(selection._nodes).join(', ')}]`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function printGridSelection(selection) {
|
|
189
|
+
return `: grid\n └ { grid: ${selection.gridKey}, anchorCell: ${selection.anchorCellKey}, focusCell: ${selection.focusCellKey} }`;
|
|
190
|
+
}
|
|
191
|
+
|
|
184
192
|
function generateContent(editorState) {
|
|
185
193
|
let res = ' root\n';
|
|
186
194
|
const selectionString = editorState.read(() => {
|
|
@@ -200,7 +208,7 @@ function generateContent(editorState) {
|
|
|
200
208
|
typeDisplay
|
|
201
209
|
});
|
|
202
210
|
});
|
|
203
|
-
return selection === null ? ': null' : printRangeSelection(selection);
|
|
211
|
+
return selection === null ? ': null' : lexical.$isRangeSelection(selection) ? printRangeSelection(selection) : lexical.$isGridSelection(selection) ? printGridSelection(selection) : printObjectSelection(selection);
|
|
204
212
|
});
|
|
205
213
|
return res + '\n selection' + selectionString;
|
|
206
214
|
}
|
|
@@ -279,7 +287,7 @@ function printSelectedCharsLine({
|
|
|
279
287
|
typeDisplay
|
|
280
288
|
}) {
|
|
281
289
|
// No selection or node is not selected.
|
|
282
|
-
if (!lexical.$isTextNode(node) || selection
|
|
290
|
+
if (!lexical.$isTextNode(node) || !lexical.$isRangeSelection(selection) || !isSelected || lexical.$isElementNode(node)) {
|
|
283
291
|
return '';
|
|
284
292
|
} // No selected characters.
|
|
285
293
|
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {LexicalEditor} from 'lexical';
|
|
11
|
+
|
|
12
|
+
declare export default function TreeView(props: {
|
|
13
|
+
timeTravelPanelClassName: string,
|
|
14
|
+
timeTravelPanelSliderClassName: string,
|
|
15
|
+
timeTravelPanelButtonClassName: string,
|
|
16
|
+
timeTravelButtonClassName: string,
|
|
17
|
+
viewClassName: string,
|
|
18
|
+
editor: LexicalEditor,
|
|
19
|
+
}): React$Node;
|
package/LexicalTreeView.prod.js
CHANGED
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var k=require("lexical"),q=require("react");const
|
|
7
|
+
var k=require("lexical"),q=require("react");const t=Object.freeze({"\t":"\\t","\n":"\\n"}),D=new RegExp(Object.keys(t).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
|
-
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
|
|
10
|
-
typeDisplay:g})});return null===c?": null":F(c)
|
|
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 v=b,u=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=v+`${u} ${r} ${f} ${g} ${l}\n`;b+=N({indent:d,isSelected:m,node:e,nodeKeyDisplay:f,selection:c,
|
|
10
|
+
typeDisplay:g})});return null===c?": null":k.$isRangeSelection(c)?F(c):k.$isGridSelection(c)?`: grid\n \u2514 { grid: ${c.gridKey}, anchorCell: ${c.anchorCellKey}, focusCell: ${c.focusCellKey} }`:`: node\n \u2514 [${Array.from(c._nodes).join(", ")}]`});return b+"\n selection"+a}
|
|
11
|
+
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(t).reduce((b,[c,e])=>b.replace(new RegExp(c,"g"),String(e)),a)}
|
|
11
12
|
const O=[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"],P=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],Q=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented",a=>a.isInert()&&"Inert"];function L(a){let b=P.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="detail: "+b);return b}
|
|
12
13
|
function M(a){let b=Q.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="mode: "+b);return b}function G(a){let b=O.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="format: "+b);return b}
|
|
13
|
-
function N({indent:a,isSelected:b,node:c,nodeKeyDisplay:e,selection:d,typeDisplay:f}){if(!k.$isTextNode(c)
|
|
14
|
-
c===n?[d,b]=n.isBefore(
|
|
14
|
+
function N({indent:a,isSelected:b,node:c,nodeKeyDisplay:e,selection:d,typeDisplay:f}){if(!k.$isTextNode(c)||!k.$isRangeSelection(d)||!b||k.$isElementNode(c))return"";b=d.anchor;var g=d.focus;if(""===c.getTextContent()||b.getNode()===d.focus.getNode()&&b.offset===g.offset)return"";g=d.anchor;const m=d.focus,v=c.getTextContent(!0),u=v.length;b=d=-1;if("text"===g.type&&"text"===m.type){const n=g.getNode(),w=m.getNode();n===w&&c===n&&g.offset!==m.offset?[d,b]=g.offset<m.offset?[g.offset,m.offset]:[m.offset,
|
|
15
|
+
g.offset]:c===n?[d,b]=n.isBefore(w)?[g.offset,u]:[0,g.offset]:c===w?[d,b]=w.isBefore(n)?[m.offset,u]:[0,m.offset]:[d,b]=[0,u]}c=(v.slice(0,d).match(D)||[]).length;g=(v.slice(d,b).match(D)||[]).length;const [r,l]=[d+c,b+c+g];if(r===l)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(l-r).fill(E.selectedChar);e=Array(e.length+(f.length+3)).fill(" ");return[E.selectedLine,a.join(" "),[...e,...c,...d].join("")].join(" ")+
|
|
15
16
|
"\n"}
|
|
16
|
-
module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:e,timeTravelPanelClassName:d,editor:f}){const [g,m]=q.useState([]),[u
|
|
17
|
-
m(A=>[...A,[Date.now(),h]])})},[r,f]);const y=g.length;q.useEffect(()=>{if(z){let h;const p=()=>{const x=n.current;x===y-1?C(!1):h=setTimeout(()=>{n.current++;const A=n.current,I=B.current;null!==I&&(I.value=String(A));f.setEditorState(g[A][1]);p()},g[x+1][0]-g[x][0])};p();return()=>{window.clearTimeout(h)}}},[g,z,f,y]);q.useEffect(()=>{const h=
|
|
18
|
-
{onClick:()=>{const h=f.getRootElement();null!==h&&(h.contentEditable="false",n.current=y-1,l(!0))},className:a},"Time Travel"),q.createElement("pre",{ref:
|
|
17
|
+
module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:e,timeTravelPanelClassName:d,editor:f}){const [g,m]=q.useState([]),[v,u]=q.useState(""),[r,l]=q.useState(!1),n=q.useRef(0),w=q.useRef(null),B=q.useRef(null),[z,C]=q.useState(!1);q.useEffect(()=>{u(H(f.getEditorState()));return f.addListener("update",({editorState:h})=>{const p=f._compositionKey,x=H(f.getEditorState());u([x,null!==p&&`Composition key: ${p}`].filter(Boolean).join("\n\n"));r||
|
|
18
|
+
m(A=>[...A,[Date.now(),h]])})},[r,f]);const y=g.length;q.useEffect(()=>{if(z){let h;const p=()=>{const x=n.current;x===y-1?C(!1):h=setTimeout(()=>{n.current++;const A=n.current,I=B.current;null!==I&&(I.value=String(A));f.setEditorState(g[A][1]);p()},g[x+1][0]-g[x][0])};p();return()=>{window.clearTimeout(h)}}},[g,z,f,y]);q.useEffect(()=>{const h=w.current;if(null!==h)return h.__lexicalEditor=f,()=>{h.__lexicalEditor=null}},[f]);return q.createElement("div",{className:e},!r&&2<y&&q.createElement("button",
|
|
19
|
+
{onClick:()=>{const h=f.getRootElement();null!==h&&(h.contentEditable="false",n.current=y-1,l(!0))},className:a},"Time Travel"),q.createElement("pre",{ref:w},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=g[h];p&&(n.current=h,f.setEditorState(p[1]))},type:"range",min:"1",max:y-1}),q.createElement("button",{className:c,onClick:()=>{var h=f.getRootElement();
|
|
19
20
|
if(null!==h){h.contentEditable="true";h=g.length-1;f.setEditorState(g[h][1]);const p=B.current;null!==p&&(p.value=String(h));l(!1);C(!1)}}},"Exit")))};
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -12,12 +12,13 @@
|
|
|
12
12
|
"rich-text"
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"version": "0.1.
|
|
15
|
+
"version": "0.1.12",
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"lexical": "0.1.
|
|
18
|
-
"@lexical/helpers": "0.1.
|
|
19
|
-
"@lexical/table": "0.1.
|
|
20
|
-
"@lexical/yjs": "0.1.
|
|
17
|
+
"lexical": "0.1.12",
|
|
18
|
+
"@lexical/helpers": "0.1.12",
|
|
19
|
+
"@lexical/table": "0.1.12",
|
|
20
|
+
"@lexical/yjs": "0.1.12",
|
|
21
|
+
"@lexical/clipboard": "0.1.12",
|
|
21
22
|
"react": ">=17.x",
|
|
22
23
|
"react-dom": ">=17.x"
|
|
23
24
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {DecoratorMap, DecoratorStateValue} from 'lexical';
|
|
10
|
+
export default function useLexicalDecoratorMap<V extends DecoratorStateValue>(
|
|
11
|
+
decoratorMap: DecoratorMap,
|
|
12
|
+
key: string,
|
|
13
|
+
initialValue: (() => V) | V,
|
|
14
|
+
): [V, (arg0: DecoratorStateValue) => void];
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {DecoratorMap, DecoratorStateValue} from 'lexical';
|
|
11
|
+
|
|
12
|
+
declare export default function useLexicalDecoratorMap<V: DecoratorStateValue>(
|
|
13
|
+
decoratorMap: DecoratorMap,
|
|
14
|
+
key: string,
|
|
15
|
+
initialValue: (() => V) | V,
|
|
16
|
+
): [V, (DecoratorStateValue) => void];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {LexicalEditor} from 'lexical';
|
|
10
|
+
export default function useLexicalIsTextContentEmpty(
|
|
11
|
+
editor: LexicalEditor,
|
|
12
|
+
trim?: boolean,
|
|
13
|
+
): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {LexicalEditor} from 'lexical';
|
|
11
|
+
|
|
12
|
+
declare export default function useLexicalIsTextContentEmpty(
|
|
13
|
+
editor: LexicalEditor,
|
|
14
|
+
trim?: boolean,
|
|
15
|
+
): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {NodeKey} from 'lexical';
|
|
10
|
+
export default function useLexicalNodeSelection(
|
|
11
|
+
key: NodeKey,
|
|
12
|
+
): [boolean, (arg0: boolean) => void, () => void];
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
|
|
22
|
+
function isNodeSelected(editor, key) {
|
|
23
|
+
return editor.getEditorState().read(() => {
|
|
24
|
+
const node = lexical.$getNodeByKey(key);
|
|
25
|
+
|
|
26
|
+
if (node === null) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return node.isSelected();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function useLexicalNodeSelection(key) {
|
|
35
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
36
|
+
const [isSelected, setIsSelected] = react.useState(() => isNodeSelected(editor, key));
|
|
37
|
+
react.useEffect(() => {
|
|
38
|
+
return editor.addListener('update', () => {
|
|
39
|
+
setIsSelected(isNodeSelected(editor, key));
|
|
40
|
+
});
|
|
41
|
+
}, [editor, key]);
|
|
42
|
+
const setSelected = react.useCallback(selected => {
|
|
43
|
+
editor.update(() => {
|
|
44
|
+
let selection = lexical.$getSelection();
|
|
45
|
+
|
|
46
|
+
if (!lexical.$isNodeSelection(selection)) {
|
|
47
|
+
selection = lexical.$createNodeSelection();
|
|
48
|
+
lexical.$setSelection(selection);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (selected) {
|
|
52
|
+
selection.add(key);
|
|
53
|
+
} else {
|
|
54
|
+
selection.delete(key);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}, [editor, key]);
|
|
58
|
+
const clearSelected = react.useCallback(() => {
|
|
59
|
+
editor.update(() => {
|
|
60
|
+
const selection = lexical.$getSelection();
|
|
61
|
+
|
|
62
|
+
if (lexical.$isNodeSelection(selection)) {
|
|
63
|
+
selection.clear();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}, [editor]);
|
|
67
|
+
return [isSelected, setSelected, clearSelected];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = useLexicalNodeSelection;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
'use strict'
|
|
8
|
+
const useLexicalNodeSelection = process.env.NODE_ENV === 'development' ? require('./useLexicalNodeSelection.dev.js') : require('./useLexicalNodeSelection.prod.js')
|
|
9
|
+
module.exports = useLexicalNodeSelection;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {NodeKey} from 'lexical';
|
|
11
|
+
|
|
12
|
+
declare export default function useLexicalNodeSelection(
|
|
13
|
+
key: NodeKey,
|
|
14
|
+
): [boolean, (boolean) => void, () => void];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
var c=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),h=require("react");function k(b,a){return b.getEditorState().read(()=>{const f=e.$getNodeByKey(a);return null===f?!1:f.isSelected()})}
|
|
8
|
+
module.exports=function(b){const [a]=c.useLexicalComposerContext(),[f,l]=h.useState(()=>k(a,b));h.useEffect(()=>a.addListener("update",()=>{l(k(a,b))}),[a,b]);const m=h.useCallback(g=>{a.update(()=>{let d=e.$getSelection();e.$isNodeSelection(d)||(d=e.$createNodeSelection(),e.$setSelection(d));g?d.add(b):d.delete(b)})},[a,b]),n=h.useCallback(()=>{a.update(()=>{const g=e.$getSelection();e.$isNodeSelection(g)&&g.clear()})},[a]);return[f,m,n]};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
type UnsubscribeFn = () => void;
|
|
10
|
+
export default function withSubscriptions(
|
|
11
|
+
...unsubscribe: Array<UnsubscribeFn>
|
|
12
|
+
): () => void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
type UnsubscribeFn = () => void;
|
|
11
|
+
declare export default function withSubscriptions(
|
|
12
|
+
...unsubscribe: Array<UnsubscribeFn>
|
|
13
|
+
): () => void;
|