@rowsncolumns/grid 9.0.3 → 13.2.32
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/LICENSE.md +100 -0
- package/Readme.md +53 -59
- package/dist/cjs/Cell.d.ts +35 -0
- package/dist/cjs/Cell.d.ts.map +1 -0
- package/dist/cjs/Cell.js +29 -0
- package/dist/{CellOverlay.d.ts → cjs/CellOverlay.d.ts} +5 -5
- package/dist/cjs/CellOverlay.d.ts.map +1 -0
- package/dist/cjs/CellOverlay.js +126 -0
- package/dist/cjs/Context.d.ts +8 -0
- package/dist/cjs/Context.d.ts.map +1 -0
- package/dist/cjs/Context.js +13 -0
- package/dist/{FillHandle.d.ts → cjs/FillHandle.d.ts} +2 -1
- package/dist/cjs/FillHandle.d.ts.map +1 -0
- package/dist/cjs/FillHandle.js +26 -0
- package/dist/cjs/Grid.d.ts +558 -0
- package/dist/cjs/Grid.d.ts.map +1 -0
- package/dist/cjs/Grid.js +2446 -0
- package/dist/{GridLine.d.ts → cjs/GridLine.d.ts} +2 -1
- package/dist/cjs/GridLine.d.ts.map +1 -0
- package/dist/cjs/GridLine.js +10 -0
- package/dist/cjs/Image.d.ts +11 -0
- package/dist/cjs/Image.d.ts.map +1 -0
- package/dist/cjs/Image.js +57 -0
- package/dist/cjs/MemoizedGrid.d.ts +49 -0
- package/dist/cjs/MemoizedGrid.d.ts.map +1 -0
- package/dist/cjs/MemoizedGrid.js +105 -0
- package/dist/cjs/Selection.d.ts +5 -0
- package/dist/cjs/Selection.d.ts.map +1 -0
- package/dist/cjs/Selection.js +10 -0
- package/dist/{helpers.d.ts → cjs/helpers.d.ts} +59 -39
- package/dist/cjs/helpers.d.ts.map +1 -0
- package/dist/cjs/helpers.js +1409 -0
- package/dist/{hooks → cjs/hooks}/useCopyPaste.d.ts +3 -2
- package/dist/cjs/hooks/useCopyPaste.d.ts.map +1 -0
- package/dist/cjs/hooks/useCopyPaste.js +230 -0
- package/dist/{hooks → cjs/hooks}/useEditable.d.ts +21 -8
- package/dist/cjs/hooks/useEditable.d.ts.map +1 -0
- package/dist/cjs/hooks/useEditable.js +491 -0
- package/dist/{hooks → cjs/hooks}/useFilter.d.ts +3 -2
- package/dist/cjs/hooks/useFilter.d.ts.map +1 -0
- package/dist/cjs/hooks/useFilter.js +97 -0
- package/dist/{hooks → cjs/hooks}/useImage.d.ts +1 -0
- package/dist/cjs/hooks/useImage.d.ts.map +1 -0
- package/dist/cjs/hooks/useImage.js +80 -0
- package/dist/{hooks → cjs/hooks}/usePagination.d.ts +3 -2
- package/dist/cjs/hooks/usePagination.d.ts.map +1 -0
- package/dist/cjs/hooks/usePagination.js +53 -0
- package/dist/{hooks → cjs/hooks}/useSizer.d.ts +28 -29
- package/dist/cjs/hooks/useSizer.d.ts.map +1 -0
- package/dist/cjs/hooks/useSizer.js +176 -0
- package/dist/{hooks → cjs/hooks}/useTooltip.d.ts +2 -1
- package/dist/cjs/hooks/useTooltip.d.ts.map +1 -0
- package/dist/cjs/hooks/useTooltip.js +82 -0
- package/dist/{hooks → cjs/hooks}/useUndo.d.ts +2 -1
- package/dist/cjs/hooks/useUndo.d.ts.map +1 -0
- package/dist/cjs/hooks/useUndo.js +87 -0
- package/dist/cjs/index.d.ts +19 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +29 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/{types.d.ts → cjs/types.d.ts} +8 -3
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/{types.js → cjs/types.js} +7 -8
- package/dist/cjs/utils.d.ts +9 -0
- package/dist/cjs/utils.d.ts.map +1 -0
- package/dist/cjs/utils.js +58 -0
- package/dist/cjs/vitest.config.d.ts +3 -0
- package/dist/cjs/vitest.config.d.ts.map +1 -0
- package/dist/cjs/vitest.config.js +24 -0
- package/dist/esm/Cell.d.ts +35 -0
- package/dist/esm/Cell.d.ts.map +1 -0
- package/dist/esm/Cell.js +24 -0
- package/dist/esm/CellOverlay.d.ts +21 -0
- package/dist/esm/CellOverlay.d.ts.map +1 -0
- package/dist/esm/CellOverlay.js +120 -0
- package/dist/esm/Context.d.ts +8 -0
- package/dist/esm/Context.d.ts.map +1 -0
- package/dist/esm/Context.js +9 -0
- package/dist/esm/FillHandle.d.ts +8 -0
- package/dist/esm/FillHandle.d.ts.map +1 -0
- package/dist/{FillHandle.js → esm/FillHandle.js} +5 -11
- package/dist/esm/Grid.d.ts +558 -0
- package/dist/esm/Grid.d.ts.map +1 -0
- package/dist/esm/Grid.js +2451 -0
- package/dist/esm/GridLine.d.ts +5 -0
- package/dist/esm/GridLine.d.ts.map +1 -0
- package/dist/esm/GridLine.js +7 -0
- package/dist/esm/Image.d.ts +11 -0
- package/dist/esm/Image.d.ts.map +1 -0
- package/dist/esm/Image.js +53 -0
- package/dist/esm/MemoizedGrid.d.ts +49 -0
- package/dist/esm/MemoizedGrid.d.ts.map +1 -0
- package/dist/esm/MemoizedGrid.js +98 -0
- package/dist/esm/Selection.d.ts +5 -0
- package/dist/esm/Selection.d.ts.map +1 -0
- package/dist/esm/Selection.js +7 -0
- package/dist/esm/helpers.d.ts +281 -0
- package/dist/esm/helpers.d.ts.map +1 -0
- package/dist/esm/helpers.js +1260 -0
- package/dist/esm/hooks/useCopyPaste.d.ts +53 -0
- package/dist/esm/hooks/useCopyPaste.d.ts.map +1 -0
- package/dist/{hooks → esm/hooks}/useCopyPaste.js +40 -46
- package/dist/esm/hooks/useEditable.d.ts +253 -0
- package/dist/esm/hooks/useEditable.d.ts.map +1 -0
- package/dist/esm/hooks/useEditable.js +482 -0
- package/dist/esm/hooks/useFilter.d.ts +69 -0
- package/dist/esm/hooks/useFilter.d.ts.map +1 -0
- package/dist/{hooks → esm/hooks}/useFilter.js +22 -42
- package/dist/esm/hooks/useImage.d.ts +13 -0
- package/dist/esm/hooks/useImage.d.ts.map +1 -0
- package/dist/esm/hooks/useImage.js +76 -0
- package/dist/esm/hooks/usePagination.d.ts +69 -0
- package/dist/esm/hooks/usePagination.d.ts.map +1 -0
- package/dist/esm/hooks/usePagination.js +47 -0
- package/dist/esm/hooks/useSizer.d.ts +114 -0
- package/dist/esm/hooks/useSizer.d.ts.map +1 -0
- package/dist/esm/hooks/useSizer.js +176 -0
- package/dist/esm/hooks/useTooltip.d.ts +43 -0
- package/dist/esm/hooks/useTooltip.d.ts.map +1 -0
- package/dist/esm/hooks/useTooltip.js +80 -0
- package/dist/esm/hooks/useUndo.d.ts +36 -0
- package/dist/esm/hooks/useUndo.d.ts.map +1 -0
- package/dist/{hooks → esm/hooks}/useUndo.js +16 -25
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/esm/types.d.ts +70 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +68 -0
- package/dist/esm/utils.d.ts +9 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +104 -0
- package/dist/esm/vitest.config.d.ts +3 -0
- package/dist/esm/vitest.config.d.ts.map +1 -0
- package/dist/esm/vitest.config.js +22 -0
- package/package.json +28 -29
- package/dist/Cell.d.ts +0 -23
- package/dist/Cell.js +0 -55
- package/dist/Cell.js.map +0 -1
- package/dist/CellOverlay.js +0 -116
- package/dist/CellOverlay.js.map +0 -1
- package/dist/FillHandle.js.map +0 -1
- package/dist/Grid.d.ts +0 -385
- package/dist/Grid.js +0 -1684
- package/dist/Grid.js.map +0 -1
- package/dist/GridLine.js +0 -13
- package/dist/GridLine.js.map +0 -1
- package/dist/Image.d.ts +0 -8
- package/dist/Image.js +0 -50
- package/dist/Image.js.map +0 -1
- package/dist/Selection.d.ts +0 -4
- package/dist/Selection.js +0 -9
- package/dist/Selection.js.map +0 -1
- package/dist/helpers.js +0 -1033
- package/dist/helpers.js.map +0 -1
- package/dist/hooks/useCopyPaste.js.map +0 -1
- package/dist/hooks/useEditable.js +0 -477
- package/dist/hooks/useEditable.js.map +0 -1
- package/dist/hooks/useFilter.js.map +0 -1
- package/dist/hooks/useImage.js +0 -42
- package/dist/hooks/useImage.js.map +0 -1
- package/dist/hooks/usePagination.js +0 -73
- package/dist/hooks/usePagination.js.map +0 -1
- package/dist/hooks/useSelection.d.ts +0 -175
- package/dist/hooks/useSelection.js +0 -980
- package/dist/hooks/useSelection.js.map +0 -1
- package/dist/hooks/useSizer.js +0 -150
- package/dist/hooks/useSizer.js.map +0 -1
- package/dist/hooks/useTooltip.js +0 -106
- package/dist/hooks/useTooltip.js.map +0 -1
- package/dist/hooks/useTouch.d.ts +0 -21
- package/dist/hooks/useTouch.js +0 -73
- package/dist/hooks/useTouch.js.map +0 -1
- package/dist/hooks/useUndo.js.map +0 -1
- package/dist/index.d.ts +0 -25
- package/dist/index.js +0 -61
- package/dist/index.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -8
- package/dist/utils.js +0 -153
- package/dist/utils.js.map +0 -1
- package/src/Cell.tsx +0 -100
- package/src/CellOverlay.tsx +0 -191
- package/src/FillHandle.tsx +0 -37
- package/src/Grid.tsx +0 -2677
- package/src/GridLine.tsx +0 -23
- package/src/Image.tsx +0 -43
- package/src/Selection.tsx +0 -9
- package/src/helpers.ts +0 -1455
- package/src/hooks/useCopyPaste.ts +0 -265
- package/src/hooks/useEditable.tsx +0 -945
- package/src/hooks/useFilter.tsx +0 -233
- package/src/hooks/useImage.ts +0 -57
- package/src/hooks/usePagination.tsx +0 -153
- package/src/hooks/useSelection.ts +0 -1437
- package/src/hooks/useSizer.ts +0 -312
- package/src/hooks/useTooltip.tsx +0 -172
- package/src/hooks/useTouch.ts +0 -116
- package/src/hooks/useUndo.ts +0 -134
- package/src/index.tsx +0 -46
- package/src/tests/Grid.spec.tsx +0 -47
- package/src/tests/helpers.test.ts +0 -292
- package/src/tests/usePagination.test.ts +0 -28
- package/src/tests/useSelection.test.ts +0 -27
- package/src/tests/useUndo.test.ts +0 -73
- package/src/types.ts +0 -69
- package/src/utils.tsx +0 -287
package/dist/cjs/Grid.js
ADDED
|
@@ -0,0 +1,2446 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RESET_SCROLL_EVENTS_DEBOUNCE_INTERVAL = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
var react_konva_1 = require("react-konva");
|
|
7
|
+
var tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
|
|
8
|
+
var Cell_1 = require("./Cell");
|
|
9
|
+
var CellOverlay_1 = require("./CellOverlay");
|
|
10
|
+
var Context_1 = require("./Context");
|
|
11
|
+
var FillHandle_1 = tslib_1.__importDefault(require("./FillHandle"));
|
|
12
|
+
var GridLine_1 = tslib_1.__importDefault(require("./GridLine"));
|
|
13
|
+
var helpers_1 = require("./helpers");
|
|
14
|
+
var helpers_2 = require("./helpers");
|
|
15
|
+
var helpers_3 = require("./helpers");
|
|
16
|
+
var MemoizedGrid_1 = require("./MemoizedGrid");
|
|
17
|
+
var Selection_1 = tslib_1.__importDefault(require("./Selection"));
|
|
18
|
+
var types_1 = require("./types");
|
|
19
|
+
var DEFAULT_ESTIMATED_ITEM_SIZE = 50;
|
|
20
|
+
var defaultShadowSettings = {
|
|
21
|
+
strokeWidth: 1,
|
|
22
|
+
};
|
|
23
|
+
var DEFAULT_ROW_HEIGHT = 21;
|
|
24
|
+
var DEFAULT_COLUMN_WIDTH = 100;
|
|
25
|
+
var defaultRowHeight = function () { return DEFAULT_COLUMN_WIDTH; };
|
|
26
|
+
var defaultColumnWidth = function () { return 60; };
|
|
27
|
+
var defaultSelectionRenderer = function (props) {
|
|
28
|
+
return react_1.default.createElement(Selection_1.default, tslib_1.__assign({}, props));
|
|
29
|
+
};
|
|
30
|
+
var defaultGridLineRenderer = function (props) {
|
|
31
|
+
return react_1.default.createElement(GridLine_1.default, tslib_1.__assign({}, props));
|
|
32
|
+
};
|
|
33
|
+
exports.RESET_SCROLL_EVENTS_DEBOUNCE_INTERVAL = 150;
|
|
34
|
+
/* Placeholder for empty array -> Prevents re-render */
|
|
35
|
+
var EMPTY_ARRAY = [];
|
|
36
|
+
/* Max scroll height */
|
|
37
|
+
var MAX_SCROLLBAR_HEIGHT = 16777000;
|
|
38
|
+
/**
|
|
39
|
+
* Grid component using React Konva
|
|
40
|
+
* @param props
|
|
41
|
+
*
|
|
42
|
+
* TODO: Fix bug with snapping, since onWheel is a global handler, rowCount, columnCount becomes state
|
|
43
|
+
*/
|
|
44
|
+
var Grid = (0, react_1.memo)((0, react_1.forwardRef)(function (props, forwardedRef) {
|
|
45
|
+
var _a = props.width, containerWidth = _a === void 0 ? 800 : _a, _b = props.height, containerHeight = _b === void 0 ? 600 : _b, estimatedColumnWidth = props.estimatedColumnWidth, estimatedRowHeight = props.estimatedRowHeight, _c = props.rowHeight, rowHeight = _c === void 0 ? defaultRowHeight : _c, _d = props.columnWidth, columnWidth = _d === void 0 ? defaultColumnWidth : _d, _e = props.rowCount, rowCount = _e === void 0 ? 0 : _e, _f = props.columnCount, columnCount = _f === void 0 ? 0 : _f, _g = props.scrollbarSize, scrollbarSize = _g === void 0 ? 15 : _g, _h = props.scrollToCellOffset, scrollToCellOffset = _h === void 0 ? 0 : _h, _j = props.extendScrollSize, extendScrollSize = _j === void 0 ? false : _j, autoFocus = props.autoFocus, onScroll = props.onScroll, onImmediateScroll = props.onImmediateScroll, _k = props.showScrollbar, showScrollbar = _k === void 0 ? true : _k, _l = props.selectionBackgroundColor, selectionBackgroundColor = _l === void 0 ? "rgb(14, 101, 235, 0.1)" : _l, _m = props.selectionBorderColor, selectionBorderColor = _m === void 0 ? "#1a73e8" : _m, _o = props.selectionStrokeWidth, selectionStrokeWidth = _o === void 0 ? 1 : _o, _p = props.activeCellStrokeWidth, activeCellStrokeWidth = _p === void 0 ? 2 : _p, activeCell = props.activeCell, _q = props.selections, selections = _q === void 0 ? EMPTY_ARRAY : _q, _r = props.frozenRows, frozenRows = _r === void 0 ? 0 : _r, _s = props.frozenColumns, frozenColumns = _s === void 0 ? 0 : _s, _t = props.itemRenderer, itemRenderer = _t === void 0 ? Cell_1.CellRenderer : _t, _u = props.headerRenderer, headerRenderer = _u === void 0 ? Cell_1.CellRenderer : _u, _v = props.enableCellOverlay, enableCellOverlay = _v === void 0 ? false : _v, _w = props.enableCellBackground, enableCellBackground = _w === void 0 ? true : _w, _x = props.overlayRenderer, overlayRenderer = _x === void 0 ? CellOverlay_1.CellRenderer : _x, backgroundRenderer = props.backgroundRenderer, _y = props.mergedCells, mergedCells = _y === void 0 ? EMPTY_ARRAY : _y, _z = props.snap, snap = _z === void 0 ? false : _z, _0 = props.scrollThrottleTimeout, scrollThrottleTimeout = _0 === void 0 ? 80 : _0, onViewPortChange = props.onViewPortChange, onDimensionsChange = props.onDimensionsChange, _1 = props.selectionRenderer, selectionRenderer = _1 === void 0 ? defaultSelectionRenderer : _1, onBeforeRenderRow = props.onBeforeRenderRow, onAfterScrollToCell = props.onAfterScrollToCell, _2 = props.showFrozenRowShadow, showFrozenRowShadow = _2 === void 0 ? false : _2, _3 = props.showFrozenColumnShadow, showFrozenColumnShadow = _3 === void 0 ? false : _3, _4 = props.shadowSettings, shadowSettings = _4 === void 0 ? defaultShadowSettings : _4, _5 = props.borderStyles, borderStyles = _5 === void 0 ? EMPTY_ARRAY : _5, children = props.children, gridChildren = props.gridChildren, stageProps = props.stageProps, wrapper = props.wrapper, _6 = props.showFillHandle, showFillHandle = _6 === void 0 ? false : _6, fillSelection = props.fillSelection, _7 = props.overscanCount, overscanCount = _7 === void 0 ? 1 : _7, _8 = props.fillHandleSize, fillHandleSize = _8 === void 0 ? 8 : _8, onFillHandleMouseDown = props.onFillHandleMouseDown, onFillHandleDoubleClick = props.onFillHandleDoubleClick, _9 = props.fillhandleBorderColor, fillhandleBorderColor = _9 === void 0 ? "white" : _9, _10 = props.fillHandleBackgroundColor, fillHandleBackgroundColor = _10 === void 0 ? selectionBorderColor : _10, _11 = props.showGridLines, showGridLines = _11 === void 0 ? false : _11, _12 = props.gridLineColor, gridLineColor = _12 === void 0 ? "#E3E2E2" : _12, _13 = props.gridLineWidth, gridLineWidth = _13 === void 0 ? 1 : _13, _14 = props.gridLineRenderer, gridLineRenderer = _14 === void 0 ? defaultGridLineRenderer : _14, isHiddenRow = props.isHiddenRow, visibleRowRanges = props.visibleRowRanges, isHiddenColumn = props.isHiddenColumn, isHiddenCell = props.isHiddenCell, isHiddenOverlay = props.isHiddenOverlay, isHiddenBackground = props.isHiddenBackground, _15 = props.scale, scale = _15 === void 0 ? 1 : _15, _16 = props.enableSelectionDrag, enableSelectionDrag = _16 === void 0 ? false : _16, _17 = props.isDraggingSelection, isDraggingSelection = _17 === void 0 ? false : _17, isTouchDevice = props.isTouchDevice, _18 = props.FillHandle, FillHandle = _18 === void 0 ? FillHandle_1.default : _18, showHeaders = props.showHeaders, _19 = props.frozenShadowThickness, frozenShadowThickness = _19 === void 0 ? 0 : _19, _20 = props.preventBrowserDefaultScroll, preventBrowserDefaultScroll = _20 === void 0 ? false : _20, _21 = props.footerHeight, footerHeight = _21 === void 0 ? 0 : _21, footerComponent = props.footerComponent, getOverflowBuffer = props.getOverflowBuffer, getFrozenColumnOverflowCells = props.getFrozenColumnOverflowCells, rest = tslib_1.__rest(props, ["width", "height", "estimatedColumnWidth", "estimatedRowHeight", "rowHeight", "columnWidth", "rowCount", "columnCount", "scrollbarSize", "scrollToCellOffset", "extendScrollSize", "autoFocus", "onScroll", "onImmediateScroll", "showScrollbar", "selectionBackgroundColor", "selectionBorderColor", "selectionStrokeWidth", "activeCellStrokeWidth", "activeCell", "selections", "frozenRows", "frozenColumns", "itemRenderer", "headerRenderer", "enableCellOverlay", "enableCellBackground", "overlayRenderer", "backgroundRenderer", "mergedCells", "snap", "scrollThrottleTimeout", "onViewPortChange", "onDimensionsChange", "selectionRenderer", "onBeforeRenderRow", "onAfterScrollToCell", "showFrozenRowShadow", "showFrozenColumnShadow", "shadowSettings", "borderStyles", "children", "gridChildren", "stageProps", "wrapper", "showFillHandle", "fillSelection", "overscanCount", "fillHandleSize", "onFillHandleMouseDown", "onFillHandleDoubleClick", "fillhandleBorderColor", "fillHandleBackgroundColor", "showGridLines", "gridLineColor", "gridLineWidth", "gridLineRenderer", "isHiddenRow", "visibleRowRanges", "isHiddenColumn", "isHiddenCell", "isHiddenOverlay", "isHiddenBackground", "scale", "enableSelectionDrag", "isDraggingSelection", "isTouchDevice", "FillHandle", "showHeaders", "frozenShadowThickness", "preventBrowserDefaultScroll", "footerHeight", "footerComponent", "getOverflowBuffer", "getFrozenColumnOverflowCells"]);
|
|
46
|
+
var instanceProps = (0, react_1.useRef)({
|
|
47
|
+
columnMetadataMap: new Map(),
|
|
48
|
+
rowMetadataMap: new Map(),
|
|
49
|
+
lastMeasuredColumnIndex: -1,
|
|
50
|
+
lastMeasuredRowIndex: -1,
|
|
51
|
+
estimatedColumnWidth: estimatedColumnWidth || DEFAULT_ESTIMATED_ITEM_SIZE,
|
|
52
|
+
estimatedRowHeight: estimatedRowHeight || DEFAULT_ESTIMATED_ITEM_SIZE,
|
|
53
|
+
});
|
|
54
|
+
var stageRef = (0, react_1.useRef)(null);
|
|
55
|
+
var rowHeaderStageRef = (0, react_1.useRef)(null);
|
|
56
|
+
var columnHeaderStageRef = (0, react_1.useRef)(null);
|
|
57
|
+
var containerRef = (0, react_1.useRef)(null);
|
|
58
|
+
var scrollContainerRef = (0, react_1.useRef)(null);
|
|
59
|
+
var verticalScrollRef = (0, react_1.useRef)(null);
|
|
60
|
+
var wheelingRef = (0, react_1.useRef)(null);
|
|
61
|
+
var horizontalScrollRef = (0, react_1.useRef)(null);
|
|
62
|
+
var isEndOfVerticalScrollRef = (0, react_1.useRef)(false);
|
|
63
|
+
var isStartOffVerticalScrollRef = (0, react_1.useRef)(false);
|
|
64
|
+
var _22 = tslib_1.__read((0, react_1.useReducer)(function (s) { return s + 1; }, 0), 2), _ = _22[0], forceRender = _22[1];
|
|
65
|
+
// Cell caching
|
|
66
|
+
var cellCacheRef = (0, react_1.useRef)(new Map());
|
|
67
|
+
var cellOverlayCacheRef = (0, react_1.useRef)(new Map());
|
|
68
|
+
var cellBackgroundCacheRef = (0, react_1.useRef)(new Map());
|
|
69
|
+
var _23 = tslib_1.__read((0, react_1.useState)({
|
|
70
|
+
scrollTop: 0,
|
|
71
|
+
scrollLeft: 0,
|
|
72
|
+
isScrolling: false,
|
|
73
|
+
verticalScrollDirection: types_1.Direction.Down,
|
|
74
|
+
horizontalScrollDirection: types_1.Direction.Right,
|
|
75
|
+
}), 2), scrollState = _23[0], setScrollState = _23[1];
|
|
76
|
+
var scrollSnapRefs = (0, react_1.useRef)(null);
|
|
77
|
+
var scrollTop = scrollState.scrollTop, scrollLeft = scrollState.scrollLeft, isScrolling = scrollState.isScrolling;
|
|
78
|
+
var isMounted = (0, react_1.useRef)(false);
|
|
79
|
+
/* Focus container */
|
|
80
|
+
var focusContainer = (0, react_1.useCallback)(function () {
|
|
81
|
+
var _a;
|
|
82
|
+
if (helpers_3.canUseDOM && document.activeElement !== containerRef.current) {
|
|
83
|
+
return (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
84
|
+
}
|
|
85
|
+
}, []);
|
|
86
|
+
/**
|
|
87
|
+
* Get top offset of rowIndex
|
|
88
|
+
*/
|
|
89
|
+
var getRowOffset = (0, react_1.useCallback)(function (index, readonly) {
|
|
90
|
+
if (index < 0) {
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
return (0, helpers_3.getRowOffset)({
|
|
94
|
+
index: index,
|
|
95
|
+
rowHeight: rowHeight,
|
|
96
|
+
columnWidth: columnWidth,
|
|
97
|
+
instanceProps: instanceProps.current,
|
|
98
|
+
scale: scale,
|
|
99
|
+
readonly: readonly,
|
|
100
|
+
visibleRowRanges: visibleRowRanges,
|
|
101
|
+
});
|
|
102
|
+
}, [rowHeight, columnWidth, scale, visibleRowRanges]);
|
|
103
|
+
/**
|
|
104
|
+
* Get lefft offset of columnIndex
|
|
105
|
+
*/
|
|
106
|
+
var getColumnOffset = (0, react_1.useCallback)(function (index, readonly) {
|
|
107
|
+
if (index < 0) {
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
return (0, helpers_3.getColumnOffset)({
|
|
111
|
+
index: index,
|
|
112
|
+
rowHeight: rowHeight,
|
|
113
|
+
columnWidth: columnWidth,
|
|
114
|
+
instanceProps: instanceProps.current,
|
|
115
|
+
scale: scale,
|
|
116
|
+
readonly: readonly,
|
|
117
|
+
});
|
|
118
|
+
}, [rowHeight, columnWidth, scale]);
|
|
119
|
+
/**
|
|
120
|
+
* Get height of rowIndex
|
|
121
|
+
*/
|
|
122
|
+
var getRowHeight = (0, react_1.useCallback)(function (index) {
|
|
123
|
+
return (0, helpers_3.getRowHeight)(index, instanceProps.current);
|
|
124
|
+
}, []);
|
|
125
|
+
/**
|
|
126
|
+
* Get height of columNiondex
|
|
127
|
+
*/
|
|
128
|
+
var getColumnWidth = (0, react_1.useCallback)(function (index) {
|
|
129
|
+
return (0, helpers_3.getColumnWidth)(index, instanceProps.current);
|
|
130
|
+
}, []);
|
|
131
|
+
/**
|
|
132
|
+
* onScroll callback
|
|
133
|
+
*/
|
|
134
|
+
(0, react_1.useEffect)(function () {
|
|
135
|
+
if (!isMounted.current)
|
|
136
|
+
return;
|
|
137
|
+
onScroll === null || onScroll === void 0 ? void 0 : onScroll({ scrollTop: scrollTop, scrollLeft: scrollLeft });
|
|
138
|
+
}, [scrollTop, scrollLeft, onScroll]);
|
|
139
|
+
/**
|
|
140
|
+
* Autofocus container
|
|
141
|
+
* Imperative focus, the `div` does not support autoFocus
|
|
142
|
+
* property
|
|
143
|
+
*/
|
|
144
|
+
(0, react_1.useEffect)(function () {
|
|
145
|
+
if (autoFocus) {
|
|
146
|
+
focusContainer();
|
|
147
|
+
}
|
|
148
|
+
}, [autoFocus, focusContainer]);
|
|
149
|
+
/**
|
|
150
|
+
* Imperatively get the current scroll position
|
|
151
|
+
*/
|
|
152
|
+
var getScrollPosition = (0, react_1.useCallback)(function () {
|
|
153
|
+
return {
|
|
154
|
+
scrollTop: scrollTop,
|
|
155
|
+
scrollLeft: scrollLeft,
|
|
156
|
+
};
|
|
157
|
+
}, [scrollTop, scrollLeft]);
|
|
158
|
+
/**
|
|
159
|
+
* Redraw grid
|
|
160
|
+
*/
|
|
161
|
+
var redrawGrid = (0, react_1.useCallback)(function () {
|
|
162
|
+
var _a;
|
|
163
|
+
// Sync props
|
|
164
|
+
forceRender();
|
|
165
|
+
// Redraw camvas
|
|
166
|
+
(_a = stageRef.current) === null || _a === void 0 ? void 0 : _a.batchDraw();
|
|
167
|
+
}, []);
|
|
168
|
+
/**
|
|
169
|
+
* Create a map of merged cells
|
|
170
|
+
* [rowIndex, columnindex] => [parentRowIndex, parentColumnIndex]
|
|
171
|
+
*/
|
|
172
|
+
var mergedCellMap = (0, react_1.useMemo)(function () {
|
|
173
|
+
var e_1, _a;
|
|
174
|
+
var mergedCellMap = new Map();
|
|
175
|
+
if (mergedCells) {
|
|
176
|
+
for (var i = 0; i < mergedCells.length; i++) {
|
|
177
|
+
var bounds = mergedCells[i];
|
|
178
|
+
try {
|
|
179
|
+
for (var _b = (e_1 = void 0, tslib_1.__values((0, helpers_3.getBoundedCells)(bounds))), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
180
|
+
var cell = _c.value;
|
|
181
|
+
mergedCellMap.set(cell, bounds);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
185
|
+
finally {
|
|
186
|
+
try {
|
|
187
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
188
|
+
}
|
|
189
|
+
finally { if (e_1) throw e_1.error; }
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return mergedCellMap;
|
|
194
|
+
}, [mergedCells]);
|
|
195
|
+
/* Check if a cell is part of a merged cell */
|
|
196
|
+
var isMergedCell = (0, react_1.useCallback)(function (_a) {
|
|
197
|
+
var rowIndex = _a.rowIndex, columnIndex = _a.columnIndex;
|
|
198
|
+
return mergedCellMap.has((0, helpers_3.cellIdentifier)(rowIndex, columnIndex));
|
|
199
|
+
}, [mergedCellMap]);
|
|
200
|
+
/* Get top, left bounds of a cell */
|
|
201
|
+
var getCellBounds = (0, react_1.useCallback)(function (_a, spanMerges) {
|
|
202
|
+
var rowIndex = _a.rowIndex, columnIndex = _a.columnIndex;
|
|
203
|
+
if (spanMerges === void 0) { spanMerges = true; }
|
|
204
|
+
if (spanMerges) {
|
|
205
|
+
var isMerged = isMergedCell({ rowIndex: rowIndex, columnIndex: columnIndex });
|
|
206
|
+
if (isMerged)
|
|
207
|
+
return mergedCellMap.get((0, helpers_3.cellIdentifier)(rowIndex, columnIndex));
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
startRowIndex: rowIndex,
|
|
211
|
+
startColumnIndex: columnIndex,
|
|
212
|
+
endColumnIndex: columnIndex,
|
|
213
|
+
endRowIndex: rowIndex,
|
|
214
|
+
};
|
|
215
|
+
}, [mergedCellMap, isMergedCell]);
|
|
216
|
+
/* Get top, left bounds of a cell */
|
|
217
|
+
var getActualCellCoords = (0, react_1.useCallback)(function (_a) {
|
|
218
|
+
var rowIndex = _a.rowIndex, columnIndex = _a.columnIndex;
|
|
219
|
+
var isMerged = isMergedCell({ rowIndex: rowIndex, columnIndex: columnIndex });
|
|
220
|
+
if (isMerged) {
|
|
221
|
+
var cell = mergedCellMap.get((0, helpers_3.cellIdentifier)(rowIndex, columnIndex));
|
|
222
|
+
return {
|
|
223
|
+
rowIndex: cell === null || cell === void 0 ? void 0 : cell.startRowIndex,
|
|
224
|
+
columnIndex: cell === null || cell === void 0 ? void 0 : cell.startColumnIndex,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
rowIndex: rowIndex,
|
|
229
|
+
columnIndex: columnIndex,
|
|
230
|
+
};
|
|
231
|
+
}, [mergedCellMap, isMergedCell]);
|
|
232
|
+
/* Spacing for frozen row/column clip */
|
|
233
|
+
var frozenSpacing = 1;
|
|
234
|
+
var frozenColumnWidth = (0, react_1.useMemo)(function () { return getColumnOffset(frozenColumns); }, [frozenColumns, getColumnOffset]);
|
|
235
|
+
var frozenRowHeight = (0, react_1.useMemo)(function () { return getRowOffset(frozenRows); }, [frozenRows, getRowOffset]);
|
|
236
|
+
// Header columns dimensions: Only for Spreadsheet
|
|
237
|
+
var headerRowHeight = (0, react_1.useMemo)(function () { return getRowOffset(1) + frozenSpacing; }, [getRowOffset, frozenSpacing]);
|
|
238
|
+
var headerColumnWidth = (0, react_1.useMemo)(function () { return getColumnOffset(1) + frozenSpacing; }, [getColumnOffset, frozenSpacing]);
|
|
239
|
+
var _24 = tslib_1.__read((0, react_1.useMemo)(function () {
|
|
240
|
+
var startIndex = (0, helpers_3.getRowStartIndexForOffset)({
|
|
241
|
+
rowHeight: rowHeight,
|
|
242
|
+
columnWidth: columnWidth,
|
|
243
|
+
rowCount: rowCount,
|
|
244
|
+
columnCount: columnCount,
|
|
245
|
+
instanceProps: instanceProps.current,
|
|
246
|
+
offset: scrollTop + frozenRowHeight,
|
|
247
|
+
scale: scale,
|
|
248
|
+
});
|
|
249
|
+
var stopIndex = (0, helpers_3.getRowStopIndexForStartIndex)({
|
|
250
|
+
startIndex: startIndex,
|
|
251
|
+
rowCount: rowCount,
|
|
252
|
+
rowHeight: rowHeight,
|
|
253
|
+
columnWidth: columnWidth,
|
|
254
|
+
scrollTop: scrollTop,
|
|
255
|
+
containerHeight: containerHeight,
|
|
256
|
+
instanceProps: instanceProps.current,
|
|
257
|
+
scale: scale,
|
|
258
|
+
visibleRowRanges: visibleRowRanges,
|
|
259
|
+
});
|
|
260
|
+
return [
|
|
261
|
+
Math.max(0, startIndex),
|
|
262
|
+
Math.max(0, Math.min(rowCount - 1, stopIndex)),
|
|
263
|
+
startIndex,
|
|
264
|
+
stopIndex,
|
|
265
|
+
];
|
|
266
|
+
}, [
|
|
267
|
+
rowHeight,
|
|
268
|
+
columnWidth,
|
|
269
|
+
rowCount,
|
|
270
|
+
columnCount,
|
|
271
|
+
scale,
|
|
272
|
+
scrollTop,
|
|
273
|
+
containerHeight,
|
|
274
|
+
frozenRowHeight,
|
|
275
|
+
visibleRowRanges,
|
|
276
|
+
]), 4), rowStartIndex = _24[0], rowStopIndex = _24[1], visibleRowStartIndex = _24[2], visibleRowStopIndex = _24[3];
|
|
277
|
+
var _25 = tslib_1.__read((0, react_1.useMemo)(function () {
|
|
278
|
+
var _a;
|
|
279
|
+
var startIndex = (0, helpers_3.getColumnStartIndexForOffset)({
|
|
280
|
+
rowHeight: rowHeight,
|
|
281
|
+
columnWidth: columnWidth,
|
|
282
|
+
rowCount: rowCount,
|
|
283
|
+
columnCount: columnCount,
|
|
284
|
+
instanceProps: instanceProps.current,
|
|
285
|
+
offset: Math.max(0, scrollLeft +
|
|
286
|
+
frozenColumnWidth -
|
|
287
|
+
((_a = getOverflowBuffer === null || getOverflowBuffer === void 0 ? void 0 : getOverflowBuffer(scrollLeft)) !== null && _a !== void 0 ? _a : 0)),
|
|
288
|
+
scale: scale,
|
|
289
|
+
});
|
|
290
|
+
var stopIndex = (0, helpers_3.getColumnStopIndexForStartIndex)({
|
|
291
|
+
startIndex: startIndex,
|
|
292
|
+
columnCount: columnCount,
|
|
293
|
+
rowHeight: rowHeight,
|
|
294
|
+
columnWidth: columnWidth,
|
|
295
|
+
scrollLeft: scrollLeft,
|
|
296
|
+
containerWidth: containerWidth,
|
|
297
|
+
instanceProps: instanceProps.current,
|
|
298
|
+
scale: scale,
|
|
299
|
+
});
|
|
300
|
+
// Text overflow can be made visible with a higher
|
|
301
|
+
// overscanCount
|
|
302
|
+
return [
|
|
303
|
+
Math.max(0, startIndex - overscanCount),
|
|
304
|
+
Math.max(0, Math.min(columnCount - 1, stopIndex)),
|
|
305
|
+
startIndex,
|
|
306
|
+
stopIndex,
|
|
307
|
+
];
|
|
308
|
+
}, [
|
|
309
|
+
rowHeight,
|
|
310
|
+
columnWidth,
|
|
311
|
+
rowCount,
|
|
312
|
+
columnCount,
|
|
313
|
+
scale,
|
|
314
|
+
containerWidth,
|
|
315
|
+
scrollLeft,
|
|
316
|
+
overscanCount,
|
|
317
|
+
frozenColumnWidth,
|
|
318
|
+
getOverflowBuffer,
|
|
319
|
+
]), 4), columnStartIndex = _25[0], columnStopIndex = _25[1], visibleColumnStartIndex = _25[2], visibleColumnStopIndex = _25[3];
|
|
320
|
+
/**
|
|
321
|
+
* Get visible row indices within the viewport range.
|
|
322
|
+
* Uses visibleRowRanges for O(r) iteration when available,
|
|
323
|
+
* otherwise falls back to checking isHiddenRow for each row.
|
|
324
|
+
*/
|
|
325
|
+
var getVisibleRowIndices = (0, react_1.useCallback)(function (startIndex, stopIndex, skipFrozen) {
|
|
326
|
+
var e_2, _a;
|
|
327
|
+
if (skipFrozen === void 0) { skipFrozen = true; }
|
|
328
|
+
var indices = [];
|
|
329
|
+
if (visibleRowRanges) {
|
|
330
|
+
try {
|
|
331
|
+
// Use pre-computed ranges for efficient iteration
|
|
332
|
+
for (var visibleRowRanges_1 = tslib_1.__values(visibleRowRanges), visibleRowRanges_1_1 = visibleRowRanges_1.next(); !visibleRowRanges_1_1.done; visibleRowRanges_1_1 = visibleRowRanges_1.next()) {
|
|
333
|
+
var range = visibleRowRanges_1_1.value;
|
|
334
|
+
// Skip ranges entirely before our viewport
|
|
335
|
+
if (range.end < startIndex)
|
|
336
|
+
continue;
|
|
337
|
+
// Stop if we've passed the viewport
|
|
338
|
+
if (range.start > stopIndex)
|
|
339
|
+
break;
|
|
340
|
+
var effectiveStart = Math.max(range.start, startIndex);
|
|
341
|
+
var effectiveEnd = Math.min(range.end, stopIndex);
|
|
342
|
+
for (var rowIndex = effectiveStart; rowIndex <= effectiveEnd; rowIndex++) {
|
|
343
|
+
if (skipFrozen && rowIndex < frozenRows)
|
|
344
|
+
continue;
|
|
345
|
+
indices.push(rowIndex);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
350
|
+
finally {
|
|
351
|
+
try {
|
|
352
|
+
if (visibleRowRanges_1_1 && !visibleRowRanges_1_1.done && (_a = visibleRowRanges_1.return)) _a.call(visibleRowRanges_1);
|
|
353
|
+
}
|
|
354
|
+
finally { if (e_2) throw e_2.error; }
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
// Fallback to checking each row
|
|
359
|
+
for (var rowIndex = startIndex; rowIndex <= stopIndex; rowIndex++) {
|
|
360
|
+
if (skipFrozen && rowIndex < frozenRows)
|
|
361
|
+
continue;
|
|
362
|
+
if (isHiddenRow === null || isHiddenRow === void 0 ? void 0 : isHiddenRow(rowIndex))
|
|
363
|
+
continue;
|
|
364
|
+
indices.push(rowIndex);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return indices;
|
|
368
|
+
}, [visibleRowRanges, isHiddenRow, frozenRows]);
|
|
369
|
+
var estimatedTotalHeight = (0, react_1.useMemo)(function () { return (0, helpers_3.getEstimatedTotalHeight)(rowCount, instanceProps.current); }, [rowCount, instanceProps.current.lastMeasuredRowIndex, rowHeight]);
|
|
370
|
+
var estimatedTotalWidth = (0, react_1.useMemo)(function () { return (0, helpers_3.getEstimatedTotalWidth)(columnCount, instanceProps.current); }, [columnCount, instanceProps.current.lastMeasuredColumnIndex, columnWidth]);
|
|
371
|
+
/* Method to get dimensions of the grid */
|
|
372
|
+
var getDimensions = (0, react_1.useCallback)(function () {
|
|
373
|
+
return {
|
|
374
|
+
containerWidth: containerWidth,
|
|
375
|
+
containerHeight: containerHeight,
|
|
376
|
+
estimatedTotalWidth: estimatedTotalWidth,
|
|
377
|
+
estimatedTotalHeight: estimatedTotalHeight,
|
|
378
|
+
};
|
|
379
|
+
}, [
|
|
380
|
+
containerWidth,
|
|
381
|
+
containerHeight,
|
|
382
|
+
estimatedTotalWidth,
|
|
383
|
+
estimatedTotalHeight,
|
|
384
|
+
]);
|
|
385
|
+
/**
|
|
386
|
+
* Update snap properties if its active
|
|
387
|
+
* We need this because we are binding `onwheel` event to document
|
|
388
|
+
* So props go stale
|
|
389
|
+
*/
|
|
390
|
+
(0, helpers_3.useIsomorphicLayoutEffect)(function () {
|
|
391
|
+
if (snap) {
|
|
392
|
+
scrollSnapRefs.current = {
|
|
393
|
+
visibleRowStartIndex: visibleRowStartIndex,
|
|
394
|
+
rowCount: rowCount,
|
|
395
|
+
visibleColumnStartIndex: visibleColumnStartIndex,
|
|
396
|
+
columnCount: columnCount,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
}, [
|
|
400
|
+
snap,
|
|
401
|
+
visibleRowStartIndex,
|
|
402
|
+
rowCount,
|
|
403
|
+
visibleColumnStartIndex,
|
|
404
|
+
columnCount,
|
|
405
|
+
]);
|
|
406
|
+
/**
|
|
407
|
+
* Snaps vertical scrollbar to the next/prev visible row
|
|
408
|
+
*/
|
|
409
|
+
var snapToRowFn = (0, react_1.useCallback)(function (_a) {
|
|
410
|
+
var deltaY = _a.deltaY;
|
|
411
|
+
if (!verticalScrollRef.current || !scrollSnapRefs.current)
|
|
412
|
+
return;
|
|
413
|
+
if (deltaY !== 0) {
|
|
414
|
+
var direction = deltaY < 0 ? types_1.Direction.Up : types_1.Direction.Down;
|
|
415
|
+
var index = (0, helpers_2.getScrollIncrement)(deltaY, DEFAULT_ROW_HEIGHT);
|
|
416
|
+
var _b = scrollSnapRefs.current, visibleRowStartIndex_1 = _b.visibleRowStartIndex, rowCount_1 = _b.rowCount;
|
|
417
|
+
var nextVisibleRow = (0, helpers_3.clampIndex)(visibleRowStartIndex_1 + (direction === types_1.Direction.Down ? 1 : -1), isHiddenRow, direction);
|
|
418
|
+
var nextIndex = direction === types_1.Direction.Up
|
|
419
|
+
? // User is scrolling up
|
|
420
|
+
Math.max(0, nextVisibleRow - index)
|
|
421
|
+
: Math.min(nextVisibleRow + index, rowCount_1 - 1);
|
|
422
|
+
/* Ignore hidden row */
|
|
423
|
+
nextIndex = (0, helpers_3.clampIndex)(nextIndex, isHiddenRow, direction);
|
|
424
|
+
var rowOffset = getRowOffset(nextIndex) - frozenRowHeight;
|
|
425
|
+
verticalScrollRef.current.scrollTo({
|
|
426
|
+
top: rowOffset,
|
|
427
|
+
behavior: "auto",
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}, [getRowOffset, isHiddenRow, frozenRowHeight]);
|
|
431
|
+
/**
|
|
432
|
+
* Snaps horizontal scrollbar to the next/prev visible column
|
|
433
|
+
*/
|
|
434
|
+
var snapToColumnFn = (0, react_1.useCallback)(function (_a) {
|
|
435
|
+
var deltaX = _a.deltaX;
|
|
436
|
+
if (!horizontalScrollRef.current || !scrollSnapRefs.current)
|
|
437
|
+
return;
|
|
438
|
+
if (deltaX !== 0) {
|
|
439
|
+
var index = (0, helpers_2.getScrollIncrement)(deltaX, DEFAULT_COLUMN_WIDTH); // Min column width
|
|
440
|
+
var direction = deltaX < 0 ? types_1.Direction.Left : types_1.Direction.Right;
|
|
441
|
+
var _b = scrollSnapRefs.current, visibleColumnStartIndex_1 = _b.visibleColumnStartIndex, columnCount_1 = _b.columnCount;
|
|
442
|
+
var nextVisibleColumn = (0, helpers_3.clampIndex)(visibleColumnStartIndex_1 + (direction === types_1.Direction.Right ? 1 : -1), isHiddenColumn, direction);
|
|
443
|
+
var nextIndex = direction === types_1.Direction.Left
|
|
444
|
+
? Math.max(0, nextVisibleColumn - index)
|
|
445
|
+
: Math.min(nextVisibleColumn + index, columnCount_1 - 1);
|
|
446
|
+
/* Ignore hidden column */
|
|
447
|
+
nextIndex = (0, helpers_3.clampIndex)(nextIndex, isHiddenColumn, direction);
|
|
448
|
+
var columnOffset = getColumnOffset(nextIndex) - frozenColumnWidth;
|
|
449
|
+
horizontalScrollRef.current.scrollTo({
|
|
450
|
+
left: columnOffset,
|
|
451
|
+
behavior: "auto",
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}, [getColumnOffset, isHiddenColumn, frozenColumnWidth]);
|
|
455
|
+
var snapToRowThrottler = (0, react_1.useRef)(undefined);
|
|
456
|
+
var snapToColumnThrottler = (0, react_1.useRef)(undefined);
|
|
457
|
+
/**
|
|
458
|
+
* Register snap throttlers
|
|
459
|
+
*/
|
|
460
|
+
(0, helpers_3.useIsomorphicLayoutEffect)(function () {
|
|
461
|
+
if (snap) {
|
|
462
|
+
snapToRowThrottler.current = (0, helpers_1.ricThrottle)(snapToRowFn);
|
|
463
|
+
snapToColumnThrottler.current = (0, helpers_1.ricThrottle)(snapToColumnFn);
|
|
464
|
+
}
|
|
465
|
+
return function () {
|
|
466
|
+
snapToRowThrottler.current = undefined;
|
|
467
|
+
snapToColumnThrottler.current = undefined;
|
|
468
|
+
};
|
|
469
|
+
}, [snap, scrollThrottleTimeout, snapToColumnFn, snapToRowFn]);
|
|
470
|
+
/* Find frozen column boundary */
|
|
471
|
+
var isWithinFrozenColumnBoundary = (0, react_1.useCallback)(function (x) {
|
|
472
|
+
return frozenColumns > 0 && x < frozenColumnWidth;
|
|
473
|
+
}, [frozenColumns, frozenColumnWidth]);
|
|
474
|
+
/* Find frozen row boundary */
|
|
475
|
+
var isWithinFrozenRowBoundary = (0, react_1.useCallback)(function (y) {
|
|
476
|
+
return frozenRows > 0 && y < frozenRowHeight;
|
|
477
|
+
}, [frozenRows, frozenRowHeight]);
|
|
478
|
+
/**
|
|
479
|
+
* Get relative mouse position
|
|
480
|
+
*/
|
|
481
|
+
var getRelativePositionFromOffset = (0, react_1.useCallback)(function (left, top) {
|
|
482
|
+
var _a;
|
|
483
|
+
(0, tiny_invariant_1.default)(typeof left === "number" && typeof top === "number", "Top and left should be a number");
|
|
484
|
+
if (!stageRef.current) {
|
|
485
|
+
return undefined;
|
|
486
|
+
}
|
|
487
|
+
var stage = stageRef.current.getStage();
|
|
488
|
+
var rect = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
489
|
+
if (rect) {
|
|
490
|
+
left = left - rect.x;
|
|
491
|
+
top = top - rect.y;
|
|
492
|
+
}
|
|
493
|
+
var _b = stage
|
|
494
|
+
.getAbsoluteTransform()
|
|
495
|
+
.copy()
|
|
496
|
+
.invert()
|
|
497
|
+
.point({ x: left, y: top }), x = _b.x, y = _b.y;
|
|
498
|
+
return { x: x, y: y };
|
|
499
|
+
}, []);
|
|
500
|
+
/**
|
|
501
|
+
* Get position absolute to document
|
|
502
|
+
* from relative grid coordinates
|
|
503
|
+
*/
|
|
504
|
+
var getAbsolutePositionFromOffset = (0, react_1.useCallback)(function (x, y) {
|
|
505
|
+
var _a;
|
|
506
|
+
var rect = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
507
|
+
if (rect) {
|
|
508
|
+
x = x + rect.x;
|
|
509
|
+
y = y + rect.y;
|
|
510
|
+
}
|
|
511
|
+
return {
|
|
512
|
+
x: x,
|
|
513
|
+
y: y,
|
|
514
|
+
};
|
|
515
|
+
}, []);
|
|
516
|
+
/**
|
|
517
|
+
* Get cell cordinates from current mouse x/y positions
|
|
518
|
+
*/
|
|
519
|
+
var getCellCoordsFromOffset = (0, react_1.useCallback)(function (left, top, includeFrozen) {
|
|
520
|
+
if (includeFrozen === void 0) { includeFrozen = true; }
|
|
521
|
+
var pos = getRelativePositionFromOffset(left, top);
|
|
522
|
+
if (!pos)
|
|
523
|
+
return undefined;
|
|
524
|
+
var x = pos.x, y = pos.y;
|
|
525
|
+
var rowOffset = includeFrozen && isWithinFrozenRowBoundary(y) ? y : y + scrollTop;
|
|
526
|
+
var columnOffset = includeFrozen && isWithinFrozenColumnBoundary(x) ? x : x + scrollLeft;
|
|
527
|
+
if (rowOffset > estimatedTotalHeight ||
|
|
528
|
+
columnOffset > estimatedTotalWidth) {
|
|
529
|
+
return undefined;
|
|
530
|
+
}
|
|
531
|
+
var rowIndex = (0, helpers_3.getRowStartIndexForOffset)({
|
|
532
|
+
rowHeight: rowHeight,
|
|
533
|
+
columnWidth: columnWidth,
|
|
534
|
+
rowCount: rowCount,
|
|
535
|
+
columnCount: columnCount,
|
|
536
|
+
instanceProps: instanceProps.current,
|
|
537
|
+
offset: rowOffset,
|
|
538
|
+
scale: scale,
|
|
539
|
+
});
|
|
540
|
+
var columnIndex = (0, helpers_3.getColumnStartIndexForOffset)({
|
|
541
|
+
rowHeight: rowHeight,
|
|
542
|
+
columnWidth: columnWidth,
|
|
543
|
+
rowCount: rowCount,
|
|
544
|
+
columnCount: columnCount,
|
|
545
|
+
instanceProps: instanceProps.current,
|
|
546
|
+
offset: columnOffset,
|
|
547
|
+
scale: scale,
|
|
548
|
+
});
|
|
549
|
+
/* To be compatible with merged cells */
|
|
550
|
+
var bounds = getCellBounds({ rowIndex: rowIndex, columnIndex: columnIndex });
|
|
551
|
+
return {
|
|
552
|
+
rowIndex: bounds.startRowIndex,
|
|
553
|
+
columnIndex: bounds.startColumnIndex,
|
|
554
|
+
};
|
|
555
|
+
}, [
|
|
556
|
+
scale,
|
|
557
|
+
scrollLeft,
|
|
558
|
+
rowHeight,
|
|
559
|
+
columnWidth,
|
|
560
|
+
scrollTop,
|
|
561
|
+
rowCount,
|
|
562
|
+
estimatedTotalHeight,
|
|
563
|
+
estimatedTotalWidth,
|
|
564
|
+
columnCount,
|
|
565
|
+
isWithinFrozenRowBoundary,
|
|
566
|
+
isWithinFrozenColumnBoundary,
|
|
567
|
+
getRelativePositionFromOffset,
|
|
568
|
+
getCellBounds,
|
|
569
|
+
]);
|
|
570
|
+
/**
|
|
571
|
+
* Get cell offset position from rowIndex, columnIndex
|
|
572
|
+
*
|
|
573
|
+
*/
|
|
574
|
+
var getCellOffsetFromCoords = (0, react_1.useCallback)(function (cell, readonly) {
|
|
575
|
+
var _a = getCellBounds(cell), startRowIndex = _a.startRowIndex, startColumnIndex = _a.startColumnIndex, endColumnIndex = _a.endColumnIndex, endRowIndex = _a.endRowIndex;
|
|
576
|
+
var x = getColumnOffset(startColumnIndex, readonly);
|
|
577
|
+
var y = getRowOffset(startRowIndex, readonly);
|
|
578
|
+
var width = getColumnOffset(endColumnIndex + 1, readonly) - x;
|
|
579
|
+
var height = getRowOffset(endRowIndex + 1, readonly) - y;
|
|
580
|
+
return {
|
|
581
|
+
x: x,
|
|
582
|
+
y: y,
|
|
583
|
+
width: width,
|
|
584
|
+
height: height,
|
|
585
|
+
};
|
|
586
|
+
}, [getColumnOffset, getRowOffset, getCellBounds]);
|
|
587
|
+
/* Get current view port of the grid */
|
|
588
|
+
var getViewPort = (0, helpers_2.useCallbackRef)((0, react_1.useCallback)(function () {
|
|
589
|
+
return {
|
|
590
|
+
rowStartIndex: rowStartIndex,
|
|
591
|
+
rowStopIndex: rowStopIndex,
|
|
592
|
+
columnStartIndex: columnStartIndex,
|
|
593
|
+
columnStopIndex: columnStopIndex,
|
|
594
|
+
visibleRowStartIndex: visibleRowStartIndex,
|
|
595
|
+
visibleRowStopIndex: visibleRowStopIndex,
|
|
596
|
+
visibleColumnStartIndex: visibleColumnStartIndex,
|
|
597
|
+
visibleColumnStopIndex: visibleColumnStopIndex,
|
|
598
|
+
};
|
|
599
|
+
}, [
|
|
600
|
+
rowStartIndex,
|
|
601
|
+
rowStopIndex,
|
|
602
|
+
columnStartIndex,
|
|
603
|
+
columnStopIndex,
|
|
604
|
+
visibleRowStartIndex,
|
|
605
|
+
visibleRowStopIndex,
|
|
606
|
+
visibleColumnStartIndex,
|
|
607
|
+
visibleColumnStopIndex,
|
|
608
|
+
]));
|
|
609
|
+
// Scrollbars
|
|
610
|
+
var scrollbarXContainterWidth = containerWidth - frozenColumnWidth;
|
|
611
|
+
var scrollbarXWidth = estimatedTotalWidth -
|
|
612
|
+
frozenColumnWidth +
|
|
613
|
+
(extendScrollSize ? scrollbarSize : 0);
|
|
614
|
+
var scrollbarYContainterHeight = containerHeight - frozenRowHeight;
|
|
615
|
+
var scrollbarYHeight = estimatedTotalHeight -
|
|
616
|
+
frozenRowHeight +
|
|
617
|
+
(extendScrollSize ? scrollbarSize : 0) +
|
|
618
|
+
(footerHeight > 0 ? footerHeight - scrollbarSize : 0);
|
|
619
|
+
var showScrollbarX = showScrollbar && scrollbarXWidth > scrollbarXContainterWidth;
|
|
620
|
+
var showScrollbarY = showScrollbar && scrollbarYHeight > scrollbarYContainterHeight;
|
|
621
|
+
var needsScaling = scrollbarYHeight > MAX_SCROLLBAR_HEIGHT;
|
|
622
|
+
var effectiveScrollbarYHeight = Math.min(MAX_SCROLLBAR_HEIGHT, scrollbarYHeight);
|
|
623
|
+
/**
|
|
624
|
+
* Clears the cell cache
|
|
625
|
+
* when scrolling is done or when user changes sheet
|
|
626
|
+
*/
|
|
627
|
+
var clearCache = (0, react_1.useCallback)(function () {
|
|
628
|
+
cellCacheRef.current.clear();
|
|
629
|
+
cellOverlayCacheRef.current.clear();
|
|
630
|
+
cellBackgroundCacheRef.current.clear();
|
|
631
|
+
}, []);
|
|
632
|
+
/**
|
|
633
|
+
* Conditionally get and set cell cache and return cell
|
|
634
|
+
*/
|
|
635
|
+
var getCellCache = (0, react_1.useCallback)(function (cache, cellId, nodeGetter, isScrolling, isMerged) {
|
|
636
|
+
if (isMerged === void 0) { isMerged = false; }
|
|
637
|
+
var cell = isScrolling && !isMerged && cache.has(cellId)
|
|
638
|
+
? cache.get(cellId)
|
|
639
|
+
: nodeGetter();
|
|
640
|
+
// Get it from cache
|
|
641
|
+
if (isScrolling && !cache.has(cellId)) {
|
|
642
|
+
cache.set(cellId, cell);
|
|
643
|
+
}
|
|
644
|
+
return cell;
|
|
645
|
+
}, []);
|
|
646
|
+
/* Redraw grid imperatively */
|
|
647
|
+
var resetAfterIndices = (0, react_1.useCallback)(function (_a, shouldForceUpdate) {
|
|
648
|
+
var columnIndex = _a.columnIndex, rowIndex = _a.rowIndex;
|
|
649
|
+
if (shouldForceUpdate === void 0) { shouldForceUpdate = true; }
|
|
650
|
+
if (typeof columnIndex === "number") {
|
|
651
|
+
instanceProps.current.lastMeasuredColumnIndex = Math.min(instanceProps.current.lastMeasuredColumnIndex, columnIndex - 1);
|
|
652
|
+
}
|
|
653
|
+
if (typeof rowIndex === "number") {
|
|
654
|
+
instanceProps.current.lastMeasuredRowIndex = Math.min(instanceProps.current.lastMeasuredRowIndex, rowIndex - 1);
|
|
655
|
+
}
|
|
656
|
+
clearCache();
|
|
657
|
+
if (shouldForceUpdate)
|
|
658
|
+
forceRender();
|
|
659
|
+
}, [clearCache]);
|
|
660
|
+
/**
|
|
661
|
+
* Resize one or more columns
|
|
662
|
+
* Update columnMetadataMap
|
|
663
|
+
* lastMeasuredRowIndex or lastMeasuredColumnIndex
|
|
664
|
+
*
|
|
665
|
+
* This fixes unexpected rendering issue where
|
|
666
|
+
* 1. User resizes a column - And informs the grid that from column 2 needs to be repainted and updates the state
|
|
667
|
+
* 2. In the render, function, use uses getCellOffsetFromCoords, which changes the lastMeasured indexes
|
|
668
|
+
* 3. 2) Will happen before state has been updated and it wont queue column from 1) to be resized
|
|
669
|
+
*/
|
|
670
|
+
var resizeColumn = (0, react_1.useCallback)(function (index, dimension) {
|
|
671
|
+
instanceProps.current.columnMetadataMap.get(index).size = dimension;
|
|
672
|
+
resetAfterIndices({ columnIndex: index }, false);
|
|
673
|
+
}, [resetAfterIndices]);
|
|
674
|
+
/**
|
|
675
|
+
* Resize one or more rows
|
|
676
|
+
*/
|
|
677
|
+
var resizeRow = (0, react_1.useCallback)(function (index, dimension) {
|
|
678
|
+
instanceProps.current.rowMetadataMap.get(index).size = dimension;
|
|
679
|
+
resetAfterIndices({ rowIndex: index + 1 }, false);
|
|
680
|
+
}, [resetAfterIndices]);
|
|
681
|
+
/* Expose some methods in ref */
|
|
682
|
+
(0, react_1.useImperativeHandle)(forwardedRef, function () {
|
|
683
|
+
return {
|
|
684
|
+
scrollTo: scrollTo,
|
|
685
|
+
scrollBy: scrollBy,
|
|
686
|
+
scrollToCell: scrollToCell,
|
|
687
|
+
stage: stageRef.current,
|
|
688
|
+
rowHeaderStage: rowHeaderStageRef.current,
|
|
689
|
+
columnHeaderStage: columnHeaderStageRef.current,
|
|
690
|
+
container: containerRef.current,
|
|
691
|
+
resetAfterIndices: resetAfterIndices,
|
|
692
|
+
getScrollPosition: getScrollPosition,
|
|
693
|
+
isMergedCell: isMergedCell,
|
|
694
|
+
getCellBounds: getCellBounds,
|
|
695
|
+
getCellCoordsFromOffset: getCellCoordsFromOffset,
|
|
696
|
+
getCellOffsetFromCoords: getCellOffsetFromCoords,
|
|
697
|
+
getActualCellCoords: getActualCellCoords,
|
|
698
|
+
focus: focusContainer,
|
|
699
|
+
resizeColumn: resizeColumn,
|
|
700
|
+
resizeRow: resizeRow,
|
|
701
|
+
getViewPort: getViewPort,
|
|
702
|
+
getRelativePositionFromOffset: getRelativePositionFromOffset,
|
|
703
|
+
getAbsolutePositionFromOffset: getAbsolutePositionFromOffset,
|
|
704
|
+
scrollToTop: scrollToTop,
|
|
705
|
+
scrollToBottom: scrollToBottom,
|
|
706
|
+
getDimensions: getDimensions,
|
|
707
|
+
getRowOffset: getRowOffset,
|
|
708
|
+
getColumnOffset: getColumnOffset,
|
|
709
|
+
redrawGrid: redrawGrid,
|
|
710
|
+
clearCache: clearCache,
|
|
711
|
+
};
|
|
712
|
+
});
|
|
713
|
+
/**
|
|
714
|
+
* When the grid is scrolling,
|
|
715
|
+
* 1. Stage does not listen to any mouse events
|
|
716
|
+
* 2. Div container does not listen to pointer events
|
|
717
|
+
*/
|
|
718
|
+
/* Reset isScrolling */
|
|
719
|
+
var resetIsScrolling = (0, react_1.useCallback)(function () {
|
|
720
|
+
resetIsScrollingTimeoutID.current = null;
|
|
721
|
+
// Reset cell cache
|
|
722
|
+
clearCache();
|
|
723
|
+
setScrollState(function (prev) {
|
|
724
|
+
// Only if required
|
|
725
|
+
if (prev.isScrolling === false) {
|
|
726
|
+
return prev;
|
|
727
|
+
}
|
|
728
|
+
return tslib_1.__assign(tslib_1.__assign({}, prev), { isScrolling: false });
|
|
729
|
+
});
|
|
730
|
+
}, [clearCache]);
|
|
731
|
+
var resetIsScrollingTimeoutID = (0, react_1.useRef)(null);
|
|
732
|
+
var resetIsScrollingDebounced = (0, react_1.useCallback)(function () {
|
|
733
|
+
if (resetIsScrollingTimeoutID.current !== null) {
|
|
734
|
+
(0, helpers_3.cancelTimeout)(resetIsScrollingTimeoutID.current);
|
|
735
|
+
}
|
|
736
|
+
resetIsScrollingTimeoutID.current = (0, helpers_3.requestTimeout)(resetIsScrolling, exports.RESET_SCROLL_EVENTS_DEBOUNCE_INTERVAL);
|
|
737
|
+
}, [resetIsScrolling]);
|
|
738
|
+
/* Handle vertical scroll */
|
|
739
|
+
var handleScroll = (0, react_1.useCallback)(function (e) {
|
|
740
|
+
var scrollTop = e.currentTarget.scrollTop;
|
|
741
|
+
// Calculate what percentage of the scrollable area has been scrolled
|
|
742
|
+
// Apply scaling if needed
|
|
743
|
+
var scaledScrollTop = needsScaling
|
|
744
|
+
? (scrollTop /
|
|
745
|
+
(effectiveScrollbarYHeight - scrollbarYContainterHeight)) *
|
|
746
|
+
(scrollbarYHeight - scrollbarYContainterHeight)
|
|
747
|
+
: scrollTop;
|
|
748
|
+
setScrollState(function (prev) {
|
|
749
|
+
// Only setstate if required
|
|
750
|
+
if (prev.scrollTop === scaledScrollTop) {
|
|
751
|
+
return prev;
|
|
752
|
+
}
|
|
753
|
+
return tslib_1.__assign(tslib_1.__assign({}, prev), { isScrolling: true, verticalScrollDirection: prev.scrollTop > scaledScrollTop ? types_1.Direction.Up : types_1.Direction.Down, scrollTop: scaledScrollTop });
|
|
754
|
+
});
|
|
755
|
+
/* Scroll callbacks */
|
|
756
|
+
onImmediateScroll === null || onImmediateScroll === void 0 ? void 0 : onImmediateScroll({ scrollTop: scrollTop, scrollLeft: scrollLeft });
|
|
757
|
+
/* Reset isScrolling if required */
|
|
758
|
+
resetIsScrollingDebounced();
|
|
759
|
+
}, [
|
|
760
|
+
scrollLeft,
|
|
761
|
+
needsScaling,
|
|
762
|
+
effectiveScrollbarYHeight,
|
|
763
|
+
scrollbarYHeight,
|
|
764
|
+
scrollbarYContainterHeight,
|
|
765
|
+
onImmediateScroll,
|
|
766
|
+
resetIsScrollingDebounced,
|
|
767
|
+
]);
|
|
768
|
+
/* Handle horizontal scroll */
|
|
769
|
+
var handleScrollLeft = (0, react_1.useCallback)(function (e) {
|
|
770
|
+
var scrollLeft = e.currentTarget.scrollLeft;
|
|
771
|
+
setScrollState(function (prev) {
|
|
772
|
+
// Only setstate if required
|
|
773
|
+
if (prev.scrollLeft === scrollLeft) {
|
|
774
|
+
return prev;
|
|
775
|
+
}
|
|
776
|
+
return tslib_1.__assign(tslib_1.__assign({}, prev), { isScrolling: true, horizontalScrollDirection: prev.scrollLeft > scrollLeft ? types_1.Direction.Left : types_1.Direction.Right, scrollLeft: scrollLeft });
|
|
777
|
+
});
|
|
778
|
+
/* Scroll callbacks */
|
|
779
|
+
onImmediateScroll === null || onImmediateScroll === void 0 ? void 0 : onImmediateScroll({ scrollLeft: scrollLeft, scrollTop: scrollTop });
|
|
780
|
+
/* Reset isScrolling if required */
|
|
781
|
+
resetIsScrollingDebounced();
|
|
782
|
+
}, [scrollTop, onImmediateScroll, resetIsScrollingDebounced]);
|
|
783
|
+
/* Scroll based on left, top position */
|
|
784
|
+
var scrollTo = (0, react_1.useCallback)(function (_a,
|
|
785
|
+
// On touch devices, moving the scrollbars causes
|
|
786
|
+
// scroll flicker
|
|
787
|
+
// But when a sheet is changed, we need to immediately
|
|
788
|
+
// update the scroll state
|
|
789
|
+
// immediate is only set, when user switches to a new sheet
|
|
790
|
+
// Use with care
|
|
791
|
+
immediate) {
|
|
792
|
+
var _b, _c;
|
|
793
|
+
var scrollTop = _a.scrollTop, scrollLeft = _a.scrollLeft;
|
|
794
|
+
// Only update state in non-touch
|
|
795
|
+
// devices, otherwise it causes flickering
|
|
796
|
+
// because of scrollbar state updates
|
|
797
|
+
if (!isTouchDevice || immediate) {
|
|
798
|
+
setScrollState(function (prev) {
|
|
799
|
+
return tslib_1.__assign(tslib_1.__assign({}, prev), { scrollLeft: scrollLeft == void 0 ? prev.scrollLeft : scrollLeft, scrollTop: scrollTop == void 0 ? prev.scrollTop : scrollTop });
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
if (showScrollbar) {
|
|
803
|
+
/* If scrollbar is visible, lets update it which triggers a state change */
|
|
804
|
+
if (scrollLeft !== void 0) {
|
|
805
|
+
(_b = horizontalScrollRef.current) === null || _b === void 0 ? void 0 : _b.scrollTo({
|
|
806
|
+
left: scrollLeft,
|
|
807
|
+
behavior: "auto",
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
if (scrollTop !== void 0) {
|
|
811
|
+
// Apply scaling if needed
|
|
812
|
+
var scaledScrollTop = needsScaling
|
|
813
|
+
? (scrollTop / (scrollbarYHeight - scrollbarYContainterHeight)) *
|
|
814
|
+
(effectiveScrollbarYHeight - scrollbarYContainterHeight)
|
|
815
|
+
: scrollTop;
|
|
816
|
+
(_c = verticalScrollRef.current) === null || _c === void 0 ? void 0 : _c.scrollTo({
|
|
817
|
+
top: scaledScrollTop,
|
|
818
|
+
behavior: "auto",
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}, [
|
|
823
|
+
showScrollbar,
|
|
824
|
+
needsScaling,
|
|
825
|
+
effectiveScrollbarYHeight,
|
|
826
|
+
scrollbarYHeight,
|
|
827
|
+
scrollbarYContainterHeight,
|
|
828
|
+
isTouchDevice,
|
|
829
|
+
]);
|
|
830
|
+
/* Scroll grid to top */
|
|
831
|
+
var scrollToTop = (0, react_1.useCallback)(function () {
|
|
832
|
+
scrollTo({ scrollTop: 0, scrollLeft: 0 });
|
|
833
|
+
}, [scrollTo]);
|
|
834
|
+
/* Scroll grid to bottom */
|
|
835
|
+
var scrollToBottom = (0, react_1.useCallback)(function () {
|
|
836
|
+
scrollTo({
|
|
837
|
+
scrollTop: Math.floor(estimatedTotalHeight - containerHeight + footerHeight),
|
|
838
|
+
});
|
|
839
|
+
}, [estimatedTotalHeight, containerHeight, footerHeight, scrollTo]);
|
|
840
|
+
/**
|
|
841
|
+
* Scrollby utility
|
|
842
|
+
*/
|
|
843
|
+
var scrollBy = (0, react_1.useCallback)(function (_a) {
|
|
844
|
+
var x = _a.x, y = _a.y;
|
|
845
|
+
setScrollState(function (prev) {
|
|
846
|
+
return tslib_1.__assign(tslib_1.__assign({}, prev), { scrollLeft: x == void 0 ? prev.scrollLeft : prev.scrollLeft + x, scrollTop: y == void 0 ? prev.scrollTop : prev.scrollTop + y });
|
|
847
|
+
});
|
|
848
|
+
if (showScrollbar) {
|
|
849
|
+
if (horizontalScrollRef.current && x !== void 0)
|
|
850
|
+
horizontalScrollRef.current.scrollBy({ left: x, behavior: "auto" });
|
|
851
|
+
if (verticalScrollRef.current && y !== void 0)
|
|
852
|
+
verticalScrollRef.current.scrollBy({ top: y, behavior: "auto" });
|
|
853
|
+
}
|
|
854
|
+
}, [showScrollbar]);
|
|
855
|
+
/**
|
|
856
|
+
* Scrolls to cell
|
|
857
|
+
* Respects frozen rows and columns
|
|
858
|
+
*/
|
|
859
|
+
var scrollToCell = (0, react_1.useCallback)(function (_a, align) {
|
|
860
|
+
var rowIndex = _a.rowIndex, columnIndex = _a.columnIndex;
|
|
861
|
+
if (align === void 0) { align = helpers_3.Align.auto; }
|
|
862
|
+
var isFrozenRow = rowIndex !== void 0 && rowIndex < frozenRows;
|
|
863
|
+
var isFrozenColumn = columnIndex !== void 0 && columnIndex < frozenColumns;
|
|
864
|
+
var frozenColumnOffset = getColumnOffset(frozenColumns);
|
|
865
|
+
/* Making sure getColumnWidth works */
|
|
866
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
867
|
+
var x = columnIndex !== void 0 ? getColumnOffset(columnIndex) : void 0;
|
|
868
|
+
/* Making sure getRowHeight works */
|
|
869
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
870
|
+
var y = rowIndex !== void 0 ? getRowOffset(rowIndex) : void 0;
|
|
871
|
+
var width = columnIndex !== void 0 ? getColumnWidth(columnIndex) : 0;
|
|
872
|
+
var height = rowIndex !== void 0 ? getRowHeight(rowIndex) : 0;
|
|
873
|
+
var columnAlign = width > containerWidth ? helpers_3.Align.start : align;
|
|
874
|
+
var rowAlign = height > containerHeight ? helpers_3.Align.start : align;
|
|
875
|
+
var newScrollLeft = columnIndex !== void 0 && !isFrozenColumn
|
|
876
|
+
? Math.floor((0, helpers_3.getOffsetForColumnAndAlignment)({
|
|
877
|
+
index: columnIndex,
|
|
878
|
+
containerHeight: containerHeight,
|
|
879
|
+
containerWidth: containerWidth,
|
|
880
|
+
columnCount: columnCount,
|
|
881
|
+
columnWidth: columnWidth,
|
|
882
|
+
rowCount: rowCount,
|
|
883
|
+
rowHeight: rowHeight,
|
|
884
|
+
scrollOffset: scrollLeft,
|
|
885
|
+
instanceProps: instanceProps.current,
|
|
886
|
+
scrollbarSize: scrollbarSize +
|
|
887
|
+
(columnIndex === columnCount - 1 ? 0 : scrollToCellOffset),
|
|
888
|
+
frozenOffset: frozenColumnOffset,
|
|
889
|
+
align: columnAlign,
|
|
890
|
+
scale: scale,
|
|
891
|
+
estimatedTotalWidth: estimatedTotalWidth,
|
|
892
|
+
estimatedTotalHeight: estimatedTotalHeight,
|
|
893
|
+
}))
|
|
894
|
+
: void 0;
|
|
895
|
+
var frozenRowOffset = getRowOffset(frozenRows);
|
|
896
|
+
var newScrollTop = rowIndex !== void 0 && !isFrozenRow
|
|
897
|
+
? Math.floor((0, helpers_3.getOffsetForRowAndAlignment)({
|
|
898
|
+
index: rowIndex,
|
|
899
|
+
containerHeight: containerHeight,
|
|
900
|
+
containerWidth: containerWidth,
|
|
901
|
+
columnCount: columnCount,
|
|
902
|
+
columnWidth: columnWidth,
|
|
903
|
+
rowCount: rowCount,
|
|
904
|
+
rowHeight: rowHeight,
|
|
905
|
+
scrollOffset: scrollTop,
|
|
906
|
+
instanceProps: instanceProps.current,
|
|
907
|
+
scrollbarSize: scrollbarSize +
|
|
908
|
+
(rowIndex === rowCount - 1 ? 0 : scrollToCellOffset),
|
|
909
|
+
frozenOffset: frozenRowOffset,
|
|
910
|
+
align: rowAlign,
|
|
911
|
+
scale: scale,
|
|
912
|
+
estimatedTotalWidth: estimatedTotalWidth,
|
|
913
|
+
estimatedTotalHeight: estimatedTotalHeight + footerHeight,
|
|
914
|
+
}))
|
|
915
|
+
: void 0;
|
|
916
|
+
// We already reached bottom of the last cell
|
|
917
|
+
// If scrolling to last row and already at bottom, reveal the footer
|
|
918
|
+
// if (
|
|
919
|
+
// scrollTop > 0 &&
|
|
920
|
+
// newScrollTop !== void 0 &&
|
|
921
|
+
// newScrollTop === scrollTop &&
|
|
922
|
+
// rowIndex === rowCount - 1 &&
|
|
923
|
+
// footerHeight > 0
|
|
924
|
+
// ) {
|
|
925
|
+
// const maxContentScroll = estimatedTotalHeight - containerHeight;
|
|
926
|
+
// const maxScrollWithFooter = maxContentScroll + footerHeight;
|
|
927
|
+
// // Only reveal footer if we haven't scrolled past the content yet
|
|
928
|
+
// if (scrollTop < maxScrollWithFooter) {
|
|
929
|
+
// newScrollTop = scrollTop + footerHeight;
|
|
930
|
+
// }
|
|
931
|
+
// }
|
|
932
|
+
var isOutsideViewport = (rowIndex !== void 0 &&
|
|
933
|
+
rowIndex > rowStopIndex + (rowStopIndex - rowStartIndex)) ||
|
|
934
|
+
(columnIndex !== void 0 &&
|
|
935
|
+
columnIndex >
|
|
936
|
+
columnStopIndex + (columnStopIndex - columnStartIndex));
|
|
937
|
+
if (isOutsideViewport) {
|
|
938
|
+
requestAnimationFrame(function () {
|
|
939
|
+
scrollTo({
|
|
940
|
+
scrollLeft: newScrollLeft,
|
|
941
|
+
scrollTop: newScrollTop,
|
|
942
|
+
});
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
else {
|
|
946
|
+
scrollTo({
|
|
947
|
+
scrollLeft: newScrollLeft,
|
|
948
|
+
scrollTop: newScrollTop,
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
// After scroll to cell callback
|
|
952
|
+
onAfterScrollToCell === null || onAfterScrollToCell === void 0 ? void 0 : onAfterScrollToCell(newScrollLeft, newScrollTop);
|
|
953
|
+
}, [
|
|
954
|
+
containerHeight,
|
|
955
|
+
columnStartIndex,
|
|
956
|
+
columnStopIndex,
|
|
957
|
+
rowStartIndex,
|
|
958
|
+
rowStopIndex,
|
|
959
|
+
containerWidth,
|
|
960
|
+
estimatedTotalWidth,
|
|
961
|
+
estimatedTotalHeight,
|
|
962
|
+
rowCount,
|
|
963
|
+
columnCount,
|
|
964
|
+
scrollbarSize,
|
|
965
|
+
scrollToCellOffset,
|
|
966
|
+
scrollLeft,
|
|
967
|
+
scrollTop,
|
|
968
|
+
frozenRows,
|
|
969
|
+
frozenColumns,
|
|
970
|
+
columnWidth,
|
|
971
|
+
getColumnOffset,
|
|
972
|
+
getColumnWidth,
|
|
973
|
+
getRowHeight,
|
|
974
|
+
getRowOffset,
|
|
975
|
+
rowHeight,
|
|
976
|
+
scale,
|
|
977
|
+
scrollTo,
|
|
978
|
+
onAfterScrollToCell,
|
|
979
|
+
footerHeight,
|
|
980
|
+
]);
|
|
981
|
+
/**
|
|
982
|
+
* React to changes in rowCount or columnCount
|
|
983
|
+
*/
|
|
984
|
+
if (visibleRowStopIndex > rowCount ||
|
|
985
|
+
visibleColumnStopIndex > columnCount) {
|
|
986
|
+
scrollToTop();
|
|
987
|
+
}
|
|
988
|
+
// Check if we have reached end of vertical scroll
|
|
989
|
+
isEndOfVerticalScrollRef.current =
|
|
990
|
+
estimatedTotalHeight ===
|
|
991
|
+
scrollState.scrollTop + containerHeight - scrollbarSize;
|
|
992
|
+
isStartOffVerticalScrollRef.current = scrollState.scrollTop === 0;
|
|
993
|
+
/**
|
|
994
|
+
* Fired when user tries to scroll the canvas
|
|
995
|
+
*/
|
|
996
|
+
var handleWheel = (0, react_1.useCallback)(function (event) {
|
|
997
|
+
var _a, _b;
|
|
998
|
+
/* If user presses shift key, scroll horizontally */
|
|
999
|
+
var isCtrlKey = event.ctrlKey;
|
|
1000
|
+
var isMetaKey = event.metaKey;
|
|
1001
|
+
// Ctrl and meta key are used for zooming
|
|
1002
|
+
if (isCtrlKey || isMetaKey) {
|
|
1003
|
+
// Disable wheel event on ctrl key
|
|
1004
|
+
event.preventDefault();
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
var isScrollingHorizontally = event.shiftKey;
|
|
1008
|
+
var deltaX = event.deltaX, deltaY = event.deltaY, deltaMode = event.deltaMode;
|
|
1009
|
+
var isVerticalEndOfScroll = !isScrollingHorizontally &&
|
|
1010
|
+
((isEndOfVerticalScrollRef.current && deltaY > 0) ||
|
|
1011
|
+
(isStartOffVerticalScrollRef.current && deltaY < 0));
|
|
1012
|
+
var isUserSwipingLeft = Math.abs(deltaX) > 0;
|
|
1013
|
+
var shouldPreventDefault = preventBrowserDefaultScroll
|
|
1014
|
+
? true
|
|
1015
|
+
: !isVerticalEndOfScroll || isUserSwipingLeft;
|
|
1016
|
+
// There is a bug currently which enables swipe to back and forward
|
|
1017
|
+
// when isStartOffVerticalScrollRef and isEndOfVerticalScrollRef is true
|
|
1018
|
+
// Need more user research to understand what is the expectation here
|
|
1019
|
+
// Should swipe back and forward be disabled completely in the grid?
|
|
1020
|
+
// Or should it be enabled if user is at the top/bottom/left/right
|
|
1021
|
+
// i.e. end of the grid ?
|
|
1022
|
+
// deltaX === 0
|
|
1023
|
+
/* Prevent browser back in Mac */
|
|
1024
|
+
// Mac, swipe to back or forward will not work with
|
|
1025
|
+
// this grid. But that can be achieved by checking
|
|
1026
|
+
// StartOfHorizontalScroll and EndOfHorizontalScroll
|
|
1027
|
+
// Todo: when users requests this
|
|
1028
|
+
if (shouldPreventDefault) {
|
|
1029
|
+
event.preventDefault();
|
|
1030
|
+
}
|
|
1031
|
+
/* Scroll natively */
|
|
1032
|
+
if (wheelingRef.current) {
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
var dx = isScrollingHorizontally
|
|
1036
|
+
? deltaY === 0
|
|
1037
|
+
? deltaX
|
|
1038
|
+
: deltaY
|
|
1039
|
+
: deltaX;
|
|
1040
|
+
var dy = deltaY;
|
|
1041
|
+
/* If snaps are active */
|
|
1042
|
+
if (snap) {
|
|
1043
|
+
/* Scroll only in one direction */
|
|
1044
|
+
var isHorizontal = isScrollingHorizontally || Math.abs(dx) > Math.abs(dy);
|
|
1045
|
+
if (isHorizontal) {
|
|
1046
|
+
(_a = snapToColumnThrottler.current) === null || _a === void 0 ? void 0 : _a.call(snapToColumnThrottler, {
|
|
1047
|
+
deltaX: deltaX,
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
else {
|
|
1051
|
+
(_b = snapToRowThrottler.current) === null || _b === void 0 ? void 0 : _b.call(snapToRowThrottler, {
|
|
1052
|
+
deltaY: deltaY,
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
if (deltaMode === event.DOM_DELTA_LINE) {
|
|
1058
|
+
if (isScrollingHorizontally) {
|
|
1059
|
+
dx *= DEFAULT_COLUMN_WIDTH;
|
|
1060
|
+
}
|
|
1061
|
+
else {
|
|
1062
|
+
dy *= DEFAULT_ROW_HEIGHT;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
if (!horizontalScrollRef.current && !verticalScrollRef.current) {
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
wheelingRef.current = window.requestAnimationFrame(function () {
|
|
1069
|
+
var _a, _b, _c;
|
|
1070
|
+
wheelingRef.current = null;
|
|
1071
|
+
if (isScrollingHorizontally) {
|
|
1072
|
+
(_a = horizontalScrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollBy({
|
|
1073
|
+
left: dx,
|
|
1074
|
+
behavior: "auto",
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
else {
|
|
1078
|
+
(_b = horizontalScrollRef.current) === null || _b === void 0 ? void 0 : _b.scrollBy({
|
|
1079
|
+
left: dx,
|
|
1080
|
+
behavior: "auto",
|
|
1081
|
+
});
|
|
1082
|
+
(_c = verticalScrollRef.current) === null || _c === void 0 ? void 0 : _c.scrollBy({
|
|
1083
|
+
top: dy,
|
|
1084
|
+
behavior: "auto",
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
}, [snap, preventBrowserDefaultScroll]);
|
|
1089
|
+
/**
|
|
1090
|
+
* Handle mouse wheeel
|
|
1091
|
+
*/
|
|
1092
|
+
(0, react_1.useEffect)(function () {
|
|
1093
|
+
var scrollContainer = scrollContainerRef.current;
|
|
1094
|
+
scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.addEventListener("wheel", handleWheel, {
|
|
1095
|
+
passive: false,
|
|
1096
|
+
});
|
|
1097
|
+
isMounted.current = true;
|
|
1098
|
+
return function () {
|
|
1099
|
+
scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.removeEventListener("wheel", handleWheel);
|
|
1100
|
+
};
|
|
1101
|
+
}, [handleWheel]);
|
|
1102
|
+
/* Callback when visible rows or columns have changed */
|
|
1103
|
+
(0, react_1.useEffect)(function () {
|
|
1104
|
+
onViewPortChange === null || onViewPortChange === void 0 ? void 0 : onViewPortChange({
|
|
1105
|
+
rowStartIndex: rowStartIndex,
|
|
1106
|
+
rowStopIndex: rowStopIndex,
|
|
1107
|
+
columnStartIndex: columnStartIndex,
|
|
1108
|
+
columnStopIndex: columnStopIndex,
|
|
1109
|
+
visibleRowStartIndex: visibleRowStartIndex,
|
|
1110
|
+
visibleRowStopIndex: visibleRowStopIndex,
|
|
1111
|
+
visibleColumnStartIndex: visibleColumnStartIndex,
|
|
1112
|
+
visibleColumnStopIndex: visibleColumnStopIndex,
|
|
1113
|
+
});
|
|
1114
|
+
}, [
|
|
1115
|
+
onViewPortChange,
|
|
1116
|
+
rowStartIndex,
|
|
1117
|
+
rowStopIndex,
|
|
1118
|
+
columnStartIndex,
|
|
1119
|
+
columnStopIndex,
|
|
1120
|
+
visibleRowStartIndex,
|
|
1121
|
+
visibleRowStopIndex,
|
|
1122
|
+
visibleColumnStartIndex,
|
|
1123
|
+
visibleColumnStopIndex,
|
|
1124
|
+
]);
|
|
1125
|
+
// Callback when grid dimensions change
|
|
1126
|
+
(0, react_1.useEffect)(function () {
|
|
1127
|
+
if (!isScrolling) {
|
|
1128
|
+
onDimensionsChange === null || onDimensionsChange === void 0 ? void 0 : onDimensionsChange({
|
|
1129
|
+
containerWidth: containerWidth - frozenColumnWidth,
|
|
1130
|
+
containerHeight: containerHeight - frozenRowHeight,
|
|
1131
|
+
estimatedTotalWidth: estimatedTotalWidth -
|
|
1132
|
+
frozenColumnWidth +
|
|
1133
|
+
(extendScrollSize ? scrollbarSize : 0),
|
|
1134
|
+
estimatedTotalHeight: estimatedTotalHeight -
|
|
1135
|
+
frozenRowHeight +
|
|
1136
|
+
(extendScrollSize ? scrollbarSize : 0),
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
}, [
|
|
1140
|
+
containerWidth,
|
|
1141
|
+
containerHeight,
|
|
1142
|
+
estimatedTotalWidth,
|
|
1143
|
+
estimatedTotalHeight,
|
|
1144
|
+
isScrolling,
|
|
1145
|
+
frozenRowHeight,
|
|
1146
|
+
frozenColumnWidth,
|
|
1147
|
+
extendScrollSize,
|
|
1148
|
+
scrollbarSize,
|
|
1149
|
+
onDimensionsChange,
|
|
1150
|
+
]);
|
|
1151
|
+
/* Draw gridlines */
|
|
1152
|
+
var _26 = tslib_1.__read((0, react_1.useMemo)(function () {
|
|
1153
|
+
var e_3, _a;
|
|
1154
|
+
var gridLines = [];
|
|
1155
|
+
var gridLinesFrozenRow = [];
|
|
1156
|
+
var gridLinesFrozenColumn = [];
|
|
1157
|
+
var gridLinesFrozenIntersection = [];
|
|
1158
|
+
if (showGridLines) {
|
|
1159
|
+
// Horizontal - use getVisibleRowIndices for efficient iteration
|
|
1160
|
+
var visibleRows = getVisibleRowIndices(rowStartIndex, rowStopIndex);
|
|
1161
|
+
try {
|
|
1162
|
+
for (var visibleRows_1 = tslib_1.__values(visibleRows), visibleRows_1_1 = visibleRows_1.next(); !visibleRows_1_1.done; visibleRows_1_1 = visibleRows_1.next()) {
|
|
1163
|
+
var rowIndex = visibleRows_1_1.value;
|
|
1164
|
+
var x1 = getColumnOffset(frozenColumns);
|
|
1165
|
+
var x2 = getColumnOffset(Math.min(columnStopIndex + 1, columnCount));
|
|
1166
|
+
var y1 = getRowOffset(Math.min(rowIndex + 1, rowCount));
|
|
1167
|
+
var y2 = y1;
|
|
1168
|
+
gridLines.push(gridLineRenderer({
|
|
1169
|
+
points: [x1, y1, x2, y2],
|
|
1170
|
+
stroke: gridLineColor,
|
|
1171
|
+
strokeWidth: gridLineWidth,
|
|
1172
|
+
offsetY: -0.5,
|
|
1173
|
+
key: (0, helpers_3.itemKey)({ rowIndex: rowIndex, columnIndex: y1 }),
|
|
1174
|
+
}));
|
|
1175
|
+
if (frozenColumns > 1) {
|
|
1176
|
+
gridLinesFrozenColumn.push(gridLineRenderer({
|
|
1177
|
+
points: [0, y1, x2, y2],
|
|
1178
|
+
stroke: gridLineColor,
|
|
1179
|
+
strokeWidth: gridLineWidth,
|
|
1180
|
+
offsetY: -0.5,
|
|
1181
|
+
key: (0, helpers_3.itemKey)({ rowIndex: rowIndex, columnIndex: y1 }),
|
|
1182
|
+
}));
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1187
|
+
finally {
|
|
1188
|
+
try {
|
|
1189
|
+
if (visibleRows_1_1 && !visibleRows_1_1.done && (_a = visibleRows_1.return)) _a.call(visibleRows_1);
|
|
1190
|
+
}
|
|
1191
|
+
finally { if (e_3) throw e_3.error; }
|
|
1192
|
+
}
|
|
1193
|
+
// Vertical
|
|
1194
|
+
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
|
|
1195
|
+
/* Ignore frozen rows */
|
|
1196
|
+
if (columnIndex < frozenColumns || (isHiddenColumn === null || isHiddenColumn === void 0 ? void 0 : isHiddenColumn(columnIndex)))
|
|
1197
|
+
continue;
|
|
1198
|
+
var x1 = getColumnOffset(Math.min(columnIndex + 1, columnCount));
|
|
1199
|
+
var x2 = x1;
|
|
1200
|
+
var y1 = getRowOffset(frozenRows);
|
|
1201
|
+
var y2 = getRowOffset(Math.min(rowStopIndex + 1, rowCount));
|
|
1202
|
+
gridLines.push(gridLineRenderer({
|
|
1203
|
+
points: [x1, y1, x2, y2],
|
|
1204
|
+
stroke: gridLineColor,
|
|
1205
|
+
strokeWidth: gridLineWidth,
|
|
1206
|
+
offsetX: -0.5,
|
|
1207
|
+
key: (0, helpers_3.itemKey)({ rowIndex: x1, columnIndex: columnIndex }),
|
|
1208
|
+
}));
|
|
1209
|
+
if (frozenRows > 1) {
|
|
1210
|
+
gridLinesFrozenRow.push(gridLineRenderer({
|
|
1211
|
+
points: [x1, 0, x2, y2],
|
|
1212
|
+
stroke: gridLineColor,
|
|
1213
|
+
strokeWidth: gridLineWidth,
|
|
1214
|
+
offsetX: -0.5,
|
|
1215
|
+
key: (0, helpers_3.itemKey)({ rowIndex: x1, columnIndex: columnIndex }),
|
|
1216
|
+
}));
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
for (var rowIndex = 0; rowIndex < Math.min(rowStopIndex, frozenRows); rowIndex++) {
|
|
1220
|
+
if (isHiddenRow === null || isHiddenRow === void 0 ? void 0 : isHiddenRow(rowIndex)) {
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
var x1 = getColumnOffset(1);
|
|
1224
|
+
var x2 = getColumnOffset(Math.min(columnStopIndex + 1, columnCount));
|
|
1225
|
+
var y1 = getRowOffset(Math.min(rowIndex + 1, rowCount));
|
|
1226
|
+
var y2 = y1;
|
|
1227
|
+
gridLinesFrozenRow.push(gridLineRenderer({
|
|
1228
|
+
points: [x1, y1, x2, y2],
|
|
1229
|
+
stroke: gridLineColor,
|
|
1230
|
+
strokeWidth: gridLineWidth,
|
|
1231
|
+
offsetY: -0.5,
|
|
1232
|
+
key: (0, helpers_3.itemKey)({ rowIndex: rowIndex, columnIndex: y1 }),
|
|
1233
|
+
}));
|
|
1234
|
+
gridLinesFrozenIntersection.push(gridLineRenderer({
|
|
1235
|
+
points: [x1, y1, x2, y2],
|
|
1236
|
+
stroke: gridLineColor,
|
|
1237
|
+
strokeWidth: gridLineWidth,
|
|
1238
|
+
offsetY: -0.5,
|
|
1239
|
+
key: (0, helpers_3.itemKey)({ rowIndex: rowIndex, columnIndex: y1 }),
|
|
1240
|
+
}));
|
|
1241
|
+
}
|
|
1242
|
+
for (var columnIndex = 0; columnIndex < Math.min(columnStopIndex, frozenColumns); columnIndex++) {
|
|
1243
|
+
if (isHiddenColumn === null || isHiddenColumn === void 0 ? void 0 : isHiddenColumn(columnIndex))
|
|
1244
|
+
continue;
|
|
1245
|
+
var x1 = getColumnOffset(Math.min(columnIndex + 1, columnCount));
|
|
1246
|
+
var x2 = x1;
|
|
1247
|
+
var y1 = getRowOffset(1);
|
|
1248
|
+
var y2 = getRowOffset(Math.min(rowStopIndex + 1, rowCount));
|
|
1249
|
+
gridLinesFrozenColumn.push(gridLineRenderer({
|
|
1250
|
+
points: [x1, y1, x2, y2],
|
|
1251
|
+
stroke: gridLineColor,
|
|
1252
|
+
strokeWidth: gridLineWidth,
|
|
1253
|
+
offsetX: -0.5,
|
|
1254
|
+
key: (0, helpers_3.itemKey)({ rowIndex: x1, columnIndex: columnIndex }),
|
|
1255
|
+
}));
|
|
1256
|
+
gridLinesFrozenIntersection.push(gridLineRenderer({
|
|
1257
|
+
points: [x1, y1, x2, y2],
|
|
1258
|
+
stroke: gridLineColor,
|
|
1259
|
+
strokeWidth: gridLineWidth,
|
|
1260
|
+
offsetX: -0.5,
|
|
1261
|
+
key: (0, helpers_3.itemKey)({ rowIndex: x1, columnIndex: columnIndex }),
|
|
1262
|
+
}));
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
return [
|
|
1266
|
+
gridLines,
|
|
1267
|
+
gridLinesFrozenRow,
|
|
1268
|
+
gridLinesFrozenColumn,
|
|
1269
|
+
gridLinesFrozenIntersection,
|
|
1270
|
+
];
|
|
1271
|
+
}, [
|
|
1272
|
+
rowStartIndex,
|
|
1273
|
+
rowStopIndex,
|
|
1274
|
+
columnStartIndex,
|
|
1275
|
+
columnStopIndex,
|
|
1276
|
+
getRowOffset,
|
|
1277
|
+
getColumnOffset,
|
|
1278
|
+
gridLineColor,
|
|
1279
|
+
gridLineWidth,
|
|
1280
|
+
rowCount,
|
|
1281
|
+
columnCount,
|
|
1282
|
+
frozenRows,
|
|
1283
|
+
frozenColumns,
|
|
1284
|
+
showGridLines,
|
|
1285
|
+
getVisibleRowIndices,
|
|
1286
|
+
isHiddenRow,
|
|
1287
|
+
isHiddenColumn,
|
|
1288
|
+
gridLineRenderer,
|
|
1289
|
+
]), 4), gridLines = _26[0], gridLinesFrozenRow = _26[1], gridLinesFrozenColumn = _26[2], gridLinesFrozenIntersection = _26[3];
|
|
1290
|
+
// A data update arrives as a NEW renderer identity (hosts recreate their getters per data
|
|
1291
|
+
// version — e.g. a windowed engine loading cells asynchronously mid-scroll). The scroll cell
|
|
1292
|
+
// cache keys only on cell id, so an entry computed against the OLD data keeps painting beside
|
|
1293
|
+
// freshly rendered neighbours until the scroll-end clear — e.g. a long string that overflowed
|
|
1294
|
+
// into a then-blank neighbour drawn OVER the neighbour's just-loaded text. Invalidate the
|
|
1295
|
+
// cache the moment any renderer changes; a `useMemo` so it runs during render, BEFORE both
|
|
1296
|
+
// cell useMemos below consume the cache. (Clearing on mount is a harmless no-op.)
|
|
1297
|
+
(0, react_1.useMemo)(clearCache, [
|
|
1298
|
+
clearCache,
|
|
1299
|
+
itemRenderer,
|
|
1300
|
+
overlayRenderer,
|
|
1301
|
+
backgroundRenderer,
|
|
1302
|
+
]);
|
|
1303
|
+
var mergedCellRenderMap = new Set();
|
|
1304
|
+
var mergedCellFrozenRowMap = new Set();
|
|
1305
|
+
// Get frozen column overflow cells - computed AFTER frozen cells useMemo
|
|
1306
|
+
// so it has data from current render (itemRenderer just populated overflowMapRef)
|
|
1307
|
+
var frozenColumnOverflowCells = getFrozenColumnOverflowCells === null || getFrozenColumnOverflowCells === void 0 ? void 0 : getFrozenColumnOverflowCells(frozenColumnWidth, frozenColumns);
|
|
1308
|
+
// Frozen cells useMemo runs FIRST so itemRenderer populates overflowMapRef
|
|
1309
|
+
var _27 = tslib_1.__read((0, react_1.useMemo)(function () {
|
|
1310
|
+
var e_4, _a;
|
|
1311
|
+
/* Draw frozen rows */
|
|
1312
|
+
var frozenRowCells = [];
|
|
1313
|
+
var frozenRowCellOverlays = [];
|
|
1314
|
+
var frozenRowCellBackgrounds = [];
|
|
1315
|
+
for (var rowIndex = 1; rowIndex < Math.min(rowStopIndex, frozenRows); rowIndex++) {
|
|
1316
|
+
if (isHiddenRow === null || isHiddenRow === void 0 ? void 0 : isHiddenRow(rowIndex))
|
|
1317
|
+
continue;
|
|
1318
|
+
/**
|
|
1319
|
+
* Do any pre-processing of the row before being renderered.
|
|
1320
|
+
* Useful for `react-table` to call `prepareRow(row)`
|
|
1321
|
+
*/
|
|
1322
|
+
onBeforeRenderRow === null || onBeforeRenderRow === void 0 ? void 0 : onBeforeRenderRow(rowIndex);
|
|
1323
|
+
var _loop_1 = function (columnIndex) {
|
|
1324
|
+
/* Skip merged cells columns */
|
|
1325
|
+
if (columnIndex < frozenColumns &&
|
|
1326
|
+
!(frozenColumnOverflowCells === null || frozenColumnOverflowCells === void 0 ? void 0 : frozenColumnOverflowCells.has((0, helpers_3.cellIdentifier)(rowIndex, columnIndex)))) {
|
|
1327
|
+
return "continue";
|
|
1328
|
+
}
|
|
1329
|
+
var isMerged = isMergedCell({ rowIndex: rowIndex, columnIndex: columnIndex });
|
|
1330
|
+
var bounds = getCellBounds({ rowIndex: rowIndex, columnIndex: columnIndex });
|
|
1331
|
+
var actualRowIndex = isMerged ? bounds.startRowIndex : rowIndex;
|
|
1332
|
+
var actualColumnIndex = isMerged
|
|
1333
|
+
? bounds.startColumnIndex
|
|
1334
|
+
: columnIndex;
|
|
1335
|
+
var actualBottom = Math.max(rowIndex, bounds.endRowIndex);
|
|
1336
|
+
var actualRight = Math.max(columnIndex, bounds.endColumnIndex);
|
|
1337
|
+
if (isHiddenColumn === null || isHiddenColumn === void 0 ? void 0 : isHiddenColumn(actualColumnIndex)) {
|
|
1338
|
+
return "continue";
|
|
1339
|
+
}
|
|
1340
|
+
if (!isMerged && (isHiddenCell === null || isHiddenCell === void 0 ? void 0 : isHiddenCell(actualRowIndex, actualColumnIndex))) {
|
|
1341
|
+
return "continue";
|
|
1342
|
+
}
|
|
1343
|
+
if (isMerged) {
|
|
1344
|
+
var cellId_1 = (0, helpers_3.cellIdentifier)(bounds.startRowIndex, bounds.startColumnIndex);
|
|
1345
|
+
if (mergedCellFrozenRowMap.has(cellId_1)) {
|
|
1346
|
+
return "continue";
|
|
1347
|
+
}
|
|
1348
|
+
mergedCellFrozenRowMap.add(cellId_1);
|
|
1349
|
+
}
|
|
1350
|
+
var y = getRowOffset(actualRowIndex);
|
|
1351
|
+
var height = getRowOffset(actualBottom) - y + getRowHeight(actualBottom);
|
|
1352
|
+
var x = getColumnOffset(actualColumnIndex);
|
|
1353
|
+
var width = getColumnOffset(actualRight) - x + getColumnWidth(actualRight);
|
|
1354
|
+
var cellId = (0, helpers_3.cellIdentifier)(actualRowIndex, actualColumnIndex);
|
|
1355
|
+
var frozenRowCell = getCellCache(cellCacheRef.current, cellId, function () {
|
|
1356
|
+
return itemRenderer({
|
|
1357
|
+
x: x,
|
|
1358
|
+
y: y,
|
|
1359
|
+
width: width,
|
|
1360
|
+
height: height,
|
|
1361
|
+
rowIndex: actualRowIndex,
|
|
1362
|
+
columnIndex: actualColumnIndex,
|
|
1363
|
+
isMergedCell: isMerged,
|
|
1364
|
+
key: (0, helpers_3.itemKey)({
|
|
1365
|
+
rowIndex: actualRowIndex,
|
|
1366
|
+
columnIndex: actualColumnIndex,
|
|
1367
|
+
}),
|
|
1368
|
+
});
|
|
1369
|
+
}, isScrolling, isMerged);
|
|
1370
|
+
frozenRowCells.push(frozenRowCell);
|
|
1371
|
+
if (enableCellOverlay &&
|
|
1372
|
+
!(isHiddenOverlay === null || isHiddenOverlay === void 0 ? void 0 : isHiddenOverlay(actualRowIndex, actualColumnIndex))) {
|
|
1373
|
+
var frozenRowCellOverlay = getCellCache(cellOverlayCacheRef.current, cellId, function () {
|
|
1374
|
+
return overlayRenderer({
|
|
1375
|
+
x: x,
|
|
1376
|
+
y: y,
|
|
1377
|
+
width: width,
|
|
1378
|
+
height: height,
|
|
1379
|
+
rowIndex: actualRowIndex,
|
|
1380
|
+
columnIndex: actualColumnIndex,
|
|
1381
|
+
isMergedCell: isMerged,
|
|
1382
|
+
key: (0, helpers_3.itemKey)({
|
|
1383
|
+
rowIndex: actualRowIndex,
|
|
1384
|
+
columnIndex: actualColumnIndex,
|
|
1385
|
+
}),
|
|
1386
|
+
});
|
|
1387
|
+
}, isScrolling);
|
|
1388
|
+
frozenRowCellOverlays.push(frozenRowCellOverlay);
|
|
1389
|
+
}
|
|
1390
|
+
if (enableCellBackground &&
|
|
1391
|
+
!(isHiddenBackground === null || isHiddenBackground === void 0 ? void 0 : isHiddenBackground(actualRowIndex, actualColumnIndex))) {
|
|
1392
|
+
var frozenRowCellBackground = getCellCache(cellBackgroundCacheRef.current, cellId, function () {
|
|
1393
|
+
return backgroundRenderer === null || backgroundRenderer === void 0 ? void 0 : backgroundRenderer({
|
|
1394
|
+
x: x,
|
|
1395
|
+
y: y,
|
|
1396
|
+
width: width,
|
|
1397
|
+
height: height,
|
|
1398
|
+
rowIndex: actualRowIndex,
|
|
1399
|
+
columnIndex: actualColumnIndex,
|
|
1400
|
+
isMergedCell: isMerged,
|
|
1401
|
+
key: (0, helpers_3.itemKey)({
|
|
1402
|
+
rowIndex: actualRowIndex,
|
|
1403
|
+
columnIndex: actualColumnIndex,
|
|
1404
|
+
}),
|
|
1405
|
+
});
|
|
1406
|
+
}, isScrolling);
|
|
1407
|
+
frozenRowCellBackgrounds.push(frozenRowCellBackground);
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
|
|
1411
|
+
_loop_1(columnIndex);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
/* Draw frozen columns */
|
|
1415
|
+
var mergedCellFrozenColumnMap = new Set();
|
|
1416
|
+
var frozenColumnCells = [];
|
|
1417
|
+
var frozenColumnCellOverlays = [];
|
|
1418
|
+
var frozenColumnCellBackgrounds = [];
|
|
1419
|
+
// Use getVisibleRowIndices for efficient iteration over visible rows
|
|
1420
|
+
var visibleRowsForFrozenCols = getVisibleRowIndices(rowStartIndex, rowStopIndex);
|
|
1421
|
+
try {
|
|
1422
|
+
for (var visibleRowsForFrozenCols_1 = tslib_1.__values(visibleRowsForFrozenCols), visibleRowsForFrozenCols_1_1 = visibleRowsForFrozenCols_1.next(); !visibleRowsForFrozenCols_1_1.done; visibleRowsForFrozenCols_1_1 = visibleRowsForFrozenCols_1.next()) {
|
|
1423
|
+
var rowIndex = visibleRowsForFrozenCols_1_1.value;
|
|
1424
|
+
var _loop_2 = function (columnIndex) {
|
|
1425
|
+
var isMerged = isMergedCell({ rowIndex: rowIndex, columnIndex: columnIndex });
|
|
1426
|
+
var bounds = getCellBounds({ rowIndex: rowIndex, columnIndex: columnIndex });
|
|
1427
|
+
var actualRowIndex = isMerged ? bounds.startRowIndex : rowIndex;
|
|
1428
|
+
var actualColumnIndex = isMerged
|
|
1429
|
+
? bounds.startColumnIndex
|
|
1430
|
+
: columnIndex;
|
|
1431
|
+
var actualBottom = Math.max(rowIndex, bounds.endRowIndex);
|
|
1432
|
+
var actualRight = Math.max(columnIndex, bounds.endColumnIndex);
|
|
1433
|
+
if (isHiddenColumn === null || isHiddenColumn === void 0 ? void 0 : isHiddenColumn(actualColumnIndex)) {
|
|
1434
|
+
return "continue";
|
|
1435
|
+
}
|
|
1436
|
+
if (!isMerged && (isHiddenCell === null || isHiddenCell === void 0 ? void 0 : isHiddenCell(actualRowIndex, actualColumnIndex))) {
|
|
1437
|
+
return "continue";
|
|
1438
|
+
}
|
|
1439
|
+
if (isMerged) {
|
|
1440
|
+
var cellId_2 = (0, helpers_3.cellIdentifier)(bounds.startRowIndex, bounds.startColumnIndex);
|
|
1441
|
+
if (mergedCellFrozenColumnMap.has(cellId_2)) {
|
|
1442
|
+
return "continue";
|
|
1443
|
+
}
|
|
1444
|
+
mergedCellFrozenColumnMap.add(cellId_2);
|
|
1445
|
+
}
|
|
1446
|
+
var y = getRowOffset(actualRowIndex);
|
|
1447
|
+
var height = getRowOffset(actualBottom) - y + getRowHeight(actualBottom);
|
|
1448
|
+
var x = getColumnOffset(actualColumnIndex);
|
|
1449
|
+
var width = getColumnOffset(actualRight) - x + getColumnWidth(actualRight);
|
|
1450
|
+
var cellId = (0, helpers_3.cellIdentifier)(actualRowIndex, actualColumnIndex);
|
|
1451
|
+
var frozenColumnCell = getCellCache(cellCacheRef.current, cellId, function () {
|
|
1452
|
+
return itemRenderer({
|
|
1453
|
+
x: x,
|
|
1454
|
+
y: y,
|
|
1455
|
+
width: width,
|
|
1456
|
+
height: height,
|
|
1457
|
+
rowIndex: actualRowIndex,
|
|
1458
|
+
columnIndex: actualColumnIndex,
|
|
1459
|
+
isMergedCell: isMerged,
|
|
1460
|
+
key: (0, helpers_3.itemKey)({
|
|
1461
|
+
rowIndex: actualRowIndex,
|
|
1462
|
+
columnIndex: actualColumnIndex,
|
|
1463
|
+
}),
|
|
1464
|
+
});
|
|
1465
|
+
}, isScrolling, isMerged);
|
|
1466
|
+
frozenColumnCells.push(frozenColumnCell);
|
|
1467
|
+
if (enableCellOverlay &&
|
|
1468
|
+
!(isHiddenOverlay === null || isHiddenOverlay === void 0 ? void 0 : isHiddenOverlay(actualRowIndex, actualColumnIndex))) {
|
|
1469
|
+
var frozenColumnCellOverlay = getCellCache(cellOverlayCacheRef.current, cellId, function () {
|
|
1470
|
+
return overlayRenderer({
|
|
1471
|
+
x: x,
|
|
1472
|
+
y: y,
|
|
1473
|
+
width: width,
|
|
1474
|
+
height: height,
|
|
1475
|
+
rowIndex: actualRowIndex,
|
|
1476
|
+
columnIndex: actualColumnIndex,
|
|
1477
|
+
isMergedCell: isMerged,
|
|
1478
|
+
key: (0, helpers_3.itemKey)({
|
|
1479
|
+
rowIndex: actualRowIndex,
|
|
1480
|
+
columnIndex: actualColumnIndex,
|
|
1481
|
+
}),
|
|
1482
|
+
});
|
|
1483
|
+
}, isScrolling);
|
|
1484
|
+
frozenColumnCellOverlays.push(frozenColumnCellOverlay);
|
|
1485
|
+
}
|
|
1486
|
+
if (enableCellBackground &&
|
|
1487
|
+
!(isHiddenBackground === null || isHiddenBackground === void 0 ? void 0 : isHiddenBackground(actualRowIndex, actualColumnIndex))) {
|
|
1488
|
+
var frozenColumnCellBackground = getCellCache(cellBackgroundCacheRef.current, cellId, function () {
|
|
1489
|
+
return backgroundRenderer === null || backgroundRenderer === void 0 ? void 0 : backgroundRenderer({
|
|
1490
|
+
x: x,
|
|
1491
|
+
y: y,
|
|
1492
|
+
width: width,
|
|
1493
|
+
height: height,
|
|
1494
|
+
rowIndex: actualRowIndex,
|
|
1495
|
+
columnIndex: actualColumnIndex,
|
|
1496
|
+
isMergedCell: isMerged,
|
|
1497
|
+
key: (0, helpers_3.itemKey)({
|
|
1498
|
+
rowIndex: actualRowIndex,
|
|
1499
|
+
columnIndex: actualColumnIndex,
|
|
1500
|
+
}),
|
|
1501
|
+
});
|
|
1502
|
+
}, isScrolling);
|
|
1503
|
+
frozenColumnCellBackgrounds.push(frozenColumnCellBackground);
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
for (var columnIndex = 1; columnIndex < Math.min(columnStopIndex, frozenColumns); columnIndex++) {
|
|
1507
|
+
_loop_2(columnIndex);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1512
|
+
finally {
|
|
1513
|
+
try {
|
|
1514
|
+
if (visibleRowsForFrozenCols_1_1 && !visibleRowsForFrozenCols_1_1.done && (_a = visibleRowsForFrozenCols_1.return)) _a.call(visibleRowsForFrozenCols_1);
|
|
1515
|
+
}
|
|
1516
|
+
finally { if (e_4) throw e_4.error; }
|
|
1517
|
+
}
|
|
1518
|
+
return [
|
|
1519
|
+
frozenRowCellBackgrounds,
|
|
1520
|
+
frozenColumnCellBackgrounds,
|
|
1521
|
+
frozenRowCells,
|
|
1522
|
+
frozenColumnCells,
|
|
1523
|
+
frozenRowCellOverlays,
|
|
1524
|
+
frozenColumnCellOverlays,
|
|
1525
|
+
];
|
|
1526
|
+
}, [
|
|
1527
|
+
rowStartIndex,
|
|
1528
|
+
rowStopIndex,
|
|
1529
|
+
columnStartIndex,
|
|
1530
|
+
columnStopIndex,
|
|
1531
|
+
isMergedCell,
|
|
1532
|
+
getCellBounds,
|
|
1533
|
+
getRowOffset,
|
|
1534
|
+
getRowHeight,
|
|
1535
|
+
getColumnOffset,
|
|
1536
|
+
getColumnWidth,
|
|
1537
|
+
isHiddenCell,
|
|
1538
|
+
isHiddenRow,
|
|
1539
|
+
isHiddenColumn,
|
|
1540
|
+
getVisibleRowIndices,
|
|
1541
|
+
itemRenderer,
|
|
1542
|
+
frozenRows,
|
|
1543
|
+
frozenColumns,
|
|
1544
|
+
enableCellOverlay,
|
|
1545
|
+
onBeforeRenderRow,
|
|
1546
|
+
isHiddenOverlay,
|
|
1547
|
+
overlayRenderer,
|
|
1548
|
+
isHiddenBackground,
|
|
1549
|
+
backgroundRenderer,
|
|
1550
|
+
enableCellBackground,
|
|
1551
|
+
getCellCache,
|
|
1552
|
+
isScrolling,
|
|
1553
|
+
frozenColumnOverflowCells,
|
|
1554
|
+
]), 6), frozenRowCellBackgrounds = _27[0], frozenColumnCellBackgrounds = _27[1], frozenRowCells = _27[2], frozenColumnCells = _27[3], frozenRowCellOverlays = _27[4], frozenColumnCellOverlays = _27[5];
|
|
1555
|
+
var _28 = tslib_1.__read((0, react_1.useMemo)(function () {
|
|
1556
|
+
var e_5, _a;
|
|
1557
|
+
/* Draw all cells */
|
|
1558
|
+
var cells = [];
|
|
1559
|
+
/**
|
|
1560
|
+
* Lets users draw cells on top of existing canvas
|
|
1561
|
+
*/
|
|
1562
|
+
var cellOverlays = [];
|
|
1563
|
+
// Lets users draw layers of cells
|
|
1564
|
+
// 1. Background, 2. Text 3. Border
|
|
1565
|
+
var cellBackgrounds = [];
|
|
1566
|
+
if (columnCount > 0 && rowCount) {
|
|
1567
|
+
// Use getVisibleRowIndices for efficient iteration over visible rows
|
|
1568
|
+
var visibleRows = getVisibleRowIndices(rowStartIndex, rowStopIndex);
|
|
1569
|
+
try {
|
|
1570
|
+
for (var visibleRows_2 = tslib_1.__values(visibleRows), visibleRows_2_1 = visibleRows_2.next(); !visibleRows_2_1.done; visibleRows_2_1 = visibleRows_2.next()) {
|
|
1571
|
+
var rowIndex = visibleRows_2_1.value;
|
|
1572
|
+
var _loop_3 = function (columnIndex) {
|
|
1573
|
+
/**
|
|
1574
|
+
* Skip frozen columns unless they overflow into the body area
|
|
1575
|
+
* Skip merged cells that are out of bounds
|
|
1576
|
+
*/
|
|
1577
|
+
if (columnIndex < frozenColumns &&
|
|
1578
|
+
!(frozenColumnOverflowCells === null || frozenColumnOverflowCells === void 0 ? void 0 : frozenColumnOverflowCells.has((0, helpers_3.cellIdentifier)(rowIndex, columnIndex)))) {
|
|
1579
|
+
return "continue";
|
|
1580
|
+
}
|
|
1581
|
+
var isMerged = isMergedCell({ rowIndex: rowIndex, columnIndex: columnIndex });
|
|
1582
|
+
var bounds = getCellBounds({ rowIndex: rowIndex, columnIndex: columnIndex });
|
|
1583
|
+
var actualRowIndex = isMerged ? bounds.startRowIndex : rowIndex;
|
|
1584
|
+
var actualColumnIndex = isMerged
|
|
1585
|
+
? bounds.startColumnIndex
|
|
1586
|
+
: columnIndex;
|
|
1587
|
+
var actualBottom = Math.max(rowIndex, bounds.endRowIndex);
|
|
1588
|
+
var actualRight = Math.max(columnIndex, bounds.endColumnIndex);
|
|
1589
|
+
var cellId = (0, helpers_3.cellIdentifier)(bounds.startRowIndex, bounds.startColumnIndex);
|
|
1590
|
+
if (isHiddenColumn === null || isHiddenColumn === void 0 ? void 0 : isHiddenColumn(actualColumnIndex)) {
|
|
1591
|
+
return "continue";
|
|
1592
|
+
}
|
|
1593
|
+
if (!isMerged &&
|
|
1594
|
+
(isHiddenCell === null || isHiddenCell === void 0 ? void 0 : isHiddenCell(actualRowIndex, actualColumnIndex))) {
|
|
1595
|
+
return "continue";
|
|
1596
|
+
}
|
|
1597
|
+
if (isMerged) {
|
|
1598
|
+
if (mergedCellRenderMap.has(cellId)) {
|
|
1599
|
+
return "continue";
|
|
1600
|
+
}
|
|
1601
|
+
mergedCellRenderMap.add(cellId);
|
|
1602
|
+
}
|
|
1603
|
+
var y = getRowOffset(actualRowIndex);
|
|
1604
|
+
var height = getRowOffset(actualBottom) - y + getRowHeight(actualBottom);
|
|
1605
|
+
var x = getColumnOffset(actualColumnIndex);
|
|
1606
|
+
var width = getColumnOffset(actualRight) - x + getColumnWidth(actualRight);
|
|
1607
|
+
var cell = getCellCache(cellCacheRef.current, cellId, function () {
|
|
1608
|
+
return itemRenderer({
|
|
1609
|
+
x: x,
|
|
1610
|
+
y: y,
|
|
1611
|
+
width: width,
|
|
1612
|
+
height: height,
|
|
1613
|
+
rowIndex: actualRowIndex,
|
|
1614
|
+
columnIndex: actualColumnIndex,
|
|
1615
|
+
isMergedCell: isMerged,
|
|
1616
|
+
key: (0, helpers_3.itemKey)({
|
|
1617
|
+
rowIndex: actualRowIndex,
|
|
1618
|
+
columnIndex: actualColumnIndex,
|
|
1619
|
+
}),
|
|
1620
|
+
});
|
|
1621
|
+
}, isScrolling, isMerged);
|
|
1622
|
+
cells.push(cell);
|
|
1623
|
+
if (enableCellOverlay &&
|
|
1624
|
+
!(isHiddenOverlay === null || isHiddenOverlay === void 0 ? void 0 : isHiddenOverlay(actualRowIndex, actualColumnIndex))) {
|
|
1625
|
+
var cellOverlay = getCellCache(cellOverlayCacheRef.current, cellId, function () {
|
|
1626
|
+
return overlayRenderer({
|
|
1627
|
+
x: x,
|
|
1628
|
+
y: y,
|
|
1629
|
+
width: width,
|
|
1630
|
+
height: height,
|
|
1631
|
+
rowIndex: actualRowIndex,
|
|
1632
|
+
columnIndex: actualColumnIndex,
|
|
1633
|
+
isMergedCell: isMerged,
|
|
1634
|
+
key: (0, helpers_3.itemKey)({
|
|
1635
|
+
rowIndex: actualRowIndex,
|
|
1636
|
+
columnIndex: actualColumnIndex,
|
|
1637
|
+
}),
|
|
1638
|
+
});
|
|
1639
|
+
}, isScrolling);
|
|
1640
|
+
cellOverlays.push(cellOverlay);
|
|
1641
|
+
}
|
|
1642
|
+
if (enableCellBackground &&
|
|
1643
|
+
!(isHiddenBackground === null || isHiddenBackground === void 0 ? void 0 : isHiddenBackground(actualRowIndex, actualColumnIndex))) {
|
|
1644
|
+
var cellBackground = getCellCache(cellBackgroundCacheRef.current, cellId, function () {
|
|
1645
|
+
return backgroundRenderer === null || backgroundRenderer === void 0 ? void 0 : backgroundRenderer({
|
|
1646
|
+
x: x,
|
|
1647
|
+
y: y,
|
|
1648
|
+
width: width,
|
|
1649
|
+
height: height,
|
|
1650
|
+
rowIndex: actualRowIndex,
|
|
1651
|
+
columnIndex: actualColumnIndex,
|
|
1652
|
+
isMergedCell: isMerged,
|
|
1653
|
+
key: (0, helpers_3.itemKey)({
|
|
1654
|
+
rowIndex: actualRowIndex,
|
|
1655
|
+
columnIndex: actualColumnIndex,
|
|
1656
|
+
}),
|
|
1657
|
+
});
|
|
1658
|
+
}, isScrolling);
|
|
1659
|
+
cellBackgrounds.push(cellBackground);
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
|
|
1663
|
+
_loop_3(columnIndex);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1668
|
+
finally {
|
|
1669
|
+
try {
|
|
1670
|
+
if (visibleRows_2_1 && !visibleRows_2_1.done && (_a = visibleRows_2.return)) _a.call(visibleRows_2);
|
|
1671
|
+
}
|
|
1672
|
+
finally { if (e_5) throw e_5.error; }
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
return [cellBackgrounds, cells, cellOverlays];
|
|
1676
|
+
}, [
|
|
1677
|
+
rowStartIndex,
|
|
1678
|
+
rowStopIndex,
|
|
1679
|
+
columnStartIndex,
|
|
1680
|
+
columnStopIndex,
|
|
1681
|
+
isScrolling,
|
|
1682
|
+
isMergedCell,
|
|
1683
|
+
getCellBounds,
|
|
1684
|
+
getRowOffset,
|
|
1685
|
+
getRowHeight,
|
|
1686
|
+
getColumnOffset,
|
|
1687
|
+
getColumnWidth,
|
|
1688
|
+
isHiddenOverlay,
|
|
1689
|
+
itemRenderer,
|
|
1690
|
+
rowCount,
|
|
1691
|
+
columnCount,
|
|
1692
|
+
frozenColumns,
|
|
1693
|
+
getVisibleRowIndices,
|
|
1694
|
+
isHiddenColumn,
|
|
1695
|
+
isHiddenCell,
|
|
1696
|
+
enableCellOverlay,
|
|
1697
|
+
overlayRenderer,
|
|
1698
|
+
backgroundRenderer,
|
|
1699
|
+
enableCellBackground,
|
|
1700
|
+
isHiddenBackground,
|
|
1701
|
+
getCellCache,
|
|
1702
|
+
frozenColumnOverflowCells,
|
|
1703
|
+
]), 3), cellBackgrounds = _28[0], cells = _28[1], cellOverlays = _28[2];
|
|
1704
|
+
/**
|
|
1705
|
+
* Get x offset of a cell
|
|
1706
|
+
* takes into account frozen columns
|
|
1707
|
+
* and scoll
|
|
1708
|
+
*/
|
|
1709
|
+
var getXOffset = (0, react_1.useCallback)(function (columnIndex) {
|
|
1710
|
+
var isInFrozenColumn = columnIndex < frozenColumns;
|
|
1711
|
+
return (getColumnOffset(columnIndex) - (isInFrozenColumn ? 0 : scrollLeft));
|
|
1712
|
+
}, [getColumnOffset, scrollLeft, frozenColumns]);
|
|
1713
|
+
/**
|
|
1714
|
+
* Get y offset of a cell
|
|
1715
|
+
* takes into account frozen columns
|
|
1716
|
+
* and scoll
|
|
1717
|
+
*/
|
|
1718
|
+
var getYOffset = (0, react_1.useCallback)(function (rowIndex) {
|
|
1719
|
+
var isInFrozenRow = rowIndex < frozenRows;
|
|
1720
|
+
return getRowOffset(rowIndex) - (isInFrozenRow ? 0 : scrollTop);
|
|
1721
|
+
}, [getRowOffset, scrollTop, frozenRows]);
|
|
1722
|
+
// Frozen header cells
|
|
1723
|
+
var _29 = tslib_1.__read((0, react_1.useMemo)(function () {
|
|
1724
|
+
var e_6, _a;
|
|
1725
|
+
/* Draw frozen rows */
|
|
1726
|
+
var frozenRowHeaderCells = [];
|
|
1727
|
+
var frozenColumnHeaderCells = [];
|
|
1728
|
+
for (var rowIndex = 0; rowIndex < 1; rowIndex++) {
|
|
1729
|
+
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
|
|
1730
|
+
var y = getRowOffset(rowIndex);
|
|
1731
|
+
var height = getRowOffset(rowIndex) - y + getRowHeight(rowIndex);
|
|
1732
|
+
var x = getColumnOffset(columnIndex);
|
|
1733
|
+
var width = getColumnOffset(columnIndex) - x + getColumnWidth(columnIndex);
|
|
1734
|
+
frozenColumnHeaderCells.push(headerRenderer({
|
|
1735
|
+
x: x,
|
|
1736
|
+
y: y,
|
|
1737
|
+
width: width,
|
|
1738
|
+
height: height,
|
|
1739
|
+
rowIndex: rowIndex,
|
|
1740
|
+
columnIndex: columnIndex,
|
|
1741
|
+
key: (0, helpers_3.itemKey)({
|
|
1742
|
+
rowIndex: rowIndex,
|
|
1743
|
+
columnIndex: columnIndex,
|
|
1744
|
+
}),
|
|
1745
|
+
}));
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
/* Draw frozen columns (row headers) */
|
|
1749
|
+
// Use getVisibleRowIndices for efficient iteration
|
|
1750
|
+
var visibleRowsForHeaders = getVisibleRowIndices(rowStartIndex, rowStopIndex, false);
|
|
1751
|
+
try {
|
|
1752
|
+
for (var visibleRowsForHeaders_1 = tslib_1.__values(visibleRowsForHeaders), visibleRowsForHeaders_1_1 = visibleRowsForHeaders_1.next(); !visibleRowsForHeaders_1_1.done; visibleRowsForHeaders_1_1 = visibleRowsForHeaders_1.next()) {
|
|
1753
|
+
var rowIndex = visibleRowsForHeaders_1_1.value;
|
|
1754
|
+
for (var columnIndex = 0; columnIndex < 1; columnIndex++) {
|
|
1755
|
+
var y = getRowOffset(rowIndex);
|
|
1756
|
+
var height = getRowOffset(rowIndex) - y + getRowHeight(rowIndex);
|
|
1757
|
+
var x = getColumnOffset(columnIndex);
|
|
1758
|
+
var width = getColumnOffset(columnIndex) - x + getColumnWidth(columnIndex);
|
|
1759
|
+
frozenRowHeaderCells.push(headerRenderer({
|
|
1760
|
+
x: x,
|
|
1761
|
+
y: y,
|
|
1762
|
+
width: width,
|
|
1763
|
+
height: height,
|
|
1764
|
+
rowIndex: rowIndex,
|
|
1765
|
+
columnIndex: columnIndex,
|
|
1766
|
+
key: (0, helpers_3.itemKey)({
|
|
1767
|
+
rowIndex: rowIndex,
|
|
1768
|
+
columnIndex: columnIndex,
|
|
1769
|
+
}),
|
|
1770
|
+
}));
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1775
|
+
finally {
|
|
1776
|
+
try {
|
|
1777
|
+
if (visibleRowsForHeaders_1_1 && !visibleRowsForHeaders_1_1.done && (_a = visibleRowsForHeaders_1.return)) _a.call(visibleRowsForHeaders_1);
|
|
1778
|
+
}
|
|
1779
|
+
finally { if (e_6) throw e_6.error; }
|
|
1780
|
+
}
|
|
1781
|
+
return [frozenRowHeaderCells, frozenColumnHeaderCells];
|
|
1782
|
+
}, [
|
|
1783
|
+
rowStartIndex,
|
|
1784
|
+
rowStopIndex,
|
|
1785
|
+
columnStartIndex,
|
|
1786
|
+
columnStopIndex,
|
|
1787
|
+
getRowOffset,
|
|
1788
|
+
getRowHeight,
|
|
1789
|
+
getColumnOffset,
|
|
1790
|
+
getColumnWidth,
|
|
1791
|
+
headerRenderer,
|
|
1792
|
+
getVisibleRowIndices,
|
|
1793
|
+
]), 2), frozenRowHeaderCells = _29[0], frozenColumnHeaderCells = _29[1];
|
|
1794
|
+
/**
|
|
1795
|
+
* Frozen column shadow
|
|
1796
|
+
*/
|
|
1797
|
+
var frozenColumnShadow = (0, react_1.useMemo)(function () {
|
|
1798
|
+
var frozenColumnLineX = getColumnOffset(frozenColumns);
|
|
1799
|
+
var frozenColumnLineY = getRowOffset(Math.min(rowStopIndex + 1, rowCount));
|
|
1800
|
+
return (react_1.default.createElement(react_konva_1.Line, tslib_1.__assign({ points: [frozenColumnLineX, 0, frozenColumnLineX, frozenColumnLineY], offsetX: -0.5, strokeWidth: 1, shadowForStrokeEnabled: false, strokeScaleEnabled: false, hitStrokeWidth: 0, listening: false, perfectDrawEnabled: false }, shadowSettings)));
|
|
1801
|
+
}, [
|
|
1802
|
+
shadowSettings,
|
|
1803
|
+
frozenColumns,
|
|
1804
|
+
rowStopIndex,
|
|
1805
|
+
rowCount,
|
|
1806
|
+
getRowOffset,
|
|
1807
|
+
getColumnOffset,
|
|
1808
|
+
]);
|
|
1809
|
+
/**
|
|
1810
|
+
* Frozen row shadow
|
|
1811
|
+
*/
|
|
1812
|
+
var frozenRowShadow = (0, react_1.useMemo)(function () {
|
|
1813
|
+
var frozenRowLineY = getRowOffset(frozenRows);
|
|
1814
|
+
var frozenRowLineX = getColumnOffset(Math.min(columnStopIndex + 1, columnCount));
|
|
1815
|
+
return (react_1.default.createElement(react_konva_1.Line, tslib_1.__assign({ points: [0, frozenRowLineY, frozenRowLineX, frozenRowLineY], offsetY: -0.5, strokeWidth: 1, shadowForStrokeEnabled: false, strokeScaleEnabled: false, hitStrokeWidth: 0, listening: false, perfectDrawEnabled: false }, shadowSettings)));
|
|
1816
|
+
}, [
|
|
1817
|
+
shadowSettings,
|
|
1818
|
+
frozenRows,
|
|
1819
|
+
columnStopIndex,
|
|
1820
|
+
columnCount,
|
|
1821
|
+
getRowOffset,
|
|
1822
|
+
getColumnOffset,
|
|
1823
|
+
]);
|
|
1824
|
+
/* Draw frozen intersection cells */
|
|
1825
|
+
var _30 = tslib_1.__read((0, react_1.useMemo)(function () {
|
|
1826
|
+
var frozenIntersectionCellBackgrounds = [];
|
|
1827
|
+
var frozenIntersectionCells = [];
|
|
1828
|
+
var frozenIntersectionCellOverlays = [];
|
|
1829
|
+
for (var rowIndex = 1; rowIndex < Math.min(rowStopIndex, frozenRows); rowIndex++) {
|
|
1830
|
+
if (isHiddenRow === null || isHiddenRow === void 0 ? void 0 : isHiddenRow(rowIndex))
|
|
1831
|
+
continue;
|
|
1832
|
+
for (var columnIndex = 1; columnIndex < Math.min(columnStopIndex, frozenColumns); columnIndex++) {
|
|
1833
|
+
var isMerged = isMergedCell({ rowIndex: rowIndex, columnIndex: columnIndex });
|
|
1834
|
+
var bounds = getCellBounds({ rowIndex: rowIndex, columnIndex: columnIndex });
|
|
1835
|
+
var actualRowIndex = isMerged ? bounds.startRowIndex : rowIndex;
|
|
1836
|
+
var actualColumnIndex = isMerged
|
|
1837
|
+
? bounds.startColumnIndex
|
|
1838
|
+
: columnIndex;
|
|
1839
|
+
var actualBottom = Math.max(rowIndex, bounds.endRowIndex);
|
|
1840
|
+
var actualRight = Math.max(columnIndex, bounds.endColumnIndex);
|
|
1841
|
+
if (isHiddenColumn === null || isHiddenColumn === void 0 ? void 0 : isHiddenColumn(actualColumnIndex)) {
|
|
1842
|
+
continue;
|
|
1843
|
+
}
|
|
1844
|
+
if (!isMerged && (isHiddenCell === null || isHiddenCell === void 0 ? void 0 : isHiddenCell(actualRowIndex, actualColumnIndex))) {
|
|
1845
|
+
continue;
|
|
1846
|
+
}
|
|
1847
|
+
if (isMerged) {
|
|
1848
|
+
var cellId = (0, helpers_3.cellIdentifier)(bounds.startRowIndex, bounds.startColumnIndex);
|
|
1849
|
+
if (mergedCellRenderMap.has(cellId)) {
|
|
1850
|
+
continue;
|
|
1851
|
+
}
|
|
1852
|
+
mergedCellRenderMap.add(cellId);
|
|
1853
|
+
}
|
|
1854
|
+
var y = getRowOffset(actualRowIndex);
|
|
1855
|
+
var height = getRowOffset(actualBottom) - y + getRowHeight(actualBottom);
|
|
1856
|
+
var x = getColumnOffset(actualColumnIndex);
|
|
1857
|
+
var width = getColumnOffset(actualRight) - x + getColumnWidth(actualRight);
|
|
1858
|
+
frozenIntersectionCells.push(itemRenderer({
|
|
1859
|
+
x: x,
|
|
1860
|
+
y: y,
|
|
1861
|
+
width: width,
|
|
1862
|
+
height: height,
|
|
1863
|
+
rowIndex: actualRowIndex,
|
|
1864
|
+
columnIndex: actualColumnIndex,
|
|
1865
|
+
isMergedCell: isMerged,
|
|
1866
|
+
key: (0, helpers_3.itemKey)({
|
|
1867
|
+
rowIndex: actualRowIndex,
|
|
1868
|
+
columnIndex: actualColumnIndex,
|
|
1869
|
+
}),
|
|
1870
|
+
}));
|
|
1871
|
+
if (enableCellOverlay &&
|
|
1872
|
+
!(isHiddenOverlay === null || isHiddenOverlay === void 0 ? void 0 : isHiddenOverlay(actualRowIndex, actualColumnIndex))) {
|
|
1873
|
+
frozenIntersectionCellOverlays.push(overlayRenderer({
|
|
1874
|
+
x: x,
|
|
1875
|
+
y: y,
|
|
1876
|
+
width: width,
|
|
1877
|
+
height: height,
|
|
1878
|
+
rowIndex: actualRowIndex,
|
|
1879
|
+
columnIndex: actualColumnIndex,
|
|
1880
|
+
isMergedCell: isMerged,
|
|
1881
|
+
key: (0, helpers_3.itemKey)({
|
|
1882
|
+
rowIndex: actualRowIndex,
|
|
1883
|
+
columnIndex: actualColumnIndex,
|
|
1884
|
+
}),
|
|
1885
|
+
}));
|
|
1886
|
+
}
|
|
1887
|
+
if (enableCellBackground &&
|
|
1888
|
+
!(isHiddenBackground === null || isHiddenBackground === void 0 ? void 0 : isHiddenBackground(actualRowIndex, actualColumnIndex))) {
|
|
1889
|
+
frozenIntersectionCellBackgrounds.push(backgroundRenderer === null || backgroundRenderer === void 0 ? void 0 : backgroundRenderer({
|
|
1890
|
+
x: x,
|
|
1891
|
+
y: y,
|
|
1892
|
+
width: width,
|
|
1893
|
+
height: height,
|
|
1894
|
+
rowIndex: actualRowIndex,
|
|
1895
|
+
columnIndex: actualColumnIndex,
|
|
1896
|
+
isMergedCell: isMerged,
|
|
1897
|
+
key: (0, helpers_3.itemKey)({
|
|
1898
|
+
rowIndex: actualRowIndex,
|
|
1899
|
+
columnIndex: actualColumnIndex,
|
|
1900
|
+
}),
|
|
1901
|
+
}));
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
return [
|
|
1906
|
+
frozenIntersectionCellBackgrounds,
|
|
1907
|
+
frozenIntersectionCells,
|
|
1908
|
+
frozenIntersectionCellOverlays,
|
|
1909
|
+
];
|
|
1910
|
+
}, [
|
|
1911
|
+
rowStopIndex,
|
|
1912
|
+
columnStopIndex,
|
|
1913
|
+
isMergedCell,
|
|
1914
|
+
getCellBounds,
|
|
1915
|
+
getRowOffset,
|
|
1916
|
+
getRowHeight,
|
|
1917
|
+
getColumnOffset,
|
|
1918
|
+
getColumnWidth,
|
|
1919
|
+
itemRenderer,
|
|
1920
|
+
frozenRows,
|
|
1921
|
+
frozenColumns,
|
|
1922
|
+
enableCellOverlay,
|
|
1923
|
+
isHiddenRow,
|
|
1924
|
+
isHiddenColumn,
|
|
1925
|
+
isHiddenCell,
|
|
1926
|
+
isHiddenOverlay,
|
|
1927
|
+
isHiddenBackground,
|
|
1928
|
+
enableCellBackground,
|
|
1929
|
+
backgroundRenderer,
|
|
1930
|
+
overlayRenderer,
|
|
1931
|
+
]), 3), frozenIntersectionCellBackgrounds = _30[0], frozenIntersectionCells = _30[1], frozenIntersectionCellOverlays = _30[2];
|
|
1932
|
+
/* Draw frozen intersection cells */
|
|
1933
|
+
var _31 = tslib_1.__read((0, react_1.useMemo)(function () {
|
|
1934
|
+
var frozenIntersectionColumnHeaderCells = [];
|
|
1935
|
+
var frozenIntersectionRowHeaderCells = [];
|
|
1936
|
+
for (var rowIndex = 0; rowIndex < 1; rowIndex++) {
|
|
1937
|
+
if (isHiddenRow === null || isHiddenRow === void 0 ? void 0 : isHiddenRow(rowIndex))
|
|
1938
|
+
continue;
|
|
1939
|
+
for (var columnIndex = 0; columnIndex < Math.min(columnStopIndex, frozenColumns); columnIndex++) {
|
|
1940
|
+
if (isHiddenColumn === null || isHiddenColumn === void 0 ? void 0 : isHiddenColumn(columnIndex)) {
|
|
1941
|
+
continue;
|
|
1942
|
+
}
|
|
1943
|
+
var y = getRowOffset(rowIndex);
|
|
1944
|
+
var height = getRowOffset(rowIndex) - y + getRowHeight(rowIndex);
|
|
1945
|
+
var x = getColumnOffset(columnIndex);
|
|
1946
|
+
var width = getColumnOffset(columnIndex) - x + getColumnWidth(columnIndex);
|
|
1947
|
+
frozenIntersectionColumnHeaderCells.push(headerRenderer({
|
|
1948
|
+
x: x,
|
|
1949
|
+
y: y,
|
|
1950
|
+
width: width,
|
|
1951
|
+
height: height,
|
|
1952
|
+
rowIndex: rowIndex,
|
|
1953
|
+
columnIndex: columnIndex,
|
|
1954
|
+
key: (0, helpers_3.itemKey)({
|
|
1955
|
+
rowIndex: rowIndex,
|
|
1956
|
+
columnIndex: columnIndex,
|
|
1957
|
+
}),
|
|
1958
|
+
}));
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
for (var rowIndex = 0; rowIndex < Math.min(rowStopIndex, frozenRows); rowIndex++) {
|
|
1962
|
+
if (isHiddenRow === null || isHiddenRow === void 0 ? void 0 : isHiddenRow(rowIndex))
|
|
1963
|
+
continue;
|
|
1964
|
+
for (var columnIndex = 0; columnIndex < 1; columnIndex++) {
|
|
1965
|
+
if (isHiddenColumn === null || isHiddenColumn === void 0 ? void 0 : isHiddenColumn(columnIndex)) {
|
|
1966
|
+
continue;
|
|
1967
|
+
}
|
|
1968
|
+
var y = getRowOffset(rowIndex);
|
|
1969
|
+
var height = getRowOffset(rowIndex) - y + getRowHeight(rowIndex);
|
|
1970
|
+
var x = getColumnOffset(columnIndex);
|
|
1971
|
+
var width = getColumnOffset(columnIndex) - x + getColumnWidth(columnIndex);
|
|
1972
|
+
frozenIntersectionRowHeaderCells.push(headerRenderer({
|
|
1973
|
+
x: x,
|
|
1974
|
+
y: y,
|
|
1975
|
+
width: width,
|
|
1976
|
+
height: height,
|
|
1977
|
+
rowIndex: rowIndex,
|
|
1978
|
+
columnIndex: columnIndex,
|
|
1979
|
+
key: (0, helpers_3.itemKey)({
|
|
1980
|
+
rowIndex: rowIndex,
|
|
1981
|
+
columnIndex: columnIndex,
|
|
1982
|
+
}),
|
|
1983
|
+
}));
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
return [
|
|
1987
|
+
frozenIntersectionRowHeaderCells,
|
|
1988
|
+
frozenIntersectionColumnHeaderCells,
|
|
1989
|
+
];
|
|
1990
|
+
}, [
|
|
1991
|
+
rowStopIndex,
|
|
1992
|
+
columnStopIndex,
|
|
1993
|
+
frozenColumns,
|
|
1994
|
+
frozenRows,
|
|
1995
|
+
isHiddenColumn,
|
|
1996
|
+
isHiddenRow,
|
|
1997
|
+
getRowOffset,
|
|
1998
|
+
getRowHeight,
|
|
1999
|
+
getColumnOffset,
|
|
2000
|
+
getColumnWidth,
|
|
2001
|
+
headerRenderer,
|
|
2002
|
+
]), 2), frozenIntersectionRowHeaderCells = _31[0], frozenIntersectionColumnHeaderCells = _31[1];
|
|
2003
|
+
/**
|
|
2004
|
+
* Renders active cell
|
|
2005
|
+
*/
|
|
2006
|
+
var _32 = tslib_1.__read((0, react_1.useMemo)(function () {
|
|
2007
|
+
var fillHandleDimension = {};
|
|
2008
|
+
var activeCellSelection = null;
|
|
2009
|
+
var activeCellSelectionFrozenColumn = null;
|
|
2010
|
+
var activeCellSelectionFrozenRow = null;
|
|
2011
|
+
var activeCellSelectionFrozenIntersection = null;
|
|
2012
|
+
if (activeCell) {
|
|
2013
|
+
var bounds = getCellBounds(activeCell);
|
|
2014
|
+
var top_1 = bounds.startRowIndex, left = bounds.startColumnIndex, right = bounds.endColumnIndex, bottom = bounds.endRowIndex;
|
|
2015
|
+
var actualBottom = Math.min(rowStopIndex, bottom);
|
|
2016
|
+
var actualRight = Math.min(columnStopIndex, right);
|
|
2017
|
+
var isInFrozenColumn = left < frozenColumns;
|
|
2018
|
+
var isInFrozenRow = top_1 < frozenRows;
|
|
2019
|
+
var isInFrozenIntersection = isInFrozenRow && isInFrozenColumn;
|
|
2020
|
+
var isInBody = actualBottom >= frozenRows || actualRight >= frozenColumns;
|
|
2021
|
+
var isMerged = isMergedCell(activeCell);
|
|
2022
|
+
var y = getYOffset(top_1);
|
|
2023
|
+
var height = getYOffset(actualBottom) - y + getRowHeight(actualBottom);
|
|
2024
|
+
var x = getXOffset(left);
|
|
2025
|
+
var width = getXOffset(actualRight) - x + getColumnWidth(actualRight);
|
|
2026
|
+
var cell = selectionRenderer({
|
|
2027
|
+
stroke: selectionBorderColor,
|
|
2028
|
+
strokeWidth: activeCellStrokeWidth,
|
|
2029
|
+
fill: "transparent",
|
|
2030
|
+
x: x,
|
|
2031
|
+
y: y,
|
|
2032
|
+
width: width,
|
|
2033
|
+
height: height,
|
|
2034
|
+
type: "activeCell",
|
|
2035
|
+
index: 0,
|
|
2036
|
+
activeCell: activeCell,
|
|
2037
|
+
isDragging: isDraggingSelection,
|
|
2038
|
+
/* Active cell is draggable only there are no other selections */
|
|
2039
|
+
draggable: enableSelectionDrag && selections.length === 0,
|
|
2040
|
+
});
|
|
2041
|
+
// Active cell is hidden when xuser is dragging selections
|
|
2042
|
+
if (!(isDraggingSelection && selections.length > 0)) {
|
|
2043
|
+
// Merged cell extends to main body
|
|
2044
|
+
if (isInFrozenIntersection) {
|
|
2045
|
+
activeCellSelectionFrozenIntersection = cell;
|
|
2046
|
+
// Set fill handle position
|
|
2047
|
+
fillHandleDimension.position = "fi";
|
|
2048
|
+
}
|
|
2049
|
+
else if (isInFrozenRow) {
|
|
2050
|
+
activeCellSelectionFrozenRow = cell;
|
|
2051
|
+
// Set fill handle position
|
|
2052
|
+
fillHandleDimension.position = "fr";
|
|
2053
|
+
}
|
|
2054
|
+
else if (isInFrozenColumn) {
|
|
2055
|
+
activeCellSelectionFrozenColumn = cell;
|
|
2056
|
+
// Set fill handle position
|
|
2057
|
+
fillHandleDimension.position = "fc";
|
|
2058
|
+
}
|
|
2059
|
+
else {
|
|
2060
|
+
activeCellSelection = cell;
|
|
2061
|
+
}
|
|
2062
|
+
if (isMerged && isInBody) {
|
|
2063
|
+
activeCellSelection = cell;
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
fillHandleDimension.x = x + width;
|
|
2067
|
+
fillHandleDimension.y = y + height;
|
|
2068
|
+
}
|
|
2069
|
+
return [
|
|
2070
|
+
fillHandleDimension,
|
|
2071
|
+
activeCellSelection,
|
|
2072
|
+
activeCellSelectionFrozenColumn,
|
|
2073
|
+
activeCellSelectionFrozenRow,
|
|
2074
|
+
activeCellSelectionFrozenIntersection,
|
|
2075
|
+
];
|
|
2076
|
+
}, [
|
|
2077
|
+
getXOffset,
|
|
2078
|
+
getYOffset,
|
|
2079
|
+
activeCell,
|
|
2080
|
+
frozenRows,
|
|
2081
|
+
frozenColumns,
|
|
2082
|
+
activeCellStrokeWidth,
|
|
2083
|
+
columnStopIndex,
|
|
2084
|
+
enableSelectionDrag,
|
|
2085
|
+
isDraggingSelection,
|
|
2086
|
+
rowStopIndex,
|
|
2087
|
+
selectionBorderColor,
|
|
2088
|
+
selections.length,
|
|
2089
|
+
getColumnWidth,
|
|
2090
|
+
getRowHeight,
|
|
2091
|
+
getCellBounds,
|
|
2092
|
+
isMergedCell,
|
|
2093
|
+
selectionRenderer,
|
|
2094
|
+
]), 5), fillHandleDimension = _32[0], activeCellSelection = _32[1], activeCellSelectionFrozenColumn = _32[2], activeCellSelectionFrozenRow = _32[3], activeCellSelectionFrozenIntersection = _32[4];
|
|
2095
|
+
/**
|
|
2096
|
+
* Convert selections to area
|
|
2097
|
+
* Removed useMemo as changes to lastMeasureRowIndex, lastMeasuredColumnIndex,
|
|
2098
|
+
* does not trigger useMemo
|
|
2099
|
+
* Dependencies : [selections, rowStopIndex, columnStopIndex, instanceProps]
|
|
2100
|
+
*/
|
|
2101
|
+
var isSelectionInProgress = false;
|
|
2102
|
+
var _33 = tslib_1.__read((0, react_1.useMemo)(function () {
|
|
2103
|
+
var selectionAreas = [];
|
|
2104
|
+
var selectionAreasFrozenColumns = [];
|
|
2105
|
+
var selectionAreasFrozenRows = [];
|
|
2106
|
+
var selectionAreasIntersection = [];
|
|
2107
|
+
for (var i = 0; i < selections.length; i++) {
|
|
2108
|
+
var selection = selections[i];
|
|
2109
|
+
var range = selection.range, inProgress = selection.inProgress, style = selection.style;
|
|
2110
|
+
var top_2 = range.startRowIndex, left = range.startColumnIndex, right = range.endColumnIndex, bottom = range.endRowIndex;
|
|
2111
|
+
// Detect full row/column selections - don't expand to merged cells
|
|
2112
|
+
// to prevent selecting adjacent rows/columns due to merged cells at edges
|
|
2113
|
+
var isFullRowSelection = right >= columnCount - 1;
|
|
2114
|
+
var isFullColumnSelection = bottom >= rowCount - 1;
|
|
2115
|
+
var spanMerges = !(isFullRowSelection || isFullColumnSelection);
|
|
2116
|
+
var bounds = getCellBounds({ rowIndex: top_2, columnIndex: left }, spanMerges);
|
|
2117
|
+
var selectionBounds = { x: 0, y: 0, width: 0, height: 0 };
|
|
2118
|
+
var actualBottom = Math.max(bounds.endRowIndex, Math.min(rowStopIndex, bottom));
|
|
2119
|
+
var actualRight = Math.max(bounds.endColumnIndex, Math.min(columnStopIndex, right));
|
|
2120
|
+
var actualLeft = Math.min(bounds.startColumnIndex, left);
|
|
2121
|
+
var isLeftBoundFrozen = left < frozenColumns;
|
|
2122
|
+
var isTopBoundFrozen = top_2 < frozenRows;
|
|
2123
|
+
var isRightBoundFrozen = right < frozenColumns;
|
|
2124
|
+
var isBottomBoundFrozen = bottom < frozenRows;
|
|
2125
|
+
var isIntersectionFrozen = top_2 < frozenRows && left < frozenColumns;
|
|
2126
|
+
var isLast = i === selections.length - 1;
|
|
2127
|
+
var styles = tslib_1.__assign({ stroke: inProgress ? selectionBackgroundColor : selectionBorderColor, fill: selectionBackgroundColor, strokeWidth: selectionStrokeWidth, isDragging: isDraggingSelection, draggable: inProgress ? false : enableSelectionDrag }, style);
|
|
2128
|
+
/**
|
|
2129
|
+
* If selection is in progress,
|
|
2130
|
+
* use this variable to hide fill handle
|
|
2131
|
+
*/
|
|
2132
|
+
if (inProgress) {
|
|
2133
|
+
isSelectionInProgress = true;
|
|
2134
|
+
}
|
|
2135
|
+
selectionBounds.y = Math.max(0, getYOffset(top_2));
|
|
2136
|
+
selectionBounds.height = Math.max(0, getYOffset(actualBottom) -
|
|
2137
|
+
selectionBounds.y +
|
|
2138
|
+
getRowHeight(actualBottom));
|
|
2139
|
+
selectionBounds.x = Math.max(0, getXOffset(actualLeft));
|
|
2140
|
+
selectionBounds.width =
|
|
2141
|
+
getXOffset(actualRight) -
|
|
2142
|
+
selectionBounds.x +
|
|
2143
|
+
getColumnWidth(actualRight);
|
|
2144
|
+
if (isLeftBoundFrozen) {
|
|
2145
|
+
var frozenColumnSelectionWidth = getColumnOffset(Math.min(right + 1, frozenColumns)) -
|
|
2146
|
+
getColumnOffset(left);
|
|
2147
|
+
selectionAreasFrozenColumns.push(selectionRenderer(tslib_1.__assign(tslib_1.__assign({}, styles), { type: "selection", index: i, x: selectionBounds.x, y: selectionBounds.y, width: frozenColumnSelectionWidth, height: selectionBounds.height,
|
|
2148
|
+
// To counter selections that span frozen + floating cells
|
|
2149
|
+
strokeRightWidth: frozenColumnSelectionWidth === selectionBounds.width
|
|
2150
|
+
? undefined // Take it from strokeWidth
|
|
2151
|
+
: 0, selection: selection, inProgress: inProgress })));
|
|
2152
|
+
}
|
|
2153
|
+
if (isTopBoundFrozen) {
|
|
2154
|
+
var frozenRowSelectionHeight = getRowOffset(Math.min(bottom + 1, frozenRows)) - getRowOffset(top_2);
|
|
2155
|
+
selectionAreasFrozenRows.push(selectionRenderer(tslib_1.__assign(tslib_1.__assign({}, styles), { type: "selection", index: i, x: selectionBounds.x, y: selectionBounds.y, width: selectionBounds.width, height: frozenRowSelectionHeight, strokeBottomWidth: frozenRowSelectionHeight === selectionBounds.height
|
|
2156
|
+
? undefined // Take it from strokeWidth
|
|
2157
|
+
: 0, selection: selection, inProgress: inProgress })));
|
|
2158
|
+
}
|
|
2159
|
+
if (isIntersectionFrozen) {
|
|
2160
|
+
var frozenIntersectionSelectionHeight = getRowOffset(Math.min(bottom + 1, frozenRows)) - getRowOffset(top_2);
|
|
2161
|
+
var frozenIntersectionSelectionWidth = getColumnOffset(Math.min(right + 1, frozenColumns)) -
|
|
2162
|
+
getColumnOffset(left);
|
|
2163
|
+
selectionAreasIntersection.push(selectionRenderer(tslib_1.__assign(tslib_1.__assign({}, styles), { type: "selection", index: i, x: selectionBounds.x, y: selectionBounds.y, width: frozenIntersectionSelectionWidth, height: frozenIntersectionSelectionHeight, strokeBottomWidth: frozenIntersectionSelectionHeight === selectionBounds.height &&
|
|
2164
|
+
!isDraggingSelection
|
|
2165
|
+
? undefined // Take it from strokeWidth
|
|
2166
|
+
: 0, strokeRightWidth: frozenIntersectionSelectionWidth === selectionBounds.width &&
|
|
2167
|
+
!isDraggingSelection
|
|
2168
|
+
? undefined // Take it from strokeWidth
|
|
2169
|
+
: 0, selection: selection, inProgress: inProgress })));
|
|
2170
|
+
}
|
|
2171
|
+
selectionAreas.push(selectionRenderer(tslib_1.__assign(tslib_1.__assign({}, styles), { type: "selection", index: i, x: selectionBounds.x, y: selectionBounds.y, width: selectionBounds.width, height: selectionBounds.height, selection: selection, inProgress: inProgress })));
|
|
2172
|
+
if (isLast) {
|
|
2173
|
+
fillHandleDimension.x = selectionBounds.x + selectionBounds.width;
|
|
2174
|
+
fillHandleDimension.y = selectionBounds.y + selectionBounds.height;
|
|
2175
|
+
// Set fill handle position
|
|
2176
|
+
fillHandleDimension.position = isIntersectionFrozen
|
|
2177
|
+
? "fi"
|
|
2178
|
+
: isRightBoundFrozen
|
|
2179
|
+
? "fc"
|
|
2180
|
+
: isBottomBoundFrozen
|
|
2181
|
+
? "fr"
|
|
2182
|
+
: undefined;
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
return [
|
|
2186
|
+
selectionAreas,
|
|
2187
|
+
selectionAreasFrozenColumns,
|
|
2188
|
+
selectionAreasFrozenRows,
|
|
2189
|
+
selectionAreasIntersection,
|
|
2190
|
+
];
|
|
2191
|
+
}, [
|
|
2192
|
+
getXOffset,
|
|
2193
|
+
getYOffset,
|
|
2194
|
+
selections,
|
|
2195
|
+
columnStopIndex,
|
|
2196
|
+
rowStopIndex,
|
|
2197
|
+
frozenRows,
|
|
2198
|
+
frozenColumns,
|
|
2199
|
+
isDraggingSelection,
|
|
2200
|
+
selectionRenderer,
|
|
2201
|
+
getColumnOffset,
|
|
2202
|
+
getColumnWidth,
|
|
2203
|
+
getRowOffset,
|
|
2204
|
+
getRowHeight,
|
|
2205
|
+
getCellBounds,
|
|
2206
|
+
]), 4), selectionAreas = _33[0], selectionAreasFrozenColumns = _33[1], selectionAreasFrozenRows = _33[2], selectionAreasIntersection = _33[3];
|
|
2207
|
+
/**
|
|
2208
|
+
* Fillselection
|
|
2209
|
+
*/
|
|
2210
|
+
var fillSelections = null;
|
|
2211
|
+
if (fillSelection) {
|
|
2212
|
+
var range = fillSelection.range;
|
|
2213
|
+
var top_3 = range.startRowIndex, left = range.startColumnIndex, right = range.endColumnIndex, bottom = range.endRowIndex;
|
|
2214
|
+
var actualBottom = Math.min(rowStopIndex, bottom);
|
|
2215
|
+
var actualRight = Math.min(columnStopIndex, right);
|
|
2216
|
+
var x = getXOffset(left);
|
|
2217
|
+
var y = getYOffset(top_3);
|
|
2218
|
+
var height = getYOffset(actualBottom) - y + getRowHeight(actualBottom);
|
|
2219
|
+
var width = getXOffset(actualRight) - x + getColumnWidth(actualRight);
|
|
2220
|
+
fillSelections = selectionRenderer({
|
|
2221
|
+
type: "fill",
|
|
2222
|
+
x: x,
|
|
2223
|
+
y: y,
|
|
2224
|
+
width: width,
|
|
2225
|
+
height: height,
|
|
2226
|
+
index: -1,
|
|
2227
|
+
stroke: "gray",
|
|
2228
|
+
strokeStyle: "dashed",
|
|
2229
|
+
strokeWidth: 1,
|
|
2230
|
+
});
|
|
2231
|
+
}
|
|
2232
|
+
var _34 = tslib_1.__read((0, react_1.useMemo)(function () {
|
|
2233
|
+
var borderStyleCells = [];
|
|
2234
|
+
var borderStyleCellsFrozenColumns = [];
|
|
2235
|
+
var borderStyleCellsFrozenRows = [];
|
|
2236
|
+
var borderStyleCellsIntersection = [];
|
|
2237
|
+
for (var i = 0; i < borderStyles.length; i++) {
|
|
2238
|
+
var _a = borderStyles[i], range = _a.range, style = _a.style, _b = _a.type, type = _b === void 0 ? "border" : _b, key = _a.index, title = _a.title, rest_1 = tslib_1.__rest(_a, ["range", "style", "type", "index", "title"]);
|
|
2239
|
+
var top_4 = range.startRowIndex, left = range.startColumnIndex, right = range.endColumnIndex, bottom = range.endRowIndex;
|
|
2240
|
+
// Ignore out of bounds
|
|
2241
|
+
if (top_4 > rowStopIndex || bottom < rowStartIndex) {
|
|
2242
|
+
// continue;
|
|
2243
|
+
}
|
|
2244
|
+
var isLeftBoundFrozen = left < frozenColumns;
|
|
2245
|
+
var isTopBoundFrozen = top_4 < frozenRows;
|
|
2246
|
+
var isIntersectionFrozen = top_4 < frozenRows && left < frozenColumns;
|
|
2247
|
+
/**
|
|
2248
|
+
* A border style renders a copy into every pane its range touches,
|
|
2249
|
+
* each clipped by that pane's overflow container. The title must
|
|
2250
|
+
* appear exactly once — otherwise the copies clipped at a frozen
|
|
2251
|
+
* boundary show a duplicate, half-cut title that slides with the
|
|
2252
|
+
* scroll. It goes to the single pane that fully contains the range
|
|
2253
|
+
* (intersection → frozen columns → frozen rows → body).
|
|
2254
|
+
*/
|
|
2255
|
+
var isFullyFrozenColumns = right < frozenColumns;
|
|
2256
|
+
var isFullyFrozenRows = bottom < frozenRows;
|
|
2257
|
+
var x = getXOffset(left);
|
|
2258
|
+
var y = getYOffset(top_4);
|
|
2259
|
+
var width = Math.max(0, getXOffset(Math.min(columnCount, right + 1)) - x);
|
|
2260
|
+
var height = Math.max(0, getYOffset(bottom) - y + getRowHeight(bottom));
|
|
2261
|
+
var startsOnFirstBodyRow = frozenRows > 0 && top_4 === frozenRows;
|
|
2262
|
+
borderStyleCells.push(selectionRenderer(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, rest_1), style), { title: isFullyFrozenColumns || isFullyFrozenRows ? undefined : title, flipTitleToBottom: startsOnFirstBodyRow, range: range, x: x, y: y, index: key !== null && key !== void 0 ? key : i, width: width, height: height, type: type })));
|
|
2263
|
+
if (isLeftBoundFrozen) {
|
|
2264
|
+
var frozenColumnSelectionWidth = getColumnOffset(Math.min(right + 1, frozenColumns)) -
|
|
2265
|
+
getColumnOffset(left);
|
|
2266
|
+
borderStyleCellsFrozenColumns.push(selectionRenderer(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, rest_1), style), { title: isFullyFrozenColumns && !isFullyFrozenRows ? title : undefined, keepTitleWithinBounds: true, flipTitleToBottom: startsOnFirstBodyRow, range: range, type: type, x: x, y: y, index: key !== null && key !== void 0 ? key : i, width: frozenColumnSelectionWidth, height: height, strokeRightWidth: frozenColumnSelectionWidth === width
|
|
2267
|
+
? (style === null || style === void 0 ? void 0 : style.strokeRightWidth) || (style === null || style === void 0 ? void 0 : style.strokeWidth)
|
|
2268
|
+
: 0 })));
|
|
2269
|
+
}
|
|
2270
|
+
if (isTopBoundFrozen) {
|
|
2271
|
+
var frozenRowSelectionHeight = getRowOffset(Math.min(bottom + 1, frozenRows)) - getRowOffset(top_4);
|
|
2272
|
+
borderStyleCellsFrozenRows.push(selectionRenderer(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, rest_1), style), { title: isFullyFrozenRows && !isFullyFrozenColumns ? title : undefined, keepTitleWithinVerticalBounds: true, range: range, type: type, x: x, y: y, index: key !== null && key !== void 0 ? key : i, width: width, height: frozenRowSelectionHeight, strokeBottomWidth: frozenRowSelectionHeight === height
|
|
2273
|
+
? (style === null || style === void 0 ? void 0 : style.strokeBottomWidth) || (style === null || style === void 0 ? void 0 : style.strokeWidth)
|
|
2274
|
+
: 0 })));
|
|
2275
|
+
}
|
|
2276
|
+
if (isIntersectionFrozen) {
|
|
2277
|
+
var frozenIntersectionSelectionHeight = getRowOffset(Math.min(bottom + 1, frozenRows)) - getRowOffset(top_4);
|
|
2278
|
+
var frozenIntersectionSelectionWidth = getColumnOffset(Math.min(right + 1, frozenColumns)) -
|
|
2279
|
+
getColumnOffset(left);
|
|
2280
|
+
borderStyleCellsIntersection.push(selectionRenderer(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, rest_1), style), { title: isFullyFrozenColumns && isFullyFrozenRows ? title : undefined, keepTitleWithinBounds: true, keepTitleWithinVerticalBounds: true, range: range, type: type, x: x, y: y, index: key !== null && key !== void 0 ? key : i, width: frozenIntersectionSelectionWidth, height: frozenIntersectionSelectionHeight, strokeBottomWidth: frozenIntersectionSelectionHeight === height
|
|
2281
|
+
? selectionStrokeWidth
|
|
2282
|
+
: 0, strokeRightWidth: frozenIntersectionSelectionWidth === width
|
|
2283
|
+
? selectionStrokeWidth
|
|
2284
|
+
: 0 })));
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
return [
|
|
2288
|
+
borderStyleCells,
|
|
2289
|
+
borderStyleCellsFrozenColumns,
|
|
2290
|
+
borderStyleCellsFrozenRows,
|
|
2291
|
+
borderStyleCellsIntersection,
|
|
2292
|
+
];
|
|
2293
|
+
}, [
|
|
2294
|
+
getXOffset,
|
|
2295
|
+
getYOffset,
|
|
2296
|
+
borderStyles,
|
|
2297
|
+
columnCount,
|
|
2298
|
+
selectionStrokeWidth,
|
|
2299
|
+
frozenRows,
|
|
2300
|
+
frozenColumns,
|
|
2301
|
+
selectionRenderer,
|
|
2302
|
+
getColumnOffset,
|
|
2303
|
+
getRowOffset,
|
|
2304
|
+
getRowHeight,
|
|
2305
|
+
rowStartIndex,
|
|
2306
|
+
rowStopIndex,
|
|
2307
|
+
]), 4), borderStyleCells = _34[0], borderStyleCellsFrozenColumns = _34[1], borderStyleCellsFrozenRows = _34[2], borderStyleCellsIntersection = _34[3];
|
|
2308
|
+
/**
|
|
2309
|
+
* Prevents drawing hit region when scrolling
|
|
2310
|
+
*/
|
|
2311
|
+
var listenToEvents = !isScrolling;
|
|
2312
|
+
/* Frozen row shadow */
|
|
2313
|
+
var frozenRowShadowComponent = showFrozenRowShadow && frozenRows !== 1 ? frozenRowShadow : null;
|
|
2314
|
+
/* Frozen column shadow */
|
|
2315
|
+
var frozenColumnShadowComponent = showFrozenColumnShadow && frozenColumns !== 1 ? frozenColumnShadow : null;
|
|
2316
|
+
var fillHandleWidth = fillHandleSize;
|
|
2317
|
+
var fillhandleComponent = showFillHandle && !isSelectionInProgress ? (react_1.default.createElement(FillHandle, tslib_1.__assign({}, fillHandleDimension, { stroke: fillHandleBackgroundColor, size: fillHandleWidth, borderColor: fillhandleBorderColor, onMouseDown: onFillHandleMouseDown, onDoubleClick: onFillHandleDoubleClick }))) : null;
|
|
2318
|
+
var selectionChildren = (react_1.default.createElement("div", { className: "pointer-events-none" },
|
|
2319
|
+
react_1.default.createElement("div", { className: "absolute right-0 bottom-0 overflow-hidden", style: {
|
|
2320
|
+
left: frozenColumnWidth,
|
|
2321
|
+
top: frozenRowHeight,
|
|
2322
|
+
} },
|
|
2323
|
+
react_1.default.createElement("div", { style: {
|
|
2324
|
+
transform: "translate(-".concat(frozenColumnWidth, "px, -").concat(frozenRowHeight, "px)"),
|
|
2325
|
+
} },
|
|
2326
|
+
activeCellSelection,
|
|
2327
|
+
selectionAreas,
|
|
2328
|
+
borderStyleCells,
|
|
2329
|
+
fillhandleComponent,
|
|
2330
|
+
fillSelections)),
|
|
2331
|
+
frozenColumns ? (react_1.default.createElement("div", { className: "absolute left-0 bottom-0 overflow-hidden", style: {
|
|
2332
|
+
top: frozenRowHeight,
|
|
2333
|
+
width: frozenColumnWidth + fillHandleWidth,
|
|
2334
|
+
} },
|
|
2335
|
+
react_1.default.createElement("div", { style: {
|
|
2336
|
+
transform: "translate(0, -".concat(frozenRowHeight, "px)"),
|
|
2337
|
+
} },
|
|
2338
|
+
activeCellSelectionFrozenColumn,
|
|
2339
|
+
selectionAreasFrozenColumns,
|
|
2340
|
+
borderStyleCellsFrozenColumns,
|
|
2341
|
+
fillHandleDimension.position === "fc"
|
|
2342
|
+
? fillhandleComponent
|
|
2343
|
+
: null,
|
|
2344
|
+
fillSelections))) : null,
|
|
2345
|
+
frozenRows ? (react_1.default.createElement("div", { className: "absolute top-0 right-0 overflow-hidden", style: {
|
|
2346
|
+
left: frozenColumnWidth,
|
|
2347
|
+
height: frozenRowHeight + fillHandleWidth,
|
|
2348
|
+
} },
|
|
2349
|
+
react_1.default.createElement("div", { style: {
|
|
2350
|
+
transform: "translate(-".concat(frozenColumnWidth, "px, 0)"),
|
|
2351
|
+
} },
|
|
2352
|
+
activeCellSelectionFrozenRow,
|
|
2353
|
+
selectionAreasFrozenRows,
|
|
2354
|
+
borderStyleCellsFrozenRows,
|
|
2355
|
+
fillHandleDimension.position === "fr"
|
|
2356
|
+
? fillhandleComponent
|
|
2357
|
+
: null,
|
|
2358
|
+
fillSelections))) : null,
|
|
2359
|
+
frozenRows && frozenColumns ? (react_1.default.createElement("div", { className: "absolute left-0 top-0 overflow-hidden pointer-events-none", style: {
|
|
2360
|
+
height: frozenRowHeight + fillHandleWidth,
|
|
2361
|
+
width: frozenColumnWidth + fillHandleWidth,
|
|
2362
|
+
} },
|
|
2363
|
+
activeCellSelectionFrozenIntersection,
|
|
2364
|
+
selectionAreasIntersection,
|
|
2365
|
+
borderStyleCellsIntersection,
|
|
2366
|
+
fillHandleDimension.position === "fi" ? fillhandleComponent : null,
|
|
2367
|
+
fillSelections)) : null));
|
|
2368
|
+
/**
|
|
2369
|
+
* Context value of grid children
|
|
2370
|
+
*/
|
|
2371
|
+
var contextValue = (0, react_1.useMemo)(function () { return ({
|
|
2372
|
+
getCellOffsetFromCoords: getCellOffsetFromCoords,
|
|
2373
|
+
}); }, [getCellOffsetFromCoords]);
|
|
2374
|
+
// Print style
|
|
2375
|
+
var containerStyle = {
|
|
2376
|
+
width: containerWidth,
|
|
2377
|
+
"--rnc-print-top-margin": "-".concat(headerRowHeight, "px"),
|
|
2378
|
+
"--rnc-print-left-margin": "-".concat(headerColumnWidth, "px"),
|
|
2379
|
+
};
|
|
2380
|
+
// Footer final height - gradually reveal footer as user scrolls to bottom
|
|
2381
|
+
var contentMaxScrollTop = estimatedTotalHeight - containerHeight;
|
|
2382
|
+
var scrollPastBottom = Math.max(0, scrollTop - contentMaxScrollTop);
|
|
2383
|
+
var footerRevealAmount = Math.min(scrollPastBottom, footerHeight);
|
|
2384
|
+
return (react_1.default.createElement("div", { style: containerStyle, className: "rowsncolumns-grid print:w-full print:h-full print:block relative ", ref: scrollContainerRef },
|
|
2385
|
+
react_1.default.createElement("div", tslib_1.__assign({ className: "rowsncolumns-grid-container outline-none touch-none select-none relative", tabIndex: 0, ref: containerRef }, rest),
|
|
2386
|
+
react_1.default.createElement(MemoizedGrid_1.MemoizedGrid, { cells: cells, cellOverlays: cellOverlays, cellBackgrounds: cellBackgrounds, width: containerWidth, height: containerHeight, ref: stageRef, gridLines: gridLines, frozenRowCells: frozenRowCells, frozenColumnCells: frozenColumnCells, frozenColumnWidth: frozenColumnWidth, frozenRowHeight: frozenRowHeight, scrollTop: scrollTop, scrollLeft: scrollLeft, frozenSpacing: frozenSpacing, frozenIntersectionCells: frozenIntersectionCells, gridLinesFrozenColumn: gridLinesFrozenColumn, gridLinesFrozenRow: gridLinesFrozenRow, gridLinesFrozenIntersection: gridLinesFrozenIntersection, frozenColumnShadowComponent: frozenColumnShadowComponent, frozenRowShadowComponent: frozenRowShadowComponent, frozenIntersectionCellOverlays: frozenIntersectionCellOverlays, frozenIntersectionCellBackgrounds: frozenIntersectionCellBackgrounds, frozenRowCellOverlays: frozenRowCellOverlays, frozenRowCellBackgrounds: frozenRowCellBackgrounds, frozenColumnCellBackgrounds: frozenColumnCellBackgrounds, frozenColumnCellOverlays: frozenColumnCellOverlays, frozenRowHeaderCells: frozenRowHeaderCells, frozenColumnHeaderCells: frozenColumnHeaderCells, frozenIntersectionRowHeaderCells: frozenIntersectionRowHeaderCells, frozenIntersectionColumnHeaderCells: frozenIntersectionColumnHeaderCells, headerRowHeight: headerRowHeight, headerColumnWidth: headerColumnWidth, showHeaders: showHeaders, listening: listenToEvents, rowHeaderStageRef: rowHeaderStageRef, columnHeaderStageRef: columnHeaderStageRef })),
|
|
2387
|
+
selectionChildren,
|
|
2388
|
+
react_1.default.createElement(Context_1.GridContext.Provider, { value: contextValue },
|
|
2389
|
+
gridChildren && typeof gridChildren === "function"
|
|
2390
|
+
? gridChildren({
|
|
2391
|
+
scrollLeft: scrollLeft,
|
|
2392
|
+
scrollTop: scrollTop,
|
|
2393
|
+
frozenRowHeight: frozenRowHeight,
|
|
2394
|
+
frozenColumnWidth: frozenColumnWidth,
|
|
2395
|
+
containerHeight: containerHeight,
|
|
2396
|
+
containerWidth: containerWidth,
|
|
2397
|
+
})
|
|
2398
|
+
: null,
|
|
2399
|
+
children),
|
|
2400
|
+
footerComponent ? (react_1.default.createElement("div", { className: "absolute inset-0 overflow-hidden pointer-events-none" },
|
|
2401
|
+
react_1.default.createElement("div", { style: {
|
|
2402
|
+
height: footerHeight,
|
|
2403
|
+
bottom: 0,
|
|
2404
|
+
transform: "translateY(".concat(footerHeight - footerRevealAmount, "px)"),
|
|
2405
|
+
willChange: "transform",
|
|
2406
|
+
}, className: "rnc-bottom-footer absolute left-0 right-0 overflow-hidden pointer-events-auto flex flex-col" }, react_1.default.isValidElement(footerComponent)
|
|
2407
|
+
? footerComponent
|
|
2408
|
+
: react_1.default.createElement(footerComponent)))) : null,
|
|
2409
|
+
showScrollbarX ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
2410
|
+
react_1.default.createElement("div", { className: "rnc-scrollbar-shim bg-rnc-scrollbar-background print:hidden border-t border-l border-b border-t-rnc-scrollbar-border border-l-rnc-border border-b-rnc-scrollbar-border border-solid left-0 right-0 bottom-0 absolute", style: {
|
|
2411
|
+
height: scrollbarSize,
|
|
2412
|
+
} }),
|
|
2413
|
+
frozenColumnWidth === 0 ? null : (react_1.default.createElement("div", { className: "rnc-frozen-col-sep ml-px border-l-0 border-b-0 border-t-0 border-r border-solid border-r-rnc-border absolute bottom-0 left-0", style: {
|
|
2414
|
+
height: scrollbarSize,
|
|
2415
|
+
width: frozenColumnWidth,
|
|
2416
|
+
} })),
|
|
2417
|
+
react_1.default.createElement("div", { role: "scrollbar", "aria-orientation": "horizontal", className: "rnc-scrollbar print:hidden rnc-scrollbar-x absolute bottom-0 will-change-transform overflow-scroll", tabIndex: -1, style: {
|
|
2418
|
+
left: frozenColumnWidth,
|
|
2419
|
+
width: scrollbarXContainterWidth,
|
|
2420
|
+
height: scrollbarSize,
|
|
2421
|
+
}, onScroll: handleScrollLeft, ref: horizontalScrollRef },
|
|
2422
|
+
react_1.default.createElement("div", { style: {
|
|
2423
|
+
position: "absolute",
|
|
2424
|
+
width: scrollbarXWidth,
|
|
2425
|
+
height: 1,
|
|
2426
|
+
} })))) : null,
|
|
2427
|
+
showScrollbarY ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
2428
|
+
react_1.default.createElement("div", { className: "rnc-scrollbar-shim bg-rnc-scrollbar-background print:hidden border-t border-l border-r border-t-rnc-border border-l-rnc-scrollbar-border border-r-rnc-scrollbar-border border-solid absolute bottom-0 right-0 top-0", style: {
|
|
2429
|
+
width: scrollbarSize,
|
|
2430
|
+
} }),
|
|
2431
|
+
frozenRowHeight === 0 ? null : (react_1.default.createElement("div", { className: "rnc-frozen-row-sep mt-px border-l-0 border-r-0 border-t-0 border-b border-b-rnc-border border-solid absolute top-0 right-0", style: {
|
|
2432
|
+
width: scrollbarSize,
|
|
2433
|
+
height: frozenRowHeight,
|
|
2434
|
+
} })),
|
|
2435
|
+
react_1.default.createElement("div", { role: "scrollbar", "aria-orientation": "vertical", className: "rnc-scrollbar print:hidden rnc-scrollbar-y overflow-scroll absolute right-0 will-change-transform", tabIndex: -1, style: {
|
|
2436
|
+
height: scrollbarYContainterHeight,
|
|
2437
|
+
top: frozenRowHeight,
|
|
2438
|
+
width: scrollbarSize,
|
|
2439
|
+
}, onScroll: handleScroll, ref: verticalScrollRef },
|
|
2440
|
+
react_1.default.createElement("div", { className: "absolute", style: {
|
|
2441
|
+
height: effectiveScrollbarYHeight,
|
|
2442
|
+
width: 1,
|
|
2443
|
+
} })))) : null));
|
|
2444
|
+
}));
|
|
2445
|
+
Grid.displayName = "Grid";
|
|
2446
|
+
exports.default = Grid;
|