mhz-helpers 0.0.1 → 1.0.2
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.
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ISortOption {
|
|
2
|
+
value?: string;
|
|
3
|
+
isAsc: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface IPageQuery {
|
|
6
|
+
page: number;
|
|
7
|
+
sort: ISortOption;
|
|
8
|
+
}
|
|
9
|
+
export declare function usePage(): {
|
|
10
|
+
query: import("vue").Ref<{
|
|
11
|
+
page: number;
|
|
12
|
+
sort: {
|
|
13
|
+
value?: string | undefined;
|
|
14
|
+
isAsc: boolean;
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
17
|
+
resetQuery: (value: string) => void;
|
|
18
|
+
setQueryPage: (pageToSet: number) => void;
|
|
19
|
+
};
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,29 +1,83 @@
|
|
|
1
|
-
import { computed as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { computed as i, ref as o, watch as c, toRaw as s } from "vue";
|
|
2
|
+
import { useRouter as l, useRoute as m } from "vue-router";
|
|
3
|
+
function p(e) {
|
|
4
|
+
const t = i(() => e.value?.data), r = i(() => e.value?.total);
|
|
5
|
+
function a(u, n) {
|
|
6
|
+
return !r.value || u === 0 || u === r.value + 1 ? n : u;
|
|
6
7
|
}
|
|
7
|
-
return { data:
|
|
8
|
+
return { data: t, total: r, setPage: a };
|
|
8
9
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
10
|
+
function v() {
|
|
11
|
+
const e = l(), t = m(), r = o({
|
|
12
|
+
page: Number(t.query.page || 1),
|
|
13
|
+
sort: {
|
|
14
|
+
value: t.query.sort?.toString(),
|
|
15
|
+
isAsc: t.query.dir !== "desc"
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
function a(n) {
|
|
19
|
+
r.value = Object.assign(r.value, { page: 1, sort: { value: n, isAsc: !0 } });
|
|
20
|
+
}
|
|
21
|
+
function u(n) {
|
|
22
|
+
r.value.page = n;
|
|
23
|
+
}
|
|
24
|
+
return c(
|
|
25
|
+
() => r.value,
|
|
26
|
+
() => {
|
|
27
|
+
e.push({
|
|
28
|
+
path: t.path,
|
|
29
|
+
query: {
|
|
30
|
+
page: r.value.page,
|
|
31
|
+
sort: r.value.sort.value,
|
|
32
|
+
dir: r.value.sort.isAsc ? "asc" : "desc"
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
{ deep: !0 }
|
|
37
|
+
), { query: r, resetQuery: a, setQueryPage: u };
|
|
38
|
+
}
|
|
39
|
+
function g() {
|
|
40
|
+
const e = o(1), t = o([]);
|
|
41
|
+
function r(u) {
|
|
42
|
+
t.value = [...t.value, ...u];
|
|
43
|
+
}
|
|
44
|
+
function a(u, n) {
|
|
45
|
+
u || (e.value = n);
|
|
46
|
+
}
|
|
47
|
+
return { page: e, allData: t, addData: r, handleScroll: a };
|
|
11
48
|
}
|
|
12
|
-
function
|
|
13
|
-
return
|
|
49
|
+
function y(e) {
|
|
50
|
+
return structuredClone(s(e));
|
|
14
51
|
}
|
|
15
|
-
function D(
|
|
16
|
-
return
|
|
52
|
+
function D(e) {
|
|
53
|
+
return e ? new Intl.DateTimeFormat().format(new Date(e)) : "-";
|
|
54
|
+
}
|
|
55
|
+
function h(e) {
|
|
56
|
+
return e ? new Intl.DateTimeFormat(void 0, {
|
|
17
57
|
year: "numeric",
|
|
18
58
|
month: "numeric",
|
|
19
59
|
day: "numeric",
|
|
20
60
|
hour: "numeric",
|
|
21
61
|
minute: "numeric"
|
|
22
|
-
}).format(new Date(
|
|
62
|
+
}).format(new Date(e)) : "-";
|
|
63
|
+
}
|
|
64
|
+
function I() {
|
|
65
|
+
return `temp-${crypto.randomUUID()}`;
|
|
66
|
+
}
|
|
67
|
+
function q(e) {
|
|
68
|
+
return e.map((t) => (t._id?.includes("temp") && delete t._id, t));
|
|
69
|
+
}
|
|
70
|
+
function P(e) {
|
|
71
|
+
return e.map((t) => (delete t._id, t));
|
|
23
72
|
}
|
|
24
73
|
export {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
74
|
+
y as clone,
|
|
75
|
+
I as createTempId,
|
|
76
|
+
P as deleteId,
|
|
77
|
+
q as deleteTempId,
|
|
78
|
+
D as formatDate,
|
|
79
|
+
h as formatDateTime,
|
|
80
|
+
g as useInfiniteScroll,
|
|
81
|
+
v as usePage,
|
|
82
|
+
p as usePagination
|
|
29
83
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mhz-helpers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "mhz-helpers",
|
|
5
5
|
"author": "dergunov.com",
|
|
6
6
|
"type": "module",
|
|
@@ -16,34 +16,36 @@
|
|
|
16
16
|
"ts": "vue-tsc --noEmit"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"vue": "3.3.4"
|
|
19
|
+
"vue": "3.3.4",
|
|
20
|
+
"vue-router": "4.2.4"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
|
-
"@types/node": "20.
|
|
23
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
24
|
-
"@typescript-eslint/parser": "6.
|
|
25
|
-
"@vitejs/plugin-vue": "4.
|
|
26
|
-
"eslint": "8.
|
|
23
|
+
"@types/node": "20.5.3",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "6.4.1",
|
|
25
|
+
"@typescript-eslint/parser": "6.4.1",
|
|
26
|
+
"@vitejs/plugin-vue": "4.3.3",
|
|
27
|
+
"eslint": "8.47.0",
|
|
27
28
|
"eslint-config-prettier": "9.0.0",
|
|
28
|
-
"eslint-import-resolver-typescript": "3.
|
|
29
|
-
"eslint-plugin-import": "2.28.
|
|
29
|
+
"eslint-import-resolver-typescript": "3.6.0",
|
|
30
|
+
"eslint-plugin-import": "2.28.1",
|
|
30
31
|
"eslint-plugin-prettier": "5.0.0",
|
|
31
|
-
"eslint-plugin-vue": "9.
|
|
32
|
+
"eslint-plugin-vue": "9.17.0",
|
|
32
33
|
"postcss-html": "1.5.0",
|
|
33
|
-
"prettier": "3.0.
|
|
34
|
-
"stylelint": "15.10.
|
|
34
|
+
"prettier": "3.0.2",
|
|
35
|
+
"stylelint": "15.10.3",
|
|
35
36
|
"stylelint-config-recess-order": "4.3.0",
|
|
36
37
|
"stylelint-config-recommended-scss": "12.0.0",
|
|
37
38
|
"stylelint-config-recommended-vue": "1.5.0",
|
|
38
39
|
"stylelint-prettier": "4.0.2",
|
|
39
40
|
"typescript": "5.1.6",
|
|
40
41
|
"vite": "4.4.9",
|
|
41
|
-
"vite-plugin-dts": "3.5.
|
|
42
|
+
"vite-plugin-dts": "3.5.2",
|
|
42
43
|
"vue-linters-config": "0.1.6",
|
|
43
44
|
"vue-tsc": "1.8.8"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
|
-
"vue": "3.3.4"
|
|
47
|
+
"vue": "3.3.4",
|
|
48
|
+
"vue-router": "4.2.4"
|
|
47
49
|
},
|
|
48
50
|
"engines": {
|
|
49
51
|
"node": "18"
|