svelte-common 5.2.0 → 5.2.2

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 +1 -1
  2. package/src/pagination.mjs +14 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "5.2.0",
3
+ "version": "5.2.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,8 +32,6 @@ export class Pagination {
32
32
  this.#subscriptions.forEach(subscription => subscription(this));
33
33
  }
34
34
 
35
-
36
-
37
35
  get itemsPerPage() {
38
36
  return this.#itemsPerPage;
39
37
  }
@@ -72,7 +70,7 @@ export class Pagination {
72
70
  get numberOfPages() {
73
71
  return Math.ceil(
74
72
  (Array.isArray(this.#data) ? this.#data.length : this.#data.size) /
75
- this.itemsPerPage
73
+ this.itemsPerPage
76
74
  );
77
75
  }
78
76
 
@@ -81,7 +79,7 @@ export class Pagination {
81
79
  }
82
80
 
83
81
  *[Symbol.iterator]() {
84
- const n = this.page - 1;
82
+ const n = this.page - 1;
85
83
 
86
84
  const data = Array.isArray(this.data)
87
85
  ? this.#data
@@ -99,7 +97,7 @@ export class Pagination {
99
97
  * @deprecated
100
98
  */
101
99
  *items() {
102
- const n = this.page - 1;
100
+ const n = this.page - 1;
103
101
 
104
102
  const data = Array.isArray(this.data)
105
103
  ? this.#data
@@ -131,11 +129,17 @@ export class Pagination {
131
129
  a.setAttribute("aria-label", label);
132
130
  }
133
131
  a.innerText = innerText;
134
- if (targetPage === this.page) {
132
+
133
+ if (targetPage < 1 || targetPage > this.numberOfPages) {
135
134
  a.disabled = true;
136
- a.setAttribute("aria-current", "page");
137
135
  } else {
138
- a.onclick = () => (this.page = targetPage);
136
+ if (targetPage === this.page) {
137
+ a.disabled = true;
138
+ a.classList.add("active");
139
+ a.setAttribute("aria-current", "page");
140
+ } else {
141
+ a.onclick = () => (this.page = targetPage);
142
+ }
139
143
  }
140
144
  items.push(a);
141
145
  };
@@ -167,4 +171,6 @@ export class Pagination {
167
171
 
168
172
  export function pageNavigation(elem, pg) {
169
173
  elem.replaceChildren(pg.pageNavigationElement);
174
+
175
+ // TODO destroy
170
176
  }