@m4l/core 0.0.38 → 0.0.41
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/HostToolsContext/index.js +1 -0
- package/dist/contexts/ModuleDictionaryContext/index.js +3 -2
- package/dist/contexts/ModulePrivilegesContext/index.js +3 -2
- package/dist/contexts/ModuleSkeletonContext/index.d.ts +5 -0
- package/dist/contexts/ModuleSkeletonContext/index.js +26 -0
- package/dist/contexts/ModuleSkeletonContext/types.d.ts +8 -0
- package/dist/contexts/index.d.ts +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useModuleSkeleton/index.d.ts +1 -0
- package/dist/hooks/useModuleSkeleton/index.js +9 -0
- package/dist/index.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/axiosOperation.js +6 -2
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createContext, useState,
|
|
1
|
+
import { createContext, useState, useEffect, useCallback } from "react";
|
|
2
2
|
import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
|
|
3
3
|
import { u as useFlags } from "../../hooks/useFlags/index.js";
|
|
4
4
|
import { u as useHostTools } from "../../hooks/useHostTools/index.js";
|
|
5
5
|
import "../ModulePrivilegesContext/index.js";
|
|
6
|
+
import "../ModuleSkeletonContext/index.js";
|
|
6
7
|
import { u as useNetwork } from "../../hooks/useNetwork/index.js";
|
|
7
8
|
import { jsx } from "react/jsx-runtime";
|
|
8
9
|
const initialState = {
|
|
@@ -33,7 +34,7 @@ function ModuleDictionaryProvider(props) {
|
|
|
33
34
|
const {
|
|
34
35
|
networkOperation
|
|
35
36
|
} = useNetwork();
|
|
36
|
-
|
|
37
|
+
useEffect(() => {
|
|
37
38
|
let mounted = true;
|
|
38
39
|
startProgress();
|
|
39
40
|
networkOperation({
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createContext, useState,
|
|
1
|
+
import { createContext, useState, useEffect, useCallback } from "react";
|
|
2
2
|
import "../EnvironmentContext/index.js";
|
|
3
3
|
import { u as useFlags } from "../../hooks/useFlags/index.js";
|
|
4
4
|
import { u as useHostTools } from "../../hooks/useHostTools/index.js";
|
|
5
5
|
import "../ModuleDictionaryContext/index.js";
|
|
6
|
+
import "../ModuleSkeletonContext/index.js";
|
|
6
7
|
import { u as useNetwork } from "../../hooks/useNetwork/index.js";
|
|
7
8
|
import { jsx } from "react/jsx-runtime";
|
|
8
9
|
const initialState = {
|
|
@@ -26,7 +27,7 @@ function ModulePrivilegesProvider(props) {
|
|
|
26
27
|
const {
|
|
27
28
|
networkOperation
|
|
28
29
|
} = useNetwork();
|
|
29
|
-
|
|
30
|
+
useEffect(() => {
|
|
30
31
|
let mounted = true;
|
|
31
32
|
if (queryPrivileges.length === 0) {
|
|
32
33
|
addFlag("privileges_loaded");
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ModuleSkeletonContextProps, ModuleSkeletonProviderProps } from './types';
|
|
3
|
+
declare const ModuleSkeletonContext: import("react").Context<ModuleSkeletonContextProps>;
|
|
4
|
+
declare function ModuleSkeletonProvider(props: ModuleSkeletonProviderProps): JSX.Element;
|
|
5
|
+
export { ModuleSkeletonProvider, ModuleSkeletonContext };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import "../EnvironmentContext/index.js";
|
|
3
|
+
import { a as useFlagsPresent } from "../../hooks/useFlags/index.js";
|
|
4
|
+
import "../HostToolsContext/index.js";
|
|
5
|
+
import "../ModuleDictionaryContext/index.js";
|
|
6
|
+
import "../ModulePrivilegesContext/index.js";
|
|
7
|
+
import "../NetworkContext/index.js";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
const initialState = {
|
|
10
|
+
isSkeleton: false
|
|
11
|
+
};
|
|
12
|
+
const ModuleSkeletonContext = createContext(initialState);
|
|
13
|
+
function ModuleSkeletonProvider(props) {
|
|
14
|
+
const {
|
|
15
|
+
children,
|
|
16
|
+
flags
|
|
17
|
+
} = props;
|
|
18
|
+
const isSkeleton = !useFlagsPresent(flags);
|
|
19
|
+
return /* @__PURE__ */ jsx(ModuleSkeletonContext.Provider, {
|
|
20
|
+
value: {
|
|
21
|
+
isSkeleton
|
|
22
|
+
},
|
|
23
|
+
children
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export { ModuleSkeletonContext as M, ModuleSkeletonProvider as a };
|
package/dist/contexts/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export { NetworkContext, NetworkProvider } from './NetworkContext';
|
|
|
4
4
|
export { FlagsContext, FlagsProvider } from './FlagsContext';
|
|
5
5
|
export { ModuleDictionaryContext, ModuleDictionaryProvider } from './ModuleDictionaryContext';
|
|
6
6
|
export { ModulePrivilegesContext, ModulePrivilegesProvider } from './ModulePrivilegesContext';
|
|
7
|
+
export { ModuleSkeletonContext, ModuleSkeletonProvider } from './ModuleSkeletonContext';
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { useHostTools } from './useHostTools';
|
|
|
4
4
|
export { useLocalStorage } from './useLocalStorage';
|
|
5
5
|
export { useModuleDictionary } from './useModuleDictionary';
|
|
6
6
|
export { useModulePrivileges } from './useModulePrivileges';
|
|
7
|
+
export { useModuleSkeleton } from './useModuleSkeleton';
|
|
7
8
|
export { useNetwork } from './useNetwork';
|
|
8
9
|
export { usePaginate } from './usePaginate';
|
|
9
10
|
export type { PagerState } from './usePaginate/types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useModuleSkeleton: () => boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { M as ModuleSkeletonContext } from "../../contexts/ModuleSkeletonContext/index.js";
|
|
3
|
+
const useModuleSkeleton = () => {
|
|
4
|
+
const context = useContext(ModuleSkeletonContext);
|
|
5
|
+
if (!context)
|
|
6
|
+
throw new Error("useModuleSkeleton context must be use inside ModuleSkeletonContext");
|
|
7
|
+
return context.isSkeleton;
|
|
8
|
+
};
|
|
9
|
+
export { useModuleSkeleton as u };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { F as FlagsContext, a as FlagsProvider } from "./contexts/FlagsContext/i
|
|
|
4
4
|
export { H as HostToolsContext, a as HostToolsProvider } from "./contexts/HostToolsContext/index.js";
|
|
5
5
|
export { M as ModuleDictionaryContext, a as ModuleDictionaryProvider } from "./contexts/ModuleDictionaryContext/index.js";
|
|
6
6
|
export { M as ModulePrivilegesContext, a as ModulePrivilegesProvider } from "./contexts/ModulePrivilegesContext/index.js";
|
|
7
|
+
export { M as ModuleSkeletonContext, a as ModuleSkeletonProvider } from "./contexts/ModuleSkeletonContext/index.js";
|
|
7
8
|
export { N as NetworkContext, a as NetworkProvider } from "./contexts/NetworkContext/index.js";
|
|
8
9
|
export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
|
|
9
10
|
export { u as useFlags, a as useFlagsPresent } from "./hooks/useFlags/index.js";
|
|
@@ -11,6 +12,7 @@ export { u as useHostTools } from "./hooks/useHostTools/index.js";
|
|
|
11
12
|
export { u as useLocalStorage } from "./hooks/useLocalStorage/index.js";
|
|
12
13
|
export { u as useModuleDictionary } from "./hooks/useModuleDictionary/index.js";
|
|
13
14
|
export { u as useModulePrivileges } from "./hooks/useModulePrivileges/index.js";
|
|
15
|
+
export { u as useModuleSkeleton } from "./hooks/useModuleSkeleton/index.js";
|
|
14
16
|
export { u as useNetwork } from "./hooks/useNetwork/index.js";
|
|
15
17
|
export { i as initialPagerState, u as usePaginate } from "./hooks/usePaginate/index.js";
|
|
16
18
|
export { E as EmitEvents } from "./types/index.js";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare interface HostToolsType {
|
|
|
37
37
|
toast: ToastFunction;
|
|
38
38
|
startProgress: VoidFunction;
|
|
39
39
|
stopProgress: VoidFunction;
|
|
40
|
+
formatDate: (date: Date | number, format: string, options?: any) => string;
|
|
40
41
|
events_add_listener: (eventName: string, handler: EventFunListener) => void;
|
|
41
42
|
events_remove_listener: (eventName: string, handler: Maybe<EventFunListener>) => void;
|
|
42
43
|
events_emit: (eventName: string, arg: any) => void;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { a as axios } from "../external/axios.js";
|
|
2
2
|
import qs from "qs";
|
|
3
3
|
import { E as EmitEvents } from "../types/index.js";
|
|
4
|
-
function getResponse(endPoint, response) {
|
|
4
|
+
function getResponse(endPoint, response, hostTools) {
|
|
5
5
|
console.log("Axios response", response, typeof response.data);
|
|
6
|
+
const { toast } = hostTools;
|
|
6
7
|
if (response && response.data && typeof response.data === "object") {
|
|
7
8
|
if (response.data.error && response.data.error?.code && response.data.error?.msg !== void 0) {
|
|
8
9
|
return Promise.reject({ ...response.data.error, status: response.status });
|
|
9
10
|
}
|
|
11
|
+
if (response.data.message) {
|
|
12
|
+
toast(response.data.message);
|
|
13
|
+
}
|
|
10
14
|
return response.data;
|
|
11
15
|
}
|
|
12
16
|
return Promise.reject({
|
|
@@ -79,7 +83,7 @@ const axiosOperation = async (props, enviroment, hostTools) => {
|
|
|
79
83
|
},
|
|
80
84
|
headers,
|
|
81
85
|
timeout
|
|
82
|
-
}).then((response) => getResponse(endPoint, response)).catch((error) => Promise.reject(getError(error, hostTools, checkUnAuthorized))).finally(() => {
|
|
86
|
+
}).then((response) => getResponse(endPoint, response, hostTools)).catch((error) => Promise.reject(getError(error, hostTools, checkUnAuthorized))).finally(() => {
|
|
83
87
|
hostTools.stopProgress();
|
|
84
88
|
});
|
|
85
89
|
};
|