svelte-common 5.0.1 → 5.0.3

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.1",
3
+ "version": "5.0.3",
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",
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * Pagination support store.
3
+ * Pages go from 1 ... numberOfPages
3
4
  */
4
5
  export class Pagination {
5
6
  subscriptions = new Set();
6
7
  data;
7
8
  itemsPerPage;
8
- #page = 0;
9
+ #page = 1;
9
10
 
10
11
  constructor(source, itemsPerPage = 10) {
11
12
  this.data = [...source];
@@ -17,7 +18,7 @@ export class Pagination {
17
18
  * @param {number} n
18
19
  */
19
20
  set page(n) {
20
- if (this.#page !== n && n > 0 && n <= this.numberOfPages) {
21
+ if (this.#page !== n && n >= 1 && n <= this.numberOfPages) {
21
22
  this.#page = n;
22
23
  this.subscriptions.forEach(subscription => subscription(this));
23
24
  }
@@ -43,7 +44,7 @@ export class Pagination {
43
44
  }
44
45
 
45
46
  *items() {
46
- const n = this.page;
47
+ const n = this.page - 1;
47
48
 
48
49
  for (const item of this.data.slice(
49
50
  n * this.itemsPerPage,
@@ -64,17 +65,24 @@ export class Pagination {
64
65
  this.subscribe(pg => {
65
66
  const items = [];
66
67
 
67
- function add(innerText, eh) {
68
+ const add = (innerText, targetPage, label) => {
68
69
  const a = document.createElement("a");
69
70
  a.setAttribute("href", "#");
71
+ if (label) {
72
+ a.setAttribute("aria-label", label);
73
+ }
70
74
  a.innerText = innerText;
71
- a.onclick = eh;
75
+ if (targetPage === this.page) {
76
+ a.disabled = true;
77
+ a.setAttribute("aria-current", "page");
78
+ } else {
79
+ a.onclick = () => (this.page = targetPage);
80
+ }
72
81
  items.push(a);
73
- return a;
74
- }
82
+ };
75
83
 
76
- add("<<", event => (this.page = 1));
77
- add("<", event => (this.page = this.page - 1));
84
+ add("<<", 1, "First Page");
85
+ add("<", this.page - 1, "Previous Page");
78
86
 
79
87
  for (let n = 1; n < this.numberOfPages; n++) {
80
88
  if (
@@ -84,15 +92,12 @@ export class Pagination {
84
92
  n % 10 === 0 ||
85
93
  (n < this.page + 3 && n > this.page - 3))
86
94
  ) {
87
- const a = add(String(n), event => (this.page = n));
88
- if (n === this.page) {
89
- a.setAttribute("aria-current", "page");
90
- }
95
+ add(String(n), n);
91
96
  }
92
97
  }
93
98
 
94
- add(">", event => (this.page = this.page + 1));
95
- add(">>", event => (this.page = this.numberOfPages));
99
+ add(">", this.page + 1, "Next Page");
100
+ add(">>", this.numberOfPages, "Last Page");
96
101
 
97
102
  nav.replaceChildren(...items);
98
103
  });