svelte-common 5.0.6 → 5.2.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 +6 -6
- package/src/pagination.mjs +46 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-common",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"preview": "vite preview"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"svelte-command": "^1.1.
|
|
41
|
-
"svelte-entitlement": "^1.2.
|
|
40
|
+
"svelte-command": "^1.1.44",
|
|
41
|
+
"svelte-entitlement": "^1.2.56"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@semantic-release/commit-analyzer": "^10.0.1",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"c8": "^8.0.0",
|
|
50
50
|
"documentation": "^14.0.2",
|
|
51
51
|
"mf-styling": "^2.0.1",
|
|
52
|
-
"npm-pkgbuild": "^11.8.
|
|
52
|
+
"npm-pkgbuild": "^11.8.12",
|
|
53
53
|
"semantic-release": "^21.0.7",
|
|
54
|
-
"stylelint": "^15.10.
|
|
54
|
+
"stylelint": "^15.10.1",
|
|
55
55
|
"stylelint-config-standard": "^34.0.0",
|
|
56
56
|
"svelte": "^4.0.4",
|
|
57
57
|
"testcafe": "^3.0.1",
|
|
58
|
-
"vite": "^4.
|
|
58
|
+
"vite": "^4.4.0"
|
|
59
59
|
},
|
|
60
60
|
"optionalDependencies": {
|
|
61
61
|
"mf-hosting-cloudflare": "^1.0.5",
|
package/src/pagination.mjs
CHANGED
|
@@ -5,19 +5,35 @@
|
|
|
5
5
|
export class Pagination {
|
|
6
6
|
#subscriptions = new Set();
|
|
7
7
|
#data;
|
|
8
|
+
#unsubscribeData;
|
|
9
|
+
|
|
8
10
|
#itemsPerPage = 1;
|
|
9
11
|
#page = 1;
|
|
10
12
|
|
|
11
|
-
constructor(data, itemsPerPage =
|
|
12
|
-
this
|
|
13
|
+
constructor(data, itemsPerPage = 20) {
|
|
14
|
+
this.data = data;
|
|
13
15
|
this.itemsPerPage = itemsPerPage;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
set data(data) {
|
|
17
|
-
this.#
|
|
19
|
+
if (this.#unsubscribeData) {
|
|
20
|
+
this.#unsubscribeData();
|
|
21
|
+
this.#unsubscribeData = undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (data?.subscribe) {
|
|
25
|
+
this.#unsubscribeData = data.subscribe(newData => {
|
|
26
|
+
this.#data = newData;
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
this.#data = data;
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
this.#subscriptions.forEach(subscription => subscription(this));
|
|
19
33
|
}
|
|
20
34
|
|
|
35
|
+
|
|
36
|
+
|
|
21
37
|
get itemsPerPage() {
|
|
22
38
|
return this.#itemsPerPage;
|
|
23
39
|
}
|
|
@@ -54,16 +70,40 @@ export class Pagination {
|
|
|
54
70
|
}
|
|
55
71
|
|
|
56
72
|
get numberOfPages() {
|
|
57
|
-
return (
|
|
73
|
+
return Math.ceil(
|
|
58
74
|
(Array.isArray(this.#data) ? this.#data.length : this.#data.size) /
|
|
59
75
|
this.itemsPerPage
|
|
60
76
|
);
|
|
61
77
|
}
|
|
62
78
|
|
|
79
|
+
get length() {
|
|
80
|
+
return this.#itemsPerPage;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
*[Symbol.iterator]() {
|
|
84
|
+
const n = this.page - 1;
|
|
85
|
+
|
|
86
|
+
const data = Array.isArray(this.data)
|
|
87
|
+
? this.#data
|
|
88
|
+
: [...this.#data.values()];
|
|
89
|
+
|
|
90
|
+
for (const item of data.slice(
|
|
91
|
+
n * this.itemsPerPage,
|
|
92
|
+
(n + 1) * this.itemsPerPage
|
|
93
|
+
)) {
|
|
94
|
+
yield item;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @deprecated
|
|
100
|
+
*/
|
|
63
101
|
*items() {
|
|
64
|
-
const n = this.page - 1;
|
|
102
|
+
const n = this.page - 1;
|
|
65
103
|
|
|
66
|
-
const data = Array.isArray(this.data)
|
|
104
|
+
const data = Array.isArray(this.data)
|
|
105
|
+
? this.#data
|
|
106
|
+
: [...this.#data.values()];
|
|
67
107
|
|
|
68
108
|
for (const item of data.slice(
|
|
69
109
|
n * this.itemsPerPage,
|