@tanstack/react-table 8.0.0-alpha.9 → 8.0.0-beta.0
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.
- package/build/cjs/react-table/src/index.js +139 -0
- package/build/cjs/react-table/src/index.js.map +1 -0
- package/build/cjs/table-core/build/esm/index.js +3867 -0
- package/build/cjs/table-core/build/esm/index.js.map +1 -0
- package/build/esm/index.js +3196 -4117
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +24 -813
- package/build/types/index.d.ts +16 -9
- package/build/umd/index.development.js +3234 -4125
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +11 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +10 -6
- package/src/index.tsx +111 -9
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/aggregationTypes.js +0 -130
- package/build/cjs/aggregationTypes.js.map +0 -1
- package/build/cjs/core.js +0 -545
- package/build/cjs/core.js.map +0 -1
- package/build/cjs/createTable.js +0 -122
- package/build/cjs/createTable.js.map +0 -1
- package/build/cjs/features/ColumnSizing.js +0 -318
- package/build/cjs/features/ColumnSizing.js.map +0 -1
- package/build/cjs/features/Expanding.js +0 -239
- package/build/cjs/features/Expanding.js.map +0 -1
- package/build/cjs/features/Filters.js +0 -414
- package/build/cjs/features/Filters.js.map +0 -1
- package/build/cjs/features/Grouping.js +0 -232
- package/build/cjs/features/Grouping.js.map +0 -1
- package/build/cjs/features/Headers.js +0 -629
- package/build/cjs/features/Headers.js.map +0 -1
- package/build/cjs/features/Ordering.js +0 -86
- package/build/cjs/features/Ordering.js.map +0 -1
- package/build/cjs/features/Pagination.js +0 -193
- package/build/cjs/features/Pagination.js.map +0 -1
- package/build/cjs/features/Pinning.js +0 -149
- package/build/cjs/features/Pinning.js.map +0 -1
- package/build/cjs/features/RowSelection.js +0 -526
- package/build/cjs/features/RowSelection.js.map +0 -1
- package/build/cjs/features/Sorting.js +0 -315
- package/build/cjs/features/Sorting.js.map +0 -1
- package/build/cjs/features/Visibility.js +0 -174
- package/build/cjs/features/Visibility.js.map +0 -1
- package/build/cjs/filterTypes.js +0 -172
- package/build/cjs/filterTypes.js.map +0 -1
- package/build/cjs/index.js +0 -44
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/sortTypes.js +0 -122
- package/build/cjs/sortTypes.js.map +0 -1
- package/build/cjs/types.js +0 -22
- package/build/cjs/types.js.map +0 -1
- package/build/cjs/utils/columnFilterRowsFn.js +0 -131
- package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/expandRowsFn.js +0 -38
- package/build/cjs/utils/expandRowsFn.js.map +0 -1
- package/build/cjs/utils/globalFilterRowsFn.js +0 -101
- package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
- package/build/cjs/utils/groupRowsFn.js +0 -155
- package/build/cjs/utils/groupRowsFn.js.map +0 -1
- package/build/cjs/utils/paginateRowsFn.js +0 -44
- package/build/cjs/utils/paginateRowsFn.js.map +0 -1
- package/build/cjs/utils/sortRowsFn.js +0 -94
- package/build/cjs/utils/sortRowsFn.js.map +0 -1
- package/build/cjs/utils.js +0 -167
- package/build/cjs/utils.js.map +0 -1
- package/build/types/aggregationTypes.d.ts +0 -22
- package/build/types/core.d.ts +0 -105
- package/build/types/createTable.d.ts +0 -42
- package/build/types/features/ColumnSizing.d.ts +0 -73
- package/build/types/features/Expanding.d.ts +0 -48
- package/build/types/features/Filters.d.ts +0 -90
- package/build/types/features/Grouping.d.ts +0 -83
- package/build/types/features/Headers.d.ts +0 -41
- package/build/types/features/Ordering.d.ts +0 -19
- package/build/types/features/Pagination.d.ts +0 -39
- package/build/types/features/Pinning.d.ts +0 -39
- package/build/types/features/RowSelection.d.ts +0 -58
- package/build/types/features/Sorting.d.ts +0 -79
- package/build/types/features/Visibility.d.ts +0 -47
- package/build/types/filterTypes.d.ts +0 -50
- package/build/types/sortTypes.d.ts +0 -18
- package/build/types/types.d.ts +0 -138
- package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
- package/build/types/utils/expandRowsFn.d.ts +0 -2
- package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
- package/build/types/utils/groupRowsFn.d.ts +0 -2
- package/build/types/utils/paginateRowsFn.d.ts +0 -2
- package/build/types/utils/sortRowsFn.d.ts +0 -2
- package/build/types/utils.d.ts +0 -23
- package/src/aggregationTypes.ts +0 -115
- package/src/core.tsx +0 -763
- package/src/createTable.tsx +0 -186
- package/src/features/ColumnSizing.ts +0 -424
- package/src/features/Expanding.ts +0 -318
- package/src/features/Filters.ts +0 -560
- package/src/features/Grouping.ts +0 -361
- package/src/features/Headers.ts +0 -729
- package/src/features/Ordering.ts +0 -110
- package/src/features/Pagination.ts +0 -250
- package/src/features/Pinning.ts +0 -174
- package/src/features/RowSelection.ts +0 -651
- package/src/features/Sorting.ts +0 -453
- package/src/features/Visibility.ts +0 -238
- package/src/filterTypes.ts +0 -188
- package/src/sortTypes.ts +0 -147
- package/src/types.ts +0 -311
- package/src/utils/columnFilterRowsFn.ts +0 -113
- package/src/utils/expandRowsFn.ts +0 -30
- package/src/utils/globalFilterRowsFn.ts +0 -89
- package/src/utils/groupRowsFn.ts +0 -170
- package/src/utils/paginateRowsFn.ts +0 -28
- package/src/utils/sortRowsFn.ts +0 -95
- package/src/utils.tsx +0 -221
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
import { MouseEvent, TouchEvent } from 'react'
|
|
2
|
-
import { RowModel } from '..'
|
|
3
|
-
import {
|
|
4
|
-
Getter,
|
|
5
|
-
OnChangeFn,
|
|
6
|
-
PartialGenerics,
|
|
7
|
-
PropGetterValue,
|
|
8
|
-
TableInstance,
|
|
9
|
-
Row,
|
|
10
|
-
Updater,
|
|
11
|
-
} from '../types'
|
|
12
|
-
import { functionalUpdate, makeStateUpdater, memo, propGetter } from '../utils'
|
|
13
|
-
|
|
14
|
-
export type ExpandedStateList = Record<string, boolean>
|
|
15
|
-
export type ExpandedState = true | Record<string, boolean>
|
|
16
|
-
export type ExpandedTableState = {
|
|
17
|
-
expanded: ExpandedState
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type ExpandedRow = {
|
|
21
|
-
toggleExpanded: (expanded?: boolean) => void
|
|
22
|
-
getIsExpanded: () => boolean
|
|
23
|
-
getCanExpand: () => boolean
|
|
24
|
-
getToggleExpandedProps: <TGetter extends Getter<ToggleExpandedProps>>(
|
|
25
|
-
userProps?: TGetter
|
|
26
|
-
) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type ExpandedOptions<TGenerics extends PartialGenerics> = {
|
|
30
|
-
onExpandedChange?: OnChangeFn<ExpandedState>
|
|
31
|
-
autoResetExpanded?: boolean
|
|
32
|
-
enableExpanded?: boolean
|
|
33
|
-
expandRowsFn?: (
|
|
34
|
-
instance: TableInstance<TGenerics>,
|
|
35
|
-
rowModel: RowModel<TGenerics>
|
|
36
|
-
) => RowModel<TGenerics>
|
|
37
|
-
expandSubRows?: boolean
|
|
38
|
-
defaultCanExpand?: boolean
|
|
39
|
-
getIsRowExpanded?: (row: Row<TGenerics>) => boolean
|
|
40
|
-
getRowCanExpand?: (row: Row<TGenerics>) => boolean
|
|
41
|
-
paginateExpandedRows?: boolean
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export type ToggleExpandedProps = {
|
|
45
|
-
title?: string
|
|
46
|
-
onClick?: (event: MouseEvent | TouchEvent) => void
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type ExpandedInstance<TGenerics extends PartialGenerics> = {
|
|
50
|
-
_notifyExpandedReset: () => void
|
|
51
|
-
setExpanded: (updater: Updater<ExpandedState>) => void
|
|
52
|
-
toggleRowExpanded: (rowId: string, expanded?: boolean) => void
|
|
53
|
-
toggleAllRowsExpanded: (expanded?: boolean) => void
|
|
54
|
-
resetExpanded: () => void
|
|
55
|
-
getRowCanExpand: (rowId: string) => boolean
|
|
56
|
-
getIsRowExpanded: (rowId: string) => boolean
|
|
57
|
-
getToggleExpandedProps: <TGetter extends Getter<ToggleExpandedProps>>(
|
|
58
|
-
rowId: string,
|
|
59
|
-
userProps?: TGetter
|
|
60
|
-
) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
|
|
61
|
-
getToggleAllRowsExpandedProps: <TGetter extends Getter<ToggleExpandedProps>>(
|
|
62
|
-
userProps?: TGetter
|
|
63
|
-
) => undefined | PropGetterValue<ToggleExpandedProps, TGetter>
|
|
64
|
-
getIsAllRowsExpanded: () => boolean
|
|
65
|
-
getExpandedDepth: () => number
|
|
66
|
-
getExpandedRowModel: () => RowModel<TGenerics>
|
|
67
|
-
getPreExpandedRowModel: () => RowModel<TGenerics>
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
export function getInitialState(): ExpandedTableState {
|
|
73
|
-
return {
|
|
74
|
-
expanded: {},
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function getDefaultOptions<TGenerics extends PartialGenerics>(
|
|
79
|
-
instance: TableInstance<TGenerics>
|
|
80
|
-
): ExpandedOptions<TGenerics> {
|
|
81
|
-
return {
|
|
82
|
-
onExpandedChange: makeStateUpdater('expanded', instance),
|
|
83
|
-
autoResetExpanded: true,
|
|
84
|
-
getIsRowExpanded: row => !!(row?.original as { expanded?: any }).expanded,
|
|
85
|
-
expandSubRows: true,
|
|
86
|
-
paginateExpandedRows: true,
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function getInstance<TGenerics extends PartialGenerics>(
|
|
91
|
-
instance: TableInstance<TGenerics>
|
|
92
|
-
): ExpandedInstance<TGenerics> {
|
|
93
|
-
let registered = false
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
_notifyExpandedReset: () => {
|
|
97
|
-
if (!registered) {
|
|
98
|
-
registered = true
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (instance.options.autoResetAll === false) {
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
instance.options.autoResetAll === true ||
|
|
108
|
-
instance.options.autoResetExpanded
|
|
109
|
-
) {
|
|
110
|
-
instance.resetExpanded()
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
setExpanded: updater =>
|
|
114
|
-
instance.options.onExpandedChange?.(
|
|
115
|
-
updater,
|
|
116
|
-
functionalUpdate(updater, instance.getState().expanded)
|
|
117
|
-
),
|
|
118
|
-
toggleRowExpanded: (rowId, expanded) => {
|
|
119
|
-
if (!rowId) return
|
|
120
|
-
|
|
121
|
-
instance.setExpanded(old => {
|
|
122
|
-
const exists = old === true ? true : !!old?.[rowId]
|
|
123
|
-
|
|
124
|
-
let oldExpanded: ExpandedStateList = {}
|
|
125
|
-
|
|
126
|
-
if (old === true) {
|
|
127
|
-
Object.keys(instance.getRowModel().rowsById).forEach(rowId => {
|
|
128
|
-
oldExpanded[rowId] = true
|
|
129
|
-
})
|
|
130
|
-
} else {
|
|
131
|
-
oldExpanded = old
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
expanded = expanded ?? !exists
|
|
135
|
-
|
|
136
|
-
if (!exists && expanded) {
|
|
137
|
-
return {
|
|
138
|
-
...oldExpanded,
|
|
139
|
-
[rowId]: true,
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (exists && !expanded) {
|
|
144
|
-
const { [rowId]: _, ...rest } = oldExpanded
|
|
145
|
-
return rest
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return old
|
|
149
|
-
})
|
|
150
|
-
},
|
|
151
|
-
toggleAllRowsExpanded: expanded => {
|
|
152
|
-
if (expanded ?? !instance.getIsAllRowsExpanded()) {
|
|
153
|
-
instance.setExpanded(true)
|
|
154
|
-
} else {
|
|
155
|
-
instance.setExpanded({})
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
resetExpanded: () => {
|
|
159
|
-
instance.setExpanded(instance.initialState?.expanded ?? {})
|
|
160
|
-
},
|
|
161
|
-
getIsRowExpanded: rowId => {
|
|
162
|
-
const row = instance.getRow(rowId)
|
|
163
|
-
|
|
164
|
-
if (!row) {
|
|
165
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
166
|
-
console.warn(
|
|
167
|
-
`[ReactTable] getIsRowExpanded: no row found with id ${rowId}`
|
|
168
|
-
)
|
|
169
|
-
}
|
|
170
|
-
throw new Error()
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const expanded = instance.getState().expanded
|
|
174
|
-
|
|
175
|
-
return !!(
|
|
176
|
-
instance.options.getIsRowExpanded?.(row) ??
|
|
177
|
-
(expanded || expanded?.[rowId])
|
|
178
|
-
)
|
|
179
|
-
},
|
|
180
|
-
getRowCanExpand: rowId => {
|
|
181
|
-
const row = instance.getRow(rowId)
|
|
182
|
-
|
|
183
|
-
if (!row) {
|
|
184
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
185
|
-
console.warn(
|
|
186
|
-
`[ReactTable] getRowCanExpand: no row found with id ${rowId}`
|
|
187
|
-
)
|
|
188
|
-
}
|
|
189
|
-
throw new Error()
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return (
|
|
193
|
-
instance.options.getRowCanExpand?.(row) ??
|
|
194
|
-
instance.options.enableExpanded ??
|
|
195
|
-
instance.options.defaultCanExpand ??
|
|
196
|
-
!!row.subRows?.length
|
|
197
|
-
)
|
|
198
|
-
},
|
|
199
|
-
getToggleExpandedProps: (rowId, userProps) => {
|
|
200
|
-
const row = instance.getRow(rowId)
|
|
201
|
-
|
|
202
|
-
if (!row) {
|
|
203
|
-
return
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const canExpand = instance.getRowCanExpand(rowId)
|
|
207
|
-
|
|
208
|
-
const initialProps: ToggleExpandedProps = {
|
|
209
|
-
title: canExpand ? 'Toggle Expanded' : undefined,
|
|
210
|
-
onClick: canExpand
|
|
211
|
-
? (e: MouseEvent | TouchEvent) => {
|
|
212
|
-
e.persist()
|
|
213
|
-
instance.toggleRowExpanded(rowId)
|
|
214
|
-
}
|
|
215
|
-
: undefined,
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return propGetter(initialProps, userProps)
|
|
219
|
-
},
|
|
220
|
-
getToggleAllRowsExpandedProps: userProps => {
|
|
221
|
-
const initialProps: ToggleExpandedProps = {
|
|
222
|
-
title: 'Toggle All Expanded',
|
|
223
|
-
onClick: (e: MouseEvent | TouchEvent) => {
|
|
224
|
-
e.persist()
|
|
225
|
-
instance.toggleAllRowsExpanded()
|
|
226
|
-
},
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return propGetter(initialProps, userProps)
|
|
230
|
-
},
|
|
231
|
-
getIsAllRowsExpanded: () => {
|
|
232
|
-
const expanded = instance.getState().expanded
|
|
233
|
-
|
|
234
|
-
// If expanded is true, save some cycles and return true
|
|
235
|
-
if (expanded === true) {
|
|
236
|
-
return true
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// If any row is not expanded, return false
|
|
240
|
-
if (
|
|
241
|
-
Object.keys(instance.getRowModel().rowsById).some(
|
|
242
|
-
id => !instance.getIsRowExpanded(id)
|
|
243
|
-
)
|
|
244
|
-
) {
|
|
245
|
-
return false
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// They must all be expanded :shrug:
|
|
249
|
-
return true
|
|
250
|
-
},
|
|
251
|
-
getExpandedDepth: () => {
|
|
252
|
-
let maxDepth = 0
|
|
253
|
-
|
|
254
|
-
const rowIds =
|
|
255
|
-
instance.getState().expanded === true
|
|
256
|
-
? Object.keys(instance.getRowModel().rowsById)
|
|
257
|
-
: Object.keys(instance.getState().expanded)
|
|
258
|
-
|
|
259
|
-
rowIds.forEach(id => {
|
|
260
|
-
const splitId = id.split('.')
|
|
261
|
-
maxDepth = Math.max(maxDepth, splitId.length)
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
return maxDepth
|
|
265
|
-
},
|
|
266
|
-
getExpandedRowModel: memo(
|
|
267
|
-
() => [
|
|
268
|
-
instance.getState().expanded,
|
|
269
|
-
instance.getGroupedRowModel(),
|
|
270
|
-
instance.options.expandRowsFn,
|
|
271
|
-
instance.options.paginateExpandedRows,
|
|
272
|
-
],
|
|
273
|
-
(expanded, rowModel, expandRowsFn, paginateExpandedRows) => {
|
|
274
|
-
if (
|
|
275
|
-
!expandRowsFn ||
|
|
276
|
-
// Do not expand if rows are not included in pagination
|
|
277
|
-
!paginateExpandedRows ||
|
|
278
|
-
!Object.keys(expanded ?? {}).length
|
|
279
|
-
) {
|
|
280
|
-
return rowModel
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return expandRowsFn(instance, rowModel)
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
key: 'getExpandedRowModel',
|
|
287
|
-
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
288
|
-
onChange: () => {
|
|
289
|
-
instance._notifyPageIndexReset()
|
|
290
|
-
},
|
|
291
|
-
}
|
|
292
|
-
),
|
|
293
|
-
|
|
294
|
-
getPreExpandedRowModel: () => instance.getGroupedRowModel(),
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
export function createRow<TGenerics extends PartialGenerics>(
|
|
299
|
-
row: Row<TGenerics>,
|
|
300
|
-
instance: TableInstance<TGenerics>
|
|
301
|
-
): ExpandedRow {
|
|
302
|
-
return {
|
|
303
|
-
toggleExpanded: expanded =>
|
|
304
|
-
void instance.toggleRowExpanded(row.id, expanded),
|
|
305
|
-
getIsExpanded: () => instance.getIsRowExpanded(row.id),
|
|
306
|
-
getCanExpand: () => row.subRows && !!row.subRows.length,
|
|
307
|
-
getToggleExpandedProps: userProps => {
|
|
308
|
-
const initialProps: ToggleExpandedProps = {
|
|
309
|
-
title: 'Toggle Row Expanded',
|
|
310
|
-
onClick: (e: MouseEvent | TouchEvent) => {
|
|
311
|
-
e.stopPropagation()
|
|
312
|
-
instance.toggleRowExpanded(row.id)
|
|
313
|
-
},
|
|
314
|
-
}
|
|
315
|
-
return propGetter(initialProps, userProps)
|
|
316
|
-
},
|
|
317
|
-
}
|
|
318
|
-
}
|