@lexical/react 0.7.6 → 0.7.7

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.
Files changed (38) hide show
  1. package/LexicalCheckListPlugin.dev.js +11 -16
  2. package/LexicalCheckListPlugin.prod.js +7 -8
  3. package/{DEPRECATED_useLexicalList.d.ts → LexicalHorizontalRulePlugin.d.ts} +1 -2
  4. package/LexicalHorizontalRulePlugin.dev.js +45 -0
  5. package/LexicalHorizontalRulePlugin.js +9 -0
  6. package/LexicalHorizontalRulePlugin.prod.js +8 -0
  7. package/LexicalNodeEventPlugin.dev.js +1 -1
  8. package/LexicalNodeEventPlugin.prod.js +1 -1
  9. package/LexicalPlainTextPlugin.js.flow +5 -2
  10. package/LexicalRichTextPlugin.js.flow +5 -2
  11. package/LexicalTableOfContents__EXPERIMENTAL.d.ts +6 -1
  12. package/LexicalTableOfContents__EXPERIMENTAL.dev.js +49 -6
  13. package/LexicalTableOfContents__EXPERIMENTAL.prod.js +4 -4
  14. package/LexicalTypeaheadMenuPlugin.dev.js +10 -5
  15. package/LexicalTypeaheadMenuPlugin.prod.js +1 -1
  16. package/package.json +19 -19
  17. package/useLexicalNodeSelection.dev.js +9 -2
  18. package/useLexicalNodeSelection.prod.js +2 -2
  19. package/DEPRECATED_useLexicalAutoFormatter.d.ts +0 -9
  20. package/DEPRECATED_useLexicalAutoFormatter.dev.js +0 -25
  21. package/DEPRECATED_useLexicalAutoFormatter.js +0 -9
  22. package/DEPRECATED_useLexicalAutoFormatter.js.flow +0 -15
  23. package/DEPRECATED_useLexicalAutoFormatter.prod.js +0 -7
  24. package/DEPRECATED_useLexicalDecorators.d.ts +0 -10
  25. package/DEPRECATED_useLexicalDecorators.dev.js +0 -88
  26. package/DEPRECATED_useLexicalDecorators.js +0 -9
  27. package/DEPRECATED_useLexicalDecorators.js.flow +0 -24
  28. package/DEPRECATED_useLexicalDecorators.prod.js +0 -8
  29. package/DEPRECATED_useLexicalEditorEvents.d.ts +0 -10
  30. package/DEPRECATED_useLexicalEditorEvents.dev.js +0 -92
  31. package/DEPRECATED_useLexicalEditorEvents.js +0 -9
  32. package/DEPRECATED_useLexicalEditorEvents.js.flow +0 -22
  33. package/DEPRECATED_useLexicalEditorEvents.prod.js +0 -8
  34. package/DEPRECATED_useLexicalList.dev.js +0 -61
  35. package/DEPRECATED_useLexicalList.js +0 -9
  36. package/DEPRECATED_useLexicalList.js.flow +0 -13
  37. package/DEPRECATED_useLexicalList.prod.js +0 -9
  38. package/shared/useEditorEvents.d.ts +0 -10
@@ -91,25 +91,20 @@ function CheckListPlugin() {
91
91
 
92
92
  return false;
93
93
  });
94
- }, lexical.COMMAND_PRIORITY_LOW), listenPointerDown());
94
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerRootListener((rootElement, prevElement) => {
95
+ if (rootElement !== null) {
96
+ rootElement.addEventListener('click', handleClick);
97
+ rootElement.addEventListener('pointerdown', handlePointerDown);
98
+ }
99
+
100
+ if (prevElement !== null) {
101
+ prevElement.removeEventListener('click', handleClick);
102
+ prevElement.removeEventListener('pointerdown', handlePointerDown);
103
+ }
104
+ }));
95
105
  });
96
106
  return null;
97
107
  }
98
- let listenersCount = 0;
99
-
100
- function listenPointerDown() {
101
- if (listenersCount++ === 0) {
102
- document.addEventListener('click', handleClick);
103
- document.addEventListener('pointerdown', handlePointerDown);
104
- }
105
-
106
- return () => {
107
- if (--listenersCount === 0) {
108
- document.removeEventListener('click', handleClick);
109
- document.removeEventListener('pointerdown', handlePointerDown);
110
- }
111
- };
112
- }
113
108
 
114
109
  function handleCheckItemEvent(event, callback) {
115
110
  const target = event.target;
@@ -4,11 +4,10 @@
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/list"),g=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/utils"),l=require("lexical"),m=require("react");let n=0;function p(){0===n++&&(document.addEventListener("click",q),document.addEventListener("pointerdown",r));return()=>{0===--n&&(document.removeEventListener("click",q),document.removeEventListener("pointerdown",r))}}
8
- function t(a,d){let b=a.target;if(b instanceof HTMLElement){var c=b.firstChild;null!=c&&c instanceof HTMLElement&&("UL"===c.tagName||"OL"===c.tagName)||(c=b.parentNode)&&"check"===c.__lexicalListType&&(a=a.pageX,c=b.getBoundingClientRect(),("rtl"===b.dir?a<c.right&&a>c.right-20:a>c.left&&a<c.left+20)&&d())}}
9
- function q(a){t(a,()=>{let d=a.target,b=u(d);null!=b&&b.isEditable()&&b.update(()=>{if(a.target){let c=l.$getNearestNodeFromDOMNode(d);e.$isListItemNode(c)&&(d.focus(),c.toggleChecked())}})})}function r(a){t(a,()=>{a.preventDefault()})}function u(a){for(;a;){if(a.__lexicalEditor)return a.__lexicalEditor;a=a.parentNode}return null}function v(){let a=document.activeElement;return null!=a&&"LI"===a.tagName&&null!=a.parentNode&&"check"===a.parentNode.__lexicalListType?a:null}
10
- function w(a,d){let b=d?a.getPreviousSibling():a.getNextSibling();for(;null==b&&e.$isListItemNode(a);)a=a.getParentOrThrow().getParent(),null!=a&&(b=d?a.getPreviousSibling():a.getNextSibling());for(;e.$isListItemNode(b);){a=d?b.getLastChild():b.getFirstChild();if(!e.$isListNode(a))return b;b=d?a.getLastChild():a.getFirstChild()}return null}
11
- function x(a,d,b){let c=v();null!=c&&d.update(()=>{var f=l.$getNearestNodeFromDOMNode(c);if(e.$isListItemNode(f)&&(f=w(f,b),null!=f)){f.selectStart();let h=d.getElementByKey(f.__key);null!=h&&(a.preventDefault(),setTimeout(()=>{h.focus()},0))}});return!1}
12
- exports.CheckListPlugin=function(){let [a]=g.useLexicalComposerContext();m.useEffect(()=>k.mergeRegister(a.registerCommand(e.INSERT_CHECK_LIST_COMMAND,()=>{e.insertList(a,"check");return!0},l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_DOWN_COMMAND,d=>x(d,a,!1),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_UP_COMMAND,d=>x(d,a,!0),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{if(null!=v()){let d=a.getRootElement();null!=d&&d.focus();return!0}return!1},l.COMMAND_PRIORITY_LOW),
13
- a.registerCommand(l.KEY_SPACE_COMMAND,d=>{let b=v();return null!=b&&a.isEditable()?(a.update(()=>{let c=l.$getNearestNodeFromDOMNode(b);e.$isListItemNode(c)&&(d.preventDefault(),c.toggleChecked())}),!0):!1},l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_LEFT_COMMAND,d=>a.getEditorState().read(()=>{var b=l.$getSelection();if(l.$isRangeSelection(b)&&b.isCollapsed()){var {anchor:c}=b;if((b="element"===c.type)||0===c.offset){c=c.getNode();let f=k.$findMatchingParent(c,h=>l.$isElementNode(h)&&!h.isInline());
14
- if(e.$isListItemNode(f)){let h=f.getParent();if(e.$isListNode(h)&&"check"===h.getListType()&&(b||f.getFirstDescendant()===c)&&(b=a.getElementByKey(f.__key),null!=b&&document.activeElement!==b))return b.focus(),d.preventDefault(),!0}}}return!1}),l.COMMAND_PRIORITY_LOW),p()));return null}
7
+ 'use strict';var e=require("@lexical/list"),g=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/utils"),l=require("lexical"),m=require("react");function n(a,c){let b=a.target;if(b instanceof HTMLElement){var d=b.firstChild;null!=d&&d instanceof HTMLElement&&("UL"===d.tagName||"OL"===d.tagName)||(d=b.parentNode)&&"check"===d.__lexicalListType&&(a=a.pageX,d=b.getBoundingClientRect(),("rtl"===b.dir?a<d.right&&a>d.right-20:a>d.left&&a<d.left+20)&&c())}}
8
+ function p(a){n(a,()=>{let c=a.target,b=q(c);null!=b&&b.isEditable()&&b.update(()=>{if(a.target){let d=l.$getNearestNodeFromDOMNode(c);e.$isListItemNode(d)&&(c.focus(),d.toggleChecked())}})})}function r(a){n(a,()=>{a.preventDefault()})}function q(a){for(;a;){if(a.__lexicalEditor)return a.__lexicalEditor;a=a.parentNode}return null}function t(){let a=document.activeElement;return null!=a&&"LI"===a.tagName&&null!=a.parentNode&&"check"===a.parentNode.__lexicalListType?a:null}
9
+ function u(a,c){let b=c?a.getPreviousSibling():a.getNextSibling();for(;null==b&&e.$isListItemNode(a);)a=a.getParentOrThrow().getParent(),null!=a&&(b=c?a.getPreviousSibling():a.getNextSibling());for(;e.$isListItemNode(b);){a=c?b.getLastChild():b.getFirstChild();if(!e.$isListNode(a))return b;b=c?a.getLastChild():a.getFirstChild()}return null}
10
+ function v(a,c,b){let d=t();null!=d&&c.update(()=>{var f=l.$getNearestNodeFromDOMNode(d);if(e.$isListItemNode(f)&&(f=u(f,b),null!=f)){f.selectStart();let h=c.getElementByKey(f.__key);null!=h&&(a.preventDefault(),setTimeout(()=>{h.focus()},0))}});return!1}
11
+ exports.CheckListPlugin=function(){let [a]=g.useLexicalComposerContext();m.useEffect(()=>k.mergeRegister(a.registerCommand(e.INSERT_CHECK_LIST_COMMAND,()=>{e.insertList(a,"check");return!0},l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_DOWN_COMMAND,c=>v(c,a,!1),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_UP_COMMAND,c=>v(c,a,!0),l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{if(null!=t()){let c=a.getRootElement();null!=c&&c.focus();return!0}return!1},l.COMMAND_PRIORITY_LOW),
12
+ a.registerCommand(l.KEY_SPACE_COMMAND,c=>{let b=t();return null!=b&&a.isEditable()?(a.update(()=>{let d=l.$getNearestNodeFromDOMNode(b);e.$isListItemNode(d)&&(c.preventDefault(),d.toggleChecked())}),!0):!1},l.COMMAND_PRIORITY_LOW),a.registerCommand(l.KEY_ARROW_LEFT_COMMAND,c=>a.getEditorState().read(()=>{var b=l.$getSelection();if(l.$isRangeSelection(b)&&b.isCollapsed()){var {anchor:d}=b;if((b="element"===d.type)||0===d.offset){d=d.getNode();let f=k.$findMatchingParent(d,h=>l.$isElementNode(h)&&!h.isInline());
13
+ if(e.$isListItemNode(f)){let h=f.getParent();if(e.$isListNode(h)&&"check"===h.getListType()&&(b||f.getFirstDescendant()===d)&&(b=a.getElementByKey(f.__key),null!=b&&document.activeElement!==b))return b.focus(),c.preventDefault(),!0}}}return!1}),l.COMMAND_PRIORITY_LOW),a.registerRootListener((c,b)=>{null!==c&&(c.addEventListener("click",p),c.addEventListener("pointerdown",r));null!==b&&(b.removeEventListener("click",p),b.removeEventListener("pointerdown",r))})));return null}
@@ -5,5 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { LexicalEditor } from 'lexical';
9
- export declare function useLexicalList(editor: LexicalEditor): void;
8
+ export declare function HorizontalRulePlugin(): null;
@@ -0,0 +1,45 @@
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 LexicalHorizontalRuleNode = require('@lexical/react/LexicalHorizontalRuleNode');
11
+ var utils = require('@lexical/utils');
12
+ var lexical = require('lexical');
13
+ var react = require('react');
14
+
15
+ /**
16
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
17
+ *
18
+ * This source code is licensed under the MIT license found in the
19
+ * LICENSE file in the root directory of this source tree.
20
+ *
21
+ */
22
+ function HorizontalRulePlugin() {
23
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
24
+ react.useEffect(() => {
25
+ return editor.registerCommand(LexicalHorizontalRuleNode.INSERT_HORIZONTAL_RULE_COMMAND, type => {
26
+ const selection = lexical.$getSelection();
27
+
28
+ if (!lexical.$isRangeSelection(selection)) {
29
+ return false;
30
+ }
31
+
32
+ const focusNode = selection.focus.getNode();
33
+
34
+ if (focusNode !== null) {
35
+ const horizontalRuleNode = LexicalHorizontalRuleNode.$createHorizontalRuleNode();
36
+ utils.$insertNodeToNearestRoot(horizontalRuleNode);
37
+ }
38
+
39
+ return true;
40
+ }, lexical.COMMAND_PRIORITY_EDITOR);
41
+ }, [editor]);
42
+ return null;
43
+ }
44
+
45
+ exports.HorizontalRulePlugin = HorizontalRulePlugin;
@@ -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 LexicalHorizontalRulePlugin = process.env.NODE_ENV === 'development' ? require('./LexicalHorizontalRulePlugin.dev.js') : require('./LexicalHorizontalRulePlugin.prod.js')
9
+ module.exports = LexicalHorizontalRulePlugin;
@@ -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
+ 'use strict';var b=require("@lexical/react/LexicalComposerContext"),c=require("@lexical/react/LexicalHorizontalRuleNode"),e=require("@lexical/utils"),f=require("lexical"),g=require("react");
8
+ exports.HorizontalRulePlugin=function(){let [d]=b.useLexicalComposerContext();g.useEffect(()=>d.registerCommand(c.INSERT_HORIZONTAL_RULE_COMMAND,()=>{var a=f.$getSelection();if(!f.$isRangeSelection(a))return!1;null!==a.focus.getNode()&&(a=c.$createHorizontalRuleNode(),e.$insertNodeToNearestRoot(a));return!0},f.COMMAND_PRIORITY_EDITOR),[d]);return null}
@@ -44,8 +44,8 @@ function NodeEventPlugin({
44
44
  const listenerRef = react.useRef(eventListener);
45
45
  listenerRef.current = eventListener;
46
46
  useLayoutEffect(() => {
47
+ const registedElements = new WeakSet();
47
48
  return editor.registerMutationListener(nodeType, mutations => {
48
- const registedElements = new WeakSet();
49
49
  editor.getEditorState().read(() => {
50
50
  for (const [key, mutation] of mutations) {
51
51
  const element = editor.getElementByKey(key);
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
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}
8
+ exports.NodeEventPlugin=function({nodeType:d,eventType:n,eventListener:e}){let [a]=c.useLexicalComposerContext(),f=l.useRef(e);f.current=e;m(()=>{let g=new WeakSet;return a.registerMutationListener(d,p=>{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}
@@ -7,9 +7,12 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type {ErrorBoundaryType} from './DEPRECATED_useLexicalDecorators';
11
10
  import type {EditorState, LexicalEditor} from 'lexical';
12
11
 
12
+ import typeof LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
13
+
14
+ import * as React from 'react';
15
+
13
16
  type InitialEditorStateType =
14
17
  | null
15
18
  | string
@@ -19,5 +22,5 @@ type InitialEditorStateType =
19
22
  declare export function PlainTextPlugin({
20
23
  contentEditable: React$Node,
21
24
  placeholder: ((isEditable: boolean) => React$Node) | React$Node,
22
- ErrorBoundary: ErrorBoundaryType,
25
+ ErrorBoundary: LexicalErrorBoundary,
23
26
  }): React$Node;
@@ -7,9 +7,12 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type {ErrorBoundaryType} from './DEPRECATED_useLexicalDecorators';
11
10
  import type {EditorState, LexicalEditor} from 'lexical';
12
11
 
12
+ import typeof LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
13
+
14
+ import * as React from 'react';
15
+
13
16
  type InitialEditorStateType =
14
17
  | null
15
18
  | string
@@ -19,5 +22,5 @@ type InitialEditorStateType =
19
22
  declare export function RichTextPlugin({
20
23
  contentEditable: React$Node,
21
24
  placeholder: ((isEditable: boolean) => React$Node) | React$Node,
22
- ErrorBoundary: ErrorBoundaryType,
25
+ ErrorBoundary: LexicalErrorBoundary,
23
26
  }): React$Node;
@@ -7,8 +7,13 @@
7
7
  */
8
8
  import type { LexicalEditor, NodeKey } from 'lexical';
9
9
  import { HeadingTagType } from '@lexical/rich-text';
10
+ export declare type TableOfContentsEntry = [
11
+ key: NodeKey,
12
+ text: string,
13
+ tag: HeadingTagType
14
+ ];
10
15
  declare type Props = {
11
- children: (values: Array<[key: NodeKey, text: string, tag: HeadingTagType]>, editor: LexicalEditor) => JSX.Element;
16
+ children: (values: Array<TableOfContentsEntry>, editor: LexicalEditor) => JSX.Element;
12
17
  };
13
18
  export default function LexicalTableOfContentsPlugin({ children, }: Props): JSX.Element;
14
19
  export {};
@@ -19,12 +19,16 @@ var react = require('react');
19
19
  *
20
20
  */
21
21
 
22
+ function toEntry(heading) {
23
+ return [heading.getKey(), heading.getTextContent(), heading.getTag()];
24
+ }
25
+
22
26
  function $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents) {
23
27
  if (newHeading === null) {
24
28
  return currentTableOfContents;
25
29
  }
26
30
 
27
- const newEntry = [newHeading.getKey(), newHeading.getTextContent(), newHeading.getTag()];
31
+ const newEntry = toEntry(newHeading);
28
32
  let newTableOfContents = [];
29
33
 
30
34
  if (prevHeading === null) {
@@ -56,12 +60,11 @@ function $deleteHeadingFromTableOfContents(key, currentTableOfContents) {
56
60
  }
57
61
 
58
62
  function $updateHeadingInTableOfContents(heading, currentTableOfContents) {
59
- const newTextContent = heading.getTextContent();
60
63
  const newTableOfContents = [];
61
64
 
62
65
  for (const oldHeading of currentTableOfContents) {
63
66
  if (oldHeading[0] === heading.getKey()) {
64
- newTableOfContents.push([heading.getKey(), newTextContent, heading.getTag()]);
67
+ newTableOfContents.push(toEntry(heading));
65
68
  } else {
66
69
  newTableOfContents.push(oldHeading);
67
70
  }
@@ -69,6 +72,34 @@ function $updateHeadingInTableOfContents(heading, currentTableOfContents) {
69
72
 
70
73
  return newTableOfContents;
71
74
  }
75
+ /**
76
+ * Returns the updated table of contents, placing the given `heading` before the given `prevHeading`. If `prevHeading`
77
+ * is undefined, `heading` is placed at the start of table of contents
78
+ */
79
+
80
+
81
+ function $updateHeadingPosition(prevHeading, heading, currentTableOfContents) {
82
+ const newTableOfContents = [];
83
+ const newEntry = toEntry(heading);
84
+
85
+ if (!prevHeading) {
86
+ newTableOfContents.push(newEntry);
87
+ }
88
+
89
+ for (const oldHeading of currentTableOfContents) {
90
+ if (oldHeading[0] === heading.getKey()) {
91
+ continue;
92
+ }
93
+
94
+ newTableOfContents.push(oldHeading);
95
+
96
+ if (prevHeading && oldHeading[0] === prevHeading.getKey()) {
97
+ newTableOfContents.push(newEntry);
98
+ }
99
+ }
100
+
101
+ return newTableOfContents;
102
+ }
72
103
 
73
104
  function LexicalTableOfContentsPlugin({
74
105
  children
@@ -100,18 +131,30 @@ function LexicalTableOfContentsPlugin({
100
131
  if (newHeading !== null) {
101
132
  let prevHeading = newHeading.getPreviousSibling();
102
133
 
103
- while (prevHeading && !richText.$isHeadingNode(prevHeading)) {
134
+ while (prevHeading !== null && !richText.$isHeadingNode(prevHeading)) {
104
135
  prevHeading = prevHeading.getPreviousSibling();
105
136
  }
106
137
 
107
138
  currentTableOfContents = $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents);
108
- setTableOfContents(currentTableOfContents);
109
139
  }
110
140
  } else if (mutation === 'destroyed') {
111
141
  currentTableOfContents = $deleteHeadingFromTableOfContents(nodeKey, currentTableOfContents);
112
- setTableOfContents(currentTableOfContents);
142
+ } else if (mutation === 'updated') {
143
+ const newHeading = lexical.$getNodeByKey(nodeKey);
144
+
145
+ if (newHeading !== null) {
146
+ let prevHeading = newHeading.getPreviousSibling();
147
+
148
+ while (prevHeading !== null && !richText.$isHeadingNode(prevHeading)) {
149
+ prevHeading = prevHeading.getPreviousSibling();
150
+ }
151
+
152
+ currentTableOfContents = $updateHeadingPosition(prevHeading, newHeading, currentTableOfContents);
153
+ }
113
154
  }
114
155
  }
156
+
157
+ setTableOfContents(currentTableOfContents);
115
158
  });
116
159
  }); // Listen to text node mutation updates
117
160
 
@@ -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 k=require("@lexical/react/LexicalComposerContext"),l=require("@lexical/rich-text"),r=require("lexical"),u=require("react");
8
- module.exports=function({children:v}){let [w,m]=u.useState([]),[f]=k.useLexicalComposerContext();u.useEffect(()=>{let b=[];f.getEditorState().read(()=>{let h=r.$getRoot().getChildren();for(let a of h)l.$isHeadingNode(a)&&b.push([a.getKey(),a.getTextContent(),a.getTag()]);m(b)});let x=f.registerMutationListener(l.HeadingNode,h=>{f.getEditorState().read(()=>{for(const [n,p]of h)if("created"===p){var a=r.$getNodeByKey(n);if(null!==a){for(var c=a.getPreviousSibling();c&&!l.$isHeadingNode(c);)c=c.getPreviousSibling();
9
- a:{var d=b;if(null===a){b=d;break a}let e=[a.getKey(),a.getTextContent(),a.getTag()],g=[];if(null===c)g=[e,...d];else for(let q=0;q<d.length;q++){let t=d[q][0];g.push(d[q]);t===c.getKey()&&t!==a.getKey()&&g.push(e)}b=g}m(b)}}else if("destroyed"===p){c=n;a=b;d=[];for(let e of a)e[0]!==c&&d.push(e);b=d;m(b)}})}),y=f.registerMutationListener(r.TextNode,h=>{f.getEditorState().read(()=>{for(const [d,n]of h)if("updated"===n){var a=r.$getNodeByKey(d);if(null!==a&&(a=a.getParentOrThrow(),l.$isHeadingNode(a))){var c=
10
- b;let p=a.getTextContent(),e=[];for(let g of c)g[0]===a.getKey()?e.push([a.getKey(),p,a.getTag()]):e.push(g);b=e;m(b)}}})});return()=>{x();y()}},[f]);return v(w,f)}
7
+ 'use strict';var l=require("@lexical/react/LexicalComposerContext"),m=require("@lexical/rich-text"),q=require("lexical"),u=require("react");function w(n){return[n.getKey(),n.getTextContent(),n.getTag()]}
8
+ module.exports=function({children:n}){let [x,r]=u.useState([]),[h]=l.useLexicalComposerContext();u.useEffect(()=>{let c=[];h.getEditorState().read(()=>{let p=q.$getRoot().getChildren();for(let a of p)m.$isHeadingNode(a)&&c.push([a.getKey(),a.getTextContent(),a.getTag()]);r(c)});let y=h.registerMutationListener(m.HeadingNode,p=>{h.getEditorState().read(()=>{for(const [k,t]of p)if("created"===t){var a=q.$getNodeByKey(k);if(null!==a){for(var b=a.getPreviousSibling();null!==b&&!m.$isHeadingNode(b);)b=
9
+ b.getPreviousSibling();var d=c;if(null===a)c=d;else{var g=w(a),e=[];if(null===b)e=[g,...d];else for(let f=0;f<d.length;f++){let v=d[f][0];e.push(d[f]);v===b.getKey()&&v!==a.getKey()&&e.push(g)}c=e}}}else if("destroyed"===t){b=k;a=c;d=[];for(let f of a)f[0]!==b&&d.push(f);c=d}else if("updated"===t&&(a=q.$getNodeByKey(k),null!==a)){for(b=a.getPreviousSibling();null!==b&&!m.$isHeadingNode(b);)b=b.getPreviousSibling();d=c;g=[];e=w(a);b||g.push(e);for(let f of d)f[0]!==a.getKey()&&(g.push(f),b&&f[0]===
10
+ b.getKey()&&g.push(e));c=g}r(c)})}),z=h.registerMutationListener(q.TextNode,p=>{h.getEditorState().read(()=>{for(const [d,g]of p)if("updated"===g){var a=q.$getNodeByKey(d);if(null!==a&&(a=a.getParentOrThrow(),m.$isHeadingNode(a))){var b=c;let e=[];for(let k of b)k[0]===a.getKey()?e.push(w(a)):e.push(k);c=e;r(c)}}})});return()=>{y();z()}},[h]);return n(x,h)}
@@ -59,13 +59,18 @@ const scrollIntoViewIfNeeded = target => {
59
59
  const container = document.getElementById('typeahead-menu');
60
60
 
61
61
  if (container) {
62
- const containerRect = container.getBoundingClientRect();
63
- const targetRect = target.getBoundingClientRect();
62
+ const parentNode = target.parentNode;
64
63
 
65
- if (targetRect.bottom > containerRect.bottom) {
64
+ if (parentNode && /auto|scroll/.test(getComputedStyle(parentNode).overflow)) {
65
+ const parentRect = parentNode.getBoundingClientRect();
66
+
67
+ if (parentRect.top + parentRect.height > window.innerHeight) {
68
+ parentNode.scrollIntoView(false);
69
+ }
70
+
71
+ parentNode.scrollTop = target.offsetTop - target.clientHeight;
72
+ } else {
66
73
  target.scrollIntoView(false);
67
- } else if (targetRect.top < containerRect.top) {
68
- target.scrollIntoView();
69
74
  }
70
75
  }
71
76
  };
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict';var k=require("@lexical/react/LexicalComposerContext"),n=require("@lexical/utils"),w=require("lexical"),x=require("react"),y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?x.useLayoutEffect:x.useEffect;class z{constructor(b){this.key=b;this.ref={current:null};this.setRefElement=this.setRefElement.bind(this)}setRefElement(b){this.ref={current:b}}}
8
- let A=b=>{var a=document.getElementById("typeahead-menu");if(a){a=a.getBoundingClientRect();const c=b.getBoundingClientRect();c.bottom>a.bottom?b.scrollIntoView(!1):c.top<a.top&&b.scrollIntoView()}};function B(b,a){var c=window.getSelection();if(null===c||!c.isCollapsed)return!1;let e=c.anchorNode;c=c.anchorOffset;if(null==e||null==c)return!1;try{a.setStart(e,b),a.setEnd(e,c)}catch(f){return!1}return!0}
8
+ let A=b=>{if(document.getElementById("typeahead-menu")){const a=b.parentNode;if(a&&/auto|scroll/.test(getComputedStyle(a).overflow)){const c=a.getBoundingClientRect();c.top+c.height>window.innerHeight&&a.scrollIntoView(!1);a.scrollTop=b.offsetTop-b.clientHeight}else b.scrollIntoView(!1)}};function B(b,a){var c=window.getSelection();if(null===c||!c.isCollapsed)return!1;let e=c.anchorNode;c=c.anchorOffset;if(null==e||null==c)return!1;try{a.setStart(e,b),a.setEnd(e,c)}catch(f){return!1}return!0}
9
9
  function C(b){let a=null;b.getEditorState().read(()=>{var c=w.$getSelection();if(w.$isRangeSelection(c)){var e=c.anchor;"text"!==e.type?a=null:(c=e.getNode(),c.isSimpleText()?(e=e.offset,a=c.getTextContent().slice(0,e)):a=null)}});return a}
10
10
  function D(b,a){b=w.$getSelection();if(!w.$isRangeSelection(b)||!b.isCollapsed())return null;var c=b.anchor;if("text"!==c.type)return null;b=c.getNode();if(!b.isSimpleText())return null;c=c.offset;let e=b.getTextContent().slice(0,c);var f=a.matchingString;a=a.replaceableString.length;for(let p=a;p<=f.length;p++)e.substr(-p)===f.substr(0,p)&&(a=p);a=c-a;if(0>a)return null;let q;0===a?[q]=b.splitText(c):[,q]=b.splitText(a,c);return q}
11
11
  function E(b,a){return 0!==a?!1:b.getEditorState().read(()=>{var c=w.$getSelection();return w.$isRangeSelection(c)?(c=c.anchor.getNode().getPreviousSibling(),w.$isTextNode(c)&&c.isTextEntity()):!1})}function F(b){x.startTransition?x.startTransition(b):b()}
package/package.json CHANGED
@@ -8,29 +8,29 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.7.6",
11
+ "version": "0.7.7",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.7.6",
14
- "@lexical/code": "0.7.6",
15
- "@lexical/dragon": "0.7.6",
16
- "@lexical/hashtag": "0.7.6",
17
- "@lexical/history": "0.7.6",
18
- "@lexical/link": "0.7.6",
19
- "@lexical/list": "0.7.6",
20
- "@lexical/mark": "0.7.6",
21
- "@lexical/markdown": "0.7.6",
22
- "@lexical/overflow": "0.7.6",
23
- "@lexical/plain-text": "0.7.6",
24
- "@lexical/rich-text": "0.7.6",
25
- "@lexical/selection": "0.7.6",
26
- "@lexical/table": "0.7.6",
27
- "@lexical/text": "0.7.6",
28
- "@lexical/utils": "0.7.6",
29
- "@lexical/yjs": "0.7.6",
13
+ "@lexical/clipboard": "0.7.7",
14
+ "@lexical/code": "0.7.7",
15
+ "@lexical/dragon": "0.7.7",
16
+ "@lexical/hashtag": "0.7.7",
17
+ "@lexical/history": "0.7.7",
18
+ "@lexical/link": "0.7.7",
19
+ "@lexical/list": "0.7.7",
20
+ "@lexical/mark": "0.7.7",
21
+ "@lexical/markdown": "0.7.7",
22
+ "@lexical/overflow": "0.7.7",
23
+ "@lexical/plain-text": "0.7.7",
24
+ "@lexical/rich-text": "0.7.7",
25
+ "@lexical/selection": "0.7.7",
26
+ "@lexical/table": "0.7.7",
27
+ "@lexical/text": "0.7.7",
28
+ "@lexical/utils": "0.7.7",
29
+ "@lexical/yjs": "0.7.7",
30
30
  "react-error-boundary": "^3.1.4"
31
31
  },
32
32
  "peerDependencies": {
33
- "lexical": "0.7.6",
33
+ "lexical": "0.7.7",
34
34
  "react": ">=17.x",
35
35
  "react-dom": ">=17.x"
36
36
  },
@@ -34,9 +34,16 @@ function useLexicalNodeSelection(key) {
34
34
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
35
35
  const [isSelected, setIsSelected] = react.useState(() => isNodeSelected(editor, key));
36
36
  react.useEffect(() => {
37
- return editor.registerUpdateListener(() => {
38
- setIsSelected(isNodeSelected(editor, key));
37
+ let isMounted = true;
38
+ const unregister = editor.registerUpdateListener(() => {
39
+ if (isMounted) {
40
+ setIsSelected(isNodeSelected(editor, key));
41
+ }
39
42
  });
43
+ return () => {
44
+ isMounted = false;
45
+ unregister();
46
+ };
40
47
  }, [editor, key]);
41
48
  const setSelected = react.useCallback(selected => {
42
49
  editor.update(() => {
@@ -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 c=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),h=require("react");function k(b,a){return b.getEditorState().read(()=>{let f=e.$getNodeByKey(a);return null===f?!1:f.isSelected()})}
8
- exports.useLexicalNodeSelection=function(b){let [a]=c.useLexicalComposerContext(),[f,l]=h.useState(()=>k(a,b));h.useEffect(()=>a.registerUpdateListener(()=>{l(k(a,b))}),[a,b]);let 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]}
7
+ 'use strict';var c=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),h=require("react");function k(b,a){return b.getEditorState().read(()=>{let g=f.$getNodeByKey(a);return null===g?!1:g.isSelected()})}
8
+ exports.useLexicalNodeSelection=function(b){let [a]=c.useLexicalComposerContext(),[g,l]=h.useState(()=>k(a,b));h.useEffect(()=>{let d=!0,e=a.registerUpdateListener(()=>{d&&l(k(a,b))});return()=>{d=!1;e()}},[a,b]);let m=h.useCallback(d=>{a.update(()=>{let e=f.$getSelection();f.$isNodeSelection(e)||(e=f.$createNodeSelection(),f.$setSelection(e));d?e.add(b):e.delete(b)})},[a,b]),n=h.useCallback(()=>{a.update(()=>{const d=f.$getSelection();f.$isNodeSelection(d)&&d.clear()})},[a]);return[g,m,n]}
@@ -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
- */
8
- import type { LexicalEditor } from 'lexical';
9
- export declare function useLexicalAutoFormatter(editor: LexicalEditor): void;
@@ -1,25 +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 markdown = require('@lexical/markdown');
10
- var react = require('react');
11
-
12
- /**
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- *
18
- */
19
- function useLexicalAutoFormatter(editor) {
20
- react.useEffect(() => {
21
- return markdown.registerMarkdownShortcuts(editor, markdown.TRANSFORMERS);
22
- }, [editor]);
23
- }
24
-
25
- exports.useLexicalAutoFormatter = useLexicalAutoFormatter;
@@ -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 DEPRECATED_useLexicalAutoFormatter = process.env.NODE_ENV === 'development' ? require('./DEPRECATED_useLexicalAutoFormatter.dev.js') : require('./DEPRECATED_useLexicalAutoFormatter.prod.js')
9
- module.exports = DEPRECATED_useLexicalAutoFormatter;
@@ -1,15 +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
- * @flow strict
8
- * @format
9
- */
10
-
11
- import type {LexicalEditor, TextNode} from 'lexical';
12
-
13
- declare function updateTextNode(node: TextNode, count: number): void;
14
- declare function textNodeTransform(node: TextNode): void;
15
- declare export function useLexicalAutoFormatter(editor: LexicalEditor): void;
@@ -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 a=require("@lexical/markdown"),c=require("react");exports.useLexicalAutoFormatter=function(b){c.useEffect(()=>a.registerMarkdownShortcuts(b,a.TRANSFORMERS),[b])}
@@ -1,10 +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
- */
8
- import type { LexicalEditor } from 'lexical';
9
- import { ErrorBoundaryType } from './shared/useDecorators';
10
- export declare function useLexicalDecorators(editor: LexicalEditor, ErrorBoundary: ErrorBoundaryType): Array<JSX.Element>;
@@ -1,88 +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 React = require('react');
10
- var reactDom = require('react-dom');
11
-
12
- /**
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- *
18
- */
19
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
20
-
21
- /**
22
- * Copyright (c) Meta Platforms, Inc. and affiliates.
23
- *
24
- * This source code is licensed under the MIT license found in the
25
- * LICENSE file in the root directory of this source tree.
26
- *
27
- */
28
- const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
29
- var useLayoutEffect = useLayoutEffectImpl;
30
-
31
- /**
32
- * Copyright (c) Meta Platforms, Inc. and affiliates.
33
- *
34
- * This source code is licensed under the MIT license found in the
35
- * LICENSE file in the root directory of this source tree.
36
- *
37
- */
38
- function useDecorators(editor, ErrorBoundary) {
39
- const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
40
-
41
- useLayoutEffect(() => {
42
- return editor.registerDecoratorListener(nextDecorators => {
43
- reactDom.flushSync(() => {
44
- setDecorators(nextDecorators);
45
- });
46
- });
47
- }, [editor]);
48
- React.useEffect(() => {
49
- // If the content editable mounts before the subscription is added, then
50
- // nothing will be rendered on initial pass. We can get around that by
51
- // ensuring that we set the value.
52
- setDecorators(editor.getDecorators());
53
- }, [editor]); // Return decorators defined as React Portals
54
-
55
- return React.useMemo(() => {
56
- const decoratedPortals = [];
57
- const decoratorKeys = Object.keys(decorators);
58
-
59
- for (let i = 0; i < decoratorKeys.length; i++) {
60
- const nodeKey = decoratorKeys[i];
61
- const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
62
- onError: e => editor._onError(e)
63
- }, /*#__PURE__*/React.createElement(React.Suspense, {
64
- fallback: null
65
- }, decorators[nodeKey]));
66
- const element = editor.getElementByKey(nodeKey);
67
-
68
- if (element !== null) {
69
- decoratedPortals.push( /*#__PURE__*/reactDom.createPortal(reactDecorator, element));
70
- }
71
- }
72
-
73
- return decoratedPortals;
74
- }, [ErrorBoundary, decorators, editor]);
75
- }
76
-
77
- /**
78
- * Copyright (c) Meta Platforms, Inc. and affiliates.
79
- *
80
- * This source code is licensed under the MIT license found in the
81
- * LICENSE file in the root directory of this source tree.
82
- *
83
- */
84
- function useLexicalDecorators(editor, ErrorBoundary) {
85
- return useDecorators(editor, ErrorBoundary);
86
- }
87
-
88
- exports.useLexicalDecorators = useLexicalDecorators;
@@ -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 DEPRECATED_useLexicalDecorators = process.env.NODE_ENV === 'development' ? require('./DEPRECATED_useLexicalDecorators.dev.js') : require('./DEPRECATED_useLexicalDecorators.prod.js')
9
- module.exports = DEPRECATED_useLexicalDecorators;
@@ -1,24 +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
- * @flow strict
8
- * @format
9
- */
10
-
11
- import type {LexicalEditor} from 'lexical';
12
-
13
- import * as React from 'react';
14
-
15
- type ErrorBoundaryProps = $ReadOnly<{
16
- children: React$Node,
17
- onError: (error: Error) => void,
18
- }>;
19
- export type ErrorBoundaryType = React.AbstractComponent<ErrorBoundaryProps>;
20
-
21
- declare export function useLexicalDecorators(
22
- editor: LexicalEditor,
23
- ErrorBoundary: ErrorBoundaryType,
24
- ): Array<React.Node>;
@@ -1,8 +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("react"),h=require("react-dom"),m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?b.useLayoutEffect:b.useEffect;
8
- function n(a,d){let [f,k]=b.useState(()=>a.getDecorators());m(()=>a.registerDecoratorListener(e=>{h.flushSync(()=>{k(e)})}),[a]);b.useEffect(()=>{k(a.getDecorators())},[a]);return b.useMemo(()=>{let e=[],l=Object.keys(f);for(let g=0;g<l.length;g++){var c=l[g];let q=b.createElement(d,{onError:p=>a._onError(p)},b.createElement(b.Suspense,{fallback:null},f[c]));c=a.getElementByKey(c);null!==c&&e.push(h.createPortal(q,c))}return e},[d,f,a])}exports.useLexicalDecorators=function(a,d){return n(a,d)}
@@ -1,10 +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
- */
8
- import type { InputEvents } from './shared/useEditorEvents';
9
- import type { LexicalEditor } from 'lexical';
10
- export declare function useLexicalEditorEvents(events: InputEvents, editor: LexicalEditor): void;
@@ -1,92 +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 react = require('react');
10
-
11
- /**
12
- * Copyright (c) Meta Platforms, Inc. and affiliates.
13
- *
14
- * This source code is licensed under the MIT license found in the
15
- * LICENSE file in the root directory of this source tree.
16
- *
17
- */
18
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
19
-
20
- /**
21
- * Copyright (c) Meta Platforms, Inc. and affiliates.
22
- *
23
- * This source code is licensed under the MIT license found in the
24
- * LICENSE file in the root directory of this source tree.
25
- *
26
- */
27
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
28
- var useLayoutEffect = useLayoutEffectImpl;
29
-
30
- /**
31
- * Copyright (c) Meta Platforms, Inc. and affiliates.
32
- *
33
- * This source code is licensed under the MIT license found in the
34
- * LICENSE file in the root directory of this source tree.
35
- *
36
- */
37
-
38
- function getTarget(eventName, rootElement) {
39
- return eventName === 'selectionchange' || eventName === 'keyup' || eventName === 'pointerup' || eventName === 'pointercancel' ? rootElement.ownerDocument : rootElement;
40
- }
41
-
42
- function isRootEditable(editor) {
43
- const rootElement = editor.getRootElement();
44
- return rootElement !== null && rootElement.contentEditable === 'true';
45
- }
46
-
47
- function useEditorEvents(events, editor) {
48
- useLayoutEffect(() => {
49
- const create = [];
50
- const destroy = [];
51
-
52
- for (let i = 0; i < events.length; i++) {
53
- const [eventName, handler] = events[i];
54
-
55
- const handlerWrapper = event => {
56
- if (isRootEditable(editor)) {
57
- handler(event, editor);
58
- }
59
- };
60
-
61
- create.push(rootElement => {
62
- getTarget(eventName, rootElement).addEventListener(eventName, handlerWrapper);
63
- });
64
- destroy.push(rootElement => {
65
- getTarget(eventName, rootElement).removeEventListener(eventName, handlerWrapper);
66
- });
67
- }
68
-
69
- return editor.registerRootListener((rootElement, prevRootElement) => {
70
- if (prevRootElement !== null) {
71
- destroy.forEach(fn => fn(prevRootElement));
72
- }
73
-
74
- if (rootElement !== null) {
75
- create.forEach(fn => fn(rootElement));
76
- }
77
- });
78
- }, [editor, events]);
79
- }
80
-
81
- /**
82
- * Copyright (c) Meta Platforms, Inc. and affiliates.
83
- *
84
- * This source code is licensed under the MIT license found in the
85
- * LICENSE file in the root directory of this source tree.
86
- *
87
- */
88
- function useLexicalEditorEvents(events, editor) {
89
- useEditorEvents(events, editor);
90
- }
91
-
92
- exports.useLexicalEditorEvents = useLexicalEditorEvents;
@@ -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 DEPRECATED_useLexicalEditorEvents = process.env.NODE_ENV === 'development' ? require('./DEPRECATED_useLexicalEditorEvents.dev.js') : require('./DEPRECATED_useLexicalEditorEvents.prod.js')
9
- module.exports = DEPRECATED_useLexicalEditorEvents;
@@ -1,22 +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
- * @flow strict
8
- * @format
9
- */
10
-
11
- import type {LexicalEditor} from 'lexical';
12
-
13
- export type InputEvents = Array<[string, EventHandler]>;
14
- declare function getTarget(
15
- eventName: string,
16
- rootElement: HTMLElement,
17
- ): EventTarget;
18
- declare function isRootEditable(editor: LexicalEditor): boolean;
19
- declare export function useLexicalEditorEvents(
20
- events: InputEvents,
21
- editor: LexicalEditor,
22
- ): void;
@@ -1,8 +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 g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;function p(a,b){return"selectionchange"===a||"keyup"===a||"pointerup"===a||"pointercancel"===a?b.ownerDocument:b}
8
- function q(a,b){h(()=>{let k=[],l=[];for(let d=0;d<a.length;d++){let [c,e]=a[d],n=f=>{let m=b.getRootElement();null!==m&&"true"===m.contentEditable&&e(f,b)};k.push(f=>{p(c,f).addEventListener(c,n)});l.push(f=>{p(c,f).removeEventListener(c,n)})}return b.registerRootListener((d,c)=>{null!==c&&l.forEach(e=>e(c));null!==d&&k.forEach(e=>e(d))})},[b,a])}exports.useLexicalEditorEvents=function(a,b){q(a,b)}
@@ -1,61 +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 list = require('@lexical/list');
10
- var utils = require('@lexical/utils');
11
- var lexical = require('lexical');
12
- var react = require('react');
13
-
14
- /**
15
- * Copyright (c) Meta Platforms, Inc. and affiliates.
16
- *
17
- * This source code is licensed under the MIT license found in the
18
- * LICENSE file in the root directory of this source tree.
19
- *
20
- */
21
- function useList(editor) {
22
- react.useEffect(() => {
23
- return utils.mergeRegister(editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, () => {
24
- list.indentList();
25
- return false;
26
- }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, () => {
27
- list.outdentList();
28
- return false;
29
- }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.INSERT_ORDERED_LIST_COMMAND, () => {
30
- list.insertList(editor, 'number');
31
- return true;
32
- }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.INSERT_UNORDERED_LIST_COMMAND, () => {
33
- list.insertList(editor, 'bullet');
34
- return true;
35
- }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.REMOVE_LIST_COMMAND, () => {
36
- list.removeList(editor);
37
- return true;
38
- }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, () => {
39
- const hasHandledInsertParagraph = list.$handleListInsertParagraph();
40
-
41
- if (hasHandledInsertParagraph) {
42
- return true;
43
- }
44
-
45
- return false;
46
- }, lexical.COMMAND_PRIORITY_LOW));
47
- }, [editor]);
48
- }
49
-
50
- /**
51
- * Copyright (c) Meta Platforms, Inc. and affiliates.
52
- *
53
- * This source code is licensed under the MIT license found in the
54
- * LICENSE file in the root directory of this source tree.
55
- *
56
- */
57
- function useLexicalList(editor) {
58
- useList(editor);
59
- }
60
-
61
- exports.useLexicalList = useLexicalList;
@@ -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 DEPRECATED_useLexicalList = process.env.NODE_ENV === 'development' ? require('./DEPRECATED_useLexicalList.dev.js') : require('./DEPRECATED_useLexicalList.prod.js')
9
- module.exports = DEPRECATED_useLexicalList;
@@ -1,13 +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
- * @flow strict
8
- * @format
9
- */
10
-
11
- import type {LexicalEditor} from 'lexical';
12
-
13
- declare export function useLexicalList(editor: LexicalEditor): void;
@@ -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';var b=require("@lexical/list"),c=require("@lexical/utils"),d=require("lexical"),e=require("react");
8
- function f(a){e.useEffect(()=>c.mergeRegister(a.registerCommand(d.INDENT_CONTENT_COMMAND,()=>{b.indentList();return!1},d.COMMAND_PRIORITY_LOW),a.registerCommand(d.OUTDENT_CONTENT_COMMAND,()=>{b.outdentList();return!1},d.COMMAND_PRIORITY_LOW),a.registerCommand(b.INSERT_ORDERED_LIST_COMMAND,()=>{b.insertList(a,"number");return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(b.INSERT_UNORDERED_LIST_COMMAND,()=>{b.insertList(a,"bullet");return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(b.REMOVE_LIST_COMMAND,
9
- ()=>{b.removeList(a);return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(d.INSERT_PARAGRAPH_COMMAND,()=>b.$handleListInsertParagraph()?!0:!1,d.COMMAND_PRIORITY_LOW)),[a])}exports.useLexicalList=function(a){f(a)}
@@ -1,10 +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
- */
8
- import type { EventHandler, LexicalEditor } from 'lexical';
9
- export declare type InputEvents = Array<[string, EventHandler]>;
10
- export declare function useEditorEvents(events: InputEvents, editor: LexicalEditor): void;