@tanstack/svelte-table 8.2.1 → 8.2.2
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.
- package/build/cjs/table-core/build/esm/index.js +39 -27
- package/build/cjs/table-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +39 -27
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +47 -47
- package/build/umd/index.development.js +39 -27
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
package/build/esm/index.js
CHANGED
|
@@ -2362,7 +2362,12 @@ const textCaseSensitive = (rowA, rowB, columnId) => {
|
|
|
2362
2362
|
};
|
|
2363
2363
|
|
|
2364
2364
|
const datetime = (rowA, rowB, columnId) => {
|
|
2365
|
-
|
|
2365
|
+
const a = rowA.getValue(columnId);
|
|
2366
|
+
const b = rowB.getValue(columnId); // Can handle nullish values
|
|
2367
|
+
// Use > and < because == (and ===) doesn't work with
|
|
2368
|
+
// Date objects (would require calling getTime()).
|
|
2369
|
+
|
|
2370
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
|
2366
2371
|
};
|
|
2367
2372
|
|
|
2368
2373
|
const basic = (rowA, rowB, columnId) => {
|
|
@@ -2523,18 +2528,17 @@ const Sorting = {
|
|
|
2523
2528
|
// }
|
|
2524
2529
|
// this needs to be outside of table.setSorting to be in sync with rerender
|
|
2525
2530
|
const nextSortingOrder = column.getNextSortingOrder();
|
|
2531
|
+
const hasManualValue = typeof desc !== 'undefined' && desc !== null;
|
|
2526
2532
|
table.setSorting(old => {
|
|
2527
|
-
var _table$options$enable, _table$options$enable2;
|
|
2528
|
-
|
|
2529
2533
|
// Find any existing sorting for this column
|
|
2530
2534
|
const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
|
|
2531
2535
|
const existingIndex = old == null ? void 0 : old.findIndex(d => d.id === column.id);
|
|
2532
|
-
const hasDescDefined = typeof desc !== 'undefined' && desc !== null;
|
|
2533
2536
|
let newSorting = []; // What should we do with this sort action?
|
|
2534
2537
|
|
|
2535
2538
|
let sortAction;
|
|
2539
|
+
let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'; // Multi-mode
|
|
2536
2540
|
|
|
2537
|
-
if (column.getCanMultiSort() && multi) {
|
|
2541
|
+
if (old != null && old.length && column.getCanMultiSort() && multi) {
|
|
2538
2542
|
if (existingSorting) {
|
|
2539
2543
|
sortAction = 'toggle';
|
|
2540
2544
|
} else {
|
|
@@ -2552,63 +2556,71 @@ const Sorting = {
|
|
|
2552
2556
|
} // Handle toggle states that will remove the sorting
|
|
2553
2557
|
|
|
2554
2558
|
|
|
2555
|
-
if (sortAction === 'toggle'
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2559
|
+
if (sortAction === 'toggle') {
|
|
2560
|
+
// If we are "actually" toggling (not a manual set value), should we remove the sorting?
|
|
2561
|
+
if (!hasManualValue) {
|
|
2562
|
+
// Is our intention to remove?
|
|
2563
|
+
if (!nextSortingOrder) {
|
|
2564
|
+
sortAction = 'remove';
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2562
2567
|
}
|
|
2563
2568
|
|
|
2564
|
-
if (sortAction === '
|
|
2565
|
-
newSorting = [{
|
|
2566
|
-
id: column.id,
|
|
2567
|
-
desc: hasDescDefined ? desc : nextSortingOrder === 'desc'
|
|
2568
|
-
}];
|
|
2569
|
-
} else if (sortAction === 'add' && old != null && old.length) {
|
|
2569
|
+
if (sortAction === 'add') {
|
|
2570
2570
|
var _table$options$maxMul;
|
|
2571
2571
|
|
|
2572
2572
|
newSorting = [...old, {
|
|
2573
2573
|
id: column.id,
|
|
2574
|
-
desc:
|
|
2574
|
+
desc: nextDesc
|
|
2575
2575
|
}]; // Take latest n columns
|
|
2576
2576
|
|
|
2577
2577
|
newSorting.splice(0, newSorting.length - ((_table$options$maxMul = table.options.maxMultiSortColCount) != null ? _table$options$maxMul : Number.MAX_SAFE_INTEGER));
|
|
2578
|
-
} else if (sortAction === 'toggle'
|
|
2578
|
+
} else if (sortAction === 'toggle') {
|
|
2579
2579
|
// This flips (or sets) the
|
|
2580
2580
|
newSorting = old.map(d => {
|
|
2581
2581
|
if (d.id === column.id) {
|
|
2582
2582
|
return { ...d,
|
|
2583
|
-
desc:
|
|
2583
|
+
desc: nextDesc
|
|
2584
2584
|
};
|
|
2585
2585
|
}
|
|
2586
2586
|
|
|
2587
2587
|
return d;
|
|
2588
2588
|
});
|
|
2589
|
-
} else if (sortAction === 'remove'
|
|
2589
|
+
} else if (sortAction === 'remove') {
|
|
2590
2590
|
newSorting = old.filter(d => d.id !== column.id);
|
|
2591
|
+
} else {
|
|
2592
|
+
newSorting = [{
|
|
2593
|
+
id: column.id,
|
|
2594
|
+
desc: nextDesc
|
|
2595
|
+
}];
|
|
2591
2596
|
}
|
|
2592
2597
|
|
|
2593
2598
|
return newSorting;
|
|
2594
2599
|
});
|
|
2595
2600
|
},
|
|
2596
|
-
|
|
2601
|
+
getFirstSortDir: () => {
|
|
2597
2602
|
var _ref, _column$columnDef$sor;
|
|
2598
2603
|
|
|
2599
2604
|
const sortDescFirst = (_ref = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : table.options.sortDescFirst) != null ? _ref : column.getAutoSortDir() === 'desc';
|
|
2600
|
-
|
|
2605
|
+
return sortDescFirst ? 'desc' : 'asc';
|
|
2606
|
+
},
|
|
2607
|
+
getNextSortingOrder: multi => {
|
|
2608
|
+
var _table$options$enable, _table$options$enable2;
|
|
2609
|
+
|
|
2610
|
+
const firstSortDirection = column.getFirstSortDir();
|
|
2601
2611
|
const isSorted = column.getIsSorted();
|
|
2602
2612
|
|
|
2603
2613
|
if (!isSorted) {
|
|
2604
2614
|
return firstSortDirection;
|
|
2605
2615
|
}
|
|
2606
2616
|
|
|
2607
|
-
if (isSorted
|
|
2608
|
-
|
|
2609
|
-
|
|
2617
|
+
if (isSorted !== firstSortDirection && ((_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && ( // If enableSortRemove, enable in general
|
|
2618
|
+
multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true) // If multi, don't allow if enableMultiRemove))
|
|
2619
|
+
) {
|
|
2610
2620
|
return false;
|
|
2611
2621
|
}
|
|
2622
|
+
|
|
2623
|
+
return isSorted === 'desc' ? 'asc' : 'desc';
|
|
2612
2624
|
},
|
|
2613
2625
|
getCanSort: () => {
|
|
2614
2626
|
var _column$columnDef$ena, _table$options$enable3;
|