sheet-happens 0.0.39 → 0.0.41

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.
@@ -529,7 +529,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
529
529
  return maxXY(cell, [0, 0]);
530
530
  };
531
531
 
532
- var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
532
+ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
533
533
  var _useState = useState(null),
534
534
  hitTarget = _useState[0],
535
535
  setHitTarget = _useState[1];
@@ -619,6 +619,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
619
619
 
620
620
  var rect = e.target.getBoundingClientRect();
621
621
  var xy = [e.clientX - rect.left, e.clientY - rect.top];
622
+
623
+ if (xy[0] > e.target.clientWidth || xy[1] > e.target.clientHeight) {
624
+ return null;
625
+ }
626
+
622
627
  return xy;
623
628
  }, []);
624
629
  var getScrollPosition = useCallback(function (e) {
@@ -1038,9 +1043,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1038
1043
  pixelToRow = _ref$current3$cellLay.pixelToRow,
1039
1044
  getIndentX = _ref$current3$cellLay.getIndentX,
1040
1045
  getIndentY = _ref$current3$cellLay.getIndentY;
1046
+ window.document.body.style.cursor = 'auto';
1041
1047
  var xy = getMousePosition(e);
1042
1048
  if (!xy) return;
1043
- window.document.body.style.cursor = 'auto';
1044
1049
  var hitTarget = getMouseHit(xy);
1045
1050
 
1046
1051
  if (hitTarget) {
@@ -1283,11 +1288,48 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1283
1288
  }
1284
1289
  }, [getMousePosition, getScrollPosition, getMouseHit, onCellWidthChange, onCellHeightChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn, columnGroupKeys, rowGroupKeys]);
1285
1290
  var onDoubleClick = useCallback(function (e) {
1286
- var pixelToCell = ref.current.cellLayout.pixelToCell;
1291
+ var _ref$current4 = ref.current,
1292
+ selection = _ref$current4.selection,
1293
+ _ref$current4$cellLay = _ref$current4.cellLayout,
1294
+ pixelToCell = _ref$current4$cellLay.pixelToCell,
1295
+ columnToPixel = _ref$current4$cellLay.columnToPixel;
1287
1296
  e.preventDefault();
1288
1297
  if (e.shiftKey) return;
1289
1298
  var xy = getMousePosition(e);
1290
1299
  if (!xy) return;
1300
+ var x = xy[0];
1301
+ var columns = visibleCells.columns;
1302
+
1303
+ if (onCellWidthChange) {
1304
+ var autosized = [];
1305
+
1306
+ for (var _iterator10 = _createForOfIteratorHelperLoose(columns), _step10; !(_step10 = _iterator10()).done;) {
1307
+ var index = _step10.value;
1308
+ var edge = columnToPixel(index, 1);
1309
+
1310
+ if (Math.abs(edge - x) < SIZES.resizeZone && canSizeColumn(index)) {
1311
+ var _normalizeSelection5 = normalizeSelection(selection),
1312
+ _normalizeSelection5$ = _normalizeSelection5[0],
1313
+ minX = _normalizeSelection5$[0],
1314
+ _normalizeSelection5$2 = _normalizeSelection5[1],
1315
+ maxX = _normalizeSelection5$2[0];
1316
+
1317
+ var indices = isColumnSelection(selection) && index >= minX && index <= maxX ? mapSelectionColumns(selection)(function (i) {
1318
+ return i;
1319
+ }) : [index];
1320
+ autosized.push.apply(autosized, indices);
1321
+ }
1322
+ }
1323
+
1324
+ for (var _i = 0, _autosized = autosized; _i < _autosized.length; _i++) {
1325
+ var column = _autosized[_i];
1326
+ onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(column - 1);
1327
+ onCellWidthChange([column], getAutoSizeWidth(column));
1328
+ }
1329
+
1330
+ if (autosized.length) return;
1331
+ }
1332
+
1291
1333
  var hitTarget = getMouseHit(xy);
1292
1334
 
1293
1335
  if (hitTarget) {
@@ -1298,7 +1340,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1298
1340
  var editCell = pixelToCell(xy);
1299
1341
  if (editMode) onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1300
1342
  onEdit === null || onEdit === void 0 ? void 0 : onEdit(editCell);
1301
- }, [getMousePosition, getMouseHit, onCommit, onEdit]);
1343
+ }, [getMousePosition, getMouseHit, onCommit, onEdit, onInvalidateColumn, onCellWidthChange, getAutoSizeWidth, visibleCells, canSizeColumn]);
1302
1344
  var onContextMenu = useCallback(function (e) {
1303
1345
  var _ref$current$cellLayo2 = ref.current.cellLayout,
1304
1346
  pixelToCell = _ref$current$cellLayo2.pixelToCell,
@@ -1345,21 +1387,21 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1345
1387
  };
1346
1388
 
1347
1389
  var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly) {
1348
- var _normalizeSelection5 = normalizeSelection(knobArea),
1349
- _normalizeSelection5$ = _normalizeSelection5[0],
1350
- kx1 = _normalizeSelection5$[0],
1351
- ky1 = _normalizeSelection5$[1],
1352
- _normalizeSelection5$2 = _normalizeSelection5[1],
1353
- kx2 = _normalizeSelection5$2[0],
1354
- ky2 = _normalizeSelection5$2[1];
1355
-
1356
- var _normalizeSelection6 = normalizeSelection(selection),
1390
+ var _normalizeSelection6 = normalizeSelection(knobArea),
1357
1391
  _normalizeSelection6$ = _normalizeSelection6[0],
1358
- sx1 = _normalizeSelection6$[0],
1359
- sy1 = _normalizeSelection6$[1],
1392
+ kx1 = _normalizeSelection6$[0],
1393
+ ky1 = _normalizeSelection6$[1],
1360
1394
  _normalizeSelection6$2 = _normalizeSelection6[1],
1361
- sx2 = _normalizeSelection6$2[0],
1362
- sy2 = _normalizeSelection6$2[1];
1395
+ kx2 = _normalizeSelection6$2[0],
1396
+ ky2 = _normalizeSelection6$2[1];
1397
+
1398
+ var _normalizeSelection7 = normalizeSelection(selection),
1399
+ _normalizeSelection7$ = _normalizeSelection7[0],
1400
+ sx1 = _normalizeSelection7$[0],
1401
+ sy1 = _normalizeSelection7$[1],
1402
+ _normalizeSelection7$2 = _normalizeSelection7[1],
1403
+ sx2 = _normalizeSelection7$2[0],
1404
+ sy2 = _normalizeSelection7$2[1];
1363
1405
 
1364
1406
  var fx1 = kx1;
1365
1407
  var fy1 = ky1;
@@ -1484,6 +1526,65 @@ var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange
1484
1526
  }
1485
1527
  }, [cellLayout, onOffsetChange, onMaxScrollChange]);
1486
1528
  };
1529
+ var clipDataOffset = function clipDataOffset(view, offset, freeze, maxCells, cellLayout) {
1530
+ var newX = offset[0],
1531
+ newY = offset[1];
1532
+ var maxColumns = maxCells[0],
1533
+ maxRows = maxCells[1];
1534
+ var absoluteToColumn = cellLayout.absoluteToColumn,
1535
+ columnToAbsolute = cellLayout.columnToAbsolute,
1536
+ absoluteToRow = cellLayout.absoluteToRow,
1537
+ rowToAbsolute = cellLayout.rowToAbsolute;
1538
+
1539
+ var _getViewExtent = getViewExtent(view, [newX, newY], freeze, cellLayout),
1540
+ _getViewExtent$edge = _getViewExtent.edge,
1541
+ rightEdge = _getViewExtent$edge[0],
1542
+ bottomEdge = _getViewExtent$edge[1],
1543
+ _getViewExtent$viewpo = _getViewExtent.viewport,
1544
+ scrollW = _getViewExtent$viewpo[0],
1545
+ scrollH = _getViewExtent$viewpo[1];
1546
+
1547
+ if (rightEdge > maxColumns) {
1548
+ var remainder = columnToAbsolute(maxColumns) - columnToAbsolute(newX);
1549
+ newX = absoluteToColumn(columnToAbsolute(newX) - scrollW + remainder) + 1;
1550
+ }
1551
+
1552
+ if (bottomEdge > maxRows) {
1553
+ var _remainder = rowToAbsolute(maxRows) - rowToAbsolute(newY);
1554
+
1555
+ newY = absoluteToRow(rowToAbsolute(newY) - scrollH + _remainder) + 1;
1556
+ }
1557
+
1558
+ return [newX, newY];
1559
+ };
1560
+ var getViewExtent = function getViewExtent(view, offset, freeze, cellLayout) {
1561
+ var cellToAbsolute = cellLayout.cellToAbsolute,
1562
+ absoluteToColumn = cellLayout.absoluteToColumn,
1563
+ columnToAbsolute = cellLayout.columnToAbsolute,
1564
+ absoluteToRow = cellLayout.absoluteToRow,
1565
+ rowToAbsolute = cellLayout.rowToAbsolute,
1566
+ getIndentX = cellLayout.getIndentX,
1567
+ getIndentY = cellLayout.getIndentY;
1568
+ var x = offset[0],
1569
+ y = offset[1];
1570
+ var w = view[0],
1571
+ h = view[1];
1572
+
1573
+ var _cellToAbsolute2 = cellToAbsolute(freeze),
1574
+ frozenX = _cellToAbsolute2[0],
1575
+ frozenY = _cellToAbsolute2[1];
1576
+
1577
+ var scrollW = w - frozenX - getIndentX();
1578
+ var scrollH = h - frozenY - getIndentY();
1579
+ var leftEdge = x + freeze[0];
1580
+ var topEdge = y + freeze[1];
1581
+ var rightEdge = absoluteToColumn(columnToAbsolute(leftEdge) + scrollW);
1582
+ var bottomEdge = absoluteToRow(rowToAbsolute(topEdge) + scrollH);
1583
+ return {
1584
+ edge: [rightEdge, bottomEdge],
1585
+ viewport: [scrollW, scrollH]
1586
+ };
1587
+ };
1487
1588
  var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, maxScroll, cellLayout, callback) {
1488
1589
  var x = cell[0],
1489
1590
  y = cell[1];
@@ -1496,9 +1597,9 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1496
1597
  columnToPixel = cellLayout.columnToPixel,
1497
1598
  rowToPixel = cellLayout.rowToPixel;
1498
1599
 
1499
- var _cellToAbsolute2 = cellToAbsolute(freeze),
1500
- frozenX = _cellToAbsolute2[0],
1501
- frozenY = _cellToAbsolute2[1];
1600
+ var _cellToAbsolute3 = cellToAbsolute(freeze),
1601
+ frozenX = _cellToAbsolute3[0],
1602
+ frozenY = _cellToAbsolute3[1];
1502
1603
 
1503
1604
  var _cellToPixel = cellToPixel(cell),
1504
1605
  left = _cellToPixel[0],
@@ -1536,9 +1637,9 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1536
1637
  if (!isSameXY(newOffset, offset)) {
1537
1638
  var scroll = cellToAbsolute(newOffset);
1538
1639
 
1539
- var _cellToAbsolute3 = cellToAbsolute([0, 0], [0.5, 0.5]),
1540
- nudgeX = _cellToAbsolute3[0],
1541
- nudgeY = _cellToAbsolute3[1];
1640
+ var _cellToAbsolute4 = cellToAbsolute([0, 0], [0.5, 0.5]),
1641
+ nudgeX = _cellToAbsolute4[0],
1642
+ nudgeY = _cellToAbsolute4[1];
1542
1643
 
1543
1644
  callback(newOffset, maxXY(maxScroll, scroll));
1544
1645
  setTimeout(function () {
@@ -1550,6 +1651,85 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1550
1651
  }
1551
1652
  };
1552
1653
 
1654
+ var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
1655
+ var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
1656
+
1657
+ return {
1658
+ freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
1659
+ freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
1660
+ hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
1661
+ hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
1662
+ hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
1663
+ hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
1664
+ columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
1665
+ rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
1666
+ shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
1667
+ shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
1668
+ shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
1669
+ };
1670
+ };
1671
+ var resolveCellStyle = function resolveCellStyle(optionalStyle, defaultStyle) {
1672
+ return _extends({}, defaultStyle, optionalStyle);
1673
+ };
1674
+ var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
1675
+ if (alignment === void 0) {
1676
+ alignment = style.textAlign;
1677
+ }
1678
+
1679
+ if (alignment === 'left') {
1680
+ return start + style.marginLeft;
1681
+ } else if (alignment === 'center') {
1682
+ return start + cellSize * 0.5 - imageWidth / 2;
1683
+ } else if (alignment === 'right') {
1684
+ return start + (cellSize - style.marginRight - imageWidth);
1685
+ }
1686
+
1687
+ return start;
1688
+ };
1689
+
1690
+ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle) {
1691
+ var context = useMemo(function () {
1692
+ return document.createElement('canvas').getContext('2d');
1693
+ }, []);
1694
+ var getAutoSizeWidth = useCallback(function (x) {
1695
+ if (!context) return 0;
1696
+ var maxWidth = 0;
1697
+
1698
+ for (var _iterator = _createForOfIteratorHelperLoose(rows), _step; !(_step = _iterator()).done;) {
1699
+ var y = _step.value;
1700
+ var cellContent = displayData(x, y);
1701
+
1702
+ if (cellContent != null) {
1703
+ var style = cellStyle(x, y);
1704
+ var finalStyle = resolveCellStyle(style, DEFAULT_CELL_STYLE);
1705
+ context.fillStyle = finalStyle.color;
1706
+ context.font = finalStyle.weight + ' ' + finalStyle.fontSize + 'px ' + finalStyle.fontFamily;
1707
+
1708
+ if (typeof cellContent === 'string' || typeof cellContent === 'number') {
1709
+ var _context$measureText = context.measureText(cellContent.toString()),
1710
+ width = _context$measureText.width;
1711
+
1712
+ maxWidth = Math.max(maxWidth, width + finalStyle.marginLeft + finalStyle.marginRight);
1713
+ } else if (typeof cellContent === 'object') {
1714
+ for (var _iterator2 = _createForOfIteratorHelperLoose(cellContent.items), _step2; !(_step2 = _iterator2()).done;) {
1715
+ var obj = _step2.value;
1716
+
1717
+ if (typeof obj.content === 'string' || typeof obj.content === 'number') {
1718
+ var _context$measureText2 = context.measureText(obj.content.toString()),
1719
+ _width = _context$measureText2.width;
1720
+
1721
+ maxWidth = Math.max(maxWidth, obj.x + _width);
1722
+ }
1723
+ }
1724
+ }
1725
+ }
1726
+ }
1727
+
1728
+ return Math.ceil(maxWidth);
1729
+ }, [context]);
1730
+ return getAutoSizeWidth;
1731
+ };
1732
+
1553
1733
  var useClipboardCopy = function useClipboardCopy(textAreaRef, selection, editMode, editData) {
1554
1734
  useLayoutEffect(function () {
1555
1735
  var textArea = textAreaRef.current;
@@ -2172,42 +2352,6 @@ var makeIntMap = function makeIntMap(initialSize) {
2172
2352
  };
2173
2353
  };
2174
2354
 
2175
- var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
2176
- var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
2177
-
2178
- return {
2179
- freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
2180
- freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
2181
- hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
2182
- hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
2183
- hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
2184
- hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
2185
- columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
2186
- rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
2187
- shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
2188
- shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
2189
- shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
2190
- };
2191
- };
2192
- var resolveCellStyle = function resolveCellStyle(optionalStyle, defaultStyle) {
2193
- return _extends({}, defaultStyle, optionalStyle);
2194
- };
2195
- var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
2196
- if (alignment === void 0) {
2197
- alignment = style.textAlign;
2198
- }
2199
-
2200
- if (alignment === 'left') {
2201
- return start + style.marginLeft;
2202
- } else if (alignment === 'center') {
2203
- return start + cellSize * 0.5 - imageWidth / 2;
2204
- } else if (alignment === 'right') {
2205
- return start + (cellSize - style.marginRight - imageWidth);
2206
- }
2207
-
2208
- return start;
2209
- };
2210
-
2211
2355
  var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
2212
2356
  var canvas = context.canvas;
2213
2357
  var width = canvas.width,
@@ -3003,6 +3147,23 @@ var Sheet = forwardRef(function (props, ref) {
3003
3147
  }
3004
3148
  }, [visibleCells, props.onScrollChange]);
3005
3149
 
3150
+ var scrollToSelection = function scrollToSelection(selection, toHead) {
3151
+ if (toHead === void 0) {
3152
+ toHead = false;
3153
+ }
3154
+
3155
+ var overlay = overlayRef.current;
3156
+ if (!overlay) return;
3157
+ var anchor = selection[0],
3158
+ head = selection[1];
3159
+ var view = [canvasWidth, canvasHeight];
3160
+ var freeze = [freezeColumns, freezeRows];
3161
+ scrollToCell(overlay, toHead ? head : anchor, view, freeze, dataOffset, maxScroll, cellLayout, function (dataOffset, maxScroll) {
3162
+ setDataOffset(dataOffset);
3163
+ setMaxScroll(maxScroll);
3164
+ });
3165
+ };
3166
+
3006
3167
  var changeSelection = function changeSelection(newSelection, scrollTo, toHead) {
3007
3168
  if (scrollTo === void 0) {
3008
3169
  scrollTo = true;
@@ -3020,12 +3181,7 @@ var Sheet = forwardRef(function (props, ref) {
3020
3181
  if (!overlay) return;
3021
3182
 
3022
3183
  if (scrollTo) {
3023
- var anchor = newSelection[0],
3024
- head = newSelection[1];
3025
- scrollToCell(overlay, toHead ? head : anchor, [canvasWidth, canvasHeight], [freezeColumns, freezeRows], dataOffset, maxScroll, cellLayout, function (dataOffset, maxScroll) {
3026
- setDataOffset(dataOffset);
3027
- setMaxScroll(maxScroll);
3028
- });
3184
+ scrollToSelection(newSelection, toHead);
3029
3185
  }
3030
3186
 
3031
3187
  if (props.onSelectionChanged) {
@@ -3080,13 +3236,23 @@ var Sheet = forwardRef(function (props, ref) {
3080
3236
  setLastEditKey(editKeys.apply(void 0, editCell));
3081
3237
  };
3082
3238
 
3239
+ var _props$maxColumns = props.maxColumns,
3240
+ maxColumns = _props$maxColumns === void 0 ? Infinity : _props$maxColumns,
3241
+ _props$maxRows = props.maxRows,
3242
+ maxRows = _props$maxRows === void 0 ? Infinity : _props$maxRows;
3243
+ useLayoutEffect(function () {
3244
+ var view = [canvasWidth, canvasHeight];
3245
+ var freeze = [freezeColumns, freezeRows];
3246
+ setDataOffset(clipDataOffset(view, dataOffset, freeze, [maxColumns, maxRows], cellLayout));
3247
+ }, [maxRows, maxColumns]);
3083
3248
  var hitmapRef = useRef(NO_CLICKABLES);
3084
3249
  var textAreaRef = useRef(null);
3085
3250
  useClipboardCopy(textAreaRef, selection, editMode, editData);
3086
3251
  useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
3087
3252
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
3253
+ var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle);
3088
3254
 
3089
- var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, 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),
3255
+ var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, 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),
3090
3256
  mouseHandlers = _useMouse.mouseHandlers,
3091
3257
  knobPosition = _useMouse.knobPosition;
3092
3258