aprog 1.3.9 → 1.4.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/index.js +1 -0
- package/package.json +1 -1
- package/src/Paginate.js +88 -0
- package/src/aprog.js +18 -18
package/index.js
CHANGED
package/package.json
CHANGED
package/src/Paginate.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {storage} from "./storage.js";
|
|
2
|
+
import {button} from "./aprog.js";
|
|
3
|
+
|
|
4
|
+
const Paginate = ({count = 0, currentPage = 1, onPageChange = () => {}}) => {
|
|
5
|
+
const generatePageButtons = () => {
|
|
6
|
+
const buttons = [];
|
|
7
|
+
if (count <= 5) {
|
|
8
|
+
for (let i = 1; i <= count; i++) {
|
|
9
|
+
buttons.push(createPageButton(i));
|
|
10
|
+
}
|
|
11
|
+
} else {
|
|
12
|
+
buttons.push(createPageButton(1));
|
|
13
|
+
if (currentPage > 3) {
|
|
14
|
+
buttons.push(createDotsButton());
|
|
15
|
+
}
|
|
16
|
+
for (
|
|
17
|
+
let i = Math.max(2, currentPage - 1);
|
|
18
|
+
i <= Math.min(count - 1, currentPage + 1);
|
|
19
|
+
i++
|
|
20
|
+
) {
|
|
21
|
+
buttons.push(createPageButton(i));
|
|
22
|
+
}
|
|
23
|
+
if (currentPage < count - 2) {
|
|
24
|
+
buttons.push(createDotsButton());
|
|
25
|
+
}
|
|
26
|
+
buttons.push(createPageButton(count));
|
|
27
|
+
}
|
|
28
|
+
return buttons;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const createPageButton = (page) => button({
|
|
32
|
+
class: `paginate-btn ${page === currentPage ? "active" : ""}`,
|
|
33
|
+
value: `${page}`,
|
|
34
|
+
onClick: () => onPageChange(page),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const createDotsButton = () => button({
|
|
38
|
+
class: "paginate-dots",
|
|
39
|
+
disabled: true,
|
|
40
|
+
value: "...",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// const navigateTo = (path) => {
|
|
44
|
+
// window.history.pushState("", "", path);
|
|
45
|
+
// }
|
|
46
|
+
//
|
|
47
|
+
// navigateTo(`${window.location.pathname}?page=${currentPage || 1}${!isEmpty(_get("filter", null))
|
|
48
|
+
// ? `&filter=${_get("filter")}`
|
|
49
|
+
// : ""
|
|
50
|
+
// }${!isEmpty(_get("sort", null))
|
|
51
|
+
// ? `&sort=${_get('sort')}`
|
|
52
|
+
// : ""
|
|
53
|
+
// }`
|
|
54
|
+
// );
|
|
55
|
+
|
|
56
|
+
return div({
|
|
57
|
+
class: "paginate-block",
|
|
58
|
+
value: [
|
|
59
|
+
button({
|
|
60
|
+
class: "paginate-prev",
|
|
61
|
+
value: "<<<",
|
|
62
|
+
onClick: () => onPageChange(currentPage > 1 ? currentPage - 1 : 1),
|
|
63
|
+
disabled: currentPage === 1 || currentPage === 0,
|
|
64
|
+
}),
|
|
65
|
+
...generatePageButtons(),
|
|
66
|
+
button({
|
|
67
|
+
class: "paginate-next",
|
|
68
|
+
value: ">>>",
|
|
69
|
+
onClick: () => onPageChange(currentPage < count ? currentPage + 1 : count),
|
|
70
|
+
disabled: currentPage === count,
|
|
71
|
+
}),
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const parseData = (data, page) => {
|
|
77
|
+
const pageSize = storage.get("pageSize");
|
|
78
|
+
const totalData = data.length;
|
|
79
|
+
const pages = Math.ceil(totalData / pageSize);
|
|
80
|
+
if (page > pages) {
|
|
81
|
+
page = pages;
|
|
82
|
+
}
|
|
83
|
+
const cutData = data.slice((page - 1) * pageSize, page * pageSize);
|
|
84
|
+
|
|
85
|
+
return [pages, cutData, page];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default Paginate;
|
package/src/aprog.js
CHANGED
|
@@ -242,7 +242,7 @@ export const input = (attributes = {}) => {
|
|
|
242
242
|
if (attributes) {
|
|
243
243
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
244
244
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
245
|
-
const eventType = name.slice(2).toLowerCase();
|
|
245
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
246
246
|
input.addEventListener(eventType, attrValue);
|
|
247
247
|
} else {
|
|
248
248
|
switch (name) {
|
|
@@ -291,7 +291,7 @@ export const label = (attributes = {}) => {
|
|
|
291
291
|
if (attributes) {
|
|
292
292
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
293
293
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
294
|
-
const eventType = name.slice(2).toLowerCase();
|
|
294
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
295
295
|
label.addEventListener(eventType, attrValue);
|
|
296
296
|
} else {
|
|
297
297
|
switch (name) {
|
|
@@ -342,7 +342,7 @@ export const form = (attributes = {}) => {
|
|
|
342
342
|
if (attributes) {
|
|
343
343
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
344
344
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
345
|
-
const eventType = name.slice(2).toLowerCase();
|
|
345
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
346
346
|
form.addEventListener(eventType, attrValue);
|
|
347
347
|
} else {
|
|
348
348
|
switch (name) {
|
|
@@ -402,7 +402,7 @@ export const div = (attributes = {}) => {
|
|
|
402
402
|
if (attributes) {
|
|
403
403
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
404
404
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
405
|
-
const eventType = name.slice(2).toLowerCase();
|
|
405
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
406
406
|
div.addEventListener(eventType, attrValue);
|
|
407
407
|
} else {
|
|
408
408
|
switch (name) {
|
|
@@ -453,7 +453,7 @@ export const a = (attributes = {}) => {
|
|
|
453
453
|
if (attributes) {
|
|
454
454
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
455
455
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
456
|
-
const eventType = name.slice(2).toLowerCase();
|
|
456
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
457
457
|
a.addEventListener(eventType, attrValue);
|
|
458
458
|
} else {
|
|
459
459
|
switch (name) {
|
|
@@ -504,7 +504,7 @@ export const span = (attributes = {}) => {
|
|
|
504
504
|
if (attributes) {
|
|
505
505
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
506
506
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
507
|
-
const eventType = name.slice(2).toLowerCase();
|
|
507
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
508
508
|
span.addEventListener(eventType, attrValue);
|
|
509
509
|
} else {
|
|
510
510
|
switch (name) {
|
|
@@ -555,7 +555,7 @@ export const textarea = (attributes = {}) => {
|
|
|
555
555
|
if (attributes) {
|
|
556
556
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
557
557
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
558
|
-
const eventType = name.slice(2).toLowerCase();
|
|
558
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
559
559
|
textarea.addEventListener(eventType, attrValue);
|
|
560
560
|
} else {
|
|
561
561
|
switch (name) {
|
|
@@ -606,7 +606,7 @@ export const pre = (attributes = {}) => {
|
|
|
606
606
|
if (attributes) {
|
|
607
607
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
608
608
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
609
|
-
const eventType = name.slice(2).toLowerCase();
|
|
609
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
610
610
|
pre.addEventListener(eventType, attrValue);
|
|
611
611
|
} else {
|
|
612
612
|
switch (name) {
|
|
@@ -657,7 +657,7 @@ export const button = (attributes = {}) => {
|
|
|
657
657
|
if (attributes) {
|
|
658
658
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
659
659
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
660
|
-
const eventType = name.slice(2).toLowerCase();
|
|
660
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
661
661
|
button.addEventListener(eventType, attrValue);
|
|
662
662
|
} else {
|
|
663
663
|
switch (name) {
|
|
@@ -709,7 +709,7 @@ export const select = (attributes = {}) => {
|
|
|
709
709
|
if (attributes) {
|
|
710
710
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
711
711
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
712
|
-
const eventType = name.slice(2).toLowerCase();
|
|
712
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
713
713
|
select.addEventListener(eventType, attrValue);
|
|
714
714
|
} else {
|
|
715
715
|
switch (name) {
|
|
@@ -849,7 +849,7 @@ export const table = (attributes = {}) => {
|
|
|
849
849
|
if (attributes) {
|
|
850
850
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
851
851
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
852
|
-
const eventType = name.slice(2).toLowerCase();
|
|
852
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
853
853
|
table.addEventListener(eventType, attrValue);
|
|
854
854
|
} else {
|
|
855
855
|
switch (name) {
|
|
@@ -900,7 +900,7 @@ export const caption = (attributes = {}) => {
|
|
|
900
900
|
if (attributes) {
|
|
901
901
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
902
902
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
903
|
-
const eventType = name.slice(2).toLowerCase();
|
|
903
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
904
904
|
caption.addEventListener(eventType, attrValue);
|
|
905
905
|
} else {
|
|
906
906
|
switch (name) {
|
|
@@ -954,7 +954,7 @@ export const thead = (attributes = {}) => {
|
|
|
954
954
|
if (attributes) {
|
|
955
955
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
956
956
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
957
|
-
const eventType = name.slice(2).toLowerCase();
|
|
957
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
958
958
|
thead.addEventListener(eventType, attrValue);
|
|
959
959
|
} else {
|
|
960
960
|
switch (name) {
|
|
@@ -1005,7 +1005,7 @@ export const tbody = (attributes = {}) => {
|
|
|
1005
1005
|
if (attributes) {
|
|
1006
1006
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
1007
1007
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
1008
|
-
const eventType = name.slice(2).toLowerCase();
|
|
1008
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
1009
1009
|
tbody.addEventListener(eventType, attrValue);
|
|
1010
1010
|
} else {
|
|
1011
1011
|
switch (name) {
|
|
@@ -1056,7 +1056,7 @@ export const tr = (attributes = {}) => {
|
|
|
1056
1056
|
if (attributes) {
|
|
1057
1057
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
1058
1058
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
1059
|
-
const eventType = name.slice(2).toLowerCase();
|
|
1059
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
1060
1060
|
tr.addEventListener(eventType, attrValue);
|
|
1061
1061
|
} else {
|
|
1062
1062
|
switch (name) {
|
|
@@ -1107,7 +1107,7 @@ export const th = (attributes = {}) => {
|
|
|
1107
1107
|
if (attributes) {
|
|
1108
1108
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
1109
1109
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
1110
|
-
const eventType = name.slice(2).toLowerCase();
|
|
1110
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
1111
1111
|
th.addEventListener(eventType, attrValue);
|
|
1112
1112
|
} else {
|
|
1113
1113
|
switch (name) {
|
|
@@ -1158,7 +1158,7 @@ export const td = (attributes = {}) => {
|
|
|
1158
1158
|
if (attributes) {
|
|
1159
1159
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
1160
1160
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
1161
|
-
const eventType = name.slice(2).toLowerCase();
|
|
1161
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
1162
1162
|
td.addEventListener(eventType, attrValue);
|
|
1163
1163
|
} else {
|
|
1164
1164
|
switch (name) {
|
|
@@ -1209,7 +1209,7 @@ export const img = (attributes = {}) => {
|
|
|
1209
1209
|
if (attributes) {
|
|
1210
1210
|
Object.entries(attributes).forEach(([name, attrValue]) => {
|
|
1211
1211
|
if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
|
|
1212
|
-
const eventType = name.slice(2).toLowerCase();
|
|
1212
|
+
const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
|
|
1213
1213
|
img.addEventListener(eventType, attrValue);
|
|
1214
1214
|
} else {
|
|
1215
1215
|
switch (name) {
|