@tanstack/table-core 8.0.0-alpha.71 → 8.0.0-alpha.74
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.js +3 -94
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/features/Cells.js +1 -1
- package/build/cjs/features/Cells.js.map +1 -1
- package/build/cjs/features/Expanding.js +4 -2
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Grouping.js +1 -1
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +2 -2
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Pagination.js +8 -9
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js +31 -45
- package/build/cjs/utils/getCoreRowModel.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +1 -1
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/esm/index.js +51 -155
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +307 -307
- package/build/types/core.d.ts +2 -3
- package/build/types/features/Pagination.d.ts +0 -1
- package/build/umd/index.development.js +51 -155
- 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.ts +6 -113
- package/src/features/Cells.ts +1 -1
- package/src/features/Expanding.ts +2 -2
- package/src/features/Grouping.ts +1 -1
- package/src/features/Headers.ts +2 -2
- package/src/features/Pagination.ts +6 -11
- package/src/utils/getCoreRowModel.ts +42 -55
- package/src/utils/getGroupedRowModel.ts +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.0-alpha.
|
|
4
|
+
"version": "8.0.0-alpha.74",
|
|
5
5
|
"description": "Hooks for building lightweight, fast and extendable datagrids for React",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/react-table#readme",
|
package/src/core.ts
CHANGED
|
@@ -44,8 +44,8 @@ export type CoreOptions<TGenerics extends TableGenerics> = {
|
|
|
44
44
|
initialState?: InitialTableState
|
|
45
45
|
autoResetAll?: boolean
|
|
46
46
|
mergeOptions?: <T>(defaultOptions: T, options: Partial<T>) => T
|
|
47
|
-
keepPreviousData?: boolean
|
|
48
47
|
meta?: TGenerics['TableMeta']
|
|
48
|
+
// keepPreviousData?: boolean
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export type CoreInstance<TGenerics extends TableGenerics> = {
|
|
@@ -54,20 +54,20 @@ export type CoreInstance<TGenerics extends TableGenerics> = {
|
|
|
54
54
|
reset: () => void
|
|
55
55
|
options: RequiredKeys<TableOptions<TGenerics>, 'state'>
|
|
56
56
|
setOptions: (newOptions: Updater<TableOptions<TGenerics>>) => void
|
|
57
|
-
queue: (cb: () => void) => void
|
|
58
57
|
getState: () => TableState
|
|
59
58
|
setState: (updater: Updater<TableState>) => void
|
|
60
|
-
|
|
59
|
+
_queue: (cb: () => void) => void
|
|
60
|
+
_render: <TProps>(
|
|
61
61
|
template: Renderable<TGenerics, TProps>,
|
|
62
62
|
props: TProps
|
|
63
63
|
) => string | null | TGenerics['Rendered']
|
|
64
|
+
_features: readonly TableFeature[]
|
|
64
65
|
// getOverallProgress: () => number
|
|
65
66
|
// getProgressStage: () =>
|
|
66
67
|
// | undefined
|
|
67
68
|
// | 'coreRowModel'
|
|
68
69
|
// | 'filteredRowModel'
|
|
69
70
|
// | 'facetedRowModel'
|
|
70
|
-
_features: readonly TableFeature[]
|
|
71
71
|
// createBatch: (priority: keyof CoreBatches) => Batch
|
|
72
72
|
// init: () => void
|
|
73
73
|
// willUpdate: () => void
|
|
@@ -88,8 +88,6 @@ export type CoreInstance<TGenerics extends TableGenerics> = {
|
|
|
88
88
|
// facets: Batch[]
|
|
89
89
|
// }
|
|
90
90
|
|
|
91
|
-
// export type TaskPriority = keyof CoreBatches
|
|
92
|
-
|
|
93
91
|
export function createTableInstance<TGenerics extends TableGenerics>(
|
|
94
92
|
options: TableOptions<TGenerics>
|
|
95
93
|
): TableInstance<TGenerics> {
|
|
@@ -147,74 +145,6 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
147
145
|
const queued: (() => void)[] = []
|
|
148
146
|
let queuedTimeout = false
|
|
149
147
|
|
|
150
|
-
// let workScheduled = false
|
|
151
|
-
// let working = false
|
|
152
|
-
// let latestCallback: ReturnType<typeof requestIdleCallback>
|
|
153
|
-
// let batchUid = 0
|
|
154
|
-
// const onProgress = () => {}
|
|
155
|
-
// const getBatch = () => {
|
|
156
|
-
// instance.batches.data = instance.batches.data.filter(d => d.tasks.length)
|
|
157
|
-
// instance.batches.facets = instance.batches.facets.filter(
|
|
158
|
-
// d => d.tasks.length
|
|
159
|
-
// )
|
|
160
|
-
|
|
161
|
-
// return (
|
|
162
|
-
// instance.batches.data.find(d => d.tasks.length) ??
|
|
163
|
-
// instance.batches.facets.find(d => d.tasks.length)
|
|
164
|
-
// )
|
|
165
|
-
// }
|
|
166
|
-
|
|
167
|
-
// const startWorkLoop = () => {
|
|
168
|
-
// working = true
|
|
169
|
-
|
|
170
|
-
// const workLoop = (deadline: IdleDeadline) => {
|
|
171
|
-
// const batch = getBatch()
|
|
172
|
-
|
|
173
|
-
// if (!batch) {
|
|
174
|
-
// working = false
|
|
175
|
-
// return
|
|
176
|
-
// }
|
|
177
|
-
// // Prioritize tasks
|
|
178
|
-
// while (deadline.timeRemaining() > 0 && batch.tasks.length) {
|
|
179
|
-
// batch.tasks.shift()!()
|
|
180
|
-
// }
|
|
181
|
-
|
|
182
|
-
// onProgress()
|
|
183
|
-
|
|
184
|
-
// if (working) {
|
|
185
|
-
// latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
|
|
186
|
-
// }
|
|
187
|
-
// }
|
|
188
|
-
|
|
189
|
-
// latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
|
|
190
|
-
// }
|
|
191
|
-
|
|
192
|
-
// const startWork = () => {
|
|
193
|
-
// if (getBatch() && !working) {
|
|
194
|
-
// if (
|
|
195
|
-
// (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
|
|
196
|
-
// instance.options.debugTable
|
|
197
|
-
// ) {
|
|
198
|
-
// console.info('Starting work...')
|
|
199
|
-
// }
|
|
200
|
-
// startWorkLoop()
|
|
201
|
-
// }
|
|
202
|
-
// }
|
|
203
|
-
|
|
204
|
-
// const stopWork = () => {
|
|
205
|
-
// if (working) {
|
|
206
|
-
// if (
|
|
207
|
-
// (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
|
|
208
|
-
// instance.options.debugTable
|
|
209
|
-
// ) {
|
|
210
|
-
// console.info('Stopping work...')
|
|
211
|
-
// }
|
|
212
|
-
|
|
213
|
-
// working = false
|
|
214
|
-
// cancelIdleCallback(latestCallback)
|
|
215
|
-
// }
|
|
216
|
-
// }
|
|
217
|
-
|
|
218
148
|
const midInstance: CoreInstance<TGenerics> = {
|
|
219
149
|
...instance,
|
|
220
150
|
// init: () => {
|
|
@@ -231,7 +161,7 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
231
161
|
...options,
|
|
232
162
|
},
|
|
233
163
|
initialState,
|
|
234
|
-
|
|
164
|
+
_queue: cb => {
|
|
235
165
|
queued.push(cb)
|
|
236
166
|
|
|
237
167
|
if (!queuedTimeout) {
|
|
@@ -253,43 +183,6 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
253
183
|
)
|
|
254
184
|
}
|
|
255
185
|
},
|
|
256
|
-
// batches: {
|
|
257
|
-
// data: [],
|
|
258
|
-
// facets: [],
|
|
259
|
-
// },
|
|
260
|
-
// createBatch: priority => {
|
|
261
|
-
// const batchId = batchUid++
|
|
262
|
-
// let canceled: boolean
|
|
263
|
-
|
|
264
|
-
// const batch: Batch = {
|
|
265
|
-
// id: batchId,
|
|
266
|
-
// priority,
|
|
267
|
-
// tasks: [],
|
|
268
|
-
// schedule: cb => {
|
|
269
|
-
// if (canceled) return
|
|
270
|
-
// batch.tasks.push(cb)
|
|
271
|
-
|
|
272
|
-
// if (!working && !workScheduled) {
|
|
273
|
-
// workScheduled = true
|
|
274
|
-
// instance.queue(() => {
|
|
275
|
-
// workScheduled = false
|
|
276
|
-
// instance.setState(old => ({ ...old }))
|
|
277
|
-
// })
|
|
278
|
-
// }
|
|
279
|
-
// },
|
|
280
|
-
// cancel: () => {
|
|
281
|
-
// canceled = true
|
|
282
|
-
// batch.tasks = []
|
|
283
|
-
// instance.batches[priority] = instance.batches[priority].filter(
|
|
284
|
-
// b => b.id !== batchId
|
|
285
|
-
// )
|
|
286
|
-
// },
|
|
287
|
-
// }
|
|
288
|
-
|
|
289
|
-
// instance.batches[priority].push(batch)
|
|
290
|
-
|
|
291
|
-
// return batch
|
|
292
|
-
// },
|
|
293
186
|
reset: () => {
|
|
294
187
|
instance.setState(instance.initialState)
|
|
295
188
|
},
|
|
@@ -297,7 +190,7 @@ export function createTableInstance<TGenerics extends TableGenerics>(
|
|
|
297
190
|
const newOptions = functionalUpdate(updater, instance.options)
|
|
298
191
|
instance.options = mergeOptions(newOptions)
|
|
299
192
|
},
|
|
300
|
-
|
|
193
|
+
_render: (template, props) => {
|
|
301
194
|
if (typeof instance.options.render === 'function') {
|
|
302
195
|
return instance.options.render(template, props)
|
|
303
196
|
}
|
package/src/features/Cells.ts
CHANGED
|
@@ -82,7 +82,7 @@ export const Expanding: TableFeature = {
|
|
|
82
82
|
return {
|
|
83
83
|
_autoResetExpanded: () => {
|
|
84
84
|
if (!registered) {
|
|
85
|
-
instance.
|
|
85
|
+
instance._queue(() => {
|
|
86
86
|
registered = true
|
|
87
87
|
})
|
|
88
88
|
return
|
|
@@ -98,7 +98,7 @@ export const Expanding: TableFeature = {
|
|
|
98
98
|
) {
|
|
99
99
|
if (queued) return
|
|
100
100
|
queued = true
|
|
101
|
-
instance.
|
|
101
|
+
instance._queue(() => {
|
|
102
102
|
instance.resetExpanded()
|
|
103
103
|
queued = false
|
|
104
104
|
})
|
package/src/features/Grouping.ts
CHANGED
package/src/features/Headers.ts
CHANGED
|
@@ -88,7 +88,7 @@ export const Headers = {
|
|
|
88
88
|
},
|
|
89
89
|
renderHeader: () =>
|
|
90
90
|
column.header
|
|
91
|
-
? instance.
|
|
91
|
+
? instance._render(column.header, {
|
|
92
92
|
instance,
|
|
93
93
|
header: header as Header<TGenerics>,
|
|
94
94
|
column,
|
|
@@ -96,7 +96,7 @@ export const Headers = {
|
|
|
96
96
|
: null,
|
|
97
97
|
renderFooter: () =>
|
|
98
98
|
column.footer
|
|
99
|
-
? instance.
|
|
99
|
+
? instance._render(column.footer, {
|
|
100
100
|
instance,
|
|
101
101
|
header: header as Header<TGenerics>,
|
|
102
102
|
column,
|
|
@@ -33,7 +33,6 @@ export type PaginationOptions<TGenerics extends TableGenerics> = {
|
|
|
33
33
|
|
|
34
34
|
export type PaginationDefaultOptions = {
|
|
35
35
|
onPaginationChange: OnChangeFn<PaginationState>
|
|
36
|
-
autoResetPageIndex: boolean
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
export type PaginationInstance<TGenerics extends TableGenerics> = {
|
|
@@ -82,7 +81,6 @@ export const Pagination: TableFeature = {
|
|
|
82
81
|
): PaginationDefaultOptions => {
|
|
83
82
|
return {
|
|
84
83
|
onPaginationChange: makeStateUpdater('pagination', instance),
|
|
85
|
-
autoResetPageIndex: true,
|
|
86
84
|
}
|
|
87
85
|
},
|
|
88
86
|
|
|
@@ -95,23 +93,20 @@ export const Pagination: TableFeature = {
|
|
|
95
93
|
return {
|
|
96
94
|
_autoResetPageIndex: () => {
|
|
97
95
|
if (!registered) {
|
|
98
|
-
instance.
|
|
96
|
+
instance._queue(() => {
|
|
99
97
|
registered = true
|
|
100
98
|
})
|
|
101
99
|
return
|
|
102
100
|
}
|
|
103
101
|
|
|
104
|
-
if (instance.options.autoResetAll === false) {
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
|
|
108
102
|
if (
|
|
109
|
-
instance.options.autoResetAll
|
|
110
|
-
instance.options.autoResetPageIndex
|
|
103
|
+
instance.options.autoResetAll ??
|
|
104
|
+
instance.options.autoResetPageIndex ??
|
|
105
|
+
!instance.options.manualPagination
|
|
111
106
|
) {
|
|
112
107
|
if (queued) return
|
|
113
108
|
queued = true
|
|
114
|
-
instance.
|
|
109
|
+
instance._queue(() => {
|
|
115
110
|
instance.resetPageIndex()
|
|
116
111
|
queued = false
|
|
117
112
|
})
|
|
@@ -138,7 +133,7 @@ export const Pagination: TableFeature = {
|
|
|
138
133
|
let pageIndex = functionalUpdate(updater, old.pageIndex)
|
|
139
134
|
|
|
140
135
|
const maxPageIndex =
|
|
141
|
-
|
|
136
|
+
typeof old.pageCount !== 'undefined'
|
|
142
137
|
? old.pageCount - 1
|
|
143
138
|
: Number.MAX_SAFE_INTEGER
|
|
144
139
|
|
|
@@ -14,78 +14,65 @@ export function getCoreRowModel<TGenerics extends TableGenerics>(): (
|
|
|
14
14
|
flatRows: Row<TGenerics>[]
|
|
15
15
|
rowsById: Record<string, Row<TGenerics>>
|
|
16
16
|
} => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const rowModel: RowModel<TGenerics> = {
|
|
18
|
+
rows: [],
|
|
19
|
+
flatRows: [],
|
|
20
|
+
rowsById: {},
|
|
21
|
+
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
let rows
|
|
24
|
+
let row
|
|
25
|
+
let originalRow
|
|
23
26
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
rowIndex: number,
|
|
27
|
+
const accessRows = (
|
|
28
|
+
originalRows: TGenerics['Row'][],
|
|
27
29
|
depth = 0,
|
|
28
|
-
parentRows: Row<TGenerics>[],
|
|
29
30
|
parent?: Row<TGenerics>
|
|
30
|
-
) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!id) {
|
|
34
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
35
|
-
throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
31
|
+
): Row<TGenerics>[] => {
|
|
32
|
+
rows = []
|
|
38
33
|
|
|
39
|
-
|
|
34
|
+
for (let i = 0; i < originalRows.length; i++) {
|
|
35
|
+
originalRow = originalRows[i]
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
37
|
+
// This could be an expensive check at scale, so we should move it somewhere else, but where?
|
|
38
|
+
// if (!id) {
|
|
39
|
+
// if (process.env.NODE_ENV !== 'production') {
|
|
40
|
+
// throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
41
|
+
// }
|
|
42
|
+
// }
|
|
47
43
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// Push instance row into the parentRows array
|
|
52
|
-
parentRows.push(row)
|
|
53
|
-
// Keep track of every row in a flat array
|
|
54
|
-
flatRows.push(row)
|
|
55
|
-
// Also keep track of every row by its ID
|
|
56
|
-
rowsById[id] = row
|
|
57
|
-
|
|
58
|
-
// Get the original subrows
|
|
59
|
-
if (instance.options.getSubRows) {
|
|
60
|
-
const originalSubRows = instance.options.getSubRows(
|
|
44
|
+
// Make the row
|
|
45
|
+
row = instance.createRow(
|
|
46
|
+
instance.getRowId(originalRow, i, parent),
|
|
61
47
|
originalRow,
|
|
62
|
-
|
|
48
|
+
i,
|
|
49
|
+
depth
|
|
63
50
|
)
|
|
64
51
|
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
// Keep track of every row in a flat array
|
|
53
|
+
rowModel.flatRows.push(row)
|
|
54
|
+
// Also keep track of every row by its ID
|
|
55
|
+
rowModel.rowsById[row.id] = row
|
|
56
|
+
// Push instance row into parent
|
|
57
|
+
rows.push(row)
|
|
58
|
+
|
|
59
|
+
// Get the original subrows
|
|
60
|
+
if (instance.options.getSubRows) {
|
|
61
|
+
row.originalSubRows = instance.options.getSubRows(originalRow, i)
|
|
69
62
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
i,
|
|
74
|
-
depth + 1,
|
|
75
|
-
subRows,
|
|
76
|
-
row
|
|
77
|
-
)
|
|
63
|
+
// Then recursively access them
|
|
64
|
+
if (row.originalSubRows?.length) {
|
|
65
|
+
row.subRows = accessRows(row.originalSubRows, depth + 1, row)
|
|
78
66
|
}
|
|
79
|
-
row.subRows = subRows
|
|
80
67
|
}
|
|
81
68
|
}
|
|
82
|
-
}
|
|
83
69
|
|
|
84
|
-
|
|
85
|
-
accessRow(data[i] as TGenerics['Row'], i, 0, rows)
|
|
70
|
+
return rows
|
|
86
71
|
}
|
|
87
72
|
|
|
88
|
-
|
|
73
|
+
rowModel.rows = accessRows(data)
|
|
74
|
+
|
|
75
|
+
return rowModel
|
|
89
76
|
},
|
|
90
77
|
{
|
|
91
78
|
key: process.env.NODE_ENV === 'development' && 'getRowModel',
|
|
@@ -155,7 +155,7 @@ export function getGroupedRowModel<TGenerics extends TableGenerics>(): (
|
|
|
155
155
|
key: process.env.NODE_ENV === 'development' && 'getGroupedRowModel',
|
|
156
156
|
debug: () => instance.options.debugAll ?? instance.options.debugTable,
|
|
157
157
|
onChange: () => {
|
|
158
|
-
instance.
|
|
158
|
+
instance._queue(() => {
|
|
159
159
|
instance._autoResetExpanded()
|
|
160
160
|
instance._autoResetPageIndex()
|
|
161
161
|
})
|