@tanstack/table-core 8.9.7 → 8.9.8
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/lib/core/cell.js +1 -1
- package/build/lib/core/cell.js.map +1 -1
- package/build/lib/core/column.js +3 -3
- package/build/lib/core/column.js.map +1 -1
- package/build/lib/core/headers.js +182 -181
- package/build/lib/core/headers.js.map +1 -1
- package/build/lib/core/row.js +1 -1
- package/build/lib/core/row.js.map +1 -1
- package/build/lib/core/table.js +4 -3
- package/build/lib/core/table.js.map +1 -1
- package/build/lib/features/ColumnSizing.js +173 -179
- package/build/lib/features/ColumnSizing.js.map +1 -1
- package/build/lib/features/Expanding.js +119 -123
- package/build/lib/features/Expanding.js.map +1 -1
- package/build/lib/features/Filters.js +157 -165
- package/build/lib/features/Filters.js.map +1 -1
- package/build/lib/features/Grouping.js +71 -79
- package/build/lib/features/Grouping.js.map +1 -1
- package/build/lib/features/Ordering.js +32 -34
- package/build/lib/features/Ordering.js.map +1 -1
- package/build/lib/features/Pagination.js +112 -114
- package/build/lib/features/Pagination.js.map +1 -1
- package/build/lib/features/Pinning.js +120 -126
- package/build/lib/features/Pinning.js.map +1 -1
- package/build/lib/features/RowSelection.js +245 -247
- package/build/lib/features/RowSelection.js.map +1 -1
- package/build/lib/features/Sorting.js +163 -167
- package/build/lib/features/Sorting.js.map +1 -1
- package/build/lib/features/Visibility.js +60 -66
- package/build/lib/features/Visibility.js.map +1 -1
- package/build/lib/index.esm.js +1469 -1515
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.mjs +1469 -1515
- package/build/lib/index.mjs.map +1 -1
- package/build/umd/index.development.js +1469 -1515
- 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 +5 -8
- package/src/core/column.ts +3 -3
- package/src/core/headers.ts +264 -280
- package/src/core/row.ts +1 -1
- package/src/core/table.ts +4 -3
- package/src/features/ColumnSizing.ts +220 -231
- package/src/features/Expanding.ts +132 -140
- package/src/features/Filters.ts +193 -206
- package/src/features/Grouping.ts +94 -110
- package/src/features/Ordering.ts +48 -51
- package/src/features/Pagination.ts +150 -154
- package/src/features/Pinning.ts +158 -178
- package/src/features/RowSelection.ts +280 -286
- package/src/features/Sorting.ts +196 -206
- package/src/features/Visibility.ts +98 -107
|
@@ -61,170 +61,162 @@ export const Expanding: TableFeature = {
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
|
|
64
|
-
createTable: <TData extends RowData>(
|
|
65
|
-
table: Table<TData>
|
|
66
|
-
): ExpandedInstance<TData> => {
|
|
64
|
+
createTable: <TData extends RowData>(table: Table<TData>): void => {
|
|
67
65
|
let registered = false
|
|
68
66
|
let queued = false
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
table._autoResetExpanded = () => {
|
|
69
|
+
if (!registered) {
|
|
70
|
+
table._queue(() => {
|
|
71
|
+
registered = true
|
|
72
|
+
})
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (
|
|
77
|
+
table.options.autoResetAll ??
|
|
78
|
+
table.options.autoResetExpanded ??
|
|
79
|
+
!table.options.manualExpanding
|
|
80
|
+
) {
|
|
81
|
+
if (queued) return
|
|
82
|
+
queued = true
|
|
83
|
+
table._queue(() => {
|
|
84
|
+
table.resetExpanded()
|
|
85
|
+
queued = false
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
table.setExpanded = updater => table.options.onExpandedChange?.(updater)
|
|
90
|
+
table.toggleAllRowsExpanded = expanded => {
|
|
91
|
+
if (expanded ?? !table.getIsAllRowsExpanded()) {
|
|
92
|
+
table.setExpanded(true)
|
|
93
|
+
} else {
|
|
94
|
+
table.setExpanded({})
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
table.resetExpanded = defaultState => {
|
|
98
|
+
table.setExpanded(defaultState ? {} : table.initialState?.expanded ?? {})
|
|
99
|
+
}
|
|
100
|
+
table.getCanSomeRowsExpand = () => {
|
|
101
|
+
return table
|
|
102
|
+
.getPrePaginationRowModel()
|
|
103
|
+
.flatRows.some(row => row.getCanExpand())
|
|
104
|
+
}
|
|
105
|
+
table.getToggleAllRowsExpandedHandler = () => {
|
|
106
|
+
return (e: unknown) => {
|
|
107
|
+
;(e as any).persist?.()
|
|
108
|
+
table.toggleAllRowsExpanded()
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
table.getIsSomeRowsExpanded = () => {
|
|
112
|
+
const expanded = table.getState().expanded
|
|
113
|
+
return expanded === true || Object.values(expanded).some(Boolean)
|
|
114
|
+
}
|
|
115
|
+
table.getIsAllRowsExpanded = () => {
|
|
116
|
+
const expanded = table.getState().expanded
|
|
78
117
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
) {
|
|
84
|
-
if (queued) return
|
|
85
|
-
queued = true
|
|
86
|
-
table._queue(() => {
|
|
87
|
-
table.resetExpanded()
|
|
88
|
-
queued = false
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
setExpanded: updater => table.options.onExpandedChange?.(updater),
|
|
93
|
-
toggleAllRowsExpanded: expanded => {
|
|
94
|
-
if (expanded ?? !table.getIsAllRowsExpanded()) {
|
|
95
|
-
table.setExpanded(true)
|
|
96
|
-
} else {
|
|
97
|
-
table.setExpanded({})
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
resetExpanded: defaultState => {
|
|
101
|
-
table.setExpanded(
|
|
102
|
-
defaultState ? {} : table.initialState?.expanded ?? {}
|
|
103
|
-
)
|
|
104
|
-
},
|
|
105
|
-
getCanSomeRowsExpand: () => {
|
|
106
|
-
return table
|
|
107
|
-
.getPrePaginationRowModel()
|
|
108
|
-
.flatRows.some(row => row.getCanExpand())
|
|
109
|
-
},
|
|
110
|
-
getToggleAllRowsExpandedHandler: () => {
|
|
111
|
-
return (e: unknown) => {
|
|
112
|
-
;(e as any).persist?.()
|
|
113
|
-
table.toggleAllRowsExpanded()
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
getIsSomeRowsExpanded: () => {
|
|
117
|
-
const expanded = table.getState().expanded
|
|
118
|
-
return expanded === true || Object.values(expanded).some(Boolean)
|
|
119
|
-
},
|
|
120
|
-
getIsAllRowsExpanded: () => {
|
|
121
|
-
const expanded = table.getState().expanded
|
|
122
|
-
|
|
123
|
-
// If expanded is true, save some cycles and return true
|
|
124
|
-
if (typeof expanded === 'boolean') {
|
|
125
|
-
return expanded === true
|
|
126
|
-
}
|
|
118
|
+
// If expanded is true, save some cycles and return true
|
|
119
|
+
if (typeof expanded === 'boolean') {
|
|
120
|
+
return expanded === true
|
|
121
|
+
}
|
|
127
122
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
123
|
+
if (!Object.keys(expanded).length) {
|
|
124
|
+
return false
|
|
125
|
+
}
|
|
131
126
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
127
|
+
// If any row is not expanded, return false
|
|
128
|
+
if (table.getRowModel().flatRows.some(row => !row.getIsExpanded())) {
|
|
129
|
+
return false
|
|
130
|
+
}
|
|
136
131
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
// They must all be expanded :shrug:
|
|
133
|
+
return true
|
|
134
|
+
}
|
|
135
|
+
table.getExpandedDepth = () => {
|
|
136
|
+
let maxDepth = 0
|
|
142
137
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
const rowIds =
|
|
139
|
+
table.getState().expanded === true
|
|
140
|
+
? Object.keys(table.getRowModel().rowsById)
|
|
141
|
+
: Object.keys(table.getState().expanded)
|
|
147
142
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
143
|
+
rowIds.forEach(id => {
|
|
144
|
+
const splitId = id.split('.')
|
|
145
|
+
maxDepth = Math.max(maxDepth, splitId.length)
|
|
146
|
+
})
|
|
152
147
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
148
|
+
return maxDepth
|
|
149
|
+
}
|
|
150
|
+
table.getPreExpandedRowModel = () => table.getSortedRowModel()
|
|
151
|
+
table.getExpandedRowModel = () => {
|
|
152
|
+
if (!table._getExpandedRowModel && table.options.getExpandedRowModel) {
|
|
153
|
+
table._getExpandedRowModel = table.options.getExpandedRowModel(table)
|
|
154
|
+
}
|
|
160
155
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
156
|
+
if (table.options.manualExpanding || !table._getExpandedRowModel) {
|
|
157
|
+
return table.getPreExpandedRowModel()
|
|
158
|
+
}
|
|
164
159
|
|
|
165
|
-
|
|
166
|
-
},
|
|
160
|
+
return table._getExpandedRowModel()
|
|
167
161
|
}
|
|
168
162
|
},
|
|
169
163
|
|
|
170
164
|
createRow: <TData extends RowData>(
|
|
171
165
|
row: Row<TData>,
|
|
172
166
|
table: Table<TData>
|
|
173
|
-
):
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const exists = old === true ? true : !!old?.[row.id]
|
|
178
|
-
|
|
179
|
-
let oldExpanded: ExpandedStateList = {}
|
|
180
|
-
|
|
181
|
-
if (old === true) {
|
|
182
|
-
Object.keys(table.getRowModel().rowsById).forEach(rowId => {
|
|
183
|
-
oldExpanded[rowId] = true
|
|
184
|
-
})
|
|
185
|
-
} else {
|
|
186
|
-
oldExpanded = old
|
|
187
|
-
}
|
|
167
|
+
): void => {
|
|
168
|
+
row.toggleExpanded = expanded => {
|
|
169
|
+
table.setExpanded(old => {
|
|
170
|
+
const exists = old === true ? true : !!old?.[row.id]
|
|
188
171
|
|
|
189
|
-
|
|
172
|
+
let oldExpanded: ExpandedStateList = {}
|
|
190
173
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
174
|
+
if (old === true) {
|
|
175
|
+
Object.keys(table.getRowModel().rowsById).forEach(rowId => {
|
|
176
|
+
oldExpanded[rowId] = true
|
|
177
|
+
})
|
|
178
|
+
} else {
|
|
179
|
+
oldExpanded = old
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
expanded = expanded ?? !exists
|
|
197
183
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
184
|
+
if (!exists && expanded) {
|
|
185
|
+
return {
|
|
186
|
+
...oldExpanded,
|
|
187
|
+
[row.id]: true,
|
|
201
188
|
}
|
|
189
|
+
}
|
|
202
190
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
getIsExpanded: () => {
|
|
207
|
-
const expanded = table.getState().expanded
|
|
208
|
-
|
|
209
|
-
return !!(
|
|
210
|
-
table.options.getIsRowExpanded?.(row) ??
|
|
211
|
-
(expanded === true || expanded?.[row.id])
|
|
212
|
-
)
|
|
213
|
-
},
|
|
214
|
-
getCanExpand: () => {
|
|
215
|
-
return (
|
|
216
|
-
table.options.getRowCanExpand?.(row) ??
|
|
217
|
-
((table.options.enableExpanding ?? true) && !!row.subRows?.length)
|
|
218
|
-
)
|
|
219
|
-
},
|
|
220
|
-
getToggleExpandedHandler: () => {
|
|
221
|
-
const canExpand = row.getCanExpand()
|
|
222
|
-
|
|
223
|
-
return () => {
|
|
224
|
-
if (!canExpand) return
|
|
225
|
-
row.toggleExpanded()
|
|
191
|
+
if (exists && !expanded) {
|
|
192
|
+
const { [row.id]: _, ...rest } = oldExpanded
|
|
193
|
+
return rest
|
|
226
194
|
}
|
|
227
|
-
|
|
195
|
+
|
|
196
|
+
return old
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
row.getIsExpanded = () => {
|
|
200
|
+
const expanded = table.getState().expanded
|
|
201
|
+
|
|
202
|
+
return !!(
|
|
203
|
+
table.options.getIsRowExpanded?.(row) ??
|
|
204
|
+
(expanded === true || expanded?.[row.id])
|
|
205
|
+
)
|
|
206
|
+
}
|
|
207
|
+
row.getCanExpand = () => {
|
|
208
|
+
return (
|
|
209
|
+
table.options.getRowCanExpand?.(row) ??
|
|
210
|
+
((table.options.enableExpanding ?? true) && !!row.subRows?.length)
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
row.getToggleExpandedHandler = () => {
|
|
214
|
+
const canExpand = row.getCanExpand()
|
|
215
|
+
|
|
216
|
+
return () => {
|
|
217
|
+
if (!canExpand) return
|
|
218
|
+
row.toggleExpanded()
|
|
219
|
+
}
|
|
228
220
|
}
|
|
229
221
|
},
|
|
230
222
|
}
|