@tanstack/table-core 8.0.11 → 8.0.14
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 +67 -67
- 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 +2 -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 +567 -670
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +1092 -0
- package/build/types/index.d.ts +759 -0
- package/build/umd/index.development.js +567 -671
- 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 +2 -2
- 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 +97 -108
- 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/src/createTable.ts +0 -188
package/src/core/headers.ts
CHANGED
|
@@ -1,66 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Column,
|
|
3
|
-
Header,
|
|
4
|
-
HeaderGroup,
|
|
5
|
-
TableGenerics,
|
|
6
|
-
TableInstance,
|
|
7
|
-
} from '../types'
|
|
1
|
+
import { RowData, Column, Header, HeaderGroup, Table } from '../types'
|
|
8
2
|
import { memo } from '../utils'
|
|
9
|
-
import { TableFeature } from './
|
|
3
|
+
import { TableFeature } from './table'
|
|
10
4
|
|
|
11
|
-
export type CoreHeaderGroup<
|
|
5
|
+
export type CoreHeaderGroup<TData extends RowData> = {
|
|
12
6
|
id: string
|
|
13
7
|
depth: number
|
|
14
|
-
headers: Header<
|
|
8
|
+
headers: Header<TData>[]
|
|
15
9
|
}
|
|
16
10
|
|
|
17
|
-
export type CoreHeader<
|
|
11
|
+
export type CoreHeader<TData extends RowData> = {
|
|
18
12
|
id: string
|
|
19
13
|
index: number
|
|
20
14
|
depth: number
|
|
21
|
-
column: Column<
|
|
22
|
-
headerGroup: HeaderGroup<
|
|
23
|
-
subHeaders: Header<
|
|
15
|
+
column: Column<TData>
|
|
16
|
+
headerGroup: HeaderGroup<TData>
|
|
17
|
+
subHeaders: Header<TData>[]
|
|
24
18
|
colSpan: number
|
|
25
19
|
rowSpan: number
|
|
26
|
-
getLeafHeaders: () => Header<
|
|
20
|
+
getLeafHeaders: () => Header<TData>[]
|
|
27
21
|
isPlaceholder: boolean
|
|
28
22
|
placeholderId?: string
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}) => string | null | TGenerics['Rendered']
|
|
23
|
+
getContext: () => {
|
|
24
|
+
table: Table<TData>
|
|
25
|
+
header: Header<TData>
|
|
26
|
+
column: Column<TData>
|
|
27
|
+
}
|
|
35
28
|
}
|
|
36
29
|
|
|
37
|
-
export type HeadersInstance<
|
|
38
|
-
getHeaderGroups: () => HeaderGroup<
|
|
39
|
-
getLeftHeaderGroups: () => HeaderGroup<
|
|
40
|
-
getCenterHeaderGroups: () => HeaderGroup<
|
|
41
|
-
getRightHeaderGroups: () => HeaderGroup<
|
|
42
|
-
|
|
43
|
-
getFooterGroups: () => HeaderGroup<
|
|
44
|
-
getLeftFooterGroups: () => HeaderGroup<
|
|
45
|
-
getCenterFooterGroups: () => HeaderGroup<
|
|
46
|
-
getRightFooterGroups: () => HeaderGroup<
|
|
47
|
-
|
|
48
|
-
getFlatHeaders: () => Header<
|
|
49
|
-
getLeftFlatHeaders: () => Header<
|
|
50
|
-
getCenterFlatHeaders: () => Header<
|
|
51
|
-
getRightFlatHeaders: () => Header<
|
|
52
|
-
|
|
53
|
-
getLeafHeaders: () => Header<
|
|
54
|
-
getLeftLeafHeaders: () => Header<
|
|
55
|
-
getCenterLeafHeaders: () => Header<
|
|
56
|
-
getRightLeafHeaders: () => Header<
|
|
30
|
+
export type HeadersInstance<TData extends RowData> = {
|
|
31
|
+
getHeaderGroups: () => HeaderGroup<TData>[]
|
|
32
|
+
getLeftHeaderGroups: () => HeaderGroup<TData>[]
|
|
33
|
+
getCenterHeaderGroups: () => HeaderGroup<TData>[]
|
|
34
|
+
getRightHeaderGroups: () => HeaderGroup<TData>[]
|
|
35
|
+
|
|
36
|
+
getFooterGroups: () => HeaderGroup<TData>[]
|
|
37
|
+
getLeftFooterGroups: () => HeaderGroup<TData>[]
|
|
38
|
+
getCenterFooterGroups: () => HeaderGroup<TData>[]
|
|
39
|
+
getRightFooterGroups: () => HeaderGroup<TData>[]
|
|
40
|
+
|
|
41
|
+
getFlatHeaders: () => Header<TData>[]
|
|
42
|
+
getLeftFlatHeaders: () => Header<TData>[]
|
|
43
|
+
getCenterFlatHeaders: () => Header<TData>[]
|
|
44
|
+
getRightFlatHeaders: () => Header<TData>[]
|
|
45
|
+
|
|
46
|
+
getLeafHeaders: () => Header<TData>[]
|
|
47
|
+
getLeftLeafHeaders: () => Header<TData>[]
|
|
48
|
+
getCenterLeafHeaders: () => Header<TData>[]
|
|
49
|
+
getRightLeafHeaders: () => Header<TData>[]
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
//
|
|
60
53
|
|
|
61
|
-
function createHeader<
|
|
62
|
-
|
|
63
|
-
column: Column<
|
|
54
|
+
function createHeader<TData extends RowData>(
|
|
55
|
+
table: Table<TData>,
|
|
56
|
+
column: Column<TData>,
|
|
64
57
|
options: {
|
|
65
58
|
id?: string
|
|
66
59
|
isPlaceholder?: boolean
|
|
@@ -71,7 +64,7 @@ function createHeader<TGenerics extends TableGenerics>(
|
|
|
71
64
|
) {
|
|
72
65
|
const id = options.id ?? column.id
|
|
73
66
|
|
|
74
|
-
let header: CoreHeader<
|
|
67
|
+
let header: CoreHeader<TData> = {
|
|
75
68
|
id,
|
|
76
69
|
column,
|
|
77
70
|
index: options.index,
|
|
@@ -82,10 +75,10 @@ function createHeader<TGenerics extends TableGenerics>(
|
|
|
82
75
|
colSpan: 0,
|
|
83
76
|
rowSpan: 0,
|
|
84
77
|
headerGroup: null!,
|
|
85
|
-
getLeafHeaders: (): Header<
|
|
86
|
-
const leafHeaders: CoreHeader<
|
|
78
|
+
getLeafHeaders: (): Header<TData>[] => {
|
|
79
|
+
const leafHeaders: CoreHeader<TData>[] = []
|
|
87
80
|
|
|
88
|
-
const recurseHeader = (h: CoreHeader<
|
|
81
|
+
const recurseHeader = (h: CoreHeader<TData>) => {
|
|
89
82
|
if (h.subHeaders && h.subHeaders.length) {
|
|
90
83
|
h.subHeaders.map(recurseHeader)
|
|
91
84
|
}
|
|
@@ -94,46 +87,35 @@ function createHeader<TGenerics extends TableGenerics>(
|
|
|
94
87
|
|
|
95
88
|
recurseHeader(header)
|
|
96
89
|
|
|
97
|
-
return leafHeaders as Header<
|
|
90
|
+
return leafHeaders as Header<TData>[]
|
|
98
91
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
column,
|
|
105
|
-
})
|
|
106
|
-
: null,
|
|
107
|
-
renderFooter: () =>
|
|
108
|
-
column.columnDef.footer
|
|
109
|
-
? instance._render(column.columnDef.footer, {
|
|
110
|
-
instance,
|
|
111
|
-
header: header as Header<TGenerics>,
|
|
112
|
-
column,
|
|
113
|
-
})
|
|
114
|
-
: null,
|
|
92
|
+
getContext: () => ({
|
|
93
|
+
table,
|
|
94
|
+
header: header as Header<TData>,
|
|
95
|
+
column,
|
|
96
|
+
}),
|
|
115
97
|
}
|
|
116
98
|
|
|
117
|
-
|
|
118
|
-
Object.assign(header, feature.createHeader?.(header,
|
|
99
|
+
table._features.forEach(feature => {
|
|
100
|
+
Object.assign(header, feature.createHeader?.(header, table))
|
|
119
101
|
})
|
|
120
102
|
|
|
121
|
-
return header as Header<
|
|
103
|
+
return header as Header<TData>
|
|
122
104
|
}
|
|
123
105
|
|
|
124
106
|
export const Headers: TableFeature = {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
): HeadersInstance<
|
|
107
|
+
createTable: <TData extends RowData>(
|
|
108
|
+
table: Table<TData>
|
|
109
|
+
): HeadersInstance<TData> => {
|
|
128
110
|
return {
|
|
129
111
|
// Header Groups
|
|
130
112
|
|
|
131
113
|
getHeaderGroups: memo(
|
|
132
114
|
() => [
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
115
|
+
table.getAllColumns(),
|
|
116
|
+
table.getVisibleLeafColumns(),
|
|
117
|
+
table.getState().columnPinning.left,
|
|
118
|
+
table.getState().columnPinning.right,
|
|
137
119
|
],
|
|
138
120
|
(allColumns, leafColumns, left, right) => {
|
|
139
121
|
const leftColumns =
|
|
@@ -153,44 +135,42 @@ export const Headers: TableFeature = {
|
|
|
153
135
|
const headerGroups = buildHeaderGroups(
|
|
154
136
|
allColumns,
|
|
155
137
|
[...leftColumns, ...centerColumns, ...rightColumns],
|
|
156
|
-
|
|
138
|
+
table
|
|
157
139
|
)
|
|
158
140
|
|
|
159
141
|
return headerGroups
|
|
160
142
|
},
|
|
161
143
|
{
|
|
162
144
|
key: process.env.NODE_ENV === 'development' && 'getHeaderGroups',
|
|
163
|
-
debug: () =>
|
|
164
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
145
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
165
146
|
}
|
|
166
147
|
),
|
|
167
148
|
|
|
168
149
|
getCenterHeaderGroups: memo(
|
|
169
150
|
() => [
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
151
|
+
table.getAllColumns(),
|
|
152
|
+
table.getVisibleLeafColumns(),
|
|
153
|
+
table.getState().columnPinning.left,
|
|
154
|
+
table.getState().columnPinning.right,
|
|
174
155
|
],
|
|
175
156
|
(allColumns, leafColumns, left, right) => {
|
|
176
157
|
leafColumns = leafColumns.filter(
|
|
177
158
|
column => !left?.includes(column.id) && !right?.includes(column.id)
|
|
178
159
|
)
|
|
179
|
-
return buildHeaderGroups(allColumns, leafColumns,
|
|
160
|
+
return buildHeaderGroups(allColumns, leafColumns, table, 'center')
|
|
180
161
|
},
|
|
181
162
|
{
|
|
182
163
|
key:
|
|
183
164
|
process.env.NODE_ENV === 'development' && 'getCenterHeaderGroups',
|
|
184
|
-
debug: () =>
|
|
185
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
165
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
186
166
|
}
|
|
187
167
|
),
|
|
188
168
|
|
|
189
169
|
getLeftHeaderGroups: memo(
|
|
190
170
|
() => [
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
171
|
+
table.getAllColumns(),
|
|
172
|
+
table.getVisibleLeafColumns(),
|
|
173
|
+
table.getState().columnPinning.left,
|
|
194
174
|
],
|
|
195
175
|
(allColumns, leafColumns, left) => {
|
|
196
176
|
const orderedLeafColumns =
|
|
@@ -201,22 +181,21 @@ export const Headers: TableFeature = {
|
|
|
201
181
|
return buildHeaderGroups(
|
|
202
182
|
allColumns,
|
|
203
183
|
orderedLeafColumns,
|
|
204
|
-
|
|
184
|
+
table,
|
|
205
185
|
'left'
|
|
206
186
|
)
|
|
207
187
|
},
|
|
208
188
|
{
|
|
209
189
|
key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
|
|
210
|
-
debug: () =>
|
|
211
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
190
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
212
191
|
}
|
|
213
192
|
),
|
|
214
193
|
|
|
215
194
|
getRightHeaderGroups: memo(
|
|
216
195
|
() => [
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
196
|
+
table.getAllColumns(),
|
|
197
|
+
table.getVisibleLeafColumns(),
|
|
198
|
+
table.getState().columnPinning.right,
|
|
220
199
|
],
|
|
221
200
|
(allColumns, leafColumns, right) => {
|
|
222
201
|
const orderedLeafColumns =
|
|
@@ -227,72 +206,67 @@ export const Headers: TableFeature = {
|
|
|
227
206
|
return buildHeaderGroups(
|
|
228
207
|
allColumns,
|
|
229
208
|
orderedLeafColumns,
|
|
230
|
-
|
|
209
|
+
table,
|
|
231
210
|
'right'
|
|
232
211
|
)
|
|
233
212
|
},
|
|
234
213
|
{
|
|
235
214
|
key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
|
|
236
|
-
debug: () =>
|
|
237
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
215
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
238
216
|
}
|
|
239
217
|
),
|
|
240
218
|
|
|
241
219
|
// Footer Groups
|
|
242
220
|
|
|
243
221
|
getFooterGroups: memo(
|
|
244
|
-
() => [
|
|
222
|
+
() => [table.getHeaderGroups()],
|
|
245
223
|
headerGroups => {
|
|
246
224
|
return [...headerGroups].reverse()
|
|
247
225
|
},
|
|
248
226
|
{
|
|
249
227
|
key: process.env.NODE_ENV === 'development' && 'getFooterGroups',
|
|
250
|
-
debug: () =>
|
|
251
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
228
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
252
229
|
}
|
|
253
230
|
),
|
|
254
231
|
|
|
255
232
|
getLeftFooterGroups: memo(
|
|
256
|
-
() => [
|
|
233
|
+
() => [table.getLeftHeaderGroups()],
|
|
257
234
|
headerGroups => {
|
|
258
235
|
return [...headerGroups].reverse()
|
|
259
236
|
},
|
|
260
237
|
{
|
|
261
238
|
key: process.env.NODE_ENV === 'development' && 'getLeftFooterGroups',
|
|
262
|
-
debug: () =>
|
|
263
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
239
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
264
240
|
}
|
|
265
241
|
),
|
|
266
242
|
|
|
267
243
|
getCenterFooterGroups: memo(
|
|
268
|
-
() => [
|
|
244
|
+
() => [table.getCenterHeaderGroups()],
|
|
269
245
|
headerGroups => {
|
|
270
246
|
return [...headerGroups].reverse()
|
|
271
247
|
},
|
|
272
248
|
{
|
|
273
249
|
key:
|
|
274
250
|
process.env.NODE_ENV === 'development' && 'getCenterFooterGroups',
|
|
275
|
-
debug: () =>
|
|
276
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
251
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
277
252
|
}
|
|
278
253
|
),
|
|
279
254
|
|
|
280
255
|
getRightFooterGroups: memo(
|
|
281
|
-
() => [
|
|
256
|
+
() => [table.getRightHeaderGroups()],
|
|
282
257
|
headerGroups => {
|
|
283
258
|
return [...headerGroups].reverse()
|
|
284
259
|
},
|
|
285
260
|
{
|
|
286
261
|
key: process.env.NODE_ENV === 'development' && 'getRightFooterGroups',
|
|
287
|
-
debug: () =>
|
|
288
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
262
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
289
263
|
}
|
|
290
264
|
),
|
|
291
265
|
|
|
292
266
|
// Flat Headers
|
|
293
267
|
|
|
294
268
|
getFlatHeaders: memo(
|
|
295
|
-
() => [
|
|
269
|
+
() => [table.getHeaderGroups()],
|
|
296
270
|
headerGroups => {
|
|
297
271
|
return headerGroups
|
|
298
272
|
.map(headerGroup => {
|
|
@@ -302,13 +276,12 @@ export const Headers: TableFeature = {
|
|
|
302
276
|
},
|
|
303
277
|
{
|
|
304
278
|
key: process.env.NODE_ENV === 'development' && 'getFlatHeaders',
|
|
305
|
-
debug: () =>
|
|
306
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
279
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
307
280
|
}
|
|
308
281
|
),
|
|
309
282
|
|
|
310
283
|
getLeftFlatHeaders: memo(
|
|
311
|
-
() => [
|
|
284
|
+
() => [table.getLeftHeaderGroups()],
|
|
312
285
|
left => {
|
|
313
286
|
return left
|
|
314
287
|
.map(headerGroup => {
|
|
@@ -318,13 +291,12 @@ export const Headers: TableFeature = {
|
|
|
318
291
|
},
|
|
319
292
|
{
|
|
320
293
|
key: process.env.NODE_ENV === 'development' && 'getLeftFlatHeaders',
|
|
321
|
-
debug: () =>
|
|
322
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
294
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
323
295
|
}
|
|
324
296
|
),
|
|
325
297
|
|
|
326
298
|
getCenterFlatHeaders: memo(
|
|
327
|
-
() => [
|
|
299
|
+
() => [table.getCenterHeaderGroups()],
|
|
328
300
|
left => {
|
|
329
301
|
return left
|
|
330
302
|
.map(headerGroup => {
|
|
@@ -334,13 +306,12 @@ export const Headers: TableFeature = {
|
|
|
334
306
|
},
|
|
335
307
|
{
|
|
336
308
|
key: process.env.NODE_ENV === 'development' && 'getCenterFlatHeaders',
|
|
337
|
-
debug: () =>
|
|
338
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
309
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
339
310
|
}
|
|
340
311
|
),
|
|
341
312
|
|
|
342
313
|
getRightFlatHeaders: memo(
|
|
343
|
-
() => [
|
|
314
|
+
() => [table.getRightHeaderGroups()],
|
|
344
315
|
left => {
|
|
345
316
|
return left
|
|
346
317
|
.map(headerGroup => {
|
|
@@ -350,54 +321,50 @@ export const Headers: TableFeature = {
|
|
|
350
321
|
},
|
|
351
322
|
{
|
|
352
323
|
key: process.env.NODE_ENV === 'development' && 'getRightFlatHeaders',
|
|
353
|
-
debug: () =>
|
|
354
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
324
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
355
325
|
}
|
|
356
326
|
),
|
|
357
327
|
|
|
358
328
|
// Leaf Headers
|
|
359
329
|
|
|
360
330
|
getCenterLeafHeaders: memo(
|
|
361
|
-
() => [
|
|
331
|
+
() => [table.getCenterFlatHeaders()],
|
|
362
332
|
flatHeaders => {
|
|
363
333
|
return flatHeaders.filter(header => !header.subHeaders?.length)
|
|
364
334
|
},
|
|
365
335
|
{
|
|
366
336
|
key: process.env.NODE_ENV === 'development' && 'getCenterLeafHeaders',
|
|
367
|
-
debug: () =>
|
|
368
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
337
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
369
338
|
}
|
|
370
339
|
),
|
|
371
340
|
|
|
372
341
|
getLeftLeafHeaders: memo(
|
|
373
|
-
() => [
|
|
342
|
+
() => [table.getLeftFlatHeaders()],
|
|
374
343
|
flatHeaders => {
|
|
375
344
|
return flatHeaders.filter(header => !header.subHeaders?.length)
|
|
376
345
|
},
|
|
377
346
|
{
|
|
378
347
|
key: process.env.NODE_ENV === 'development' && 'getLeftLeafHeaders',
|
|
379
|
-
debug: () =>
|
|
380
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
348
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
381
349
|
}
|
|
382
350
|
),
|
|
383
351
|
|
|
384
352
|
getRightLeafHeaders: memo(
|
|
385
|
-
() => [
|
|
353
|
+
() => [table.getRightFlatHeaders()],
|
|
386
354
|
flatHeaders => {
|
|
387
355
|
return flatHeaders.filter(header => !header.subHeaders?.length)
|
|
388
356
|
},
|
|
389
357
|
{
|
|
390
358
|
key: process.env.NODE_ENV === 'development' && 'getRightLeafHeaders',
|
|
391
|
-
debug: () =>
|
|
392
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
359
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
393
360
|
}
|
|
394
361
|
),
|
|
395
362
|
|
|
396
363
|
getLeafHeaders: memo(
|
|
397
364
|
() => [
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
365
|
+
table.getLeftHeaderGroups(),
|
|
366
|
+
table.getCenterHeaderGroups(),
|
|
367
|
+
table.getRightHeaderGroups(),
|
|
401
368
|
],
|
|
402
369
|
(left, center, right) => {
|
|
403
370
|
return [
|
|
@@ -412,18 +379,17 @@ export const Headers: TableFeature = {
|
|
|
412
379
|
},
|
|
413
380
|
{
|
|
414
381
|
key: process.env.NODE_ENV === 'development' && 'getLeafHeaders',
|
|
415
|
-
debug: () =>
|
|
416
|
-
instance.options.debugAll ?? instance.options.debugHeaders,
|
|
382
|
+
debug: () => table.options.debugAll ?? table.options.debugHeaders,
|
|
417
383
|
}
|
|
418
384
|
),
|
|
419
385
|
}
|
|
420
386
|
},
|
|
421
387
|
}
|
|
422
388
|
|
|
423
|
-
export function buildHeaderGroups<
|
|
424
|
-
allColumns: Column<
|
|
425
|
-
columnsToGroup: Column<
|
|
426
|
-
|
|
389
|
+
export function buildHeaderGroups<TData extends RowData>(
|
|
390
|
+
allColumns: Column<TData>[],
|
|
391
|
+
columnsToGroup: Column<TData>[],
|
|
392
|
+
table: Table<TData>,
|
|
427
393
|
headerFamily?: 'center' | 'left' | 'right'
|
|
428
394
|
) {
|
|
429
395
|
// Find the max depth of the columns:
|
|
@@ -434,7 +400,7 @@ export function buildHeaderGroups<TGenerics extends TableGenerics>(
|
|
|
434
400
|
|
|
435
401
|
let maxDepth = 0
|
|
436
402
|
|
|
437
|
-
const findMaxDepth = (columns: Column<
|
|
403
|
+
const findMaxDepth = (columns: Column<TData>[], depth = 1) => {
|
|
438
404
|
maxDepth = Math.max(maxDepth, depth)
|
|
439
405
|
|
|
440
406
|
columns
|
|
@@ -448,21 +414,21 @@ export function buildHeaderGroups<TGenerics extends TableGenerics>(
|
|
|
448
414
|
|
|
449
415
|
findMaxDepth(allColumns)
|
|
450
416
|
|
|
451
|
-
let headerGroups: HeaderGroup<
|
|
417
|
+
let headerGroups: HeaderGroup<TData>[] = []
|
|
452
418
|
|
|
453
419
|
const createHeaderGroup = (
|
|
454
|
-
headersToGroup: Header<
|
|
420
|
+
headersToGroup: Header<TData>[],
|
|
455
421
|
depth: number
|
|
456
422
|
) => {
|
|
457
423
|
// The header group we are creating
|
|
458
|
-
const headerGroup: HeaderGroup<
|
|
424
|
+
const headerGroup: HeaderGroup<TData> = {
|
|
459
425
|
depth,
|
|
460
426
|
id: [headerFamily, `${depth}`].filter(Boolean).join('_'),
|
|
461
427
|
headers: [],
|
|
462
428
|
}
|
|
463
429
|
|
|
464
430
|
// The parent columns we're going to scan next
|
|
465
|
-
const pendingParentHeaders: Header<
|
|
431
|
+
const pendingParentHeaders: Header<TData>[] = []
|
|
466
432
|
|
|
467
433
|
// Scan each column for parents
|
|
468
434
|
headersToGroup.forEach(headerToGroup => {
|
|
@@ -472,7 +438,7 @@ export function buildHeaderGroups<TGenerics extends TableGenerics>(
|
|
|
472
438
|
|
|
473
439
|
const isLeafHeader = headerToGroup.column.depth === headerGroup.depth
|
|
474
440
|
|
|
475
|
-
let column: Column<
|
|
441
|
+
let column: Column<TData>
|
|
476
442
|
let isPlaceholder = false
|
|
477
443
|
|
|
478
444
|
if (isLeafHeader && headerToGroup.column.parent) {
|
|
@@ -484,12 +450,15 @@ export function buildHeaderGroups<TGenerics extends TableGenerics>(
|
|
|
484
450
|
isPlaceholder = true
|
|
485
451
|
}
|
|
486
452
|
|
|
487
|
-
if (
|
|
453
|
+
if (
|
|
454
|
+
latestPendingParentHeader &&
|
|
455
|
+
latestPendingParentHeader?.column === column
|
|
456
|
+
) {
|
|
488
457
|
// This column is repeated. Add it as a sub header to the next batch
|
|
489
458
|
latestPendingParentHeader.subHeaders.push(headerToGroup)
|
|
490
459
|
} else {
|
|
491
460
|
// This is a new header. Let's create it
|
|
492
|
-
const header = createHeader(
|
|
461
|
+
const header = createHeader(table, column, {
|
|
493
462
|
id: [headerFamily, depth, column.id, headerToGroup?.id]
|
|
494
463
|
.filter(Boolean)
|
|
495
464
|
.join('_'),
|
|
@@ -520,7 +489,7 @@ export function buildHeaderGroups<TGenerics extends TableGenerics>(
|
|
|
520
489
|
}
|
|
521
490
|
|
|
522
491
|
const bottomHeaders = columnsToGroup.map((column, index) =>
|
|
523
|
-
createHeader(
|
|
492
|
+
createHeader(table, column, {
|
|
524
493
|
depth: maxDepth,
|
|
525
494
|
index,
|
|
526
495
|
})
|
|
@@ -535,7 +504,7 @@ export function buildHeaderGroups<TGenerics extends TableGenerics>(
|
|
|
535
504
|
// })
|
|
536
505
|
|
|
537
506
|
const recurseHeadersForSpans = (
|
|
538
|
-
headers: Header<
|
|
507
|
+
headers: Header<TData>[]
|
|
539
508
|
): { colSpan: number; rowSpan: number }[] => {
|
|
540
509
|
const filteredHeaders = headers.filter(header =>
|
|
541
510
|
header.column.getIsVisible()
|
package/src/core/row.ts
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import { Cell, Row, TableGenerics,
|
|
1
|
+
import { RowData, Cell, Row, TableGenerics, Table } from '../types'
|
|
2
2
|
import { flattenBy, memo } from '../utils'
|
|
3
3
|
import { createCell } from './cell'
|
|
4
4
|
|
|
5
|
-
export type CoreRow<
|
|
5
|
+
export type CoreRow<TData extends RowData> = {
|
|
6
6
|
id: string
|
|
7
7
|
index: number
|
|
8
|
-
original?:
|
|
8
|
+
original?: TData
|
|
9
9
|
depth: number
|
|
10
10
|
_valuesCache: Record<string, any>
|
|
11
11
|
getValue: (columnId: string) => any
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
renderValue: (columnId: string) => unknown
|
|
13
|
+
subRows: Row<TData>[]
|
|
14
|
+
getLeafRows: () => Row<TData>[]
|
|
15
|
+
originalSubRows?: TData[]
|
|
16
|
+
getAllCells: () => Cell<TData>[]
|
|
17
|
+
_getAllCellsByColumnId: () => Record<string, Cell<TData>>
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
export const createRow = <
|
|
20
|
-
|
|
20
|
+
export const createRow = <TData extends RowData>(
|
|
21
|
+
table: Table<TData>,
|
|
21
22
|
id: string,
|
|
22
|
-
original:
|
|
23
|
+
original: TData | undefined,
|
|
23
24
|
rowIndex: number,
|
|
24
25
|
depth: number,
|
|
25
|
-
subRows?: Row<
|
|
26
|
-
): Row<
|
|
27
|
-
let row: CoreRow<
|
|
26
|
+
subRows?: Row<TData>[]
|
|
27
|
+
): Row<TData> => {
|
|
28
|
+
let row: CoreRow<TData> = {
|
|
28
29
|
id,
|
|
29
30
|
index: rowIndex,
|
|
30
31
|
original,
|
|
@@ -35,28 +36,33 @@ export const createRow = <TGenerics extends TableGenerics>(
|
|
|
35
36
|
return row._valuesCache[columnId]
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
const column =
|
|
39
|
+
const column = table.getColumn(columnId)
|
|
39
40
|
|
|
40
41
|
if (!column.accessorFn) {
|
|
41
42
|
return undefined
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
row._valuesCache[columnId] = column.accessorFn(
|
|
45
|
+
row._valuesCache[columnId] = column.accessorFn(
|
|
46
|
+
row.original as TData,
|
|
47
|
+
rowIndex
|
|
48
|
+
)
|
|
45
49
|
|
|
46
50
|
return row._valuesCache[columnId]
|
|
47
51
|
},
|
|
52
|
+
renderValue: columnId =>
|
|
53
|
+
row.getValue(columnId) ?? table.options.renderFallbackValue,
|
|
48
54
|
subRows: subRows ?? [],
|
|
49
55
|
getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
|
|
50
56
|
getAllCells: memo(
|
|
51
|
-
() => [
|
|
57
|
+
() => [table.getAllLeafColumns()],
|
|
52
58
|
leafColumns => {
|
|
53
59
|
return leafColumns.map(column => {
|
|
54
|
-
return createCell(
|
|
60
|
+
return createCell(table, row as Row<TData>, column, column.id)
|
|
55
61
|
})
|
|
56
62
|
},
|
|
57
63
|
{
|
|
58
64
|
key: process.env.NODE_ENV === 'development' && 'row.getAllCells',
|
|
59
|
-
debug: () =>
|
|
65
|
+
debug: () => table.options.debugAll ?? table.options.debugRows,
|
|
60
66
|
}
|
|
61
67
|
),
|
|
62
68
|
|
|
@@ -66,20 +72,20 @@ export const createRow = <TGenerics extends TableGenerics>(
|
|
|
66
72
|
return allCells.reduce((acc, cell) => {
|
|
67
73
|
acc[cell.column.id] = cell
|
|
68
74
|
return acc
|
|
69
|
-
}, {} as Record<string, Cell<
|
|
75
|
+
}, {} as Record<string, Cell<TData>>)
|
|
70
76
|
},
|
|
71
77
|
{
|
|
72
78
|
key:
|
|
73
79
|
process.env.NODE_ENV === 'production' && 'row.getAllCellsByColumnId',
|
|
74
|
-
debug: () =>
|
|
80
|
+
debug: () => table.options.debugAll ?? table.options.debugRows,
|
|
75
81
|
}
|
|
76
82
|
),
|
|
77
83
|
}
|
|
78
84
|
|
|
79
|
-
for (let i = 0; i <
|
|
80
|
-
const feature =
|
|
81
|
-
Object.assign(row, feature?.createRow?.(row,
|
|
85
|
+
for (let i = 0; i < table._features.length; i++) {
|
|
86
|
+
const feature = table._features[i]
|
|
87
|
+
Object.assign(row, feature?.createRow?.(row, table))
|
|
82
88
|
}
|
|
83
89
|
|
|
84
|
-
return row as Row<
|
|
90
|
+
return row as Row<TData>
|
|
85
91
|
}
|