@m4l/core 0.1.16 → 0.1.18

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { DomainProviderProps, Domain } from './types';
3
- declare const DomainContext: import("react").Context<Domain>;
3
+ declare const DomainContext: import("react").Context<Domain | null>;
4
4
  declare function DomainProvider(props: DomainProviderProps): JSX.Element;
5
5
  export { DomainProvider, DomainContext };
@@ -1,13 +1,9 @@
1
1
  import { createContext, useState, useEffect } from "react";
2
- import { useEnvironment, useFlags, useNetwork } from "@m4l/core";
2
+ import { u as useFlags } from "../../hooks/useFlags/index.js";
3
+ import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
4
+ import { u as useNetwork } from "../../hooks/useNetwork/index.js";
3
5
  import { jsx } from "react/jsx-runtime";
4
- const initialState = {
5
- company_logo_small_url: "",
6
- company_logo_normal_url: "",
7
- name: ""
8
- };
9
- console.log("DomainContext createContext");
10
- const DomainContext = createContext(initialState);
6
+ const DomainContext = createContext(null);
11
7
  function DomainProvider(props) {
12
8
  const {
13
9
  children
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { EnvironmentProviderProps } from './types';
3
- declare const EnvironmentContext: import("react").Context<import("../..").EnvironmentType>;
3
+ declare const EnvironmentContext: import("react").Context<import("../..").EnvironmentType | null>;
4
4
  declare function EnvironmentProvider(props: EnvironmentProviderProps): JSX.Element;
5
5
  export { EnvironmentProvider, EnvironmentContext };
@@ -1,23 +1,6 @@
1
1
  import { createContext, useState } from "react";
2
2
  import { jsx } from "react/jsx-runtime";
3
- const initialValue = {
4
- isLocalhost: true,
5
- host: "",
6
- domain_token: "",
7
- host_api_local: "",
8
- host_api_remote: "",
9
- host_static_assets: "",
10
- environment_assets: "",
11
- dfnsFormat: {
12
- date_format: "yyyy-MM-dd",
13
- date_mask: "____-__-__",
14
- time_format: "HH:mm:ss",
15
- time_mask: "__:__:__",
16
- datetime_format: "yyyy-MM-dd HH:mm:ss",
17
- datetime_mask: "____-__-__ __:__:__"
18
- }
19
- };
20
- const EnvironmentContext = createContext(initialValue);
3
+ const EnvironmentContext = createContext(null);
21
4
  function EnvironmentProvider(props) {
22
5
  const {
23
6
  children,
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { FlagsContextProps, FlagsProviderProps } from './types';
3
- declare const FlagsContext: import("react").Context<FlagsContextProps>;
3
+ declare const FlagsContext: import("react").Context<FlagsContextProps | null>;
4
4
  declare function FlagsProvider({ children }: FlagsProviderProps): JSX.Element;
5
5
  export { FlagsProvider, FlagsContext };
@@ -1,13 +1,6 @@
1
1
  import { createContext, useState, useCallback } from "react";
2
- import { v as voidFunction } from "../../utils/index.js";
3
2
  import { jsx } from "react/jsx-runtime";
4
- const initialState = {
5
- flags: [],
6
- clearFlags: voidFunction,
7
- addFlag: voidFunction
8
- };
9
- console.log("FlagsContex createContext");
10
- const FlagsContext = createContext(initialState);
3
+ const FlagsContext = createContext(null);
11
4
  function FlagsProvider({
12
5
  children
13
6
  }) {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { HostToolsType } from '../../types';
3
3
  import type { HostToolsProviderProps } from './types';
4
- declare const HostToolsContext: import("react").Context<HostToolsType>;
4
+ declare const HostToolsContext: import("react").Context<HostToolsType | null>;
5
5
  declare function HostToolsProvider(props: HostToolsProviderProps): JSX.Element;
6
6
  export { HostToolsProvider, HostToolsContext };
@@ -1,16 +1,6 @@
1
1
  import { createContext, useState } from "react";
2
- import { v as voidFunction } from "../../utils/index.js";
3
2
  import { jsx } from "react/jsx-runtime";
4
- const initialValue = {
5
- toast: () => 0,
6
- startProgress: voidFunction,
7
- stopProgress: voidFunction,
8
- formatDate: () => "",
9
- events_add_listener: voidFunction,
10
- events_remove_listener: voidFunction,
11
- events_emit: voidFunction
12
- };
13
- const HostToolsContext = createContext(initialValue);
3
+ const HostToolsContext = createContext(null);
14
4
  function HostToolsProvider(props) {
15
5
  const {
16
6
  children,
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { ModuleDictionaryContextProps, ModuleDictionaryProviderProps } from './types';
3
- declare const ModuleDictionaryContext: import("react").Context<ModuleDictionaryContextProps>;
3
+ declare const ModuleDictionaryContext: import("react").Context<ModuleDictionaryContextProps | null>;
4
4
  declare function ModuleDictionaryProvider(props: ModuleDictionaryProviderProps): JSX.Element;
5
5
  export { ModuleDictionaryProvider, ModuleDictionaryContext };
@@ -7,12 +7,7 @@ import "../ModulePrivilegesContext/index.js";
7
7
  import "../ModuleSkeletonContext/index.js";
8
8
  import { u as useNetwork } from "../../hooks/useNetwork/index.js";
9
9
  import { jsx } from "react/jsx-runtime";
10
- const initialState = {
11
- getLabel: () => "..",
12
- getModuleLabel: () => "No dictionary context"
13
- };
14
- console.log("ModuleDictionaryContext createContext");
15
- const ModuleDictionaryContext = createContext(initialState);
10
+ const ModuleDictionaryContext = createContext(null);
16
11
  function ModuleDictionaryProvider(props) {
17
12
  const {
18
13
  children,
@@ -51,7 +46,6 @@ function ModuleDictionaryProvider(props) {
51
46
  }
52
47
  }).then((response) => {
53
48
  if (mounted) {
54
- console.log("useEffect - ModuleProvider - response");
55
49
  setModuleDictionary({
56
50
  ...response
57
51
  });
@@ -67,19 +61,23 @@ function ModuleDictionaryProvider(props) {
67
61
  const getLabel = useCallback((key) => {
68
62
  if (moduleDictionary === void 0)
69
63
  return "";
70
- if (key === void 0)
64
+ if (key === "")
71
65
  return "No key";
66
+ let ret = void 0;
72
67
  const parts = key.split(".");
73
- if (parts.length === 2) {
74
- if (moduleDictionary[parts[0]] && moduleDictionary[parts[0]][parts[1]]) {
75
- return moduleDictionary[parts[0]][parts[1]];
68
+ try {
69
+ if (parts.length === 1) {
70
+ ret = moduleDictionary.data[key];
76
71
  }
77
- } else if (parts.length === 1) {
78
- if (moduleDictionary.data && moduleDictionary.data[key]) {
79
- return moduleDictionary.data[key];
72
+ if (parts.length === 2) {
73
+ ret = moduleDictionary[parts[0]][parts[1]];
80
74
  }
75
+ } catch (error) {
81
76
  }
82
- return `No dictionary:${key}`;
77
+ if (ret) {
78
+ return ret;
79
+ }
80
+ return `N_D:[${key}]`;
83
81
  }, [moduleDictionary]);
84
82
  const getModuleLabel = useCallback(() => getLabel(moduleName), [moduleName, getLabel]);
85
83
  return /* @__PURE__ */ jsx(ModuleDictionaryContext.Provider, {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { ModulePrivilegesContextProps, ModulePrivilegesProviderProps } from './types';
3
- declare const ModulePrivilegesContext: import("react").Context<ModulePrivilegesContextProps>;
3
+ declare const ModulePrivilegesContext: import("react").Context<ModulePrivilegesContextProps | null>;
4
4
  declare function ModulePrivilegesProvider(props: ModulePrivilegesProviderProps): JSX.Element;
5
5
  export { ModulePrivilegesProvider, ModulePrivilegesContext };
@@ -7,11 +7,7 @@ import "../ModuleDictionaryContext/index.js";
7
7
  import "../ModuleSkeletonContext/index.js";
8
8
  import { u as useNetwork } from "../../hooks/useNetwork/index.js";
9
9
  import { jsx } from "react/jsx-runtime";
10
- const initialState = {
11
- privileges: {},
12
- hasPrivilege: () => false
13
- };
14
- const ModulePrivilegesContext = createContext(initialState);
10
+ const ModulePrivilegesContext = createContext(null);
15
11
  function ModulePrivilegesProvider(props) {
16
12
  const {
17
13
  children,
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { ModuleSkeletonContextProps, ModuleSkeletonProviderProps } from './types';
3
- declare const ModuleSkeletonContext: import("react").Context<ModuleSkeletonContextProps>;
3
+ declare const ModuleSkeletonContext: import("react").Context<ModuleSkeletonContextProps | null>;
4
4
  declare function ModuleSkeletonProvider(props: ModuleSkeletonProviderProps): JSX.Element;
5
5
  export { ModuleSkeletonProvider, ModuleSkeletonContext };
@@ -7,10 +7,7 @@ import "../ModuleDictionaryContext/index.js";
7
7
  import "../ModulePrivilegesContext/index.js";
8
8
  import "../NetworkContext/index.js";
9
9
  import { jsx } from "react/jsx-runtime";
10
- const initialState = {
11
- isSkeleton: false
12
- };
13
- const ModuleSkeletonContext = createContext(initialState);
10
+ const ModuleSkeletonContext = createContext(null);
14
11
  function ModuleSkeletonProvider(props) {
15
12
  const {
16
13
  children,
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import type { NetworkProviderProps } from './types';
3
- declare const NetworkContext: import("react").Context<import("./types").NetworkType>;
3
+ declare const NetworkContext: import("react").Context<import("./types").NetworkType | null>;
4
4
  declare function NetworkProvider(props: NetworkProviderProps): JSX.Element;
5
5
  export { NetworkProvider, NetworkContext };
@@ -2,10 +2,7 @@ import { createContext, useCallback } from "react";
2
2
  import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
3
3
  import { u as useHostTools } from "../../hooks/useHostTools/index.js";
4
4
  import { jsx } from "react/jsx-runtime";
5
- const initialValue = {
6
- networkOperation: () => Promise.resolve()
7
- };
8
- const NetworkContext = createContext(initialValue);
5
+ const NetworkContext = createContext(null);
9
6
  function NetworkProvider(props) {
10
7
  const {
11
8
  children,
@@ -1,2 +1,3 @@
1
- export declare const useEnvironment: () => import("../..").EnvironmentType;
1
+ import { EnvironmentType } from '../../types';
2
+ export declare const useEnvironment: () => EnvironmentType;
2
3
  export default useEnvironment;
@@ -7,9 +7,7 @@ const useFlags = () => {
7
7
  return context;
8
8
  };
9
9
  function isFlagsPresent(compareFlags, flags) {
10
- const filterFlags = compareFlags.filter(
11
- (findFlag) => flags.findIndex((sFlag) => sFlag === findFlag) !== -1
12
- );
10
+ const filterFlags = compareFlags.filter((findFlag) => flags.findIndex((sFlag) => sFlag === findFlag) !== -1);
13
11
  return filterFlags.length === compareFlags.length;
14
12
  }
15
13
  const useFlagsPresent = (compareFlags) => {
@@ -13,20 +13,28 @@ function useLocalStorage(key, initialValue) {
13
13
  window.localStorage.setItem(key, JSON.stringify(newValue));
14
14
  setValue(newValue);
15
15
  } catch (e) {
16
- console.error(e);
17
16
  }
18
17
  };
19
18
  return [value, setValueInLocalStorage];
20
19
  }
21
20
  function useLocalStorageWithListener(key, defaultValue) {
22
21
  const [value, setValue] = useState(() => {
23
- const storedValue = localStorage.getItem(key);
24
- return storedValue === null ? defaultValue : JSON.parse(storedValue);
22
+ try {
23
+ const storedValue = localStorage.getItem(key);
24
+ return storedValue === null ? defaultValue : JSON.parse(storedValue);
25
+ } catch (e) {
26
+ return defaultValue;
27
+ }
25
28
  });
26
29
  useEffect(() => {
27
30
  const listener = (e) => {
28
31
  if (e.storageArea === localStorage && e.key === key) {
29
- setValue(e.newValue ? JSON.parse(e.newValue) : e.newValue);
32
+ try {
33
+ if (e.newValue) {
34
+ setValue(JSON.parse(e.newValue));
35
+ }
36
+ } catch (_e) {
37
+ }
30
38
  }
31
39
  };
32
40
  window.addEventListener("storage", listener);
@@ -2,7 +2,6 @@ import { useContext } from "react";
2
2
  import { M as ModuleSkeletonContext } from "../../contexts/ModuleSkeletonContext/index.js";
3
3
  const useModuleSkeleton = () => {
4
4
  const context = useContext(ModuleSkeletonContext);
5
- console.log("useModuleSkeleton", context);
6
5
  if (!context)
7
6
  throw new Error("useModuleSkeleton context must be use inside ModuleSkeletonContext");
8
7
  return context.isSkeleton;
@@ -7,17 +7,28 @@ const initialPagerState = {
7
7
  totalRecords: 0
8
8
  };
9
9
  const usePaginate = (props) => {
10
- const { endPoint, timeout = 5e3, queryParams = {}, fireOnChangeParms } = props;
10
+ const {
11
+ endPoint,
12
+ timeout = 5e3,
13
+ queryParams,
14
+ fireOnChangeParms,
15
+ rowsPerPage = initialPagerState.rowsPerPage
16
+ } = props;
11
17
  const [refresh, setRefresh] = useState(fireOnChangeParms ? 1 : 0);
12
18
  const [rows, setRows] = useState([]);
13
- const [pagerState, setPagerState] = useState(initialPagerState);
14
- const refPagerState = useRef(initialPagerState);
19
+ const [pagerState, setPagerState] = useState({ ...initialPagerState, rowsPerPage });
20
+ const refPagerState = useRef({ ...initialPagerState, rowsPerPage });
21
+ const [firstQueryParams, setFirstQueryParams] = useState(true);
15
22
  const { startProgress, stopProgress } = useHostTools();
16
23
  const { networkOperation } = useNetwork();
17
24
  const Refresh = useCallback(() => {
18
25
  setRefresh((oldValue) => oldValue + 1);
19
26
  }, []);
20
27
  useEffect(() => {
28
+ if (firstQueryParams) {
29
+ setFirstQueryParams(false);
30
+ return;
31
+ }
21
32
  if (fireOnChangeParms) {
22
33
  Refresh();
23
34
  }
@@ -8,5 +8,6 @@ export interface UsePaginateProps {
8
8
  endPoint: string;
9
9
  timeout?: number;
10
10
  fireOnChangeParms?: boolean;
11
- queryParams?: Record<string, unknown>;
11
+ queryParams: Record<string, unknown>;
12
+ rowsPerPage?: number;
12
13
  }
package/index.js CHANGED
@@ -21,6 +21,5 @@ export { E as EmitEvents } from "./types/index.js";
21
21
  export { a as getLocalStorage, g as getPropertyByString, s as setLocalStorage, v as voidFunction } from "./utils/index.js";
22
22
  export { a as axiosOperation } from "./utils/axiosOperation.js";
23
23
  import "react/jsx-runtime";
24
- import "@m4l/core";
25
24
  import "./external/axios.js";
26
25
  import "qs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "license": "UNLICENSED",
5
5
  "author": "M4L Team",
6
6
  "dependencies": {
package/vite-env.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  /// <reference types="vite/client" />
2
2
  /// <reference types="vitest" />
3
+ /// <reference types="vitest/globals" />
3
4
  /// <reference types="vitest/importMeta" />
package/jest.d.ts DELETED
@@ -1 +0,0 @@
1
- /// <reference types="jest" />