sheet-happens 0.0.52 → 0.0.53

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/index.js CHANGED
@@ -648,7 +648,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
648
648
  return maxXY(cell, [0, 0]);
649
649
  };
650
650
 
651
- var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, getAutoSizeHeight, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onFocusChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
651
+ var useMouse = function useMouse(elementRef, dataOffset, hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, getAutoSizeHeight, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onFocusChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
652
652
  var _useState = React.useState(null),
653
653
  columnResize = _useState[0],
654
654
  setColumnResize = _useState[1];
@@ -664,18 +664,21 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
664
664
  var _useState5 = React.useState(null),
665
665
  hitTestDown = _useState5[0],
666
666
  setHitTestDown = _useState5[1];
667
- var _useState6 = React.useState(false),
668
- draggingKnob = _useState6[0],
669
- setDraggingKnob = _useState6[1];
667
+ var _useState6 = React.useState(null),
668
+ autoScroll = _useState6[0],
669
+ setAutoScroll = _useState6[1];
670
670
  var _useState7 = React.useState(false),
671
- draggingSelection = _useState7[0],
672
- setDraggingSelection = _useState7[1];
671
+ draggingKnob = _useState7[0],
672
+ setDraggingKnob = _useState7[1];
673
673
  var _useState8 = React.useState(false),
674
- draggingRowSelection = _useState8[0],
675
- setDraggingRowSelection = _useState8[1];
674
+ draggingSelection = _useState8[0],
675
+ setDraggingSelection = _useState8[1];
676
676
  var _useState9 = React.useState(false),
677
- draggingColumnSelection = _useState9[0],
678
- setDraggingColumnSelection = _useState9[1];
677
+ draggingRowSelection = _useState9[0],
678
+ setDraggingRowSelection = _useState9[1];
679
+ var _useState10 = React.useState(false),
680
+ draggingColumnSelection = _useState10[0],
681
+ setDraggingColumnSelection = _useState10[1];
679
682
  var hideRowHeaders = sheetStyle.hideRowHeaders,
680
683
  hideColumnHeaders = sheetStyle.hideColumnHeaders;
681
684
  var cellToPixel = cellLayout.cellToPixel,
@@ -699,6 +702,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
699
702
  }, [selection, cellToPixel, version]);
700
703
  var refState = {
701
704
  selection: selection,
705
+ dataOffset: dataOffset,
702
706
  knobArea: knobArea,
703
707
  editMode: editMode,
704
708
  editData: editData,
@@ -717,27 +721,29 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
717
721
  };
718
722
  var ref = React.useRef(refState);
719
723
  ref.current = refState;
720
- var getMousePosition = React.useCallback(function (e) {
724
+ var getMousePosition = React.useCallback(function (e, strict) {
721
725
  if (!e.target || !(e.target instanceof Element)) {
722
726
  return null;
723
727
  }
724
728
  var rect = e.target.getBoundingClientRect();
725
729
  var xy = [e.clientX - rect.left, e.clientY - rect.top];
726
- if (xy[0] > e.target.clientWidth || xy[1] > e.target.clientHeight) {
730
+ if (strict && (xy[0] > e.target.clientWidth || xy[1] > e.target.clientHeight)) {
727
731
  return null;
728
732
  }
729
733
  return xy;
730
734
  }, []);
731
- var getScrollPosition = React.useCallback(function (e) {
735
+ var getMouseOutOfBounds = React.useCallback(function (e, allowX, allowY) {
732
736
  if (!e.target || !(e.target instanceof Element)) {
733
- return [0, 0];
737
+ return null;
734
738
  }
735
- var _e$target = e.target,
736
- scrollLeft = _e$target.scrollLeft,
737
- scrollTop = _e$target.scrollTop;
738
- var xy = [scrollLeft, scrollTop];
739
- return xy;
740
- }, []);
739
+ var rect = e.target.getBoundingClientRect();
740
+ var xy = [e.clientX - rect.left, e.clientY - rect.top];
741
+ var indentX = cellLayout.getIndentX();
742
+ var indentY = cellLayout.getIndentY();
743
+ var xSign = allowX ? xy[0] < indentX ? -1 : xy[0] > e.target.clientWidth ? 1 : 0 : 0;
744
+ var ySign = allowY ? xy[1] < indentY ? -1 : xy[1] > e.target.clientHeight ? 1 : 0 : 0;
745
+ return xSign || ySign ? [xSign, ySign] : null;
746
+ }, [cellLayout]);
741
747
  var getMouseHit = React.useCallback(function (xy) {
742
748
  var hitmap = hitmapRef.current;
743
749
  if (!hitmap) return null;
@@ -754,9 +760,10 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
754
760
  window.document.body.style.cursor = 'auto';
755
761
  }, []);
756
762
  var onPointerDown = React.useCallback(function (e) {
757
- var _e$target2, _e$target2$setPointer;
763
+ var _e$target, _e$target$setPointerC;
758
764
  var _ref$current = ref.current,
759
765
  selection = _ref$current.selection,
766
+ dataOffset = _ref$current.dataOffset,
760
767
  _ref$current$cellLayo = _ref$current.cellLayout,
761
768
  columnToPixel = _ref$current$cellLayo.columnToPixel,
762
769
  rowToPixel = _ref$current$cellLayo.rowToPixel,
@@ -769,8 +776,8 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
769
776
  knobPosition = _ref$current.knobPosition;
770
777
  onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
771
778
  if (e.button !== 0) return;
772
- (_e$target2 = e.target) === null || _e$target2 === void 0 ? void 0 : (_e$target2$setPointer = _e$target2.setPointerCapture) === null || _e$target2$setPointer === void 0 ? void 0 : _e$target2$setPointer.call(_e$target2, e.pointerId);
773
- var xy = getMousePosition(e);
779
+ (_e$target = e.target) === null || _e$target === void 0 ? void 0 : (_e$target$setPointerC = _e$target.setPointerCapture) === null || _e$target$setPointerC === void 0 ? void 0 : _e$target$setPointerC.call(_e$target, e.pointerId);
780
+ var xy = getMousePosition(e, true);
774
781
  if (!xy) return;
775
782
  var hitTarget = getMouseHit(xy);
776
783
  setHitTestDown(hitTarget);
@@ -820,11 +827,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
820
827
  dragIndices = seq(dragEnd - dragStart + 1, dragStart);
821
828
  }
822
829
  var size = columnToPixel(maxX, 1) - columnToPixel(minX);
823
- var _getScrollPosition = getScrollPosition(e),
824
- scroll = _getScrollPosition[0];
825
830
  setColumnDrag({
826
- anchor: x,
827
- scroll: scroll,
831
+ anchor: xy,
832
+ offset: dataOffset,
828
833
  size: size,
829
834
  indices: indices
830
835
  });
@@ -844,11 +849,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
844
849
  var asGroup = isColumnSelection(selection) && maxX === _index;
845
850
  var _indices = asGroup ? selectedColumns : [_index];
846
851
  var _size = asGroup ? columnToPixel(maxX, 1) - columnToPixel(minX) : columnToPixel(_index, 1) - columnToPixel(_index);
847
- var _getScrollPosition2 = getScrollPosition(e),
848
- _scroll = _getScrollPosition2[0];
849
852
  setColumnResize({
850
- anchor: x,
851
- scroll: _scroll,
853
+ anchor: xy,
854
+ offset: dataOffset,
852
855
  size: _size,
853
856
  indices: _indices
854
857
  });
@@ -890,11 +893,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
890
893
  _dragIndices = seq(_dragEnd - _dragStart + 1, _dragStart);
891
894
  }
892
895
  var _size2 = rowToPixel(maxY, 1) - rowToPixel(minY);
893
- var _getScrollPosition3 = getScrollPosition(e),
894
- _scroll2 = _getScrollPosition3[1];
895
896
  setRowDrag({
896
- anchor: y,
897
- scroll: _scroll2,
897
+ anchor: xy,
898
+ offset: dataOffset,
898
899
  size: _size2,
899
900
  indices: _indices2
900
901
  });
@@ -914,11 +915,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
914
915
  var _asGroup = isRowSelection(selection) && maxY === _index3;
915
916
  var _indices3 = _asGroup ? selectedRows : [_index3];
916
917
  var _size3 = _asGroup ? rowToPixel(maxY, 1) - rowToPixel(minY) : rowToPixel(_index3, 1) - rowToPixel(_index3);
917
- var _getScrollPosition4 = getScrollPosition(e),
918
- _scroll3 = _getScrollPosition4[1];
919
918
  setRowResize({
920
- anchor: y,
921
- scroll: _scroll3,
919
+ anchor: xy,
920
+ offset: dataOffset,
922
921
  size: _size3,
923
922
  indices: _indices3
924
923
  });
@@ -958,7 +957,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
958
957
  }
959
958
  setDraggingSelection(true);
960
959
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([anchor, head], scrollTo, true);
961
- }, [getMousePosition, getScrollPosition, getMouseHit, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onKnobAreaChange, onSelectionChange, onCommit, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, dontCommitEditOnSelectionChange, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups]);
960
+ }, [getMousePosition, getMouseHit, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onKnobAreaChange, onSelectionChange, onCommit, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, dontCommitEditOnSelectionChange, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups]);
962
961
  var onPointerUp = React.useCallback(function (e) {
963
962
  var _ref$current2 = ref.current,
964
963
  knobArea = _ref$current2.knobArea,
@@ -993,8 +992,8 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
993
992
  _normalizeSelection2$2 = _normalizeSelection2[1],
994
993
  maxX = _normalizeSelection2$2[0],
995
994
  maxY = _normalizeSelection2$2[1];
996
- var cellX = Math.max(0, pixelToColumn(x, 0.5));
997
- var cellY = Math.max(0, pixelToRow(y, 0.5));
995
+ var cellX = pixelToColumn(x, 0.5);
996
+ var cellY = pixelToRow(y, 0.5);
998
997
  if (columnDrag) {
999
998
  var indices = columnDrag.indices;
1000
999
  var insideSelection = cellX >= minX && cellX <= maxX + 1;
@@ -1032,10 +1031,12 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1032
1031
  setColumnDrag(null);
1033
1032
  setRowResize(null);
1034
1033
  setRowDrag(null);
1034
+ setAutoScroll(null);
1035
1035
  }, [getMousePosition, getMouseHit, onChange, onSelectionChange, onKnobAreaChange, onDropTargetChange, onColumnOrderChange, onRowOrderChange, dontChangeSelectionOnOrderChange]);
1036
1036
  var onPointerMove = React.useCallback(function (e) {
1037
1037
  var _ref$current3 = ref.current,
1038
1038
  selection = _ref$current3.selection,
1039
+ dataOffset = _ref$current3.dataOffset,
1039
1040
  visibleCells = _ref$current3.visibleCells,
1040
1041
  knobPosition = _ref$current3.knobPosition,
1041
1042
  columnResize = _ref$current3.columnResize,
@@ -1047,6 +1048,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1047
1048
  draggingColumnSelection = _ref$current3.draggingColumnSelection,
1048
1049
  draggingRowSelection = _ref$current3.draggingRowSelection,
1049
1050
  _ref$current3$cellLay = _ref$current3.cellLayout,
1051
+ cellToPixel = _ref$current3$cellLay.cellToPixel,
1050
1052
  columnToPixel = _ref$current3$cellLay.columnToPixel,
1051
1053
  rowToPixel = _ref$current3$cellLay.rowToPixel,
1052
1054
  pixelToCell = _ref$current3$cellLay.pixelToCell,
@@ -1055,6 +1057,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1055
1057
  getIndentX = _ref$current3$cellLay.getIndentX,
1056
1058
  getIndentY = _ref$current3$cellLay.getIndentY;
1057
1059
  window.document.body.style.cursor = 'auto';
1060
+ var isDraggingX = !!columnResize || !!columnDrag || draggingColumnSelection || draggingSelection || draggingKnob;
1061
+ var isDraggingY = !!rowResize || !!rowDrag || draggingRowSelection || draggingSelection || draggingKnob;
1062
+ var isDragging = isDraggingX || isDraggingY;
1063
+ var outOfBounds = getMouseOutOfBounds(e, isDraggingX, isDraggingY);
1064
+ if (isDragging) setAutoScroll(outOfBounds);
1058
1065
  var xy = getMousePosition(e);
1059
1066
  if (!xy) return;
1060
1067
  var hitTarget = getMouseHit(xy);
@@ -1082,7 +1089,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1082
1089
  _normalizeSelection3$2 = _normalizeSelection3[1],
1083
1090
  maxX = _normalizeSelection3$2[0],
1084
1091
  maxY = _normalizeSelection3$2[1];
1085
- var isDragging = columnResize || columnDrag || rowResize || rowDrag || draggingRowSelection || draggingColumnSelection;
1092
+ var getDragScrollOffset = function getDragScrollOffset(startOffset) {
1093
+ return subXY(cellToPixel(dataOffset), cellToPixel(startOffset));
1094
+ };
1086
1095
  if (!isDragging) {
1087
1096
  if (!hideColumnHeaders && y < getIndentY()) {
1088
1097
  if (onColumnOrderChange) {
@@ -1151,11 +1160,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1151
1160
  if (onCellWidthChange) {
1152
1161
  var size = columnResize.size,
1153
1162
  anchor = columnResize.anchor,
1154
- scroll = columnResize.scroll,
1163
+ offset = columnResize.offset,
1155
1164
  indices = columnResize.indices;
1156
- var _getScrollPosition5 = getScrollPosition(e),
1157
- currentScroll = _getScrollPosition5[0];
1158
- var newWidth = Math.round(Math.max(size + x - anchor + scroll - currentScroll, SIZES.minimumWidth * indices.length));
1165
+ var _getDragScrollOffset = getDragScrollOffset(offset),
1166
+ scrollOffset = _getDragScrollOffset[0];
1167
+ var newWidth = Math.round(Math.max(size + x - anchor[0] + scrollOffset, SIZES.minimumWidth * indices.length));
1159
1168
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(indices[0] - 1);
1160
1169
  onCellWidthChange(indices, indices.map(function (_) {
1161
1170
  return Math.round(newWidth / indices.length);
@@ -1167,11 +1176,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1167
1176
  if (onCellHeightChange) {
1168
1177
  var _size4 = rowResize.size,
1169
1178
  _anchor = rowResize.anchor,
1170
- _scroll4 = rowResize.scroll,
1179
+ _offset = rowResize.offset,
1171
1180
  _indices5 = rowResize.indices;
1172
- var _getScrollPosition6 = getScrollPosition(e),
1173
- _currentScroll = _getScrollPosition6[1];
1174
- var newHeight = Math.round(Math.max(_size4 + y - _anchor + _scroll4 - _currentScroll, SIZES.minimumHeight * _indices5.length));
1181
+ var _getDragScrollOffset2 = getDragScrollOffset(_offset),
1182
+ _scrollOffset = _getDragScrollOffset2[1];
1183
+ var newHeight = Math.round(Math.max(_size4 + y - _anchor[1] + _scrollOffset, SIZES.minimumHeight * _indices5.length));
1175
1184
  onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(_indices5[0] - 1);
1176
1185
  onCellHeightChange(_indices5, _indices5.map(function (_) {
1177
1186
  return newHeight / _indices5.length;
@@ -1181,7 +1190,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1181
1190
  }
1182
1191
  if (draggingSelection) {
1183
1192
  var _anchor2 = selection[0];
1184
- var head = pixelToCell(xy);
1193
+ var head = maxXY(dataOffset, pixelToCell(xy));
1185
1194
  var anchorX = _anchor2[0],
1186
1195
  anchorY = _anchor2[1];
1187
1196
  var headX = head[0],
@@ -1227,31 +1236,31 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1227
1236
  var _x = xy[0],
1228
1237
  _y = xy[1];
1229
1238
  if (columnDrag) {
1230
- var _cellX = Math.max(0, pixelToColumn(_x, 0.5));
1239
+ var _cellX = pixelToColumn(_x, 0.5);
1231
1240
  var insideSelection = _cellX >= minX && _cellX <= maxX + 1;
1232
1241
  var insideGroup = isBoundaryInsideGroup(_cellX, columnGroupKeys);
1233
1242
  var _anchor3 = columnDrag.anchor,
1234
- _scroll5 = columnDrag.scroll;
1235
- var shift = _x - _anchor3;
1236
- var _getScrollPosition7 = getScrollPosition(e),
1237
- _currentScroll2 = _getScrollPosition7[0];
1238
- onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([shift + _currentScroll2 - _scroll5, 0]);
1243
+ _offset2 = columnDrag.offset;
1244
+ var shift = _x - _anchor3[0];
1245
+ var _getDragScrollOffset3 = getDragScrollOffset(_offset2),
1246
+ _scrollOffset2 = _getDragScrollOffset3[0];
1247
+ onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([shift + _scrollOffset2, 0]);
1239
1248
  onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(insideSelection || insideGroup ? null : [[_cellX, -1], [_cellX, -1]]);
1240
1249
  }
1241
1250
  if (rowDrag) {
1242
- var _cellY = Math.max(0, pixelToRow(_y, 0.5));
1251
+ var _cellY = pixelToRow(_y, 0.5);
1243
1252
  var _insideSelection2 = _cellY >= minY && _cellY <= maxY + 1;
1244
1253
  var _insideGroup2 = isBoundaryInsideGroup(_cellY, rowGroupKeys);
1245
1254
  var _anchor4 = rowDrag.anchor,
1246
- _scroll6 = rowDrag.scroll;
1247
- var _shift = _y - _anchor4;
1248
- var _getScrollPosition8 = getScrollPosition(e),
1249
- _currentScroll3 = _getScrollPosition8[1];
1250
- onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, _shift + _currentScroll3 - _scroll6]);
1255
+ _offset3 = rowDrag.offset;
1256
+ var _shift = _y - _anchor4[1];
1257
+ var _getDragScrollOffset4 = getDragScrollOffset(_offset3),
1258
+ _scrollOffset3 = _getDragScrollOffset4[1];
1259
+ onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, _shift + _scrollOffset3]);
1251
1260
  onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(_insideSelection2 || _insideGroup2 ? null : [[-1, _cellY], [-1, _cellY]]);
1252
1261
  }
1253
1262
  }
1254
- }, [getMousePosition, getScrollPosition, getMouseHit, onCellWidthChange, onCellHeightChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn, columnGroupKeys, rowGroupKeys]);
1263
+ }, [getMousePosition, getMouseOutOfBounds, getMouseHit, onCellWidthChange, onCellHeightChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn, columnGroupKeys, rowGroupKeys]);
1255
1264
  var onClick = React.useCallback(function (e) {
1256
1265
  var xy = getMousePosition(e);
1257
1266
  if (!xy) return;
@@ -1369,6 +1378,23 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1369
1378
  });
1370
1379
  onRightClick === null || onRightClick === void 0 ? void 0 : onRightClick(event);
1371
1380
  }, [getMousePosition, onSelectionChange, onPointerMove, onRightClick]);
1381
+ React.useLayoutEffect(function () {
1382
+ if (!autoScroll) return;
1383
+ var loop = function loop() {
1384
+ var element = elementRef.current;
1385
+ if (!element) return;
1386
+ var x = autoScroll[0],
1387
+ y = autoScroll[1];
1388
+ var speed = 4;
1389
+ element.scrollLeft += x * speed * 2;
1390
+ element.scrollTop += y * speed;
1391
+ };
1392
+ var timer = setInterval(loop, 33);
1393
+ loop();
1394
+ return function () {
1395
+ clearInterval(timer);
1396
+ };
1397
+ }, [elementRef, autoScroll]);
1372
1398
  var mouseHandlers = {
1373
1399
  onPointerLeave: onPointerLeave,
1374
1400
  onPointerDown: onPointerDown,
@@ -2224,7 +2250,8 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2224
2250
  var rows = table.rows,
2225
2251
  payload = table.payload;
2226
2252
  var _normalizeSelection = normalizeSelection(selection),
2227
- min = _normalizeSelection[0];
2253
+ min = _normalizeSelection[0],
2254
+ max = _normalizeSelection[1];
2228
2255
  var minX = min[0],
2229
2256
  minY = min[1];
2230
2257
  var left = Math.max(0, minX);
@@ -2233,18 +2260,27 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2233
2260
  return Math.max(a, b.length);
2234
2261
  }, 0);
2235
2262
  var height = rows.length;
2236
- var newSelection = [min, addXY(min, [width - 1, height - 1])];
2263
+ var selectionSize = mulXY(addXY(subXY(max, min), [1, 1]), [1 / width, 1 / height]);
2264
+ var repeatX = Math.max(1, Math.floor(selectionSize[0]));
2265
+ var repeatY = Math.max(1, Math.floor(selectionSize[1]));
2266
+ var newSelection = [min, addXY(min, [width * repeatX - 1, height * repeatY - 1])];
2237
2267
  return Promise.resolve(onPaste === null || onPaste === void 0 ? void 0 : onPaste(newSelection, rows, payload)).then(function (shouldPaste) {
2238
2268
  if (shouldPaste !== false) {
2239
2269
  var changes = rows.flatMap(function (row, j) {
2240
- return row.map(function (value, i) {
2241
- var x = left + i;
2242
- var y = top + j;
2243
- return !(cellReadOnly !== null && cellReadOnly !== void 0 && cellReadOnly(x, y)) ? {
2244
- x: x,
2245
- y: y,
2246
- value: value
2247
- } : null;
2270
+ return row.flatMap(function (value, i) {
2271
+ var cells = [];
2272
+ for (var rx = 0; rx < repeatX; ++rx) {
2273
+ for (var ry = 0; ry < repeatY; ++ry) {
2274
+ var x = left + i + rx * width;
2275
+ var y = top + j + ry * height;
2276
+ if (!(cellReadOnly !== null && cellReadOnly !== void 0 && cellReadOnly(x, y))) cells.push({
2277
+ x: x,
2278
+ y: y,
2279
+ value: value
2280
+ });
2281
+ }
2282
+ }
2283
+ return cells;
2248
2284
  });
2249
2285
  }).filter(function (change) {
2250
2286
  return !!change;
@@ -2610,7 +2646,7 @@ var makeCellLayout = function makeCellLayout(freeze, offset, columns, rows) {
2610
2646
  var getStart = layout.getStart,
2611
2647
  lookupIndex = layout.lookupIndex;
2612
2648
  var indent = getStart(0);
2613
- if (pixel < indent) return -1;
2649
+ if (pixel < indent) return 0;
2614
2650
  var frozen = getStart(freeze);
2615
2651
  if (pixel < frozen) {
2616
2652
  return lookupIndex(pixel, anchor);
@@ -3636,7 +3672,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3636
3672
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
3637
3673
  var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, freezeColumns);
3638
3674
  var getAutoSizeHeight = useAutoSizeRow(visibleCells.columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, freezeRows);
3639
- var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, getAutoSizeHeight, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, setFocused, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange, props.dontChangeSelectionOnOrderChange),
3675
+ var _useMouse = useMouse(overlayRef, dataOffset, hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, getAutoSizeHeight, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, setFocused, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange, props.dontChangeSelectionOnOrderChange),
3640
3676
  mouseHandlers = _useMouse.mouseHandlers,
3641
3677
  knobPosition = _useMouse.knobPosition;
3642
3678
  var _useKeyboard = useKeyboard(arrowKeyCommitMode, overlayRef, cellReadOnly, displayData, editCell, editMode, focused, rawSelection, selection, startEditingCell, commitEditingCell, cancelEditingCell, changeSelection, setFocused, onClipboardCopy, props.onChange),