@tanstack/svelte-table 8.0.0-beta.3 → 8.0.0-beta.6

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
  /**
@@ -827,7 +827,6 @@ const Expanding = {
827
827
  getDefaultOptions: instance => {
828
828
  return {
829
829
  onExpandedChange: makeStateUpdater('expanded', instance),
830
- autoResetExpanded: true,
831
830
  paginateExpandedRows: true
832
831
  };
833
832
  },
@@ -836,6 +835,8 @@ const Expanding = {
836
835
  let queued = false;
837
836
  return {
838
837
  _autoResetExpanded: () => {
838
+ var _ref, _instance$options$aut;
839
+
839
840
  if (!registered) {
840
841
  instance._queue(() => {
841
842
  registered = true;
@@ -844,11 +845,7 @@ const Expanding = {
844
845
  return;
845
846
  }
846
847
 
847
- if (instance.options.autoResetAll === false) {
848
- return;
849
- }
850
-
851
- if (instance.options.autoResetAll === true || instance.options.autoResetExpanded) {
848
+ if ((_ref = (_instance$options$aut = instance.options.autoResetAll) != null ? _instance$options$aut : instance.options.autoResetExpanded) != null ? _ref : !instance.options.manualExpanding) {
852
849
  if (queued) return;
853
850
  queued = true;
854
851
 
@@ -912,7 +909,7 @@ const Expanding = {
912
909
  });
913
910
  return maxDepth;
914
911
  },
915
- getPreExpandedRowModel: () => instance.getGroupedRowModel(),
912
+ getPreExpandedRowModel: () => instance.getSortedRowModel(),
916
913
  getExpandedRowModel: () => {
917
914
  if (!instance._getExpandedRowModel && instance.options.getExpandedRowModel) {
918
915
  instance._getExpandedRowModel = instance.options.getExpandedRowModel(instance);
@@ -1513,7 +1510,7 @@ const Grouping = {
1513
1510
 
1514
1511
  instance.setGrouping(defaultState ? [] : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.grouping) != null ? _instance$initialStat : []);
1515
1512
  },
1516
- getPreGroupedRowModel: () => instance.getSortedRowModel(),
1513
+ getPreGroupedRowModel: () => instance.getFilteredRowModel(),
1517
1514
  getGroupedRowModel: () => {
1518
1515
  if (!instance._getGroupedRowModel && instance.options.getGroupedRowModel) {
1519
1516
  instance._getGroupedRowModel = instance.options.getGroupedRowModel(instance);
@@ -1534,6 +1531,12 @@ const Grouping = {
1534
1531
  };
1535
1532
  },
1536
1533
  createCell: (cell, column, row, instance) => {
1534
+ const getRenderValue = () => {
1535
+ var _cell$getValue;
1536
+
1537
+ return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
1538
+ };
1539
+
1537
1540
  return {
1538
1541
  getIsGrouped: () => column.getIsGrouped() && column.id === row.groupingColumnId,
1539
1542
  getIsPlaceholder: () => !cell.getIsGrouped() && column.getIsGrouped(),
@@ -1543,15 +1546,19 @@ const Grouping = {
1543
1546
  return !cell.getIsGrouped() && !cell.getIsPlaceholder() && ((_row$subRows = row.subRows) == null ? void 0 : _row$subRows.length) > 1;
1544
1547
  },
1545
1548
  renderAggregatedCell: () => {
1546
- var _column$columnDef$agg;
1549
+ if (process.env.NODE_ENV === 'development') {
1550
+ if (!column.columnDef.aggregatedCell) {
1551
+ console.warn('A columnDef.aggregatedCell template is recommended for displaying aggregated values.');
1552
+ }
1553
+ }
1547
1554
 
1548
- const template = (_column$columnDef$agg = column.columnDef.aggregatedCell) != null ? _column$columnDef$agg : column.columnDef.cell;
1555
+ const template = column.columnDef.aggregatedCell || column.columnDef.cell;
1549
1556
  return template ? instance._render(template, {
1550
1557
  instance,
1551
1558
  column,
1552
1559
  row,
1553
1560
  cell,
1554
- getValue: cell.getValue
1561
+ getValue: getRenderValue
1555
1562
  }) : null;
1556
1563
  }
1557
1564
  };
@@ -2021,11 +2028,11 @@ const RowSelection = {
2021
2028
  });
2022
2029
  },
2023
2030
  toggleAllPageRowsSelected: value => instance.setRowSelection(old => {
2024
- typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
2031
+ const resolvedValue = typeof value !== 'undefined' ? value : !instance.getIsAllPageRowsSelected();
2025
2032
  const rowSelection = { ...old
2026
2033
  };
2027
2034
  instance.getRowModel().rows.forEach(row => {
2028
- mutateRowIsSelected(rowSelection, row.id, value, instance);
2035
+ mutateRowIsSelected(rowSelection, row.id, resolvedValue, instance);
2029
2036
  });
2030
2037
  return rowSelection;
2031
2038
  }),
@@ -2116,7 +2123,7 @@ const RowSelection = {
2116
2123
  return (_instance$options$deb2 = instance.options.debugAll) != null ? _instance$options$deb2 : instance.options.debugTable;
2117
2124
  }
2118
2125
  }),
2119
- getGroupedSelectedRowModel: memo(() => [instance.getState().rowSelection, instance.getGroupedRowModel()], (rowSelection, rowModel) => {
2126
+ getGroupedSelectedRowModel: memo(() => [instance.getState().rowSelection, instance.getSortedRowModel()], (rowSelection, rowModel) => {
2120
2127
  if (!Object.keys(rowSelection).length) {
2121
2128
  return {
2122
2129
  rows: [],
@@ -2180,7 +2187,7 @@ const RowSelection = {
2180
2187
  },
2181
2188
  getIsSomePageRowsSelected: () => {
2182
2189
  const paginationFlatRows = instance.getPaginationRowModel().flatRows;
2183
- return instance.getIsAllPageRowsSelected() ? false : !!(paginationFlatRows != null && paginationFlatRows.length);
2190
+ return instance.getIsAllPageRowsSelected() ? false : paginationFlatRows.some(d => d.getIsSelected() || d.getIsSomeSelected());
2184
2191
  },
2185
2192
  getToggleAllRowsSelectedHandler: () => {
2186
2193
  return e => {
@@ -2534,8 +2541,10 @@ const Sorting = {
2534
2541
  // })
2535
2542
  // return
2536
2543
  // }
2544
+ // this needs to be outside of instance.setSorting to be in sync with rerender
2545
+ const nextSortingOrder = column.getNextSortingOrder();
2537
2546
  instance.setSorting(old => {
2538
- var _ref2, _column$columnDef$sor, _instance$options$ena, _instance$options$ena2;
2547
+ var _instance$options$ena, _instance$options$ena2;
2539
2548
 
2540
2549
  // Find any existing sorting for this column
2541
2550
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
@@ -2560,30 +2569,29 @@ const Sorting = {
2560
2569
  } else {
2561
2570
  sortAction = 'replace';
2562
2571
  }
2563
- }
2572
+ } // Handle toggle states that will remove the sorting
2564
2573
 
2565
- 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
2566
2574
 
2567
2575
  if (sortAction === 'toggle' && ( // Must be toggling
2568
2576
  (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2569
2577
  !hasDescDefined && ( // Must not be setting desc
2570
- multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && ( // If multi, don't allow if enableMultiRemove
2571
- existingSorting != null && existingSorting.desc // Finally, detect if it should indeed be removed
2572
- ? !sortDescFirst : sortDescFirst)) {
2578
+ multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && // If multi, don't allow if enableMultiRemove
2579
+ !nextSortingOrder // Finally, detect if it should indeed be removed
2580
+ ) {
2573
2581
  sortAction = 'remove';
2574
2582
  }
2575
2583
 
2576
2584
  if (sortAction === 'replace') {
2577
2585
  newSorting = [{
2578
2586
  id: column.id,
2579
- desc: hasDescDefined ? desc : !!sortDescFirst
2587
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2580
2588
  }];
2581
2589
  } else if (sortAction === 'add' && old != null && old.length) {
2582
2590
  var _instance$options$max;
2583
2591
 
2584
2592
  newSorting = [...old, {
2585
2593
  id: column.id,
2586
- desc: hasDescDefined ? desc : !!sortDescFirst
2594
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2587
2595
  }]; // Take latest n columns
2588
2596
 
2589
2597
  newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
@@ -2592,7 +2600,7 @@ const Sorting = {
2592
2600
  newSorting = old.map(d => {
2593
2601
  if (d.id === column.id) {
2594
2602
  return { ...d,
2595
- desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2603
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2596
2604
  };
2597
2605
  }
2598
2606
 
@@ -2605,6 +2613,23 @@ const Sorting = {
2605
2613
  return newSorting;
2606
2614
  });
2607
2615
  },
2616
+ getNextSortingOrder: () => {
2617
+ var _ref2, _column$columnDef$sor;
2618
+
2619
+ const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc';
2620
+ const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
2621
+ const isSorted = column.getIsSorted();
2622
+
2623
+ if (!isSorted) {
2624
+ return firstSortDirection;
2625
+ }
2626
+
2627
+ if (isSorted === firstSortDirection) {
2628
+ return isSorted === 'desc' ? 'asc' : 'desc';
2629
+ } else {
2630
+ return false;
2631
+ }
2632
+ },
2608
2633
  getCanSort: () => {
2609
2634
  var _column$columnDef$ena, _instance$options$ena3;
2610
2635
 
@@ -2648,7 +2673,7 @@ const Sorting = {
2648
2673
 
2649
2674
  instance.setSorting(defaultState ? [] : (_instance$initialStat = (_instance$initialStat2 = instance.initialState) == null ? void 0 : _instance$initialStat2.sorting) != null ? _instance$initialStat : []);
2650
2675
  },
2651
- getPreSortedRowModel: () => instance.getFilteredRowModel(),
2676
+ getPreSortedRowModel: () => instance.getGroupedRowModel(),
2652
2677
  getSortedRowModel: () => {
2653
2678
  if (!instance._getSortedRowModel && instance.options.getSortedRowModel) {
2654
2679
  instance._getSortedRowModel = instance.options.getSortedRowModel(instance);
@@ -3054,6 +3079,12 @@ function createTable$1(_, __, options) {
3054
3079
  }
3055
3080
 
3056
3081
  function createCell(instance, row, column, columnId) {
3082
+ const getRenderValue = () => {
3083
+ var _cell$getValue;
3084
+
3085
+ return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : instance.options.renderFallbackValue;
3086
+ };
3087
+
3057
3088
  const cell = {
3058
3089
  id: row.id + "_" + column.id,
3059
3090
  row,
@@ -3065,7 +3096,7 @@ function createCell(instance, row, column, columnId) {
3065
3096
  column,
3066
3097
  row,
3067
3098
  cell: cell,
3068
- getValue: cell.getValue
3099
+ getValue: getRenderValue
3069
3100
  }) : null;
3070
3101
  }
3071
3102
  };
@@ -3794,20 +3825,34 @@ function getPaginationRowModel(opts) {
3794
3825
  const pageStart = pageSize * pageIndex;
3795
3826
  const pageEnd = pageStart + pageSize;
3796
3827
  rows = rows.slice(pageStart, pageEnd);
3828
+ let paginatedRowModel;
3797
3829
 
3798
3830
  if (!instance.options.paginateExpandedRows) {
3799
- return expandRows({
3831
+ paginatedRowModel = expandRows({
3800
3832
  rows,
3801
3833
  flatRows,
3802
3834
  rowsById
3803
3835
  });
3836
+ } else {
3837
+ paginatedRowModel = {
3838
+ rows,
3839
+ flatRows,
3840
+ rowsById
3841
+ };
3804
3842
  }
3805
3843
 
3806
- return {
3807
- rows,
3808
- flatRows,
3809
- rowsById
3844
+ paginatedRowModel.flatRows = [];
3845
+
3846
+ const handleRow = row => {
3847
+ paginatedRowModel.flatRows.push(row);
3848
+
3849
+ if (row.subRows.length) {
3850
+ row.subRows.forEach(handleRow);
3851
+ }
3810
3852
  };
3853
+
3854
+ paginatedRowModel.rows.forEach(handleRow);
3855
+ return paginatedRowModel;
3811
3856
  }, {
3812
3857
  key: process.env.NODE_ENV === 'development' && 'getPaginationRowModel',
3813
3858
  debug: () => {
@@ -3827,8 +3872,11 @@ function create_fragment$1(ctx) {
3827
3872
  c() {
3828
3873
  t = text$1(/*content*/ ctx[0]);
3829
3874
  },
3875
+ l(nodes) {
3876
+ t = claim_text(nodes, /*content*/ ctx[0]);
3877
+ },
3830
3878
  m(target, anchor) {
3831
- insert(target, t, anchor);
3879
+ insert_hydration(target, t, anchor);
3832
3880
  },
3833
3881
  p(ctx, [dirty]) {
3834
3882
  if (dirty & /*content*/ 1) set_data(t, /*content*/ ctx[0]);
@@ -3851,13 +3899,18 @@ function instance($$self, $$props, $$invalidate) {
3851
3899
  return [content];
3852
3900
  }
3853
3901
 
3854
- class Placeholder extends SvelteComponent {
3902
+ class Placeholder$1 extends SvelteComponent {
3855
3903
  constructor(options) {
3856
3904
  super();
3857
3905
  init(this, options, instance, create_fragment$1, safe_not_equal, { content: 0 });
3858
3906
  }
3859
3907
  }
3860
3908
 
3909
+ const PlaceholderServer = create_ssr_component(($$result, $$props, $$bindings, slots) => {
3910
+ return "" + escape($$props.content);
3911
+ });
3912
+ var Placeholder = typeof document === 'undefined' ? PlaceholderServer : Placeholder$1;
3913
+
3861
3914
  function create_fragment(ctx, Comp, props) {
3862
3915
  let c;
3863
3916
  let current;
@@ -3870,6 +3923,10 @@ function create_fragment(ctx, Comp, props) {
3870
3923
  create_component(c.$$.fragment);
3871
3924
  },
3872
3925
 
3926
+ l(nodes) {
3927
+ claim_component(c.$$.fragment, nodes);
3928
+ },
3929
+
3873
3930
  m(target, anchor) {
3874
3931
  // @ts-ignore
3875
3932
  mount_component(c, target, anchor);
@@ -3908,7 +3965,7 @@ function renderClient(Comp, props) {
3908
3965
 
3909
3966
  function renderServer(Comp, props) {
3910
3967
  const WrapperComp = create_ssr_component(($$result, $$props, $$bindings, slots) => {
3911
- return "" + validate_component(Comp, 'Comp').$$render($$result, props, {}, {});
3968
+ return "" + validate_component(Comp, 'TableComponent').$$render($$result, props, {}, {});
3912
3969
  });
3913
3970
  return WrapperComp;
3914
3971
  }
@@ -3920,7 +3977,10 @@ function isSvelteServerComponent(component) {
3920
3977
  }
3921
3978
 
3922
3979
  function isSvelteClientComponent(component) {
3923
- return component.prototype instanceof SvelteComponent;
3980
+ var _component$name, _component$name2;
3981
+
3982
+ let isHMR = ('__SVELTE_HMR' in window);
3983
+ 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('>'));
3924
3984
  }
3925
3985
 
3926
3986
  function isSvelteComponent(component) {
@@ -3974,6 +4034,7 @@ function createTableInstance(table, options) {
3974
4034
  onStateChange: () => {},
3975
4035
  // noop
3976
4036
  render,
4037
+ renderFallbackValue: null,
3977
4038
  ...get(optionsStore)
3978
4039
  };
3979
4040
  let instance = createTableInstance$1(resolvedOptions);