@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/build/types/core.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export declare type CoreOptions<TGenerics extends TableGenerics> = {
|
|
|
14
14
|
initialState?: InitialTableState;
|
|
15
15
|
autoResetAll?: boolean;
|
|
16
16
|
mergeOptions?: <T>(defaultOptions: T, options: Partial<T>) => T;
|
|
17
|
-
keepPreviousData?: boolean;
|
|
18
17
|
meta?: TGenerics['TableMeta'];
|
|
19
18
|
};
|
|
20
19
|
export declare type CoreInstance<TGenerics extends TableGenerics> = {
|
|
@@ -22,10 +21,10 @@ export declare type CoreInstance<TGenerics extends TableGenerics> = {
|
|
|
22
21
|
reset: () => void;
|
|
23
22
|
options: RequiredKeys<TableOptions<TGenerics>, 'state'>;
|
|
24
23
|
setOptions: (newOptions: Updater<TableOptions<TGenerics>>) => void;
|
|
25
|
-
queue: (cb: () => void) => void;
|
|
26
24
|
getState: () => TableState;
|
|
27
25
|
setState: (updater: Updater<TableState>) => void;
|
|
28
|
-
|
|
26
|
+
_queue: (cb: () => void) => void;
|
|
27
|
+
_render: <TProps>(template: Renderable<TGenerics, TProps>, props: TProps) => string | null | TGenerics['Rendered'];
|
|
29
28
|
_features: readonly TableFeature[];
|
|
30
29
|
};
|
|
31
30
|
export declare function createTableInstance<TGenerics extends TableGenerics>(options: TableOptions<TGenerics>): TableInstance<TGenerics>;
|
|
@@ -18,7 +18,6 @@ export declare type PaginationOptions<TGenerics extends TableGenerics> = {
|
|
|
18
18
|
};
|
|
19
19
|
export declare type PaginationDefaultOptions = {
|
|
20
20
|
onPaginationChange: OnChangeFn<PaginationState>;
|
|
21
|
-
autoResetPageIndex: boolean;
|
|
22
21
|
};
|
|
23
22
|
export declare type PaginationInstance<TGenerics extends TableGenerics> = {
|
|
24
23
|
_autoResetPageIndex: () => void;
|
|
@@ -375,7 +375,7 @@
|
|
|
375
375
|
row,
|
|
376
376
|
column,
|
|
377
377
|
getValue: () => row.getValue(columnId),
|
|
378
|
-
renderCell: () => column.cell ? instance.
|
|
378
|
+
renderCell: () => column.cell ? instance._render(column.cell, {
|
|
379
379
|
instance,
|
|
380
380
|
column,
|
|
381
381
|
row,
|
|
@@ -699,9 +699,10 @@
|
|
|
699
699
|
return {
|
|
700
700
|
_autoResetExpanded: () => {
|
|
701
701
|
if (!registered) {
|
|
702
|
-
instance.
|
|
702
|
+
instance._queue(() => {
|
|
703
703
|
registered = true;
|
|
704
704
|
});
|
|
705
|
+
|
|
705
706
|
return;
|
|
706
707
|
}
|
|
707
708
|
|
|
@@ -712,7 +713,8 @@
|
|
|
712
713
|
if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
|
|
713
714
|
if (queued) return;
|
|
714
715
|
queued = true;
|
|
715
|
-
|
|
716
|
+
|
|
717
|
+
instance._queue(() => {
|
|
716
718
|
instance.resetExpanded();
|
|
717
719
|
queued = false;
|
|
718
720
|
});
|
|
@@ -1396,7 +1398,7 @@
|
|
|
1396
1398
|
var _column$aggregatedCel;
|
|
1397
1399
|
|
|
1398
1400
|
const template = (_column$aggregatedCel = column.aggregatedCell) != null ? _column$aggregatedCel : column.cell;
|
|
1399
|
-
return template ? instance.
|
|
1401
|
+
return template ? instance._render(template, {
|
|
1400
1402
|
instance,
|
|
1401
1403
|
column,
|
|
1402
1404
|
row,
|
|
@@ -1497,8 +1499,7 @@
|
|
|
1497
1499
|
},
|
|
1498
1500
|
getDefaultOptions: instance => {
|
|
1499
1501
|
return {
|
|
1500
|
-
onPaginationChange: makeStateUpdater('pagination', instance)
|
|
1501
|
-
autoResetPageIndex: true
|
|
1502
|
+
onPaginationChange: makeStateUpdater('pagination', instance)
|
|
1502
1503
|
};
|
|
1503
1504
|
},
|
|
1504
1505
|
createInstance: instance => {
|
|
@@ -1506,21 +1507,21 @@
|
|
|
1506
1507
|
let queued = false;
|
|
1507
1508
|
return {
|
|
1508
1509
|
_autoResetPageIndex: () => {
|
|
1510
|
+
var _ref, _instance$options$aut;
|
|
1511
|
+
|
|
1509
1512
|
if (!registered) {
|
|
1510
|
-
instance.
|
|
1513
|
+
instance._queue(() => {
|
|
1511
1514
|
registered = true;
|
|
1512
1515
|
});
|
|
1513
|
-
return;
|
|
1514
|
-
}
|
|
1515
1516
|
|
|
1516
|
-
if (instance.options.autoResetAll === false) {
|
|
1517
1517
|
return;
|
|
1518
1518
|
}
|
|
1519
1519
|
|
|
1520
|
-
if (instance.options.autoResetAll
|
|
1520
|
+
if ((_ref = (_instance$options$aut = instance.options.autoResetAll) != null ? _instance$options$aut : instance.options.autoResetPageIndex) != null ? _ref : !instance.options.manualPagination) {
|
|
1521
1521
|
if (queued) return;
|
|
1522
1522
|
queued = true;
|
|
1523
|
-
|
|
1523
|
+
|
|
1524
|
+
instance._queue(() => {
|
|
1524
1525
|
instance.resetPageIndex();
|
|
1525
1526
|
queued = false;
|
|
1526
1527
|
});
|
|
@@ -1542,7 +1543,7 @@
|
|
|
1542
1543
|
setPageIndex: updater => {
|
|
1543
1544
|
instance.setPagination(old => {
|
|
1544
1545
|
let pageIndex = functionalUpdate(updater, old.pageIndex);
|
|
1545
|
-
const maxPageIndex =
|
|
1546
|
+
const maxPageIndex = typeof old.pageCount !== 'undefined' ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
|
|
1546
1547
|
pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
|
|
1547
1548
|
return { ...old,
|
|
1548
1549
|
pageIndex
|
|
@@ -2653,12 +2654,12 @@
|
|
|
2653
2654
|
recurseHeader(header);
|
|
2654
2655
|
return leafHeaders;
|
|
2655
2656
|
},
|
|
2656
|
-
renderHeader: () => column.header ? instance.
|
|
2657
|
+
renderHeader: () => column.header ? instance._render(column.header, {
|
|
2657
2658
|
instance,
|
|
2658
2659
|
header: header,
|
|
2659
2660
|
column
|
|
2660
2661
|
}) : null,
|
|
2661
|
-
renderFooter: () => column.footer ? instance.
|
|
2662
|
+
renderFooter: () => column.footer ? instance._render(column.footer, {
|
|
2662
2663
|
instance,
|
|
2663
2664
|
header: header,
|
|
2664
2665
|
column
|
|
@@ -3021,7 +3022,6 @@
|
|
|
3021
3022
|
// data: Batch[]
|
|
3022
3023
|
// facets: Batch[]
|
|
3023
3024
|
// }
|
|
3024
|
-
// export type TaskPriority = keyof CoreBatches
|
|
3025
3025
|
function createTableInstance(options) {
|
|
3026
3026
|
var _options$initialState;
|
|
3027
3027
|
|
|
@@ -3060,64 +3060,7 @@
|
|
|
3060
3060
|
});
|
|
3061
3061
|
|
|
3062
3062
|
const queued = [];
|
|
3063
|
-
let queuedTimeout = false;
|
|
3064
|
-
// let working = false
|
|
3065
|
-
// let latestCallback: ReturnType<typeof requestIdleCallback>
|
|
3066
|
-
// let batchUid = 0
|
|
3067
|
-
// const onProgress = () => {}
|
|
3068
|
-
// const getBatch = () => {
|
|
3069
|
-
// instance.batches.data = instance.batches.data.filter(d => d.tasks.length)
|
|
3070
|
-
// instance.batches.facets = instance.batches.facets.filter(
|
|
3071
|
-
// d => d.tasks.length
|
|
3072
|
-
// )
|
|
3073
|
-
// return (
|
|
3074
|
-
// instance.batches.data.find(d => d.tasks.length) ??
|
|
3075
|
-
// instance.batches.facets.find(d => d.tasks.length)
|
|
3076
|
-
// )
|
|
3077
|
-
// }
|
|
3078
|
-
// const startWorkLoop = () => {
|
|
3079
|
-
// working = true
|
|
3080
|
-
// const workLoop = (deadline: IdleDeadline) => {
|
|
3081
|
-
// const batch = getBatch()
|
|
3082
|
-
// if (!batch) {
|
|
3083
|
-
// working = false
|
|
3084
|
-
// return
|
|
3085
|
-
// }
|
|
3086
|
-
// // Prioritize tasks
|
|
3087
|
-
// while (deadline.timeRemaining() > 0 && batch.tasks.length) {
|
|
3088
|
-
// batch.tasks.shift()!()
|
|
3089
|
-
// }
|
|
3090
|
-
// onProgress()
|
|
3091
|
-
// if (working) {
|
|
3092
|
-
// latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
|
|
3093
|
-
// }
|
|
3094
|
-
// }
|
|
3095
|
-
// latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
|
|
3096
|
-
// }
|
|
3097
|
-
// const startWork = () => {
|
|
3098
|
-
// if (getBatch() && !working) {
|
|
3099
|
-
// if (
|
|
3100
|
-
// ("development" === 'development' && instance.options.debugAll) ??
|
|
3101
|
-
// instance.options.debugTable
|
|
3102
|
-
// ) {
|
|
3103
|
-
// console.info('Starting work...')
|
|
3104
|
-
// }
|
|
3105
|
-
// startWorkLoop()
|
|
3106
|
-
// }
|
|
3107
|
-
// }
|
|
3108
|
-
// const stopWork = () => {
|
|
3109
|
-
// if (working) {
|
|
3110
|
-
// if (
|
|
3111
|
-
// ("development" === 'development' && instance.options.debugAll) ??
|
|
3112
|
-
// instance.options.debugTable
|
|
3113
|
-
// ) {
|
|
3114
|
-
// console.info('Stopping work...')
|
|
3115
|
-
// }
|
|
3116
|
-
// working = false
|
|
3117
|
-
// cancelIdleCallback(latestCallback)
|
|
3118
|
-
// }
|
|
3119
|
-
// }
|
|
3120
|
-
|
|
3063
|
+
let queuedTimeout = false;
|
|
3121
3064
|
const midInstance = { ...instance,
|
|
3122
3065
|
// init: () => {
|
|
3123
3066
|
// startWork()
|
|
@@ -3132,7 +3075,7 @@
|
|
|
3132
3075
|
...options
|
|
3133
3076
|
},
|
|
3134
3077
|
initialState,
|
|
3135
|
-
|
|
3078
|
+
_queue: cb => {
|
|
3136
3079
|
queued.push(cb);
|
|
3137
3080
|
|
|
3138
3081
|
if (!queuedTimeout) {
|
|
@@ -3150,39 +3093,6 @@
|
|
|
3150
3093
|
}));
|
|
3151
3094
|
}
|
|
3152
3095
|
},
|
|
3153
|
-
// batches: {
|
|
3154
|
-
// data: [],
|
|
3155
|
-
// facets: [],
|
|
3156
|
-
// },
|
|
3157
|
-
// createBatch: priority => {
|
|
3158
|
-
// const batchId = batchUid++
|
|
3159
|
-
// let canceled: boolean
|
|
3160
|
-
// const batch: Batch = {
|
|
3161
|
-
// id: batchId,
|
|
3162
|
-
// priority,
|
|
3163
|
-
// tasks: [],
|
|
3164
|
-
// schedule: cb => {
|
|
3165
|
-
// if (canceled) return
|
|
3166
|
-
// batch.tasks.push(cb)
|
|
3167
|
-
// if (!working && !workScheduled) {
|
|
3168
|
-
// workScheduled = true
|
|
3169
|
-
// instance.queue(() => {
|
|
3170
|
-
// workScheduled = false
|
|
3171
|
-
// instance.setState(old => ({ ...old }))
|
|
3172
|
-
// })
|
|
3173
|
-
// }
|
|
3174
|
-
// },
|
|
3175
|
-
// cancel: () => {
|
|
3176
|
-
// canceled = true
|
|
3177
|
-
// batch.tasks = []
|
|
3178
|
-
// instance.batches[priority] = instance.batches[priority].filter(
|
|
3179
|
-
// b => b.id !== batchId
|
|
3180
|
-
// )
|
|
3181
|
-
// },
|
|
3182
|
-
// }
|
|
3183
|
-
// instance.batches[priority].push(batch)
|
|
3184
|
-
// return batch
|
|
3185
|
-
// },
|
|
3186
3096
|
reset: () => {
|
|
3187
3097
|
instance.setState(instance.initialState);
|
|
3188
3098
|
},
|
|
@@ -3190,7 +3100,7 @@
|
|
|
3190
3100
|
const newOptions = functionalUpdate(updater, instance.options);
|
|
3191
3101
|
instance.options = mergeOptions(newOptions);
|
|
3192
3102
|
},
|
|
3193
|
-
|
|
3103
|
+
_render: (template, props) => {
|
|
3194
3104
|
if (typeof instance.options.render === 'function') {
|
|
3195
3105
|
return instance.options.render(template, props);
|
|
3196
3106
|
}
|
|
@@ -3293,69 +3203,55 @@
|
|
|
3293
3203
|
|
|
3294
3204
|
function getCoreRowModel() {
|
|
3295
3205
|
return instance => memo(() => [instance.options.data], data => {
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3206
|
+
const rowModel = {
|
|
3207
|
+
rows: [],
|
|
3208
|
+
flatRows: [],
|
|
3209
|
+
rowsById: {}
|
|
3210
|
+
};
|
|
3211
|
+
let rows;
|
|
3212
|
+
let row;
|
|
3213
|
+
let originalRow;
|
|
3301
3214
|
|
|
3302
|
-
const
|
|
3215
|
+
const accessRows = function (originalRows, depth, parent) {
|
|
3303
3216
|
if (depth === void 0) {
|
|
3304
3217
|
depth = 0;
|
|
3305
3218
|
}
|
|
3306
3219
|
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
if (!id) {
|
|
3310
|
-
{
|
|
3311
|
-
throw new Error("getRowId expected an ID, but got " + id);
|
|
3312
|
-
}
|
|
3313
|
-
}
|
|
3314
|
-
|
|
3315
|
-
const values = {};
|
|
3316
|
-
|
|
3317
|
-
for (let i = 0; i < leafColumns.length; i++) {
|
|
3318
|
-
const column = leafColumns[i];
|
|
3319
|
-
|
|
3320
|
-
if (column && column.accessorFn) {
|
|
3321
|
-
values[column.id] = column.accessorFn(originalRow, rowIndex);
|
|
3322
|
-
}
|
|
3323
|
-
} // Make the row
|
|
3220
|
+
rows = [];
|
|
3324
3221
|
|
|
3222
|
+
for (let i = 0; i < originalRows.length; i++) {
|
|
3223
|
+
originalRow = originalRows[i]; // This could be an expensive check at scale, so we should move it somewhere else, but where?
|
|
3224
|
+
// if (!id) {
|
|
3225
|
+
// if ("development" !== 'production') {
|
|
3226
|
+
// throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
3227
|
+
// }
|
|
3228
|
+
// }
|
|
3229
|
+
// Make the row
|
|
3325
3230
|
|
|
3326
|
-
|
|
3231
|
+
row = instance.createRow(instance.getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
|
|
3327
3232
|
|
|
3328
|
-
|
|
3233
|
+
rowModel.flatRows.push(row); // Also keep track of every row by its ID
|
|
3329
3234
|
|
|
3330
|
-
|
|
3235
|
+
rowModel.rowsById[row.id] = row; // Push instance row into parent
|
|
3331
3236
|
|
|
3332
|
-
|
|
3237
|
+
rows.push(row); // Get the original subrows
|
|
3333
3238
|
|
|
3334
|
-
|
|
3335
|
-
|
|
3239
|
+
if (instance.options.getSubRows) {
|
|
3240
|
+
var _row$originalSubRows;
|
|
3336
3241
|
|
|
3337
|
-
|
|
3338
|
-
row.originalSubRows = originalSubRows;
|
|
3339
|
-
const subRows = [];
|
|
3242
|
+
row.originalSubRows = instance.options.getSubRows(originalRow, i); // Then recursively access them
|
|
3340
3243
|
|
|
3341
|
-
|
|
3342
|
-
|
|
3244
|
+
if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
|
|
3245
|
+
row.subRows = accessRows(row.originalSubRows, depth + 1, row);
|
|
3343
3246
|
}
|
|
3344
|
-
|
|
3345
|
-
row.subRows = subRows;
|
|
3346
3247
|
}
|
|
3347
3248
|
}
|
|
3348
|
-
};
|
|
3349
3249
|
|
|
3350
|
-
|
|
3351
|
-
accessRow(data[i], i, 0, rows);
|
|
3352
|
-
}
|
|
3353
|
-
|
|
3354
|
-
return {
|
|
3355
|
-
rows,
|
|
3356
|
-
flatRows,
|
|
3357
|
-
rowsById
|
|
3250
|
+
return rows;
|
|
3358
3251
|
};
|
|
3252
|
+
|
|
3253
|
+
rowModel.rows = accessRows(data);
|
|
3254
|
+
return rowModel;
|
|
3359
3255
|
}, {
|
|
3360
3256
|
key: 'getRowModel',
|
|
3361
3257
|
debug: () => {
|
|
@@ -3889,7 +3785,7 @@
|
|
|
3889
3785
|
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3890
3786
|
},
|
|
3891
3787
|
onChange: () => {
|
|
3892
|
-
instance.
|
|
3788
|
+
instance._queue(() => {
|
|
3893
3789
|
instance._autoResetExpanded();
|
|
3894
3790
|
|
|
3895
3791
|
instance._autoResetPageIndex();
|