@deephaven/grid 0.22.3-beta.18 → 0.22.3-beta.21

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 (82) hide show
  1. package/dist/CellInputField.d.ts +5 -5
  2. package/dist/CellInputField.d.ts.map +1 -1
  3. package/dist/CellInputField.js +6 -23
  4. package/dist/CellInputField.js.map +1 -1
  5. package/dist/EditableGridModel.js +1 -0
  6. package/dist/EditableGridModel.js.map +1 -1
  7. package/dist/ExpandableGridModel.js +1 -0
  8. package/dist/ExpandableGridModel.js.map +1 -1
  9. package/dist/Grid.js +77 -315
  10. package/dist/Grid.js.map +1 -1
  11. package/dist/GridAxisRange.js.map +1 -1
  12. package/dist/GridColorUtils.js +1 -2
  13. package/dist/GridColorUtils.js.map +1 -1
  14. package/dist/GridMetricCalculator.js +83 -240
  15. package/dist/GridMetricCalculator.js.map +1 -1
  16. package/dist/GridModel.js +13 -31
  17. package/dist/GridModel.js.map +1 -1
  18. package/dist/GridMouseHandler.js +2 -15
  19. package/dist/GridMouseHandler.js.map +1 -1
  20. package/dist/GridRange.js +46 -160
  21. package/dist/GridRange.js.map +1 -1
  22. package/dist/GridRenderer.js +126 -407
  23. package/dist/GridRenderer.js.map +1 -1
  24. package/dist/GridTestUtils.js +0 -5
  25. package/dist/GridTestUtils.js.map +1 -1
  26. package/dist/GridTheme.js.map +1 -1
  27. package/dist/GridUtils.js +68 -217
  28. package/dist/GridUtils.js.map +1 -1
  29. package/dist/KeyHandler.js +2 -8
  30. package/dist/KeyHandler.js.map +1 -1
  31. package/dist/MockGridData.js.map +1 -1
  32. package/dist/MockGridModel.js +0 -42
  33. package/dist/MockGridModel.js.map +1 -1
  34. package/dist/MockTreeGridModel.js +6 -55
  35. package/dist/MockTreeGridModel.js.map +1 -1
  36. package/dist/StaticDataGridModel.js +0 -15
  37. package/dist/StaticDataGridModel.js.map +1 -1
  38. package/dist/ThemeContext.js.map +1 -1
  39. package/dist/ViewportDataGridModel.js +0 -14
  40. package/dist/ViewportDataGridModel.js.map +1 -1
  41. package/dist/errors/AssertionError.js +0 -3
  42. package/dist/errors/AssertionError.js.map +1 -1
  43. package/dist/errors/PasteError.js +0 -3
  44. package/dist/errors/PasteError.js.map +1 -1
  45. package/dist/errors/assertIsDefined.js.map +1 -1
  46. package/dist/errors/index.js.map +1 -1
  47. package/dist/index.js.map +1 -1
  48. package/dist/key-handlers/EditKeyHandler.js +0 -12
  49. package/dist/key-handlers/EditKeyHandler.js.map +1 -1
  50. package/dist/key-handlers/PasteKeyHandler.js +15 -33
  51. package/dist/key-handlers/PasteKeyHandler.js.map +1 -1
  52. package/dist/key-handlers/SelectionKeyHandler.js +6 -53
  53. package/dist/key-handlers/SelectionKeyHandler.js.map +1 -1
  54. package/dist/key-handlers/TreeKeyHandler.js +0 -11
  55. package/dist/key-handlers/TreeKeyHandler.js.map +1 -1
  56. package/dist/key-handlers/index.js.map +1 -1
  57. package/dist/memoizeClear.js +1 -4
  58. package/dist/memoizeClear.js.map +1 -1
  59. package/dist/mouse-handlers/EditMouseHandler.js +0 -5
  60. package/dist/mouse-handlers/EditMouseHandler.js.map +1 -1
  61. package/dist/mouse-handlers/GridColumnMoveMouseHandler.js +35 -123
  62. package/dist/mouse-handlers/GridColumnMoveMouseHandler.js.map +1 -1
  63. package/dist/mouse-handlers/GridColumnSeparatorMouseHandler.js +2 -27
  64. package/dist/mouse-handlers/GridColumnSeparatorMouseHandler.js.map +1 -1
  65. package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.js +0 -28
  66. package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.js.map +1 -1
  67. package/dist/mouse-handlers/GridRowMoveMouseHandler.js +0 -27
  68. package/dist/mouse-handlers/GridRowMoveMouseHandler.js.map +1 -1
  69. package/dist/mouse-handlers/GridRowSeparatorMouseHandler.js +0 -23
  70. package/dist/mouse-handlers/GridRowSeparatorMouseHandler.js.map +1 -1
  71. package/dist/mouse-handlers/GridRowTreeMouseHandler.js +0 -10
  72. package/dist/mouse-handlers/GridRowTreeMouseHandler.js.map +1 -1
  73. package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.js +0 -6
  74. package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.js.map +1 -1
  75. package/dist/mouse-handlers/GridSelectionMouseHandler.js +8 -38
  76. package/dist/mouse-handlers/GridSelectionMouseHandler.js.map +1 -1
  77. package/dist/mouse-handlers/GridSeparatorMouseHandler.js +5 -54
  78. package/dist/mouse-handlers/GridSeparatorMouseHandler.js.map +1 -1
  79. package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.js +0 -28
  80. package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.js.map +1 -1
  81. package/dist/mouse-handlers/index.js.map +1 -1
  82. package/package.json +4 -4
package/dist/GridRange.js CHANGED
@@ -1,15 +1,12 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
3
2
  // Also exported via GridRange.SELECTION_DIRECTION
4
3
  export var SELECTION_DIRECTION;
5
-
6
4
  (function (SELECTION_DIRECTION) {
7
5
  SELECTION_DIRECTION["DOWN"] = "DOWN";
8
6
  SELECTION_DIRECTION["UP"] = "UP";
9
7
  SELECTION_DIRECTION["LEFT"] = "LEFT";
10
8
  SELECTION_DIRECTION["RIGHT"] = "RIGHT";
11
9
  })(SELECTION_DIRECTION || (SELECTION_DIRECTION = {}));
12
-
13
10
  export class GridRange {
14
11
  /**
15
12
  * Returns a normalized array of indexes ensuring left <= right and top <= bottom
@@ -24,19 +21,17 @@ export class GridRange {
24
21
  var top = startRow;
25
22
  var right = endColumn;
26
23
  var bottom = endRow;
27
-
28
24
  if (left != null && right != null && right < left) {
29
25
  left = right;
30
26
  right = startColumn;
31
27
  }
32
-
33
28
  if (top != null && bottom != null && bottom < top) {
34
29
  top = bottom;
35
30
  bottom = startRow;
36
31
  }
37
-
38
32
  return [left, top, right, bottom];
39
33
  }
34
+
40
35
  /**
41
36
  * Makes a GridRange ensuring startColumn <= endColumn, startRow <= endRow
42
37
  * @param startColumn Start column index
@@ -45,92 +40,80 @@ export class GridRange {
45
40
  * @param endRow End row index
46
41
  * @returns Normalized GridRange
47
42
  */
48
-
49
-
50
43
  static makeNormalized(startColumn, startRow, endColumn, endRow) {
51
44
  return new GridRange(...GridRange.normalize(startColumn, startRow, endColumn, endRow));
52
45
  }
46
+
53
47
  /**
54
48
  * Creates a GridRange representing a single cell
55
49
  * @param column Column index
56
50
  * @param row Row index
57
51
  * @returns GridRange representing the cell
58
52
  */
59
-
60
-
61
53
  static makeCell(column, row) {
62
54
  return new GridRange(column, row, column, row);
63
55
  }
56
+
64
57
  /**
65
58
  * Creates a GridRange representing an infinite length column
66
59
  * @param column Column index
67
60
  * @returns GridRange representing the column
68
61
  */
69
-
70
-
71
62
  static makeColumn(column) {
72
63
  return new GridRange(column, null, column, null);
73
64
  }
65
+
74
66
  /**
75
67
  * Creates a GridRange representing an infinite length row
76
68
  * @param row Row index
77
69
  * @returns GridRange representing the row
78
70
  */
79
-
80
-
81
71
  static makeRow(row) {
82
72
  return new GridRange(null, row, null, row);
83
73
  }
74
+
84
75
  /**
85
76
  * Returns the minimum value between 2 range indexes or null if at least 1 is null
86
77
  * @param index1 First grid range index
87
78
  * @param index2 Second grid range index
88
79
  * @returns Minimum index or null if either index is null
89
80
  */
90
-
91
-
92
81
  static minOrNull(index1, index2) {
93
82
  if (index1 == null || index2 == null) {
94
83
  return null;
95
84
  }
96
-
97
85
  return Math.min(index1, index2);
98
86
  }
87
+
99
88
  /**
100
89
  * Returns the maximum value between 2 range indexes or null if at least 1 is null
101
90
  * @param index1 First grid range index
102
91
  * @param index2 Second grid range index
103
92
  * @returns Maximum index or null if either index is null
104
93
  */
105
-
106
-
107
94
  static maxOrNull(index1, index2) {
108
95
  if (index1 == null || index2 == null) {
109
96
  return null;
110
97
  }
111
-
112
98
  return Math.max(index1, index2);
113
99
  }
100
+
114
101
  /**
115
102
  * Consolidate the passed in ranges to the minimum set, merging overlapping ranges.
116
103
  * @param ranges The ranges to consolidate
117
104
  * @returns Consolidated ranges
118
105
  */
119
-
120
-
121
106
  static consolidate(ranges) {
122
107
  var result = ranges.slice();
123
108
  var wasModified = true;
124
-
125
109
  while (wasModified) {
126
110
  wasModified = false;
127
-
128
111
  for (var i = 0; i < result.length && !wasModified; i += 1) {
129
112
  var range = result[i];
130
-
131
113
  for (var j = result.length - 1; j > i; j -= 1) {
132
- var other = result[j]; // If one contains the other, we can just keep the bigger one
114
+ var other = result[j];
133
115
 
116
+ // If one contains the other, we can just keep the bigger one
134
117
  if (range.contains(other)) {
135
118
  result.splice(j, 1);
136
119
  } else if (other.contains(range)) {
@@ -159,11 +142,8 @@ export class GridRange {
159
142
  startColumn: _startColumn,
160
143
  endColumn: _endColumn
161
144
  } = range;
162
-
163
145
  var _startRow = GridRange.minOrNull(range.startRow, other.startRow);
164
-
165
146
  var _endRow = GridRange.maxOrNull(range.endRow, other.endRow);
166
-
167
147
  wasModified = true;
168
148
  result[i] = new GridRange(_startColumn, _startRow, _endColumn, _endRow);
169
149
  result.splice(j, 1);
@@ -173,9 +153,9 @@ export class GridRange {
173
153
  }
174
154
  }
175
155
  }
176
-
177
156
  return result;
178
157
  }
158
+
179
159
  /**
180
160
  * Checks if the 1-D ranges between 2 index pairs overlap or are continuous.
181
161
  * For example ranges [0, 1] and [2, 3] are continuous and will return true.
@@ -187,87 +167,69 @@ export class GridRange {
187
167
  * @param end2 End of 2nd range
188
168
  * @returns True if the ranges overlap or touch, else false
189
169
  */
190
-
191
-
192
170
  static isAxisRangeTouching(start1, end1, start2, end2) {
193
171
  if (start1 == null) {
194
172
  if (end1 == null) {
195
173
  return true;
196
174
  }
197
-
198
175
  if (start2 == null) {
199
176
  return true;
200
177
  }
201
-
202
178
  return start2 <= end1 + 1;
203
179
  }
204
-
205
180
  if (end1 == null) {
206
181
  if (end2 == null) {
207
182
  return true;
208
183
  }
209
-
210
184
  return end2 >= start1 - 1;
211
185
  }
212
-
213
186
  if (start2 == null) {
214
187
  if (end2 == null) {
215
188
  return true;
216
189
  }
217
-
218
190
  return start1 <= end2 + 1;
219
191
  }
220
-
221
192
  if (end2 == null) {
222
193
  return end1 >= start2 - 1;
223
194
  }
224
-
225
195
  if (start2 >= start1 - 1) {
226
196
  return start2 <= end1 + 1;
227
197
  }
228
-
229
198
  return end2 >= start1 - 1;
230
199
  }
200
+
231
201
  /**
232
202
  * Checks if 2 arrays of ranges are the same ranges
233
203
  * @param ranges1 First array of ranges
234
204
  * @param ranges2 Second array of ranges
235
205
  * @returns True if the arrays contain the same ranges in the same order
236
206
  */
237
-
238
-
239
207
  static rangeArraysEqual(ranges1, ranges2) {
240
208
  if (ranges1 === ranges2) {
241
209
  return true;
242
210
  }
243
-
244
211
  if (ranges1 == null || ranges2 == null || ranges1.length !== ranges2.length) {
245
212
  return false;
246
213
  }
247
-
248
214
  for (var i = 0; i < ranges1.length; i += 1) {
249
215
  if (!ranges1[i].equals(ranges2[i])) {
250
216
  return false;
251
217
  }
252
218
  }
253
-
254
219
  return true;
255
220
  }
221
+
256
222
  /**
257
223
  * Get the intersection (overlapping area) of two ranges
258
224
  * @param range One range to check for the intersection
259
225
  * @param otherRange The other range to check for the intersection
260
226
  * @returns Intersection of the two ranges. If they do not intersect, returns `null`.
261
227
  */
262
-
263
-
264
228
  static intersection(range, otherRange) {
265
229
  var _startColumn2, _endColumn2, _startRow2, _endRow2, _endColumn3, _endRow3;
266
-
267
230
  if (range.equals(otherRange)) {
268
231
  return range;
269
232
  }
270
-
271
233
  var {
272
234
  startColumn,
273
235
  startRow,
@@ -278,101 +240,90 @@ export class GridRange {
278
240
  endColumn = endColumn != null && otherRange.endColumn != null ? Math.min(endColumn, otherRange.endColumn) : (_endColumn2 = endColumn) !== null && _endColumn2 !== void 0 ? _endColumn2 : otherRange.endColumn;
279
241
  startRow = startRow != null && otherRange.startRow != null ? Math.max(startRow, otherRange.startRow) : (_startRow2 = startRow) !== null && _startRow2 !== void 0 ? _startRow2 : otherRange.startRow;
280
242
  endRow = endRow != null && otherRange.endRow != null ? Math.min(endRow, otherRange.endRow) : (_endRow2 = endRow) !== null && _endRow2 !== void 0 ? _endRow2 : otherRange.endRow;
281
-
282
243
  if (startColumn != null && startColumn > ((_endColumn3 = endColumn) !== null && _endColumn3 !== void 0 ? _endColumn3 : -1) || startRow != null && startRow > ((_endRow3 = endRow) !== null && _endRow3 !== void 0 ? _endRow3 : -1)) {
283
244
  return null;
284
245
  }
285
-
286
246
  return new GridRange(startColumn, startRow, endColumn, endRow);
287
247
  }
248
+
288
249
  /**
289
250
  * Subtracts 1 range from another
290
251
  * @param range The range to be subtracted from
291
252
  * @param subtractRange The range to subtract from within this range
292
253
  * @returns The ranges needed to represent the remaining
293
254
  */
294
-
295
-
296
255
  static subtractFromRange(range, subtractRange) {
297
- var result = []; // Make it a little easier by finding only the part the subtraction range intersects
256
+ var result = [];
298
257
 
258
+ // Make it a little easier by finding only the part the subtraction range intersects
299
259
  var subtract = GridRange.intersection(range, subtractRange);
300
-
301
260
  if (subtract == null) {
302
261
  return [range];
303
- } // Go through each of the quadrants for deselection, there can be up to 4
304
- // Top quadrant (above the subtracted area)
305
-
262
+ }
306
263
 
264
+ // Go through each of the quadrants for deselection, there can be up to 4
265
+ // Top quadrant (above the subtracted area)
307
266
  if (subtract.startRow != null && (range.startRow == null || range.startRow < subtract.startRow)) {
308
267
  result.push(new GridRange(range.startColumn, range.startRow, range.endColumn, subtract.startRow - 1));
309
- } // middle left
310
-
268
+ }
311
269
 
270
+ // middle left
312
271
  if (subtract.startColumn != null && (range.startColumn == null || range.startColumn < subtract.startColumn)) {
313
272
  result.push(new GridRange(range.startColumn, subtract.startRow, subtract.startColumn - 1, subtract.endRow));
314
- } // middle right
315
-
273
+ }
316
274
 
275
+ // middle right
317
276
  if (subtract.endColumn != null && (range.endColumn == null || range.endColumn > subtract.endColumn)) {
318
277
  result.push(new GridRange(subtract.endColumn + 1, subtract.startRow, range.endColumn, subtract.endRow));
319
- } // Bottom quadrant
320
-
278
+ }
321
279
 
280
+ // Bottom quadrant
322
281
  if (subtract.endRow != null && (range.endRow == null || range.endRow > subtract.endRow)) {
323
282
  result.push(new GridRange(range.startColumn, subtract.endRow + 1, range.endColumn, range.endRow));
324
283
  }
325
-
326
284
  return result;
327
285
  }
286
+
328
287
  /**
329
288
  * Subtract a range from multiple ranges
330
289
  * @param ranges The ranges to be subtracted from
331
290
  * @param subtractRange The range to subtract from within these ranges
332
291
  * @returns The ranges needed to represent the remaining
333
292
  */
334
-
335
-
336
293
  static subtractFromRanges(ranges, subtractRange) {
337
294
  var result = [];
338
-
339
295
  for (var i = 0; i < ranges.length; i += 1) {
340
296
  result.push(...GridRange.subtractFromRange(ranges[i], subtractRange));
341
297
  }
342
-
343
298
  return result;
344
299
  }
300
+
345
301
  /**
346
302
  * Subtract multiple ranges from multiple ranges
347
303
  * @param ranges The ranges to be subtracted from
348
304
  * @param subtractRanges The ranges to subtract from within these ranges
349
305
  * @returns The ranges needed to represent the remaining
350
306
  */
351
-
352
-
353
307
  static subtractRangesFromRanges(ranges, subtractRanges) {
354
308
  if (subtractRanges == null || subtractRanges.length === 0) {
355
309
  return ranges;
356
310
  }
357
-
358
311
  var result = [...ranges];
359
-
360
312
  for (var i = 0; i < subtractRanges.length; i += 1) {
361
313
  result = GridRange.subtractFromRanges(result, subtractRanges[i]);
362
314
  }
363
-
364
315
  return result;
365
316
  }
317
+
366
318
  /**
367
319
  * Test if a given range is bounded (all values are non-null)
368
320
  * @param range The range to test
369
321
  * @returns True if this range is bounded, false otherwise
370
322
  */
371
-
372
-
373
323
  static isBounded(range) {
374
324
  return range.startRow != null && range.startColumn != null && range.endRow != null && range.endColumn != null;
375
325
  }
326
+
376
327
  /**
377
328
  * Converts any GridRange passed in that is a full row or column selection to be bound
378
329
  * to the `columnCount` and `rowCount` passed in
@@ -382,17 +333,14 @@ export class GridRange {
382
333
  * @param rowCount The number of rows
383
334
  * @returns The passed in GridRange with any null values filled in
384
335
  */
385
-
386
-
387
336
  static boundedRange(range, columnCount, rowCount) {
388
337
  var _range$startColumn, _range$startRow, _range$endColumn, _range$endRow;
389
-
390
338
  if (GridRange.isBounded(range)) {
391
339
  return range;
392
340
  }
393
-
394
341
  return new GridRange((_range$startColumn = range.startColumn) !== null && _range$startColumn !== void 0 ? _range$startColumn : 0, (_range$startRow = range.startRow) !== null && _range$startRow !== void 0 ? _range$startRow : 0, (_range$endColumn = range.endColumn) !== null && _range$endColumn !== void 0 ? _range$endColumn : columnCount - 1, (_range$endRow = range.endRow) !== null && _range$endRow !== void 0 ? _range$endRow : rowCount - 1);
395
342
  }
343
+
396
344
  /**
397
345
  * Converts the GridRanges passed in to be bound to the `columnCount` and `rowCount` passed in
398
346
  *
@@ -401,11 +349,10 @@ export class GridRange {
401
349
  * @param rowCount The number of rows
402
350
  * @returns The passed in GridRange with any null values filled in
403
351
  */
404
-
405
-
406
352
  static boundedRanges(ranges, columnCount, rowCount) {
407
353
  return ranges.map(r => GridRange.boundedRange(r, columnCount, rowCount));
408
354
  }
355
+
409
356
  /**
410
357
  * Offsets a GridRange by the specified amount in the x and y directions
411
358
  *
@@ -414,11 +361,10 @@ export class GridRange {
414
361
  * @param rowOffset The number of rows to offset
415
362
  * @returns The new grid range offset from the original
416
363
  */
417
-
418
-
419
364
  static offset(range, columnOffset, rowOffset) {
420
365
  return new GridRange(range.startColumn != null ? range.startColumn + columnOffset : null, range.startRow != null ? range.startRow + rowOffset : null, range.endColumn != null ? range.endColumn + columnOffset : null, range.endRow != null ? range.endRow + rowOffset : null);
421
366
  }
367
+
422
368
  /**
423
369
  * Get the next cell given the selected ranges and the current cell
424
370
  * @param ranges The selected bounded ranges within the grid
@@ -427,33 +373,26 @@ export class GridRange {
427
373
  * @param direction The direction in which to select next
428
374
  * @returns The next cell to focus, or null if there should be no more focus
429
375
  */
430
-
431
-
432
376
  static nextCell(ranges) {
433
377
  var column = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
434
378
  var row = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
435
379
  var direction = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : GridRange.SELECTION_DIRECTION.DOWN;
436
-
437
380
  if (ranges.length === 0) {
438
381
  return null;
439
382
  }
440
-
441
383
  var rangeIndex = -1;
442
-
443
384
  if (column != null && row != null) {
444
385
  rangeIndex = ranges.findIndex(r => r.containsCell(column, row));
445
-
446
386
  if (rangeIndex >= 0) {
447
387
  var range = ranges[rangeIndex];
448
388
  var nextCell = range.nextCell(column, row, direction);
449
-
450
389
  if (nextCell != null) {
451
390
  return nextCell;
452
391
  }
453
392
  }
454
- } // Otherwise go to the start of the next range (could be same range if only one range)
455
-
393
+ }
456
394
 
395
+ // Otherwise go to the start of the next range (could be same range if only one range)
457
396
  switch (direction) {
458
397
  case GridRange.SELECTION_DIRECTION.DOWN:
459
398
  case GridRange.SELECTION_DIRECTION.RIGHT:
@@ -462,62 +401,54 @@ export class GridRange {
462
401
  var nextRange = ranges[nextRangeIndex];
463
402
  return nextRange.startCell(direction);
464
403
  }
465
-
466
404
  case GridRange.SELECTION_DIRECTION.LEFT:
467
405
  case GridRange.SELECTION_DIRECTION.UP:
468
406
  {
469
407
  var _nextRangeIndex = rangeIndex > 0 ? rangeIndex - 1 : ranges.length - 1;
470
-
471
408
  var _nextRange = ranges[_nextRangeIndex];
472
409
  return _nextRange.startCell(direction);
473
410
  }
474
-
475
411
  default:
476
412
  throw new Error("Invalid direction: ".concat(direction));
477
413
  }
478
414
  }
415
+
479
416
  /**
480
417
  * Count the number of cells in the provided grid ranges
481
418
  * @param ranges The ranges to count the rows of
482
419
  * @returns The number of cells in the ranges, or `NaN` if any of the ranges were unbounded
483
420
  */
484
-
485
-
486
421
  static cellCount(ranges) {
487
422
  return ranges.reduce((cellCount, range) => {
488
423
  var _range$endRow2, _range$startRow2, _range$endColumn2, _range$startColumn2;
489
-
490
424
  return cellCount + (((_range$endRow2 = range.endRow) !== null && _range$endRow2 !== void 0 ? _range$endRow2 : NaN) - ((_range$startRow2 = range.startRow) !== null && _range$startRow2 !== void 0 ? _range$startRow2 : NaN) + 1) * (((_range$endColumn2 = range.endColumn) !== null && _range$endColumn2 !== void 0 ? _range$endColumn2 : NaN) - ((_range$startColumn2 = range.startColumn) !== null && _range$startColumn2 !== void 0 ? _range$startColumn2 : NaN) + 1);
491
425
  }, 0);
492
426
  }
427
+
493
428
  /**
494
429
  * Count the number of rows in the provided grid ranges
495
430
  * @param ranges The ranges to count the rows of
496
431
  * @returns The number of rows in the ranges, or `NaN` if any of the ranges were unbounded
497
432
  */
498
-
499
-
500
433
  static rowCount(ranges) {
501
434
  return ranges.reduce((rowCount, range) => {
502
435
  var _range$endRow3, _range$startRow3;
503
-
504
436
  return rowCount + ((_range$endRow3 = range.endRow) !== null && _range$endRow3 !== void 0 ? _range$endRow3 : NaN) - ((_range$startRow3 = range.startRow) !== null && _range$startRow3 !== void 0 ? _range$startRow3 : NaN) + 1;
505
437
  }, 0);
506
438
  }
439
+
507
440
  /**
508
441
  * Count the number of columns in the provided grid ranges
509
442
  * @param ranges The ranges to count the columns of
510
443
  * @returns The number of columns in the ranges, or `NaN` if any of the ranges were unbounded
511
444
  */
512
-
513
-
514
445
  static columnCount(ranges) {
515
446
  return ranges.reduce((columnCount, range) => {
516
447
  var _range$endColumn3, _range$startColumn3;
517
-
518
448
  return columnCount + ((_range$endColumn3 = range.endColumn) !== null && _range$endColumn3 !== void 0 ? _range$endColumn3 : NaN) - ((_range$startColumn3 = range.startColumn) !== null && _range$startColumn3 !== void 0 ? _range$startColumn3 : NaN) + 1;
519
449
  }, 0);
520
450
  }
451
+
521
452
  /**
522
453
  * Check if the provided ranges contain the provided cell
523
454
  * @param ranges The ranges to check
@@ -525,120 +456,100 @@ export class GridRange {
525
456
  * @param row The row index
526
457
  * @returns True if the cell is within the provided ranges, false otherwise.
527
458
  */
528
-
529
-
530
459
  static containsCell(ranges, column, row) {
531
460
  for (var i = 0; i < ranges.length; i += 1) {
532
461
  var range = ranges[i];
533
-
534
462
  if (range.containsCell(column, row)) {
535
463
  return true;
536
464
  }
537
465
  }
538
-
539
466
  return false;
540
467
  }
468
+
541
469
  /**
542
470
  * Iterate through each cell in the provided ranges
543
471
  * @param ranges The ranges to iterate through
544
472
  * @param {(column: number, row: number, index: number) => void} callback The callback to execute. `index` is the index within that range
545
473
  * @param {GridRange.SELECTION_DIRECTION} direction The direction to iterate in
546
474
  */
547
-
548
-
549
475
  static forEachCell(ranges, callback) {
550
476
  var direction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : GridRange.SELECTION_DIRECTION.RIGHT;
551
-
552
477
  for (var i = 0; i < ranges.length; i += 1) {
553
478
  ranges[i].forEach(callback, direction);
554
479
  }
555
480
  }
556
-
557
481
  constructor(startColumn, startRow, endColumn, endRow) {
558
482
  _defineProperty(this, "startColumn", void 0);
559
-
560
483
  _defineProperty(this, "startRow", void 0);
561
-
562
484
  _defineProperty(this, "endColumn", void 0);
563
-
564
485
  _defineProperty(this, "endRow", void 0);
565
-
566
486
  this.startColumn = startColumn;
567
487
  this.startRow = startRow;
568
488
  this.endColumn = endColumn;
569
489
  this.endRow = endRow;
570
490
  }
491
+
571
492
  /**
572
493
  * Checks if the provided range is equivalent to this range (same start and end column/row indexes)
573
494
  * @param other Grid range to check against
574
495
  * @returns True if the ranges cover the same area
575
496
  */
576
-
577
-
578
497
  equals(other) {
579
498
  return this.startColumn === other.startColumn && this.startRow === other.startRow && this.endColumn === other.endColumn && this.endRow === other.endRow;
580
499
  }
500
+
581
501
  /**
582
502
  * Checks if this GridRange contains another range
583
503
  * @param other The range to check
584
504
  * @returns True if this GridRange completely contains `other`
585
505
  * */
586
-
587
-
588
506
  contains(other) {
589
507
  return (this.startColumn == null || other.startColumn != null && this.startColumn <= other.startColumn) && (this.startRow == null || other.startRow != null && this.startRow <= other.startRow) && (this.endColumn == null || other.endColumn != null && this.endColumn >= other.endColumn) && (this.endRow == null || other.endRow != null && this.endRow >= other.endRow);
590
508
  }
509
+
591
510
  /**
592
511
  * Check if the provided cell is in this range
593
512
  * @param column The column to check
594
513
  * @param row The row to check
595
514
  * @returns True if this cell is within this range
596
515
  */
597
-
598
-
599
516
  containsCell(column, row) {
600
517
  if (column == null || row == null) {
601
518
  return false;
602
519
  }
603
-
604
520
  return (this.startColumn == null || this.startColumn <= column) && (this.endColumn == null || this.endColumn >= column) && (this.startRow == null || this.startRow <= row) && (this.endRow == null || this.endRow >= row);
605
521
  }
522
+
606
523
  /**
607
524
  * Check if the provided range touches (or overlaps) this GridRange
608
525
  * Effectively checks if the 2 ranges could be represented by 1 continuous range
609
526
  * @param other The range to check
610
527
  * @returns True if this GridRange touches `other`
611
528
  * */
612
-
613
-
614
529
  touches(other) {
615
530
  return GridRange.isAxisRangeTouching(this.startRow, this.endRow, other.startRow, other.endRow) && GridRange.isAxisRangeTouching(this.startColumn, this.endColumn, other.startColumn, other.endColumn);
616
531
  }
532
+
617
533
  /**
618
534
  * Subtracts a range from this range
619
535
  * @param other The range to deselect from within this range
620
536
  * @returns The ranges needed to represent the remaining
621
537
  */
622
-
623
-
624
538
  subtract(other) {
625
539
  return GridRange.subtractFromRange(this, other);
626
540
  }
541
+
627
542
  /**
628
543
  * Get the first cell in this range. Throws if this range is unbounded.
629
544
  *
630
545
  * @param direction The direction to get the starting cell in. Defaults to DOWN
631
546
  * @returns The first cell in this range in the direction specified
632
547
  */
633
-
634
-
635
548
  startCell() {
636
549
  var direction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : GridRange.SELECTION_DIRECTION.DOWN;
637
-
638
550
  if (!GridRange.isBounded(this)) {
639
551
  throw new Error('Cannot get the startCell of an unbounded range');
640
552
  }
641
-
642
553
  switch (direction) {
643
554
  case GridRange.SELECTION_DIRECTION.DOWN:
644
555
  case GridRange.SELECTION_DIRECTION.RIGHT:
@@ -646,7 +557,6 @@ export class GridRange {
646
557
  column: this.startColumn,
647
558
  row: this.startRow
648
559
  };
649
-
650
560
  case GridRange.SELECTION_DIRECTION.LEFT:
651
561
  case GridRange.SELECTION_DIRECTION.UP:
652
562
  {
@@ -655,11 +565,11 @@ export class GridRange {
655
565
  row: this.endRow
656
566
  };
657
567
  }
658
-
659
568
  default:
660
569
  throw new Error("Invalid direction: ".concat(direction));
661
570
  }
662
571
  }
572
+
663
573
  /**
664
574
  * Get the next cell in the direction specified. Throws if this range is unbounded.
665
575
  * If already at the bounds of the range in that direction, wrap to the next column or row
@@ -671,24 +581,19 @@ export class GridRange {
671
581
  * @param direction The direction to go in
672
582
  * @returns The next cell in the direction specified, or `null` if at the end of the range
673
583
  */
674
-
675
-
676
584
  nextCell(column, row, direction) {
677
585
  if (!GridRange.isBounded(this)) {
678
586
  throw new Error('Bounded range required');
679
587
  }
680
-
681
588
  if (column == null || row == null) {
682
589
  throw new Error('Require a non-null cursor');
683
590
  }
684
-
685
591
  var {
686
592
  startColumn,
687
593
  endColumn,
688
594
  startRow,
689
595
  endRow
690
596
  } = this;
691
-
692
597
  switch (direction) {
693
598
  case GridRange.SELECTION_DIRECTION.DOWN:
694
599
  if (row < endRow) {
@@ -697,16 +602,13 @@ export class GridRange {
697
602
  row: Math.max(row + 1, startRow)
698
603
  };
699
604
  }
700
-
701
605
  if (column < endColumn) {
702
606
  return {
703
607
  column: Math.max(column + 1, startColumn),
704
608
  row: startRow
705
609
  };
706
610
  }
707
-
708
611
  break;
709
-
710
612
  case GridRange.SELECTION_DIRECTION.UP:
711
613
  if (row > startRow) {
712
614
  return {
@@ -714,16 +616,13 @@ export class GridRange {
714
616
  row: Math.min(row - 1, endRow)
715
617
  };
716
618
  }
717
-
718
619
  if (column > startColumn) {
719
620
  return {
720
621
  column: Math.min(column - 1, endColumn),
721
622
  row: endRow
722
623
  };
723
624
  }
724
-
725
625
  break;
726
-
727
626
  case GridRange.SELECTION_DIRECTION.RIGHT:
728
627
  if (column < endColumn) {
729
628
  return {
@@ -731,16 +630,13 @@ export class GridRange {
731
630
  row
732
631
  };
733
632
  }
734
-
735
633
  if (row < endRow) {
736
634
  return {
737
635
  column: startColumn,
738
636
  row: Math.max(row + 1, startRow)
739
637
  };
740
638
  }
741
-
742
639
  break;
743
-
744
640
  case GridRange.SELECTION_DIRECTION.LEFT:
745
641
  if (column > startColumn) {
746
642
  return {
@@ -748,29 +644,24 @@ export class GridRange {
748
644
  row
749
645
  };
750
646
  }
751
-
752
647
  if (row > startRow) {
753
648
  return {
754
649
  column: endColumn,
755
650
  row: Math.min(row - 1, endRow)
756
651
  };
757
652
  }
758
-
759
653
  break;
760
-
761
654
  default:
762
655
  throw new Error("Invalid direction: ".concat(direction));
763
656
  }
764
-
765
657
  return null;
766
658
  }
659
+
767
660
  /**
768
661
  * Iterate through each cell in the range
769
662
  * @param callback Callback to execute. `index` is the index within this range
770
663
  * @param direction The direction to iterate in
771
664
  */
772
-
773
-
774
665
  forEach(callback) {
775
666
  var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : GridRange.SELECTION_DIRECTION.RIGHT;
776
667
  var i = 0;
@@ -778,10 +669,8 @@ export class GridRange {
778
669
  column: c,
779
670
  row: r
780
671
  } = this.startCell(direction);
781
-
782
672
  while (c != null && r != null) {
783
673
  var _this$nextCell;
784
-
785
674
  callback(c, r, i);
786
675
  i += 1;
787
676
  ({
@@ -790,10 +679,7 @@ export class GridRange {
790
679
  } = (_this$nextCell = this.nextCell(c, r, direction)) !== null && _this$nextCell !== void 0 ? _this$nextCell : {});
791
680
  }
792
681
  }
793
-
794
682
  }
795
-
796
683
  _defineProperty(GridRange, "SELECTION_DIRECTION", SELECTION_DIRECTION);
797
-
798
684
  export default GridRange;
799
685
  //# sourceMappingURL=GridRange.js.map