@tanstack/svelte-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.
@@ -386,7 +386,7 @@ const Cells = {
386
386
  row,
387
387
  column,
388
388
  getValue: () => row.getValue(columnId),
389
- renderCell: () => column.cell ? instance.render(column.cell, {
389
+ renderCell: () => column.cell ? instance._render(column.cell, {
390
390
  instance,
391
391
  column,
392
392
  row,
@@ -714,9 +714,10 @@ const Expanding = {
714
714
  return {
715
715
  _autoResetExpanded: () => {
716
716
  if (!registered) {
717
- instance.queue(() => {
717
+ instance._queue(() => {
718
718
  registered = true;
719
719
  });
720
+
720
721
  return;
721
722
  }
722
723
 
@@ -727,7 +728,8 @@ const Expanding = {
727
728
  if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
728
729
  if (queued) return;
729
730
  queued = true;
730
- instance.queue(() => {
731
+
732
+ instance._queue(() => {
731
733
  instance.resetExpanded();
732
734
  queued = false;
733
735
  });
@@ -1411,7 +1413,7 @@ const Grouping = {
1411
1413
  var _column$aggregatedCel;
1412
1414
 
1413
1415
  const template = (_column$aggregatedCel = column.aggregatedCell) != null ? _column$aggregatedCel : column.cell;
1414
- return template ? instance.render(template, {
1416
+ return template ? instance._render(template, {
1415
1417
  instance,
1416
1418
  column,
1417
1419
  row,
@@ -1512,8 +1514,7 @@ const Pagination = {
1512
1514
  },
1513
1515
  getDefaultOptions: instance => {
1514
1516
  return {
1515
- onPaginationChange: makeStateUpdater('pagination', instance),
1516
- autoResetPageIndex: true
1517
+ onPaginationChange: makeStateUpdater('pagination', instance)
1517
1518
  };
1518
1519
  },
1519
1520
  createInstance: instance => {
@@ -1521,21 +1522,21 @@ const Pagination = {
1521
1522
  let queued = false;
1522
1523
  return {
1523
1524
  _autoResetPageIndex: () => {
1525
+ var _ref, _instance$options$aut;
1526
+
1524
1527
  if (!registered) {
1525
- instance.queue(() => {
1528
+ instance._queue(() => {
1526
1529
  registered = true;
1527
1530
  });
1528
- return;
1529
- }
1530
1531
 
1531
- if (instance.options.autoResetAll === false) {
1532
1532
  return;
1533
1533
  }
1534
1534
 
1535
- if (instance.options.autoResetAll === true || instance.options.autoResetPageIndex) {
1535
+ if ((_ref = (_instance$options$aut = instance.options.autoResetAll) != null ? _instance$options$aut : instance.options.autoResetPageIndex) != null ? _ref : !instance.options.manualPagination) {
1536
1536
  if (queued) return;
1537
1537
  queued = true;
1538
- instance.queue(() => {
1538
+
1539
+ instance._queue(() => {
1539
1540
  instance.resetPageIndex();
1540
1541
  queued = false;
1541
1542
  });
@@ -1557,7 +1558,7 @@ const Pagination = {
1557
1558
  setPageIndex: updater => {
1558
1559
  instance.setPagination(old => {
1559
1560
  let pageIndex = functionalUpdate(updater, old.pageIndex);
1560
- const maxPageIndex = old.pageCount && old.pageCount > 0 ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
1561
+ const maxPageIndex = typeof old.pageCount !== 'undefined' ? old.pageCount - 1 : Number.MAX_SAFE_INTEGER;
1561
1562
  pageIndex = Math.min(Math.max(0, pageIndex), maxPageIndex);
1562
1563
  return { ...old,
1563
1564
  pageIndex
@@ -2668,12 +2669,12 @@ const Headers = {
2668
2669
  recurseHeader(header);
2669
2670
  return leafHeaders;
2670
2671
  },
2671
- renderHeader: () => column.header ? instance.render(column.header, {
2672
+ renderHeader: () => column.header ? instance._render(column.header, {
2672
2673
  instance,
2673
2674
  header: header,
2674
2675
  column
2675
2676
  }) : null,
2676
- renderFooter: () => column.footer ? instance.render(column.footer, {
2677
+ renderFooter: () => column.footer ? instance._render(column.footer, {
2677
2678
  instance,
2678
2679
  header: header,
2679
2680
  column
@@ -2713,8 +2714,10 @@ const Headers = {
2713
2714
  }
2714
2715
  }),
2715
2716
  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');
2717
+ var _left$map$filter;
2718
+
2719
+ const orderedLeafColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
2720
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'left');
2718
2721
  }, {
2719
2722
  key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
2720
2723
  debug: () => {
@@ -2724,8 +2727,10 @@ const Headers = {
2724
2727
  }
2725
2728
  }),
2726
2729
  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');
2730
+ var _right$map$filter;
2731
+
2732
+ const orderedLeafColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
2733
+ return buildHeaderGroups(allColumns, orderedLeafColumns, instance, 'right');
2729
2734
  }, {
2730
2735
  key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
2731
2736
  debug: () => {
@@ -3036,7 +3041,6 @@ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
3036
3041
  // data: Batch[]
3037
3042
  // facets: Batch[]
3038
3043
  // }
3039
- // export type TaskPriority = keyof CoreBatches
3040
3044
  function createTableInstance$1(options) {
3041
3045
  var _options$initialState;
3042
3046
 
@@ -3075,64 +3079,7 @@ function createTableInstance$1(options) {
3075
3079
  });
3076
3080
 
3077
3081
  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
-
3082
+ let queuedTimeout = false;
3136
3083
  const midInstance = { ...instance,
3137
3084
  // init: () => {
3138
3085
  // startWork()
@@ -3147,7 +3094,7 @@ function createTableInstance$1(options) {
3147
3094
  ...options
3148
3095
  },
3149
3096
  initialState,
3150
- queue: cb => {
3097
+ _queue: cb => {
3151
3098
  queued.push(cb);
3152
3099
 
3153
3100
  if (!queuedTimeout) {
@@ -3165,39 +3112,6 @@ function createTableInstance$1(options) {
3165
3112
  }));
3166
3113
  }
3167
3114
  },
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
3115
  reset: () => {
3202
3116
  instance.setState(instance.initialState);
3203
3117
  },
@@ -3205,7 +3119,7 @@ function createTableInstance$1(options) {
3205
3119
  const newOptions = functionalUpdate(updater, instance.options);
3206
3120
  instance.options = mergeOptions(newOptions);
3207
3121
  },
3208
- render: (template, props) => {
3122
+ _render: (template, props) => {
3209
3123
  if (typeof instance.options.render === 'function') {
3210
3124
  return instance.options.render(template, props);
3211
3125
  }
@@ -3308,69 +3222,55 @@ function createTable$1(_, __, options) {
3308
3222
 
3309
3223
  function getCoreRowModel() {
3310
3224
  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();
3225
+ const rowModel = {
3226
+ rows: [],
3227
+ flatRows: [],
3228
+ rowsById: {}
3229
+ };
3230
+ let rows;
3231
+ let row;
3232
+ let originalRow;
3316
3233
 
3317
- const accessRow = function (originalRow, rowIndex, depth, parentRows, parent) {
3234
+ const accessRows = function (originalRows, depth, parent) {
3318
3235
  if (depth === void 0) {
3319
3236
  depth = 0;
3320
3237
  }
3321
3238
 
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
3239
+ rows = [];
3339
3240
 
3241
+ for (let i = 0; i < originalRows.length; i++) {
3242
+ originalRow = originalRows[i]; // This could be an expensive check at scale, so we should move it somewhere else, but where?
3243
+ // if (!id) {
3244
+ // if (process.env.NODE_ENV !== 'production') {
3245
+ // throw new Error(`getRowId expected an ID, but got ${id}`)
3246
+ // }
3247
+ // }
3248
+ // Make the row
3340
3249
 
3341
- const row = instance.createRow(id, originalRow, rowIndex, depth); // Push instance row into the parentRows array
3250
+ row = instance.createRow(instance.getRowId(originalRow, i, parent), originalRow, i, depth); // Keep track of every row in a flat array
3342
3251
 
3343
- parentRows.push(row); // Keep track of every row in a flat array
3252
+ rowModel.flatRows.push(row); // Also keep track of every row by its ID
3344
3253
 
3345
- flatRows.push(row); // Also keep track of every row by its ID
3254
+ rowModel.rowsById[row.id] = row; // Push instance row into parent
3346
3255
 
3347
- rowsById[id] = row; // Get the original subrows
3256
+ rows.push(row); // Get the original subrows
3348
3257
 
3349
- if (instance.options.getSubRows) {
3350
- const originalSubRows = instance.options.getSubRows(originalRow, rowIndex); // Then recursively access them
3258
+ if (instance.options.getSubRows) {
3259
+ var _row$originalSubRows;
3351
3260
 
3352
- if (originalSubRows != null && originalSubRows.length) {
3353
- row.originalSubRows = originalSubRows;
3354
- const subRows = [];
3261
+ row.originalSubRows = instance.options.getSubRows(originalRow, i); // Then recursively access them
3355
3262
 
3356
- for (let i = 0; i < row.originalSubRows.length; i++) {
3357
- accessRow(row.originalSubRows[i], i, depth + 1, subRows, row);
3263
+ if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
3264
+ row.subRows = accessRows(row.originalSubRows, depth + 1, row);
3358
3265
  }
3359
-
3360
- row.subRows = subRows;
3361
3266
  }
3362
3267
  }
3363
- };
3364
-
3365
- for (let i = 0; i < data.length; i++) {
3366
- accessRow(data[i], i, 0, rows);
3367
- }
3368
3268
 
3369
- return {
3370
- rows,
3371
- flatRows,
3372
- rowsById
3269
+ return rows;
3373
3270
  };
3271
+
3272
+ rowModel.rows = accessRows(data);
3273
+ return rowModel;
3374
3274
  }, {
3375
3275
  key: process.env.NODE_ENV === 'development' && 'getRowModel',
3376
3276
  debug: () => {
@@ -3904,7 +3804,7 @@ function getGroupedRowModel() {
3904
3804
  return (_instance$options$deb = instance.options.debugAll) != null ? _instance$options$deb : instance.options.debugTable;
3905
3805
  },
3906
3806
  onChange: () => {
3907
- instance.queue(() => {
3807
+ instance._queue(() => {
3908
3808
  instance._autoResetExpanded();
3909
3809
 
3910
3810
  instance._autoResetPageIndex();