svelte-common 4.8.1 → 4.11.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 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
- * [toggleOrdeBy](#toggleordeby)
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,27 @@ 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
- ## toggleOrdeBy
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 SORT_NONE, SORT_ASCENDING or SORT_DESCENDING
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
+ Synchronizes store value with node sortable attribute.
62
+
63
+ ### Parameters
64
+
65
+ * `node` **[Node](https://developer.mozilla.org/docs/Web/API/Node/nextSibling)** 
66
+ * `store`  
67
+ * `where` **Store** to keep in sync with sorting properties
54
68
 
55
69
  # install
56
70
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "4.8.1",
3
+ "version": "4.11.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.23",
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.1",
42
+ "@sveltejs/vite-plugin-svelte": "^1.0.2",
43
43
  "ava": "^4.3.1",
44
- "documentation": "^13.2.5",
45
- "mf-styling": "^1.2.45",
44
+ "documentation": "^14.0.0",
45
+ "mf-styling": "^1.3.1",
46
46
  "npm-pkgbuild": "^10.14.8",
47
- "semantic-release": "^19.0.3",
48
- "stylelint": "^14.10.0",
49
- "stylelint-config-standard": "^27.0.0",
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.8"
52
+ "vite": "^3.0.9"
53
53
  },
54
54
  "optionalDependencies": {
55
55
  "mf-hosting": "^1.7.2"
package/src/index.svelte CHANGED
@@ -46,8 +46,8 @@
46
46
  } from "./util.mjs";
47
47
  export {
48
48
  sortable,
49
- toggleOrdeBy,
50
- orderByCycle,
49
+ toggleOrderBy,
50
+ orderByCycle,
51
51
  SORT_NONE,
52
52
  SORT_ASCENDING,
53
53
  SORT_DESCENDING
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,51 @@ 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 toggleOrdeBy(orderBy) { return orderByCycle[orderBy] || "none"; }
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
+ * Synchronizes store value with node sortable attribute.
22
25
  * @param {Node} node
26
+ * @param {Store} where to keep in sync with sorting properties
23
27
  */
24
- export function sortable(node) {
25
- node.click = () => { node.sortable = toggleOrderBy(node.sortable); };
28
+ export function sortable(node, store) {
29
+ node.setAttribute("aria-sort", SORT_NONE);
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
+
39
+ node.onclick = () => {
40
+ const orderBy = {};
41
+
42
+ node.setAttribute(
43
+ "aria-sort",
44
+ toggleOrderBy(node.getAttribute("aria-sort"))
45
+ );
46
+
47
+ for (const peer of node.parentElement.children) {
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
+ }
55
+ }
56
+
57
+ orderBy[peer.id] = sort;
58
+ }
59
+ }
60
+ store.set(orderBy);
61
+ };
26
62
  }