@kdcloudjs/table 1.2.2-canary.5 → 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.
@@ -79,7 +79,7 @@ export function rowDrag(opt) {
79
79
  direction = getDirection(cell, event.clientY, allowDragIntoRow);
80
80
  }
81
81
  }
82
- if (overIndex === -1 && dataSource.length > 0 && event.target === dropZoneTarget) {
82
+ if (overIndex === -1 && dataSource.length > 0 && dropZoneTarget.contains(event.target)) {
83
83
  overIndex = dataSource.length - 1;
84
84
  direction = 'bottom';
85
85
  }
@@ -430,6 +430,7 @@ function createDragLine(isTreeTable) {
430
430
  return dragLine;
431
431
  }
432
432
  function positionDragLine(_ref) {
433
+ var _context7;
433
434
  var lineElement = _ref.lineElement,
434
435
  dragZone = _ref.dragZone,
435
436
  event = _ref.event;
@@ -442,6 +443,9 @@ function positionDragLine(_ref) {
442
443
  var treeModeOptions = getTreeModeOptions();
443
444
  var rowDragOptions = getRowDragOptions() || {};
444
445
  var allowDragIntoRow = rowDragOptions.allowDragIntoRow;
446
+ var isTreeTable = !!treeModeOptions;
447
+ var bodyRect = tableContainer.getBoundingClientRect();
448
+ var offsetParentSize = getElementRectWithOffset(document.body);
445
449
  if (dataSource.length === 0) {
446
450
  tableContainer.classList.add(Classes.rowDragNoData);
447
451
  lineElement.style.display = 'none';
@@ -451,60 +455,57 @@ function positionDragLine(_ref) {
451
455
  }
452
456
  // 鼠标悬停所在的拖拽行信息
453
457
  var dragItem = getDragRowItem(event.target, tableContainer, dataSource);
454
- if (!dragItem) return;
458
+ if (!dragItem) {
459
+ if (dataSource.length > 0 && tableContainer.contains(event.target)) {
460
+ var _context5, _context6;
461
+ var _rowIndex = dataSource.length - 1;
462
+ var _row = dataSource[_rowIndex];
463
+ var _direction = 'bottom';
464
+ var _targetCell = isTreeTable ? tableContainer.querySelector(_concatInstanceProperty(_context5 = "tr[data-rowindex=\"".concat(_rowIndex, "\"] .")).call(_context5, Classes.tableExtendCell)) : tableContainer.querySelector(_concatInstanceProperty(_context6 = "tr[data-rowindex=\"".concat(_rowIndex, "\"] .")).call(_context6, Classes.rowDragCell));
465
+ if (!_targetCell) return;
466
+ var _getLinePosition = getLinePosition({
467
+ treeModeOptions: treeModeOptions,
468
+ cell: _targetCell,
469
+ row: _row,
470
+ direction: _direction,
471
+ offsetParentSize: offsetParentSize,
472
+ bodyRect: bodyRect
473
+ }),
474
+ _top = _getLinePosition.top,
475
+ _left = _getLinePosition.left,
476
+ _width = _getLinePosition.width;
477
+ lineElement.style.left = "".concat(_left, "px");
478
+ lineElement.style.top = "".concat(_top, "px");
479
+ lineElement.style.width = "".concat(_width, "px");
480
+ }
481
+ return;
482
+ }
455
483
  var cell = dragItem.cell,
456
484
  rowIndex = dragItem.rowIndex,
457
485
  row = dragItem.row;
458
- var bodyRect = tableContainer.getBoundingClientRect();
459
- var offsetParentSize = getElementRectWithOffset(document.body);
460
- var isTreeTable = !!treeModeOptions;
461
486
  var allowDragInto = isTreeTable && allowDragIntoRow;
462
487
  var direction = getDirection(cell, event.clientY, allowDragInto);
463
- if (isTreeTable) {
464
- var _context5;
465
- var iconWidth = treeModeOptions.iconWidth,
466
- iconIndent = treeModeOptions.iconIndent,
467
- iconGap = treeModeOptions.iconGap,
468
- indentSize = treeModeOptions.indentSize,
469
- treeMetaKey = treeModeOptions.treeMetaKey;
470
- var expandCell = tableContainer.querySelector(_concatInstanceProperty(_context5 = "tr[data-rowindex=\"".concat(rowIndex, "\"] .")).call(_context5, Classes.tableExtendCell));
471
- if (expandCell) {
472
- var _getElementSize2 = _getElementSize(expandCell),
473
- paddingLeft = _getElementSize2.paddingLeft;
474
- var expandCellRect = expandCell.getBoundingClientRect();
475
- var _row$treeMetaKey = row[treeMetaKey],
476
- rowKey = _row$treeMetaKey.rowKey,
477
- depth = _row$treeMetaKey.depth,
478
- isLeaf = _row$treeMetaKey.isLeaf,
479
- expanded = _row$treeMetaKey.expanded;
480
- var addWidth = isLeaf ? iconWidth + iconGap : 0;
481
- var indent = iconIndent + depth * indentSize + addWidth;
482
- var x = expandCellRect.x,
483
- _y = expandCellRect.y,
484
- _height = expandCellRect.height;
485
- var _top = direction === 'bottom' ? _y + _height - offsetParentSize.top : _y - offsetParentSize.top;
486
- var offsetX = Math.max(x + paddingLeft + indent - bodyRect.x, 0);
487
- var _left = bodyRect.x + offsetX - offsetParentSize.left;
488
- lineElement.style.left = "".concat(_left, "px");
489
- lineElement.style.top = "".concat(_top, "px");
490
- lineElement.style.width = "".concat(bodyRect.width - offsetX, "px");
491
- if (direction === 'into') {
492
- lineElement.style.display = 'none';
493
- } else {
494
- lineElement.style.display = 'block';
495
- }
496
- return;
497
- }
498
- }
499
- // 根据鼠标悬停位置所在单元格和显示位置计算拖拽线的位置
500
- var rect = cell.getBoundingClientRect();
501
- var y = rect.y,
502
- height = rect.height;
503
- var top = direction === 'bottom' ? y + height - offsetParentSize.top : y - offsetParentSize.top;
504
- var left = bodyRect.x - offsetParentSize.left;
488
+ var targetCell = isTreeTable ? tableContainer.querySelector(_concatInstanceProperty(_context7 = "tr[data-rowindex=\"".concat(rowIndex, "\"] .")).call(_context7, Classes.tableExtendCell)) : cell;
489
+ if (!targetCell) return;
490
+ var _getLinePosition2 = getLinePosition({
491
+ treeModeOptions: treeModeOptions,
492
+ cell: targetCell,
493
+ row: row,
494
+ direction: direction,
495
+ offsetParentSize: offsetParentSize,
496
+ bodyRect: bodyRect
497
+ }),
498
+ top = _getLinePosition2.top,
499
+ left = _getLinePosition2.left,
500
+ width = _getLinePosition2.width;
505
501
  lineElement.style.left = "".concat(left, "px");
506
502
  lineElement.style.top = "".concat(top, "px");
507
- lineElement.style.width = "".concat(bodyRect.width, "px");
503
+ lineElement.style.width = "".concat(width, "px");
504
+ if (direction === 'into') {
505
+ lineElement.style.display = 'none';
506
+ } else {
507
+ lineElement.style.display = 'block';
508
+ }
508
509
  }
509
510
  function showDragLine(lineElement) {
510
511
  lineElement.style.display = 'block';
@@ -537,11 +538,11 @@ function positionDragElemment(element, event) {
537
538
  }
538
539
  function getElementRectWithOffset(el) {
539
540
  var offsetElementRect = el.getBoundingClientRect();
540
- var _getElementSize3 = _getElementSize(el),
541
- borderTopWidth = _getElementSize3.borderTopWidth,
542
- borderLeftWidth = _getElementSize3.borderLeftWidth,
543
- borderRightWidth = _getElementSize3.borderRightWidth,
544
- borderBottomWidth = _getElementSize3.borderBottomWidth;
541
+ var _getElementSize2 = _getElementSize(el),
542
+ borderTopWidth = _getElementSize2.borderTopWidth,
543
+ borderLeftWidth = _getElementSize2.borderLeftWidth,
544
+ borderRightWidth = _getElementSize2.borderRightWidth,
545
+ borderBottomWidth = _getElementSize2.borderBottomWidth;
545
546
  return {
546
547
  top: offsetElementRect.top + (borderTopWidth || 0),
547
548
  left: offsetElementRect.left + (borderLeftWidth || 0),
@@ -667,4 +668,54 @@ function getDirection(cell, clientY) {
667
668
  direction = 'top';
668
669
  }
669
670
  return direction;
670
- }
671
+ }
672
+ var getLinePosition = function getLinePosition(_ref2) {
673
+ var treeModeOptions = _ref2.treeModeOptions,
674
+ cell = _ref2.cell,
675
+ row = _ref2.row,
676
+ direction = _ref2.direction,
677
+ offsetParentSize = _ref2.offsetParentSize,
678
+ bodyRect = _ref2.bodyRect;
679
+ var isTreeTable = !!treeModeOptions;
680
+ if (isTreeTable) {
681
+ var iconWidth = treeModeOptions.iconWidth,
682
+ iconIndent = treeModeOptions.iconIndent,
683
+ iconGap = treeModeOptions.iconGap,
684
+ indentSize = treeModeOptions.indentSize,
685
+ treeMetaKey = treeModeOptions.treeMetaKey;
686
+ var _getElementSize3 = _getElementSize(cell),
687
+ paddingLeft = _getElementSize3.paddingLeft;
688
+ var expandCellRect = cell.getBoundingClientRect();
689
+ var _row$treeMetaKey = row[treeMetaKey],
690
+ rowKey = _row$treeMetaKey.rowKey,
691
+ depth = _row$treeMetaKey.depth,
692
+ isLeaf = _row$treeMetaKey.isLeaf,
693
+ expanded = _row$treeMetaKey.expanded;
694
+ var addWidth = isLeaf ? iconWidth + iconGap : 0;
695
+ var indent = iconIndent + depth * indentSize + addWidth;
696
+ var x = expandCellRect.x,
697
+ _y = expandCellRect.y,
698
+ _height = expandCellRect.height;
699
+ var _top2 = direction === 'bottom' ? _y + _height - offsetParentSize.top : _y - offsetParentSize.top;
700
+ var offsetX = Math.max(x + paddingLeft + indent - bodyRect.x, 0);
701
+ var _left2 = bodyRect.x + offsetX - offsetParentSize.left;
702
+ var _width2 = bodyRect.width - offsetX;
703
+ return {
704
+ top: _top2,
705
+ left: _left2,
706
+ width: _width2
707
+ };
708
+ }
709
+ // 根据鼠标悬停位置所在单元格和显示位置计算拖拽线的位置
710
+ var rect = cell.getBoundingClientRect();
711
+ var y = rect.y,
712
+ height = rect.height;
713
+ var top = direction === 'bottom' ? y + height - offsetParentSize.top : y - offsetParentSize.top;
714
+ var left = bodyRect.x - offsetParentSize.left;
715
+ var width = bodyRect.width;
716
+ return {
717
+ top: top,
718
+ left: left,
719
+ width: width
720
+ };
721
+ };
@@ -90,7 +90,7 @@ function rowDrag(opt) {
90
90
  direction = getDirection(cell, event.clientY, allowDragIntoRow);
91
91
  }
92
92
  }
93
- if (overIndex === -1 && dataSource.length > 0 && event.target === dropZoneTarget) {
93
+ if (overIndex === -1 && dataSource.length > 0 && dropZoneTarget.contains(event.target)) {
94
94
  overIndex = dataSource.length - 1;
95
95
  direction = 'bottom';
96
96
  }
@@ -441,6 +441,7 @@ function createDragLine(isTreeTable) {
441
441
  return dragLine;
442
442
  }
443
443
  function positionDragLine(_ref) {
444
+ var _context7;
444
445
  var lineElement = _ref.lineElement,
445
446
  dragZone = _ref.dragZone,
446
447
  event = _ref.event;
@@ -453,6 +454,9 @@ function positionDragLine(_ref) {
453
454
  var treeModeOptions = getTreeModeOptions();
454
455
  var rowDragOptions = getRowDragOptions() || {};
455
456
  var allowDragIntoRow = rowDragOptions.allowDragIntoRow;
457
+ var isTreeTable = !!treeModeOptions;
458
+ var bodyRect = tableContainer.getBoundingClientRect();
459
+ var offsetParentSize = getElementRectWithOffset(document.body);
456
460
  if (dataSource.length === 0) {
457
461
  tableContainer.classList.add(_styles.Classes.rowDragNoData);
458
462
  lineElement.style.display = 'none';
@@ -462,60 +466,57 @@ function positionDragLine(_ref) {
462
466
  }
463
467
  // 鼠标悬停所在的拖拽行信息
464
468
  var dragItem = getDragRowItem(event.target, tableContainer, dataSource);
465
- if (!dragItem) return;
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
+ }
466
494
  var cell = dragItem.cell,
467
495
  rowIndex = dragItem.rowIndex,
468
496
  row = dragItem.row;
469
- var bodyRect = tableContainer.getBoundingClientRect();
470
- var offsetParentSize = getElementRectWithOffset(document.body);
471
- var isTreeTable = !!treeModeOptions;
472
497
  var allowDragInto = isTreeTable && allowDragIntoRow;
473
498
  var direction = getDirection(cell, event.clientY, allowDragInto);
474
- if (isTreeTable) {
475
- var _context5;
476
- var iconWidth = treeModeOptions.iconWidth,
477
- iconIndent = treeModeOptions.iconIndent,
478
- iconGap = treeModeOptions.iconGap,
479
- indentSize = treeModeOptions.indentSize,
480
- treeMetaKey = treeModeOptions.treeMetaKey;
481
- var expandCell = tableContainer.querySelector((0, _concat.default)(_context5 = "tr[data-rowindex=\"".concat(rowIndex, "\"] .")).call(_context5, _styles.Classes.tableExtendCell));
482
- if (expandCell) {
483
- var _getElementSize2 = _getElementSize(expandCell),
484
- paddingLeft = _getElementSize2.paddingLeft;
485
- var expandCellRect = expandCell.getBoundingClientRect();
486
- var _row$treeMetaKey = row[treeMetaKey],
487
- rowKey = _row$treeMetaKey.rowKey,
488
- depth = _row$treeMetaKey.depth,
489
- isLeaf = _row$treeMetaKey.isLeaf,
490
- expanded = _row$treeMetaKey.expanded;
491
- var addWidth = isLeaf ? iconWidth + iconGap : 0;
492
- var indent = iconIndent + depth * indentSize + addWidth;
493
- var x = expandCellRect.x,
494
- _y = expandCellRect.y,
495
- _height = expandCellRect.height;
496
- var _top = direction === 'bottom' ? _y + _height - offsetParentSize.top : _y - offsetParentSize.top;
497
- var offsetX = Math.max(x + paddingLeft + indent - bodyRect.x, 0);
498
- var _left = bodyRect.x + offsetX - offsetParentSize.left;
499
- lineElement.style.left = "".concat(_left, "px");
500
- lineElement.style.top = "".concat(_top, "px");
501
- lineElement.style.width = "".concat(bodyRect.width - offsetX, "px");
502
- if (direction === 'into') {
503
- lineElement.style.display = 'none';
504
- } else {
505
- lineElement.style.display = 'block';
506
- }
507
- return;
508
- }
509
- }
510
- // 根据鼠标悬停位置所在单元格和显示位置计算拖拽线的位置
511
- var rect = cell.getBoundingClientRect();
512
- var y = rect.y,
513
- height = rect.height;
514
- var top = direction === 'bottom' ? y + height - offsetParentSize.top : y - offsetParentSize.top;
515
- 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;
516
512
  lineElement.style.left = "".concat(left, "px");
517
513
  lineElement.style.top = "".concat(top, "px");
518
- lineElement.style.width = "".concat(bodyRect.width, "px");
514
+ lineElement.style.width = "".concat(width, "px");
515
+ if (direction === 'into') {
516
+ lineElement.style.display = 'none';
517
+ } else {
518
+ lineElement.style.display = 'block';
519
+ }
519
520
  }
520
521
  function showDragLine(lineElement) {
521
522
  lineElement.style.display = 'block';
@@ -548,11 +549,11 @@ function positionDragElemment(element, event) {
548
549
  }
549
550
  function getElementRectWithOffset(el) {
550
551
  var offsetElementRect = el.getBoundingClientRect();
551
- var _getElementSize3 = _getElementSize(el),
552
- borderTopWidth = _getElementSize3.borderTopWidth,
553
- borderLeftWidth = _getElementSize3.borderLeftWidth,
554
- borderRightWidth = _getElementSize3.borderRightWidth,
555
- borderBottomWidth = _getElementSize3.borderBottomWidth;
552
+ var _getElementSize2 = _getElementSize(el),
553
+ borderTopWidth = _getElementSize2.borderTopWidth,
554
+ borderLeftWidth = _getElementSize2.borderLeftWidth,
555
+ borderRightWidth = _getElementSize2.borderRightWidth,
556
+ borderBottomWidth = _getElementSize2.borderBottomWidth;
556
557
  return {
557
558
  top: offsetElementRect.top + (borderTopWidth || 0),
558
559
  left: offsetElementRect.left + (borderLeftWidth || 0),
@@ -678,4 +679,54 @@ function getDirection(cell, clientY) {
678
679
  direction = 'top';
679
680
  }
680
681
  return direction;
681
- }
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kdcloudjs/table",
3
- "version": "1.2.2-canary.5",
3
+ "version": "1.2.2-canary.6",
4
4
  "description": "金蝶 react table 组件",
5
5
  "title": "table",
6
6
  "keywords": [