@tanstack/table-core 8.0.0-alpha.72 → 8.0.0-alpha.76
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 +10 -6
- 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 +59 -159
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +308 -308
- package/build/types/core.d.ts +2 -3
- package/build/types/features/Pagination.d.ts +0 -1
- package/build/umd/index.development.js +59 -159
- 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.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 +24 -6
- 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
|
|
@@ -2698,8 +2699,10 @@
|
|
|
2698
2699
|
}
|
|
2699
2700
|
}),
|
|
2700
2701
|
getLeftHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left], (allColumns, leafColumns, left) => {
|
|
2701
|
-
|
|
2702
|
-
|
|
2702
|
+
var _left$map$filter;
|
|
2703
|
+
|
|
2704
|
+
const orderedLeafColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
|
|
2705
|
+
return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'left');
|
|
2703
2706
|
}, {
|
|
2704
2707
|
key: 'getLeftHeaderGroups',
|
|
2705
2708
|
debug: () => {
|
|
@@ -2709,8 +2712,10 @@
|
|
|
2709
2712
|
}
|
|
2710
2713
|
}),
|
|
2711
2714
|
getRightHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right], (allColumns, leafColumns, right) => {
|
|
2712
|
-
|
|
2713
|
-
|
|
2715
|
+
var _right$map$filter;
|
|
2716
|
+
|
|
2717
|
+
const orderedLeafColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
|
|
2718
|
+
return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'right');
|
|
2714
2719
|
}, {
|
|
2715
2720
|
key: 'getRightHeaderGroups',
|
|
2716
2721
|
debug: () => {
|
|
@@ -3021,7 +3026,6 @@
|
|
|
3021
3026
|
// data: Batch[]
|
|
3022
3027
|
// facets: Batch[]
|
|
3023
3028
|
// }
|
|
3024
|
-
// export type TaskPriority = keyof CoreBatches
|
|
3025
3029
|
function createTableInstance(options) {
|
|
3026
3030
|
var _options$initialState;
|
|
3027
3031
|
|
|
@@ -3060,64 +3064,7 @@
|
|
|
3060
3064
|
});
|
|
3061
3065
|
|
|
3062
3066
|
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
|
-
|
|
3067
|
+
let queuedTimeout = false;
|
|
3121
3068
|
const midInstance = { ...instance,
|
|
3122
3069
|
// init: () => {
|
|
3123
3070
|
// startWork()
|
|
@@ -3132,7 +3079,7 @@
|
|
|
3132
3079
|
...options
|
|
3133
3080
|
},
|
|
3134
3081
|
initialState,
|
|
3135
|
-
|
|
3082
|
+
_queue: cb => {
|
|
3136
3083
|
queued.push(cb);
|
|
3137
3084
|
|
|
3138
3085
|
if (!queuedTimeout) {
|
|
@@ -3150,39 +3097,6 @@
|
|
|
3150
3097
|
}));
|
|
3151
3098
|
}
|
|
3152
3099
|
},
|
|
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
3100
|
reset: () => {
|
|
3187
3101
|
instance.setState(instance.initialState);
|
|
3188
3102
|
},
|
|
@@ -3190,7 +3104,7 @@
|
|
|
3190
3104
|
const newOptions = functionalUpdate(updater, instance.options);
|
|
3191
3105
|
instance.options = mergeOptions(newOptions);
|
|
3192
3106
|
},
|
|
3193
|
-
|
|
3107
|
+
_render: (template, props) => {
|
|
3194
3108
|
if (typeof instance.options.render === 'function') {
|
|
3195
3109
|
return instance.options.render(template, props);
|
|
3196
3110
|
}
|
|
@@ -3293,69 +3207,55 @@
|
|
|
3293
3207
|
|
|
3294
3208
|
function getCoreRowModel() {
|
|
3295
3209
|
return instance => memo(() => [instance.options.data], data => {
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3210
|
+
const rowModel = {
|
|
3211
|
+
rows: [],
|
|
3212
|
+
flatRows: [],
|
|
3213
|
+
rowsById: {}
|
|
3214
|
+
};
|
|
3215
|
+
let rows;
|
|
3216
|
+
let row;
|
|
3217
|
+
let originalRow;
|
|
3301
3218
|
|
|
3302
|
-
const
|
|
3219
|
+
const accessRows = function (originalRows, depth, parent) {
|
|
3303
3220
|
if (depth === void 0) {
|
|
3304
3221
|
depth = 0;
|
|
3305
3222
|
}
|
|
3306
3223
|
|
|
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
|
|
3224
|
+
rows = [];
|
|
3324
3225
|
|
|
3226
|
+
for (let i = 0; i < originalRows.length; i++) {
|
|
3227
|
+
originalRow = originalRows[i]; // This could be an expensive check at scale, so we should move it somewhere else, but where?
|
|
3228
|
+
// if (!id) {
|
|
3229
|
+
// if ("development" !== 'production') {
|
|
3230
|
+
// throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
3231
|
+
// }
|
|
3232
|
+
// }
|
|
3233
|
+
// Make the row
|
|
3325
3234
|
|
|
3326
|
-
|
|
3235
|
+
row = instance.createRow(instance.getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
|
|
3327
3236
|
|
|
3328
|
-
|
|
3237
|
+
rowModel.flatRows.push(row); // Also keep track of every row by its ID
|
|
3329
3238
|
|
|
3330
|
-
|
|
3239
|
+
rowModel.rowsById[row.id] = row; // Push instance row into parent
|
|
3331
3240
|
|
|
3332
|
-
|
|
3241
|
+
rows.push(row); // Get the original subrows
|
|
3333
3242
|
|
|
3334
|
-
|
|
3335
|
-
|
|
3243
|
+
if (instance.options.getSubRows) {
|
|
3244
|
+
var _row$originalSubRows;
|
|
3336
3245
|
|
|
3337
|
-
|
|
3338
|
-
row.originalSubRows = originalSubRows;
|
|
3339
|
-
const subRows = [];
|
|
3246
|
+
row.originalSubRows = instance.options.getSubRows(originalRow, i); // Then recursively access them
|
|
3340
3247
|
|
|
3341
|
-
|
|
3342
|
-
|
|
3248
|
+
if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
|
|
3249
|
+
row.subRows = accessRows(row.originalSubRows, depth + 1, row);
|
|
3343
3250
|
}
|
|
3344
|
-
|
|
3345
|
-
row.subRows = subRows;
|
|
3346
3251
|
}
|
|
3347
3252
|
}
|
|
3348
|
-
};
|
|
3349
|
-
|
|
3350
|
-
for (let i = 0; i < data.length; i++) {
|
|
3351
|
-
accessRow(data[i], i, 0, rows);
|
|
3352
|
-
}
|
|
3353
3253
|
|
|
3354
|
-
|
|
3355
|
-
rows,
|
|
3356
|
-
flatRows,
|
|
3357
|
-
rowsById
|
|
3254
|
+
return rows;
|
|
3358
3255
|
};
|
|
3256
|
+
|
|
3257
|
+
rowModel.rows = accessRows(data);
|
|
3258
|
+
return rowModel;
|
|
3359
3259
|
}, {
|
|
3360
3260
|
key: 'getRowModel',
|
|
3361
3261
|
debug: () => {
|
|
@@ -3889,7 +3789,7 @@
|
|
|
3889
3789
|
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3890
3790
|
},
|
|
3891
3791
|
onChange: () => {
|
|
3892
|
-
instance.
|
|
3792
|
+
instance._queue(() => {
|
|
3893
3793
|
instance._autoResetExpanded();
|
|
3894
3794
|
|
|
3895
3795
|
instance._autoResetPageIndex();
|