sheet-happens 0.0.51 → 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.
@@ -1,3 +1,3 @@
1
- import { RowOrColumnPropertyFunction, RowOrColumnPropertyStyledFunction, CellPropertyFunction, CellPropertyStyledFunction, CellContentType, Style } from './types';
2
- export declare const useAutoSizeColumn: (rows: number[], displayData: CellPropertyStyledFunction<CellContentType>, cellStyle: CellPropertyFunction<Style>, columnHeaders: RowOrColumnPropertyStyledFunction<CellContentType>, columnHeaderStyle: RowOrColumnPropertyFunction<Style>, canvasWidth: number) => (x: number) => number;
3
- export declare const useAutoSizeRow: (columns: number[], displayData: CellPropertyStyledFunction<CellContentType>, cellStyle: CellPropertyFunction<Style>, columnHeaders: RowOrColumnPropertyStyledFunction<CellContentType>, columnHeaderStyle: RowOrColumnPropertyFunction<Style>, cellWidth: RowOrColumnPropertyFunction<number>, canvasHeight: number) => (y: number) => number;
1
+ import { RowOrColumnPropertyFunction, RowOrColumnPropertyStyledFunction, CellLayout, CellPropertyFunction, CellPropertyStyledFunction, CellContentType, Style } from './types';
2
+ export declare const useAutoSizeColumn: (rows: number[], displayData: CellPropertyStyledFunction<CellContentType>, cellLayout: CellLayout, cellStyle: CellPropertyFunction<Style>, columnHeaders: RowOrColumnPropertyStyledFunction<CellContentType>, columnHeaderStyle: RowOrColumnPropertyFunction<Style>, canvasWidth: number, frozenColumns: number) => (x: number) => number;
3
+ export declare const useAutoSizeRow: (columns: number[], displayData: CellPropertyStyledFunction<CellContentType>, cellLayout: CellLayout, cellStyle: CellPropertyFunction<Style>, columnHeaders: RowOrColumnPropertyStyledFunction<CellContentType>, columnHeaderStyle: RowOrColumnPropertyFunction<Style>, cellWidth: RowOrColumnPropertyFunction<number>, canvasHeight: number, frozenRows: number) => (y: number) => number;
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,
@@ -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,
@@ -2018,12 +2044,13 @@ var wrapText = function wrapText(context, text, style, itemAlign, xCoord, yCoord
2018
2044
  newline(n);
2019
2045
  };
2020
2046
 
2021
- var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth) {
2047
+ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, frozenColumns) {
2022
2048
  var context = React.useMemo(function () {
2023
2049
  return document.createElement('canvas').getContext('2d');
2024
2050
  }, []);
2025
2051
  var getAutoSizeWidth = React.useCallback(function (x) {
2026
2052
  if (!context) return 0;
2053
+ var viewWidth = canvasWidth - cellLayout.columnToAbsolute(x < frozenColumns ? 0 : frozenColumns);
2027
2054
  var getWidth = function getWidth(cellContent, style) {
2028
2055
  context.font = style.fontWeight + ' ' + style.fontSize + 'px ' + style.fontFamily;
2029
2056
  var inlineMargin = style.marginLeft + style.marginRight;
@@ -2067,22 +2094,23 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
2067
2094
  maxWidth = Math.max(maxWidth, getWidth(cellContent, style));
2068
2095
  }
2069
2096
  }
2070
- return Math.ceil(Math.min(canvasWidth, maxWidth));
2071
- }, [context, displayData, cellStyle, columnHeaders, columnHeaderStyle]);
2097
+ return Math.ceil(Math.min(viewWidth, maxWidth));
2098
+ }, [context, rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, frozenColumns]);
2072
2099
  return getAutoSizeWidth;
2073
2100
  };
2074
- var useAutoSizeRow = function useAutoSizeRow(columns, displayData, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight) {
2101
+ var useAutoSizeRow = function useAutoSizeRow(columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, frozenRows) {
2075
2102
  var context = React.useMemo(function () {
2076
2103
  return document.createElement('canvas').getContext('2d');
2077
2104
  }, []);
2078
2105
  var getAutoSizeHeight = React.useCallback(function (y) {
2079
2106
  if (!context) return 0;
2107
+ var viewHeight = canvasHeight - cellLayout.rowToAbsolute(y < frozenRows ? 0 : frozenRows);
2080
2108
  var measureTextHeight = function measureTextHeight(text, style, columnWidth) {
2081
2109
  var maxY = 0;
2082
2110
  var measureY = function measureY(_t, _x, y) {
2083
2111
  maxY = y + style.lineHeight;
2084
2112
  };
2085
- wrapText(context, text, style, undefined, 0, 0, columnWidth, canvasHeight, measureY);
2113
+ wrapText(context, text, style, undefined, 0, 0, columnWidth, viewHeight, measureY);
2086
2114
  return maxY;
2087
2115
  };
2088
2116
  var getHeight = function getHeight(cellContent, style, columnWidth) {
@@ -2093,13 +2121,19 @@ var useAutoSizeRow = function useAutoSizeRow(columns, displayData, cellStyle, co
2093
2121
  return height + verticalMargin;
2094
2122
  } else if (typeof cellContent === 'object') {
2095
2123
  var _maxHeight = 0;
2096
- for (var _iterator3 = _createForOfIteratorHelperLoose(cellContent.items), _step3; !(_step3 = _iterator3()).done;) {
2097
- var item = _step3.value;
2098
- if (item.absolute) continue;
2124
+ var flexLayout = resolveCellFlexLayout(context, cellContent, 0, 0, columnWidth, 0);
2125
+ for (var _iterator3 = _createForOfIteratorHelperLoose(flexLayout), _step3; !(_step3 = _iterator3()).done;) {
2126
+ var _step3$value = _step3.value,
2127
+ box = _step3$value.box,
2128
+ item = _step3$value.item;
2099
2129
  if (item.height != null) {
2100
2130
  _maxHeight = Math.max(_maxHeight, item.height);
2101
2131
  } else if (item.display === 'inline' && item.text != null) {
2102
- var _height = measureTextHeight(item.text.toString(), style, columnWidth);
2132
+ var _box$ = box[0],
2133
+ left = _box$[0],
2134
+ _box$2 = box[1],
2135
+ right = _box$2[0];
2136
+ var _height = measureTextHeight(item.text.toString(), style, right - left);
2103
2137
  _maxHeight = Math.max(_maxHeight, _height);
2104
2138
  }
2105
2139
  }
@@ -2118,8 +2152,8 @@ var useAutoSizeRow = function useAutoSizeRow(columns, displayData, cellStyle, co
2118
2152
  maxHeight = Math.max(maxHeight, getHeight(cellContent, style, columnWidth));
2119
2153
  }
2120
2154
  }
2121
- return Math.ceil(Math.min(canvasHeight, maxHeight));
2122
- }, [context, displayData, cellStyle, cellWidth]);
2155
+ return Math.ceil(Math.min(viewHeight, maxHeight));
2156
+ }, [context, columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, frozenRows]);
2123
2157
  return getAutoSizeHeight;
2124
2158
  };
2125
2159
 
@@ -2216,7 +2250,8 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2216
2250
  var rows = table.rows,
2217
2251
  payload = table.payload;
2218
2252
  var _normalizeSelection = normalizeSelection(selection),
2219
- min = _normalizeSelection[0];
2253
+ min = _normalizeSelection[0],
2254
+ max = _normalizeSelection[1];
2220
2255
  var minX = min[0],
2221
2256
  minY = min[1];
2222
2257
  var left = Math.max(0, minX);
@@ -2225,18 +2260,27 @@ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly
2225
2260
  return Math.max(a, b.length);
2226
2261
  }, 0);
2227
2262
  var height = rows.length;
2228
- 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])];
2229
2267
  return Promise.resolve(onPaste === null || onPaste === void 0 ? void 0 : onPaste(newSelection, rows, payload)).then(function (shouldPaste) {
2230
2268
  if (shouldPaste !== false) {
2231
2269
  var changes = rows.flatMap(function (row, j) {
2232
- return row.map(function (value, i) {
2233
- var x = left + i;
2234
- var y = top + j;
2235
- return !(cellReadOnly !== null && cellReadOnly !== void 0 && cellReadOnly(x, y)) ? {
2236
- x: x,
2237
- y: y,
2238
- value: value
2239
- } : 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;
2240
2284
  });
2241
2285
  }).filter(function (change) {
2242
2286
  return !!change;
@@ -2602,7 +2646,7 @@ var makeCellLayout = function makeCellLayout(freeze, offset, columns, rows) {
2602
2646
  var getStart = layout.getStart,
2603
2647
  lookupIndex = layout.lookupIndex;
2604
2648
  var indent = getStart(0);
2605
- if (pixel < indent) return -1;
2649
+ if (pixel < indent) return 0;
2606
2650
  var frozen = getStart(freeze);
2607
2651
  if (pixel < frozen) {
2608
2652
  return lookupIndex(pixel, anchor);
@@ -3156,9 +3200,11 @@ var renderCell = function renderCell(context, imageRenderer, cellContent, style,
3156
3200
  var renderedFlex = resolveCellFlexLayout(context, cellContent, innerX, innerY, innerWidth, innerHeight);
3157
3201
  var renderedAbsolute = resolveCellAbsoluteLayout(cellContent, innerX, innerY, innerWidth, innerHeight);
3158
3202
  var rendered = [].concat(renderedFlex, renderedAbsolute);
3159
- clipToBox(context, innerX, innerY, innerWidth, innerHeight, function () {
3203
+ clipToBox(context, xCoord, yCoord, cellWidth, cellHeight, function () {
3160
3204
  var _loop = function _loop() {
3161
- var render = _step12.value;
3205
+ var _step12$value = _step12.value,
3206
+ i = _step12$value[0],
3207
+ render = _step12$value[1];
3162
3208
  var box = render.box,
3163
3209
  item = render.item;
3164
3210
  var _box$ = box[0],
@@ -3174,7 +3220,10 @@ var renderCell = function renderCell(context, imageRenderer, cellContent, style,
3174
3220
  context.strokeStyle = '#ff00ff';
3175
3221
  context.strokeRect(left + 0.5, top + 0.5, width - 0.5, height - 0.5);
3176
3222
  }
3177
- clipToBox(context, left, top, width, height, function () {
3223
+ var clipLeft = i > 0 ? left : xCoord;
3224
+ var clipRight = i < rendered.length ? right : yCoord + cellWidth;
3225
+ var clipWidth = clipRight - clipLeft;
3226
+ clipToBox(context, clipLeft, yCoord, clipWidth, cellHeight, function () {
3178
3227
  if (item.display === 'inline') {
3179
3228
  var text = item.text;
3180
3229
  if (text != null) {
@@ -3186,7 +3235,7 @@ var renderCell = function renderCell(context, imageRenderer, cellContent, style,
3186
3235
  }
3187
3236
  });
3188
3237
  };
3189
- for (var _iterator12 = _createForOfIteratorHelperLoose(rendered), _step12; !(_step12 = _iterator12()).done;) {
3238
+ for (var _iterator12 = _createForOfIteratorHelperLoose(rendered.entries()), _step12; !(_step12 = _iterator12()).done;) {
3190
3239
  _loop();
3191
3240
  }
3192
3241
  });
@@ -3621,9 +3670,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3621
3670
  clipboardApi = _useClipboardAPI.clipboardApi,
3622
3671
  onClipboardCopy = _useClipboardAPI.onClipboardCopy;
3623
3672
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
3624
- var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth);
3625
- var getAutoSizeHeight = useAutoSizeRow(visibleCells.columns, displayData, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight);
3626
- 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),
3673
+ var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth, freezeColumns);
3674
+ var getAutoSizeHeight = useAutoSizeRow(visibleCells.columns, displayData, cellLayout, cellStyle, columnHeaders, columnHeaderStyle, cellWidth, canvasHeight, freezeRows);
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),
3627
3676
  mouseHandlers = _useMouse.mouseHandlers,
3628
3677
  knobPosition = _useMouse.knobPosition;
3629
3678
  var _useKeyboard = useKeyboard(arrowKeyCommitMode, overlayRef, cellReadOnly, displayData, editCell, editMode, focused, rawSelection, selection, startEditingCell, commitEditingCell, cancelEditingCell, changeSelection, setFocused, onClipboardCopy, props.onChange),
@@ -3657,6 +3706,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3657
3706
  var editTextAlign = 'right';
3658
3707
  var editTextLineHeight = '';
3659
3708
  var editTextMargin = '';
3709
+ var editTextFontSize = DEFAULT_CELL_STYLE.fontSize;
3710
+ var editTextFontFamily = DEFAULT_CELL_STYLE.fontFamily;
3711
+ var editTextFontWeight = DEFAULT_CELL_STYLE.fontWeight;
3660
3712
  if (editMode) {
3661
3713
  var style = _extends({}, DEFAULT_CELL_STYLE, cellStyle.apply(void 0, editCell));
3662
3714
  editTextPosition = cellToPixel(editCell);
@@ -3665,6 +3717,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3665
3717
  editTextHeight = cellHeight(editCellY) - 3;
3666
3718
  editTextAlign = style.textAlign;
3667
3719
  editTextLineHeight = style.lineHeight + "px";
3720
+ editTextFontSize = style.fontSize;
3721
+ editTextFontFamily = style.fontFamily;
3722
+ editTextFontWeight = style.fontWeight;
3668
3723
  var yNudge = getDpiNudge();
3669
3724
  editTextMargin = style.marginTop - 1 + yNudge + "px " + (style.marginRight - 2) + "px " + (style.marginBottom - 2) + "px " + (style.marginLeft - 1) + "px";
3670
3725
  var editKey = editKeys.apply(void 0, editCell);
@@ -3692,8 +3747,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3692
3747
  textAlign: editTextAlign,
3693
3748
  lineHeight: editTextLineHeight,
3694
3749
  color: 'black',
3695
- fontSize: DEFAULT_CELL_STYLE.fontSize,
3696
- fontFamily: 'sans-serif',
3750
+ fontSize: editTextFontSize,
3751
+ fontFamily: editTextFontFamily,
3752
+ fontWeight: editTextFontWeight,
3697
3753
  resize: 'none'
3698
3754
  }
3699
3755
  };