@tanstack/react-table 8.0.0-alpha.8 → 8.0.0-alpha.9

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 (96) hide show
  1. package/build/cjs/core.js +65 -80
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/createTable.js +44 -30
  4. package/build/cjs/createTable.js.map +1 -1
  5. package/build/cjs/features/ColumnSizing.js +23 -22
  6. package/build/cjs/features/ColumnSizing.js.map +1 -1
  7. package/build/cjs/features/Expanding.js +10 -22
  8. package/build/cjs/features/Expanding.js.map +1 -1
  9. package/build/cjs/features/Filters.js +27 -58
  10. package/build/cjs/features/Filters.js.map +1 -1
  11. package/build/cjs/features/Grouping.js +10 -27
  12. package/build/cjs/features/Grouping.js.map +1 -1
  13. package/build/cjs/features/Headers.js +108 -28
  14. package/build/cjs/features/Headers.js.map +1 -1
  15. package/build/cjs/features/Ordering.js +2 -2
  16. package/build/cjs/features/Ordering.js.map +1 -1
  17. package/build/cjs/features/Pagination.js +24 -29
  18. package/build/cjs/features/Pagination.js.map +1 -1
  19. package/build/cjs/features/Pinning.js.map +1 -1
  20. package/build/cjs/features/RowSelection.js +23 -38
  21. package/build/cjs/features/RowSelection.js.map +1 -1
  22. package/build/cjs/features/Sorting.js +10 -22
  23. package/build/cjs/features/Sorting.js.map +1 -1
  24. package/build/cjs/features/Visibility.js +10 -2
  25. package/build/cjs/features/Visibility.js.map +1 -1
  26. package/build/cjs/filterTypes.js.map +1 -1
  27. package/build/cjs/index.js +12 -0
  28. package/build/cjs/index.js.map +1 -1
  29. package/build/cjs/sortTypes.js.map +1 -1
  30. package/build/cjs/types.js +22 -0
  31. package/build/cjs/types.js.map +1 -0
  32. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -1
  33. package/build/cjs/utils/expandRowsFn.js.map +1 -1
  34. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -1
  35. package/build/cjs/utils/groupRowsFn.js.map +1 -1
  36. package/build/cjs/utils/paginateRowsFn.js.map +1 -1
  37. package/build/cjs/utils/sortRowsFn.js.map +1 -1
  38. package/build/cjs/utils.js +44 -18
  39. package/build/cjs/utils.js.map +1 -1
  40. package/build/esm/index.js +1382 -1357
  41. package/build/esm/index.js.map +1 -1
  42. package/build/stats-html.html +1 -1
  43. package/build/stats-react.json +337 -321
  44. package/build/types/core.d.ts +63 -68
  45. package/build/types/createTable.d.ts +34 -44
  46. package/build/types/features/ColumnSizing.d.ts +13 -7
  47. package/build/types/features/Expanding.d.ts +11 -16
  48. package/build/types/features/Filters.d.ts +39 -47
  49. package/build/types/features/Grouping.d.ts +28 -27
  50. package/build/types/features/Headers.d.ts +30 -30
  51. package/build/types/features/Ordering.d.ts +5 -5
  52. package/build/types/features/Pagination.d.ts +11 -16
  53. package/build/types/features/Pinning.d.ts +5 -5
  54. package/build/types/features/RowSelection.d.ts +15 -23
  55. package/build/types/features/Sorting.d.ts +26 -25
  56. package/build/types/features/Visibility.d.ts +9 -9
  57. package/build/types/filterTypes.d.ts +10 -10
  58. package/build/types/index.d.ts +1 -0
  59. package/build/types/sortTypes.d.ts +7 -7
  60. package/build/types/types.d.ts +34 -23
  61. package/build/types/utils/columnFilterRowsFn.d.ts +2 -2
  62. package/build/types/utils/expandRowsFn.d.ts +2 -2
  63. package/build/types/utils/globalFilterRowsFn.d.ts +2 -2
  64. package/build/types/utils/groupRowsFn.d.ts +2 -2
  65. package/build/types/utils/paginateRowsFn.d.ts +2 -2
  66. package/build/types/utils/sortRowsFn.d.ts +2 -2
  67. package/build/types/utils.d.ts +5 -6
  68. package/build/umd/index.development.js +1395 -1359
  69. package/build/umd/index.development.js.map +1 -1
  70. package/build/umd/index.production.js +1 -1
  71. package/build/umd/index.production.js.map +1 -1
  72. package/package.json +1 -7
  73. package/src/core.tsx +189 -522
  74. package/src/createTable.tsx +133 -191
  75. package/src/features/ColumnSizing.ts +48 -77
  76. package/src/features/Expanding.ts +25 -113
  77. package/src/features/Filters.ts +91 -293
  78. package/src/features/Grouping.ts +60 -165
  79. package/src/features/Headers.ts +148 -331
  80. package/src/features/Ordering.ts +19 -42
  81. package/src/features/Pagination.ts +35 -110
  82. package/src/features/Pinning.ts +16 -40
  83. package/src/features/RowSelection.ts +47 -227
  84. package/src/features/Sorting.ts +49 -143
  85. package/src/features/Visibility.ts +23 -64
  86. package/src/filterTypes.ts +19 -82
  87. package/src/index.tsx +1 -0
  88. package/src/sortTypes.ts +19 -31
  89. package/src/types.ts +80 -100
  90. package/src/utils/columnFilterRowsFn.ts +11 -53
  91. package/src/utils/expandRowsFn.ts +7 -27
  92. package/src/utils/globalFilterRowsFn.ts +10 -43
  93. package/src/utils/groupRowsFn.ts +13 -37
  94. package/src/utils/paginateRowsFn.ts +5 -11
  95. package/src/utils/sortRowsFn.ts +8 -28
  96. package/src/utils.tsx +61 -35
@@ -7,48 +7,52 @@ import {
7
7
  Getter,
8
8
  OnChangeFn,
9
9
  PropGetterValue,
10
- ReactTable,
10
+ TableInstance,
11
11
  Row,
12
12
  Updater,
13
+ PartialGenerics,
13
14
  } from '../types'
14
15
  import {
15
16
  functionalUpdate,
16
17
  isFunction,
17
18
  makeStateUpdater,
18
19
  memo,
20
+ Overwrite,
19
21
  propGetter,
20
22
  } from '../utils'
21
23
 
22
24
  export type GroupingState = string[]
23
25
 
24
- export type AggregationFn = (leafValues: any[], childValues: any[]) => any
26
+ export type AggregationFn<TGenerics extends PartialGenerics> = (
27
+ leafValues: TGenerics['Row'][],
28
+ childValues: TGenerics['Row'][]
29
+ ) => any
25
30
 
26
- export type AggregationType<TAggregationFns> =
31
+ export type CustomAggregationTypes<TGenerics extends PartialGenerics> = Record<
32
+ string,
33
+ AggregationFn<TGenerics>
34
+ >
35
+
36
+ export type AggregationType<TGenerics extends PartialGenerics> =
27
37
  | 'auto'
28
38
  | BuiltInAggregationType
29
- | keyof TAggregationFns
30
- | AggregationFn
39
+ | keyof TGenerics['AggregationFns']
40
+ | AggregationFn<TGenerics>
31
41
 
32
42
  export type GroupingTableState = {
33
43
  grouping: GroupingState
34
44
  }
35
45
 
36
- export type GroupingColumnDef<TAggregationFns> = {
37
- aggregationType?: AggregationType<TAggregationFns>
46
+ export type GroupingColumnDef<TGenerics extends PartialGenerics> = {
47
+ aggregationType?: AggregationType<Overwrite<TGenerics, { Value: any }>>
38
48
  aggregateValue?: (columnValue: unknown) => any
39
49
  renderAggregatedCell?: () => React.ReactNode
40
50
  enableGrouping?: boolean
41
51
  defaultCanGroup?: boolean
42
52
  }
43
53
 
44
- export type GroupingColumn<
45
- _TData,
46
- _TValue,
47
- _TFilterFns,
48
- _TSortingFns,
49
- TAggregationFns
50
- > = {
51
- aggregationType?: AggregationType<TAggregationFns>
54
+ export type GroupingColumn<TGenerics extends PartialGenerics> = {
55
+ aggregationType?: AggregationType<Overwrite<TGenerics, { Value: any }>>
52
56
  getCanGroup: () => boolean
53
57
  getIsGrouped: () => boolean
54
58
  getGroupedIndex: () => number
@@ -77,28 +81,16 @@ export type ColumnDefaultOptions = {
77
81
  enableGrouping: boolean
78
82
  }
79
83
 
80
- export type GroupingOptions<
81
- TData,
82
- TValue,
83
- TFilterFns,
84
- TSortingFns,
85
- TAggregationFns
86
- > = {
87
- aggregationTypes?: TAggregationFns
84
+ export type GroupingOptions<TGenerics extends PartialGenerics> = {
85
+ aggregationTypes?: TGenerics['AggregationFns']
88
86
  onGroupingChange?: OnChangeFn<GroupingState>
89
87
  autoResetGrouping?: boolean
90
88
  enableGrouping?: boolean
91
89
  enableGroupingRemoval?: boolean
92
90
  groupRowsFn?: (
93
- instance: ReactTable<
94
- TData,
95
- TValue,
96
- TFilterFns,
97
- TSortingFns,
98
- TAggregationFns
99
- >,
100
- rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
101
- ) => RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
91
+ instance: TableInstance<TGenerics>,
92
+ rowModel: RowModel<TGenerics>
93
+ ) => RowModel<TGenerics>
102
94
 
103
95
  groupedColumnMode?: false | 'reorder' | 'remove'
104
96
  }
@@ -110,16 +102,14 @@ export type ToggleGroupingProps = {
110
102
  onClick?: (event: MouseEvent | TouchEvent) => void
111
103
  }
112
104
 
113
- export type GroupingInstance<
114
- TData,
115
- TValue,
116
- TFilterFns,
117
- TSortingFns,
118
- TAggregationFns
119
- > = {
105
+ export type GroupingInstance<TGenerics extends PartialGenerics> = {
120
106
  _notifyGroupingReset: () => void
121
- getColumnAutoAggregationFn: (columnId: string) => AggregationFn | undefined
122
- getColumnAggregationFn: (columnId: string) => AggregationFn | undefined
107
+ getColumnAutoAggregationFn: (
108
+ columnId: string
109
+ ) => AggregationFn<TGenerics> | undefined
110
+ getColumnAggregationFn: (
111
+ columnId: string
112
+ ) => AggregationFn<TGenerics> | undefined
123
113
  setGrouping: (updater: Updater<GroupingState>) => void
124
114
  resetGrouping: () => void
125
115
  toggleColumnGrouping: (columnId: string) => void
@@ -131,54 +121,15 @@ export type GroupingInstance<
131
121
  userProps?: TGetter
132
122
  ) => undefined | PropGetterValue<ToggleGroupingProps, TGetter>
133
123
  getRowIsGrouped: (rowId: string) => boolean
134
- getGroupedRowModel: () => RowModel<
135
- TData,
136
- TValue,
137
- TFilterFns,
138
- TSortingFns,
139
- TAggregationFns
140
- >
141
- getPreGroupedRows: () => Row<
142
- TData,
143
- TValue,
144
- TFilterFns,
145
- TSortingFns,
146
- TAggregationFns
147
- >[]
148
- getPreGroupedFlatRows: () => Row<
149
- TData,
150
- TValue,
151
- TFilterFns,
152
- TSortingFns,
153
- TAggregationFns
154
- >[]
155
- getPreGroupedRowsById: () => Record<
156
- string,
157
- Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
158
- >
159
- getGroupedRows: () => Row<
160
- TData,
161
- TValue,
162
- TFilterFns,
163
- TSortingFns,
164
- TAggregationFns
165
- >[]
166
- getGroupedFlatRows: () => Row<
167
- TData,
168
- TValue,
169
- TFilterFns,
170
- TSortingFns,
171
- TAggregationFns
172
- >[]
173
- getGroupedRowsById: () => Record<
174
- string,
175
- Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
176
- >
124
+ getPreGroupedRowModel: () => RowModel<TGenerics>
125
+ getGroupedRowModel: () => RowModel<TGenerics>
177
126
  }
178
127
 
179
128
  //
180
129
 
181
- export function getDefaultColumn<TFilterFns>(): GroupingColumnDef<TFilterFns> {
130
+ export function getDefaultColumn<
131
+ TGenerics extends PartialGenerics
132
+ >(): GroupingColumnDef<TGenerics> {
182
133
  return {
183
134
  aggregationType: 'auto',
184
135
  }
@@ -190,15 +141,9 @@ export function getInitialState(): GroupingTableState {
190
141
  }
191
142
  }
192
143
 
193
- export function getDefaultOptions<
194
- TData,
195
- TValue,
196
- TFilterFns,
197
- TSortingFns,
198
- TAggregationFns
199
- >(
200
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
201
- ): GroupingOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
144
+ export function getDefaultOptions<TGenerics extends PartialGenerics>(
145
+ instance: TableInstance<TGenerics>
146
+ ): GroupingOptions<TGenerics> {
202
147
  return {
203
148
  onGroupingChange: makeStateUpdater('grouping', instance),
204
149
  autoResetGrouping: true,
@@ -206,16 +151,10 @@ export function getDefaultOptions<
206
151
  }
207
152
  }
208
153
 
209
- export function createColumn<
210
- TData,
211
- TValue,
212
- TFilterFns,
213
- TSortingFns,
214
- TAggregationFns
215
- >(
216
- column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
217
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
218
- ): GroupingColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
154
+ export function createColumn<TGenerics extends PartialGenerics>(
155
+ column: Column<TGenerics>,
156
+ instance: TableInstance<TGenerics>
157
+ ): GroupingColumn<TGenerics> {
219
158
  return {
220
159
  aggregationType: column.aggregationType,
221
160
  getCanGroup: () => instance.getColumnCanGroup(column.id),
@@ -227,15 +166,9 @@ export function createColumn<
227
166
  }
228
167
  }
229
168
 
230
- export function getInstance<
231
- TData,
232
- TValue,
233
- TFilterFns,
234
- TSortingFns,
235
- TAggregationFns
236
- >(
237
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
238
- ): GroupingInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
169
+ export function getInstance<TGenerics extends PartialGenerics>(
170
+ instance: TableInstance<TGenerics>
171
+ ): GroupingInstance<TGenerics> {
239
172
  let registered = false
240
173
 
241
174
  return {
@@ -257,7 +190,7 @@ export function getInstance<
257
190
  }
258
191
  },
259
192
  getColumnAutoAggregationFn: columnId => {
260
- const firstRow = instance.getCoreFlatRows()[0]
193
+ const firstRow = instance.getCoreRowModel().flatRows[0]
261
194
 
262
195
  const value = firstRow?.values[columnId]
263
196
 
@@ -288,7 +221,7 @@ export function getInstance<
288
221
  ] ??
289
222
  (aggregationTypes[
290
223
  column.aggregationType as BuiltInAggregationType
291
- ] as AggregationFn)
224
+ ] as AggregationFn<TGenerics>)
292
225
  },
293
226
 
294
227
  setGrouping: updater =>
@@ -337,10 +270,6 @@ export function getInstance<
337
270
  getToggleGroupingProps: (columnId, userProps) => {
338
271
  const column = instance.getColumn(columnId)
339
272
 
340
- if (!column) {
341
- return
342
- }
343
-
344
273
  const canGroup = column.getCanGroup()
345
274
 
346
275
  const initialProps: ToggleGroupingProps = {
@@ -358,6 +287,7 @@ export function getInstance<
358
287
 
359
288
  getRowIsGrouped: rowId => !!instance.getRow(rowId)?.groupingColumnId,
360
289
 
290
+ getPreGroupedRowModel: () => instance.getSortedRowModel(),
361
291
  getGroupedRowModel: memo(
362
292
  () => [
363
293
  instance.getState().grouping,
@@ -369,54 +299,31 @@ export function getInstance<
369
299
  return rowModel
370
300
  }
371
301
 
372
- if (process.env.NODE_ENV !== 'production' && instance.options.debug)
373
- console.info('Grouping...')
374
-
375
302
  return groupRowsFn(instance, rowModel)
376
303
  },
377
304
  {
378
305
  key: 'getGroupedRowModel',
379
- debug: instance.options.debug,
306
+ debug: () => instance.options.debugAll ?? instance.options.debugTable,
380
307
  onChange: () => instance._notifyExpandedReset(),
381
308
  }
382
309
  ),
383
-
384
- getPreGroupedRows: () => instance.getSortedRowModel().rows,
385
- getPreGroupedFlatRows: () => instance.getSortedRowModel().flatRows,
386
- getPreGroupedRowsById: () => instance.getSortedRowModel().rowsById,
387
- getGroupedRows: () => instance.getGroupedRowModel().rows,
388
- getGroupedFlatRows: () => instance.getGroupedRowModel().flatRows,
389
- getGroupedRowsById: () => instance.getGroupedRowModel().rowsById,
390
310
  }
391
311
  }
392
312
 
393
- export function createRow<
394
- TData,
395
- TValue,
396
- TFilterFns,
397
- TSortingFns,
398
- TAggregationFns
399
- >(
400
- row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
401
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
313
+ export function createRow<TGenerics extends PartialGenerics>(
314
+ row: Row<TGenerics>,
315
+ instance: TableInstance<TGenerics>
402
316
  ): GroupingRow {
403
317
  return {
404
318
  getIsGrouped: () => instance.getRowIsGrouped(row.id),
405
319
  }
406
320
  }
407
321
 
408
- export function createCell<
409
- TData,
410
- TValue,
411
- TFilterFns,
412
- TSortingFns,
413
- TAggregationFns
414
- >(
415
- cell: Cell<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
416
- GroupingCell,
417
- column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
418
- row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
419
- _instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
322
+ export function createCell<TGenerics extends PartialGenerics>(
323
+ cell: Cell<TGenerics> & GroupingCell,
324
+ column: Column<TGenerics>,
325
+ row: Row<TGenerics>,
326
+ _instance: TableInstance<TGenerics>
420
327
  ): GroupingCell {
421
328
  return {
422
329
  getIsGrouped: () =>
@@ -429,20 +336,8 @@ export function createCell<
429
336
  }
430
337
  }
431
338
 
432
- export function orderColumns<
433
- TData,
434
- TValue,
435
- TFilterFns,
436
- TSortingFns,
437
- TAggregationFns
438
- >(
439
- leafColumns: Column<
440
- TData,
441
- TValue,
442
- TFilterFns,
443
- TSortingFns,
444
- TAggregationFns
445
- >[],
339
+ export function orderColumns<TGenerics extends PartialGenerics>(
340
+ leafColumns: Column<TGenerics>[],
446
341
  grouping: string[],
447
342
  groupedColumnMode?: GroupingColumnMode
448
343
  ) {