svelte-common 4.8.1 → 4.9.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/README.md +16 -4
- package/package.json +9 -9
- package/src/index.svelte +3 -2
- package/src/sorting.mjs +46 -5
package/README.md
CHANGED
|
@@ -28,8 +28,10 @@ or the [live example](https://arlac77.github.io/components/svelte-common/example
|
|
|
28
28
|
|
|
29
29
|
* [initializeServiceWorker](#initializeserviceworker)
|
|
30
30
|
* [Parameters](#parameters)
|
|
31
|
-
* [
|
|
31
|
+
* [toggleOrderBy](#toggleorderby)
|
|
32
32
|
* [Parameters](#parameters-1)
|
|
33
|
+
* [sortable](#sortable)
|
|
34
|
+
* [Parameters](#parameters-2)
|
|
33
35
|
|
|
34
36
|
## initializeServiceWorker
|
|
35
37
|
|
|
@@ -42,15 +44,25 @@ Create a store holding a service worker
|
|
|
42
44
|
|
|
43
45
|
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** store holding the service worker
|
|
44
46
|
|
|
45
|
-
##
|
|
47
|
+
## toggleOrderBy
|
|
46
48
|
|
|
47
49
|
Deliver next value in the order by cycle.
|
|
50
|
+
SORT\_NONE -> SORT\_ASCENDING -> SORT\_DESCENDING -> SORT\_NONE ...
|
|
48
51
|
|
|
49
52
|
### Parameters
|
|
50
53
|
|
|
51
|
-
* `orderBy` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)
|
|
54
|
+
* `orderBy` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
|
|
52
55
|
|
|
53
|
-
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** new order either
|
|
56
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** new order either SORT\_NONE, SORT\_ASCENDING or SORT\_DESCENDING
|
|
57
|
+
|
|
58
|
+
## sortable
|
|
59
|
+
|
|
60
|
+
Add sortable toggle to a node.
|
|
61
|
+
cycles "aria-sort" though orderByCycle.
|
|
62
|
+
|
|
63
|
+
### Parameters
|
|
64
|
+
|
|
65
|
+
* `node` **[Node](https://developer.mozilla.org/docs/Web/API/Node/nextSibling)** 
|
|
54
66
|
|
|
55
67
|
# install
|
|
56
68
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-common",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -32,24 +32,24 @@
|
|
|
32
32
|
"preview": "vite preview"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"svelte-command": "^1.1.
|
|
35
|
+
"svelte-command": "^1.1.24",
|
|
36
36
|
"svelte-entitlement": "^1.2.30"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
40
40
|
"@semantic-release/exec": "^6.0.3",
|
|
41
41
|
"@semantic-release/release-notes-generator": "^10.0.3",
|
|
42
|
-
"@sveltejs/vite-plugin-svelte": "^1.0.
|
|
42
|
+
"@sveltejs/vite-plugin-svelte": "^1.0.2",
|
|
43
43
|
"ava": "^4.3.1",
|
|
44
|
-
"documentation": "^
|
|
45
|
-
"mf-styling": "^1.
|
|
44
|
+
"documentation": "^14.0.0",
|
|
45
|
+
"mf-styling": "^1.3.1",
|
|
46
46
|
"npm-pkgbuild": "^10.14.8",
|
|
47
|
-
"semantic-release": "^19.0.
|
|
48
|
-
"stylelint": "^14.
|
|
49
|
-
"stylelint-config-standard": "^
|
|
47
|
+
"semantic-release": "^19.0.4",
|
|
48
|
+
"stylelint": "^14.11.0",
|
|
49
|
+
"stylelint-config-standard": "^28.0.0",
|
|
50
50
|
"svelte": "^3.49.0",
|
|
51
51
|
"testcafe": "^1.20.1",
|
|
52
|
-
"vite": "^3.0.
|
|
52
|
+
"vite": "^3.0.9"
|
|
53
53
|
},
|
|
54
54
|
"optionalDependencies": {
|
|
55
55
|
"mf-hosting": "^1.7.2"
|
package/src/index.svelte
CHANGED
package/src/sorting.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const SORT_NONE = "none";
|
|
2
2
|
export const SORT_ASCENDING = "ascending";
|
|
3
3
|
export const SORT_DESCENDING = "descending";
|
|
4
|
+
export const SORT_OTHER = "other";
|
|
4
5
|
|
|
5
6
|
export const orderByCycle = {
|
|
6
7
|
[SORT_NONE]: SORT_ASCENDING,
|
|
@@ -11,16 +12,56 @@ export const orderByCycle = {
|
|
|
11
12
|
/**
|
|
12
13
|
* Deliver next value in the order by cycle.
|
|
13
14
|
* SORT_NONE -> SORT_ASCENDING -> SORT_DESCENDING -> SORT_NONE ...
|
|
14
|
-
* @param {string} orderBy
|
|
15
|
+
* @param {string} orderBy
|
|
15
16
|
* @returns {string} new order either SORT_NONE, SORT_ASCENDING or SORT_DESCENDING
|
|
16
17
|
*/
|
|
17
|
-
export function
|
|
18
|
-
|
|
18
|
+
export function toggleOrderBy(orderBy) {
|
|
19
|
+
return orderByCycle[orderBy] || SORT_NONE;
|
|
20
|
+
}
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Add sortable toggle to a node.
|
|
24
|
+
* cycles "aria-sort" though orderByCycle.
|
|
22
25
|
* @param {Node} node
|
|
26
|
+
* @param {Store} where to put sorting info into
|
|
23
27
|
*/
|
|
24
|
-
export function sortable(node) {
|
|
25
|
-
node.
|
|
28
|
+
export function sortable(node, store) {
|
|
29
|
+
node.setAttribute("aria-sort", SORT_NONE);
|
|
30
|
+
|
|
31
|
+
node.onclick = () => {
|
|
32
|
+
const orderBy = {};
|
|
33
|
+
node.setAttribute(
|
|
34
|
+
"aria-sort",
|
|
35
|
+
toggleOrderBy(node.getAttribute("aria-sort"))
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
for (const peer of node.parentElement.children) {
|
|
39
|
+
if (peer !== node) {
|
|
40
|
+
if (peer.getAttribute("aria-sort") !== SORT_NONE) {
|
|
41
|
+
peer.setAttribute("aria-sort", SORT_NONE);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
orderBy[peer.id] = peer.getAttribute("aria-sort");
|
|
46
|
+
}
|
|
47
|
+
store.set(orderBy);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function sortableStore() {
|
|
52
|
+
const subscriptions = new Set();
|
|
53
|
+
|
|
54
|
+
let value = {};
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
subscribe: cb => {
|
|
58
|
+
subscriptions.add(cb);
|
|
59
|
+
cb(value);
|
|
60
|
+
return () => subscriptions.delete(cb);
|
|
61
|
+
},
|
|
62
|
+
set(v) {
|
|
63
|
+
value = v;
|
|
64
|
+
subscriptions.forEach(subscription => subscription(value));
|
|
65
|
+
}
|
|
66
|
+
};
|
|
26
67
|
}
|