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

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.
@@ -3038,7 +3038,6 @@ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
3038
3038
  // data: Batch[]
3039
3039
  // facets: Batch[]
3040
3040
  // }
3041
- // export type TaskPriority = keyof CoreBatches
3042
3041
  function createTableInstance(options) {
3043
3042
  var _options$initialState;
3044
3043
 
@@ -3077,64 +3076,7 @@ function createTableInstance(options) {
3077
3076
  });
3078
3077
 
3079
3078
  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
-
3079
+ let queuedTimeout = false;
3138
3080
  const midInstance = { ...instance,
3139
3081
  // init: () => {
3140
3082
  // startWork()
@@ -3167,39 +3109,6 @@ function createTableInstance(options) {
3167
3109
  }));
3168
3110
  }
3169
3111
  },
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
3112
  reset: () => {
3204
3113
  instance.setState(instance.initialState);
3205
3114
  },
@@ -3310,69 +3219,55 @@ function createTable(_, __, options) {
3310
3219
 
3311
3220
  function getCoreRowModel() {
3312
3221
  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();
3222
+ const rowModel = {
3223
+ rows: [],
3224
+ flatRows: [],
3225
+ rowsById: {}
3226
+ };
3227
+ let rows;
3228
+ let row;
3229
+ let originalRow;
3318
3230
 
3319
- const accessRow = function (originalRow, rowIndex, depth, parentRows, parent) {
3231
+ const accessRows = function (originalRows, depth, parent) {
3320
3232
  if (depth === void 0) {
3321
3233
  depth = 0;
3322
3234
  }
3323
3235
 
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
3236
+ rows = [];
3341
3237
 
3238
+ for (let i = 0; i < originalRows.length; i++) {
3239
+ originalRow = originalRows[i]; // This could be an expensive check at scale, so we should move it somewhere else, but where?
3240
+ // if (!id) {
3241
+ // if (process.env.NODE_ENV !== 'production') {
3242
+ // throw new Error(`getRowId expected an ID, but got ${id}`)
3243
+ // }
3244
+ // }
3245
+ // Make the row
3342
3246
 
3343
- const row = instance.createRow(id, originalRow, rowIndex, depth); // Push instance row into the parentRows array
3247
+ row = instance.createRow(instance.getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
3344
3248
 
3345
- parentRows.push(row); // Keep track of every row in a flat array
3249
+ rowModel.flatRows.push(row); // Also keep track of every row by its ID
3346
3250
 
3347
- flatRows.push(row); // Also keep track of every row by its ID
3251
+ rowModel.rowsById[row.id] = row; // Push instance row into parent
3348
3252
 
3349
- rowsById[id] = row; // Get the original subrows
3253
+ rows.push(row); // Get the original subrows
3350
3254
 
3351
- if (instance.options.getSubRows) {
3352
- const originalSubRows = instance.options.getSubRows(originalRow, rowIndex); // Then recursively access them
3255
+ if (instance.options.getSubRows) {
3256
+ var _row$originalSubRows;
3353
3257
 
3354
- if (originalSubRows != null && originalSubRows.length) {
3355
- row.originalSubRows = originalSubRows;
3356
- const subRows = [];
3258
+ row.originalSubRows = instance.options.getSubRows(originalRow, i); // Then recursively access them
3357
3259
 
3358
- for (let i = 0; i < row.originalSubRows.length; i++) {
3359
- accessRow(row.originalSubRows[i], i, depth + 1, subRows, row);
3260
+ if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
3261
+ row.subRows = accessRows(row.originalSubRows, depth + 1, row);
3360
3262
  }
3361
-
3362
- row.subRows = subRows;
3363
3263
  }
3364
3264
  }
3365
- };
3366
-
3367
- for (let i = 0; i < data.length; i++) {
3368
- accessRow(data[i], i, 0, rows);
3369
- }
3370
3265
 
3371
- return {
3372
- rows,
3373
- flatRows,
3374
- rowsById
3266
+ return rows;
3375
3267
  };
3268
+
3269
+ rowModel.rows = accessRows(data);
3270
+ return rowModel;
3376
3271
  }, {
3377
3272
  key: process.env.NODE_ENV === 'development' && 'getRowModel',
3378
3273
  debug: () => {