svelte-common 6.14.0 → 6.15.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 +6 -6
- package/src/pagination.mjs +27 -6
- package/types/pagination.d.mts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.15.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
57
57
|
"@semantic-release/exec": "^6.0.3",
|
|
58
|
-
"@semantic-release/github": "^10.1.
|
|
58
|
+
"@semantic-release/github": "^10.1.6",
|
|
59
59
|
"@semantic-release/release-notes-generator": "^14.0.1",
|
|
60
60
|
"@sveltejs/vite-plugin-svelte": "^3.1.1",
|
|
61
61
|
"ava": "^6.1.3",
|
|
@@ -63,13 +63,13 @@
|
|
|
63
63
|
"documentation": "^14.0.3",
|
|
64
64
|
"mf-styling": "^3.1.8",
|
|
65
65
|
"npm-pkgbuild": "^15.3.29",
|
|
66
|
-
"semantic-release": "^24.
|
|
67
|
-
"stylelint": "^16.8.
|
|
66
|
+
"semantic-release": "^24.1.0",
|
|
67
|
+
"stylelint": "^16.8.2",
|
|
68
68
|
"stylelint-config-standard": "^36.0.1",
|
|
69
|
-
"svelte": "^5.0.0-next.
|
|
69
|
+
"svelte": "^5.0.0-next.225",
|
|
70
70
|
"testcafe": "^3.6.2",
|
|
71
71
|
"typescript": "^5.5.4",
|
|
72
|
-
"vite": "^5.4.
|
|
72
|
+
"vite": "^5.4.1",
|
|
73
73
|
"vite-plugin-compression2": "^1.2.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
package/src/pagination.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { readable } from "svelte/store";
|
|
|
6
6
|
* @param {Map|Set|Array|readable} data
|
|
7
7
|
* @param {Object} options
|
|
8
8
|
* @param {number} [options.itemsPerPage]
|
|
9
|
-
* @param {number} [options.page]
|
|
9
|
+
* @param {number} [options.page] current page
|
|
10
10
|
* @param {Function} [options.sorter]
|
|
11
11
|
* @param {Function} [options.filter]
|
|
12
12
|
*/
|
|
@@ -17,6 +17,7 @@ export class Pagination {
|
|
|
17
17
|
#filter;
|
|
18
18
|
#unsubscribeFilter;
|
|
19
19
|
#sorter;
|
|
20
|
+
#unsubscribeSorter;
|
|
20
21
|
#itemsPerPage = 20;
|
|
21
22
|
#page = 1;
|
|
22
23
|
|
|
@@ -54,8 +55,21 @@ export class Pagination {
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
set sorter(sorter) {
|
|
57
|
-
this.#
|
|
58
|
-
|
|
58
|
+
if (this.#unsubscribeSorter) {
|
|
59
|
+
this.#unsubscribeSorter();
|
|
60
|
+
this.#unsubscribeSorter = undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const applySorter = sorter => {
|
|
64
|
+
this.#sorter = sorter;
|
|
65
|
+
this.fireSubscriptions();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
if (sorter?.subscribe) {
|
|
69
|
+
this.#unsubscribeFilter = sorter.subscribe(applySorter);
|
|
70
|
+
} else {
|
|
71
|
+
applySorter(sorter);
|
|
72
|
+
}
|
|
59
73
|
}
|
|
60
74
|
|
|
61
75
|
get sorter() {
|
|
@@ -167,13 +181,20 @@ export class Pagination {
|
|
|
167
181
|
return this.#itemsPerPage;
|
|
168
182
|
}
|
|
169
183
|
|
|
170
|
-
|
|
171
|
-
|
|
184
|
+
get filteredItems()
|
|
185
|
+
{
|
|
186
|
+
let items = Array.isArray(this.#data) ? this.#data : [...this.#data.values()];
|
|
172
187
|
|
|
173
188
|
if (this.filter) {
|
|
174
|
-
|
|
189
|
+
return items.filter(this.filter);
|
|
175
190
|
}
|
|
176
191
|
|
|
192
|
+
return items;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
*[Symbol.iterator]() {
|
|
196
|
+
let data = this.filteredItems;
|
|
197
|
+
|
|
177
198
|
if (this.sorter) {
|
|
178
199
|
data = data.sort(this.sorter);
|
|
179
200
|
}
|
package/types/pagination.d.mts
CHANGED
|
@@ -13,7 +13,7 @@ export function navigationItems(numberOfPages: number, currentPage: number, numb
|
|
|
13
13
|
* @param {Map|Set|Array|readable} data
|
|
14
14
|
* @param {Object} options
|
|
15
15
|
* @param {number} [options.itemsPerPage]
|
|
16
|
-
* @param {number} [options.page]
|
|
16
|
+
* @param {number} [options.page] current page
|
|
17
17
|
* @param {Function} [options.sorter]
|
|
18
18
|
* @param {Function} [options.filter]
|
|
19
19
|
*/
|
|
@@ -56,11 +56,12 @@ export class Pagination {
|
|
|
56
56
|
* @return {number}
|
|
57
57
|
*/
|
|
58
58
|
get length(): number;
|
|
59
|
+
get filteredItems(): any[];
|
|
59
60
|
/**
|
|
60
61
|
* @see https://getbootstrap.com/docs/4.0/components/pagination
|
|
61
62
|
* @see https://a11y-style-guide.com/style-guide/section-navigation.html#kssref-navigation-pagination
|
|
62
63
|
*/
|
|
63
64
|
get pageNavigationElement(): HTMLElement;
|
|
64
|
-
[Symbol.iterator](): Generator<any, void,
|
|
65
|
+
[Symbol.iterator](): Generator<any, void, undefined>;
|
|
65
66
|
#private;
|
|
66
67
|
}
|