svelte-common 4.9.0 → 4.10.0
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 +20 -7
package/package.json
CHANGED
package/src/sorting.mjs
CHANGED
|
@@ -21,28 +21,41 @@ export function toggleOrderBy(orderBy) {
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Add sortable toggle to a node.
|
|
24
|
-
*
|
|
24
|
+
* Synchronizes store value with node sortable attribute.
|
|
25
25
|
* @param {Node} node
|
|
26
|
-
* @param {Store} where to
|
|
26
|
+
* @param {Store} where to keep in sync with sorting properties
|
|
27
27
|
*/
|
|
28
28
|
export function sortable(node, store) {
|
|
29
29
|
node.setAttribute("aria-sort", SORT_NONE);
|
|
30
30
|
|
|
31
|
+
store.subscribe(orderBy => {
|
|
32
|
+
for (const peer of node.parentElement.children) {
|
|
33
|
+
if (peer.getAttribute("aria-sort")) {
|
|
34
|
+
peer.setAttribute("aria-sort", orderBy[peer.id] || SORT_NONE);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
31
39
|
node.onclick = () => {
|
|
32
40
|
const orderBy = {};
|
|
41
|
+
|
|
33
42
|
node.setAttribute(
|
|
34
43
|
"aria-sort",
|
|
35
44
|
toggleOrderBy(node.getAttribute("aria-sort"))
|
|
36
45
|
);
|
|
37
46
|
|
|
38
47
|
for (const peer of node.parentElement.children) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
const sort = peer.getAttribute("aria-sort");
|
|
49
|
+
|
|
50
|
+
if (sort) {
|
|
51
|
+
if (peer !== node) {
|
|
52
|
+
if (sort !== SORT_NONE) {
|
|
53
|
+
peer.setAttribute("aria-sort", SORT_NONE);
|
|
54
|
+
}
|
|
42
55
|
}
|
|
43
|
-
}
|
|
44
56
|
|
|
45
|
-
|
|
57
|
+
orderBy[peer.id] = sort;
|
|
58
|
+
}
|
|
46
59
|
}
|
|
47
60
|
store.set(orderBy);
|
|
48
61
|
};
|