svelte-common 4.18.2 → 4.19.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 CHANGED
@@ -34,6 +34,8 @@ or the [live example](https://arlac77.github.io/components/svelte-common/example
34
34
  * [Parameters](#parameters-2)
35
35
  * [sorter](#sorter)
36
36
  * [Parameters](#parameters-3)
37
+ * [keyPrefixStore](#keyprefixstore)
38
+ * [Parameters](#parameters-4)
37
39
 
38
40
  ## initializeServiceWorker
39
41
 
@@ -79,6 +81,17 @@ Generate a sort function for a given sort-by set.
79
81
 
80
82
  Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** sorter
81
83
 
84
+ ## keyPrefixStore
85
+
86
+ Create a store where all the object keys are prefixed.
87
+
88
+ ### Parameters
89
+
90
+ * `store` **WriteableStore** 
91
+ * `prefix` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
92
+
93
+ Returns **WriteableStore** 
94
+
82
95
  # install
83
96
 
84
97
  With [npm](http://npmjs.org) do:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "4.18.2",
3
+ "version": "4.19.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/sorting.mjs CHANGED
@@ -22,7 +22,7 @@ export function toggleOrderBy(orderBy) {
22
22
  /**
23
23
  * Add sortable toggle button with img element to a node.
24
24
  * Synchronizes store value with node "aria-sort" attribute.
25
- * @param {Node} th header node
25
+ * @param {Node} the header node
26
26
  * @param {WritableStore} to keep in sync with sorting properties
27
27
  */
28
28
  export function sortable(th, store) {
@@ -33,7 +33,7 @@ export function sortable(th, store) {
33
33
  const button = document.createElement("button");
34
34
  button.setAttribute("aria-label", `sortable ${th.id}`);
35
35
  const img = document.createElement("img");
36
- img.setAttribute("alt", "sorting order indicator");
36
+ //img.setAttribute("alt", "sorting order indicator");
37
37
 
38
38
  button.appendChild(img);
39
39
 
@@ -53,7 +53,11 @@ export function sortable(th, store) {
53
53
  }
54
54
  }
55
55
 
56
- orderBy[peer.id] = sort;
56
+ if (sort === SORT_NONE) {
57
+ delete orderBy[peer.id];
58
+ } else {
59
+ orderBy[peer.id] = sort;
60
+ }
57
61
  }
58
62
  }
59
63
  store.set(orderBy);
package/src/util.mjs CHANGED
@@ -96,7 +96,7 @@ function liveDuration(seconds) {
96
96
  */
97
97
 
98
98
  /**
99
- * Create a store where al the object keys are prefixed
99
+ * Create a store where all the object keys are prefixed.
100
100
  * @param {WriteableStore} store
101
101
  * @param {string} prefix
102
102
  * @returns {WriteableStore}
@@ -105,12 +105,16 @@ export function keyPrefixStore(store, prefix) {
105
105
  const subscriptions = new Set();
106
106
 
107
107
  let forwardSubscription;
108
+ let forwardObject;
108
109
 
109
110
  return {
110
111
  set: object =>
111
112
  store.set(
112
- Object.fromEntries(
113
- Object.entries(object).map(([k, v]) => [prefix + k, v])
113
+ Object.assign(
114
+ forwardObject,
115
+ Object.fromEntries(
116
+ Object.entries(object).map(([k, v]) => [prefix + k, v])
117
+ )
114
118
  )
115
119
  ),
116
120
 
@@ -118,12 +122,13 @@ export function keyPrefixStore(store, prefix) {
118
122
  subscriptions.add(s);
119
123
 
120
124
  if (!forwardSubscription) {
121
- forwardSubscription = store.subscribe(prefixedKeyObject => {
125
+ forwardSubscription = store.subscribe(o => {
126
+ forwardObject = o;
122
127
  const object =
123
- prefixedKeyObject === undefined
128
+ forwardObject === undefined
124
129
  ? {}
125
130
  : Object.fromEntries(
126
- Object.entries(prefixedKeyObject)
131
+ Object.entries(forwardObject)
127
132
  .filter(([k, v]) => k.startsWith(prefix))
128
133
  .map(([k, v]) => [k.substring(prefix.length), v])
129
134
  );