svelte-common 6.1.2 → 6.2.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/pagination.mjs +17 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "6.1.2",
3
+ "version": "6.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -48,7 +48,7 @@
48
48
  "ava": "^5.3.1",
49
49
  "c8": "^8.0.0",
50
50
  "documentation": "^14.0.2",
51
- "mf-styling": "^2.0.2",
51
+ "mf-styling": "^2.0.3",
52
52
  "npm-pkgbuild": "^11.8.14",
53
53
  "semantic-release": "^21.0.7",
54
54
  "stylelint": "^15.10.1",
@@ -11,6 +11,7 @@ export class Pagination {
11
11
  #data;
12
12
  #unsubscribeData;
13
13
  #filter;
14
+ #sorter;
14
15
  #itemsPerPage = 20;
15
16
  #page = 1;
16
17
 
@@ -32,6 +33,18 @@ export class Pagination {
32
33
  return this.#filter;
33
34
  }
34
35
 
36
+ set sorter(sorter)
37
+ {
38
+ this.#sorter = sorter;
39
+
40
+ this.#subscriptions.forEach(subscription => subscription(this));
41
+ }
42
+
43
+ get sorter()
44
+ {
45
+ return this.#sorter;
46
+ }
47
+
35
48
  set data(data) {
36
49
  if (this.#unsubscribeData) {
37
50
  this.#unsubscribeData();
@@ -116,6 +129,10 @@ export class Pagination {
116
129
  data = data.filter(this.filter);
117
130
  }
118
131
 
132
+ if(this.sorter) {
133
+ data = data.sort(this.sorter);
134
+ }
135
+
119
136
  for (const item of data.slice(
120
137
  n * this.itemsPerPage,
121
138
  (n + 1) * this.itemsPerPage