sheet-happens 0.0.40 → 0.0.42

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.
@@ -0,0 +1,2 @@
1
+ import { RowOrColumnPropertyFunction, CellPropertyFunction, CellContentType, Style } from './types';
2
+ export declare const useAutoSizeColumn: (rows: number[], displayData: CellPropertyFunction<CellContentType>, cellStyle: CellPropertyFunction<Style>, columnHeaders: RowOrColumnPropertyFunction<CellContentType>, columnHeaderStyle: RowOrColumnPropertyFunction<Style>, canvasWidth: number) => (x: number) => number;
package/dist/index.js CHANGED
@@ -351,11 +351,6 @@ var orientSelection = function orientSelection(normalized, to) {
351
351
  var swapY = (ay - hy || 1) * (bottom - top || 1) < 0;
352
352
  return [[swapX ? right : left, swapY ? bottom : top], [swapX ? left : right, swapY ? top : bottom]];
353
353
  };
354
- var clipSelection = function clipSelection(selection, max) {
355
- var anchor = selection[0],
356
- head = selection[1];
357
- return [minXY(anchor, max), minXY(head, max)];
358
- };
359
354
 
360
355
  var LIMIT = 1000;
361
356
 
@@ -537,7 +532,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
537
532
  return maxXY(cell, [0, 0]);
538
533
  };
539
534
 
540
- 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) {
535
+ 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) {
541
536
  var _useState = React.useState(null),
542
537
  hitTarget = _useState[0],
543
538
  setHitTarget = _useState[1];
@@ -627,6 +622,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
627
622
 
628
623
  var rect = e.target.getBoundingClientRect();
629
624
  var xy = [e.clientX - rect.left, e.clientY - rect.top];
625
+
626
+ if (xy[0] > e.target.clientWidth || xy[1] > e.target.clientHeight) {
627
+ return null;
628
+ }
629
+
630
630
  return xy;
631
631
  }, []);
632
632
  var getScrollPosition = React.useCallback(function (e) {
@@ -1046,9 +1046,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1046
1046
  pixelToRow = _ref$current3$cellLay.pixelToRow,
1047
1047
  getIndentX = _ref$current3$cellLay.getIndentX,
1048
1048
  getIndentY = _ref$current3$cellLay.getIndentY;
1049
+ window.document.body.style.cursor = 'auto';
1049
1050
  var xy = getMousePosition(e);
1050
1051
  if (!xy) return;
1051
- window.document.body.style.cursor = 'auto';
1052
1052
  var hitTarget = getMouseHit(xy);
1053
1053
 
1054
1054
  if (hitTarget) {
@@ -1291,11 +1291,48 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1291
1291
  }
1292
1292
  }, [getMousePosition, getScrollPosition, getMouseHit, onCellWidthChange, onCellHeightChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn, columnGroupKeys, rowGroupKeys]);
1293
1293
  var onDoubleClick = React.useCallback(function (e) {
1294
- var pixelToCell = ref.current.cellLayout.pixelToCell;
1294
+ var _ref$current4 = ref.current,
1295
+ selection = _ref$current4.selection,
1296
+ _ref$current4$cellLay = _ref$current4.cellLayout,
1297
+ pixelToCell = _ref$current4$cellLay.pixelToCell,
1298
+ columnToPixel = _ref$current4$cellLay.columnToPixel;
1295
1299
  e.preventDefault();
1296
1300
  if (e.shiftKey) return;
1297
1301
  var xy = getMousePosition(e);
1298
1302
  if (!xy) return;
1303
+ var x = xy[0];
1304
+ var columns = visibleCells.columns;
1305
+
1306
+ if (onCellWidthChange) {
1307
+ var autosized = [];
1308
+
1309
+ for (var _iterator10 = _createForOfIteratorHelperLoose(columns), _step10; !(_step10 = _iterator10()).done;) {
1310
+ var index = _step10.value;
1311
+ var edge = columnToPixel(index, 1);
1312
+
1313
+ if (Math.abs(edge - x) < SIZES.resizeZone && canSizeColumn(index)) {
1314
+ var _normalizeSelection5 = normalizeSelection(selection),
1315
+ _normalizeSelection5$ = _normalizeSelection5[0],
1316
+ minX = _normalizeSelection5$[0],
1317
+ _normalizeSelection5$2 = _normalizeSelection5[1],
1318
+ maxX = _normalizeSelection5$2[0];
1319
+
1320
+ var indices = isColumnSelection(selection) && index >= minX && index <= maxX ? mapSelectionColumns(selection)(function (i) {
1321
+ return i;
1322
+ }) : [index];
1323
+ autosized.push.apply(autosized, indices);
1324
+ }
1325
+ }
1326
+
1327
+ for (var _i = 0, _autosized = autosized; _i < _autosized.length; _i++) {
1328
+ var column = _autosized[_i];
1329
+ onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(column - 1);
1330
+ onCellWidthChange([column], getAutoSizeWidth(column));
1331
+ }
1332
+
1333
+ if (autosized.length) return;
1334
+ }
1335
+
1299
1336
  var hitTarget = getMouseHit(xy);
1300
1337
 
1301
1338
  if (hitTarget) {
@@ -1306,7 +1343,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1306
1343
  var editCell = pixelToCell(xy);
1307
1344
  if (editMode) onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1308
1345
  onEdit === null || onEdit === void 0 ? void 0 : onEdit(editCell);
1309
- }, [getMousePosition, getMouseHit, onCommit, onEdit]);
1346
+ }, [getMousePosition, getMouseHit, onCommit, onEdit, onInvalidateColumn, onCellWidthChange, getAutoSizeWidth, visibleCells, canSizeColumn]);
1310
1347
  var onContextMenu = React.useCallback(function (e) {
1311
1348
  var _ref$current$cellLayo2 = ref.current.cellLayout,
1312
1349
  pixelToCell = _ref$current$cellLayo2.pixelToCell,
@@ -1353,21 +1390,21 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1353
1390
  };
1354
1391
 
1355
1392
  var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly) {
1356
- var _normalizeSelection5 = normalizeSelection(knobArea),
1357
- _normalizeSelection5$ = _normalizeSelection5[0],
1358
- kx1 = _normalizeSelection5$[0],
1359
- ky1 = _normalizeSelection5$[1],
1360
- _normalizeSelection5$2 = _normalizeSelection5[1],
1361
- kx2 = _normalizeSelection5$2[0],
1362
- ky2 = _normalizeSelection5$2[1];
1363
-
1364
- var _normalizeSelection6 = normalizeSelection(selection),
1393
+ var _normalizeSelection6 = normalizeSelection(knobArea),
1365
1394
  _normalizeSelection6$ = _normalizeSelection6[0],
1366
- sx1 = _normalizeSelection6$[0],
1367
- sy1 = _normalizeSelection6$[1],
1395
+ kx1 = _normalizeSelection6$[0],
1396
+ ky1 = _normalizeSelection6$[1],
1368
1397
  _normalizeSelection6$2 = _normalizeSelection6[1],
1369
- sx2 = _normalizeSelection6$2[0],
1370
- sy2 = _normalizeSelection6$2[1];
1398
+ kx2 = _normalizeSelection6$2[0],
1399
+ ky2 = _normalizeSelection6$2[1];
1400
+
1401
+ var _normalizeSelection7 = normalizeSelection(selection),
1402
+ _normalizeSelection7$ = _normalizeSelection7[0],
1403
+ sx1 = _normalizeSelection7$[0],
1404
+ sy1 = _normalizeSelection7$[1],
1405
+ _normalizeSelection7$2 = _normalizeSelection7[1],
1406
+ sx2 = _normalizeSelection7$2[0],
1407
+ sy2 = _normalizeSelection7$2[1];
1371
1408
 
1372
1409
  var fx1 = kx1;
1373
1410
  var fy1 = ky1;
@@ -1492,30 +1529,81 @@ var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange
1492
1529
  }
1493
1530
  }, [cellLayout, onOffsetChange, onMaxScrollChange]);
1494
1531
  };
1495
- var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, maxCells, maxScroll, cellLayout, callback) {
1496
- var x = cell[0],
1497
- y = cell[1];
1498
- var w = view[0],
1499
- h = view[1];
1500
- var offsetX = offset[0],
1501
- offsetY = offset[1];
1532
+ var clipDataOffset = function clipDataOffset(view, offset, freeze, maxCells, cellLayout) {
1533
+ var newX = offset[0],
1534
+ newY = offset[1];
1502
1535
  var maxColumns = maxCells[0],
1503
1536
  maxRows = maxCells[1];
1537
+ var absoluteToColumn = cellLayout.absoluteToColumn,
1538
+ columnToAbsolute = cellLayout.columnToAbsolute,
1539
+ absoluteToRow = cellLayout.absoluteToRow,
1540
+ rowToAbsolute = cellLayout.rowToAbsolute;
1541
+
1542
+ var _getViewExtent = getViewExtent(view, [newX, newY], freeze, cellLayout),
1543
+ _getViewExtent$edge = _getViewExtent.edge,
1544
+ rightEdge = _getViewExtent$edge[0],
1545
+ bottomEdge = _getViewExtent$edge[1],
1546
+ _getViewExtent$viewpo = _getViewExtent.viewport,
1547
+ scrollW = _getViewExtent$viewpo[0],
1548
+ scrollH = _getViewExtent$viewpo[1];
1549
+
1550
+ if (rightEdge > maxColumns) {
1551
+ var remainder = columnToAbsolute(maxColumns) - columnToAbsolute(newX);
1552
+ newX = absoluteToColumn(columnToAbsolute(newX) - scrollW + remainder) + 1;
1553
+ }
1554
+
1555
+ if (bottomEdge > maxRows) {
1556
+ var _remainder = rowToAbsolute(maxRows) - rowToAbsolute(newY);
1557
+
1558
+ newY = absoluteToRow(rowToAbsolute(newY) - scrollH + _remainder) + 1;
1559
+ }
1560
+
1561
+ return [newX, newY];
1562
+ };
1563
+ var getViewExtent = function getViewExtent(view, offset, freeze, cellLayout) {
1504
1564
  var cellToAbsolute = cellLayout.cellToAbsolute,
1505
- cellToPixel = cellLayout.cellToPixel,
1506
- columnToPixel = cellLayout.columnToPixel,
1507
- rowToPixel = cellLayout.rowToPixel,
1508
1565
  absoluteToColumn = cellLayout.absoluteToColumn,
1509
1566
  columnToAbsolute = cellLayout.columnToAbsolute,
1510
1567
  absoluteToRow = cellLayout.absoluteToRow,
1511
1568
  rowToAbsolute = cellLayout.rowToAbsolute,
1512
1569
  getIndentX = cellLayout.getIndentX,
1513
1570
  getIndentY = cellLayout.getIndentY;
1571
+ var x = offset[0],
1572
+ y = offset[1];
1573
+ var w = view[0],
1574
+ h = view[1];
1514
1575
 
1515
1576
  var _cellToAbsolute2 = cellToAbsolute(freeze),
1516
1577
  frozenX = _cellToAbsolute2[0],
1517
1578
  frozenY = _cellToAbsolute2[1];
1518
1579
 
1580
+ var scrollW = w - frozenX - getIndentX();
1581
+ var scrollH = h - frozenY - getIndentY();
1582
+ var leftEdge = x + freeze[0];
1583
+ var topEdge = y + freeze[1];
1584
+ var rightEdge = absoluteToColumn(columnToAbsolute(leftEdge) + scrollW);
1585
+ var bottomEdge = absoluteToRow(rowToAbsolute(topEdge) + scrollH);
1586
+ return {
1587
+ edge: [rightEdge, bottomEdge],
1588
+ viewport: [scrollW, scrollH]
1589
+ };
1590
+ };
1591
+ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, maxScroll, cellLayout, callback) {
1592
+ var x = cell[0],
1593
+ y = cell[1];
1594
+ var w = view[0],
1595
+ h = view[1];
1596
+ var offsetX = offset[0],
1597
+ offsetY = offset[1];
1598
+ var cellToAbsolute = cellLayout.cellToAbsolute,
1599
+ cellToPixel = cellLayout.cellToPixel,
1600
+ columnToPixel = cellLayout.columnToPixel,
1601
+ rowToPixel = cellLayout.rowToPixel;
1602
+
1603
+ var _cellToAbsolute3 = cellToAbsolute(freeze),
1604
+ frozenX = _cellToAbsolute3[0],
1605
+ frozenY = _cellToAbsolute3[1];
1606
+
1519
1607
  var _cellToPixel = cellToPixel(cell),
1520
1608
  left = _cellToPixel[0],
1521
1609
  top = _cellToPixel[1];
@@ -1529,25 +1617,10 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1529
1617
 
1530
1618
  if (left <= frozenX) {
1531
1619
  newX = x - freeze[0];
1532
- var scrollW = w - frozenX - getIndentX();
1533
- var rightEdge = absoluteToColumn(columnToAbsolute(newX) + scrollW);
1534
-
1535
- if (rightEdge > maxColumns) {
1536
- var remainder = columnToAbsolute(maxColumns) - columnToAbsolute(newX);
1537
- newX = absoluteToColumn(columnToAbsolute(newX) - scrollW + remainder) + 1;
1538
- }
1539
1620
  }
1540
1621
 
1541
1622
  if (top <= frozenY) {
1542
1623
  newY = y - freeze[1];
1543
- var scrollH = h - frozenY - getIndentY();
1544
- var bottomEdge = absoluteToRow(rowToAbsolute(newY) + scrollH);
1545
-
1546
- if (bottomEdge > maxRows) {
1547
- var _remainder = rowToAbsolute(maxRows) - rowToAbsolute(newY);
1548
-
1549
- newY = absoluteToRow(rowToAbsolute(newY) - scrollH + _remainder) + 1;
1550
- }
1551
1624
  }
1552
1625
 
1553
1626
  if (right > w) {
@@ -1567,9 +1640,9 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1567
1640
  if (!isSameXY(newOffset, offset)) {
1568
1641
  var scroll = cellToAbsolute(newOffset);
1569
1642
 
1570
- var _cellToAbsolute3 = cellToAbsolute([0, 0], [0.5, 0.5]),
1571
- nudgeX = _cellToAbsolute3[0],
1572
- nudgeY = _cellToAbsolute3[1];
1643
+ var _cellToAbsolute4 = cellToAbsolute([0, 0], [0.5, 0.5]),
1644
+ nudgeX = _cellToAbsolute4[0],
1645
+ nudgeY = _cellToAbsolute4[1];
1573
1646
 
1574
1647
  callback(newOffset, maxXY(maxScroll, scroll));
1575
1648
  setTimeout(function () {
@@ -1581,6 +1654,112 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1581
1654
  }
1582
1655
  };
1583
1656
 
1657
+ var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
1658
+ var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
1659
+
1660
+ return {
1661
+ freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
1662
+ freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
1663
+ hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
1664
+ hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
1665
+ hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
1666
+ hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
1667
+ columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
1668
+ rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
1669
+ shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
1670
+ shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
1671
+ shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
1672
+ };
1673
+ };
1674
+ var resolveCellStyle = function resolveCellStyle(optionalStyle, defaultStyle) {
1675
+ return _extends({}, defaultStyle, optionalStyle);
1676
+ };
1677
+ var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
1678
+ if (alignment === void 0) {
1679
+ alignment = style.textAlign;
1680
+ }
1681
+
1682
+ if (alignment === 'left') {
1683
+ return start + style.marginLeft;
1684
+ } else if (alignment === 'center') {
1685
+ return start + cellSize * 0.5 - imageWidth / 2;
1686
+ } else if (alignment === 'right') {
1687
+ return start + (cellSize - style.marginRight - imageWidth);
1688
+ }
1689
+
1690
+ return start;
1691
+ };
1692
+
1693
+ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth) {
1694
+ var context = React.useMemo(function () {
1695
+ return document.createElement('canvas').getContext('2d');
1696
+ }, []);
1697
+ var getAutoSizeWidth = React.useCallback(function (x) {
1698
+ if (!context) return 0;
1699
+
1700
+ var getWidth = function getWidth(cellContent, style) {
1701
+ var finalStyle = resolveCellStyle(style, DEFAULT_CELL_STYLE);
1702
+ context.font = finalStyle.weight + ' ' + finalStyle.fontSize + 'px ' + finalStyle.fontFamily;
1703
+ var inlineMargin = finalStyle.marginLeft + finalStyle.marginRight;
1704
+
1705
+ if (typeof cellContent === 'string' || typeof cellContent === 'number') {
1706
+ var _context$measureText = context.measureText(cellContent.toString()),
1707
+ width = _context$measureText.width;
1708
+
1709
+ return width + inlineMargin;
1710
+ } else if (typeof cellContent === 'object') {
1711
+ var _maxWidth = 0;
1712
+ var extraWidth = 0;
1713
+
1714
+ for (var _iterator = _createForOfIteratorHelperLoose(cellContent.items), _step; !(_step = _iterator()).done;) {
1715
+ var obj = _step.value;
1716
+ var _width = 0;
1717
+
1718
+ if (typeof obj.content === 'string' || typeof obj.content === 'number') {
1719
+ var _context$measureText2 = context.measureText(obj.content.toString()),
1720
+ w = _context$measureText2.width;
1721
+
1722
+ _width = obj.x + w + inlineMargin;
1723
+ } else if (obj.width) {
1724
+ _width = obj.width;
1725
+ }
1726
+
1727
+ if (obj.horizontalAlign === 'right') {
1728
+ extraWidth += _width;
1729
+ } else {
1730
+ _maxWidth = Math.max(_maxWidth, _width);
1731
+ }
1732
+ }
1733
+
1734
+ return _maxWidth + extraWidth;
1735
+ }
1736
+
1737
+ return 0;
1738
+ };
1739
+
1740
+ var maxWidth = SIZES.minimumWidth;
1741
+ var headerContent = columnHeaders(x);
1742
+
1743
+ if (headerContent) {
1744
+ var headerStyle = columnHeaderStyle(x);
1745
+ maxWidth = Math.max(maxWidth, getWidth(headerContent, headerStyle));
1746
+ }
1747
+
1748
+ for (var _iterator2 = _createForOfIteratorHelperLoose(rows), _step2; !(_step2 = _iterator2()).done;) {
1749
+ var y = _step2.value;
1750
+ var cellContent = displayData(x, y);
1751
+
1752
+ if (cellContent != null) {
1753
+ var style = cellStyle(x, y);
1754
+ maxWidth = Math.max(maxWidth, getWidth(cellContent, style));
1755
+ }
1756
+ }
1757
+
1758
+ return Math.ceil(Math.min(canvasWidth, maxWidth));
1759
+ }, [context, displayData, cellStyle, columnHeaders, columnHeaderStyle]);
1760
+ return getAutoSizeWidth;
1761
+ };
1762
+
1584
1763
  var useClipboardCopy = function useClipboardCopy(textAreaRef, selection, editMode, editData) {
1585
1764
  React.useLayoutEffect(function () {
1586
1765
  var textArea = textAreaRef.current;
@@ -2203,42 +2382,6 @@ var makeIntMap = function makeIntMap(initialSize) {
2203
2382
  };
2204
2383
  };
2205
2384
 
2206
- var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
2207
- var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
2208
-
2209
- return {
2210
- freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
2211
- freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
2212
- hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
2213
- hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
2214
- hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
2215
- hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
2216
- columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
2217
- rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
2218
- shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
2219
- shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
2220
- shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
2221
- };
2222
- };
2223
- var resolveCellStyle = function resolveCellStyle(optionalStyle, defaultStyle) {
2224
- return _extends({}, defaultStyle, optionalStyle);
2225
- };
2226
- var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
2227
- if (alignment === void 0) {
2228
- alignment = style.textAlign;
2229
- }
2230
-
2231
- if (alignment === 'left') {
2232
- return start + style.marginLeft;
2233
- } else if (alignment === 'center') {
2234
- return start + cellSize * 0.5 - imageWidth / 2;
2235
- } else if (alignment === 'right') {
2236
- return start + (cellSize - style.marginRight - imageWidth);
2237
- }
2238
-
2239
- return start;
2240
- };
2241
-
2242
2385
  var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
2243
2386
  var canvas = context.canvas;
2244
2387
  var width = canvas.width,
@@ -3034,6 +3177,23 @@ var Sheet = React.forwardRef(function (props, ref) {
3034
3177
  }
3035
3178
  }, [visibleCells, props.onScrollChange]);
3036
3179
 
3180
+ var scrollToSelection = function scrollToSelection(selection, toHead) {
3181
+ if (toHead === void 0) {
3182
+ toHead = false;
3183
+ }
3184
+
3185
+ var overlay = overlayRef.current;
3186
+ if (!overlay) return;
3187
+ var anchor = selection[0],
3188
+ head = selection[1];
3189
+ var view = [canvasWidth, canvasHeight];
3190
+ var freeze = [freezeColumns, freezeRows];
3191
+ scrollToCell(overlay, toHead ? head : anchor, view, freeze, dataOffset, maxScroll, cellLayout, function (dataOffset, maxScroll) {
3192
+ setDataOffset(dataOffset);
3193
+ setMaxScroll(maxScroll);
3194
+ });
3195
+ };
3196
+
3037
3197
  var changeSelection = function changeSelection(newSelection, scrollTo, toHead) {
3038
3198
  if (scrollTo === void 0) {
3039
3199
  scrollTo = true;
@@ -3051,12 +3211,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3051
3211
  if (!overlay) return;
3052
3212
 
3053
3213
  if (scrollTo) {
3054
- var anchor = newSelection[0],
3055
- head = newSelection[1];
3056
- scrollToCell(overlay, toHead ? head : anchor, [canvasWidth, canvasHeight], [freezeColumns, freezeRows], dataOffset, [maxColumns, maxRows], maxScroll, cellLayout, function (dataOffset, maxScroll) {
3057
- setDataOffset(dataOffset);
3058
- setMaxScroll(maxScroll);
3059
- });
3214
+ scrollToSelection(newSelection, toHead);
3060
3215
  }
3061
3216
 
3062
3217
  if (props.onSelectionChanged) {
@@ -3116,24 +3271,18 @@ var Sheet = React.forwardRef(function (props, ref) {
3116
3271
  _props$maxRows = props.maxRows,
3117
3272
  maxRows = _props$maxRows === void 0 ? Infinity : _props$maxRows;
3118
3273
  React.useLayoutEffect(function () {
3119
- var _normalizeSelection2 = normalizeSelection(selection),
3120
- _normalizeSelection2$ = _normalizeSelection2[1],
3121
- maxX = _normalizeSelection2$[0],
3122
- maxY = _normalizeSelection2$[1];
3123
-
3124
- var overflowX = maxX > maxColumns;
3125
- var overflowY = maxY > maxRows;
3126
- if (!overflowX && !overflowY) return;
3127
- var corner = [maxColumns - 1, maxRows - 1];
3128
- changeSelection(clipSelection(selection, corner), true);
3274
+ var view = [canvasWidth, canvasHeight];
3275
+ var freeze = [freezeColumns, freezeRows];
3276
+ setDataOffset(clipDataOffset(view, dataOffset, freeze, [maxColumns, maxRows], cellLayout));
3129
3277
  }, [maxRows, maxColumns]);
3130
3278
  var hitmapRef = React.useRef(NO_CLICKABLES);
3131
3279
  var textAreaRef = React.useRef(null);
3132
3280
  useClipboardCopy(textAreaRef, selection, editMode, editData);
3133
3281
  useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
3134
3282
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
3283
+ var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth);
3135
3284
 
3136
- 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),
3285
+ 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),
3137
3286
  mouseHandlers = _useMouse.mouseHandlers,
3138
3287
  knobPosition = _useMouse.knobPosition;
3139
3288
 
@@ -3192,13 +3341,13 @@ var Sheet = React.forwardRef(function (props, ref) {
3192
3341
  }
3193
3342
 
3194
3343
  if (e.key === 'Backspace' || e.key === 'Delete') {
3195
- var _normalizeSelection3 = normalizeSelection(selection),
3196
- _normalizeSelection3$ = _normalizeSelection3[0],
3197
- x1 = _normalizeSelection3$[0],
3198
- y1 = _normalizeSelection3$[1],
3199
- _normalizeSelection3$2 = _normalizeSelection3[1],
3200
- x2 = _normalizeSelection3$2[0],
3201
- y2 = _normalizeSelection3$2[1];
3344
+ var _normalizeSelection2 = normalizeSelection(selection),
3345
+ _normalizeSelection2$ = _normalizeSelection2[0],
3346
+ x1 = _normalizeSelection2$[0],
3347
+ y1 = _normalizeSelection2$[1],
3348
+ _normalizeSelection2$2 = _normalizeSelection2[1],
3349
+ x2 = _normalizeSelection2$2[0],
3350
+ y2 = _normalizeSelection2$2[1];
3202
3351
 
3203
3352
  if (isRowSelection(selection)) {
3204
3353
  x1 = 0;