@tanstack/table-core 9.0.0-beta.56 → 9.0.0-beta.58
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/core/row-models/createCoreRowModel.js +5 -1
- package/dist/features/cell-selection/cellSelectionFeature.d.ts +9 -0
- package/dist/features/cell-selection/cellSelectionFeature.js +117 -0
- package/dist/features/cell-selection/cellSelectionFeature.types.d.ts +273 -0
- package/dist/features/cell-selection/cellSelectionFeature.utils.d.ts +288 -0
- package/dist/features/cell-selection/cellSelectionFeature.utils.js +732 -0
- package/dist/features/row-aggregation/rowAggregationFeature.types.d.ts +7 -7
- package/dist/features/stockFeatures.d.ts +3 -1
- package/dist/features/stockFeatures.js +3 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -1
- package/dist/static-functions.d.ts +2 -1
- package/dist/static-functions.js +2 -1
- package/dist/types/Cell.d.ts +4 -2
- package/dist/types/Column.d.ts +2 -2
- package/dist/types/ColumnDef.d.ts +10 -8
- package/dist/types/Row.d.ts +2 -2
- package/dist/types/RowModelFns.d.ts +3 -3
- package/dist/types/Table.d.ts +3 -1
- package/dist/types/TableOptions.d.ts +6 -4
- package/dist/types/TableState.d.ts +3 -1
- package/package.json +1 -1
- package/skills/aggregation/SKILL.md +2 -2
- package/skills/api-not-found/SKILL.md +1 -1
- package/skills/cell-selection/SKILL.md +180 -0
- package/skills/client-vs-server/SKILL.md +1 -1
- package/skills/column-faceting/SKILL.md +1 -1
- package/skills/column-filtering/SKILL.md +1 -1
- package/skills/column-ordering/SKILL.md +1 -1
- package/skills/column-pinning/SKILL.md +1 -1
- package/skills/column-resizing/SKILL.md +1 -1
- package/skills/column-sizing/SKILL.md +1 -1
- package/skills/column-visibility/SKILL.md +1 -1
- package/skills/core/SKILL.md +1 -1
- package/skills/custom-features/SKILL.md +1 -1
- package/skills/expanding/SKILL.md +1 -1
- package/skills/global-filtering/SKILL.md +1 -1
- package/skills/grouping/SKILL.md +1 -1
- package/skills/migrate-v8-to-v9/SKILL.md +1 -1
- package/skills/pagination/SKILL.md +1 -1
- package/skills/row-pinning/SKILL.md +1 -1
- package/skills/row-selection/SKILL.md +1 -1
- package/skills/sorting/SKILL.md +1 -1
- package/skills/table-features/SKILL.md +1 -1
- package/skills/typescript/SKILL.md +1 -1
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { CellData, RowData, Updater } from "../../types/type-utils.js";
|
|
2
|
+
import { CellSelectionBounds, CellSelectionDirection, CellSelectionEdges, CellSelectionRange, CellSelectionState, SelectCellRangeOptions } from "./cellSelectionFeature.types.js";
|
|
3
|
+
import { Table } from "../../types/Table.js";
|
|
4
|
+
import { Cell } from "../../types/Cell.js";
|
|
5
|
+
import { TableFeatures } from "../../types/TableFeatures.js";
|
|
6
|
+
|
|
7
|
+
//#region src/features/cell-selection/cellSelectionFeature.utils.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Creates the default cell selection state.
|
|
10
|
+
*
|
|
11
|
+
* The feature default is an empty selection. Reset APIs use this value when
|
|
12
|
+
* `defaultState` is `true`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const selection = getDefaultCellSelectionState()
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function getDefaultCellSelectionState(): CellSelectionState;
|
|
20
|
+
/**
|
|
21
|
+
* Routes a cell selection updater through the table's selection change handler.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* table_setCellSelection(table, (old) => old.slice(0, -1))
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function table_setCellSelection<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, updater: Updater<CellSelectionState>): void;
|
|
29
|
+
/**
|
|
30
|
+
* Resets `cellSelection` to the configured initial state or feature default.
|
|
31
|
+
*
|
|
32
|
+
* With no argument, the reset clones `table.initialState.cellSelection` when it
|
|
33
|
+
* exists. Passing `true` ignores initial state and resets to an empty selection.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* table_resetCellSelection(table, true)
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function table_resetCellSelection<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, defaultState?: boolean): void;
|
|
41
|
+
/**
|
|
42
|
+
* Schedules a cell selection reset after `data` changes.
|
|
43
|
+
*
|
|
44
|
+
* Ranges are stored as row and column ids, so without this a data swap would
|
|
45
|
+
* leave a selection pointing at rows that no longer exist, or silently
|
|
46
|
+
* re-select cells whenever new data reuses ids. The reset runs when
|
|
47
|
+
* `autoResetAll` or `autoResetCellSelection` allows it, defaulting to on.
|
|
48
|
+
*
|
|
49
|
+
* Resetting to `initialState.cellSelection` rather than to empty means the
|
|
50
|
+
* first row-model computation is a no-op, matching `table_autoResetExpanded`.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* table_autoResetCellSelection(table)
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function table_autoResetCellSelection<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): void;
|
|
58
|
+
/**
|
|
59
|
+
* Builds a column id to render-order index map.
|
|
60
|
+
*
|
|
61
|
+
* Registered by this feature so the lookup stays memoized even when
|
|
62
|
+
* `columnOrderingFeature` is absent, since that feature's `getColumnIndexes`
|
|
63
|
+
* static rebuilds all four maps on every call, which would make per-cell reads
|
|
64
|
+
* O(columns).
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const index = table_getCellSelectionColumnIndexes(table)[columnId]
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function table_getCellSelectionColumnIndexes<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): Record<string, number>;
|
|
72
|
+
/**
|
|
73
|
+
* Resolves the selected ranges into inclusive display-order index rectangles.
|
|
74
|
+
*
|
|
75
|
+
* This is the single cache every per-cell read goes through, so index lookups
|
|
76
|
+
* happen once per invalidation rather than once per cell. A range whose corners
|
|
77
|
+
* no longer resolve, for example because its anchor row was filtered out, is
|
|
78
|
+
* omitted rather than clamped, so it contributes nothing while remaining in
|
|
79
|
+
* state and returns intact when the filter clears.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const bounds = table_getCellSelectionBounds(table)
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function table_getCellSelectionBounds<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): Array<CellSelectionBounds>;
|
|
87
|
+
/**
|
|
88
|
+
* Checks whether this cell can currently be selected.
|
|
89
|
+
*
|
|
90
|
+
* A column def opting out with `enableCellSelection: false` wins over the table
|
|
91
|
+
* option, matching how the other per-column enable flags resolve.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const canSelect = cell_getCanSelect(cell)
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare function cell_getCanSelect<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Checks whether this cell falls inside any selected range.
|
|
101
|
+
*
|
|
102
|
+
* Deliberately not memoized. Registering this through `assignPrototypeAPIs`
|
|
103
|
+
* with `memoDeps` would allocate a memo closure and dependency array per cell,
|
|
104
|
+
* which costs more than the handful of integer comparisons it would save.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const isSelected = cell_getIsSelected(cell)
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function cell_getIsSelected<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Checks whether this cell is the active cell.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const isFocused = cell_getIsFocused(cell)
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
declare function cell_getIsFocused<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Returns `0` for the focused cell and `-1` otherwise, for roving tabindex.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const tabIndex = cell_getTabIndex(cell)
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function cell_getTabIndex<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): number;
|
|
130
|
+
/**
|
|
131
|
+
* Returns which sides of this cell sit on the outer boundary of the selection.
|
|
132
|
+
*
|
|
133
|
+
* A side is an edge when the neighbouring cell in that direction is not itself
|
|
134
|
+
* covered by a range, which is what lets a consumer draw a single outline
|
|
135
|
+
* around an arbitrary union of rectangles.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* const { top, right, bottom, left } = cell_getSelectionEdges(cell)
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare function cell_getSelectionEdges<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): CellSelectionEdges;
|
|
143
|
+
/**
|
|
144
|
+
* Returns the active cell, i.e. the anchor of the most recent range.
|
|
145
|
+
*
|
|
146
|
+
* Focus is derived rather than stored: in spreadsheet semantics, dragging from
|
|
147
|
+
* A1 to C5 leaves the active cell at A1, so the active range's anchor already
|
|
148
|
+
* is the active cell.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const cell = table_getFocusedCell(table)
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
declare function table_getFocusedCell<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): Cell<TFeatures, TData, any> | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* Collapses the selection to a single cell at the given coordinates.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* table_setFocusedCell(table, '3', 'firstName')
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function table_setFocusedCell<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, rowId: string, columnId: string): void;
|
|
165
|
+
/**
|
|
166
|
+
* Selects a rectangle, replacing the current selection unless `additive`.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* table_selectCellRange(table, range, { additive: true })
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
declare function table_selectCellRange<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, range: CellSelectionRange, opts?: SelectCellRangeOptions): void;
|
|
174
|
+
/**
|
|
175
|
+
* Selects every selectable cell in the table as one range.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* table_selectAllCells(table)
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
declare function table_selectAllCells<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): void;
|
|
183
|
+
/**
|
|
184
|
+
* Moves the selection one step in a direction, collapsing it to a single cell.
|
|
185
|
+
*
|
|
186
|
+
* With nothing selected, this selects the first selectable cell so keyboard
|
|
187
|
+
* navigation has somewhere to start.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* table_moveCellSelection(table, 'down')
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare function table_moveCellSelection<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, direction: CellSelectionDirection): void;
|
|
195
|
+
/**
|
|
196
|
+
* Extends the active range one step in a direction, keeping its anchor fixed.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* table_extendCellSelection(table, 'right')
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
declare function table_extendCellSelection<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, direction: CellSelectionDirection): void;
|
|
204
|
+
/**
|
|
205
|
+
* Returns the ids of all selected cells, in row-major order.
|
|
206
|
+
*
|
|
207
|
+
* Cells covered by overlapping ranges are returned once, at their first
|
|
208
|
+
* occurrence.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* const ids = table_getSelectedCellIds(table)
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
declare function table_getSelectedCellIds<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): Array<string>;
|
|
216
|
+
/**
|
|
217
|
+
* Returns each selected range's values as a row-major grid.
|
|
218
|
+
*
|
|
219
|
+
* This is the raw material for clipboard export. Serializing it to text is left
|
|
220
|
+
* to userland, since the delimiter, the null representation, and whether values
|
|
221
|
+
* containing delimiters get quoted are all application decisions.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* const [firstRange] = table_getSelectedCellRangesData(table)
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
declare function table_getSelectedCellRangesData<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): Array<Array<Array<unknown>>>;
|
|
229
|
+
/**
|
|
230
|
+
* Returns the number of selected cells.
|
|
231
|
+
*
|
|
232
|
+
* Uses rectangle arithmetic for a single range, which needs no expansion.
|
|
233
|
+
* Multiple ranges are enumerated so overlapping cells are counted once. A
|
|
234
|
+
* per-cell `enableCellSelection` predicate also requires enumeration.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* const count = table_getSelectedCellCount(table)
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
declare function table_getSelectedCellCount<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): number;
|
|
242
|
+
/**
|
|
243
|
+
* Returns the ids of all rows intersected by the selection.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* const rowIds = table_getCellSelectionRowIds(table)
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
declare function table_getCellSelectionRowIds<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): Array<string>;
|
|
251
|
+
/**
|
|
252
|
+
* Returns the ids of all columns intersected by the selection.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* const columnIds = table_getCellSelectionColumnIds(table)
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
declare function table_getCellSelectionColumnIds<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): Array<string>;
|
|
260
|
+
/**
|
|
261
|
+
* Creates a handler that begins a selection at this cell.
|
|
262
|
+
*
|
|
263
|
+
* Follows `header_getResizeHandler`: the enable check is resolved once outside
|
|
264
|
+
* the returned closure and guarded again inside it, the document is injectable
|
|
265
|
+
* for SSR and cross-document rendering, and the document-level `mouseup`
|
|
266
|
+
* listener is attached here so a drag released outside the table still ends.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```tsx
|
|
270
|
+
* <td onMouseDown={cell.getSelectionStartHandler()} />
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
declare function cell_getSelectionStartHandler<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>, _contextDocument?: Document): (e: unknown) => void;
|
|
274
|
+
/**
|
|
275
|
+
* Creates a handler that extends the active range to this cell during a drag.
|
|
276
|
+
*
|
|
277
|
+
* No rAF coalescing is needed here, unlike the resize handler: `mouseenter`
|
|
278
|
+
* fires once per cell boundary crossed rather than continuously, and deferring
|
|
279
|
+
* it by a frame would only delay the highlight.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```tsx
|
|
283
|
+
* <td onMouseEnter={cell.getSelectionExtendHandler()} />
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
declare function cell_getSelectionExtendHandler<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): (_e: unknown) => void;
|
|
287
|
+
//#endregion
|
|
288
|
+
export { cell_getCanSelect, cell_getIsFocused, cell_getIsSelected, cell_getSelectionEdges, cell_getSelectionExtendHandler, cell_getSelectionStartHandler, cell_getTabIndex, getDefaultCellSelectionState, table_autoResetCellSelection, table_extendCellSelection, table_getCellSelectionBounds, table_getCellSelectionColumnIds, table_getCellSelectionColumnIndexes, table_getCellSelectionRowIds, table_getFocusedCell, table_getSelectedCellCount, table_getSelectedCellIds, table_getSelectedCellRangesData, table_moveCellSelection, table_resetCellSelection, table_selectAllCells, table_selectCellRange, table_setCellSelection, table_setFocusedCell };
|