@lexical/react 0.12.1 → 0.12.3
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/LexicalAutoEmbedPlugin.d.ts +3 -2
- package/LexicalAutoEmbedPlugin.dev.js +4 -14
- package/LexicalAutoEmbedPlugin.prod.js +4 -3
- package/LexicalAutoFocusPlugin.dev.js +0 -1
- package/LexicalAutoLinkPlugin.dev.js +126 -73
- package/LexicalAutoLinkPlugin.prod.js +11 -7
- package/LexicalBlockWithAlignableContents.dev.js +0 -10
- package/LexicalCharacterLimitPlugin.dev.js +7 -46
- package/LexicalCheckListPlugin.dev.js +10 -48
- package/LexicalClearEditorPlugin.dev.js +1 -1
- package/LexicalClickableLinkPlugin.dev.js +2 -20
- package/LexicalCollaborationContext.dev.js +0 -3
- package/LexicalCollaborationPlugin.dev.js +8 -37
- package/LexicalComposer.d.ts +3 -7
- package/LexicalComposer.dev.js +9 -11
- package/LexicalComposer.js.flow +4 -4
- package/LexicalComposer.prod.js +2 -1
- package/LexicalComposerContext.dev.js +0 -6
- package/LexicalContentEditable.dev.js +1 -2
- package/LexicalContextMenuPlugin.d.ts +3 -2
- package/LexicalContextMenuPlugin.dev.js +28 -82
- package/LexicalContextMenuPlugin.prod.js +16 -15
- package/LexicalDecoratorBlockNode.dev.js +0 -6
- package/LexicalEditorRefPlugin.dev.js +0 -3
- package/LexicalHashtagPlugin.dev.js +73 -43
- package/LexicalHorizontalRuleNode.dev.js +0 -21
- package/LexicalHorizontalRulePlugin.dev.js +0 -4
- package/LexicalLinkPlugin.dev.js +4 -10
- package/LexicalListPlugin.dev.js +0 -2
- package/LexicalMarkdownShortcutPlugin.dev.js +2 -2
- package/LexicalNestedComposer.d.ts +2 -2
- package/LexicalNestedComposer.dev.js +18 -16
- package/LexicalNestedComposer.js.flow +7 -2
- package/LexicalNestedComposer.prod.js +4 -3
- package/LexicalNodeEventPlugin.dev.js +2 -6
- package/LexicalNodeMenuPlugin.d.ts +3 -2
- package/LexicalNodeMenuPlugin.dev.js +27 -83
- package/LexicalNodeMenuPlugin.prod.js +15 -15
- package/LexicalOnChangePlugin.dev.js +1 -1
- package/LexicalPlainTextPlugin.dev.js +8 -12
- package/LexicalRichTextPlugin.dev.js +8 -12
- package/LexicalTabIndentationPlugin.dev.js +7 -16
- package/LexicalTableOfContents.dev.js +5 -33
- package/LexicalTablePlugin.dev.js +11 -28
- package/LexicalTreeView.dev.js +14 -79
- package/LexicalTypeaheadMenuPlugin.d.ts +4 -3
- package/LexicalTypeaheadMenuPlugin.dev.js +39 -176
- package/LexicalTypeaheadMenuPlugin.prod.js +19 -20
- package/package.json +19 -19
- package/shared/LexicalMenu.d.ts +3 -2
- package/useLexicalEditable.dev.js +1 -5
- package/useLexicalIsTextContentEmpty.dev.js +1 -0
- package/useLexicalNodeSelection.dev.js +0 -7
- package/useLexicalSubscription.dev.js +1 -3
|
@@ -4,23 +4,22 @@
|
|
|
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
|
-
'use strict';var k=require("@lexical/react/LexicalComposerContext"),
|
|
8
|
-
let
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
()=>{let g=a.getRootElement();null!==g&&g.removeAttribute("aria-activedescendant")},[a]);
|
|
15
|
-
g.preventDefault();g.stopImmediatePropagation()}return!0},
|
|
16
|
-
f
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
()=>{null!==
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,onOpen:
|
|
23
|
-
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
26
|
-
c);document.removeEventListener("scroll",h)}}},[a,f,e,c,b])}
|
|
7
|
+
'use strict';var k=require("@lexical/react/LexicalComposerContext"),p=require("lexical"),y=require("react"),z=require("@lexical/utils"),A="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?y.useLayoutEffect:y.useEffect;class B{constructor(b){this.key=b;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(b){this.ref={current:b}}}
|
|
8
|
+
let C=b=>{const a=document.getElementById("typeahead-menu");if(a){var c=a.getBoundingClientRect();c.top+c.height>window.innerHeight&&a.scrollIntoView({block:"center"});0>c.top&&a.scrollIntoView({block:"center"});b.scrollIntoView({block:"nearest"})}};
|
|
9
|
+
function D(b){var a=p.$getSelection();if(!p.$isRangeSelection(a)||!a.isCollapsed())return null;var c=a.anchor;if("text"!==c.type)return null;a=c.getNode();if(!a.isSimpleText())return null;c=c.offset;let d=a.getTextContent().slice(0,c);var e=b.matchingString;b=b.replaceableString.length;for(let t=b;t<=e.length;t++)d.substr(-t)===e.substr(0,t)&&(b=t);b=c-b;if(0>b)return null;let r;0===b?[r]=a.splitText(c):[,r]=a.splitText(b,c);return r}
|
|
10
|
+
function G(b,a){let c=getComputedStyle(b),d="absolute"===c.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===c.position)return document.body;for(;b=b.parentElement;)if(c=getComputedStyle(b),(!d||"static"!==c.position)&&a.test(c.overflow+c.overflowY+c.overflowX))return b;return document.body}function H(b,a){b=b.getBoundingClientRect();a=a.getBoundingClientRect();return b.top>a.top&&b.top<a.bottom}
|
|
11
|
+
function I(b,a,c,d){let [e]=k.useLexicalComposerContext();y.useEffect(()=>{if(null!=a&&null!=b){let r=e.getRootElement(),t=null!=r?G(r,!1):document.body,n=!1,h=H(a,t),f=function(){n||(window.requestAnimationFrame(function(){c();n=!1}),n=!0);const u=H(a,t);u!==h&&(h=u,null!=d&&d(u))},m=new ResizeObserver(c);window.addEventListener("resize",c);document.addEventListener("scroll",f,{capture:!0,passive:!0});m.observe(a);return()=>{m.unobserve(a);window.removeEventListener("resize",c);document.removeEventListener("scroll",
|
|
12
|
+
f,!0)}}},[a,e,d,c,b])}let J=p.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
|
|
13
|
+
function K({close:b,editor:a,anchorElementRef:c,resolution:d,options:e,menuRenderFn:r,onSelectOption:t,shouldSplitNodeWithQuery:n=!1,commandPriority:h=p.COMMAND_PRIORITY_LOW}){let [f,m]=y.useState(null);y.useEffect(()=>{m(0)},[d.match&&d.match.matchingString]);let u=y.useCallback(g=>{a.update(()=>{const l=null!=d.match&&n?D(d.match):null;t(g,l,b,d.match?d.match.matchingString:"")})},[a,n,d.match,t,b]),q=y.useCallback(g=>{const l=a.getRootElement();null!==l&&(l.setAttribute("aria-activedescendant",
|
|
14
|
+
"typeahead-item-"+g),m(g))},[a]);y.useEffect(()=>()=>{let g=a.getRootElement();null!==g&&g.removeAttribute("aria-activedescendant")},[a]);A(()=>{null===e?m(null):null===f&&q(0)},[e,f,q]);y.useEffect(()=>z.mergeRegister(a.registerCommand(J,({option:g})=>g.ref&&null!=g.ref.current?(C(g.ref.current),!0):!1,h)),[a,q,h]);y.useEffect(()=>z.mergeRegister(a.registerCommand(p.KEY_ARROW_DOWN_COMMAND,g=>{if(null!==e&&e.length&&null!==f){let l=f!==e.length-1?f+1:0;q(l);let v=e[l];null!=v.ref&&v.ref.current&&
|
|
15
|
+
a.dispatchCommand(J,{index:l,option:v});g.preventDefault();g.stopImmediatePropagation()}return!0},h),a.registerCommand(p.KEY_ARROW_UP_COMMAND,g=>{if(null!==e&&e.length&&null!==f){var l=0!==f?f-1:e.length-1;q(l);l=e[l];null!=l.ref&&l.ref.current&&C(l.ref.current);g.preventDefault();g.stopImmediatePropagation()}return!0},h),a.registerCommand(p.KEY_ESCAPE_COMMAND,g=>{g.preventDefault();g.stopImmediatePropagation();b();return!0},h),a.registerCommand(p.KEY_TAB_COMMAND,g=>{if(null===e||null===f||null==
|
|
16
|
+
e[f])return!1;g.preventDefault();g.stopImmediatePropagation();u(e[f]);return!0},h),a.registerCommand(p.KEY_ENTER_COMMAND,g=>{if(null===e||null===f||null==e[f])return!1;null!==g&&(g.preventDefault(),g.stopImmediatePropagation());u(e[f]);return!0},h)),[u,b,a,e,f,q,h]);let w=y.useMemo(()=>({options:e,selectOptionAndCleanUp:u,selectedIndex:f,setHighlightedIndex:m}),[u,f,e]);return r(c,w,d.match?d.match.matchingString:"")}
|
|
17
|
+
function L(b,a,c){let [d]=k.useLexicalComposerContext(),e=y.useRef(document.createElement("div")),r=y.useCallback(()=>{e.current.style.top=e.current.style.bottom;const n=d.getRootElement(),h=e.current;var f=h.firstChild;if(null!==n&&null!==b){const {left:u,top:q,width:w,height:g}=b.getRect();h.style.top=`${q+window.pageYOffset+e.current.offsetHeight+3}px`;h.style.left=`${u+window.pageXOffset}px`;h.style.height=`${g}px`;h.style.width=`${w}px`;if(null!==f){f.style.top=`${q}`;var m=f.getBoundingClientRect();
|
|
18
|
+
f=m.height;m=m.width;const l=n.getBoundingClientRect();u+m>l.right&&(h.style.left=`${l.right-m+window.pageXOffset}px`);(q+f>window.innerHeight||q+f>l.bottom)&&q-l.top>f&&(h.style.top=`${q-f+window.pageYOffset-g}px`)}h.isConnected||(null!=c&&(h.className=c),h.setAttribute("aria-label","Typeahead menu"),h.setAttribute("id","typeahead-menu"),h.setAttribute("role","listbox"),h.style.display="block",h.style.position="absolute",document.body.append(h));e.current=h;n.setAttribute("aria-controls","typeahead-menu")}},
|
|
19
|
+
[d,b,c]);y.useEffect(()=>{let n=d.getRootElement();if(null!==b)return r(),()=>{null!==n&&n.removeAttribute("aria-controls");let h=e.current;null!==h&&h.isConnected&&h.remove()}},[d,r,b]);let t=y.useCallback(n=>{null!==b&&(n||a(null))},[b,a]);I(b,e.current,r,t);return e}function M(b,a,c){var d=c.getSelection();if(null===d||!d.isCollapsed)return!1;c=d.anchorNode;d=d.anchorOffset;if(null==c||null==d)return!1;try{a.setStart(c,b),a.setEnd(c,d)}catch(e){return!1}return!0}
|
|
20
|
+
function N(b){let a=null;b.getEditorState().read(()=>{var c=p.$getSelection();if(p.$isRangeSelection(c)){var d=c.anchor;"text"!==d.type?a=null:(c=d.getNode(),c.isSimpleText()?(d=d.offset,a=c.getTextContent().slice(0,d)):a=null)}});return a}function O(b,a){return 0!==a?!1:b.getEditorState().read(()=>{var c=p.$getSelection();return p.$isRangeSelection(c)?(c=c.anchor.getNode().getPreviousSibling(),p.$isTextNode(c)&&c.isTextEntity()):!1})}function P(b){y.startTransition?y.startTransition(b):b()}
|
|
21
|
+
let Q=p.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
|
|
22
|
+
exports.LexicalTypeaheadMenuPlugin=function({options:b,onQueryChange:a,onSelectOption:c,onOpen:d,onClose:e,menuRenderFn:r,triggerFn:t,anchorClassName:n,commandPriority:h=p.COMMAND_PRIORITY_LOW}){let [f]=k.useLexicalComposerContext(),[m,u]=y.useState(null);n=L(m,u,n);let q=y.useCallback(()=>{u(null);null!=e&&null!==m&&e()},[e,m]),w=y.useCallback(g=>{u(g);null!=d&&null===m&&d(g)},[d,m]);y.useEffect(()=>{let g=f.registerUpdateListener(()=>{f.getEditorState().read(()=>{const l=f._window||window,v=l.document.createRange(),
|
|
23
|
+
E=p.$getSelection(),F=N(f);if(p.$isRangeSelection(E)&&E.isCollapsed()&&null!==F&&null!==v){var x=t(F,f);a(x?x.matchingString:null);null===x||O(f,x.leadOffset)||null===M(x.leadOffset,v,l)?q():P(()=>w({getRect:()=>v.getBoundingClientRect(),match:x}))}else q()})});return()=>{g()}},[f,t,a,m,q,w]);return null===m||null===f?null:y.createElement(K,{close:q,resolution:m,editor:f,anchorElementRef:n,options:b,menuRenderFn:r,shouldSplitNodeWithQuery:!0,onSelectOption:c,commandPriority:h})};
|
|
24
|
+
exports.MenuOption=B;exports.PUNCTUATION="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";exports.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND=Q;exports.getScrollParent=function(b,a){let c=getComputedStyle(b),d="absolute"===c.position;a=a?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===c.position)return document.body;for(;b=b.parentElement;)if(c=getComputedStyle(b),(!d||"static"!==c.position)&&a.test(c.overflow+c.overflowY+c.overflowX))return b;return document.body};
|
|
25
|
+
exports.useBasicTypeaheadTriggerMatch=function(b,{minLength:a=1,maxLength:c=75}){return y.useCallback(d=>{d=(new RegExp("(^|\\s|\\()(["+b+"]((?:[^"+(b+"\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;\\s]){0,")+c+"}))$")).exec(d);if(null!==d){let e=d[1],r=d[3];if(r.length>=a)return{leadOffset:d.index+e.length,matchingString:r,replaceableString:d[2]}}return null},[c,a,b])};exports.useDynamicPositioning=I
|
package/package.json
CHANGED
|
@@ -8,29 +8,29 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.12.
|
|
11
|
+
"version": "0.12.3",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.12.
|
|
14
|
-
"@lexical/code": "0.12.
|
|
15
|
-
"@lexical/dragon": "0.12.
|
|
16
|
-
"@lexical/hashtag": "0.12.
|
|
17
|
-
"@lexical/history": "0.12.
|
|
18
|
-
"@lexical/link": "0.12.
|
|
19
|
-
"@lexical/list": "0.12.
|
|
20
|
-
"@lexical/mark": "0.12.
|
|
21
|
-
"@lexical/markdown": "0.12.
|
|
22
|
-
"@lexical/overflow": "0.12.
|
|
23
|
-
"@lexical/plain-text": "0.12.
|
|
24
|
-
"@lexical/rich-text": "0.12.
|
|
25
|
-
"@lexical/selection": "0.12.
|
|
26
|
-
"@lexical/table": "0.12.
|
|
27
|
-
"@lexical/text": "0.12.
|
|
28
|
-
"@lexical/utils": "0.12.
|
|
29
|
-
"@lexical/yjs": "0.12.
|
|
13
|
+
"@lexical/clipboard": "0.12.3",
|
|
14
|
+
"@lexical/code": "0.12.3",
|
|
15
|
+
"@lexical/dragon": "0.12.3",
|
|
16
|
+
"@lexical/hashtag": "0.12.3",
|
|
17
|
+
"@lexical/history": "0.12.3",
|
|
18
|
+
"@lexical/link": "0.12.3",
|
|
19
|
+
"@lexical/list": "0.12.3",
|
|
20
|
+
"@lexical/mark": "0.12.3",
|
|
21
|
+
"@lexical/markdown": "0.12.3",
|
|
22
|
+
"@lexical/overflow": "0.12.3",
|
|
23
|
+
"@lexical/plain-text": "0.12.3",
|
|
24
|
+
"@lexical/rich-text": "0.12.3",
|
|
25
|
+
"@lexical/selection": "0.12.3",
|
|
26
|
+
"@lexical/table": "0.12.3",
|
|
27
|
+
"@lexical/text": "0.12.3",
|
|
28
|
+
"@lexical/utils": "0.12.3",
|
|
29
|
+
"@lexical/yjs": "0.12.3",
|
|
30
30
|
"react-error-boundary": "^3.1.4"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"lexical": "0.12.
|
|
33
|
+
"lexical": "0.12.3",
|
|
34
34
|
"react": ">=17.x",
|
|
35
35
|
"react-dom": ">=17.x"
|
|
36
36
|
},
|
package/shared/LexicalMenu.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { LexicalCommand, LexicalEditor, TextNode } from 'lexical';
|
|
8
|
+
import { CommandListenerPriority, LexicalCommand, LexicalEditor, TextNode } from 'lexical';
|
|
9
9
|
import { MutableRefObject, ReactPortal } from 'react';
|
|
10
10
|
export type MenuTextMatch = {
|
|
11
11
|
leadOffset: number;
|
|
@@ -35,7 +35,7 @@ export declare const SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND: LexicalCommand<{
|
|
|
35
35
|
index: number;
|
|
36
36
|
option: MenuOption;
|
|
37
37
|
}>;
|
|
38
|
-
export declare function LexicalMenu<TOption extends MenuOption>({ close, editor, anchorElementRef, resolution, options, menuRenderFn, onSelectOption, shouldSplitNodeWithQuery, }: {
|
|
38
|
+
export declare function LexicalMenu<TOption extends MenuOption>({ close, editor, anchorElementRef, resolution, options, menuRenderFn, onSelectOption, shouldSplitNodeWithQuery, commandPriority, }: {
|
|
39
39
|
close: () => void;
|
|
40
40
|
editor: LexicalEditor;
|
|
41
41
|
anchorElementRef: MutableRefObject<HTMLElement>;
|
|
@@ -44,6 +44,7 @@ export declare function LexicalMenu<TOption extends MenuOption>({ close, editor,
|
|
|
44
44
|
shouldSplitNodeWithQuery?: boolean;
|
|
45
45
|
menuRenderFn: MenuRenderFn<TOption>;
|
|
46
46
|
onSelectOption: (option: TOption, textNodeContainingQuery: TextNode | null, closeMenu: () => void, matchingString: string) => void;
|
|
47
|
+
commandPriority?: CommandListenerPriority;
|
|
47
48
|
}): JSX.Element | null;
|
|
48
49
|
export declare function useMenuAnchorRef(resolution: MenuResolution | null, setResolution: (r: MenuResolution | null) => void, className?: string): MutableRefObject<HTMLElement>;
|
|
49
50
|
export type TriggerFn = (text: string, editor: LexicalEditor) => MenuTextMatch | null;
|
|
@@ -16,6 +16,7 @@ var react = require('react');
|
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
|
+
|
|
19
20
|
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -35,7 +36,6 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
35
36
|
* LICENSE file in the root directory of this source tree.
|
|
36
37
|
*
|
|
37
38
|
*/
|
|
38
|
-
|
|
39
39
|
/**
|
|
40
40
|
* Shortcut to Lexical subscriptions when values are used for render.
|
|
41
41
|
*/
|
|
@@ -50,12 +50,10 @@ function useLexicalSubscription(subscription) {
|
|
|
50
50
|
subscribe
|
|
51
51
|
} = initializedSubscription;
|
|
52
52
|
const currentValue = initialValueFn();
|
|
53
|
-
|
|
54
53
|
if (valueRef.current !== currentValue) {
|
|
55
54
|
valueRef.current = currentValue;
|
|
56
55
|
setValue(currentValue);
|
|
57
56
|
}
|
|
58
|
-
|
|
59
57
|
return subscribe(newValue => {
|
|
60
58
|
valueRef.current = newValue;
|
|
61
59
|
setValue(newValue);
|
|
@@ -71,7 +69,6 @@ function useLexicalSubscription(subscription) {
|
|
|
71
69
|
* LICENSE file in the root directory of this source tree.
|
|
72
70
|
*
|
|
73
71
|
*/
|
|
74
|
-
|
|
75
72
|
function subscription(editor) {
|
|
76
73
|
return {
|
|
77
74
|
initialValueFn: () => editor.isEditable(),
|
|
@@ -80,7 +77,6 @@ function subscription(editor) {
|
|
|
80
77
|
}
|
|
81
78
|
};
|
|
82
79
|
}
|
|
83
|
-
|
|
84
80
|
function useLexicalEditable() {
|
|
85
81
|
return useLexicalSubscription(subscription);
|
|
86
82
|
}
|
|
@@ -16,6 +16,7 @@ var react = require('react');
|
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
|
+
|
|
19
20
|
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -17,19 +17,15 @@ var react = require('react');
|
|
|
17
17
|
* LICENSE file in the root directory of this source tree.
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
20
|
function isNodeSelected(editor, key) {
|
|
22
21
|
return editor.getEditorState().read(() => {
|
|
23
22
|
const node = lexical.$getNodeByKey(key);
|
|
24
|
-
|
|
25
23
|
if (node === null) {
|
|
26
24
|
return false;
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
return node.isSelected();
|
|
30
27
|
});
|
|
31
28
|
}
|
|
32
|
-
|
|
33
29
|
function useLexicalNodeSelection(key) {
|
|
34
30
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
35
31
|
const [isSelected, setIsSelected] = react.useState(() => isNodeSelected(editor, key));
|
|
@@ -48,12 +44,10 @@ function useLexicalNodeSelection(key) {
|
|
|
48
44
|
const setSelected = react.useCallback(selected => {
|
|
49
45
|
editor.update(() => {
|
|
50
46
|
let selection = lexical.$getSelection();
|
|
51
|
-
|
|
52
47
|
if (!lexical.$isNodeSelection(selection)) {
|
|
53
48
|
selection = lexical.$createNodeSelection();
|
|
54
49
|
lexical.$setSelection(selection);
|
|
55
50
|
}
|
|
56
|
-
|
|
57
51
|
if (selected) {
|
|
58
52
|
selection.add(key);
|
|
59
53
|
} else {
|
|
@@ -64,7 +58,6 @@ function useLexicalNodeSelection(key) {
|
|
|
64
58
|
const clearSelected = react.useCallback(() => {
|
|
65
59
|
editor.update(() => {
|
|
66
60
|
const selection = lexical.$getSelection();
|
|
67
|
-
|
|
68
61
|
if (lexical.$isNodeSelection(selection)) {
|
|
69
62
|
selection.clear();
|
|
70
63
|
}
|
|
@@ -16,6 +16,7 @@ var react = require('react');
|
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
|
+
|
|
19
20
|
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -35,7 +36,6 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
35
36
|
* LICENSE file in the root directory of this source tree.
|
|
36
37
|
*
|
|
37
38
|
*/
|
|
38
|
-
|
|
39
39
|
/**
|
|
40
40
|
* Shortcut to Lexical subscriptions when values are used for render.
|
|
41
41
|
*/
|
|
@@ -50,12 +50,10 @@ function useLexicalSubscription(subscription) {
|
|
|
50
50
|
subscribe
|
|
51
51
|
} = initializedSubscription;
|
|
52
52
|
const currentValue = initialValueFn();
|
|
53
|
-
|
|
54
53
|
if (valueRef.current !== currentValue) {
|
|
55
54
|
valueRef.current = currentValue;
|
|
56
55
|
setValue(currentValue);
|
|
57
56
|
}
|
|
58
|
-
|
|
59
57
|
return subscribe(newValue => {
|
|
60
58
|
valueRef.current = newValue;
|
|
61
59
|
setValue(newValue);
|