sheet-happens 0.0.41 → 0.0.43

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.
@@ -1687,46 +1687,73 @@ var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth,
1687
1687
  return start;
1688
1688
  };
1689
1689
 
1690
- var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle) {
1690
+ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth) {
1691
1691
  var context = useMemo(function () {
1692
1692
  return document.createElement('canvas').getContext('2d');
1693
1693
  }, []);
1694
1694
  var getAutoSizeWidth = useCallback(function (x) {
1695
1695
  if (!context) return 0;
1696
- var maxWidth = 0;
1697
1696
 
1698
- for (var _iterator = _createForOfIteratorHelperLoose(rows), _step; !(_step = _iterator()).done;) {
1699
- var y = _step.value;
1700
- var cellContent = displayData(x, y);
1697
+ var getWidth = function getWidth(cellContent, style) {
1698
+ var finalStyle = resolveCellStyle(style, DEFAULT_CELL_STYLE);
1699
+ context.font = finalStyle.weight + ' ' + finalStyle.fontSize + 'px ' + finalStyle.fontFamily;
1700
+ var inlineMargin = finalStyle.marginLeft + finalStyle.marginRight;
1701
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;
1702
+ if (typeof cellContent === 'string' || typeof cellContent === 'number') {
1703
+ var _context$measureText = context.measureText(cellContent.toString()),
1704
+ width = _context$measureText.width;
1707
1705
 
1708
- if (typeof cellContent === 'string' || typeof cellContent === 'number') {
1709
- var _context$measureText = context.measureText(cellContent.toString()),
1710
- width = _context$measureText.width;
1706
+ return width + inlineMargin;
1707
+ } else if (typeof cellContent === 'object') {
1708
+ var _maxWidth = 0;
1709
+ var extraWidth = 0;
1711
1710
 
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;
1711
+ for (var _iterator = _createForOfIteratorHelperLoose(cellContent.items), _step; !(_step = _iterator()).done;) {
1712
+ var obj = _step.value;
1713
+ var _width = 0;
1716
1714
 
1717
- if (typeof obj.content === 'string' || typeof obj.content === 'number') {
1718
- var _context$measureText2 = context.measureText(obj.content.toString()),
1719
- _width = _context$measureText2.width;
1715
+ if (typeof obj.content === 'string' || typeof obj.content === 'number') {
1716
+ var _context$measureText2 = context.measureText(obj.content.toString()),
1717
+ w = _context$measureText2.width;
1720
1718
 
1721
- maxWidth = Math.max(maxWidth, obj.x + _width);
1722
- }
1719
+ _width = obj.x + w + inlineMargin;
1720
+ } else if (obj.width) {
1721
+ _width = obj.width;
1722
+ }
1723
+
1724
+ if (obj.horizontalAlign === 'right') {
1725
+ extraWidth += _width;
1726
+ } else {
1727
+ _maxWidth = Math.max(_maxWidth, _width);
1723
1728
  }
1724
1729
  }
1730
+
1731
+ return _maxWidth + extraWidth;
1725
1732
  }
1733
+
1734
+ return 0;
1735
+ };
1736
+
1737
+ var maxWidth = SIZES.minimumWidth;
1738
+ var headerContent = columnHeaders(x);
1739
+
1740
+ if (headerContent) {
1741
+ var headerStyle = columnHeaderStyle(x);
1742
+ maxWidth = Math.max(maxWidth, getWidth(headerContent, headerStyle));
1726
1743
  }
1727
1744
 
1728
- return Math.ceil(maxWidth);
1729
- }, [context]);
1745
+ for (var _iterator2 = _createForOfIteratorHelperLoose(rows), _step2; !(_step2 = _iterator2()).done;) {
1746
+ var y = _step2.value;
1747
+ var cellContent = displayData(x, y);
1748
+
1749
+ if (cellContent != null) {
1750
+ var style = cellStyle(x, y);
1751
+ maxWidth = Math.max(maxWidth, getWidth(cellContent, style));
1752
+ }
1753
+ }
1754
+
1755
+ return Math.ceil(Math.min(canvasWidth, maxWidth));
1756
+ }, [context, displayData, cellStyle, columnHeaders, columnHeaderStyle]);
1730
1757
  return getAutoSizeWidth;
1731
1758
  };
1732
1759
 
@@ -2148,10 +2175,13 @@ var makeCellLayout = function makeCellLayout(freeze, indent, offset, columns, ro
2148
2175
 
2149
2176
  var getVisibleIndices = function getVisibleIndices(view, indent, freeze, offset, layout) {
2150
2177
  var indices = [].concat(seq(freeze));
2151
- var getStart = layout.getStart;
2152
- var relative = view - indent + getStart(offset);
2178
+ var getStart = layout.getStart,
2179
+ getEnd = layout.getEnd;
2180
+ var frozen = getEnd(freeze - 1);
2181
+ var notFrozen = getStart(offset + freeze);
2182
+ var relative = view - indent - frozen;
2153
2183
 
2154
- for (var i = offset + freeze; getStart(i) <= relative; ++i) {
2184
+ for (var i = offset + freeze; getStart(i) - notFrozen <= relative; ++i) {
2155
2185
  indices.push(i);
2156
2186
  }
2157
2187
 
@@ -3250,7 +3280,7 @@ var Sheet = forwardRef(function (props, ref) {
3250
3280
  useClipboardCopy(textAreaRef, selection, editMode, editData);
3251
3281
  useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
3252
3282
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
3253
- var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle);
3283
+ var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth);
3254
3284
 
3255
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),
3256
3286
  mouseHandlers = _useMouse.mouseHandlers,