@mdxeditor/editor 4.2.1 → 4.2.2
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.
|
@@ -3,10 +3,11 @@ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
|
|
|
3
3
|
import { LexicalExtensionEditorComposer } from "@lexical/react/LexicalExtensionEditorComposer";
|
|
4
4
|
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
5
5
|
import * as RadixPopover from "@radix-ui/react-popover";
|
|
6
|
-
import { $createParagraphNode, $getRoot, KEY_TAB_COMMAND, COMMAND_PRIORITY_CRITICAL, FOCUS_COMMAND, COMMAND_PRIORITY_LOW, KEY_ENTER_COMMAND, BLUR_COMMAND, COMMAND_PRIORITY_EDITOR } from "lexical";
|
|
6
|
+
import { $createParagraphNode, $getNodeByKey, $getRoot, KEY_TAB_COMMAND, COMMAND_PRIORITY_CRITICAL, FOCUS_COMMAND, COMMAND_PRIORITY_LOW, KEY_ENTER_COMMAND, BLUR_COMMAND, COMMAND_PRIORITY_EDITOR } from "lexical";
|
|
7
7
|
import React__default from "react";
|
|
8
8
|
import { exportLexicalTreeToMdast } from "../../exportMarkdownFromLexical.js";
|
|
9
9
|
import { importMdastTreeToLexical } from "../../importMarkdownToLexical.js";
|
|
10
|
+
import { $isTableNode } from "./TableNode.js";
|
|
10
11
|
import { mergeRegister } from "@lexical/utils";
|
|
11
12
|
import * as RadixToolbar from "@radix-ui/react-toolbar";
|
|
12
13
|
import classNames from "classnames";
|
|
@@ -27,7 +28,12 @@ const AlignToTailwindClassMap = {
|
|
|
27
28
|
left: styles.leftAlignedCell,
|
|
28
29
|
right: styles.rightAlignedCell
|
|
29
30
|
};
|
|
31
|
+
function $getTableNodeByKey(key) {
|
|
32
|
+
const node = $getNodeByKey(key);
|
|
33
|
+
return $isTableNode(node) ? node : null;
|
|
34
|
+
}
|
|
30
35
|
const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
36
|
+
const tableKey = lexicalTable.getKey();
|
|
31
37
|
const [activeCell, setActiveCell] = React__default.useState(null);
|
|
32
38
|
const [iconComponentFor, readOnly] = useCellValues(iconComponentFor$, readOnly$);
|
|
33
39
|
const getCellKey = React__default.useMemo(() => {
|
|
@@ -55,12 +61,16 @@ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
|
55
61
|
if (rowIndex > lexicalTable.getRowCount() - 1) {
|
|
56
62
|
setActiveCell(null);
|
|
57
63
|
parentEditor.update(() => {
|
|
58
|
-
const
|
|
64
|
+
const currentTable = $getTableNodeByKey(tableKey);
|
|
65
|
+
if (!currentTable) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const nextSibling = currentTable.getNextSibling();
|
|
59
69
|
if (nextSibling) {
|
|
60
|
-
|
|
70
|
+
currentTable.selectNext();
|
|
61
71
|
} else {
|
|
62
72
|
const newParagraph = $createParagraphNode();
|
|
63
|
-
|
|
73
|
+
currentTable.insertAfter(newParagraph);
|
|
64
74
|
newParagraph.select();
|
|
65
75
|
}
|
|
66
76
|
});
|
|
@@ -69,13 +79,14 @@ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
|
69
79
|
if (rowIndex < 0) {
|
|
70
80
|
setActiveCell(null);
|
|
71
81
|
parentEditor.update(() => {
|
|
72
|
-
|
|
82
|
+
var _a;
|
|
83
|
+
(_a = $getTableNodeByKey(tableKey)) == null ? void 0 : _a.selectPrevious();
|
|
73
84
|
});
|
|
74
85
|
return;
|
|
75
86
|
}
|
|
76
87
|
setActiveCell([colIndex, rowIndex]);
|
|
77
88
|
},
|
|
78
|
-
[lexicalTable, parentEditor]
|
|
89
|
+
[lexicalTable, parentEditor, tableKey]
|
|
79
90
|
);
|
|
80
91
|
React__default.useEffect(() => {
|
|
81
92
|
lexicalTable.focusEmitter.subscribe(setActiveCellWithBoundaries);
|
|
@@ -84,21 +95,29 @@ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
|
84
95
|
(e) => {
|
|
85
96
|
e.preventDefault();
|
|
86
97
|
parentEditor.update(() => {
|
|
87
|
-
|
|
88
|
-
|
|
98
|
+
const currentTable = $getTableNodeByKey(tableKey);
|
|
99
|
+
if (!currentTable) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
currentTable.addRowToBottom();
|
|
103
|
+
setActiveCell([0, currentTable.getRowCount()]);
|
|
89
104
|
});
|
|
90
105
|
},
|
|
91
|
-
[parentEditor,
|
|
106
|
+
[parentEditor, tableKey]
|
|
92
107
|
);
|
|
93
108
|
const addColumnToRight = React__default.useCallback(
|
|
94
109
|
(e) => {
|
|
95
110
|
e.preventDefault();
|
|
96
111
|
parentEditor.update(() => {
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
const currentTable = $getTableNodeByKey(tableKey);
|
|
113
|
+
if (!currentTable) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
currentTable.addColumnToRight();
|
|
117
|
+
setActiveCell([currentTable.getColCount(), 0]);
|
|
99
118
|
});
|
|
100
119
|
},
|
|
101
|
-
[parentEditor,
|
|
120
|
+
[parentEditor, tableKey]
|
|
102
121
|
);
|
|
103
122
|
const [highlightedCoordinates, setHighlightedCoordinates] = React__default.useState([-1, -1]);
|
|
104
123
|
const onTableMouseOver = React__default.useCallback((e) => {
|
|
@@ -157,8 +176,12 @@ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
|
157
176
|
onClick: (e) => {
|
|
158
177
|
e.preventDefault();
|
|
159
178
|
parentEditor.update(() => {
|
|
160
|
-
|
|
161
|
-
|
|
179
|
+
const currentTable = $getTableNodeByKey(tableKey);
|
|
180
|
+
if (!currentTable) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
currentTable.selectNext();
|
|
184
|
+
currentTable.remove();
|
|
162
185
|
});
|
|
163
186
|
}
|
|
164
187
|
},
|
|
@@ -207,6 +230,7 @@ const Cell = ({ align, ...props }) => {
|
|
|
207
230
|
);
|
|
208
231
|
};
|
|
209
232
|
const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents, colIndex, rowIndex }) => {
|
|
233
|
+
const tableKey = lexicalTable.getKey();
|
|
210
234
|
const [
|
|
211
235
|
importVisitors,
|
|
212
236
|
exportVisitors,
|
|
@@ -269,7 +293,11 @@ const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents
|
|
|
269
293
|
});
|
|
270
294
|
parentEditor.update(
|
|
271
295
|
() => {
|
|
272
|
-
|
|
296
|
+
const currentTable = $getTableNodeByKey(tableKey);
|
|
297
|
+
if (!currentTable) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
currentTable.updateCellContents(colIndex, rowIndex, mdast.children[0].children);
|
|
273
301
|
},
|
|
274
302
|
{ discrete: true }
|
|
275
303
|
);
|
|
@@ -277,7 +305,7 @@ const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents
|
|
|
277
305
|
});
|
|
278
306
|
setActiveCell(nextCell);
|
|
279
307
|
},
|
|
280
|
-
[colIndex, editor, exportVisitors, jsxComponentDescriptors, jsxIsAvailable,
|
|
308
|
+
[colIndex, editor, exportVisitors, jsxComponentDescriptors, jsxIsAvailable, parentEditor, rowIndex, setActiveCell, tableKey]
|
|
281
309
|
);
|
|
282
310
|
React__default.useEffect(() => {
|
|
283
311
|
if (!editor) {
|
|
@@ -352,31 +380,38 @@ const ColumnEditor = ({
|
|
|
352
380
|
colIndex,
|
|
353
381
|
setActiveCellWithBoundaries
|
|
354
382
|
}) => {
|
|
383
|
+
const tableKey = lexicalTable.getKey();
|
|
355
384
|
const [editorRootElementRef, iconComponentFor] = useCellValues(editorRootElementRef$, iconComponentFor$);
|
|
356
385
|
const insertColumnAt = React__default.useCallback(
|
|
357
386
|
(colIndex2) => {
|
|
358
387
|
parentEditor.update(() => {
|
|
359
|
-
|
|
388
|
+
const currentTable = $getTableNodeByKey(tableKey);
|
|
389
|
+
if (!currentTable) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
currentTable.insertColumnAt(colIndex2);
|
|
393
|
+
setActiveCellWithBoundaries([colIndex2, 0]);
|
|
360
394
|
});
|
|
361
|
-
setActiveCellWithBoundaries([colIndex2, 0]);
|
|
362
395
|
},
|
|
363
|
-
[parentEditor,
|
|
396
|
+
[parentEditor, setActiveCellWithBoundaries, tableKey]
|
|
364
397
|
);
|
|
365
398
|
const deleteColumnAt = React__default.useCallback(
|
|
366
399
|
(colIndex2) => {
|
|
367
400
|
parentEditor.update(() => {
|
|
368
|
-
|
|
401
|
+
var _a;
|
|
402
|
+
(_a = $getTableNodeByKey(tableKey)) == null ? void 0 : _a.deleteColumnAt(colIndex2);
|
|
369
403
|
});
|
|
370
404
|
},
|
|
371
|
-
[parentEditor,
|
|
405
|
+
[parentEditor, tableKey]
|
|
372
406
|
);
|
|
373
407
|
const setColumnAlign = React__default.useCallback(
|
|
374
408
|
(colIndex2, align2) => {
|
|
375
409
|
parentEditor.update(() => {
|
|
376
|
-
|
|
410
|
+
var _a;
|
|
411
|
+
(_a = $getTableNodeByKey(tableKey)) == null ? void 0 : _a.setColumnAlign(colIndex2, align2);
|
|
377
412
|
});
|
|
378
413
|
},
|
|
379
|
-
[parentEditor,
|
|
414
|
+
[parentEditor, tableKey]
|
|
380
415
|
);
|
|
381
416
|
const t = useTranslation();
|
|
382
417
|
return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, null, /* @__PURE__ */ React__default.createElement(
|
|
@@ -436,23 +471,29 @@ const RowEditor = ({
|
|
|
436
471
|
rowIndex,
|
|
437
472
|
setActiveCellWithBoundaries
|
|
438
473
|
}) => {
|
|
474
|
+
const tableKey = lexicalTable.getKey();
|
|
439
475
|
const [editorRootElementRef, iconComponentFor] = useCellValues(editorRootElementRef$, iconComponentFor$);
|
|
440
476
|
const insertRowAt = React__default.useCallback(
|
|
441
477
|
(rowIndex2) => {
|
|
442
478
|
parentEditor.update(() => {
|
|
443
|
-
|
|
479
|
+
const currentTable = $getTableNodeByKey(tableKey);
|
|
480
|
+
if (!currentTable) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
currentTable.insertRowAt(rowIndex2);
|
|
484
|
+
setActiveCellWithBoundaries([0, rowIndex2]);
|
|
444
485
|
});
|
|
445
|
-
setActiveCellWithBoundaries([0, rowIndex2]);
|
|
446
486
|
},
|
|
447
|
-
[parentEditor,
|
|
487
|
+
[parentEditor, setActiveCellWithBoundaries, tableKey]
|
|
448
488
|
);
|
|
449
489
|
const deleteRowAt = React__default.useCallback(
|
|
450
490
|
(rowIndex2) => {
|
|
451
491
|
parentEditor.update(() => {
|
|
452
|
-
|
|
492
|
+
var _a;
|
|
493
|
+
(_a = $getTableNodeByKey(tableKey)) == null ? void 0 : _a.deleteRowAt(rowIndex2);
|
|
453
494
|
});
|
|
454
495
|
},
|
|
455
|
-
[parentEditor,
|
|
496
|
+
[parentEditor, tableKey]
|
|
456
497
|
);
|
|
457
498
|
const t = useTranslation();
|
|
458
499
|
return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, null, /* @__PURE__ */ React__default.createElement(
|