@m4l/core 0.0.2 → 0.0.3

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,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,15 @@
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,3 +1,5 @@
1
1
  export { EnvironmentContext } from './EnvironmentContext';
2
2
  export { HostToolsContext } from './HostToolsContext';
3
3
  export { NetworkContext } from './NetworkContext';
4
+ export { FlagsContext } from './FlagsContext';
5
+ export { ModuleDictionaryContext } from './ModuleDictionaryContext';
@@ -2,3 +2,5 @@ export { useLocalStorage } from './useLocalStorage/useLocalStorage';
2
2
  export { useHostTools } from './useHostTools';
3
3
  export { useNetwork } from './useNetwork';
4
4
  export { useEnvironment } from './useEnvironment';
5
+ export { useFlags } from './useFlags';
6
+ export { useModuleDictionary } from './useModuleDictionary';
@@ -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 @@
1
+ export declare const useModuleDictionary: () => import("../../contexts/ModuleDictionaryContext/types").ModuleDictionaryContextProps;
package/dist/index.js CHANGED
@@ -1516,6 +1516,12 @@ const initialValue = {
1516
1516
  networkOperation: () => Promise.resolve()
1517
1517
  };
1518
1518
  const NetworkContext = createContext(initialValue);
1519
+ const initialState$1 = {
1520
+ flags: [],
1521
+ clearFlags: voidFunction,
1522
+ addFlag: voidFunction
1523
+ };
1524
+ const FlagsContext = createContext(initialState$1);
1519
1525
  function useLocalStorage(key, initialValue2) {
1520
1526
  const [value, setValue] = useState(() => {
1521
1527
  try {
@@ -1541,4 +1547,21 @@ const useNetwork = () => {
1541
1547
  throw new Error("useNetwork context must be use inside NetworkContext");
1542
1548
  return context;
1543
1549
  };
1544
- export { EmitEvents, EnvironmentContext, HostToolsContext, NetworkContext, axiosOperation, getLocalStorage, getPropertyByString, setLocalStorage, useEnvironment, useHostTools, useLocalStorage, useNetwork, voidFunction };
1550
+ const useFlags = () => {
1551
+ const context = useContext(FlagsContext);
1552
+ if (!context)
1553
+ throw new Error("useFlags context must be use inside FlagsProvider");
1554
+ return context;
1555
+ };
1556
+ const useModuleDictionary = () => {
1557
+ const context = useContext(ModuleDictionaryContext);
1558
+ if (!context)
1559
+ throw new Error("useModuleDictionary context must be use inside ModuleDictionaryProvider");
1560
+ return context;
1561
+ };
1562
+ const initialState = {
1563
+ getLabel: () => "..",
1564
+ getModuleLabel: () => "No dictionary context"
1565
+ };
1566
+ const ModuleDictionaryContext = createContext(initialState);
1567
+ export { EmitEvents, EnvironmentContext, FlagsContext, HostToolsContext, ModuleDictionaryContext, NetworkContext, axiosOperation, getLocalStorage, getPropertyByString, setLocalStorage, useEnvironment, useFlags, useHostTools, useLocalStorage, useModuleDictionary, useNetwork, voidFunction };
@@ -0,0 +1,13 @@
1
+ export declare type GetLabelType = (key: string) => string;
2
+ export interface ComponentDictionary {
3
+ [key: string]: string;
4
+ }
5
+ export interface Dictionary {
6
+ [key: string]: ComponentDictionary | boolean | undefined | string;
7
+ }
8
+ export interface DataDictionary extends ComponentDictionary {
9
+ module_name: string;
10
+ }
11
+ export interface ModuleDictionary extends Dictionary {
12
+ data: DataDictionary;
13
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
3
  "private": false,
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "license": "UNLICENSED",
6
6
  "author": "M4L Team",
7
7
  "scripts": {
@@ -33,7 +33,6 @@
33
33
  "@typescript-eslint/parser": "^5.27.1",
34
34
  "@vitejs/plugin-react": "^1.3.0",
35
35
  "axios": "^0.27.2",
36
- "c8": "^7.11.3",
37
36
  "eslint": "^8.17.0",
38
37
  "eslint-config-prettier": "^8.5.0",
39
38
  "eslint-import-resolver-alias": "^1.1.2",