@m4l/core 0.0.16 → 0.0.17
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 +1 -1
- package/dist/index.js +2 -41
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './contexts';
|
|
2
|
-
export
|
|
2
|
+
export { useEnvironment } from './hooks/useEnvironment';
|
|
3
3
|
export { EmitEvents } from './types';
|
|
4
4
|
export type { Maybe, HostToolsType, NetworkProps, EnvironmentType, AxiosOperation, EventFunListener, } from './types';
|
|
5
5
|
export type { GetLabelType, Dictionary, ModuleDictionary, ComponentDictionary, } from './types/dictionary';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useState, useContext, useCallback,
|
|
1
|
+
import { createContext, useState, useContext, useCallback, useLayoutEffect } from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { a as axios } from "./axios.js";
|
|
4
4
|
import { s as snakecaseKeys } from "./snakecase-keys.js";
|
|
@@ -108,25 +108,6 @@ function FlagsProvider({
|
|
|
108
108
|
children
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
|
-
function useLocalStorage(key, initialValue2) {
|
|
112
|
-
const [value, setValue] = useState(() => {
|
|
113
|
-
try {
|
|
114
|
-
const item = window.localStorage.getItem(key);
|
|
115
|
-
return item !== null ? JSON.parse(item) : initialValue2;
|
|
116
|
-
} catch (e) {
|
|
117
|
-
return initialValue2;
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
const setValueInLocalStorage = (newValue) => {
|
|
121
|
-
try {
|
|
122
|
-
window.localStorage.setItem(key, JSON.stringify(newValue));
|
|
123
|
-
setValue(newValue);
|
|
124
|
-
} catch (e) {
|
|
125
|
-
console.error(e);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
return [value, setValueInLocalStorage];
|
|
129
|
-
}
|
|
130
111
|
const useNetwork = () => {
|
|
131
112
|
const context = useContext(NetworkContext);
|
|
132
113
|
if (!context)
|
|
@@ -139,26 +120,6 @@ const useFlags = () => {
|
|
|
139
120
|
throw new Error("useFlags context must be use inside FlagsProvider");
|
|
140
121
|
return context;
|
|
141
122
|
};
|
|
142
|
-
function isFlagsPresent(compareFlags, flags) {
|
|
143
|
-
const filterFlags = compareFlags.filter((findFlag) => flags.findIndex((sFlag) => sFlag === findFlag) !== -1);
|
|
144
|
-
return filterFlags.length === compareFlags.length;
|
|
145
|
-
}
|
|
146
|
-
const useFlagsPresent = (compareFlags) => {
|
|
147
|
-
const context = useFlags();
|
|
148
|
-
const [isPresent, setIsPresent] = useState(isFlagsPresent(compareFlags, context.flags));
|
|
149
|
-
useEffect(() => {
|
|
150
|
-
if (isFlagsPresent(compareFlags, context.flags)) {
|
|
151
|
-
setIsPresent(true);
|
|
152
|
-
}
|
|
153
|
-
}, [context.flags, compareFlags]);
|
|
154
|
-
return isPresent;
|
|
155
|
-
};
|
|
156
|
-
const useModuleDictionary = () => {
|
|
157
|
-
const context = useContext(ModuleDictionaryContext);
|
|
158
|
-
if (!context)
|
|
159
|
-
throw new Error("useModuleDictionary context must be use inside ModuleDictionaryProvider");
|
|
160
|
-
return context;
|
|
161
|
-
};
|
|
162
123
|
const initialState = {
|
|
163
124
|
getLabel: () => "..",
|
|
164
125
|
getModuleLabel: () => "No dictionary context"
|
|
@@ -350,4 +311,4 @@ const axiosOperation = async (props, enviroment, hostTools) => {
|
|
|
350
311
|
hostTools.stopProgress();
|
|
351
312
|
});
|
|
352
313
|
};
|
|
353
|
-
export { EmitEvents, EnvironmentContext, EnvironmentProvider, FlagsContext, FlagsProvider, HostToolsContext, HostToolsProvider, ModuleDictionaryContext, ModuleDictionaryProvider, NetworkContext, NetworkProvider, axiosOperation, getLocalStorage, getPropertyByString, setLocalStorage, useEnvironment,
|
|
314
|
+
export { EmitEvents, EnvironmentContext, EnvironmentProvider, FlagsContext, FlagsProvider, HostToolsContext, HostToolsProvider, ModuleDictionaryContext, ModuleDictionaryProvider, NetworkContext, NetworkProvider, axiosOperation, getLocalStorage, getPropertyByString, setLocalStorage, useEnvironment, voidFunction };
|