@lexical/react 0.3.5 → 0.3.8

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 (52) hide show
  1. package/DEPRECATED_useLexical.d.ts +1 -2
  2. package/DEPRECATED_useLexical.dev.js +18 -9
  3. package/DEPRECATED_useLexical.prod.js +2 -3
  4. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +18 -9
  5. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +2 -2
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +3 -3
  7. package/DEPRECATED_useLexicalEditor.dev.js +18 -9
  8. package/DEPRECATED_useLexicalEditor.prod.js +2 -2
  9. package/LexicalAutoFocusPlugin.d.ts +5 -1
  10. package/LexicalAutoFocusPlugin.dev.js +7 -3
  11. package/LexicalAutoFocusPlugin.js.flow +5 -1
  12. package/LexicalAutoFocusPlugin.prod.js +1 -1
  13. package/LexicalAutoLinkPlugin.d.ts +1 -1
  14. package/LexicalAutoLinkPlugin.prod.js +3 -3
  15. package/LexicalAutoScrollPlugin.d.ts +1 -1
  16. package/LexicalBlockWithAlignableContents.d.ts +2 -1
  17. package/LexicalBlockWithAlignableContents.dev.js +3 -4
  18. package/LexicalBlockWithAlignableContents.prod.js +2 -2
  19. package/LexicalCharacterLimitPlugin.prod.js +3 -3
  20. package/LexicalCheckListPlugin.dev.js +11 -6
  21. package/LexicalCheckListPlugin.prod.js +7 -7
  22. package/LexicalClearEditorPlugin.d.ts +1 -1
  23. package/LexicalCollaborationPlugin.dev.js +1 -0
  24. package/LexicalCollaborationPlugin.prod.js +1 -1
  25. package/LexicalComposer.d.ts +2 -2
  26. package/LexicalComposerContext.prod.js +2 -1
  27. package/LexicalContentEditable.dev.js +3 -3
  28. package/LexicalContentEditable.prod.js +1 -1
  29. package/LexicalDecoratorBlockNode.d.ts +2 -2
  30. package/LexicalDecoratorBlockNode.dev.js +1 -1
  31. package/LexicalDecoratorBlockNode.prod.js +1 -1
  32. package/LexicalHashtagPlugin.d.ts +1 -1
  33. package/LexicalNestedComposer.d.ts +2 -1
  34. package/LexicalNestedComposer.prod.js +2 -2
  35. package/LexicalPlainTextPlugin.dev.js +20 -12
  36. package/LexicalPlainTextPlugin.prod.js +4 -4
  37. package/LexicalRichTextPlugin.dev.js +20 -12
  38. package/LexicalRichTextPlugin.prod.js +4 -4
  39. package/LexicalTableOfContents__EXPERIMENTAL.d.ts +14 -0
  40. package/LexicalTableOfContents__EXPERIMENTAL.dev.js +144 -0
  41. package/LexicalTableOfContents__EXPERIMENTAL.js +9 -0
  42. package/LexicalTableOfContents__EXPERIMENTAL.js.flow +17 -0
  43. package/LexicalTableOfContents__EXPERIMENTAL.prod.js +10 -0
  44. package/LexicalTablePlugin.d.ts +1 -1
  45. package/LexicalTablePlugin.dev.js +1 -1
  46. package/LexicalTablePlugin.prod.js +3 -3
  47. package/LexicalTypeaheadMenuPlugin.d.ts +44 -0
  48. package/LexicalTypeaheadMenuPlugin.dev.js +463 -0
  49. package/LexicalTypeaheadMenuPlugin.js +9 -0
  50. package/LexicalTypeaheadMenuPlugin.prod.js +19 -0
  51. package/package.json +19 -22
  52. package/useLexicalTextEntity.d.ts +2 -3
@@ -9,10 +9,10 @@
9
9
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
10
  var React = require('react');
11
11
  var text = require('@lexical/text');
12
+ var utils = require('@lexical/utils');
12
13
  var reactDom = require('react-dom');
13
14
  var dragon = require('@lexical/dragon');
14
15
  var plainText = require('@lexical/plain-text');
15
- var utils = require('@lexical/utils');
16
16
 
17
17
  /**
18
18
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -59,18 +59,26 @@ var useLayoutEffect = useLayoutEffectImpl;
59
59
  * LICENSE file in the root directory of this source tree.
60
60
  *
61
61
  */
62
+
63
+ function canShowPlaceholderFromCurrentEditorState(editor) {
64
+ const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing(), editor.isReadOnly()));
65
+ return currentCanShowPlaceholder;
66
+ }
67
+
62
68
  function useCanShowPlaceholder(editor) {
63
- const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
69
+ const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
64
70
  useLayoutEffect(() => {
65
- let currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
66
- setCanShowPlaceholder(currentCanShowPlaceholder);
67
- return editor.registerUpdateListener(({
68
- editorState
69
- }) => {
70
- const isComposing = editor.isComposing();
71
- currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
71
+ function resetCanShowPlaceholder() {
72
+ const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
72
73
  setCanShowPlaceholder(currentCanShowPlaceholder);
73
- });
74
+ }
75
+
76
+ resetCanShowPlaceholder();
77
+ return utils.mergeRegister(editor.registerUpdateListener(() => {
78
+ resetCanShowPlaceholder();
79
+ }), editor.registerReadOnlyListener(() => {
80
+ resetCanShowPlaceholder();
81
+ }));
74
82
  }, [editor]);
75
83
  return canShowPlaceholder;
76
84
  }
@@ -138,13 +146,13 @@ function usePlainTextSetup(editor, initialEditorState) {
138
146
  * LICENSE file in the root directory of this source tree.
139
147
  *
140
148
  */
141
- const deprecatedInitialEditorStateWarning = warnOnlyOnce('initialEditorState on PlainTextPlugin is deprecated and will be removed soon. Use LexicalComposer initialEditorState instead.');
149
+ const deprecatedInitialEditorStateWarning = warnOnlyOnce('`initialEditorState` on `PlainTextPlugin` is deprecated and will be removed soon. Use the `initialConfig.editorState` prop on the `LexicalComposer` instead.');
142
150
  function PlainTextPlugin({
143
151
  contentEditable,
144
152
  placeholder,
145
153
  initialEditorState
146
154
  }) {
147
- if (initialEditorState !== undefined) {
155
+ if (deprecatedInitialEditorStateWarning && initialEditorState !== undefined) {
148
156
  deprecatedInitialEditorStateWarning();
149
157
  }
150
158
 
@@ -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 e=require("@lexical/react/LexicalComposerContext"),h=require("react"),k=require("@lexical/text"),m=require("react-dom"),n=require("@lexical/dragon"),p=require("@lexical/plain-text"),q=require("@lexical/utils"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
8
- function t(a){let [c,f]=h.useState(a.getEditorState().read(k.$canShowPlaceholderCurry(a.isComposing())));r(()=>{let b=a.getEditorState().read(k.$canShowPlaceholderCurry(a.isComposing()));f(b);return a.registerUpdateListener(({editorState:g})=>{let d=a.isComposing();b=g.read(k.$canShowPlaceholderCurry(d));f(b)})},[a]);return c}
9
- function u(a){let [c,f]=h.useState(()=>a.getDecorators());r(()=>a.registerDecoratorListener(b=>{m.flushSync(()=>{f(b)})}),[a]);h.useEffect(()=>{f(a.getDecorators())},[a]);return h.useMemo(()=>{let b=[],g=Object.keys(c);for(let l=0;l<g.length;l++){var d=g[l];let v=c[d];d=a.getElementByKey(d);null!==d&&b.push(m.createPortal(v,d))}return b},[c,a])}function w(a,c){r(()=>q.mergeRegister(p.registerPlainText(a,c),n.registerDragonSupport(a)),[a])}
10
- exports.PlainTextPlugin=function({contentEditable:a,placeholder:c,initialEditorState:f}){let [b]=e.useLexicalComposerContext(),g=t(b),d=u(b);w(b,f);return h.createElement(h.Fragment,null,a,g&&c,d)}
7
+ 'use strict';var d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/plain-text"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function t(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isReadOnly()))}
8
+ function u(a){let [c,f]=h.useState(()=>t(a));r(()=>{function b(){let g=t(a);f(g)}b();return m.mergeRegister(a.registerUpdateListener(()=>{b()}),a.registerReadOnlyListener(()=>{b()}))},[a]);return c}
9
+ function v(a){let [c,f]=h.useState(()=>a.getDecorators());r(()=>a.registerDecoratorListener(b=>{n.flushSync(()=>{f(b)})}),[a]);h.useEffect(()=>{f(a.getDecorators())},[a]);return h.useMemo(()=>{let b=[],g=Object.keys(c);for(let k=0;k<g.length;k++){var e=g[k];let w=c[e];e=a.getElementByKey(e);null!==e&&b.push(n.createPortal(w,e))}return b},[c,a])}function x(a,c){r(()=>m.mergeRegister(q.registerPlainText(a,c),p.registerDragonSupport(a)),[a])}
10
+ exports.PlainTextPlugin=function({contentEditable:a,placeholder:c,initialEditorState:f}){let [b]=d.useLexicalComposerContext(),g=u(b),e=v(b);x(b,f);return h.createElement(h.Fragment,null,a,g&&c,e)}
@@ -9,10 +9,10 @@
9
9
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
10
  var React = require('react');
11
11
  var text = require('@lexical/text');
12
+ var utils = require('@lexical/utils');
12
13
  var reactDom = require('react-dom');
13
14
  var dragon = require('@lexical/dragon');
14
15
  var richText = require('@lexical/rich-text');
15
- var utils = require('@lexical/utils');
16
16
 
17
17
  /**
18
18
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -59,18 +59,26 @@ var useLayoutEffect = useLayoutEffectImpl;
59
59
  * LICENSE file in the root directory of this source tree.
60
60
  *
61
61
  */
62
+
63
+ function canShowPlaceholderFromCurrentEditorState(editor) {
64
+ const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing(), editor.isReadOnly()));
65
+ return currentCanShowPlaceholder;
66
+ }
67
+
62
68
  function useCanShowPlaceholder(editor) {
63
- const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
69
+ const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
64
70
  useLayoutEffect(() => {
65
- let currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
66
- setCanShowPlaceholder(currentCanShowPlaceholder);
67
- return editor.registerUpdateListener(({
68
- editorState
69
- }) => {
70
- const isComposing = editor.isComposing();
71
- currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
71
+ function resetCanShowPlaceholder() {
72
+ const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
72
73
  setCanShowPlaceholder(currentCanShowPlaceholder);
73
- });
74
+ }
75
+
76
+ resetCanShowPlaceholder();
77
+ return utils.mergeRegister(editor.registerUpdateListener(() => {
78
+ resetCanShowPlaceholder();
79
+ }), editor.registerReadOnlyListener(() => {
80
+ resetCanShowPlaceholder();
81
+ }));
74
82
  }, [editor]);
75
83
  return canShowPlaceholder;
76
84
  }
@@ -138,13 +146,13 @@ function useRichTextSetup(editor, initialEditorState) {
138
146
  * LICENSE file in the root directory of this source tree.
139
147
  *
140
148
  */
141
- const deprecatedInitialEditorStateWarning = warnOnlyOnce('initialEditorState on RichTextPlugin is deprecated and will be removed soon. Use LexicalComposer initialEditorState instead.');
149
+ const deprecatedInitialEditorStateWarning = warnOnlyOnce('`initialEditorState` on `RichTextPlugin` is deprecated and will be removed soon. Use the `initialConfig.editorState` prop on the `LexicalComposer` instead.');
142
150
  function RichTextPlugin({
143
151
  contentEditable,
144
152
  placeholder,
145
153
  initialEditorState
146
154
  }) {
147
- if (initialEditorState !== undefined) {
155
+ if (deprecatedInitialEditorStateWarning && initialEditorState !== undefined) {
148
156
  deprecatedInitialEditorStateWarning();
149
157
  }
150
158
 
@@ -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 e=require("@lexical/react/LexicalComposerContext"),h=require("react"),k=require("@lexical/text"),m=require("react-dom"),n=require("@lexical/dragon"),p=require("@lexical/rich-text"),q=require("@lexical/utils"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
8
- function t(a){let [c,f]=h.useState(a.getEditorState().read(k.$canShowPlaceholderCurry(a.isComposing())));r(()=>{let b=a.getEditorState().read(k.$canShowPlaceholderCurry(a.isComposing()));f(b);return a.registerUpdateListener(({editorState:g})=>{let d=a.isComposing();b=g.read(k.$canShowPlaceholderCurry(d));f(b)})},[a]);return c}
9
- function u(a){let [c,f]=h.useState(()=>a.getDecorators());r(()=>a.registerDecoratorListener(b=>{m.flushSync(()=>{f(b)})}),[a]);h.useEffect(()=>{f(a.getDecorators())},[a]);return h.useMemo(()=>{let b=[],g=Object.keys(c);for(let l=0;l<g.length;l++){var d=g[l];let v=c[d];d=a.getElementByKey(d);null!==d&&b.push(m.createPortal(v,d))}return b},[c,a])}function w(a,c){r(()=>q.mergeRegister(p.registerRichText(a,c),n.registerDragonSupport(a)),[a])}
10
- exports.RichTextPlugin=function({contentEditable:a,placeholder:c,initialEditorState:f}){let [b]=e.useLexicalComposerContext(),g=t(b),d=u(b);w(b,f);return h.createElement(h.Fragment,null,a,g&&c,d)}
7
+ 'use strict';var d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("@lexical/utils"),n=require("react-dom"),p=require("@lexical/dragon"),q=require("@lexical/rich-text"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;function t(a){return a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing(),a.isReadOnly()))}
8
+ function u(a){let [c,f]=h.useState(()=>t(a));r(()=>{function b(){let g=t(a);f(g)}b();return m.mergeRegister(a.registerUpdateListener(()=>{b()}),a.registerReadOnlyListener(()=>{b()}))},[a]);return c}
9
+ function v(a){let [c,f]=h.useState(()=>a.getDecorators());r(()=>a.registerDecoratorListener(b=>{n.flushSync(()=>{f(b)})}),[a]);h.useEffect(()=>{f(a.getDecorators())},[a]);return h.useMemo(()=>{let b=[],g=Object.keys(c);for(let k=0;k<g.length;k++){var e=g[k];let w=c[e];e=a.getElementByKey(e);null!==e&&b.push(n.createPortal(w,e))}return b},[c,a])}function x(a,c){r(()=>m.mergeRegister(q.registerRichText(a,c),p.registerDragonSupport(a)),[a])}
10
+ exports.RichTextPlugin=function({contentEditable:a,placeholder:c,initialEditorState:f}){let [b]=d.useLexicalComposerContext(),g=u(b),e=v(b);x(b,f);return h.createElement(h.Fragment,null,a,g&&c,e)}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { LexicalEditor, NodeKey } from 'lexical';
9
+ import { HeadingTagType } from '@lexical/rich-text';
10
+ declare type Props = {
11
+ children: (values: Array<[key: NodeKey, text: string, tag: HeadingTagType]>, editor: LexicalEditor) => JSX.Element;
12
+ };
13
+ export default function LexicalTableOfContentsPlugin({ children, }: Props): JSX.Element;
14
+ export {};
@@ -0,0 +1,144 @@
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 richText = require('@lexical/rich-text');
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
+
22
+ function $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents) {
23
+ if (newHeading === null) {
24
+ return currentTableOfContents;
25
+ }
26
+
27
+ const newEntry = [newHeading.getKey(), newHeading.getTextContent(), newHeading.getTag()];
28
+ let newTableOfContents = [];
29
+
30
+ if (prevHeading === null) {
31
+ newTableOfContents = [newEntry, ...currentTableOfContents];
32
+ } else {
33
+ for (let i = 0; i < currentTableOfContents.length; i++) {
34
+ const key = currentTableOfContents[i][0];
35
+ newTableOfContents.push(currentTableOfContents[i]);
36
+
37
+ if (key === prevHeading.getKey() && key !== newHeading.getKey()) {
38
+ newTableOfContents.push(newEntry);
39
+ }
40
+ }
41
+ }
42
+
43
+ return newTableOfContents;
44
+ }
45
+
46
+ function $deleteHeadingFromTableOfContents(key, currentTableOfContents) {
47
+ const newTableOfContents = [];
48
+
49
+ for (const heading of currentTableOfContents) {
50
+ if (heading[0] !== key) {
51
+ newTableOfContents.push(heading);
52
+ }
53
+ }
54
+
55
+ return newTableOfContents;
56
+ }
57
+
58
+ function $updateHeadingInTableOfContents(heading, currentTableOfContents) {
59
+ const newTextContent = heading.getTextContent();
60
+ const newTableOfContents = [];
61
+
62
+ for (const oldHeading of currentTableOfContents) {
63
+ if (oldHeading[0] === heading.getKey()) {
64
+ newTableOfContents.push([heading.getKey(), newTextContent, heading.getTag()]);
65
+ } else {
66
+ newTableOfContents.push(oldHeading);
67
+ }
68
+ }
69
+
70
+ return newTableOfContents;
71
+ }
72
+
73
+ function LexicalTableOfContentsPlugin({
74
+ children
75
+ }) {
76
+ const [tableOfContents, setTableOfContents] = react.useState([]);
77
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
78
+ react.useEffect(() => {
79
+ // Set table of contents initial state
80
+ let currentTableOfContents = [];
81
+ editor.getEditorState().read(() => {
82
+ const root = lexical.$getRoot();
83
+ const rootChildren = root.getChildren();
84
+
85
+ for (const child of rootChildren) {
86
+ if (richText.$isHeadingNode(child)) {
87
+ currentTableOfContents.push([child.getKey(), child.getTextContent(), child.getTag()]);
88
+ }
89
+ }
90
+
91
+ setTableOfContents(currentTableOfContents);
92
+ }); // Listen to updates to heading mutations and update state
93
+
94
+ const removeHeaderMutationListener = editor.registerMutationListener(richText.HeadingNode, mutatedNodes => {
95
+ editor.getEditorState().read(() => {
96
+ for (const [nodeKey, mutation] of mutatedNodes) {
97
+ if (mutation === 'created') {
98
+ const newHeading = lexical.$getNodeByKey(nodeKey);
99
+
100
+ if (newHeading !== null) {
101
+ let prevHeading = newHeading.getPreviousSibling();
102
+
103
+ while (prevHeading && !richText.$isHeadingNode(prevHeading)) {
104
+ prevHeading = prevHeading.getPreviousSibling();
105
+ }
106
+
107
+ currentTableOfContents = $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents);
108
+ setTableOfContents(currentTableOfContents);
109
+ }
110
+ } else if (mutation === 'destroyed') {
111
+ currentTableOfContents = $deleteHeadingFromTableOfContents(nodeKey, currentTableOfContents);
112
+ setTableOfContents(currentTableOfContents);
113
+ }
114
+ }
115
+ });
116
+ }); // Listen to text node mutation updates
117
+
118
+ const removeTextNodeMutationListener = editor.registerMutationListener(lexical.TextNode, mutatedNodes => {
119
+ editor.getEditorState().read(() => {
120
+ for (const [nodeKey, mutation] of mutatedNodes) {
121
+ if (mutation === 'updated') {
122
+ const currNode = lexical.$getNodeByKey(nodeKey);
123
+
124
+ if (currNode !== null) {
125
+ const parentNode = currNode.getParentOrThrow();
126
+
127
+ if (richText.$isHeadingNode(parentNode)) {
128
+ currentTableOfContents = $updateHeadingInTableOfContents(parentNode, currentTableOfContents);
129
+ setTableOfContents(currentTableOfContents);
130
+ }
131
+ }
132
+ }
133
+ }
134
+ });
135
+ });
136
+ return () => {
137
+ removeHeaderMutationListener();
138
+ removeTextNodeMutationListener();
139
+ };
140
+ }, [editor]);
141
+ return children(tableOfContents, editor);
142
+ }
143
+
144
+ module.exports = LexicalTableOfContentsPlugin;
@@ -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 LexicalTableOfContents__EXPERIMENTAL = process.env.NODE_ENV === 'development' ? require('./LexicalTableOfContents__EXPERIMENTAL.dev.js') : require('./LexicalTableOfContents__EXPERIMENTAL.prod.js')
9
+ module.exports = LexicalTableOfContents__EXPERIMENTAL;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type {HeadingTagType} from '@lexical/rich-text';
11
+ import type {NodeKey} from 'lexical';
12
+
13
+ declare export function LexicalTableOfContentsPlugin(
14
+ children: (
15
+ tableOfContents: Array<[NodeKey, string, HeadingTagType]>,
16
+ ) => React$Node,
17
+ ): React$Node;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ '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)}
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- export declare function TablePlugin(): JSX.Element;
8
+ export declare function TablePlugin(): JSX.Element | null;
@@ -84,7 +84,7 @@ function TablePlugin() {
84
84
  } else if (mutation === 'destroyed') {
85
85
  const tableSelection = tableSelections.get(nodeKey);
86
86
 
87
- if (tableSelection) {
87
+ if (tableSelection !== undefined) {
88
88
  tableSelection.removeListeners();
89
89
  tableSelections.delete(nodeKey);
90
90
  }
@@ -5,6 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/table"),k=require("lexical"),m=require("react");
8
- exports.TablePlugin=function(){let [c]=e.useLexicalComposerContext();m.useEffect(()=>{if(!c.hasNodes([f.TableNode,f.TableCellNode,f.TableRowNode]))throw Error("Minified Lexical error #10; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return c.registerCommand(f.INSERT_TABLE_COMMAND,({columns:a,rows:d,includeHeaders:g})=>{var b=k.$getSelection();if(!k.$isRangeSelection(b))return!0;let h=b.focus;b=h.getNode();null!==b&&
9
- (a=f.$createTableNodeWithDimensions(Number(d),Number(a),g),k.$isRootNode(b)?(d=b.getChildAtIndex(h.offset),null!==d?d.insertBefore(a):b.append(a),a.insertBefore(k.$createParagraphNode())):b.getTopLevelElementOrThrow().insertAfter(a),a.insertAfter(k.$createParagraphNode()),a.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0},k.COMMAND_PRIORITY_EDITOR)},[c]);m.useEffect(()=>{let a=new Map;return c.registerMutationListener(f.TableNode,d=>{for(let [g,b]of d)"created"===b?c.update(()=>{var h=
10
- c.getElementByKey(g);let l=k.$getNodeByKey(g);h&&l&&(h=f.applyTableHandlers(l,h,c),a.set(g,h))}):"destroyed"===b&&(d=a.get(g))&&(d.removeListeners(),a.delete(g))})},[c]);return null}
8
+ exports.TablePlugin=function(){let [d]=e.useLexicalComposerContext();m.useEffect(()=>{if(!d.hasNodes([f.TableNode,f.TableCellNode,f.TableRowNode]))throw Error("Minified Lexical error #10; visit https://lexical.dev/docs/error?code=10 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return d.registerCommand(f.INSERT_TABLE_COMMAND,({columns:a,rows:c,includeHeaders:g})=>{var b=k.$getSelection();if(!k.$isRangeSelection(b))return!0;let h=b.focus;
9
+ b=h.getNode();null!==b&&(a=f.$createTableNodeWithDimensions(Number(c),Number(a),g),k.$isRootNode(b)?(c=b.getChildAtIndex(h.offset),null!==c?c.insertBefore(a):b.append(a),a.insertBefore(k.$createParagraphNode())):b.getTopLevelElementOrThrow().insertAfter(a),a.insertAfter(k.$createParagraphNode()),a.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0},k.COMMAND_PRIORITY_EDITOR)},[d]);m.useEffect(()=>{let a=new Map;return d.registerMutationListener(f.TableNode,c=>{for(let [g,b]of c)"created"===
10
+ b?d.update(()=>{var h=d.getElementByKey(g);let l=k.$getNodeByKey(g);h&&l&&(h=f.applyTableHandlers(l,h,d),a.set(g,h))}):"destroyed"===b&&(c=a.get(g),void 0!==c&&(c.removeListeners(),a.delete(g)))})},[d]);return null}
@@ -0,0 +1,44 @@
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 { TextNode } from 'lexical';
9
+ import { MutableRefObject, ReactPortal } from 'react';
10
+ export declare type QueryMatch = {
11
+ leadOffset: number;
12
+ matchingString: string;
13
+ replaceableString: string;
14
+ };
15
+ export declare type Resolution = {
16
+ match: QueryMatch;
17
+ range: Range;
18
+ };
19
+ export declare const PUNCTUATION = "\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
20
+ export declare class TypeaheadOption {
21
+ key: string;
22
+ ref?: MutableRefObject<HTMLElement | null>;
23
+ constructor(key: string);
24
+ setRefElement(element: HTMLElement | null): void;
25
+ }
26
+ declare type MenuRenderFn<TOption extends TypeaheadOption> = (anchorElement: HTMLElement | null, itemProps: {
27
+ selectedIndex: number | null;
28
+ selectOptionAndCleanUp: (option: TOption) => void;
29
+ setHighlightedIndex: (index: number) => void;
30
+ }, matchingString: string) => ReactPortal | JSX.Element | null;
31
+ export declare function useBasicTypeaheadTriggerMatch(trigger: string, { minLength, maxLength }: {
32
+ minLength?: number;
33
+ maxLength?: number;
34
+ }): TriggerFn;
35
+ declare type TypeaheadMenuPluginArgs<TOption extends TypeaheadOption> = {
36
+ onQueryChange: (matchingString: string | null) => void;
37
+ onSelectOption: (option: TOption, textNodeContainingQuery: TextNode | null, closeMenu: () => void, matchingString: string) => void;
38
+ options: Array<TOption>;
39
+ menuRenderFn: MenuRenderFn<TOption>;
40
+ triggerFn: TriggerFn;
41
+ };
42
+ declare type TriggerFn = (text: string) => QueryMatch | null;
43
+ export declare function LexicalTypeaheadMenuPlugin<TOption extends TypeaheadOption>({ options, onQueryChange, onSelectOption, menuRenderFn, triggerFn, }: TypeaheadMenuPluginArgs<TOption>): JSX.Element | null;
44
+ export {};