svelte-common 6.13.1 → 6.15.0
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 +5 -5
- package/src/pagination.mjs +46 -7
- package/types/pagination.d.mts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.15.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"pacc": "^3.1.8",
|
|
52
52
|
"svelte-command": "^3.0.2",
|
|
53
|
-
"svelte-entitlement": "^2.0.
|
|
53
|
+
"svelte-entitlement": "^2.0.1"
|
|
54
54
|
},
|
|
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.5",
|
|
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",
|
|
@@ -66,11 +66,11 @@
|
|
|
66
66
|
"semantic-release": "^24.0.0",
|
|
67
67
|
"stylelint": "^16.8.1",
|
|
68
68
|
"stylelint-config-standard": "^36.0.1",
|
|
69
|
-
"svelte": "^5.0.0-next.
|
|
69
|
+
"svelte": "^5.0.0-next.222",
|
|
70
70
|
"testcafe": "^3.6.2",
|
|
71
71
|
"typescript": "^5.5.4",
|
|
72
72
|
"vite": "^5.4.0",
|
|
73
|
-
"vite-plugin-compression2": "^1.
|
|
73
|
+
"vite-plugin-compression2": "^1.2.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"svelte": "^5.0.0-next.0"
|
package/src/pagination.mjs
CHANGED
|
@@ -15,11 +15,13 @@ export class Pagination {
|
|
|
15
15
|
#data;
|
|
16
16
|
#unsubscribeData;
|
|
17
17
|
#filter;
|
|
18
|
+
#unsubscribeFilter;
|
|
18
19
|
#sorter;
|
|
20
|
+
#unsubscribeSorter;
|
|
19
21
|
#itemsPerPage = 20;
|
|
20
22
|
#page = 1;
|
|
21
23
|
|
|
22
|
-
constructor(data=[], options) {
|
|
24
|
+
constructor(data = [], options) {
|
|
23
25
|
this.data = data;
|
|
24
26
|
|
|
25
27
|
Object.assign(this, options);
|
|
@@ -30,9 +32,22 @@ export class Pagination {
|
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
set filter(filter) {
|
|
33
|
-
this.#
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
if (this.#unsubscribeFilter) {
|
|
36
|
+
this.#unsubscribeFilter();
|
|
37
|
+
this.#unsubscribeFilter = undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const applyFilter = filter => {
|
|
41
|
+
this.#filter = filter;
|
|
42
|
+
this.recalibrateCurrentPage();
|
|
43
|
+
this.fireSubscriptions();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (filter?.subscribe) {
|
|
47
|
+
this.#unsubscribeFilter = filter.subscribe(applyFilter);
|
|
48
|
+
} else {
|
|
49
|
+
applyFilter(filter);
|
|
50
|
+
}
|
|
36
51
|
}
|
|
37
52
|
|
|
38
53
|
get filter() {
|
|
@@ -40,8 +55,21 @@ export class Pagination {
|
|
|
40
55
|
}
|
|
41
56
|
|
|
42
57
|
set sorter(sorter) {
|
|
43
|
-
this.#
|
|
44
|
-
|
|
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
|
+
}
|
|
45
73
|
}
|
|
46
74
|
|
|
47
75
|
get sorter() {
|
|
@@ -153,8 +181,19 @@ export class Pagination {
|
|
|
153
181
|
return this.#itemsPerPage;
|
|
154
182
|
}
|
|
155
183
|
|
|
184
|
+
get filteredItems()
|
|
185
|
+
{
|
|
186
|
+
let items = Array.isArray(this.#data) ? this.#data : [...this.#data.values()];
|
|
187
|
+
|
|
188
|
+
if (this.filter) {
|
|
189
|
+
return items.filter(this.filter);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return items;
|
|
193
|
+
}
|
|
194
|
+
|
|
156
195
|
*[Symbol.iterator]() {
|
|
157
|
-
let data = Array.isArray(this
|
|
196
|
+
let data = Array.isArray(this.#data) ? this.#data : [...this.#data.values()];
|
|
158
197
|
|
|
159
198
|
if (this.filter) {
|
|
160
199
|
data = data.filter(this.filter);
|
package/types/pagination.d.mts
CHANGED
|
@@ -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
|
}
|