@tanstack/react-table 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.
@@ -385,7 +385,7 @@ const Cells = {
385
385
  row,
386
386
  column,
387
387
  getValue: () => row.getValue(columnId),
388
- renderCell: () => column.cell ? instance.render(column.cell, {
388
+ renderCell: () => column.cell ? instance._render(column.cell, {
389
389
  instance,
390
390
  column,
391
391
  row,
@@ -713,9 +713,10 @@ const Expanding = {
713
713
  return {
714
714
  _autoResetExpanded: () => {
715
715
  if (!registered) {
716
- instance.queue(() => {
716
+ instance._queue(() => {
717
717
  registered = true;
718
718
  });
719
+
719
720
  return;
720
721
  }
721
722
 
@@ -726,7 +727,8 @@ const Expanding = {
726
727
  if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
727
728
  if (queued) return;
728
729
  queued = true;
729
- instance.queue(() => {
730
+
731
+ instance._queue(() => {
730
732
  instance.resetExpanded();
731
733
  queued = false;
732
734
  });
@@ -1410,7 +1412,7 @@ const Grouping = {
1410
1412
  var _column$aggregatedCel;
1411
1413
 
1412
1414
  const template = (_column$aggregatedCel = column.aggregatedCell) != null ? _column$aggregatedCel : column.cell;
1413
- return template ? instance.render(template, {
1415
+ return template ? instance._render(template, {
1414
1416
  instance,
1415
1417
  column,
1416
1418
  row,
@@ -1511,8 +1513,7 @@ const Pagination = {
1511
1513
  },
1512
1514
  getDefaultOptions: instance => {
1513
1515
  return {
1514
- onPaginationChange: makeStateUpdater('pagination', instance),
1515
- autoResetPageIndex: true
1516
+ onPaginationChange: makeStateUpdater('pagination', instance)
1516
1517
  };
1517
1518
  },
1518
1519
  createInstance: instance => {
@@ -1520,21 +1521,21 @@ const Pagination = {
1520
1521
  let queued = false;
1521
1522
  return {
1522
1523
  _autoResetPageIndex: () => {
1524
+ var _ref, _instance$options$aut;
1525
+
1523
1526
  if (!registered) {
1524
- instance.queue(() => {
1527
+ instance._queue(() => {
1525
1528
  registered = true;
1526
1529
  });
1527
- return;
1528
- }
1529
1530
 
1530
- if (instance.options.autoResetAll === false) {
1531
1531
  return;
1532
1532
  }
1533
1533
 
1534
- if (instance.options.autoResetAll === true || instance.options.autoResetPageIndex) {
1534
+ if ((_ref = (_instance$options$aut = instance.options.autoResetAll) != null ? _instance$options$aut : instance.options.autoResetPageIndex) != null ? _ref : !instance.options.manualPagination) {
1535
1535
  if (queued) return;
1536
1536
  queued = true;
1537
- instance.queue(() => {
1537
+
1538
+ instance._queue(() => {
1538
1539
  instance.resetPageIndex();
1539
1540
  queued = false;
1540
1541
  });
@@ -1556,7 +1557,7 @@ const Pagination = {
1556
1557
  setPageIndex: updater => {
1557
1558
  instance.setPagination(old => {
1558
1559
  let pageIndex = functionalUpdate(updater, old.pageIndex);
1559
- const maxPageIndex = old.pageCount && old.pageCount > 0 ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
1560
+ const maxPageIndex = typeof old.pageCount !== 'undefined' ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
1560
1561
  pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
1561
1562
  return { ...old,
1562
1563
  pageIndex
@@ -2667,12 +2668,12 @@ const Headers = {
2667
2668
  recurseHeader(header);
2668
2669
  return leafHeaders;
2669
2670
  },
2670
- renderHeader: () => column.header ? instance.render(column.header, {
2671
+ renderHeader: () => column.header ? instance._render(column.header, {
2671
2672
  instance,
2672
2673
  header: header,
2673
2674
  column
2674
2675
  }) : null,
2675
- renderFooter: () => column.footer ? instance.render(column.footer, {
2676
+ renderFooter: () => column.footer ? instance._render(column.footer, {
2676
2677
  instance,
2677
2678
  header: header,
2678
2679
  column
@@ -2712,8 +2713,10 @@ const Headers = {
2712
2713
  }
2713
2714
  }),
2714
2715
  getLeftHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left], (allColumns, leafColumns, left) => {
2715
- leafColumns = leafColumns.filter(column => left == null ? void 0 : left.includes(column.id));
2716
- return buildHeaderGroups(allColumns, leafColumns, instance, 'left');
2716
+ var _left$map$filter;
2717
+
2718
+ const orderedLeafColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
2719
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'left');
2717
2720
  }, {
2718
2721
  key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
2719
2722
  debug: () => {
@@ -2723,8 +2726,10 @@ const Headers = {
2723
2726
  }
2724
2727
  }),
2725
2728
  getRightHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right], (allColumns, leafColumns, right) => {
2726
- leafColumns = leafColumns.filter(column => right == null ? void 0 : right.includes(column.id));
2727
- return buildHeaderGroups(allColumns, leafColumns, instance, 'right');
2729
+ var _right$map$filter;
2730
+
2731
+ const orderedLeafColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
2732
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'right');
2728
2733
  }, {
2729
2734
  key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
2730
2735
  debug: () => {
@@ -3035,7 +3040,6 @@ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
3035
3040
  // data: Batch[]
3036
3041
  // facets: Batch[]
3037
3042
  // }
3038
- // export type TaskPriority = keyof CoreBatches
3039
3043
  function createTableInstance(options) {
3040
3044
  var _options$initialState;
3041
3045
 
@@ -3074,64 +3078,7 @@ function createTableInstance(options) {
3074
3078
  });
3075
3079
 
3076
3080
  const queued = [];
3077
- let queuedTimeout = false; // let workScheduled = false
3078
- // let working = false
3079
- // let latestCallback: ReturnType<typeof requestIdleCallback>
3080
- // let batchUid = 0
3081
- // const onProgress = () => {}
3082
- // const getBatch = () => {
3083
- // instance.batches.data = instance.batches.data.filter(d => d.tasks.length)
3084
- // instance.batches.facets = instance.batches.facets.filter(
3085
- // d => d.tasks.length
3086
- // )
3087
- // return (
3088
- // instance.batches.data.find(d => d.tasks.length) ??
3089
- // instance.batches.facets.find(d => d.tasks.length)
3090
- // )
3091
- // }
3092
- // const startWorkLoop = () => {
3093
- // working = true
3094
- // const workLoop = (deadline: IdleDeadline) => {
3095
- // const batch = getBatch()
3096
- // if (!batch) {
3097
- // working = false
3098
- // return
3099
- // }
3100
- // // Prioritize tasks
3101
- // while (deadline.timeRemaining() > 0 && batch.tasks.length) {
3102
- // batch.tasks.shift()!()
3103
- // }
3104
- // onProgress()
3105
- // if (working) {
3106
- // latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
3107
- // }
3108
- // }
3109
- // latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
3110
- // }
3111
- // const startWork = () => {
3112
- // if (getBatch() && !working) {
3113
- // if (
3114
- // (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
3115
- // instance.options.debugTable
3116
- // ) {
3117
- // console.info('Starting work...')
3118
- // }
3119
- // startWorkLoop()
3120
- // }
3121
- // }
3122
- // const stopWork = () => {
3123
- // if (working) {
3124
- // if (
3125
- // (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
3126
- // instance.options.debugTable
3127
- // ) {
3128
- // console.info('Stopping work...')
3129
- // }
3130
- // working = false
3131
- // cancelIdleCallback(latestCallback)
3132
- // }
3133
- // }
3134
-
3081
+ let queuedTimeout = false;
3135
3082
  const midInstance = { ...instance,
3136
3083
  // init: () => {
3137
3084
  // startWork()
@@ -3146,7 +3093,7 @@ function createTableInstance(options) {
3146
3093
  ...options
3147
3094
  },
3148
3095
  initialState,
3149
- queue: cb => {
3096
+ _queue: cb => {
3150
3097
  queued.push(cb);
3151
3098
 
3152
3099
  if (!queuedTimeout) {
@@ -3164,39 +3111,6 @@ function createTableInstance(options) {
3164
3111
  }));
3165
3112
  }
3166
3113
  },
3167
- // batches: {
3168
- // data: [],
3169
- // facets: [],
3170
- // },
3171
- // createBatch: priority => {
3172
- // const batchId = batchUid++
3173
- // let canceled: boolean
3174
- // const batch: Batch = {
3175
- // id: batchId,
3176
- // priority,
3177
- // tasks: [],
3178
- // schedule: cb => {
3179
- // if (canceled) return
3180
- // batch.tasks.push(cb)
3181
- // if (!working && !workScheduled) {
3182
- // workScheduled = true
3183
- // instance.queue(() => {
3184
- // workScheduled = false
3185
- // instance.setState(old => ({ ...old }))
3186
- // })
3187
- // }
3188
- // },
3189
- // cancel: () => {
3190
- // canceled = true
3191
- // batch.tasks = []
3192
- // instance.batches[priority] = instance.batches[priority].filter(
3193
- // b => b.id !== batchId
3194
- // )
3195
- // },
3196
- // }
3197
- // instance.batches[priority].push(batch)
3198
- // return batch
3199
- // },
3200
3114
  reset: () => {
3201
3115
  instance.setState(instance.initialState);
3202
3116
  },
@@ -3204,7 +3118,7 @@ function createTableInstance(options) {
3204
3118
  const newOptions = functionalUpdate(updater, instance.options);
3205
3119
  instance.options = mergeOptions(newOptions);
3206
3120
  },
3207
- render: (template, props) => {
3121
+ _render: (template, props) => {
3208
3122
  if (typeof instance.options.render === 'function') {
3209
3123
  return instance.options.render(template, props);
3210
3124
  }
@@ -3307,69 +3221,55 @@ function createTable$1(_, __, options) {
3307
3221
 
3308
3222
  function getCoreRowModel() {
3309
3223
  return instance => memo(() => [instance.options.data], data => {
3310
- // Access the row model using initial columns
3311
- const rows = [];
3312
- const flatRows = [];
3313
- const rowsById = {};
3314
- const leafColumns = instance.getAllLeafColumns();
3224
+ const rowModel = {
3225
+ rows: [],
3226
+ flatRows: [],
3227
+ rowsById: {}
3228
+ };
3229
+ let rows;
3230
+ let row;
3231
+ let originalRow;
3315
3232
 
3316
- const accessRow = function (originalRow, rowIndex, depth, parentRows, parent) {
3233
+ const accessRows = function (originalRows, depth, parent) {
3317
3234
  if (depth === void 0) {
3318
3235
  depth = 0;
3319
3236
  }
3320
3237
 
3321
- const id = instance.getRowId(originalRow, rowIndex, parent);
3322
-
3323
- if (!id) {
3324
- if (process.env.NODE_ENV !== 'production') {
3325
- throw new Error("getRowId expected an ID, but got " + id);
3326
- }
3327
- }
3328
-
3329
- const values = {};
3330
-
3331
- for (let i = 0; i < leafColumns.length; i++) {
3332
- const column = leafColumns[i];
3333
-
3334
- if (column && column.accessorFn) {
3335
- values[column.id] = column.accessorFn(originalRow, rowIndex);
3336
- }
3337
- } // Make the row
3238
+ rows = [];
3338
3239
 
3240
+ for (let i = 0; i < originalRows.length; i++) {
3241
+ originalRow = originalRows[i]; // This could be an expensive check at scale, so we should move it somewhere else, but where?
3242
+ // if (!id) {
3243
+ // if (process.env.NODE_ENV !== 'production') {
3244
+ // throw new Error(`getRowId expected an ID, but got ${id}`)
3245
+ // }
3246
+ // }
3247
+ // Make the row
3339
3248
 
3340
- const row = instance.createRow(id, originalRow, rowIndex, depth); // Push instance row into the parentRows array
3249
+ row = instance.createRow(instance.getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
3341
3250
 
3342
- parentRows.push(row); // Keep track of every row in a flat array
3251
+ rowModel.flatRows.push(row); // Also keep track of every row by its ID
3343
3252
 
3344
- flatRows.push(row); // Also keep track of every row by its ID
3253
+ rowModel.rowsById[row.id] = row; // Push instance row into parent
3345
3254
 
3346
- rowsById[id] = row; // Get the original subrows
3255
+ rows.push(row); // Get the original subrows
3347
3256
 
3348
- if (instance.options.getSubRows) {
3349
- const originalSubRows = instance.options.getSubRows(originalRow, rowIndex); // Then recursively access them
3257
+ if (instance.options.getSubRows) {
3258
+ var _row$originalSubRows;
3350
3259
 
3351
- if (originalSubRows != null && originalSubRows.length) {
3352
- row.originalSubRows = originalSubRows;
3353
- const subRows = [];
3260
+ row.originalSubRows = instance.options.getSubRows(originalRow, i); // Then recursively access them
3354
3261
 
3355
- for (let i = 0; i < row.originalSubRows.length; i++) {
3356
- accessRow(row.originalSubRows[i], i, depth + 1, subRows, row);
3262
+ if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
3263
+ row.subRows = accessRows(row.originalSubRows, depth + 1, row);
3357
3264
  }
3358
-
3359
- row.subRows = subRows;
3360
3265
  }
3361
3266
  }
3362
- };
3363
-
3364
- for (let i = 0; i < data.length; i++) {
3365
- accessRow(data[i], i, 0, rows);
3366
- }
3367
3267
 
3368
- return {
3369
- rows,
3370
- flatRows,
3371
- rowsById
3268
+ return rows;
3372
3269
  };
3270
+
3271
+ rowModel.rows = accessRows(data);
3272
+ return rowModel;
3373
3273
  }, {
3374
3274
  key: process.env.NODE_ENV === 'development' && 'getRowModel',
3375
3275
  debug: () => {
@@ -3903,7 +3803,7 @@ function getGroupedRowModel() {
3903
3803
  return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3904
3804
  },
3905
3805
  onChange: () => {
3906
- instance.queue(() => {
3806
+ instance._queue(() => {
3907
3807
  instance._autoResetExpanded();
3908
3808
 
3909
3809
  instance._autoResetPageIndex();