@tanstack/svelte-table 8.0.0-alpha.88 → 8.0.0-alpha.89

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.
@@ -2532,8 +2532,10 @@ const Sorting = {
2532
2532
  // })
2533
2533
  // return
2534
2534
  // }
2535
+ // this needs to be outside of instance.setSorting to be in sync with rerender
2536
+ const nextSortingOrder = column.getNextSortingOrder();
2535
2537
  instance.setSorting(old => {
2536
- var _ref2, _column$columnDef$sor, _instance$options$ena, _instance$options$ena2;
2538
+ var _instance$options$ena, _instance$options$ena2;
2537
2539
 
2538
2540
  // Find any existing sorting for this column
2539
2541
  const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
@@ -2558,30 +2560,29 @@ const Sorting = {
2558
2560
  } else {
2559
2561
  sortAction = 'replace';
2560
2562
  }
2561
- }
2563
+ } // Handle toggle states that will remove the sorting
2562
2564
 
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
2565
 
2565
2566
  if (sortAction === 'toggle' && ( // Must be toggling
2566
2567
  (_instance$options$ena = instance.options.enableSortingRemoval) != null ? _instance$options$ena : true) && // If enableSortRemove, enable in general
2567
2568
  !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)) {
2569
+ multi ? (_instance$options$ena2 = instance.options.enableMultiRemove) != null ? _instance$options$ena2 : true : true) && // If multi, don't allow if enableMultiRemove
2570
+ !nextSortingOrder // Finally, detect if it should indeed be removed
2571
+ ) {
2571
2572
  sortAction = 'remove';
2572
2573
  }
2573
2574
 
2574
2575
  if (sortAction === 'replace') {
2575
2576
  newSorting = [{
2576
2577
  id: column.id,
2577
- desc: hasDescDefined ? desc : !!sortDescFirst
2578
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2578
2579
  }];
2579
2580
  } else if (sortAction === 'add' && old != null && old.length) {
2580
2581
  var _instance$options$max;
2581
2582
 
2582
2583
  newSorting = [...old, {
2583
2584
  id: column.id,
2584
- desc: hasDescDefined ? desc : !!sortDescFirst
2585
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2585
2586
  }]; // Take latest n columns
2586
2587
 
2587
2588
  newSorting.splice(0, newSorting.length - ((_instance$options$max = instance.options.maxMultiSortColCount) != null ? _instance$options$max : Number.MAX_SAFE_INTEGER));
@@ -2590,7 +2591,7 @@ const Sorting = {
2590
2591
  newSorting = old.map(d => {
2591
2592
  if (d.id === column.id) {
2592
2593
  return { ...d,
2593
- desc: hasDescDefined ? desc : !(existingSorting != null && existingSorting.desc)
2594
+ desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
2594
2595
  };
2595
2596
  }
2596
2597
 
@@ -2603,6 +2604,23 @@ const Sorting = {
2603
2604
  return newSorting;
2604
2605
  });
2605
2606
  },
2607
+ getNextSortingOrder: () => {
2608
+ var _ref2, _column$columnDef$sor;
2609
+
2610
+ const sortDescFirst = (_ref2 = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : instance.options.sortDescFirst) != null ? _ref2 : column.getAutoSortDir() === 'desc';
2611
+ const firstSortDirection = sortDescFirst ? 'desc' : 'asc';
2612
+ const isSorted = column.getIsSorted();
2613
+
2614
+ if (!isSorted) {
2615
+ return firstSortDirection;
2616
+ }
2617
+
2618
+ if (isSorted === firstSortDirection) {
2619
+ return isSorted === 'desc' ? 'asc' : 'desc';
2620
+ } else {
2621
+ return false;
2622
+ }
2623
+ },
2606
2624
  getCanSort: () => {
2607
2625
  var _column$columnDef$ena, _instance$options$ena3;
2608
2626