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