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