svelte-common 6.5.3 → 6.5.5
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 +6 -6
- package/src/filter.mjs +17 -0
- package/src/pagination.mjs +55 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-common",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -48,18 +48,18 @@
|
|
|
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.
|
|
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.
|
|
56
|
+
"npm-pkgbuild": "^11.10.11",
|
|
57
57
|
"semantic-release": "^21.0.7",
|
|
58
58
|
"stylelint": "^15.10.2",
|
|
59
59
|
"stylelint-config-standard": "^34.0.0",
|
|
60
|
-
"svelte": "^4.
|
|
60
|
+
"svelte": "^4.2.0",
|
|
61
61
|
"testcafe": "^3.1.0",
|
|
62
|
-
"vite": "^4.4.
|
|
62
|
+
"vite": "^4.4.9",
|
|
63
63
|
"vite-plugin-compression2": "^0.10.3"
|
|
64
64
|
},
|
|
65
65
|
"optionalDependencies": {
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
"arlac77/template-ava-coverage",
|
|
138
138
|
"arlac77/template-cloudflare",
|
|
139
139
|
"arlac77/template-css",
|
|
140
|
-
"arlac77/template-
|
|
140
|
+
"arlac77/template-npm-pkgbuild",
|
|
141
141
|
"arlac77/template-svelte-component"
|
|
142
142
|
]
|
|
143
143
|
}
|
package/src/filter.mjs
CHANGED
|
@@ -70,6 +70,14 @@ function allOp(value, against, op) {
|
|
|
70
70
|
if (against instanceof RegExp) {
|
|
71
71
|
return against.test(value);
|
|
72
72
|
}
|
|
73
|
+
|
|
74
|
+
if (Array.isArray(against) || against instanceof Set) {
|
|
75
|
+
for (const i of against) {
|
|
76
|
+
if (value.match(i)) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
return value.match(against);
|
|
@@ -78,6 +86,15 @@ function allOp(value, against, op) {
|
|
|
78
86
|
if (against instanceof RegExp) {
|
|
79
87
|
return against.test(value);
|
|
80
88
|
}
|
|
89
|
+
|
|
90
|
+
if (Array.isArray(against) || against instanceof Set) {
|
|
91
|
+
for (const i of against) {
|
|
92
|
+
if (numberOp(value, i, op)) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
81
98
|
return numberOp(value, against, op);
|
|
82
99
|
case "boolean":
|
|
83
100
|
return value == against;
|
package/src/pagination.mjs
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
|
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
|
|
218
|
-
* @param {number}
|
|
221
|
+
* Generade actual sequence of page numbers to navigate to.
|
|
222
|
+
* @param {number} numberOfPages
|
|
219
223
|
* @param {number} currentPage
|
|
224
|
+
* @param {number} numberOfItems
|
|
220
225
|
* @return {Iterator<number>}
|
|
221
226
|
*/
|
|
222
|
-
export function* navigationItems(
|
|
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 (
|
|
235
|
-
for (let n = 1; n <=
|
|
243
|
+
if (numberOfPages <= j.maxPages) {
|
|
244
|
+
for (let n = 1; n <= numberOfPages; n++) {
|
|
236
245
|
if (
|
|
237
246
|
n <= j.edge ||
|
|
238
|
-
n >
|
|
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,30 @@ export function* navigationItems(nunmberOfPages, currentPage) {
|
|
|
245
254
|
break;
|
|
246
255
|
}
|
|
247
256
|
}
|
|
257
|
+
|
|
258
|
+
/*
|
|
259
|
+
const pageJumps = [
|
|
260
|
+
{ maxPages: 10, stepping: [1] },
|
|
261
|
+
{ maxPages: 100, stepping: [1, 10] },
|
|
262
|
+
{ maxPages: 1000, stepping: [1, 10, 100] },
|
|
263
|
+
{ maxPages: 10000, stepping: [1, 100, 1000] },
|
|
264
|
+
{ maxPages: 100000, stepping: [1, 1000, 10000] }
|
|
265
|
+
];
|
|
266
|
+
|
|
267
|
+
for (const j of pageJumps) {
|
|
268
|
+
if (numberOfPages <= j.maxPages) {
|
|
269
|
+
yield 1;
|
|
270
|
+
for (const s of j.stepping) {
|
|
271
|
+
for (let n = currentPage - s; n < currentPage + s; n++) {
|
|
272
|
+
yield n;
|
|
273
|
+
}
|
|
274
|
+
yield currentPage;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
yield numberOfPages;
|
|
278
|
+
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
*/
|
|
248
283
|
}
|