@lexical/react 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalAutoEmbedPlugin.d.ts +1 -0
- package/LexicalAutoEmbedPlugin.dev.js +11 -0
- package/LexicalAutoFocusPlugin.dev.js +1 -0
- package/LexicalAutoLinkPlugin.d.ts +1 -0
- package/LexicalAutoLinkPlugin.dev.js +50 -7
- package/LexicalBlockWithAlignableContents.dev.js +13 -2
- package/LexicalBlockWithAlignableContents.prod.js +4 -4
- package/LexicalCharacterLimitPlugin.d.ts +1 -0
- package/LexicalCharacterLimitPlugin.dev.js +46 -7
- package/LexicalCheckListPlugin.dev.js +48 -10
- package/LexicalClearEditorPlugin.d.ts +1 -0
- package/LexicalClearEditorPlugin.dev.js +1 -1
- package/LexicalCollaborationContext.dev.js +3 -0
- package/LexicalCollaborationPlugin.d.ts +3 -2
- package/LexicalCollaborationPlugin.dev.js +35 -6
- package/LexicalComposer.d.ts +1 -0
- package/LexicalComposer.dev.js +10 -6
- package/LexicalComposerContext.dev.js +6 -0
- package/LexicalContentEditable.dev.js +0 -1
- package/LexicalDecoratorBlockNode.d.ts +1 -0
- package/LexicalDecoratorBlockNode.dev.js +5 -0
- package/LexicalErrorBoundary.d.ts +1 -0
- package/LexicalHashtagPlugin.d.ts +1 -0
- package/LexicalHashtagPlugin.dev.js +43 -73
- package/LexicalHorizontalRuleNode.d.ts +1 -0
- package/LexicalHorizontalRuleNode.dev.js +22 -0
- package/LexicalHorizontalRulePlugin.dev.js +4 -0
- package/LexicalLinkPlugin.dev.js +10 -4
- package/LexicalListPlugin.dev.js +2 -0
- package/LexicalMarkdownShortcutPlugin.dev.js +2 -2
- package/LexicalNestedComposer.dev.js +12 -6
- package/LexicalNestedComposer.prod.js +2 -2
- package/LexicalNodeEventPlugin.dev.js +3 -5
- package/LexicalOnChangePlugin.dev.js +1 -1
- package/LexicalPlainTextPlugin.d.ts +1 -0
- package/LexicalPlainTextPlugin.dev.js +12 -8
- package/LexicalRichTextPlugin.d.ts +1 -0
- package/LexicalRichTextPlugin.dev.js +12 -8
- package/LexicalTabIndentationPlugin.dev.js +3 -1
- package/{LexicalTableOfContents__EXPERIMENTAL.d.ts → LexicalTableOfContents.d.ts} +1 -0
- package/{LexicalTableOfContents__EXPERIMENTAL.dev.js → LexicalTableOfContents.dev.js} +33 -5
- package/{DEPRECATED_useLexical.js → LexicalTableOfContents.js} +2 -2
- package/LexicalTablePlugin.d.ts +1 -0
- package/LexicalTablePlugin.dev.js +19 -5
- package/LexicalTreeView.d.ts +1 -0
- package/LexicalTreeView.dev.js +113 -21
- package/LexicalTreeView.prod.js +16 -15
- package/LexicalTypeaheadMenuPlugin.dev.js +123 -17
- package/LexicalTypeaheadMenuPlugin.prod.js +18 -18
- package/package.json +19 -19
- package/shared/useYjsCollaboration.d.ts +3 -4
- package/useLexicalEditable.dev.js +5 -1
- package/useLexicalIsTextContentEmpty.dev.js +0 -1
- package/useLexicalNodeSelection.dev.js +7 -0
- package/useLexicalSubscription.dev.js +3 -1
- package/DEPRECATED_useLexical.d.ts +0 -18
- package/DEPRECATED_useLexical.dev.js +0 -104
- package/DEPRECATED_useLexical.js.flow +0 -25
- package/DEPRECATED_useLexical.prod.js +0 -8
- package/DEPRECATED_useLexicalCanShowPlaceholder.d.ts +0 -9
- package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +0 -72
- package/DEPRECATED_useLexicalCanShowPlaceholder.js +0 -9
- package/DEPRECATED_useLexicalCanShowPlaceholder.js.flow +0 -15
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +0 -8
- package/DEPRECATED_useLexicalCharacterLimit.d.ts +0 -8
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +0 -213
- package/DEPRECATED_useLexicalCharacterLimit.js +0 -9
- package/DEPRECATED_useLexicalCharacterLimit.js.flow +0 -31
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +0 -13
- package/DEPRECATED_useLexicalEditor.d.ts +0 -9
- package/DEPRECATED_useLexicalEditor.dev.js +0 -87
- package/DEPRECATED_useLexicalEditor.js +0 -9
- package/DEPRECATED_useLexicalEditor.prod.js +0 -8
- package/DEPRECATED_useLexicalHistory.d.ts +0 -12
- package/DEPRECATED_useLexicalHistory.dev.js +0 -38
- package/DEPRECATED_useLexicalHistory.js +0 -9
- package/DEPRECATED_useLexicalHistory.js.flow +0 -34
- package/DEPRECATED_useLexicalHistory.prod.js +0 -7
- package/DEPRECATED_useLexicalPlainText.d.ts +0 -10
- package/DEPRECATED_useLexicalPlainText.dev.js +0 -88
- package/DEPRECATED_useLexicalPlainText.js +0 -9
- package/DEPRECATED_useLexicalPlainText.js.flow +0 -17
- package/DEPRECATED_useLexicalPlainText.prod.js +0 -8
- package/DEPRECATED_useLexicalRichText.d.ts +0 -10
- package/DEPRECATED_useLexicalRichText.dev.js +0 -88
- package/DEPRECATED_useLexicalRichText.js +0 -9
- package/DEPRECATED_useLexicalRichText.js.flow +0 -17
- package/DEPRECATED_useLexicalRichText.prod.js +0 -8
- package/LexicalTableOfContents__EXPERIMENTAL.js +0 -9
- /package/{LexicalTableOfContents__EXPERIMENTAL.js.flow → LexicalTableOfContents.js.flow} +0 -0
- /package/{LexicalTableOfContents__EXPERIMENTAL.prod.js → LexicalTableOfContents.prod.js} +0 -0
|
@@ -22,7 +22,6 @@ var richText = require('@lexical/rich-text');
|
|
|
22
22
|
* LICENSE file in the root directory of this source tree.
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
25
|
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
27
26
|
|
|
28
27
|
/**
|
|
@@ -42,10 +41,12 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
42
41
|
* LICENSE file in the root directory of this source tree.
|
|
43
42
|
*
|
|
44
43
|
*/
|
|
44
|
+
|
|
45
45
|
function canShowPlaceholderFromCurrentEditorState(editor) {
|
|
46
46
|
const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
|
|
47
47
|
return currentCanShowPlaceholder;
|
|
48
48
|
}
|
|
49
|
+
|
|
49
50
|
function useCanShowPlaceholder(editor) {
|
|
50
51
|
const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
|
|
51
52
|
useLayoutEffect(() => {
|
|
@@ -53,6 +54,7 @@ function useCanShowPlaceholder(editor) {
|
|
|
53
54
|
const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
|
|
54
55
|
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
55
56
|
}
|
|
57
|
+
|
|
56
58
|
resetCanShowPlaceholder();
|
|
57
59
|
return utils.mergeRegister(editor.registerUpdateListener(() => {
|
|
58
60
|
resetCanShowPlaceholder();
|
|
@@ -71,9 +73,8 @@ function useCanShowPlaceholder(editor) {
|
|
|
71
73
|
*
|
|
72
74
|
*/
|
|
73
75
|
function useDecorators(editor, ErrorBoundary) {
|
|
74
|
-
const [decorators, setDecorators] = React.useState(() => editor.getDecorators());
|
|
76
|
+
const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
|
|
75
77
|
|
|
76
|
-
// Subscribe to changes
|
|
77
78
|
useLayoutEffect(() => {
|
|
78
79
|
return editor.registerDecoratorListener(nextDecorators => {
|
|
79
80
|
reactDom.flushSync(() => {
|
|
@@ -86,12 +87,12 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
86
87
|
// nothing will be rendered on initial pass. We can get around that by
|
|
87
88
|
// ensuring that we set the value.
|
|
88
89
|
setDecorators(editor.getDecorators());
|
|
89
|
-
}, [editor]);
|
|
90
|
+
}, [editor]); // Return decorators defined as React Portals
|
|
90
91
|
|
|
91
|
-
// Return decorators defined as React Portals
|
|
92
92
|
return React.useMemo(() => {
|
|
93
93
|
const decoratedPortals = [];
|
|
94
94
|
const decoratorKeys = Object.keys(decorators);
|
|
95
|
+
|
|
95
96
|
for (let i = 0; i < decoratorKeys.length; i++) {
|
|
96
97
|
const nodeKey = decoratorKeys[i];
|
|
97
98
|
const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
@@ -100,10 +101,12 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
100
101
|
fallback: null
|
|
101
102
|
}, decorators[nodeKey]));
|
|
102
103
|
const element = editor.getElementByKey(nodeKey);
|
|
104
|
+
|
|
103
105
|
if (element !== null) {
|
|
104
106
|
decoratedPortals.push( /*#__PURE__*/reactDom.createPortal(reactDecorator, element));
|
|
105
107
|
}
|
|
106
108
|
}
|
|
109
|
+
|
|
107
110
|
return decoratedPortals;
|
|
108
111
|
}, [ErrorBoundary, decorators, editor]);
|
|
109
112
|
}
|
|
@@ -117,9 +120,7 @@ function useDecorators(editor, ErrorBoundary) {
|
|
|
117
120
|
*/
|
|
118
121
|
function useRichTextSetup(editor) {
|
|
119
122
|
useLayoutEffect(() => {
|
|
120
|
-
return utils.mergeRegister(richText.registerRichText(editor), dragon.registerDragonSupport(editor));
|
|
121
|
-
|
|
122
|
-
// We only do this for init
|
|
123
|
+
return utils.mergeRegister(richText.registerRichText(editor), dragon.registerDragonSupport(editor)); // We only do this for init
|
|
123
124
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
124
125
|
}, [editor]);
|
|
125
126
|
}
|
|
@@ -143,15 +144,18 @@ function RichTextPlugin({
|
|
|
143
144
|
content: placeholder
|
|
144
145
|
}), decorators);
|
|
145
146
|
}
|
|
147
|
+
|
|
146
148
|
function Placeholder({
|
|
147
149
|
content
|
|
148
150
|
}) {
|
|
149
151
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
150
152
|
const showPlaceholder = useCanShowPlaceholder(editor);
|
|
151
153
|
const editable = useLexicalEditable();
|
|
154
|
+
|
|
152
155
|
if (!showPlaceholder) {
|
|
153
156
|
return null;
|
|
154
157
|
}
|
|
158
|
+
|
|
155
159
|
if (typeof content === 'function') {
|
|
156
160
|
return content(editable);
|
|
157
161
|
} else {
|
|
@@ -17,20 +17,22 @@ var react = require('react');
|
|
|
17
17
|
* LICENSE file in the root directory of this source tree.
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
20
|
/**
|
|
22
21
|
* This plugin adds the ability to indent content using the tab key. Generally, we don't
|
|
23
22
|
* recommend using this plugin as it could negatively affect acessibility for keyboard
|
|
24
23
|
* users, causing focus to become trapped within the editor.
|
|
25
24
|
*/
|
|
25
|
+
|
|
26
26
|
function TabIndentationPlugin() {
|
|
27
27
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
28
28
|
react.useEffect(() => {
|
|
29
29
|
return editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
|
|
30
30
|
const selection = lexical.$getSelection();
|
|
31
|
+
|
|
31
32
|
if (!lexical.$isRangeSelection(selection)) {
|
|
32
33
|
return false;
|
|
33
34
|
}
|
|
35
|
+
|
|
34
36
|
event.preventDefault();
|
|
35
37
|
return editor.dispatchCommand(event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND, undefined);
|
|
36
38
|
}, lexical.COMMAND_PRIORITY_EDITOR);
|
|
@@ -18,39 +18,50 @@ var react = require('react');
|
|
|
18
18
|
* LICENSE file in the root directory of this source tree.
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
+
|
|
21
22
|
function toEntry(heading) {
|
|
22
23
|
return [heading.getKey(), heading.getTextContent(), heading.getTag()];
|
|
23
24
|
}
|
|
25
|
+
|
|
24
26
|
function $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents) {
|
|
25
27
|
if (newHeading === null) {
|
|
26
28
|
return currentTableOfContents;
|
|
27
29
|
}
|
|
30
|
+
|
|
28
31
|
const newEntry = toEntry(newHeading);
|
|
29
32
|
let newTableOfContents = [];
|
|
33
|
+
|
|
30
34
|
if (prevHeading === null) {
|
|
31
35
|
newTableOfContents = [newEntry, ...currentTableOfContents];
|
|
32
36
|
} else {
|
|
33
37
|
for (let i = 0; i < currentTableOfContents.length; i++) {
|
|
34
38
|
const key = currentTableOfContents[i][0];
|
|
35
39
|
newTableOfContents.push(currentTableOfContents[i]);
|
|
40
|
+
|
|
36
41
|
if (key === prevHeading.getKey() && key !== newHeading.getKey()) {
|
|
37
42
|
newTableOfContents.push(newEntry);
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
}
|
|
46
|
+
|
|
41
47
|
return newTableOfContents;
|
|
42
48
|
}
|
|
49
|
+
|
|
43
50
|
function $deleteHeadingFromTableOfContents(key, currentTableOfContents) {
|
|
44
51
|
const newTableOfContents = [];
|
|
52
|
+
|
|
45
53
|
for (const heading of currentTableOfContents) {
|
|
46
54
|
if (heading[0] !== key) {
|
|
47
55
|
newTableOfContents.push(heading);
|
|
48
56
|
}
|
|
49
57
|
}
|
|
58
|
+
|
|
50
59
|
return newTableOfContents;
|
|
51
60
|
}
|
|
61
|
+
|
|
52
62
|
function $updateHeadingInTableOfContents(heading, currentTableOfContents) {
|
|
53
63
|
const newTableOfContents = [];
|
|
64
|
+
|
|
54
65
|
for (const oldHeading of currentTableOfContents) {
|
|
55
66
|
if (oldHeading[0] === heading.getKey()) {
|
|
56
67
|
newTableOfContents.push(toEntry(heading));
|
|
@@ -58,30 +69,38 @@ function $updateHeadingInTableOfContents(heading, currentTableOfContents) {
|
|
|
58
69
|
newTableOfContents.push(oldHeading);
|
|
59
70
|
}
|
|
60
71
|
}
|
|
72
|
+
|
|
61
73
|
return newTableOfContents;
|
|
62
74
|
}
|
|
63
|
-
|
|
64
75
|
/**
|
|
65
76
|
* Returns the updated table of contents, placing the given `heading` before the given `prevHeading`. If `prevHeading`
|
|
66
77
|
* is undefined, `heading` is placed at the start of table of contents
|
|
67
78
|
*/
|
|
79
|
+
|
|
80
|
+
|
|
68
81
|
function $updateHeadingPosition(prevHeading, heading, currentTableOfContents) {
|
|
69
82
|
const newTableOfContents = [];
|
|
70
83
|
const newEntry = toEntry(heading);
|
|
84
|
+
|
|
71
85
|
if (!prevHeading) {
|
|
72
86
|
newTableOfContents.push(newEntry);
|
|
73
87
|
}
|
|
88
|
+
|
|
74
89
|
for (const oldHeading of currentTableOfContents) {
|
|
75
90
|
if (oldHeading[0] === heading.getKey()) {
|
|
76
91
|
continue;
|
|
77
92
|
}
|
|
93
|
+
|
|
78
94
|
newTableOfContents.push(oldHeading);
|
|
95
|
+
|
|
79
96
|
if (prevHeading && oldHeading[0] === prevHeading.getKey()) {
|
|
80
97
|
newTableOfContents.push(newEntry);
|
|
81
98
|
}
|
|
82
99
|
}
|
|
100
|
+
|
|
83
101
|
return newTableOfContents;
|
|
84
102
|
}
|
|
103
|
+
|
|
85
104
|
function LexicalTableOfContentsPlugin({
|
|
86
105
|
children
|
|
87
106
|
}) {
|
|
@@ -93,52 +112,61 @@ function LexicalTableOfContentsPlugin({
|
|
|
93
112
|
editor.getEditorState().read(() => {
|
|
94
113
|
const root = lexical.$getRoot();
|
|
95
114
|
const rootChildren = root.getChildren();
|
|
115
|
+
|
|
96
116
|
for (const child of rootChildren) {
|
|
97
117
|
if (richText.$isHeadingNode(child)) {
|
|
98
118
|
currentTableOfContents.push([child.getKey(), child.getTextContent(), child.getTag()]);
|
|
99
119
|
}
|
|
100
120
|
}
|
|
121
|
+
|
|
101
122
|
setTableOfContents(currentTableOfContents);
|
|
102
|
-
});
|
|
123
|
+
}); // Listen to updates to heading mutations and update state
|
|
103
124
|
|
|
104
|
-
// Listen to updates to heading mutations and update state
|
|
105
125
|
const removeHeaderMutationListener = editor.registerMutationListener(richText.HeadingNode, mutatedNodes => {
|
|
106
126
|
editor.getEditorState().read(() => {
|
|
107
127
|
for (const [nodeKey, mutation] of mutatedNodes) {
|
|
108
128
|
if (mutation === 'created') {
|
|
109
129
|
const newHeading = lexical.$getNodeByKey(nodeKey);
|
|
130
|
+
|
|
110
131
|
if (newHeading !== null) {
|
|
111
132
|
let prevHeading = newHeading.getPreviousSibling();
|
|
133
|
+
|
|
112
134
|
while (prevHeading !== null && !richText.$isHeadingNode(prevHeading)) {
|
|
113
135
|
prevHeading = prevHeading.getPreviousSibling();
|
|
114
136
|
}
|
|
137
|
+
|
|
115
138
|
currentTableOfContents = $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents);
|
|
116
139
|
}
|
|
117
140
|
} else if (mutation === 'destroyed') {
|
|
118
141
|
currentTableOfContents = $deleteHeadingFromTableOfContents(nodeKey, currentTableOfContents);
|
|
119
142
|
} else if (mutation === 'updated') {
|
|
120
143
|
const newHeading = lexical.$getNodeByKey(nodeKey);
|
|
144
|
+
|
|
121
145
|
if (newHeading !== null) {
|
|
122
146
|
let prevHeading = newHeading.getPreviousSibling();
|
|
147
|
+
|
|
123
148
|
while (prevHeading !== null && !richText.$isHeadingNode(prevHeading)) {
|
|
124
149
|
prevHeading = prevHeading.getPreviousSibling();
|
|
125
150
|
}
|
|
151
|
+
|
|
126
152
|
currentTableOfContents = $updateHeadingPosition(prevHeading, newHeading, currentTableOfContents);
|
|
127
153
|
}
|
|
128
154
|
}
|
|
129
155
|
}
|
|
156
|
+
|
|
130
157
|
setTableOfContents(currentTableOfContents);
|
|
131
158
|
});
|
|
132
|
-
});
|
|
159
|
+
}); // Listen to text node mutation updates
|
|
133
160
|
|
|
134
|
-
// Listen to text node mutation updates
|
|
135
161
|
const removeTextNodeMutationListener = editor.registerMutationListener(lexical.TextNode, mutatedNodes => {
|
|
136
162
|
editor.getEditorState().read(() => {
|
|
137
163
|
for (const [nodeKey, mutation] of mutatedNodes) {
|
|
138
164
|
if (mutation === 'updated') {
|
|
139
165
|
const currNode = lexical.$getNodeByKey(nodeKey);
|
|
166
|
+
|
|
140
167
|
if (currNode !== null) {
|
|
141
168
|
const parentNode = currNode.getParentOrThrow();
|
|
169
|
+
|
|
142
170
|
if (richText.$isHeadingNode(parentNode)) {
|
|
143
171
|
currentTableOfContents = $updateHeadingInTableOfContents(parentNode, currentTableOfContents);
|
|
144
172
|
setTableOfContents(currentTableOfContents);
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const
|
|
9
|
-
module.exports =
|
|
8
|
+
const LexicalTableOfContents = process.env.NODE_ENV === 'development' ? require('./LexicalTableOfContents.dev.js') : require('./LexicalTableOfContents.prod.js')
|
|
9
|
+
module.exports = LexicalTableOfContents;
|
package/LexicalTablePlugin.d.ts
CHANGED
|
@@ -26,53 +26,65 @@ function TablePlugin() {
|
|
|
26
26
|
throw Error(`TablePlugin: TableNode, TableCellNode or TableRowNode not registered on editor`);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
|
|
29
30
|
return editor.registerCommand(table.INSERT_TABLE_COMMAND, ({
|
|
30
31
|
columns,
|
|
31
32
|
rows,
|
|
32
33
|
includeHeaders
|
|
33
34
|
}) => {
|
|
34
35
|
const selection = lexical.$getSelection();
|
|
36
|
+
|
|
35
37
|
if (!lexical.$isRangeSelection(selection)) {
|
|
36
38
|
return true;
|
|
37
39
|
}
|
|
40
|
+
|
|
38
41
|
const focus = selection.focus;
|
|
39
42
|
const focusNode = focus.getNode();
|
|
43
|
+
|
|
40
44
|
if (focusNode !== null) {
|
|
41
45
|
const tableNode = table.$createTableNodeWithDimensions(Number(rows), Number(columns), includeHeaders);
|
|
46
|
+
|
|
42
47
|
if (lexical.$isRootOrShadowRoot(focusNode)) {
|
|
43
48
|
const target = focusNode.getChildAtIndex(focus.offset);
|
|
49
|
+
|
|
44
50
|
if (target !== null) {
|
|
45
51
|
target.insertBefore(tableNode);
|
|
46
52
|
} else {
|
|
47
53
|
focusNode.append(tableNode);
|
|
48
54
|
}
|
|
55
|
+
|
|
49
56
|
tableNode.insertBefore(lexical.$createParagraphNode());
|
|
50
57
|
} else {
|
|
51
58
|
const topLevelNode = focusNode.getTopLevelElementOrThrow();
|
|
52
59
|
topLevelNode.insertAfter(tableNode);
|
|
53
60
|
}
|
|
61
|
+
|
|
54
62
|
tableNode.insertAfter(lexical.$createParagraphNode());
|
|
55
63
|
const firstCell = tableNode.getFirstChildOrThrow().getFirstChildOrThrow();
|
|
56
64
|
firstCell.select();
|
|
57
65
|
}
|
|
66
|
+
|
|
58
67
|
return true;
|
|
59
68
|
}, lexical.COMMAND_PRIORITY_EDITOR);
|
|
60
69
|
}, [editor]);
|
|
61
70
|
react.useEffect(() => {
|
|
62
71
|
const tableSelections = new Map();
|
|
72
|
+
|
|
63
73
|
const initializeTableNode = tableNode => {
|
|
64
74
|
const nodeKey = tableNode.getKey();
|
|
65
75
|
const tableElement = editor.getElementByKey(nodeKey);
|
|
76
|
+
|
|
66
77
|
if (tableElement && !tableSelections.has(nodeKey)) {
|
|
67
78
|
const tableSelection = table.applyTableHandlers(tableNode, tableElement, editor);
|
|
68
79
|
tableSelections.set(nodeKey, tableSelection);
|
|
69
80
|
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// Plugins might be loaded _after_ initial content is set, hence existing table nodes
|
|
81
|
+
}; // Plugins might be loaded _after_ initial content is set, hence existing table nodes
|
|
73
82
|
// won't be initialized from mutation[create] listener. Instead doing it here,
|
|
83
|
+
|
|
84
|
+
|
|
74
85
|
editor.getEditorState().read(() => {
|
|
75
86
|
const tableNodes = lexical.$nodesOfType(table.TableNode);
|
|
87
|
+
|
|
76
88
|
for (const tableNode of tableNodes) {
|
|
77
89
|
if (table.$isTableNode(tableNode)) {
|
|
78
90
|
initializeTableNode(tableNode);
|
|
@@ -84,12 +96,14 @@ function TablePlugin() {
|
|
|
84
96
|
if (mutation === 'created') {
|
|
85
97
|
editor.getEditorState().read(() => {
|
|
86
98
|
const tableNode = lexical.$getNodeByKey(nodeKey);
|
|
99
|
+
|
|
87
100
|
if (table.$isTableNode(tableNode)) {
|
|
88
101
|
initializeTableNode(tableNode);
|
|
89
102
|
}
|
|
90
103
|
});
|
|
91
104
|
} else if (mutation === 'destroyed') {
|
|
92
105
|
const tableSelection = tableSelections.get(nodeKey);
|
|
106
|
+
|
|
93
107
|
if (tableSelection !== undefined) {
|
|
94
108
|
tableSelection.removeListeners();
|
|
95
109
|
tableSelections.delete(nodeKey);
|
|
@@ -98,9 +112,9 @@ function TablePlugin() {
|
|
|
98
112
|
}
|
|
99
113
|
});
|
|
100
114
|
return () => {
|
|
101
|
-
unregisterMutationListener();
|
|
102
|
-
// Hook might be called multiple times so cleaning up tables listeners as well,
|
|
115
|
+
unregisterMutationListener(); // Hook might be called multiple times so cleaning up tables listeners as well,
|
|
103
116
|
// as it'll be reinitialized during recurring call
|
|
117
|
+
|
|
104
118
|
for (const [, tableSelection] of tableSelections) {
|
|
105
119
|
tableSelection.removeListeners();
|
|
106
120
|
}
|
package/LexicalTreeView.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
+
/// <reference types="react" />
|
|
8
9
|
import type { LexicalEditor } from 'lexical';
|
|
9
10
|
export declare function TreeView({ timeTravelButtonClassName, timeTravelPanelSliderClassName, timeTravelPanelButtonClassName, viewClassName, timeTravelPanelClassName, editor, }: {
|
|
10
11
|
editor: LexicalEditor;
|