@lexical/react 0.6.3 → 0.6.5

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.
@@ -29,7 +29,7 @@ function AutoFocusPlugin({
29
29
  const activeElement = document.activeElement;
30
30
  const rootElement = editor.getRootElement();
31
31
 
32
- if (!rootElement.contains(activeElement) || rootElement !== null || activeElement === null) {
32
+ if (rootElement !== null && (activeElement === null || !rootElement.contains(activeElement))) {
33
33
  // Note: preventScroll won't work in Webkit.
34
34
  rootElement.focus({
35
35
  preventScroll: true
@@ -4,4 +4,4 @@
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 e=require("@lexical/react/LexicalComposerContext"),f=require("react");exports.AutoFocusPlugin=function({defaultSelection:c}){let [a]=e.useLexicalComposerContext();f.useEffect(()=>{a.focus(()=>{let d=document.activeElement,b=a.getRootElement();b.contains(d)&&null===b&&null!==d||b.focus({preventScroll:!0})},{defaultSelection:c})},[c,a]);return null}
7
+ 'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("react");exports.AutoFocusPlugin=function({defaultSelection:c}){let [a]=e.useLexicalComposerContext();f.useEffect(()=>{a.focus(()=>{let d=document.activeElement,b=a.getRootElement();null===b||null!==d&&b.contains(d)||b.focus({preventScroll:!0})},{defaultSelection:c})},[c,a]);return null}
@@ -7,22 +7,23 @@
7
7
  */
8
8
  import { EditorState, EditorThemeClasses, Klass, LexicalEditor, LexicalNode } from 'lexical';
9
9
  export declare type InitialEditorStateType = null | string | EditorState | ((editor: LexicalEditor) => void);
10
+ export declare type InitialConfigType = Readonly<{
11
+ editor__DEPRECATED?: LexicalEditor | null;
12
+ namespace: string;
13
+ nodes?: ReadonlyArray<Klass<LexicalNode> | {
14
+ replace: Klass<LexicalNode>;
15
+ with: <T extends {
16
+ new (...args: any): any;
17
+ }>(node: InstanceType<T>) => LexicalNode;
18
+ }>;
19
+ onError: (error: Error, editor: LexicalEditor) => void;
20
+ editable?: boolean;
21
+ theme?: EditorThemeClasses;
22
+ editorState?: InitialEditorStateType;
23
+ }>;
10
24
  declare type Props = {
11
25
  children: JSX.Element | string | (JSX.Element | string)[];
12
- initialConfig: Readonly<{
13
- editor__DEPRECATED?: LexicalEditor | null;
14
- namespace: string;
15
- nodes?: ReadonlyArray<Klass<LexicalNode> | {
16
- replace: Klass<LexicalNode>;
17
- with: <T extends {
18
- new (...args: any): any;
19
- }>(node: InstanceType<T>) => LexicalNode;
20
- }>;
21
- onError: (error: Error, editor: LexicalEditor) => void;
22
- editable?: boolean;
23
- theme?: EditorThemeClasses;
24
- editorState?: InitialEditorStateType;
25
- }>;
26
+ initialConfig: InitialConfigType;
26
27
  };
27
28
  export declare function LexicalComposer({ initialConfig, children }: Props): JSX.Element;
28
29
  export {};
@@ -92,7 +92,7 @@ function initializeEditor(editor, initialEditorState) {
92
92
  if (root.isEmpty()) {
93
93
  const paragraph = lexical.$createParagraphNode();
94
94
  root.append(paragraph);
95
- const activeElement = document.activeElement;
95
+ const activeElement = CAN_USE_DOM ? document.activeElement : null;
96
96
 
97
97
  if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
98
98
  paragraph.select();
@@ -20,19 +20,21 @@ export type InitialEditorStateType =
20
20
  | EditorState
21
21
  | ((editor: LexicalEditor) => void);
22
22
 
23
+ export type InitialConfigType = $ReadOnly<{
24
+ editor__DEPRECATED?: LexicalEditor | null,
25
+ editable?: boolean,
26
+ namespace: string,
27
+ nodes?: $ReadOnlyArray<
28
+ | Class<LexicalNode>
29
+ | {replace: Class<LexicalNode>, with: (node: LexicalNode) => LexicalNode},
30
+ >,
31
+ theme?: EditorThemeClasses,
32
+ editorState?: InitialEditorStateType,
33
+ onError: (error: Error, editor: LexicalEditor) => void,
34
+ }>;
35
+
23
36
  type Props = {
24
- initialConfig: $ReadOnly<{
25
- editor__DEPRECATED?: LexicalEditor | null,
26
- editable?: boolean,
27
- namespace: string,
28
- nodes?: $ReadOnlyArray<
29
- | Class<LexicalNode>
30
- | {replace: Class<LexicalNode>, with: (node: LexicalNode) => LexicalNode},
31
- >,
32
- theme?: EditorThemeClasses,
33
- editorState?: InitialEditorStateType,
34
- onError: (error: Error, editor: LexicalEditor) => void,
35
- }>,
37
+ initialConfig: InitialConfigType,
36
38
  children: React$Node,
37
39
  };
38
40
 
@@ -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
- 'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),g=require("react"),m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;let n={tag:"history-merge"};
8
- function p(a,c){if(null!==c)if(void 0===c)a.update(()=>{var b=f.$getRoot();if(b.isEmpty()){let d=f.$createParagraphNode();b.append(d);b=document.activeElement;(null!==f.$getSelection()||null!==b&&b===a.getRootElement())&&d.select()}},n);else if(null!==c)switch(typeof c){case "string":let b=a.parseEditorState(c);a.setEditorState(b,n);break;case "object":a.setEditorState(c,n);break;case "function":a.update(()=>{f.$getRoot().isEmpty()&&c(a)},n)}}
9
- exports.LexicalComposer=function({initialConfig:a,children:c}){let b=g.useMemo(()=>{const {theme:d,namespace:h,editor__DEPRECATED:q,nodes:r,onError:t,editorState:u}=a,v=e.createLexicalComposerContext(null,d);let k=q||null;if(null===k){const l=f.createEditor({editable:!1,namespace:h,nodes:r,onError:w=>t(w,l),theme:d});p(l,u);k=l}return[k,v]},[]);m(()=>{let d=a.editable,[h]=b;h.setEditable(void 0!==d?d:!0)},[]);return g.createElement(e.LexicalComposerContext.Provider,{value:b},c)}
7
+ 'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),g=require("react");let m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;var n=m?g.useLayoutEffect:g.useEffect;let p={tag:"history-merge"};
8
+ function q(a,c){if(null!==c)if(void 0===c)a.update(()=>{var b=f.$getRoot();if(b.isEmpty()){let d=f.$createParagraphNode();b.append(d);b=m?document.activeElement:null;(null!==f.$getSelection()||null!==b&&b===a.getRootElement())&&d.select()}},p);else if(null!==c)switch(typeof c){case "string":let b=a.parseEditorState(c);a.setEditorState(b,p);break;case "object":a.setEditorState(c,p);break;case "function":a.update(()=>{f.$getRoot().isEmpty()&&c(a)},p)}}
9
+ exports.LexicalComposer=function({initialConfig:a,children:c}){let b=g.useMemo(()=>{const {theme:d,namespace:h,editor__DEPRECATED:r,nodes:t,onError:u,editorState:v}=a,w=e.createLexicalComposerContext(null,d);let k=r||null;if(null===k){const l=f.createEditor({editable:!1,namespace:h,nodes:t,onError:x=>u(x,l),theme:d});q(l,v);k=l}return[k,w]},[]);n(()=>{let d=a.editable,[h]=b;h.setEditable(void 0!==d?d:!0)},[]);return g.createElement(e.LexicalComposerContext.Provider,{value:b},c)}
@@ -25,7 +25,6 @@ function HorizontalRuleComponent({
25
25
  nodeKey
26
26
  }) {
27
27
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
28
- const hrRef = React.useRef(null);
29
28
  const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection.useLexicalNodeSelection(nodeKey);
30
29
  const onDelete = React.useCallback(payload => {
31
30
  if (isSelected && lexical.$isNodeSelection(lexical.$getSelection())) {
@@ -44,7 +43,7 @@ function HorizontalRuleComponent({
44
43
  }, [isSelected, nodeKey, setSelected]);
45
44
  React.useEffect(() => {
46
45
  return utils.mergeRegister(editor.registerCommand(lexical.CLICK_COMMAND, event => {
47
- const hrElem = hrRef.current;
46
+ const hrElem = editor.getElementByKey(nodeKey);
48
47
 
49
48
  if (event.target === hrElem) {
50
49
  if (!event.shiftKey) {
@@ -57,11 +56,15 @@ function HorizontalRuleComponent({
57
56
 
58
57
  return false;
59
58
  }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_DELETE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW));
60
- }, [clearSelection, editor, isSelected, onDelete, setSelected]);
61
- return /*#__PURE__*/React.createElement("hr", {
62
- ref: hrRef,
63
- className: isSelected ? 'selected' : undefined
64
- });
59
+ }, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]);
60
+ React.useEffect(() => {
61
+ const hrElem = editor.getElementByKey(nodeKey);
62
+
63
+ if (hrElem !== null) {
64
+ hrElem.className = isSelected ? 'selected' : '';
65
+ }
66
+ }, [editor, isSelected, nodeKey]);
67
+ return null;
65
68
  }
66
69
 
67
70
  class HorizontalRuleNode extends lexical.DecoratorNode {
@@ -100,9 +103,7 @@ class HorizontalRuleNode extends lexical.DecoratorNode {
100
103
  }
101
104
 
102
105
  createDOM() {
103
- const div = document.createElement('div');
104
- div.style.display = 'contents';
105
- return div;
106
+ return document.createElement('hr');
106
107
  }
107
108
 
108
109
  getTextContent() {
@@ -4,8 +4,8 @@
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 a=require("@lexical/react/LexicalComposerContext"),d=require("@lexical/react/useLexicalNodeSelection"),h=require("@lexical/utils"),l=require("lexical"),p=require("react");let q=l.createCommand("INSERT_HORIZONTAL_RULE_COMMAND");
8
- function r({nodeKey:b}){let [f]=a.useLexicalComposerContext(),m=p.useRef(null),[e,g,n]=d.useLexicalNodeSelection(b),k=p.useCallback(c=>{e&&l.$isNodeSelection(l.$getSelection())&&(c.preventDefault(),c=l.$getNodeByKey(b),t(c)&&c.remove(),g(!1));return!1},[e,b,g]);p.useEffect(()=>h.mergeRegister(f.registerCommand(l.CLICK_COMMAND,c=>c.target===m.current?(c.shiftKey||n(),g(!e),!0):!1,l.COMMAND_PRIORITY_LOW),f.registerCommand(l.KEY_DELETE_COMMAND,k,l.COMMAND_PRIORITY_LOW),f.registerCommand(l.KEY_BACKSPACE_COMMAND,
9
- k,l.COMMAND_PRIORITY_LOW)),[n,f,e,k,g]);return p.createElement("hr",{ref:m,className:e?"selected":void 0})}
10
- class u extends l.DecoratorNode{static getType(){return"horizontalrule"}static clone(b){return new u(b.__key)}static importJSON(){return v()}static importDOM(){return{hr:()=>({conversion:w,priority:0})}}exportJSON(){return{type:"horizontalrule",version:1}}exportDOM(){return{element:document.createElement("hr")}}createDOM(){let b=document.createElement("div");b.style.display="contents";return b}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}decorate(){return p.createElement(r,{nodeKey:this.__key})}}
11
- function w(){return{node:v()}}function v(){return l.$applyNodeReplacement(new u)}function t(b){return b instanceof u}exports.$createHorizontalRuleNode=v;exports.$isHorizontalRuleNode=t;exports.HorizontalRuleNode=u;exports.INSERT_HORIZONTAL_RULE_COMMAND=q
7
+ 'use strict';var a=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/react/useLexicalNodeSelection"),h=require("@lexical/utils"),l=require("lexical"),n=require("react");let p=l.createCommand("INSERT_HORIZONTAL_RULE_COMMAND");
8
+ function q({nodeKey:b}){let [d]=a.useLexicalComposerContext(),[e,g,m]=f.useLexicalNodeSelection(b),k=n.useCallback(c=>{e&&l.$isNodeSelection(l.$getSelection())&&(c.preventDefault(),c=l.$getNodeByKey(b),r(c)&&c.remove(),g(!1));return!1},[e,b,g]);n.useEffect(()=>h.mergeRegister(d.registerCommand(l.CLICK_COMMAND,c=>{let v=d.getElementByKey(b);return c.target===v?(c.shiftKey||m(),g(!e),!0):!1},l.COMMAND_PRIORITY_LOW),d.registerCommand(l.KEY_DELETE_COMMAND,k,l.COMMAND_PRIORITY_LOW),d.registerCommand(l.KEY_BACKSPACE_COMMAND,
9
+ k,l.COMMAND_PRIORITY_LOW)),[m,d,e,b,k,g]);n.useEffect(()=>{let c=d.getElementByKey(b);null!==c&&(c.className=e?"selected":"")},[d,e,b]);return null}
10
+ class t extends l.DecoratorNode{static getType(){return"horizontalrule"}static clone(b){return new t(b.__key)}static importJSON(){return u()}static importDOM(){return{hr:()=>({conversion:w,priority:0})}}exportJSON(){return{type:"horizontalrule",version:1}}exportDOM(){return{element:document.createElement("hr")}}createDOM(){return document.createElement("hr")}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}decorate(){return n.createElement(q,{nodeKey:this.__key})}}
11
+ function w(){return{node:u()}}function u(){return l.$applyNodeReplacement(new t)}function r(b){return b instanceof t}exports.$createHorizontalRuleNode=u;exports.$isHorizontalRuleNode=r;exports.HorizontalRuleNode=t;exports.INSERT_HORIZONTAL_RULE_COMMAND=p
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { EditorThemeClasses, Klass, LexicalEditor, LexicalNode } from 'lexical';
8
+ import { EditorThemeClasses, Klass, LexicalEditor, LexicalNode } from 'lexical';
9
9
  import { ReactNode } from 'react';
10
10
  export declare function LexicalNestedComposer({ initialEditor, children, initialNodes, initialTheme, skipCollabChecks, }: {
11
11
  children: ReactNode;
@@ -33,9 +33,11 @@ function LexicalNestedComposer({
33
33
  }
34
34
  }
35
35
 
36
+ const [parentEditor, {
37
+ getTheme: getParentTheme
38
+ }] = parentContext;
36
39
  const composerContext = React.useMemo(() => {
37
- const [parentEditor, parentContextContext] = parentContext;
38
- const composerTheme = initialTheme || parentContextContext.getTheme() || undefined;
40
+ const composerTheme = initialTheme || getParentTheme() || undefined;
39
41
  const context = LexicalComposerContext.createLexicalComposerContext(parentContext, composerTheme);
40
42
 
41
43
  if (composerTheme !== undefined) {
@@ -70,8 +72,7 @@ function LexicalNestedComposer({
70
72
  return [initialEditor, context];
71
73
  }, // We only do this for init
72
74
  // eslint-disable-next-line react-hooks/exhaustive-deps
73
- []); // If collaboration is enabled, make sure we don't render the children
74
- // until the collaboration subdocument is ready.
75
+ []); // If collaboration is enabled, make sure we don't render the children until the collaboration subdocument is ready.
75
76
 
76
77
  const {
77
78
  isCollabActive,
@@ -82,7 +83,13 @@ function LexicalNestedComposer({
82
83
  if (isCollabReady) {
83
84
  wasCollabPreviouslyReadyRef.current = true;
84
85
  }
85
- }, [isCollabReady]);
86
+ }, [isCollabReady]); // Update `isEditable` state of nested editor in response to the same change on parent editor.
87
+
88
+ React.useEffect(() => {
89
+ return parentEditor.registerEditableListener(editable => {
90
+ initialEditor.setEditable(editable);
91
+ });
92
+ }, [initialEditor, parentEditor]);
86
93
  return /*#__PURE__*/React.createElement(LexicalComposerContext.LexicalComposerContext.Provider, {
87
94
  value: composerContext
88
95
  }, !isCollabActive || isCollabReady ? children : null);
@@ -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
- 'use strict';var b=require("@lexical/react/LexicalCollaborationContext"),e=require("@lexical/react/LexicalComposerContext"),n=require("react");
8
- exports.LexicalNestedComposer=function({initialEditor:a,children:p,initialNodes:k,initialTheme:q,skipCollabChecks:r}){let l=n.useRef(!1),f=n.useContext(e.LexicalComposerContext);if(null==f)throw Error("Minified Lexical error #9; visit https://lexical.dev/docs/error?code=9 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let w=n.useMemo(()=>{const [g,t]=f;var c=q||t.getTheme()||void 0;const u=e.createLexicalComposerContext(f,c);void 0!==
9
- c&&(a._config.theme=c);a._parentEditor=g;if(k)for(var d of k)c=d.getType(),a._nodes.set(c,{klass:d,replace:null,transforms:new Set});else{d=a._nodes=new Map(g._nodes);for(const [v,m]of d)a._nodes.set(v,{klass:m.klass,replace:m.replace,transforms:new Set})}a._config.namespace=g._config.namespace;return[a,u]},[]),{isCollabActive:x,yjsDocMap:y}=b.useCollaborationContext(),h=r||l.current||y.has(a.getKey());n.useEffect(()=>{h&&(l.current=!0)},[h]);return n.createElement(e.LexicalComposerContext.Provider,
10
- {value:w},!x||h?p:null)}
7
+ 'use strict';var c=require("@lexical/react/LexicalCollaborationContext"),f=require("@lexical/react/LexicalComposerContext"),n=require("react");
8
+ exports.LexicalNestedComposer=function({initialEditor:a,children:p,initialNodes:k,initialTheme:q,skipCollabChecks:r}){let l=n.useRef(!1),g=n.useContext(f.LexicalComposerContext);if(null==g)throw Error("Minified Lexical error #9; visit https://lexical.dev/docs/error?code=9 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let [d,{getTheme:t}]=g,w=n.useMemo(()=>{var b=q||t()||void 0;const u=f.createLexicalComposerContext(g,b);void 0!==b&&
9
+ (a._config.theme=b);a._parentEditor=d;if(k)for(var e of k)b=e.getType(),a._nodes.set(b,{klass:e,replace:null,transforms:new Set});else{e=a._nodes=new Map(d._nodes);for(const [v,m]of e)a._nodes.set(v,{klass:m.klass,replace:m.replace,transforms:new Set})}a._config.namespace=d._config.namespace;return[a,u]},[]),{isCollabActive:x,yjsDocMap:y}=c.useCollaborationContext(),h=r||l.current||y.has(a.getKey());n.useEffect(()=>{h&&(l.current=!0)},[h]);n.useEffect(()=>d.registerEditableListener(b=>{a.setEditable(b)}),
10
+ [a,d]);return n.createElement(f.LexicalComposerContext.Provider,{value:w},!x||h?p:null)}
@@ -45,11 +45,15 @@ function NodeEventPlugin({
45
45
  listenerRef.current = eventListener;
46
46
  useLayoutEffect(() => {
47
47
  return editor.registerMutationListener(nodeType, mutations => {
48
+ const registedElements = new WeakSet();
48
49
  editor.getEditorState().read(() => {
49
50
  for (const [key, mutation] of mutations) {
50
51
  const element = editor.getElementByKey(key);
51
52
 
52
- if (mutation === 'created' && element !== null) {
53
+ if ( // Updated might be a move, so that might mean a new DOM element
54
+ // is created. In this case, we need to add and event listener too.
55
+ (mutation === 'created' || mutation === 'updated') && element !== null && !registedElements.has(element)) {
56
+ registedElements.add(element);
53
57
  element.addEventListener(eventType, event => {
54
58
  listenerRef.current(event, editor, key);
55
59
  });
@@ -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
- 'use strict';var b=require("@lexical/react/LexicalComposerContext"),h=require("react"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
8
- exports.NodeEventPlugin=function({nodeType:c,eventType:l,eventListener:d}){let [a]=b.useLexicalComposerContext(),e=h.useRef(d);e.current=d;k(()=>a.registerMutationListener(c,m=>{a.getEditorState().read(()=>{for(let [f,n]of m){let g=a.getElementByKey(f);"created"===n&&null!==g&&g.addEventListener(l,p=>{e.current(p,a,f)})}})}),[a,c]);return null}
7
+ 'use strict';var c=require("@lexical/react/LexicalComposerContext"),l=require("react"),m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?l.useLayoutEffect:l.useEffect;
8
+ exports.NodeEventPlugin=function({nodeType:d,eventType:n,eventListener:e}){let [a]=c.useLexicalComposerContext(),f=l.useRef(e);f.current=e;m(()=>a.registerMutationListener(d,p=>{let g=new WeakSet;a.getEditorState().read(()=>{for(let [h,k]of p){let b=a.getElementByKey(h);"created"!==k&&"updated"!==k||null===b||g.has(b)||(g.add(b),b.addEventListener(n,q=>{f.current(q,a,h)}))}})}),[a,d]);return null}
@@ -369,7 +369,7 @@ function LexicalPopoverMenu({
369
369
  }
370
370
 
371
371
  return true;
372
- }, lexical.COMMAND_PRIORITY_CRITICAL), editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, payload => {
372
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, payload => {
373
373
  const event = payload;
374
374
 
375
375
  if (options !== null && options.length && selectedIndex !== null) {
@@ -386,13 +386,13 @@ function LexicalPopoverMenu({
386
386
  }
387
387
 
388
388
  return true;
389
- }, lexical.COMMAND_PRIORITY_CRITICAL), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, payload => {
389
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, payload => {
390
390
  const event = payload;
391
391
  event.preventDefault();
392
392
  event.stopImmediatePropagation();
393
393
  close();
394
394
  return true;
395
- }, lexical.COMMAND_PRIORITY_CRITICAL), editor.registerCommand(lexical.KEY_TAB_COMMAND, payload => {
395
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_TAB_COMMAND, payload => {
396
396
  const event = payload;
397
397
 
398
398
  if (options === null || selectedIndex === null || options[selectedIndex] == null) {
@@ -403,7 +403,7 @@ function LexicalPopoverMenu({
403
403
  event.stopImmediatePropagation();
404
404
  selectOptionAndCleanUp(options[selectedIndex]);
405
405
  return true;
406
- }, lexical.COMMAND_PRIORITY_CRITICAL), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
406
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
407
407
  if (options === null || selectedIndex === null || options[selectedIndex] == null) {
408
408
  return false;
409
409
  }
@@ -415,7 +415,7 @@ function LexicalPopoverMenu({
415
415
 
416
416
  selectOptionAndCleanUp(options[selectedIndex]);
417
417
  return true;
418
- }, lexical.COMMAND_PRIORITY_CRITICAL));
418
+ }, lexical.COMMAND_PRIORITY_LOW));
419
419
  }, [selectOptionAndCleanUp, close, editor, options, selectedIndex, updateSelectedIndex]);
420
420
  const listItemProps = React.useMemo(() => ({
421
421
  options,
@@ -13,9 +13,9 @@ function I(b,a){let c=getComputedStyle(b),e="absolute"===c.position;a=a?/(auto|s
13
13
  function K(b,a,c,e){let [f]=k.useLexicalComposerContext();x.useEffect(()=>{if(null!=a&&null!=b){let q=f.getRootElement(),p=null!=q?I(q,!1):document.body,g=!1,d=J(a,p),l=function(){g||(window.requestAnimationFrame(function(){c();g=!1}),g=!0);const t=J(a,p);t!==d&&(d=t,null!=e&&e(t))},r=new ResizeObserver(c);window.addEventListener("resize",c);document.addEventListener("scroll",l,{capture:!0,passive:!0});r.observe(a);return()=>{r.unobserve(a);window.removeEventListener("resize",c);document.removeEventListener("scroll",
14
14
  l)}}},[a,f,e,c,b])}let L=w.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");
15
15
  function M({close:b,editor:a,anchorElementRef:c,resolution:e,options:f,menuRenderFn:q,onSelectOption:p}){let [g,d]=x.useState(null);x.useEffect(()=>{d(0)},[e.match.matchingString]);let l=x.useCallback(h=>{a.update(()=>{const m=D(a,e.match);p(h,m,b,e.match.matchingString)})},[b,a,e.match,p]),r=x.useCallback(h=>{const m=a.getRootElement();null!==m&&(m.setAttribute("aria-activedescendant","typeahead-item-"+h),d(h))},[a]);x.useEffect(()=>()=>{let h=a.getRootElement();null!==h&&h.removeAttribute("aria-activedescendant")},
16
- [a]);y(()=>{null===f?d(null):null===g&&r(0)},[f,g,r]);x.useEffect(()=>n.mergeRegister(a.registerCommand(L,({option:h})=>h.ref&&null!=h.ref.current?(A(h.ref.current),!0):!1,w.COMMAND_PRIORITY_LOW)),[a,r]);x.useEffect(()=>n.mergeRegister(a.registerCommand(w.KEY_ARROW_DOWN_COMMAND,h=>{if(null!==f&&f.length&&null!==g){let m=g!==f.length-1?g+1:0;r(m);let u=f[m];null!=u.ref&&u.ref.current&&a.dispatchCommand(L,{index:m,option:u});h.preventDefault();h.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_CRITICAL),
17
- a.registerCommand(w.KEY_ARROW_UP_COMMAND,h=>{if(null!==f&&f.length&&null!==g){var m=0!==g?g-1:f.length-1;r(m);m=f[m];null!=m.ref&&m.ref.current&&A(m.ref.current);h.preventDefault();h.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_CRITICAL),a.registerCommand(w.KEY_ESCAPE_COMMAND,h=>{h.preventDefault();h.stopImmediatePropagation();b();return!0},w.COMMAND_PRIORITY_CRITICAL),a.registerCommand(w.KEY_TAB_COMMAND,h=>{if(null===f||null===g||null==f[g])return!1;h.preventDefault();h.stopImmediatePropagation();
18
- l(f[g]);return!0},w.COMMAND_PRIORITY_CRITICAL),a.registerCommand(w.KEY_ENTER_COMMAND,h=>{if(null===f||null===g||null==f[g])return!1;null!==h&&(h.preventDefault(),h.stopImmediatePropagation());l(f[g]);return!0},w.COMMAND_PRIORITY_CRITICAL)),[l,b,a,f,g,r]);let t=x.useMemo(()=>({options:f,selectOptionAndCleanUp:l,selectedIndex:g,setHighlightedIndex:d}),[l,g,f]);return q(c,t,e.match.matchingString)}
16
+ [a]);y(()=>{null===f?d(null):null===g&&r(0)},[f,g,r]);x.useEffect(()=>n.mergeRegister(a.registerCommand(L,({option:h})=>h.ref&&null!=h.ref.current?(A(h.ref.current),!0):!1,w.COMMAND_PRIORITY_LOW)),[a,r]);x.useEffect(()=>n.mergeRegister(a.registerCommand(w.KEY_ARROW_DOWN_COMMAND,h=>{if(null!==f&&f.length&&null!==g){let m=g!==f.length-1?g+1:0;r(m);let u=f[m];null!=u.ref&&u.ref.current&&a.dispatchCommand(L,{index:m,option:u});h.preventDefault();h.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_LOW),
17
+ a.registerCommand(w.KEY_ARROW_UP_COMMAND,h=>{if(null!==f&&f.length&&null!==g){var m=0!==g?g-1:f.length-1;r(m);m=f[m];null!=m.ref&&m.ref.current&&A(m.ref.current);h.preventDefault();h.stopImmediatePropagation()}return!0},w.COMMAND_PRIORITY_LOW),a.registerCommand(w.KEY_ESCAPE_COMMAND,h=>{h.preventDefault();h.stopImmediatePropagation();b();return!0},w.COMMAND_PRIORITY_LOW),a.registerCommand(w.KEY_TAB_COMMAND,h=>{if(null===f||null===g||null==f[g])return!1;h.preventDefault();h.stopImmediatePropagation();
18
+ l(f[g]);return!0},w.COMMAND_PRIORITY_LOW),a.registerCommand(w.KEY_ENTER_COMMAND,h=>{if(null===f||null===g||null==f[g])return!1;null!==h&&(h.preventDefault(),h.stopImmediatePropagation());l(f[g]);return!0},w.COMMAND_PRIORITY_LOW)),[l,b,a,f,g,r]);let t=x.useMemo(()=>({options:f,selectOptionAndCleanUp:l,selectedIndex:g,setHighlightedIndex:d}),[l,g,f]);return q(c,t,e.match.matchingString)}
19
19
  function N(b,a,c){let [e]=k.useLexicalComposerContext(),f=x.useRef(document.createElement("div")),q=x.useCallback(()=>{const g=e.getRootElement(),d=f.current;if(null!==g&&null!==b){const {left:l,top:r,width:t,height:h}=b.getRect();d.style.top=`${r+window.pageYOffset}px`;d.style.left=`${l+window.pageXOffset}px`;d.style.height=`${h}px`;d.style.width=`${t}px`;d.isConnected||(null!=c&&(d.className=c),d.setAttribute("aria-label","Typeahead menu"),d.setAttribute("id","typeahead-menu"),d.setAttribute("role",
20
20
  "listbox"),d.style.display="block",d.style.position="absolute",document.body.append(d));f.current=d;g.setAttribute("aria-controls","typeahead-menu")}},[e,b,c]);x.useEffect(()=>{let g=e.getRootElement();if(null!==b)return q(),()=>{null!==g&&g.removeAttribute("aria-controls");let d=f.current;null!==d&&d.isConnected&&d.remove()}},[e,q,b]);let p=x.useCallback(g=>{null!==b&&(g||a(null))},[b,a]);K(b,f.current,q,p);return f}
21
21
  exports.LexicalNodeMenuPlugin=function({options:b,nodeKey:a,onClose:c,onOpen:e,onSelectOption:f,menuRenderFn:q,anchorClassName:p}){let [g]=k.useLexicalComposerContext(),[d,l]=x.useState(null);p=N(d,l,p);let r=x.useCallback(()=>{l(null);null!=c&&null!==d&&c()},[c,d]),t=x.useCallback(h=>{l(h);null!=e&&null===d&&e(h)},[e,d]);x.useEffect(()=>{a&&null==d?g.update(()=>{let h=w.$getNodeByKey(a),m=g.getElementByKey(a);if(null!=h&&null!=m){let u=h.getTextContent();F(()=>t({getRect:()=>m.getBoundingClientRect(),
package/package.json CHANGED
@@ -8,29 +8,29 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.6.3",
11
+ "version": "0.6.5",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.6.3",
14
- "@lexical/code": "0.6.3",
15
- "@lexical/dragon": "0.6.3",
16
- "@lexical/hashtag": "0.6.3",
17
- "@lexical/history": "0.6.3",
18
- "@lexical/link": "0.6.3",
19
- "@lexical/list": "0.6.3",
20
- "@lexical/mark": "0.6.3",
21
- "@lexical/markdown": "0.6.3",
22
- "@lexical/overflow": "0.6.3",
23
- "@lexical/plain-text": "0.6.3",
24
- "@lexical/rich-text": "0.6.3",
25
- "@lexical/selection": "0.6.3",
26
- "@lexical/table": "0.6.3",
27
- "@lexical/text": "0.6.3",
28
- "@lexical/utils": "0.6.3",
29
- "@lexical/yjs": "0.6.3",
13
+ "@lexical/clipboard": "0.6.5",
14
+ "@lexical/code": "0.6.5",
15
+ "@lexical/dragon": "0.6.5",
16
+ "@lexical/hashtag": "0.6.5",
17
+ "@lexical/history": "0.6.5",
18
+ "@lexical/link": "0.6.5",
19
+ "@lexical/list": "0.6.5",
20
+ "@lexical/mark": "0.6.5",
21
+ "@lexical/markdown": "0.6.5",
22
+ "@lexical/overflow": "0.6.5",
23
+ "@lexical/plain-text": "0.6.5",
24
+ "@lexical/rich-text": "0.6.5",
25
+ "@lexical/selection": "0.6.5",
26
+ "@lexical/table": "0.6.5",
27
+ "@lexical/text": "0.6.5",
28
+ "@lexical/utils": "0.6.5",
29
+ "@lexical/yjs": "0.6.5",
30
30
  "react-error-boundary": "^3.1.4"
31
31
  },
32
32
  "peerDependencies": {
33
- "lexical": "0.6.3",
33
+ "lexical": "0.6.5",
34
34
  "react": ">=17.x",
35
35
  "react-dom": ">=17.x"
36
36
  },