svelte-common 4.17.2 → 4.17.5

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
@@ -59,12 +59,12 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
59
59
 
60
60
  ## sortable
61
61
 
62
- Add sortable toggle to a node.
62
+ Add sortable toggle button with img element to a node.
63
63
  Synchronizes store value with node "aria-sort" attribute.
64
64
 
65
65
  ### Parameters
66
66
 
67
- * `node` **[Node](https://developer.mozilla.org/docs/Web/API/Node/nextSibling)** 
67
+ * `th` **[Node](https://developer.mozilla.org/docs/Web/API/Node/nextSibling)** header node
68
68
  * `store`  
69
69
  * `to` **WritableStore** keep in sync with sorting properties
70
70
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "4.17.2",
3
+ "version": "4.17.5",
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.3",
44
44
  "documentation": "^14.0.0",
45
- "mf-styling": "^1.7.3",
45
+ "mf-styling": "^1.7.5",
46
46
  "npm-pkgbuild": "^10.14.8",
47
47
  "semantic-release": "^19.0.5",
48
48
  "stylelint": "^14.11.0",
@@ -52,7 +52,7 @@
52
52
  "vite": "^3.0.9"
53
53
  },
54
54
  "optionalDependencies": {
55
- "mf-hosting": "^1.7.2"
55
+ "mf-hosting": "^1.7.3"
56
56
  },
57
57
  "repository": {
58
58
  "type": "git",
package/src/filter.mjs CHANGED
@@ -4,8 +4,15 @@ export function filter(filterBy, getters = {}) {
4
4
  const getter = getters[key] || (object => object && object[key]);
5
5
  return a => {
6
6
  const av = getter(a);
7
- if (typeof av === "string") {
8
- return av.match(value);
7
+
8
+ switch (typeof av) {
9
+ case "object":
10
+ return av.toString().match(value);
11
+ case "string":
12
+ return av.match(value);
13
+ case "number":
14
+ case "boolean":
15
+ return av == value;
9
16
  }
10
17
  return false;
11
18
  };
package/src/sorting.mjs CHANGED
@@ -26,13 +26,15 @@ export function toggleOrderBy(orderBy) {
26
26
  * @param {WritableStore} to keep in sync with sorting properties
27
27
  */
28
28
  export function sortable(th, store) {
29
-
30
29
  store.subscribe(orderBy =>
31
30
  th.setAttribute("aria-sort", orderBy[th.id] || SORT_NONE)
32
31
  );
33
32
 
34
33
  const button = document.createElement("button");
34
+ button.setAttribute("aria-label", `sortable ${th.id}`);
35
35
  const img = document.createElement("img");
36
+ img.setAttribute("alt", "sorting order indicator");
37
+
36
38
  button.appendChild(img);
37
39
 
38
40
  button.onclick = () => {
@@ -71,51 +73,32 @@ export function sorter(sortBy, getters = {}) {
71
73
  for (const [key, value] of Object.entries(sortBy)) {
72
74
  const getter = getters[key] || (object => object[key]);
73
75
 
76
+ let rev = 1;
77
+
74
78
  switch (value) {
79
+ case SORT_DESCENDING: rev = -1;
80
+
75
81
  case SORT_ASCENDING:
76
82
  return (a, b) => {
77
83
  const av = getter(a);
78
84
  const bv = getter(b);
79
85
  if (av === undefined) {
80
- return -1;
81
- }
82
- if (bv === undefined) {
83
- return 1;
84
- }
85
-
86
- if (typeof av === "string") {
87
- return typeof bv === "string" ? av.localeCompare(bv) : 1;
88
- }
89
- if (av instanceof Date) {
90
- const avt = av.getTime();
91
- const bvt = bv.getTime();
92
- return avt > bvt ? 1 : avt === bvt ? 0 : -1;
93
- }
94
-
95
- return av > bv ? 1 : av == bv ? 0 : -1;
96
- };
97
-
98
- case SORT_DESCENDING:
99
- return (b, a) => {
100
- const av = getter(a);
101
- const bv = getter(b);
102
- if (av === undefined) {
103
- return -1;
86
+ return -rev;
104
87
  }
105
88
  if (bv === undefined) {
106
- return 1;
89
+ return rev;
107
90
  }
108
91
 
109
92
  if (typeof av === "string") {
110
- return typeof bv === "string" ? av.localeCompare(bv) : 1;
93
+ return typeof bv === "string" ? av.localeCompare(bv) : rev;
111
94
  }
112
95
  if (av instanceof Date) {
113
96
  const avt = av.getTime();
114
97
  const bvt = bv.getTime();
115
- return avt > bvt ? 1 : avt === bvt ? 0 : -1;
98
+ return avt > bvt ? rev : avt === bvt ? 0 : -rev;
116
99
  }
117
100
 
118
- return av > bv ? 1 : av == bv ? 0 : -1;
101
+ return av > bv ? rev : av == bv ? 0 : -rev;
119
102
  };
120
103
  }
121
104
  }