@m4l/core 0.0.24 → 0.0.27

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 (86) hide show
  1. package/dist/contexts/EnvironmentContext/index.d.ts +5 -0
  2. package/dist/contexts/EnvironmentContext/index.js +24 -0
  3. package/{src/contexts/EnvironmentContext/types.ts → dist/contexts/EnvironmentContext/types.d.ts} +1 -3
  4. package/dist/contexts/FlagsContext/index.d.ts +5 -0
  5. package/dist/contexts/FlagsContext/index.js +34 -0
  6. package/{src/contexts/FlagsContext/types.ts → dist/contexts/FlagsContext/types.d.ts} +1 -7
  7. package/dist/contexts/HostToolsContext/index.d.ts +6 -0
  8. package/dist/contexts/HostToolsContext/index.js +24 -0
  9. package/{src/contexts/HostToolsContext/types.ts → dist/contexts/HostToolsContext/types.d.ts} +1 -3
  10. package/dist/contexts/ModuleDictionaryContext/index.d.ts +5 -0
  11. package/dist/contexts/ModuleDictionaryContext/index.js +88 -0
  12. package/{src/contexts/ModuleDictionaryContext/types.ts → dist/contexts/ModuleDictionaryContext/types.d.ts} +1 -4
  13. package/dist/contexts/NetworkContext/index.d.ts +5 -0
  14. package/dist/contexts/NetworkContext/index.js +26 -0
  15. package/{src/contexts/NetworkContext/types.ts → dist/contexts/NetworkContext/types.d.ts} +2 -6
  16. package/{src/contexts/index.ts → dist/contexts/index.d.ts} +0 -0
  17. package/dist/external/axios.js +1299 -0
  18. package/dist/external/snakecase-keys.js +18 -0
  19. package/{src/hooks/index.ts → dist/hooks/index.d.ts} +6 -4
  20. package/dist/hooks/useEnvironment/index.d.ts +2 -0
  21. package/dist/hooks/useEnvironment/index.js +9 -0
  22. package/dist/hooks/useFlags/index.d.ts +3 -0
  23. package/dist/hooks/useFlags/index.js +23 -0
  24. package/dist/hooks/useHostTools/index.d.ts +2 -0
  25. package/dist/hooks/useHostTools/index.js +9 -0
  26. package/dist/hooks/useLocalStorage/index.d.ts +1 -0
  27. package/dist/hooks/useLocalStorage/index.js +21 -0
  28. package/dist/hooks/useModuleDictionary/index.d.ts +1 -0
  29. package/dist/hooks/useModuleDictionary/index.js +9 -0
  30. package/dist/hooks/useNetwork/index.d.ts +2 -0
  31. package/dist/hooks/useNetwork/index.js +9 -0
  32. package/dist/hooks/usePaginate/index.d.ts +15 -0
  33. package/dist/hooks/usePaginate/index.js +72 -0
  34. package/dist/hooks/usePaginate/types.d.ts +6 -0
  35. package/dist/index.d.ts +6 -0
  36. package/dist/index.js +20 -0
  37. package/dist/node_modules.js +100 -0
  38. package/{src/types/dictionary.ts → dist/types/dictionary.d.ts} +1 -5
  39. package/{src/types/index.ts → dist/types/index.d.ts} +5 -20
  40. package/dist/types/index.js +6 -0
  41. package/dist/utils/axiosOperation/index.d.ts +2 -0
  42. package/{src/utils/axiosOperation/types.ts → dist/utils/axiosOperation/types.d.ts} +1 -1
  43. package/dist/utils/getLocalStorage.d.ts +1 -0
  44. package/dist/utils/getPropertyByString.d.ts +1 -0
  45. package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
  46. package/dist/utils/index.js +33 -0
  47. package/dist/utils/setLocalStorage.d.ts +1 -0
  48. package/dist/utils/voidFunction.d.ts +1 -0
  49. package/dist/vendor.js +32 -0
  50. package/{src → dist}/vite-env.d.ts +0 -0
  51. package/package.json +4 -2
  52. package/.eslintignore +0 -2
  53. package/.eslintrc.cjs +0 -109
  54. package/.prettierignore +0 -2
  55. package/.prettierrc.json +0 -26
  56. package/.vscode/settings.json +0 -50
  57. package/README copy.md +0 -0
  58. package/index.html +0 -13
  59. package/package_with_dependicies.json +0 -75
  60. package/src/contexts/EnvironmentContext/index.tsx +0 -37
  61. package/src/contexts/FlagsContext/index.tsx +0 -50
  62. package/src/contexts/HostToolsContext/index.tsx +0 -34
  63. package/src/contexts/ModuleDictionaryContext/index.tsx +0 -109
  64. package/src/contexts/NetworkContext/index.tsx +0 -44
  65. package/src/hooks/useEnvironment/index.test.tsx +0 -36
  66. package/src/hooks/useEnvironment/index.ts +0 -13
  67. package/src/hooks/useFlags/index.ts +0 -33
  68. package/src/hooks/useHostTools/index.ts +0 -13
  69. package/src/hooks/useLocalStorage/index.ts +0 -23
  70. package/src/hooks/useModuleDictionary/index.ts +0 -11
  71. package/src/hooks/useNetwork/index.ts +0 -13
  72. package/src/index.ts +0 -43
  73. package/src/indexFlags.ts +0 -1
  74. package/src/isolation/App.tsx +0 -24
  75. package/src/main.tsx +0 -10
  76. package/src/prueba.d1.t1 +0 -10
  77. package/src/test/setup.ts +0 -1
  78. package/src/test/utils.tsx +0 -20
  79. package/src/utils/axiosOperation/index.ts +0 -140
  80. package/src/utils/getLocalStorage.ts +0 -8
  81. package/src/utils/getPropertyByString.ts +0 -10
  82. package/src/utils/setLocalStorage.ts +0 -12
  83. package/src/utils/voidFunction.ts +0 -2
  84. package/tsconfig.json +0 -37
  85. package/tsconfig.node.json +0 -10
  86. package/vite.config.ts +0 -178
package/.eslintrc.cjs DELETED
@@ -1,109 +0,0 @@
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
- // }
package/.prettierignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules
2
- yarn.lock
package/.prettierrc.json DELETED
@@ -1,26 +0,0 @@
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
-
@@ -1,50 +0,0 @@
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 DELETED
File without changes
package/index.html DELETED
@@ -1,13 +0,0 @@
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>
@@ -1,75 +0,0 @@
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
- }
@@ -1,37 +0,0 @@
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,50 +0,0 @@
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,34 +0,0 @@
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,109 +0,0 @@
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,44 +0,0 @@
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,36 +0,0 @@
1
- //import { render, screen } from '../../../test/utils';
2
- import { render, screen } from '../../test/utils';
3
- import { it } from 'vitest';
4
- import { EnvironmentProvider } from '../../contexts/EnvironmentContext';
5
- import useEnvironment from '.';
6
-
7
- it('useEnvironment tenga acceso a las variables del contexto', () => {
8
- const obValue = {
9
- isLocalhost: true,
10
- host: 'h1',
11
- domain_token: '1',
12
- host_api_local: '2',
13
- host_api_remote: '3',
14
- host_static_assets: '4',
15
- environment: '5',
16
- };
17
-
18
- const stringValue = JSON.stringify(obValue);
19
-
20
- const Component = () => {
21
- const value = useEnvironment();
22
- return <div data-testid="useDivHostId">{JSON.stringify(value)}</div>;
23
- };
24
-
25
- // const { container } =
26
- render(
27
- <EnvironmentProvider {...obValue}>
28
- <Component />
29
- </EnvironmentProvider>,
30
- );
31
-
32
- // container.querySelector('#useDivHostId');
33
- //console.log('Q trajo', window);
34
-
35
- expect(screen.getByTestId('useDivHostId').textContent).toBe(stringValue);
36
- });
@@ -1,13 +0,0 @@
1
- import { useContext } from 'react';
2
- import { EnvironmentContext } from '../../contexts/EnvironmentContext';
3
-
4
- // ----------------------------------------------------------------------
5
- export const useEnvironment = () => {
6
- const context = useContext(EnvironmentContext);
7
-
8
- if (!context) throw new Error('useEnvironment context must be use inside EnvironmentContext');
9
-
10
- return context;
11
- };
12
-
13
- export default useEnvironment;
@@ -1,33 +0,0 @@
1
- import { useContext, useEffect, useState } from 'react';
2
- import { FlagsContext } from '../../contexts/FlagsContext';
3
- import type { Flag, FlagsContextProps } from '../../contexts/FlagsContext/types';
4
-
5
- // ----------------------------------------------------------------------
6
- export const useFlags = (): FlagsContextProps => {
7
- const context = useContext(FlagsContext);
8
-
9
- if (!context) throw new Error('useFlags context must be use inside FlagsProvider');
10
-
11
- return context;
12
- };
13
-
14
- function isFlagsPresent(compareFlags: Array<Flag>, flags: Array<Flag>) {
15
- const filterFlags = compareFlags.filter(
16
- findFlag => flags.findIndex(sFlag => sFlag === findFlag) !== -1,
17
- );
18
-
19
- return filterFlags.length === compareFlags.length;
20
- }
21
- export const useFlagsPresent = (compareFlags: Array<Flag>): boolean => {
22
- const context = useFlags();
23
-
24
- const [isPresent, setIsPresent] = useState(isFlagsPresent(compareFlags, context.flags));
25
-
26
- useEffect(() => {
27
- if (isFlagsPresent(compareFlags, context.flags)) {
28
- setIsPresent(true);
29
- }
30
- }, [context.flags, compareFlags]);
31
-
32
- return isPresent;
33
- };
@@ -1,13 +0,0 @@
1
- import { useContext } from 'react';
2
- import { HostToolsContext } from '../../contexts/HostToolsContext';
3
-
4
- // ----------------------------------------------------------------------
5
- export const useHostTools = () => {
6
- const context = useContext(HostToolsContext);
7
-
8
- if (!context) throw new Error('useHostTools context must be use inside HostToolsContext');
9
-
10
- return context;
11
- };
12
-
13
- export default useHostTools;