@tanstack/svelte-table 8.0.0-beta.1 → 8.0.0-beta.4

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.
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- import { SvelteComponent, init, safe_not_equal, text as text$1, insert, set_data, noop as noop$1, detach, create_component, mount_component, transition_in, transition_out, destroy_component, create_ssr_component, validate_component } from 'svelte/internal';
11
+ import { SvelteComponent, init, safe_not_equal, text as text$1, claim_text, insert_hydration, set_data, noop as noop$1, detach, create_ssr_component, escape, create_component, claim_component, mount_component, transition_in, transition_out, destroy_component, validate_component } from 'svelte/internal';
12
12
  import { readable, get, writable, derived } from 'svelte/store';
13
13
 
14
14
  /**
@@ -1107,7 +1107,6 @@ const Filters = {
1107
1107
  },
1108
1108
  createColumn: (column, instance) => {
1109
1109
  return {
1110
- filterFn: column.filterFn,
1111
1110
  getAutoFilterFn: () => {
1112
1111
  const firstRow = instance.getCoreRowModel().flatRows[0];
1113
1112
  const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
@@ -1138,7 +1137,7 @@ const Filters = {
1138
1137
  var _ref;
1139
1138
 
1140
1139
  const userFilterFns = instance.options.filterFns;
1141
- return isFunction(column.filterFn) ? column.filterFn : column.filterFn === 'auto' ? column.getAutoFilterFn() : (_ref = userFilterFns == null ? void 0 : userFilterFns[column.filterFn]) != null ? _ref : filterFns[column.filterFn];
1140
+ return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn : column.columnDef.filterFn === 'auto' ? column.getAutoFilterFn() : (_ref = userFilterFns == null ? void 0 : userFilterFns[column.columnDef.filterFn]) != null ? _ref : filterFns[column.columnDef.filterFn];
1142
1141
  },
1143
1142
  getCanFilter: () => {
1144
1143
  var _column$columnDef$ena, _instance$options$ena, _instance$options$ena2;
@@ -1427,6 +1426,11 @@ const aggregationFns = {
1427
1426
  const Grouping = {
1428
1427
  getDefaultColumnDef: () => {
1429
1428
  return {
1429
+ aggregatedCell: props => {
1430
+ var _props$getValue$toStr, _props$getValue;
1431
+
1432
+ return (_props$getValue$toStr = (_props$getValue = props.getValue()) == null ? void 0 : _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _props$getValue$toStr : null;
1433
+ },
1430
1434
  aggregationFn: 'auto'
1431
1435
  };
1432
1436
  },
@@ -1487,8 +1491,6 @@ const Grouping = {
1487
1491
  if (Object.prototype.toString.call(value) === '[object Date]') {
1488
1492
  return aggregationFns.extent;
1489
1493
  }
1490
-
1491
- return aggregationFns.count;
1492
1494
  },
1493
1495
  getAggregationFn: () => {
1494
1496
  var _ref4;
@@ -1499,7 +1501,7 @@ const Grouping = {
1499
1501
  throw new Error();
1500
1502
  }
1501
1503
 
1502
- return isFunction(column.aggregationFn) ? column.aggregationFn : column.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.aggregationFn]) != null ? _ref4 : aggregationFns[column.aggregationFn];
1504
+ return isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn : column.columnDef.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_ref4 = userAggregationFns == null ? void 0 : userAggregationFns[column.columnDef.aggregationFn]) != null ? _ref4 : aggregationFns[column.columnDef.aggregationFn];
1503
1505
  }
1504
1506
  };
1505
1507
  },
@@ -1532,6 +1534,12 @@ const Grouping = {
1532
1534
  };
1533
1535
  },
1534
1536
  createCell: (cell, column, row, instance) => {
1537
+ const getRenderValue = () => {
1538
+ var _cell$getValue;
1539
+
1540
+ return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
1541
+ };
1542
+
1535
1543
  return {
1536
1544
  getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
1537
1545
  getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
@@ -1541,15 +1549,19 @@ const Grouping = {
1541
1549
  return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
1542
1550
  },
1543
1551
  renderAggregatedCell: () => {
1544
- var _column$columnDef$agg;
1552
+ if (process.env.NODE_ENV === 'development') {
1553
+ if (!column.columnDef.aggregatedCell) {
1554
+ console.warn('A columnDef.aggregatedCell template is recommended for displaying aggregated values.');
1555
+ }
1556
+ }
1545
1557
 
1546
- const template = (_column$columnDef$agg = column.columnDef.aggregatedCell) != null ? _column$columnDef$agg : column.columnDef.cell;
1558
+ const template = column.columnDef.aggregatedCell || column.columnDef.cell;
1547
1559
  return template ? instance._render(template, {
1548
1560
  instance,
1549
1561
  column,
1550
1562
  row,
1551
1563
  cell,
1552
- getValue: cell.getValue
1564
+ getValue: getRenderValue
1553
1565
  }) : null;
1554
1566
  }
1555
1567
  };
@@ -2532,8 +2544,10 @@ const Sorting = {
2532
2544
  // })
2533
2545
  // return
2534
2546
  // }
2547
+ // this needs to be outside of instance.setSorting to be in sync with rerender
2548
+ const nextSortingOrder = column.getNextSortingOrder();
2535
2549
  instance.setSorting(old => {
2536
- var _ref2, _column$columnDef$sor, _instance$options$ena, _instance$options$ena2;
2550
+ var _instance$options$ena, _instance$options$ena2;
2537
2551
 
2538
2552
  // Find any existing sorting for this column
2539
2553
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
@@ -2558,30 +2572,29 @@ const Sorting = {
2558
2572
  } else {
2559
2573
  sortAction = 'replace';
2560
2574
  }
2561
- }
2575
+ } // Handle toggle states that will remove the sorting
2562
2576
 
2563
- const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc'; // Handle toggle states that will remove the sorting
2564
2577
 
2565
2578
  if (sortAction === 'toggle' && ( // Must be toggling
2566
2579
  (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2567
2580
  !hasDescDefined && ( // Must not be setting desc
2568
- multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2569
- existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2570
- ? !sortDescFirst : sortDescFirst)) {
2581
+ multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && // If multi, don't allow if enableMultiRemove
2582
+ !nextSortingOrder // Finally, detect if it should indeed be removed
2583
+ ) {
2571
2584
  sortAction = 'remove';
2572
2585
  }
2573
2586
 
2574
2587
  if (sortAction === 'replace') {
2575
2588
  newSorting = [{
2576
2589
  id: column.id,
2577
- desc: hasDescDefined ? desc : !!sortDescFirst
2590
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2578
2591
  }];
2579
2592
  } else if (sortAction === 'add' && old != null && old.length) {
2580
2593
  var _instance$options$max;
2581
2594
 
2582
2595
  newSorting = [...old, {
2583
2596
  id: column.id,
2584
- desc: hasDescDefined ? desc : !!sortDescFirst
2597
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2585
2598
  }]; // Take latest n columns
2586
2599
 
2587
2600
  newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
@@ -2590,7 +2603,7 @@ const Sorting = {
2590
2603
  newSorting = old.map(d => {
2591
2604
  if (d.id === column.id) {
2592
2605
  return { ...d,
2593
- desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2606
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2594
2607
  };
2595
2608
  }
2596
2609
 
@@ -2603,6 +2616,23 @@ const Sorting = {
2603
2616
  return newSorting;
2604
2617
  });
2605
2618
  },
2619
+ getNextSortingOrder: () => {
2620
+ var _ref2, _column$columnDef$sor;
2621
+
2622
+ const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc';
2623
+ const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
2624
+ const isSorted = column.getIsSorted();
2625
+
2626
+ if (!isSorted) {
2627
+ return firstSortDirection;
2628
+ }
2629
+
2630
+ if (isSorted === firstSortDirection) {
2631
+ return isSorted === 'desc' ? 'asc' : 'desc';
2632
+ } else {
2633
+ return false;
2634
+ }
2635
+ },
2606
2636
  getCanSort: () => {
2607
2637
  var _column$columnDef$ena, _instance$options$ena3;
2608
2638
 
@@ -2896,9 +2926,9 @@ function createTableInstance$1(options) {
2896
2926
  header: props => props.header.column.id,
2897
2927
  footer: props => props.header.column.id,
2898
2928
  cell: props => {
2899
- var _props$getValue$toStr, _props$getValue$toStr2, _props$getValue;
2929
+ var _props$getValue$toStr, _props$getValue;
2900
2930
 
2901
- return (_props$getValue$toStr = (_props$getValue$toStr2 = (_props$getValue = props.getValue()).toString) == null ? void 0 : _props$getValue$toStr2.call(_props$getValue)) != null ? _props$getValue$toStr : null;
2931
+ return (_props$getValue$toStr = (_props$getValue = props.getValue()) == null ? void 0 : _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _props$getValue$toStr : null;
2902
2932
  },
2903
2933
  ...instance._features.reduce((obj, feature) => {
2904
2934
  return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
@@ -3052,6 +3082,12 @@ function createTable$1(_, __, options) {
3052
3082
  }
3053
3083
 
3054
3084
  function createCell(instance, row, column, columnId) {
3085
+ const getRenderValue = () => {
3086
+ var _cell$getValue;
3087
+
3088
+ return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
3089
+ };
3090
+
3055
3091
  const cell = {
3056
3092
  id: row.id + "_" + column.id,
3057
3093
  row,
@@ -3063,7 +3099,7 @@ function createCell(instance, row, column, columnId) {
3063
3099
  column,
3064
3100
  row,
3065
3101
  cell: cell,
3066
- getValue: cell.getValue
3102
+ getValue: getRenderValue
3067
3103
  }) : null;
3068
3104
  }
3069
3105
  };
@@ -3669,11 +3705,6 @@ function getGroupedRowModel() {
3669
3705
  if (aggregateFn) {
3670
3706
  row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
3671
3707
  return row._groupingValuesCache[columnId];
3672
- } else if (column.aggregationFn) {
3673
- console.info({
3674
- column
3675
- });
3676
- throw new Error(process.env.NODE_ENV !== 'production' ? "Table: Invalid column.aggregateType option for column listed above" : '');
3677
3708
  }
3678
3709
  }
3679
3710
  });
@@ -3830,8 +3861,11 @@ function create_fragment$1(ctx) {
3830
3861
  c() {
3831
3862
  t = text$1(/*content*/ ctx[0]);
3832
3863
  },
3864
+ l(nodes) {
3865
+ t = claim_text(nodes, /*content*/ ctx[0]);
3866
+ },
3833
3867
  m(target, anchor) {
3834
- insert(target, t, anchor);
3868
+ insert_hydration(target, t, anchor);
3835
3869
  },
3836
3870
  p(ctx, [dirty]) {
3837
3871
  if (dirty & /*content*/ 1) set_data(t, /*content*/ ctx[0]);
@@ -3854,13 +3888,18 @@ function instance($$self, $$props, $$invalidate) {
3854
3888
  return [content];
3855
3889
  }
3856
3890
 
3857
- class Placeholder extends SvelteComponent {
3891
+ class Placeholder$1 extends SvelteComponent {
3858
3892
  constructor(options) {
3859
3893
  super();
3860
3894
  init(this, options, instance, create_fragment$1, safe_not_equal, { content: 0 });
3861
3895
  }
3862
3896
  }
3863
3897
 
3898
+ const PlaceholderServer = create_ssr_component(($$result, $$props, $$bindings, slots) => {
3899
+ return "" + escape($$props.content);
3900
+ });
3901
+ var Placeholder = typeof document === 'undefined' ? PlaceholderServer : Placeholder$1;
3902
+
3864
3903
  function create_fragment(ctx, Comp, props) {
3865
3904
  let c;
3866
3905
  let current;
@@ -3873,6 +3912,10 @@ function create_fragment(ctx, Comp, props) {
3873
3912
  create_component(c.$$.fragment);
3874
3913
  },
3875
3914
 
3915
+ l(nodes) {
3916
+ claim_component(c.$$.fragment, nodes);
3917
+ },
3918
+
3876
3919
  m(target, anchor) {
3877
3920
  // @ts-ignore
3878
3921
  mount_component(c, target, anchor);
@@ -3911,7 +3954,7 @@ function renderClient(Comp, props) {
3911
3954
 
3912
3955
  function renderServer(Comp, props) {
3913
3956
  const WrapperComp = create_ssr_component(($$result, $$props, $$bindings, slots) => {
3914
- return "" + validate_component(Comp, 'Comp').$$render($$result, props, {}, {});
3957
+ return "" + validate_component(Comp, 'TableComponent').$$render($$result, props, {}, {});
3915
3958
  });
3916
3959
  return WrapperComp;
3917
3960
  }
@@ -3923,7 +3966,10 @@ function isSvelteServerComponent(component) {
3923
3966
  }
3924
3967
 
3925
3968
  function isSvelteClientComponent(component) {
3926
- return component.prototype instanceof SvelteComponent;
3969
+ var _component$name, _component$name2;
3970
+
3971
+ let isHMR = ('__SVELTE_HMR' in window);
3972
+ return component.prototype instanceof SvelteComponent || isHMR && ((_component$name = component.name) == null ? void 0 : _component$name.startsWith('Proxy<')) && ((_component$name2 = component.name) == null ? void 0 : _component$name2.endsWith('>'));
3927
3973
  }
3928
3974
 
3929
3975
  function isSvelteComponent(component) {
@@ -3977,6 +4023,7 @@ function createTableInstance(table, options) {
3977
4023
  onStateChange: () => {},
3978
4024
  // noop
3979
4025
  render,
4026
+ renderFallbackValue: null,
3980
4027
  ...get(optionsStore)
3981
4028
  };
3982
4029
  let instance = createTableInstance$1(resolvedOptions);