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/autosize.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CellPropertyFunction, CellContentType, Style } from './types';
|
|
2
|
-
export declare const useAutoSizeColumn: (rows: number[], displayData: CellPropertyFunction<CellContentType>, cellStyle: CellPropertyFunction<Style
|
|
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
|
@@ -1690,46 +1690,73 @@ var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth,
|
|
|
1690
1690
|
return start;
|
|
1691
1691
|
};
|
|
1692
1692
|
|
|
1693
|
-
var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle) {
|
|
1693
|
+
var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth) {
|
|
1694
1694
|
var context = React.useMemo(function () {
|
|
1695
1695
|
return document.createElement('canvas').getContext('2d');
|
|
1696
1696
|
}, []);
|
|
1697
1697
|
var getAutoSizeWidth = React.useCallback(function (x) {
|
|
1698
1698
|
if (!context) return 0;
|
|
1699
|
-
var maxWidth = 0;
|
|
1700
1699
|
|
|
1701
|
-
|
|
1702
|
-
var
|
|
1703
|
-
|
|
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
1704
|
|
|
1705
|
-
if (cellContent
|
|
1706
|
-
var
|
|
1707
|
-
|
|
1708
|
-
context.fillStyle = finalStyle.color;
|
|
1709
|
-
context.font = finalStyle.weight + ' ' + finalStyle.fontSize + 'px ' + finalStyle.fontFamily;
|
|
1705
|
+
if (typeof cellContent === 'string' || typeof cellContent === 'number') {
|
|
1706
|
+
var _context$measureText = context.measureText(cellContent.toString()),
|
|
1707
|
+
width = _context$measureText.width;
|
|
1710
1708
|
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1709
|
+
return width + inlineMargin;
|
|
1710
|
+
} else if (typeof cellContent === 'object') {
|
|
1711
|
+
var _maxWidth = 0;
|
|
1712
|
+
var extraWidth = 0;
|
|
1714
1713
|
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
var obj = _step2.value;
|
|
1714
|
+
for (var _iterator = _createForOfIteratorHelperLoose(cellContent.items), _step; !(_step = _iterator()).done;) {
|
|
1715
|
+
var obj = _step.value;
|
|
1716
|
+
var _width = 0;
|
|
1719
1717
|
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1718
|
+
if (typeof obj.content === 'string' || typeof obj.content === 'number') {
|
|
1719
|
+
var _context$measureText2 = context.measureText(obj.content.toString()),
|
|
1720
|
+
w = _context$measureText2.width;
|
|
1723
1721
|
|
|
1724
|
-
|
|
1725
|
-
|
|
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);
|
|
1726
1731
|
}
|
|
1727
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));
|
|
1728
1755
|
}
|
|
1729
1756
|
}
|
|
1730
1757
|
|
|
1731
|
-
return Math.ceil(maxWidth);
|
|
1732
|
-
}, [context]);
|
|
1758
|
+
return Math.ceil(Math.min(canvasWidth, maxWidth));
|
|
1759
|
+
}, [context, displayData, cellStyle, columnHeaders, columnHeaderStyle]);
|
|
1733
1760
|
return getAutoSizeWidth;
|
|
1734
1761
|
};
|
|
1735
1762
|
|
|
@@ -3253,7 +3280,7 @@ var Sheet = React.forwardRef(function (props, ref) {
|
|
|
3253
3280
|
useClipboardCopy(textAreaRef, selection, editMode, editData);
|
|
3254
3281
|
useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
|
|
3255
3282
|
var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
|
|
3256
|
-
var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle);
|
|
3283
|
+
var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth);
|
|
3257
3284
|
|
|
3258
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),
|
|
3259
3286
|
mouseHandlers = _useMouse.mouseHandlers,
|