@m4l/core 0.0.23 → 0.0.24

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.
Files changed (83) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.cjs +109 -0
  3. package/.prettierignore +2 -0
  4. package/.prettierrc.json +26 -0
  5. package/.vscode/settings.json +50 -0
  6. package/README copy.md +0 -0
  7. package/index.html +13 -0
  8. package/package.json +2 -4
  9. package/package_with_dependicies.json +75 -0
  10. package/src/contexts/EnvironmentContext/index.tsx +37 -0
  11. package/{dist/contexts/EnvironmentContext/types.d.ts → src/contexts/EnvironmentContext/types.ts} +3 -1
  12. package/src/contexts/FlagsContext/index.tsx +50 -0
  13. package/{dist/contexts/FlagsContext/types.d.ts → src/contexts/FlagsContext/types.ts} +7 -1
  14. package/src/contexts/HostToolsContext/index.tsx +34 -0
  15. package/{dist/contexts/HostToolsContext/types.d.ts → src/contexts/HostToolsContext/types.ts} +3 -1
  16. package/src/contexts/ModuleDictionaryContext/index.tsx +109 -0
  17. package/{dist/contexts/ModuleDictionaryContext/types.d.ts → src/contexts/ModuleDictionaryContext/types.ts} +4 -1
  18. package/src/contexts/NetworkContext/index.tsx +44 -0
  19. package/{dist/contexts/NetworkContext/types.d.ts → src/contexts/NetworkContext/types.ts} +6 -2
  20. package/{dist/contexts/index.d.ts → src/contexts/index.ts} +0 -0
  21. package/{dist/hooks/index.d.ts → src/hooks/index.ts} +1 -0
  22. package/src/hooks/useEnvironment/index.test.tsx +36 -0
  23. package/src/hooks/useEnvironment/index.ts +13 -0
  24. package/src/hooks/useFlags/index.ts +33 -0
  25. package/src/hooks/useHostTools/index.ts +13 -0
  26. package/src/hooks/useLocalStorage/index.ts +23 -0
  27. package/src/hooks/useModuleDictionary/index.ts +11 -0
  28. package/src/hooks/useNetwork/index.ts +13 -0
  29. package/src/index.ts +43 -0
  30. package/src/indexFlags.ts +1 -0
  31. package/src/isolation/App.tsx +24 -0
  32. package/src/main.tsx +10 -0
  33. package/src/prueba.d1.t1 +10 -0
  34. package/src/test/setup.ts +1 -0
  35. package/src/test/utils.tsx +20 -0
  36. package/{dist/types/dictionary.d.ts → src/types/dictionary.ts} +5 -1
  37. package/{dist/types/index.d.ts → src/types/index.ts} +20 -5
  38. package/src/utils/axiosOperation/index.ts +140 -0
  39. package/{dist/utils/axiosOperation/types.d.ts → src/utils/axiosOperation/types.ts} +1 -1
  40. package/src/utils/getLocalStorage.ts +8 -0
  41. package/src/utils/getPropertyByString.ts +10 -0
  42. package/{dist/utils/index.d.ts → src/utils/index.ts} +0 -0
  43. package/src/utils/setLocalStorage.ts +12 -0
  44. package/src/utils/voidFunction.ts +2 -0
  45. package/{dist → src}/vite-env.d.ts +0 -0
  46. package/tsconfig.json +37 -0
  47. package/tsconfig.node.json +10 -0
  48. package/vite.config.ts +178 -0
  49. package/dist/contexts/EnvironmentContext/index.d.ts +0 -5
  50. package/dist/contexts/EnvironmentContext/index.js +0 -24
  51. package/dist/contexts/FlagsContext/index.d.ts +0 -5
  52. package/dist/contexts/FlagsContext/index.js +0 -34
  53. package/dist/contexts/HostToolsContext/index.d.ts +0 -6
  54. package/dist/contexts/HostToolsContext/index.js +0 -24
  55. package/dist/contexts/ModuleDictionaryContext/index.d.ts +0 -5
  56. package/dist/contexts/ModuleDictionaryContext/index.js +0 -88
  57. package/dist/contexts/NetworkContext/index.d.ts +0 -5
  58. package/dist/contexts/NetworkContext/index.js +0 -26
  59. package/dist/external/axios.js +0 -1299
  60. package/dist/external/snakecase-keys.js +0 -18
  61. package/dist/hooks/useEnvironment/index.d.ts +0 -2
  62. package/dist/hooks/useEnvironment/index.js +0 -9
  63. package/dist/hooks/useFlags/index.d.ts +0 -3
  64. package/dist/hooks/useFlags/index.js +0 -9
  65. package/dist/hooks/useHostTools/index.d.ts +0 -2
  66. package/dist/hooks/useHostTools/index.js +0 -9
  67. package/dist/hooks/useLocalStorage/index.d.ts +0 -1
  68. package/dist/hooks/useLocalStorage/index.js +0 -21
  69. package/dist/hooks/useModuleDictionary/index.d.ts +0 -1
  70. package/dist/hooks/useModuleDictionary/index.js +0 -2
  71. package/dist/hooks/useNetwork/index.d.ts +0 -2
  72. package/dist/hooks/useNetwork/index.js +0 -9
  73. package/dist/index.d.ts +0 -10
  74. package/dist/index.js +0 -18
  75. package/dist/node_modules.js +0 -100
  76. package/dist/types/index.js +0 -6
  77. package/dist/utils/axiosOperation/index.d.ts +0 -2
  78. package/dist/utils/getLocalStorage.d.ts +0 -1
  79. package/dist/utils/getPropertyByString.d.ts +0 -1
  80. package/dist/utils/index.js +0 -33
  81. package/dist/utils/setLocalStorage.d.ts +0 -1
  82. package/dist/utils/voidFunction.d.ts +0 -1
  83. package/dist/vendor.js +0 -30
package/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ dist
package/.eslintrc.cjs ADDED
@@ -0,0 +1,109 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const prettierOptions = JSON.parse(fs.readFileSync(path.resolve(__dirname, '.prettierrc.json'), 'utf8'));
6
+
7
+ module.exports = {
8
+ env: {
9
+ browser: true,
10
+ es2021: true,
11
+ },
12
+ extends: [
13
+ 'plugin:react/recommended',
14
+ // 'airbnb',
15
+ 'eslint:recommended',
16
+ 'plugin:jsx-a11y/recommended',
17
+ 'plugin:import/typescript',
18
+ 'plugin:react/jsx-runtime',
19
+ 'plugin:prettier/recommended',
20
+ 'plugin:@typescript-eslint/recommended',
21
+ 'prettier',
22
+ ],
23
+ parser: '@typescript-eslint/parser',
24
+ parserOptions: {
25
+ ecmaFeatures: {
26
+ jsx: true,
27
+ },
28
+ ecmaVersion: 'latest',
29
+ sourceType: 'module',
30
+ },
31
+ plugins: ['react', '@typescript-eslint', 'import', 'jsx-a11y', 'react-hooks', 'prettier', 'unused-imports'],
32
+ rules: {
33
+ 'prettier/prettier': ['error', prettierOptions],
34
+ 'react/jsx-filename-extension': [1, {extensions: ['.ts', '.tsx']}], //En que archivos va a haber jsx
35
+ '@typescript-eslint/no-explicit-any':"off",
36
+ 'react/jsx-props-no-spreading':"off", //Que se pueda usar el spread
37
+ "react/prop-types":"off", //Desactivar los proptypes
38
+ "react/require-default-props":"off", //Cuando se usan props parametros opcionales no es necesariio definir los valores por defecto
39
+ "react/jsx-no-useless-fragment":"warn", //No usar jsx dentro de un fragment
40
+ "react/no-unstable-nested-components": [
41
+ "off",
42
+ { "allowAsProps": true }
43
+ ],
44
+ "@typescript-eslint/no-empty-interface":"warn",
45
+ "@typescript-eslint/ban-ts-comment":"off",
46
+ "no-empty-pattern":"warn",
47
+ "no-shadow":"warn", //que se puedan declarar las mismas variables dentro del scope
48
+ 'no-console': 'off', //Que no se puedan imprimir en la consola
49
+ "no-empty": "off",
50
+ // "no-empty-function": "error",
51
+ "@typescript-eslint/no-empty-function": "off",
52
+ 'import/extensions': [
53
+ 'off',
54
+ 'ignorePackages',
55
+ {
56
+ // js: 'never',
57
+ // mjs: 'never',
58
+ // jsx: 'never',
59
+ ts: 'never', //se especifica q tipo de librerias se pueden importar
60
+ tsx: 'never',
61
+ },
62
+ ],
63
+ 'import/prefer-default-export': 'off',
64
+ },
65
+ overrides: [
66
+ {
67
+ files: ['**/*.ts?(x)','**/*.js?(x)'],
68
+ rules: {
69
+ 'prettier/prettier': ['warn', prettierOptions],
70
+ },
71
+ },
72
+ ],
73
+ settings: {
74
+ "react": {
75
+ "createClass": "createReactClass", // Regex for Component Factory to use,
76
+ // default to "createReactClass"
77
+ "pragma": "React", // Pragma to use, default to "React"
78
+ "fragment": "Fragment", // Fragment to use (may be a property of <pragma>), default to "Fragment"
79
+ "version": "detect", // React version. "detect" automatically picks the version you have installed.
80
+ // You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
81
+ // It will default to "latest" and warn if missing, and to "detect" in the future
82
+ "flowVersion": "0.53" // Flow version
83
+ },
84
+ 'import/extensions': ['.js', '.mjs', '.jsx', '.ts', '.tsx'],
85
+ 'import/resolver': { //Permite encontrar los alias de los paths de importación
86
+ alias: {
87
+ map: [['~', path.resolve(__dirname)],['@hooks', path.resolve(__dirname)||'/hooks/']],
88
+ extensions: ['.ts', '.js', '.tsx'],
89
+ },
90
+ },
91
+ },
92
+ };
93
+
94
+ // {
95
+ // "jsxSingleQuote": false,
96
+ // "singleQuote": true,
97
+ // "semi": true,
98
+ // "tabWidth": 4,
99
+ // "trailingComma": "all",
100
+ // "printWidth": 100,
101
+ // "bracketSpacing": false,
102
+ // "bracketSameLine": false,
103
+ // "useTabs": false,
104
+ // "arrowParens": "always",
105
+ // "endOfLine": "crlf",
106
+ // "proseWrap": "preserve",
107
+ // "quoteProps": "as-needed",
108
+ // "htmlWhitespaceSensitivity": "css"
109
+ // }
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ yarn.lock
@@ -0,0 +1,26 @@
1
+ {
2
+ "printWidth": 100,
3
+ "endOfLine":"auto",
4
+ "tabWidth": 4,
5
+ "useTabs": false,
6
+ "semi": true,
7
+ "singleQuote": true,
8
+ "trailingComma": "all",
9
+ "arrowParens" : "avoid",
10
+ "bracketSpacing": true,
11
+ "bracketSameLine":false,
12
+ "proseWrap": "never",
13
+ "quoteProps": "as-needed",
14
+ "singleAttributePerLine":false ,
15
+
16
+ "overrides": [
17
+ {
18
+ "files": ".prettierrc",
19
+ "options": { "parser": "typescript" }
20
+ }
21
+ ]
22
+
23
+
24
+ }
25
+
26
+
@@ -0,0 +1,50 @@
1
+ {
2
+ "explorer.confirmDelete": false,
3
+ "code-runner.clearPreviousOutput": true,
4
+ "explorer.confirmDragAndDrop": false,
5
+ "liveServer.settings.donotShowInfoMsg": true,
6
+ "prettier.eslintIntegration": true,
7
+ "editor.codeActionsOnSave": {
8
+ "source.fixAll.eslint": true
9
+ },
10
+ "eslint.probe": [
11
+ "javascriptreact",
12
+ "typescript",
13
+ "typescriptreact",
14
+ "html",
15
+ "markdown"
16
+ ],
17
+ "color-highlight.matchRgbWithNoFunction": true,
18
+ "color-highlight.matchWords": true,
19
+ "[typescript]": {
20
+ "editor.defaultFormatter": "vscode.typescript-language-features"
21
+ },
22
+ "thunder-client.codeSnippetLanguage": "js-axios",
23
+ "editor.formatOnSave": false,
24
+ "[typescriptreact]": {
25
+ "editor.defaultFormatter": "vscode.typescript-language-features"
26
+ },
27
+ "javascript.updateImportsOnFileMove.enabled": "always",
28
+ "typescript.updateImportsOnFileMove.enabled": "always",
29
+ // "git.autofetch": true,
30
+ "eslint.nodeEnv": "",
31
+ // "prettier.useEditorConfig": false,
32
+ // "prettier.typescriptEnable": [
33
+ // "typescript",
34
+ // "typescriptreact"
35
+ // ],
36
+ // "prettier.tabWidth": 4,
37
+ // "prettier.jsonEnable": [
38
+ // "json"
39
+ // ],
40
+ // "prettier.trailingComma": "all",
41
+ // "prettier.singleQuote": true,
42
+ // "prettier.printWidth": 100,
43
+ // "prettier.bracketSpacing": true,
44
+ // "prettier.singleAttributePerLine": false,
45
+ // "prettier.graphqlEnable": [
46
+ // "graphql"
47
+ // ],
48
+ // "eslint.rules.customizations": [],
49
+ // "eslint.runtime": ""
50
+ }
package/README copy.md ADDED
File without changes
package/index.html ADDED
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Vite App</title>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ <script type="module" src="/src/main.tsx"></script>
12
+ </body>
13
+ </html>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
3
  "private": false,
4
- "version": "0.0.23",
4
+ "version": "0.0.24",
5
5
  "license": "UNLICENSED",
6
6
  "author": "M4L Team",
7
7
  "scripts": {
@@ -57,9 +57,7 @@
57
57
  "vite-plugin-mkcert": "^1.6.4",
58
58
  "vitest": "^0.15.2"
59
59
  },
60
- "files": [
61
- "dist"
62
- ],
60
+
63
61
  "main": "./dist/index.js",
64
62
  "module": "./dist/index.js",
65
63
  "type": "module",
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "m4l_core",
3
+ "private": false,
4
+ "version": "1.0.2",
5
+ "license": "UNLICENSED",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview",
10
+ "lint": "npx eslint src",
11
+ "lint:fix": "npm run lint -- --fix",
12
+ "prettier": "npx prettier src --check",
13
+ "prettier:fix": "npm run prettier -- --write",
14
+ "format": "npm run prettier:fix && npm run lint:fix",
15
+ "prepack": "json -f package.json -I -e \"delete this.devDependencies; delete this.dependencies\""
16
+ },
17
+ "dependencies": {
18
+ "@emotion/react": "^11.9.0",
19
+ "@emotion/styled": "^11.8.1",
20
+ "@mui/material": "^5.8.2",
21
+ "history": "^5.3.0",
22
+ "nprogress": "^0.2.0",
23
+ "react": "^17.0.0 || 18.x",
24
+ "react-dom": "^18.0.0",
25
+ "react-router-dom": "6.3.0",
26
+ "react-toastify": "^9.0.3",
27
+ "snakecase-keys": "^5.4.2"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^17.0.40",
31
+ "@types/nprogress": "^0.2.0",
32
+ "@types/react": "^18.0.0",
33
+ "@types/react-dom": "^18.0.0",
34
+ "@typescript-eslint/eslint-plugin": "^5.27.1",
35
+ "@typescript-eslint/parser": "^5.27.1",
36
+ "@vitejs/plugin-react": "^1.3.0",
37
+ "eslint": "^8.17.0",
38
+ "eslint-config-prettier": "^8.5.0",
39
+ "eslint-import-resolver-alias": "^1.1.2",
40
+ "eslint-plugin-import": "^2.26.0",
41
+ "eslint-plugin-jsx-a11y": "^6.5.1",
42
+ "eslint-plugin-prettier": "^4.0.0",
43
+ "eslint-plugin-react": "^7.30.0",
44
+ "eslint-plugin-react-hooks": "^4.5.0",
45
+ "eslint-plugin-unused-imports": "^2.0.0",
46
+ "json": "^11.0.0",
47
+ "prettier": "^2.6.2",
48
+ "rollup-plugin-terser": "^7.0.2",
49
+ "typescript": "^4.6.3",
50
+ "vite": "^2.9.9",
51
+ "vite-plugin-dts": "^1.2.0",
52
+ "vite-plugin-mkcert": "^1.6.4"
53
+ },
54
+ "peerDependencies": {
55
+ "@emotion/react": "^11.9.0",
56
+ "@emotion/styled": "^11.8.1",
57
+ "@mui/material": "^5.8.2",
58
+ "react": "^17.0.0 || 18.x",
59
+ "react-dom": "^18.0.0",
60
+ "react-router-dom": "6.3.0",
61
+ "react-toastify": "^9.0.3"
62
+ },
63
+ "files": [
64
+ "dist"
65
+ ],
66
+ "main": "./dist/m4l_core.umd.js",
67
+ "module": "./dist/m4l_core.es.js",
68
+ "types": "./dist/index.d.ts",
69
+ "exports": {
70
+ ".": {
71
+ "import": "./dist/m4l_core.es.js",
72
+ "require": "./dist/m4l_core.umd.js"
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,37 @@
1
+ //react
2
+ import { createContext, useState } from 'react';
3
+ // mui
4
+ // hooks
5
+ // utils
6
+ // config
7
+ // @type
8
+ import { EnvironmentContextType, EnvironmentProviderProps } from './types';
9
+
10
+ // ----------------------------------------------------------------------
11
+
12
+ const initialValue: EnvironmentContextType = {
13
+ isLocalhost: true,
14
+ host: '',
15
+ domain_token: '',
16
+ host_api_local: '',
17
+ host_api_remote: '',
18
+ host_static_assets: '',
19
+ environment: '',
20
+ };
21
+
22
+ const EnvironmentContext = createContext<EnvironmentContextType>(initialValue);
23
+
24
+ function EnvironmentProvider(props: EnvironmentProviderProps) {
25
+ const { children, ...other } = props;
26
+
27
+ const [finalEnvironment] = useState<EnvironmentContextType>(other);
28
+
29
+ // console.log('Por aca', finalEnvironment);
30
+ return (
31
+ <EnvironmentContext.Provider value={finalEnvironment}>
32
+ {children}
33
+ </EnvironmentContext.Provider>
34
+ );
35
+ }
36
+
37
+ export { EnvironmentProvider, EnvironmentContext };
@@ -1,6 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { EnvironmentType } from '../../types';
3
+
3
4
  export interface EnvironmentProviderProps extends EnvironmentType {
4
5
  children: ReactNode;
5
6
  }
6
- export declare type EnvironmentContextType = EnvironmentType;
7
+
8
+ export type EnvironmentContextType = EnvironmentType;
@@ -0,0 +1,50 @@
1
+ import { createContext, useCallback, useState } from 'react';
2
+ import { voidFunction } from '../../utils/voidFunction';
3
+
4
+ // mui
5
+ // hooks
6
+ // utils
7
+ // config
8
+ // @type
9
+ import { FlagsContextProps, Flag, FlagsProviderProps } from './types';
10
+
11
+ // ----------------------------------------------------------------------
12
+
13
+ const initialState: FlagsContextProps = {
14
+ flags: [],
15
+ clearFlags: voidFunction,
16
+ addFlag: voidFunction,
17
+ };
18
+
19
+ const FlagsContext = createContext<FlagsContextProps>(initialState);
20
+
21
+ function FlagsProvider({ children }: FlagsProviderProps) {
22
+ const [flags, setFlags] = useState<Array<Flag>>([]);
23
+
24
+ const clearFlags = useCallback(() => {
25
+ setFlags([]);
26
+ }, []);
27
+
28
+ const addFlag = useCallback((newFlag: Flag) => {
29
+ setFlags(oldFlags => {
30
+ if (oldFlags.findIndex(f => f === newFlag) < 0) {
31
+ return [...oldFlags, newFlag];
32
+ }
33
+ return [...oldFlags];
34
+ });
35
+ }, []);
36
+
37
+ return (
38
+ <FlagsContext.Provider
39
+ value={{
40
+ flags,
41
+ addFlag,
42
+ clearFlags,
43
+ }}
44
+ >
45
+ {children}
46
+ </FlagsContext.Provider>
47
+ );
48
+ }
49
+
50
+ export { FlagsProvider, FlagsContext };
@@ -1,8 +1,14 @@
1
1
  import { ReactNode } from 'react';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
2
4
  export interface FlagsProviderProps {
3
5
  children: ReactNode;
4
6
  }
5
- export declare type Flag = string;
7
+
8
+ export type Flag = string;
9
+
10
+ // Interface para almacenar el estado del contexto
11
+ // Interface para indicar las propiedas y metodos que comparte el contexto
6
12
  export interface FlagsContextProps {
7
13
  flags: Array<Flag>;
8
14
  clearFlags: () => void;
@@ -0,0 +1,34 @@
1
+ import { createContext, useState } from 'react';
2
+ import { HostToolsType } from '../../types';
3
+ import { voidFunction } from '../../utils/voidFunction';
4
+
5
+ // mui
6
+
7
+ // hooks
8
+ // utils
9
+ // config
10
+ // @type
11
+ import type { HostToolsContextType, HostToolsProviderProps } from './types';
12
+
13
+ // ----------------------------------------------------------------------
14
+
15
+ const initialValue: HostToolsContextType = {
16
+ toast: () => 0,
17
+ startProgress: voidFunction,
18
+ stopProgress: voidFunction,
19
+ events_add_listener: voidFunction,
20
+ events_remove_listener: voidFunction,
21
+ events_emit: voidFunction,
22
+ };
23
+
24
+ const HostToolsContext = createContext<HostToolsContextType>(initialValue);
25
+
26
+ function HostToolsProvider(props: HostToolsProviderProps) {
27
+ const { children, ...hostTools } = props;
28
+
29
+ const [finalTools] = useState<HostToolsType>(hostTools);
30
+
31
+ return <HostToolsContext.Provider value={finalTools}>{children}</HostToolsContext.Provider>;
32
+ }
33
+
34
+ export { HostToolsProvider, HostToolsContext };
@@ -1,6 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { HostToolsType } from '../../types';
3
+
3
4
  export interface HostToolsProviderProps extends HostToolsType {
4
5
  children: ReactNode;
5
6
  }
6
- export declare type HostToolsContextType = HostToolsType;
7
+
8
+ export type HostToolsContextType = HostToolsType;
@@ -0,0 +1,109 @@
1
+ //react
2
+ import { createContext, useCallback, useLayoutEffect, useState } from 'react';
3
+ //m4l
4
+ // mui
5
+ // hooks
6
+ // utils
7
+ // config
8
+ // @type
9
+ import { ModuleDictionaryContextProps, ModuleDictionaryProviderProps } from './types';
10
+
11
+ import { useEnvironment, useFlags, useHostTools, useNetwork } from '../../hooks';
12
+ import { ModuleDictionary } from '../../types/dictionary';
13
+ // ----------------------------------------------------------------------
14
+
15
+ const initialState: ModuleDictionaryContextProps = {
16
+ getLabel: () => '..',
17
+ getModuleLabel: () => 'No dictionary context',
18
+ };
19
+
20
+ const ModuleDictionaryContext = createContext<ModuleDictionaryContextProps>(initialState);
21
+
22
+ function ModuleDictionaryProvider(props: ModuleDictionaryProviderProps) {
23
+ const {
24
+ children,
25
+ componentsDictionary,
26
+ moduleId,
27
+ moduleName = 'module_name',
28
+ currentLang = 'us',
29
+ isAuth = true,
30
+ } = props;
31
+ const { addFlag } = useFlags();
32
+ // Cargar el diccionario
33
+ const [moduleDictionary, setModuleDictionary] = useState<ModuleDictionary | undefined>(
34
+ undefined,
35
+ );
36
+ const { domain_token } = useEnvironment();
37
+ const { startProgress, stopProgress } = useHostTools();
38
+ const { networkOperation } = useNetwork();
39
+
40
+ useLayoutEffect(() => {
41
+ let mounted = true;
42
+ startProgress();
43
+
44
+ networkOperation({
45
+ method: 'GET',
46
+ endPoint: isAuth ? `dictionaries/${moduleId}` : `na/dictionaries/${moduleId}`,
47
+ parms: {
48
+ comps: componentsDictionary,
49
+ ...(isAuth ? {} : { domain_token }),
50
+ },
51
+ // isRemote: false
52
+ })
53
+ .then((response: any) => {
54
+ if (mounted) {
55
+ /// /console.log("useEffect - ModuleProvider - response");
56
+
57
+ setModuleDictionary({
58
+ ...response,
59
+ });
60
+
61
+ addFlag('dictionary_loaded');
62
+ }
63
+ })
64
+ .finally(() => {
65
+ stopProgress();
66
+ });
67
+
68
+ return function cleanUp() {
69
+ mounted = false;
70
+ };
71
+ // eslint-disable-next-line react-hooks/exhaustive-deps
72
+ }, [currentLang]);
73
+
74
+ const getLabel = useCallback(
75
+ (key: string) => {
76
+ if (moduleDictionary === undefined) return 'No dictionary';
77
+ if (key === undefined) return 'No key';
78
+
79
+ const parts = key.split('.');
80
+
81
+ if (parts.length === 2) {
82
+ if (moduleDictionary[parts[0]] && (moduleDictionary as any)[parts[0]][parts[1]]) {
83
+ return (moduleDictionary as any)[parts[0]][parts[1]];
84
+ }
85
+ } else if (parts.length === 1) {
86
+ if (moduleDictionary.data && (moduleDictionary as any).data[key]) {
87
+ return (moduleDictionary as any).data[key];
88
+ }
89
+ }
90
+
91
+ return `No dictionary:${key}`;
92
+ },
93
+ [moduleDictionary],
94
+ );
95
+ const getModuleLabel = useCallback(() => getLabel(moduleName), [moduleName, getLabel]);
96
+ return (
97
+ <ModuleDictionaryContext.Provider
98
+ value={{
99
+ moduleDictionary: moduleDictionary,
100
+ getLabel,
101
+ getModuleLabel,
102
+ }}
103
+ >
104
+ {children}
105
+ </ModuleDictionaryContext.Provider>
106
+ );
107
+ }
108
+
109
+ export { ModuleDictionaryProvider, ModuleDictionaryContext };
@@ -1,13 +1,16 @@
1
1
  import { ReactNode } from 'react';
2
2
  import type { GetLabelType, ModuleDictionary } from 'src/types/dictionary';
3
+
4
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
3
5
  export interface ModuleDictionaryProviderProps {
4
6
  currentLang?: string;
5
7
  isAuth?: boolean;
6
8
  moduleId: number;
7
- moduleName?: string;
9
+ moduleName?: string; //la llave donde reposa el nombre del modulo en el diccionario
8
10
  componentsDictionary: string[];
9
11
  children: ReactNode;
10
12
  }
13
+
11
14
  export interface ModuleDictionaryContextProps {
12
15
  moduleDictionary?: ModuleDictionary;
13
16
  getLabel: GetLabelType;
@@ -0,0 +1,44 @@
1
+ import { createContext, useCallback } from 'react';
2
+
3
+ // mui
4
+ // hooks
5
+ import useEnvironment from '../../hooks/useEnvironment';
6
+ import useHostTools from '../../hooks/useHostTools';
7
+ // utils
8
+ // config
9
+ // @type
10
+ import type { NetworkProps } from '../../types';
11
+ import type { NetworkContextType, NetworkProviderProps } from './types';
12
+
13
+ // ----------------------------------------------------------------------
14
+
15
+ const initialValue: NetworkContextType = {
16
+ networkOperation: () => Promise.resolve(),
17
+ };
18
+
19
+ const NetworkContext = createContext<NetworkContextType>(initialValue);
20
+
21
+ function NetworkProvider(props: NetworkProviderProps) {
22
+ const { children, axiosOperation } = props;
23
+ const environment = useEnvironment();
24
+ const hostTools = useHostTools();
25
+
26
+ const networkOperation = useCallback(
27
+ async (networkProps: NetworkProps) => {
28
+ return axiosOperation(networkProps, environment, hostTools);
29
+ },
30
+ [axiosOperation],
31
+ );
32
+
33
+ return (
34
+ <NetworkContext.Provider
35
+ value={{
36
+ networkOperation,
37
+ }}
38
+ >
39
+ {children}
40
+ </NetworkContext.Provider>
41
+ );
42
+ }
43
+
44
+ export { NetworkProvider, NetworkContext };
@@ -1,11 +1,15 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { AxiosOperation, NetworkProps } from '../../types';
3
- export declare type EventFunListener = (...args: any[]) => void;
3
+
4
+ export type EventFunListener = (...args: any[]) => void;
5
+
4
6
  export interface NetworkType {
5
7
  networkOperation: (props: NetworkProps) => Promise<any>;
6
8
  }
9
+
7
10
  export interface NetworkProviderProps {
8
11
  axiosOperation: AxiosOperation;
9
12
  children: ReactNode;
10
13
  }
11
- export declare type NetworkContextType = NetworkType;
14
+
15
+ export type NetworkContextType = NetworkType;
@@ -3,4 +3,5 @@ export { useHostTools } from './useHostTools';
3
3
  export { useNetwork } from './useNetwork';
4
4
  export { useEnvironment } from './useEnvironment';
5
5
  export { useFlags, useFlagsPresent } from './useFlags';
6
+
6
7
  export { useModuleDictionary } from './useModuleDictionary';