@tanstack/react-table 0.0.1-alpha.8 → 8.0.0-alpha.11

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 (61) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +34 -0
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  3. package/build/cjs/index.js +85 -0
  4. package/build/cjs/index.js.map +1 -0
  5. package/build/esm/index.js +73 -0
  6. package/build/esm/index.js.map +1 -0
  7. package/build/stats-html.html +2689 -0
  8. package/build/stats-react.json +99 -0
  9. package/build/types/index.d.ts +3 -0
  10. package/build/umd/index.development.js +105 -0
  11. package/build/umd/index.development.js.map +1 -0
  12. package/build/umd/index.production.js +12 -0
  13. package/build/umd/index.production.js.map +1 -0
  14. package/package.json +12 -94
  15. package/src/index.tsx +56 -7
  16. package/dist/react-table.development.js +0 -3406
  17. package/dist/react-table.development.js.map +0 -1
  18. package/dist/react-table.production.min.js +0 -2
  19. package/dist/react-table.production.min.js.map +0 -1
  20. package/lib/index.js +0 -65
  21. package/src/aggregationTypes.ts +0 -115
  22. package/src/core.tsx +0 -1194
  23. package/src/createTable.tsx +0 -181
  24. package/src/features/Expanding.ts +0 -388
  25. package/src/features/Filters.ts +0 -707
  26. package/src/features/Grouping.ts +0 -451
  27. package/src/features/Headers.ts +0 -907
  28. package/src/features/Ordering.ts +0 -134
  29. package/src/features/Pinning.ts +0 -213
  30. package/src/features/Sorting.ts +0 -487
  31. package/src/features/Visibility.ts +0 -281
  32. package/src/features/notest/useAbsoluteLayout.test.js +0 -152
  33. package/src/features/notest/useBlockLayout.test.js +0 -158
  34. package/src/features/notest/useColumnOrder.test.js +0 -186
  35. package/src/features/notest/useExpanded.test.js +0 -125
  36. package/src/features/notest/useFilters.test.js +0 -393
  37. package/src/features/notest/useFiltersAndRowSelect.test.js +0 -256
  38. package/src/features/notest/useFlexLayout.test.js +0 -152
  39. package/src/features/notest/useGroupBy.test.js +0 -259
  40. package/src/features/notest/usePagination.test.js +0 -231
  41. package/src/features/notest/useResizeColumns.test.js +0 -229
  42. package/src/features/notest/useRowSelect.test.js +0 -250
  43. package/src/features/notest/useRowState.test.js +0 -178
  44. package/src/features/tests/Visibility.test.tsx +0 -225
  45. package/src/features/tests/__snapshots__/Visibility.test.tsx.snap +0 -390
  46. package/src/features/tests/withSorting.notest.tsx +0 -341
  47. package/src/features/withColumnResizing.ts +0 -281
  48. package/src/features/withPagination.ts +0 -208
  49. package/src/features/withRowSelection.ts +0 -467
  50. package/src/filterTypes.ts +0 -251
  51. package/src/sortTypes.ts +0 -159
  52. package/src/test-utils/makeTestData.ts +0 -41
  53. package/src/tests/__snapshots__/core.test.tsx.snap +0 -148
  54. package/src/tests/core.test.tsx +0 -241
  55. package/src/types.ts +0 -285
  56. package/src/utils/columnFilterRowsFn.ts +0 -162
  57. package/src/utils/expandRowsFn.ts +0 -53
  58. package/src/utils/globalFilterRowsFn.ts +0 -129
  59. package/src/utils/groupRowsFn.ts +0 -196
  60. package/src/utils/sortRowsFn.ts +0 -115
  61. 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
- }