svelte-common 4.19.9 → 4.19.10
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/package.json +1 -1
- package/src/sorting.mjs +10 -8
package/package.json
CHANGED
package/src/sorting.mjs
CHANGED
|
@@ -9,6 +9,8 @@ export const orderByCycle = {
|
|
|
9
9
|
[SORT_DESCENDING]: SORT_ASCENDING
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
const ARIA_SORT = "aria-sort";
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* Deliver next value in the order by cycle.
|
|
14
16
|
* SORT_NONE -> SORT_ASCENDING -> SORT_DESCENDING -> SORT_NONE ...
|
|
@@ -21,17 +23,17 @@ export function toggleOrderBy(orderBy) {
|
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* Add sortable toggle button to a th node.
|
|
24
|
-
* Synchronizes store value with
|
|
26
|
+
* Synchronizes store value with the nodes "aria-sort" attribute.
|
|
25
27
|
* @param {Node} the header node
|
|
26
28
|
* @param {WritableStore} to keep in sync with sorting properties
|
|
27
29
|
*/
|
|
28
30
|
export function sortable(th, store) {
|
|
29
31
|
const storeSubscription = store.subscribe(orderBy =>
|
|
30
|
-
th.setAttribute(
|
|
32
|
+
th.setAttribute(ARIA_SORT, orderBy[th.id] || SORT_NONE)
|
|
31
33
|
);
|
|
32
34
|
|
|
33
|
-
if (!th.getAttribute(
|
|
34
|
-
th.setAttribute(
|
|
35
|
+
if (!th.getAttribute(ARIA_SORT)) {
|
|
36
|
+
th.setAttribute(ARIA_SORT, SORT_NONE);
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
const button = document.createElement("button");
|
|
@@ -40,16 +42,16 @@ export function sortable(th, store) {
|
|
|
40
42
|
button.onclick = () => {
|
|
41
43
|
const orderBy = {};
|
|
42
44
|
|
|
43
|
-
th.setAttribute(
|
|
45
|
+
th.setAttribute(ARIA_SORT, toggleOrderBy(th.getAttribute(ARIA_SORT)));
|
|
44
46
|
|
|
45
47
|
for (const peer of th.parentElement.children) {
|
|
46
|
-
let sort = peer.getAttribute(
|
|
48
|
+
let sort = peer.getAttribute(ARIA_SORT);
|
|
47
49
|
|
|
48
50
|
if (sort) {
|
|
49
51
|
if (peer !== th) {
|
|
50
52
|
if (sort !== SORT_NONE) {
|
|
51
53
|
sort = SORT_NONE;
|
|
52
|
-
peer.setAttribute(
|
|
54
|
+
peer.setAttribute(ARIA_SORT, sort);
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
|
|
@@ -93,7 +95,7 @@ export function sorter(sortBy, getters = {}) {
|
|
|
93
95
|
let bv = getter(b);
|
|
94
96
|
|
|
95
97
|
if (av === undefined) {
|
|
96
|
-
return -rev;
|
|
98
|
+
return bv === undefined ? 0 : -rev;
|
|
97
99
|
}
|
|
98
100
|
if (bv === undefined) {
|
|
99
101
|
return rev;
|