@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.
Files changed (208) hide show
  1. package/LICENSE.md +100 -0
  2. package/Readme.md +53 -59
  3. package/dist/cjs/Cell.d.ts +35 -0
  4. package/dist/cjs/Cell.d.ts.map +1 -0
  5. package/dist/cjs/Cell.js +29 -0
  6. package/dist/{CellOverlay.d.ts → cjs/CellOverlay.d.ts} +5 -5
  7. package/dist/cjs/CellOverlay.d.ts.map +1 -0
  8. package/dist/cjs/CellOverlay.js +126 -0
  9. package/dist/cjs/Context.d.ts +8 -0
  10. package/dist/cjs/Context.d.ts.map +1 -0
  11. package/dist/cjs/Context.js +13 -0
  12. package/dist/{FillHandle.d.ts → cjs/FillHandle.d.ts} +2 -1
  13. package/dist/cjs/FillHandle.d.ts.map +1 -0
  14. package/dist/cjs/FillHandle.js +26 -0
  15. package/dist/cjs/Grid.d.ts +558 -0
  16. package/dist/cjs/Grid.d.ts.map +1 -0
  17. package/dist/cjs/Grid.js +2446 -0
  18. package/dist/{GridLine.d.ts → cjs/GridLine.d.ts} +2 -1
  19. package/dist/cjs/GridLine.d.ts.map +1 -0
  20. package/dist/cjs/GridLine.js +10 -0
  21. package/dist/cjs/Image.d.ts +11 -0
  22. package/dist/cjs/Image.d.ts.map +1 -0
  23. package/dist/cjs/Image.js +57 -0
  24. package/dist/cjs/MemoizedGrid.d.ts +49 -0
  25. package/dist/cjs/MemoizedGrid.d.ts.map +1 -0
  26. package/dist/cjs/MemoizedGrid.js +105 -0
  27. package/dist/cjs/Selection.d.ts +5 -0
  28. package/dist/cjs/Selection.d.ts.map +1 -0
  29. package/dist/cjs/Selection.js +10 -0
  30. package/dist/{helpers.d.ts → cjs/helpers.d.ts} +59 -39
  31. package/dist/cjs/helpers.d.ts.map +1 -0
  32. package/dist/cjs/helpers.js +1409 -0
  33. package/dist/{hooks → cjs/hooks}/useCopyPaste.d.ts +3 -2
  34. package/dist/cjs/hooks/useCopyPaste.d.ts.map +1 -0
  35. package/dist/cjs/hooks/useCopyPaste.js +230 -0
  36. package/dist/{hooks → cjs/hooks}/useEditable.d.ts +21 -8
  37. package/dist/cjs/hooks/useEditable.d.ts.map +1 -0
  38. package/dist/cjs/hooks/useEditable.js +491 -0
  39. package/dist/{hooks → cjs/hooks}/useFilter.d.ts +3 -2
  40. package/dist/cjs/hooks/useFilter.d.ts.map +1 -0
  41. package/dist/cjs/hooks/useFilter.js +97 -0
  42. package/dist/{hooks → cjs/hooks}/useImage.d.ts +1 -0
  43. package/dist/cjs/hooks/useImage.d.ts.map +1 -0
  44. package/dist/cjs/hooks/useImage.js +80 -0
  45. package/dist/{hooks → cjs/hooks}/usePagination.d.ts +3 -2
  46. package/dist/cjs/hooks/usePagination.d.ts.map +1 -0
  47. package/dist/cjs/hooks/usePagination.js +53 -0
  48. package/dist/{hooks → cjs/hooks}/useSizer.d.ts +28 -29
  49. package/dist/cjs/hooks/useSizer.d.ts.map +1 -0
  50. package/dist/cjs/hooks/useSizer.js +176 -0
  51. package/dist/{hooks → cjs/hooks}/useTooltip.d.ts +2 -1
  52. package/dist/cjs/hooks/useTooltip.d.ts.map +1 -0
  53. package/dist/cjs/hooks/useTooltip.js +82 -0
  54. package/dist/{hooks → cjs/hooks}/useUndo.d.ts +2 -1
  55. package/dist/cjs/hooks/useUndo.d.ts.map +1 -0
  56. package/dist/cjs/hooks/useUndo.js +87 -0
  57. package/dist/cjs/index.d.ts +19 -0
  58. package/dist/cjs/index.d.ts.map +1 -0
  59. package/dist/cjs/index.js +29 -0
  60. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  61. package/dist/{types.d.ts → cjs/types.d.ts} +8 -3
  62. package/dist/cjs/types.d.ts.map +1 -0
  63. package/dist/{types.js → cjs/types.js} +7 -8
  64. package/dist/cjs/utils.d.ts +9 -0
  65. package/dist/cjs/utils.d.ts.map +1 -0
  66. package/dist/cjs/utils.js +58 -0
  67. package/dist/cjs/vitest.config.d.ts +3 -0
  68. package/dist/cjs/vitest.config.d.ts.map +1 -0
  69. package/dist/cjs/vitest.config.js +24 -0
  70. package/dist/esm/Cell.d.ts +35 -0
  71. package/dist/esm/Cell.d.ts.map +1 -0
  72. package/dist/esm/Cell.js +24 -0
  73. package/dist/esm/CellOverlay.d.ts +21 -0
  74. package/dist/esm/CellOverlay.d.ts.map +1 -0
  75. package/dist/esm/CellOverlay.js +120 -0
  76. package/dist/esm/Context.d.ts +8 -0
  77. package/dist/esm/Context.d.ts.map +1 -0
  78. package/dist/esm/Context.js +9 -0
  79. package/dist/esm/FillHandle.d.ts +8 -0
  80. package/dist/esm/FillHandle.d.ts.map +1 -0
  81. package/dist/{FillHandle.js → esm/FillHandle.js} +5 -11
  82. package/dist/esm/Grid.d.ts +558 -0
  83. package/dist/esm/Grid.d.ts.map +1 -0
  84. package/dist/esm/Grid.js +2451 -0
  85. package/dist/esm/GridLine.d.ts +5 -0
  86. package/dist/esm/GridLine.d.ts.map +1 -0
  87. package/dist/esm/GridLine.js +7 -0
  88. package/dist/esm/Image.d.ts +11 -0
  89. package/dist/esm/Image.d.ts.map +1 -0
  90. package/dist/esm/Image.js +53 -0
  91. package/dist/esm/MemoizedGrid.d.ts +49 -0
  92. package/dist/esm/MemoizedGrid.d.ts.map +1 -0
  93. package/dist/esm/MemoizedGrid.js +98 -0
  94. package/dist/esm/Selection.d.ts +5 -0
  95. package/dist/esm/Selection.d.ts.map +1 -0
  96. package/dist/esm/Selection.js +7 -0
  97. package/dist/esm/helpers.d.ts +281 -0
  98. package/dist/esm/helpers.d.ts.map +1 -0
  99. package/dist/esm/helpers.js +1260 -0
  100. package/dist/esm/hooks/useCopyPaste.d.ts +53 -0
  101. package/dist/esm/hooks/useCopyPaste.d.ts.map +1 -0
  102. package/dist/{hooks → esm/hooks}/useCopyPaste.js +40 -46
  103. package/dist/esm/hooks/useEditable.d.ts +253 -0
  104. package/dist/esm/hooks/useEditable.d.ts.map +1 -0
  105. package/dist/esm/hooks/useEditable.js +482 -0
  106. package/dist/esm/hooks/useFilter.d.ts +69 -0
  107. package/dist/esm/hooks/useFilter.d.ts.map +1 -0
  108. package/dist/{hooks → esm/hooks}/useFilter.js +22 -42
  109. package/dist/esm/hooks/useImage.d.ts +13 -0
  110. package/dist/esm/hooks/useImage.d.ts.map +1 -0
  111. package/dist/esm/hooks/useImage.js +76 -0
  112. package/dist/esm/hooks/usePagination.d.ts +69 -0
  113. package/dist/esm/hooks/usePagination.d.ts.map +1 -0
  114. package/dist/esm/hooks/usePagination.js +47 -0
  115. package/dist/esm/hooks/useSizer.d.ts +114 -0
  116. package/dist/esm/hooks/useSizer.d.ts.map +1 -0
  117. package/dist/esm/hooks/useSizer.js +176 -0
  118. package/dist/esm/hooks/useTooltip.d.ts +43 -0
  119. package/dist/esm/hooks/useTooltip.d.ts.map +1 -0
  120. package/dist/esm/hooks/useTooltip.js +80 -0
  121. package/dist/esm/hooks/useUndo.d.ts +36 -0
  122. package/dist/esm/hooks/useUndo.d.ts.map +1 -0
  123. package/dist/{hooks → esm/hooks}/useUndo.js +16 -25
  124. package/dist/esm/index.d.ts +19 -0
  125. package/dist/esm/index.d.ts.map +1 -0
  126. package/dist/esm/index.js +17 -0
  127. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  128. package/dist/esm/types.d.ts +70 -0
  129. package/dist/esm/types.d.ts.map +1 -0
  130. package/dist/esm/types.js +68 -0
  131. package/dist/esm/utils.d.ts +9 -0
  132. package/dist/esm/utils.d.ts.map +1 -0
  133. package/dist/esm/utils.js +104 -0
  134. package/dist/esm/vitest.config.d.ts +3 -0
  135. package/dist/esm/vitest.config.d.ts.map +1 -0
  136. package/dist/esm/vitest.config.js +22 -0
  137. package/package.json +28 -29
  138. package/dist/Cell.d.ts +0 -23
  139. package/dist/Cell.js +0 -55
  140. package/dist/Cell.js.map +0 -1
  141. package/dist/CellOverlay.js +0 -116
  142. package/dist/CellOverlay.js.map +0 -1
  143. package/dist/FillHandle.js.map +0 -1
  144. package/dist/Grid.d.ts +0 -385
  145. package/dist/Grid.js +0 -1684
  146. package/dist/Grid.js.map +0 -1
  147. package/dist/GridLine.js +0 -13
  148. package/dist/GridLine.js.map +0 -1
  149. package/dist/Image.d.ts +0 -8
  150. package/dist/Image.js +0 -50
  151. package/dist/Image.js.map +0 -1
  152. package/dist/Selection.d.ts +0 -4
  153. package/dist/Selection.js +0 -9
  154. package/dist/Selection.js.map +0 -1
  155. package/dist/helpers.js +0 -1033
  156. package/dist/helpers.js.map +0 -1
  157. package/dist/hooks/useCopyPaste.js.map +0 -1
  158. package/dist/hooks/useEditable.js +0 -477
  159. package/dist/hooks/useEditable.js.map +0 -1
  160. package/dist/hooks/useFilter.js.map +0 -1
  161. package/dist/hooks/useImage.js +0 -42
  162. package/dist/hooks/useImage.js.map +0 -1
  163. package/dist/hooks/usePagination.js +0 -73
  164. package/dist/hooks/usePagination.js.map +0 -1
  165. package/dist/hooks/useSelection.d.ts +0 -175
  166. package/dist/hooks/useSelection.js +0 -980
  167. package/dist/hooks/useSelection.js.map +0 -1
  168. package/dist/hooks/useSizer.js +0 -150
  169. package/dist/hooks/useSizer.js.map +0 -1
  170. package/dist/hooks/useTooltip.js +0 -106
  171. package/dist/hooks/useTooltip.js.map +0 -1
  172. package/dist/hooks/useTouch.d.ts +0 -21
  173. package/dist/hooks/useTouch.js +0 -73
  174. package/dist/hooks/useTouch.js.map +0 -1
  175. package/dist/hooks/useUndo.js.map +0 -1
  176. package/dist/index.d.ts +0 -25
  177. package/dist/index.js +0 -61
  178. package/dist/index.js.map +0 -1
  179. package/dist/types.js.map +0 -1
  180. package/dist/utils.d.ts +0 -8
  181. package/dist/utils.js +0 -153
  182. package/dist/utils.js.map +0 -1
  183. package/src/Cell.tsx +0 -100
  184. package/src/CellOverlay.tsx +0 -191
  185. package/src/FillHandle.tsx +0 -37
  186. package/src/Grid.tsx +0 -2677
  187. package/src/GridLine.tsx +0 -23
  188. package/src/Image.tsx +0 -43
  189. package/src/Selection.tsx +0 -9
  190. package/src/helpers.ts +0 -1455
  191. package/src/hooks/useCopyPaste.ts +0 -265
  192. package/src/hooks/useEditable.tsx +0 -945
  193. package/src/hooks/useFilter.tsx +0 -233
  194. package/src/hooks/useImage.ts +0 -57
  195. package/src/hooks/usePagination.tsx +0 -153
  196. package/src/hooks/useSelection.ts +0 -1437
  197. package/src/hooks/useSizer.ts +0 -312
  198. package/src/hooks/useTooltip.tsx +0 -172
  199. package/src/hooks/useTouch.ts +0 -116
  200. package/src/hooks/useUndo.ts +0 -134
  201. package/src/index.tsx +0 -46
  202. package/src/tests/Grid.spec.tsx +0 -47
  203. package/src/tests/helpers.test.ts +0 -292
  204. package/src/tests/usePagination.test.ts +0 -28
  205. package/src/tests/useSelection.test.ts +0 -27
  206. package/src/tests/useUndo.test.ts +0 -73
  207. package/src/types.ts +0 -69
  208. package/src/utils.tsx +0 -287
package/dist/helpers.js DELETED
@@ -1,1033 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isArrowKey = exports.castToString = exports.focusableNodeNames = exports.findNextCellInDataRegion = exports.findLastContentfulCell = exports.findNextContentfulCell = exports.clampIndex = exports.isCellWithinBounds = exports.isEqualCells = exports.isNull = exports.autoSizerCanvas = exports.AutoSizerCanvas = exports.canUseDOM = 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.requestTimeout = exports.cancelTimeout = exports.getOffsetForRowAndAlignment = exports.getOffsetForColumnAndAlignment = exports.getOffsetForIndexAndAlignment = exports.rafThrottle = exports.debounce = exports.throttle = 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
- const types_1 = require("./types");
5
- var Align;
6
- (function (Align) {
7
- Align["start"] = "start";
8
- Align["end"] = "end";
9
- Align["center"] = "center";
10
- Align["auto"] = "auto";
11
- Align["smart"] = "smart";
12
- })(Align = exports.Align || (exports.Align = {}));
13
- var ItemType;
14
- (function (ItemType) {
15
- ItemType["row"] = "row";
16
- ItemType["column"] = "column";
17
- })(ItemType = exports.ItemType || (exports.ItemType = {}));
18
- const getRowStartIndexForOffset = ({ rowHeight, columnWidth, rowCount, columnCount, instanceProps, offset, scale, }) => {
19
- return findNearestItem({
20
- itemType: ItemType.row,
21
- rowHeight,
22
- columnWidth,
23
- rowCount,
24
- columnCount,
25
- instanceProps,
26
- offset,
27
- scale,
28
- });
29
- };
30
- exports.getRowStartIndexForOffset = getRowStartIndexForOffset;
31
- const getRowStopIndexForStartIndex = ({ startIndex, rowCount, rowHeight, columnWidth, scrollTop, containerHeight, instanceProps, scale, }) => {
32
- const itemMetadata = (0, exports.getItemMetadata)({
33
- itemType: ItemType.row,
34
- rowHeight,
35
- columnWidth,
36
- index: startIndex,
37
- instanceProps,
38
- scale,
39
- });
40
- const maxOffset = scrollTop + containerHeight;
41
- let offset = itemMetadata.offset + itemMetadata.size;
42
- let stopIndex = startIndex;
43
- while (stopIndex < rowCount - 1 && offset < maxOffset) {
44
- stopIndex++;
45
- offset += (0, exports.getItemMetadata)({
46
- itemType: ItemType.row,
47
- rowHeight,
48
- columnWidth,
49
- index: stopIndex,
50
- instanceProps,
51
- scale,
52
- }).size;
53
- }
54
- return stopIndex;
55
- };
56
- exports.getRowStopIndexForStartIndex = getRowStopIndexForStartIndex;
57
- const getColumnStartIndexForOffset = ({ rowHeight, columnWidth, rowCount, columnCount, instanceProps, offset, scale, }) => {
58
- return findNearestItem({
59
- itemType: ItemType.column,
60
- rowHeight,
61
- columnWidth,
62
- rowCount,
63
- columnCount,
64
- instanceProps,
65
- offset,
66
- scale,
67
- });
68
- };
69
- exports.getColumnStartIndexForOffset = getColumnStartIndexForOffset;
70
- const getColumnStopIndexForStartIndex = ({ startIndex, rowHeight, columnWidth, instanceProps, containerWidth, scrollLeft, columnCount, scale, }) => {
71
- const itemMetadata = (0, exports.getItemMetadata)({
72
- itemType: ItemType.column,
73
- index: startIndex,
74
- rowHeight,
75
- columnWidth,
76
- instanceProps,
77
- scale,
78
- });
79
- const maxOffset = scrollLeft + containerWidth;
80
- let offset = itemMetadata.offset + itemMetadata.size;
81
- let stopIndex = startIndex;
82
- while (stopIndex < columnCount - 1 && offset < maxOffset) {
83
- stopIndex++;
84
- offset += (0, exports.getItemMetadata)({
85
- itemType: ItemType.column,
86
- rowHeight,
87
- columnWidth,
88
- index: stopIndex,
89
- instanceProps,
90
- scale,
91
- }).size;
92
- }
93
- return stopIndex;
94
- };
95
- exports.getColumnStopIndexForStartIndex = getColumnStopIndexForStartIndex;
96
- const getBoundedCells = (area) => {
97
- const cells = new Set();
98
- if (!area)
99
- return cells;
100
- const { top, bottom, left, right } = area;
101
- for (let i = top; i <= bottom; i++) {
102
- for (let j = left; j <= right; j++) {
103
- cells.add((0, exports.cellIdentifier)(i, j));
104
- }
105
- }
106
- return cells;
107
- };
108
- exports.getBoundedCells = getBoundedCells;
109
- const itemKey = ({ rowIndex, columnIndex }) => `${rowIndex}:${columnIndex}`;
110
- exports.itemKey = itemKey;
111
- const getRowOffset = ({ index, rowHeight, columnWidth, instanceProps, scale, }) => {
112
- return (0, exports.getItemMetadata)({
113
- itemType: ItemType.row,
114
- index,
115
- rowHeight,
116
- columnWidth,
117
- instanceProps,
118
- scale,
119
- }).offset;
120
- };
121
- exports.getRowOffset = getRowOffset;
122
- const getColumnOffset = ({ index, rowHeight, columnWidth, instanceProps, scale, }) => {
123
- return (0, exports.getItemMetadata)({
124
- itemType: ItemType.column,
125
- index,
126
- rowHeight,
127
- columnWidth,
128
- instanceProps,
129
- scale,
130
- }).offset;
131
- };
132
- exports.getColumnOffset = getColumnOffset;
133
- const getRowHeight = (index, instanceProps) => {
134
- return instanceProps.rowMetadataMap[index].size;
135
- };
136
- exports.getRowHeight = getRowHeight;
137
- const getColumnWidth = (index, instanceProps) => {
138
- return instanceProps.columnMetadataMap[index].size;
139
- };
140
- exports.getColumnWidth = getColumnWidth;
141
- const getItemMetadata = ({ itemType, index, rowHeight, columnWidth, instanceProps, scale = 2, }) => {
142
- var _a;
143
- let itemMetadataMap, itemSize, lastMeasuredIndex, recalcIndices;
144
- if (itemType === "column") {
145
- itemMetadataMap = instanceProps.columnMetadataMap;
146
- itemSize = columnWidth;
147
- lastMeasuredIndex = instanceProps.lastMeasuredColumnIndex;
148
- recalcIndices = instanceProps.recalcColumnIndices;
149
- }
150
- else {
151
- itemMetadataMap = instanceProps.rowMetadataMap;
152
- itemSize = rowHeight;
153
- lastMeasuredIndex = instanceProps.lastMeasuredRowIndex;
154
- recalcIndices = instanceProps.recalcRowIndices;
155
- }
156
- const recalcWithinBoundsOnly = recalcIndices.length > 0;
157
- if (index > lastMeasuredIndex) {
158
- let offset = 0;
159
- if (lastMeasuredIndex >= 0) {
160
- const itemMetadata = itemMetadataMap[lastMeasuredIndex];
161
- offset = itemMetadata.offset + itemMetadata.size;
162
- }
163
- for (let i = lastMeasuredIndex + 1; i <= index; i++) {
164
- // Only recalculates specified columns
165
- let size = recalcWithinBoundsOnly
166
- ? recalcIndices.includes(i)
167
- ? itemSize(i) * scale
168
- : ((_a = itemMetadataMap[i]) === null || _a === void 0 ? void 0 : _a.size) || itemSize(i) * scale
169
- : itemSize(i) * scale;
170
- itemMetadataMap[i] = {
171
- offset,
172
- size,
173
- };
174
- offset += size;
175
- }
176
- if (itemType === "column") {
177
- instanceProps.lastMeasuredColumnIndex = index;
178
- }
179
- else {
180
- instanceProps.lastMeasuredRowIndex = index;
181
- }
182
- }
183
- return itemMetadataMap[index];
184
- };
185
- exports.getItemMetadata = getItemMetadata;
186
- const findNearestItem = ({ itemType, rowHeight, columnWidth, rowCount, columnCount, instanceProps, offset, scale, }) => {
187
- let itemMetadataMap, lastMeasuredIndex;
188
- if (itemType === "column") {
189
- itemMetadataMap = instanceProps.columnMetadataMap;
190
- lastMeasuredIndex = instanceProps.lastMeasuredColumnIndex;
191
- }
192
- else {
193
- itemMetadataMap = instanceProps.rowMetadataMap;
194
- lastMeasuredIndex = instanceProps.lastMeasuredRowIndex;
195
- }
196
- const lastMeasuredItemOffset = lastMeasuredIndex > 0 ? itemMetadataMap[lastMeasuredIndex].offset : 0;
197
- if (lastMeasuredItemOffset >= offset) {
198
- // If we've already measured items within this range just use a binary search as it's faster.
199
- return findNearestItemBinarySearch({
200
- itemType,
201
- rowHeight,
202
- columnWidth,
203
- instanceProps,
204
- high: lastMeasuredIndex,
205
- low: 0,
206
- offset,
207
- scale,
208
- });
209
- }
210
- else {
211
- // If we haven't yet measured this high, fallback to an exponential search with an inner binary search.
212
- // The exponential search avoids pre-computing sizes for the full set of items as a binary search would.
213
- // The overall complexity for this approach is O(log n).
214
- return findNearestItemExponentialSearch({
215
- itemType,
216
- rowHeight,
217
- rowCount,
218
- columnCount,
219
- columnWidth,
220
- instanceProps,
221
- index: Math.max(0, lastMeasuredIndex),
222
- offset,
223
- scale,
224
- });
225
- }
226
- };
227
- const findNearestItemBinarySearch = ({ itemType, rowHeight, columnWidth, instanceProps, high, low, offset, scale, }) => {
228
- while (low <= high) {
229
- const middle = low + Math.floor((high - low) / 2);
230
- const currentOffset = (0, exports.getItemMetadata)({
231
- itemType,
232
- rowHeight,
233
- columnWidth,
234
- index: middle,
235
- instanceProps,
236
- scale,
237
- }).offset;
238
- if (currentOffset === offset) {
239
- return middle;
240
- }
241
- else if (currentOffset < offset) {
242
- low = middle + 1;
243
- }
244
- else if (currentOffset > offset) {
245
- high = middle - 1;
246
- }
247
- }
248
- if (low > 0) {
249
- return low - 1;
250
- }
251
- else {
252
- return 0;
253
- }
254
- };
255
- const findNearestItemExponentialSearch = ({ itemType, rowHeight, columnWidth, rowCount, columnCount, instanceProps, index, offset, scale, }) => {
256
- const itemCount = itemType === "column" ? columnCount : rowCount;
257
- let interval = 1;
258
- while (index < itemCount &&
259
- (0, exports.getItemMetadata)({
260
- itemType,
261
- rowHeight,
262
- columnWidth,
263
- index,
264
- instanceProps,
265
- scale,
266
- }).offset < offset) {
267
- index += interval;
268
- interval *= 2;
269
- }
270
- return findNearestItemBinarySearch({
271
- itemType,
272
- rowHeight,
273
- columnWidth,
274
- instanceProps,
275
- high: Math.min(index, itemCount - 1),
276
- low: Math.floor(index / 2),
277
- offset,
278
- scale,
279
- });
280
- };
281
- const getEstimatedTotalHeight = (rowCount, instanceProps) => {
282
- const { estimatedRowHeight } = instanceProps;
283
- let totalSizeOfMeasuredRows = 0;
284
- let { lastMeasuredRowIndex, rowMetadataMap } = instanceProps;
285
- // Edge case check for when the number of items decreases while a scroll is in progress.
286
- // https://github.com/bvaughn/react-window/pull/138
287
- if (lastMeasuredRowIndex >= rowCount) {
288
- lastMeasuredRowIndex = rowCount - 1;
289
- }
290
- if (lastMeasuredRowIndex >= 0) {
291
- const itemMetadata = rowMetadataMap[lastMeasuredRowIndex];
292
- totalSizeOfMeasuredRows = itemMetadata.offset + itemMetadata.size;
293
- }
294
- const numUnmeasuredItems = rowCount - lastMeasuredRowIndex - 1;
295
- const totalSizeOfUnmeasuredItems = numUnmeasuredItems * estimatedRowHeight;
296
- return totalSizeOfMeasuredRows + totalSizeOfUnmeasuredItems;
297
- };
298
- exports.getEstimatedTotalHeight = getEstimatedTotalHeight;
299
- const getEstimatedTotalWidth = (columnCount, instanceProps) => {
300
- const { estimatedColumnWidth } = instanceProps;
301
- let totalSizeOfMeasuredRows = 0;
302
- let { lastMeasuredColumnIndex, columnMetadataMap } = instanceProps;
303
- // Edge case check for when the number of items decreases while a scroll is in progress.
304
- // https://github.com/bvaughn/react-window/pull/138
305
- if (lastMeasuredColumnIndex >= columnCount) {
306
- lastMeasuredColumnIndex = columnCount - 1;
307
- }
308
- if (lastMeasuredColumnIndex >= 0) {
309
- const itemMetadata = columnMetadataMap[lastMeasuredColumnIndex];
310
- totalSizeOfMeasuredRows = itemMetadata.offset + itemMetadata.size;
311
- }
312
- const numUnmeasuredItems = columnCount - lastMeasuredColumnIndex - 1;
313
- const totalSizeOfUnmeasuredItems = numUnmeasuredItems * estimatedColumnWidth;
314
- return totalSizeOfMeasuredRows + totalSizeOfUnmeasuredItems;
315
- };
316
- exports.getEstimatedTotalWidth = getEstimatedTotalWidth;
317
- /* Create a stringified cell identifier */
318
- const cellIdentifier = (rowIndex, columnIndex) => `${rowIndex},${columnIndex}`;
319
- exports.cellIdentifier = cellIdentifier;
320
- /**
321
- * @desc Throttle fn
322
- * @param func function
323
- * @param limit Delay in milliseconds
324
- */
325
- function throttle(func, limit) {
326
- var lastEventTimestamp = null;
327
- let callable = (...args) => {
328
- const now = Date.now();
329
- if (!lastEventTimestamp || now - lastEventTimestamp >= limit) {
330
- lastEventTimestamp = now;
331
- func(...args);
332
- }
333
- };
334
- return callable;
335
- }
336
- exports.throttle = throttle;
337
- function debounce(cb, wait = 300) {
338
- let h = 0;
339
- let callable = (...args) => {
340
- clearTimeout(h);
341
- h = window.setTimeout(() => cb(...args), wait);
342
- };
343
- return callable;
344
- }
345
- exports.debounce = debounce;
346
- function rafThrottle(callback) {
347
- var active = false; // a simple flag
348
- var evt; // to keep track of the last event
349
- var handler = function () {
350
- // fired only when screen has refreshed
351
- active = false; // release our flag
352
- callback(evt);
353
- };
354
- return function handleEvent(e) {
355
- // the actual event handler
356
- evt = e; // save our event at each call
357
- evt && evt.persist && evt.persist();
358
- if (!active) {
359
- // only if we weren't already doing it
360
- active = true; // raise the flag
361
- requestAnimationFrame(handler); // wait for next screen refresh
362
- }
363
- };
364
- }
365
- exports.rafThrottle = rafThrottle;
366
- const getOffsetForIndexAndAlignment = ({ itemType, containerHeight, containerWidth, rowHeight, columnWidth, columnCount, rowCount, index, align = Align.smart, scrollOffset, instanceProps, scrollbarSize, frozenOffset = 0, scale, estimatedTotalHeight, estimatedTotalWidth, }) => {
367
- const size = itemType === "column" ? containerWidth : containerHeight;
368
- const itemMetadata = (0, exports.getItemMetadata)({
369
- itemType,
370
- rowHeight,
371
- columnWidth,
372
- index,
373
- instanceProps,
374
- scale,
375
- });
376
- // Get estimated total size after ItemMetadata is computed,
377
- // To ensure it reflects actual measurements instead of just estimates.
378
- const estimatedTotalSize = itemType === "column" ? estimatedTotalWidth : estimatedTotalHeight;
379
- const maxOffset = Math.max(0, Math.min(estimatedTotalSize - size, itemMetadata.offset - frozenOffset));
380
- const minOffset = Math.max(0, itemMetadata.offset - size + scrollbarSize + itemMetadata.size);
381
- if (align === Align.smart) {
382
- if (scrollOffset >= minOffset - size && scrollOffset <= maxOffset + size) {
383
- align = Align.auto;
384
- }
385
- else {
386
- align = Align.center;
387
- }
388
- }
389
- switch (align) {
390
- case Align.start:
391
- return maxOffset;
392
- case Align.end:
393
- return minOffset;
394
- case Align.center:
395
- return Math.round(minOffset + (maxOffset - minOffset) / 2);
396
- case Align.auto:
397
- default:
398
- if (scrollOffset >= minOffset && scrollOffset <= maxOffset) {
399
- return scrollOffset;
400
- }
401
- else if (minOffset > maxOffset) {
402
- // Because we only take into account the scrollbar size when calculating minOffset
403
- // this value can be larger than maxOffset when at the end of the list
404
- return minOffset;
405
- }
406
- else if (scrollOffset < minOffset) {
407
- return minOffset;
408
- }
409
- else {
410
- return maxOffset;
411
- }
412
- }
413
- };
414
- exports.getOffsetForIndexAndAlignment = getOffsetForIndexAndAlignment;
415
- const getOffsetForColumnAndAlignment = (props) => {
416
- return (0, exports.getOffsetForIndexAndAlignment)({
417
- itemType: ItemType.column,
418
- ...props,
419
- });
420
- };
421
- exports.getOffsetForColumnAndAlignment = getOffsetForColumnAndAlignment;
422
- const getOffsetForRowAndAlignment = (props) => {
423
- return (0, exports.getOffsetForIndexAndAlignment)({
424
- itemType: ItemType.row,
425
- ...props,
426
- });
427
- };
428
- exports.getOffsetForRowAndAlignment = getOffsetForRowAndAlignment;
429
- // Animation frame based implementation of setTimeout.
430
- // Inspired by Joe Lambert, https://gist.github.com/joelambert/1002116#file-requesttimeout-js
431
- const hasNativePerformanceNow = typeof performance === "object" && typeof performance.now === "function";
432
- const now = hasNativePerformanceNow
433
- ? () => performance.now()
434
- : () => Date.now();
435
- function cancelTimeout(timeoutID) {
436
- cancelAnimationFrame(timeoutID.id);
437
- }
438
- exports.cancelTimeout = cancelTimeout;
439
- /**
440
- * Create a throttler based on RAF
441
- * @param callback
442
- * @param delay
443
- */
444
- function requestTimeout(callback, delay) {
445
- const start = now();
446
- function tick() {
447
- if (now() - start >= delay) {
448
- callback.call(null);
449
- }
450
- else {
451
- timeoutID.id = requestAnimationFrame(tick);
452
- }
453
- }
454
- const timeoutID = {
455
- id: requestAnimationFrame(tick),
456
- };
457
- return timeoutID;
458
- }
459
- exports.requestTimeout = requestTimeout;
460
- const selectionFromActiveCell = (activeCell) => {
461
- if (!activeCell)
462
- return [];
463
- return [
464
- {
465
- bounds: {
466
- top: activeCell.rowIndex,
467
- left: activeCell.columnIndex,
468
- bottom: activeCell.rowIndex,
469
- right: activeCell.columnIndex,
470
- },
471
- },
472
- ];
473
- };
474
- exports.selectionFromActiveCell = selectionFromActiveCell;
475
- /**
476
- * Check if a selection are spans multiple cells
477
- * @param sel
478
- */
479
- const selectionSpansCells = (sel) => {
480
- if (!sel)
481
- return false;
482
- return sel.bottom !== sel.top || sel.left !== sel.right;
483
- };
484
- exports.selectionSpansCells = selectionSpansCells;
485
- /**
486
- * When user tries to drag a selection
487
- * @param initialSelection
488
- * @param from
489
- * @param to
490
- */
491
- const newSelectionFromDrag = (initialSelection, from, to, topBound = 0, leftBound = 0, rowCount, columnCount) => {
492
- const currentBounds = initialSelection.bounds;
493
- const top = Math.max(topBound, Math.min(rowCount, to.rowIndex + currentBounds.top - from.rowIndex));
494
- const left = Math.max(leftBound, Math.min(columnCount, to.columnIndex + currentBounds.left - from.columnIndex));
495
- return {
496
- bounds: {
497
- top,
498
- left,
499
- bottom: top + (currentBounds.bottom - currentBounds.top),
500
- right: left + (currentBounds.right - currentBounds.left),
501
- },
502
- };
503
- };
504
- exports.newSelectionFromDrag = newSelectionFromDrag;
505
- /**
506
- * Clamp cell coordinates to be inside activeCell and selection
507
- * @param coords
508
- * @param activeCell
509
- * @param selection
510
- */
511
- const clampCellCoords = (coords, activeCell, selection) => {
512
- if (activeCell) {
513
- coords.rowIndex = Math.max(activeCell.rowIndex, coords.rowIndex);
514
- coords.columnIndex = Math.min(activeCell.columnIndex, coords.columnIndex);
515
- }
516
- if (selection) {
517
- coords.rowIndex = Math.min(selection.bounds.bottom, Math.max(selection.bounds.top, coords.rowIndex));
518
- coords.columnIndex = Math.min(selection.bounds.right, Math.max(selection.bounds.left, coords.columnIndex));
519
- }
520
- return coords;
521
- };
522
- exports.clampCellCoords = clampCellCoords;
523
- /**
524
- * Converts a number to alphabet
525
- * @param i
526
- */
527
- const numberToAlphabet = (i) => {
528
- return ((i >= 26 ? (0, exports.numberToAlphabet)(((i / 26) >> 0) - 1) : "") +
529
- "abcdefghijklmnopqrstuvwxyz"[i % 26 >> 0]).toUpperCase();
530
- };
531
- exports.numberToAlphabet = numberToAlphabet;
532
- /**
533
- * Convert selections to html and csv data
534
- * @param rows
535
- */
536
- const prepareClipboardData = (rows) => {
537
- const html = ["<table>"];
538
- const csv = [];
539
- const sanitizeCell = (value) => {
540
- if ((0, exports.isNull)(value))
541
- return "";
542
- return value;
543
- };
544
- rows.forEach((row) => {
545
- html.push("<tr>");
546
- const csvRow = [];
547
- row.forEach((cell) => {
548
- var _a;
549
- html.push(`<td>${sanitizeCell(cell)}</td>`);
550
- csvRow.push(`${(_a = (0, exports.castToString)(cell)) === null || _a === void 0 ? void 0 : _a.replace(/"/g, '""')}`);
551
- });
552
- csv.push(csvRow.join(","));
553
- html.push("</tr>");
554
- });
555
- html.push("</table>");
556
- return [html.join(""), csv.join("\n")];
557
- };
558
- exports.prepareClipboardData = prepareClipboardData;
559
- /**
560
- * Cycles active cell within selecton bounds
561
- * @param activeCellBounds
562
- * @param selectionBounds
563
- * @param direction
564
- */
565
- const findNextCellWithinBounds = (activeCellBounds, selectionBounds, direction = types_1.Direction.Right) => {
566
- const intersects = (0, exports.areaIntersects)(activeCellBounds, selectionBounds);
567
- if (!intersects)
568
- return null;
569
- let rowIndex, columnIndex;
570
- let nextActiveCell = null;
571
- if (direction === types_1.Direction.Right) {
572
- rowIndex = activeCellBounds.top;
573
- columnIndex = activeCellBounds.left + 1;
574
- if (columnIndex > selectionBounds.right) {
575
- rowIndex = rowIndex + 1;
576
- columnIndex = selectionBounds.left;
577
- if (rowIndex > selectionBounds.bottom) {
578
- rowIndex = selectionBounds.top;
579
- }
580
- }
581
- nextActiveCell = { rowIndex, columnIndex };
582
- }
583
- if (direction === types_1.Direction.Left) {
584
- rowIndex = activeCellBounds.bottom;
585
- columnIndex = activeCellBounds.left - 1;
586
- if (columnIndex < selectionBounds.left) {
587
- rowIndex = rowIndex - 1;
588
- columnIndex = selectionBounds.right;
589
- if (rowIndex < selectionBounds.top) {
590
- rowIndex = selectionBounds.bottom;
591
- }
592
- }
593
- nextActiveCell = { rowIndex, columnIndex };
594
- }
595
- if (direction === types_1.Direction.Down) {
596
- rowIndex = activeCellBounds.bottom + 1;
597
- columnIndex = activeCellBounds.left;
598
- if (rowIndex > selectionBounds.bottom) {
599
- columnIndex = activeCellBounds.left + 1;
600
- rowIndex = selectionBounds.top;
601
- if (columnIndex > selectionBounds.right) {
602
- columnIndex = selectionBounds.left;
603
- }
604
- }
605
- nextActiveCell = { rowIndex, columnIndex };
606
- }
607
- if (direction === types_1.Direction.Up) {
608
- rowIndex = activeCellBounds.top - 1;
609
- columnIndex = activeCellBounds.left;
610
- if (rowIndex < selectionBounds.top) {
611
- columnIndex = activeCellBounds.left - 1;
612
- rowIndex = selectionBounds.bottom;
613
- if (columnIndex < selectionBounds.left) {
614
- columnIndex = selectionBounds.right;
615
- }
616
- }
617
- nextActiveCell = { rowIndex, columnIndex };
618
- }
619
- return nextActiveCell;
620
- };
621
- exports.findNextCellWithinBounds = findNextCellWithinBounds;
622
- /**
623
- * Check if 2 areas overlap
624
- * @param area1
625
- * @param area2
626
- */
627
- const areaIntersects = (area1, area2) => {
628
- if (area1.left > area2.right || area2.left > area1.right) {
629
- return false;
630
- }
631
- if (area1.top > area2.bottom || area2.top > area1.bottom) {
632
- return false;
633
- }
634
- return true;
635
- };
636
- exports.areaIntersects = areaIntersects;
637
- /**
638
- * Check if area is inside another area
639
- * @param needle
640
- * @param haystack
641
- */
642
- const areaInsideArea = (needle, haystack) => {
643
- return (needle.top >= haystack.top &&
644
- needle.bottom <= haystack.bottom &&
645
- needle.left >= haystack.left &&
646
- needle.right <= haystack.right);
647
- };
648
- exports.areaInsideArea = areaInsideArea;
649
- /**
650
- * Check if two areas are equal
651
- * @param area1
652
- * @param area2
653
- */
654
- const isAreasEqual = (area1, area2) => {
655
- if (area1 === void 0 || area2 === void 0) {
656
- return false;
657
- }
658
- return (area1.bottom === area2.bottom &&
659
- area1.top === area2.top &&
660
- area1.left === area2.left &&
661
- area1.right === area2.right);
662
- };
663
- exports.isAreasEqual = isAreasEqual;
664
- /**
665
- * Get maximum bound of an area, caters to merged cells
666
- * @param area
667
- * @param boundGetter
668
- */
669
- const extendAreaToMergedCells = (_area, mergedCells) => {
670
- const area = { ..._area };
671
- for (const bounds of mergedCells) {
672
- if ((0, exports.areaIntersects)(area, bounds)) {
673
- area.top = Math.min(area.top, bounds.top);
674
- area.bottom = Math.max(area.bottom, bounds.bottom);
675
- area.right = Math.max(area.right, bounds.right);
676
- area.left = Math.min(area.left, bounds.left);
677
- }
678
- }
679
- return area;
680
- };
681
- exports.extendAreaToMergedCells = extendAreaToMergedCells;
682
- /**
683
- * Convert 2 cells to bounds
684
- * @param start
685
- * @param end
686
- * @returns
687
- *
688
- * 2 loops O(n)
689
- */
690
- const cellRangeToBounds = (start, end, spanMerges = true, getCellBounds) => {
691
- let top = Math.min(start.rowIndex, end.rowIndex);
692
- let bottom = Math.max(start.rowIndex, end.rowIndex);
693
- let left = Math.min(start.columnIndex, end.columnIndex);
694
- let right = Math.max(start.columnIndex, end.columnIndex);
695
- /**
696
- * The idea is that
697
- * We do 2 loops >
698
- * Left to Right and then top to bottom
699
- * => Find top cell and bottom cell and check
700
- * if there are any merged cells at the edge
701
- * Then keep extending our top and bottom bounds accordingly
702
- *
703
- * Same goes for Top to bottom
704
- * => Find left most and right most cells
705
- */
706
- if (spanMerges) {
707
- for (let columnIndex = left; columnIndex <= right; columnIndex++) {
708
- const topCell = getCellBounds({ rowIndex: top, columnIndex });
709
- const bottomCell = getCellBounds({ rowIndex: bottom, columnIndex });
710
- bottom = Math.max(topCell.bottom, bottomCell.bottom, bottom);
711
- top = Math.min(topCell.top, bottomCell.top, top);
712
- }
713
- for (let rowIndex = top; rowIndex <= bottom; rowIndex++) {
714
- const topCell = getCellBounds({ rowIndex, columnIndex: left });
715
- const bottomCell = getCellBounds({ rowIndex, columnIndex: right });
716
- right = Math.max(topCell.right, bottomCell.right, right);
717
- left = Math.min(topCell.left, bottomCell.left, left);
718
- }
719
- }
720
- return {
721
- top,
722
- left,
723
- right,
724
- bottom,
725
- };
726
- };
727
- exports.cellRangeToBounds = cellRangeToBounds;
728
- /**
729
- * Check if its being rendered in Browser or SSR
730
- */
731
- exports.canUseDOM = !!(typeof window !== "undefined" &&
732
- window.document &&
733
- window.document.createElement);
734
- const AutoSizerCanvas = (defaults = {}) => {
735
- const { fontFamily = "Arial", fontSize = 12, fontWeight = "", fontStyle = "", lineHeight = 16, scale = 1, } = defaults;
736
- var o = {
737
- fontFamily,
738
- fontSize,
739
- fontWeight,
740
- fontStyle,
741
- lineHeight,
742
- scale,
743
- };
744
- const canvas = exports.canUseDOM && document.createElement("canvas");
745
- const context = canvas ? canvas.getContext("2d") : null;
746
- const setFont = (options = {}) => {
747
- var _a;
748
- for (const key in options) {
749
- o[key] = (_a = options[key]) !== null && _a !== void 0 ? _a : o[key];
750
- }
751
- if (context) {
752
- context.font = `${o.fontStyle} ${o.fontWeight} ${o.fontSize * o.scale}px ${o.fontFamily}`;
753
- }
754
- };
755
- const getWidthOfLongestText = (text) => {
756
- var _a;
757
- let width = 0;
758
- let height = 0;
759
- if (text === void 0)
760
- return { width, height };
761
- const lines = text.split("\n");
762
- for (let i = 0; i < lines.length; i++) {
763
- const line = lines[i];
764
- const lineWidth = (_a = context === null || context === void 0 ? void 0 : context.measureText(line).width) !== null && _a !== void 0 ? _a : 0;
765
- width = Math.max(width, lineWidth);
766
- height += o.fontSize * 1.2 * o.scale;
767
- }
768
- return { width: Math.ceil(width), height: Math.ceil(height) };
769
- };
770
- const measureText = (text) => getWidthOfLongestText((0, exports.castToString)(text));
771
- const reset = () => setFont(defaults);
772
- /* Set font in constructor */
773
- setFont(o);
774
- return {
775
- context,
776
- measureText,
777
- setFont,
778
- reset,
779
- };
780
- };
781
- exports.AutoSizerCanvas = AutoSizerCanvas;
782
- /* Export a singleton */
783
- exports.autoSizerCanvas = (0, exports.AutoSizerCanvas)();
784
- /* Check if a value is null */
785
- const isNull = (value) => value === void 0 || value === null || value === "";
786
- exports.isNull = isNull;
787
- const isEqualCells = (a, b) => {
788
- if ((0, exports.isNull)(a) || (0, exports.isNull)(b) || a === null || b === null)
789
- return false;
790
- return a.rowIndex === b.rowIndex && a.columnIndex === b.columnIndex;
791
- };
792
- exports.isEqualCells = isEqualCells;
793
- /**
794
- * Simple utility function to check if cell is within bounds
795
- * @param cell
796
- * @param bounds
797
- */
798
- const isCellWithinBounds = (cell, bounds) => {
799
- if (cell.rowIndex < bounds.top || cell.rowIndex > bounds.bottom) {
800
- return false;
801
- }
802
- if (cell.columnIndex < bounds.left || cell.columnIndex > bounds.right) {
803
- return false;
804
- }
805
- return true;
806
- };
807
- exports.isCellWithinBounds = isCellWithinBounds;
808
- const clampIndex = (index, isHidden, direction) => {
809
- switch (direction) {
810
- case types_1.Direction.Right:
811
- case types_1.Direction.Down:
812
- let hidden = isHidden === null || isHidden === void 0 ? void 0 : isHidden(index);
813
- while (hidden === true) {
814
- hidden = isHidden === null || isHidden === void 0 ? void 0 : isHidden(++index);
815
- }
816
- break;
817
- case types_1.Direction.Left:
818
- case types_1.Direction.Up: {
819
- let hidden = isHidden === null || isHidden === void 0 ? void 0 : isHidden(index);
820
- while (hidden === true) {
821
- hidden = isHidden === null || isHidden === void 0 ? void 0 : isHidden(--index);
822
- }
823
- break;
824
- }
825
- }
826
- return index;
827
- };
828
- exports.clampIndex = clampIndex;
829
- /**
830
- * Find a cell with content if the current cell is out of the current dataregion
831
- * [
832
- * 1, 2, 3,
833
- * x, x, x
834
- * 7, 8, 9
835
- * ]
836
- * activeCel = 2
837
- * direction = Down
838
- * New Cell = 8
839
- *
840
- * @param activeCell
841
- * @param getValue
842
- * @param isHidden
843
- * @param direction
844
- * @param limit
845
- */
846
- const findNextContentfulCell = (activeCell, getValue, isHidden, direction, limit) => {
847
- var { rowIndex, columnIndex } = activeCell;
848
- switch (direction) {
849
- case types_1.Direction.Down: {
850
- rowIndex = (0, exports.clampIndex)(Math.min(rowIndex + 1, limit), isHidden, direction);
851
- let value = getValue({ rowIndex, columnIndex });
852
- while ((0, exports.isNull)(value) && rowIndex < limit) {
853
- rowIndex = (0, exports.clampIndex)(Math.min(++rowIndex, limit), isHidden, direction);
854
- value = getValue({ rowIndex, columnIndex });
855
- }
856
- return { rowIndex, columnIndex };
857
- }
858
- case types_1.Direction.Up: {
859
- rowIndex = (0, exports.clampIndex)(Math.max(rowIndex - 1, limit), isHidden, direction);
860
- let value = getValue({ rowIndex, columnIndex });
861
- while ((0, exports.isNull)(value) && rowIndex > limit) {
862
- rowIndex = (0, exports.clampIndex)(Math.max(--rowIndex, limit), isHidden, direction);
863
- value = getValue({ rowIndex, columnIndex });
864
- }
865
- return { rowIndex, columnIndex };
866
- }
867
- case types_1.Direction.Right: {
868
- columnIndex = (0, exports.clampIndex)(Math.min(columnIndex + 1, limit), isHidden, direction);
869
- let value = getValue({ rowIndex, columnIndex });
870
- while ((0, exports.isNull)(value) && columnIndex < limit) {
871
- columnIndex = (0, exports.clampIndex)(Math.min(++columnIndex, limit), isHidden, direction);
872
- value = getValue({ rowIndex, columnIndex });
873
- }
874
- return { rowIndex, columnIndex };
875
- }
876
- case types_1.Direction.Left: {
877
- columnIndex = (0, exports.clampIndex)(Math.max(columnIndex - 1, limit), isHidden, direction);
878
- let value = getValue({ rowIndex, columnIndex });
879
- while ((0, exports.isNull)(value) && columnIndex > limit) {
880
- columnIndex = (0, exports.clampIndex)(Math.max(--columnIndex, limit), isHidden, direction);
881
- value = getValue({ rowIndex, columnIndex });
882
- }
883
- return { rowIndex, columnIndex };
884
- }
885
- default:
886
- return activeCell;
887
- }
888
- };
889
- exports.findNextContentfulCell = findNextContentfulCell;
890
- /**
891
- * Find the next cell
892
- * @param activeCell
893
- * @param getValue
894
- * @param isHidden
895
- * @param direction
896
- * @param limit
897
- */
898
- const findLastContentfulCell = (activeCell, getValue, isHidden, direction, limit) => {
899
- var { rowIndex, columnIndex } = activeCell;
900
- switch (direction) {
901
- case types_1.Direction.Down: {
902
- rowIndex = (0, exports.clampIndex)(Math.min(rowIndex + 1, limit), isHidden, direction);
903
- let value = getValue({ rowIndex, columnIndex });
904
- while (!(0, exports.isNull)(value) && rowIndex < limit) {
905
- rowIndex = (0, exports.clampIndex)(Math.min(++rowIndex, limit), isHidden, direction);
906
- value = getValue({ rowIndex, columnIndex });
907
- }
908
- return {
909
- columnIndex,
910
- rowIndex: (0, exports.isNull)(getValue({ columnIndex, rowIndex }))
911
- ? rowIndex - 1
912
- : rowIndex,
913
- };
914
- }
915
- case types_1.Direction.Up: {
916
- rowIndex = (0, exports.clampIndex)(Math.max(rowIndex - 1, limit), isHidden, direction);
917
- let value = getValue({ rowIndex, columnIndex });
918
- while (!(0, exports.isNull)(value) && rowIndex > limit) {
919
- rowIndex = (0, exports.clampIndex)(Math.max(--rowIndex, limit), isHidden, direction);
920
- value = getValue({ rowIndex, columnIndex });
921
- }
922
- return {
923
- columnIndex,
924
- rowIndex: (0, exports.isNull)(getValue({ columnIndex, rowIndex }))
925
- ? rowIndex + 1
926
- : rowIndex,
927
- };
928
- }
929
- case types_1.Direction.Right: {
930
- columnIndex = (0, exports.clampIndex)(Math.min(columnIndex + 1, limit), isHidden, direction);
931
- let value = getValue({ rowIndex, columnIndex });
932
- while (!(0, exports.isNull)(value) && columnIndex < limit) {
933
- columnIndex = (0, exports.clampIndex)(Math.min(++columnIndex, limit), isHidden, direction);
934
- value = getValue({ rowIndex, columnIndex });
935
- }
936
- return {
937
- rowIndex,
938
- columnIndex: (0, exports.isNull)(getValue({ columnIndex, rowIndex }))
939
- ? columnIndex - 1
940
- : columnIndex,
941
- };
942
- }
943
- case types_1.Direction.Left: {
944
- columnIndex = (0, exports.clampIndex)(Math.max(columnIndex - 1, limit), isHidden, direction);
945
- let value = getValue({ rowIndex, columnIndex });
946
- while (!(0, exports.isNull)(value) && columnIndex > limit) {
947
- columnIndex = (0, exports.clampIndex)(Math.max(--columnIndex, limit), isHidden, direction);
948
- value = getValue({ rowIndex, columnIndex });
949
- }
950
- return {
951
- rowIndex,
952
- columnIndex: (0, exports.isNull)(getValue({ columnIndex, rowIndex }))
953
- ? columnIndex + 1
954
- : columnIndex,
955
- };
956
- }
957
- default:
958
- return activeCell;
959
- }
960
- };
961
- exports.findLastContentfulCell = findLastContentfulCell;
962
- /**
963
- * Ex
964
- */
965
- const findNextCellInDataRegion = (activeCell, getValue, isHidden, direction, limit) => {
966
- var { rowIndex, columnIndex } = activeCell;
967
- const isCurrentCellEmpty = (0, exports.isNull)(getValue(activeCell));
968
- const didWeReachTheEdge = (cur, next) => {
969
- return (cur && next) || (cur && !next) || (!cur && next);
970
- };
971
- switch (direction) {
972
- case types_1.Direction.Down: {
973
- const nextCellValue = getValue({ rowIndex: rowIndex + 1, columnIndex });
974
- const isNextCellEmpty = (0, exports.isNull)(nextCellValue);
975
- const isEdge = didWeReachTheEdge(isCurrentCellEmpty, isNextCellEmpty);
976
- const nextCell = isEdge
977
- ? (0, exports.findNextContentfulCell)(activeCell, getValue, isHidden, direction, limit)
978
- : (0, exports.findLastContentfulCell)(activeCell, getValue, isHidden, direction, limit);
979
- return nextCell === null || nextCell === void 0 ? void 0 : nextCell.rowIndex;
980
- }
981
- case types_1.Direction.Up: {
982
- const nextCellValue = getValue({ rowIndex: rowIndex - 1, columnIndex });
983
- const isNextCellEmpty = (0, exports.isNull)(nextCellValue);
984
- const isEdge = didWeReachTheEdge(isCurrentCellEmpty, isNextCellEmpty);
985
- const nextCell = isEdge
986
- ? (0, exports.findNextContentfulCell)(activeCell, getValue, isHidden, direction, limit)
987
- : (0, exports.findLastContentfulCell)(activeCell, getValue, isHidden, direction, limit);
988
- return nextCell === null || nextCell === void 0 ? void 0 : nextCell.rowIndex;
989
- }
990
- case types_1.Direction.Right: {
991
- const nextCellValue = getValue({
992
- rowIndex,
993
- columnIndex: columnIndex + 1,
994
- });
995
- const isNextCellEmpty = (0, exports.isNull)(nextCellValue);
996
- const isEdge = didWeReachTheEdge(isCurrentCellEmpty, isNextCellEmpty);
997
- const nextCell = isEdge
998
- ? (0, exports.findNextContentfulCell)(activeCell, getValue, isHidden, direction, limit)
999
- : (0, exports.findLastContentfulCell)(activeCell, getValue, isHidden, direction, limit);
1000
- return nextCell === null || nextCell === void 0 ? void 0 : nextCell.columnIndex;
1001
- }
1002
- case types_1.Direction.Left: {
1003
- const nextCellValue = getValue({
1004
- rowIndex,
1005
- columnIndex: columnIndex - 1,
1006
- });
1007
- const isNextCellEmpty = (0, exports.isNull)(nextCellValue);
1008
- const isEdge = didWeReachTheEdge(isCurrentCellEmpty, isNextCellEmpty);
1009
- const nextCell = isEdge
1010
- ? (0, exports.findNextContentfulCell)(activeCell, getValue, isHidden, direction, limit)
1011
- : (0, exports.findLastContentfulCell)(activeCell, getValue, isHidden, direction, limit);
1012
- return nextCell === null || nextCell === void 0 ? void 0 : nextCell.columnIndex;
1013
- }
1014
- }
1015
- };
1016
- exports.findNextCellInDataRegion = findNextCellInDataRegion;
1017
- /* Focusable node names */
1018
- exports.focusableNodeNames = new Set(["INPUT", "TEXTAREA", "SELECT"]);
1019
- /**
1020
- * Converts a value to string
1021
- * @param value
1022
- */
1023
- const castToString = (value) => {
1024
- if (value === null || value === void 0)
1025
- return void 0;
1026
- return typeof value !== "string" ? "" + value : value;
1027
- };
1028
- exports.castToString = castToString;
1029
- const isArrowKey = (keyCode) => {
1030
- return [types_1.KeyCodes.Up, types_1.KeyCodes.Down, types_1.KeyCodes.Left, types_1.KeyCodes.Right].includes(keyCode);
1031
- };
1032
- exports.isArrowKey = isArrowKey;
1033
- //# sourceMappingURL=helpers.js.map