@m4l/core 0.0.18 → 0.0.19

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/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './contexts';
2
1
  export { useEnvironment } from './hooks/useEnvironment';
3
2
  export { EmitEvents } from './types';
4
3
  export type { Maybe, HostToolsType, NetworkProps, EnvironmentType, AxiosOperation, EventFunListener, } from './types';
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { createContext, useState, useContext, useCallback, useLayoutEffect } from "react";
2
- import { jsx } from "react/jsx-runtime";
1
+ import { createContext, useContext } from "react";
2
+ import "react/jsx-runtime";
3
3
  import { a as axios } from "./axios.js";
4
4
  import { s as snakecaseKeys } from "./snakecase-keys.js";
5
- const initialValue$2 = {
5
+ const initialValue = {
6
6
  isLocalhost: true,
7
7
  host: "",
8
8
  domain_token: "",
@@ -11,201 +11,20 @@ const initialValue$2 = {
11
11
  host_static_assets: "",
12
12
  environment: ""
13
13
  };
14
- const EnvironmentContext = createContext(initialValue$2);
15
- function EnvironmentProvider(props) {
16
- const {
17
- children,
18
- ...other
19
- } = props;
20
- const [finalEnvironment] = useState(other);
21
- return /* @__PURE__ */ jsx(EnvironmentContext.Provider, {
22
- value: finalEnvironment,
23
- children
24
- });
25
- }
26
- function voidFunction() {
27
- }
28
- const initialValue$1 = {
29
- toast: () => 0,
30
- startProgress: voidFunction,
31
- stopProgress: voidFunction,
32
- events_add_listener: voidFunction,
33
- events_remove_listener: voidFunction,
34
- events_emit: voidFunction
35
- };
36
- const HostToolsContext = createContext(initialValue$1);
37
- function HostToolsProvider(props) {
38
- const {
39
- children,
40
- ...hostTools
41
- } = props;
42
- const [finalTools] = useState(hostTools);
43
- return /* @__PURE__ */ jsx(HostToolsContext.Provider, {
44
- value: finalTools,
45
- children
46
- });
47
- }
14
+ const EnvironmentContext = createContext(initialValue);
48
15
  const useEnvironment = () => {
49
16
  const context = useContext(EnvironmentContext);
50
17
  if (!context)
51
18
  throw new Error("useEnvironment context must be use inside EnvironmentContext");
52
19
  return context;
53
20
  };
54
- const useHostTools = () => {
55
- const context = useContext(HostToolsContext);
56
- if (!context)
57
- throw new Error("useHostTools context must be use inside HostToolsContext");
58
- return context;
59
- };
60
- const initialValue = {
61
- networkOperation: () => Promise.resolve()
62
- };
63
- const NetworkContext = createContext(initialValue);
64
- function NetworkProvider(props) {
65
- const {
66
- children,
67
- axiosOperation: axiosOperation2
68
- } = props;
69
- const environment = useEnvironment();
70
- const hostTools = useHostTools();
71
- const networkOperation = useCallback(async (networkProps) => {
72
- return axiosOperation2(networkProps, environment, hostTools);
73
- }, [axiosOperation2]);
74
- return /* @__PURE__ */ jsx(NetworkContext.Provider, {
75
- value: {
76
- networkOperation
77
- },
78
- children
79
- });
80
- }
81
- const initialState$1 = {
82
- flags: [],
83
- clearFlags: voidFunction,
84
- addFlag: voidFunction
85
- };
86
- const FlagsContext = createContext(initialState$1);
87
- function FlagsProvider({
88
- children
89
- }) {
90
- const [flags, setFlags] = useState([]);
91
- const clearFlags = useCallback(() => {
92
- setFlags([]);
93
- }, []);
94
- const addFlag = useCallback((newFlag) => {
95
- setFlags((oldFlags) => {
96
- if (oldFlags.findIndex((f) => f === newFlag) < 0) {
97
- return [...oldFlags, newFlag];
98
- }
99
- return [...oldFlags];
100
- });
101
- }, []);
102
- return /* @__PURE__ */ jsx(FlagsContext.Provider, {
103
- value: {
104
- flags,
105
- addFlag,
106
- clearFlags
107
- },
108
- children
109
- });
110
- }
111
- const useNetwork = () => {
112
- const context = useContext(NetworkContext);
113
- if (!context)
114
- throw new Error("useNetwork context must be use inside NetworkContext");
115
- return context;
116
- };
117
- const useFlags = () => {
118
- const context = useContext(FlagsContext);
119
- if (!context)
120
- throw new Error("useFlags context must be use inside FlagsProvider");
121
- return context;
122
- };
123
- const initialState = {
124
- getLabel: () => "..",
125
- getModuleLabel: () => "No dictionary context"
126
- };
127
- const ModuleDictionaryContext = createContext(initialState);
128
- function ModuleDictionaryProvider(props) {
129
- const {
130
- children,
131
- componentsDictionary,
132
- moduleId,
133
- moduleName = "module_name",
134
- currentLang = "us",
135
- isAuth = true
136
- } = props;
137
- const {
138
- addFlag
139
- } = useFlags();
140
- const [moduleDictionary, setModuleDictionary] = useState(void 0);
141
- const {
142
- domain_token
143
- } = useEnvironment();
144
- const {
145
- startProgress,
146
- stopProgress
147
- } = useHostTools();
148
- const {
149
- networkOperation
150
- } = useNetwork();
151
- useLayoutEffect(() => {
152
- let mounted = true;
153
- startProgress();
154
- networkOperation({
155
- method: "GET",
156
- endPoint: isAuth ? `dictionaries/${moduleId}` : `na/dictionaries/${moduleId}`,
157
- parms: {
158
- comps: componentsDictionary,
159
- ...isAuth ? {} : {
160
- domain_token
161
- }
162
- }
163
- }).then((response) => {
164
- if (mounted) {
165
- setModuleDictionary({
166
- ...response
167
- });
168
- addFlag("dictionary_loaded");
169
- }
170
- }).finally(() => {
171
- stopProgress();
172
- });
173
- return function cleanUp() {
174
- mounted = false;
175
- };
176
- }, [currentLang]);
177
- const getLabel = useCallback((key) => {
178
- if (moduleDictionary === void 0)
179
- return "No dictionary";
180
- if (key === void 0)
181
- return "No key";
182
- const parts = key.split(".");
183
- if (parts.length === 2) {
184
- if (moduleDictionary[parts[0]] && moduleDictionary[parts[0]][parts[1]]) {
185
- return moduleDictionary[parts[0]][parts[1]];
186
- }
187
- } else if (parts.length === 1) {
188
- if (moduleDictionary.data && moduleDictionary.data[key]) {
189
- return moduleDictionary.data[key];
190
- }
191
- }
192
- return `No dictionary:${key}`;
193
- }, [moduleDictionary]);
194
- const getModuleLabel = useCallback(() => getLabel(moduleName), [moduleName, getLabel]);
195
- return /* @__PURE__ */ jsx(ModuleDictionaryContext.Provider, {
196
- value: {
197
- moduleDictionary,
198
- getLabel,
199
- getModuleLabel
200
- },
201
- children
202
- });
203
- }
204
21
  var EmitEvents = /* @__PURE__ */ ((EmitEvents2) => {
205
22
  EmitEvents2["EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED"] = `netsevice_unauthorized`;
206
23
  EmitEvents2["EMMIT_EVENT_HOST_THEME_CHANGE"] = "host_theme_change";
207
24
  return EmitEvents2;
208
25
  })(EmitEvents || {});
26
+ function voidFunction() {
27
+ }
209
28
  function getPropertyByString(object, propString) {
210
29
  let value = object;
211
30
  const props = propString.split(".");
@@ -311,4 +130,4 @@ const axiosOperation = async (props, enviroment, hostTools) => {
311
130
  hostTools.stopProgress();
312
131
  });
313
132
  };
314
- export { EmitEvents, EnvironmentContext, EnvironmentProvider, FlagsContext, FlagsProvider, HostToolsContext, HostToolsProvider, ModuleDictionaryContext, ModuleDictionaryProvider, NetworkContext, NetworkProvider, axiosOperation, getLocalStorage, getPropertyByString, setLocalStorage, useEnvironment, voidFunction };
133
+ export { EmitEvents, axiosOperation, getLocalStorage, getPropertyByString, setLocalStorage, useEnvironment, voidFunction };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
3
  "private": false,
4
- "version": "0.0.18",
4
+ "version": "0.0.19",
5
5
  "license": "UNLICENSED",
6
6
  "author": "M4L Team",
7
7
  "scripts": {
@@ -1,5 +0,0 @@
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 };
@@ -1,10 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
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 };
@@ -1,6 +0,0 @@
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;
@@ -1,5 +0,0 @@
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 };
@@ -1,15 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import type { GetLabelType, ModuleDictionary } from 'src/types/dictionary';
3
- export interface ModuleDictionaryProviderProps {
4
- currentLang?: string;
5
- isAuth?: boolean;
6
- moduleId: number;
7
- moduleName?: string;
8
- componentsDictionary: string[];
9
- children: ReactNode;
10
- }
11
- export interface ModuleDictionaryContextProps {
12
- moduleDictionary?: ModuleDictionary;
13
- getLabel: GetLabelType;
14
- getModuleLabel: () => string;
15
- }
@@ -1,5 +0,0 @@
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 };
@@ -1,11 +0,0 @@
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;
@@ -1,5 +0,0 @@
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';
@@ -1,6 +0,0 @@
1
- export { useLocalStorage } from './useLocalStorage/useLocalStorage';
2
- export { useHostTools } from './useHostTools';
3
- export { useNetwork } from './useNetwork';
4
- export { useEnvironment } from './useEnvironment';
5
- export { useFlags, useFlagsPresent } from './useFlags';
6
- export { useModuleDictionary } from './useModuleDictionary';
@@ -1,3 +0,0 @@
1
- import type { Flag, FlagsContextProps } from '../../contexts/FlagsContext/types';
2
- export declare const useFlags: () => FlagsContextProps;
3
- export declare const useFlagsPresent: (compareFlags: Array<Flag>) => boolean;
@@ -1,2 +0,0 @@
1
- export declare const useHostTools: () => import("../..").HostToolsType;
2
- export default useHostTools;
@@ -1 +0,0 @@
1
- export declare function useLocalStorage<ValueType>(key: string, initialValue: ValueType): any[];
@@ -1 +0,0 @@
1
- export declare const useModuleDictionary: () => import("../../contexts/ModuleDictionaryContext/types").ModuleDictionaryContextProps;
@@ -1,2 +0,0 @@
1
- export declare const useNetwork: () => import("../../contexts/NetworkContext/types").NetworkType;
2
- export default useNetwork;