svelte-common 4.11.0 → 4.13.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 +3 -3
- package/src/index.svelte +1 -0
- package/src/sorting.mjs +29 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-common",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,9 +42,9 @@
|
|
|
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.4.0",
|
|
46
46
|
"npm-pkgbuild": "^10.14.8",
|
|
47
|
-
"semantic-release": "^19.0.
|
|
47
|
+
"semantic-release": "^19.0.5",
|
|
48
48
|
"stylelint": "^14.11.0",
|
|
49
49
|
"stylelint-config-standard": "^28.0.0",
|
|
50
50
|
"svelte": "^3.49.0",
|
package/src/index.svelte
CHANGED
package/src/sorting.mjs
CHANGED
|
@@ -21,9 +21,9 @@ export function toggleOrderBy(orderBy) {
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Add sortable toggle to a node.
|
|
24
|
-
* Synchronizes store value with node
|
|
24
|
+
* Synchronizes store value with node "aria-sort" attribute.
|
|
25
25
|
* @param {Node} node
|
|
26
|
-
* @param {Store}
|
|
26
|
+
* @param {Store} to keep in sync with sorting properties
|
|
27
27
|
*/
|
|
28
28
|
export function sortable(node, store) {
|
|
29
29
|
node.setAttribute("aria-sort", SORT_NONE);
|
|
@@ -60,3 +60,30 @@ export function sortable(node, store) {
|
|
|
60
60
|
store.set(orderBy);
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Generate a sort function for a given sort by set.
|
|
66
|
+
* @param {Object} sortBy
|
|
67
|
+
* @param {Object} getters
|
|
68
|
+
* @return {Function} sorter
|
|
69
|
+
*/
|
|
70
|
+
export function sorter(sortBy, getters = {}) {
|
|
71
|
+
if (sortBy) {
|
|
72
|
+
for (const [key, value] of Object.entries(sortBy)) {
|
|
73
|
+
const getter = getters[key];
|
|
74
|
+
|
|
75
|
+
switch (value) {
|
|
76
|
+
case SORT_ASCENDING:
|
|
77
|
+
if (getter) {
|
|
78
|
+
return (a, b) => getter(a).localeCompare(getter(b));
|
|
79
|
+
}
|
|
80
|
+
return (a, b) => a[key].localeCompare(b[key]);
|
|
81
|
+
case SORT_DESCENDING:
|
|
82
|
+
if (getter) {
|
|
83
|
+
return (b, a) => getter(a).localeCompare(getter(b));
|
|
84
|
+
}
|
|
85
|
+
return (b, a) => a[key].localeCompare(b[key]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|