@kdcloudjs/table 1.2.2-canary.4 → 1.2.2-canary.6
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/@kdcloudjs/table.css +1 -1
- package/dist/@kdcloudjs/table.js +160 -87
- package/dist/@kdcloudjs/table.js.map +1 -1
- package/dist/@kdcloudjs/table.min.css +1 -1
- package/dist/@kdcloudjs/table.min.js +6 -6
- package/dist/@kdcloudjs/table.min.js.map +1 -1
- package/es/table/base/styles.d.ts +1 -0
- package/es/table/base/styles.js +2 -1
- package/es/table/pipeline/features/rowDrag.js +123 -55
- package/lib/table/base/styles.d.ts +1 -0
- package/lib/table/base/styles.js +2 -1
- package/lib/table/pipeline/features/rowDrag.js +123 -55
- package/package.json +1 -1
|
@@ -81,7 +81,7 @@ function rowDrag(opt) {
|
|
|
81
81
|
var isLeave = !isMouseOnDropTarget(event, dropZoneTarget);
|
|
82
82
|
var overIndex = -1;
|
|
83
83
|
var direction = 'bottom';
|
|
84
|
-
if (!isLeave) {
|
|
84
|
+
if (!isLeave && dataSource.length > 0) {
|
|
85
85
|
var overDragItem = getDragRowItem(event.target, dropZoneTarget, dataSource);
|
|
86
86
|
if (overDragItem) {
|
|
87
87
|
var rowIndex = overDragItem.rowIndex,
|
|
@@ -90,6 +90,10 @@ function rowDrag(opt) {
|
|
|
90
90
|
direction = getDirection(cell, event.clientY, allowDragIntoRow);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
+
if (overIndex === -1 && dataSource.length > 0 && dropZoneTarget.contains(event.target)) {
|
|
94
|
+
overIndex = dataSource.length - 1;
|
|
95
|
+
direction = 'bottom';
|
|
96
|
+
}
|
|
93
97
|
var overRow = overIndex >= 0 ? dataSource[overIndex] : null;
|
|
94
98
|
return {
|
|
95
99
|
startRowIndex: dragItem.rowIndex,
|
|
@@ -184,6 +188,7 @@ function rowDrag(opt) {
|
|
|
184
188
|
if (intervalId) {
|
|
185
189
|
clearInterval(intervalId);
|
|
186
190
|
}
|
|
191
|
+
if (!tableBody) return;
|
|
187
192
|
var moveOffset = getScrollMoveOffset(tableBody, mouseMoveEvent);
|
|
188
193
|
if (moveOffset === 0) {
|
|
189
194
|
return;
|
|
@@ -216,12 +221,14 @@ function rowDrag(opt) {
|
|
|
216
221
|
var dropTarget = (0, _find.default)(validDropZones).call(validDropZones, function (zone) {
|
|
217
222
|
return isMouseOnDropTarget(mouseMoveEvent, zone.getContainer());
|
|
218
223
|
}) || null;
|
|
224
|
+
updateScrollPosition(dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.getContainer(), mouseMoveEvent); // 拖拽到底时让滚动条可以滚动
|
|
219
225
|
if (dropTarget !== lastDropTarget) {
|
|
220
226
|
// 拖拽离开表格
|
|
221
227
|
if (lastDropTarget !== null && dropTarget === null) {
|
|
222
228
|
if (lastDropTarget.onDragLeave) {
|
|
223
229
|
setDragElementIcon(dragElement, 'notAllowed');
|
|
224
230
|
hiddenDragLine(dragLine);
|
|
231
|
+
lastDropTarget.getContainer().classList.remove(_styles.Classes.rowDragNoData);
|
|
225
232
|
var dragEvent = createDropTargetEvent(lastDropTarget, mouseMoveEvent, startDataItem, currentDropZone);
|
|
226
233
|
lastDropTarget.onDragLeave(dragEvent);
|
|
227
234
|
}
|
|
@@ -247,7 +254,6 @@ function rowDrag(opt) {
|
|
|
247
254
|
dragZone: dropTarget,
|
|
248
255
|
event: mouseMoveEvent
|
|
249
256
|
});
|
|
250
|
-
updateScrollPosition(dropTarget.getContainer(), mouseMoveEvent); // 拖拽到底时让滚动条可以滚动
|
|
251
257
|
}
|
|
252
258
|
// 树形表格悬停1s展开对应行节点
|
|
253
259
|
if ((_a = dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.tableParams) === null || _a === void 0 ? void 0 : _a.getTreeModeOptions()) {
|
|
@@ -293,6 +299,10 @@ function rowDrag(opt) {
|
|
|
293
299
|
callback();
|
|
294
300
|
}
|
|
295
301
|
var rowDropZones = rowDragApi.getRowDropZone();
|
|
302
|
+
rowDropZones.forEach(function (dropzone) {
|
|
303
|
+
var container = dropzone.getContainer();
|
|
304
|
+
container && container.classList.remove(_styles.Classes.rowDragNoData);
|
|
305
|
+
});
|
|
296
306
|
var validDropZones = (0, _concat.default)(rowDropZones).call(rowDropZones, currentDropZone);
|
|
297
307
|
var dropTarget = (0, _find.default)(validDropZones).call(validDropZones, function (zone) {
|
|
298
308
|
return isMouseOnDropTarget(mouseUpEvent, zone.getContainer());
|
|
@@ -431,6 +441,7 @@ function createDragLine(isTreeTable) {
|
|
|
431
441
|
return dragLine;
|
|
432
442
|
}
|
|
433
443
|
function positionDragLine(_ref) {
|
|
444
|
+
var _context7;
|
|
434
445
|
var lineElement = _ref.lineElement,
|
|
435
446
|
dragZone = _ref.dragZone,
|
|
436
447
|
event = _ref.event;
|
|
@@ -443,62 +454,69 @@ function positionDragLine(_ref) {
|
|
|
443
454
|
var treeModeOptions = getTreeModeOptions();
|
|
444
455
|
var rowDragOptions = getRowDragOptions() || {};
|
|
445
456
|
var allowDragIntoRow = rowDragOptions.allowDragIntoRow;
|
|
457
|
+
var isTreeTable = !!treeModeOptions;
|
|
458
|
+
var bodyRect = tableContainer.getBoundingClientRect();
|
|
459
|
+
var offsetParentSize = getElementRectWithOffset(document.body);
|
|
460
|
+
if (dataSource.length === 0) {
|
|
461
|
+
tableContainer.classList.add(_styles.Classes.rowDragNoData);
|
|
462
|
+
lineElement.style.display = 'none';
|
|
463
|
+
} else {
|
|
464
|
+
tableContainer.classList.remove(_styles.Classes.rowDragNoData);
|
|
465
|
+
lineElement.style.display = 'block';
|
|
466
|
+
}
|
|
446
467
|
// 鼠标悬停所在的拖拽行信息
|
|
447
468
|
var dragItem = getDragRowItem(event.target, tableContainer, dataSource);
|
|
448
|
-
if (!dragItem)
|
|
469
|
+
if (!dragItem) {
|
|
470
|
+
if (dataSource.length > 0 && tableContainer.contains(event.target)) {
|
|
471
|
+
var _context5, _context6;
|
|
472
|
+
var _rowIndex = dataSource.length - 1;
|
|
473
|
+
var _row = dataSource[_rowIndex];
|
|
474
|
+
var _direction = 'bottom';
|
|
475
|
+
var _targetCell = isTreeTable ? tableContainer.querySelector((0, _concat.default)(_context5 = "tr[data-rowindex=\"".concat(_rowIndex, "\"] .")).call(_context5, _styles.Classes.tableExtendCell)) : tableContainer.querySelector((0, _concat.default)(_context6 = "tr[data-rowindex=\"".concat(_rowIndex, "\"] .")).call(_context6, _styles.Classes.rowDragCell));
|
|
476
|
+
if (!_targetCell) return;
|
|
477
|
+
var _getLinePosition = getLinePosition({
|
|
478
|
+
treeModeOptions: treeModeOptions,
|
|
479
|
+
cell: _targetCell,
|
|
480
|
+
row: _row,
|
|
481
|
+
direction: _direction,
|
|
482
|
+
offsetParentSize: offsetParentSize,
|
|
483
|
+
bodyRect: bodyRect
|
|
484
|
+
}),
|
|
485
|
+
_top = _getLinePosition.top,
|
|
486
|
+
_left = _getLinePosition.left,
|
|
487
|
+
_width = _getLinePosition.width;
|
|
488
|
+
lineElement.style.left = "".concat(_left, "px");
|
|
489
|
+
lineElement.style.top = "".concat(_top, "px");
|
|
490
|
+
lineElement.style.width = "".concat(_width, "px");
|
|
491
|
+
}
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
449
494
|
var cell = dragItem.cell,
|
|
450
495
|
rowIndex = dragItem.rowIndex,
|
|
451
496
|
row = dragItem.row;
|
|
452
|
-
var bodyRect = tableContainer.getBoundingClientRect();
|
|
453
|
-
var offsetParentSize = getElementRectWithOffset(document.body);
|
|
454
|
-
var isTreeTable = !!treeModeOptions;
|
|
455
497
|
var allowDragInto = isTreeTable && allowDragIntoRow;
|
|
456
498
|
var direction = getDirection(cell, event.clientY, allowDragInto);
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
rowKey = _row$treeMetaKey.rowKey,
|
|
471
|
-
depth = _row$treeMetaKey.depth,
|
|
472
|
-
isLeaf = _row$treeMetaKey.isLeaf,
|
|
473
|
-
expanded = _row$treeMetaKey.expanded;
|
|
474
|
-
var addWidth = isLeaf ? iconWidth + iconGap : 0;
|
|
475
|
-
var indent = iconIndent + depth * indentSize + addWidth;
|
|
476
|
-
var x = expandCellRect.x,
|
|
477
|
-
_y = expandCellRect.y,
|
|
478
|
-
_height = expandCellRect.height;
|
|
479
|
-
var _top = direction === 'bottom' ? _y + _height - offsetParentSize.top : _y - offsetParentSize.top;
|
|
480
|
-
var offsetX = Math.max(x + paddingLeft + indent - bodyRect.x, 0);
|
|
481
|
-
var _left = bodyRect.x + offsetX - offsetParentSize.left;
|
|
482
|
-
lineElement.style.left = "".concat(_left, "px");
|
|
483
|
-
lineElement.style.top = "".concat(_top, "px");
|
|
484
|
-
lineElement.style.width = "".concat(bodyRect.width - offsetX, "px");
|
|
485
|
-
if (direction === 'into') {
|
|
486
|
-
lineElement.style.display = 'none';
|
|
487
|
-
} else {
|
|
488
|
-
lineElement.style.display = 'block';
|
|
489
|
-
}
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
// 根据鼠标悬停位置所在单元格和显示位置计算拖拽线的位置
|
|
494
|
-
var rect = cell.getBoundingClientRect();
|
|
495
|
-
var y = rect.y,
|
|
496
|
-
height = rect.height;
|
|
497
|
-
var top = direction === 'bottom' ? y + height - offsetParentSize.top : y - offsetParentSize.top;
|
|
498
|
-
var left = bodyRect.x - offsetParentSize.left;
|
|
499
|
+
var targetCell = isTreeTable ? tableContainer.querySelector((0, _concat.default)(_context7 = "tr[data-rowindex=\"".concat(rowIndex, "\"] .")).call(_context7, _styles.Classes.tableExtendCell)) : cell;
|
|
500
|
+
if (!targetCell) return;
|
|
501
|
+
var _getLinePosition2 = getLinePosition({
|
|
502
|
+
treeModeOptions: treeModeOptions,
|
|
503
|
+
cell: targetCell,
|
|
504
|
+
row: row,
|
|
505
|
+
direction: direction,
|
|
506
|
+
offsetParentSize: offsetParentSize,
|
|
507
|
+
bodyRect: bodyRect
|
|
508
|
+
}),
|
|
509
|
+
top = _getLinePosition2.top,
|
|
510
|
+
left = _getLinePosition2.left,
|
|
511
|
+
width = _getLinePosition2.width;
|
|
499
512
|
lineElement.style.left = "".concat(left, "px");
|
|
500
513
|
lineElement.style.top = "".concat(top, "px");
|
|
501
|
-
lineElement.style.width = "".concat(
|
|
514
|
+
lineElement.style.width = "".concat(width, "px");
|
|
515
|
+
if (direction === 'into') {
|
|
516
|
+
lineElement.style.display = 'none';
|
|
517
|
+
} else {
|
|
518
|
+
lineElement.style.display = 'block';
|
|
519
|
+
}
|
|
502
520
|
}
|
|
503
521
|
function showDragLine(lineElement) {
|
|
504
522
|
lineElement.style.display = 'block';
|
|
@@ -531,11 +549,11 @@ function positionDragElemment(element, event) {
|
|
|
531
549
|
}
|
|
532
550
|
function getElementRectWithOffset(el) {
|
|
533
551
|
var offsetElementRect = el.getBoundingClientRect();
|
|
534
|
-
var
|
|
535
|
-
borderTopWidth =
|
|
536
|
-
borderLeftWidth =
|
|
537
|
-
borderRightWidth =
|
|
538
|
-
borderBottomWidth =
|
|
552
|
+
var _getElementSize2 = _getElementSize(el),
|
|
553
|
+
borderTopWidth = _getElementSize2.borderTopWidth,
|
|
554
|
+
borderLeftWidth = _getElementSize2.borderLeftWidth,
|
|
555
|
+
borderRightWidth = _getElementSize2.borderRightWidth,
|
|
556
|
+
borderBottomWidth = _getElementSize2.borderBottomWidth;
|
|
539
557
|
return {
|
|
540
558
|
top: offsetElementRect.top + (borderTopWidth || 0),
|
|
541
559
|
left: offsetElementRect.left + (borderLeftWidth || 0),
|
|
@@ -661,4 +679,54 @@ function getDirection(cell, clientY) {
|
|
|
661
679
|
direction = 'top';
|
|
662
680
|
}
|
|
663
681
|
return direction;
|
|
664
|
-
}
|
|
682
|
+
}
|
|
683
|
+
var getLinePosition = function getLinePosition(_ref2) {
|
|
684
|
+
var treeModeOptions = _ref2.treeModeOptions,
|
|
685
|
+
cell = _ref2.cell,
|
|
686
|
+
row = _ref2.row,
|
|
687
|
+
direction = _ref2.direction,
|
|
688
|
+
offsetParentSize = _ref2.offsetParentSize,
|
|
689
|
+
bodyRect = _ref2.bodyRect;
|
|
690
|
+
var isTreeTable = !!treeModeOptions;
|
|
691
|
+
if (isTreeTable) {
|
|
692
|
+
var iconWidth = treeModeOptions.iconWidth,
|
|
693
|
+
iconIndent = treeModeOptions.iconIndent,
|
|
694
|
+
iconGap = treeModeOptions.iconGap,
|
|
695
|
+
indentSize = treeModeOptions.indentSize,
|
|
696
|
+
treeMetaKey = treeModeOptions.treeMetaKey;
|
|
697
|
+
var _getElementSize3 = _getElementSize(cell),
|
|
698
|
+
paddingLeft = _getElementSize3.paddingLeft;
|
|
699
|
+
var expandCellRect = cell.getBoundingClientRect();
|
|
700
|
+
var _row$treeMetaKey = row[treeMetaKey],
|
|
701
|
+
rowKey = _row$treeMetaKey.rowKey,
|
|
702
|
+
depth = _row$treeMetaKey.depth,
|
|
703
|
+
isLeaf = _row$treeMetaKey.isLeaf,
|
|
704
|
+
expanded = _row$treeMetaKey.expanded;
|
|
705
|
+
var addWidth = isLeaf ? iconWidth + iconGap : 0;
|
|
706
|
+
var indent = iconIndent + depth * indentSize + addWidth;
|
|
707
|
+
var x = expandCellRect.x,
|
|
708
|
+
_y = expandCellRect.y,
|
|
709
|
+
_height = expandCellRect.height;
|
|
710
|
+
var _top2 = direction === 'bottom' ? _y + _height - offsetParentSize.top : _y - offsetParentSize.top;
|
|
711
|
+
var offsetX = Math.max(x + paddingLeft + indent - bodyRect.x, 0);
|
|
712
|
+
var _left2 = bodyRect.x + offsetX - offsetParentSize.left;
|
|
713
|
+
var _width2 = bodyRect.width - offsetX;
|
|
714
|
+
return {
|
|
715
|
+
top: _top2,
|
|
716
|
+
left: _left2,
|
|
717
|
+
width: _width2
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
// 根据鼠标悬停位置所在单元格和显示位置计算拖拽线的位置
|
|
721
|
+
var rect = cell.getBoundingClientRect();
|
|
722
|
+
var y = rect.y,
|
|
723
|
+
height = rect.height;
|
|
724
|
+
var top = direction === 'bottom' ? y + height - offsetParentSize.top : y - offsetParentSize.top;
|
|
725
|
+
var left = bodyRect.x - offsetParentSize.left;
|
|
726
|
+
var width = bodyRect.width;
|
|
727
|
+
return {
|
|
728
|
+
top: top,
|
|
729
|
+
left: left,
|
|
730
|
+
width: width
|
|
731
|
+
};
|
|
732
|
+
};
|