@kermodes/grid 0.0.0-stage → 0.3.13-dev.71.ge96feae

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/ColumnHeaderGroup.d.ts +8 -0
  2. package/dist/ContextMenu.d.ts +15 -0
  3. package/dist/EventHandlerResult.d.ts +16 -0
  4. package/dist/FilterBar.d.ts +32 -0
  5. package/dist/Grid.d.ts +458 -0
  6. package/dist/GridAxisRange.d.ts +9 -0
  7. package/dist/GridMetricCalculator.d.ts +509 -0
  8. package/dist/GridMetrics.d.ts +125 -0
  9. package/dist/GridModel.d.ts +96 -0
  10. package/dist/GridMouseHandler.d.ts +29 -0
  11. package/dist/GridRange.d.ts +268 -0
  12. package/dist/GridRenderer.d.ts +159 -0
  13. package/dist/GridRendererTypes.d.ts +25 -0
  14. package/dist/GridSelectionUtils.d.ts +97 -0
  15. package/dist/GridStyles.d.ts +2 -0
  16. package/dist/GridTheme.d.ts +96 -0
  17. package/dist/GridUtils.d.ts +457 -0
  18. package/dist/KeyHandler.d.ts +33 -0
  19. package/dist/RangedSelection.d.ts +118 -0
  20. package/dist/Selection.d.ts +218 -0
  21. package/dist/TableViewer.d.ts +16 -0
  22. package/dist/TableViewerGrid.d.ts +16 -0
  23. package/dist/TextCellRenderer.d.ts +8 -0
  24. package/dist/ThemeContext.d.ts +5 -0
  25. package/dist/ValuePopover.d.ts +23 -0
  26. package/dist/ViewportGridModel.d.ts +92 -0
  27. package/dist/cellValue.d.ts +11 -0
  28. package/dist/copy.d.ts +29 -0
  29. package/dist/cover.d.ts +16 -0
  30. package/dist/errors/AssertionError.d.ts +4 -0
  31. package/dist/errors/assertIsDefined.d.ts +2 -0
  32. package/dist/errors/index.d.ts +2 -0
  33. package/dist/fastMemoize.d.ts +50 -0
  34. package/dist/index.d.ts +32 -0
  35. package/dist/index.js +7909 -0
  36. package/dist/key-handlers/SelectionKeyHandler.d.ts +11 -0
  37. package/dist/key-handlers/index.d.ts +1 -0
  38. package/dist/menuItems.d.ts +53 -0
  39. package/dist/mouse-handlers/GridColumnMoveMouseHandler.d.ts +50 -0
  40. package/dist/mouse-handlers/GridColumnSeparatorMouseHandler.d.ts +27 -0
  41. package/dist/mouse-handlers/GridHorizontalScrollBarMouseHandler.d.ts +24 -0
  42. package/dist/mouse-handlers/GridScrollBarCornerMouseHandler.d.ts +14 -0
  43. package/dist/mouse-handlers/GridSelectionMouseHandler.d.ts +19 -0
  44. package/dist/mouse-handlers/GridSeparatorMouseHandler.d.ts +61 -0
  45. package/dist/mouse-handlers/GridVerticalScrollBarMouseHandler.d.ts +24 -0
  46. package/dist/mouse-handlers/index.d.ts +8 -0
  47. package/dist/sorting.d.ts +19 -0
  48. package/dist/utils.d.ts +15 -0
  49. package/package.json +28 -3
  50. package/README.md +0 -3
@@ -0,0 +1,2 @@
1
+ export declare function injectGridStyles(doc?: Document): void;
2
+ export default injectGridStyles;
@@ -0,0 +1,96 @@
1
+ /** A color parsed as CSS color value, eg. '#FF0000' */
2
+ export type GridColor = string;
3
+ /** A nullable color, eg. pass `null` to skip drawing this item */
4
+ export type NullableGridColor = GridColor | null;
5
+ /** One or more colors parsed as CSS color value separated by space, eg. '#FF0000 #00FF00' */
6
+ export type GridColorWay = string;
7
+ /** A font parsed as CSS font value */
8
+ export type GridFont = string;
9
+ export type GridTheme = {
10
+ allowColumnResize: boolean;
11
+ allowRowResize: boolean;
12
+ autoSelectRow: boolean;
13
+ autoSelectColumn: boolean;
14
+ autoSizeColumns: boolean;
15
+ autoSizeRows: boolean;
16
+ backgroundColor: GridColor;
17
+ textColor: GridColor;
18
+ positiveNumberColor: GridColor;
19
+ negativeNumberColor: GridColor;
20
+ zeroNumberColor: GridColor;
21
+ dateColor: GridColor;
22
+ nullBackgroundColor: NullableGridColor;
23
+ cellHorizontalPadding: number;
24
+ headerHorizontalPadding: number;
25
+ font: GridFont;
26
+ gridColumnColor: NullableGridColor;
27
+ gridRowColor: NullableGridColor;
28
+ headerBackgroundColor: GridColor;
29
+ headerSeparatorColor: GridColor;
30
+ headerSeparatorHoverColor: GridColor;
31
+ headerSeparatorHandleSize: number;
32
+ headerHiddenSeparatorSize: number;
33
+ headerHiddenSeparatorHoverColor: GridColor;
34
+ headerColor: GridColor;
35
+ headerFont: GridFont;
36
+ columnHoverBackgroundColor: NullableGridColor;
37
+ rowHoverBackgroundColor: NullableGridColor;
38
+ selectedRowHoverBackgroundColor: NullableGridColor;
39
+ cursorRowBackgroundColor: NullableGridColor;
40
+ rowBackgroundColors: GridColorWay;
41
+ minScrollHandleSize: number;
42
+ scrollBarBackgroundColor: GridColor;
43
+ scrollBarHoverBackgroundColor: GridColor;
44
+ scrollBarCasingColor: GridColor;
45
+ scrollBarCornerColor: GridColor;
46
+ scrollBarColor: GridColor;
47
+ scrollBarHoverColor: GridColor;
48
+ scrollBarActiveColor: GridColor;
49
+ scrollBarSize: number;
50
+ scrollBarHoverSize: number;
51
+ scrollBarCasingWidth: number;
52
+ scrollSnapToColumn: boolean;
53
+ scrollSnapToRow: boolean;
54
+ scrollBarSelectionTick: boolean;
55
+ scrollBarSelectionTickColor: NullableGridColor;
56
+ scrollBarActiveSelectionTickColor: NullableGridColor;
57
+ activeCellSelectionBorderWidth: number;
58
+ selectionColor: GridColor;
59
+ selectionOutlineColor: GridColor;
60
+ selectionOutlineCasingColor: GridColor;
61
+ reorderOffset: number;
62
+ shadowBlur: number;
63
+ shadowColor: GridColor;
64
+ flashColor: GridColor;
65
+ errorColor: GridColor;
66
+ rowHeight: number;
67
+ columnWidth: number;
68
+ minColumnWidth: number;
69
+ maxColumnWidth: number;
70
+ columnHeaderHeight: number;
71
+ rowHeaderWidth: number;
72
+ rowFooterWidth: number;
73
+ headerResizeSnapThreshold: number;
74
+ headerResizeHiddenSnapThreshold: number;
75
+ floatingGridColumnColor: NullableGridColor;
76
+ floatingGridRowColor: NullableGridColor;
77
+ floatingRowBackgroundColors: GridColorWay;
78
+ floatingDividerOuterColor: GridColor;
79
+ floatingDividerInnerColor: GridColor;
80
+ };
81
+ /** A design token's value by name, without the leading `--` (web/theme/tokens.css) */
82
+ export type TokenReader = (name: string) => string;
83
+ /**
84
+ * The grid's look from the design tokens (docs/theme.md), so the canvas draws with the same
85
+ * colours and fonts as the page around it: cells in the mono for aligned figures, headers in
86
+ * the sans.
87
+ */
88
+ export declare function gridTheme(token: TokenReader): GridTheme;
89
+ /** The grid's theme from the tokens in effect at `element`, which must be in the document */
90
+ export declare function gridThemeOf(element: Element): GridTheme;
91
+ /**
92
+ * Geometry and behaviour for a grid given no theme; its colours are the token names, so a host
93
+ * that forgets to pass `gridThemeOf(...)` draws nothing rather than a second palette.
94
+ */
95
+ declare const baseTheme: GridTheme;
96
+ export default baseTheme;
@@ -0,0 +1,457 @@
1
+ import type React from 'react';
2
+ import GridRange, { type GridRangeIndex } from './GridRange';
3
+ import { type BoxCoordinates, type Coordinate, type CoordinateMap, type VisibleIndex, type VisibleToModelMap, type ModelIndex, type ModelSizeMap, type MoveOperation, type SizeMap, type GridMetrics } from './GridMetrics';
4
+ import { type GridTheme } from './GridTheme';
5
+ import { type GridWheelEvent } from './GridMouseHandler';
6
+ import { type AxisRange, type BoundedAxisRange, type Range } from './GridAxisRange';
7
+ import { type GridRenderState } from './GridRendererTypes';
8
+ import type GridModel from './GridModel';
9
+ export type GridPoint = {
10
+ x: Coordinate;
11
+ y: Coordinate;
12
+ column: GridRangeIndex;
13
+ row: GridRangeIndex;
14
+ columnHeaderDepth?: number;
15
+ };
16
+ export interface CellInfo {
17
+ row: VisibleIndex | null;
18
+ column: VisibleIndex | null;
19
+ modelRow: ModelIndex | null;
20
+ modelColumn: ModelIndex | null;
21
+ left: Coordinate | null;
22
+ top: Coordinate | null;
23
+ columnWidth: number | null;
24
+ rowHeight: number | null;
25
+ }
26
+ export type IndexCallback<T> = (itemIndex: VisibleIndex) => T | undefined;
27
+ export declare class GridUtils {
28
+ static PIXELS_PER_LINE: number;
29
+ /**
30
+ * Get the GridPoint for the coordinates provided
31
+ * @param x The grid x coordinate
32
+ * @param y The grid y coordinate
33
+ * @param metrics The grid metrics
34
+ * @returns The GridPoint including the column/row information
35
+ */
36
+ static getGridPointFromXY(x: Coordinate, y: Coordinate, metrics: GridMetrics): GridPoint;
37
+ static getCellInfoFromXY(x: Coordinate, y: Coordinate, metrics: GridMetrics): CellInfo;
38
+ static getColumnHeaderDepthAtY(y: Coordinate, metrics: GridMetrics): number | undefined;
39
+ /**
40
+ * Iterate through each floating item at the start and call a callback, returning the first result
41
+ * @param start The count of floating items at the start
42
+ * @param total The total number of items
43
+ * @param callback Function to call for each item
44
+ * @returns The result from the callback
45
+ */
46
+ static iterateFloatingStart<T>(start: number, total: number, callback: IndexCallback<T>): T | undefined;
47
+ /**
48
+ * Iterate through floating items at the end. Iterates in increasing order.
49
+ * @param end The count of floating items at the end
50
+ * @param total The total number of items
51
+ * @param callback Function to call for each item
52
+ * @returns The result from the callback
53
+ */
54
+ static iterateFloatingEnd<T>(end: number, total: number, callback: IndexCallback<T>): T | undefined;
55
+ /**
56
+ * Iterate through all floating items in increasing order, starting with the top items.
57
+ * @param start Count of start floating rows, e.g. floatingTopRowCount
58
+ * @param end Count of end floating rows, e.g. floatingBottomRowCount
59
+ * @param total Total number of items
60
+ * @param callback Callback called for each value, stopping the iterating and returning the value if one is returned
61
+ */
62
+ static iterateFloating<T>(start: number, end: number, total: number, callback: IndexCallback<T>): T | undefined;
63
+ /**
64
+ * Iterate through all items in one dimension on the grid - first floating, then visible.
65
+ * Call the callback for each item, break if a result is returned and return that result.
66
+ * @param visibleStart Index of the start of the visible viewport
67
+ * @param visibleEnd Index of the end of the visible viewport
68
+ * @param floatingStartCount Number of items floating at the start
69
+ * @param floatingEndCount Number of items floating at the end
70
+ * @param totalCount Total number of items
71
+ * @param callback Callback to call for each item
72
+ * @returns The first result from the callback called, or undefined
73
+ */
74
+ static iterateAllItems<T>(visibleStart: VisibleIndex, visibleEnd: VisibleIndex, floatingStartCount: number, floatingEndCount: number, totalCount: number, callback: IndexCallback<T>): T | undefined;
75
+ /**
76
+ * Check if the coordinate is within the item specified in this dimension
77
+ * @param itemIndex Index of the item to check
78
+ * @param itemCoordinatess Coordinate of all items in this dimension
79
+ * @param itemSizes Size of all items in this dimension
80
+ * @param coordinate The coordinate to check
81
+ * @returns True if the coordinate is within the item specified, false otherwise
82
+ */
83
+ static isInItem(itemIndex: VisibleIndex, itemCoordinates: CoordinateMap, itemSizes: SizeMap, coordinate: Coordinate): boolean;
84
+ /**
85
+ * Get the Index of the item at the provided offset
86
+ * @param offset Coordinate of the offset to get the item of
87
+ * @param itemCount The total count of items
88
+ * @param floatingStart Count of floating items at the start
89
+ * @param floatingEnd Count of floating items at the end
90
+ * @param items Index of all items
91
+ * @param itemCoordinates The coordinate of each item
92
+ * @param itemSizes The size of each item
93
+ * @returns The item index, or null if no item matches
94
+ */
95
+ static getItemAtOffset(offset: Coordinate, itemCount: number, floatingStart: number, floatingEnd: number, items: readonly VisibleIndex[], itemCoordinates: CoordinateMap, itemSizes: SizeMap, ignoreFloating?: boolean): VisibleIndex | null;
96
+ /**
97
+ * Get the index of the column at the specified x coordinate
98
+ * @param x Coordinate to get the item of
99
+ * @param metrics Grid metrics
100
+ * @returns Index of the column at that coordinate, or null if no column matches
101
+ */
102
+ static getColumnAtX(x: Coordinate, metrics: GridMetrics, ignoreFloating?: boolean): VisibleIndex | null;
103
+ /**
104
+ * Get the index of the row at the specified y coordinate
105
+ * @param y Coordinate to get the item of
106
+ * @param metrics Grid metrics
107
+ * @returns Index of the row at that coordinate, or null if no row matches
108
+ */
109
+ static getRowAtY(y: Coordinate, metrics: GridMetrics): VisibleIndex | null;
110
+ /**
111
+ * Iterate backward through the visible items until a shown item is hit
112
+ * @param startIndex The index to start from
113
+ * @param modelIndexes The mapping of model indexes
114
+ * @param visibleItems The visible items
115
+ * @param userSizes The user set sizes
116
+ * @returns Index of the next visible item, or null if no more are visible
117
+ */
118
+ static getNextShownItem(startIndex: VisibleIndex, modelIndexes: VisibleToModelMap, visibleItems: readonly VisibleIndex[], userSizes: ModelSizeMap): VisibleIndex | null;
119
+ /**
120
+ * Iterate backward through the visible columns until a shown column is hit
121
+ * @param columnIndex The column index to start iterating backward from
122
+ * @param metrics The GridMetricCalculator metrics
123
+ * @returns Index of the next visible item, or null if no more are visible
124
+ */
125
+ static getNextShownColumn(startIndex: VisibleIndex, metrics: GridMetrics): VisibleIndex | null;
126
+ /**
127
+ * Iterate backward through the visible rows until a shown row is hit
128
+ * @param rowIndex The row index to start iterating backward from
129
+ * @param metrics The GridMetricCalculator metrics
130
+ * @returns Index of the next visible item, or null if no more are visible
131
+ */
132
+ static getNextShownRow(startIndex: VisibleIndex, metrics: GridMetrics): VisibleIndex | null;
133
+ /**
134
+ * Determine whether two adjacent columns belong to the same column-header group
135
+ * at the given depth.
136
+ *
137
+ * - When the model exposes group instances via `getColumnHeaderGroup`, identity
138
+ * decides: two distinct group instances that happen to share a display name
139
+ * (e.g. pivot Totals groups) are treated as different groups.
140
+ * - When only one side has a declared group, they are different groups.
141
+ * - When neither side has a declared group, fall back to header-text equality so
142
+ * plain grouped-header models (which express grouping only through repeated
143
+ * text) keep their existing behavior.
144
+ *
145
+ * @param model The grid model
146
+ * @param depth The header depth to check at
147
+ * @param columnIndex The first model column index
148
+ * @param otherColumnIndex The second model column index
149
+ * @returns true if both columns are part of the same group at this depth
150
+ */
151
+ static isSameColumnGroupAtDepth(model: GridModel, depth: number, columnIndex: ModelIndex, otherColumnIndex: ModelIndex): boolean;
152
+ /**
153
+ * Check if a separator exists between the column at `visibleIndex` and the
154
+ * column immediately after it at a given header depth.
155
+ *
156
+ * - At leaf depth (0), every model column has a separator on its trailing edge.
157
+ * - At deeper depths, separator existence follows column-header-group identity
158
+ * (see {@link isSameColumnGroupAtDepth}). Distinct group instances that share a
159
+ * display name (e.g. pivot Totals groups) are correctly treated as separate.
160
+ * - The true trailing edge of the table (the last column) always has a separator.
161
+ *
162
+ * The next model column is resolved from `visibleIndex + 1` so that an off-screen
163
+ * neighbor is handled correctly and is not mistaken for the table's trailing edge.
164
+ *
165
+ * @param model The grid model
166
+ * @param depth The header depth to check at
167
+ * @param visibleIndex The visible index of the current column
168
+ * @param columnCount The total number of columns in the model
169
+ * @param movedColumns The current column-move operations
170
+ * @returns true if a separator should be shown, false otherwise
171
+ */
172
+ static hasColumnSeparatorAtDepth(model: GridModel, depth: number | undefined, visibleIndex: VisibleIndex | undefined, columnCount: number, movedColumns: readonly MoveOperation[]): boolean;
173
+ /**
174
+ * Gets the column index if the x/y coordinates provided are close enough to the separator, otherwise null
175
+ * @param x Mouse x coordinate
176
+ * @param y Mouse y coordinate
177
+ * @param metrics The grid metrics
178
+ * @param theme The grid theme with potential user overrides
179
+ * @param model The grid model
180
+ * @returns Index of the column separator at the coordinates provided, or null if none match
181
+ */
182
+ static getColumnSeparatorIndex(x: Coordinate, y: Coordinate, metrics: GridMetrics, theme: GridTheme, model: GridModel): VisibleIndex | null;
183
+ /**
184
+ * Check if the item specified is hidden
185
+ * @param itemIndex Index of the item to check
186
+ * @param visibleSizes Sizes of all visible items
187
+ * @returns True if the item is hidden, false otherwise
188
+ */
189
+ static isItemHidden(itemIndex: VisibleIndex, visibleSizes: SizeMap): boolean;
190
+ /**
191
+ * Check if the column specified is hidden
192
+ * @param columnIndex Index of the column to check
193
+ * @param metrics Grid metrics
194
+ * @returns True if the column is hidden, false otherwise
195
+ */
196
+ static isColumnHidden(columnIndex: VisibleIndex, metrics: GridMetrics): boolean;
197
+ /**
198
+ * Check if the provided row is a floating row
199
+ * @param row The row index to check
200
+ * @param metrics The grid metrics to check against
201
+ * @returns True if it's a floating row, false otherwise
202
+ */
203
+ static isFloatingRow(row: VisibleIndex, metrics: GridMetrics): boolean;
204
+ /**
205
+ * Check if the provided column is a floating column
206
+ * @param column The column index to check
207
+ * @param metrics The grid metrics to check against
208
+ * @returns True if it's a floating column, false otherwise
209
+ */
210
+ static isFloatingColumn(column: VisibleIndex, metrics: GridMetrics): boolean;
211
+ /**
212
+ * Get all the items that are hidden under the same Index
213
+ * 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]
214
+ * @param itemIndex Index of the item to start at
215
+ * @param visibleSizes Visible size map
216
+ * @param visibleItems Visible items
217
+ * @returns Array of items that are hidden
218
+ */
219
+ static getHiddenItems(itemIndex: VisibleIndex, visibleSizes: SizeMap, visibleItems: readonly VisibleIndex[]): VisibleIndex[];
220
+ /**
221
+ * Get all the columns that are hidden under the same Index
222
+ * @param columnIndex Index of the item to start at
223
+ * @param metrics Grid metrics
224
+ * @returns Array of items that are hidden
225
+ */
226
+ static getHiddenColumns(columnIndex: VisibleIndex, metrics: GridMetrics): VisibleIndex[];
227
+ /**
228
+ * Returns the row index if the x/y coordinates provided are close enough to the separator, otherwise null
229
+ * @param x X coordinate to check
230
+ * @param y Y coordinate to check
231
+ * @param metrics The grid metrics
232
+ * @param theme The grid theme
233
+ * @returns Index of the row separator at the coordinates provided, or null if none match
234
+ */
235
+ static getRowSeparatorIndex(x: Coordinate, y: Coordinate, metrics: GridMetrics, theme: GridTheme): VisibleIndex | null;
236
+ /**
237
+ * Check if the row specified is hidden
238
+ * @param rowIndex Index of the row to check
239
+ * @param metrics Grid metrics
240
+ * @returns True if the row is hidden, false otherwise
241
+ */
242
+ static isRowHidden(rowIndex: VisibleIndex, metrics: GridMetrics): boolean;
243
+ /**
244
+ * Get all the rows that are hidden under the same Index
245
+ * @param rowIndex Index of the item to start at
246
+ * @param metrics Grid metrics
247
+ * @returns Array of items that are hidden
248
+ */
249
+ static getHiddenRows(rowIndex: VisibleIndex, metrics: GridMetrics): VisibleIndex[];
250
+ /**
251
+ * Set a new order for items in the grid
252
+ * @param from The visible index to move from
253
+ * @param to The visible index to move the item to
254
+ * @param oldMovedItems The old reordered items
255
+ * @returns The new reordered items. The original array if the operation is a no-op.
256
+ */
257
+ static moveItem(from: VisibleIndex, to: VisibleIndex, oldMovedItems: MoveOperation[]): MoveOperation[];
258
+ static moveItem(from: VisibleIndex, to: VisibleIndex, oldMovedItems: readonly MoveOperation[]): readonly MoveOperation[];
259
+ /**
260
+ * Move a visible range in the grid
261
+ *
262
+ * This will effectively slice the range out of the grid,
263
+ * re-index the remaining columns,
264
+ * then insert the range with the first element at the provided index
265
+ *
266
+ * @param from The visible axis range to move
267
+ * @param to The visible index to move the start of the range to
268
+ * @param oldMovedItems The old reordered items
269
+ * @param isPreMoveTo If toParam is the index before the movement
270
+ * If true, this will account for the shift when moving
271
+ * a range before the drop positin
272
+ * E.g. Move range [0, 2] 1 item down (after element 3)
273
+ * The move is [0, 2] -> 1 if this is false. [0, 2] -> 3 if this is true
274
+ * Both will result in [0, 2] -> 1
275
+ * @returns The new reordered items. The original array if the operation is a no-op.
276
+ */
277
+ static moveRange(from: BoundedAxisRange, to: VisibleIndex, oldMovedItems: MoveOperation[], isPreMoveTo?: boolean): MoveOperation[];
278
+ static moveRange(from: BoundedAxisRange, toParam: VisibleIndex, oldMovedItems: readonly MoveOperation[], isPreMoveTo?: boolean): readonly MoveOperation[];
279
+ static moveItemOrRange(from: VisibleIndex | BoundedAxisRange, to: VisibleIndex, oldMovedItems: MoveOperation[], isPreMoveTo?: boolean): MoveOperation[];
280
+ static moveItemOrRange(from: VisibleIndex | BoundedAxisRange, to: VisibleIndex, oldMovedItems: readonly MoveOperation[], isPreMoveTo?: boolean): readonly MoveOperation[];
281
+ /**
282
+ * Applies the items moves to the AxisRange
283
+ * @param start The start index of the range
284
+ * @param end The end index of the range
285
+ * @param movedItems The move operations to apply
286
+ * @param reverse If the moved items should be applied in reverse (this reverses the effects of the moves)
287
+ * @returns A list of AxisRanges in the translated space. Possibly multiple non-continuous ranges
288
+ */
289
+ static applyItemMoves<T extends number | GridRangeIndex>(start: T, end: T, movedItems: readonly MoveOperation[], reverse?: boolean): Range<T>[];
290
+ /**
291
+ * Applies the items moves to the givengrid range
292
+ * @param range The grid range to translate
293
+ * @param movedColumns The moved columns
294
+ * @param movedRows The moved rows
295
+ * @param reverse If the moved items should be reversed (i.e. visible to model range)
296
+ * @returns A list of grid ranges in the translated space. Possibly multiple non-continuous ranges
297
+ */
298
+ static translateRange(range: GridRange, movedColumns: readonly MoveOperation[], movedRows: readonly MoveOperation[], reverse: boolean): GridRange[];
299
+ /**
300
+ * Retrieve the model index given the currently moved items
301
+ * @param visibleIndex The visible index of the item to get the model index for
302
+ * @param movedItems The moved items
303
+ * @returns The model index of the item
304
+ */
305
+ static getModelIndex(visibleIndex: VisibleIndex, movedItems: readonly MoveOperation[]): ModelIndex;
306
+ /**
307
+ * Retrieve the model indexes given the currently moved items
308
+ * @param visibleIndexes The visible indexes of the item to get the model indexes for
309
+ * @param movedItems The moved items
310
+ * @returns The model indexes of the item
311
+ */
312
+ static getModelIndexes(visibleIndexes: ModelIndex[], movedItems: MoveOperation[]): VisibleIndex[];
313
+ /**
314
+ * Translate the provided UI start/end indexes to the model start/end indexes by applying the `movedItems` transformations.
315
+ * Since moved items can split apart a range, multiple pairs of indexes are returned
316
+ *
317
+ * @param start Start item in one dimension
318
+ * @param end End item in one dimension
319
+ * @param movedItems Moved item pairs in this dimension
320
+ * @returns Array of start/end pairs of the indexes after transformations applied.
321
+ */
322
+ static getModelRangeIndexes(start: GridRangeIndex, end: GridRangeIndex, movedItems: readonly MoveOperation[]): AxisRange[];
323
+ /**
324
+ * Translate the provided UI range into model range, using the `movedColumns` and `movedRows` to apply the necessary transforms.
325
+ * `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items
326
+ *
327
+ * @param uiRange The currently selected UI ranges
328
+ * @param movedColumns The moved column pairs
329
+ * @param movedRows The moved row pairs
330
+ * @returns The model ranges after translation.
331
+ */
332
+ static getModelRange(uiRange: GridRange, movedColumns?: readonly MoveOperation[], movedRows?: readonly MoveOperation[]): GridRange[];
333
+ /**
334
+ * Translate the provided UI range into model ranges, using the `movedColumns` and `movedRows` to apply the necessary transforms.
335
+ * `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items
336
+ *
337
+ * @param uiRanges The currently selected UI ranges
338
+ * @param movedColumns The moved column pairs
339
+ * @param movedRows The moved row pairs
340
+ * @returns The model ranges after translation.
341
+ */
342
+ static getModelRanges(uiRanges: readonly GridRange[], movedColumns?: readonly MoveOperation[], movedRows?: readonly MoveOperation[]): GridRange[];
343
+ /**
344
+ * Translate the provided UI start/end indexes to the visible start/end indexes by applying the `movedItems` transformations.
345
+ * Since moved items can split apart a range, multiple pairs of indexes are returned
346
+ *
347
+ * @param start Start item in one dimension
348
+ * @param end End item in one dimension
349
+ * @param movedItems Moved item pairs in this dimension
350
+ * @returns Array of start/end pairs of the indexes after transformations applied.
351
+ */
352
+ static getVisibleRangeIndexes(start: GridRangeIndex, end: GridRangeIndex, movedItems: readonly MoveOperation[]): AxisRange[];
353
+ /**
354
+ * Translate the provided UI range into visible range, using the `movedColumns` and `movedRows` to apply the necessary transforms.
355
+ * `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items
356
+ *
357
+ * @param uiRange The currently selected UI ranges
358
+ * @param movedColumns The moved column pairs
359
+ * @param movedRows The moved row pairs
360
+ * @returns The model ranges after translation.
361
+ */
362
+ static getVisibleRange(modelRange: GridRange, movedColumns?: readonly MoveOperation[], movedRows?: readonly MoveOperation[]): GridRange[];
363
+ /**
364
+ * Translate the provided model ranges into visible ranges, using the `movedColumns` and `movedRows` to apply the necessary transforms.
365
+ * `movedColumns` and `movedRows` are array of operations done to the UI indexes to re-order items
366
+ *
367
+ * @param modelRanges The model ranges
368
+ * @param movedColumns The moved column pairs
369
+ * @param movedRows The moved row pairs
370
+ * @returns The model ranges after translation.
371
+ */
372
+ static getVisibleRanges(modelRanges: readonly GridRange[], movedColumns?: readonly MoveOperation[], movedRows?: readonly MoveOperation[]): GridRange[];
373
+ /**
374
+ * Retrieve the visible index given the currently moved items
375
+ * @param modelIndex The model index to get the visible index for
376
+ * @param movedItems Moved items
377
+ * @returns The visible index of the item
378
+ */
379
+ static getVisibleIndex(modelIndex: ModelIndex, movedItems: readonly MoveOperation[]): VisibleIndex;
380
+ /**
381
+ * Retrieve the visible indexes given the currently moved items
382
+ * @param modelIndexes The model indexes to get the visible indexes for
383
+ * @param movedItems Moved items
384
+ * @returns The visible indexes of the item
385
+ */
386
+ static getVisibleIndexes(modelIndexes: readonly ModelIndex[], movedItems: readonly MoveOperation[]): VisibleIndex[];
387
+ /**
388
+ * Check if the current platform is Mac
389
+ * @returns True if this platform is a Mac, false otherwise
390
+ */
391
+ static isMacPlatform(): boolean;
392
+ /**
393
+ * Get the modifier key for the current platform
394
+ * @returns The modifier key for the current platform
395
+ */
396
+ static getModifierKey(): 'metaKey' | 'ctrlKey';
397
+ /**
398
+ * Check if the modifier key is down for the given event
399
+ * @param event The event to check
400
+ * @returns True if the modifier key is down, false otherwise
401
+ */
402
+ static isModifierKeyDown(event: MouseEvent | KeyboardEvent | React.KeyboardEvent | React.MouseEvent): boolean;
403
+ /**
404
+ * Check if the user has hidden the specified column
405
+ * @param modelIndex The model index to check
406
+ * @param userColumnWidths The user set column widths
407
+ * @returns True if the user has hidden the column
408
+ */
409
+ static checkColumnHidden(modelIndex: ModelIndex, userColumnWidths: ModelSizeMap): boolean;
410
+ /**
411
+ * Check if all the columns specified are hidden
412
+ * @param columns Columns to check
413
+ * @param userColumnWidths The user set column widths
414
+ * @returns True if the user has hidden all of the columns
415
+ */
416
+ static checkAllColumnsHidden(columns: readonly ModelIndex[], userColumnWidths: ModelSizeMap): boolean;
417
+ /**
418
+ * Get the bounds the mouse needs to be dragged outside of from an initial selection before scrolling occurs.
419
+ * Taking into account any floating rows that may be covering the viewport.
420
+ * @param metrics Grid metrics
421
+ * @param row The row they started dragging in
422
+ * @param column The column they started the drag from
423
+ * @returns Dimensions of the drag area in relation to the canvas they need to drag outside of to start scrolling
424
+ */
425
+ static getScrollDragBounds(metrics: GridMetrics, row: GridRangeIndex, column: GridRangeIndex): BoxCoordinates;
426
+ /**
427
+ * Converts the delta coordinates from the provided wheel event to pixels
428
+ * Different platforms have different ways of providing the delta so this normalizes it
429
+ * @param wheelEvent The mouse wheel event to get the scrolling delta for
430
+ * @param pageWidth The width of the page that is scrolling
431
+ * @param pageHeight The height of the page that is scrolling
432
+ * @param lineWidth The width of the line scrolling in line mode
433
+ * @param lineHeight The height of the line scrolling in line mode
434
+ * @returns The delta coordinates normalized to pixels
435
+ */
436
+ static getScrollDelta(wheelEvent: GridWheelEvent, pageWidth?: number, pageHeight?: number, lineWidth?: number, lineHeight?: number): {
437
+ deltaX: number;
438
+ deltaY: number;
439
+ };
440
+ static compareRanges(range1: AxisRange, range2: AxisRange): number;
441
+ static mergeSortedRanges(ranges: BoundedAxisRange[]): BoundedAxisRange[];
442
+ /**
443
+ * Gets textWidth and X-Y position for a specific cell
444
+ * The textWidth returned is the width that the text can occupy accounting for cell padding
445
+ *
446
+ * @param state GridRenderState to get the text metrics for
447
+ * @param column Column of cell to get text metrics for
448
+ * @param row Row of cell to get text metrics for
449
+ * @returns Object with width, x, and y of the text
450
+ */
451
+ static getTextRenderMetrics(state: GridRenderState, column: VisibleIndex, row: VisibleIndex): {
452
+ width: number;
453
+ x: number;
454
+ y: number;
455
+ };
456
+ }
457
+ export default GridUtils;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Handle keys in a grid
3
+ * Return true from any of the events to indicate they're consumed, and stopPropagation/preventDefault will be called.
4
+ */
5
+ import type React from 'react';
6
+ import { type EventHandlerResult } from './EventHandlerResult';
7
+ import type Grid from './Grid';
8
+ /**
9
+ * Some events we listen to are a native keyboard event, and others are wrapped with React's SyntheticEvent.
10
+ * The KeyHandler shouldn't care though - the properties it accesses should be common on both types of events.
11
+ */
12
+ export type GridKeyboardEvent = KeyboardEvent | React.KeyboardEvent;
13
+ export type GridKeyHandlerFunctionName = 'onDown' | 'onUp';
14
+ export declare class KeyHandler {
15
+ order: number;
16
+ constructor(order?: number);
17
+ cursor: string | null;
18
+ /**
19
+ * Handle a keydown event on the grid.
20
+ * @param event The keyboard event
21
+ * @param grid The grid component the key press is on
22
+ * @returns Response indicating if the key was consumed
23
+ */
24
+ onDown(event: GridKeyboardEvent, grid: Grid): EventHandlerResult;
25
+ /**
26
+ * Handle a keyup event on the grid.
27
+ * @param event The keyboard event
28
+ * @param grid The grid component the key press is on
29
+ * @returns Response indicating if the key was consumed
30
+ */
31
+ onUp(event: GridKeyboardEvent, grid: Grid): EventHandlerResult;
32
+ }
33
+ export default KeyHandler;