@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,6 +1,9 @@
|
|
|
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 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; }
|
|
3
3
|
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; }
|
|
4
|
+
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; } } }; }
|
|
5
|
+
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); }
|
|
6
|
+
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; }
|
|
4
7
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
8
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
6
9
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -71,35 +74,40 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
71
74
|
_defineProperty(this, "mouseMoveHandler", function (event) {
|
|
72
75
|
if (_this.menuFrozen || _this.mouseState === 'selecting') return;
|
|
73
76
|
var target = event.target;
|
|
74
|
-
//
|
|
75
|
-
// when dragging outside the editor, which is the key to preventing errors
|
|
77
|
+
// 鼠标不在编辑器内时不处理,避免拖拽出界导致状态被清空
|
|
76
78
|
if (!isHTMLElement(target) || !_this.editorView.dom.contains(target)) return;
|
|
77
79
|
|
|
78
|
-
//
|
|
80
|
+
// 判断是否悬停在手柄或扩展按钮上
|
|
79
81
|
var isOverHandle = target.closest('.tiptap-table-handle-menu') !== null;
|
|
80
|
-
var isOverExtendButton = target.closest('.tiptap-table-extend-row-column-button') !== null;
|
|
82
|
+
var isOverExtendButton = target.closest('.tiptap-table-extend-row-column-button, .tiptap-table-add-button') !== null;
|
|
81
83
|
|
|
82
|
-
//
|
|
84
|
+
// 悬停其上时保持显示
|
|
83
85
|
if (isOverHandle || isOverExtendButton) {
|
|
84
86
|
return;
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
//
|
|
88
|
-
var
|
|
89
|
+
// 检查鼠标是否在手柄或按钮附近,使用缓存优化性能
|
|
90
|
+
var handleRects = _this._getCachedHandleRects();
|
|
89
91
|
var isNearHandle = false;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
var _iterator = _createForOfIteratorHelper(handleRects),
|
|
93
|
+
_step;
|
|
94
|
+
try {
|
|
95
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
96
|
+
var rect = _step.value;
|
|
97
|
+
// 周围扩展 10px 容错便于移动
|
|
98
|
+
var expandedRect = new DOMRect(rect.left - 10, rect.top - 10, rect.width + 20, rect.height + 20);
|
|
99
|
+
if (event.clientX >= expandedRect.left && event.clientX <= expandedRect.right && event.clientY >= expandedRect.top && event.clientY <= expandedRect.bottom) {
|
|
100
|
+
isNearHandle = true;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
99
103
|
}
|
|
100
|
-
}
|
|
101
104
|
|
|
102
|
-
|
|
105
|
+
// 靠近手柄时不继续处理,避免闪烁
|
|
106
|
+
} catch (err) {
|
|
107
|
+
_iterator.e(err);
|
|
108
|
+
} finally {
|
|
109
|
+
_iterator.f();
|
|
110
|
+
}
|
|
103
111
|
if (isNearHandle) {
|
|
104
112
|
return;
|
|
105
113
|
}
|
|
@@ -114,7 +122,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
114
122
|
event.dataTransfer.dropEffect = 'move';
|
|
115
123
|
hideElements('.prosemirror-dropcursor-block, .prosemirror-dropcursor-inline', _this.editorView.root);
|
|
116
124
|
|
|
117
|
-
//
|
|
125
|
+
// 将鼠标坐标限制在表格包围框内
|
|
118
126
|
var _this$state$reference = _this.state.referencePosTable,
|
|
119
127
|
tableLeft = _this$state$reference.left,
|
|
120
128
|
tableRight = _this$state$reference.right,
|
|
@@ -125,7 +133,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
125
133
|
top: clamp(event.clientY, tableTop + 1, tableBottom - 1)
|
|
126
134
|
};
|
|
127
135
|
|
|
128
|
-
//
|
|
136
|
+
// 获取所在位置的单元格元素
|
|
129
137
|
var tableCellElements = _this.editorView.root.elementsFromPoint(boundedMouseCoords.left, boundedMouseCoords.top).filter(function (element) {
|
|
130
138
|
return element.tagName === 'TD' || element.tagName === 'TH';
|
|
131
139
|
});
|
|
@@ -141,19 +149,19 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
141
149
|
var rowIndex = cellPosition.rowIndex,
|
|
142
150
|
colIndex = cellPosition.colIndex;
|
|
143
151
|
|
|
144
|
-
//
|
|
152
|
+
// 判断被拖动的索引是否改变
|
|
145
153
|
var oldIndex = _this.state.draggingState.draggedCellOrientation === 'row' ? _this.state.rowIndex : _this.state.colIndex;
|
|
146
154
|
var newIndex = _this.state.draggingState.draggedCellOrientation === 'row' ? rowIndex : colIndex;
|
|
147
155
|
var dispatchDecorationsTransaction = newIndex !== oldIndex;
|
|
148
156
|
var mousePos = _this.state.draggingState.draggedCellOrientation === 'row' ? boundedMouseCoords.top : boundedMouseCoords.left;
|
|
149
157
|
|
|
150
|
-
//
|
|
158
|
+
// 仅在单元格或鼠标位置变化时更新
|
|
151
159
|
var cellChanged = _this.state.rowIndex !== rowIndex || _this.state.colIndex !== colIndex;
|
|
152
160
|
var mousePosChanged = _this.state.draggingState.mousePos !== mousePos;
|
|
153
161
|
if (cellChanged || mousePosChanged) {
|
|
154
162
|
var _this$state$draggingS;
|
|
155
163
|
var newCellRect = tableCellElement.getBoundingClientRect();
|
|
156
|
-
//
|
|
164
|
+
// 拖拽时保持初始单元格尺寸,避免手柄高度抖动
|
|
157
165
|
var preservedCellRect = (_this$state$draggingS = _this.state.draggingState) !== null && _this$state$draggingS !== void 0 && _this$state$draggingS.originalCellSize ? new DOMRect(newCellRect.x, newCellRect.y, _this.state.draggingState.originalCellSize.width, _this.state.draggingState.originalCellSize.height) : newCellRect;
|
|
158
166
|
_this.state = _objectSpread(_objectSpread({}, _this.state), {}, {
|
|
159
167
|
rowIndex: rowIndex,
|
|
@@ -166,7 +174,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
166
174
|
_this.emitUpdate();
|
|
167
175
|
}
|
|
168
176
|
|
|
169
|
-
//
|
|
177
|
+
// 如需刷新拖拽装饰则派发事务
|
|
170
178
|
if (dispatchDecorationsTransaction) {
|
|
171
179
|
_this.editor.view.dispatch(_this.editor.state.tr.setMeta(tableHandlePluginKey, true));
|
|
172
180
|
}
|
|
@@ -198,8 +206,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
198
206
|
});
|
|
199
207
|
if (!stateWithCellSel) return false;
|
|
200
208
|
|
|
201
|
-
//
|
|
202
|
-
// Type assertion is safe here because we explicitly requested 'state' mode
|
|
209
|
+
// mode 为 state 时 selectCellsByCoords 返回 EditorState,这里的断言是安全的
|
|
203
210
|
var editorState = stateWithCellSel;
|
|
204
211
|
var dispatch = function dispatch(tr) {
|
|
205
212
|
return _this.editor.view.dispatch(tr);
|
|
@@ -228,9 +235,9 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
228
235
|
});
|
|
229
236
|
_defineProperty(this, "scrollHandler", function () {
|
|
230
237
|
var _this$state2, _this$tableElement;
|
|
231
|
-
//
|
|
238
|
+
// 滚动时若手柄可见则重新计算位置
|
|
232
239
|
if ((_this$state2 = _this.state) !== null && _this$state2 !== void 0 && _this$state2.show && (_this$tableElement = _this.tableElement) !== null && _this$tableElement !== void 0 && _this$tableElement.isConnected) {
|
|
233
|
-
//
|
|
240
|
+
// 强制刷新定位
|
|
234
241
|
_this.updatePositions();
|
|
235
242
|
}
|
|
236
243
|
});
|
|
@@ -245,18 +252,40 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
245
252
|
this.editorView.root.addEventListener('dragover', this.dragOverHandler);
|
|
246
253
|
this.editorView.root.addEventListener('drop', this.dropHandler);
|
|
247
254
|
|
|
248
|
-
//
|
|
255
|
+
// 监听滚动事件以更新手柄位置
|
|
249
256
|
window.addEventListener('scroll', this.scrollHandler, true);
|
|
250
|
-
//
|
|
257
|
+
// 同时监听窗口尺寸变化
|
|
251
258
|
window.addEventListener('resize', this.scrollHandler);
|
|
252
259
|
}
|
|
253
260
|
_createClass(TableHandleView, [{
|
|
261
|
+
key: "_getCachedHandleRects",
|
|
262
|
+
value:
|
|
263
|
+
// 获取缓存的手柄边界矩形,每100ms更新一次以提高性能
|
|
264
|
+
function _getCachedHandleRects() {
|
|
265
|
+
var _this$state3;
|
|
266
|
+
var now = Date.now();
|
|
267
|
+
if ((_this$state3 = this.state) !== null && _this$state3 !== void 0 && _this$state3._cachedHandleRects && this.state._cachedHandleRectsTime && now - this.state._cachedHandleRectsTime < 100) {
|
|
268
|
+
return this.state._cachedHandleRects;
|
|
269
|
+
}
|
|
270
|
+
var handleElements = Array.from(this.editorView.root.querySelectorAll('.tiptap-table-handle-menu, .tiptap-table-extend-row-column-button, .tiptap-table-add-button'));
|
|
271
|
+
var rects = handleElements.filter(isHTMLElement).map(function (el) {
|
|
272
|
+
return el.getBoundingClientRect();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// 更新缓存
|
|
276
|
+
if (this.state) {
|
|
277
|
+
this.state._cachedHandleRects = rects;
|
|
278
|
+
this.state._cachedHandleRectsTime = now;
|
|
279
|
+
}
|
|
280
|
+
return rects;
|
|
281
|
+
}
|
|
282
|
+
}, {
|
|
254
283
|
key: "hideHandles",
|
|
255
284
|
value: function hideHandles() {
|
|
256
|
-
var _this$
|
|
257
|
-
if (!((_this$
|
|
285
|
+
var _this$state4;
|
|
286
|
+
if (!((_this$state4 = this.state) !== null && _this$state4 !== void 0 && _this$state4.show)) return;
|
|
258
287
|
|
|
259
|
-
//
|
|
288
|
+
// 拖拽进行中保持手柄显示,保留拖拽状态
|
|
260
289
|
if (this.state.draggingState) return;
|
|
261
290
|
this.state = _objectSpread(_objectSpread({}, this.state), {}, {
|
|
262
291
|
show: false,
|
|
@@ -273,11 +302,11 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
273
302
|
}, {
|
|
274
303
|
key: "_handleMouseMoveNow",
|
|
275
304
|
value: function _handleMouseMoveNow(event) {
|
|
276
|
-
var _this$
|
|
305
|
+
var _this$state5;
|
|
277
306
|
var around = domCellAround(event.target);
|
|
278
307
|
|
|
279
|
-
//
|
|
280
|
-
if ((around === null || around === void 0 ? void 0 : around.type) === 'cell' && this.mouseState === 'down' && !((_this$
|
|
308
|
+
// 在单元格内拖拽选区时隐藏手柄
|
|
309
|
+
if ((around === null || around === void 0 ? void 0 : around.type) === 'cell' && this.mouseState === 'down' && !((_this$state5 = this.state) !== null && _this$state5 !== void 0 && _this$state5.draggingState)) {
|
|
281
310
|
this.mouseState = 'selecting';
|
|
282
311
|
this.hideHandles();
|
|
283
312
|
return;
|
|
@@ -295,7 +324,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
295
324
|
});
|
|
296
325
|
if (!coords) return;
|
|
297
326
|
|
|
298
|
-
//
|
|
327
|
+
// 基于坐标解析当前所在的表格节点
|
|
299
328
|
var $pos = this.editor.view.state.doc.resolve(coords.pos);
|
|
300
329
|
var blockInfo;
|
|
301
330
|
for (var d = $pos.depth; d >= 0; d--) {
|
|
@@ -315,14 +344,14 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
315
344
|
var wrapper = safeClosest(around.domNode, '.tableWrapper');
|
|
316
345
|
var widgetContainer = wrapper === null || wrapper === void 0 ? void 0 : wrapper.querySelector(':scope > .table-controls');
|
|
317
346
|
|
|
318
|
-
//
|
|
347
|
+
// 悬停在表格外围(非单元格区域)
|
|
319
348
|
if (around.type === 'wrapper') {
|
|
320
|
-
var _this$
|
|
349
|
+
var _this$state6, _nearestRowIndex, _this$state7, _nearestCellRect, _this$state8;
|
|
321
350
|
var below = event.clientY >= tableRect.bottom - 1 && event.clientY < tableRect.bottom + 20;
|
|
322
351
|
var right = event.clientX >= tableRect.right - 1 && event.clientX < tableRect.right + 20;
|
|
323
352
|
var cursorBeyondRightOrBottom = event.clientX > tableRect.right || event.clientY > tableRect.bottom;
|
|
324
353
|
|
|
325
|
-
//
|
|
354
|
+
// 悬停在边缘时预先计算扩展按钮位置
|
|
326
355
|
var referencePosLastRow;
|
|
327
356
|
var referencePosLastCol;
|
|
328
357
|
if (below || right) {
|
|
@@ -366,6 +395,25 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
366
395
|
}
|
|
367
396
|
}
|
|
368
397
|
}
|
|
398
|
+
|
|
399
|
+
// 尝试根据鼠标 Y 找到最近的行,并使用该行的首个单元格尺寸作为句柄参考,避免整行/整表尺寸
|
|
400
|
+
var nearestRowIndex;
|
|
401
|
+
var nearestCellRect;
|
|
402
|
+
if (!cursorBeyondRightOrBottom && tbody) {
|
|
403
|
+
var rows = Array.from(tbody.children);
|
|
404
|
+
var minDist = Number.POSITIVE_INFINITY;
|
|
405
|
+
rows.forEach(function (rowEl, idx) {
|
|
406
|
+
var rowRect = rowEl.getBoundingClientRect();
|
|
407
|
+
var dist = Math.abs(event.clientY - (rowRect.top + rowRect.height / 2));
|
|
408
|
+
if (dist < minDist) {
|
|
409
|
+
var _firstCell$getBoundin;
|
|
410
|
+
minDist = dist;
|
|
411
|
+
nearestRowIndex = idx;
|
|
412
|
+
var _firstCell = rowEl.children[0];
|
|
413
|
+
nearestCellRect = (_firstCell$getBoundin = _firstCell === null || _firstCell === void 0 ? void 0 : _firstCell.getBoundingClientRect()) !== null && _firstCell$getBoundin !== void 0 ? _firstCell$getBoundin : rowRect;
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
}
|
|
369
417
|
this.state = _objectSpread(_objectSpread({}, this.state), {}, {
|
|
370
418
|
show: true,
|
|
371
419
|
showAddOrRemoveRowsButton: below,
|
|
@@ -376,47 +424,76 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
376
424
|
block: blockInfo.node,
|
|
377
425
|
blockPos: blockInfo.pos,
|
|
378
426
|
widgetContainer: widgetContainer,
|
|
379
|
-
colIndex: cursorBeyondRightOrBottom ? undefined : (_this$
|
|
380
|
-
rowIndex: cursorBeyondRightOrBottom ? undefined : (_this$
|
|
381
|
-
referencePosCell: cursorBeyondRightOrBottom ? undefined : (_this$
|
|
427
|
+
colIndex: cursorBeyondRightOrBottom ? undefined : (_this$state6 = this.state) === null || _this$state6 === void 0 ? void 0 : _this$state6.colIndex,
|
|
428
|
+
rowIndex: cursorBeyondRightOrBottom ? undefined : (_nearestRowIndex = nearestRowIndex) !== null && _nearestRowIndex !== void 0 ? _nearestRowIndex : (_this$state7 = this.state) === null || _this$state7 === void 0 ? void 0 : _this$state7.rowIndex,
|
|
429
|
+
referencePosCell: cursorBeyondRightOrBottom ? undefined : (_nearestCellRect = nearestCellRect) !== null && _nearestCellRect !== void 0 ? _nearestCellRect : (_this$state8 = this.state) === null || _this$state8 === void 0 ? void 0 : _this$state8.referencePosCell
|
|
382
430
|
});
|
|
383
431
|
} else {
|
|
384
|
-
var _blockInfo$node$conte3, _blockInfo$node$conte4, _this$
|
|
385
|
-
//
|
|
432
|
+
var _blockInfo$node$conte3, _blockInfo$node$conte4, _this$state9;
|
|
433
|
+
// 悬停在单元格上
|
|
386
434
|
var cellPosition = getCellIndicesFromDOM(around.domNode, blockInfo.node, this.editor);
|
|
387
435
|
if (!cellPosition) return;
|
|
436
|
+
var tbodyEl = around.tbodyNode;
|
|
388
437
|
var rowIndex = cellPosition.rowIndex,
|
|
389
438
|
colIndex = cellPosition.colIndex;
|
|
439
|
+
|
|
440
|
+
// 如果单元格跨行,map 计算的 rowIndex 会指向起始行;这里用 DOM 行索引兜底,保证手柄定位在实际行
|
|
441
|
+
var trEl = safeClosest(around.domNode, 'tr');
|
|
442
|
+
if (tbodyEl && trEl) {
|
|
443
|
+
var domRowIndex = Array.from(tbodyEl.children).indexOf(trEl);
|
|
444
|
+
if (domRowIndex >= 0 && domRowIndex !== rowIndex) {
|
|
445
|
+
rowIndex = domRowIndex;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
390
448
|
var _cellRect = around.domNode.getBoundingClientRect();
|
|
449
|
+
var map = TableMap.get(blockInfo.node);
|
|
450
|
+
var cellIndex = rowIndex * map.width + colIndex;
|
|
451
|
+
var cellOffset = map.map[cellIndex];
|
|
452
|
+
var rect = cellOffset !== undefined ? map.findCell(cellOffset) : null;
|
|
453
|
+
var effectiveCellRect = _cellRect;
|
|
454
|
+
|
|
455
|
+
// 如果单元格跨行,按鼠标所在行拆分高度,句柄高度限定为单行高度
|
|
456
|
+
if (rect && rect.bottom - rect.top > 1) {
|
|
457
|
+
var span = rect.bottom - rect.top;
|
|
458
|
+
var unitHeight = _cellRect.height / span;
|
|
459
|
+
var clampedY = clamp(event.clientY, _cellRect.top, _cellRect.bottom);
|
|
460
|
+
var rowOffset = Math.min(span - 1, Math.max(0, Math.floor((clampedY - _cellRect.top) / unitHeight)));
|
|
461
|
+
var rowTop = _cellRect.top + unitHeight * rowOffset;
|
|
462
|
+
rowIndex = rect.top + rowOffset;
|
|
463
|
+
effectiveCellRect = new DOMRect(_cellRect.x, rowTop, _cellRect.width, unitHeight);
|
|
464
|
+
} else if (trEl) {
|
|
465
|
+
var trRect = trEl.getBoundingClientRect();
|
|
466
|
+
effectiveCellRect = new DOMRect(_cellRect.x, trRect.y, _cellRect.width, trRect.height);
|
|
467
|
+
}
|
|
391
468
|
var _lastRowIndex = blockInfo.node.content.childCount - 1;
|
|
392
469
|
var _lastColIndex = ((_blockInfo$node$conte3 = (_blockInfo$node$conte4 = blockInfo.node.content.firstChild) === null || _blockInfo$node$conte4 === void 0 ? void 0 : _blockInfo$node$conte4.content.childCount) !== null && _blockInfo$node$conte3 !== void 0 ? _blockInfo$node$conte3 : 0) - 1;
|
|
393
470
|
|
|
394
|
-
//
|
|
395
|
-
if ((_this$
|
|
471
|
+
// 与上次同一单元格则跳过
|
|
472
|
+
if ((_this$state9 = this.state) !== null && _this$state9 !== void 0 && _this$state9.show && this.tableId === blockInfo.node.attrs.id && this.state.rowIndex === rowIndex && this.state.colIndex === colIndex) {
|
|
396
473
|
return;
|
|
397
474
|
}
|
|
398
475
|
|
|
399
|
-
//
|
|
476
|
+
// 计算扩展按钮位置
|
|
400
477
|
var _referencePosLastRow;
|
|
401
478
|
var _referencePosLastCol;
|
|
402
479
|
if (rowIndex === _lastRowIndex || colIndex === _lastColIndex) {
|
|
403
480
|
var _this$tableElement3;
|
|
404
481
|
var _tbody2 = (_this$tableElement3 = this.tableElement) === null || _this$tableElement3 === void 0 ? void 0 : _this$tableElement3.querySelector('tbody');
|
|
405
482
|
if (_tbody2) {
|
|
406
|
-
//
|
|
483
|
+
// 记录末行位置
|
|
407
484
|
if (rowIndex === _lastRowIndex) {
|
|
408
485
|
var _lastRow2 = _tbody2.children[_lastRowIndex];
|
|
409
486
|
if (_lastRow2) {
|
|
410
487
|
_referencePosLastRow = _lastRow2.getBoundingClientRect();
|
|
411
488
|
}
|
|
412
489
|
}
|
|
413
|
-
//
|
|
490
|
+
// 记录末列位置
|
|
414
491
|
if (colIndex === _lastColIndex) {
|
|
415
|
-
//
|
|
492
|
+
// 在所有行里取最右侧单元格
|
|
416
493
|
var _maxRight = 0;
|
|
417
494
|
var _lastColRect = null;
|
|
418
|
-
for (var
|
|
419
|
-
var _row = _tbody2.children[
|
|
495
|
+
for (var _i = 0; _i < _tbody2.children.length; _i++) {
|
|
496
|
+
var _row = _tbody2.children[_i];
|
|
420
497
|
if (_row && _row.children[_lastColIndex]) {
|
|
421
498
|
var _cell = _row.children[_lastColIndex];
|
|
422
499
|
var _cellRect2 = _cell.getBoundingClientRect();
|
|
@@ -427,13 +504,13 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
427
504
|
}
|
|
428
505
|
}
|
|
429
506
|
if (_lastColRect) {
|
|
430
|
-
//
|
|
507
|
+
// 生成代表整列的矩形
|
|
431
508
|
var _firstRow = _tbody2.children[0];
|
|
432
509
|
var _lastRow3 = _tbody2.children[_lastRowIndex];
|
|
433
510
|
if (_firstRow && _lastRow3) {
|
|
434
|
-
var
|
|
435
|
-
if (
|
|
436
|
-
var _firstRect =
|
|
511
|
+
var _firstCell2 = _firstRow.children[_lastColIndex];
|
|
512
|
+
if (_firstCell2) {
|
|
513
|
+
var _firstRect = _firstCell2.getBoundingClientRect();
|
|
437
514
|
_referencePosLastCol = new DOMRect(_lastColRect.right, _firstRect.top, 0, _lastRow3.getBoundingClientRect().bottom - _firstRect.top);
|
|
438
515
|
}
|
|
439
516
|
}
|
|
@@ -451,7 +528,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
451
528
|
block: blockInfo.node,
|
|
452
529
|
blockPos: blockInfo.pos,
|
|
453
530
|
draggingState: undefined,
|
|
454
|
-
referencePosCell:
|
|
531
|
+
referencePosCell: effectiveCellRect,
|
|
455
532
|
colIndex: colIndex,
|
|
456
533
|
rowIndex: rowIndex,
|
|
457
534
|
widgetContainer: widgetContainer
|
|
@@ -463,12 +540,12 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
463
540
|
}, {
|
|
464
541
|
key: "update",
|
|
465
542
|
value: function update(view) {
|
|
466
|
-
var _this$
|
|
543
|
+
var _this$state10, _this$tableElement4, _this$tableElement5;
|
|
467
544
|
var pluginState = tableHandlePluginKey.getState(view.state);
|
|
468
545
|
if (pluginState !== undefined && pluginState !== this.menuFrozen) {
|
|
469
546
|
this.menuFrozen = pluginState;
|
|
470
547
|
}
|
|
471
|
-
if (!((_this$
|
|
548
|
+
if (!((_this$state10 = this.state) !== null && _this$state10 !== void 0 && _this$state10.show)) return;
|
|
472
549
|
if (!((_this$tableElement4 = this.tableElement) !== null && _this$tableElement4 !== void 0 && _this$tableElement4.isConnected)) {
|
|
473
550
|
this.hideHandles();
|
|
474
551
|
return;
|
|
@@ -479,7 +556,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
479
556
|
return;
|
|
480
557
|
}
|
|
481
558
|
|
|
482
|
-
//
|
|
559
|
+
// 检查表格是否已变更
|
|
483
560
|
var blockChanged = this.state.block !== tableInfo.node || this.state.blockPos !== tableInfo.pos;
|
|
484
561
|
if (!tableInfo.node || tableInfo.node.type.name !== 'table' || !((_this$tableElement5 = this.tableElement) !== null && _this$tableElement5 !== void 0 && _this$tableElement5.isConnected)) {
|
|
485
562
|
this.hideHandles();
|
|
@@ -489,11 +566,11 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
489
566
|
rowCount = _TableMap$get.height,
|
|
490
567
|
colCount = _TableMap$get.width;
|
|
491
568
|
|
|
492
|
-
//
|
|
569
|
+
// 计算新的行列索引
|
|
493
570
|
var newRowIndex = this.state.rowIndex;
|
|
494
571
|
var newColIndex = this.state.colIndex;
|
|
495
572
|
|
|
496
|
-
//
|
|
573
|
+
// 若删除了行/列则裁剪索引
|
|
497
574
|
if (newRowIndex !== undefined && newRowIndex >= rowCount) {
|
|
498
575
|
newRowIndex = rowCount ? rowCount - 1 : undefined;
|
|
499
576
|
}
|
|
@@ -505,7 +582,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
505
582
|
throw new Error("Table block does not contain a 'tbody' HTML element. This should never happen.");
|
|
506
583
|
}
|
|
507
584
|
|
|
508
|
-
//
|
|
585
|
+
// 计算新的参考位置信息
|
|
509
586
|
var newReferencePosCell = this.state.referencePosCell;
|
|
510
587
|
if (newRowIndex !== undefined && newColIndex !== undefined) {
|
|
511
588
|
var rowEl = tableBody.children[newRowIndex];
|
|
@@ -513,7 +590,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
513
590
|
if (cellEl) {
|
|
514
591
|
var _this$state$draggingS2;
|
|
515
592
|
var newCellRect = cellEl.getBoundingClientRect();
|
|
516
|
-
//
|
|
593
|
+
// 拖拽时保持最初的单元格尺寸,避免高度抖动
|
|
517
594
|
if ((_this$state$draggingS2 = this.state.draggingState) !== null && _this$state$draggingS2 !== void 0 && _this$state$draggingS2.originalCellSize) {
|
|
518
595
|
newReferencePosCell = new DOMRect(newCellRect.x, newCellRect.y, this.state.draggingState.originalCellSize.width, this.state.draggingState.originalCellSize.height);
|
|
519
596
|
} else {
|
|
@@ -527,7 +604,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
527
604
|
}
|
|
528
605
|
var newReferencePosTable = tableBody.getBoundingClientRect();
|
|
529
606
|
|
|
530
|
-
//
|
|
607
|
+
// 如需显示扩展按钮则刷新末行末列位置
|
|
531
608
|
var newReferencePosLastRow = this.state.referencePosLastRow;
|
|
532
609
|
var newReferencePosLastCol = this.state.referencePosLastCol;
|
|
533
610
|
if (this.state.showAddOrRemoveRowsButton || this.state.showAddOrRemoveColumnsButton) {
|
|
@@ -568,7 +645,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
568
645
|
}
|
|
569
646
|
}
|
|
570
647
|
|
|
571
|
-
//
|
|
648
|
+
// 若任一关键数据变化则推送更新
|
|
572
649
|
var indicesChanged = newRowIndex !== this.state.rowIndex || newColIndex !== this.state.colIndex;
|
|
573
650
|
var refPosChanged = newReferencePosCell !== this.state.referencePosCell || newReferencePosTable !== this.state.referencePosTable || newReferencePosLastRow !== this.state.referencePosLastRow || newReferencePosLastCol !== this.state.referencePosLastCol;
|
|
574
651
|
if (blockChanged || indicesChanged || refPosChanged) {
|
|
@@ -588,15 +665,15 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
588
665
|
}, {
|
|
589
666
|
key: "updatePositions",
|
|
590
667
|
value: function updatePositions() {
|
|
591
|
-
var _this$
|
|
592
|
-
if (!((_this$
|
|
668
|
+
var _this$state11, _this$tableElement6;
|
|
669
|
+
if (!((_this$state11 = this.state) !== null && _this$state11 !== void 0 && _this$state11.show) || !((_this$tableElement6 = this.tableElement) !== null && _this$tableElement6 !== void 0 && _this$tableElement6.isConnected)) return;
|
|
593
670
|
var tableInfo = getTableFromDOM(this.tableElement, this.editor);
|
|
594
671
|
if (!tableInfo || tableInfo.node.type.name !== 'table') return;
|
|
595
672
|
var tableBody = this.tableElement.querySelector('tbody');
|
|
596
673
|
if (!tableBody) return;
|
|
597
674
|
var newReferencePosTable = tableBody.getBoundingClientRect();
|
|
598
675
|
|
|
599
|
-
//
|
|
676
|
+
// 若已有行列索引则同步单元格位置
|
|
600
677
|
var newReferencePosCell = this.state.referencePosCell;
|
|
601
678
|
if (this.state.rowIndex !== undefined && this.state.colIndex !== undefined) {
|
|
602
679
|
var rowEl = tableBody.children[this.state.rowIndex];
|
|
@@ -604,7 +681,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
604
681
|
if (cellEl) {
|
|
605
682
|
var _this$state$draggingS3;
|
|
606
683
|
var newCellRect = cellEl.getBoundingClientRect();
|
|
607
|
-
//
|
|
684
|
+
// 拖拽时保留初始尺寸
|
|
608
685
|
if ((_this$state$draggingS3 = this.state.draggingState) !== null && _this$state$draggingS3 !== void 0 && _this$state$draggingS3.originalCellSize) {
|
|
609
686
|
newReferencePosCell = new DOMRect(newCellRect.x, newCellRect.y, this.state.draggingState.originalCellSize.width, this.state.draggingState.originalCellSize.height);
|
|
610
687
|
} else {
|
|
@@ -613,7 +690,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
613
690
|
}
|
|
614
691
|
}
|
|
615
692
|
|
|
616
|
-
//
|
|
693
|
+
// 如需显示扩展按钮则刷新末行末列位置
|
|
617
694
|
var newReferencePosLastRow = this.state.referencePosLastRow;
|
|
618
695
|
var newReferencePosLastCol = this.state.referencePosLastCol;
|
|
619
696
|
if (this.state.showAddOrRemoveRowsButton || this.state.showAddOrRemoveColumnsButton) {
|
|
@@ -654,7 +731,7 @@ var TableHandleView = /*#__PURE__*/function () {
|
|
|
654
731
|
}
|
|
655
732
|
}
|
|
656
733
|
|
|
657
|
-
//
|
|
734
|
+
// 对比具体属性,确认位置是否发生变化
|
|
658
735
|
var refPosChanged = !newReferencePosCell || !this.state.referencePosCell || newReferencePosCell.x !== this.state.referencePosCell.x || newReferencePosCell.y !== this.state.referencePosCell.y || newReferencePosTable.x !== this.state.referencePosTable.x || newReferencePosTable.y !== this.state.referencePosTable.y || newReferencePosLastRow && this.state.referencePosLastRow && (newReferencePosLastRow.x !== this.state.referencePosLastRow.x || newReferencePosLastRow.y !== this.state.referencePosLastRow.y) || newReferencePosLastCol && this.state.referencePosLastCol && (newReferencePosLastCol.x !== this.state.referencePosLastCol.x || newReferencePosLastCol.y !== this.state.referencePosLastCol.y);
|
|
659
736
|
if (refPosChanged) {
|
|
660
737
|
this.state = _objectSpread(_objectSpread({}, this.state), {}, {
|
|
@@ -730,9 +807,7 @@ export function TableHandlePlugin(editor, emitUpdate) {
|
|
|
730
807
|
});
|
|
731
808
|
}
|
|
732
809
|
|
|
733
|
-
//
|
|
734
|
-
// - original index is same as new index (no change)
|
|
735
|
-
// - editor is not defined for some reason
|
|
810
|
+
// 若无变更或 editor 不存在,直接返回已有装饰
|
|
736
811
|
if (newIndex === originalIndex || !editor) {
|
|
737
812
|
return DecorationSet.create(state.doc, decorations);
|
|
738
813
|
}
|
|
@@ -744,9 +819,7 @@ export function TableHandlePlugin(editor, emitUpdate) {
|
|
|
744
819
|
return;
|
|
745
820
|
}
|
|
746
821
|
|
|
747
|
-
//
|
|
748
|
-
// depending on whether the new index is before or after the
|
|
749
|
-
// original index.
|
|
822
|
+
// 根据拖动方向在单元格首尾插入装饰
|
|
750
823
|
var decorationPos = cell.pos + (newIndex > originalIndex ? cellNode.nodeSize - 2 : 2);
|
|
751
824
|
decorations.push(Decoration.widget(decorationPos, function () {
|
|
752
825
|
var widget = document.createElement('div');
|
|
@@ -756,11 +829,7 @@ export function TableHandlePlugin(editor, emitUpdate) {
|
|
|
756
829
|
widget.style.right = '0';
|
|
757
830
|
widget.style.zIndex = '20';
|
|
758
831
|
widget.style.pointerEvents = 'none';
|
|
759
|
-
//
|
|
760
|
-
// is an even number of pixels, whereas the border between
|
|
761
|
-
// table cells is an odd number of pixels. So this makes the
|
|
762
|
-
// positioning slightly more consistent regardless of where
|
|
763
|
-
// the row is being dropped.
|
|
832
|
+
// 处理奇偶像素差,避免行插入指示线的视觉偏差
|
|
764
833
|
if (newIndex > originalIndex) {
|
|
765
834
|
widget.style.bottom = '-1px';
|
|
766
835
|
} else {
|
|
@@ -778,9 +847,7 @@ export function TableHandlePlugin(editor, emitUpdate) {
|
|
|
778
847
|
if (!cellNode) {
|
|
779
848
|
return;
|
|
780
849
|
}
|
|
781
|
-
//
|
|
782
|
-
// depending on whether the new index is before or after the
|
|
783
|
-
// original index.
|
|
850
|
+
// 根据拖动方向在单元格首尾插入装饰
|
|
784
851
|
var decorationPos = cell.pos + (newIndex > originalIndex ? cellNode.nodeSize - 2 : 2);
|
|
785
852
|
decorations.push(Decoration.widget(decorationPos, function () {
|
|
786
853
|
var widget = document.createElement('div');
|
|
@@ -790,11 +857,7 @@ export function TableHandlePlugin(editor, emitUpdate) {
|
|
|
790
857
|
widget.style.bottom = '0';
|
|
791
858
|
widget.style.zIndex = '20';
|
|
792
859
|
widget.style.pointerEvents = 'none';
|
|
793
|
-
//
|
|
794
|
-
// is an even number of pixels, whereas the border between
|
|
795
|
-
// table cells is an odd number of pixels. So this makes the
|
|
796
|
-
// positioning slightly more consistent regardless of where
|
|
797
|
-
// the column is being dropped.
|
|
860
|
+
// 处理奇偶像素差,避免列插入指示线的视觉偏差
|
|
798
861
|
if (newIndex > originalIndex) {
|
|
799
862
|
widget.style.right = '-1px';
|
|
800
863
|
} else {
|
|
@@ -812,17 +875,15 @@ export function TableHandlePlugin(editor, emitUpdate) {
|
|
|
812
875
|
});
|
|
813
876
|
}
|
|
814
877
|
|
|
815
|
-
/**
|
|
816
|
-
* Shared drag start handler for table rows and columns
|
|
817
|
-
*/
|
|
878
|
+
/** 行/列通用的拖拽起始处理 */
|
|
818
879
|
var tableDragStart = function tableDragStart(orientation, event) {
|
|
819
880
|
var _tableHandleView;
|
|
820
|
-
//
|
|
881
|
+
// 若状态不存在,尝试从 DOM 或 data 属性恢复
|
|
821
882
|
if (!((_tableHandleView = tableHandleView) !== null && _tableHandleView !== void 0 && _tableHandleView.state)) {
|
|
822
883
|
var _tableHandleView2, _tableHandleView3;
|
|
823
884
|
var handleElement = event.currentTarget;
|
|
824
885
|
|
|
825
|
-
//
|
|
886
|
+
// 优先使用组件写入的 data 属性恢复
|
|
826
887
|
var dataIndex = handleElement.dataset.tableIndex;
|
|
827
888
|
var dataTablePos = handleElement.dataset.tablePos;
|
|
828
889
|
var dataTableId = handleElement.dataset.tableId;
|
|
@@ -830,7 +891,7 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
830
891
|
var _index = parseInt(dataIndex, 10);
|
|
831
892
|
var _blockPos = parseInt(dataTablePos, 10);
|
|
832
893
|
if (!isNaN(_index) && !isNaN(_blockPos)) {
|
|
833
|
-
//
|
|
894
|
+
// 尝试找到对应表格节点
|
|
834
895
|
var tableNode = tableHandleView.editor.state.doc.nodeAt(_blockPos);
|
|
835
896
|
if (tableNode && isTableNode(tableNode)) {
|
|
836
897
|
var tableWrapper = safeClosest(handleElement, '.tableWrapper');
|
|
@@ -838,7 +899,7 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
838
899
|
if (tbody) {
|
|
839
900
|
var tableRect = tbody.getBoundingClientRect();
|
|
840
901
|
|
|
841
|
-
//
|
|
902
|
+
// 构造最小拖拽状态
|
|
842
903
|
var recoveredState = {
|
|
843
904
|
show: true,
|
|
844
905
|
showAddOrRemoveRowsButton: false,
|
|
@@ -857,18 +918,18 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
857
918
|
}
|
|
858
919
|
}
|
|
859
920
|
|
|
860
|
-
//
|
|
921
|
+
// 若仍无状态,再尝试基于 DOM 恢复
|
|
861
922
|
if (!((_tableHandleView2 = tableHandleView) !== null && _tableHandleView2 !== void 0 && _tableHandleView2.state)) {
|
|
862
923
|
var _tableWrapper = safeClosest(handleElement, '.tableWrapper');
|
|
863
924
|
if (!_tableWrapper || !tableHandleView) {
|
|
864
|
-
//
|
|
925
|
+
// 无法恢复则静默取消拖拽
|
|
865
926
|
if (event.dataTransfer) {
|
|
866
927
|
event.dataTransfer.effectAllowed = 'none';
|
|
867
928
|
}
|
|
868
929
|
return;
|
|
869
930
|
}
|
|
870
931
|
|
|
871
|
-
//
|
|
932
|
+
// 基于 DOM 获取表格信息
|
|
872
933
|
var tableInfo = getTableFromDOM(_tableWrapper, tableHandleView.editor);
|
|
873
934
|
if (!tableInfo) {
|
|
874
935
|
if (event.dataTransfer) {
|
|
@@ -877,7 +938,7 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
877
938
|
return;
|
|
878
939
|
}
|
|
879
940
|
|
|
880
|
-
//
|
|
941
|
+
// 构建基础状态
|
|
881
942
|
var _tbody3 = _tableWrapper.querySelector('tbody');
|
|
882
943
|
if (!_tbody3) {
|
|
883
944
|
if (event.dataTransfer) {
|
|
@@ -886,13 +947,11 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
886
947
|
return;
|
|
887
948
|
}
|
|
888
949
|
|
|
889
|
-
//
|
|
890
|
-
// This is a fallback - ideally state should exist
|
|
950
|
+
// 通过手柄位置估算索引(兜底方案)
|
|
891
951
|
var _tableRect = _tbody3.getBoundingClientRect();
|
|
892
952
|
var handleRect = handleElement.getBoundingClientRect();
|
|
893
953
|
|
|
894
|
-
//
|
|
895
|
-
// This is not perfect but better than throwing an error
|
|
954
|
+
// 通过坐标粗略推算索引,避免报错
|
|
896
955
|
var approximateIndex = 0;
|
|
897
956
|
if (orientation === 'row') {
|
|
898
957
|
var rowHeight = _tableRect.height / tableInfo.node.content.childCount;
|
|
@@ -903,7 +962,7 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
903
962
|
approximateIndex = Math.floor((handleRect.left - _tableRect.left) / colWidth);
|
|
904
963
|
}
|
|
905
964
|
|
|
906
|
-
//
|
|
965
|
+
// 构造最小拖拽状态
|
|
907
966
|
var _recoveredState = {
|
|
908
967
|
show: true,
|
|
909
968
|
showAddOrRemoveRowsButton: false,
|
|
@@ -919,7 +978,7 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
919
978
|
tableHandleView.state = _recoveredState;
|
|
920
979
|
}
|
|
921
980
|
|
|
922
|
-
//
|
|
981
|
+
// 最终仍无状态则取消拖拽
|
|
923
982
|
if (!((_tableHandleView3 = tableHandleView) !== null && _tableHandleView3 !== void 0 && _tableHandleView3.state)) {
|
|
924
983
|
if (event.dataTransfer) {
|
|
925
984
|
event.dataTransfer.effectAllowed = 'none';
|
|
@@ -932,7 +991,7 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
932
991
|
editor = _tableHandleView4.editor;
|
|
933
992
|
var index = orientation === 'col' ? state.colIndex : state.rowIndex;
|
|
934
993
|
if (index === undefined) {
|
|
935
|
-
//
|
|
994
|
+
// 无法确定索引,静默取消
|
|
936
995
|
if (event.dataTransfer) {
|
|
937
996
|
event.dataTransfer.effectAllowed = 'none';
|
|
938
997
|
}
|
|
@@ -942,14 +1001,14 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
942
1001
|
referencePosCell = state.referencePosCell;
|
|
943
1002
|
var mousePos = orientation === 'col' ? event.clientX : event.clientY;
|
|
944
1003
|
|
|
945
|
-
//
|
|
1004
|
+
// 清除单元格选区,避免表格引用塌缩
|
|
946
1005
|
if (editor.state.selection instanceof CellSelection) {
|
|
947
1006
|
var safeSel = TextSelection.near(editor.state.doc.resolve(blockPos), 1);
|
|
948
1007
|
editor.view.dispatch(editor.state.tr.setSelection(safeSel));
|
|
949
1008
|
}
|
|
950
1009
|
var dragImage = createTableDragImage(editor, orientation, index, blockPos);
|
|
951
1010
|
|
|
952
|
-
//
|
|
1011
|
+
// 配置拖拽预览图
|
|
953
1012
|
if (event.dataTransfer) {
|
|
954
1013
|
var _handleRect = event.currentTarget.getBoundingClientRect();
|
|
955
1014
|
var offset = orientation === 'col' ? {
|
|
@@ -963,7 +1022,7 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
963
1022
|
event.dataTransfer.setDragImage(dragImage, offset.x, offset.y);
|
|
964
1023
|
}
|
|
965
1024
|
|
|
966
|
-
//
|
|
1025
|
+
// 清理拖拽预览图
|
|
967
1026
|
var cleanup = function cleanup() {
|
|
968
1027
|
var _dragImage$parentNode;
|
|
969
1028
|
return (_dragImage$parentNode = dragImage.parentNode) === null || _dragImage$parentNode === void 0 ? void 0 : _dragImage$parentNode.removeChild(dragImage);
|
|
@@ -976,13 +1035,13 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
976
1035
|
});
|
|
977
1036
|
var initialOffset = referencePosCell ? (orientation === 'col' ? referencePosCell.left : referencePosCell.top) - mousePos : 0;
|
|
978
1037
|
|
|
979
|
-
//
|
|
1038
|
+
// 记录原始单元格尺寸,拖拽中保持不变
|
|
980
1039
|
var originalCellSize = referencePosCell ? {
|
|
981
1040
|
width: referencePosCell.width,
|
|
982
1041
|
height: referencePosCell.height
|
|
983
1042
|
} : undefined;
|
|
984
1043
|
|
|
985
|
-
//
|
|
1044
|
+
// 写回拖拽状态
|
|
986
1045
|
tableHandleView.state = _objectSpread(_objectSpread({}, state), {}, {
|
|
987
1046
|
draggingState: {
|
|
988
1047
|
draggedCellOrientation: orientation,
|
|
@@ -996,27 +1055,21 @@ var tableDragStart = function tableDragStart(orientation, event) {
|
|
|
996
1055
|
editor.view.dispatch(editor.state.tr.setMeta(tableHandlePluginKey, true));
|
|
997
1056
|
};
|
|
998
1057
|
|
|
999
|
-
/**
|
|
1000
|
-
* Callback for column drag handle
|
|
1001
|
-
*/
|
|
1058
|
+
/** 列拖拽句柄回调 */
|
|
1002
1059
|
export var colDragStart = function colDragStart(event) {
|
|
1003
1060
|
return tableDragStart('col', _objectSpread(_objectSpread({}, event), {}, {
|
|
1004
1061
|
clientY: 0
|
|
1005
1062
|
}));
|
|
1006
1063
|
};
|
|
1007
1064
|
|
|
1008
|
-
/**
|
|
1009
|
-
* Callback for row drag handle
|
|
1010
|
-
*/
|
|
1065
|
+
/** 行拖拽句柄回调 */
|
|
1011
1066
|
export var rowDragStart = function rowDragStart(event) {
|
|
1012
1067
|
return tableDragStart('row', _objectSpread(_objectSpread({}, event), {}, {
|
|
1013
1068
|
clientX: 0
|
|
1014
1069
|
}));
|
|
1015
1070
|
};
|
|
1016
1071
|
|
|
1017
|
-
/**
|
|
1018
|
-
* Drag end cleanup
|
|
1019
|
-
*/
|
|
1072
|
+
/** 拖拽结束后的清理 */
|
|
1020
1073
|
export var dragEnd = function dragEnd() {
|
|
1021
1074
|
if (!tableHandleView || tableHandleView.state === undefined) {
|
|
1022
1075
|
return;
|