svelte-common 4.13.0 → 4.13.3
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 +2 -2
- package/src/sorting.mjs +22 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-common",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@sveltejs/vite-plugin-svelte": "^1.0.2",
|
|
43
43
|
"ava": "^4.3.1",
|
|
44
44
|
"documentation": "^14.0.0",
|
|
45
|
-
"mf-styling": "^1.
|
|
45
|
+
"mf-styling": "^1.5.0",
|
|
46
46
|
"npm-pkgbuild": "^10.14.8",
|
|
47
47
|
"semantic-release": "^19.0.5",
|
|
48
48
|
"stylelint": "^14.11.0",
|
package/src/sorting.mjs
CHANGED
|
@@ -23,7 +23,7 @@ export function toggleOrderBy(orderBy) {
|
|
|
23
23
|
* Add sortable toggle to a node.
|
|
24
24
|
* Synchronizes store value with node "aria-sort" attribute.
|
|
25
25
|
* @param {Node} node
|
|
26
|
-
* @param {
|
|
26
|
+
* @param {WritableStore} to keep in sync with sorting properties
|
|
27
27
|
*/
|
|
28
28
|
export function sortable(node, store) {
|
|
29
29
|
node.setAttribute("aria-sort", SORT_NONE);
|
|
@@ -45,12 +45,13 @@ export function sortable(node, store) {
|
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
for (const peer of node.parentElement.children) {
|
|
48
|
-
|
|
48
|
+
let sort = peer.getAttribute("aria-sort");
|
|
49
49
|
|
|
50
50
|
if (sort) {
|
|
51
51
|
if (peer !== node) {
|
|
52
52
|
if (sort !== SORT_NONE) {
|
|
53
|
-
|
|
53
|
+
sort = SORT_NONE;
|
|
54
|
+
peer.setAttribute("aria-sort", sort);
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
@@ -70,19 +71,28 @@ export function sortable(node, store) {
|
|
|
70
71
|
export function sorter(sortBy, getters = {}) {
|
|
71
72
|
if (sortBy) {
|
|
72
73
|
for (const [key, value] of Object.entries(sortBy)) {
|
|
73
|
-
const getter = getters[key];
|
|
74
|
+
const getter = getters[key] || (object => object[key]);
|
|
74
75
|
|
|
75
76
|
switch (value) {
|
|
76
77
|
case SORT_ASCENDING:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
return (a, b) => {
|
|
79
|
+
const av = getter(a);
|
|
80
|
+
if (typeof av === "string") {
|
|
81
|
+
const bv = getter(b);
|
|
82
|
+
return typeof bv === "string" ? av.localeCompare(bv) : 1;
|
|
83
|
+
}
|
|
84
|
+
return -1;
|
|
85
|
+
};
|
|
86
|
+
|
|
81
87
|
case SORT_DESCENDING:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
return (a, b) => {
|
|
89
|
+
const av = getter(a);
|
|
90
|
+
if (typeof av === "string") {
|
|
91
|
+
const bv = getter(b);
|
|
92
|
+
return typeof bv === "string" ? av.localeCompare(bv) : 1;
|
|
93
|
+
}
|
|
94
|
+
return -1;
|
|
95
|
+
};
|
|
86
96
|
}
|
|
87
97
|
}
|
|
88
98
|
}
|