svelte-common 4.15.0 → 4.15.1
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/README.md +15 -2
- package/package.json +2 -2
- package/src/sorting.mjs +15 -18
package/README.md
CHANGED
|
@@ -32,6 +32,8 @@ or the [live example](https://arlac77.github.io/components/svelte-common/example
|
|
|
32
32
|
* [Parameters](#parameters-1)
|
|
33
33
|
* [sortable](#sortable)
|
|
34
34
|
* [Parameters](#parameters-2)
|
|
35
|
+
* [sorter](#sorter)
|
|
36
|
+
* [Parameters](#parameters-3)
|
|
35
37
|
|
|
36
38
|
## initializeServiceWorker
|
|
37
39
|
|
|
@@ -58,13 +60,24 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
|
|
|
58
60
|
## sortable
|
|
59
61
|
|
|
60
62
|
Add sortable toggle to a node.
|
|
61
|
-
Synchronizes store value with node
|
|
63
|
+
Synchronizes store value with node "aria-sort" attribute.
|
|
62
64
|
|
|
63
65
|
### Parameters
|
|
64
66
|
|
|
65
67
|
* `node` **[Node](https://developer.mozilla.org/docs/Web/API/Node/nextSibling)** 
|
|
66
68
|
* `store`  
|
|
67
|
-
* `
|
|
69
|
+
* `to` **WritableStore** keep in sync with sorting properties
|
|
70
|
+
|
|
71
|
+
## sorter
|
|
72
|
+
|
|
73
|
+
Generate a sort function for a given sort by set.
|
|
74
|
+
|
|
75
|
+
### Parameters
|
|
76
|
+
|
|
77
|
+
* `sortBy` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
|
|
78
|
+
* `getters` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{}`)
|
|
79
|
+
|
|
80
|
+
Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** sorter
|
|
68
81
|
|
|
69
82
|
# install
|
|
70
83
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-common",
|
|
3
|
-
"version": "4.15.
|
|
3
|
+
"version": "4.15.1",
|
|
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.5.
|
|
45
|
+
"mf-styling": "^1.5.5",
|
|
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
|
@@ -20,35 +20,30 @@ export function toggleOrderBy(orderBy) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Add sortable toggle to a node.
|
|
23
|
+
* Add sortable toggle button to a node.
|
|
24
24
|
* Synchronizes store value with node "aria-sort" attribute.
|
|
25
|
-
* @param {Node} node
|
|
25
|
+
* @param {Node} th header node
|
|
26
26
|
* @param {WritableStore} to keep in sync with sorting properties
|
|
27
27
|
*/
|
|
28
|
-
export function sortable(
|
|
29
|
-
|
|
28
|
+
export function sortable(th, store) {
|
|
29
|
+
const button = document.createElement("button");
|
|
30
|
+
const img = document.createElement("img");
|
|
31
|
+
button.appendChild(img);
|
|
30
32
|
|
|
31
|
-
store.subscribe(orderBy =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
peer.setAttribute("aria-sort", orderBy[peer.id] || SORT_NONE);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
33
|
+
store.subscribe(orderBy =>
|
|
34
|
+
th.setAttribute("aria-sort", orderBy[th.id] || SORT_NONE)
|
|
35
|
+
);
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
button.onclick = () => {
|
|
40
38
|
const orderBy = {};
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
"aria-sort",
|
|
44
|
-
toggleOrderBy(node.getAttribute("aria-sort"))
|
|
45
|
-
);
|
|
40
|
+
th.setAttribute("aria-sort", toggleOrderBy(th.getAttribute("aria-sort")));
|
|
46
41
|
|
|
47
|
-
for (const peer of
|
|
42
|
+
for (const peer of th.parentElement.children) {
|
|
48
43
|
let sort = peer.getAttribute("aria-sort");
|
|
49
44
|
|
|
50
45
|
if (sort) {
|
|
51
|
-
if (peer !==
|
|
46
|
+
if (peer !== th) {
|
|
52
47
|
if (sort !== SORT_NONE) {
|
|
53
48
|
sort = SORT_NONE;
|
|
54
49
|
peer.setAttribute("aria-sort", sort);
|
|
@@ -60,6 +55,8 @@ export function sortable(node, store) {
|
|
|
60
55
|
}
|
|
61
56
|
store.set(orderBy);
|
|
62
57
|
};
|
|
58
|
+
|
|
59
|
+
th.appendChild(button);
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
/**
|