@kermodes/grid 0.0.0-stage → 0.3.13-dev.68.g32b767a
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/ColumnHeaderGroup.d.ts +8 -0
- package/dist/ContextMenu.d.ts +15 -0
- package/dist/EventHandlerResult.d.ts +16 -0
- package/dist/FilterBar.d.ts +32 -0
- package/dist/Grid.d.ts +458 -0
- package/dist/GridAxisRange.d.ts +9 -0
- package/dist/GridMetricCalculator.d.ts +509 -0
- package/dist/GridMetrics.d.ts +125 -0
- package/dist/GridModel.d.ts +96 -0
- package/dist/GridMouseHandler.d.ts +29 -0
- package/dist/GridRange.d.ts +268 -0
- package/dist/GridRenderer.d.ts +159 -0
- package/dist/GridRendererTypes.d.ts +25 -0
- package/dist/GridSelectionUtils.d.ts +97 -0
- package/dist/GridStyles.d.ts +2 -0
- package/dist/GridTheme.d.ts +96 -0
- package/dist/GridUtils.d.ts +457 -0
- package/dist/KeyHandler.d.ts +33 -0
- package/dist/RangedSelection.d.ts +118 -0
- package/dist/Selection.d.ts +218 -0
- package/dist/TableViewer.d.ts +16 -0
- package/dist/TableViewerGrid.d.ts +16 -0
- package/dist/TextCellRenderer.d.ts +8 -0
- package/dist/ThemeContext.d.ts +5 -0
- package/dist/ValuePopover.d.ts +23 -0
- package/dist/ViewportGridModel.d.ts +92 -0
- package/dist/cellValue.d.ts +11 -0
- package/dist/copy.d.ts +29 -0
- package/dist/cover.d.ts +16 -0
- package/dist/errors/AssertionError.d.ts +4 -0
- package/dist/errors/assertIsDefined.d.ts +2 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/fastMemoize.d.ts +50 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +7909 -0
- package/dist/key-handlers/SelectionKeyHandler.d.ts +11 -0
- package/dist/key-handlers/index.d.ts +1 -0
- package/dist/menuItems.d.ts +53 -0
- package/dist/mouse-handlers/GridColumnMoveMouseHandler.d.ts +50 -0
- package/dist/mouse-handlers/GridColumnSeparatorMouseHandler.d.ts +27 -0
- package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.d.ts +24 -0
- package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.d.ts +14 -0
- package/dist/mouse-handlers/GridSelectionMouseHandler.d.ts +19 -0
- package/dist/mouse-handlers/GridSeparatorMouseHandler.d.ts +61 -0
- package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.d.ts +24 -0
- package/dist/mouse-handlers/index.d.ts +8 -0
- package/dist/sorting.d.ts +19 -0
- package/dist/utils.d.ts +15 -0
- package/package.json +28 -3
- package/README.md +0 -3
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import type GridModel from './GridModel';
|
|
2
|
+
import type { GridMetrics, Coordinate, CoordinateMap, VisibleIndex, VisibleToModelMap, ModelIndex, ModelSizeMap, MoveOperation, SizeMap } from './GridMetrics';
|
|
3
|
+
import { type GridFont, type GridTheme } from './GridTheme';
|
|
4
|
+
import { type DraggingColumn } from './mouse-handlers/GridColumnMoveMouseHandler';
|
|
5
|
+
export interface GridMetricState {
|
|
6
|
+
left: VisibleIndex;
|
|
7
|
+
top: VisibleIndex;
|
|
8
|
+
leftOffset: Coordinate;
|
|
9
|
+
topOffset: Coordinate;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
scaleX?: number;
|
|
13
|
+
scaleY?: number;
|
|
14
|
+
context: CanvasRenderingContext2D;
|
|
15
|
+
theme: GridTheme;
|
|
16
|
+
model: GridModel;
|
|
17
|
+
movedColumns: readonly MoveOperation[];
|
|
18
|
+
movedRows: readonly MoveOperation[];
|
|
19
|
+
isDraggingHorizontalScrollBar: boolean;
|
|
20
|
+
isDraggingVerticalScrollBar: boolean;
|
|
21
|
+
draggingColumn: DraggingColumn | null;
|
|
22
|
+
filterBarHeight: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Trim the provided map in place. Trims oldest inserted items down to the target size if the cache size is exceeded.
|
|
26
|
+
* Instead of trimming one item on every tick, we trim half the items so there isn't a cache clear on every new item.
|
|
27
|
+
* @param map The map to trim
|
|
28
|
+
* @param cacheSize The maximum number of elements to cache
|
|
29
|
+
* @param targetSize The number of elements to reduce the cache down to if `cacheSize` is exceeded
|
|
30
|
+
*/
|
|
31
|
+
export declare function trimMap(map: Map<unknown, unknown>, cacheSize?: number, targetSize?: number): void;
|
|
32
|
+
/**
|
|
33
|
+
* Get the coordinates of floating items in one dimension.
|
|
34
|
+
* Can be used for getting the y coordinates of floating rows, or x coordinates of floating columns, calculated using the `sizeMap` passed in.
|
|
35
|
+
* @param startCount The number of floating items at the start (ie. `floatingTopRowCount` for rows, `floatingLeftColumnCount` for columns)
|
|
36
|
+
* @param endCount The number of floating items at the end (ie. `floatingBottomRowCount` for rows, `floatingRightColumnCount` for columns)
|
|
37
|
+
* @param totalCount Total number of items in this dimension (ie. `rowCount` for rows, `columnCount` for columns)
|
|
38
|
+
* @param max The max coordinate value (ie. `maxY` for rows, `maxX` for columns)
|
|
39
|
+
* @param sizeMap Map from index to size of item (ie. `rowHeightMap` for rows, `columnWidthMap` for columns)
|
|
40
|
+
*/
|
|
41
|
+
export declare function getFloatingCoordinates(startCount: number, endCount: number, totalCount: number, max: number, sizeMap: SizeMap): CoordinateMap;
|
|
42
|
+
/**
|
|
43
|
+
* Class to calculate all the metrics for drawing a grid.
|
|
44
|
+
* Call getMetrics() with the state to get the full metrics.
|
|
45
|
+
* Override this class and override the individual methods to provide additional functionality.
|
|
46
|
+
*/
|
|
47
|
+
export declare class GridMetricCalculator {
|
|
48
|
+
/** The size of the caches this calculator stores */
|
|
49
|
+
static CACHE_SIZE: number;
|
|
50
|
+
/** The maximum column width as a percentage of the full grid */
|
|
51
|
+
static MAX_COLUMN_WIDTH: number;
|
|
52
|
+
/** The initial row heights if any overrides from the default calculated values */
|
|
53
|
+
initialRowHeights: ReadonlyMap<ModelIndex, number>;
|
|
54
|
+
/** The initial column widths if any overrides from the default calculated values */
|
|
55
|
+
initialColumnWidths: ReadonlyMap<ModelIndex, number>;
|
|
56
|
+
/** User set column widths */
|
|
57
|
+
protected userColumnWidths: ModelSizeMap;
|
|
58
|
+
/** User set row heights */
|
|
59
|
+
protected userRowHeights: ModelSizeMap;
|
|
60
|
+
/** Calculated column widths based on cell contents and caching largest value */
|
|
61
|
+
protected calculatedColumnWidths: ModelSizeMap;
|
|
62
|
+
/** Calculated row heights based on cell contents and caching largest value */
|
|
63
|
+
protected calculatedRowHeights: ModelSizeMap;
|
|
64
|
+
/** Calculated column widths based on cell contents */
|
|
65
|
+
protected contentColumnWidths: ModelSizeMap;
|
|
66
|
+
/** Calculated row heights based on cell contents */
|
|
67
|
+
protected contentRowHeights: ModelSizeMap;
|
|
68
|
+
/** Cache of fonts to estimated width of the smallest char */
|
|
69
|
+
protected fontWidthsLower: Map<string, number>;
|
|
70
|
+
/** Cache of fonts to estimated width of the largest char */
|
|
71
|
+
protected fontWidthsUpper: Map<string, number>;
|
|
72
|
+
/** Cache of fonts to width of all chars */
|
|
73
|
+
protected allCharWidths: Map<string, Map<string, number>>;
|
|
74
|
+
/** Map from visible index to model index for rows (e.g. reversing movedRows operations) */
|
|
75
|
+
protected modelRows: VisibleToModelMap;
|
|
76
|
+
/** Map from visible index to model index for columns (e.g. reversing movedColumns operations) */
|
|
77
|
+
protected modelColumns: VisibleToModelMap;
|
|
78
|
+
/** List of moved row operations. Need to track the previous value so we know if modelRows needs to be cleared. */
|
|
79
|
+
protected movedRows: readonly MoveOperation[];
|
|
80
|
+
/** List of moved column operations. Need to track the previous value so we know if modelColumns needs to be cleared. */
|
|
81
|
+
protected movedColumns: readonly MoveOperation[];
|
|
82
|
+
constructor({ userColumnWidths, userRowHeights, calculatedColumnWidths, calculatedRowHeights, contentColumnWidths, contentRowHeights, fontWidthsLower, fontWidthsUpper, allCharWidths, modelRows, modelColumns, movedRows, movedColumns, initialRowHeights, initialColumnWidths, }?: {
|
|
83
|
+
allCharWidths?: Map<any, any> | undefined;
|
|
84
|
+
calculatedColumnWidths?: Map<any, any> | undefined;
|
|
85
|
+
calculatedRowHeights?: Map<any, any> | undefined;
|
|
86
|
+
contentColumnWidths?: Map<any, any> | undefined;
|
|
87
|
+
contentRowHeights?: Map<any, any> | undefined;
|
|
88
|
+
fontWidthsLower?: Map<any, any> | undefined;
|
|
89
|
+
fontWidthsUpper?: Map<any, any> | undefined;
|
|
90
|
+
initialColumnWidths?: Map<any, any> | undefined;
|
|
91
|
+
initialRowHeights?: Map<any, any> | undefined;
|
|
92
|
+
modelColumns?: Map<any, any> | undefined;
|
|
93
|
+
modelRows?: Map<any, any> | undefined;
|
|
94
|
+
movedColumns?: readonly MoveOperation[] | undefined;
|
|
95
|
+
movedRows?: readonly MoveOperation[] | undefined;
|
|
96
|
+
userColumnWidths?: Map<any, any> | undefined;
|
|
97
|
+
userRowHeights?: Map<any, any> | undefined;
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* Get the metrics for the provided metric state
|
|
101
|
+
* @params state The state to get metrics for
|
|
102
|
+
* @returns The full metrics
|
|
103
|
+
*/
|
|
104
|
+
getMetrics(state: GridMetricState): GridMetrics;
|
|
105
|
+
/**
|
|
106
|
+
* The x offset of the grid
|
|
107
|
+
* @param state The current grid state
|
|
108
|
+
* @returns x value of the left side of the first cell
|
|
109
|
+
*/
|
|
110
|
+
getGridX(state: GridMetricState): Coordinate;
|
|
111
|
+
/**
|
|
112
|
+
* The y offset of the grid
|
|
113
|
+
* @param state The current grid state
|
|
114
|
+
* @returns y value of the top side of the first cell
|
|
115
|
+
*/
|
|
116
|
+
getGridY(state: GridMetricState): Coordinate;
|
|
117
|
+
/**
|
|
118
|
+
* The height of the "visible" area (excludes floating areas)
|
|
119
|
+
* @param state The current grid state
|
|
120
|
+
* @param visibleRowHeights All the visible row heights
|
|
121
|
+
* @returns The visible height in pixels
|
|
122
|
+
*/
|
|
123
|
+
getVisibleHeight(state: GridMetricState, visibleRowHeights?: SizeMap): number;
|
|
124
|
+
/**
|
|
125
|
+
* The width of the "visible" area (excludes floating areas)
|
|
126
|
+
* @param state The current grid state
|
|
127
|
+
* @param visibleColumnWidths All the visible column widths
|
|
128
|
+
* @returns The visible width in pixels
|
|
129
|
+
*/
|
|
130
|
+
getVisibleWidth(state: GridMetricState, visibleColumnWidths?: SizeMap): number;
|
|
131
|
+
/**
|
|
132
|
+
* Retrieve the index of the first non-hidden item
|
|
133
|
+
* @param itemSizes The size of the items in this dimension
|
|
134
|
+
* @param getModelIndex A function to map from the Index to the ModelIndex
|
|
135
|
+
* @param state The current grid state
|
|
136
|
+
* @returns The first item that is not hidden
|
|
137
|
+
*/
|
|
138
|
+
getFirstIndex(itemSizes: ModelSizeMap, getModelIndex: (visibleIndex: VisibleIndex, state: GridMetricState) => ModelIndex, state: GridMetricState): VisibleIndex;
|
|
139
|
+
/**
|
|
140
|
+
* Get the first column index that isn't hidden
|
|
141
|
+
* @param state The current grid state
|
|
142
|
+
* @returns The first column that is not hidden
|
|
143
|
+
*/
|
|
144
|
+
getFirstColumn(state: GridMetricState): VisibleIndex;
|
|
145
|
+
/**
|
|
146
|
+
* Get the first row index that isn't hidden
|
|
147
|
+
* @param state The current grid state
|
|
148
|
+
* @returns The first row that is not hidden
|
|
149
|
+
*/
|
|
150
|
+
getFirstRow(state: GridMetricState): VisibleIndex;
|
|
151
|
+
/**
|
|
152
|
+
* Get the last column that can be the left most column (e.g. scrolled to the right)
|
|
153
|
+
* If no right column is provided, then the last column is used.
|
|
154
|
+
* @param state The current grid state
|
|
155
|
+
* @param right The right-most column to be visible, or null to default to last cell
|
|
156
|
+
* @param visibleWidth The width of the "visible" area (excluding floating items)
|
|
157
|
+
* @returns The index of the last left visible column
|
|
158
|
+
*/
|
|
159
|
+
getLastLeft(state: GridMetricState, right: VisibleIndex | null, visibleWidth: number): VisibleIndex;
|
|
160
|
+
/**
|
|
161
|
+
* The last row that can be the top row (e.g. scrolled to the bottom)
|
|
162
|
+
* If no bottom row is provided, then the last row that is not floating is used
|
|
163
|
+
* @param state The current grid state
|
|
164
|
+
* @param bottom The bottom-most row to be visible, or null to default to last cell
|
|
165
|
+
* @param visibleHeight The height of the "visible" area (excluding floating items)
|
|
166
|
+
* @returns The index of the last top visible row
|
|
167
|
+
*/
|
|
168
|
+
getLastTop(state: GridMetricState, bottom: VisibleIndex | null, visibleHeight: number): VisibleIndex;
|
|
169
|
+
/**
|
|
170
|
+
* Retrieve the top row to scroll to so the passed in `topVisible` is completely visible, taking the floating rows into account.
|
|
171
|
+
* The `top` row is at the top underneath any floating rows, whereas `topVisible` is visible below the floating rows.
|
|
172
|
+
* If there are no floating rows, they should be the same value.
|
|
173
|
+
* @param state The grid metric state
|
|
174
|
+
* @param topVisible The top row to be visible
|
|
175
|
+
* @returns The index of the top row to scroll to (under the floating top rows)
|
|
176
|
+
*/
|
|
177
|
+
getTopForTopVisible(state: GridMetricState, topVisible: VisibleIndex): VisibleIndex;
|
|
178
|
+
/**
|
|
179
|
+
* Retrieve the top row to scroll to so the passed in `bottomVisible` is completely visible
|
|
180
|
+
* at the bottom of the visible viewport, taking the floating rows into account.
|
|
181
|
+
* @param state The grid metric state
|
|
182
|
+
* @param bottomVisible The bottom row to be visible
|
|
183
|
+
* @returns The index of the top row to scroll to (under the floating top rows)
|
|
184
|
+
*/
|
|
185
|
+
getTopForBottomVisible(state: GridMetricState, bottomVisible: VisibleIndex): VisibleIndex;
|
|
186
|
+
/**
|
|
187
|
+
* Retrieve the left column to scroll to so the passed in `leftVisible` is completely visible
|
|
188
|
+
* at the left of the visible viewport, taking the floating columns into account.
|
|
189
|
+
* @param state The grid metric state
|
|
190
|
+
* @param leftVisible The left column to be visible
|
|
191
|
+
* @returns The index of the left column to scroll to (under the floating left columns)
|
|
192
|
+
*/
|
|
193
|
+
getLeftForLeftVisible(state: GridMetricState, leftVisible: VisibleIndex): VisibleIndex;
|
|
194
|
+
/**
|
|
195
|
+
* Retrieve the left column to scroll to so the passed in `rightVisible` is completely visible
|
|
196
|
+
* at the right of the visible viewport, taking the floating columns into account.
|
|
197
|
+
* @param state The grid metric state
|
|
198
|
+
* @param rightVisible The right column to be visible
|
|
199
|
+
* @returns The index of the left column to scroll to (under the floating left columns)
|
|
200
|
+
*/
|
|
201
|
+
getLeftForRightVisible(state: GridMetricState, rightVisible: VisibleIndex): VisibleIndex;
|
|
202
|
+
/**
|
|
203
|
+
* Retrieve a map of the height of each floating row
|
|
204
|
+
* @param state The grid metric state
|
|
205
|
+
* @returns The heights of all the floating rows
|
|
206
|
+
*/
|
|
207
|
+
getFloatingRowHeights(state: GridMetricState): SizeMap;
|
|
208
|
+
/**
|
|
209
|
+
* Retrieve a map of the height of all the visible rows (non-floating)
|
|
210
|
+
* @param state The grid metric state
|
|
211
|
+
* @returns The heights of all the visible rows
|
|
212
|
+
*/
|
|
213
|
+
getVisibleRowHeights(state: GridMetricState): SizeMap;
|
|
214
|
+
/**
|
|
215
|
+
* Retrieve a map of the width of each floating column
|
|
216
|
+
* @param state The grid metric state
|
|
217
|
+
* @returns The widths of all the floating columns
|
|
218
|
+
*/
|
|
219
|
+
getFloatingColumnWidths(state: GridMetricState): SizeMap;
|
|
220
|
+
/**
|
|
221
|
+
* Retrieve a map of the width of all the visible columns (non-floating)
|
|
222
|
+
* @param state The grid metric state
|
|
223
|
+
* @returns The widths of all the visible columns and an array of visible, non-hidden columns
|
|
224
|
+
*/
|
|
225
|
+
getVisibleColumnWidths(state: GridMetricState): [SizeMap, VisibleIndex[]];
|
|
226
|
+
/**
|
|
227
|
+
* Retrieve a map of all the floating columns to their x coordinate
|
|
228
|
+
* @param state The grid metric state
|
|
229
|
+
* @param columnWidthMap Map from visible index to column width
|
|
230
|
+
* @param maxX The maximum X size for the grid
|
|
231
|
+
* @returns Map of the x coordinate of all floating columns
|
|
232
|
+
*/
|
|
233
|
+
getFloatingColumnXs(state: GridMetricState, columnWidthMap: SizeMap, maxX: Coordinate): CoordinateMap;
|
|
234
|
+
/**
|
|
235
|
+
* Retrieve a map of all the visible columns to their x coordinate.
|
|
236
|
+
* Starts at leftOffset with the first index in `visibleColumns`, then
|
|
237
|
+
* calculates all the coordinates from there
|
|
238
|
+
* @param visibleColumnWidths Map of visible column index to widths
|
|
239
|
+
* @param visibleColumns All visible columns
|
|
240
|
+
* @param leftOffset The left scroll offset
|
|
241
|
+
* @returns Map of the x coordinate of all visible columns
|
|
242
|
+
*/
|
|
243
|
+
getVisibleColumnXs(visibleColumnWidths: SizeMap, visibleColumns: VisibleIndex[], leftOffset: number): CoordinateMap;
|
|
244
|
+
/**
|
|
245
|
+
* Retrieve a map of all the floating rows to their y coordinate
|
|
246
|
+
* @param state The grid metric state
|
|
247
|
+
* @param rowHeightMap Map of visible index to row height
|
|
248
|
+
* @param maxY The maximum Y size for the grid
|
|
249
|
+
* @returns Map of the y coordinate of all floating rows
|
|
250
|
+
*/
|
|
251
|
+
getFloatingRowYs(state: GridMetricState, rowHeightMap: SizeMap, maxY: Coordinate): CoordinateMap;
|
|
252
|
+
/**
|
|
253
|
+
* Retrieve a map of all the visible rows to their y coordinate.
|
|
254
|
+
* Starts at topOffset with the first index in `visibleRows`, then
|
|
255
|
+
* calculates all the coordinates from there
|
|
256
|
+
* @param visibleRowHeights Map of visible row index to heights
|
|
257
|
+
* @param visibleRows All visible rows
|
|
258
|
+
* @param topOffset The top scroll offset
|
|
259
|
+
* @returns Map of the y coordinate of all visible rows
|
|
260
|
+
*/
|
|
261
|
+
getVisibleRowYs(visibleRowHeights: SizeMap, visibleRows: VisibleIndex[], topOffset: number): CoordinateMap;
|
|
262
|
+
/**
|
|
263
|
+
* Get the total width of the floating columns on the left
|
|
264
|
+
* @param state The grid metric state
|
|
265
|
+
* @param columnWidths Map of column index to width
|
|
266
|
+
* @returns The total width of the floating left section
|
|
267
|
+
*/
|
|
268
|
+
getFloatingLeftWidth(state: GridMetricState, columnWidths?: SizeMap): number;
|
|
269
|
+
/**
|
|
270
|
+
* Get the total width of the floating columns on the right
|
|
271
|
+
* @param state The grid metric state
|
|
272
|
+
* @param columnWidths Map of column index to width
|
|
273
|
+
* @returns The total width of the floating right section
|
|
274
|
+
*/
|
|
275
|
+
getFloatingRightWidth(state: GridMetricState, columnWidths?: SizeMap): number;
|
|
276
|
+
/**
|
|
277
|
+
* Get the total height of the floating rows on the top
|
|
278
|
+
* @param state The grid metric state
|
|
279
|
+
* @param rowHeights Map of row index to height
|
|
280
|
+
* @returns The total height of the floating top section
|
|
281
|
+
*/
|
|
282
|
+
getFloatingTopHeight(state: GridMetricState, rowHeights?: SizeMap): number;
|
|
283
|
+
/**
|
|
284
|
+
* Get the total height of the floating rows on the bottom
|
|
285
|
+
* @param state The grid metric state
|
|
286
|
+
* @param rowHeights Map of row index to height
|
|
287
|
+
* @returns The total height of the floating bottom section
|
|
288
|
+
*/
|
|
289
|
+
getFloatingBottomHeight(state: GridMetricState, rowHeights?: SizeMap): number;
|
|
290
|
+
/**
|
|
291
|
+
* Retrieve the index of the first fully visible row in the "visible" viewport of the grid.
|
|
292
|
+
* E.g. First row visible after the floating rows, provided the visible rows.
|
|
293
|
+
* @param state The grid metric state
|
|
294
|
+
* @param visibleRowYs Map of row index to y coordinate
|
|
295
|
+
* @param visibleRowHeights Map of row index to height
|
|
296
|
+
* @param visibleRows Array of visible row indexes
|
|
297
|
+
* @returns Index of the top visible row
|
|
298
|
+
*/
|
|
299
|
+
getTopVisible(state: GridMetricState, visibleRowYs: CoordinateMap, visibleRowHeights: SizeMap, visibleRows: VisibleIndex[]): VisibleIndex;
|
|
300
|
+
/**
|
|
301
|
+
* Retrieve the index of the first fully visible column in the "visible" viewport of the grid.
|
|
302
|
+
* E.g. First column visible after the floating columns, provided the visible columns.
|
|
303
|
+
* @param state The grid metric state
|
|
304
|
+
* @param visibleColumnXs Map of column index to x coordinate
|
|
305
|
+
* @param visibleColumnWidths Map of column index to widths
|
|
306
|
+
* @param visibleColumns Array of visible row indexes
|
|
307
|
+
* @returns Index of the left visible column
|
|
308
|
+
*/
|
|
309
|
+
getLeftVisible(state: GridMetricState, visibleColumnXs: CoordinateMap, visibleColumnWidths: SizeMap, visibleColumns: VisibleIndex[]): VisibleIndex;
|
|
310
|
+
/**
|
|
311
|
+
* Retrieve the index of the last fully visible row in the "visible" viewport of the grid.
|
|
312
|
+
* E.g. Last row visible before the bottom floating rows, provided the visible rows.
|
|
313
|
+
* @param state The grid metric state
|
|
314
|
+
* @param visibleRowYs Map of row index to y coordinate
|
|
315
|
+
* @param visibleRowHeights Map of row index to height
|
|
316
|
+
* @param visibleRows Array of visible row indexes
|
|
317
|
+
* @param gridY The starting y coordinate of the grid
|
|
318
|
+
* @returns Index of the bottom visible row
|
|
319
|
+
*/
|
|
320
|
+
getBottomVisible(state: GridMetricState, visibleRowYs: CoordinateMap, visibleRowHeights: SizeMap, visibleRows: VisibleIndex[], gridY: Coordinate): VisibleIndex;
|
|
321
|
+
/**
|
|
322
|
+
* Retrieve the index of the last fully visible column in the "visible" viewport of the grid.
|
|
323
|
+
* E.g. Last column visible before the floating columns, provided the visible columns.
|
|
324
|
+
* @param state The grid metric state
|
|
325
|
+
* @param visibleColumnXs Map of column index to x coordinate
|
|
326
|
+
* @param visibleColumnWidths Map of column index to widths
|
|
327
|
+
* @param visibleColumns Array of visible column indexes
|
|
328
|
+
* @returns Index of the right visible column
|
|
329
|
+
*/
|
|
330
|
+
getRightVisible(state: GridMetricState, visibleColumnXs: CoordinateMap, visibleColumnWidths: SizeMap, visibleColumns: VisibleIndex[], gridX: Coordinate): VisibleIndex;
|
|
331
|
+
/**
|
|
332
|
+
* Retrieve the possible bottom of the visible viewport (not limited by data size)
|
|
333
|
+
* @param state The grid metric state
|
|
334
|
+
* @param visibleRows Array of visible row indexes
|
|
335
|
+
* @param visibleRowYs Map of row index to y coordinate
|
|
336
|
+
* @param visibleRowHeights Map of row index to height
|
|
337
|
+
* @returns The index of the bottom viewport possible
|
|
338
|
+
*/
|
|
339
|
+
getBottomViewport(state: GridMetricState, visibleRows: VisibleIndex[], visibleRowYs: CoordinateMap, visibleRowHeights: SizeMap): VisibleIndex;
|
|
340
|
+
/**
|
|
341
|
+
* Retrieve the possible right of the visible viewport (not limited by data size)
|
|
342
|
+
* @param state The grid metric state
|
|
343
|
+
* @param visibleColumns Array of visible column indexes
|
|
344
|
+
* @param visibleColumnXs Map of column index to x coordinate
|
|
345
|
+
* @param visibleColumnWidths Map of column index to width
|
|
346
|
+
* @returns The index of the right viewport possible
|
|
347
|
+
*/
|
|
348
|
+
getRightViewport(state: GridMetricState, visibleColumns: VisibleIndex[], visibleColumnXs: CoordinateMap, visibleColumnWidths: SizeMap): VisibleIndex;
|
|
349
|
+
/**
|
|
350
|
+
* Get the Index of the of the last index visible
|
|
351
|
+
* @param items Array of visible item indexes
|
|
352
|
+
* @param itemXs Map of index to coordinate
|
|
353
|
+
* @param itemSizes Map of index to size
|
|
354
|
+
* @param maxSize Full size of the grid
|
|
355
|
+
* @param defaultItemSize Default size of an item
|
|
356
|
+
* @returns The Index of the last index visible
|
|
357
|
+
*/
|
|
358
|
+
getLastIndexViewport(items: VisibleIndex[], itemXs: CoordinateMap, itemSizes: SizeMap, maxSize: number, defaultItemSize: number): VisibleIndex;
|
|
359
|
+
/**
|
|
360
|
+
* Get the size from the provided size map of the specified item
|
|
361
|
+
* @param modelIndex The model index to get the size for
|
|
362
|
+
* @param userSizes The user set sizes
|
|
363
|
+
* @param getDefaultSize Method to get the default size for this item
|
|
364
|
+
* @returns The size from the provided size map of the specified item
|
|
365
|
+
*/
|
|
366
|
+
getVisibleItemSize(modelIndex: ModelIndex, userSizes: ModelSizeMap, getDefaultSize: () => number): number;
|
|
367
|
+
/**
|
|
368
|
+
* Get the height of the specified row
|
|
369
|
+
* @param row Index of the row to get the height of
|
|
370
|
+
* @param state The grid metric state
|
|
371
|
+
* @returns The height of the row specified
|
|
372
|
+
*/
|
|
373
|
+
getVisibleRowHeight(row: VisibleIndex, state: GridMetricState): number;
|
|
374
|
+
/**
|
|
375
|
+
* Get the width of the specified column
|
|
376
|
+
* @param column Index of the column to get the width of
|
|
377
|
+
* @param state The grid metric state
|
|
378
|
+
* @returns The width of the column
|
|
379
|
+
*/
|
|
380
|
+
getVisibleColumnWidth(column: VisibleIndex, state: GridMetricState): number;
|
|
381
|
+
/**
|
|
382
|
+
* Get a map of VisibleIndex to ModelIndex
|
|
383
|
+
* @param visibleRows Array of visible row indexes
|
|
384
|
+
* @param state The grid metric state
|
|
385
|
+
* @returns Map of VisibleIndex to ModelIndex
|
|
386
|
+
*/
|
|
387
|
+
getModelRows(visibleRows: VisibleIndex[], state: GridMetricState): VisibleToModelMap;
|
|
388
|
+
/**
|
|
389
|
+
* Get the ModelIndex of the specified row
|
|
390
|
+
* @param visibleRow Index of the row
|
|
391
|
+
* @param state The grid metric state
|
|
392
|
+
* @returns ModelIndex of the row
|
|
393
|
+
*/
|
|
394
|
+
getModelRow(visibleRow: VisibleIndex, state: GridMetricState): ModelIndex;
|
|
395
|
+
/**
|
|
396
|
+
* Get a map of Index to ModelIndex. Applies the move operations to get the transformation.
|
|
397
|
+
* @param visibleColumns Array of visible column indexes
|
|
398
|
+
* @param state The grid metric state
|
|
399
|
+
* @returns Map of Index to ModelIndex
|
|
400
|
+
*/
|
|
401
|
+
getModelColumns(visibleColumns: VisibleIndex[], state: GridMetricState): VisibleToModelMap;
|
|
402
|
+
/**
|
|
403
|
+
* Get the ModelIndex of the specified column
|
|
404
|
+
* @param visibleColumn Index of the column
|
|
405
|
+
* @param state The grid metric state
|
|
406
|
+
* @returns ModelIndex of the column
|
|
407
|
+
*/
|
|
408
|
+
getModelColumn(visibleColumn: VisibleIndex, state: GridMetricState): ModelIndex;
|
|
409
|
+
/**
|
|
410
|
+
* Calculate the height of the row specified.
|
|
411
|
+
* @param row Index of the row to calculate the height for
|
|
412
|
+
* @param modelRow ModelIndex of the row to calculate the height
|
|
413
|
+
* @param state The grid metric state
|
|
414
|
+
* @returns The height of the row
|
|
415
|
+
*/
|
|
416
|
+
calculateRowHeight(row: VisibleIndex, modelRow: ModelIndex, state: GridMetricState): number;
|
|
417
|
+
/**
|
|
418
|
+
* Calculates the column width based on the provided column model index
|
|
419
|
+
* @param modelColumn ModelIndex of the column to calculate the width
|
|
420
|
+
* @param state The grid metric state
|
|
421
|
+
* @returns The width of the column
|
|
422
|
+
*/
|
|
423
|
+
calculateColumnWidth(modelColumn: ModelIndex, state: GridMetricState): number;
|
|
424
|
+
/**
|
|
425
|
+
* Checks if a column is hidden either by a user setting the width to 0 or by initial width being 0
|
|
426
|
+
* @param modelIndex the model index of the column to check
|
|
427
|
+
* @returns true if the column is hidden, false otherwise
|
|
428
|
+
*/
|
|
429
|
+
isColumnHidden(modelIndex: ModelIndex): boolean;
|
|
430
|
+
/**
|
|
431
|
+
* Calculate the width of the specified column's header
|
|
432
|
+
* @param modelColumn ModelIndex of the column to get the header width for
|
|
433
|
+
* @param state The grid metric state
|
|
434
|
+
* @returns The calculated width of the column header
|
|
435
|
+
*/
|
|
436
|
+
calculateColumnHeaderWidth(modelColumn: ModelIndex, state: GridMetricState, maxColumnWidth: number): number;
|
|
437
|
+
/**
|
|
438
|
+
* Calculate the width of the specified column's data
|
|
439
|
+
* @param modelColumn ModelIndex of the column to get the data width for
|
|
440
|
+
* @param state The grid metric state
|
|
441
|
+
* @returns The calculated width of the column data
|
|
442
|
+
*/
|
|
443
|
+
calculateColumnDataWidth(modelColumn: ModelIndex, state: GridMetricState, maxColumnWidth: number): number;
|
|
444
|
+
/**
|
|
445
|
+
* Calculates the width of a string using widths of individual and pairs of characters to take into account font kerning
|
|
446
|
+
* @param context The canvas rendering context
|
|
447
|
+
* @param font The font to get the width for
|
|
448
|
+
* @param text The text to calculate the width for
|
|
449
|
+
* @param maxWidth The maximum width to calculate to
|
|
450
|
+
*/
|
|
451
|
+
calculateTextWidth(context: CanvasRenderingContext2D, font: string, text: string, maxWidth?: number): number;
|
|
452
|
+
/**
|
|
453
|
+
* Calculates the lower bound width of a character of the provided font.
|
|
454
|
+
* @param font The font to get the width for
|
|
455
|
+
* @param context The canvas rendering context
|
|
456
|
+
*/
|
|
457
|
+
calculateLowerFontWidth(font: GridFont, context: CanvasRenderingContext2D): void;
|
|
458
|
+
/**
|
|
459
|
+
* Calculates the upper bound width of a character of the provided font.
|
|
460
|
+
* @param font The font to get the width for
|
|
461
|
+
* @param context The canvas rendering context
|
|
462
|
+
*/
|
|
463
|
+
calculateUpperFontWidth(font: GridFont, context: CanvasRenderingContext2D): void;
|
|
464
|
+
/**
|
|
465
|
+
* Sets the width for the specified column
|
|
466
|
+
* @param column The column model index to set
|
|
467
|
+
* @param size The size to set it to
|
|
468
|
+
*/
|
|
469
|
+
setColumnWidth(column: ModelIndex, size: number): void;
|
|
470
|
+
/**
|
|
471
|
+
* Resets the column width for the specified column to the calculated width
|
|
472
|
+
* @param column The column model index to reset
|
|
473
|
+
*/
|
|
474
|
+
resetColumnWidth(column: ModelIndex): void;
|
|
475
|
+
/**
|
|
476
|
+
* Sets the calculated width for the specified column
|
|
477
|
+
* @param column The column model index to set
|
|
478
|
+
* @param size The size to set it to
|
|
479
|
+
*/
|
|
480
|
+
setCalculatedColumnWidth(column: ModelIndex, size: number): void;
|
|
481
|
+
/**
|
|
482
|
+
* Resets all the calculated column widths
|
|
483
|
+
* Useful if the theme minimum column width changes
|
|
484
|
+
*/
|
|
485
|
+
resetCalculatedColumnWidths(): void;
|
|
486
|
+
/**
|
|
487
|
+
* Sets the width for the specified row
|
|
488
|
+
* @param row The row model index to set
|
|
489
|
+
* @param size The size to set it to
|
|
490
|
+
*/
|
|
491
|
+
setRowHeight(row: ModelIndex, size: number): void;
|
|
492
|
+
/**
|
|
493
|
+
* Resets the row height for the specified row to the calculated height
|
|
494
|
+
* @param row The row model index to reset
|
|
495
|
+
*/
|
|
496
|
+
resetRowHeight(row: ModelIndex): void;
|
|
497
|
+
/**
|
|
498
|
+
* Sets the calculated height for the specified row
|
|
499
|
+
* @param row The column model index to set
|
|
500
|
+
* @param size The size to set it to
|
|
501
|
+
*/
|
|
502
|
+
setCalculatedRowHeight(row: ModelIndex, size: number): void;
|
|
503
|
+
/**
|
|
504
|
+
* Resets all the calculated row heights
|
|
505
|
+
* Useful if the theme row height changes
|
|
506
|
+
*/
|
|
507
|
+
resetCalculatedRowHeights(): void;
|
|
508
|
+
}
|
|
509
|
+
export default GridMetricCalculator;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { BoundedAxisRange } from './GridAxisRange';
|
|
2
|
+
/** A grid coordinate value */
|
|
3
|
+
export type Coordinate = number;
|
|
4
|
+
/** Coordinates of a box */
|
|
5
|
+
export type BoxCoordinates = {
|
|
6
|
+
x1: Coordinate;
|
|
7
|
+
y1: Coordinate;
|
|
8
|
+
x2: Coordinate;
|
|
9
|
+
y2: Coordinate;
|
|
10
|
+
};
|
|
11
|
+
/** The visible index of the item, eg. after moves are applied */
|
|
12
|
+
export type VisibleIndex = number;
|
|
13
|
+
/** The model index of the item, eg. moves are not applied */
|
|
14
|
+
export type ModelIndex = number;
|
|
15
|
+
/** Map from an item index to it's coordinate */
|
|
16
|
+
export type CoordinateMap = Map<VisibleIndex, Coordinate>;
|
|
17
|
+
/** Map from an item index to it's size */
|
|
18
|
+
export type SizeMap = Map<VisibleIndex, number>;
|
|
19
|
+
/** Map from a ModelIndex to it's size */
|
|
20
|
+
export type ModelSizeMap = Map<ModelIndex, number>;
|
|
21
|
+
/** Map from visible Index to ModelIndex */
|
|
22
|
+
export type VisibleToModelMap = Map<VisibleIndex, ModelIndex>;
|
|
23
|
+
/** Represents a move operation from one index to another */
|
|
24
|
+
export type MoveOperation = {
|
|
25
|
+
from: VisibleIndex | BoundedAxisRange;
|
|
26
|
+
to: VisibleIndex;
|
|
27
|
+
};
|
|
28
|
+
export type GridMetrics = {
|
|
29
|
+
rowHeight: number;
|
|
30
|
+
rowHeaderWidth: number;
|
|
31
|
+
rowFooterWidth: number;
|
|
32
|
+
rowCount: number;
|
|
33
|
+
columnWidth: number;
|
|
34
|
+
columnCount: number;
|
|
35
|
+
columnHeaderHeight: number;
|
|
36
|
+
floatingTopRowCount: number;
|
|
37
|
+
floatingBottomRowCount: number;
|
|
38
|
+
floatingLeftColumnCount: number;
|
|
39
|
+
floatingRightColumnCount: number;
|
|
40
|
+
gridX: Coordinate;
|
|
41
|
+
gridY: Coordinate;
|
|
42
|
+
firstRow: VisibleIndex;
|
|
43
|
+
firstColumn: VisibleIndex;
|
|
44
|
+
/**
|
|
45
|
+
* The visible index of the left-most column that is at least partially visible.
|
|
46
|
+
*/
|
|
47
|
+
left: VisibleIndex;
|
|
48
|
+
/**
|
|
49
|
+
* The visible index of the top row that is at least partially visible.
|
|
50
|
+
*/
|
|
51
|
+
top: VisibleIndex;
|
|
52
|
+
/**
|
|
53
|
+
* The visible index of the bottom row that is at least partially visible.
|
|
54
|
+
*/
|
|
55
|
+
bottom: VisibleIndex;
|
|
56
|
+
/**
|
|
57
|
+
* The visible index of the right-most column that is at least partially visible.
|
|
58
|
+
*/
|
|
59
|
+
right: VisibleIndex;
|
|
60
|
+
topOffset: Coordinate;
|
|
61
|
+
leftOffset: Coordinate;
|
|
62
|
+
topVisible: VisibleIndex;
|
|
63
|
+
leftVisible: VisibleIndex;
|
|
64
|
+
bottomVisible: VisibleIndex;
|
|
65
|
+
rightVisible: VisibleIndex;
|
|
66
|
+
bottomViewport: VisibleIndex;
|
|
67
|
+
rightViewport: VisibleIndex;
|
|
68
|
+
width: number;
|
|
69
|
+
height: number;
|
|
70
|
+
scaleX: number;
|
|
71
|
+
scaleY: number;
|
|
72
|
+
maxX: Coordinate;
|
|
73
|
+
maxY: Coordinate;
|
|
74
|
+
lastLeft: VisibleIndex;
|
|
75
|
+
lastTop: VisibleIndex;
|
|
76
|
+
barHeight: number;
|
|
77
|
+
barTop: number;
|
|
78
|
+
barWidth: number;
|
|
79
|
+
barLeft: number;
|
|
80
|
+
handleHeight: number;
|
|
81
|
+
handleWidth: number;
|
|
82
|
+
hasHorizontalBar: boolean;
|
|
83
|
+
hasVerticalBar: boolean;
|
|
84
|
+
verticalBarWidth: number;
|
|
85
|
+
horizontalBarHeight: number;
|
|
86
|
+
scrollX: number;
|
|
87
|
+
scrollY: number;
|
|
88
|
+
scrollableContentWidth: number;
|
|
89
|
+
scrollableContentHeight: number;
|
|
90
|
+
scrollableViewportWidth: number;
|
|
91
|
+
scrollableViewportHeight: number;
|
|
92
|
+
visibleRows: readonly VisibleIndex[];
|
|
93
|
+
visibleColumns: readonly VisibleIndex[];
|
|
94
|
+
columnsForRender: readonly VisibleIndex[];
|
|
95
|
+
visibleRowHeights: SizeMap;
|
|
96
|
+
visibleColumnWidths: SizeMap;
|
|
97
|
+
floatingRows: readonly VisibleIndex[];
|
|
98
|
+
floatingColumns: readonly VisibleIndex[];
|
|
99
|
+
allRows: readonly VisibleIndex[];
|
|
100
|
+
allColumns: readonly VisibleIndex[];
|
|
101
|
+
allRowHeights: SizeMap;
|
|
102
|
+
allColumnWidths: SizeMap;
|
|
103
|
+
floatingTopHeight: number;
|
|
104
|
+
floatingBottomHeight: number;
|
|
105
|
+
floatingLeftWidth: number;
|
|
106
|
+
floatingRightWidth: number;
|
|
107
|
+
visibleRowYs: CoordinateMap;
|
|
108
|
+
visibleColumnXs: CoordinateMap;
|
|
109
|
+
allRowYs: CoordinateMap;
|
|
110
|
+
allColumnXs: CoordinateMap;
|
|
111
|
+
modelRows: VisibleToModelMap;
|
|
112
|
+
modelColumns: VisibleToModelMap;
|
|
113
|
+
movedRows: readonly MoveOperation[];
|
|
114
|
+
movedColumns: readonly MoveOperation[];
|
|
115
|
+
fontWidthsLower: Map<string, number>;
|
|
116
|
+
fontWidthsUpper: Map<string, number>;
|
|
117
|
+
userColumnWidths: ModelSizeMap;
|
|
118
|
+
userRowHeights: ModelSizeMap;
|
|
119
|
+
calculatedRowHeights: ModelSizeMap;
|
|
120
|
+
calculatedColumnWidths: ModelSizeMap;
|
|
121
|
+
contentColumnWidths: ModelSizeMap;
|
|
122
|
+
contentRowHeights: ModelSizeMap;
|
|
123
|
+
columnHeaderMaxDepth: number;
|
|
124
|
+
};
|
|
125
|
+
export default GridMetrics;
|