svelte-common 6.5.2 → 6.5.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.
Files changed (2) hide show
  1. package/package.json +9 -9
  2. package/src/pagination.mjs +56 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "6.5.2",
3
+ "version": "6.5.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -41,30 +41,30 @@
41
41
  "preview": "vite preview"
42
42
  },
43
43
  "dependencies": {
44
- "svelte-command": "^1.1.46",
45
- "svelte-entitlement": "^1.2.59"
44
+ "svelte-command": "^1.1.48",
45
+ "svelte-entitlement": "^1.2.60"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@semantic-release/commit-analyzer": "^10.0.1",
49
49
  "@semantic-release/exec": "^6.0.3",
50
50
  "@semantic-release/release-notes-generator": "^11.0.4",
51
- "@sveltejs/vite-plugin-svelte": "^2.4.3",
51
+ "@sveltejs/vite-plugin-svelte": "^2.4.5",
52
52
  "ava": "^5.3.1",
53
53
  "c8": "^8.0.1",
54
54
  "documentation": "^14.0.2",
55
55
  "mf-styling": "^3.0.2",
56
- "npm-pkgbuild": "^11.10.5",
56
+ "npm-pkgbuild": "^11.10.10",
57
57
  "semantic-release": "^21.0.7",
58
58
  "stylelint": "^15.10.2",
59
59
  "stylelint-config-standard": "^34.0.0",
60
- "svelte": "^4.1.2",
60
+ "svelte": "^4.2.0",
61
61
  "testcafe": "^3.1.0",
62
- "vite": "^4.4.7",
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.0"
67
+ "mf-hosting-frontend": "^2.0.1"
68
68
  },
69
69
  "repository": {
70
70
  "type": "git",
@@ -137,7 +137,7 @@
137
137
  "arlac77/template-ava-coverage",
138
138
  "arlac77/template-cloudflare",
139
139
  "arlac77/template-css",
140
- "arlac77/template-pacman",
140
+ "arlac77/template-npm-pkgbuild",
141
141
  "arlac77/template-svelte-component"
142
142
  ]
143
143
  }
@@ -22,10 +22,13 @@ export class Pagination {
22
22
  Object.assign(this, options);
23
23
  }
24
24
 
25
+ fireSubscriptions() {
26
+ this.#subscriptions.forEach(subscription => subscription(this));
27
+ }
28
+
25
29
  set filter(filter) {
26
30
  this.#filter = filter;
27
-
28
- this.#subscriptions.forEach(subscription => subscription(this));
31
+ this.fireSubscriptions();
29
32
  }
30
33
 
31
34
  get filter() {
@@ -34,8 +37,7 @@ export class Pagination {
34
37
 
35
38
  set sorter(sorter) {
36
39
  this.#sorter = sorter;
37
-
38
- this.#subscriptions.forEach(subscription => subscription(this));
40
+ this.fireSubscriptions();
39
41
  }
40
42
 
41
43
  get sorter() {
@@ -56,7 +58,7 @@ export class Pagination {
56
58
  this.#data = data;
57
59
  }
58
60
 
59
- this.#subscriptions.forEach(subscription => subscription(this));
61
+ this.fireSubscriptions();
60
62
  }
61
63
 
62
64
  get itemsPerPage() {
@@ -65,7 +67,7 @@ export class Pagination {
65
67
 
66
68
  set itemsPerPage(n) {
67
69
  this.#itemsPerPage = n;
68
- this.#subscriptions.forEach(subscription => subscription(this));
70
+ this.fireSubscriptions();
69
71
  }
70
72
 
71
73
  /**
@@ -73,14 +75,14 @@ export class Pagination {
73
75
  * @param {number} n
74
76
  */
75
77
  set page(n) {
76
- if(n < 0) {
78
+ if (n < 0) {
77
79
  n = this.numberOfPages + n + 1;
78
80
  }
79
81
 
80
82
  if (this.#page !== n) {
81
83
  if (n >= 1 && n <= this.numberOfPages) {
82
84
  this.#page = n;
83
- this.#subscriptions.forEach(subscription => subscription(this));
85
+ this.fireSubscriptions();
84
86
  }
85
87
  }
86
88
  }
@@ -151,11 +153,13 @@ export class Pagination {
151
153
  nav.setAttribute("aria-label", "pagination");
152
154
 
153
155
  nav.onkeyup = event => {
154
- switch(event.key) {
155
- case 'ArrowLeft': this.page = this.page - 1;
156
- break;
157
- case 'ArrowRight': this.page = this.page + 1;
158
- break;
156
+ switch (event.key) {
157
+ case "ArrowLeft":
158
+ this.page = this.page - 1;
159
+ break;
160
+ case "ArrowRight":
161
+ this.page = this.page + 1;
162
+ break;
159
163
  }
160
164
  };
161
165
 
@@ -173,7 +177,7 @@ export class Pagination {
173
177
 
174
178
  if (targetPage < 1 || targetPage > np) {
175
179
  a.setAttribute("aria-disabled", "true");
176
- a.tabIndex=-1;
180
+ a.tabIndex = -1;
177
181
  } else {
178
182
  if (targetPage === this.page) {
179
183
  a.classList.add("active");
@@ -214,12 +218,17 @@ export function pageNavigation(elem, pg) {
214
218
  }
215
219
 
216
220
  /**
217
- * Generade actual sequence of page numbers to navigate to
221
+ * Generade actual sequence of page numbers to navigate to.
218
222
  * @param {number} nunmberOfPages
219
223
  * @param {number} currentPage
224
+ * @param {number} numberOfItems
220
225
  * @return {Iterator<number>}
221
226
  */
222
- export function* navigationItems(nunmberOfPages, currentPage) {
227
+ export function* navigationItems(
228
+ numberOfPages,
229
+ currentPage,
230
+ numberOfItems = 7
231
+ ) {
223
232
  const pageJumps = [
224
233
  { maxPages: 10, side: 1, edge: 2 },
225
234
  { maxPages: 100, side: 1, edge: 2, step: 10 },
@@ -231,11 +240,11 @@ export function* navigationItems(nunmberOfPages, currentPage) {
231
240
  ];
232
241
 
233
242
  for (const j of pageJumps) {
234
- if (nunmberOfPages <= j.maxPages) {
235
- for (let n = 1; n <= nunmberOfPages; n++) {
243
+ if (numberOfPages <= j.maxPages) {
244
+ for (let n = 1; n <= numberOfPages; n++) {
236
245
  if (
237
246
  n <= j.edge ||
238
- n > nunmberOfPages - j.edge ||
247
+ n > numberOfPages - j.edge ||
239
248
  n % j.step === 0 ||
240
249
  (n < currentPage + j.side && n > currentPage - j.side)
241
250
  ) {
@@ -245,4 +254,32 @@ export function* navigationItems(nunmberOfPages, currentPage) {
245
254
  break;
246
255
  }
247
256
  }
257
+ /*
258
+
259
+
260
+
261
+ const pageJumps = [
262
+ { maxPages: 10, stepping: [1] },
263
+ { maxPages: 100, stepping: [1, 10] },
264
+ { maxPages: 1000, stepping: [1, 10, 100] },
265
+ { maxPages: 10000, stepping: [1, 100, 1000] },
266
+ { maxPages: 100000, stepping: [1, 1000, 10000] }
267
+ ];
268
+
269
+ for (const j of pageJumps) {
270
+ if (numberOfPages <= j.maxPages) {
271
+ yield 1;
272
+ for (const s of j.stepping) {
273
+ for (let n = currentPage - s; n < currentPage + s; n++) {
274
+ yield n;
275
+ }
276
+ yield currentPage;
277
+ }
278
+
279
+ yield numberOfPages;
280
+
281
+ break;
282
+ }
283
+ }
284
+ */
248
285
  }