@tanstack/table-core 8.0.12 → 8.1.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/core/cell.js +13 -13
- package/build/cjs/core/cell.js.map +1 -1
- package/build/cjs/core/column.js +20 -21
- package/build/cjs/core/column.js.map +1 -1
- package/build/cjs/core/headers.js +63 -68
- package/build/cjs/core/headers.js.map +1 -1
- package/build/cjs/core/row.js +16 -11
- package/build/cjs/core/row.js.map +1 -1
- package/build/cjs/core/{instance.js → table.js} +46 -57
- package/build/cjs/core/table.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +36 -36
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +34 -34
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +46 -52
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +24 -49
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Ordering.js +8 -8
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +37 -37
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +33 -33
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +86 -74
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +36 -40
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +30 -30
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/index.js +3 -4
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +8 -8
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js +8 -8
- package/build/cjs/utils/getCoreRowModel.js.map +1 -1
- package/build/cjs/utils/getExpandedRowModel.js +4 -4
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedMinMaxValues.js +3 -3
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -1
- package/build/cjs/utils/getFacetedRowModel.js +4 -4
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedUniqueValues.js +3 -3
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -1
- package/build/cjs/utils/getFilteredRowModel.js +8 -8
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +9 -9
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js +4 -4
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModel.js +7 -7
- package/build/cjs/utils/getSortedRowModel.js.map +1 -1
- package/build/cjs/utils.js +2 -2
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +585 -677
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +352 -377
- package/build/types/index.d.ts +761 -29
- package/build/umd/index.development.js +586 -678
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/core/cell.ts +34 -28
- package/src/core/column.ts +83 -72
- package/src/core/headers.ts +118 -149
- package/src/core/row.ts +31 -25
- package/src/core/{instance.ts → table.ts} +85 -116
- package/src/features/ColumnSizing.ts +45 -47
- package/src/features/Expanding.ts +53 -59
- package/src/features/Filters.ts +112 -132
- package/src/features/Grouping.ts +63 -112
- package/src/features/Ordering.ts +19 -21
- package/src/features/Pagination.ts +54 -55
- package/src/features/Pinning.ts +49 -61
- package/src/features/RowSelection.ts +115 -114
- package/src/features/Sorting.ts +57 -72
- package/src/features/Visibility.ts +48 -48
- package/src/index.ts +1 -2
- package/src/types.ts +64 -69
- package/src/utils/filterRowsUtils.ts +33 -28
- package/src/utils/getCoreRowModel.ts +22 -22
- package/src/utils/getExpandedRowModel.ts +15 -15
- package/src/utils/getFacetedMinMaxValues.ts +6 -6
- package/src/utils/getFacetedRowModel.ts +12 -12
- package/src/utils/getFacetedUniqueValues.ts +6 -6
- package/src/utils/getFilteredRowModel.ts +17 -17
- package/src/utils/getGroupedRowModel.ts +18 -21
- package/src/utils/getPaginationRowModel.ts +10 -13
- package/src/utils/getSortedRowModel.ts +14 -14
- package/src/utils.ts +8 -2
- package/build/cjs/core/instance.js.map +0 -1
- package/build/cjs/createTable.js +0 -72
- package/build/cjs/createTable.js.map +0 -1
- package/build/types/aggregationFns.d.ts +0 -13
- package/build/types/core/cell.d.ts +0 -9
- package/build/types/core/column.d.ts +0 -40
- package/build/types/core/headers.d.ts +0 -46
- package/build/types/core/instance.d.ts +0 -58
- package/build/types/core/row.d.ts +0 -15
- package/build/types/createTable.d.ts +0 -63
- package/build/types/features/ColumnSizing.d.ts +0 -63
- package/build/types/features/Expanding.d.ts +0 -39
- package/build/types/features/Filters.d.ts +0 -90
- package/build/types/features/Grouping.d.ts +0 -68
- package/build/types/features/Ordering.d.ts +0 -18
- package/build/types/features/Pagination.d.ts +0 -42
- package/build/types/features/Pinning.d.ts +0 -40
- package/build/types/features/RowSelection.d.ts +0 -40
- package/build/types/features/Sorting.d.ts +0 -63
- package/build/types/features/Visibility.d.ts +0 -40
- package/build/types/filterFns.d.ts +0 -13
- package/build/types/sortingFns.d.ts +0 -11
- package/build/types/types.d.ts +0 -53
- package/build/types/utils/filterRowsUtils.d.ts +0 -4
- package/build/types/utils/getCoreRowModel.d.ts +0 -2
- package/build/types/utils/getExpandedRowModel.d.ts +0 -7
- package/build/types/utils/getFacetedMinMaxValues.d.ts +0 -2
- package/build/types/utils/getFacetedRowModel.d.ts +0 -2
- package/build/types/utils/getFacetedUniqueValues.d.ts +0 -2
- package/build/types/utils/getFilteredRowModel.d.ts +0 -2
- package/build/types/utils/getGroupedRowModel.d.ts +0 -2
- package/build/types/utils/getPaginationRowModel.d.ts +0 -4
- package/build/types/utils/getSortedRowModel.d.ts +0 -2
- package/build/types/utils.d.ts +0 -19
- package/src/createTable.ts +0 -188
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { RowModel } from '..'
|
|
2
|
-
import { TableFeature } from '../core/
|
|
2
|
+
import { TableFeature } from '../core/table'
|
|
3
3
|
import {
|
|
4
4
|
OnChangeFn,
|
|
5
5
|
TableGenerics,
|
|
6
|
-
|
|
6
|
+
Table,
|
|
7
7
|
Row,
|
|
8
8
|
Updater,
|
|
9
|
+
RowData,
|
|
9
10
|
} from '../types'
|
|
10
11
|
import { makeStateUpdater } from '../utils'
|
|
11
12
|
|
|
@@ -22,18 +23,18 @@ export type ExpandedRow = {
|
|
|
22
23
|
getToggleExpandedHandler: () => () => void
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export type ExpandedOptions<
|
|
26
|
+
export type ExpandedOptions<TData extends RowData> = {
|
|
26
27
|
manualExpanding?: boolean
|
|
27
28
|
onExpandedChange?: OnChangeFn<ExpandedState>
|
|
28
29
|
autoResetExpanded?: boolean
|
|
29
30
|
enableExpanding?: boolean
|
|
30
|
-
getExpandedRowModel?: (
|
|
31
|
-
getIsRowExpanded?: (row: Row<
|
|
32
|
-
getRowCanExpand?: (row: Row<
|
|
31
|
+
getExpandedRowModel?: (table: Table<any>) => () => RowModel<any>
|
|
32
|
+
getIsRowExpanded?: (row: Row<TData>) => boolean
|
|
33
|
+
getRowCanExpand?: (row: Row<TData>) => boolean
|
|
33
34
|
paginateExpandedRows?: boolean
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
export type ExpandedInstance<
|
|
37
|
+
export type ExpandedInstance<TData extends RowData> = {
|
|
37
38
|
_autoResetExpanded: () => void
|
|
38
39
|
setExpanded: (updater: Updater<ExpandedState>) => void
|
|
39
40
|
toggleAllRowsExpanded: (expanded?: boolean) => void
|
|
@@ -43,9 +44,9 @@ export type ExpandedInstance<TGenerics extends TableGenerics> = {
|
|
|
43
44
|
getIsSomeRowsExpanded: () => boolean
|
|
44
45
|
getIsAllRowsExpanded: () => boolean
|
|
45
46
|
getExpandedDepth: () => number
|
|
46
|
-
getExpandedRowModel: () => RowModel<
|
|
47
|
-
_getExpandedRowModel?: () => RowModel<
|
|
48
|
-
getPreExpandedRowModel: () => RowModel<
|
|
47
|
+
getExpandedRowModel: () => RowModel<TData>
|
|
48
|
+
_getExpandedRowModel?: () => RowModel<TData>
|
|
49
|
+
getPreExpandedRowModel: () => RowModel<TData>
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
//
|
|
@@ -58,71 +59,71 @@ export const Expanding: TableFeature = {
|
|
|
58
59
|
}
|
|
59
60
|
},
|
|
60
61
|
|
|
61
|
-
getDefaultOptions: <
|
|
62
|
-
|
|
63
|
-
): ExpandedOptions<
|
|
62
|
+
getDefaultOptions: <TData extends RowData>(
|
|
63
|
+
table: Table<TData>
|
|
64
|
+
): ExpandedOptions<TData> => {
|
|
64
65
|
return {
|
|
65
|
-
onExpandedChange: makeStateUpdater('expanded',
|
|
66
|
+
onExpandedChange: makeStateUpdater('expanded', table),
|
|
66
67
|
paginateExpandedRows: true,
|
|
67
68
|
}
|
|
68
69
|
},
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
): ExpandedInstance<
|
|
71
|
+
createTable: <TData extends RowData>(
|
|
72
|
+
table: Table<TData>
|
|
73
|
+
): ExpandedInstance<TData> => {
|
|
73
74
|
let registered = false
|
|
74
75
|
let queued = false
|
|
75
76
|
|
|
76
77
|
return {
|
|
77
78
|
_autoResetExpanded: () => {
|
|
78
79
|
if (!registered) {
|
|
79
|
-
|
|
80
|
+
table._queue(() => {
|
|
80
81
|
registered = true
|
|
81
82
|
})
|
|
82
83
|
return
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
!
|
|
87
|
+
table.options.autoResetAll ??
|
|
88
|
+
table.options.autoResetExpanded ??
|
|
89
|
+
!table.options.manualExpanding
|
|
89
90
|
) {
|
|
90
91
|
if (queued) return
|
|
91
92
|
queued = true
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
table._queue(() => {
|
|
94
|
+
table.resetExpanded()
|
|
94
95
|
queued = false
|
|
95
96
|
})
|
|
96
97
|
}
|
|
97
98
|
},
|
|
98
|
-
setExpanded: updater =>
|
|
99
|
+
setExpanded: updater => table.options.onExpandedChange?.(updater),
|
|
99
100
|
toggleAllRowsExpanded: expanded => {
|
|
100
|
-
if (expanded ?? !
|
|
101
|
-
|
|
101
|
+
if (expanded ?? !table.getIsAllRowsExpanded()) {
|
|
102
|
+
table.setExpanded(true)
|
|
102
103
|
} else {
|
|
103
|
-
|
|
104
|
+
table.setExpanded({})
|
|
104
105
|
}
|
|
105
106
|
},
|
|
106
107
|
resetExpanded: defaultState => {
|
|
107
|
-
|
|
108
|
-
defaultState ? {} :
|
|
108
|
+
table.setExpanded(
|
|
109
|
+
defaultState ? {} : table.initialState?.expanded ?? {}
|
|
109
110
|
)
|
|
110
111
|
},
|
|
111
112
|
getCanSomeRowsExpand: () => {
|
|
112
|
-
return
|
|
113
|
+
return table.getRowModel().flatRows.some(row => row.getCanExpand())
|
|
113
114
|
},
|
|
114
115
|
getToggleAllRowsExpandedHandler: () => {
|
|
115
116
|
return (e: unknown) => {
|
|
116
117
|
;(e as any).persist?.()
|
|
117
|
-
|
|
118
|
+
table.toggleAllRowsExpanded()
|
|
118
119
|
}
|
|
119
120
|
},
|
|
120
121
|
getIsSomeRowsExpanded: () => {
|
|
121
|
-
const expanded =
|
|
122
|
+
const expanded = table.getState().expanded
|
|
122
123
|
return expanded === true || Object.values(expanded).some(Boolean)
|
|
123
124
|
},
|
|
124
125
|
getIsAllRowsExpanded: () => {
|
|
125
|
-
const expanded =
|
|
126
|
+
const expanded = table.getState().expanded
|
|
126
127
|
|
|
127
128
|
// If expanded is true, save some cycles and return true
|
|
128
129
|
if (typeof expanded === 'boolean') {
|
|
@@ -134,7 +135,7 @@ export const Expanding: TableFeature = {
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
// If any row is not expanded, return false
|
|
137
|
-
if (
|
|
138
|
+
if (table.getRowModel().flatRows.some(row => row.getIsExpanded())) {
|
|
138
139
|
return false
|
|
139
140
|
}
|
|
140
141
|
|
|
@@ -145,9 +146,9 @@ export const Expanding: TableFeature = {
|
|
|
145
146
|
let maxDepth = 0
|
|
146
147
|
|
|
147
148
|
const rowIds =
|
|
148
|
-
|
|
149
|
-
? Object.keys(
|
|
150
|
-
: Object.keys(
|
|
149
|
+
table.getState().expanded === true
|
|
150
|
+
? Object.keys(table.getRowModel().rowsById)
|
|
151
|
+
: Object.keys(table.getState().expanded)
|
|
151
152
|
|
|
152
153
|
rowIds.forEach(id => {
|
|
153
154
|
const splitId = id.split('.')
|
|
@@ -156,41 +157,34 @@ export const Expanding: TableFeature = {
|
|
|
156
157
|
|
|
157
158
|
return maxDepth
|
|
158
159
|
},
|
|
159
|
-
getPreExpandedRowModel: () =>
|
|
160
|
+
getPreExpandedRowModel: () => table.getSortedRowModel(),
|
|
160
161
|
getExpandedRowModel: () => {
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
instance.options.getExpandedRowModel
|
|
164
|
-
) {
|
|
165
|
-
instance._getExpandedRowModel =
|
|
166
|
-
instance.options.getExpandedRowModel(instance)
|
|
162
|
+
if (!table._getExpandedRowModel && table.options.getExpandedRowModel) {
|
|
163
|
+
table._getExpandedRowModel = table.options.getExpandedRowModel(table)
|
|
167
164
|
}
|
|
168
165
|
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
!instance._getExpandedRowModel
|
|
172
|
-
) {
|
|
173
|
-
return instance.getPreExpandedRowModel()
|
|
166
|
+
if (table.options.manualExpanding || !table._getExpandedRowModel) {
|
|
167
|
+
return table.getPreExpandedRowModel()
|
|
174
168
|
}
|
|
175
169
|
|
|
176
|
-
return
|
|
170
|
+
return table._getExpandedRowModel()
|
|
177
171
|
},
|
|
178
172
|
}
|
|
179
173
|
},
|
|
180
174
|
|
|
181
|
-
createRow: <
|
|
182
|
-
row: Row<
|
|
183
|
-
|
|
175
|
+
createRow: <TData extends RowData>(
|
|
176
|
+
row: Row<TData>,
|
|
177
|
+
table: Table<TData>
|
|
184
178
|
): ExpandedRow => {
|
|
185
179
|
return {
|
|
186
180
|
toggleExpanded: expanded => {
|
|
187
|
-
|
|
181
|
+
table.setExpanded(old => {
|
|
188
182
|
const exists = old === true ? true : !!old?.[row.id]
|
|
189
183
|
|
|
190
184
|
let oldExpanded: ExpandedStateList = {}
|
|
191
185
|
|
|
192
186
|
if (old === true) {
|
|
193
|
-
Object.keys(
|
|
187
|
+
Object.keys(table.getRowModel().rowsById).forEach(rowId => {
|
|
194
188
|
oldExpanded[rowId] = true
|
|
195
189
|
})
|
|
196
190
|
} else {
|
|
@@ -215,17 +209,17 @@ export const Expanding: TableFeature = {
|
|
|
215
209
|
})
|
|
216
210
|
},
|
|
217
211
|
getIsExpanded: () => {
|
|
218
|
-
const expanded =
|
|
212
|
+
const expanded = table.getState().expanded
|
|
219
213
|
|
|
220
214
|
return !!(
|
|
221
|
-
|
|
215
|
+
table.options.getIsRowExpanded?.(row) ??
|
|
222
216
|
(expanded === true || expanded?.[row.id])
|
|
223
217
|
)
|
|
224
218
|
},
|
|
225
219
|
getCanExpand: () => {
|
|
226
220
|
return (
|
|
227
|
-
(
|
|
228
|
-
(
|
|
221
|
+
(table.options.getRowCanExpand?.(row) ?? true) &&
|
|
222
|
+
(table.options.enableExpanding ?? true) &&
|
|
229
223
|
!!row.subRows?.length
|
|
230
224
|
)
|
|
231
225
|
},
|