@m4l/core 0.1.7 → 0.1.10

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.
Files changed (60) hide show
  1. package/contexts/EnvironmentContext/index.d.ts +5 -0
  2. package/contexts/EnvironmentContext/index.js +32 -0
  3. package/contexts/EnvironmentContext/types.d.ts +6 -0
  4. package/contexts/FlagsContext/index.d.ts +5 -0
  5. package/contexts/FlagsContext/index.js +34 -0
  6. package/contexts/FlagsContext/types.d.ts +10 -0
  7. package/contexts/HostToolsContext/index.d.ts +6 -0
  8. package/contexts/HostToolsContext/index.js +25 -0
  9. package/contexts/HostToolsContext/types.d.ts +6 -0
  10. package/contexts/ModuleDictionaryContext/index.d.ts +5 -0
  11. package/contexts/ModuleDictionaryContext/index.js +90 -0
  12. package/contexts/ModuleDictionaryContext/types.d.ts +15 -0
  13. package/contexts/ModulePrivilegesContext/index.d.ts +5 -0
  14. package/contexts/ModulePrivilegesContext/index.js +68 -0
  15. package/contexts/ModulePrivilegesContext/types.d.ts +9 -0
  16. package/contexts/ModuleSkeletonContext/index.d.ts +5 -0
  17. package/contexts/ModuleSkeletonContext/index.js +26 -0
  18. package/contexts/ModuleSkeletonContext/types.d.ts +8 -0
  19. package/contexts/NetworkContext/index.d.ts +5 -0
  20. package/contexts/NetworkContext/index.js +26 -0
  21. package/contexts/NetworkContext/types.d.ts +11 -0
  22. package/contexts/index.d.ts +7 -0
  23. package/external/axios.js +1261 -0
  24. package/hooks/index.d.ts +11 -0
  25. package/hooks/useEnvironment/index.d.ts +2 -0
  26. package/hooks/useEnvironment/index.js +9 -0
  27. package/hooks/useFlags/index.d.ts +3 -0
  28. package/hooks/useFlags/index.js +25 -0
  29. package/hooks/useHostTools/index.d.ts +2 -0
  30. package/hooks/useHostTools/index.js +9 -0
  31. package/hooks/useLocalStorage/index.d.ts +1 -0
  32. package/hooks/useLocalStorage/index.js +21 -0
  33. package/hooks/useModuleDictionary/index.d.ts +1 -0
  34. package/hooks/useModuleDictionary/index.js +9 -0
  35. package/hooks/useModulePrivileges/index.d.ts +1 -0
  36. package/hooks/useModulePrivileges/index.js +9 -0
  37. package/hooks/useModuleSkeleton/index.d.ts +1 -0
  38. package/hooks/useModuleSkeleton/index.js +9 -0
  39. package/hooks/useNetwork/index.d.ts +2 -0
  40. package/hooks/useNetwork/index.js +9 -0
  41. package/hooks/usePaginate/index.d.ts +10 -0
  42. package/hooks/usePaginate/index.js +74 -0
  43. package/hooks/usePaginate/types.d.ts +12 -0
  44. package/index.d.ts +6 -0
  45. package/index.js +23 -0
  46. package/jest.d.ts +1 -0
  47. package/package.json +2 -2
  48. package/types/dictionary.d.ts +13 -0
  49. package/types/index.d.ts +49 -0
  50. package/types/index.js +6 -0
  51. package/utils/axiosOperation/index.d.ts +2 -0
  52. package/utils/axiosOperation/types.d.ts +5 -0
  53. package/utils/axiosOperation.js +90 -0
  54. package/utils/getLocalStorage.d.ts +1 -0
  55. package/utils/getPropertyByString.d.ts +1 -0
  56. package/utils/index.d.ts +5 -0
  57. package/utils/index.js +33 -0
  58. package/utils/setLocalStorage.d.ts +1 -0
  59. package/utils/voidFunction.d.ts +1 -0
  60. package/vite-env.d.ts +4 -0
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { EnvironmentProviderProps } from './types';
3
+ declare const EnvironmentContext: import("react").Context<import("../..").EnvironmentType>;
4
+ declare function EnvironmentProvider(props: EnvironmentProviderProps): JSX.Element;
5
+ export { EnvironmentProvider, EnvironmentContext };
@@ -0,0 +1,32 @@
1
+ import { createContext, useState } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ const initialValue = {
4
+ isLocalhost: true,
5
+ host: "",
6
+ domain_token: "",
7
+ host_api_local: "",
8
+ host_api_remote: "",
9
+ host_static_assets: "",
10
+ environment_assets: "",
11
+ dfnsFormat: {
12
+ date_format: "yyyy-MM-dd",
13
+ date_mask: "____-__-__",
14
+ time_format: "HH:mm:ss",
15
+ time_mask: "__:__:__",
16
+ datetime_format: "yyyy-MM-dd HH:mm:ss",
17
+ datetime_mask: "____-__-__ __:__:__"
18
+ }
19
+ };
20
+ const EnvironmentContext = createContext(initialValue);
21
+ function EnvironmentProvider(props) {
22
+ const {
23
+ children,
24
+ ...other
25
+ } = props;
26
+ const [finalEnvironment] = useState(other);
27
+ return /* @__PURE__ */ jsx(EnvironmentContext.Provider, {
28
+ value: finalEnvironment,
29
+ children
30
+ });
31
+ }
32
+ export { EnvironmentContext as E, EnvironmentProvider as a };
@@ -0,0 +1,6 @@
1
+ import { ReactNode } from 'react';
2
+ import { EnvironmentType } from '../../types';
3
+ export interface EnvironmentProviderProps extends EnvironmentType {
4
+ children: ReactNode;
5
+ }
6
+ export declare type EnvironmentContextType = EnvironmentType;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { FlagsContextProps, FlagsProviderProps } from './types';
3
+ declare const FlagsContext: import("react").Context<FlagsContextProps>;
4
+ declare function FlagsProvider({ children }: FlagsProviderProps): JSX.Element;
5
+ export { FlagsProvider, FlagsContext };
@@ -0,0 +1,34 @@
1
+ import { createContext, useState, useCallback } from "react";
2
+ import { v as voidFunction } from "../../utils/index.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ const initialState = {
5
+ flags: [],
6
+ clearFlags: voidFunction,
7
+ addFlag: voidFunction
8
+ };
9
+ const FlagsContext = createContext(initialState);
10
+ function FlagsProvider({
11
+ children
12
+ }) {
13
+ const [flags, setFlags] = useState([]);
14
+ const clearFlags = useCallback(() => {
15
+ setFlags([]);
16
+ }, []);
17
+ const addFlag = useCallback((newFlag) => {
18
+ setFlags((oldFlags) => {
19
+ if (oldFlags.findIndex((f) => f === newFlag) < 0) {
20
+ return [...oldFlags, newFlag];
21
+ }
22
+ return [...oldFlags];
23
+ });
24
+ }, []);
25
+ return /* @__PURE__ */ jsx(FlagsContext.Provider, {
26
+ value: {
27
+ flags,
28
+ addFlag,
29
+ clearFlags
30
+ },
31
+ children
32
+ });
33
+ }
34
+ export { FlagsContext as F, FlagsProvider as a };
@@ -0,0 +1,10 @@
1
+ import { ReactNode } from 'react';
2
+ export interface FlagsProviderProps {
3
+ children: ReactNode;
4
+ }
5
+ export declare type Flag = string;
6
+ export interface FlagsContextProps {
7
+ flags: Array<Flag>;
8
+ clearFlags: () => void;
9
+ addFlag: (flag: Flag) => void;
10
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { HostToolsType } from '../../types';
3
+ import type { HostToolsProviderProps } from './types';
4
+ declare const HostToolsContext: import("react").Context<HostToolsType>;
5
+ declare function HostToolsProvider(props: HostToolsProviderProps): JSX.Element;
6
+ export { HostToolsProvider, HostToolsContext };
@@ -0,0 +1,25 @@
1
+ import { createContext, useState } from "react";
2
+ import { v as voidFunction } from "../../utils/index.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ const initialValue = {
5
+ toast: () => 0,
6
+ startProgress: voidFunction,
7
+ stopProgress: voidFunction,
8
+ formatDate: () => "",
9
+ events_add_listener: voidFunction,
10
+ events_remove_listener: voidFunction,
11
+ events_emit: voidFunction
12
+ };
13
+ const HostToolsContext = createContext(initialValue);
14
+ function HostToolsProvider(props) {
15
+ const {
16
+ children,
17
+ ...hostTools
18
+ } = props;
19
+ const [finalTools] = useState(hostTools);
20
+ return /* @__PURE__ */ jsx(HostToolsContext.Provider, {
21
+ value: finalTools,
22
+ children
23
+ });
24
+ }
25
+ export { HostToolsContext as H, HostToolsProvider as a };
@@ -0,0 +1,6 @@
1
+ import { ReactNode } from 'react';
2
+ import { HostToolsType } from '../../types';
3
+ export interface HostToolsProviderProps extends HostToolsType {
4
+ children: ReactNode;
5
+ }
6
+ export declare type HostToolsContextType = HostToolsType;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { ModuleDictionaryContextProps, ModuleDictionaryProviderProps } from './types';
3
+ declare const ModuleDictionaryContext: import("react").Context<ModuleDictionaryContextProps>;
4
+ declare function ModuleDictionaryProvider(props: ModuleDictionaryProviderProps): JSX.Element;
5
+ export { ModuleDictionaryProvider, ModuleDictionaryContext };
@@ -0,0 +1,90 @@
1
+ import { createContext, useState, useEffect, useCallback } from "react";
2
+ import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
3
+ import { u as useFlags } from "../../hooks/useFlags/index.js";
4
+ import { u as useHostTools } from "../../hooks/useHostTools/index.js";
5
+ import "../ModulePrivilegesContext/index.js";
6
+ import "../ModuleSkeletonContext/index.js";
7
+ import { u as useNetwork } from "../../hooks/useNetwork/index.js";
8
+ import { jsx } from "react/jsx-runtime";
9
+ const initialState = {
10
+ getLabel: () => "..",
11
+ getModuleLabel: () => "No dictionary context"
12
+ };
13
+ const ModuleDictionaryContext = createContext(initialState);
14
+ function ModuleDictionaryProvider(props) {
15
+ const {
16
+ children,
17
+ componentsDictionary,
18
+ moduleId,
19
+ moduleName = "module_name",
20
+ currentLang = "us",
21
+ isAuth = true
22
+ } = props;
23
+ const {
24
+ addFlag
25
+ } = useFlags();
26
+ const [moduleDictionary, setModuleDictionary] = useState(void 0);
27
+ const {
28
+ domain_token
29
+ } = useEnvironment();
30
+ const {
31
+ startProgress,
32
+ stopProgress
33
+ } = useHostTools();
34
+ const {
35
+ networkOperation
36
+ } = useNetwork();
37
+ useEffect(() => {
38
+ let mounted = true;
39
+ startProgress();
40
+ networkOperation({
41
+ method: "GET",
42
+ endPoint: isAuth ? `dictionaries/${moduleId}` : `na/dictionaries/${moduleId}`,
43
+ parms: {
44
+ comps: componentsDictionary,
45
+ ...isAuth ? {} : {
46
+ domain_token
47
+ }
48
+ }
49
+ }).then((response) => {
50
+ if (mounted) {
51
+ setModuleDictionary({
52
+ ...response
53
+ });
54
+ addFlag("dictionary_loaded");
55
+ }
56
+ }).finally(() => {
57
+ stopProgress();
58
+ });
59
+ return function cleanUp() {
60
+ mounted = false;
61
+ };
62
+ }, [currentLang]);
63
+ const getLabel = useCallback((key) => {
64
+ if (moduleDictionary === void 0)
65
+ return "No dictionary";
66
+ if (key === void 0)
67
+ return "No key";
68
+ const parts = key.split(".");
69
+ if (parts.length === 2) {
70
+ if (moduleDictionary[parts[0]] && moduleDictionary[parts[0]][parts[1]]) {
71
+ return moduleDictionary[parts[0]][parts[1]];
72
+ }
73
+ } else if (parts.length === 1) {
74
+ if (moduleDictionary.data && moduleDictionary.data[key]) {
75
+ return moduleDictionary.data[key];
76
+ }
77
+ }
78
+ return `No dictionary:${key}`;
79
+ }, [moduleDictionary]);
80
+ const getModuleLabel = useCallback(() => getLabel(moduleName), [moduleName, getLabel]);
81
+ return /* @__PURE__ */ jsx(ModuleDictionaryContext.Provider, {
82
+ value: {
83
+ moduleDictionary,
84
+ getLabel,
85
+ getModuleLabel
86
+ },
87
+ children
88
+ });
89
+ }
90
+ export { ModuleDictionaryContext as M, ModuleDictionaryProvider as a };
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from 'react';
2
+ import type { GetLabelType, ModuleDictionary } from '../../types/dictionary';
3
+ export interface ModuleDictionaryProviderProps {
4
+ currentLang?: string;
5
+ isAuth?: boolean;
6
+ moduleId: string;
7
+ moduleName?: string;
8
+ componentsDictionary: string[];
9
+ children: ReactNode;
10
+ }
11
+ export interface ModuleDictionaryContextProps {
12
+ moduleDictionary?: ModuleDictionary;
13
+ getLabel: GetLabelType;
14
+ getModuleLabel: () => string;
15
+ }
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { ModulePrivilegesContextProps, ModulePrivilegesProviderProps } from './types';
3
+ declare const ModulePrivilegesContext: import("react").Context<ModulePrivilegesContextProps>;
4
+ declare function ModulePrivilegesProvider(props: ModulePrivilegesProviderProps): JSX.Element;
5
+ export { ModulePrivilegesProvider, ModulePrivilegesContext };
@@ -0,0 +1,68 @@
1
+ import { createContext, useState, useEffect, useCallback } from "react";
2
+ import "../EnvironmentContext/index.js";
3
+ import { u as useFlags } from "../../hooks/useFlags/index.js";
4
+ import { u as useHostTools } from "../../hooks/useHostTools/index.js";
5
+ import "../ModuleDictionaryContext/index.js";
6
+ import "../ModuleSkeletonContext/index.js";
7
+ import { u as useNetwork } from "../../hooks/useNetwork/index.js";
8
+ import { jsx } from "react/jsx-runtime";
9
+ const initialState = {
10
+ privileges: {},
11
+ hasPrivilege: () => false
12
+ };
13
+ const ModulePrivilegesContext = createContext(initialState);
14
+ function ModulePrivilegesProvider(props) {
15
+ const {
16
+ children,
17
+ queryPrivileges
18
+ } = props;
19
+ const {
20
+ addFlag
21
+ } = useFlags();
22
+ const [privileges, setPrivileges] = useState({});
23
+ const {
24
+ startProgress,
25
+ stopProgress
26
+ } = useHostTools();
27
+ const {
28
+ networkOperation
29
+ } = useNetwork();
30
+ useEffect(() => {
31
+ let mounted = true;
32
+ if (queryPrivileges.length === 0) {
33
+ addFlag("privileges_loaded");
34
+ return;
35
+ }
36
+ startProgress();
37
+ networkOperation({
38
+ method: "GET",
39
+ endPoint: `auth/login`,
40
+ parms: {
41
+ privileges: queryPrivileges
42
+ }
43
+ }).then((response) => {
44
+ if (mounted) {
45
+ setPrivileges({
46
+ ...response.data
47
+ });
48
+ addFlag("privileges_loaded");
49
+ }
50
+ }).finally(() => {
51
+ stopProgress();
52
+ });
53
+ return function cleanUp() {
54
+ mounted = false;
55
+ };
56
+ }, []);
57
+ const hasPrivilege = useCallback((key) => {
58
+ return key in privileges;
59
+ }, [privileges]);
60
+ return /* @__PURE__ */ jsx(ModulePrivilegesContext.Provider, {
61
+ value: {
62
+ hasPrivilege,
63
+ privileges
64
+ },
65
+ children
66
+ });
67
+ }
68
+ export { ModulePrivilegesContext as M, ModulePrivilegesProvider as a };
@@ -0,0 +1,9 @@
1
+ import { ReactNode } from 'react';
2
+ export interface ModulePrivilegesProviderProps {
3
+ queryPrivileges: string[];
4
+ children: ReactNode;
5
+ }
6
+ export interface ModulePrivilegesContextProps {
7
+ privileges: Record<string, boolean>;
8
+ hasPrivilege: (id: string) => boolean;
9
+ }
@@ -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 };
@@ -0,0 +1,8 @@
1
+ import { ReactNode } from 'react';
2
+ export interface ModuleSkeletonProviderProps {
3
+ flags: string[];
4
+ children: ReactNode;
5
+ }
6
+ export interface ModuleSkeletonContextProps {
7
+ isSkeleton: boolean;
8
+ }
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import type { NetworkProviderProps } from './types';
3
+ declare const NetworkContext: import("react").Context<import("./types").NetworkType>;
4
+ declare function NetworkProvider(props: NetworkProviderProps): JSX.Element;
5
+ export { NetworkProvider, NetworkContext };
@@ -0,0 +1,26 @@
1
+ import { createContext, useCallback } from "react";
2
+ import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
3
+ import { u as useHostTools } from "../../hooks/useHostTools/index.js";
4
+ import { jsx } from "react/jsx-runtime";
5
+ const initialValue = {
6
+ networkOperation: () => Promise.resolve()
7
+ };
8
+ const NetworkContext = createContext(initialValue);
9
+ function NetworkProvider(props) {
10
+ const {
11
+ children,
12
+ axiosOperation
13
+ } = props;
14
+ const environment = useEnvironment();
15
+ const hostTools = useHostTools();
16
+ const networkOperation = useCallback(async (networkProps) => {
17
+ return axiosOperation(networkProps, environment, hostTools);
18
+ }, [axiosOperation]);
19
+ return /* @__PURE__ */ jsx(NetworkContext.Provider, {
20
+ value: {
21
+ networkOperation
22
+ },
23
+ children
24
+ });
25
+ }
26
+ export { NetworkContext as N, NetworkProvider as a };
@@ -0,0 +1,11 @@
1
+ import { ReactNode } from 'react';
2
+ import { AxiosOperation, NetworkProps } from '../../types';
3
+ export declare type EventFunListener = (...args: any[]) => void;
4
+ export interface NetworkType {
5
+ networkOperation: (props: NetworkProps) => Promise<any>;
6
+ }
7
+ export interface NetworkProviderProps {
8
+ axiosOperation: AxiosOperation;
9
+ children: ReactNode;
10
+ }
11
+ export declare type NetworkContextType = NetworkType;
@@ -0,0 +1,7 @@
1
+ export { EnvironmentContext, EnvironmentProvider } from './EnvironmentContext';
2
+ export { HostToolsContext, HostToolsProvider } from './HostToolsContext';
3
+ export { NetworkContext, NetworkProvider } from './NetworkContext';
4
+ export { FlagsContext, FlagsProvider } from './FlagsContext';
5
+ export { ModuleDictionaryContext, ModuleDictionaryProvider } from './ModuleDictionaryContext';
6
+ export { ModulePrivilegesContext, ModulePrivilegesProvider } from './ModulePrivilegesContext';
7
+ export { ModuleSkeletonContext, ModuleSkeletonProvider } from './ModuleSkeletonContext';