@m4l/core 0.1.44 → 0.1.46
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,39 +1,40 @@
|
|
|
1
|
-
import { useState as s, useRef as
|
|
2
|
-
import { u as
|
|
3
|
-
import { u as
|
|
1
|
+
import { useState as s, useRef as G, useCallback as H, useEffect as p } from "react";
|
|
2
|
+
import { u as L } from "../useHostTools/index.66d9a667.js";
|
|
3
|
+
import { u as N } from "../useNetwork/index.acbf28d5.js";
|
|
4
4
|
const a = {
|
|
5
5
|
page: 0,
|
|
6
6
|
rowsPerPage: 25,
|
|
7
7
|
totalRecords: 0
|
|
8
|
-
},
|
|
8
|
+
}, D = (l) => {
|
|
9
9
|
const {
|
|
10
10
|
endPoint: m,
|
|
11
|
-
timeout:
|
|
11
|
+
timeout: w = 5e3,
|
|
12
12
|
queryParams: P,
|
|
13
|
-
fireOnChangeParms:
|
|
14
|
-
fireOnFirstLoad:
|
|
15
|
-
rowsPerPage:
|
|
13
|
+
fireOnChangeParms: i,
|
|
14
|
+
fireOnFirstLoad: h = !0,
|
|
15
|
+
rowsPerPage: u = a.rowsPerPage,
|
|
16
16
|
startProgress: R,
|
|
17
17
|
stopProgress: C,
|
|
18
18
|
isRemote: d = !0,
|
|
19
19
|
bodyToSnakeCase: S = !1,
|
|
20
|
-
responseToCamelCase: k = !1
|
|
21
|
-
|
|
20
|
+
responseToCamelCase: k = !1,
|
|
21
|
+
initialRows: y = []
|
|
22
|
+
} = l, [c, o] = s(i ? 1 : 0), [T, n] = s(y), [O, g] = s({ ...a, rowsPerPage: u }), t = G({ ...a, rowsPerPage: u }), [b, E] = s(h), { startProgress: F, stopProgress: Q } = L(), { networkOperation: q } = N(), f = H(() => {
|
|
22
23
|
o((r) => r + 1);
|
|
23
24
|
}, []);
|
|
24
25
|
return p(() => {
|
|
25
|
-
if (
|
|
26
|
-
|
|
26
|
+
if (b) {
|
|
27
|
+
E(!1);
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
+
i && f();
|
|
30
31
|
}, [P]), p(() => {
|
|
31
32
|
let r = !0;
|
|
32
|
-
if (
|
|
33
|
-
return
|
|
33
|
+
if (c !== 0)
|
|
34
|
+
return q({
|
|
34
35
|
method: "GET",
|
|
35
36
|
endPoint: m,
|
|
36
|
-
timeout:
|
|
37
|
+
timeout: w,
|
|
37
38
|
parms: {
|
|
38
39
|
...P,
|
|
39
40
|
page: t.current.page,
|
|
@@ -42,28 +43,28 @@ const a = {
|
|
|
42
43
|
bodyToSnakeCase: S,
|
|
43
44
|
responseToCamelCase: k,
|
|
44
45
|
options: {
|
|
45
|
-
startProgress: R ||
|
|
46
|
-
stopProgress: C ||
|
|
46
|
+
startProgress: R || F,
|
|
47
|
+
stopProgress: C || Q
|
|
47
48
|
},
|
|
48
49
|
isRemote: d
|
|
49
50
|
}).then((e) => {
|
|
50
|
-
r && (n(e.data), t.current.page = e.pager.page, g((
|
|
51
|
-
...
|
|
51
|
+
r && (n(e.data), t.current.page = e.pager.page, g((x) => ({
|
|
52
|
+
...x,
|
|
52
53
|
page: e.pager.page,
|
|
53
54
|
totalRecords: e.pager.total
|
|
54
55
|
})));
|
|
55
56
|
}), function() {
|
|
56
57
|
r = !1;
|
|
57
58
|
};
|
|
58
|
-
}, [
|
|
59
|
+
}, [c]), { onPageChange: (r) => {
|
|
59
60
|
t.current.page = r, o((e) => e + 1);
|
|
60
61
|
}, onRowsPerPageChange: (r) => {
|
|
61
62
|
t.current.rowsPerPage = r, g((e) => ({ ...e, rowsPerPage: r })), o((e) => e + 1);
|
|
62
|
-
}, pagerState:
|
|
63
|
+
}, pagerState: O, rows: T, clearRows: () => {
|
|
63
64
|
n([]), g(a);
|
|
64
65
|
}, Refresh: f, setRows: n };
|
|
65
66
|
};
|
|
66
67
|
export {
|
|
67
68
|
a as i,
|
|
68
|
-
|
|
69
|
+
D as u
|
|
69
70
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { UsePaginateProps } from './types';
|
|
3
3
|
import type { PagerState } from './types';
|
|
4
|
-
export declare const usePaginate: <TRow>(props: UsePaginateProps) => {
|
|
4
|
+
export declare const usePaginate: <TRow>(props: UsePaginateProps<TRow>) => {
|
|
5
5
|
onPageChange: (newPage: number) => void;
|
|
6
6
|
onRowsPerPageChange: (newRowsPerPage: number) => void;
|
|
7
7
|
pagerState: PagerState;
|
|
@@ -6,9 +6,10 @@ export declare interface PagerState {
|
|
|
6
6
|
totalRecords: number;
|
|
7
7
|
}
|
|
8
8
|
export declare const initialPagerState: PagerState;
|
|
9
|
-
export interface UsePaginateProps extends Pick<NetworkProps, 'endPoint' | 'timeout' | 'isRemote' | 'bodyToSnakeCase' | 'responseToCamelCase'>, AxiosOptions {
|
|
9
|
+
export interface UsePaginateProps<TRow> extends Pick<NetworkProps, 'endPoint' | 'timeout' | 'isRemote' | 'bodyToSnakeCase' | 'responseToCamelCase'>, AxiosOptions {
|
|
10
10
|
fireOnChangeParms?: boolean;
|
|
11
11
|
fireOnFirstLoad?: boolean;
|
|
12
12
|
queryParams: Record<string, unknown>;
|
|
13
13
|
rowsPerPage?: number;
|
|
14
|
+
initialRows?: TRow[];
|
|
14
15
|
}
|
package/index.js
CHANGED
|
@@ -19,11 +19,11 @@ import { u as $ } from "./hooks/useModuleDictionary/index.c4454f46.js";
|
|
|
19
19
|
import { u as eo } from "./hooks/useModulePrivileges/index.7a9da551.js";
|
|
20
20
|
import { u as ao } from "./hooks/useModuleSkeleton/index.07843a4f.js";
|
|
21
21
|
import { u as so } from "./hooks/useNetwork/index.acbf28d5.js";
|
|
22
|
-
import { i as no, u as mo } from "./hooks/usePaginate/index.
|
|
22
|
+
import { i as no, u as mo } from "./hooks/usePaginate/index.030f3b27.js";
|
|
23
23
|
import { u as xo } from "./hooks/usePropageteMF/index.c440b829.js";
|
|
24
24
|
import { C as lo, E as fo } from "./types/index.42c24946.js";
|
|
25
25
|
import { e as go, a as Po, g as Co, s as Mo, v as Do } from "./utils/index.6d56ba04.js";
|
|
26
|
-
import { a as co } from "./utils/axiosOperation.
|
|
26
|
+
import { a as co } from "./utils/axiosOperation.30c7cc9d.js";
|
|
27
27
|
import "react/jsx-runtime";
|
|
28
28
|
import "axios";
|
|
29
29
|
import "qs";
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import $ from "axios";
|
|
2
|
+
import j from "qs";
|
|
3
|
+
import C from "camelcase-keys";
|
|
4
4
|
import v from "snakecase-keys";
|
|
5
5
|
import { E as b } from "../types/index.42c24946.js";
|
|
6
6
|
function h(e, t, a, i, o, s) {
|
|
7
7
|
const { toast: d } = a;
|
|
8
|
-
return i === "json" ? t && t.data && typeof t.data == "object" ? t.data.error && t.data.error?.code && t.data.error?.msg !== void 0 ? Promise.reject({ ...t.data.error, status: t.status }) : (t.data.messagen && o && d(t.data.message, { type: "success", autoClose: 1e4 }), s ?
|
|
8
|
+
return i === "json" ? t && t.data && typeof t.data == "object" ? t.data.error && t.data.error?.code && t.data.error?.msg !== void 0 ? Promise.reject({ ...t.data.error, status: t.status }) : (t.data.messagen && o && d(t.data.message, { type: "success", autoClose: 1e4 }), s ? C(t.data, { deep: !0 }) : t.data) : Promise.reject({
|
|
9
9
|
code: 1,
|
|
10
10
|
msg: `Incorrect endpoint: ${e}`,
|
|
11
11
|
status: t.status
|
|
@@ -18,38 +18,38 @@ function x(e, t, a = !0, i = !0) {
|
|
|
18
18
|
status: 1,
|
|
19
19
|
code: 0
|
|
20
20
|
};
|
|
21
|
-
return e?.code !== void 0 && s.status !== void 0 && e.message !== void 0 && (s = { ...s, ...e }), e?.response ? e.response.data && typeof e.response.data == "object" && e.response.data.error && e.response.data.error?.code && e.response.data.error?.message !== void 0 ? s = { ...e.response.data.error, status: e.response.status } : (s.message = e.message, s.status = e.response.status, s.code = 0) : e?.request ? (s.message = `${e?.code} ${e.message}`, s.code = -1) : (s.message = `${e?.code} ${e.message}`, s.status = 0, s.code = -2), a && e?.response?.status === 401 && t.events_emit(b.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, {}), e?.response?.data?.error?.message && (s.message = e?.response?.data?.error.message), a && (s.message.indexOf("ERR_CANCELED") > -1 || i && o(`${s.message} - status: ${s.status} - code: ${s.code}`, {
|
|
21
|
+
return e?.code !== void 0 && s.status !== void 0 && e.message !== void 0 && (s = { ...s, ...e }), e?.response ? e.response.data && typeof e.response.data == "object" && e.response.data.error && e.response.data.error?.code && e.response.data.error?.message !== void 0 ? s = { ...e.response.data.error, status: e.response.status } : (s.message = e.message, s.status = e.response.status, s.code = 0) : e?.request ? (s.message = `${e?.code} ${e.message}`, s.code = -1) : (s.message = `${e?.code} ${e.message}`, s.status = 0, s.code = -2), console.log("ERROR", e), console.log("err", s), a && e?.response?.status === 401 && t.events_emit(b.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, {}), e?.response?.data?.error?.message && (s.message = e?.response?.data?.error.message), a && (s.message.indexOf("ERR_CANCELED") > -1 || i && o(`${s.message} - status: ${s.status} - code: ${s.code}`, {
|
|
22
22
|
type: "error"
|
|
23
23
|
})), s;
|
|
24
24
|
}
|
|
25
|
-
const
|
|
25
|
+
const S = async (e, t, a) => {
|
|
26
26
|
const {
|
|
27
27
|
method: i,
|
|
28
28
|
endPoint: o,
|
|
29
29
|
timeout: s = 6e4,
|
|
30
30
|
parms: d = {},
|
|
31
31
|
data: m = {},
|
|
32
|
-
isRemote:
|
|
32
|
+
isRemote: c = !0,
|
|
33
33
|
checkUnAuthorized: g = !0,
|
|
34
34
|
headers: l,
|
|
35
35
|
onDownloadProgress: p,
|
|
36
|
-
isExternalUrl:
|
|
36
|
+
isExternalUrl: u,
|
|
37
37
|
responseType: f = "json",
|
|
38
38
|
signal: E,
|
|
39
|
-
toastSuccess:
|
|
40
|
-
toastError:
|
|
41
|
-
bodyToSnakeCase:
|
|
42
|
-
responseToCamelCase:
|
|
39
|
+
toastSuccess: R = !0,
|
|
40
|
+
toastError: y = !0,
|
|
41
|
+
bodyToSnakeCase: _ = !1,
|
|
42
|
+
responseToCamelCase: P = !1
|
|
43
43
|
} = e;
|
|
44
44
|
let r;
|
|
45
|
-
return
|
|
46
|
-
baseURL:
|
|
47
|
-
withCredentials:
|
|
45
|
+
return c ? r = t.host_api_remote : r = t.host_api_local, e?.options?.startProgress && e?.options?.startProgress(), $({
|
|
46
|
+
baseURL: u ? void 0 : r,
|
|
47
|
+
withCredentials: c,
|
|
48
48
|
method: i,
|
|
49
|
-
url:
|
|
50
|
-
data:
|
|
49
|
+
url: u ? o : `/${o}`,
|
|
50
|
+
data: _ ? v(m, { deep: !0 }) : m,
|
|
51
51
|
params: {},
|
|
52
|
-
paramsSerializer: () =>
|
|
52
|
+
paramsSerializer: () => j.stringify(d, { encode: !0 }),
|
|
53
53
|
headers: l,
|
|
54
54
|
timeout: s,
|
|
55
55
|
onDownloadProgress: p,
|
|
@@ -60,14 +60,14 @@ const D = async (e, t, a) => {
|
|
|
60
60
|
n,
|
|
61
61
|
a,
|
|
62
62
|
f,
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
R,
|
|
64
|
+
P
|
|
65
65
|
)).catch(
|
|
66
|
-
(n) => Promise.reject(x(n, a, g,
|
|
66
|
+
(n) => (console.log("Reject de la promesa"), Promise.reject(x(n, a, g, y)))
|
|
67
67
|
).finally(() => {
|
|
68
68
|
e?.options?.stopProgress && e?.options?.stopProgress();
|
|
69
69
|
});
|
|
70
70
|
};
|
|
71
71
|
export {
|
|
72
|
-
|
|
72
|
+
S as a
|
|
73
73
|
};
|