svelte-common 6.6.0 → 6.6.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 +3 -3
  2. package/src/pagination.mjs +21 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "6.6.0",
3
+ "version": "6.6.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -58,13 +58,13 @@
58
58
  "stylelint": "^15.10.2",
59
59
  "stylelint-config-standard": "^34.0.0",
60
60
  "svelte": "^4.2.0",
61
- "testcafe": "^3.1.0",
61
+ "testcafe": "^3.2.0",
62
62
  "vite": "^4.4.9",
63
63
  "vite-plugin-compression2": "^0.10.3"
64
64
  },
65
65
  "optionalDependencies": {
66
66
  "mf-hosting-cloudflare": "^1.0.5",
67
- "mf-hosting-frontend": "^2.0.1"
67
+ "mf-hosting-frontend": "^2.0.2"
68
68
  },
69
69
  "repository": {
70
70
  "type": "git",
@@ -53,9 +53,15 @@ export class Pagination {
53
53
  if (data?.subscribe) {
54
54
  this.#unsubscribeData = data.subscribe(newData => {
55
55
  this.#data = newData;
56
+ if (this.page > this.numberOfPages) {
57
+ this.page = this.numberOfPages;
58
+ }
56
59
  });
57
60
  } else {
58
61
  this.#data = data;
62
+ if (this.page > this.numberOfPages) {
63
+ this.page = this.numberOfPages;
64
+ }
59
65
  }
60
66
 
61
67
  this.fireSubscriptions();
@@ -153,7 +159,7 @@ export class Pagination {
153
159
  nav.setAttribute("aria-label", "pagination");
154
160
 
155
161
  nav.onkeyup = event => {
156
- const step = (event.altKey ? 10 : 1);
162
+ const step = event.altKey ? 10 : 1;
157
163
 
158
164
  switch (event.key) {
159
165
  case "ArrowLeft":
@@ -231,33 +237,22 @@ export function* navigationItems(
231
237
  currentPage,
232
238
  numberOfItems = 7
233
239
  ) {
234
- const pageJumps = [
235
- { maxPages: 10, side: 1, edge: 2 },
236
- { maxPages: 100, side: 1, edge: 2, step: 10 },
237
- { maxPages: 1000, side: 1, edge: 2, step: 100 },
238
- { maxPages: 10000, side: 1, edge: 2, step: 1000 },
239
- { maxPages: 100000, side: 1, edge: 2, step: 10000 },
240
- { maxPages: 1000000, side: 1, edge: 2, step: 100000 },
241
- { maxPages: 10000000, side: 1, edge: 2, step: 1000000 }
242
- ];
243
-
244
- for (const j of pageJumps) {
245
- if (numberOfPages <= j.maxPages) {
246
- for (let n = 1; n <= numberOfPages; n++) {
247
- if (
248
- n <= j.edge ||
249
- n > numberOfPages - j.edge ||
250
- n % j.step === 0 ||
251
- (n < currentPage + j.side && n > currentPage - j.side)
252
- ) {
253
- yield n;
254
- }
255
- }
256
- break;
240
+ const edge = 2;
241
+ const side = 1;
242
+ const step = numberOfPages >= 100 ? Math.floor(numberOfPages / 10) : undefined;
243
+
244
+ for (let n = 1; n <= numberOfPages; n++) {
245
+ if (
246
+ n <= edge ||
247
+ n > numberOfPages - edge ||
248
+ n % step === 0 ||
249
+ (n < currentPage + side && n > currentPage - side)
250
+ ) {
251
+ yield n;
257
252
  }
258
253
  }
259
-
260
- /*
254
+
255
+ /*
261
256
  const pageJumps = [
262
257
  { maxPages: 10, stepping: [1] },
263
258
  { maxPages: 100, stepping: [1, 10] },