@tanstack/react-table 8.0.0-alpha.1 → 8.0.0-alpha.16

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/_virtual/_rollupPluginBabelHelpers.js +0 -78
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  3. package/build/cjs/index.js +96 -12
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/esm/index.js +40 -3330
  6. package/build/esm/index.js.map +1 -1
  7. package/build/stats-html.html +1 -1
  8. package/build/stats-react.json +28 -632
  9. package/build/types/index.d.ts +13 -7
  10. package/build/umd/index.development.js +50 -3332
  11. package/build/umd/index.development.js.map +1 -1
  12. package/build/umd/index.production.js +1 -1
  13. package/build/umd/index.production.js.map +1 -1
  14. package/package.json +4 -1
  15. package/src/index.tsx +105 -7
  16. package/build/cjs/aggregationTypes.js +0 -130
  17. package/build/cjs/aggregationTypes.js.map +0 -1
  18. package/build/cjs/core.js +0 -493
  19. package/build/cjs/core.js.map +0 -1
  20. package/build/cjs/createTable.js +0 -103
  21. package/build/cjs/createTable.js.map +0 -1
  22. package/build/cjs/features/Expanding.js +0 -234
  23. package/build/cjs/features/Expanding.js.map +0 -1
  24. package/build/cjs/features/Filters.js +0 -396
  25. package/build/cjs/features/Filters.js.map +0 -1
  26. package/build/cjs/features/Grouping.js +0 -228
  27. package/build/cjs/features/Grouping.js.map +0 -1
  28. package/build/cjs/features/Headers.js +0 -483
  29. package/build/cjs/features/Headers.js.map +0 -1
  30. package/build/cjs/features/Ordering.js +0 -83
  31. package/build/cjs/features/Ordering.js.map +0 -1
  32. package/build/cjs/features/Pinning.js +0 -163
  33. package/build/cjs/features/Pinning.js.map +0 -1
  34. package/build/cjs/features/Sorting.js +0 -269
  35. package/build/cjs/features/Sorting.js.map +0 -1
  36. package/build/cjs/features/Visibility.js +0 -160
  37. package/build/cjs/features/Visibility.js.map +0 -1
  38. package/build/cjs/filterTypes.js +0 -172
  39. package/build/cjs/filterTypes.js.map +0 -1
  40. package/build/cjs/sortTypes.js +0 -121
  41. package/build/cjs/sortTypes.js.map +0 -1
  42. package/build/cjs/utils/columnFilterRowsFn.js +0 -130
  43. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  44. package/build/cjs/utils/expandRowsFn.js +0 -38
  45. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  46. package/build/cjs/utils/globalFilterRowsFn.js +0 -100
  47. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  48. package/build/cjs/utils/groupRowsFn.js +0 -154
  49. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  50. package/build/cjs/utils/sortRowsFn.js +0 -93
  51. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  52. package/build/cjs/utils.js +0 -143
  53. package/build/cjs/utils.js.map +0 -1
  54. package/build/types/aggregationTypes.d.ts +0 -22
  55. package/build/types/core.d.ts +0 -122
  56. package/build/types/createTable.d.ts +0 -35
  57. package/build/types/features/Expanding.d.ts +0 -52
  58. package/build/types/features/Filters.d.ts +0 -93
  59. package/build/types/features/Grouping.d.ts +0 -82
  60. package/build/types/features/Headers.d.ts +0 -41
  61. package/build/types/features/Ordering.d.ts +0 -19
  62. package/build/types/features/Pinning.d.ts +0 -39
  63. package/build/types/features/Sorting.d.ts +0 -75
  64. package/build/types/features/Visibility.d.ts +0 -47
  65. package/build/types/filterTypes.d.ts +0 -50
  66. package/build/types/sortTypes.d.ts +0 -17
  67. package/build/types/types.d.ts +0 -122
  68. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  69. package/build/types/utils/expandRowsFn.d.ts +0 -2
  70. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  71. package/build/types/utils/groupRowsFn.d.ts +0 -2
  72. package/build/types/utils/sortRowsFn.d.ts +0 -2
  73. package/build/types/utils.d.ts +0 -24
  74. package/src/aggregationTypes.ts +0 -115
  75. package/src/core.tsx +0 -1194
  76. package/src/createTable.tsx +0 -181
  77. package/src/features/Expanding.ts +0 -388
  78. package/src/features/Filters.ts +0 -707
  79. package/src/features/Grouping.ts +0 -451
  80. package/src/features/Headers.ts +0 -907
  81. package/src/features/Ordering.ts +0 -134
  82. package/src/features/Pinning.ts +0 -213
  83. package/src/features/Sorting.ts +0 -487
  84. package/src/features/Visibility.ts +0 -281
  85. package/src/features/withColumnResizing.oldts +0 -281
  86. package/src/features/withPagination.oldts +0 -208
  87. package/src/features/withRowSelection.oldts +0 -467
  88. package/src/filterTypes.ts +0 -251
  89. package/src/sortTypes.ts +0 -159
  90. package/src/types.ts +0 -285
  91. package/src/utils/columnFilterRowsFn.ts +0 -162
  92. package/src/utils/expandRowsFn.ts +0 -53
  93. package/src/utils/globalFilterRowsFn.ts +0 -129
  94. package/src/utils/groupRowsFn.ts +0 -196
  95. package/src/utils/sortRowsFn.ts +0 -115
  96. package/src/utils.tsx +0 -243
@@ -1,451 +0,0 @@
1
- import React, { MouseEvent, TouchEvent } from 'react'
2
- import { RowModel } from '..'
3
- import { BuiltInAggregationType, aggregationTypes } from '../aggregationTypes'
4
- import {
5
- Cell,
6
- Column,
7
- Getter,
8
- OnChangeFn,
9
- PropGetterValue,
10
- ReactTable,
11
- Row,
12
- Updater,
13
- } from '../types'
14
- import {
15
- functionalUpdate,
16
- isFunction,
17
- makeStateUpdater,
18
- memo,
19
- propGetter,
20
- } from '../utils'
21
-
22
- export type GroupingState = string[]
23
-
24
- export type AggregationFn = (leafValues: any[], childValues: any[]) => any
25
-
26
- export type AggregationType<TAggregationFns> =
27
- | 'auto'
28
- | BuiltInAggregationType
29
- | keyof TAggregationFns
30
- | AggregationFn
31
-
32
- export type GroupingTableState = {
33
- grouping: GroupingState
34
- }
35
-
36
- export type GroupingColumnDef<TAggregationFns> = {
37
- aggregationType?: AggregationType<TAggregationFns>
38
- aggregateValue?: (columnValue: unknown) => any
39
- renderAggregatedCell?: () => React.ReactNode
40
- enableGrouping?: boolean
41
- defaultCanGroup?: boolean
42
- getCanGroup?: unknown
43
- }
44
-
45
- export type GroupingColumn<
46
- _TData,
47
- _TValue,
48
- _TFilterFns,
49
- _TSortingFns,
50
- TAggregationFns
51
- > = {
52
- aggregationType?: AggregationType<TAggregationFns>
53
- getCanGroup: () => boolean
54
- getIsGrouped: () => boolean
55
- getGroupedIndex: () => number
56
- toggleGrouping: () => void
57
- getToggleGroupingProps: <TGetter extends Getter<ToggleGroupingProps>>(
58
- userProps?: TGetter
59
- ) => undefined | PropGetterValue<ToggleGroupingProps, TGetter>
60
- }
61
-
62
- export type GroupingRow = {
63
- groupingColumnId?: string
64
- groupingValue?: any
65
- getIsGrouped: () => boolean
66
- }
67
-
68
- export type GroupingCell = {
69
- getIsGrouped: () => boolean
70
- getIsPlaceholder: () => boolean
71
- getIsAggregated: () => boolean
72
- }
73
-
74
- export type ColumnDefaultOptions = {
75
- // Column
76
- onGroupingChange: OnChangeFn<GroupingState>
77
- autoResetGrouping: boolean
78
- enableGrouping: boolean
79
- }
80
-
81
- export type GroupingOptions<
82
- TData,
83
- TValue,
84
- TFilterFns,
85
- TSortingFns,
86
- TAggregationFns
87
- > = {
88
- aggregationTypes?: TAggregationFns
89
- onGroupingChange?: OnChangeFn<GroupingState>
90
- autoResetGrouping?: boolean
91
- enableGrouping?: boolean
92
- enableGroupingRemoval?: boolean
93
- groupRowsFn?: (
94
- instance: ReactTable<
95
- TData,
96
- TValue,
97
- TFilterFns,
98
- TSortingFns,
99
- TAggregationFns
100
- >,
101
- groupingState: GroupingState,
102
- sortedRowsModel: RowModel<
103
- TData,
104
- TValue,
105
- TFilterFns,
106
- TSortingFns,
107
- TAggregationFns
108
- >
109
- ) => RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
110
-
111
- groupedColumnMode?: false | 'reorder' | 'remove'
112
- }
113
-
114
- export type GroupingColumnMode = false | 'reorder' | 'remove'
115
-
116
- export type ToggleGroupingProps = {
117
- title?: string
118
- onClick?: (event: MouseEvent | TouchEvent) => void
119
- }
120
-
121
- export type GroupingInstance<
122
- TData,
123
- TValue,
124
- TFilterFns,
125
- TSortingFns,
126
- TAggregationFns
127
- > = {
128
- getColumnAutoAggregationFn: (columnId: string) => AggregationFn | undefined
129
- getColumnAggregationFn: (columnId: string) => AggregationFn | undefined
130
- setGrouping: (updater: Updater<GroupingState>) => void
131
- resetGrouping: () => void
132
- toggleColumnGrouping: (columnId: string) => void
133
- getColumnCanGroup: (columnId: string) => boolean
134
- getColumnIsGrouped: (columnId: string) => boolean
135
- getColumnGroupedIndex: (columnId: string) => number
136
- getToggleGroupingProps: <TGetter extends Getter<ToggleGroupingProps>>(
137
- columnId: string,
138
- userProps?: TGetter
139
- ) => undefined | PropGetterValue<ToggleGroupingProps, TGetter>
140
- getRowIsGrouped: (rowId: string) => boolean
141
- getGroupedRowModel: () => RowModel<
142
- TData,
143
- TValue,
144
- TFilterFns,
145
- TSortingFns,
146
- TAggregationFns
147
- >
148
- getPreGroupedRows: () => Row<
149
- TData,
150
- TValue,
151
- TFilterFns,
152
- TSortingFns,
153
- TAggregationFns
154
- >[]
155
- getPreGroupedFlatRows: () => Row<
156
- TData,
157
- TValue,
158
- TFilterFns,
159
- TSortingFns,
160
- TAggregationFns
161
- >[]
162
- getPreGroupedRowsById: () => Record<
163
- string,
164
- Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
165
- >
166
- getGroupedRows: () => Row<
167
- TData,
168
- TValue,
169
- TFilterFns,
170
- TSortingFns,
171
- TAggregationFns
172
- >[]
173
- getGroupedFlatRows: () => Row<
174
- TData,
175
- TValue,
176
- TFilterFns,
177
- TSortingFns,
178
- TAggregationFns
179
- >[]
180
- getGroupedRowsById: () => Record<
181
- string,
182
- Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
183
- >
184
- }
185
-
186
- //
187
-
188
- export function getDefaultColumn<TFilterFns>(): GroupingColumnDef<TFilterFns> {
189
- return {
190
- aggregationType: 'auto',
191
- }
192
- }
193
-
194
- export function getInitialState(): GroupingTableState {
195
- return {
196
- grouping: [],
197
- }
198
- }
199
-
200
- export function getDefaultOptions<
201
- TData,
202
- TValue,
203
- TFilterFns,
204
- TSortingFns,
205
- TAggregationFns
206
- >(
207
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
208
- ): GroupingOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
209
- return {
210
- onGroupingChange: makeStateUpdater('grouping', instance),
211
- autoResetGrouping: true,
212
- groupedColumnMode: 'reorder',
213
- }
214
- }
215
-
216
- export function createColumn<
217
- TData,
218
- TValue,
219
- TFilterFns,
220
- TSortingFns,
221
- TAggregationFns
222
- >(
223
- column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
224
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
225
- ): GroupingColumn<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
226
- return {
227
- aggregationType: column.aggregationType,
228
- getCanGroup: () => instance.getColumnCanGroup(column.id),
229
- getGroupedIndex: () => instance.getColumnGroupedIndex(column.id),
230
- getIsGrouped: () => instance.getColumnIsGrouped(column.id),
231
- toggleGrouping: () => instance.toggleColumnGrouping(column.id),
232
- getToggleGroupingProps: userProps =>
233
- instance.getToggleGroupingProps(column.id, userProps),
234
- }
235
- }
236
-
237
- export function getInstance<
238
- TData,
239
- TValue,
240
- TFilterFns,
241
- TSortingFns,
242
- TAggregationFns
243
- >(
244
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
245
- ): GroupingInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
246
- return {
247
- getColumnAutoAggregationFn: columnId => {
248
- const firstRow = instance.getCoreFlatRows()[0]
249
-
250
- const value = firstRow?.values[columnId]
251
-
252
- if (typeof value === 'number') {
253
- return aggregationTypes.sum
254
- }
255
-
256
- if (Object.prototype.toString.call(value) === '[object Date]') {
257
- return aggregationTypes.extent
258
- }
259
-
260
- return aggregationTypes.count
261
- },
262
- getColumnAggregationFn: columnId => {
263
- const column = instance.getColumn(columnId)
264
- const userAggregationTypes = instance.options.aggregationTypes
265
-
266
- if (!column) {
267
- throw new Error()
268
- }
269
-
270
- return isFunction(column.aggregationType)
271
- ? column.aggregationType
272
- : column.aggregationType === 'auto'
273
- ? instance.getColumnAutoFilterFn(columnId)
274
- : (userAggregationTypes as Record<string, any>)?.[
275
- column.aggregationType as string
276
- ] ??
277
- (aggregationTypes[
278
- column.aggregationType as BuiltInAggregationType
279
- ] as AggregationFn)
280
- },
281
-
282
- setGrouping: updater =>
283
- instance.options.onGroupingChange?.(
284
- updater,
285
- functionalUpdate(updater, instance.getState().grouping)
286
- ),
287
-
288
- toggleColumnGrouping: columnId => {
289
- instance.setGrouping(old => {
290
- // Find any existing grouping for this column
291
- if (old?.includes(columnId)) {
292
- return old.filter(d => d !== columnId)
293
- }
294
-
295
- return [...(old ?? []), columnId]
296
- })
297
- },
298
-
299
- getColumnCanGroup: columnId => {
300
- const column = instance.getColumn(columnId)
301
-
302
- if (!column) {
303
- throw new Error()
304
- }
305
-
306
- return (
307
- column.enableGrouping ??
308
- instance.options.enableGrouping ??
309
- column.defaultCanGroup ??
310
- !!column.accessorFn
311
- )
312
- },
313
-
314
- getColumnIsGrouped: columnId => {
315
- return instance.getState().grouping?.includes(columnId)
316
- },
317
-
318
- getColumnGroupedIndex: columnId =>
319
- instance.getState().grouping?.indexOf(columnId),
320
-
321
- resetGrouping: () => {
322
- instance.setGrouping(instance.options?.initialState?.grouping ?? [])
323
- },
324
-
325
- getToggleGroupingProps: (columnId, userProps) => {
326
- const column = instance.getColumn(columnId)
327
-
328
- if (!column) {
329
- return
330
- }
331
-
332
- const canGroup = column.getCanGroup()
333
-
334
- const initialProps: ToggleGroupingProps = {
335
- title: canGroup ? 'Toggle Grouping' : undefined,
336
- onClick: canGroup
337
- ? (e: MouseEvent | TouchEvent) => {
338
- e.persist()
339
- column.toggleGrouping?.()
340
- }
341
- : undefined,
342
- }
343
-
344
- return propGetter(initialProps, userProps)
345
- },
346
-
347
- getRowIsGrouped: rowId => !!instance.getRow(rowId)?.groupingColumnId,
348
-
349
- getGroupedRowModel: memo(
350
- () => [
351
- instance.getState().grouping,
352
- instance.getSortedRowModel(),
353
- instance.options.groupRowsFn,
354
- ],
355
- (grouping, rowModel, groupRowsFn) => {
356
- if (!groupRowsFn || !grouping.length) {
357
- return rowModel
358
- }
359
-
360
- if (process.env.NODE_ENV !== 'production' && instance.options.debug)
361
- console.info('Grouping...')
362
-
363
- return groupRowsFn(instance, grouping, rowModel)
364
- },
365
- 'getGroupedRowModel',
366
- instance.options.debug
367
- ),
368
-
369
- getPreGroupedRows: () => instance.getSortedRowModel().rows,
370
- getPreGroupedFlatRows: () => instance.getSortedRowModel().flatRows,
371
- getPreGroupedRowsById: () => instance.getSortedRowModel().rowsById,
372
- getGroupedRows: () => instance.getGroupedRowModel().rows,
373
- getGroupedFlatRows: () => instance.getGroupedRowModel().flatRows,
374
- getGroupedRowsById: () => instance.getGroupedRowModel().rowsById,
375
- }
376
- }
377
-
378
- export function createRow<
379
- TData,
380
- TValue,
381
- TFilterFns,
382
- TSortingFns,
383
- TAggregationFns
384
- >(
385
- row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
386
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
387
- ): GroupingRow {
388
- return {
389
- getIsGrouped: () => instance.getRowIsGrouped(row.id),
390
- }
391
- }
392
-
393
- export function createCell<
394
- TData,
395
- TValue,
396
- TFilterFns,
397
- TSortingFns,
398
- TAggregationFns
399
- >(
400
- cell: Cell<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> &
401
- GroupingCell,
402
- column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
403
- row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
404
- _instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
405
- ): GroupingCell {
406
- return {
407
- getIsGrouped: () =>
408
- column.getIsGrouped() && column.id === row.groupingColumnId,
409
- getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
410
- getIsAggregated: () =>
411
- !cell.getIsGrouped() &&
412
- !cell.getIsPlaceholder() &&
413
- row.subRows?.length > 1,
414
- }
415
- }
416
-
417
- export function orderColumns<
418
- TData,
419
- TValue,
420
- TFilterFns,
421
- TSortingFns,
422
- TAggregationFns
423
- >(
424
- leafColumns: Column<
425
- TData,
426
- TValue,
427
- TFilterFns,
428
- TSortingFns,
429
- TAggregationFns
430
- >[],
431
- grouping: string[],
432
- groupedColumnMode?: GroupingColumnMode
433
- ) {
434
- if (!grouping?.length || !groupedColumnMode) {
435
- return leafColumns
436
- }
437
-
438
- const nonGroupingColumns = leafColumns.filter(
439
- col => !grouping.includes(col.id)
440
- )
441
-
442
- if (groupedColumnMode === 'remove') {
443
- return nonGroupingColumns
444
- }
445
-
446
- const groupingColumns = grouping
447
- .map(g => leafColumns.find(col => col.id === g)!)
448
- .filter(Boolean)
449
-
450
- return [...groupingColumns, ...nonGroupingColumns]
451
- }