@tanstack/react-table 8.0.0-alpha.73 → 8.0.0-alpha.78

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.
@@ -2690,8 +2690,10 @@ const Headers = {
2690
2690
  },
2691
2691
  // Header Groups
2692
2692
  getHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left, instance.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
2693
- const leftColumns = leafColumns.filter(column => left == null ? void 0 : left.includes(column.id));
2694
- const rightColumns = leafColumns.filter(column => right == null ? void 0 : right.includes(column.id));
2693
+ var _left$map$filter, _right$map$filter;
2694
+
2695
+ const leftColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
2696
+ const rightColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
2695
2697
  const centerColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
2696
2698
  const headerGroups = buildHeaderGroups(allColumns, [...leftColumns, ...centerColumns, ...rightColumns], instance);
2697
2699
  return headerGroups;
@@ -2715,8 +2717,10 @@ const Headers = {
2715
2717
  }
2716
2718
  }),
2717
2719
  getLeftHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left], (allColumns, leafColumns, left) => {
2718
- leafColumns = leafColumns.filter(column => left == null ? void 0 : left.includes(column.id));
2719
- return buildHeaderGroups(allColumns, leafColumns, instance, 'left');
2720
+ var _left$map$filter2;
2721
+
2722
+ const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
2723
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'left');
2720
2724
  }, {
2721
2725
  key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
2722
2726
  debug: () => {
@@ -2726,8 +2730,10 @@ const Headers = {
2726
2730
  }
2727
2731
  }),
2728
2732
  getRightHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right], (allColumns, leafColumns, right) => {
2729
- leafColumns = leafColumns.filter(column => right == null ? void 0 : right.includes(column.id));
2730
- return buildHeaderGroups(allColumns, leafColumns, instance, 'right');
2733
+ var _right$map$filter2;
2734
+
2735
+ const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
2736
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'right');
2731
2737
  }, {
2732
2738
  key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
2733
2739
  debug: () => {
@@ -3038,7 +3044,6 @@ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
3038
3044
  // data: Batch[]
3039
3045
  // facets: Batch[]
3040
3046
  // }
3041
- // export type TaskPriority = keyof CoreBatches
3042
3047
  function createTableInstance(options) {
3043
3048
  var _options$initialState;
3044
3049
 
@@ -3077,64 +3082,7 @@ function createTableInstance(options) {
3077
3082
  });
3078
3083
 
3079
3084
  const queued = [];
3080
- let queuedTimeout = false; // let workScheduled = false
3081
- // let working = false
3082
- // let latestCallback: ReturnType<typeof requestIdleCallback>
3083
- // let batchUid = 0
3084
- // const onProgress = () => {}
3085
- // const getBatch = () => {
3086
- // instance.batches.data = instance.batches.data.filter(d => d.tasks.length)
3087
- // instance.batches.facets = instance.batches.facets.filter(
3088
- // d => d.tasks.length
3089
- // )
3090
- // return (
3091
- // instance.batches.data.find(d => d.tasks.length) ??
3092
- // instance.batches.facets.find(d => d.tasks.length)
3093
- // )
3094
- // }
3095
- // const startWorkLoop = () => {
3096
- // working = true
3097
- // const workLoop = (deadline: IdleDeadline) => {
3098
- // const batch = getBatch()
3099
- // if (!batch) {
3100
- // working = false
3101
- // return
3102
- // }
3103
- // // Prioritize tasks
3104
- // while (deadline.timeRemaining() > 0 && batch.tasks.length) {
3105
- // batch.tasks.shift()!()
3106
- // }
3107
- // onProgress()
3108
- // if (working) {
3109
- // latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
3110
- // }
3111
- // }
3112
- // latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
3113
- // }
3114
- // const startWork = () => {
3115
- // if (getBatch() && !working) {
3116
- // if (
3117
- // (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
3118
- // instance.options.debugTable
3119
- // ) {
3120
- // console.info('Starting work...')
3121
- // }
3122
- // startWorkLoop()
3123
- // }
3124
- // }
3125
- // const stopWork = () => {
3126
- // if (working) {
3127
- // if (
3128
- // (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
3129
- // instance.options.debugTable
3130
- // ) {
3131
- // console.info('Stopping work...')
3132
- // }
3133
- // working = false
3134
- // cancelIdleCallback(latestCallback)
3135
- // }
3136
- // }
3137
-
3085
+ let queuedTimeout = false;
3138
3086
  const midInstance = { ...instance,
3139
3087
  // init: () => {
3140
3088
  // startWork()
@@ -3167,39 +3115,6 @@ function createTableInstance(options) {
3167
3115
  }));
3168
3116
  }
3169
3117
  },
3170
- // batches: {
3171
- // data: [],
3172
- // facets: [],
3173
- // },
3174
- // createBatch: priority => {
3175
- // const batchId = batchUid++
3176
- // let canceled: boolean
3177
- // const batch: Batch = {
3178
- // id: batchId,
3179
- // priority,
3180
- // tasks: [],
3181
- // schedule: cb => {
3182
- // if (canceled) return
3183
- // batch.tasks.push(cb)
3184
- // if (!working && !workScheduled) {
3185
- // workScheduled = true
3186
- // instance.queue(() => {
3187
- // workScheduled = false
3188
- // instance.setState(old => ({ ...old }))
3189
- // })
3190
- // }
3191
- // },
3192
- // cancel: () => {
3193
- // canceled = true
3194
- // batch.tasks = []
3195
- // instance.batches[priority] = instance.batches[priority].filter(
3196
- // b => b.id !== batchId
3197
- // )
3198
- // },
3199
- // }
3200
- // instance.batches[priority].push(batch)
3201
- // return batch
3202
- // },
3203
3118
  reset: () => {
3204
3119
  instance.setState(instance.initialState);
3205
3120
  },
@@ -3310,69 +3225,55 @@ function createTable(_, __, options) {
3310
3225
 
3311
3226
  function getCoreRowModel() {
3312
3227
  return instance => memo(() => [instance.options.data], data => {
3313
- // Access the row model using initial columns
3314
- const rows = [];
3315
- const flatRows = [];
3316
- const rowsById = {};
3317
- const leafColumns = instance.getAllLeafColumns();
3228
+ const rowModel = {
3229
+ rows: [],
3230
+ flatRows: [],
3231
+ rowsById: {}
3232
+ };
3233
+ let rows;
3234
+ let row;
3235
+ let originalRow;
3318
3236
 
3319
- const accessRow = function (originalRow, rowIndex, depth, parentRows, parent) {
3237
+ const accessRows = function (originalRows, depth, parent) {
3320
3238
  if (depth === void 0) {
3321
3239
  depth = 0;
3322
3240
  }
3323
3241
 
3324
- const id = instance.getRowId(originalRow, rowIndex, parent);
3325
-
3326
- if (!id) {
3327
- if (process.env.NODE_ENV !== 'production') {
3328
- throw new Error("getRowId expected an ID, but got " + id);
3329
- }
3330
- }
3331
-
3332
- const values = {};
3333
-
3334
- for (let i = 0; i < leafColumns.length; i++) {
3335
- const column = leafColumns[i];
3336
-
3337
- if (column && column.accessorFn) {
3338
- values[column.id] = column.accessorFn(originalRow, rowIndex);
3339
- }
3340
- } // Make the row
3242
+ rows = [];
3341
3243
 
3244
+ for (let i = 0; i < originalRows.length; i++) {
3245
+ originalRow = originalRows[i]; // This could be an expensive check at scale, so we should move it somewhere else, but where?
3246
+ // if (!id) {
3247
+ // if (process.env.NODE_ENV !== 'production') {
3248
+ // throw new Error(`getRowId expected an ID, but got ${id}`)
3249
+ // }
3250
+ // }
3251
+ // Make the row
3342
3252
 
3343
- const row = instance.createRow(id, originalRow, rowIndex, depth); // Push instance row into the parentRows array
3253
+ row = instance.createRow(instance.getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
3344
3254
 
3345
- parentRows.push(row); // Keep track of every row in a flat array
3255
+ rowModel.flatRows.push(row); // Also keep track of every row by its ID
3346
3256
 
3347
- flatRows.push(row); // Also keep track of every row by its ID
3257
+ rowModel.rowsById[row.id] = row; // Push instance row into parent
3348
3258
 
3349
- rowsById[id] = row; // Get the original subrows
3259
+ rows.push(row); // Get the original subrows
3350
3260
 
3351
- if (instance.options.getSubRows) {
3352
- const originalSubRows = instance.options.getSubRows(originalRow, rowIndex); // Then recursively access them
3261
+ if (instance.options.getSubRows) {
3262
+ var _row$originalSubRows;
3353
3263
 
3354
- if (originalSubRows != null && originalSubRows.length) {
3355
- row.originalSubRows = originalSubRows;
3356
- const subRows = [];
3264
+ row.originalSubRows = instance.options.getSubRows(originalRow, i); // Then recursively access them
3357
3265
 
3358
- for (let i = 0; i < row.originalSubRows.length; i++) {
3359
- accessRow(row.originalSubRows[i], i, depth + 1, subRows, row);
3266
+ if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
3267
+ row.subRows = accessRows(row.originalSubRows, depth + 1, row);
3360
3268
  }
3361
-
3362
- row.subRows = subRows;
3363
3269
  }
3364
3270
  }
3365
- };
3366
3271
 
3367
- for (let i = 0; i < data.length; i++) {
3368
- accessRow(data[i], i, 0, rows);
3369
- }
3370
-
3371
- return {
3372
- rows,
3373
- flatRows,
3374
- rowsById
3272
+ return rows;
3375
3273
  };
3274
+
3275
+ rowModel.rows = accessRows(data);
3276
+ return rowModel;
3376
3277
  }, {
3377
3278
  key: process.env.NODE_ENV === 'development' && 'getRowModel',
3378
3279
  debug: () => {