@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,1198 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
+
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; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
|
+
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); }
|
|
6
|
+
import clamp from 'lodash.clamp';
|
|
7
|
+
import { find as linkifyFind } from 'linkifyjs';
|
|
8
|
+
import { EMPTY_ARRAY, getOrThrow } from '@deephaven/utils';
|
|
9
|
+
import GridRange from "./GridRange.js";
|
|
10
|
+
import { isBoundedAxisRange } from "./GridAxisRange.js";
|
|
11
|
+
import { isExpandableGridModel } from "./ExpandableGridModel.js";
|
|
12
|
+
export function isLinkToken(token) {
|
|
13
|
+
return (token === null || token === void 0 ? void 0 : token.href) !== undefined;
|
|
14
|
+
}
|
|
15
|
+
export class GridUtils {
|
|
16
|
+
// use same constant as chrome source for windows
|
|
17
|
+
// https://github.com/chromium/chromium/blob/973af9d461b6b5dc60208c8d3d66adc27e53da78/ui/events/blink/web_input_event_builders_win.cc#L285
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get the GridPoint for the coordinates provided
|
|
21
|
+
* @param x The grid x coordinate
|
|
22
|
+
* @param y The grid y coordinate
|
|
23
|
+
* @param metrics The grid metrics
|
|
24
|
+
* @returns The GridPoint including the column/row information
|
|
25
|
+
*/
|
|
26
|
+
static getGridPointFromXY(x, y, metrics) {
|
|
27
|
+
var column = GridUtils.getColumnAtX(x, metrics);
|
|
28
|
+
var row = GridUtils.getRowAtY(y, metrics);
|
|
29
|
+
var columnHeaderDepth = GridUtils.getColumnHeaderDepthAtY(y, metrics);
|
|
30
|
+
return {
|
|
31
|
+
x,
|
|
32
|
+
y,
|
|
33
|
+
row,
|
|
34
|
+
column,
|
|
35
|
+
columnHeaderDepth
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
static getCellInfoFromXY(x, y, metrics) {
|
|
39
|
+
var {
|
|
40
|
+
row,
|
|
41
|
+
column
|
|
42
|
+
} = GridUtils.getGridPointFromXY(x, y, metrics);
|
|
43
|
+
var {
|
|
44
|
+
allColumnWidths,
|
|
45
|
+
allRowHeights,
|
|
46
|
+
allColumnXs,
|
|
47
|
+
allRowYs,
|
|
48
|
+
modelColumns,
|
|
49
|
+
modelRows
|
|
50
|
+
} = metrics;
|
|
51
|
+
var modelRow = row !== null ? modelRows.get(row) : null;
|
|
52
|
+
var modelColumn = column !== null ? modelColumns.get(column) : null;
|
|
53
|
+
var left = column !== null ? allColumnXs.get(column) : null;
|
|
54
|
+
var top = row !== null ? allRowYs.get(row) : null;
|
|
55
|
+
var columnWidth = column !== null ? allColumnWidths.get(column) : null;
|
|
56
|
+
var rowHeight = row !== null ? allRowHeights.get(row) : null;
|
|
57
|
+
return {
|
|
58
|
+
row,
|
|
59
|
+
column,
|
|
60
|
+
modelRow: modelRow !== null && modelRow !== void 0 ? modelRow : null,
|
|
61
|
+
modelColumn: modelColumn !== null && modelColumn !== void 0 ? modelColumn : null,
|
|
62
|
+
left: left !== null && left !== void 0 ? left : null,
|
|
63
|
+
top: top !== null && top !== void 0 ? top : null,
|
|
64
|
+
columnWidth: columnWidth !== null && columnWidth !== void 0 ? columnWidth : null,
|
|
65
|
+
rowHeight: rowHeight !== null && rowHeight !== void 0 ? rowHeight : null
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
static getColumnHeaderDepthAtY(y, metrics) {
|
|
69
|
+
var row = GridUtils.getRowAtY(y, metrics);
|
|
70
|
+
var {
|
|
71
|
+
columnHeaderHeight,
|
|
72
|
+
columnHeaderMaxDepth
|
|
73
|
+
} = metrics;
|
|
74
|
+
if (row === null && y <= columnHeaderHeight * columnHeaderMaxDepth) {
|
|
75
|
+
return clamp(columnHeaderMaxDepth - Math.ceil(y / columnHeaderHeight), 0, columnHeaderMaxDepth - 1);
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Iterate through each floating item at the start and call a callback, returning the first result
|
|
82
|
+
* @param start The count of floating items at the start
|
|
83
|
+
* @param total The total number of items
|
|
84
|
+
* @param callback Function to call for each item
|
|
85
|
+
* @returns The result from the callback
|
|
86
|
+
*/
|
|
87
|
+
static iterateFloatingStart(start, total, callback) {
|
|
88
|
+
for (var i = 0; i < start && i < total; i += 1) {
|
|
89
|
+
var result = callback(i);
|
|
90
|
+
if (result !== undefined) {
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Iterate through floating items at the end. Iterates in increasing order.
|
|
99
|
+
* @param end The count of floating items at the end
|
|
100
|
+
* @param total The total number of items
|
|
101
|
+
* @param callback Function to call for each item
|
|
102
|
+
* @returns The result from the callback
|
|
103
|
+
*/
|
|
104
|
+
static iterateFloatingEnd(end, total, callback) {
|
|
105
|
+
for (var i = 0; i < end && total - (end - i) >= 0; i += 1) {
|
|
106
|
+
var result = callback(total - (end - i));
|
|
107
|
+
if (result !== undefined) {
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Iterate through all floating items in increasing order, starting with the top items.
|
|
116
|
+
* @param start Count of start floating rows, e.g. floatingTopRowCount
|
|
117
|
+
* @param end Count of end floating rows, e.g. floatingBottomRowCount
|
|
118
|
+
* @param total Total number of items
|
|
119
|
+
* @param callback Callback called for each value, stopping the iterating and returning the value if one is returned
|
|
120
|
+
*/
|
|
121
|
+
static iterateFloating(start, end, total, callback) {
|
|
122
|
+
var result = GridUtils.iterateFloatingStart(start, total, callback);
|
|
123
|
+
if (result !== undefined) {
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
return GridUtils.iterateFloatingEnd(end, total, callback);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Iterate through all items in one dimension on the grid - first floating, then visible.
|
|
131
|
+
* Call the callback for each item, break if a result is returned and return that result.
|
|
132
|
+
* @param visibleStart Index of the start of the visible viewport
|
|
133
|
+
* @param visibleEnd Index of the end of the visible viewport
|
|
134
|
+
* @param floatingStartCount Number of items floating at the start
|
|
135
|
+
* @param floatingEndCount Number of items floating at the end
|
|
136
|
+
* @param totalCount Total number of items
|
|
137
|
+
* @param callback Callback to call for each item
|
|
138
|
+
* @returns The first result from the callback called, or undefined
|
|
139
|
+
*/
|
|
140
|
+
static iterateAllItems(visibleStart, visibleEnd, floatingStartCount, floatingEndCount, totalCount, callback) {
|
|
141
|
+
var visibleStartIndex = Math.max(visibleStart, floatingStartCount);
|
|
142
|
+
var visibleEndIndex = Math.min(visibleEnd, totalCount - floatingEndCount - 1);
|
|
143
|
+
var result = GridUtils.iterateFloating(floatingStartCount, floatingEndCount, totalCount, callback);
|
|
144
|
+
if (result !== undefined) {
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
for (var i = visibleStartIndex; i <= visibleEndIndex; i += 1) {
|
|
148
|
+
result = callback(i);
|
|
149
|
+
if (result !== undefined) {
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Check if the coordinate is within the item specified in this dimension
|
|
158
|
+
* @param itemIndex Index of the item to check
|
|
159
|
+
* @param itemCoordinatess Coordinate of all items in this dimension
|
|
160
|
+
* @param itemSizes Size of all items in this dimension
|
|
161
|
+
* @param coordinate The coordinate to check
|
|
162
|
+
* @returns True if the coordinate is within the item specified, false otherwise
|
|
163
|
+
*/
|
|
164
|
+
static isInItem(itemIndex, itemCoordinates, itemSizes, coordinate) {
|
|
165
|
+
var _itemCoordinates$get, _itemSizes$get;
|
|
166
|
+
var itemX = (_itemCoordinates$get = itemCoordinates.get(itemIndex)) !== null && _itemCoordinates$get !== void 0 ? _itemCoordinates$get : 0;
|
|
167
|
+
var itemSize = (_itemSizes$get = itemSizes.get(itemIndex)) !== null && _itemSizes$get !== void 0 ? _itemSizes$get : 0;
|
|
168
|
+
return itemX <= coordinate && coordinate <= itemX + itemSize;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Get the Index of the item at the provided offset
|
|
173
|
+
* @param offset Coordinate of the offset to get the item of
|
|
174
|
+
* @param itemCount The total count of items
|
|
175
|
+
* @param floatingStart Count of floating items at the start
|
|
176
|
+
* @param floatingEnd Count of floating items at the end
|
|
177
|
+
* @param items Index of all items
|
|
178
|
+
* @param itemCoordinates The coordinate of each item
|
|
179
|
+
* @param itemSizes The size of each item
|
|
180
|
+
* @returns The item index, or null if no item matches
|
|
181
|
+
*/
|
|
182
|
+
static getItemAtOffset(offset, itemCount, floatingStart, floatingEnd, items, itemCoordinates, itemSizes) {
|
|
183
|
+
var ignoreFloating = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
|
|
184
|
+
var floatingItem = ignoreFloating ? undefined : GridUtils.iterateFloating(floatingStart, floatingEnd, itemCount, item => {
|
|
185
|
+
if (GridUtils.isInItem(item, itemCoordinates, itemSizes, offset)) {
|
|
186
|
+
return item;
|
|
187
|
+
}
|
|
188
|
+
return undefined;
|
|
189
|
+
});
|
|
190
|
+
if (!ignoreFloating && floatingItem !== undefined) {
|
|
191
|
+
return floatingItem;
|
|
192
|
+
}
|
|
193
|
+
for (var i = 0; i < items.length; i += 1) {
|
|
194
|
+
var item = items[i];
|
|
195
|
+
if (GridUtils.isInItem(item, itemCoordinates, itemSizes, offset)) {
|
|
196
|
+
return item;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Get the index of the column at the specified x coordinate
|
|
204
|
+
* @param x Coordinate to get the item of
|
|
205
|
+
* @param metrics Grid metrics
|
|
206
|
+
* @returns Index of the column at that coordinate, or null if no column matches
|
|
207
|
+
*/
|
|
208
|
+
static getColumnAtX(x, metrics) {
|
|
209
|
+
var ignoreFloating = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
210
|
+
var {
|
|
211
|
+
columnCount,
|
|
212
|
+
floatingLeftColumnCount,
|
|
213
|
+
floatingRightColumnCount,
|
|
214
|
+
visibleColumns,
|
|
215
|
+
allColumnXs,
|
|
216
|
+
allColumnWidths,
|
|
217
|
+
gridX
|
|
218
|
+
} = metrics;
|
|
219
|
+
if (x < gridX) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
return this.getItemAtOffset(x - gridX, columnCount, floatingLeftColumnCount, floatingRightColumnCount, visibleColumns, allColumnXs, allColumnWidths, ignoreFloating);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Get the index of the row at the specified y coordinate
|
|
227
|
+
* @param y Coordinate to get the item of
|
|
228
|
+
* @param metrics Grid metrics
|
|
229
|
+
* @returns Index of the row at that coordinate, or null if no row matches
|
|
230
|
+
*/
|
|
231
|
+
static getRowAtY(y, metrics) {
|
|
232
|
+
var {
|
|
233
|
+
floatingTopRowCount,
|
|
234
|
+
floatingBottomRowCount,
|
|
235
|
+
rowCount,
|
|
236
|
+
visibleRows,
|
|
237
|
+
allRowYs,
|
|
238
|
+
allRowHeights,
|
|
239
|
+
gridY
|
|
240
|
+
} = metrics;
|
|
241
|
+
if (y < gridY) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
return this.getItemAtOffset(y - gridY, rowCount, floatingTopRowCount, floatingBottomRowCount, visibleRows, allRowYs, allRowHeights);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Iterate backward through the visible items until a shown item is hit
|
|
249
|
+
* @param startIndex The index to start from
|
|
250
|
+
* @param modelIndexes The mapping of model indexes
|
|
251
|
+
* @param visibleItems The visible items
|
|
252
|
+
* @param userSizes The user set sizes
|
|
253
|
+
* @returns Index of the next visible item, or null if no more are visible
|
|
254
|
+
*/
|
|
255
|
+
static getNextShownItem(startIndex, modelIndexes, visibleItems, userSizes) {
|
|
256
|
+
var visibleItemIndex = visibleItems.findIndex(value => value === startIndex) || 0;
|
|
257
|
+
visibleItemIndex -= 1;
|
|
258
|
+
while (visibleItemIndex != null && visibleItemIndex >= 0) {
|
|
259
|
+
var item = visibleItems[visibleItemIndex];
|
|
260
|
+
var modelIndex = modelIndexes.get(item);
|
|
261
|
+
if (modelIndex != null && userSizes.get(modelIndex) !== 0) {
|
|
262
|
+
return item;
|
|
263
|
+
}
|
|
264
|
+
visibleItemIndex -= 1;
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Iterate backward through the visible columns until a shown column is hit
|
|
271
|
+
* @param columnIndex The column index to start iterating backward from
|
|
272
|
+
* @param metrics The GridMetricCalculator metrics
|
|
273
|
+
* @returns Index of the next visible item, or null if no more are visible
|
|
274
|
+
*/
|
|
275
|
+
static getNextShownColumn(startIndex, metrics) {
|
|
276
|
+
var {
|
|
277
|
+
modelColumns,
|
|
278
|
+
visibleColumns,
|
|
279
|
+
userColumnWidths
|
|
280
|
+
} = metrics;
|
|
281
|
+
return GridUtils.getNextShownItem(startIndex, modelColumns, visibleColumns, userColumnWidths);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Iterate backward through the visible rows until a shown row is hit
|
|
286
|
+
* @param rowIndex The row index to start iterating backward from
|
|
287
|
+
* @param metrics The GridMetricCalculator metrics
|
|
288
|
+
* @returns Index of the next visible item, or null if no more are visible
|
|
289
|
+
*/
|
|
290
|
+
static getNextShownRow(startIndex, metrics) {
|
|
291
|
+
var {
|
|
292
|
+
modelRows,
|
|
293
|
+
visibleRows,
|
|
294
|
+
userRowHeights
|
|
295
|
+
} = metrics;
|
|
296
|
+
return GridUtils.getNextShownItem(startIndex, modelRows, visibleRows, userRowHeights);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Gets the column index if the x/y coordinates provided are close enough to the separator, otherwise null
|
|
301
|
+
* @param x Mouse x coordinate
|
|
302
|
+
* @param y Mouse y coordinate
|
|
303
|
+
* @param metrics The grid metrics
|
|
304
|
+
* @param theme The grid theme with potential user overrides
|
|
305
|
+
* @returns Index of the column separator at the coordinates provided, or null if none match
|
|
306
|
+
*/
|
|
307
|
+
static getColumnSeparatorIndex(x, y, metrics, theme) {
|
|
308
|
+
var {
|
|
309
|
+
rowHeaderWidth,
|
|
310
|
+
columnHeaderHeight,
|
|
311
|
+
floatingColumns,
|
|
312
|
+
floatingLeftWidth,
|
|
313
|
+
visibleColumns,
|
|
314
|
+
allColumnXs,
|
|
315
|
+
allColumnWidths,
|
|
316
|
+
columnHeaderMaxDepth
|
|
317
|
+
} = metrics;
|
|
318
|
+
var {
|
|
319
|
+
allowColumnResize,
|
|
320
|
+
headerSeparatorHandleSize
|
|
321
|
+
} = theme;
|
|
322
|
+
if (columnHeaderMaxDepth * columnHeaderHeight < y || !allowColumnResize || headerSeparatorHandleSize <= 0) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
var gridX = x - rowHeaderWidth;
|
|
326
|
+
var halfSeparatorSize = headerSeparatorHandleSize * 0.5;
|
|
327
|
+
|
|
328
|
+
// Iterate through the floating columns first since they're on top
|
|
329
|
+
var isPreviousColumnHidden = false;
|
|
330
|
+
for (var i = floatingColumns.length - 1; i >= 0; i -= 1) {
|
|
331
|
+
var _allColumnXs$get, _allColumnWidths$get;
|
|
332
|
+
var column = floatingColumns[i];
|
|
333
|
+
var columnX = (_allColumnXs$get = allColumnXs.get(column)) !== null && _allColumnXs$get !== void 0 ? _allColumnXs$get : 0;
|
|
334
|
+
var columnWidth = (_allColumnWidths$get = allColumnWidths.get(column)) !== null && _allColumnWidths$get !== void 0 ? _allColumnWidths$get : 0;
|
|
335
|
+
var isColumnHidden = columnWidth === 0;
|
|
336
|
+
if (!isPreviousColumnHidden || !isColumnHidden) {
|
|
337
|
+
var midX = columnX + columnWidth;
|
|
338
|
+
if (isColumnHidden) {
|
|
339
|
+
midX += halfSeparatorSize;
|
|
340
|
+
} else if (isPreviousColumnHidden) {
|
|
341
|
+
midX -= halfSeparatorSize;
|
|
342
|
+
}
|
|
343
|
+
var minX = midX - halfSeparatorSize;
|
|
344
|
+
var maxX = midX + halfSeparatorSize;
|
|
345
|
+
if (minX <= gridX && gridX <= maxX) {
|
|
346
|
+
return column;
|
|
347
|
+
}
|
|
348
|
+
isPreviousColumnHidden = isColumnHidden;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Iterate backward so that you can reveal hidden columns properly
|
|
353
|
+
isPreviousColumnHidden = false;
|
|
354
|
+
for (var _i = visibleColumns.length - 1; _i >= 0; _i -= 1) {
|
|
355
|
+
var _allColumnXs$get2, _allColumnWidths$get2;
|
|
356
|
+
var _column = visibleColumns[_i];
|
|
357
|
+
var _columnX = (_allColumnXs$get2 = allColumnXs.get(_column)) !== null && _allColumnXs$get2 !== void 0 ? _allColumnXs$get2 : 0;
|
|
358
|
+
var _columnWidth = (_allColumnWidths$get2 = allColumnWidths.get(_column)) !== null && _allColumnWidths$get2 !== void 0 ? _allColumnWidths$get2 : 0;
|
|
359
|
+
var _isColumnHidden = _columnWidth === 0;
|
|
360
|
+
|
|
361
|
+
// If this column is under the floating columns "layer". Terminate early.
|
|
362
|
+
if (_columnX < floatingLeftWidth - _columnWidth) {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
if (!isPreviousColumnHidden || !_isColumnHidden) {
|
|
366
|
+
var _midX = _columnX + _columnWidth;
|
|
367
|
+
if (_isColumnHidden) {
|
|
368
|
+
_midX += halfSeparatorSize;
|
|
369
|
+
} else if (isPreviousColumnHidden) {
|
|
370
|
+
_midX -= halfSeparatorSize;
|
|
371
|
+
}
|
|
372
|
+
var _minX = _midX - halfSeparatorSize;
|
|
373
|
+
var _maxX = _midX + halfSeparatorSize;
|
|
374
|
+
if (_minX <= gridX && gridX <= _maxX) {
|
|
375
|
+
return _column;
|
|
376
|
+
}
|
|
377
|
+
isPreviousColumnHidden = _isColumnHidden;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Check if the item specified is hidden
|
|
385
|
+
* @param itemIndex Index of the item to check
|
|
386
|
+
* @param visibleSizes Sizes of all visible items
|
|
387
|
+
* @returns True if the item is hidden, false otherwise
|
|
388
|
+
*/
|
|
389
|
+
static isItemHidden(itemIndex, visibleSizes) {
|
|
390
|
+
return visibleSizes.get(itemIndex) === 0;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Check if the column specified is hidden
|
|
395
|
+
* @param columnIndex Index of the column to check
|
|
396
|
+
* @param metrics Grid metrics
|
|
397
|
+
* @returns True if the column is hidden, false otherwise
|
|
398
|
+
*/
|
|
399
|
+
static isColumnHidden(columnIndex, metrics) {
|
|
400
|
+
var {
|
|
401
|
+
allColumnWidths
|
|
402
|
+
} = metrics;
|
|
403
|
+
return GridUtils.isItemHidden(columnIndex, allColumnWidths);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Check if the provided row is a floating row
|
|
408
|
+
* @param row The row index to check
|
|
409
|
+
* @param metrics The grid metrics to check against
|
|
410
|
+
* @returns True if it's a floating row, false otherwise
|
|
411
|
+
*/
|
|
412
|
+
static isFloatingRow(row, metrics) {
|
|
413
|
+
if (row == null) {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
var {
|
|
417
|
+
floatingTopRowCount,
|
|
418
|
+
floatingBottomRowCount,
|
|
419
|
+
rowCount
|
|
420
|
+
} = metrics;
|
|
421
|
+
return row < floatingTopRowCount || row >= rowCount - floatingBottomRowCount;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Check if the provided column is a floating column
|
|
426
|
+
* @param column The column index to check
|
|
427
|
+
* @param metrics The grid metrics to check against
|
|
428
|
+
* @returns True if it's a floating column, false otherwise
|
|
429
|
+
*/
|
|
430
|
+
static isFloatingColumn(column, metrics) {
|
|
431
|
+
if (column == null) {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
var {
|
|
435
|
+
floatingLeftColumnCount,
|
|
436
|
+
floatingRightColumnCount,
|
|
437
|
+
columnCount
|
|
438
|
+
} = metrics;
|
|
439
|
+
return column < floatingLeftColumnCount || column >= columnCount - floatingRightColumnCount;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Get all the items that are hidden under the same Index
|
|
444
|
+
* E.g. If columns are 1, 2, 3, 4, 5, and column 2, 3, 4 are hidden, and we check for item 4, the return will be [2, 3, 4]
|
|
445
|
+
* @param itemIndex Index of the item to start at
|
|
446
|
+
* @param visibleSizes Visible size map
|
|
447
|
+
* @param visibleItems Visible items
|
|
448
|
+
* @returns Array of items that are hidden
|
|
449
|
+
*/
|
|
450
|
+
static getHiddenItems(itemIndex, visibleSizes, visibleItems) {
|
|
451
|
+
if (!GridUtils.isItemHidden(itemIndex, visibleSizes)) {
|
|
452
|
+
return [];
|
|
453
|
+
}
|
|
454
|
+
var hiddenItems = [itemIndex];
|
|
455
|
+
var visibleItemIndex = visibleItems.findIndex(value => value === itemIndex);
|
|
456
|
+
for (var i = visibleItemIndex - 1; i >= 0; i -= 1) {
|
|
457
|
+
var item = visibleItems[i];
|
|
458
|
+
if (!GridUtils.isItemHidden(item, visibleSizes)) {
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
hiddenItems.push(item);
|
|
462
|
+
}
|
|
463
|
+
return hiddenItems;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Get all the columns that are hidden under the same Index
|
|
468
|
+
* @param columnIndex Index of the item to start at
|
|
469
|
+
* @param metrics Grid metrics
|
|
470
|
+
* @returns Array of items that are hidden
|
|
471
|
+
*/
|
|
472
|
+
static getHiddenColumns(columnIndex, metrics) {
|
|
473
|
+
var {
|
|
474
|
+
visibleColumns,
|
|
475
|
+
allColumnWidths
|
|
476
|
+
} = metrics;
|
|
477
|
+
return GridUtils.getHiddenItems(columnIndex, allColumnWidths, visibleColumns);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Returns the row index if the x/y coordinates provided are close enough to the separator, otherwise null
|
|
482
|
+
* @param x X coordinate to check
|
|
483
|
+
* @param y Y coordinate to check
|
|
484
|
+
* @param metrics The grid metrics
|
|
485
|
+
* @param theme The grid theme
|
|
486
|
+
* @returns Index of the row separator at the coordinates provided, or null if none match
|
|
487
|
+
*/
|
|
488
|
+
static getRowSeparatorIndex(x, y, metrics, theme) {
|
|
489
|
+
var {
|
|
490
|
+
rowHeaderWidth,
|
|
491
|
+
columnHeaderHeight,
|
|
492
|
+
visibleRows,
|
|
493
|
+
allRowYs,
|
|
494
|
+
allRowHeights
|
|
495
|
+
} = metrics;
|
|
496
|
+
var {
|
|
497
|
+
allowRowResize,
|
|
498
|
+
headerSeparatorHandleSize
|
|
499
|
+
} = theme;
|
|
500
|
+
if (rowHeaderWidth < x || !allowRowResize || headerSeparatorHandleSize <= 0) {
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
var gridY = y - columnHeaderHeight;
|
|
504
|
+
var halfSeparatorSize = headerSeparatorHandleSize * 0.5;
|
|
505
|
+
|
|
506
|
+
// Iterate backward so you can reveal hidden rows properly
|
|
507
|
+
var isPreviousRowHidden = false;
|
|
508
|
+
for (var i = visibleRows.length - 1; i >= 0; i -= 1) {
|
|
509
|
+
var _allRowYs$get, _allRowHeights$get;
|
|
510
|
+
var row = visibleRows[i];
|
|
511
|
+
var rowY = (_allRowYs$get = allRowYs.get(row)) !== null && _allRowYs$get !== void 0 ? _allRowYs$get : 0;
|
|
512
|
+
var rowHeight = (_allRowHeights$get = allRowHeights.get(row)) !== null && _allRowHeights$get !== void 0 ? _allRowHeights$get : 0;
|
|
513
|
+
var isRowHidden = rowHeight === 0;
|
|
514
|
+
if (!isPreviousRowHidden || !isRowHidden) {
|
|
515
|
+
var midY = rowY + rowHeight;
|
|
516
|
+
if (isRowHidden) {
|
|
517
|
+
midY += halfSeparatorSize;
|
|
518
|
+
} else if (isPreviousRowHidden) {
|
|
519
|
+
midY -= halfSeparatorSize;
|
|
520
|
+
}
|
|
521
|
+
var minY = midY - halfSeparatorSize;
|
|
522
|
+
var maxY = midY + halfSeparatorSize;
|
|
523
|
+
if (minY <= gridY && gridY <= maxY) {
|
|
524
|
+
return row;
|
|
525
|
+
}
|
|
526
|
+
isPreviousRowHidden = isRowHidden;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Check if the row specified is hidden
|
|
534
|
+
* @param rowIndex Index of the row to check
|
|
535
|
+
* @param metrics Grid metrics
|
|
536
|
+
* @returns True if the row is hidden, false otherwise
|
|
537
|
+
*/
|
|
538
|
+
static isRowHidden(rowIndex, metrics) {
|
|
539
|
+
var {
|
|
540
|
+
allRowHeights
|
|
541
|
+
} = metrics;
|
|
542
|
+
return GridUtils.isItemHidden(rowIndex, allRowHeights);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Get all the rows that are hidden under the same Index
|
|
547
|
+
* @param rowIndex Index of the item to start at
|
|
548
|
+
* @param metrics Grid metrics
|
|
549
|
+
* @returns Array of items that are hidden
|
|
550
|
+
*/
|
|
551
|
+
static getHiddenRows(rowIndex, metrics) {
|
|
552
|
+
var {
|
|
553
|
+
visibleRows,
|
|
554
|
+
allRowHeights
|
|
555
|
+
} = metrics;
|
|
556
|
+
return GridUtils.getHiddenItems(rowIndex, allRowHeights, visibleRows);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Set a new order for items in the grid
|
|
561
|
+
* @param from The visible index to move from
|
|
562
|
+
* @param to The visible index to move the item to
|
|
563
|
+
* @param oldMovedItems The old reordered items
|
|
564
|
+
* @returns The new reordered items
|
|
565
|
+
*/
|
|
566
|
+
static moveItem(from, to, oldMovedItems) {
|
|
567
|
+
if (from === to) {
|
|
568
|
+
return [...oldMovedItems];
|
|
569
|
+
}
|
|
570
|
+
var movedItems = [...oldMovedItems];
|
|
571
|
+
var lastMovedItem = movedItems[movedItems.length - 1];
|
|
572
|
+
|
|
573
|
+
// Check if we should combine with the previous move
|
|
574
|
+
// E.g. 1 -> 2, 2 -> 3 can just be 1 -> 3
|
|
575
|
+
if (lastMovedItem != null && !isBoundedAxisRange(lastMovedItem.from) && lastMovedItem.to === from) {
|
|
576
|
+
// Remove the move if it is now a no-op
|
|
577
|
+
if (lastMovedItem.from === to) {
|
|
578
|
+
movedItems.pop();
|
|
579
|
+
} else {
|
|
580
|
+
movedItems[movedItems.length - 1] = _objectSpread(_objectSpread({}, lastMovedItem), {}, {
|
|
581
|
+
to
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
} else {
|
|
585
|
+
movedItems.push({
|
|
586
|
+
from,
|
|
587
|
+
to
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
return movedItems;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Move a visible range in the grid
|
|
595
|
+
*
|
|
596
|
+
* This will effectively slice the range out of the grid,
|
|
597
|
+
* re-index the remaining columns,
|
|
598
|
+
* then insert the range with the first element at the provided index
|
|
599
|
+
*
|
|
600
|
+
* @param from The visible axis range to move
|
|
601
|
+
* @param to The visible index to move the start of the range to
|
|
602
|
+
* @param oldMovedItems The old reordered items
|
|
603
|
+
* @param isPreMoveTo If toParam is the index before the movement
|
|
604
|
+
* If true, this will account for the shift when moving
|
|
605
|
+
* a range before the drop positin
|
|
606
|
+
* E.g. Move range [0, 2] 1 item down (after element 3)
|
|
607
|
+
* The move is [0, 2] -> 1 if this is false. [0, 2] -> 3 if this is true
|
|
608
|
+
* Both will result in [0, 2] -> 1
|
|
609
|
+
* @returns The new reordered items
|
|
610
|
+
*/
|
|
611
|
+
static moveRange(from, toParam, oldMovedItems) {
|
|
612
|
+
var isPreMoveTo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
613
|
+
if (from[0] === from[1]) {
|
|
614
|
+
return GridUtils.moveItem(from[0], toParam, oldMovedItems);
|
|
615
|
+
}
|
|
616
|
+
var to = toParam;
|
|
617
|
+
if (isPreMoveTo && from[0] < toParam) {
|
|
618
|
+
to -= from[1] - from[0];
|
|
619
|
+
}
|
|
620
|
+
if (from[0] === to) {
|
|
621
|
+
return [...oldMovedItems];
|
|
622
|
+
}
|
|
623
|
+
var movedItems = [...oldMovedItems];
|
|
624
|
+
var lastMovedItem = movedItems[movedItems.length - 1];
|
|
625
|
+
|
|
626
|
+
// Check if we should combine with the previous move
|
|
627
|
+
// E.g. [1, 2] -> 2, [2, 3] -> 3 can just be [1, 2] -> 3
|
|
628
|
+
if (lastMovedItem != null && isBoundedAxisRange(lastMovedItem.from) && lastMovedItem.from[1] - lastMovedItem.from[0] === from[1] - from[0] && lastMovedItem.to === from[0]) {
|
|
629
|
+
movedItems[movedItems.length - 1] = _objectSpread(_objectSpread({}, lastMovedItem), {}, {
|
|
630
|
+
to
|
|
631
|
+
});
|
|
632
|
+
} else {
|
|
633
|
+
movedItems.push({
|
|
634
|
+
from,
|
|
635
|
+
to
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
var newLastMovedItem = movedItems[movedItems.length - 1];
|
|
639
|
+
// Remove the move if it is now a no-op
|
|
640
|
+
if (isBoundedAxisRange(newLastMovedItem.from) && newLastMovedItem.from[0] === newLastMovedItem.to) {
|
|
641
|
+
movedItems.pop();
|
|
642
|
+
}
|
|
643
|
+
return movedItems;
|
|
644
|
+
}
|
|
645
|
+
static moveItemOrRange(from, to, oldMovedItems) {
|
|
646
|
+
var isPreMoveTo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
647
|
+
return Array.isArray(from) ? GridUtils.moveRange(from, to, oldMovedItems, isPreMoveTo) : GridUtils.moveItem(from, to, oldMovedItems);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Applies the items moves to the AxisRange
|
|
652
|
+
* @param start The start index of the range
|
|
653
|
+
* @param end The end index of the range
|
|
654
|
+
* @param movedItems The move operations to apply
|
|
655
|
+
* @param reverse If the moved items should be applied in reverse (this reverses the effects of the moves)
|
|
656
|
+
* @returns A list of AxisRanges in the translated space. Possibly multiple non-continuous ranges
|
|
657
|
+
*/
|
|
658
|
+
static applyItemMoves(start, end, movedItems) {
|
|
659
|
+
var reverse = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
660
|
+
var result = [[start, end]];
|
|
661
|
+
var _loop = function _loop() {
|
|
662
|
+
var {
|
|
663
|
+
from: fromItemOrRange,
|
|
664
|
+
to: toItem
|
|
665
|
+
} = movedItems[i];
|
|
666
|
+
var length = 1;
|
|
667
|
+
var fromItem;
|
|
668
|
+
if (isBoundedAxisRange(fromItemOrRange)) {
|
|
669
|
+
length = fromItemOrRange[1] - fromItemOrRange[0] + 1; // Ranges are inclusive
|
|
670
|
+
[fromItem] = fromItemOrRange;
|
|
671
|
+
} else {
|
|
672
|
+
fromItem = fromItemOrRange;
|
|
673
|
+
}
|
|
674
|
+
var fromStart = reverse ? toItem : fromItem;
|
|
675
|
+
var fromEnd = fromStart + length - 1;
|
|
676
|
+
var toStart = reverse ? fromItem : toItem;
|
|
677
|
+
var moveDistance = toStart - fromStart;
|
|
678
|
+
var nextResult = [];
|
|
679
|
+
var _loop2 = function _loop2() {
|
|
680
|
+
var _result$j$, _result$j$2;
|
|
681
|
+
var currentStart = (_result$j$ = result[j][0]) !== null && _result$j$ !== void 0 ? _result$j$ : Number.NEGATIVE_INFINITY;
|
|
682
|
+
var currentEnd = (_result$j$2 = result[j][1]) !== null && _result$j$2 !== void 0 ? _result$j$2 : Number.POSITIVE_INFINITY;
|
|
683
|
+
var movedRange;
|
|
684
|
+
var currentResult = [[currentStart, fromStart - 1], [fromStart, fromEnd], [fromEnd + 1, currentEnd]].map(_ref2 => {
|
|
685
|
+
var [s, e] = _ref2;
|
|
686
|
+
return [
|
|
687
|
+
// Cap the ranges to within the current range bounds
|
|
688
|
+
Math.max(s, currentStart), Math.min(e, currentEnd)];
|
|
689
|
+
}).filter(_ref3 => {
|
|
690
|
+
var [s, e] = _ref3;
|
|
691
|
+
return s <= e;
|
|
692
|
+
}) // Remove invalid ranges
|
|
693
|
+
.map(range => {
|
|
694
|
+
var [s, e] = range;
|
|
695
|
+
if (fromStart <= s && fromEnd >= e) {
|
|
696
|
+
// Current range in moved range
|
|
697
|
+
movedRange = [s + moveDistance, e + moveDistance];
|
|
698
|
+
return movedRange;
|
|
699
|
+
}
|
|
700
|
+
if (fromEnd < s) {
|
|
701
|
+
// Current range is after moved range
|
|
702
|
+
return [s - length, e - length];
|
|
703
|
+
}
|
|
704
|
+
return range;
|
|
705
|
+
}).map(range => {
|
|
706
|
+
var [s, e] = range;
|
|
707
|
+
if (toStart > s && toStart <= e) {
|
|
708
|
+
// Moved range splits this range
|
|
709
|
+
return [[s, toStart - 1], [toStart + length, e + length]];
|
|
710
|
+
}
|
|
711
|
+
if (range === movedRange) {
|
|
712
|
+
// Moved range has already been shifted
|
|
713
|
+
return [range];
|
|
714
|
+
}
|
|
715
|
+
if (toStart <= s) {
|
|
716
|
+
// Moved range shifts this range right
|
|
717
|
+
return [[s + length, e + length]];
|
|
718
|
+
}
|
|
719
|
+
return [range];
|
|
720
|
+
}).flat();
|
|
721
|
+
nextResult.push(...currentResult);
|
|
722
|
+
};
|
|
723
|
+
for (var j = 0; j < result.length; j += 1) {
|
|
724
|
+
_loop2();
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// Return infinity values back to null
|
|
728
|
+
result = nextResult.map(_ref => {
|
|
729
|
+
var [s, e] = _ref;
|
|
730
|
+
return [Number.isFinite(s) ? s : null, Number.isFinite(e) ? e : null];
|
|
731
|
+
});
|
|
732
|
+
};
|
|
733
|
+
for (var i = reverse ? movedItems.length - 1 : 0; reverse ? i >= 0 : i < movedItems.length; reverse ? i -= 1 : i += 1) {
|
|
734
|
+
_loop();
|
|
735
|
+
}
|
|
736
|
+
return result;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Applies the items moves to the givengrid range
|
|
741
|
+
* @param range The grid range to translate
|
|
742
|
+
* @param movedColumns The moved columns
|
|
743
|
+
* @param movedRows The moved rows
|
|
744
|
+
* @param reverse If the moved items should be reversed (i.e. visible to model range)
|
|
745
|
+
* @returns A list of grid ranges in the translated space. Possibly multiple non-continuous ranges
|
|
746
|
+
*/
|
|
747
|
+
static translateRange(range, movedColumns, movedRows, reverse) {
|
|
748
|
+
var columnRanges = GridUtils.applyItemMoves(range.startColumn, range.endColumn, movedColumns, reverse);
|
|
749
|
+
var rowRanges = GridUtils.applyItemMoves(range.startRow, range.endRow, movedRows, reverse);
|
|
750
|
+
var ranges = [];
|
|
751
|
+
for (var i = 0; i < columnRanges.length; i += 1) {
|
|
752
|
+
var c = columnRanges[i];
|
|
753
|
+
for (var j = 0; j < rowRanges.length; j += 1) {
|
|
754
|
+
var r = rowRanges[j];
|
|
755
|
+
ranges.push(new GridRange(c[0], r[0], c[1], r[1]));
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
return ranges;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Retrieve the model index given the currently moved items
|
|
763
|
+
* @param visibleIndex The visible index of the item to get the model index for
|
|
764
|
+
* @param movedItems The moved items
|
|
765
|
+
* @returns The model index of the item
|
|
766
|
+
*/
|
|
767
|
+
static getModelIndex(visibleIndex, movedItems) {
|
|
768
|
+
var modelIndex = GridUtils.applyItemMoves(visibleIndex, visibleIndex, movedItems, true)[0][0];
|
|
769
|
+
return modelIndex;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Retrieve the model indexes given the currently moved items
|
|
774
|
+
* @param visibleIndexes The visible indexes of the item to get the model indexes for
|
|
775
|
+
* @param movedItems The moved items
|
|
776
|
+
* @returns The model indexes of the item
|
|
777
|
+
*/
|
|
778
|
+
static getModelIndexes(visibleIndexes, movedItems) {
|
|
779
|
+
return visibleIndexes.map(i => GridUtils.getModelIndex(i, movedItems));
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Translate the provided UI start/end indexes to the model start/end indexes by applying the `movedItems` transformations.
|
|
784
|
+
* Since moved items can split apart a range, multiple pairs of indexes are returned
|
|
785
|
+
*
|
|
786
|
+
* @param start Start item in one dimension
|
|
787
|
+
* @param end End item in one dimension
|
|
788
|
+
* @param movedItems Moved item pairs in this dimension
|
|
789
|
+
* @returns Array of start/end pairs of the indexes after transformations applied.
|
|
790
|
+
*/
|
|
791
|
+
static getModelRangeIndexes(start, end, movedItems) {
|
|
792
|
+
return GridUtils.applyItemMoves(start, end, movedItems, true);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Translate the provided UI range into model range, using the `movedColumns` and `movedRows` to apply the necessary transforms.
|
|
797
|
+
* `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items
|
|
798
|
+
*
|
|
799
|
+
* @param uiRange The currently selected UI ranges
|
|
800
|
+
* @param movedColumns The moved column pairs
|
|
801
|
+
* @param movedRows The moved row pairs
|
|
802
|
+
* @returns The model ranges after translation.
|
|
803
|
+
*/
|
|
804
|
+
static getModelRange(uiRange) {
|
|
805
|
+
var movedColumns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : EMPTY_ARRAY;
|
|
806
|
+
var movedRows = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : EMPTY_ARRAY;
|
|
807
|
+
return GridUtils.translateRange(uiRange, movedColumns, movedRows, true);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Translate the provided UI range into model ranges, using the `movedColumns` and `movedRows` to apply the necessary transforms.
|
|
812
|
+
* `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items
|
|
813
|
+
*
|
|
814
|
+
* @param uiRanges The currently selected UI ranges
|
|
815
|
+
* @param movedColumns The moved column pairs
|
|
816
|
+
* @param movedRows The moved row pairs
|
|
817
|
+
* @returns The model ranges after translation.
|
|
818
|
+
*/
|
|
819
|
+
static getModelRanges(uiRanges) {
|
|
820
|
+
var movedColumns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : EMPTY_ARRAY;
|
|
821
|
+
var movedRows = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : EMPTY_ARRAY;
|
|
822
|
+
var modelRanges = [];
|
|
823
|
+
for (var i = 0; i < uiRanges.length; i += 1) {
|
|
824
|
+
modelRanges.push(...GridUtils.getModelRange(uiRanges[i], movedColumns, movedRows));
|
|
825
|
+
}
|
|
826
|
+
return modelRanges;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Translate the provided UI start/end indexes to the visible start/end indexes by applying the `movedItems` transformations.
|
|
831
|
+
* Since moved items can split apart a range, multiple pairs of indexes are returned
|
|
832
|
+
*
|
|
833
|
+
* @param start Start item in one dimension
|
|
834
|
+
* @param end End item in one dimension
|
|
835
|
+
* @param movedItems Moved item pairs in this dimension
|
|
836
|
+
* @returns Array of start/end pairs of the indexes after transformations applied.
|
|
837
|
+
*/
|
|
838
|
+
static getVisibleRangeIndexes(start, end, movedItems) {
|
|
839
|
+
return GridUtils.applyItemMoves(start, end, movedItems, false);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Translate the provided UI range into visible range, using the `movedColumns` and `movedRows` to apply the necessary transforms.
|
|
844
|
+
* `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items
|
|
845
|
+
*
|
|
846
|
+
* @param uiRange The currently selected UI ranges
|
|
847
|
+
* @param movedColumns The moved column pairs
|
|
848
|
+
* @param movedRows The moved row pairs
|
|
849
|
+
* @returns The model ranges after translation.
|
|
850
|
+
*/
|
|
851
|
+
static getVisibleRange(modelRange) {
|
|
852
|
+
var movedColumns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : EMPTY_ARRAY;
|
|
853
|
+
var movedRows = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : EMPTY_ARRAY;
|
|
854
|
+
return this.translateRange(modelRange, movedColumns, movedRows, false);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Translate the provided model ranges into visible ranges, using the `movedColumns` and `movedRows` to apply the necessary transforms.
|
|
859
|
+
* `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items
|
|
860
|
+
*
|
|
861
|
+
* @param modelRanges The model ranges
|
|
862
|
+
* @param movedColumns The moved column pairs
|
|
863
|
+
* @param movedRows The moved row pairs
|
|
864
|
+
* @returns The model ranges after translation.
|
|
865
|
+
*/
|
|
866
|
+
static getVisibleRanges(modelRanges) {
|
|
867
|
+
var movedColumns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : EMPTY_ARRAY;
|
|
868
|
+
var movedRows = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : EMPTY_ARRAY;
|
|
869
|
+
var visibleRanges = [];
|
|
870
|
+
for (var i = 0; i < modelRanges.length; i += 1) {
|
|
871
|
+
visibleRanges.push(...GridUtils.getVisibleRange(modelRanges[i], movedColumns, movedRows));
|
|
872
|
+
}
|
|
873
|
+
return visibleRanges;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* Retrieve the visible index given the currently moved items
|
|
878
|
+
* @param modelIndex The model index to get the visible index for
|
|
879
|
+
* @param movedItems Moved items
|
|
880
|
+
* @returns The visible index of the item
|
|
881
|
+
*/
|
|
882
|
+
static getVisibleIndex(modelIndex, movedItems) {
|
|
883
|
+
var visibleIndex = GridUtils.applyItemMoves(modelIndex, modelIndex, movedItems)[0][0];
|
|
884
|
+
return visibleIndex;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Retrieve the visible indexes given the currently moved items
|
|
889
|
+
* @param modelIndexes The model indexes to get the visible indexes for
|
|
890
|
+
* @param movedItems Moved items
|
|
891
|
+
* @returns The visible indexes of the item
|
|
892
|
+
*/
|
|
893
|
+
static getVisibleIndexes(modelIndexes, movedItems) {
|
|
894
|
+
return modelIndexes.map(i => GridUtils.getVisibleIndex(i, movedItems));
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* Check if the current platform is Mac
|
|
899
|
+
* @returns True if this platform is a Mac, false otherwise
|
|
900
|
+
*/
|
|
901
|
+
static isMacPlatform() {
|
|
902
|
+
var {
|
|
903
|
+
platform
|
|
904
|
+
} = window.navigator;
|
|
905
|
+
return platform.startsWith('Mac');
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Get the modifier key for the current platform
|
|
910
|
+
* @returns The modifier key for the current platform
|
|
911
|
+
*/
|
|
912
|
+
static getModifierKey() {
|
|
913
|
+
if (GridUtils.isMacPlatform()) {
|
|
914
|
+
return 'metaKey';
|
|
915
|
+
}
|
|
916
|
+
return 'ctrlKey';
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* Check if the modifier key is down for the given event
|
|
921
|
+
* @param event The event to check
|
|
922
|
+
* @returns True if the modifier key is down, false otherwise
|
|
923
|
+
*/
|
|
924
|
+
static isModifierKeyDown(event) {
|
|
925
|
+
var modifierKey = GridUtils.getModifierKey();
|
|
926
|
+
return event[modifierKey];
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* Check if the user has hidden the specified column
|
|
931
|
+
* @param modelIndex The model index to check
|
|
932
|
+
* @param userColumnWidths The user set column widths
|
|
933
|
+
* @returns True if the user has hidden the column
|
|
934
|
+
*/
|
|
935
|
+
static checkColumnHidden(modelIndex, userColumnWidths) {
|
|
936
|
+
return userColumnWidths.get(modelIndex) === 0;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Check if all the columns specified are hidden
|
|
941
|
+
* @param columns Columns to check
|
|
942
|
+
* @param userColumnWidths The user set column widths
|
|
943
|
+
* @returns True if the user has hidden all of the columns
|
|
944
|
+
*/
|
|
945
|
+
static checkAllColumnsHidden(columns, userColumnWidths) {
|
|
946
|
+
if (userColumnWidths.size === 0) {
|
|
947
|
+
return false;
|
|
948
|
+
}
|
|
949
|
+
return columns.every(column => userColumnWidths.get(column) === 0);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* Get the bounds the mouse needs to be dragged outside of from an initial selection before scrolling occurs.
|
|
954
|
+
* Taking into account any floating rows that may be covering the viewport.
|
|
955
|
+
* @param metrics Grid metrics
|
|
956
|
+
* @param row The row they started dragging in
|
|
957
|
+
* @param column The column they started the drag from
|
|
958
|
+
* @returns Dimensions of the drag area in relation to the canvas they need to drag outside of to start scrolling
|
|
959
|
+
*/
|
|
960
|
+
static getScrollDragBounds(metrics, row, column) {
|
|
961
|
+
var {
|
|
962
|
+
gridX,
|
|
963
|
+
gridY,
|
|
964
|
+
width,
|
|
965
|
+
height,
|
|
966
|
+
floatingTopRowCount,
|
|
967
|
+
floatingBottomRowCount,
|
|
968
|
+
floatingLeftColumnCount,
|
|
969
|
+
floatingRightColumnCount,
|
|
970
|
+
floatingLeftWidth,
|
|
971
|
+
floatingRightWidth,
|
|
972
|
+
floatingTopHeight,
|
|
973
|
+
floatingBottomHeight,
|
|
974
|
+
columnCount,
|
|
975
|
+
rowCount
|
|
976
|
+
} = metrics;
|
|
977
|
+
var x1 = gridX;
|
|
978
|
+
var y1 = gridY;
|
|
979
|
+
var x2 = width;
|
|
980
|
+
var y2 = height;
|
|
981
|
+
if (column != null) {
|
|
982
|
+
if (column > floatingLeftColumnCount) {
|
|
983
|
+
x1 += floatingLeftWidth;
|
|
984
|
+
}
|
|
985
|
+
if (column < columnCount - floatingRightColumnCount) {
|
|
986
|
+
x2 -= floatingRightWidth;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
if (row != null) {
|
|
990
|
+
if (row > floatingTopRowCount) {
|
|
991
|
+
y1 += floatingTopHeight;
|
|
992
|
+
}
|
|
993
|
+
if (row < rowCount - floatingBottomRowCount) {
|
|
994
|
+
y2 -= floatingBottomHeight;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
return {
|
|
998
|
+
x1,
|
|
999
|
+
y1,
|
|
1000
|
+
x2,
|
|
1001
|
+
y2
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Converts the delta coordinates from the provided wheel event to pixels
|
|
1007
|
+
* Different platforms have different ways of providing the delta so this normalizes it
|
|
1008
|
+
* @param wheelEvent The mouse wheel event to get the scrolling delta for
|
|
1009
|
+
* @param pageWidth The width of the page that is scrolling
|
|
1010
|
+
* @param pageHeight The height of the page that is scrolling
|
|
1011
|
+
* @param lineWidth The width of the line scrolling in line mode
|
|
1012
|
+
* @param lineHeight The height of the line scrolling in line mode
|
|
1013
|
+
* @returns The delta coordinates normalized to pixels
|
|
1014
|
+
*/
|
|
1015
|
+
static getScrollDelta(wheelEvent) {
|
|
1016
|
+
var pageWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1024;
|
|
1017
|
+
var pageHeight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 768;
|
|
1018
|
+
var lineWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 20;
|
|
1019
|
+
var lineHeight = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 20;
|
|
1020
|
+
var {
|
|
1021
|
+
deltaX,
|
|
1022
|
+
deltaY
|
|
1023
|
+
} = wheelEvent;
|
|
1024
|
+
|
|
1025
|
+
// Flip scroll direction if shiftKey is held on windows/linux.
|
|
1026
|
+
// On mac, deltaX/Y values are switched at the event level when shiftKey=true.
|
|
1027
|
+
// Guard on strictly Y only changing, to ignore trackpad diagonal motion,
|
|
1028
|
+
// through that guard may not be necessary, but it is difficult to determine for
|
|
1029
|
+
// all platforms/browser/scroll method combos.
|
|
1030
|
+
if (!GridUtils.isMacPlatform() && wheelEvent.shiftKey && wheelEvent.deltaX === 0 && wheelEvent.deltaY !== 0) {
|
|
1031
|
+
deltaX = wheelEvent.deltaY;
|
|
1032
|
+
deltaY = wheelEvent.deltaX;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
// Normalize other deltaMode values to pixel units
|
|
1036
|
+
// deltaMode 0, is already in pixel units
|
|
1037
|
+
if ((wheelEvent === null || wheelEvent === void 0 ? void 0 : wheelEvent.deltaMode) === WheelEvent.DOM_DELTA_PAGE) {
|
|
1038
|
+
// Users can set OS to be in deltaMode page
|
|
1039
|
+
// scrolly by page units as pixels
|
|
1040
|
+
deltaX *= pageWidth;
|
|
1041
|
+
deltaY *= pageHeight;
|
|
1042
|
+
} else if ((wheelEvent === null || wheelEvent === void 0 ? void 0 : wheelEvent.deltaMode) === WheelEvent.DOM_DELTA_LINE) {
|
|
1043
|
+
// Firefox reports deltaMode line
|
|
1044
|
+
// Normalize distance travelled between browsers
|
|
1045
|
+
// but remain ~platform/browser combo consistent
|
|
1046
|
+
if (GridUtils.isMacPlatform()) {
|
|
1047
|
+
// for mac treat lines as a standard row height
|
|
1048
|
+
// on mac, firefox travels less distance then chrome per tick
|
|
1049
|
+
deltaX = Math.round(deltaX * lineWidth);
|
|
1050
|
+
deltaY = Math.round(deltaY * lineHeight);
|
|
1051
|
+
} else {
|
|
1052
|
+
// for windows convert to pixels using the same method as chrome
|
|
1053
|
+
// chrome goes 100 per 3 lines, and firefox would go 102 per 3 (17 lineheight * 3 lines * 2)
|
|
1054
|
+
// make the behaviour the same between as it's close enough
|
|
1055
|
+
deltaX = Math.round(deltaX * this.PIXELS_PER_LINE);
|
|
1056
|
+
deltaY = Math.round(deltaY * this.PIXELS_PER_LINE);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
return {
|
|
1060
|
+
deltaX,
|
|
1061
|
+
deltaY
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
static compareRanges(range1, range2) {
|
|
1065
|
+
if (range1[0] == null || range1[1] == null || range2[0] == null || range2[1] == null) {
|
|
1066
|
+
return 0;
|
|
1067
|
+
}
|
|
1068
|
+
return range1[0] !== range2[0] ? range1[0] - range2[0] : range1[1] - range2[1];
|
|
1069
|
+
}
|
|
1070
|
+
static mergeSortedRanges(ranges) {
|
|
1071
|
+
var mergedRanges = [];
|
|
1072
|
+
for (var i = 0; i < ranges.length; i += 1) {
|
|
1073
|
+
var range = ranges[i];
|
|
1074
|
+
var start = range[0];
|
|
1075
|
+
var end = range[1];
|
|
1076
|
+
if (i === 0) {
|
|
1077
|
+
mergedRanges.push([start, end]);
|
|
1078
|
+
} else if (start - 1 <= mergedRanges[mergedRanges.length - 1][1]) {
|
|
1079
|
+
mergedRanges[mergedRanges.length - 1][1] = Math.max(mergedRanges[mergedRanges.length - 1][1], end);
|
|
1080
|
+
} else {
|
|
1081
|
+
mergedRanges.push([start, end]);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
return mergedRanges;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
/**
|
|
1088
|
+
* Translates coordinates that are relative to gridX/gridY to be translated by gridX and gridY
|
|
1089
|
+
* @param tokenBox The token box to translate
|
|
1090
|
+
* @param metrics The grid metrics
|
|
1091
|
+
* @returns The token box with translated coordinates
|
|
1092
|
+
*/
|
|
1093
|
+
static translateTokenBox(tokenBox, metrics) {
|
|
1094
|
+
var {
|
|
1095
|
+
x1: left,
|
|
1096
|
+
y1: top,
|
|
1097
|
+
x2: right,
|
|
1098
|
+
y2: bottom
|
|
1099
|
+
} = tokenBox;
|
|
1100
|
+
var {
|
|
1101
|
+
gridX,
|
|
1102
|
+
gridY,
|
|
1103
|
+
width: gridWidth,
|
|
1104
|
+
height: gridHeight,
|
|
1105
|
+
verticalBarWidth,
|
|
1106
|
+
horizontalBarHeight
|
|
1107
|
+
} = metrics;
|
|
1108
|
+
|
|
1109
|
+
// Clamp the values within the grid
|
|
1110
|
+
var newLeft = clamp(gridX + left, gridX, gridWidth - verticalBarWidth);
|
|
1111
|
+
var newRight = clamp(gridX + right, gridX, gridWidth - verticalBarWidth);
|
|
1112
|
+
var newTop = clamp(gridY + top, gridY, gridHeight - horizontalBarHeight);
|
|
1113
|
+
var newBottom = clamp(gridY + bottom, gridY, gridHeight - horizontalBarHeight);
|
|
1114
|
+
return {
|
|
1115
|
+
x1: newLeft,
|
|
1116
|
+
y1: newTop,
|
|
1117
|
+
x2: newRight,
|
|
1118
|
+
y2: newBottom,
|
|
1119
|
+
token: tokenBox.token
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* Gets textWidth and X-Y position for a specific cell
|
|
1125
|
+
* The textWidth returned is the width that the text can occupy accounting for any other cell markings
|
|
1126
|
+
* The width accounts for tree table indents and cell padding, so it is the width the text may consume
|
|
1127
|
+
*
|
|
1128
|
+
* @param state GridRenderState to get the text metrics for
|
|
1129
|
+
* @param column Column of cell to get text metrics for
|
|
1130
|
+
* @param row Row of cell to get text metrics for
|
|
1131
|
+
* @returns Object with width, x, and y of the text
|
|
1132
|
+
*/
|
|
1133
|
+
static getTextRenderMetrics(state, column, row) {
|
|
1134
|
+
var {
|
|
1135
|
+
metrics,
|
|
1136
|
+
model,
|
|
1137
|
+
theme
|
|
1138
|
+
} = state;
|
|
1139
|
+
var {
|
|
1140
|
+
firstColumn,
|
|
1141
|
+
allColumnXs,
|
|
1142
|
+
allColumnWidths,
|
|
1143
|
+
allRowYs,
|
|
1144
|
+
allRowHeights,
|
|
1145
|
+
modelRows,
|
|
1146
|
+
modelColumns
|
|
1147
|
+
} = metrics;
|
|
1148
|
+
var {
|
|
1149
|
+
cellHorizontalPadding,
|
|
1150
|
+
treeDepthIndent,
|
|
1151
|
+
treeHorizontalPadding
|
|
1152
|
+
} = theme;
|
|
1153
|
+
var modelRow = getOrThrow(modelRows, row);
|
|
1154
|
+
var modelColumn = getOrThrow(modelColumns, column);
|
|
1155
|
+
var textAlign = model.textAlignForCell(modelColumn, modelRow);
|
|
1156
|
+
var x = getOrThrow(allColumnXs, column);
|
|
1157
|
+
var y = getOrThrow(allRowYs, row);
|
|
1158
|
+
var columnWidth = getOrThrow(allColumnWidths, column);
|
|
1159
|
+
var rowHeight = getOrThrow(allRowHeights, row);
|
|
1160
|
+
var isFirstColumn = column === firstColumn;
|
|
1161
|
+
var treeIndent = 0;
|
|
1162
|
+
if (isExpandableGridModel(model) && model.hasExpandableRows && isFirstColumn) {
|
|
1163
|
+
treeIndent = treeDepthIndent * (model.depthForRow(row) + 1) + treeHorizontalPadding;
|
|
1164
|
+
}
|
|
1165
|
+
var textWidth = columnWidth - treeIndent;
|
|
1166
|
+
var textX = x + cellHorizontalPadding;
|
|
1167
|
+
var textY = y + rowHeight * 0.5;
|
|
1168
|
+
if (textAlign === 'right') {
|
|
1169
|
+
textX = x + textWidth - cellHorizontalPadding;
|
|
1170
|
+
} else if (textAlign === 'center') {
|
|
1171
|
+
textX = x + textWidth * 0.5;
|
|
1172
|
+
}
|
|
1173
|
+
textX += treeIndent;
|
|
1174
|
+
return {
|
|
1175
|
+
width: textWidth - cellHorizontalPadding * 2,
|
|
1176
|
+
x: textX,
|
|
1177
|
+
y: textY
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
/**
|
|
1182
|
+
* Finds tokens in text (urls, emails) that start with https:// or http://
|
|
1183
|
+
* @param text The text to search in
|
|
1184
|
+
* @returns An array of tokens
|
|
1185
|
+
*/
|
|
1186
|
+
static findTokensWithProtocolInText(text) {
|
|
1187
|
+
var tokens = linkifyFind(text);
|
|
1188
|
+
return tokens.filter(token => {
|
|
1189
|
+
if (token.type === 'url') {
|
|
1190
|
+
return /^https?:\/\//.test(token.value);
|
|
1191
|
+
}
|
|
1192
|
+
return true;
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
_defineProperty(GridUtils, "PIXELS_PER_LINE", 100 / 3);
|
|
1197
|
+
export default GridUtils;
|
|
1198
|
+
//# sourceMappingURL=GridUtils.js.map
|