svelte-common 4.7.0 → 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 CHANGED
@@ -28,6 +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
+ * [toggleOrderBy](#toggleorderby)
32
+ * [Parameters](#parameters-1)
33
+ * [sortable](#sortable)
34
+ * [Parameters](#parameters-2)
31
35
 
32
36
  ## initializeServiceWorker
33
37
 
@@ -40,6 +44,26 @@ Create a store holding a service worker
40
44
 
41
45
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** store holding the service worker
42
46
 
47
+ ## toggleOrderBy
48
+
49
+ Deliver next value in the order by cycle.
50
+ SORT\_NONE -> SORT\_ASCENDING -> SORT\_DESCENDING -> SORT\_NONE ...
51
+
52
+ ### Parameters
53
+
54
+ * `orderBy` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
55
+
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)** 
66
+
43
67
  # install
44
68
 
45
69
  With [npm](http://npmjs.org) do:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "4.7.0",
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.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
@@ -45,7 +45,9 @@
45
45
  formatSecondsSinceEpoch
46
46
  } from "./util.mjs";
47
47
  export {
48
- toggleOrdeBy,
48
+ sortable,
49
+ sortableStore,
50
+ toggleOrderBy,
49
51
  orderByCycle,
50
52
  SORT_NONE,
51
53
  SORT_ASCENDING,
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,
@@ -10,7 +11,57 @@ export const orderByCycle = {
10
11
 
11
12
  /**
12
13
  * Deliver next value in the order by cycle.
13
- * @param {string} orderBy
14
+ * SORT_NONE -> SORT_ASCENDING -> SORT_DESCENDING -> SORT_NONE ...
15
+ * @param {string} orderBy
14
16
  * @returns {string} new order either SORT_NONE, SORT_ASCENDING or SORT_DESCENDING
15
17
  */
16
- export function toggleOrdeBy(orderBy) { return orderByCycle[orderBy] || "none"; }
18
+ export function toggleOrderBy(orderBy) {
19
+ return orderByCycle[orderBy] || SORT_NONE;
20
+ }
21
+
22
+ /**
23
+ * Add sortable toggle to a node.
24
+ * cycles "aria-sort" though orderByCycle.
25
+ * @param {Node} node
26
+ * @param {Store} where to put sorting info into
27
+ */
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
+ };
67
+ }