@tanstack/svelte-table 8.0.0-alpha.73 → 8.0.0-alpha.77

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.
@@ -2714,8 +2714,10 @@ const Headers = {
2714
2714
  }
2715
2715
  }),
2716
2716
  getLeftHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.left], (allColumns, leafColumns, left) => {
2717
- leafColumns = leafColumns.filter(column => left == null ? void 0 : left.includes(column.id));
2718
- 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');
2719
2721
  }, {
2720
2722
  key: process.env.NODE_ENV === 'development' && 'getLeftHeaderGroups',
2721
2723
  debug: () => {
@@ -2725,8 +2727,10 @@ const Headers = {
2725
2727
  }
2726
2728
  }),
2727
2729
  getRightHeaderGroups: memo(() => [instance.getAllColumns(), instance.getVisibleLeafColumns(), instance.getState().columnPinning.right], (allColumns, leafColumns, right) => {
2728
- leafColumns = leafColumns.filter(column => right == null ? void 0 : right.includes(column.id));
2729
- 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');
2730
2734
  }, {
2731
2735
  key: process.env.NODE_ENV === 'development' && 'getRightHeaderGroups',
2732
2736
  debug: () => {
@@ -3037,7 +3041,6 @@ function buildHeaderGroups(allColumns, columnsToGroup, instance, headerFamily) {
3037
3041
  // data: Batch[]
3038
3042
  // facets: Batch[]
3039
3043
  // }
3040
- // export type TaskPriority = keyof CoreBatches
3041
3044
  function createTableInstance$1(options) {
3042
3045
  var _options$initialState;
3043
3046
 
@@ -3076,64 +3079,7 @@ function createTableInstance$1(options) {
3076
3079
  });
3077
3080
 
3078
3081
  const queued = [];
3079
- let queuedTimeout = false; // let workScheduled = false
3080
- // let working = false
3081
- // let latestCallback: ReturnType<typeof requestIdleCallback>
3082
- // let batchUid = 0
3083
- // const onProgress = () => {}
3084
- // const getBatch = () => {
3085
- // instance.batches.data = instance.batches.data.filter(d => d.tasks.length)
3086
- // instance.batches.facets = instance.batches.facets.filter(
3087
- // d => d.tasks.length
3088
- // )
3089
- // return (
3090
- // instance.batches.data.find(d => d.tasks.length) ??
3091
- // instance.batches.facets.find(d => d.tasks.length)
3092
- // )
3093
- // }
3094
- // const startWorkLoop = () => {
3095
- // working = true
3096
- // const workLoop = (deadline: IdleDeadline) => {
3097
- // const batch = getBatch()
3098
- // if (!batch) {
3099
- // working = false
3100
- // return
3101
- // }
3102
- // // Prioritize tasks
3103
- // while (deadline.timeRemaining() > 0 && batch.tasks.length) {
3104
- // batch.tasks.shift()!()
3105
- // }
3106
- // onProgress()
3107
- // if (working) {
3108
- // latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
3109
- // }
3110
- // }
3111
- // latestCallback = requestIdleCallback(workLoop, { timeout: 10000 })
3112
- // }
3113
- // const startWork = () => {
3114
- // if (getBatch() && !working) {
3115
- // if (
3116
- // (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
3117
- // instance.options.debugTable
3118
- // ) {
3119
- // console.info('Starting work...')
3120
- // }
3121
- // startWorkLoop()
3122
- // }
3123
- // }
3124
- // const stopWork = () => {
3125
- // if (working) {
3126
- // if (
3127
- // (process.env.NODE_ENV === 'development' && instance.options.debugAll) ??
3128
- // instance.options.debugTable
3129
- // ) {
3130
- // console.info('Stopping work...')
3131
- // }
3132
- // working = false
3133
- // cancelIdleCallback(latestCallback)
3134
- // }
3135
- // }
3136
-
3082
+ let queuedTimeout = false;
3137
3083
  const midInstance = { ...instance,
3138
3084
  // init: () => {
3139
3085
  // startWork()
@@ -3166,39 +3112,6 @@ function createTableInstance$1(options) {
3166
3112
  }));
3167
3113
  }
3168
3114
  },
3169
- // batches: {
3170
- // data: [],
3171
- // facets: [],
3172
- // },
3173
- // createBatch: priority => {
3174
- // const batchId = batchUid++
3175
- // let canceled: boolean
3176
- // const batch: Batch = {
3177
- // id: batchId,
3178
- // priority,
3179
- // tasks: [],
3180
- // schedule: cb => {
3181
- // if (canceled) return
3182
- // batch.tasks.push(cb)
3183
- // if (!working && !workScheduled) {
3184
- // workScheduled = true
3185
- // instance.queue(() => {
3186
- // workScheduled = false
3187
- // instance.setState(old => ({ ...old }))
3188
- // })
3189
- // }
3190
- // },
3191
- // cancel: () => {
3192
- // canceled = true
3193
- // batch.tasks = []
3194
- // instance.batches[priority] = instance.batches[priority].filter(
3195
- // b => b.id !== batchId
3196
- // )
3197
- // },
3198
- // }
3199
- // instance.batches[priority].push(batch)
3200
- // return batch
3201
- // },
3202
3115
  reset: () => {
3203
3116
  instance.setState(instance.initialState);
3204
3117
  },
@@ -3309,69 +3222,55 @@ function createTable$1(_, __, options) {
3309
3222
 
3310
3223
  function getCoreRowModel() {
3311
3224
  return instance => memo(() => [instance.options.data], data => {
3312
- // Access the row model using initial columns
3313
- const rows = [];
3314
- const flatRows = [];
3315
- const rowsById = {};
3316
- const leafColumns = instance.getAllLeafColumns();
3225
+ const rowModel = {
3226
+ rows: [],
3227
+ flatRows: [],
3228
+ rowsById: {}
3229
+ };
3230
+ let rows;
3231
+ let row;
3232
+ let originalRow;
3317
3233
 
3318
- const accessRow = function (originalRow, rowIndex, depth, parentRows, parent) {
3234
+ const accessRows = function (originalRows, depth, parent) {
3319
3235
  if (depth === void 0) {
3320
3236
  depth = 0;
3321
3237
  }
3322
3238
 
3323
- const id = instance.getRowId(originalRow, rowIndex, parent);
3324
-
3325
- if (!id) {
3326
- if (process.env.NODE_ENV !== 'production') {
3327
- throw new Error("getRowId expected an ID, but got " + id);
3328
- }
3329
- }
3330
-
3331
- const values = {};
3332
-
3333
- for (let i = 0; i < leafColumns.length; i++) {
3334
- const column = leafColumns[i];
3335
-
3336
- if (column && column.accessorFn) {
3337
- values[column.id] = column.accessorFn(originalRow, rowIndex);
3338
- }
3339
- } // Make the row
3239
+ rows = [];
3340
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
3341
3249
 
3342
- 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
3343
3251
 
3344
- 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
3345
3253
 
3346
- flatRows.push(row); // Also keep track of every row by its ID
3254
+ rowModel.rowsById[row.id] = row; // Push instance row into parent
3347
3255
 
3348
- rowsById[id] = row; // Get the original subrows
3256
+ rows.push(row); // Get the original subrows
3349
3257
 
3350
- if (instance.options.getSubRows) {
3351
- const originalSubRows = instance.options.getSubRows(originalRow, rowIndex); // Then recursively access them
3258
+ if (instance.options.getSubRows) {
3259
+ var _row$originalSubRows;
3352
3260
 
3353
- if (originalSubRows != null && originalSubRows.length) {
3354
- row.originalSubRows = originalSubRows;
3355
- const subRows = [];
3261
+ row.originalSubRows = instance.options.getSubRows(originalRow, i); // Then recursively access them
3356
3262
 
3357
- for (let i = 0; i < row.originalSubRows.length; i++) {
3358
- 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);
3359
3265
  }
3360
-
3361
- row.subRows = subRows;
3362
3266
  }
3363
3267
  }
3364
- };
3365
-
3366
- for (let i = 0; i < data.length; i++) {
3367
- accessRow(data[i], i, 0, rows);
3368
- }
3369
3268
 
3370
- return {
3371
- rows,
3372
- flatRows,
3373
- rowsById
3269
+ return rows;
3374
3270
  };
3271
+
3272
+ rowModel.rows = accessRows(data);
3273
+ return rowModel;
3375
3274
  }, {
3376
3275
  key: process.env.NODE_ENV === 'development' && 'getRowModel',
3377
3276
  debug: () => {
@@ -4107,18 +4006,46 @@ function renderServer(Comp, props) {
4107
4006
 
4108
4007
  const renderComponent = typeof window === 'undefined' ? renderServer : renderClient;
4109
4008
 
4110
- function render(Comp, props) {
4111
- if (!Comp) return null;
4009
+ function isSvelteServerComponent(component) {
4010
+ return typeof component === 'object' && typeof component.$$render === 'function' && typeof component.render === 'function';
4011
+ }
4012
+
4013
+ function isSvelteClientComponent(component) {
4014
+ return component.prototype instanceof SvelteComponent;
4015
+ }
4112
4016
 
4113
- if (Comp instanceof Function) {
4114
- let res = Comp(props);
4115
- return res;
4017
+ function isSvelteComponent(component) {
4018
+ if (typeof document === 'undefined') {
4019
+ return isSvelteServerComponent(component);
4116
4020
  } else {
4117
- return renderComponent(Placeholder, {
4118
- content: Comp
4119
- });
4120
- } // return Comp
4021
+ return isSvelteClientComponent(component);
4022
+ }
4023
+ }
4024
+
4025
+ function wrapInPlaceholder(content) {
4026
+ return renderComponent(Placeholder, {
4027
+ content
4028
+ });
4029
+ }
4030
+
4031
+ function render(component, props) {
4032
+ if (!component) return null;
4033
+
4034
+ if (isSvelteComponent(component)) {
4035
+ return renderComponent(component, props);
4036
+ }
4037
+
4038
+ if (typeof component === 'function') {
4039
+ const result = component(props);
4040
+
4041
+ if (isSvelteComponent(result)) {
4042
+ return result;
4043
+ }
4044
+
4045
+ return wrapInPlaceholder(result);
4046
+ }
4121
4047
 
4048
+ return wrapInPlaceholder(component);
4122
4049
  }
4123
4050
  const createTable = createTableFactory({
4124
4051
  render