@m4l/core 0.0.15 → 0.0.18

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,7 +1,6 @@
1
1
  export * from './contexts';
2
- export * from './hooks';
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';
6
- export { voidFunction } from './utils/voidFunction';
7
- export { axiosOperation } from './utils/axiosOperation/index';
6
+ export * from './utils';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createContext, useState, useContext, useCallback, useEffect, useLayoutEffect } from "react";
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"
@@ -245,6 +206,34 @@ var EmitEvents = /* @__PURE__ */ ((EmitEvents2) => {
245
206
  EmitEvents2["EMMIT_EVENT_HOST_THEME_CHANGE"] = "host_theme_change";
246
207
  return EmitEvents2;
247
208
  })(EmitEvents || {});
209
+ function getPropertyByString(object, propString) {
210
+ let value = object;
211
+ const props = propString.split(".");
212
+ for (let index = 0; index < props.length; index += 1) {
213
+ if (props[index] === void 0)
214
+ break;
215
+ value = value[props[index]];
216
+ }
217
+ return value;
218
+ }
219
+ function getLocalStorage(key, initialValue2) {
220
+ try {
221
+ const item = window.localStorage.getItem(key);
222
+ return item !== null ? JSON.parse(item) : initialValue2;
223
+ } catch (e) {
224
+ return initialValue2;
225
+ }
226
+ }
227
+ function setLocalStorage(key, value) {
228
+ try {
229
+ const item = window.localStorage.getItem(key);
230
+ let newValue = item !== null ? JSON.parse(item) : {};
231
+ newValue = { ...newValue, ...value };
232
+ window.localStorage.setItem(key, JSON.stringify(newValue));
233
+ } catch (e) {
234
+ console.error(e);
235
+ }
236
+ }
248
237
  function getResponse(endPoint, response) {
249
238
  console.log("Axios response", response, typeof response.data);
250
239
  if (response && response.data && typeof response.data === "object") {
@@ -322,4 +311,4 @@ const axiosOperation = async (props, enviroment, hostTools) => {
322
311
  hostTools.stopProgress();
323
312
  });
324
313
  };
325
- export { EmitEvents, EnvironmentContext, EnvironmentProvider, FlagsContext, FlagsProvider, HostToolsContext, HostToolsProvider, ModuleDictionaryContext, ModuleDictionaryProvider, NetworkContext, NetworkProvider, axiosOperation, useEnvironment, useFlags, useFlagsPresent, useHostTools, useLocalStorage, useModuleDictionary, useNetwork, voidFunction };
314
+ export { EmitEvents, EnvironmentContext, EnvironmentProvider, FlagsContext, FlagsProvider, HostToolsContext, HostToolsProvider, ModuleDictionaryContext, ModuleDictionaryProvider, NetworkContext, NetworkProvider, axiosOperation, getLocalStorage, getPropertyByString, setLocalStorage, useEnvironment, voidFunction };
@@ -0,0 +1 @@
1
+ export declare function getLocalStorage<ValueType>(key: string, initialValue: ValueType): ValueType;
@@ -0,0 +1 @@
1
+ export declare function getPropertyByString(object: Record<string, unknown>, propString: string): any;
@@ -0,0 +1,5 @@
1
+ export { voidFunction } from './voidFunction';
2
+ export { getPropertyByString } from './getPropertyByString';
3
+ export { getLocalStorage } from './getLocalStorage';
4
+ export { setLocalStorage } from './setLocalStorage';
5
+ export { axiosOperation } from './axiosOperation';
@@ -0,0 +1 @@
1
+ export declare function setLocalStorage<ValueType>(key: string, value: ValueType): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
3
  "private": false,
4
- "version": "0.0.15",
4
+ "version": "0.0.18",
5
5
  "license": "UNLICENSED",
6
6
  "author": "M4L Team",
7
7
  "scripts": {