sheet-happens 0.0.41 → 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.
- package/dist/autosize.d.ts +2 -2
- package/dist/index.js +52 -25
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +52 -25
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -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
|
-
|
|
1699
|
-
var
|
|
1700
|
-
|
|
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
|
|
1703
|
-
var
|
|
1704
|
-
|
|
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
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1706
|
+
return width + inlineMargin;
|
|
1707
|
+
} else if (typeof cellContent === 'object') {
|
|
1708
|
+
var _maxWidth = 0;
|
|
1709
|
+
var extraWidth = 0;
|
|
1711
1710
|
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
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
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
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
|
-
|
|
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;
|
|
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));
|
|
1743
|
+
}
|
|
1744
|
+
|
|
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));
|
|
1725
1752
|
}
|
|
1726
1753
|
}
|
|
1727
1754
|
|
|
1728
|
-
return Math.ceil(maxWidth);
|
|
1729
|
-
}, [context]);
|
|
1755
|
+
return Math.ceil(Math.min(canvasWidth, maxWidth));
|
|
1756
|
+
}, [context, displayData, cellStyle, columnHeaders, columnHeaderStyle]);
|
|
1730
1757
|
return getAutoSizeWidth;
|
|
1731
1758
|
};
|
|
1732
1759
|
|
|
@@ -3250,7 +3277,7 @@ var Sheet = forwardRef(function (props, ref) {
|
|
|
3250
3277
|
useClipboardCopy(textAreaRef, selection, editMode, editData);
|
|
3251
3278
|
useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
|
|
3252
3279
|
var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
|
|
3253
|
-
var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle);
|
|
3280
|
+
var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth);
|
|
3254
3281
|
|
|
3255
3282
|
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
3283
|
mouseHandlers = _useMouse.mouseHandlers,
|