@rowsncolumns/grid 9.0.4 → 13.2.33
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 -982
- 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 -1440
- 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
|
@@ -0,0 +1,1409 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDevicePixelRatio = exports.useCallbackRef = exports.useIsomorphicLayoutEffect = exports.getScrollIncrement = exports.isArrowKey = exports.castToString = exports.findNextCellInDataRegion = exports.findLastContentfulCell = exports.findNextContentfulCell = exports.clampIndex = exports.isCellWithinBounds = exports.isEqualCells = exports.isNull = exports.autoSizerCanvas = exports.AutoSizerCanvas = exports.toCssFontFamily = exports.canUseDOM = exports.cellToArea = exports.cellRangeToBounds = exports.extendAreaToMergedCells = exports.isAreasEqual = exports.areaInsideArea = exports.areaIntersects = exports.findNextCellWithinBounds = exports.prepareClipboardData = exports.numberToAlphabet = exports.clampCellCoords = exports.newSelectionFromDrag = exports.selectionSpansCells = exports.selectionFromActiveCell = exports.getOffsetForRowAndAlignment = exports.getOffsetForColumnAndAlignment = exports.getOffsetForIndexAndAlignment = exports.scheduleIdlePriorityCallback = exports.cellIdentifier = exports.getEstimatedTotalWidth = exports.getEstimatedTotalHeight = exports.getItemMetadata = exports.getColumnWidth = exports.getRowHeight = exports.getColumnOffset = exports.getRowOffset = exports.itemKey = exports.getBoundedCells = exports.getColumnStopIndexForStartIndex = exports.getColumnStartIndexForOffset = exports.getRowStopIndexForStartIndex = exports.getRowStartIndexForOffset = exports.ItemType = exports.Align = void 0;
|
|
4
|
+
exports.getPreviousCellInDirection = void 0;
|
|
5
|
+
exports.throttle = throttle;
|
|
6
|
+
exports.debounce = debounce;
|
|
7
|
+
exports.rafThrottle = rafThrottle;
|
|
8
|
+
exports.ricThrottle = ricThrottle;
|
|
9
|
+
exports.cancelTimeout = cancelTimeout;
|
|
10
|
+
exports.requestTimeout = requestTimeout;
|
|
11
|
+
var tslib_1 = require("tslib");
|
|
12
|
+
// Utilities extracted from https://github.com/bvaughn/react-window
|
|
13
|
+
var react_1 = require("react");
|
|
14
|
+
var scheduler_1 = require("scheduler");
|
|
15
|
+
var types_1 = require("./types");
|
|
16
|
+
var Align;
|
|
17
|
+
(function (Align) {
|
|
18
|
+
Align["start"] = "start";
|
|
19
|
+
Align["end"] = "end";
|
|
20
|
+
Align["center"] = "center";
|
|
21
|
+
Align["auto"] = "auto";
|
|
22
|
+
Align["smart"] = "smart";
|
|
23
|
+
})(Align || (exports.Align = Align = {}));
|
|
24
|
+
var ItemType;
|
|
25
|
+
(function (ItemType) {
|
|
26
|
+
ItemType["row"] = "row";
|
|
27
|
+
ItemType["column"] = "column";
|
|
28
|
+
})(ItemType || (exports.ItemType = ItemType = {}));
|
|
29
|
+
var getRowStartIndexForOffset = function (_a) {
|
|
30
|
+
var rowHeight = _a.rowHeight, columnWidth = _a.columnWidth, rowCount = _a.rowCount, columnCount = _a.columnCount, instanceProps = _a.instanceProps, offset = _a.offset, scale = _a.scale;
|
|
31
|
+
return findNearestItem({
|
|
32
|
+
itemType: ItemType.row,
|
|
33
|
+
rowHeight: rowHeight,
|
|
34
|
+
columnWidth: columnWidth,
|
|
35
|
+
rowCount: rowCount,
|
|
36
|
+
columnCount: columnCount,
|
|
37
|
+
instanceProps: instanceProps,
|
|
38
|
+
offset: offset,
|
|
39
|
+
scale: scale,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
exports.getRowStartIndexForOffset = getRowStartIndexForOffset;
|
|
43
|
+
var getRowStopIndexForStartIndex = function (_a) {
|
|
44
|
+
var startIndex = _a.startIndex, rowCount = _a.rowCount, rowHeight = _a.rowHeight, columnWidth = _a.columnWidth, scrollTop = _a.scrollTop, containerHeight = _a.containerHeight, instanceProps = _a.instanceProps, scale = _a.scale, visibleRowRanges = _a.visibleRowRanges;
|
|
45
|
+
var itemMetadata = (0, exports.getItemMetadata)({
|
|
46
|
+
itemType: ItemType.row,
|
|
47
|
+
rowHeight: rowHeight,
|
|
48
|
+
columnWidth: columnWidth,
|
|
49
|
+
index: startIndex,
|
|
50
|
+
instanceProps: instanceProps,
|
|
51
|
+
scale: scale,
|
|
52
|
+
});
|
|
53
|
+
var maxOffset = scrollTop + containerHeight;
|
|
54
|
+
var offset = itemMetadata.offset + itemMetadata.size;
|
|
55
|
+
var stopIndex = startIndex;
|
|
56
|
+
// If visibleRowRanges provided, use it to skip hidden rows efficiently
|
|
57
|
+
if (visibleRowRanges && visibleRowRanges.length > 0) {
|
|
58
|
+
// Find which range we're currently in
|
|
59
|
+
var currentRangeIdx = 0;
|
|
60
|
+
for (var i = 0; i < visibleRowRanges.length; i++) {
|
|
61
|
+
if (visibleRowRanges[i].end >= stopIndex) {
|
|
62
|
+
currentRangeIdx = i;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
while (stopIndex < rowCount - 1 && offset < maxOffset) {
|
|
67
|
+
var currentRange = visibleRowRanges[currentRangeIdx];
|
|
68
|
+
if (currentRange && stopIndex < currentRange.end) {
|
|
69
|
+
// Still within current visible range, move to next row
|
|
70
|
+
stopIndex++;
|
|
71
|
+
offset += (0, exports.getItemMetadata)({
|
|
72
|
+
itemType: ItemType.row,
|
|
73
|
+
rowHeight: rowHeight,
|
|
74
|
+
columnWidth: columnWidth,
|
|
75
|
+
index: stopIndex,
|
|
76
|
+
instanceProps: instanceProps,
|
|
77
|
+
scale: scale,
|
|
78
|
+
visibleRowRanges: visibleRowRanges,
|
|
79
|
+
}).size;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// At end of current range, jump to next visible range
|
|
83
|
+
currentRangeIdx++;
|
|
84
|
+
if (currentRangeIdx >= visibleRowRanges.length) {
|
|
85
|
+
// No more visible ranges
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
var nextRange = visibleRowRanges[currentRangeIdx];
|
|
89
|
+
stopIndex = nextRange.start;
|
|
90
|
+
offset = (0, exports.getItemMetadata)({
|
|
91
|
+
itemType: ItemType.row,
|
|
92
|
+
rowHeight: rowHeight,
|
|
93
|
+
columnWidth: columnWidth,
|
|
94
|
+
index: stopIndex,
|
|
95
|
+
instanceProps: instanceProps,
|
|
96
|
+
scale: scale,
|
|
97
|
+
visibleRowRanges: visibleRowRanges,
|
|
98
|
+
}).offset;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Fallback to original behavior
|
|
104
|
+
while (stopIndex < rowCount - 1 && offset < maxOffset) {
|
|
105
|
+
stopIndex++;
|
|
106
|
+
offset += (0, exports.getItemMetadata)({
|
|
107
|
+
itemType: ItemType.row,
|
|
108
|
+
rowHeight: rowHeight,
|
|
109
|
+
columnWidth: columnWidth,
|
|
110
|
+
index: stopIndex,
|
|
111
|
+
instanceProps: instanceProps,
|
|
112
|
+
scale: scale,
|
|
113
|
+
}).size;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return stopIndex;
|
|
117
|
+
};
|
|
118
|
+
exports.getRowStopIndexForStartIndex = getRowStopIndexForStartIndex;
|
|
119
|
+
var getColumnStartIndexForOffset = function (_a) {
|
|
120
|
+
var rowHeight = _a.rowHeight, columnWidth = _a.columnWidth, rowCount = _a.rowCount, columnCount = _a.columnCount, instanceProps = _a.instanceProps, offset = _a.offset, scale = _a.scale;
|
|
121
|
+
return findNearestItem({
|
|
122
|
+
itemType: ItemType.column,
|
|
123
|
+
rowHeight: rowHeight,
|
|
124
|
+
columnWidth: columnWidth,
|
|
125
|
+
rowCount: rowCount,
|
|
126
|
+
columnCount: columnCount,
|
|
127
|
+
instanceProps: instanceProps,
|
|
128
|
+
offset: offset,
|
|
129
|
+
scale: scale,
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
exports.getColumnStartIndexForOffset = getColumnStartIndexForOffset;
|
|
133
|
+
var getColumnStopIndexForStartIndex = function (_a) {
|
|
134
|
+
var startIndex = _a.startIndex, rowHeight = _a.rowHeight, columnWidth = _a.columnWidth, instanceProps = _a.instanceProps, containerWidth = _a.containerWidth, scrollLeft = _a.scrollLeft, columnCount = _a.columnCount, scale = _a.scale;
|
|
135
|
+
var itemMetadata = (0, exports.getItemMetadata)({
|
|
136
|
+
itemType: ItemType.column,
|
|
137
|
+
index: startIndex,
|
|
138
|
+
rowHeight: rowHeight,
|
|
139
|
+
columnWidth: columnWidth,
|
|
140
|
+
instanceProps: instanceProps,
|
|
141
|
+
scale: scale,
|
|
142
|
+
});
|
|
143
|
+
var maxOffset = scrollLeft + containerWidth;
|
|
144
|
+
var offset = itemMetadata.offset + itemMetadata.size;
|
|
145
|
+
var stopIndex = startIndex;
|
|
146
|
+
while (stopIndex < columnCount - 1 && offset < maxOffset) {
|
|
147
|
+
stopIndex++;
|
|
148
|
+
offset += (0, exports.getItemMetadata)({
|
|
149
|
+
itemType: ItemType.column,
|
|
150
|
+
rowHeight: rowHeight,
|
|
151
|
+
columnWidth: columnWidth,
|
|
152
|
+
index: stopIndex,
|
|
153
|
+
instanceProps: instanceProps,
|
|
154
|
+
scale: scale,
|
|
155
|
+
}).size;
|
|
156
|
+
}
|
|
157
|
+
return stopIndex;
|
|
158
|
+
};
|
|
159
|
+
exports.getColumnStopIndexForStartIndex = getColumnStopIndexForStartIndex;
|
|
160
|
+
var getBoundedCells = function (area) {
|
|
161
|
+
var cells = new Set();
|
|
162
|
+
if (!area)
|
|
163
|
+
return cells;
|
|
164
|
+
var top = area.startRowIndex, left = area.startColumnIndex, right = area.endColumnIndex, bottom = area.endRowIndex;
|
|
165
|
+
for (var i = top; i <= bottom; i++) {
|
|
166
|
+
for (var j = left; j <= right; j++) {
|
|
167
|
+
cells.add((0, exports.cellIdentifier)(i, j));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return cells;
|
|
171
|
+
};
|
|
172
|
+
exports.getBoundedCells = getBoundedCells;
|
|
173
|
+
var itemKey = function (_a) {
|
|
174
|
+
var rowIndex = _a.rowIndex, columnIndex = _a.columnIndex;
|
|
175
|
+
return "".concat(rowIndex, ":").concat(columnIndex);
|
|
176
|
+
};
|
|
177
|
+
exports.itemKey = itemKey;
|
|
178
|
+
var getRowOffset = function (_a) {
|
|
179
|
+
var index = _a.index, rowHeight = _a.rowHeight, columnWidth = _a.columnWidth, instanceProps = _a.instanceProps, scale = _a.scale, readonly = _a.readonly, visibleRowRanges = _a.visibleRowRanges;
|
|
180
|
+
return (0, exports.getItemMetadata)({
|
|
181
|
+
itemType: ItemType.row,
|
|
182
|
+
index: index,
|
|
183
|
+
rowHeight: rowHeight,
|
|
184
|
+
columnWidth: columnWidth,
|
|
185
|
+
instanceProps: instanceProps,
|
|
186
|
+
scale: scale,
|
|
187
|
+
readonly: readonly,
|
|
188
|
+
visibleRowRanges: visibleRowRanges,
|
|
189
|
+
}).offset;
|
|
190
|
+
};
|
|
191
|
+
exports.getRowOffset = getRowOffset;
|
|
192
|
+
var getColumnOffset = function (_a) {
|
|
193
|
+
var index = _a.index, rowHeight = _a.rowHeight, columnWidth = _a.columnWidth, instanceProps = _a.instanceProps, scale = _a.scale, readonly = _a.readonly;
|
|
194
|
+
return (0, exports.getItemMetadata)({
|
|
195
|
+
itemType: ItemType.column,
|
|
196
|
+
index: index,
|
|
197
|
+
rowHeight: rowHeight,
|
|
198
|
+
columnWidth: columnWidth,
|
|
199
|
+
instanceProps: instanceProps,
|
|
200
|
+
scale: scale,
|
|
201
|
+
readonly: readonly,
|
|
202
|
+
}).offset;
|
|
203
|
+
};
|
|
204
|
+
exports.getColumnOffset = getColumnOffset;
|
|
205
|
+
var getRowHeight = function (index, instanceProps) {
|
|
206
|
+
var _a, _b;
|
|
207
|
+
return (_b = (_a = instanceProps.rowMetadataMap.get(index)) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0;
|
|
208
|
+
};
|
|
209
|
+
exports.getRowHeight = getRowHeight;
|
|
210
|
+
var getColumnWidth = function (index, instanceProps) {
|
|
211
|
+
var _a, _b;
|
|
212
|
+
return (_b = (_a = instanceProps.columnMetadataMap.get(index)) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0;
|
|
213
|
+
};
|
|
214
|
+
exports.getColumnWidth = getColumnWidth;
|
|
215
|
+
var getItemMetadata = function (_a) {
|
|
216
|
+
var itemType = _a.itemType, index = _a.index, rowHeight = _a.rowHeight, columnWidth = _a.columnWidth, instanceProps = _a.instanceProps, _b = _a.scale, scale = _b === void 0 ? 1 : _b, readonly = _a.readonly, visibleRowRanges = _a.visibleRowRanges;
|
|
217
|
+
var itemMetadataMap, itemSize, lastMeasuredIndex, recalcIndices;
|
|
218
|
+
if (itemType === "column") {
|
|
219
|
+
itemMetadataMap = instanceProps.columnMetadataMap;
|
|
220
|
+
itemSize = columnWidth;
|
|
221
|
+
lastMeasuredIndex = instanceProps.lastMeasuredColumnIndex;
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
itemMetadataMap = instanceProps.rowMetadataMap;
|
|
225
|
+
itemSize = rowHeight;
|
|
226
|
+
lastMeasuredIndex = instanceProps.lastMeasuredRowIndex;
|
|
227
|
+
}
|
|
228
|
+
if (index > lastMeasuredIndex) {
|
|
229
|
+
var offset = 0;
|
|
230
|
+
if (lastMeasuredIndex >= 0) {
|
|
231
|
+
var itemMetadata = itemMetadataMap.get(lastMeasuredIndex);
|
|
232
|
+
if (itemMetadata) {
|
|
233
|
+
offset = itemMetadata.offset + itemMetadata.size;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// If visibleRowRanges provided for rows, skip expensive itemSize() calls for hidden rows
|
|
237
|
+
// We still store metadata for all rows (required by binary search), but hidden rows get size=0
|
|
238
|
+
if (itemType === "row" && visibleRowRanges && visibleRowRanges.length > 0) {
|
|
239
|
+
// Build a quick lookup for which ranges we're in
|
|
240
|
+
var rangeIdx = 0;
|
|
241
|
+
for (var i = lastMeasuredIndex + 1; i <= index; i++) {
|
|
242
|
+
// Advance to the appropriate range
|
|
243
|
+
while (rangeIdx < visibleRowRanges.length && visibleRowRanges[rangeIdx].end < i) {
|
|
244
|
+
rangeIdx++;
|
|
245
|
+
}
|
|
246
|
+
// Check if i is in the current range (visible) or in a gap (hidden)
|
|
247
|
+
var currentRange = visibleRowRanges[rangeIdx];
|
|
248
|
+
var isVisible = currentRange && i >= currentRange.start && i <= currentRange.end;
|
|
249
|
+
// Only call itemSize for visible rows - hidden rows have size 0
|
|
250
|
+
var size = isVisible ? itemSize(i) * scale : 0;
|
|
251
|
+
itemMetadataMap.set(i, { offset: offset, size: size });
|
|
252
|
+
offset += size;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
// Original behavior for columns or when no visibleRowRanges
|
|
257
|
+
for (var i = lastMeasuredIndex + 1; i <= index; i++) {
|
|
258
|
+
var size = itemSize(i) * scale;
|
|
259
|
+
itemMetadataMap.set(i, {
|
|
260
|
+
offset: offset,
|
|
261
|
+
size: size,
|
|
262
|
+
});
|
|
263
|
+
offset += size;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (!readonly) {
|
|
267
|
+
if (itemType === "column") {
|
|
268
|
+
instanceProps.lastMeasuredColumnIndex = index;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
instanceProps.lastMeasuredRowIndex = index;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return itemMetadataMap.get(index);
|
|
276
|
+
};
|
|
277
|
+
exports.getItemMetadata = getItemMetadata;
|
|
278
|
+
var findNearestItem = function (_a) {
|
|
279
|
+
var _b, _c;
|
|
280
|
+
var itemType = _a.itemType, rowHeight = _a.rowHeight, columnWidth = _a.columnWidth, rowCount = _a.rowCount, columnCount = _a.columnCount, instanceProps = _a.instanceProps, offset = _a.offset, scale = _a.scale;
|
|
281
|
+
var itemMetadataMap, lastMeasuredIndex;
|
|
282
|
+
if (itemType === "column") {
|
|
283
|
+
itemMetadataMap = instanceProps.columnMetadataMap;
|
|
284
|
+
lastMeasuredIndex = instanceProps.lastMeasuredColumnIndex;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
itemMetadataMap = instanceProps.rowMetadataMap;
|
|
288
|
+
lastMeasuredIndex = instanceProps.lastMeasuredRowIndex;
|
|
289
|
+
}
|
|
290
|
+
var lastMeasuredItemOffset = lastMeasuredIndex > 0
|
|
291
|
+
? (_c = (_b = itemMetadataMap.get(lastMeasuredIndex)) === null || _b === void 0 ? void 0 : _b.offset) !== null && _c !== void 0 ? _c : 0
|
|
292
|
+
: 0;
|
|
293
|
+
if (lastMeasuredItemOffset >= offset) {
|
|
294
|
+
// If we've already measured items within this range just use a binary search as it's faster.
|
|
295
|
+
return findNearestItemBinarySearch({
|
|
296
|
+
itemType: itemType,
|
|
297
|
+
rowHeight: rowHeight,
|
|
298
|
+
columnWidth: columnWidth,
|
|
299
|
+
instanceProps: instanceProps,
|
|
300
|
+
high: lastMeasuredIndex,
|
|
301
|
+
low: 0,
|
|
302
|
+
offset: offset,
|
|
303
|
+
scale: scale,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
// If we haven't yet measured this high, fallback to an exponential search with an inner binary search.
|
|
308
|
+
// The exponential search avoids pre-computing sizes for the full set of items as a binary search would.
|
|
309
|
+
// The overall complexity for this approach is O(log n).
|
|
310
|
+
return findNearestItemExponentialSearch({
|
|
311
|
+
itemType: itemType,
|
|
312
|
+
rowHeight: rowHeight,
|
|
313
|
+
rowCount: rowCount,
|
|
314
|
+
columnCount: columnCount,
|
|
315
|
+
columnWidth: columnWidth,
|
|
316
|
+
instanceProps: instanceProps,
|
|
317
|
+
index: Math.max(0, lastMeasuredIndex),
|
|
318
|
+
offset: offset,
|
|
319
|
+
scale: scale,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
var findNearestItemBinarySearch = function (_a) {
|
|
324
|
+
var itemType = _a.itemType, rowHeight = _a.rowHeight, columnWidth = _a.columnWidth, instanceProps = _a.instanceProps, high = _a.high, low = _a.low, offset = _a.offset, scale = _a.scale;
|
|
325
|
+
while (low <= high) {
|
|
326
|
+
var middle = low + Math.floor((high - low) / 2);
|
|
327
|
+
var currentOffset = (0, exports.getItemMetadata)({
|
|
328
|
+
itemType: itemType,
|
|
329
|
+
rowHeight: rowHeight,
|
|
330
|
+
columnWidth: columnWidth,
|
|
331
|
+
index: middle,
|
|
332
|
+
instanceProps: instanceProps,
|
|
333
|
+
scale: scale,
|
|
334
|
+
}).offset;
|
|
335
|
+
if (currentOffset === offset) {
|
|
336
|
+
return middle;
|
|
337
|
+
}
|
|
338
|
+
else if (currentOffset < offset) {
|
|
339
|
+
low = middle + 1;
|
|
340
|
+
}
|
|
341
|
+
else if (currentOffset > offset) {
|
|
342
|
+
high = middle - 1;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (low > 0) {
|
|
346
|
+
return low - 1;
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
return 0;
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
var findNearestItemExponentialSearch = function (_a) {
|
|
353
|
+
var itemType = _a.itemType, rowHeight = _a.rowHeight, columnWidth = _a.columnWidth, rowCount = _a.rowCount, columnCount = _a.columnCount, instanceProps = _a.instanceProps, index = _a.index, offset = _a.offset, scale = _a.scale;
|
|
354
|
+
var itemCount = itemType === "column" ? columnCount : rowCount;
|
|
355
|
+
var interval = 1;
|
|
356
|
+
while (index < itemCount &&
|
|
357
|
+
(0, exports.getItemMetadata)({
|
|
358
|
+
itemType: itemType,
|
|
359
|
+
rowHeight: rowHeight,
|
|
360
|
+
columnWidth: columnWidth,
|
|
361
|
+
index: index,
|
|
362
|
+
instanceProps: instanceProps,
|
|
363
|
+
scale: scale,
|
|
364
|
+
}).offset < offset) {
|
|
365
|
+
index += interval;
|
|
366
|
+
interval *= 2;
|
|
367
|
+
}
|
|
368
|
+
return findNearestItemBinarySearch({
|
|
369
|
+
itemType: itemType,
|
|
370
|
+
rowHeight: rowHeight,
|
|
371
|
+
columnWidth: columnWidth,
|
|
372
|
+
instanceProps: instanceProps,
|
|
373
|
+
high: Math.min(index, itemCount - 1),
|
|
374
|
+
low: Math.floor(index / 2),
|
|
375
|
+
offset: offset,
|
|
376
|
+
scale: scale,
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
var getEstimatedTotalHeight = function (rowCount, instanceProps) {
|
|
380
|
+
var estimatedRowHeight = instanceProps.estimatedRowHeight;
|
|
381
|
+
var totalSizeOfMeasuredRows = 0;
|
|
382
|
+
var lastMeasuredRowIndex = instanceProps.lastMeasuredRowIndex;
|
|
383
|
+
var rowMetadataMap = instanceProps.rowMetadataMap;
|
|
384
|
+
// Edge case check for when the number of items decreases while a scroll is in progress.
|
|
385
|
+
// https://github.com/bvaughn/react-window/pull/138
|
|
386
|
+
if (lastMeasuredRowIndex >= rowCount) {
|
|
387
|
+
lastMeasuredRowIndex = rowCount - 1;
|
|
388
|
+
}
|
|
389
|
+
if (lastMeasuredRowIndex >= 0) {
|
|
390
|
+
var itemMetadata = rowMetadataMap.get(lastMeasuredRowIndex);
|
|
391
|
+
if (itemMetadata) {
|
|
392
|
+
totalSizeOfMeasuredRows = itemMetadata.offset + itemMetadata.size;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
var numUnmeasuredItems = rowCount - lastMeasuredRowIndex - 1;
|
|
396
|
+
var totalSizeOfUnmeasuredItems = numUnmeasuredItems * estimatedRowHeight;
|
|
397
|
+
return totalSizeOfMeasuredRows + totalSizeOfUnmeasuredItems;
|
|
398
|
+
};
|
|
399
|
+
exports.getEstimatedTotalHeight = getEstimatedTotalHeight;
|
|
400
|
+
var getEstimatedTotalWidth = function (columnCount, instanceProps) {
|
|
401
|
+
var estimatedColumnWidth = instanceProps.estimatedColumnWidth;
|
|
402
|
+
var totalSizeOfMeasuredRows = 0;
|
|
403
|
+
var lastMeasuredColumnIndex = instanceProps.lastMeasuredColumnIndex;
|
|
404
|
+
var columnMetadataMap = instanceProps.columnMetadataMap;
|
|
405
|
+
// Edge case check for when the number of items decreases while a scroll is in progress.
|
|
406
|
+
// https://github.com/bvaughn/react-window/pull/138
|
|
407
|
+
if (lastMeasuredColumnIndex >= columnCount) {
|
|
408
|
+
lastMeasuredColumnIndex = columnCount - 1;
|
|
409
|
+
}
|
|
410
|
+
if (lastMeasuredColumnIndex >= 0) {
|
|
411
|
+
var itemMetadata = columnMetadataMap.get(lastMeasuredColumnIndex);
|
|
412
|
+
if (itemMetadata) {
|
|
413
|
+
totalSizeOfMeasuredRows = itemMetadata.offset + itemMetadata.size;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
var numUnmeasuredItems = columnCount - lastMeasuredColumnIndex - 1;
|
|
417
|
+
var totalSizeOfUnmeasuredItems = numUnmeasuredItems * estimatedColumnWidth;
|
|
418
|
+
return totalSizeOfMeasuredRows + totalSizeOfUnmeasuredItems;
|
|
419
|
+
};
|
|
420
|
+
exports.getEstimatedTotalWidth = getEstimatedTotalWidth;
|
|
421
|
+
/* Create a stringified cell identifier */
|
|
422
|
+
var cellIdentifier = function (rowIndex, columnIndex) {
|
|
423
|
+
return "".concat(rowIndex, ",").concat(columnIndex);
|
|
424
|
+
};
|
|
425
|
+
exports.cellIdentifier = cellIdentifier;
|
|
426
|
+
/**
|
|
427
|
+
* @desc Throttle fn
|
|
428
|
+
* @param func function
|
|
429
|
+
* @param limit Delay in milliseconds
|
|
430
|
+
*/
|
|
431
|
+
function throttle(func, limit) {
|
|
432
|
+
var lastEventTimestamp = null;
|
|
433
|
+
var callable = function () {
|
|
434
|
+
var args = [];
|
|
435
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
436
|
+
args[_i] = arguments[_i];
|
|
437
|
+
}
|
|
438
|
+
var now = Date.now();
|
|
439
|
+
if (!lastEventTimestamp || now - lastEventTimestamp >= limit) {
|
|
440
|
+
lastEventTimestamp = now;
|
|
441
|
+
func.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(args), false));
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
return callable;
|
|
445
|
+
}
|
|
446
|
+
function debounce(cb, wait) {
|
|
447
|
+
if (wait === void 0) { wait = 300; }
|
|
448
|
+
var h = 0;
|
|
449
|
+
var callable = function () {
|
|
450
|
+
var args = [];
|
|
451
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
452
|
+
args[_i] = arguments[_i];
|
|
453
|
+
}
|
|
454
|
+
clearTimeout(h);
|
|
455
|
+
h = window.setTimeout(function () { return cb.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(args), false)); }, wait);
|
|
456
|
+
};
|
|
457
|
+
return callable;
|
|
458
|
+
}
|
|
459
|
+
function rafThrottle(callback) {
|
|
460
|
+
var active = false; // a simple flag
|
|
461
|
+
var evt; // to keep track of the last event
|
|
462
|
+
var handler = function () {
|
|
463
|
+
// fired only when screen has refreshed
|
|
464
|
+
active = false; // release our flag
|
|
465
|
+
callback(evt);
|
|
466
|
+
};
|
|
467
|
+
return function handleEvent(e) {
|
|
468
|
+
// the actual event handler
|
|
469
|
+
evt = e; // save our event at each call
|
|
470
|
+
evt && evt.persist && evt.persist();
|
|
471
|
+
if (!active) {
|
|
472
|
+
// only if we weren't already doing it
|
|
473
|
+
active = true; // raise the flag
|
|
474
|
+
requestAnimationFrame(handler); // wait for next screen refresh
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
var scheduleIdlePriorityCallback = function (callback) {
|
|
479
|
+
return (0, scheduler_1.unstable_scheduleCallback)(scheduler_1.unstable_IdlePriority, callback);
|
|
480
|
+
};
|
|
481
|
+
exports.scheduleIdlePriorityCallback = scheduleIdlePriorityCallback;
|
|
482
|
+
function ricThrottle(callback) {
|
|
483
|
+
var active = false; // a simple flag
|
|
484
|
+
var evt; // to keep track of the last event
|
|
485
|
+
var handler = function () {
|
|
486
|
+
// fired only when screen has refreshed
|
|
487
|
+
active = false; // release our flag
|
|
488
|
+
callback(evt);
|
|
489
|
+
};
|
|
490
|
+
return function handleEvent(e) {
|
|
491
|
+
// the actual event handler
|
|
492
|
+
evt = e; // save our event at each call
|
|
493
|
+
evt && evt.persist && evt.persist();
|
|
494
|
+
if (!active) {
|
|
495
|
+
// only if we weren't already doing it
|
|
496
|
+
active = true; // raise the flag
|
|
497
|
+
(0, exports.scheduleIdlePriorityCallback)(handler); // wait for next screen refresh
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
var getOffsetForIndexAndAlignment = function (_a) {
|
|
502
|
+
var itemType = _a.itemType, containerHeight = _a.containerHeight, containerWidth = _a.containerWidth, rowHeight = _a.rowHeight, columnWidth = _a.columnWidth, columnCount = _a.columnCount, rowCount = _a.rowCount, index = _a.index, _b = _a.align, align = _b === void 0 ? Align.smart : _b, scrollOffset = _a.scrollOffset, instanceProps = _a.instanceProps, scrollbarSize = _a.scrollbarSize, _c = _a.frozenOffset, frozenOffset = _c === void 0 ? 0 : _c, scale = _a.scale, estimatedTotalHeight = _a.estimatedTotalHeight, estimatedTotalWidth = _a.estimatedTotalWidth;
|
|
503
|
+
var size = itemType === "column" ? containerWidth : containerHeight;
|
|
504
|
+
var itemMetadata = (0, exports.getItemMetadata)({
|
|
505
|
+
itemType: itemType,
|
|
506
|
+
rowHeight: rowHeight,
|
|
507
|
+
columnWidth: columnWidth,
|
|
508
|
+
index: index,
|
|
509
|
+
instanceProps: instanceProps,
|
|
510
|
+
scale: scale,
|
|
511
|
+
});
|
|
512
|
+
// Get estimated total size after ItemMetadata is computed,
|
|
513
|
+
// To ensure it reflects actual measurements instead of just estimates.
|
|
514
|
+
var estimatedTotalSize = itemType === "column" ? estimatedTotalWidth : estimatedTotalHeight;
|
|
515
|
+
var maxOffset = Math.max(0, Math.min(estimatedTotalSize - size + scrollbarSize, itemMetadata.offset - frozenOffset));
|
|
516
|
+
var minOffset = Math.max(0, itemMetadata.offset - size + scrollbarSize + itemMetadata.size);
|
|
517
|
+
if (align === Align.smart) {
|
|
518
|
+
if (scrollOffset >= minOffset - size && scrollOffset <= maxOffset + size) {
|
|
519
|
+
align = Align.auto;
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
align = Align.center;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
switch (align) {
|
|
526
|
+
case Align.start:
|
|
527
|
+
return maxOffset;
|
|
528
|
+
case Align.end:
|
|
529
|
+
return minOffset;
|
|
530
|
+
case Align.center:
|
|
531
|
+
return Math.round(minOffset + (maxOffset - minOffset) / 2);
|
|
532
|
+
case Align.auto:
|
|
533
|
+
default:
|
|
534
|
+
if (scrollOffset >= minOffset && scrollOffset <= maxOffset) {
|
|
535
|
+
return scrollOffset;
|
|
536
|
+
}
|
|
537
|
+
else if (minOffset > maxOffset) {
|
|
538
|
+
// Because we only take into account the scrollbar size when calculating minOffset
|
|
539
|
+
// this value can be larger than maxOffset when at the end of the list
|
|
540
|
+
return minOffset;
|
|
541
|
+
}
|
|
542
|
+
else if (scrollOffset < minOffset) {
|
|
543
|
+
return minOffset;
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
return maxOffset;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
exports.getOffsetForIndexAndAlignment = getOffsetForIndexAndAlignment;
|
|
551
|
+
var getOffsetForColumnAndAlignment = function (props) {
|
|
552
|
+
return (0, exports.getOffsetForIndexAndAlignment)(tslib_1.__assign({ itemType: ItemType.column }, props));
|
|
553
|
+
};
|
|
554
|
+
exports.getOffsetForColumnAndAlignment = getOffsetForColumnAndAlignment;
|
|
555
|
+
var getOffsetForRowAndAlignment = function (props) {
|
|
556
|
+
return (0, exports.getOffsetForIndexAndAlignment)(tslib_1.__assign({ itemType: ItemType.row }, props));
|
|
557
|
+
};
|
|
558
|
+
exports.getOffsetForRowAndAlignment = getOffsetForRowAndAlignment;
|
|
559
|
+
// Animation frame based implementation of setTimeout.
|
|
560
|
+
// Inspired by Joe Lambert, https://gist.github.com/joelambert/1002116#file-requesttimeout-js
|
|
561
|
+
var hasNativePerformanceNow = typeof performance === "object" && typeof performance.now === "function";
|
|
562
|
+
var now = hasNativePerformanceNow
|
|
563
|
+
? function () { return performance.now(); }
|
|
564
|
+
: function () { return Date.now(); };
|
|
565
|
+
function cancelTimeout(timeoutID) {
|
|
566
|
+
cancelAnimationFrame(timeoutID.id);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Create a throttler based on RAF
|
|
570
|
+
* @param callback
|
|
571
|
+
* @param delay
|
|
572
|
+
*/
|
|
573
|
+
function requestTimeout(callback, delay) {
|
|
574
|
+
var start = now();
|
|
575
|
+
function tick() {
|
|
576
|
+
if (now() - start >= delay) {
|
|
577
|
+
callback.call(null);
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
timeoutID.id = requestAnimationFrame(tick);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
var timeoutID = {
|
|
584
|
+
id: requestAnimationFrame(tick),
|
|
585
|
+
};
|
|
586
|
+
return timeoutID;
|
|
587
|
+
}
|
|
588
|
+
var selectionFromActiveCell = function (activeCell) {
|
|
589
|
+
if (!activeCell)
|
|
590
|
+
return [];
|
|
591
|
+
return [
|
|
592
|
+
{
|
|
593
|
+
range: {
|
|
594
|
+
startRowIndex: activeCell.rowIndex,
|
|
595
|
+
startColumnIndex: activeCell.columnIndex,
|
|
596
|
+
endRowIndex: activeCell.rowIndex,
|
|
597
|
+
endColumnIndex: activeCell.columnIndex,
|
|
598
|
+
},
|
|
599
|
+
},
|
|
600
|
+
];
|
|
601
|
+
};
|
|
602
|
+
exports.selectionFromActiveCell = selectionFromActiveCell;
|
|
603
|
+
/**
|
|
604
|
+
* Check if a selection are spans multiple cells
|
|
605
|
+
* @param sel
|
|
606
|
+
*/
|
|
607
|
+
var selectionSpansCells = function (sel) {
|
|
608
|
+
if (!sel)
|
|
609
|
+
return false;
|
|
610
|
+
return (sel.endRowIndex !== sel.startRowIndex ||
|
|
611
|
+
sel.startColumnIndex !== sel.endColumnIndex);
|
|
612
|
+
};
|
|
613
|
+
exports.selectionSpansCells = selectionSpansCells;
|
|
614
|
+
/**
|
|
615
|
+
* When user tries to drag a selection
|
|
616
|
+
* @param initialSelection
|
|
617
|
+
* @param from
|
|
618
|
+
* @param to
|
|
619
|
+
*/
|
|
620
|
+
var newSelectionFromDrag = function (initialSelection, from, to, topBound, leftBound, rowCount, columnCount) {
|
|
621
|
+
if (topBound === void 0) { topBound = 0; }
|
|
622
|
+
if (leftBound === void 0) { leftBound = 0; }
|
|
623
|
+
var currentBounds = initialSelection.range;
|
|
624
|
+
var startRowIndex = Math.max(topBound, Math.min(rowCount, to.rowIndex + currentBounds.startRowIndex - from.rowIndex));
|
|
625
|
+
var startColumnIndex = Math.max(leftBound, Math.min(columnCount, to.columnIndex + currentBounds.startColumnIndex - from.columnIndex));
|
|
626
|
+
return {
|
|
627
|
+
range: {
|
|
628
|
+
startRowIndex: startRowIndex,
|
|
629
|
+
startColumnIndex: startColumnIndex,
|
|
630
|
+
endRowIndex: startRowIndex +
|
|
631
|
+
(currentBounds.endRowIndex - currentBounds.startRowIndex),
|
|
632
|
+
endColumnIndex: startColumnIndex +
|
|
633
|
+
(currentBounds.endColumnIndex - currentBounds.startColumnIndex),
|
|
634
|
+
},
|
|
635
|
+
};
|
|
636
|
+
};
|
|
637
|
+
exports.newSelectionFromDrag = newSelectionFromDrag;
|
|
638
|
+
/**
|
|
639
|
+
* Clamp cell coordinates to be inside activeCell and selection
|
|
640
|
+
* @param coords
|
|
641
|
+
* @param activeCell
|
|
642
|
+
* @param selection
|
|
643
|
+
*/
|
|
644
|
+
var clampCellCoords = function (coords, activeCell, selection) {
|
|
645
|
+
if (activeCell) {
|
|
646
|
+
coords.rowIndex = Math.max(activeCell.rowIndex, coords.rowIndex);
|
|
647
|
+
coords.columnIndex = Math.min(activeCell.columnIndex, coords.columnIndex);
|
|
648
|
+
}
|
|
649
|
+
if (selection) {
|
|
650
|
+
coords.rowIndex = Math.min(selection.range.endRowIndex, Math.max(selection.range.startRowIndex, coords.rowIndex));
|
|
651
|
+
coords.columnIndex = Math.min(selection.range.endColumnIndex, Math.max(selection.range.startColumnIndex, coords.columnIndex));
|
|
652
|
+
}
|
|
653
|
+
return coords;
|
|
654
|
+
};
|
|
655
|
+
exports.clampCellCoords = clampCellCoords;
|
|
656
|
+
/**
|
|
657
|
+
* Converts a number to alphabet
|
|
658
|
+
* @param i
|
|
659
|
+
*/
|
|
660
|
+
var numberToAlphabet = function (i) {
|
|
661
|
+
return ((i >= 26 ? (0, exports.numberToAlphabet)(((i / 26) >> 0) - 1) : "") +
|
|
662
|
+
"abcdefghijklmnopqrstuvwxyz"[i % 26 >> 0]).toUpperCase();
|
|
663
|
+
};
|
|
664
|
+
exports.numberToAlphabet = numberToAlphabet;
|
|
665
|
+
/**
|
|
666
|
+
* Convert selections to html and csv data
|
|
667
|
+
* @param rows
|
|
668
|
+
*/
|
|
669
|
+
var prepareClipboardData = function (rows) {
|
|
670
|
+
var html = ["<table>"];
|
|
671
|
+
var csv = [];
|
|
672
|
+
var sanitizeCell = function (value) {
|
|
673
|
+
if ((0, exports.isNull)(value))
|
|
674
|
+
return "";
|
|
675
|
+
return value;
|
|
676
|
+
};
|
|
677
|
+
rows.forEach(function (row) {
|
|
678
|
+
html.push("<tr>");
|
|
679
|
+
var csvRow = [];
|
|
680
|
+
row.forEach(function (cell) {
|
|
681
|
+
var _a;
|
|
682
|
+
html.push("<td>".concat(sanitizeCell(cell), "</td>"));
|
|
683
|
+
csvRow.push("".concat((_a = (0, exports.castToString)(cell)) === null || _a === void 0 ? void 0 : _a.replace(/"/g, '""')));
|
|
684
|
+
});
|
|
685
|
+
csv.push(csvRow.join(","));
|
|
686
|
+
html.push("</tr>");
|
|
687
|
+
});
|
|
688
|
+
html.push("</table>");
|
|
689
|
+
return [html.join(""), csv.join("\n")];
|
|
690
|
+
};
|
|
691
|
+
exports.prepareClipboardData = prepareClipboardData;
|
|
692
|
+
/**
|
|
693
|
+
* Cycles active cell within selecton bounds
|
|
694
|
+
* @param activeCellBounds
|
|
695
|
+
* @param selectionBounds
|
|
696
|
+
* @param direction
|
|
697
|
+
*/
|
|
698
|
+
var findNextCellWithinBounds = function (activeCellBounds, selectionBounds, direction) {
|
|
699
|
+
if (direction === void 0) { direction = types_1.Direction.Right; }
|
|
700
|
+
var intersects = (0, exports.areaIntersects)(activeCellBounds, selectionBounds);
|
|
701
|
+
if (!intersects)
|
|
702
|
+
return null;
|
|
703
|
+
var rowIndex, columnIndex;
|
|
704
|
+
var nextActiveCell = null;
|
|
705
|
+
if (direction === types_1.Direction.Right) {
|
|
706
|
+
rowIndex = activeCellBounds.startRowIndex;
|
|
707
|
+
columnIndex = activeCellBounds.startColumnIndex + 1;
|
|
708
|
+
if (columnIndex > selectionBounds.endColumnIndex) {
|
|
709
|
+
rowIndex = rowIndex + 1;
|
|
710
|
+
columnIndex = selectionBounds.startColumnIndex;
|
|
711
|
+
if (rowIndex > selectionBounds.endRowIndex) {
|
|
712
|
+
rowIndex = selectionBounds.startRowIndex;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
nextActiveCell = { rowIndex: rowIndex, columnIndex: columnIndex };
|
|
716
|
+
}
|
|
717
|
+
if (direction === types_1.Direction.Left) {
|
|
718
|
+
rowIndex = activeCellBounds.endRowIndex;
|
|
719
|
+
columnIndex = activeCellBounds.startColumnIndex - 1;
|
|
720
|
+
if (columnIndex < selectionBounds.startColumnIndex) {
|
|
721
|
+
rowIndex = rowIndex - 1;
|
|
722
|
+
columnIndex = selectionBounds.endColumnIndex;
|
|
723
|
+
if (rowIndex < selectionBounds.startRowIndex) {
|
|
724
|
+
rowIndex = selectionBounds.endRowIndex;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
nextActiveCell = { rowIndex: rowIndex, columnIndex: columnIndex };
|
|
728
|
+
}
|
|
729
|
+
if (direction === types_1.Direction.Down) {
|
|
730
|
+
rowIndex = activeCellBounds.endRowIndex + 1;
|
|
731
|
+
columnIndex = activeCellBounds.startColumnIndex;
|
|
732
|
+
if (rowIndex > selectionBounds.endRowIndex) {
|
|
733
|
+
columnIndex = activeCellBounds.startColumnIndex + 1;
|
|
734
|
+
rowIndex = selectionBounds.startRowIndex;
|
|
735
|
+
if (columnIndex > selectionBounds.endColumnIndex) {
|
|
736
|
+
columnIndex = selectionBounds.startColumnIndex;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
nextActiveCell = { rowIndex: rowIndex, columnIndex: columnIndex };
|
|
740
|
+
}
|
|
741
|
+
if (direction === types_1.Direction.Up) {
|
|
742
|
+
rowIndex = activeCellBounds.startRowIndex - 1;
|
|
743
|
+
columnIndex = activeCellBounds.startColumnIndex;
|
|
744
|
+
if (rowIndex < selectionBounds.startRowIndex) {
|
|
745
|
+
columnIndex = activeCellBounds.startColumnIndex - 1;
|
|
746
|
+
rowIndex = selectionBounds.endRowIndex;
|
|
747
|
+
if (columnIndex < selectionBounds.startColumnIndex) {
|
|
748
|
+
columnIndex = selectionBounds.endColumnIndex;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
nextActiveCell = { rowIndex: rowIndex, columnIndex: columnIndex };
|
|
752
|
+
}
|
|
753
|
+
return nextActiveCell;
|
|
754
|
+
};
|
|
755
|
+
exports.findNextCellWithinBounds = findNextCellWithinBounds;
|
|
756
|
+
/**
|
|
757
|
+
* Check if 2 areas overlap
|
|
758
|
+
* @param area1
|
|
759
|
+
* @param area2
|
|
760
|
+
*/
|
|
761
|
+
var areaIntersects = function (area1, area2) {
|
|
762
|
+
if (!area2) {
|
|
763
|
+
return false;
|
|
764
|
+
}
|
|
765
|
+
if (area1.startColumnIndex > area2.endColumnIndex ||
|
|
766
|
+
area2.startColumnIndex > area1.endColumnIndex) {
|
|
767
|
+
return false;
|
|
768
|
+
}
|
|
769
|
+
if (area1.startRowIndex > area2.endRowIndex ||
|
|
770
|
+
area2.startRowIndex > area1.endRowIndex) {
|
|
771
|
+
return false;
|
|
772
|
+
}
|
|
773
|
+
return true;
|
|
774
|
+
};
|
|
775
|
+
exports.areaIntersects = areaIntersects;
|
|
776
|
+
/**
|
|
777
|
+
* Check if area is inside another area
|
|
778
|
+
* @param needle
|
|
779
|
+
* @param haystack
|
|
780
|
+
*/
|
|
781
|
+
var areaInsideArea = function (needle, haystack) {
|
|
782
|
+
return (needle.startRowIndex >= haystack.startRowIndex &&
|
|
783
|
+
needle.endRowIndex <= haystack.endRowIndex &&
|
|
784
|
+
needle.startColumnIndex >= haystack.startColumnIndex &&
|
|
785
|
+
needle.endColumnIndex <= haystack.endColumnIndex);
|
|
786
|
+
};
|
|
787
|
+
exports.areaInsideArea = areaInsideArea;
|
|
788
|
+
/**
|
|
789
|
+
* Check if two areas are equal
|
|
790
|
+
* @param area1
|
|
791
|
+
* @param area2
|
|
792
|
+
*/
|
|
793
|
+
var isAreasEqual = function (area1, area2) {
|
|
794
|
+
if (area1 === void 0 || area2 === void 0) {
|
|
795
|
+
return false;
|
|
796
|
+
}
|
|
797
|
+
return (area1.endRowIndex === area2.endRowIndex &&
|
|
798
|
+
area1.startRowIndex === area2.startRowIndex &&
|
|
799
|
+
area1.startColumnIndex === area2.startColumnIndex &&
|
|
800
|
+
area1.endColumnIndex === area2.endColumnIndex);
|
|
801
|
+
};
|
|
802
|
+
exports.isAreasEqual = isAreasEqual;
|
|
803
|
+
/**
|
|
804
|
+
* Get maximum bound of an area, caters to merged cells
|
|
805
|
+
* @param area
|
|
806
|
+
* @param boundGetter
|
|
807
|
+
*/
|
|
808
|
+
var extendAreaToMergedCells = function (_area, mergedCells) {
|
|
809
|
+
var e_1, _a;
|
|
810
|
+
var area = tslib_1.__assign({}, _area);
|
|
811
|
+
try {
|
|
812
|
+
for (var mergedCells_1 = tslib_1.__values(mergedCells), mergedCells_1_1 = mergedCells_1.next(); !mergedCells_1_1.done; mergedCells_1_1 = mergedCells_1.next()) {
|
|
813
|
+
var bounds = mergedCells_1_1.value;
|
|
814
|
+
if ((0, exports.areaIntersects)(area, bounds)) {
|
|
815
|
+
area.startRowIndex = Math.min(area.startRowIndex, bounds.startRowIndex);
|
|
816
|
+
area.endRowIndex = Math.max(area.endRowIndex, bounds.endRowIndex);
|
|
817
|
+
area.endColumnIndex = Math.max(area.endColumnIndex, bounds.endColumnIndex);
|
|
818
|
+
area.startColumnIndex = Math.min(area.startColumnIndex, bounds.startColumnIndex);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
823
|
+
finally {
|
|
824
|
+
try {
|
|
825
|
+
if (mergedCells_1_1 && !mergedCells_1_1.done && (_a = mergedCells_1.return)) _a.call(mergedCells_1);
|
|
826
|
+
}
|
|
827
|
+
finally { if (e_1) throw e_1.error; }
|
|
828
|
+
}
|
|
829
|
+
return area;
|
|
830
|
+
};
|
|
831
|
+
exports.extendAreaToMergedCells = extendAreaToMergedCells;
|
|
832
|
+
/**
|
|
833
|
+
* Convert 2 cells to bounds
|
|
834
|
+
* @param start
|
|
835
|
+
* @param end
|
|
836
|
+
* @returns
|
|
837
|
+
*
|
|
838
|
+
* 2 loops O(n)
|
|
839
|
+
*/
|
|
840
|
+
var cellRangeToBounds = function (start, end, spanMerges, getCellBounds, selectionLeftbound, selectionTopBound) {
|
|
841
|
+
if (spanMerges === void 0) { spanMerges = true; }
|
|
842
|
+
if (selectionLeftbound === void 0) { selectionLeftbound = 1; }
|
|
843
|
+
if (selectionTopBound === void 0) { selectionTopBound = 1; }
|
|
844
|
+
var top = Math.min(Math.max(selectionTopBound, start.rowIndex), Math.max(selectionTopBound, end.rowIndex));
|
|
845
|
+
var bottom = Math.max(start.rowIndex, end.rowIndex);
|
|
846
|
+
var left = Math.min(Math.max(selectionLeftbound, start.columnIndex), Math.max(selectionLeftbound, end.columnIndex));
|
|
847
|
+
var right = Math.max(start.columnIndex, end.columnIndex);
|
|
848
|
+
/**
|
|
849
|
+
* The idea is that
|
|
850
|
+
* We do 2 loops >
|
|
851
|
+
* Left to Right and then top to bottom
|
|
852
|
+
* => Find top cell and bottom cell and check
|
|
853
|
+
* if there are any merged cells at the edge
|
|
854
|
+
* Then keep extending our top and bottom bounds accordingly
|
|
855
|
+
*
|
|
856
|
+
* Same goes for Top to bottom
|
|
857
|
+
* => Find left most and right most cells
|
|
858
|
+
*/
|
|
859
|
+
if (spanMerges) {
|
|
860
|
+
for (var columnIndex = left; columnIndex <= right; columnIndex++) {
|
|
861
|
+
var topCell = getCellBounds({ rowIndex: top, columnIndex: columnIndex });
|
|
862
|
+
var bottomCell = getCellBounds({ rowIndex: bottom, columnIndex: columnIndex });
|
|
863
|
+
bottom = Math.max(topCell.endRowIndex, bottomCell.endRowIndex, bottom);
|
|
864
|
+
top = Math.min(topCell.startRowIndex, bottomCell.startRowIndex, top);
|
|
865
|
+
}
|
|
866
|
+
for (var rowIndex = top; rowIndex <= bottom; rowIndex++) {
|
|
867
|
+
var topCell = getCellBounds({ rowIndex: rowIndex, columnIndex: left });
|
|
868
|
+
var bottomCell = getCellBounds({ rowIndex: rowIndex, columnIndex: right });
|
|
869
|
+
right = Math.max(topCell.endColumnIndex, bottomCell.endColumnIndex, right);
|
|
870
|
+
left = Math.min(topCell.startColumnIndex, bottomCell.startColumnIndex, left);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
return {
|
|
874
|
+
startRowIndex: top,
|
|
875
|
+
startColumnIndex: left,
|
|
876
|
+
endColumnIndex: right,
|
|
877
|
+
endRowIndex: bottom,
|
|
878
|
+
};
|
|
879
|
+
};
|
|
880
|
+
exports.cellRangeToBounds = cellRangeToBounds;
|
|
881
|
+
/**
|
|
882
|
+
* Create a range out of a cell
|
|
883
|
+
* @param param0
|
|
884
|
+
* @returns
|
|
885
|
+
*/
|
|
886
|
+
var cellToArea = function (_a) {
|
|
887
|
+
var rowIndex = _a.rowIndex, columnIndex = _a.columnIndex;
|
|
888
|
+
return {
|
|
889
|
+
startRowIndex: rowIndex,
|
|
890
|
+
startColumnIndex: columnIndex,
|
|
891
|
+
endColumnIndex: columnIndex,
|
|
892
|
+
endRowIndex: rowIndex,
|
|
893
|
+
};
|
|
894
|
+
};
|
|
895
|
+
exports.cellToArea = cellToArea;
|
|
896
|
+
/**
|
|
897
|
+
* Check if its being rendered in Browser or SSR
|
|
898
|
+
*/
|
|
899
|
+
exports.canUseDOM = typeof window !== "undefined" &&
|
|
900
|
+
typeof document !== "undefined" &&
|
|
901
|
+
typeof window.document !== "undefined";
|
|
902
|
+
/**
|
|
903
|
+
* Make a font-family value safe for CSS font shorthand (canvas
|
|
904
|
+
* `ctx.font`). Family names that aren't a single safe identifier
|
|
905
|
+
* (leading digit, spaces with odd characters, slashes, …) must be
|
|
906
|
+
* quoted or the shorthand is invalid; generic families (sans-serif,
|
|
907
|
+
* serif, monospace, …) must stay unquoted to keep their generic
|
|
908
|
+
* meaning. Accepts a single family or a comma-separated stack.
|
|
909
|
+
*/
|
|
910
|
+
var toCssFontFamily = function (family) {
|
|
911
|
+
return family
|
|
912
|
+
.split(",")
|
|
913
|
+
.map(function (part) {
|
|
914
|
+
var trimmed = part.trim().replace(/^["']|["']$/g, "");
|
|
915
|
+
if (!trimmed)
|
|
916
|
+
return "";
|
|
917
|
+
return /^[a-zA-Z][a-zA-Z0-9-]*$/.test(trimmed)
|
|
918
|
+
? trimmed
|
|
919
|
+
: "\"".concat(trimmed.replace(/"/g, ""), "\"");
|
|
920
|
+
})
|
|
921
|
+
.filter(Boolean)
|
|
922
|
+
.join(", ");
|
|
923
|
+
};
|
|
924
|
+
exports.toCssFontFamily = toCssFontFamily;
|
|
925
|
+
var AutoSizerCanvas = function (defaults) {
|
|
926
|
+
if (defaults === void 0) { defaults = {}; }
|
|
927
|
+
var _a = defaults.fontFamily, fontFamily = _a === void 0 ? "Arial" : _a, _b = defaults.fontSize, fontSize = _b === void 0 ? 12 : _b, _c = defaults.fontWeight, fontWeight = _c === void 0 ? "" : _c, _d = defaults.fontStyle, fontStyle = _d === void 0 ? "" : _d, _e = defaults.lineHeight, lineHeight = _e === void 0 ? 16 : _e, _f = defaults.scale, scale = _f === void 0 ? 1 : _f;
|
|
928
|
+
var o = {
|
|
929
|
+
fontFamily: fontFamily,
|
|
930
|
+
fontSize: fontSize,
|
|
931
|
+
fontWeight: fontWeight,
|
|
932
|
+
fontStyle: fontStyle,
|
|
933
|
+
lineHeight: lineHeight,
|
|
934
|
+
scale: scale,
|
|
935
|
+
};
|
|
936
|
+
var canvas = exports.canUseDOM && document.createElement("canvas");
|
|
937
|
+
var context = canvas ? canvas.getContext("2d") : null;
|
|
938
|
+
var SegmenterCtor = typeof Intl !== "undefined" && "Segmenter" in Intl
|
|
939
|
+
? Intl.Segmenter
|
|
940
|
+
: undefined;
|
|
941
|
+
var wordSegmenter = SegmenterCtor
|
|
942
|
+
? new SegmenterCtor(undefined, { granularity: "word" })
|
|
943
|
+
: undefined;
|
|
944
|
+
var graphemeSegmenter = SegmenterCtor
|
|
945
|
+
? new SegmenterCtor(undefined, { granularity: "grapheme" })
|
|
946
|
+
: undefined;
|
|
947
|
+
var setFont = function (options) {
|
|
948
|
+
var _a;
|
|
949
|
+
if (options === void 0) { options = {}; }
|
|
950
|
+
for (var key in options) {
|
|
951
|
+
o[key] = (_a = options[key]) !== null && _a !== void 0 ? _a : o[key];
|
|
952
|
+
}
|
|
953
|
+
if (context) {
|
|
954
|
+
// Canvas `ctx.font` takes CSS font shorthand — an unquoted family
|
|
955
|
+
// that needs quoting (leading digit, slash, …) makes the whole
|
|
956
|
+
// assignment silently no-op, so the sizer keeps measuring with the
|
|
957
|
+
// PREVIOUS font. Quote non-identifier families (generic families
|
|
958
|
+
// must stay unquoted) and always end on a sans-serif fallback so
|
|
959
|
+
// painter and sizer agree on unknown fonts.
|
|
960
|
+
var family = o.fontFamily
|
|
961
|
+
? "".concat((0, exports.toCssFontFamily)(String(o.fontFamily)), ", sans-serif")
|
|
962
|
+
: "sans-serif";
|
|
963
|
+
context.font = "".concat(o.fontStyle, " ").concat(o.fontWeight, " ").concat(o.fontSize * o.scale, "px ").concat(family);
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
var getWidthOfLongestText = function (text, shouldWrap, width) {
|
|
967
|
+
if (text == null) {
|
|
968
|
+
return { width: 0, height: 0 };
|
|
969
|
+
}
|
|
970
|
+
return getMultilineTextDimensions(text, shouldWrap, width);
|
|
971
|
+
};
|
|
972
|
+
// Get width and height of multi-line text
|
|
973
|
+
var getMultilineTextDimensions = function (text, shouldWrap, width) {
|
|
974
|
+
var e_2, _a;
|
|
975
|
+
var lines = text.split("\n");
|
|
976
|
+
var textWidth = 0;
|
|
977
|
+
// Keep this in-sync with the default line-height used by <Cell /> (1.15)
|
|
978
|
+
var lineHeightRatio = 1.2;
|
|
979
|
+
var lineHeightPx = o.fontSize * lineHeightRatio * o.scale;
|
|
980
|
+
var currentHeightPx = 0;
|
|
981
|
+
var maxWidth = width !== null && width !== void 0 ? width : 0;
|
|
982
|
+
var wrapAtWord = shouldWrap;
|
|
983
|
+
var SPACE = " ";
|
|
984
|
+
var DASH = "-";
|
|
985
|
+
var measureWidth = function (value) { var _a; return (_a = context === null || context === void 0 ? void 0 : context.measureText(value).width) !== null && _a !== void 0 ? _a : 0; };
|
|
986
|
+
var pushLine = function (content, clampToWidth) {
|
|
987
|
+
var normalized = content.replace(/\s+$/g, "");
|
|
988
|
+
var measured = normalized.length ? measureWidth(normalized) : 0;
|
|
989
|
+
var finalWidth = clampToWidth && maxWidth > 0 ? Math.min(measured, maxWidth) : measured;
|
|
990
|
+
textWidth = Math.max(textWidth, finalWidth);
|
|
991
|
+
currentHeightPx += lineHeightPx;
|
|
992
|
+
};
|
|
993
|
+
var getWordSegments = function (value) {
|
|
994
|
+
var _a;
|
|
995
|
+
if (wordSegmenter) {
|
|
996
|
+
return Array.from(wordSegmenter.segment(value), function (segment) { return segment.segment; });
|
|
997
|
+
}
|
|
998
|
+
return (_a = value.match(/\S+|\s+/g)) !== null && _a !== void 0 ? _a : [value];
|
|
999
|
+
};
|
|
1000
|
+
var getGraphemeSegments = function (value) {
|
|
1001
|
+
if (graphemeSegmenter) {
|
|
1002
|
+
return Array.from(graphemeSegmenter.segment(value), function (segment) { return segment.segment; });
|
|
1003
|
+
}
|
|
1004
|
+
return Array.from(value);
|
|
1005
|
+
};
|
|
1006
|
+
var splitSegment = function (segment) {
|
|
1007
|
+
var e_3, _a;
|
|
1008
|
+
if (maxWidth <= 0) {
|
|
1009
|
+
return [segment];
|
|
1010
|
+
}
|
|
1011
|
+
var graphemes = getGraphemeSegments(segment);
|
|
1012
|
+
var pieces = [];
|
|
1013
|
+
var buffer = "";
|
|
1014
|
+
try {
|
|
1015
|
+
for (var graphemes_1 = tslib_1.__values(graphemes), graphemes_1_1 = graphemes_1.next(); !graphemes_1_1.done; graphemes_1_1 = graphemes_1.next()) {
|
|
1016
|
+
var grapheme = graphemes_1_1.value;
|
|
1017
|
+
var tentative = buffer + grapheme;
|
|
1018
|
+
var tentativeWidth = measureWidth(tentative);
|
|
1019
|
+
if (tentativeWidth <= maxWidth || !buffer) {
|
|
1020
|
+
buffer = tentative;
|
|
1021
|
+
}
|
|
1022
|
+
else {
|
|
1023
|
+
pieces.push(buffer);
|
|
1024
|
+
buffer = grapheme;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1029
|
+
finally {
|
|
1030
|
+
try {
|
|
1031
|
+
if (graphemes_1_1 && !graphemes_1_1.done && (_a = graphemes_1.return)) _a.call(graphemes_1);
|
|
1032
|
+
}
|
|
1033
|
+
finally { if (e_3) throw e_3.error; }
|
|
1034
|
+
}
|
|
1035
|
+
if (buffer) {
|
|
1036
|
+
pieces.push(buffer);
|
|
1037
|
+
}
|
|
1038
|
+
return pieces;
|
|
1039
|
+
};
|
|
1040
|
+
var wrapLine = function (line) {
|
|
1041
|
+
var e_4, _a;
|
|
1042
|
+
var _b;
|
|
1043
|
+
if (!shouldWrap || maxWidth <= 0) {
|
|
1044
|
+
pushLine(line, false);
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
var segments = getWordSegments(line);
|
|
1048
|
+
var currentLine = "";
|
|
1049
|
+
try {
|
|
1050
|
+
for (var segments_1 = tslib_1.__values(segments), segments_1_1 = segments_1.next(); !segments_1_1.done; segments_1_1 = segments_1.next()) {
|
|
1051
|
+
var segment = segments_1_1.value;
|
|
1052
|
+
var tentative = currentLine + segment;
|
|
1053
|
+
var tentativeWidth = measureWidth(tentative);
|
|
1054
|
+
if (tentativeWidth <= maxWidth || tentative.trim().length === 0) {
|
|
1055
|
+
currentLine = tentative;
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
if (currentLine.trim().length) {
|
|
1059
|
+
pushLine(currentLine, true);
|
|
1060
|
+
currentLine = segment.trimStart();
|
|
1061
|
+
if (!currentLine.length) {
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
if (measureWidth(currentLine) > maxWidth) {
|
|
1065
|
+
var pieces_1 = splitSegment(currentLine);
|
|
1066
|
+
for (var i = 0; i < pieces_1.length - 1; i++) {
|
|
1067
|
+
pushLine(pieces_1[i], true);
|
|
1068
|
+
}
|
|
1069
|
+
currentLine = (_b = pieces_1[pieces_1.length - 1]) !== null && _b !== void 0 ? _b : "";
|
|
1070
|
+
}
|
|
1071
|
+
continue;
|
|
1072
|
+
}
|
|
1073
|
+
var trimmedSegment = segment.trim();
|
|
1074
|
+
var pieces = splitSegment(trimmedSegment);
|
|
1075
|
+
for (var i = 0; i < pieces.length; i++) {
|
|
1076
|
+
var piece = pieces[i];
|
|
1077
|
+
if (i === pieces.length - 1) {
|
|
1078
|
+
currentLine = piece;
|
|
1079
|
+
}
|
|
1080
|
+
else {
|
|
1081
|
+
pushLine(piece, true);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1087
|
+
finally {
|
|
1088
|
+
try {
|
|
1089
|
+
if (segments_1_1 && !segments_1_1.done && (_a = segments_1.return)) _a.call(segments_1);
|
|
1090
|
+
}
|
|
1091
|
+
finally { if (e_4) throw e_4.error; }
|
|
1092
|
+
}
|
|
1093
|
+
var trimmedLine = currentLine.trim();
|
|
1094
|
+
if (trimmedLine.length) {
|
|
1095
|
+
pushLine(trimmedLine, true);
|
|
1096
|
+
}
|
|
1097
|
+
else if (currentLine.length) {
|
|
1098
|
+
currentHeightPx += lineHeightPx;
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
try {
|
|
1102
|
+
for (var lines_1 = tslib_1.__values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
1103
|
+
var line = lines_1_1.value;
|
|
1104
|
+
wrapLine(line);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1108
|
+
finally {
|
|
1109
|
+
try {
|
|
1110
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
1111
|
+
}
|
|
1112
|
+
finally { if (e_2) throw e_2.error; }
|
|
1113
|
+
}
|
|
1114
|
+
return {
|
|
1115
|
+
width: textWidth,
|
|
1116
|
+
height: currentHeightPx,
|
|
1117
|
+
};
|
|
1118
|
+
};
|
|
1119
|
+
var measureText = function (text, shouldWrap, boundedWidth) { return getWidthOfLongestText((0, exports.castToString)(text), shouldWrap, boundedWidth); };
|
|
1120
|
+
var reset = function () { return setFont(defaults); };
|
|
1121
|
+
/* Set font in constructor */
|
|
1122
|
+
setFont(o);
|
|
1123
|
+
return {
|
|
1124
|
+
context: context,
|
|
1125
|
+
measureText: measureText,
|
|
1126
|
+
setFont: setFont,
|
|
1127
|
+
reset: reset,
|
|
1128
|
+
};
|
|
1129
|
+
};
|
|
1130
|
+
exports.AutoSizerCanvas = AutoSizerCanvas;
|
|
1131
|
+
/* Export a singleton */
|
|
1132
|
+
exports.autoSizerCanvas = (0, exports.AutoSizerCanvas)();
|
|
1133
|
+
/* Check if a value is null */
|
|
1134
|
+
var isNull = function (value) {
|
|
1135
|
+
return value === void 0 || value === null || value === "";
|
|
1136
|
+
};
|
|
1137
|
+
exports.isNull = isNull;
|
|
1138
|
+
var isEqualCells = function (a, b) {
|
|
1139
|
+
if ((0, exports.isNull)(a) ||
|
|
1140
|
+
(0, exports.isNull)(b) ||
|
|
1141
|
+
a === null ||
|
|
1142
|
+
b === null ||
|
|
1143
|
+
a === void 0 ||
|
|
1144
|
+
b === void 0)
|
|
1145
|
+
return false;
|
|
1146
|
+
return a.rowIndex === b.rowIndex && a.columnIndex === b.columnIndex;
|
|
1147
|
+
};
|
|
1148
|
+
exports.isEqualCells = isEqualCells;
|
|
1149
|
+
/**
|
|
1150
|
+
* Simple utility function to check if cell is within bounds
|
|
1151
|
+
* @param cell
|
|
1152
|
+
* @param bounds
|
|
1153
|
+
*/
|
|
1154
|
+
var isCellWithinBounds = function (cell, bounds) {
|
|
1155
|
+
if (!bounds) {
|
|
1156
|
+
return false;
|
|
1157
|
+
}
|
|
1158
|
+
if (cell.rowIndex < bounds.startRowIndex ||
|
|
1159
|
+
cell.rowIndex > bounds.endRowIndex) {
|
|
1160
|
+
return false;
|
|
1161
|
+
}
|
|
1162
|
+
if (cell.columnIndex < bounds.startColumnIndex ||
|
|
1163
|
+
cell.columnIndex > bounds.endColumnIndex) {
|
|
1164
|
+
return false;
|
|
1165
|
+
}
|
|
1166
|
+
return true;
|
|
1167
|
+
};
|
|
1168
|
+
exports.isCellWithinBounds = isCellWithinBounds;
|
|
1169
|
+
var clampIndex = function (index, isHidden, direction) {
|
|
1170
|
+
switch (direction) {
|
|
1171
|
+
case types_1.Direction.Right:
|
|
1172
|
+
case types_1.Direction.Down: {
|
|
1173
|
+
var hidden = isHidden === null || isHidden === void 0 ? void 0 : isHidden(index);
|
|
1174
|
+
while (hidden === true) {
|
|
1175
|
+
hidden = isHidden === null || isHidden === void 0 ? void 0 : isHidden(++index);
|
|
1176
|
+
}
|
|
1177
|
+
break;
|
|
1178
|
+
}
|
|
1179
|
+
case types_1.Direction.Left:
|
|
1180
|
+
case types_1.Direction.Up: {
|
|
1181
|
+
var hidden = isHidden === null || isHidden === void 0 ? void 0 : isHidden(index);
|
|
1182
|
+
while (hidden === true) {
|
|
1183
|
+
hidden = isHidden === null || isHidden === void 0 ? void 0 : isHidden(--index);
|
|
1184
|
+
}
|
|
1185
|
+
break;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
return Math.max(0, index);
|
|
1189
|
+
};
|
|
1190
|
+
exports.clampIndex = clampIndex;
|
|
1191
|
+
/**
|
|
1192
|
+
* Find a cell with content if the current cell is out of the current dataregion
|
|
1193
|
+
* [
|
|
1194
|
+
* 1, 2, 3,
|
|
1195
|
+
* x, x, x
|
|
1196
|
+
* 7, 8, 9
|
|
1197
|
+
* ]
|
|
1198
|
+
* activeCel = 2
|
|
1199
|
+
* direction = Down
|
|
1200
|
+
* New Cell = 8
|
|
1201
|
+
*
|
|
1202
|
+
* @param activeCell
|
|
1203
|
+
* @param getValue
|
|
1204
|
+
* @param isHidden
|
|
1205
|
+
* @param direction
|
|
1206
|
+
* @param limit
|
|
1207
|
+
*/
|
|
1208
|
+
var findNextContentfulCell = function (sheetId, activeCell, getValue, isHidden, direction, limit) {
|
|
1209
|
+
var rowIndex = activeCell.rowIndex, columnIndex = activeCell.columnIndex;
|
|
1210
|
+
switch (direction) {
|
|
1211
|
+
case types_1.Direction.Down: {
|
|
1212
|
+
rowIndex = (0, exports.clampIndex)(Math.min(rowIndex + 1, limit), isHidden, direction);
|
|
1213
|
+
while ((0, exports.isNull)(getValue(sheetId, rowIndex, columnIndex)) &&
|
|
1214
|
+
rowIndex < limit) {
|
|
1215
|
+
rowIndex = (0, exports.clampIndex)(Math.min(rowIndex + 1, limit), isHidden, direction);
|
|
1216
|
+
}
|
|
1217
|
+
return { rowIndex: rowIndex, columnIndex: columnIndex };
|
|
1218
|
+
}
|
|
1219
|
+
case types_1.Direction.Up: {
|
|
1220
|
+
rowIndex = (0, exports.clampIndex)(Math.max(rowIndex - 1, limit), isHidden, direction);
|
|
1221
|
+
while ((0, exports.isNull)(getValue(sheetId, rowIndex, columnIndex)) &&
|
|
1222
|
+
rowIndex > limit) {
|
|
1223
|
+
rowIndex = (0, exports.clampIndex)(Math.max(rowIndex - 1, limit), isHidden, direction);
|
|
1224
|
+
}
|
|
1225
|
+
return { rowIndex: rowIndex, columnIndex: columnIndex };
|
|
1226
|
+
}
|
|
1227
|
+
case types_1.Direction.Right: {
|
|
1228
|
+
columnIndex = (0, exports.clampIndex)(Math.min(columnIndex + 1, limit), isHidden, direction);
|
|
1229
|
+
while ((0, exports.isNull)(getValue(sheetId, rowIndex, columnIndex)) &&
|
|
1230
|
+
columnIndex < limit) {
|
|
1231
|
+
columnIndex = (0, exports.clampIndex)(Math.min(columnIndex + 1, limit), isHidden, direction);
|
|
1232
|
+
}
|
|
1233
|
+
return { rowIndex: rowIndex, columnIndex: columnIndex };
|
|
1234
|
+
}
|
|
1235
|
+
case types_1.Direction.Left: {
|
|
1236
|
+
columnIndex = (0, exports.clampIndex)(Math.max(columnIndex - 1, limit), isHidden, direction);
|
|
1237
|
+
while ((0, exports.isNull)(getValue(sheetId, rowIndex, columnIndex)) &&
|
|
1238
|
+
columnIndex > limit) {
|
|
1239
|
+
columnIndex = (0, exports.clampIndex)(Math.max(columnIndex - 1, limit), isHidden, direction);
|
|
1240
|
+
}
|
|
1241
|
+
return { rowIndex: rowIndex, columnIndex: columnIndex };
|
|
1242
|
+
}
|
|
1243
|
+
default:
|
|
1244
|
+
return activeCell;
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
exports.findNextContentfulCell = findNextContentfulCell;
|
|
1248
|
+
/**
|
|
1249
|
+
* Find the next cell
|
|
1250
|
+
* @param activeCell
|
|
1251
|
+
* @param getValue
|
|
1252
|
+
* @param isHidden
|
|
1253
|
+
* @param direction
|
|
1254
|
+
* @param limit
|
|
1255
|
+
*/
|
|
1256
|
+
var findLastContentfulCell = function (sheetId, activeCell, getValue, isHidden, direction, limit) {
|
|
1257
|
+
var rowIndex = activeCell.rowIndex, columnIndex = activeCell.columnIndex;
|
|
1258
|
+
switch (direction) {
|
|
1259
|
+
case types_1.Direction.Down: {
|
|
1260
|
+
while (!(0, exports.isNull)(getValue(sheetId, (0, exports.clampIndex)(Math.min(rowIndex + 1, limit), isHidden, direction), columnIndex)) &&
|
|
1261
|
+
rowIndex < limit) {
|
|
1262
|
+
(0, exports.clampIndex)(Math.min(++rowIndex, limit), isHidden, direction);
|
|
1263
|
+
}
|
|
1264
|
+
return {
|
|
1265
|
+
columnIndex: columnIndex,
|
|
1266
|
+
rowIndex: rowIndex,
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
case types_1.Direction.Up: {
|
|
1270
|
+
while (!(0, exports.isNull)(getValue(sheetId, (0, exports.clampIndex)(Math.max(rowIndex - 1, limit), isHidden, direction), columnIndex)) &&
|
|
1271
|
+
rowIndex > limit) {
|
|
1272
|
+
rowIndex = (0, exports.clampIndex)(Math.max(--rowIndex, limit), isHidden, direction);
|
|
1273
|
+
}
|
|
1274
|
+
return {
|
|
1275
|
+
columnIndex: columnIndex,
|
|
1276
|
+
rowIndex: rowIndex,
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
case types_1.Direction.Right: {
|
|
1280
|
+
while (!(0, exports.isNull)(getValue(sheetId, rowIndex, (0, exports.clampIndex)(Math.min(columnIndex + 1, limit), isHidden, direction))) &&
|
|
1281
|
+
columnIndex < limit) {
|
|
1282
|
+
columnIndex = (0, exports.clampIndex)(Math.min(++columnIndex, limit), isHidden, direction);
|
|
1283
|
+
}
|
|
1284
|
+
return {
|
|
1285
|
+
rowIndex: rowIndex,
|
|
1286
|
+
columnIndex: columnIndex,
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
case types_1.Direction.Left: {
|
|
1290
|
+
while (!(0, exports.isNull)(getValue(sheetId, rowIndex, (0, exports.clampIndex)(Math.max(columnIndex - 1, limit), isHidden, direction))) &&
|
|
1291
|
+
columnIndex > limit) {
|
|
1292
|
+
columnIndex = (0, exports.clampIndex)(Math.max(--columnIndex, limit), isHidden, direction);
|
|
1293
|
+
}
|
|
1294
|
+
return {
|
|
1295
|
+
rowIndex: rowIndex,
|
|
1296
|
+
columnIndex: columnIndex,
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
default:
|
|
1300
|
+
return activeCell;
|
|
1301
|
+
}
|
|
1302
|
+
};
|
|
1303
|
+
exports.findLastContentfulCell = findLastContentfulCell;
|
|
1304
|
+
/**
|
|
1305
|
+
* Ex
|
|
1306
|
+
*/
|
|
1307
|
+
var findNextCellInDataRegion = function (sheetId, activeCell, getValue, isHidden, direction, limit) {
|
|
1308
|
+
var rowIndex = activeCell.rowIndex, columnIndex = activeCell.columnIndex;
|
|
1309
|
+
var isCurrentCellEmpty = (0, exports.isNull)(getValue(sheetId, rowIndex, columnIndex));
|
|
1310
|
+
var didWeReachTheEdge = function (cur, next) {
|
|
1311
|
+
return (cur && next) || (cur && !next) || (!cur && next);
|
|
1312
|
+
};
|
|
1313
|
+
switch (direction) {
|
|
1314
|
+
case types_1.Direction.Down: {
|
|
1315
|
+
var nextIndex = (0, exports.clampIndex)(Math.min(rowIndex + 1, limit), isHidden, direction);
|
|
1316
|
+
var nextCellValue = getValue(sheetId, nextIndex, columnIndex);
|
|
1317
|
+
var isNextCellEmpty = (0, exports.isNull)(nextCellValue);
|
|
1318
|
+
var isEdge = didWeReachTheEdge(isCurrentCellEmpty, isNextCellEmpty);
|
|
1319
|
+
var nextCell = isEdge
|
|
1320
|
+
? (0, exports.findNextContentfulCell)(sheetId, activeCell, getValue, isHidden, direction, limit)
|
|
1321
|
+
: (0, exports.findLastContentfulCell)(sheetId, activeCell, getValue, isHidden, direction, limit);
|
|
1322
|
+
return nextCell === null || nextCell === void 0 ? void 0 : nextCell.rowIndex;
|
|
1323
|
+
}
|
|
1324
|
+
case types_1.Direction.Up: {
|
|
1325
|
+
var nextIndex = (0, exports.clampIndex)(Math.max(rowIndex - 1, limit), isHidden, direction);
|
|
1326
|
+
var nextCellValue = getValue(sheetId, nextIndex, columnIndex);
|
|
1327
|
+
var isNextCellEmpty = (0, exports.isNull)(nextCellValue);
|
|
1328
|
+
var isEdge = didWeReachTheEdge(isCurrentCellEmpty, isNextCellEmpty);
|
|
1329
|
+
var nextCell = isEdge
|
|
1330
|
+
? (0, exports.findNextContentfulCell)(sheetId, activeCell, getValue, isHidden, direction, limit)
|
|
1331
|
+
: (0, exports.findLastContentfulCell)(sheetId, activeCell, getValue, isHidden, direction, limit);
|
|
1332
|
+
return nextCell === null || nextCell === void 0 ? void 0 : nextCell.rowIndex;
|
|
1333
|
+
}
|
|
1334
|
+
case types_1.Direction.Right: {
|
|
1335
|
+
var nextIndex = (0, exports.clampIndex)(Math.min(columnIndex + 1, limit), isHidden, direction);
|
|
1336
|
+
var nextCellValue = getValue(sheetId, rowIndex, nextIndex);
|
|
1337
|
+
var isNextCellEmpty = (0, exports.isNull)(nextCellValue);
|
|
1338
|
+
var isEdge = didWeReachTheEdge(isCurrentCellEmpty, isNextCellEmpty);
|
|
1339
|
+
var nextCell = isEdge
|
|
1340
|
+
? (0, exports.findNextContentfulCell)(sheetId, activeCell, getValue, isHidden, direction, limit)
|
|
1341
|
+
: (0, exports.findLastContentfulCell)(sheetId, activeCell, getValue, isHidden, direction, limit);
|
|
1342
|
+
return nextCell === null || nextCell === void 0 ? void 0 : nextCell.columnIndex;
|
|
1343
|
+
}
|
|
1344
|
+
case types_1.Direction.Left: {
|
|
1345
|
+
var nextIndex = (0, exports.clampIndex)(Math.max(columnIndex - 1, limit), isHidden, direction);
|
|
1346
|
+
var nextCellValue = getValue(sheetId, rowIndex, nextIndex);
|
|
1347
|
+
var isNextCellEmpty = (0, exports.isNull)(nextCellValue);
|
|
1348
|
+
var isEdge = didWeReachTheEdge(isCurrentCellEmpty, isNextCellEmpty);
|
|
1349
|
+
var nextCell = isEdge
|
|
1350
|
+
? (0, exports.findNextContentfulCell)(sheetId, activeCell, getValue, isHidden, direction, limit)
|
|
1351
|
+
: (0, exports.findLastContentfulCell)(sheetId, activeCell, getValue, isHidden, direction, limit);
|
|
1352
|
+
return nextCell === null || nextCell === void 0 ? void 0 : nextCell.columnIndex;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1356
|
+
exports.findNextCellInDataRegion = findNextCellInDataRegion;
|
|
1357
|
+
/**
|
|
1358
|
+
* Converts a value to string
|
|
1359
|
+
* @param value
|
|
1360
|
+
*/
|
|
1361
|
+
var castToString = function (value) {
|
|
1362
|
+
if (value === null || value === void 0)
|
|
1363
|
+
return void 0;
|
|
1364
|
+
return typeof value !== "string" ? "" + value : value;
|
|
1365
|
+
};
|
|
1366
|
+
exports.castToString = castToString;
|
|
1367
|
+
var isArrowKey = function (key) {
|
|
1368
|
+
return (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].indexOf(key) !== -1);
|
|
1369
|
+
};
|
|
1370
|
+
exports.isArrowKey = isArrowKey;
|
|
1371
|
+
var getScrollIncrement = function (delta, minDim) {
|
|
1372
|
+
if (minDim === void 0) { minDim = 8; }
|
|
1373
|
+
return Math.max(1, Math.round(Math.abs(delta) / minDim));
|
|
1374
|
+
};
|
|
1375
|
+
exports.getScrollIncrement = getScrollIncrement;
|
|
1376
|
+
exports.useIsomorphicLayoutEffect = exports.canUseDOM
|
|
1377
|
+
? react_1.useLayoutEffect
|
|
1378
|
+
: react_1.useEffect;
|
|
1379
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1380
|
+
var useCallbackRef = function (callback) {
|
|
1381
|
+
var callbackRef = (0, react_1.useRef)(callback);
|
|
1382
|
+
(0, exports.useIsomorphicLayoutEffect)(function () {
|
|
1383
|
+
callbackRef.current = callback;
|
|
1384
|
+
});
|
|
1385
|
+
// https://github.com/facebook/react/issues/19240
|
|
1386
|
+
return (0, react_1.useMemo)(function () { return (function () {
|
|
1387
|
+
var _a;
|
|
1388
|
+
var args = [];
|
|
1389
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1390
|
+
args[_i] = arguments[_i];
|
|
1391
|
+
}
|
|
1392
|
+
return (_a = callbackRef.current) === null || _a === void 0 ? void 0 : _a.call.apply(_a, tslib_1.__spreadArray([callbackRef], tslib_1.__read(args), false));
|
|
1393
|
+
}); }, []);
|
|
1394
|
+
};
|
|
1395
|
+
exports.useCallbackRef = useCallbackRef;
|
|
1396
|
+
var getDevicePixelRatio = function () {
|
|
1397
|
+
return exports.canUseDOM && typeof window !== "undefined" ? window.devicePixelRatio : 1;
|
|
1398
|
+
};
|
|
1399
|
+
exports.getDevicePixelRatio = getDevicePixelRatio;
|
|
1400
|
+
var getPreviousCellInDirection = function (cell, direction) {
|
|
1401
|
+
if (direction === void 0) { direction = types_1.Direction.Down; }
|
|
1402
|
+
if (direction === types_1.Direction.Down) {
|
|
1403
|
+
return tslib_1.__assign(tslib_1.__assign({}, cell), { rowIndex: cell.rowIndex - 1 });
|
|
1404
|
+
}
|
|
1405
|
+
if (direction === types_1.Direction.Right) {
|
|
1406
|
+
return tslib_1.__assign(tslib_1.__assign({}, cell), { columnIndex: cell.columnIndex - 1 });
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
exports.getPreviousCellInDirection = getPreviousCellInDirection;
|