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.
- package/dist/autosize.d.ts +2 -0
- package/dist/coordinate.d.ts +1 -0
- package/dist/index.js +232 -66
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +232 -66
- package/dist/index.modern.js.map +1 -1
- package/dist/mouse.d.ts +1 -1
- package/dist/scroll.d.ts +5 -0
- package/dist/sheet.d.ts +2 -0
- package/package.json +1 -1
package/dist/coordinate.d.ts
CHANGED
|
@@ -23,3 +23,4 @@ export declare const isPointInsideSelection: (selection: Rectangle, point: XY) =
|
|
|
23
23
|
export declare const validateSelection: (selection: Rectangle) => Rectangle;
|
|
24
24
|
export declare const normalizeSelection: (selection: Rectangle) => Rectangle;
|
|
25
25
|
export declare const orientSelection: (normalized: Rectangle, to: Rectangle) => Rectangle;
|
|
26
|
+
export declare const clipSelection: (selection: Rectangle, max: XY) => Rectangle;
|
package/dist/index.js
CHANGED
|
@@ -532,7 +532,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
|
|
|
532
532
|
return maxXY(cell, [0, 0]);
|
|
533
533
|
};
|
|
534
534
|
|
|
535
|
-
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) {
|
|
536
536
|
var _useState = React.useState(null),
|
|
537
537
|
hitTarget = _useState[0],
|
|
538
538
|
setHitTarget = _useState[1];
|
|
@@ -622,6 +622,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
622
622
|
|
|
623
623
|
var rect = e.target.getBoundingClientRect();
|
|
624
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
|
+
|
|
625
630
|
return xy;
|
|
626
631
|
}, []);
|
|
627
632
|
var getScrollPosition = React.useCallback(function (e) {
|
|
@@ -1041,9 +1046,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1041
1046
|
pixelToRow = _ref$current3$cellLay.pixelToRow,
|
|
1042
1047
|
getIndentX = _ref$current3$cellLay.getIndentX,
|
|
1043
1048
|
getIndentY = _ref$current3$cellLay.getIndentY;
|
|
1049
|
+
window.document.body.style.cursor = 'auto';
|
|
1044
1050
|
var xy = getMousePosition(e);
|
|
1045
1051
|
if (!xy) return;
|
|
1046
|
-
window.document.body.style.cursor = 'auto';
|
|
1047
1052
|
var hitTarget = getMouseHit(xy);
|
|
1048
1053
|
|
|
1049
1054
|
if (hitTarget) {
|
|
@@ -1286,11 +1291,48 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1286
1291
|
}
|
|
1287
1292
|
}, [getMousePosition, getScrollPosition, getMouseHit, onCellWidthChange, onCellHeightChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn, columnGroupKeys, rowGroupKeys]);
|
|
1288
1293
|
var onDoubleClick = React.useCallback(function (e) {
|
|
1289
|
-
var
|
|
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;
|
|
1290
1299
|
e.preventDefault();
|
|
1291
1300
|
if (e.shiftKey) return;
|
|
1292
1301
|
var xy = getMousePosition(e);
|
|
1293
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
|
+
|
|
1294
1336
|
var hitTarget = getMouseHit(xy);
|
|
1295
1337
|
|
|
1296
1338
|
if (hitTarget) {
|
|
@@ -1301,7 +1343,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1301
1343
|
var editCell = pixelToCell(xy);
|
|
1302
1344
|
if (editMode) onCommit === null || onCommit === void 0 ? void 0 : onCommit();
|
|
1303
1345
|
onEdit === null || onEdit === void 0 ? void 0 : onEdit(editCell);
|
|
1304
|
-
}, [getMousePosition, getMouseHit, onCommit, onEdit]);
|
|
1346
|
+
}, [getMousePosition, getMouseHit, onCommit, onEdit, onInvalidateColumn, onCellWidthChange, getAutoSizeWidth, visibleCells, canSizeColumn]);
|
|
1305
1347
|
var onContextMenu = React.useCallback(function (e) {
|
|
1306
1348
|
var _ref$current$cellLayo2 = ref.current.cellLayout,
|
|
1307
1349
|
pixelToCell = _ref$current$cellLayo2.pixelToCell,
|
|
@@ -1348,21 +1390,21 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1348
1390
|
};
|
|
1349
1391
|
|
|
1350
1392
|
var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly) {
|
|
1351
|
-
var
|
|
1352
|
-
_normalizeSelection5$ = _normalizeSelection5[0],
|
|
1353
|
-
kx1 = _normalizeSelection5$[0],
|
|
1354
|
-
ky1 = _normalizeSelection5$[1],
|
|
1355
|
-
_normalizeSelection5$2 = _normalizeSelection5[1],
|
|
1356
|
-
kx2 = _normalizeSelection5$2[0],
|
|
1357
|
-
ky2 = _normalizeSelection5$2[1];
|
|
1358
|
-
|
|
1359
|
-
var _normalizeSelection6 = normalizeSelection(selection),
|
|
1393
|
+
var _normalizeSelection6 = normalizeSelection(knobArea),
|
|
1360
1394
|
_normalizeSelection6$ = _normalizeSelection6[0],
|
|
1361
|
-
|
|
1362
|
-
|
|
1395
|
+
kx1 = _normalizeSelection6$[0],
|
|
1396
|
+
ky1 = _normalizeSelection6$[1],
|
|
1363
1397
|
_normalizeSelection6$2 = _normalizeSelection6[1],
|
|
1364
|
-
|
|
1365
|
-
|
|
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];
|
|
1366
1408
|
|
|
1367
1409
|
var fx1 = kx1;
|
|
1368
1410
|
var fy1 = ky1;
|
|
@@ -1487,6 +1529,65 @@ var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange
|
|
|
1487
1529
|
}
|
|
1488
1530
|
}, [cellLayout, onOffsetChange, onMaxScrollChange]);
|
|
1489
1531
|
};
|
|
1532
|
+
var clipDataOffset = function clipDataOffset(view, offset, freeze, maxCells, cellLayout) {
|
|
1533
|
+
var newX = offset[0],
|
|
1534
|
+
newY = offset[1];
|
|
1535
|
+
var maxColumns = maxCells[0],
|
|
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) {
|
|
1564
|
+
var cellToAbsolute = cellLayout.cellToAbsolute,
|
|
1565
|
+
absoluteToColumn = cellLayout.absoluteToColumn,
|
|
1566
|
+
columnToAbsolute = cellLayout.columnToAbsolute,
|
|
1567
|
+
absoluteToRow = cellLayout.absoluteToRow,
|
|
1568
|
+
rowToAbsolute = cellLayout.rowToAbsolute,
|
|
1569
|
+
getIndentX = cellLayout.getIndentX,
|
|
1570
|
+
getIndentY = cellLayout.getIndentY;
|
|
1571
|
+
var x = offset[0],
|
|
1572
|
+
y = offset[1];
|
|
1573
|
+
var w = view[0],
|
|
1574
|
+
h = view[1];
|
|
1575
|
+
|
|
1576
|
+
var _cellToAbsolute2 = cellToAbsolute(freeze),
|
|
1577
|
+
frozenX = _cellToAbsolute2[0],
|
|
1578
|
+
frozenY = _cellToAbsolute2[1];
|
|
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
|
+
};
|
|
1490
1591
|
var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, maxScroll, cellLayout, callback) {
|
|
1491
1592
|
var x = cell[0],
|
|
1492
1593
|
y = cell[1];
|
|
@@ -1499,9 +1600,9 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
|
|
|
1499
1600
|
columnToPixel = cellLayout.columnToPixel,
|
|
1500
1601
|
rowToPixel = cellLayout.rowToPixel;
|
|
1501
1602
|
|
|
1502
|
-
var
|
|
1503
|
-
frozenX =
|
|
1504
|
-
frozenY =
|
|
1603
|
+
var _cellToAbsolute3 = cellToAbsolute(freeze),
|
|
1604
|
+
frozenX = _cellToAbsolute3[0],
|
|
1605
|
+
frozenY = _cellToAbsolute3[1];
|
|
1505
1606
|
|
|
1506
1607
|
var _cellToPixel = cellToPixel(cell),
|
|
1507
1608
|
left = _cellToPixel[0],
|
|
@@ -1539,9 +1640,9 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
|
|
|
1539
1640
|
if (!isSameXY(newOffset, offset)) {
|
|
1540
1641
|
var scroll = cellToAbsolute(newOffset);
|
|
1541
1642
|
|
|
1542
|
-
var
|
|
1543
|
-
nudgeX =
|
|
1544
|
-
nudgeY =
|
|
1643
|
+
var _cellToAbsolute4 = cellToAbsolute([0, 0], [0.5, 0.5]),
|
|
1644
|
+
nudgeX = _cellToAbsolute4[0],
|
|
1645
|
+
nudgeY = _cellToAbsolute4[1];
|
|
1545
1646
|
|
|
1546
1647
|
callback(newOffset, maxXY(maxScroll, scroll));
|
|
1547
1648
|
setTimeout(function () {
|
|
@@ -1553,6 +1654,85 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
|
|
|
1553
1654
|
}
|
|
1554
1655
|
};
|
|
1555
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) {
|
|
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
|
+
var maxWidth = 0;
|
|
1700
|
+
|
|
1701
|
+
for (var _iterator = _createForOfIteratorHelperLoose(rows), _step; !(_step = _iterator()).done;) {
|
|
1702
|
+
var y = _step.value;
|
|
1703
|
+
var cellContent = displayData(x, y);
|
|
1704
|
+
|
|
1705
|
+
if (cellContent != null) {
|
|
1706
|
+
var style = cellStyle(x, y);
|
|
1707
|
+
var finalStyle = resolveCellStyle(style, DEFAULT_CELL_STYLE);
|
|
1708
|
+
context.fillStyle = finalStyle.color;
|
|
1709
|
+
context.font = finalStyle.weight + ' ' + finalStyle.fontSize + 'px ' + finalStyle.fontFamily;
|
|
1710
|
+
|
|
1711
|
+
if (typeof cellContent === 'string' || typeof cellContent === 'number') {
|
|
1712
|
+
var _context$measureText = context.measureText(cellContent.toString()),
|
|
1713
|
+
width = _context$measureText.width;
|
|
1714
|
+
|
|
1715
|
+
maxWidth = Math.max(maxWidth, width + finalStyle.marginLeft + finalStyle.marginRight);
|
|
1716
|
+
} else if (typeof cellContent === 'object') {
|
|
1717
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(cellContent.items), _step2; !(_step2 = _iterator2()).done;) {
|
|
1718
|
+
var obj = _step2.value;
|
|
1719
|
+
|
|
1720
|
+
if (typeof obj.content === 'string' || typeof obj.content === 'number') {
|
|
1721
|
+
var _context$measureText2 = context.measureText(obj.content.toString()),
|
|
1722
|
+
_width = _context$measureText2.width;
|
|
1723
|
+
|
|
1724
|
+
maxWidth = Math.max(maxWidth, obj.x + _width);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
return Math.ceil(maxWidth);
|
|
1732
|
+
}, [context]);
|
|
1733
|
+
return getAutoSizeWidth;
|
|
1734
|
+
};
|
|
1735
|
+
|
|
1556
1736
|
var useClipboardCopy = function useClipboardCopy(textAreaRef, selection, editMode, editData) {
|
|
1557
1737
|
React.useLayoutEffect(function () {
|
|
1558
1738
|
var textArea = textAreaRef.current;
|
|
@@ -2175,42 +2355,6 @@ var makeIntMap = function makeIntMap(initialSize) {
|
|
|
2175
2355
|
};
|
|
2176
2356
|
};
|
|
2177
2357
|
|
|
2178
|
-
var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
|
|
2179
|
-
var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
|
|
2180
|
-
|
|
2181
|
-
return {
|
|
2182
|
-
freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
|
|
2183
|
-
freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
|
|
2184
|
-
hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
|
|
2185
|
-
hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
|
|
2186
|
-
hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
|
|
2187
|
-
hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
|
|
2188
|
-
columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
|
|
2189
|
-
rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
|
|
2190
|
-
shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
|
|
2191
|
-
shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
|
|
2192
|
-
shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
|
|
2193
|
-
};
|
|
2194
|
-
};
|
|
2195
|
-
var resolveCellStyle = function resolveCellStyle(optionalStyle, defaultStyle) {
|
|
2196
|
-
return _extends({}, defaultStyle, optionalStyle);
|
|
2197
|
-
};
|
|
2198
|
-
var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
|
|
2199
|
-
if (alignment === void 0) {
|
|
2200
|
-
alignment = style.textAlign;
|
|
2201
|
-
}
|
|
2202
|
-
|
|
2203
|
-
if (alignment === 'left') {
|
|
2204
|
-
return start + style.marginLeft;
|
|
2205
|
-
} else if (alignment === 'center') {
|
|
2206
|
-
return start + cellSize * 0.5 - imageWidth / 2;
|
|
2207
|
-
} else if (alignment === 'right') {
|
|
2208
|
-
return start + (cellSize - style.marginRight - imageWidth);
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
return start;
|
|
2212
|
-
};
|
|
2213
|
-
|
|
2214
2358
|
var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
|
|
2215
2359
|
var canvas = context.canvas;
|
|
2216
2360
|
var width = canvas.width,
|
|
@@ -3006,6 +3150,23 @@ var Sheet = React.forwardRef(function (props, ref) {
|
|
|
3006
3150
|
}
|
|
3007
3151
|
}, [visibleCells, props.onScrollChange]);
|
|
3008
3152
|
|
|
3153
|
+
var scrollToSelection = function scrollToSelection(selection, toHead) {
|
|
3154
|
+
if (toHead === void 0) {
|
|
3155
|
+
toHead = false;
|
|
3156
|
+
}
|
|
3157
|
+
|
|
3158
|
+
var overlay = overlayRef.current;
|
|
3159
|
+
if (!overlay) return;
|
|
3160
|
+
var anchor = selection[0],
|
|
3161
|
+
head = selection[1];
|
|
3162
|
+
var view = [canvasWidth, canvasHeight];
|
|
3163
|
+
var freeze = [freezeColumns, freezeRows];
|
|
3164
|
+
scrollToCell(overlay, toHead ? head : anchor, view, freeze, dataOffset, maxScroll, cellLayout, function (dataOffset, maxScroll) {
|
|
3165
|
+
setDataOffset(dataOffset);
|
|
3166
|
+
setMaxScroll(maxScroll);
|
|
3167
|
+
});
|
|
3168
|
+
};
|
|
3169
|
+
|
|
3009
3170
|
var changeSelection = function changeSelection(newSelection, scrollTo, toHead) {
|
|
3010
3171
|
if (scrollTo === void 0) {
|
|
3011
3172
|
scrollTo = true;
|
|
@@ -3023,12 +3184,7 @@ var Sheet = React.forwardRef(function (props, ref) {
|
|
|
3023
3184
|
if (!overlay) return;
|
|
3024
3185
|
|
|
3025
3186
|
if (scrollTo) {
|
|
3026
|
-
|
|
3027
|
-
head = newSelection[1];
|
|
3028
|
-
scrollToCell(overlay, toHead ? head : anchor, [canvasWidth, canvasHeight], [freezeColumns, freezeRows], dataOffset, maxScroll, cellLayout, function (dataOffset, maxScroll) {
|
|
3029
|
-
setDataOffset(dataOffset);
|
|
3030
|
-
setMaxScroll(maxScroll);
|
|
3031
|
-
});
|
|
3187
|
+
scrollToSelection(newSelection, toHead);
|
|
3032
3188
|
}
|
|
3033
3189
|
|
|
3034
3190
|
if (props.onSelectionChanged) {
|
|
@@ -3083,13 +3239,23 @@ var Sheet = React.forwardRef(function (props, ref) {
|
|
|
3083
3239
|
setLastEditKey(editKeys.apply(void 0, editCell));
|
|
3084
3240
|
};
|
|
3085
3241
|
|
|
3242
|
+
var _props$maxColumns = props.maxColumns,
|
|
3243
|
+
maxColumns = _props$maxColumns === void 0 ? Infinity : _props$maxColumns,
|
|
3244
|
+
_props$maxRows = props.maxRows,
|
|
3245
|
+
maxRows = _props$maxRows === void 0 ? Infinity : _props$maxRows;
|
|
3246
|
+
React.useLayoutEffect(function () {
|
|
3247
|
+
var view = [canvasWidth, canvasHeight];
|
|
3248
|
+
var freeze = [freezeColumns, freezeRows];
|
|
3249
|
+
setDataOffset(clipDataOffset(view, dataOffset, freeze, [maxColumns, maxRows], cellLayout));
|
|
3250
|
+
}, [maxRows, maxColumns]);
|
|
3086
3251
|
var hitmapRef = React.useRef(NO_CLICKABLES);
|
|
3087
3252
|
var textAreaRef = React.useRef(null);
|
|
3088
3253
|
useClipboardCopy(textAreaRef, selection, editMode, editData);
|
|
3089
3254
|
useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
|
|
3090
3255
|
var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
|
|
3256
|
+
var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle);
|
|
3091
3257
|
|
|
3092
|
-
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),
|
|
3258
|
+
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),
|
|
3093
3259
|
mouseHandlers = _useMouse.mouseHandlers,
|
|
3094
3260
|
knobPosition = _useMouse.knobPosition;
|
|
3095
3261
|
|