mhz-helpers 1.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.
@@ -1 +1,3 @@
1
1
  export * from './usePagination';
2
+ export * from './usePage';
3
+ export * from './useInfiniteScroll';
@@ -0,0 +1,7 @@
1
+ import { Ref } from 'vue';
2
+ export declare function useInfiniteScroll<T>(): {
3
+ page: Ref<number>;
4
+ allData: Ref<T[]>;
5
+ addData: (data: T[]) => void;
6
+ handleScroll: (isLoading: boolean, pageToSet: number) => void;
7
+ };
@@ -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/index.js CHANGED
@@ -1,18 +1,58 @@
1
- import { computed as i, toRaw as o } from "vue";
2
- function c(e) {
3
- const t = i(() => e.value?.data), n = i(() => e.value?.total);
4
- function m(r, u) {
5
- return !n.value || r === 0 || r === n.value + 1 ? u : r;
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: t, total: n, setPage: m };
8
+ return { data: t, total: r, setPage: a };
8
9
  }
9
- function f(e) {
10
- return structuredClone(o(e));
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 };
48
+ }
49
+ function y(e) {
50
+ return structuredClone(s(e));
11
51
  }
12
- function l(e) {
52
+ function D(e) {
13
53
  return e ? new Intl.DateTimeFormat().format(new Date(e)) : "-";
14
54
  }
15
- function d(e) {
55
+ function h(e) {
16
56
  return e ? new Intl.DateTimeFormat(void 0, {
17
57
  year: "numeric",
18
58
  month: "numeric",
@@ -21,21 +61,23 @@ function d(e) {
21
61
  minute: "numeric"
22
62
  }).format(new Date(e)) : "-";
23
63
  }
24
- function p() {
64
+ function I() {
25
65
  return `temp-${crypto.randomUUID()}`;
26
66
  }
27
- function s(e) {
67
+ function q(e) {
28
68
  return e.map((t) => (t._id?.includes("temp") && delete t._id, t));
29
69
  }
30
- function D(e) {
70
+ function P(e) {
31
71
  return e.map((t) => (delete t._id, t));
32
72
  }
33
73
  export {
34
- f as clone,
35
- p as createTempId,
36
- D as deleteId,
37
- s as deleteTempId,
38
- l as formatDate,
39
- d as formatDateTime,
40
- c as usePagination
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
41
83
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mhz-helpers",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "mhz-helpers",
5
5
  "author": "dergunov.com",
6
6
  "type": "module",
@@ -16,22 +16,23 @@
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.4.10",
23
- "@typescript-eslint/eslint-plugin": "6.3.0",
24
- "@typescript-eslint/parser": "6.3.0",
25
- "@vitejs/plugin-vue": "4.2.3",
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",
26
27
  "eslint": "8.47.0",
27
28
  "eslint-config-prettier": "9.0.0",
28
29
  "eslint-import-resolver-typescript": "3.6.0",
29
- "eslint-plugin-import": "2.28.0",
30
+ "eslint-plugin-import": "2.28.1",
30
31
  "eslint-plugin-prettier": "5.0.0",
31
32
  "eslint-plugin-vue": "9.17.0",
32
33
  "postcss-html": "1.5.0",
33
- "prettier": "3.0.1",
34
- "stylelint": "15.10.2",
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",
@@ -43,7 +44,8 @@
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"