@ctzhian/tiptap 2.6.1 → 2.7.1
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/dist/Editor/demo.js +1 -1
- package/dist/EditorMarkdown/demo.js +1 -1
- package/dist/asset/css/index.css +1 -0
- package/dist/component/ImageViewer/index.d.ts +0 -1
- package/dist/component/ImageViewer/index.js +0 -1
- package/dist/extension/component/TableExtendButton/index.d.ts +1 -3
- package/dist/extension/component/TableExtendButton/index.js +16 -7
- package/dist/extension/component/TableExtendButton/use-table-extend-row-column.d.ts +1 -3
- package/dist/extension/component/TableExtendButton/use-table-extend-row-column.js +5 -10
- package/dist/extension/component/TableHandle/TableHandleAddButton.js +19 -11
- package/dist/extension/component/TableHandle/TableHandleMenu.js +159 -83
- package/dist/extension/component/TableHandle/index.d.ts +2 -7
- package/dist/extension/component/TableHandle/index.js +1 -4
- package/dist/extension/component/TableHandle/use-table-handle-positioning.d.ts +2 -6
- package/dist/extension/component/TableHandle/use-table-handle-positioning.js +28 -55
- package/dist/extension/component/TableHandle/use-table-handle-state.d.ts +4 -13
- package/dist/extension/component/TableHandle/use-table-handle-state.js +1 -1
- package/dist/extension/component/UploadProgress/index.d.ts +1 -1
- package/dist/extension/index.js +2 -2
- package/dist/extension/node/Table.js +112 -151
- package/dist/extension/node/TableHandler/plugin.d.ts +5 -9
- package/dist/extension/node/TableHandler/plugin.js +177 -124
- package/dist/extension/node/TableOfContents/index.d.ts +4 -7
- package/dist/extension/node/TableOfContents/index.js +23 -419
- package/dist/util/table-utils.d.ts +28 -61
- package/dist/util/table-utils.js +157 -124
- package/package.json +32 -32
- package/dist/extension/node/TableOfContents/plugin.d.ts +0 -6
- package/dist/extension/node/TableOfContents/plugin.js +0 -58
- package/dist/extension/node/TableOfContents/types.d.ts +0 -45
- package/dist/extension/node/TableOfContents/types.js +0 -1
- package/dist/extension/node/TableOfContents/util.d.ts +0 -6
- package/dist/extension/node/TableOfContents/util.js +0 -70
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
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) { function e(_x) { return _e.apply(this, arguments); } e.toString = function () { return _e.toString(); }; return e; }(function (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 (_e2) { function e(_x2) { return _e2.apply(this, arguments); } e.toString = function () { return _e2.toString(); }; return e; }(function (e) { didErr = true; err = e; }), f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
3
7
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
8
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
9
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
10
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
11
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
12
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
13
|
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."); }
|
|
14
14
|
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); }
|
|
@@ -19,11 +19,11 @@ import { AlignBottomIcon, AlignCenterIcon, AlignJustifyIcon, AlignLeftIcon, Alig
|
|
|
19
19
|
import { DeleteBack2LineIcon } from "../../../component/Icons/delete-back-2-line-icon";
|
|
20
20
|
import { getThemeTextBgColor, getThemeTextColor } from "../../../contants/enums";
|
|
21
21
|
import { Box, Divider, Typography, useTheme } from '@mui/material';
|
|
22
|
-
import { addColumnAfter,
|
|
22
|
+
import { addColumnAfter, CellSelection, deleteCellSelection, TableMap } from '@tiptap/pm/tables';
|
|
23
23
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
24
24
|
import { MoreLineIcon } from "../../../component/Icons/more-line-icon";
|
|
25
25
|
import Menu from "../../../component/Menu";
|
|
26
|
-
import { getColumnCells, getIndexCoordinates, getRowCells, getTable, selectCellsByCoords } from "../../../util/table-utils";
|
|
26
|
+
import { getColumnCells, getIndexCoordinates, getRowCells, getRowOriginCoords, getTable, getUniqueCellsWithRect, selectCellsByCoords } from "../../../util/table-utils";
|
|
27
27
|
import { dragEnd } from "../../node/TableHandler/plugin";
|
|
28
28
|
import "./TableHandleMenu.css";
|
|
29
29
|
export var TableHandleMenu = function TableHandleMenu(_ref) {
|
|
@@ -40,30 +40,46 @@ export var TableHandleMenu = function TableHandleMenu(_ref) {
|
|
|
40
40
|
_useState2 = _slicedToArray(_useState, 2),
|
|
41
41
|
isDragging = _useState2[0],
|
|
42
42
|
setIsDragging = _useState2[1];
|
|
43
|
+
var dedupeCells = useCallback(function (cells) {
|
|
44
|
+
var seen = new Set();
|
|
45
|
+
return cells.filter(function (cell) {
|
|
46
|
+
if (seen.has(cell.pos)) return false;
|
|
47
|
+
seen.add(cell.pos);
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
}, []);
|
|
43
51
|
var selectRowOrColumn = useCallback(function () {
|
|
44
52
|
if (!editor || !tableNode || typeof tablePos !== 'number' || typeof index !== 'number') return;
|
|
45
53
|
try {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
if (orientation === 'row') {
|
|
55
|
+
var coords = getRowOriginCoords({
|
|
56
|
+
editor: editor,
|
|
57
|
+
rowIndex: index,
|
|
58
|
+
tablePos: tablePos,
|
|
59
|
+
includeMerged: false
|
|
60
|
+
});
|
|
61
|
+
if (!coords) return;
|
|
62
|
+
selectCellsByCoords(editor, tablePos, coords, {
|
|
63
|
+
mode: 'dispatch',
|
|
64
|
+
dispatch: editor.view.dispatch.bind(editor.view)
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
var _TableMap$get = TableMap.get(tableNode),
|
|
68
|
+
width = _TableMap$get.width,
|
|
69
|
+
height = _TableMap$get.height;
|
|
70
|
+
var start = {
|
|
71
|
+
row: 0,
|
|
72
|
+
col: index
|
|
73
|
+
};
|
|
74
|
+
var end = {
|
|
75
|
+
row: height - 1,
|
|
76
|
+
col: index
|
|
77
|
+
};
|
|
78
|
+
selectCellsByCoords(editor, tablePos, [start, end], {
|
|
79
|
+
mode: 'dispatch',
|
|
80
|
+
dispatch: editor.view.dispatch.bind(editor.view)
|
|
81
|
+
});
|
|
82
|
+
}
|
|
67
83
|
} catch (error) {
|
|
68
84
|
console.warn('Failed to select row/column:', error);
|
|
69
85
|
}
|
|
@@ -73,60 +89,106 @@ export var TableHandleMenu = function TableHandleMenu(_ref) {
|
|
|
73
89
|
return false;
|
|
74
90
|
}
|
|
75
91
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
92
|
+
if (orientation === 'row') {
|
|
93
|
+
var rowCells = getRowCells(editor, index, tablePos);
|
|
94
|
+
return dedupeCells(rowCells.cells).length > 0;
|
|
95
|
+
}
|
|
96
|
+
var cells = getColumnCells(editor, index, tablePos);
|
|
97
|
+
return dedupeCells(cells.cells).length > 0 && cells.mergedCells.length === 0;
|
|
78
98
|
} catch (_unused) {
|
|
79
99
|
return false;
|
|
80
100
|
}
|
|
81
|
-
}, [editor, index, orientation, tablePos, tableNode, editor === null || editor === void 0 ? void 0 : editor.state.doc]);
|
|
101
|
+
}, [dedupeCells, editor, index, orientation, tablePos, tableNode, editor === null || editor === void 0 ? void 0 : editor.state.doc]);
|
|
82
102
|
var duplicateRowOrColumn = useCallback(function () {
|
|
83
103
|
if (!editor || typeof index !== 'number' || typeof tablePos !== 'number' || !canDuplicate) {
|
|
84
104
|
return;
|
|
85
105
|
}
|
|
86
106
|
try {
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
addSuccess = orientation === 'row' ? editor.chain().focus().addRowAfter().run() : editor.chain().focus().addColumnAfter().run();
|
|
107
|
+
// 添加新行/列
|
|
108
|
+
if (orientation === 'row') {
|
|
109
|
+
selectRowOrColumn();
|
|
110
|
+
var added = editor.chain().focus().addRowAfter().run();
|
|
111
|
+
if (!added) return;
|
|
93
112
|
} else {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
tablePos: tablePos
|
|
99
|
-
});
|
|
100
|
-
if (!sourceCoords) return;
|
|
101
|
-
var stateWithCellSel = selectCellsByCoords(editor, tablePos, sourceCoords, {
|
|
102
|
-
mode: 'state'
|
|
103
|
-
});
|
|
104
|
-
if (!stateWithCellSel) return;
|
|
105
|
-
var dispatch = function dispatch(tr) {
|
|
106
|
-
return editor.view.dispatch(tr);
|
|
107
|
-
};
|
|
108
|
-
if (orientation === 'row') {
|
|
109
|
-
addSuccess = addRowAfter(stateWithCellSel, dispatch);
|
|
113
|
+
selectRowOrColumn();
|
|
114
|
+
var addSuccess = false;
|
|
115
|
+
if (editor.state.selection instanceof CellSelection) {
|
|
116
|
+
addSuccess = editor.chain().focus().addColumnAfter().run();
|
|
110
117
|
} else {
|
|
118
|
+
var sourceCoords = getIndexCoordinates({
|
|
119
|
+
editor: editor,
|
|
120
|
+
index: index,
|
|
121
|
+
orientation: orientation,
|
|
122
|
+
tablePos: tablePos
|
|
123
|
+
});
|
|
124
|
+
if (!sourceCoords) return;
|
|
125
|
+
var stateWithCellSel = selectCellsByCoords(editor, tablePos, sourceCoords, {
|
|
126
|
+
mode: 'state'
|
|
127
|
+
});
|
|
128
|
+
if (!stateWithCellSel) return;
|
|
129
|
+
var dispatch = function dispatch(tr) {
|
|
130
|
+
return editor.view.dispatch(tr);
|
|
131
|
+
};
|
|
111
132
|
addSuccess = addColumnAfter(stateWithCellSel, dispatch);
|
|
112
133
|
}
|
|
134
|
+
if (!addSuccess) return;
|
|
113
135
|
}
|
|
114
|
-
if (!addSuccess) return;
|
|
115
136
|
var updatedTable = getTable(editor, tablePos);
|
|
116
137
|
if (!updatedTable) return;
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
|
|
139
|
+
// 获取新添加的行/列中的单元格
|
|
140
|
+
var newCells = orientation === 'row' ? dedupeCells(getRowCells(editor, index + 1, updatedTable.pos).cells) : dedupeCells(getColumnCells(editor, index + 1, updatedTable.pos).cells);
|
|
141
|
+
|
|
142
|
+
// 获取要复制的原始行/列中的单元格
|
|
143
|
+
var originalCells = orientation === 'row' ? dedupeCells(getRowCells(editor, index, tablePos).cells) : dedupeCells(getColumnCells(editor, index, tablePos).cells);
|
|
144
|
+
if (newCells.length === 0 || originalCells.length === 0) return;
|
|
119
145
|
var state = editor.state,
|
|
120
146
|
view = editor.view;
|
|
121
147
|
var tr = state.tr;
|
|
122
|
-
|
|
123
|
-
|
|
148
|
+
|
|
149
|
+
// 处理合并单元格
|
|
150
|
+
var table = getTable(editor, tablePos);
|
|
151
|
+
var cellsToSkip = new Set(); // 记录要跳过的单元格位置
|
|
152
|
+
|
|
153
|
+
if (table && orientation === 'row') {
|
|
154
|
+
var cellsWithRect = getUniqueCellsWithRect(table);
|
|
155
|
+
cellsWithRect.forEach(function (cell) {
|
|
156
|
+
var _node$attrs$rowspan;
|
|
157
|
+
var pos = cell.pos,
|
|
158
|
+
node = cell.node,
|
|
159
|
+
rect = cell.rect;
|
|
160
|
+
var rowspan = (_node$attrs$rowspan = node.attrs.rowspan) !== null && _node$attrs$rowspan !== void 0 ? _node$attrs$rowspan : 1;
|
|
161
|
+
var colspan = rect.right - rect.left;
|
|
162
|
+
if (rowspan > 1 && rect.top === index) {
|
|
163
|
+
tr = tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
164
|
+
rowspan: rowspan + 1
|
|
165
|
+
}), node.marks);
|
|
166
|
+
} else if (rowspan > 1 && rect.top < index && index < rect.bottom) {
|
|
167
|
+
// 记录被纵向合并覆盖的每一列,注意合并单元格可能横跨多列
|
|
168
|
+
for (var col = rect.left; col < rect.left + colspan; col++) {
|
|
169
|
+
cellsToSkip.add(col);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 按列号建立映射,保证合并(横跨多列)时能精确匹配原始单元格
|
|
176
|
+
var originalCellByColumn = new Map();
|
|
177
|
+
originalCells.forEach(function (cell) {
|
|
178
|
+
originalCellByColumn.set(cell.column, cell);
|
|
179
|
+
});
|
|
180
|
+
var cellsToReplace = _toConsumableArray(newCells).reverse();
|
|
124
181
|
cellsToReplace.forEach(function (newCell, reverseIndex) {
|
|
125
|
-
var originalCell =
|
|
182
|
+
var originalCell = originalCellByColumn.get(newCell.column);
|
|
126
183
|
if (newCell.node && originalCell !== null && originalCell !== void 0 && originalCell.node) {
|
|
184
|
+
// 使用实际列索引判断是否需要跳过被合并覆盖的单元格,避免反向遍历导致错位
|
|
185
|
+
var shouldSkip = orientation === 'row' && cellsToSkip.has(newCell.column);
|
|
186
|
+
if (shouldSkip) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
127
189
|
var duplicatedCell = newCell.node.type.create(_objectSpread({}, originalCell.node.attrs), originalCell.node.content, originalCell.node.marks);
|
|
128
190
|
var cellEnd = newCell.pos + newCell.node.nodeSize;
|
|
129
|
-
tr.replaceWith(newCell.pos, cellEnd, duplicatedCell);
|
|
191
|
+
tr = tr.replaceWith(newCell.pos, cellEnd, duplicatedCell);
|
|
130
192
|
}
|
|
131
193
|
});
|
|
132
194
|
if (tr.docChanged) {
|
|
@@ -207,18 +269,25 @@ export var TableHandleMenu = function TableHandleMenu(_ref) {
|
|
|
207
269
|
}
|
|
208
270
|
}),
|
|
209
271
|
onClick: function onClick() {
|
|
210
|
-
if (typeof index === 'number' && typeof tablePos === 'number') {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
272
|
+
if (editor && typeof index === 'number' && typeof tablePos === 'number') {
|
|
273
|
+
if (orientation === 'row') {
|
|
274
|
+
selectCellsByCoords(editor, tablePos, [{
|
|
275
|
+
row: index,
|
|
276
|
+
col: 0
|
|
277
|
+
}], {
|
|
278
|
+
mode: 'dispatch',
|
|
279
|
+
dispatch: editor.view.dispatch.bind(editor.view)
|
|
280
|
+
});
|
|
281
|
+
} else {
|
|
282
|
+
var cellCoord = {
|
|
283
|
+
row: 0,
|
|
284
|
+
col: index
|
|
285
|
+
};
|
|
286
|
+
selectCellsByCoords(editor, tablePos, [cellCoord], {
|
|
287
|
+
mode: 'dispatch',
|
|
288
|
+
dispatch: editor.view.dispatch.bind(editor.view)
|
|
289
|
+
});
|
|
290
|
+
}
|
|
222
291
|
}
|
|
223
292
|
if (orientation === 'row') {
|
|
224
293
|
editor.chain().focus().addRowBefore().run();
|
|
@@ -239,18 +308,25 @@ export var TableHandleMenu = function TableHandleMenu(_ref) {
|
|
|
239
308
|
}
|
|
240
309
|
}),
|
|
241
310
|
onClick: function onClick() {
|
|
242
|
-
if (typeof index === 'number' && typeof tablePos === 'number') {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
311
|
+
if (editor && typeof index === 'number' && typeof tablePos === 'number') {
|
|
312
|
+
if (orientation === 'row') {
|
|
313
|
+
selectCellsByCoords(editor, tablePos, [{
|
|
314
|
+
row: index,
|
|
315
|
+
col: 0
|
|
316
|
+
}], {
|
|
317
|
+
mode: 'dispatch',
|
|
318
|
+
dispatch: editor.view.dispatch.bind(editor.view)
|
|
319
|
+
});
|
|
320
|
+
} else {
|
|
321
|
+
var cellCoord = {
|
|
322
|
+
row: 0,
|
|
323
|
+
col: index
|
|
324
|
+
};
|
|
325
|
+
selectCellsByCoords(editor, tablePos, [cellCoord], {
|
|
326
|
+
mode: 'dispatch',
|
|
327
|
+
dispatch: editor.view.dispatch.bind(editor.view)
|
|
328
|
+
});
|
|
329
|
+
}
|
|
254
330
|
}
|
|
255
331
|
if (orientation === 'row') {
|
|
256
332
|
editor.chain().focus().addRowAfter().run();
|
|
@@ -13,15 +13,10 @@ export interface TableHandleButtonProps {
|
|
|
13
13
|
dragStart?: (e: React.DragEvent) => void;
|
|
14
14
|
}
|
|
15
15
|
export interface TableHandleProps {
|
|
16
|
-
/**
|
|
17
|
-
* The Tiptap editor instance.
|
|
18
|
-
*/
|
|
16
|
+
/** Tiptap 编辑器实例 */
|
|
19
17
|
editor?: Editor | null;
|
|
20
18
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Main table handle component that manages the positioning and rendering
|
|
23
|
-
* of table row/column handles, extend buttons, and context menus.
|
|
24
|
-
*/
|
|
19
|
+
/** 负责行/列手柄、扩展按钮与菜单的定位与渲染 */
|
|
25
20
|
export declare function TableHandle({ editor: providedEditor, }: TableHandleProps): React.JSX.Element | null;
|
|
26
21
|
export declare namespace TableHandle {
|
|
27
22
|
var displayName: string;
|
|
@@ -11,10 +11,7 @@ import { TableHandleAddButton } from "./TableHandleAddButton";
|
|
|
11
11
|
import { TableHandleMenu } from "./TableHandleMenu";
|
|
12
12
|
import { useTableHandlePositioning } from "./use-table-handle-positioning";
|
|
13
13
|
import { useTableHandleState } from "./use-table-handle-state";
|
|
14
|
-
/**
|
|
15
|
-
* Main table handle component that manages the positioning and rendering
|
|
16
|
-
* of table row/column handles, extend buttons, and context menus.
|
|
17
|
-
*/
|
|
14
|
+
/** 负责行/列手柄、扩展按钮与菜单的定位与渲染 */
|
|
18
15
|
export function TableHandle(_ref) {
|
|
19
16
|
var providedEditor = _ref.editor;
|
|
20
17
|
var editor = providedEditor;
|
|
@@ -9,17 +9,13 @@ type DraggingState = {
|
|
|
9
9
|
height: number;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
/**
|
|
13
|
-
* Hook for positioning individual table handles using Floating UI React
|
|
14
|
-
*/
|
|
12
|
+
/** 基于 Floating UI 定位单个表格手柄的 Hook */
|
|
15
13
|
export declare function useTableHandlePosition(orientation: Orientation, show: boolean, referencePosCell: DOMRect | null, referencePosTable: DOMRect | null, draggingState?: DraggingState): {
|
|
16
14
|
isMounted: boolean;
|
|
17
15
|
ref: (node: HTMLElement | null) => void;
|
|
18
16
|
style: React.CSSProperties;
|
|
19
17
|
};
|
|
20
|
-
/**
|
|
21
|
-
* Hook for managing positioning of all table handles (row, column, and cell)
|
|
22
|
-
*/
|
|
18
|
+
/** 统一返回行、列、单元格手柄的位置数据 */
|
|
23
19
|
export declare function useTableHandlePositioning(show: boolean, referencePosCell: DOMRect | null, referencePosTable: DOMRect | null, draggingState?: DraggingState): {
|
|
24
20
|
rowHandle: {
|
|
25
21
|
isMounted: boolean;
|
|
@@ -7,46 +7,30 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
7
7
|
import { offset, size, useFloating, useTransitionStyles } from '@floating-ui/react';
|
|
8
8
|
import { useEffect, useMemo } from 'react';
|
|
9
9
|
import { clamp } from "../../../util/table-utils";
|
|
10
|
-
/**
|
|
11
|
-
* Creates a DOMRect for row handle positioning
|
|
12
|
-
* Reference is positioned at table edge, aligned with cell
|
|
13
|
-
*/
|
|
10
|
+
/** 创建行手柄的参考 DOMRect,贴边并与单元格对齐 */
|
|
14
11
|
function makeRowRect(cell, table, dragging) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return new DOMRect(table.x, clampedY, table.width, cell.height);
|
|
21
|
-
}
|
|
22
|
-
return new DOMRect(table.x, cell.y, table.width, cell.height);
|
|
12
|
+
var _dragging$initialOffs;
|
|
13
|
+
var baseY = (dragging === null || dragging === void 0 ? void 0 : dragging.draggedCellOrientation) === 'row' ? clamp(dragging.mousePos + ((_dragging$initialOffs = dragging.initialOffset) !== null && _dragging$initialOffs !== void 0 ? _dragging$initialOffs : 0), table.y, table.bottom - cell.height) : cell.y;
|
|
14
|
+
|
|
15
|
+
// 行手柄沿整行宽度,高度保持单元格高度
|
|
16
|
+
return new DOMRect(table.x, baseY, table.width, cell.height);
|
|
23
17
|
}
|
|
24
18
|
|
|
25
|
-
/**
|
|
26
|
-
* Creates a DOMRect for column handle positioning
|
|
27
|
-
* Reference is positioned at table edge, aligned with cell
|
|
28
|
-
*/
|
|
19
|
+
/** 创建列手柄的参考 DOMRect,贴边并与单元格对齐 */
|
|
29
20
|
function makeColRect(cell, table, dragging) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return new DOMRect(clampedX, table.y, cell.width, table.height);
|
|
36
|
-
}
|
|
37
|
-
return new DOMRect(cell.x, table.y, cell.width, table.height);
|
|
21
|
+
var _dragging$initialOffs2;
|
|
22
|
+
var baseX = (dragging === null || dragging === void 0 ? void 0 : dragging.draggedCellOrientation) === 'col' ? clamp(dragging.mousePos + ((_dragging$initialOffs2 = dragging.initialOffset) !== null && _dragging$initialOffs2 !== void 0 ? _dragging$initialOffs2 : 0), table.x, table.right - cell.width) : cell.x;
|
|
23
|
+
|
|
24
|
+
// 列手柄宽度保持单元格宽度,高度沿整列
|
|
25
|
+
return new DOMRect(baseX, table.y, cell.width, table.height);
|
|
38
26
|
}
|
|
39
27
|
|
|
40
|
-
/**
|
|
41
|
-
* Creates a DOMRect for cell handle positioning
|
|
42
|
-
*/
|
|
28
|
+
/** 创建单元格手柄的参考 DOMRect */
|
|
43
29
|
function makeCellRect(cell) {
|
|
44
30
|
return new DOMRect(cell.x, cell.y, cell.width, 0);
|
|
45
31
|
}
|
|
46
32
|
|
|
47
|
-
/**
|
|
48
|
-
* Gets the placement configuration for different handle orientations
|
|
49
|
-
*/
|
|
33
|
+
/** 根据手柄方向获取浮层位置 */
|
|
50
34
|
function getPlacement(orientation) {
|
|
51
35
|
switch (orientation) {
|
|
52
36
|
case 'row':
|
|
@@ -59,9 +43,7 @@ function getPlacement(orientation) {
|
|
|
59
43
|
}
|
|
60
44
|
}
|
|
61
45
|
|
|
62
|
-
/**
|
|
63
|
-
* Gets the offset configuration for different handle orientations
|
|
64
|
-
*/
|
|
46
|
+
/** 根据手柄方向获取偏移配置 */
|
|
65
47
|
function getOffset(orientation) {
|
|
66
48
|
switch (orientation) {
|
|
67
49
|
case 'row':
|
|
@@ -77,9 +59,7 @@ function getOffset(orientation) {
|
|
|
77
59
|
}
|
|
78
60
|
}
|
|
79
61
|
|
|
80
|
-
/**
|
|
81
|
-
* Factory function to create DOMRect based on orientation
|
|
82
|
-
*/
|
|
62
|
+
/** 按方向生成对应的参考 DOMRect */
|
|
83
63
|
function rectFactory(orientation, cell, table, dragging) {
|
|
84
64
|
switch (orientation) {
|
|
85
65
|
case 'row':
|
|
@@ -92,9 +72,7 @@ function rectFactory(orientation, cell, table, dragging) {
|
|
|
92
72
|
}
|
|
93
73
|
}
|
|
94
74
|
|
|
95
|
-
/**
|
|
96
|
-
* Hook for positioning individual table handles using Floating UI React
|
|
97
|
-
*/
|
|
75
|
+
/** 基于 Floating UI 定位单个表格手柄的 Hook */
|
|
98
76
|
export function useTableHandlePosition(orientation, show, referencePosCell, referencePosTable, draggingState) {
|
|
99
77
|
var placement = useMemo(function () {
|
|
100
78
|
return getPlacement(orientation);
|
|
@@ -107,18 +85,18 @@ export function useTableHandlePosition(orientation, show, referencePosCell, refe
|
|
|
107
85
|
placement: placement,
|
|
108
86
|
middleware: [offset(offsetValue), size({
|
|
109
87
|
apply: function apply(_ref) {
|
|
110
|
-
var _ref2,
|
|
88
|
+
var _ref2, _referencePosTable$wi, _referencePosTable$wi2, _ref3, _referencePosTable$he, _referencePosTable$he2;
|
|
111
89
|
var rects = _ref.rects,
|
|
112
90
|
elements = _ref.elements;
|
|
113
91
|
if (!elements.floating) return;
|
|
114
|
-
var refWidth = (_ref2 = orientation === 'col' ? (
|
|
115
|
-
var refHeight = (_ref3 = orientation === 'row' ? (
|
|
92
|
+
var refWidth = (_ref2 = orientation === 'col' ? (_referencePosTable$wi = referencePosTable === null || referencePosTable === void 0 ? void 0 : referencePosTable.width) !== null && _referencePosTable$wi !== void 0 ? _referencePosTable$wi : referencePosCell === null || referencePosCell === void 0 ? void 0 : referencePosCell.width : (_referencePosTable$wi2 = referencePosTable === null || referencePosTable === void 0 ? void 0 : referencePosTable.width) !== null && _referencePosTable$wi2 !== void 0 ? _referencePosTable$wi2 : referencePosCell === null || referencePosCell === void 0 ? void 0 : referencePosCell.width) !== null && _ref2 !== void 0 ? _ref2 : rects.reference.width;
|
|
93
|
+
var refHeight = (_ref3 = orientation === 'row' ? (_referencePosTable$he = referencePosTable === null || referencePosTable === void 0 ? void 0 : referencePosTable.height) !== null && _referencePosTable$he !== void 0 ? _referencePosTable$he : referencePosCell === null || referencePosCell === void 0 ? void 0 : referencePosCell.height : (_referencePosTable$he2 = referencePosTable === null || referencePosTable === void 0 ? void 0 : referencePosTable.height) !== null && _referencePosTable$he2 !== void 0 ? _referencePosTable$he2 : referencePosCell === null || referencePosCell === void 0 ? void 0 : referencePosCell.height) !== null && _ref3 !== void 0 ? _ref3 : rects.reference.height;
|
|
116
94
|
|
|
117
|
-
//
|
|
95
|
+
// 将尺寸写入 CSS 变量,便于样式使用
|
|
118
96
|
elements.floating.style.setProperty('--table-handle-ref-width', "".concat(refWidth, "px"));
|
|
119
97
|
elements.floating.style.setProperty('--table-handle-ref-height', "".concat(refHeight, "px"));
|
|
120
98
|
|
|
121
|
-
//
|
|
99
|
+
// 主尺寸随方向切换,行取高度、列取宽度
|
|
122
100
|
var mainSize = orientation === 'row' ? refHeight : refWidth;
|
|
123
101
|
elements.floating.style.setProperty('--table-handle-available-size', "".concat(mainSize, "px"));
|
|
124
102
|
}
|
|
@@ -132,26 +110,23 @@ export function useTableHandlePosition(orientation, show, referencePosCell, refe
|
|
|
132
110
|
isMounted = _useTransitionStyles.isMounted,
|
|
133
111
|
styles = _useTransitionStyles.styles;
|
|
134
112
|
|
|
135
|
-
//
|
|
136
|
-
// Use a function that always returns the latest values to ensure autoUpdate works correctly
|
|
113
|
+
// 为 Floating UI 提供虚拟参考矩形;使用闭包拿最新值以保证 autoUpdate 生效
|
|
137
114
|
useEffect(function () {
|
|
138
|
-
//
|
|
115
|
+
// 尚无参考节点
|
|
139
116
|
if (!referencePosCell || !referencePosTable) {
|
|
140
117
|
refs.setReference(null);
|
|
141
118
|
return;
|
|
142
119
|
}
|
|
143
120
|
|
|
144
|
-
//
|
|
121
|
+
// 拖动时隐藏单元格手柄(保持与原行为一致)
|
|
145
122
|
if (draggingState && orientation === 'cell') {
|
|
146
123
|
refs.setReference(null);
|
|
147
124
|
return;
|
|
148
125
|
}
|
|
149
126
|
|
|
150
|
-
//
|
|
151
|
-
// This ensures autoUpdate can detect changes when scrolling
|
|
127
|
+
// 创建返回最新矩形的虚拟元素,保证滚动时位置能自动更新
|
|
152
128
|
refs.setReference({
|
|
153
129
|
getBoundingClientRect: function getBoundingClientRect() {
|
|
154
|
-
// Always use the latest values from closure
|
|
155
130
|
if (!referencePosCell || !referencePosTable) {
|
|
156
131
|
return new DOMRect();
|
|
157
132
|
}
|
|
@@ -160,7 +135,7 @@ export function useTableHandlePosition(orientation, show, referencePosCell, refe
|
|
|
160
135
|
});
|
|
161
136
|
}, [refs, orientation, referencePosCell, referencePosTable, draggingState]);
|
|
162
137
|
|
|
163
|
-
//
|
|
138
|
+
// 参考位置变化时更新浮层
|
|
164
139
|
useEffect(function () {
|
|
165
140
|
if (!show || !referencePosCell || !referencePosTable) return;
|
|
166
141
|
update();
|
|
@@ -176,9 +151,7 @@ export function useTableHandlePosition(orientation, show, referencePosCell, refe
|
|
|
176
151
|
}, [isMounted, refs.setFloating, styles, floatingStyles]);
|
|
177
152
|
}
|
|
178
153
|
|
|
179
|
-
/**
|
|
180
|
-
* Hook for managing positioning of all table handles (row, column, and cell)
|
|
181
|
-
*/
|
|
154
|
+
/** 统一返回行、列、单元格手柄的位置数据 */
|
|
182
155
|
export function useTableHandlePositioning(show, referencePosCell, referencePosTable, draggingState) {
|
|
183
156
|
var rowHandle = useTableHandlePosition('row', show, referencePosCell, referencePosTable, draggingState);
|
|
184
157
|
var colHandle = useTableHandlePosition('col', show, referencePosCell, referencePosTable, draggingState);
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import type { Editor } from '@tiptap/react';
|
|
2
2
|
import type { TableHandlesState } from '../../node/TableHandler/plugin';
|
|
3
3
|
export interface UseTableHandleStateConfig {
|
|
4
|
-
/**
|
|
5
|
-
* The Tiptap editor instance. If omitted, the hook will use
|
|
6
|
-
* the context/editor from `useTiptapEditor`.
|
|
7
|
-
*/
|
|
4
|
+
/** Tiptap 编辑器实例;未传则使用外部上下文中的 editor */
|
|
8
5
|
editor?: Editor | null;
|
|
9
|
-
/**
|
|
10
|
-
* Initial state of the table handles
|
|
11
|
-
*/
|
|
6
|
+
/** 手柄的初始状态 */
|
|
12
7
|
initialState?: TableHandlesState | null;
|
|
13
|
-
/**
|
|
14
|
-
* Only update state when specific fields change
|
|
15
|
-
*/
|
|
8
|
+
/** 仅在特定字段变动时触发更新 */
|
|
16
9
|
watchFields?: (keyof TableHandlesState)[];
|
|
17
|
-
/**
|
|
18
|
-
* Callback when state changes
|
|
19
|
-
*/
|
|
10
|
+
/** 状态变更回调 */
|
|
20
11
|
onStateChange?: (state: TableHandlesState | null) => void;
|
|
21
12
|
}
|
|
22
13
|
export declare function useTableHandleState(config?: UseTableHandleStateConfig): TableHandlesState | null;
|
|
@@ -4,7 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
5
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import {
|
|
7
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
8
8
|
export function useTableHandleState() {
|
|
9
9
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
10
10
|
var providedEditor = config.editor,
|
|
@@ -7,6 +7,6 @@ export interface UploadProgressAttributes {
|
|
|
7
7
|
tempId: string;
|
|
8
8
|
}
|
|
9
9
|
export declare const getFileIcon: (fileType: string) => React.JSX.Element;
|
|
10
|
-
export declare const getFileTypeText: (fileType: string) => "
|
|
10
|
+
export declare const getFileTypeText: (fileType: string) => "图片" | "视频" | "音频" | "文件";
|
|
11
11
|
declare const UploadProgressView: React.FC<NodeViewProps>;
|
|
12
12
|
export default UploadProgressView;
|
package/dist/extension/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import StarterKit from '@tiptap/starter-kit';
|
|
|
14
14
|
import { PLACEHOLDER } from "../contants/placeholder";
|
|
15
15
|
import { AiWritingExtension, ImeComposition, SlashCommands, StructuredDiffExtension } from "./extension";
|
|
16
16
|
import { CodeExtension } from "./mark/Code";
|
|
17
|
-
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomHorizontalRule, CustomInlineMathExtension, CustomSubscript, CustomSuperscript, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, FlipGridColumnExtension, FlipGridExtension, FlowExtension, IframeExtension, ImageExtension, Indent, InlineAttachmentExtension, InlineLinkExtension, InlineUploadProgressExtension, ListExtension, MentionExtension, TableExtension,
|
|
17
|
+
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomHorizontalRule, CustomInlineMathExtension, CustomSubscript, CustomSuperscript, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, FlipGridColumnExtension, FlipGridExtension, FlowExtension, IframeExtension, ImageExtension, Indent, InlineAttachmentExtension, InlineLinkExtension, InlineUploadProgressExtension, ListExtension, MentionExtension, TableExtension, TableOfContentsExtension, UploadProgressExtension, VerticalAlign, VideoExtension, YamlFormat, YoutubeExtension } from "./node";
|
|
18
18
|
export var getExtensions = function getExtensions(_ref) {
|
|
19
19
|
var limit = _ref.limit,
|
|
20
20
|
exclude = _ref.exclude,
|
|
@@ -52,7 +52,7 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
52
52
|
onError: onError
|
|
53
53
|
}), CustomInlineMathExtension({
|
|
54
54
|
onError: onError
|
|
55
|
-
}),
|
|
55
|
+
}), TableOfContentsExtension({
|
|
56
56
|
onTocUpdate: onTocUpdate,
|
|
57
57
|
tableOfContentsOptions: tableOfContentsOptions
|
|
58
58
|
}), InlineLinkExtension, BlockLinkExtension, IframeExtension({
|