@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
@@ -3,8 +3,9 @@ import { RowModel } from '..'
3
3
  import {
4
4
  Getter,
5
5
  OnChangeFn,
6
+ PartialGenerics,
6
7
  PropGetterValue,
7
- ReactTable,
8
+ TableInstance,
8
9
  Row,
9
10
  Updater,
10
11
  } from '../types'
@@ -25,34 +26,18 @@ export type ExpandedRow = {
25
26
  ) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
26
27
  }
27
28
 
28
- export type ExpandedOptions<
29
- TData,
30
- TValue,
31
- TFilterFns,
32
- TSortingFns,
33
- TAggregationFns
34
- > = {
29
+ export type ExpandedOptions<TGenerics extends PartialGenerics> = {
35
30
  onExpandedChange?: OnChangeFn<ExpandedState>
36
31
  autoResetExpanded?: boolean
37
32
  enableExpanded?: boolean
38
33
  expandRowsFn?: (
39
- instance: ReactTable<
40
- TData,
41
- TValue,
42
- TFilterFns,
43
- TSortingFns,
44
- TAggregationFns
45
- >,
46
- rowModel: RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
47
- ) => RowModel<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
34
+ instance: TableInstance<TGenerics>,
35
+ rowModel: RowModel<TGenerics>
36
+ ) => RowModel<TGenerics>
48
37
  expandSubRows?: boolean
49
38
  defaultCanExpand?: boolean
50
- getIsRowExpanded?: (
51
- row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
52
- ) => boolean
53
- getRowCanExpand?: (
54
- row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
55
- ) => boolean
39
+ getIsRowExpanded?: (row: Row<TGenerics>) => boolean
40
+ getRowCanExpand?: (row: Row<TGenerics>) => boolean
56
41
  paginateExpandedRows?: boolean
57
42
  }
58
43
 
@@ -61,13 +46,7 @@ export type ToggleExpandedProps = {
61
46
  onClick?: (event: MouseEvent | TouchEvent) => void
62
47
  }
63
48
 
64
- export type ExpandedInstance<
65
- TData,
66
- TValue,
67
- TFilterFns,
68
- TSortingFns,
69
- TAggregationFns
70
- > = {
49
+ export type ExpandedInstance<TGenerics extends PartialGenerics> = {
71
50
  _notifyExpandedReset: () => void
72
51
  setExpanded: (updater: Updater<ExpandedState>) => void
73
52
  toggleRowExpanded: (rowId: string, expanded?: boolean) => void
@@ -84,49 +63,8 @@ export type ExpandedInstance<
84
63
  ) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
85
64
  getIsAllRowsExpanded: () => boolean
86
65
  getExpandedDepth: () => number
87
- getExpandedRowModel: () => RowModel<
88
- TData,
89
- TValue,
90
- TFilterFns,
91
- TSortingFns,
92
- TAggregationFns
93
- >
94
- getPreExpandedRows: () => Row<
95
- TData,
96
- TValue,
97
- TFilterFns,
98
- TSortingFns,
99
- TAggregationFns
100
- >[]
101
- getPreExpandedFlatRows: () => Row<
102
- TData,
103
- TValue,
104
- TFilterFns,
105
- TSortingFns,
106
- TAggregationFns
107
- >[]
108
- getPreExpandedRowsById: () => Record<
109
- string,
110
- Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
111
- >
112
- getExpandedRows: () => Row<
113
- TData,
114
- TValue,
115
- TFilterFns,
116
- TSortingFns,
117
- TAggregationFns
118
- >[]
119
- getExpandedFlatRows: () => Row<
120
- TData,
121
- TValue,
122
- TFilterFns,
123
- TSortingFns,
124
- TAggregationFns
125
- >[]
126
- getExpandedRowsById: () => Record<
127
- string,
128
- Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
129
- >
66
+ getExpandedRowModel: () => RowModel<TGenerics>
67
+ getPreExpandedRowModel: () => RowModel<TGenerics>
130
68
  }
131
69
 
132
70
  //
@@ -137,15 +75,9 @@ export function getInitialState(): ExpandedTableState {
137
75
  }
138
76
  }
139
77
 
140
- export function getDefaultOptions<
141
- TData,
142
- TValue,
143
- TFilterFns,
144
- TSortingFns,
145
- TAggregationFns
146
- >(
147
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
148
- ): ExpandedOptions<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
78
+ export function getDefaultOptions<TGenerics extends PartialGenerics>(
79
+ instance: TableInstance<TGenerics>
80
+ ): ExpandedOptions<TGenerics> {
149
81
  return {
150
82
  onExpandedChange: makeStateUpdater('expanded', instance),
151
83
  autoResetExpanded: true,
@@ -155,15 +87,9 @@ export function getDefaultOptions<
155
87
  }
156
88
  }
157
89
 
158
- export function getInstance<
159
- TData,
160
- TValue,
161
- TFilterFns,
162
- TSortingFns,
163
- TAggregationFns
164
- >(
165
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
166
- ): ExpandedInstance<TData, TValue, TFilterFns, TSortingFns, TAggregationFns> {
90
+ export function getInstance<TGenerics extends PartialGenerics>(
91
+ instance: TableInstance<TGenerics>
92
+ ): ExpandedInstance<TGenerics> {
167
93
  let registered = false
168
94
 
169
95
  return {
@@ -198,7 +124,7 @@ export function getInstance<
198
124
  let oldExpanded: ExpandedStateList = {}
199
125
 
200
126
  if (old === true) {
201
- Object.keys(instance.getRowsById()).forEach(rowId => {
127
+ Object.keys(instance.getRowModel().rowsById).forEach(rowId => {
202
128
  oldExpanded[rowId] = true
203
129
  })
204
130
  } else {
@@ -312,7 +238,7 @@ export function getInstance<
312
238
 
313
239
  // If any row is not expanded, return false
314
240
  if (
315
- Object.keys(instance.getRowsById()).some(
241
+ Object.keys(instance.getRowModel().rowsById).some(
316
242
  id => !instance.getIsRowExpanded(id)
317
243
  )
318
244
  ) {
@@ -327,7 +253,7 @@ export function getInstance<
327
253
 
328
254
  const rowIds =
329
255
  instance.getState().expanded === true
330
- ? Object.keys(instance.getRowsById())
256
+ ? Object.keys(instance.getRowModel().rowsById)
331
257
  : Object.keys(instance.getState().expanded)
332
258
 
333
259
  rowIds.forEach(id => {
@@ -354,38 +280,24 @@ export function getInstance<
354
280
  return rowModel
355
281
  }
356
282
 
357
- if (process.env.NODE_ENV !== 'production' && instance.options.debug)
358
- console.info('Expanding...')
359
-
360
283
  return expandRowsFn(instance, rowModel)
361
284
  },
362
285
  {
363
286
  key: 'getExpandedRowModel',
364
- debug: instance.options.debug,
287
+ debug: () => instance.options.debugAll ?? instance.options.debugTable,
365
288
  onChange: () => {
366
289
  instance._notifyPageIndexReset()
367
290
  },
368
291
  }
369
292
  ),
370
293
 
371
- getPreExpandedRows: () => instance.getGroupedRowModel().rows,
372
- getPreExpandedFlatRows: () => instance.getGroupedRowModel().flatRows,
373
- getPreExpandedRowsById: () => instance.getGroupedRowModel().rowsById,
374
- getExpandedRows: () => instance.getExpandedRowModel().rows,
375
- getExpandedFlatRows: () => instance.getExpandedRowModel().flatRows,
376
- getExpandedRowsById: () => instance.getExpandedRowModel().rowsById,
294
+ getPreExpandedRowModel: () => instance.getGroupedRowModel(),
377
295
  }
378
296
  }
379
297
 
380
- export function createRow<
381
- TData,
382
- TValue,
383
- TFilterFns,
384
- TSortingFns,
385
- TAggregationFns
386
- >(
387
- row: Row<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>,
388
- instance: ReactTable<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
298
+ export function createRow<TGenerics extends PartialGenerics>(
299
+ row: Row<TGenerics>,
300
+ instance: TableInstance<TGenerics>
389
301
  ): ExpandedRow {
390
302
  return {
391
303
  toggleExpanded: expanded =>