@tanstack/react-table 8.0.0-alpha.5 → 8.0.0-alpha.50

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 (109) 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 +98 -17
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/esm/index.js +38 -4716
  6. package/build/esm/index.js.map +1 -1
  7. package/build/stats-html.html +1 -1
  8. package/build/stats-react.json +29 -779
  9. package/build/types/index.d.ts +10 -8
  10. package/build/umd/index.development.js +50 -4722
  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 +104 -8
  16. package/build/cjs/aggregationTypes.js +0 -130
  17. package/build/cjs/aggregationTypes.js.map +0 -1
  18. package/build/cjs/core.js +0 -552
  19. package/build/cjs/core.js.map +0 -1
  20. package/build/cjs/createTable.js +0 -108
  21. package/build/cjs/createTable.js.map +0 -1
  22. package/build/cjs/features/ColumnSizing.js +0 -317
  23. package/build/cjs/features/ColumnSizing.js.map +0 -1
  24. package/build/cjs/features/Expanding.js +0 -255
  25. package/build/cjs/features/Expanding.js.map +0 -1
  26. package/build/cjs/features/Filters.js +0 -445
  27. package/build/cjs/features/Filters.js.map +0 -1
  28. package/build/cjs/features/Grouping.js +0 -249
  29. package/build/cjs/features/Grouping.js.map +0 -1
  30. package/build/cjs/features/Headers.js +0 -549
  31. package/build/cjs/features/Headers.js.map +0 -1
  32. package/build/cjs/features/Ordering.js +0 -86
  33. package/build/cjs/features/Ordering.js.map +0 -1
  34. package/build/cjs/features/Pagination.js +0 -198
  35. package/build/cjs/features/Pagination.js.map +0 -1
  36. package/build/cjs/features/Pinning.js +0 -149
  37. package/build/cjs/features/Pinning.js.map +0 -1
  38. package/build/cjs/features/RowSelection.js +0 -541
  39. package/build/cjs/features/RowSelection.js.map +0 -1
  40. package/build/cjs/features/Sorting.js +0 -327
  41. package/build/cjs/features/Sorting.js.map +0 -1
  42. package/build/cjs/features/Visibility.js +0 -166
  43. package/build/cjs/features/Visibility.js.map +0 -1
  44. package/build/cjs/filterTypes.js +0 -172
  45. package/build/cjs/filterTypes.js.map +0 -1
  46. package/build/cjs/sortTypes.js +0 -122
  47. package/build/cjs/sortTypes.js.map +0 -1
  48. package/build/cjs/utils/columnFilterRowsFn.js +0 -131
  49. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  50. package/build/cjs/utils/expandRowsFn.js +0 -38
  51. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  52. package/build/cjs/utils/globalFilterRowsFn.js +0 -101
  53. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  54. package/build/cjs/utils/groupRowsFn.js +0 -155
  55. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  56. package/build/cjs/utils/paginateRowsFn.js +0 -44
  57. package/build/cjs/utils/paginateRowsFn.js.map +0 -1
  58. package/build/cjs/utils/sortRowsFn.js +0 -94
  59. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  60. package/build/cjs/utils.js +0 -146
  61. package/build/cjs/utils.js.map +0 -1
  62. package/build/types/aggregationTypes.d.ts +0 -22
  63. package/build/types/core.d.ts +0 -111
  64. package/build/types/createTable.d.ts +0 -52
  65. package/build/types/features/ColumnSizing.d.ts +0 -67
  66. package/build/types/features/Expanding.d.ts +0 -53
  67. package/build/types/features/Filters.d.ts +0 -98
  68. package/build/types/features/Grouping.d.ts +0 -82
  69. package/build/types/features/Headers.d.ts +0 -41
  70. package/build/types/features/Ordering.d.ts +0 -19
  71. package/build/types/features/Pagination.d.ts +0 -44
  72. package/build/types/features/Pinning.d.ts +0 -39
  73. package/build/types/features/RowSelection.d.ts +0 -66
  74. package/build/types/features/Sorting.d.ts +0 -78
  75. package/build/types/features/Visibility.d.ts +0 -47
  76. package/build/types/filterTypes.d.ts +0 -50
  77. package/build/types/sortTypes.d.ts +0 -18
  78. package/build/types/types.d.ts +0 -127
  79. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  80. package/build/types/utils/expandRowsFn.d.ts +0 -2
  81. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  82. package/build/types/utils/groupRowsFn.d.ts +0 -2
  83. package/build/types/utils/paginateRowsFn.d.ts +0 -2
  84. package/build/types/utils/sortRowsFn.d.ts +0 -2
  85. package/build/types/utils.d.ts +0 -28
  86. package/src/aggregationTypes.ts +0 -115
  87. package/src/core.tsx +0 -1181
  88. package/src/createTable.tsx +0 -241
  89. package/src/features/ColumnSizing.ts +0 -453
  90. package/src/features/Expanding.ts +0 -404
  91. package/src/features/Filters.ts +0 -762
  92. package/src/features/Grouping.ts +0 -466
  93. package/src/features/Headers.ts +0 -912
  94. package/src/features/Ordering.ts +0 -133
  95. package/src/features/Pagination.ts +0 -327
  96. package/src/features/Pinning.ts +0 -200
  97. package/src/features/RowSelection.ts +0 -831
  98. package/src/features/Sorting.ts +0 -547
  99. package/src/features/Visibility.ts +0 -279
  100. package/src/filterTypes.ts +0 -251
  101. package/src/sortTypes.ts +0 -159
  102. package/src/types.ts +0 -331
  103. package/src/utils/columnFilterRowsFn.ts +0 -155
  104. package/src/utils/expandRowsFn.ts +0 -50
  105. package/src/utils/globalFilterRowsFn.ts +0 -122
  106. package/src/utils/groupRowsFn.ts +0 -194
  107. package/src/utils/paginateRowsFn.ts +0 -34
  108. package/src/utils/sortRowsFn.ts +0 -115
  109. package/src/utils.tsx +0 -257
@@ -1,404 +0,0 @@
1
- import { MouseEvent, TouchEvent } from 'react'
2
- import { RowModel } from '..'
3
- import {
4
- Getter,
5
- OnChangeFn,
6
- PropGetterValue,
7
- ReactTable,
8
- Row,
9
- Updater,
10
- } from '../types'
11
- import { functionalUpdate, makeStateUpdater, memo, propGetter } from '../utils'
12
-
13
- export type ExpandedStateList = Record<string, boolean>
14
- export type ExpandedState = true | Record<string, boolean>
15
- export type ExpandedTableState = {
16
- expanded: ExpandedState
17
- }
18
-
19
- export type ExpandedRow = {
20
- toggleExpanded: (expanded?: boolean) => void
21
- getIsExpanded: () => boolean
22
- getCanExpand: () => boolean
23
- getToggleExpandedProps: <TGetter extends Getter<ToggleExpandedProps>>(
24
- userProps?: TGetter
25
- ) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
26
- }
27
-
28
- export type ExpandedOptions<
29
- TData,
30
- TValue,
31
- TFilterFns,
32
- TSortingFns,
33
- TAggregationFns
34
- > = {
35
- onExpandedChange?: OnChangeFn<ExpandedState>
36
- autoResetExpanded?: boolean
37
- enableExpanded?: boolean
38
- 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>
48
- expandSubRows?: boolean
49
- 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
56
- paginateExpandedRows?: boolean
57
- }
58
-
59
- export type ToggleExpandedProps = {
60
- title?: string
61
- onClick?: (event: MouseEvent | TouchEvent) => void
62
- }
63
-
64
- export type ExpandedInstance<
65
- TData,
66
- TValue,
67
- TFilterFns,
68
- TSortingFns,
69
- TAggregationFns
70
- > = {
71
- _notifyExpandedReset: () => void
72
- setExpanded: (updater: Updater<ExpandedState>) => void
73
- toggleRowExpanded: (rowId: string, expanded?: boolean) => void
74
- toggleAllRowsExpanded: (expanded?: boolean) => void
75
- resetExpanded: () => void
76
- getRowCanExpand: (rowId: string) => boolean
77
- getIsRowExpanded: (rowId: string) => boolean
78
- getToggleExpandedProps: <TGetter extends Getter<ToggleExpandedProps>>(
79
- rowId: string,
80
- userProps?: TGetter
81
- ) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
82
- getToggleAllRowsExpandedProps: <TGetter extends Getter<ToggleExpandedProps>>(
83
- userProps?: TGetter
84
- ) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
85
- getIsAllRowsExpanded: () => boolean
86
- 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
- >
130
- }
131
-
132
- //
133
-
134
- export function getInitialState(): ExpandedTableState {
135
- return {
136
- expanded: {},
137
- }
138
- }
139
-
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> {
149
- return {
150
- onExpandedChange: makeStateUpdater('expanded', instance),
151
- autoResetExpanded: true,
152
- getIsRowExpanded: row => !!(row?.original as { expanded?: any }).expanded,
153
- expandSubRows: true,
154
- paginateExpandedRows: true,
155
- }
156
- }
157
-
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> {
167
- let registered = false
168
-
169
- return {
170
- _notifyExpandedReset: () => {
171
- if (!registered) {
172
- registered = true
173
- return
174
- }
175
-
176
- if (instance.options.autoResetAll === false) {
177
- return
178
- }
179
-
180
- if (
181
- instance.options.autoResetAll === true ||
182
- instance.options.autoResetExpanded
183
- ) {
184
- instance.resetExpanded()
185
- }
186
- },
187
- setExpanded: updater =>
188
- instance.options.onExpandedChange?.(
189
- updater,
190
- functionalUpdate(updater, instance.getState().expanded)
191
- ),
192
- toggleRowExpanded: (rowId, expanded) => {
193
- if (!rowId) return
194
-
195
- instance.setExpanded((old = {}) => {
196
- const exists = old === true ? true : !!old?.[rowId]
197
-
198
- let oldExpanded: ExpandedStateList = {}
199
-
200
- if (old === true) {
201
- Object.keys(instance.getRowsById()).forEach(rowId => {
202
- oldExpanded[rowId] = true
203
- })
204
- } else {
205
- oldExpanded = old
206
- }
207
-
208
- expanded = expanded ?? !exists
209
-
210
- if (!exists && expanded) {
211
- return {
212
- ...oldExpanded,
213
- [rowId]: true,
214
- }
215
- }
216
-
217
- if (exists && !expanded) {
218
- const { [rowId]: _, ...rest } = oldExpanded
219
- return rest
220
- }
221
-
222
- return old
223
- })
224
- },
225
- toggleAllRowsExpanded: expanded => {
226
- if (expanded ?? !instance.getIsAllRowsExpanded()) {
227
- instance.setExpanded(true)
228
- } else {
229
- instance.setExpanded({})
230
- }
231
- },
232
- resetExpanded: () => {
233
- instance.setExpanded(instance.options?.initialState?.expanded ?? {})
234
- },
235
- getIsRowExpanded: rowId => {
236
- const row = instance.getRow(rowId)
237
-
238
- if (!row) {
239
- if (process.env.NODE_ENV !== 'production') {
240
- console.warn(
241
- `[ReactTable] getIsRowExpanded: no row found with id ${rowId}`
242
- )
243
- }
244
- throw new Error()
245
- }
246
-
247
- const expanded = instance.getState().expanded
248
-
249
- return !!(
250
- instance.options.getIsRowExpanded?.(row) ??
251
- (expanded || expanded?.[rowId])
252
- )
253
- },
254
- getRowCanExpand: rowId => {
255
- const row = instance.getRow(rowId)
256
-
257
- if (!row) {
258
- if (process.env.NODE_ENV !== 'production') {
259
- console.warn(
260
- `[ReactTable] getRowCanExpand: no row found with id ${rowId}`
261
- )
262
- }
263
- throw new Error()
264
- }
265
-
266
- return (
267
- instance.options.getRowCanExpand?.(row) ??
268
- instance.options.enableExpanded ??
269
- instance.options.defaultCanExpand ??
270
- !!row.subRows?.length
271
- )
272
- },
273
- getToggleExpandedProps: (rowId, userProps) => {
274
- const row = instance.getRow(rowId)
275
-
276
- if (!row) {
277
- return
278
- }
279
-
280
- const canExpand = instance.getRowCanExpand(rowId)
281
-
282
- const initialProps: ToggleExpandedProps = {
283
- title: canExpand ? 'Toggle Expanded' : undefined,
284
- onClick: canExpand
285
- ? (e: MouseEvent | TouchEvent) => {
286
- e.persist()
287
- instance.toggleRowExpanded(rowId)
288
- }
289
- : undefined,
290
- }
291
-
292
- return propGetter(initialProps, userProps)
293
- },
294
- getToggleAllRowsExpandedProps: userProps => {
295
- const initialProps: ToggleExpandedProps = {
296
- title: 'Toggle All Expanded',
297
- onClick: (e: MouseEvent | TouchEvent) => {
298
- e.persist()
299
- instance.toggleAllRowsExpanded()
300
- },
301
- }
302
-
303
- return propGetter(initialProps, userProps)
304
- },
305
- getIsAllRowsExpanded: () => {
306
- const expanded = instance.getState().expanded
307
-
308
- // If expanded is true, save some cycles and return true
309
- if (expanded === true) {
310
- return true
311
- }
312
-
313
- // If any row is not expanded, return false
314
- if (
315
- Object.keys(instance.getRowsById()).some(
316
- id => !instance.getIsRowExpanded(id)
317
- )
318
- ) {
319
- return false
320
- }
321
-
322
- // They must all be expanded :shrug:
323
- return true
324
- },
325
- getExpandedDepth: () => {
326
- let maxDepth = 0
327
-
328
- const rowIds =
329
- instance.getState().expanded === true
330
- ? Object.keys(instance.getRowsById())
331
- : Object.keys(instance.getState().expanded)
332
-
333
- rowIds.forEach(id => {
334
- const splitId = id.split('.')
335
- maxDepth = Math.max(maxDepth, splitId.length)
336
- })
337
-
338
- return maxDepth
339
- },
340
- getExpandedRowModel: memo(
341
- () => [
342
- instance.getState().expanded,
343
- instance.getGroupedRowModel(),
344
- instance.options.expandRowsFn,
345
- instance.options.paginateExpandedRows,
346
- ],
347
- (expanded, rowModel, expandRowsFn, paginateExpandedRows) => {
348
- if (
349
- !expandRowsFn ||
350
- // Do not expand if rows are not included in pagination
351
- !paginateExpandedRows ||
352
- !Object.keys(expanded ?? {}).length
353
- ) {
354
- return rowModel
355
- }
356
-
357
- if (process.env.NODE_ENV !== 'production' && instance.options.debug)
358
- console.info('Expanding...')
359
-
360
- return expandRowsFn(instance, rowModel)
361
- },
362
- {
363
- key: 'getExpandedRowModel',
364
- debug: instance.options.debug,
365
- onChange: () => instance._notifyPageIndexReset(),
366
- }
367
- ),
368
-
369
- getPreExpandedRows: () => instance.getGroupedRowModel().rows,
370
- getPreExpandedFlatRows: () => instance.getGroupedRowModel().flatRows,
371
- getPreExpandedRowsById: () => instance.getGroupedRowModel().rowsById,
372
- getExpandedRows: () => instance.getExpandedRowModel().rows,
373
- getExpandedFlatRows: () => instance.getExpandedRowModel().flatRows,
374
- getExpandedRowsById: () => instance.getExpandedRowModel().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
- ): ExpandedRow {
388
- return {
389
- toggleExpanded: expanded =>
390
- void instance.toggleRowExpanded(row.id, expanded),
391
- getIsExpanded: () => instance.getIsRowExpanded(row.id),
392
- getCanExpand: () => row.subRows && !!row.subRows.length,
393
- getToggleExpandedProps: userProps => {
394
- const initialProps: ToggleExpandedProps = {
395
- title: 'Toggle Row Expanded',
396
- onClick: (e: MouseEvent | TouchEvent) => {
397
- e.stopPropagation()
398
- instance.toggleRowExpanded(row.id)
399
- },
400
- }
401
- return propGetter(initialProps, userProps)
402
- },
403
- }
404
- }