@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/esm/index.js
CHANGED
|
@@ -373,7 +373,7 @@ const Cells = {
|
|
|
373
373
|
row,
|
|
374
374
|
column,
|
|
375
375
|
getValue: () => row.getValue(columnId),
|
|
376
|
-
renderCell: () => column.cell ? instance.
|
|
376
|
+
renderCell: () => column.cell ? instance._render(column.cell, {
|
|
377
377
|
instance,
|
|
378
378
|
column,
|
|
379
379
|
row,
|
|
@@ -701,9 +701,10 @@ const Expanding = {
|
|
|
701
701
|
return {
|
|
702
702
|
_autoResetExpanded: () => {
|
|
703
703
|
if (!registered) {
|
|
704
|
-
instance.
|
|
704
|
+
instance._queue(() => {
|
|
705
705
|
registered = true;
|
|
706
706
|
});
|
|
707
|
+
|
|
707
708
|
return;
|
|
708
709
|
}
|
|
709
710
|
|
|
@@ -714,7 +715,8 @@ const Expanding = {
|
|
|
714
715
|
if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
|
|
715
716
|
if (queued) return;
|
|
716
717
|
queued = true;
|
|
717
|
-
|
|
718
|
+
|
|
719
|
+
instance._queue(() => {
|
|
718
720
|
instance.resetExpanded();
|
|
719
721
|
queued = false;
|
|
720
722
|
});
|
|
@@ -1398,7 +1400,7 @@ const Grouping = {
|
|
|
1398
1400
|
var _column$aggregatedCel;
|
|
1399
1401
|
|
|
1400
1402
|
const template = (_column$aggregatedCel = column.aggregatedCell) != null ? _column$aggregatedCel : column.cell;
|
|
1401
|
-
return template ? instance.
|
|
1403
|
+
return template ? instance._render(template, {
|
|
1402
1404
|
instance,
|
|
1403
1405
|
column,
|
|
1404
1406
|
row,
|
|
@@ -1499,8 +1501,7 @@ const Pagination = {
|
|
|
1499
1501
|
},
|
|
1500
1502
|
getDefaultOptions: instance => {
|
|
1501
1503
|
return {
|
|
1502
|
-
onPaginationChange: makeStateUpdater('pagination', instance)
|
|
1503
|
-
autoResetPageIndex: true
|
|
1504
|
+
onPaginationChange: makeStateUpdater('pagination', instance)
|
|
1504
1505
|
};
|
|
1505
1506
|
},
|
|
1506
1507
|
createInstance: instance => {
|
|
@@ -1508,21 +1509,21 @@ const Pagination = {
|
|
|
1508
1509
|
let queued = false;
|
|
1509
1510
|
return {
|
|
1510
1511
|
_autoResetPageIndex: () => {
|
|
1512
|
+
var _ref, _instance$options$aut;
|
|
1513
|
+
|
|
1511
1514
|
if (!registered) {
|
|
1512
|
-
instance.
|
|
1515
|
+
instance._queue(() => {
|
|
1513
1516
|
registered = true;
|
|
1514
1517
|
});
|
|
1515
|
-
return;
|
|
1516
|
-
}
|
|
1517
1518
|
|
|
1518
|
-
if (instance.options.autoResetAll === false) {
|
|
1519
1519
|
return;
|
|
1520
1520
|
}
|
|
1521
1521
|
|
|
1522
|
-
if (instance.options.autoResetAll
|
|
1522
|
+
if ((_ref = (_instance$options$aut = instance.options.autoResetAll) != null ? _instance$options$aut : instance.options.autoResetPageIndex) != null ? _ref : !instance.options.manualPagination) {
|
|
1523
1523
|
if (queued) return;
|
|
1524
1524
|
queued = true;
|
|
1525
|
-
|
|
1525
|
+
|
|
1526
|
+
instance._queue(() => {
|
|
1526
1527
|
instance.resetPageIndex();
|
|
1527
1528
|
queued = false;
|
|
1528
1529
|
});
|
|
@@ -1544,7 +1545,7 @@ const Pagination = {
|
|
|
1544
1545
|
setPageIndex: updater => {
|
|
1545
1546
|
instance.setPagination(old => {
|
|
1546
1547
|
let pageIndex = functionalUpdate(updater, old.pageIndex);
|
|
1547
|
-
const maxPageIndex =
|
|
1548
|
+
const maxPageIndex = typeof old.pageCount !== 'undefined' ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
|
|
1548
1549
|
pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
|
|
1549
1550
|
return { ...old,
|
|
1550
1551
|
pageIndex
|
|
@@ -2655,12 +2656,12 @@ const Headers = {
|
|
|
2655
2656
|
recurseHeader(header);
|
|
2656
2657
|
return leafHeaders;
|
|
2657
2658
|
},
|
|
2658
|
-
renderHeader: () => column.header ? instance.
|
|
2659
|
+
renderHeader: () => column.header ? instance._render(column.header, {
|
|
2659
2660
|
instance,
|
|
2660
2661
|
header: header,
|
|
2661
2662
|
column
|
|
2662
2663
|
}) : null,
|
|
2663
|
-
renderFooter: () => column.footer ? instance.
|
|
2664
|
+
renderFooter: () => column.footer ? instance._render(column.footer, {
|
|
2664
2665
|
instance,
|
|
2665
2666
|
header: header,
|
|
2666
2667
|
column
|
|
@@ -2700,8 +2701,10 @@ const Headers = {
|
|
|
2700
2701
|
}
|
|
2701
2702
|
}),
|
|
2702
2703
|
getLeftHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left], (allColumns, leafColumns, left) => {
|
|
2703
|
-
|
|
2704
|
-
|
|
2704
|
+
var _left$map$filter;
|
|
2705
|
+
|
|
2706
|
+
const orderedLeafColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
|
|
2707
|
+
return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'left');
|
|
2705
2708
|
}, {
|
|
2706
2709
|
key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
|
|
2707
2710
|
debug: () => {
|
|
@@ -2711,8 +2714,10 @@ const Headers = {
|
|
|
2711
2714
|
}
|
|
2712
2715
|
}),
|
|
2713
2716
|
getRightHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right], (allColumns, leafColumns, right) => {
|
|
2714
|
-
|
|
2715
|
-
|
|
2717
|
+
var _right$map$filter;
|
|
2718
|
+
|
|
2719
|
+
const orderedLeafColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
|
|
2720
|
+
return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'right');
|
|
2716
2721
|
}, {
|
|
2717
2722
|
key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
|
|
2718
2723
|
debug: () => {
|
|
@@ -3023,7 +3028,6 @@ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
|
|
|
3023
3028
|
// data: Batch[]
|
|
3024
3029
|
// facets: Batch[]
|
|
3025
3030
|
// }
|
|
3026
|
-
// export type TaskPriority = keyof CoreBatches
|
|
3027
3031
|
function createTableInstance(options) {
|
|
3028
3032
|
var _options$initialState;
|
|
3029
3033
|
|
|
@@ -3062,64 +3066,7 @@ function createTableInstance(options) {
|
|
|
3062
3066
|
});
|
|
3063
3067
|
|
|
3064
3068
|
const queued = [];
|
|
3065
|
-
let queuedTimeout = false;
|
|
3066
|
-
// let working = false
|
|
3067
|
-
// let latestCallback: ReturnType<typeof requestIdleCallback>
|
|
3068
|
-
// let batchUid = 0
|
|
3069
|
-
// const onProgress = () => {}
|
|
3070
|
-
// const getBatch = () => {
|
|
3071
|
-
// instance.batches.data = instance.batches.data.filter(d => d.tasks.length)
|
|
3072
|
-
// instance.batches.facets = instance.batches.facets.filter(
|
|
3073
|
-
// d => d.tasks.length
|
|
3074
|
-
// )
|
|
3075
|
-
// return (
|
|
3076
|
-
// instance.batches.data.find(d => d.tasks.length) ??
|
|
3077
|
-
// instance.batches.facets.find(d => d.tasks.length)
|
|
3078
|
-
// )
|
|
3079
|
-
// }
|
|
3080
|
-
// const startWorkLoop = () => {
|
|
3081
|
-
// working = true
|
|
3082
|
-
// const workLoop = (deadline: IdleDeadline) => {
|
|
3083
|
-
// const batch = getBatch()
|
|
3084
|
-
// if (!batch) {
|
|
3085
|
-
// working = false
|
|
3086
|
-
// return
|
|
3087
|
-
// }
|
|
3088
|
-
// // Prioritize tasks
|
|
3089
|
-
// while (deadline.timeRemaining() > 0 && batch.tasks.length) {
|
|
3090
|
-
// batch.tasks.shift()!()
|
|
3091
|
-
// }
|
|
3092
|
-
// onProgress()
|
|
3093
|
-
// if (working) {
|
|
3094
|
-
// latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
|
|
3095
|
-
// }
|
|
3096
|
-
// }
|
|
3097
|
-
// latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
|
|
3098
|
-
// }
|
|
3099
|
-
// const startWork = () => {
|
|
3100
|
-
// if (getBatch() && !working) {
|
|
3101
|
-
// if (
|
|
3102
|
-
// (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
|
|
3103
|
-
// instance.options.debugTable
|
|
3104
|
-
// ) {
|
|
3105
|
-
// console.info('Starting work...')
|
|
3106
|
-
// }
|
|
3107
|
-
// startWorkLoop()
|
|
3108
|
-
// }
|
|
3109
|
-
// }
|
|
3110
|
-
// const stopWork = () => {
|
|
3111
|
-
// if (working) {
|
|
3112
|
-
// if (
|
|
3113
|
-
// (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
|
|
3114
|
-
// instance.options.debugTable
|
|
3115
|
-
// ) {
|
|
3116
|
-
// console.info('Stopping work...')
|
|
3117
|
-
// }
|
|
3118
|
-
// working = false
|
|
3119
|
-
// cancelIdleCallback(latestCallback)
|
|
3120
|
-
// }
|
|
3121
|
-
// }
|
|
3122
|
-
|
|
3069
|
+
let queuedTimeout = false;
|
|
3123
3070
|
const midInstance = { ...instance,
|
|
3124
3071
|
// init: () => {
|
|
3125
3072
|
// startWork()
|
|
@@ -3134,7 +3081,7 @@ function createTableInstance(options) {
|
|
|
3134
3081
|
...options
|
|
3135
3082
|
},
|
|
3136
3083
|
initialState,
|
|
3137
|
-
|
|
3084
|
+
_queue: cb => {
|
|
3138
3085
|
queued.push(cb);
|
|
3139
3086
|
|
|
3140
3087
|
if (!queuedTimeout) {
|
|
@@ -3152,39 +3099,6 @@ function createTableInstance(options) {
|
|
|
3152
3099
|
}));
|
|
3153
3100
|
}
|
|
3154
3101
|
},
|
|
3155
|
-
// batches: {
|
|
3156
|
-
// data: [],
|
|
3157
|
-
// facets: [],
|
|
3158
|
-
// },
|
|
3159
|
-
// createBatch: priority => {
|
|
3160
|
-
// const batchId = batchUid++
|
|
3161
|
-
// let canceled: boolean
|
|
3162
|
-
// const batch: Batch = {
|
|
3163
|
-
// id: batchId,
|
|
3164
|
-
// priority,
|
|
3165
|
-
// tasks: [],
|
|
3166
|
-
// schedule: cb => {
|
|
3167
|
-
// if (canceled) return
|
|
3168
|
-
// batch.tasks.push(cb)
|
|
3169
|
-
// if (!working && !workScheduled) {
|
|
3170
|
-
// workScheduled = true
|
|
3171
|
-
// instance.queue(() => {
|
|
3172
|
-
// workScheduled = false
|
|
3173
|
-
// instance.setState(old => ({ ...old }))
|
|
3174
|
-
// })
|
|
3175
|
-
// }
|
|
3176
|
-
// },
|
|
3177
|
-
// cancel: () => {
|
|
3178
|
-
// canceled = true
|
|
3179
|
-
// batch.tasks = []
|
|
3180
|
-
// instance.batches[priority] = instance.batches[priority].filter(
|
|
3181
|
-
// b => b.id !== batchId
|
|
3182
|
-
// )
|
|
3183
|
-
// },
|
|
3184
|
-
// }
|
|
3185
|
-
// instance.batches[priority].push(batch)
|
|
3186
|
-
// return batch
|
|
3187
|
-
// },
|
|
3188
3102
|
reset: () => {
|
|
3189
3103
|
instance.setState(instance.initialState);
|
|
3190
3104
|
},
|
|
@@ -3192,7 +3106,7 @@ function createTableInstance(options) {
|
|
|
3192
3106
|
const newOptions = functionalUpdate(updater, instance.options);
|
|
3193
3107
|
instance.options = mergeOptions(newOptions);
|
|
3194
3108
|
},
|
|
3195
|
-
|
|
3109
|
+
_render: (template, props) => {
|
|
3196
3110
|
if (typeof instance.options.render === 'function') {
|
|
3197
3111
|
return instance.options.render(template, props);
|
|
3198
3112
|
}
|
|
@@ -3295,69 +3209,55 @@ function createTable(_, __, options) {
|
|
|
3295
3209
|
|
|
3296
3210
|
function getCoreRowModel() {
|
|
3297
3211
|
return instance => memo(() => [instance.options.data], data => {
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3212
|
+
const rowModel = {
|
|
3213
|
+
rows: [],
|
|
3214
|
+
flatRows: [],
|
|
3215
|
+
rowsById: {}
|
|
3216
|
+
};
|
|
3217
|
+
let rows;
|
|
3218
|
+
let row;
|
|
3219
|
+
let originalRow;
|
|
3303
3220
|
|
|
3304
|
-
const
|
|
3221
|
+
const accessRows = function (originalRows, depth, parent) {
|
|
3305
3222
|
if (depth === void 0) {
|
|
3306
3223
|
depth = 0;
|
|
3307
3224
|
}
|
|
3308
3225
|
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
if (!id) {
|
|
3312
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
3313
|
-
throw new Error("getRowId expected an ID, but got " + id);
|
|
3314
|
-
}
|
|
3315
|
-
}
|
|
3316
|
-
|
|
3317
|
-
const values = {};
|
|
3318
|
-
|
|
3319
|
-
for (let i = 0; i < leafColumns.length; i++) {
|
|
3320
|
-
const column = leafColumns[i];
|
|
3321
|
-
|
|
3322
|
-
if (column && column.accessorFn) {
|
|
3323
|
-
values[column.id] = column.accessorFn(originalRow, rowIndex);
|
|
3324
|
-
}
|
|
3325
|
-
} // Make the row
|
|
3226
|
+
rows = [];
|
|
3326
3227
|
|
|
3228
|
+
for (let i = 0; i < originalRows.length; i++) {
|
|
3229
|
+
originalRow = originalRows[i]; // This could be an expensive check at scale, so we should move it somewhere else, but where?
|
|
3230
|
+
// if (!id) {
|
|
3231
|
+
// if (process.env.NODE_ENV !== 'production') {
|
|
3232
|
+
// throw new Error(`getRowId expected an ID, but got ${id}`)
|
|
3233
|
+
// }
|
|
3234
|
+
// }
|
|
3235
|
+
// Make the row
|
|
3327
3236
|
|
|
3328
|
-
|
|
3237
|
+
row = instance.createRow(instance.getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
|
|
3329
3238
|
|
|
3330
|
-
|
|
3239
|
+
rowModel.flatRows.push(row); // Also keep track of every row by its ID
|
|
3331
3240
|
|
|
3332
|
-
|
|
3241
|
+
rowModel.rowsById[row.id] = row; // Push instance row into parent
|
|
3333
3242
|
|
|
3334
|
-
|
|
3243
|
+
rows.push(row); // Get the original subrows
|
|
3335
3244
|
|
|
3336
|
-
|
|
3337
|
-
|
|
3245
|
+
if (instance.options.getSubRows) {
|
|
3246
|
+
var _row$originalSubRows;
|
|
3338
3247
|
|
|
3339
|
-
|
|
3340
|
-
row.originalSubRows = originalSubRows;
|
|
3341
|
-
const subRows = [];
|
|
3248
|
+
row.originalSubRows = instance.options.getSubRows(originalRow, i); // Then recursively access them
|
|
3342
3249
|
|
|
3343
|
-
|
|
3344
|
-
|
|
3250
|
+
if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
|
|
3251
|
+
row.subRows = accessRows(row.originalSubRows, depth + 1, row);
|
|
3345
3252
|
}
|
|
3346
|
-
|
|
3347
|
-
row.subRows = subRows;
|
|
3348
3253
|
}
|
|
3349
3254
|
}
|
|
3350
|
-
};
|
|
3351
|
-
|
|
3352
|
-
for (let i = 0; i < data.length; i++) {
|
|
3353
|
-
accessRow(data[i], i, 0, rows);
|
|
3354
|
-
}
|
|
3355
3255
|
|
|
3356
|
-
|
|
3357
|
-
rows,
|
|
3358
|
-
flatRows,
|
|
3359
|
-
rowsById
|
|
3256
|
+
return rows;
|
|
3360
3257
|
};
|
|
3258
|
+
|
|
3259
|
+
rowModel.rows = accessRows(data);
|
|
3260
|
+
return rowModel;
|
|
3361
3261
|
}, {
|
|
3362
3262
|
key: process.env.NODE_ENV === 'development' && 'getRowModel',
|
|
3363
3263
|
debug: () => {
|
|
@@ -3891,7 +3791,7 @@ function getGroupedRowModel() {
|
|
|
3891
3791
|
return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
|
|
3892
3792
|
},
|
|
3893
3793
|
onChange: () => {
|
|
3894
|
-
instance.
|
|
3794
|
+
instance._queue(() => {
|
|
3895
3795
|
instance._autoResetExpanded();
|
|
3896
3796
|
|
|
3897
3797
|
instance._autoResetPageIndex();
|