@deephaven/grid 0.7.0 → 0.7.1-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/GridRange.js CHANGED
@@ -1,6 +1,24 @@
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
2
 
3
+ // Also exported via GridRange.SELECTION_DIRECTION
4
+ export var SELECTION_DIRECTION;
5
+
6
+ (function (SELECTION_DIRECTION) {
7
+ SELECTION_DIRECTION["DOWN"] = "DOWN";
8
+ SELECTION_DIRECTION["UP"] = "UP";
9
+ SELECTION_DIRECTION["LEFT"] = "LEFT";
10
+ SELECTION_DIRECTION["RIGHT"] = "RIGHT";
11
+ })(SELECTION_DIRECTION || (SELECTION_DIRECTION = {}));
12
+
3
13
  class GridRange {
14
+ /**
15
+ * Returns a normalized array of indexes ensuring left <= right and top <= bottom
16
+ * @param startColumn Start column index
17
+ * @param startRow Start row index
18
+ * @param endColumn End column index
19
+ * @param endRow End row index
20
+ * @returns Array containing normalized indexes [left, top, right, bottom]
21
+ */
4
22
  static normalize(startColumn, startRow, endColumn, endRow) {
5
23
  var left = startColumn;
6
24
  var top = startRow;
@@ -19,43 +37,84 @@ class GridRange {
19
37
 
20
38
  return [left, top, right, bottom];
21
39
  }
22
- /** Make a GridRange, but ensure startColumn <= endColumn, startRow <= endRow */
40
+ /**
41
+ * Makes a GridRange ensuring startColumn <= endColumn, startRow <= endRow
42
+ * @param startColumn Start column index
43
+ * @param startRow Start row index
44
+ * @param endColumn End column index
45
+ * @param endRow End row index
46
+ * @returns Normalized GridRange
47
+ */
23
48
 
24
49
 
25
- static makeNormalized() {
26
- return new GridRange(...GridRange.normalize(...arguments));
50
+ static makeNormalized(startColumn, startRow, endColumn, endRow) {
51
+ return new GridRange(...GridRange.normalize(startColumn, startRow, endColumn, endRow));
27
52
  }
53
+ /**
54
+ * Creates a GridRange representing a single cell
55
+ * @param column Column index
56
+ * @param row Row index
57
+ * @returns GridRange representing the cell
58
+ */
59
+
28
60
 
29
61
  static makeCell(column, row) {
30
62
  return new GridRange(column, row, column, row);
31
63
  }
64
+ /**
65
+ * Creates a GridRange representing an infinite length column
66
+ * @param column Column index
67
+ * @returns GridRange representing the column
68
+ */
69
+
32
70
 
33
71
  static makeColumn(column) {
34
72
  return new GridRange(column, null, column, null);
35
73
  }
74
+ /**
75
+ * Creates a GridRange representing an infinite length row
76
+ * @param row Row index
77
+ * @returns GridRange representing the row
78
+ */
79
+
36
80
 
37
81
  static makeRow(row) {
38
82
  return new GridRange(null, row, null, row);
39
83
  }
84
+ /**
85
+ * Returns the minimum value between 2 range indexes or null if at least 1 is null
86
+ * @param index1 First grid range index
87
+ * @param index2 Second grid range index
88
+ * @returns Minimum index or null if either index is null
89
+ */
40
90
 
41
- static minOrNull(value1, value2) {
42
- if (value1 == null || value2 == null) {
91
+
92
+ static minOrNull(index1, index2) {
93
+ if (index1 == null || index2 == null) {
43
94
  return null;
44
95
  }
45
96
 
46
- return Math.min(value1, value2);
97
+ return Math.min(index1, index2);
47
98
  }
99
+ /**
100
+ * Returns the maximum value between 2 range indexes or null if at least 1 is null
101
+ * @param index1 First grid range index
102
+ * @param index2 Second grid range index
103
+ * @returns Maximum index or null if either index is null
104
+ */
105
+
48
106
 
49
- static maxOrNull(value1, value2) {
50
- if (value1 == null || value2 == null) {
107
+ static maxOrNull(index1, index2) {
108
+ if (index1 == null || index2 == null) {
51
109
  return null;
52
110
  }
53
111
 
54
- return Math.max(value1, value2);
112
+ return Math.max(index1, index2);
55
113
  }
56
114
  /**
57
115
  * Consolidate the passed in ranges to the minimum set, merging overlapping ranges.
58
- * @param {[GridRange]} ranges The ranges to consolidate
116
+ * @param ranges The ranges to consolidate
117
+ * @returns Consolidated ranges
59
118
  */
60
119
 
61
120
 
@@ -117,46 +176,65 @@ class GridRange {
117
176
 
118
177
  return result;
119
178
  }
179
+ /**
180
+ * Checks if the 1-D ranges between 2 index pairs overlap or are continuous.
181
+ * For example ranges [0, 1] and [2, 3] are continuous and will return true.
182
+ * [0, 1] and [1, 3] overlap and return true.
183
+ * [0, 1] and [3, 4] do not overlap and have a gap so this will return false.
184
+ * @param start1 Start of 1st range
185
+ * @param end1 End of 1st range
186
+ * @param start2 Start of 2nd range
187
+ * @param end2 End of 2nd range
188
+ * @returns True if the ranges overlap or touch, else false
189
+ */
190
+
120
191
 
121
- static isAxisRangeTouching(start, end, otherStart, otherEnd) {
122
- if (start == null) {
123
- if (end == null) {
192
+ static isAxisRangeTouching(start1, end1, start2, end2) {
193
+ if (start1 == null) {
194
+ if (end1 == null) {
124
195
  return true;
125
196
  }
126
197
 
127
- if (otherStart == null) {
198
+ if (start2 == null) {
128
199
  return true;
129
200
  }
130
201
 
131
- return otherStart <= end + 1;
202
+ return start2 <= end1 + 1;
132
203
  }
133
204
 
134
- if (end == null) {
135
- if (otherEnd == null) {
205
+ if (end1 == null) {
206
+ if (end2 == null) {
136
207
  return true;
137
208
  }
138
209
 
139
- return otherEnd >= start - 1;
210
+ return end2 >= start1 - 1;
140
211
  }
141
212
 
142
- if (otherStart == null) {
143
- if (otherEnd == null) {
213
+ if (start2 == null) {
214
+ if (end2 == null) {
144
215
  return true;
145
216
  }
146
217
 
147
- return start <= otherEnd + 1;
218
+ return start1 <= end2 + 1;
148
219
  }
149
220
 
150
- if (otherEnd == null) {
151
- return end >= otherStart - 1;
221
+ if (end2 == null) {
222
+ return end1 >= start2 - 1;
152
223
  }
153
224
 
154
- if (otherStart >= start - 1) {
155
- return otherStart <= end + 1;
225
+ if (start2 >= start1 - 1) {
226
+ return start2 <= end1 + 1;
156
227
  }
157
228
 
158
- return otherEnd >= start - 1;
229
+ return end2 >= start1 - 1;
159
230
  }
231
+ /**
232
+ * Checks if 2 arrays of ranges are the same ranges
233
+ * @param ranges1 First array of ranges
234
+ * @param ranges2 Second array of ranges
235
+ * @returns True if the arrays contain the same ranges in the same order
236
+ */
237
+
160
238
 
161
239
  static rangeArraysEqual(ranges1, ranges2) {
162
240
  if (ranges1 === ranges2) {
@@ -177,14 +255,14 @@ class GridRange {
177
255
  }
178
256
  /**
179
257
  * Get the intersection (overlapping area) of two ranges
180
- * @param {GridRange} range One range to check for the intersection
181
- * @param {GridRange} otherRange The other range to check for the intersection
182
- * @returns {GridRange|null} Intersection of the two ranges. If they do not intersect, returns `null`.
258
+ * @param range One range to check for the intersection
259
+ * @param otherRange The other range to check for the intersection
260
+ * @returns Intersection of the two ranges. If they do not intersect, returns `null`.
183
261
  */
184
262
 
185
263
 
186
264
  static intersection(range, otherRange) {
187
- var _startColumn2, _endColumn2, _startRow2, _endRow2;
265
+ var _startColumn2, _endColumn2, _startRow2, _endRow2, _endColumn3, _endRow3;
188
266
 
189
267
  if (range.equals(otherRange)) {
190
268
  return range;
@@ -201,16 +279,17 @@ class GridRange {
201
279
  startRow = startRow != null && otherRange.startRow != null ? Math.max(startRow, otherRange.startRow) : (_startRow2 = startRow) !== null && _startRow2 !== void 0 ? _startRow2 : otherRange.startRow;
202
280
  endRow = endRow != null && otherRange.endRow != null ? Math.min(endRow, otherRange.endRow) : (_endRow2 = endRow) !== null && _endRow2 !== void 0 ? _endRow2 : otherRange.endRow;
203
281
 
204
- if (startColumn != null && startColumn > endColumn || startRow != null && startRow > endRow) {
282
+ if (startColumn != null && startColumn > ((_endColumn3 = endColumn) !== null && _endColumn3 !== void 0 ? _endColumn3 : -1) || startRow != null && startRow > ((_endRow3 = endRow) !== null && _endRow3 !== void 0 ? _endRow3 : -1)) {
205
283
  return null;
206
284
  }
207
285
 
208
286
  return new GridRange(startColumn, startRow, endColumn, endRow);
209
287
  }
210
288
  /**
211
- * @param {GridRange} range The range to be subtracted from
212
- * @param {GridRange} subtractRange The range to subtract from within this range
213
- * @returns {GridRange[]} The ranges needed to represent the remaining
289
+ * Subtracts 1 range from another
290
+ * @param range The range to be subtracted from
291
+ * @param subtractRange The range to subtract from within this range
292
+ * @returns The ranges needed to represent the remaining
214
293
  */
215
294
 
216
295
 
@@ -248,9 +327,9 @@ class GridRange {
248
327
  }
249
328
  /**
250
329
  * Subtract a range from multiple ranges
251
- * @param {GridRange[]} ranges The ranges to be subtracted from
252
- * @param {GridRange} subtractRange The range to subtract from within these ranges
253
- * @returns {GridRange[]} The ranges needed to represent the remaining
330
+ * @param ranges The ranges to be subtracted from
331
+ * @param subtractRange The range to subtract from within these ranges
332
+ * @returns The ranges needed to represent the remaining
254
333
  */
255
334
 
256
335
 
@@ -265,9 +344,9 @@ class GridRange {
265
344
  }
266
345
  /**
267
346
  * Subtract multiple ranges from multiple ranges
268
- * @param {GridRange[]} ranges The ranges to be subtracted from
269
- * @param {GridRange[]} subtractRanges The ranges to subtract from within these ranges
270
- * @returns {GridRange[]} The ranges needed to represent the remaining
347
+ * @param ranges The ranges to be subtracted from
348
+ * @param subtractRanges The ranges to subtract from within these ranges
349
+ * @returns The ranges needed to represent the remaining
271
350
  */
272
351
 
273
352
 
@@ -286,8 +365,8 @@ class GridRange {
286
365
  }
287
366
  /**
288
367
  * Test if a given range is bounded (all values are non-null)
289
- * @param {GridRange} range The range to test
290
- * @returns {boolean} True if this range is bounded, false otherwise
368
+ * @param range The range to test
369
+ * @returns True if this range is bounded, false otherwise
291
370
  */
292
371
 
293
372
 
@@ -298,10 +377,10 @@ class GridRange {
298
377
  * Converts any GridRange passed in that is a full row or column selection to be bound
299
378
  * to the `columnCount` and `rowCount` passed in
300
379
  *
301
- * @param {GridRange} range The range to get the bounded range of
302
- * @param {number} columnCount The number of columns
303
- * @param {number} rowCount The number of rows
304
- * @returns {GridRange} The passed in GridRange with any null values filled in
380
+ * @param range The range to get the bounded range of
381
+ * @param columnCount The number of columns
382
+ * @param rowCount The number of rows
383
+ * @returns The passed in GridRange with any null values filled in
305
384
  */
306
385
 
307
386
 
@@ -317,10 +396,10 @@ class GridRange {
317
396
  /**
318
397
  * Converts the GridRanges passed in to be bound to the `columnCount` and `rowCount` passed in
319
398
  *
320
- * @param {GridRange[]} ranges The ranges to get the bounded ranges of
321
- * @param {number} columnCount The number of columns
322
- * @param {number} rowCount The number of rows
323
- * @returns {GridRange} The passed in GridRange with any null values filled in
399
+ * @param ranges The ranges to get the bounded ranges of
400
+ * @param columnCount The number of columns
401
+ * @param rowCount The number of rows
402
+ * @returns The passed in GridRange with any null values filled in
324
403
  */
325
404
 
326
405
 
@@ -330,10 +409,10 @@ class GridRange {
330
409
  /**
331
410
  * Offsets a GridRange by the specified amount in the x and y directions
332
411
  *
333
- * @param {GridRange} range The range to offset
334
- * @param {number} columnOffset The number of columns to offset
335
- * @param {number} rowOffset The number of rows to offset
336
- * @returns {GridRange} The new grid range offset from the original
412
+ * @param range The range to offset
413
+ * @param columnOffset The number of columns to offset
414
+ * @param rowOffset The number of rows to offset
415
+ * @returns The new grid range offset from the original
337
416
  */
338
417
 
339
418
 
@@ -342,11 +421,11 @@ class GridRange {
342
421
  }
343
422
  /**
344
423
  * Get the next cell given the selected ranges and the current cell
345
- * @param {GridRange[]} ranges The selected bounded ranges within the grid
346
- * @param {number|null} column The cursor column, or null if none focused
347
- * @param {number|null} row The cursor row, or null if none focused
348
- * @param {SELECTION_DIRECTION} direction The direction in which to select next
349
- * @returns {Cell} The next cell to focus, or null if there should be no more focus
424
+ * @param ranges The selected bounded ranges within the grid
425
+ * @param column The cursor column, or null if none focused
426
+ * @param row The cursor row, or null if none focused
427
+ * @param direction The direction in which to select next
428
+ * @returns The next cell to focus, or null if there should be no more focus
350
429
  */
351
430
 
352
431
 
@@ -399,8 +478,8 @@ class GridRange {
399
478
  }
400
479
  /**
401
480
  * Count the number of cells in the provided grid ranges
402
- * @param {GridRange[]} ranges The ranges to count the rows of
403
- * @returns {number|NaN} The number of cells in the ranges, or `NaN` if any of the ranges were unbounded
481
+ * @param ranges The ranges to count the rows of
482
+ * @returns The number of cells in the ranges, or `NaN` if any of the ranges were unbounded
404
483
  */
405
484
 
406
485
 
@@ -413,8 +492,8 @@ class GridRange {
413
492
  }
414
493
  /**
415
494
  * Count the number of rows in the provided grid ranges
416
- * @param {GridRange[]} ranges The ranges to count the rows of
417
- * @returns {number|NaN} The number of rows in the ranges, or `NaN` if any of the ranges were unbounded
495
+ * @param ranges The ranges to count the rows of
496
+ * @returns The number of rows in the ranges, or `NaN` if any of the ranges were unbounded
418
497
  */
419
498
 
420
499
 
@@ -427,8 +506,8 @@ class GridRange {
427
506
  }
428
507
  /**
429
508
  * Count the number of columns in the provided grid ranges
430
- * @param {GridRange[]} ranges The ranges to count the columns of
431
- * @returns {number|NaN} The number of columns in the ranges, or `NaN` if any of the ranges were unbounded
509
+ * @param ranges The ranges to count the columns of
510
+ * @returns The number of columns in the ranges, or `NaN` if any of the ranges were unbounded
432
511
  */
433
512
 
434
513
 
@@ -441,10 +520,10 @@ class GridRange {
441
520
  }
442
521
  /**
443
522
  * Check if the provided ranges contain the provided cell
444
- * @param {GridRange[]} ranges The ranges to check
445
- * @param {number} column The column index
446
- * @param {number} row The row index
447
- * @returns {boolean} True if the cell is within the provided ranges, false otherwise.
523
+ * @param ranges The ranges to check
524
+ * @param column The column index
525
+ * @param row The row index
526
+ * @returns True if the cell is within the provided ranges, false otherwise.
448
527
  */
449
528
 
450
529
 
@@ -461,7 +540,7 @@ class GridRange {
461
540
  }
462
541
  /**
463
542
  * Iterate through each cell in the provided ranges
464
- * @param {GridRange[]} ranges The ranges to iterate through
543
+ * @param ranges The ranges to iterate through
465
544
  * @param {(column: number, row: number, index: number) => void} callback The callback to execute. `index` is the index within that range
466
545
  * @param {GridRange.SELECTION_DIRECTION} direction The direction to iterate in
467
546
  */
@@ -476,16 +555,34 @@ class GridRange {
476
555
  }
477
556
 
478
557
  constructor(startColumn, startRow, endColumn, endRow) {
558
+ _defineProperty(this, "startColumn", void 0);
559
+
560
+ _defineProperty(this, "startRow", void 0);
561
+
562
+ _defineProperty(this, "endColumn", void 0);
563
+
564
+ _defineProperty(this, "endRow", void 0);
565
+
479
566
  this.startColumn = startColumn;
480
567
  this.startRow = startRow;
481
568
  this.endColumn = endColumn;
482
569
  this.endRow = endRow;
483
570
  }
571
+ /**
572
+ * Checks if the provided range is equivalent to this range (same start and end column/row indexes)
573
+ * @param other Grid range to check against
574
+ * @returns True if the ranges cover the same area
575
+ */
576
+
484
577
 
485
578
  equals(other) {
486
579
  return this.startColumn === other.startColumn && this.startRow === other.startRow && this.endColumn === other.endColumn && this.endRow === other.endRow;
487
580
  }
488
- /** @returns {boolean} true if this GridRange completely contains `other` */
581
+ /**
582
+ * Checks if this GridRange contains another range
583
+ * @param other The range to check
584
+ * @returns True if this GridRange completely contains `other`
585
+ * */
489
586
 
490
587
 
491
588
  contains(other) {
@@ -493,9 +590,9 @@ class GridRange {
493
590
  }
494
591
  /**
495
592
  * Check if the provided cell is in this range
496
- * @param {number} column The column to check
497
- * @param {number} row The row to check
498
- * @returns {boolean} True if this cell is within this range
593
+ * @param column The column to check
594
+ * @param row The row to check
595
+ * @returns True if this cell is within this range
499
596
  */
500
597
 
501
598
 
@@ -506,15 +603,21 @@ class GridRange {
506
603
 
507
604
  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);
508
605
  }
509
- /** @returns {boolean} true if this GridRange touches `other` */
606
+ /**
607
+ * Check if the provided range touches (or overlaps) this GridRange
608
+ * Effectively checks if the 2 ranges could be represented by 1 continuous range
609
+ * @param other The range to check
610
+ * @returns True if this GridRange touches `other`
611
+ * */
510
612
 
511
613
 
512
614
  touches(other) {
513
615
  return GridRange.isAxisRangeTouching(this.startRow, this.endRow, other.startRow, other.endRow) && GridRange.isAxisRangeTouching(this.startColumn, this.endColumn, other.startColumn, other.endColumn);
514
616
  }
515
617
  /**
516
- * @param {GridRange} other The range to deselect from within this range
517
- * @returns {[GridRange]} The ranges needed to represent the remaining
618
+ * Subtracts a range from this range
619
+ * @param other The range to deselect from within this range
620
+ * @returns The ranges needed to represent the remaining
518
621
  */
519
622
 
520
623
 
@@ -524,8 +627,8 @@ class GridRange {
524
627
  /**
525
628
  * Get the first cell in this range. Throws if this range is unbounded.
526
629
  *
527
- * @param {GridRange.SELECTION_DIRECTION?} direction The direction to get the starting cell in. Defaults to DOWN
528
- * @returns {{column: number, row: number}} The first cell in this range in the direction specified
630
+ * @param direction The direction to get the starting cell in. Defaults to DOWN
631
+ * @returns The first cell in this range in the direction specified
529
632
  */
530
633
 
531
634
 
@@ -663,8 +766,8 @@ class GridRange {
663
766
  }
664
767
  /**
665
768
  * Iterate through each cell in the range
666
- * @param {(column:number, row:number, index:number) => void} callback Callback to execute. `index` is the index within this range
667
- * @param {GridRange.SELECTION_DIRECTION} direction The direction to iterate in
769
+ * @param callback Callback to execute. `index` is the index within this range
770
+ * @param direction The direction to iterate in
668
771
  */
669
772
 
670
773
 
@@ -690,12 +793,7 @@ class GridRange {
690
793
 
691
794
  }
692
795
 
693
- _defineProperty(GridRange, "SELECTION_DIRECTION", Object.freeze({
694
- DOWN: 'DOWN',
695
- UP: 'UP',
696
- LEFT: 'LEFT',
697
- RIGHT: 'RIGHT'
698
- }));
796
+ _defineProperty(GridRange, "SELECTION_DIRECTION", SELECTION_DIRECTION);
699
797
 
700
798
  export default GridRange;
701
799
  //# sourceMappingURL=GridRange.js.map