@m4l/core 0.0.25 → 0.0.28
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/dist/contexts/ModuleDictionaryContext/index.js +1 -1
- package/dist/contexts/ModuleDictionaryContext/types.d.ts +1 -1
- package/dist/external/axios.js +4 -2
- package/dist/hooks/index.d.ts +6 -3
- package/dist/hooks/useFlags/index.js +16 -2
- package/dist/hooks/useModuleDictionary/index.js +9 -2
- package/dist/hooks/usePaginate/index.d.ts +15 -0
- package/dist/hooks/usePaginate/index.js +72 -0
- package/dist/hooks/usePaginate/types.d.ts +6 -0
- package/dist/index.d.ts +1 -5
- package/dist/index.js +4 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/vendor.js +5 -3
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createContext, useState, useLayoutEffect, useCallback } from "react";
|
|
2
|
+
import { u as useFlags } from "../../hooks/useFlags/index.js";
|
|
2
3
|
import { u as useHostTools } from "../../hooks/useHostTools/index.js";
|
|
3
4
|
import { u as useNetwork } from "../../hooks/useNetwork/index.js";
|
|
4
5
|
import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
|
|
5
|
-
import { u as useFlags } from "../../hooks/useFlags/index.js";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
const initialState = {
|
|
8
8
|
getLabel: () => "..",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import type { GetLabelType, ModuleDictionary } from '
|
|
2
|
+
import type { GetLabelType, ModuleDictionary } from '../../types/dictionary';
|
|
3
3
|
export interface ModuleDictionaryProviderProps {
|
|
4
4
|
currentLang?: string;
|
|
5
5
|
isAuth?: boolean;
|
package/dist/external/axios.js
CHANGED
|
@@ -1275,7 +1275,8 @@ const axiosOperation = async (props, enviroment, hostTools) => {
|
|
|
1275
1275
|
parms = {},
|
|
1276
1276
|
data: data2 = {},
|
|
1277
1277
|
isRemote = true,
|
|
1278
|
-
checkUnAuthorized = true
|
|
1278
|
+
checkUnAuthorized = true,
|
|
1279
|
+
headers
|
|
1279
1280
|
} = props;
|
|
1280
1281
|
let baseURL;
|
|
1281
1282
|
if (isRemote) {
|
|
@@ -1289,8 +1290,9 @@ const axiosOperation = async (props, enviroment, hostTools) => {
|
|
|
1289
1290
|
withCredentials: isRemote,
|
|
1290
1291
|
method,
|
|
1291
1292
|
url: `/${endPoint}`,
|
|
1292
|
-
data:
|
|
1293
|
+
data: data2,
|
|
1293
1294
|
params: snakecaseKeys(parms, { deep: true }),
|
|
1295
|
+
headers,
|
|
1294
1296
|
timeout
|
|
1295
1297
|
}).then((response) => getResponse(endPoint, response)).catch((error) => Promise.reject(getError(error, hostTools, checkUnAuthorized))).finally(() => {
|
|
1296
1298
|
hostTools.stopProgress();
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { useFlags, useFlagsPresent } from './useFlags';
|
|
2
2
|
export { useHostTools } from './useHostTools';
|
|
3
|
+
export { useLocalStorage } from './useLocalStorage';
|
|
4
|
+
export { useModuleDictionary } from './useModuleDictionary';
|
|
3
5
|
export { useNetwork } from './useNetwork';
|
|
4
6
|
export { useEnvironment } from './useEnvironment';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
+
export { usePaginate } from './usePaginate';
|
|
8
|
+
export type { PagerState } from './usePaginate/types';
|
|
9
|
+
export { initialPagerState } from './usePaginate/types';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
1
|
+
import { useContext, useState, useEffect } from "react";
|
|
2
2
|
import { F as FlagsContext } from "../../contexts/FlagsContext/index.js";
|
|
3
3
|
const useFlags = () => {
|
|
4
4
|
const context = useContext(FlagsContext);
|
|
@@ -6,4 +6,18 @@ const useFlags = () => {
|
|
|
6
6
|
throw new Error("useFlags context must be use inside FlagsProvider");
|
|
7
7
|
return context;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
function isFlagsPresent(compareFlags, flags) {
|
|
10
|
+
const filterFlags = compareFlags.filter((findFlag) => flags.findIndex((sFlag) => sFlag === findFlag) !== -1);
|
|
11
|
+
return filterFlags.length === compareFlags.length;
|
|
12
|
+
}
|
|
13
|
+
const useFlagsPresent = (compareFlags) => {
|
|
14
|
+
const context = useFlags();
|
|
15
|
+
const [isPresent, setIsPresent] = useState(isFlagsPresent(compareFlags, context.flags));
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (isFlagsPresent(compareFlags, context.flags)) {
|
|
18
|
+
setIsPresent(true);
|
|
19
|
+
}
|
|
20
|
+
}, [context.flags, compareFlags]);
|
|
21
|
+
return isPresent;
|
|
22
|
+
};
|
|
23
|
+
export { useFlagsPresent as a, useFlags as u };
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import "react";
|
|
2
|
-
import "../../contexts/ModuleDictionaryContext/index.js";
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { M as ModuleDictionaryContext } from "../../contexts/ModuleDictionaryContext/index.js";
|
|
3
|
+
const useModuleDictionary = () => {
|
|
4
|
+
const context = useContext(ModuleDictionaryContext);
|
|
5
|
+
if (!context)
|
|
6
|
+
throw new Error("useModuleDictionary context must be use inside ModuleDictionaryProvider");
|
|
7
|
+
return context;
|
|
8
|
+
};
|
|
9
|
+
export { useModuleDictionary as u };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PagerState } from './types';
|
|
2
|
+
export interface propsUsePaginate {
|
|
3
|
+
endPoint: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
fireOnEnter?: boolean;
|
|
6
|
+
queryParams?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export declare const usePaginate: <TRow>(props: propsUsePaginate) => {
|
|
9
|
+
onPageChange: (newPage: number) => void;
|
|
10
|
+
onRowsPerPageChange: (newRowsPerPage: number) => void;
|
|
11
|
+
pagerState: PagerState;
|
|
12
|
+
rows: TRow[];
|
|
13
|
+
clearRows: () => void;
|
|
14
|
+
Refresh: () => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useState, useRef, useCallback, useEffect } from "react";
|
|
2
|
+
import { u as useHostTools } from "../useHostTools/index.js";
|
|
3
|
+
import { u as useNetwork } from "../useNetwork/index.js";
|
|
4
|
+
const initialPagerState = {
|
|
5
|
+
page: 0,
|
|
6
|
+
rowsPerPage: 25,
|
|
7
|
+
totalRecords: 0
|
|
8
|
+
};
|
|
9
|
+
const usePaginate = (props) => {
|
|
10
|
+
const { endPoint, timeout = 5e3, queryParams = {}, fireOnEnter = true } = props;
|
|
11
|
+
const [refresh, setRefresh] = useState(0);
|
|
12
|
+
const [rows, setRows] = useState([]);
|
|
13
|
+
const [pagerState, setPagerState] = useState(initialPagerState);
|
|
14
|
+
const refPagerState = useRef(initialPagerState);
|
|
15
|
+
const [fire, setFire] = useState(fireOnEnter);
|
|
16
|
+
const { startProgress, stopProgress } = useHostTools();
|
|
17
|
+
const { networkOperation } = useNetwork();
|
|
18
|
+
const Refresh = useCallback(() => {
|
|
19
|
+
setRefresh((oldValue) => oldValue + 1);
|
|
20
|
+
}, []);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
let mounted = true;
|
|
23
|
+
if (!fire) {
|
|
24
|
+
setFire(true);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
startProgress();
|
|
28
|
+
networkOperation({
|
|
29
|
+
method: "GET",
|
|
30
|
+
endPoint,
|
|
31
|
+
timeout,
|
|
32
|
+
parms: {
|
|
33
|
+
...queryParams,
|
|
34
|
+
page: refPagerState.current.page,
|
|
35
|
+
limit: refPagerState.current.rowsPerPage
|
|
36
|
+
}
|
|
37
|
+
}).then((response) => {
|
|
38
|
+
if (mounted) {
|
|
39
|
+
setRows(response.data);
|
|
40
|
+
refPagerState.current.page = response.pager.page;
|
|
41
|
+
setPagerState((oldPagerState) => ({
|
|
42
|
+
...oldPagerState,
|
|
43
|
+
page: response.pager.page,
|
|
44
|
+
totalRecords: response.pager.total
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
}).finally(() => {
|
|
48
|
+
if (mounted) {
|
|
49
|
+
stopProgress();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return function cleanUp() {
|
|
53
|
+
stopProgress();
|
|
54
|
+
mounted = false;
|
|
55
|
+
};
|
|
56
|
+
}, [refresh, queryParams]);
|
|
57
|
+
const onPageChange = (newPage) => {
|
|
58
|
+
refPagerState.current.page = newPage;
|
|
59
|
+
setRefresh((oldValue) => oldValue + 1);
|
|
60
|
+
};
|
|
61
|
+
const onRowsPerPageChange = (newRowsPerPage) => {
|
|
62
|
+
refPagerState.current.rowsPerPage = newRowsPerPage;
|
|
63
|
+
setPagerState((oldPagerState) => ({ ...oldPagerState, rowsPerPage: newRowsPerPage }));
|
|
64
|
+
setRefresh((oldValue) => oldValue + 1);
|
|
65
|
+
};
|
|
66
|
+
const clearRows = () => {
|
|
67
|
+
setRows([]);
|
|
68
|
+
setPagerState(initialPagerState);
|
|
69
|
+
};
|
|
70
|
+
return { onPageChange, onRowsPerPageChange, pagerState, rows, clearRows, Refresh };
|
|
71
|
+
};
|
|
72
|
+
export { initialPagerState as i, usePaginate as u };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
export * from './contexts';
|
|
2
|
-
export
|
|
3
|
-
export { useFlags } from './hooks/useFlags';
|
|
4
|
-
export { useHostTools } from './hooks/useHostTools';
|
|
5
|
-
export { useLocalStorage } from './hooks/useLocalStorage';
|
|
6
|
-
export { useNetwork } from './hooks/useNetwork';
|
|
2
|
+
export * from './hooks';
|
|
7
3
|
export { EmitEvents } from './types';
|
|
8
4
|
export type { Maybe, HostToolsType, NetworkProps, EnvironmentType, AxiosOperation, EventFunListener, } from './types';
|
|
9
5
|
export type { GetLabelType, Dictionary, ModuleDictionary, ComponentDictionary, } from './types/dictionary';
|
package/dist/index.js
CHANGED
|
@@ -3,11 +3,13 @@ export { H as HostToolsContext, a as HostToolsProvider } from "./contexts/HostTo
|
|
|
3
3
|
export { N as NetworkContext, a as NetworkProvider } from "./contexts/NetworkContext/index.js";
|
|
4
4
|
export { F as FlagsContext, a as FlagsProvider } from "./contexts/FlagsContext/index.js";
|
|
5
5
|
export { M as ModuleDictionaryContext, a as ModuleDictionaryProvider } from "./contexts/ModuleDictionaryContext/index.js";
|
|
6
|
-
export { u as
|
|
7
|
-
export { u as useFlags } from "./hooks/useFlags/index.js";
|
|
6
|
+
export { u as useFlags, a as useFlagsPresent } from "./hooks/useFlags/index.js";
|
|
8
7
|
export { u as useHostTools } from "./hooks/useHostTools/index.js";
|
|
9
8
|
export { u as useLocalStorage } from "./hooks/useLocalStorage/index.js";
|
|
9
|
+
export { u as useModuleDictionary } from "./hooks/useModuleDictionary/index.js";
|
|
10
10
|
export { u as useNetwork } from "./hooks/useNetwork/index.js";
|
|
11
|
+
export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
|
|
12
|
+
export { i as initialPagerState, u as usePaginate } from "./hooks/usePaginate/index.js";
|
|
11
13
|
export { E as EmitEvents } from "./types/index.js";
|
|
12
14
|
export { a as getLocalStorage, g as getPropertyByString, s as setLocalStorage, v as voidFunction } from "./utils/index.js";
|
|
13
15
|
export { a as axiosOperation } from "./external/axios.js";
|
package/dist/types/index.d.ts
CHANGED
package/dist/vendor.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import "react";
|
|
2
|
+
import "./contexts/FlagsContext/index.js";
|
|
2
3
|
import "./contexts/HostToolsContext/index.js";
|
|
4
|
+
import "./contexts/ModuleDictionaryContext/index.js";
|
|
3
5
|
import "./contexts/NetworkContext/index.js";
|
|
4
6
|
import "./contexts/EnvironmentContext/index.js";
|
|
5
|
-
import "./contexts/FlagsContext/index.js";
|
|
6
|
-
import "./contexts/ModuleDictionaryContext/index.js";
|
|
7
|
-
import "./hooks/useEnvironment/index.js";
|
|
8
7
|
import "./hooks/useFlags/index.js";
|
|
9
8
|
import "./hooks/useHostTools/index.js";
|
|
10
9
|
import "./hooks/useLocalStorage/index.js";
|
|
10
|
+
import "./hooks/useModuleDictionary/index.js";
|
|
11
11
|
import "./hooks/useNetwork/index.js";
|
|
12
|
+
import "./hooks/useEnvironment/index.js";
|
|
13
|
+
import "./hooks/usePaginate/index.js";
|
|
12
14
|
import "./types/index.js";
|
|
13
15
|
import "./utils/index.js";
|
|
14
16
|
import "./external/axios.js";
|