@tanstack/table-core 8.0.0-alpha.73 → 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 +1 -92
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js +31 -45
- package/build/cjs/utils/getCoreRowModel.js.map +1 -1
- package/build/esm/index.js +32 -137
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +298 -298
- package/build/umd/index.development.js +32 -137
- 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 +0 -107
- package/src/utils/getCoreRowModel.ts +42 -55
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
|
@@ -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: () => {
|
|
@@ -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
|
},
|
|
@@ -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',
|