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