svelte-common 6.16.0 → 6.17.1
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/package.json +3 -3
- package/src/pagination.mjs +19 -17
- package/types/pagination.d.mts +12 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.17.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -66,14 +66,14 @@
|
|
|
66
66
|
"semantic-release": "^24.2.2",
|
|
67
67
|
"stylelint": "^16.14.1",
|
|
68
68
|
"stylelint-config-standard": "^37.0.0",
|
|
69
|
-
"svelte": "^5.
|
|
69
|
+
"svelte": "^5.20.0",
|
|
70
70
|
"testcafe": "^3.7.1",
|
|
71
71
|
"typescript": "^5.7.3",
|
|
72
72
|
"vite": "^6.1.0",
|
|
73
73
|
"vite-plugin-compression2": "^1.3.3"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"svelte": "^5.
|
|
76
|
+
"svelte": "^5.20.0"
|
|
77
77
|
},
|
|
78
78
|
"optionalDependencies": {
|
|
79
79
|
"mf-hosting-cloudflare": "^1.0.7",
|
package/src/pagination.mjs
CHANGED
|
@@ -219,7 +219,7 @@ export class Pagination {
|
|
|
219
219
|
* @see https://getbootstrap.com/docs/4.0/components/pagination
|
|
220
220
|
* @see https://a11y-style-guide.com/style-guide/section-navigation.html#kssref-navigation-pagination
|
|
221
221
|
*/
|
|
222
|
-
|
|
222
|
+
pageNavigationElement(options) {
|
|
223
223
|
const nav = document.createElement("nav");
|
|
224
224
|
nav.setAttribute("tabindex", "0");
|
|
225
225
|
nav.setAttribute("aria-label", "pagination");
|
|
@@ -287,19 +287,30 @@ export class Pagination {
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
export function pageNavigation(elem, pg) {
|
|
290
|
-
elem.replaceChildren(pg.pageNavigationElement);
|
|
290
|
+
elem.replaceChildren(pg.pageNavigationElement());
|
|
291
291
|
|
|
292
292
|
// TODO destroy
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
+
export const defaultNavigationItemOptions = {
|
|
296
|
+
numberOfItems: 7,
|
|
297
|
+
spreads: [[0], [1, 5, 25, 125, 625, 3125, 15625], [2, 3, 4, 10, 50, 100, 500]]
|
|
298
|
+
};
|
|
299
|
+
|
|
295
300
|
/**
|
|
296
301
|
* Generate actual sequence of page numbers to navigate to.
|
|
297
302
|
* @param {number} numberOfPages
|
|
298
303
|
* @param {number} currentPage
|
|
299
|
-
* @param {
|
|
304
|
+
* @param {Object} options
|
|
305
|
+
* @param {Number} options.numberOfItems
|
|
306
|
+
* @param {Number[][]} options.spreads
|
|
300
307
|
* @return {Iterable<number>}
|
|
301
308
|
*/
|
|
302
|
-
export function navigationItems(
|
|
309
|
+
export function navigationItems(
|
|
310
|
+
numberOfPages,
|
|
311
|
+
currentPage,
|
|
312
|
+
options = defaultNavigationItemOptions
|
|
313
|
+
) {
|
|
303
314
|
if (numberOfPages === 0) {
|
|
304
315
|
return [];
|
|
305
316
|
}
|
|
@@ -308,12 +319,12 @@ export function navigationItems(numberOfPages, currentPage, numberOfItems = 7) {
|
|
|
308
319
|
|
|
309
320
|
const spread = (n, sides) => {
|
|
310
321
|
for (const side of sides) {
|
|
311
|
-
if (items.size === numberOfItems) {
|
|
322
|
+
if (items.size === options.numberOfItems) {
|
|
312
323
|
return true;
|
|
313
324
|
}
|
|
314
325
|
if (n - side >= 1) {
|
|
315
326
|
items.add(n - side);
|
|
316
|
-
}
|
|
327
|
+
}
|
|
317
328
|
if (n + side <= numberOfPages) {
|
|
318
329
|
items.add(n + side);
|
|
319
330
|
}
|
|
@@ -321,17 +332,8 @@ export function navigationItems(numberOfPages, currentPage, numberOfItems = 7) {
|
|
|
321
332
|
return false;
|
|
322
333
|
};
|
|
323
334
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
[0],
|
|
327
|
-
[1, 5, 25, 125, 625, 3125, 15625],
|
|
328
|
-
[2, 3, 4, 10, 50, 100, 500]
|
|
329
|
-
]) {
|
|
330
|
-
if (
|
|
331
|
-
spread(currentPage, sides) ||
|
|
332
|
-
spread(1, sides) ||
|
|
333
|
-
spread(numberOfPages, sides)
|
|
334
|
-
) {
|
|
335
|
+
for (const s of options.spreads) {
|
|
336
|
+
if (spread(currentPage, s) || spread(1, s) || spread(numberOfPages, s)) {
|
|
335
337
|
break;
|
|
336
338
|
}
|
|
337
339
|
}
|
package/types/pagination.d.mts
CHANGED
|
@@ -3,10 +3,15 @@ export function pageNavigation(elem: any, pg: any): void;
|
|
|
3
3
|
* Generate actual sequence of page numbers to navigate to.
|
|
4
4
|
* @param {number} numberOfPages
|
|
5
5
|
* @param {number} currentPage
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {Object} options
|
|
7
|
+
* @param {Number} options.numberOfItems
|
|
8
|
+
* @param {Number[][]} options.spreads
|
|
7
9
|
* @return {Iterable<number>}
|
|
8
10
|
*/
|
|
9
|
-
export function navigationItems(numberOfPages: number, currentPage: number,
|
|
11
|
+
export function navigationItems(numberOfPages: number, currentPage: number, options?: {
|
|
12
|
+
numberOfItems: number;
|
|
13
|
+
spreads: number[][];
|
|
14
|
+
}): Iterable<number>;
|
|
10
15
|
/**
|
|
11
16
|
* Pagination support store.
|
|
12
17
|
* Pages go from 1 ... numberOfPages
|
|
@@ -68,7 +73,11 @@ export class Pagination {
|
|
|
68
73
|
* @see https://getbootstrap.com/docs/4.0/components/pagination
|
|
69
74
|
* @see https://a11y-style-guide.com/style-guide/section-navigation.html#kssref-navigation-pagination
|
|
70
75
|
*/
|
|
71
|
-
|
|
76
|
+
pageNavigationElement(options: any): HTMLElement;
|
|
72
77
|
[Symbol.iterator](): Generator<any, void, unknown>;
|
|
73
78
|
#private;
|
|
74
79
|
}
|
|
80
|
+
export namespace defaultNavigationItemOptions {
|
|
81
|
+
let numberOfItems: number;
|
|
82
|
+
let spreads: number[][];
|
|
83
|
+
}
|