svelte-common 6.14.0 → 6.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "6.14.0",
3
+ "version": "6.15.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -17,6 +17,7 @@ export class Pagination {
17
17
  #filter;
18
18
  #unsubscribeFilter;
19
19
  #sorter;
20
+ #unsubscribeSorter;
20
21
  #itemsPerPage = 20;
21
22
  #page = 1;
22
23
 
@@ -54,8 +55,21 @@ export class Pagination {
54
55
  }
55
56
 
56
57
  set sorter(sorter) {
57
- this.#sorter = sorter;
58
- this.fireSubscriptions();
58
+ if (this.#unsubscribeSorter) {
59
+ this.#unsubscribeSorter();
60
+ this.#unsubscribeSorter = undefined;
61
+ }
62
+
63
+ const applySorter = sorter => {
64
+ this.#sorter = sorter;
65
+ this.fireSubscriptions();
66
+ };
67
+
68
+ if (sorter?.subscribe) {
69
+ this.#unsubscribeFilter = sorter.subscribe(applySorter);
70
+ } else {
71
+ applySorter(sorter);
72
+ }
59
73
  }
60
74
 
61
75
  get sorter() {
@@ -167,8 +181,19 @@ export class Pagination {
167
181
  return this.#itemsPerPage;
168
182
  }
169
183
 
184
+ get filteredItems()
185
+ {
186
+ let items = Array.isArray(this.#data) ? this.#data : [...this.#data.values()];
187
+
188
+ if (this.filter) {
189
+ return items.filter(this.filter);
190
+ }
191
+
192
+ return items;
193
+ }
194
+
170
195
  *[Symbol.iterator]() {
171
- let data = Array.isArray(this.data) ? this.#data : [...this.#data.values()];
196
+ let data = Array.isArray(this.#data) ? this.#data : [...this.#data.values()];
172
197
 
173
198
  if (this.filter) {
174
199
  data = data.filter(this.filter);
@@ -56,11 +56,12 @@ export class Pagination {
56
56
  * @return {number}
57
57
  */
58
58
  get length(): number;
59
+ get filteredItems(): any[];
59
60
  /**
60
61
  * @see https://getbootstrap.com/docs/4.0/components/pagination
61
62
  * @see https://a11y-style-guide.com/style-guide/section-navigation.html#kssref-navigation-pagination
62
63
  */
63
64
  get pageNavigationElement(): HTMLElement;
64
- [Symbol.iterator](): Generator<any, void, any>;
65
+ [Symbol.iterator](): Generator<any, void, undefined>;
65
66
  #private;
66
67
  }