svelte-common 5.0.2 → 5.0.4

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
@@ -130,6 +130,7 @@ Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference
130
130
  ## Pagination
131
131
 
132
132
  Pagination support store.
133
+ Pages go from 1 ... numberOfPages
133
134
 
134
135
  ### Parameters
135
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "5.0.2",
3
+ "version": "5.0.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "svelte-command": "^1.1.42",
37
- "svelte-entitlement": "^1.2.53"
37
+ "svelte-entitlement": "^1.2.54"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@semantic-release/commit-analyzer": "^10.0.1",
@@ -44,7 +44,7 @@
44
44
  "ava": "^5.3.1",
45
45
  "c8": "^8.0.0",
46
46
  "documentation": "^14.0.2",
47
- "mf-styling": "^1.8.1",
47
+ "mf-styling": "^2.0.0",
48
48
  "npm-pkgbuild": "^11.8.9",
49
49
  "semantic-release": "^21.0.5",
50
50
  "stylelint": "^15.9.0",
@@ -3,16 +3,30 @@
3
3
  * Pages go from 1 ... numberOfPages
4
4
  */
5
5
  export class Pagination {
6
- subscriptions = new Set();
7
- data;
8
- itemsPerPage;
6
+ #subscriptions = new Set();
7
+ #data;
8
+ #itemsPerPage = 1;
9
9
  #page = 1;
10
10
 
11
- constructor(source, itemsPerPage = 10) {
12
- this.data = [...source];
11
+ constructor(data, itemsPerPage = 10) {
12
+ this.#data = data;
13
13
  this.itemsPerPage = itemsPerPage;
14
14
  }
15
15
 
16
+ set data(data) {
17
+ this.#data = data;
18
+ this.#subscriptions.forEach(subscription => subscription(this));
19
+ }
20
+
21
+ get itemsPerPage() {
22
+ return this.#itemsPerPage;
23
+ }
24
+
25
+ set itemsPerPage(n) {
26
+ this.#itemsPerPage = n;
27
+ this.#subscriptions.forEach(subscription => subscription(this));
28
+ }
29
+
16
30
  /**
17
31
  * Set current page
18
32
  * @param {number} n
@@ -20,7 +34,7 @@ export class Pagination {
20
34
  set page(n) {
21
35
  if (this.#page !== n && n >= 1 && n <= this.numberOfPages) {
22
36
  this.#page = n;
23
- this.subscriptions.forEach(subscription => subscription(this));
37
+ this.#subscriptions.forEach(subscription => subscription(this));
24
38
  }
25
39
  }
26
40
 
@@ -32,21 +46,26 @@ export class Pagination {
32
46
  }
33
47
 
34
48
  subscribe(s) {
35
- this.subscriptions.add(s);
49
+ this.#subscriptions.add(s);
36
50
 
37
51
  s(this);
38
52
 
39
- return () => this.subscriptions.delete(s);
53
+ return () => this.#subscriptions.delete(s);
40
54
  }
41
55
 
42
56
  get numberOfPages() {
43
- return this.data.length / this.itemsPerPage;
57
+ return (
58
+ (Array.isArray(this.#data) ? this.#data.length : this.#data.size) /
59
+ this.itemsPerPage
60
+ );
44
61
  }
45
62
 
46
63
  *items() {
47
64
  const n = this.page - 1;
48
65
 
49
- for (const item of this.data.slice(
66
+ const data = Array.isArray(this.data) ? this.#data : [...this.#data.values()];
67
+
68
+ for (const item of data.slice(
50
69
  n * this.itemsPerPage,
51
70
  (n + 1) * this.itemsPerPage
52
71
  )) {
@@ -79,7 +98,6 @@ export class Pagination {
79
98
  a.onclick = () => (this.page = targetPage);
80
99
  }
81
100
  items.push(a);
82
- return a;
83
101
  };
84
102
 
85
103
  add("<<", 1, "First Page");