@m4l/core 0.0.19 → 0.0.20

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.
@@ -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,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,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 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,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,3 @@
1
+ import type { Flag, FlagsContextProps } from '../../contexts/FlagsContext/types';
2
+ export declare const useFlags: () => FlagsContextProps;
3
+ export declare const useFlagsPresent: (compareFlags: Array<Flag>) => boolean;
@@ -0,0 +1,2 @@
1
+ export declare const useHostTools: () => import("../..").HostToolsType;
2
+ export default useHostTools;
@@ -0,0 +1 @@
1
+ export declare function useLocalStorage<ValueType>(key: string, initialValue: ValueType): any[];
@@ -0,0 +1,2 @@
1
+ export declare const useNetwork: () => import("../../contexts/NetworkContext/types").NetworkType;
2
+ export default useNetwork;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  export { useEnvironment } from './hooks/useEnvironment';
2
+ export { useFlags } from './hooks/useFlags';
3
+ export { useHostTools } from './hooks/useHostTools';
4
+ export { useLocalStorage } from './hooks/useLocalStorage';
5
+ export { useNetwork } from './hooks/useNetwork';
2
6
  export { EmitEvents } from './types';
3
7
  export type { Maybe, HostToolsType, NetworkProps, EnvironmentType, AxiosOperation, EventFunListener, } from './types';
4
8
  export type { GetLabelType, Dictionary, ModuleDictionary, ComponentDictionary, } from './types/dictionary';
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { createContext, useContext } from "react";
1
+ import { createContext, useContext, useState } from "react";
2
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 = {
5
+ const initialValue$2 = {
6
6
  isLocalhost: true,
7
7
  host: "",
8
8
  domain_token: "",
@@ -11,20 +11,76 @@ const initialValue = {
11
11
  host_static_assets: "",
12
12
  environment: ""
13
13
  };
14
- const EnvironmentContext = createContext(initialValue);
14
+ const EnvironmentContext = createContext(initialValue$2);
15
15
  const useEnvironment = () => {
16
16
  const context = useContext(EnvironmentContext);
17
17
  if (!context)
18
18
  throw new Error("useEnvironment context must be use inside EnvironmentContext");
19
19
  return context;
20
20
  };
21
+ function voidFunction() {
22
+ }
23
+ const initialState = {
24
+ flags: [],
25
+ clearFlags: voidFunction,
26
+ addFlag: voidFunction
27
+ };
28
+ const FlagsContext = createContext(initialState);
29
+ const useFlags = () => {
30
+ const context = useContext(FlagsContext);
31
+ if (!context)
32
+ throw new Error("useFlags context must be use inside FlagsProvider");
33
+ return context;
34
+ };
35
+ const initialValue$1 = {
36
+ toast: () => 0,
37
+ startProgress: voidFunction,
38
+ stopProgress: voidFunction,
39
+ events_add_listener: voidFunction,
40
+ events_remove_listener: voidFunction,
41
+ events_emit: voidFunction
42
+ };
43
+ const HostToolsContext = createContext(initialValue$1);
44
+ const useHostTools = () => {
45
+ const context = useContext(HostToolsContext);
46
+ if (!context)
47
+ throw new Error("useHostTools context must be use inside HostToolsContext");
48
+ return context;
49
+ };
50
+ function useLocalStorage(key, initialValue2) {
51
+ const [value, setValue] = useState(() => {
52
+ try {
53
+ const item = window.localStorage.getItem(key);
54
+ return item !== null ? JSON.parse(item) : initialValue2;
55
+ } catch (e) {
56
+ return initialValue2;
57
+ }
58
+ });
59
+ const setValueInLocalStorage = (newValue) => {
60
+ try {
61
+ window.localStorage.setItem(key, JSON.stringify(newValue));
62
+ setValue(newValue);
63
+ } catch (e) {
64
+ console.error(e);
65
+ }
66
+ };
67
+ return [value, setValueInLocalStorage];
68
+ }
69
+ const initialValue = {
70
+ networkOperation: () => Promise.resolve()
71
+ };
72
+ const NetworkContext = createContext(initialValue);
73
+ const useNetwork = () => {
74
+ const context = useContext(NetworkContext);
75
+ if (!context)
76
+ throw new Error("useNetwork context must be use inside NetworkContext");
77
+ return context;
78
+ };
21
79
  var EmitEvents = /* @__PURE__ */ ((EmitEvents2) => {
22
80
  EmitEvents2["EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED"] = `netsevice_unauthorized`;
23
81
  EmitEvents2["EMMIT_EVENT_HOST_THEME_CHANGE"] = "host_theme_change";
24
82
  return EmitEvents2;
25
83
  })(EmitEvents || {});
26
- function voidFunction() {
27
- }
28
84
  function getPropertyByString(object, propString) {
29
85
  let value = object;
30
86
  const props = propString.split(".");
@@ -130,4 +186,4 @@ const axiosOperation = async (props, enviroment, hostTools) => {
130
186
  hostTools.stopProgress();
131
187
  });
132
188
  };
133
- export { EmitEvents, axiosOperation, getLocalStorage, getPropertyByString, setLocalStorage, useEnvironment, voidFunction };
189
+ export { EmitEvents, axiosOperation, getLocalStorage, getPropertyByString, setLocalStorage, useEnvironment, useFlags, useHostTools, useLocalStorage, useNetwork, voidFunction };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
3
  "private": false,
4
- "version": "0.0.19",
4
+ "version": "0.0.20",
5
5
  "license": "UNLICENSED",
6
6
  "author": "M4L Team",
7
7
  "scripts": {