svelte-common 5.1.0 → 5.2.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.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/pagination.mjs +30 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "5.1.0",
3
+ "version": "5.2.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -37,7 +37,7 @@
37
37
  "preview": "vite preview"
38
38
  },
39
39
  "dependencies": {
40
- "svelte-command": "^1.1.43",
40
+ "svelte-command": "^1.1.44",
41
41
  "svelte-entitlement": "^1.2.56"
42
42
  },
43
43
  "devDependencies": {
@@ -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.11",
52
+ "npm-pkgbuild": "^11.8.12",
53
53
  "semantic-release": "^21.0.7",
54
- "stylelint": "^15.10.0",
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.3.9"
58
+ "vite": "^4.4.0"
59
59
  },
60
60
  "optionalDependencies": {
61
61
  "mf-hosting-cloudflare": "^1.0.5",
@@ -10,7 +10,7 @@ export class Pagination {
10
10
  #itemsPerPage = 1;
11
11
  #page = 1;
12
12
 
13
- constructor(data, itemsPerPage = 10) {
13
+ constructor(data, itemsPerPage = 20) {
14
14
  this.data = data;
15
15
  this.itemsPerPage = itemsPerPage;
16
16
  }
@@ -32,6 +32,8 @@ export class Pagination {
32
32
  this.#subscriptions.forEach(subscription => subscription(this));
33
33
  }
34
34
 
35
+
36
+
35
37
  get itemsPerPage() {
36
38
  return this.#itemsPerPage;
37
39
  }
@@ -68,14 +70,36 @@ export class Pagination {
68
70
  }
69
71
 
70
72
  get numberOfPages() {
71
- return (
73
+ return Math.ceil(
72
74
  (Array.isArray(this.#data) ? this.#data.length : this.#data.size) /
73
75
  this.itemsPerPage
74
76
  );
75
77
  }
76
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
+ */
77
101
  *items() {
78
- const n = this.page - 1;
102
+ const n = this.page - 1;
79
103
 
80
104
  const data = Array.isArray(this.data)
81
105
  ? this.#data
@@ -109,6 +133,7 @@ export class Pagination {
109
133
  a.innerText = innerText;
110
134
  if (targetPage === this.page) {
111
135
  a.disabled = true;
136
+ a.classList.add("active");
112
137
  a.setAttribute("aria-current", "page");
113
138
  } else {
114
139
  a.onclick = () => (this.page = targetPage);
@@ -143,4 +168,6 @@ export class Pagination {
143
168
 
144
169
  export function pageNavigation(elem, pg) {
145
170
  elem.replaceChildren(pg.pageNavigationElement);
171
+
172
+ // TODO destroy
146
173
  }