sheet-happens 0.0.40 → 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/index.js +232 -110
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +232 -110
- package/dist/index.modern.js.map +1 -1
- package/dist/mouse.d.ts +1 -1
- package/dist/scroll.d.ts +6 -1
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -348,11 +348,6 @@ var orientSelection = function orientSelection(normalized, to) {
|
|
|
348
348
|
var swapY = (ay - hy || 1) * (bottom - top || 1) < 0;
|
|
349
349
|
return [[swapX ? right : left, swapY ? bottom : top], [swapX ? left : right, swapY ? top : bottom]];
|
|
350
350
|
};
|
|
351
|
-
var clipSelection = function clipSelection(selection, max) {
|
|
352
|
-
var anchor = selection[0],
|
|
353
|
-
head = selection[1];
|
|
354
|
-
return [minXY(anchor, max), minXY(head, max)];
|
|
355
|
-
};
|
|
356
351
|
|
|
357
352
|
var LIMIT = 1000;
|
|
358
353
|
|
|
@@ -534,7 +529,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
|
|
|
534
529
|
return maxXY(cell, [0, 0]);
|
|
535
530
|
};
|
|
536
531
|
|
|
537
|
-
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) {
|
|
532
|
+
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) {
|
|
538
533
|
var _useState = useState(null),
|
|
539
534
|
hitTarget = _useState[0],
|
|
540
535
|
setHitTarget = _useState[1];
|
|
@@ -624,6 +619,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
624
619
|
|
|
625
620
|
var rect = e.target.getBoundingClientRect();
|
|
626
621
|
var xy = [e.clientX - rect.left, e.clientY - rect.top];
|
|
622
|
+
|
|
623
|
+
if (xy[0] > e.target.clientWidth || xy[1] > e.target.clientHeight) {
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
627
|
return xy;
|
|
628
628
|
}, []);
|
|
629
629
|
var getScrollPosition = useCallback(function (e) {
|
|
@@ -1043,9 +1043,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1043
1043
|
pixelToRow = _ref$current3$cellLay.pixelToRow,
|
|
1044
1044
|
getIndentX = _ref$current3$cellLay.getIndentX,
|
|
1045
1045
|
getIndentY = _ref$current3$cellLay.getIndentY;
|
|
1046
|
+
window.document.body.style.cursor = 'auto';
|
|
1046
1047
|
var xy = getMousePosition(e);
|
|
1047
1048
|
if (!xy) return;
|
|
1048
|
-
window.document.body.style.cursor = 'auto';
|
|
1049
1049
|
var hitTarget = getMouseHit(xy);
|
|
1050
1050
|
|
|
1051
1051
|
if (hitTarget) {
|
|
@@ -1288,11 +1288,48 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1288
1288
|
}
|
|
1289
1289
|
}, [getMousePosition, getScrollPosition, getMouseHit, onCellWidthChange, onCellHeightChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn, columnGroupKeys, rowGroupKeys]);
|
|
1290
1290
|
var onDoubleClick = useCallback(function (e) {
|
|
1291
|
-
var
|
|
1291
|
+
var _ref$current4 = ref.current,
|
|
1292
|
+
selection = _ref$current4.selection,
|
|
1293
|
+
_ref$current4$cellLay = _ref$current4.cellLayout,
|
|
1294
|
+
pixelToCell = _ref$current4$cellLay.pixelToCell,
|
|
1295
|
+
columnToPixel = _ref$current4$cellLay.columnToPixel;
|
|
1292
1296
|
e.preventDefault();
|
|
1293
1297
|
if (e.shiftKey) return;
|
|
1294
1298
|
var xy = getMousePosition(e);
|
|
1295
1299
|
if (!xy) return;
|
|
1300
|
+
var x = xy[0];
|
|
1301
|
+
var columns = visibleCells.columns;
|
|
1302
|
+
|
|
1303
|
+
if (onCellWidthChange) {
|
|
1304
|
+
var autosized = [];
|
|
1305
|
+
|
|
1306
|
+
for (var _iterator10 = _createForOfIteratorHelperLoose(columns), _step10; !(_step10 = _iterator10()).done;) {
|
|
1307
|
+
var index = _step10.value;
|
|
1308
|
+
var edge = columnToPixel(index, 1);
|
|
1309
|
+
|
|
1310
|
+
if (Math.abs(edge - x) < SIZES.resizeZone && canSizeColumn(index)) {
|
|
1311
|
+
var _normalizeSelection5 = normalizeSelection(selection),
|
|
1312
|
+
_normalizeSelection5$ = _normalizeSelection5[0],
|
|
1313
|
+
minX = _normalizeSelection5$[0],
|
|
1314
|
+
_normalizeSelection5$2 = _normalizeSelection5[1],
|
|
1315
|
+
maxX = _normalizeSelection5$2[0];
|
|
1316
|
+
|
|
1317
|
+
var indices = isColumnSelection(selection) && index >= minX && index <= maxX ? mapSelectionColumns(selection)(function (i) {
|
|
1318
|
+
return i;
|
|
1319
|
+
}) : [index];
|
|
1320
|
+
autosized.push.apply(autosized, indices);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
for (var _i = 0, _autosized = autosized; _i < _autosized.length; _i++) {
|
|
1325
|
+
var column = _autosized[_i];
|
|
1326
|
+
onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(column - 1);
|
|
1327
|
+
onCellWidthChange([column], getAutoSizeWidth(column));
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
if (autosized.length) return;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1296
1333
|
var hitTarget = getMouseHit(xy);
|
|
1297
1334
|
|
|
1298
1335
|
if (hitTarget) {
|
|
@@ -1303,7 +1340,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1303
1340
|
var editCell = pixelToCell(xy);
|
|
1304
1341
|
if (editMode) onCommit === null || onCommit === void 0 ? void 0 : onCommit();
|
|
1305
1342
|
onEdit === null || onEdit === void 0 ? void 0 : onEdit(editCell);
|
|
1306
|
-
}, [getMousePosition, getMouseHit, onCommit, onEdit]);
|
|
1343
|
+
}, [getMousePosition, getMouseHit, onCommit, onEdit, onInvalidateColumn, onCellWidthChange, getAutoSizeWidth, visibleCells, canSizeColumn]);
|
|
1307
1344
|
var onContextMenu = useCallback(function (e) {
|
|
1308
1345
|
var _ref$current$cellLayo2 = ref.current.cellLayout,
|
|
1309
1346
|
pixelToCell = _ref$current$cellLayo2.pixelToCell,
|
|
@@ -1350,21 +1387,21 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
|
|
|
1350
1387
|
};
|
|
1351
1388
|
|
|
1352
1389
|
var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly) {
|
|
1353
|
-
var
|
|
1354
|
-
_normalizeSelection5$ = _normalizeSelection5[0],
|
|
1355
|
-
kx1 = _normalizeSelection5$[0],
|
|
1356
|
-
ky1 = _normalizeSelection5$[1],
|
|
1357
|
-
_normalizeSelection5$2 = _normalizeSelection5[1],
|
|
1358
|
-
kx2 = _normalizeSelection5$2[0],
|
|
1359
|
-
ky2 = _normalizeSelection5$2[1];
|
|
1360
|
-
|
|
1361
|
-
var _normalizeSelection6 = normalizeSelection(selection),
|
|
1390
|
+
var _normalizeSelection6 = normalizeSelection(knobArea),
|
|
1362
1391
|
_normalizeSelection6$ = _normalizeSelection6[0],
|
|
1363
|
-
|
|
1364
|
-
|
|
1392
|
+
kx1 = _normalizeSelection6$[0],
|
|
1393
|
+
ky1 = _normalizeSelection6$[1],
|
|
1365
1394
|
_normalizeSelection6$2 = _normalizeSelection6[1],
|
|
1366
|
-
|
|
1367
|
-
|
|
1395
|
+
kx2 = _normalizeSelection6$2[0],
|
|
1396
|
+
ky2 = _normalizeSelection6$2[1];
|
|
1397
|
+
|
|
1398
|
+
var _normalizeSelection7 = normalizeSelection(selection),
|
|
1399
|
+
_normalizeSelection7$ = _normalizeSelection7[0],
|
|
1400
|
+
sx1 = _normalizeSelection7$[0],
|
|
1401
|
+
sy1 = _normalizeSelection7$[1],
|
|
1402
|
+
_normalizeSelection7$2 = _normalizeSelection7[1],
|
|
1403
|
+
sx2 = _normalizeSelection7$2[0],
|
|
1404
|
+
sy2 = _normalizeSelection7$2[1];
|
|
1368
1405
|
|
|
1369
1406
|
var fx1 = kx1;
|
|
1370
1407
|
var fy1 = ky1;
|
|
@@ -1489,30 +1526,81 @@ var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange
|
|
|
1489
1526
|
}
|
|
1490
1527
|
}, [cellLayout, onOffsetChange, onMaxScrollChange]);
|
|
1491
1528
|
};
|
|
1492
|
-
var
|
|
1493
|
-
var
|
|
1494
|
-
|
|
1495
|
-
var w = view[0],
|
|
1496
|
-
h = view[1];
|
|
1497
|
-
var offsetX = offset[0],
|
|
1498
|
-
offsetY = offset[1];
|
|
1529
|
+
var clipDataOffset = function clipDataOffset(view, offset, freeze, maxCells, cellLayout) {
|
|
1530
|
+
var newX = offset[0],
|
|
1531
|
+
newY = offset[1];
|
|
1499
1532
|
var maxColumns = maxCells[0],
|
|
1500
1533
|
maxRows = maxCells[1];
|
|
1534
|
+
var absoluteToColumn = cellLayout.absoluteToColumn,
|
|
1535
|
+
columnToAbsolute = cellLayout.columnToAbsolute,
|
|
1536
|
+
absoluteToRow = cellLayout.absoluteToRow,
|
|
1537
|
+
rowToAbsolute = cellLayout.rowToAbsolute;
|
|
1538
|
+
|
|
1539
|
+
var _getViewExtent = getViewExtent(view, [newX, newY], freeze, cellLayout),
|
|
1540
|
+
_getViewExtent$edge = _getViewExtent.edge,
|
|
1541
|
+
rightEdge = _getViewExtent$edge[0],
|
|
1542
|
+
bottomEdge = _getViewExtent$edge[1],
|
|
1543
|
+
_getViewExtent$viewpo = _getViewExtent.viewport,
|
|
1544
|
+
scrollW = _getViewExtent$viewpo[0],
|
|
1545
|
+
scrollH = _getViewExtent$viewpo[1];
|
|
1546
|
+
|
|
1547
|
+
if (rightEdge > maxColumns) {
|
|
1548
|
+
var remainder = columnToAbsolute(maxColumns) - columnToAbsolute(newX);
|
|
1549
|
+
newX = absoluteToColumn(columnToAbsolute(newX) - scrollW + remainder) + 1;
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
if (bottomEdge > maxRows) {
|
|
1553
|
+
var _remainder = rowToAbsolute(maxRows) - rowToAbsolute(newY);
|
|
1554
|
+
|
|
1555
|
+
newY = absoluteToRow(rowToAbsolute(newY) - scrollH + _remainder) + 1;
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
return [newX, newY];
|
|
1559
|
+
};
|
|
1560
|
+
var getViewExtent = function getViewExtent(view, offset, freeze, cellLayout) {
|
|
1501
1561
|
var cellToAbsolute = cellLayout.cellToAbsolute,
|
|
1502
|
-
cellToPixel = cellLayout.cellToPixel,
|
|
1503
|
-
columnToPixel = cellLayout.columnToPixel,
|
|
1504
|
-
rowToPixel = cellLayout.rowToPixel,
|
|
1505
1562
|
absoluteToColumn = cellLayout.absoluteToColumn,
|
|
1506
1563
|
columnToAbsolute = cellLayout.columnToAbsolute,
|
|
1507
1564
|
absoluteToRow = cellLayout.absoluteToRow,
|
|
1508
1565
|
rowToAbsolute = cellLayout.rowToAbsolute,
|
|
1509
1566
|
getIndentX = cellLayout.getIndentX,
|
|
1510
1567
|
getIndentY = cellLayout.getIndentY;
|
|
1568
|
+
var x = offset[0],
|
|
1569
|
+
y = offset[1];
|
|
1570
|
+
var w = view[0],
|
|
1571
|
+
h = view[1];
|
|
1511
1572
|
|
|
1512
1573
|
var _cellToAbsolute2 = cellToAbsolute(freeze),
|
|
1513
1574
|
frozenX = _cellToAbsolute2[0],
|
|
1514
1575
|
frozenY = _cellToAbsolute2[1];
|
|
1515
1576
|
|
|
1577
|
+
var scrollW = w - frozenX - getIndentX();
|
|
1578
|
+
var scrollH = h - frozenY - getIndentY();
|
|
1579
|
+
var leftEdge = x + freeze[0];
|
|
1580
|
+
var topEdge = y + freeze[1];
|
|
1581
|
+
var rightEdge = absoluteToColumn(columnToAbsolute(leftEdge) + scrollW);
|
|
1582
|
+
var bottomEdge = absoluteToRow(rowToAbsolute(topEdge) + scrollH);
|
|
1583
|
+
return {
|
|
1584
|
+
edge: [rightEdge, bottomEdge],
|
|
1585
|
+
viewport: [scrollW, scrollH]
|
|
1586
|
+
};
|
|
1587
|
+
};
|
|
1588
|
+
var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, maxScroll, cellLayout, callback) {
|
|
1589
|
+
var x = cell[0],
|
|
1590
|
+
y = cell[1];
|
|
1591
|
+
var w = view[0],
|
|
1592
|
+
h = view[1];
|
|
1593
|
+
var offsetX = offset[0],
|
|
1594
|
+
offsetY = offset[1];
|
|
1595
|
+
var cellToAbsolute = cellLayout.cellToAbsolute,
|
|
1596
|
+
cellToPixel = cellLayout.cellToPixel,
|
|
1597
|
+
columnToPixel = cellLayout.columnToPixel,
|
|
1598
|
+
rowToPixel = cellLayout.rowToPixel;
|
|
1599
|
+
|
|
1600
|
+
var _cellToAbsolute3 = cellToAbsolute(freeze),
|
|
1601
|
+
frozenX = _cellToAbsolute3[0],
|
|
1602
|
+
frozenY = _cellToAbsolute3[1];
|
|
1603
|
+
|
|
1516
1604
|
var _cellToPixel = cellToPixel(cell),
|
|
1517
1605
|
left = _cellToPixel[0],
|
|
1518
1606
|
top = _cellToPixel[1];
|
|
@@ -1526,25 +1614,10 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
|
|
|
1526
1614
|
|
|
1527
1615
|
if (left <= frozenX) {
|
|
1528
1616
|
newX = x - freeze[0];
|
|
1529
|
-
var scrollW = w - frozenX - getIndentX();
|
|
1530
|
-
var rightEdge = absoluteToColumn(columnToAbsolute(newX) + scrollW);
|
|
1531
|
-
|
|
1532
|
-
if (rightEdge > maxColumns) {
|
|
1533
|
-
var remainder = columnToAbsolute(maxColumns) - columnToAbsolute(newX);
|
|
1534
|
-
newX = absoluteToColumn(columnToAbsolute(newX) - scrollW + remainder) + 1;
|
|
1535
|
-
}
|
|
1536
1617
|
}
|
|
1537
1618
|
|
|
1538
1619
|
if (top <= frozenY) {
|
|
1539
1620
|
newY = y - freeze[1];
|
|
1540
|
-
var scrollH = h - frozenY - getIndentY();
|
|
1541
|
-
var bottomEdge = absoluteToRow(rowToAbsolute(newY) + scrollH);
|
|
1542
|
-
|
|
1543
|
-
if (bottomEdge > maxRows) {
|
|
1544
|
-
var _remainder = rowToAbsolute(maxRows) - rowToAbsolute(newY);
|
|
1545
|
-
|
|
1546
|
-
newY = absoluteToRow(rowToAbsolute(newY) - scrollH + _remainder) + 1;
|
|
1547
|
-
}
|
|
1548
1621
|
}
|
|
1549
1622
|
|
|
1550
1623
|
if (right > w) {
|
|
@@ -1564,9 +1637,9 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
|
|
|
1564
1637
|
if (!isSameXY(newOffset, offset)) {
|
|
1565
1638
|
var scroll = cellToAbsolute(newOffset);
|
|
1566
1639
|
|
|
1567
|
-
var
|
|
1568
|
-
nudgeX =
|
|
1569
|
-
nudgeY =
|
|
1640
|
+
var _cellToAbsolute4 = cellToAbsolute([0, 0], [0.5, 0.5]),
|
|
1641
|
+
nudgeX = _cellToAbsolute4[0],
|
|
1642
|
+
nudgeY = _cellToAbsolute4[1];
|
|
1570
1643
|
|
|
1571
1644
|
callback(newOffset, maxXY(maxScroll, scroll));
|
|
1572
1645
|
setTimeout(function () {
|
|
@@ -1578,6 +1651,85 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
|
|
|
1578
1651
|
}
|
|
1579
1652
|
};
|
|
1580
1653
|
|
|
1654
|
+
var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
|
|
1655
|
+
var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
|
|
1656
|
+
|
|
1657
|
+
return {
|
|
1658
|
+
freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
|
|
1659
|
+
freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
|
|
1660
|
+
hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
|
|
1661
|
+
hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
|
|
1662
|
+
hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
|
|
1663
|
+
hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
|
|
1664
|
+
columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
|
|
1665
|
+
rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
|
|
1666
|
+
shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
|
|
1667
|
+
shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
|
|
1668
|
+
shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
|
|
1669
|
+
};
|
|
1670
|
+
};
|
|
1671
|
+
var resolveCellStyle = function resolveCellStyle(optionalStyle, defaultStyle) {
|
|
1672
|
+
return _extends({}, defaultStyle, optionalStyle);
|
|
1673
|
+
};
|
|
1674
|
+
var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
|
|
1675
|
+
if (alignment === void 0) {
|
|
1676
|
+
alignment = style.textAlign;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
if (alignment === 'left') {
|
|
1680
|
+
return start + style.marginLeft;
|
|
1681
|
+
} else if (alignment === 'center') {
|
|
1682
|
+
return start + cellSize * 0.5 - imageWidth / 2;
|
|
1683
|
+
} else if (alignment === 'right') {
|
|
1684
|
+
return start + (cellSize - style.marginRight - imageWidth);
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
return start;
|
|
1688
|
+
};
|
|
1689
|
+
|
|
1690
|
+
var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle) {
|
|
1691
|
+
var context = useMemo(function () {
|
|
1692
|
+
return document.createElement('canvas').getContext('2d');
|
|
1693
|
+
}, []);
|
|
1694
|
+
var getAutoSizeWidth = useCallback(function (x) {
|
|
1695
|
+
if (!context) return 0;
|
|
1696
|
+
var maxWidth = 0;
|
|
1697
|
+
|
|
1698
|
+
for (var _iterator = _createForOfIteratorHelperLoose(rows), _step; !(_step = _iterator()).done;) {
|
|
1699
|
+
var y = _step.value;
|
|
1700
|
+
var cellContent = displayData(x, y);
|
|
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;
|
|
1707
|
+
|
|
1708
|
+
if (typeof cellContent === 'string' || typeof cellContent === 'number') {
|
|
1709
|
+
var _context$measureText = context.measureText(cellContent.toString()),
|
|
1710
|
+
width = _context$measureText.width;
|
|
1711
|
+
|
|
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;
|
|
1716
|
+
|
|
1717
|
+
if (typeof obj.content === 'string' || typeof obj.content === 'number') {
|
|
1718
|
+
var _context$measureText2 = context.measureText(obj.content.toString()),
|
|
1719
|
+
_width = _context$measureText2.width;
|
|
1720
|
+
|
|
1721
|
+
maxWidth = Math.max(maxWidth, obj.x + _width);
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
return Math.ceil(maxWidth);
|
|
1729
|
+
}, [context]);
|
|
1730
|
+
return getAutoSizeWidth;
|
|
1731
|
+
};
|
|
1732
|
+
|
|
1581
1733
|
var useClipboardCopy = function useClipboardCopy(textAreaRef, selection, editMode, editData) {
|
|
1582
1734
|
useLayoutEffect(function () {
|
|
1583
1735
|
var textArea = textAreaRef.current;
|
|
@@ -2200,42 +2352,6 @@ var makeIntMap = function makeIntMap(initialSize) {
|
|
|
2200
2352
|
};
|
|
2201
2353
|
};
|
|
2202
2354
|
|
|
2203
|
-
var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
|
|
2204
|
-
var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
|
|
2205
|
-
|
|
2206
|
-
return {
|
|
2207
|
-
freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
|
|
2208
|
-
freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
|
|
2209
|
-
hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
|
|
2210
|
-
hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
|
|
2211
|
-
hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
|
|
2212
|
-
hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
|
|
2213
|
-
columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
|
|
2214
|
-
rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
|
|
2215
|
-
shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
|
|
2216
|
-
shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
|
|
2217
|
-
shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
|
|
2218
|
-
};
|
|
2219
|
-
};
|
|
2220
|
-
var resolveCellStyle = function resolveCellStyle(optionalStyle, defaultStyle) {
|
|
2221
|
-
return _extends({}, defaultStyle, optionalStyle);
|
|
2222
|
-
};
|
|
2223
|
-
var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
|
|
2224
|
-
if (alignment === void 0) {
|
|
2225
|
-
alignment = style.textAlign;
|
|
2226
|
-
}
|
|
2227
|
-
|
|
2228
|
-
if (alignment === 'left') {
|
|
2229
|
-
return start + style.marginLeft;
|
|
2230
|
-
} else if (alignment === 'center') {
|
|
2231
|
-
return start + cellSize * 0.5 - imageWidth / 2;
|
|
2232
|
-
} else if (alignment === 'right') {
|
|
2233
|
-
return start + (cellSize - style.marginRight - imageWidth);
|
|
2234
|
-
}
|
|
2235
|
-
|
|
2236
|
-
return start;
|
|
2237
|
-
};
|
|
2238
|
-
|
|
2239
2355
|
var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
|
|
2240
2356
|
var canvas = context.canvas;
|
|
2241
2357
|
var width = canvas.width,
|
|
@@ -3031,6 +3147,23 @@ var Sheet = forwardRef(function (props, ref) {
|
|
|
3031
3147
|
}
|
|
3032
3148
|
}, [visibleCells, props.onScrollChange]);
|
|
3033
3149
|
|
|
3150
|
+
var scrollToSelection = function scrollToSelection(selection, toHead) {
|
|
3151
|
+
if (toHead === void 0) {
|
|
3152
|
+
toHead = false;
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
var overlay = overlayRef.current;
|
|
3156
|
+
if (!overlay) return;
|
|
3157
|
+
var anchor = selection[0],
|
|
3158
|
+
head = selection[1];
|
|
3159
|
+
var view = [canvasWidth, canvasHeight];
|
|
3160
|
+
var freeze = [freezeColumns, freezeRows];
|
|
3161
|
+
scrollToCell(overlay, toHead ? head : anchor, view, freeze, dataOffset, maxScroll, cellLayout, function (dataOffset, maxScroll) {
|
|
3162
|
+
setDataOffset(dataOffset);
|
|
3163
|
+
setMaxScroll(maxScroll);
|
|
3164
|
+
});
|
|
3165
|
+
};
|
|
3166
|
+
|
|
3034
3167
|
var changeSelection = function changeSelection(newSelection, scrollTo, toHead) {
|
|
3035
3168
|
if (scrollTo === void 0) {
|
|
3036
3169
|
scrollTo = true;
|
|
@@ -3048,12 +3181,7 @@ var Sheet = forwardRef(function (props, ref) {
|
|
|
3048
3181
|
if (!overlay) return;
|
|
3049
3182
|
|
|
3050
3183
|
if (scrollTo) {
|
|
3051
|
-
|
|
3052
|
-
head = newSelection[1];
|
|
3053
|
-
scrollToCell(overlay, toHead ? head : anchor, [canvasWidth, canvasHeight], [freezeColumns, freezeRows], dataOffset, [maxColumns, maxRows], maxScroll, cellLayout, function (dataOffset, maxScroll) {
|
|
3054
|
-
setDataOffset(dataOffset);
|
|
3055
|
-
setMaxScroll(maxScroll);
|
|
3056
|
-
});
|
|
3184
|
+
scrollToSelection(newSelection, toHead);
|
|
3057
3185
|
}
|
|
3058
3186
|
|
|
3059
3187
|
if (props.onSelectionChanged) {
|
|
@@ -3113,24 +3241,18 @@ var Sheet = forwardRef(function (props, ref) {
|
|
|
3113
3241
|
_props$maxRows = props.maxRows,
|
|
3114
3242
|
maxRows = _props$maxRows === void 0 ? Infinity : _props$maxRows;
|
|
3115
3243
|
useLayoutEffect(function () {
|
|
3116
|
-
var
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
maxY = _normalizeSelection2$[1];
|
|
3120
|
-
|
|
3121
|
-
var overflowX = maxX > maxColumns;
|
|
3122
|
-
var overflowY = maxY > maxRows;
|
|
3123
|
-
if (!overflowX && !overflowY) return;
|
|
3124
|
-
var corner = [maxColumns - 1, maxRows - 1];
|
|
3125
|
-
changeSelection(clipSelection(selection, corner), true);
|
|
3244
|
+
var view = [canvasWidth, canvasHeight];
|
|
3245
|
+
var freeze = [freezeColumns, freezeRows];
|
|
3246
|
+
setDataOffset(clipDataOffset(view, dataOffset, freeze, [maxColumns, maxRows], cellLayout));
|
|
3126
3247
|
}, [maxRows, maxColumns]);
|
|
3127
3248
|
var hitmapRef = useRef(NO_CLICKABLES);
|
|
3128
3249
|
var textAreaRef = useRef(null);
|
|
3129
3250
|
useClipboardCopy(textAreaRef, selection, editMode, editData);
|
|
3130
3251
|
useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
|
|
3131
3252
|
var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
|
|
3253
|
+
var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle);
|
|
3132
3254
|
|
|
3133
|
-
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),
|
|
3255
|
+
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),
|
|
3134
3256
|
mouseHandlers = _useMouse.mouseHandlers,
|
|
3135
3257
|
knobPosition = _useMouse.knobPosition;
|
|
3136
3258
|
|
|
@@ -3189,13 +3311,13 @@ var Sheet = forwardRef(function (props, ref) {
|
|
|
3189
3311
|
}
|
|
3190
3312
|
|
|
3191
3313
|
if (e.key === 'Backspace' || e.key === 'Delete') {
|
|
3192
|
-
var
|
|
3193
|
-
|
|
3194
|
-
x1 =
|
|
3195
|
-
y1 =
|
|
3196
|
-
|
|
3197
|
-
x2 =
|
|
3198
|
-
y2 =
|
|
3314
|
+
var _normalizeSelection2 = normalizeSelection(selection),
|
|
3315
|
+
_normalizeSelection2$ = _normalizeSelection2[0],
|
|
3316
|
+
x1 = _normalizeSelection2$[0],
|
|
3317
|
+
y1 = _normalizeSelection2$[1],
|
|
3318
|
+
_normalizeSelection2$2 = _normalizeSelection2[1],
|
|
3319
|
+
x2 = _normalizeSelection2$2[0],
|
|
3320
|
+
y2 = _normalizeSelection2$2[1];
|
|
3199
3321
|
|
|
3200
3322
|
if (isRowSelection(selection)) {
|
|
3201
3323
|
x1 = 0;
|