@lobehub/editor 1.8.1 → 1.8.3
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/es/editor-kernel/react/PortalAnchor.d.ts +5 -0
- package/es/editor-kernel/react/PortalAnchor.js +13 -0
- package/es/editor-kernel/react/useAnchor.d.ts +1 -0
- package/es/editor-kernel/react/useAnchor.js +23 -0
- package/es/plugins/link/react/ReactLinkPlugin.js +8 -96
- package/es/plugins/link/react/components/LinkEdit.d.ts +6 -2
- package/es/plugins/link/react/components/LinkEdit.js +21 -25
- package/es/plugins/link/react/components/LinkToolbar.d.ts +1 -4
- package/es/plugins/link/react/components/LinkToolbar.js +103 -21
- package/es/plugins/math/react/{component → components}/MathEditor.js +11 -8
- package/es/plugins/math/react/{component → components}/MathEditorContainer.d.ts +2 -1
- package/es/plugins/math/react/{component → components}/MathEditorContainer.js +3 -2
- package/es/plugins/math/react/{component → components}/MathEditorContent.d.ts +2 -1
- package/es/plugins/math/react/{component → components}/MathEditorContent.js +3 -2
- package/es/plugins/math/react/index.js +2 -2
- package/es/plugins/slash/react/components/DefaultSlashMenu.d.ts +5 -0
- package/es/plugins/slash/react/components/DefaultSlashMenu.js +48 -0
- package/es/plugins/slash/react/components/SlashMenu.d.ts +2 -2
- package/es/plugins/slash/react/components/SlashMenu.js +16 -36
- package/es/plugins/table/react/TableActionMenu/ActionMenu.d.ts +18 -0
- package/es/plugins/table/react/TableActionMenu/ActionMenu.js +309 -0
- package/es/plugins/table/react/TableActionMenu/index.d.ts +2 -3
- package/es/plugins/table/react/TableActionMenu/index.js +17 -321
- package/es/plugins/table/react/TableHoverActions/index.d.ts +3 -4
- package/es/plugins/table/react/TableHoverActions/index.js +7 -20
- package/es/plugins/table/react/index.js +8 -5
- package/package.json +1 -1
- /package/es/plugins/math/react/{component → components}/MathEditor.d.ts +0 -0
- /package/es/plugins/math/react/{component → components}/MathInline.d.ts +0 -0
- /package/es/plugins/math/react/{component → components}/MathInline.js +0 -0
- /package/es/plugins/math/react/{component → components}/Placeholder.d.ts +0 -0
- /package/es/plugins/math/react/{component → components}/Placeholder.js +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
1
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
2
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
3
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -12,311 +11,25 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
12
11
|
* LICENSE file in the root directory of this source tree.
|
|
13
12
|
*
|
|
14
13
|
*/
|
|
15
|
-
import { $
|
|
14
|
+
import { $getTableCellNodeFromLexicalNode, $getTableNodeFromLexicalNodeOrThrow, $isTableCellNode, $isTableSelection, getTableElement, getTableObserverFromTableElement } from '@lexical/table';
|
|
16
15
|
import { mergeRegister } from '@lexical/utils';
|
|
17
|
-
import { ActionIcon
|
|
18
|
-
import { $getSelection, $isRangeSelection,
|
|
19
|
-
import { ChevronDown
|
|
20
|
-
import { memo, useCallback, useEffect,
|
|
21
|
-
import {
|
|
22
|
-
import
|
|
16
|
+
import { ActionIcon } from '@lobehub/ui';
|
|
17
|
+
import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_CRITICAL, SELECTION_CHANGE_COMMAND, getDOMSelection } from 'lexical';
|
|
18
|
+
import { ChevronDown } from 'lucide-react';
|
|
19
|
+
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
20
|
+
import { useAnchor } from "../../../../editor-kernel/react/useAnchor";
|
|
21
|
+
import ActionMenu from "./ActionMenu";
|
|
23
22
|
import { useStyles } from "./style";
|
|
24
|
-
import { $canUnmerge, $selectLastDescendant, computeSelectionCount, currentCellBackgroundColor } from "./utils";
|
|
25
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
26
24
|
var TableActionMenu = /*#__PURE__*/memo(function (_ref) {
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var _useState = useState(
|
|
25
|
+
var cellMerge = _ref.cellMerge,
|
|
26
|
+
editor = _ref.editor;
|
|
27
|
+
var anchorElem = useAnchor();
|
|
28
|
+
var menuButtonRef = useRef(null);
|
|
29
|
+
var _useState = useState(null),
|
|
32
30
|
_useState2 = _slicedToArray(_useState, 2),
|
|
33
31
|
tableCellNode = _useState2[0],
|
|
34
|
-
|
|
35
|
-
var _useState3 = useState({
|
|
36
|
-
columns: 1,
|
|
37
|
-
rows: 1
|
|
38
|
-
}),
|
|
39
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
40
|
-
selectionCounts = _useState4[0],
|
|
41
|
-
updateSelectionCounts = _useState4[1];
|
|
42
|
-
var _useState5 = useState(false),
|
|
43
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
44
|
-
canMergeCells = _useState6[0],
|
|
45
|
-
setCanMergeCells = _useState6[1];
|
|
46
|
-
var _useState7 = useState(false),
|
|
47
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
48
|
-
canUnmergeCell = _useState8[0],
|
|
49
|
-
setCanUnmergeCell = _useState8[1];
|
|
50
|
-
var _useState9 = useState(function () {
|
|
51
|
-
return currentCellBackgroundColor(editor) || '';
|
|
52
|
-
}),
|
|
53
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
54
|
-
setBackgroundColor = _useState10[1];
|
|
55
|
-
var t = useTranslation();
|
|
56
|
-
useEffect(function () {
|
|
57
|
-
return editor.registerMutationListener(TableCellNode, function (nodeMutations) {
|
|
58
|
-
var nodeUpdated = nodeMutations.get(tableCellNode.getKey()) === 'updated';
|
|
59
|
-
if (nodeUpdated) {
|
|
60
|
-
editor.getEditorState().read(function () {
|
|
61
|
-
updateTableCellNode(tableCellNode.getLatest());
|
|
62
|
-
});
|
|
63
|
-
setBackgroundColor(currentCellBackgroundColor(editor) || '');
|
|
64
|
-
}
|
|
65
|
-
}, {
|
|
66
|
-
skipInitialization: true
|
|
67
|
-
});
|
|
68
|
-
}, [editor, tableCellNode]);
|
|
69
|
-
useEffect(function () {
|
|
70
|
-
editor.getEditorState().read(function () {
|
|
71
|
-
var selection = $getSelection();
|
|
72
|
-
// Merge cells
|
|
73
|
-
if ($isTableSelection(selection)) {
|
|
74
|
-
var currentSelectionCounts = computeSelectionCount(selection);
|
|
75
|
-
updateSelectionCounts(computeSelectionCount(selection));
|
|
76
|
-
setCanMergeCells(currentSelectionCounts.columns > 1 || currentSelectionCounts.rows > 1);
|
|
77
|
-
}
|
|
78
|
-
// Unmerge cell
|
|
79
|
-
setCanUnmergeCell($canUnmerge());
|
|
80
|
-
});
|
|
81
|
-
}, [editor]);
|
|
82
|
-
var clearTableSelection = useCallback(function () {
|
|
83
|
-
editor.update(function () {
|
|
84
|
-
if (tableCellNode.isAttached()) {
|
|
85
|
-
var tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
|
|
86
|
-
var tableElement = getTableElement(tableNode, editor.getElementByKey(tableNode.getKey()));
|
|
87
|
-
if (tableElement === null) {
|
|
88
|
-
throw new Error('TableActionMenu: Expected to find tableElement in DOM');
|
|
89
|
-
}
|
|
90
|
-
var tableObserver = getTableObserverFromTableElement(tableElement);
|
|
91
|
-
if (tableObserver !== null) {
|
|
92
|
-
tableObserver.$clearHighlight();
|
|
93
|
-
}
|
|
94
|
-
tableNode.markDirty();
|
|
95
|
-
updateTableCellNode(tableCellNode.getLatest());
|
|
96
|
-
}
|
|
97
|
-
$setSelection(null);
|
|
98
|
-
});
|
|
99
|
-
}, [editor, tableCellNode]);
|
|
100
|
-
var mergeTableCellsAtSelection = function mergeTableCellsAtSelection() {
|
|
101
|
-
editor.update(function () {
|
|
102
|
-
var selection = $getSelection();
|
|
103
|
-
if (!$isTableSelection(selection)) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
var nodes = selection.getNodes();
|
|
107
|
-
var tableCells = nodes.filter($isTableCellNode);
|
|
108
|
-
var targetCell = $mergeCells(tableCells);
|
|
109
|
-
if (targetCell) {
|
|
110
|
-
$selectLastDescendant(targetCell);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
var unmergeTableCellsAtSelection = function unmergeTableCellsAtSelection() {
|
|
115
|
-
editor.update(function () {
|
|
116
|
-
$unmergeCell();
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
var insertTableRowAtSelection = useCallback(function (shouldInsertAfter) {
|
|
120
|
-
editor.update(function () {
|
|
121
|
-
for (var i = 0; i < selectionCounts.rows; i++) {
|
|
122
|
-
$insertTableRowAtSelection(shouldInsertAfter);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}, [editor, selectionCounts.rows]);
|
|
126
|
-
var insertTableColumnAtSelection = useCallback(function (shouldInsertAfter) {
|
|
127
|
-
editor.update(function () {
|
|
128
|
-
for (var i = 0; i < selectionCounts.columns; i++) {
|
|
129
|
-
$insertTableColumnAtSelection(shouldInsertAfter);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}, [editor, selectionCounts.columns]);
|
|
133
|
-
var deleteTableRowAtSelection = useCallback(function () {
|
|
134
|
-
editor.update(function () {
|
|
135
|
-
$deleteTableRowAtSelection();
|
|
136
|
-
});
|
|
137
|
-
}, [editor]);
|
|
138
|
-
var deleteTableAtSelection = useCallback(function () {
|
|
139
|
-
editor.update(function () {
|
|
140
|
-
var tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
|
|
141
|
-
tableNode.remove();
|
|
142
|
-
clearTableSelection();
|
|
143
|
-
});
|
|
144
|
-
}, [editor, tableCellNode, clearTableSelection]);
|
|
145
|
-
var deleteTableColumnAtSelection = useCallback(function () {
|
|
146
|
-
editor.update(function () {
|
|
147
|
-
$deleteTableColumnAtSelection();
|
|
148
|
-
});
|
|
149
|
-
}, [editor]);
|
|
150
|
-
var toggleTableRowIsHeader = useCallback(function () {
|
|
151
|
-
editor.update(function () {
|
|
152
|
-
var tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
|
|
153
|
-
var tableRowIndex = $getTableRowIndexFromTableCellNode(tableCellNode);
|
|
154
|
-
var _$computeTableMapSkip = $computeTableMapSkipCellCheck(tableNode, null, null),
|
|
155
|
-
_$computeTableMapSkip2 = _slicedToArray(_$computeTableMapSkip, 1),
|
|
156
|
-
gridMap = _$computeTableMapSkip2[0];
|
|
157
|
-
var rowCells = new Set();
|
|
158
|
-
var newStyle = tableCellNode.getHeaderStyles() ^ TableCellHeaderStates.ROW;
|
|
159
|
-
for (var col = 0; col < gridMap[tableRowIndex].length; col++) {
|
|
160
|
-
var mapCell = gridMap[tableRowIndex][col];
|
|
161
|
-
if (!(mapCell !== null && mapCell !== void 0 && mapCell.cell)) {
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (!rowCells.has(mapCell.cell)) {
|
|
165
|
-
rowCells.add(mapCell.cell);
|
|
166
|
-
mapCell.cell.setHeaderStyles(newStyle, TableCellHeaderStates.ROW);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
clearTableSelection();
|
|
170
|
-
});
|
|
171
|
-
}, [editor, tableCellNode, clearTableSelection]);
|
|
172
|
-
var toggleTableColumnIsHeader = useCallback(function () {
|
|
173
|
-
editor.update(function () {
|
|
174
|
-
var tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode);
|
|
175
|
-
var tableColumnIndex = $getTableColumnIndexFromTableCellNode(tableCellNode);
|
|
176
|
-
var _$computeTableMapSkip3 = $computeTableMapSkipCellCheck(tableNode, null, null),
|
|
177
|
-
_$computeTableMapSkip4 = _slicedToArray(_$computeTableMapSkip3, 1),
|
|
178
|
-
gridMap = _$computeTableMapSkip4[0];
|
|
179
|
-
var columnCells = new Set();
|
|
180
|
-
var newStyle = tableCellNode.getHeaderStyles() ^ TableCellHeaderStates.COLUMN;
|
|
181
|
-
var _iterator = _createForOfIteratorHelper(gridMap),
|
|
182
|
-
_step;
|
|
183
|
-
try {
|
|
184
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
185
|
-
var element = _step.value;
|
|
186
|
-
var mapCell = element[tableColumnIndex];
|
|
187
|
-
if (!(mapCell !== null && mapCell !== void 0 && mapCell.cell)) {
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
if (!columnCells.has(mapCell.cell)) {
|
|
191
|
-
columnCells.add(mapCell.cell);
|
|
192
|
-
mapCell.cell.setHeaderStyles(newStyle, TableCellHeaderStates.COLUMN);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
} catch (err) {
|
|
196
|
-
_iterator.e(err);
|
|
197
|
-
} finally {
|
|
198
|
-
_iterator.f();
|
|
199
|
-
}
|
|
200
|
-
clearTableSelection();
|
|
201
|
-
});
|
|
202
|
-
}, [editor, tableCellNode, clearTableSelection]);
|
|
203
|
-
|
|
204
|
-
// Create menu items array with useMemo for performance
|
|
205
|
-
var menuItems = useMemo(function () {
|
|
206
|
-
return [
|
|
207
|
-
// // Merge/Unmerge cells (conditional)
|
|
208
|
-
// ...(cellMerge && canMergeCells
|
|
209
|
-
// ? [
|
|
210
|
-
// {
|
|
211
|
-
// key: 'table-merge-cells',
|
|
212
|
-
// label: 'Merge cells',
|
|
213
|
-
// onClick: () => mergeTableCellsAtSelection(),
|
|
214
|
-
// },
|
|
215
|
-
// ]
|
|
216
|
-
// : []),
|
|
217
|
-
// ...(cellMerge && canUnmergeCell
|
|
218
|
-
// ? [
|
|
219
|
-
// {
|
|
220
|
-
// key: 'table-unmerge-cells',
|
|
221
|
-
// label: 'Unmerge cells',
|
|
222
|
-
// onClick: () => unmergeTableCellsAtSelection(),
|
|
223
|
-
// },
|
|
224
|
-
// ]
|
|
225
|
-
// : []),
|
|
226
|
-
// // Divider after merge operations (if any merge operations exist)
|
|
227
|
-
// ...(cellMerge && (canMergeCells || canUnmergeCell) ? [{ type: 'divider' as const }] : []),
|
|
228
|
-
//
|
|
229
|
-
// // Row operations
|
|
230
|
-
{
|
|
231
|
-
icon: PanelTopCloseIcon,
|
|
232
|
-
key: 'table-insert-row-above',
|
|
233
|
-
label: t("table.insertRowAbove", {
|
|
234
|
-
count: selectionCounts.rows
|
|
235
|
-
}),
|
|
236
|
-
onClick: function onClick() {
|
|
237
|
-
return insertTableRowAtSelection(false);
|
|
238
|
-
}
|
|
239
|
-
}, {
|
|
240
|
-
icon: PanelBottomCloseIcon,
|
|
241
|
-
key: 'table-insert-row-below',
|
|
242
|
-
label: t("table.insertRowBelow", {
|
|
243
|
-
count: selectionCounts.rows
|
|
244
|
-
}),
|
|
245
|
-
onClick: function onClick() {
|
|
246
|
-
return insertTableRowAtSelection(true);
|
|
247
|
-
}
|
|
248
|
-
}, {
|
|
249
|
-
type: 'divider'
|
|
250
|
-
},
|
|
251
|
-
// Column operations
|
|
252
|
-
{
|
|
253
|
-
icon: PanelLeftCloseIcon,
|
|
254
|
-
key: 'table-insert-column-before',
|
|
255
|
-
// label: `Insert ${selectionCounts.columns === 1 ? 'column' : `${selectionCounts.columns} columns`} left`,
|
|
256
|
-
label: t("table.insertColumnLeft", {
|
|
257
|
-
count: selectionCounts.columns
|
|
258
|
-
}),
|
|
259
|
-
onClick: function onClick() {
|
|
260
|
-
return insertTableColumnAtSelection(false);
|
|
261
|
-
}
|
|
262
|
-
}, {
|
|
263
|
-
icon: PanelRightCloseIcon,
|
|
264
|
-
key: 'table-insert-column-after',
|
|
265
|
-
// label: `Insert ${selectionCounts.columns === 1 ? 'column' : `${selectionCounts.columns} columns`} right`,
|
|
266
|
-
label: t("table.insertColumnRight", {
|
|
267
|
-
count: selectionCounts.columns
|
|
268
|
-
}),
|
|
269
|
-
onClick: function onClick() {
|
|
270
|
-
return insertTableColumnAtSelection(true);
|
|
271
|
-
}
|
|
272
|
-
}, {
|
|
273
|
-
type: 'divider'
|
|
274
|
-
},
|
|
275
|
-
// Delete operations
|
|
276
|
-
{
|
|
277
|
-
icon: TableColumnsSplitIcon,
|
|
278
|
-
key: 'table-delete-columns',
|
|
279
|
-
// label: 'Delete column',
|
|
280
|
-
label: t("table.deleteColumn"),
|
|
281
|
-
onClick: function onClick() {
|
|
282
|
-
return deleteTableColumnAtSelection();
|
|
283
|
-
}
|
|
284
|
-
}, {
|
|
285
|
-
icon: TableRowsSplitIcon,
|
|
286
|
-
key: 'table-delete-rows',
|
|
287
|
-
// label: 'Delete row',
|
|
288
|
-
label: t("table.deleteRow"),
|
|
289
|
-
onClick: function onClick() {
|
|
290
|
-
return deleteTableRowAtSelection();
|
|
291
|
-
}
|
|
292
|
-
}, {
|
|
293
|
-
type: 'divider'
|
|
294
|
-
}, {
|
|
295
|
-
icon: Grid2X2XIcon,
|
|
296
|
-
key: 'table-delete',
|
|
297
|
-
// label: 'Delete table',
|
|
298
|
-
label: t("table.delete"),
|
|
299
|
-
onClick: function onClick() {
|
|
300
|
-
return deleteTableAtSelection();
|
|
301
|
-
}
|
|
302
|
-
}];
|
|
303
|
-
}, [cellMerge, canMergeCells, canUnmergeCell, selectionCounts.rows, selectionCounts.columns, tableCellNode.__headerState, mergeTableCellsAtSelection, unmergeTableCellsAtSelection, insertTableRowAtSelection, insertTableColumnAtSelection, deleteTableColumnAtSelection, deleteTableRowAtSelection, deleteTableAtSelection, toggleTableRowIsHeader, toggleTableColumnIsHeader]);
|
|
304
|
-
return /*#__PURE__*/_jsx(Dropdown, {
|
|
305
|
-
menu: {
|
|
306
|
-
items: menuItems
|
|
307
|
-
},
|
|
308
|
-
children: children
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
function TableCellActionMenuContainer(_ref2) {
|
|
312
|
-
var anchorElem = _ref2.anchorElem,
|
|
313
|
-
cellMerge = _ref2.cellMerge,
|
|
314
|
-
editor = _ref2.editor;
|
|
315
|
-
var menuButtonRef = useRef(null);
|
|
316
|
-
var _useState11 = useState(null),
|
|
317
|
-
_useState12 = _slicedToArray(_useState11, 2),
|
|
318
|
-
tableCellNode = _useState12[0],
|
|
319
|
-
setTableMenuCellNode = _useState12[1];
|
|
32
|
+
setTableMenuCellNode = _useState2[1];
|
|
320
33
|
|
|
321
34
|
// const [colorPickerModal, showColorPickerModal] = useModal();
|
|
322
35
|
|
|
@@ -402,7 +115,7 @@ function TableCellActionMenuContainer(_ref2) {
|
|
|
402
115
|
var enabled = !tableObserver || !tableObserver.isSelecting;
|
|
403
116
|
menu.classList.toggle('table-cell-action-button-container--active', enabled);
|
|
404
117
|
menu.classList.toggle('table-cell-action-button-container--inactive', !enabled);
|
|
405
|
-
if (enabled) {
|
|
118
|
+
if (enabled && anchorElem) {
|
|
406
119
|
var tableCellRect = tableCellParentNodeDOM.getBoundingClientRect();
|
|
407
120
|
var anchorRect = anchorElem.getBoundingClientRect();
|
|
408
121
|
var top = tableCellRect.top - anchorRect.top;
|
|
@@ -445,7 +158,7 @@ function TableCellActionMenuContainer(_ref2) {
|
|
|
445
158
|
return /*#__PURE__*/_jsx("div", {
|
|
446
159
|
className: styles,
|
|
447
160
|
ref: menuButtonRef,
|
|
448
|
-
children: tableCellNode && /*#__PURE__*/_jsx(
|
|
161
|
+
children: tableCellNode && /*#__PURE__*/_jsx(ActionMenu, {
|
|
449
162
|
cellMerge: cellMerge,
|
|
450
163
|
editor: editor,
|
|
451
164
|
tableCellNode: tableCellNode,
|
|
@@ -462,22 +175,5 @@ function TableCellActionMenuContainer(_ref2) {
|
|
|
462
175
|
})
|
|
463
176
|
})
|
|
464
177
|
});
|
|
465
|
-
}
|
|
466
|
-
export default
|
|
467
|
-
var anchorElem = _ref3.anchorElem,
|
|
468
|
-
_ref3$cellMerge = _ref3.cellMerge,
|
|
469
|
-
cellMerge = _ref3$cellMerge === void 0 ? false : _ref3$cellMerge,
|
|
470
|
-
editor = _ref3.editor;
|
|
471
|
-
// Don't render portal on server side
|
|
472
|
-
if (typeof document === 'undefined') {
|
|
473
|
-
return null;
|
|
474
|
-
}
|
|
475
|
-
var root = editor.getRootElement();
|
|
476
|
-
var anchor = root ? root.parentElement : null;
|
|
477
|
-
var targetElement = anchorElem || anchor || document.body;
|
|
478
|
-
return /*#__PURE__*/createPortal( /*#__PURE__*/_jsx(TableCellActionMenuContainer, {
|
|
479
|
-
anchorElem: targetElement,
|
|
480
|
-
cellMerge: cellMerge,
|
|
481
|
-
editor: editor
|
|
482
|
-
}), targetElement);
|
|
483
|
-
});
|
|
178
|
+
});
|
|
179
|
+
export default TableActionMenu;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { LexicalEditor } from 'lexical';
|
|
3
|
-
declare const
|
|
4
|
-
anchorElem?: HTMLElement | undefined;
|
|
3
|
+
declare const TableHoverActions: import("react").NamedExoticComponent<{
|
|
5
4
|
editor: LexicalEditor;
|
|
6
|
-
}
|
|
7
|
-
export default
|
|
5
|
+
}>;
|
|
6
|
+
export default TableHoverActions;
|
|
@@ -17,15 +17,15 @@ import { ActionIcon } from '@lobehub/ui';
|
|
|
17
17
|
import { $getNearestNodeFromDOMNode } from 'lexical';
|
|
18
18
|
import { PlusIcon } from 'lucide-react';
|
|
19
19
|
import { memo, useEffect, useMemo, useRef, useState } from 'react';
|
|
20
|
-
import { createPortal } from 'react-dom';
|
|
21
20
|
import { useLexicalComposerContext } from "../../../../editor-kernel/react";
|
|
21
|
+
import { useAnchor } from "../../../../editor-kernel/react/useAnchor";
|
|
22
22
|
import { useStyles } from "./style";
|
|
23
23
|
import { getMouseInfo, useDebounce } from "./utils";
|
|
24
24
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
25
25
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
|
|
26
|
+
var TableHoverActions = /*#__PURE__*/memo(function (_ref) {
|
|
27
|
+
var editor = _ref.editor;
|
|
28
|
+
var anchorElem = useAnchor();
|
|
29
29
|
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
30
30
|
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
31
31
|
iEditor = _useLexicalComposerCo2[0];
|
|
@@ -92,7 +92,7 @@ var TableHoverActionsContainer = /*#__PURE__*/memo(function (_ref) {
|
|
|
92
92
|
}, {
|
|
93
93
|
editor: editor
|
|
94
94
|
});
|
|
95
|
-
if (tableDOMElement) {
|
|
95
|
+
if (tableDOMElement && anchorElem) {
|
|
96
96
|
var _getBoundingClientRec = tableDOMElement.getBoundingClientRect(),
|
|
97
97
|
tableElemY = _getBoundingClientRec.y,
|
|
98
98
|
tableElemRight = _getBoundingClientRec.right,
|
|
@@ -247,18 +247,5 @@ var TableHoverActionsContainer = /*#__PURE__*/memo(function (_ref) {
|
|
|
247
247
|
})]
|
|
248
248
|
});
|
|
249
249
|
});
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
editor = _ref2.editor;
|
|
253
|
-
// Don't render portal on server side
|
|
254
|
-
if (typeof document === 'undefined') {
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
var root = editor.getRootElement();
|
|
258
|
-
var anchor = root ? root.parentElement : null;
|
|
259
|
-
var targetElement = anchorElem || anchor || document.body;
|
|
260
|
-
return /*#__PURE__*/createPortal( /*#__PURE__*/_jsx(TableHoverActionsContainer, {
|
|
261
|
-
anchorElem: targetElement,
|
|
262
|
-
editor: editor
|
|
263
|
-
}), targetElement);
|
|
264
|
-
});
|
|
250
|
+
TableHoverActions.displayName = 'TableHoverActions';
|
|
251
|
+
export default TableHoverActions;
|
|
@@ -11,6 +11,7 @@ import EventEmitter from 'eventemitter3';
|
|
|
11
11
|
import { $getSelection, $isRangeSelection } from 'lexical';
|
|
12
12
|
import { useLayoutEffect, useMemo, useState } from 'react';
|
|
13
13
|
import { useLexicalEditor } from "../../../editor-kernel/react";
|
|
14
|
+
import PortalAnchor from "../../../editor-kernel/react/PortalAnchor";
|
|
14
15
|
import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
|
|
15
16
|
import { TablePlugin } from "../plugin";
|
|
16
17
|
import { $updateDOMForSelection } from "../utils";
|
|
@@ -19,8 +20,8 @@ import TableHoverActionsPlugin from "./TableHoverActions";
|
|
|
19
20
|
import TableCellResizePlugin from "./TableResize";
|
|
20
21
|
import { useStyles } from "./style";
|
|
21
22
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
23
23
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
24
25
|
export var ReactTablePlugin = function ReactTablePlugin(_ref) {
|
|
25
26
|
var className = _ref.className,
|
|
26
27
|
locale = _ref.locale;
|
|
@@ -68,10 +69,12 @@ export var ReactTablePlugin = function ReactTablePlugin(_ref) {
|
|
|
68
69
|
children: [/*#__PURE__*/_jsx(TableCellResizePlugin, {
|
|
69
70
|
editor: lexicalEditor,
|
|
70
71
|
eventEmitter: eventEmitter
|
|
71
|
-
}), /*#__PURE__*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
}), /*#__PURE__*/_jsxs(PortalAnchor, {
|
|
73
|
+
children: [/*#__PURE__*/_jsx(TableActionMenuPlugin, {
|
|
74
|
+
editor: lexicalEditor
|
|
75
|
+
}), /*#__PURE__*/_jsx(TableHoverActionsPlugin, {
|
|
76
|
+
editor: lexicalEditor
|
|
77
|
+
})]
|
|
75
78
|
})]
|
|
76
79
|
});
|
|
77
80
|
};
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|