@m4l/core 0.0.0
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/README.md +0 -0
- package/dist/index.d.ts +3 -0
- package/dist/lib/contexts/EnvironmentContext/index.d.ts +5 -0
- package/dist/lib/contexts/EnvironmentContext/types.d.ts +6 -0
- package/dist/lib/contexts/HostToolsContext/index.d.ts +6 -0
- package/dist/lib/contexts/HostToolsContext/types.d.ts +6 -0
- package/dist/lib/contexts/NetworkContext/index.d.ts +5 -0
- package/dist/lib/contexts/NetworkContext/types.d.ts +11 -0
- package/dist/lib/contexts/index.d.ts +3 -0
- package/dist/lib/hooks/index.d.ts +4 -0
- package/dist/lib/hooks/useEnvironment/index.d.ts +2 -0
- package/dist/lib/hooks/useHostTools/index.d.ts +2 -0
- package/dist/lib/hooks/useLocalStorage/useLocalStorage.d.ts +1 -0
- package/dist/lib/hooks/useNetwork/index.d.ts +2 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/types/index.d.ts +39 -0
- package/dist/lib/utils/getLocalStorage.d.ts +1 -0
- package/dist/lib/utils/getPropertyByString.d.ts +1 -0
- package/dist/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/setLocalStorage.d.ts +1 -0
- package/dist/lib/utils/voidFunction.d.ts +1 -0
- package/dist/m4l_core.es.js +114 -0
- package/dist/manifest.json +7 -0
- package/dist/vite-env.d.ts +3 -0
- package/package.json +85 -0
package/README.md
ADDED
|
File without changes
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { EnvironmentProviderProps } from './types';
|
|
3
|
+
declare const EnvironmentContext: import("react").Context<import("../..").EnvironmentType>;
|
|
4
|
+
declare function EnvironmentProvider(props: EnvironmentProviderProps): JSX.Element;
|
|
5
|
+
export { EnvironmentProvider, EnvironmentContext };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { HostToolsType } from '../../types';
|
|
3
|
+
import { 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,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { 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 @@
|
|
|
1
|
+
export declare function useLocalStorage<ValueType>(key: string, initialValue: ValueType): any[];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Method } from 'axios';
|
|
2
|
+
import type { Id, ToastContent, ToastOptions } from 'react-toastify';
|
|
3
|
+
import type { BrowserHistory } from 'history';
|
|
4
|
+
export declare type Maybe<T> = T | undefined | null;
|
|
5
|
+
export declare interface EnvironmentType {
|
|
6
|
+
isLocalhost: boolean;
|
|
7
|
+
host: string;
|
|
8
|
+
domain_token: string;
|
|
9
|
+
host_api_remote: string;
|
|
10
|
+
host_api_local: string;
|
|
11
|
+
host_static_assets: string;
|
|
12
|
+
environment: string;
|
|
13
|
+
}
|
|
14
|
+
export declare type NetworkProps = {
|
|
15
|
+
method: Method;
|
|
16
|
+
endPoint: string;
|
|
17
|
+
timeout?: number;
|
|
18
|
+
parms?: object;
|
|
19
|
+
data?: object;
|
|
20
|
+
checkUnAuthorized?: boolean;
|
|
21
|
+
isRemote?: boolean;
|
|
22
|
+
showSuccesInfo?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare type ToastFunction = (content: ToastContent, options?: ToastOptions) => Id;
|
|
25
|
+
export declare type EventFunListener = (...args: any[]) => void;
|
|
26
|
+
export declare interface HostToolsType {
|
|
27
|
+
history?: BrowserHistory;
|
|
28
|
+
toast: ToastFunction;
|
|
29
|
+
startProgress: VoidFunction;
|
|
30
|
+
stopProgress: VoidFunction;
|
|
31
|
+
events_add_listener: (eventName: string, handler: EventFunListener) => void;
|
|
32
|
+
events_remove_listener: (eventName: string, handler: Maybe<EventFunListener>) => void;
|
|
33
|
+
events_emit: (eventName: string, arg: any) => void;
|
|
34
|
+
}
|
|
35
|
+
export declare enum EmitEvents {
|
|
36
|
+
EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED = "netsevice_unauthorized",
|
|
37
|
+
EMMIT_EVENT_HOST_THEME_CHANGE = "host_theme_change"
|
|
38
|
+
}
|
|
39
|
+
export declare type AxiosOperation = (props: NetworkProps, enviroment: EnvironmentType, hostTools: HostToolsType) => Promise<any>;
|
|
@@ -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 @@
|
|
|
1
|
+
export declare function setLocalStorage<ValueType>(key: string, value: ValueType): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function voidFunction(): void;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
import { createContext, useContext, useState } from "react";
|
|
18
|
+
import "react/jsx-runtime";
|
|
19
|
+
const initialValue$2 = {
|
|
20
|
+
isLocalhost: true,
|
|
21
|
+
host: "",
|
|
22
|
+
domain_token: "",
|
|
23
|
+
host_api_local: "",
|
|
24
|
+
host_api_remote: "",
|
|
25
|
+
host_static_assets: "",
|
|
26
|
+
environment: ""
|
|
27
|
+
};
|
|
28
|
+
const EnvironmentContext = createContext(initialValue$2);
|
|
29
|
+
function voidFunction() {
|
|
30
|
+
}
|
|
31
|
+
function getPropertyByString(object, propString) {
|
|
32
|
+
let value = object;
|
|
33
|
+
const props = propString.split(".");
|
|
34
|
+
for (let index = 0; index < props.length; index += 1) {
|
|
35
|
+
if (props[index] === void 0)
|
|
36
|
+
break;
|
|
37
|
+
value = value[props[index]];
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
function getLocalStorage(key, initialValue2) {
|
|
42
|
+
try {
|
|
43
|
+
const item = window.localStorage.getItem(key);
|
|
44
|
+
return item !== null ? JSON.parse(item) : initialValue2;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return initialValue2;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function setLocalStorage(key, value) {
|
|
50
|
+
try {
|
|
51
|
+
const item = window.localStorage.getItem(key);
|
|
52
|
+
let newValue = item !== null ? JSON.parse(item) : {};
|
|
53
|
+
newValue = __spreadValues(__spreadValues({}, newValue), value);
|
|
54
|
+
window.localStorage.setItem(key, JSON.stringify(newValue));
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.error(e);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const initialValue$1 = {
|
|
60
|
+
toast: () => 0,
|
|
61
|
+
startProgress: voidFunction,
|
|
62
|
+
stopProgress: voidFunction,
|
|
63
|
+
events_add_listener: voidFunction,
|
|
64
|
+
events_remove_listener: voidFunction,
|
|
65
|
+
events_emit: voidFunction
|
|
66
|
+
};
|
|
67
|
+
const HostToolsContext = createContext(initialValue$1);
|
|
68
|
+
const useEnvironment = () => {
|
|
69
|
+
const context = useContext(EnvironmentContext);
|
|
70
|
+
if (!context)
|
|
71
|
+
throw new Error("useEnvironment context must be use inside EnvironmentContext");
|
|
72
|
+
return context;
|
|
73
|
+
};
|
|
74
|
+
const useHostTools = () => {
|
|
75
|
+
const context = useContext(HostToolsContext);
|
|
76
|
+
if (!context)
|
|
77
|
+
throw new Error("useHostTools context must be use inside HostToolsContext");
|
|
78
|
+
return context;
|
|
79
|
+
};
|
|
80
|
+
const initialValue = {
|
|
81
|
+
networkOperation: () => Promise.resolve()
|
|
82
|
+
};
|
|
83
|
+
const NetworkContext = createContext(initialValue);
|
|
84
|
+
function useLocalStorage(key, initialValue2) {
|
|
85
|
+
const [value, setValue] = useState(() => {
|
|
86
|
+
try {
|
|
87
|
+
const item = window.localStorage.getItem(key);
|
|
88
|
+
return item !== null ? JSON.parse(item) : initialValue2;
|
|
89
|
+
} catch (e) {
|
|
90
|
+
return initialValue2;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const setValueInLocalStorage = (newValue) => {
|
|
94
|
+
try {
|
|
95
|
+
window.localStorage.setItem(key, JSON.stringify(newValue));
|
|
96
|
+
setValue(newValue);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error(e);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return [value, setValueInLocalStorage];
|
|
102
|
+
}
|
|
103
|
+
const useNetwork = () => {
|
|
104
|
+
const context = useContext(NetworkContext);
|
|
105
|
+
if (!context)
|
|
106
|
+
throw new Error("useNetwork context must be use inside NetworkContext");
|
|
107
|
+
return context;
|
|
108
|
+
};
|
|
109
|
+
function fn(arr) {
|
|
110
|
+
const arr2 = [1, ...arr];
|
|
111
|
+
const a = __spreadValues({}, { A: 1 });
|
|
112
|
+
console.log(a, arr2);
|
|
113
|
+
}
|
|
114
|
+
export { EnvironmentContext, HostToolsContext, NetworkContext, fn, getLocalStorage, getPropertyByString, setLocalStorage, useEnvironment, useHostTools, useLocalStorage, useNetwork, voidFunction };
|
package/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@m4l/core",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"author": "M4L Team",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "vite",
|
|
9
|
+
"build": "tsc && vite build",
|
|
10
|
+
"preview": "vite preview",
|
|
11
|
+
"lint": "npx eslint src",
|
|
12
|
+
"lint:fix": "npm run lint -- --fix",
|
|
13
|
+
"prettier": "npx prettier src --check",
|
|
14
|
+
"prettier:fix": "npm run prettier -- --write",
|
|
15
|
+
"format": "npm run prettier:fix && npm run lint:fix",
|
|
16
|
+
"test": "vitest",
|
|
17
|
+
"coverage": "vitest run --coverage",
|
|
18
|
+
"Oldprepack": "json -f package.json -I -e \"delete this.devDependencies; delete this.dependencies\""
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
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-toastify": "^9.0.3",
|
|
26
|
+
"snakecase-keys": "^5.4.2"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@testing-library/jest-dom": "^5.16.4",
|
|
30
|
+
"@testing-library/react": "^13.3.0",
|
|
31
|
+
"@testing-library/user-event": "^14.2.1",
|
|
32
|
+
"@types/node": "^17.0.40",
|
|
33
|
+
"@types/nprogress": "^0.2.0",
|
|
34
|
+
"@types/numeral": "^2.0.2",
|
|
35
|
+
"@types/react": "^18.0.0",
|
|
36
|
+
"@types/react-dom": "^18.0.0",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^5.27.1",
|
|
38
|
+
"@typescript-eslint/parser": "^5.27.1",
|
|
39
|
+
"@vitejs/plugin-react": "^1.3.0",
|
|
40
|
+
"c8": "^7.11.3",
|
|
41
|
+
"eslint": "^8.17.0",
|
|
42
|
+
"eslint-config-prettier": "^8.5.0",
|
|
43
|
+
"eslint-import-resolver-alias": "^1.1.2",
|
|
44
|
+
"eslint-plugin-import": "^2.26.0",
|
|
45
|
+
"eslint-plugin-jsx-a11y": "^6.5.1",
|
|
46
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
47
|
+
"eslint-plugin-react": "^7.30.0",
|
|
48
|
+
"eslint-plugin-react-hooks": "^4.5.0",
|
|
49
|
+
"eslint-plugin-unused-imports": "^2.0.0",
|
|
50
|
+
"jsdom": "^20.0.0",
|
|
51
|
+
"json": "^11.0.0",
|
|
52
|
+
"prettier": "^2.6.2",
|
|
53
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
54
|
+
"typescript": "^4.6.3",
|
|
55
|
+
"vite": "^2.9.9",
|
|
56
|
+
"vite-plugin-dts": "^1.2.0",
|
|
57
|
+
"vite-plugin-mkcert": "^1.6.4",
|
|
58
|
+
"vitest": "^0.15.2"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"react": "^17.0.0 || 18.x",
|
|
62
|
+
"react-dom": "^18.0.0",
|
|
63
|
+
"react-toastify": "^9.0.3"
|
|
64
|
+
},
|
|
65
|
+
"files": [
|
|
66
|
+
"dist"
|
|
67
|
+
],
|
|
68
|
+
"main": "./dist/m4l_core.es.js",
|
|
69
|
+
"module": "./dist/m4l_core.es.js",
|
|
70
|
+
"type": "module",
|
|
71
|
+
"types": "./dist/index.d.ts",
|
|
72
|
+
"exports": {
|
|
73
|
+
".": {
|
|
74
|
+
"import": "./dist/m4l_core.es.js",
|
|
75
|
+
"require": "./dist/m4l_core.umd.js"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"sideEffects": false,
|
|
79
|
+
"publishConfig": {
|
|
80
|
+
"access": "public"
|
|
81
|
+
},
|
|
82
|
+
"engines": {
|
|
83
|
+
"node": ">=12.0.0"
|
|
84
|
+
}
|
|
85
|
+
}
|