@m4l/core 0.0.37 → 0.0.40

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.
@@ -5,6 +5,7 @@ const initialValue = {
5
5
  toast: () => 0,
6
6
  startProgress: voidFunction,
7
7
  stopProgress: voidFunction,
8
+ formatDate: () => "",
8
9
  events_add_listener: voidFunction,
9
10
  events_remove_listener: voidFunction,
10
11
  events_emit: voidFunction
@@ -1,8 +1,9 @@
1
- import { createContext, useState, useLayoutEffect, useCallback } from "react";
1
+ import { createContext, useState, useEffect, useCallback } from "react";
2
2
  import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
3
3
  import { u as useFlags } from "../../hooks/useFlags/index.js";
4
4
  import { u as useHostTools } from "../../hooks/useHostTools/index.js";
5
5
  import "../ModulePrivilegesContext/index.js";
6
+ import "../ModuleSkeletonContext/index.js";
6
7
  import { u as useNetwork } from "../../hooks/useNetwork/index.js";
7
8
  import { jsx } from "react/jsx-runtime";
8
9
  const initialState = {
@@ -33,7 +34,7 @@ function ModuleDictionaryProvider(props) {
33
34
  const {
34
35
  networkOperation
35
36
  } = useNetwork();
36
- useLayoutEffect(() => {
37
+ useEffect(() => {
37
38
  let mounted = true;
38
39
  startProgress();
39
40
  networkOperation({
@@ -1,8 +1,9 @@
1
- import { createContext, useState, useLayoutEffect, useCallback } from "react";
1
+ import { createContext, useState, useEffect, useCallback } from "react";
2
2
  import "../EnvironmentContext/index.js";
3
3
  import { u as useFlags } from "../../hooks/useFlags/index.js";
4
4
  import { u as useHostTools } from "../../hooks/useHostTools/index.js";
5
5
  import "../ModuleDictionaryContext/index.js";
6
+ import "../ModuleSkeletonContext/index.js";
6
7
  import { u as useNetwork } from "../../hooks/useNetwork/index.js";
7
8
  import { jsx } from "react/jsx-runtime";
8
9
  const initialState = {
@@ -26,8 +27,12 @@ function ModulePrivilegesProvider(props) {
26
27
  const {
27
28
  networkOperation
28
29
  } = useNetwork();
29
- useLayoutEffect(() => {
30
+ useEffect(() => {
30
31
  let mounted = true;
32
+ if (queryPrivileges.length === 0) {
33
+ addFlag("privileges_loaded");
34
+ return;
35
+ }
31
36
  startProgress();
32
37
  networkOperation({
33
38
  method: "GET",
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { ModuleSkeletonContextProps, ModuleSkeletonProviderProps } from './types';
3
+ declare const ModuleSkeletonContext: import("react").Context<ModuleSkeletonContextProps>;
4
+ declare function ModuleSkeletonProvider(props: ModuleSkeletonProviderProps): JSX.Element;
5
+ export { ModuleSkeletonProvider, ModuleSkeletonContext };
@@ -0,0 +1,26 @@
1
+ import { createContext } from "react";
2
+ import "../EnvironmentContext/index.js";
3
+ import { a as useFlagsPresent } from "../../hooks/useFlags/index.js";
4
+ import "../HostToolsContext/index.js";
5
+ import "../ModuleDictionaryContext/index.js";
6
+ import "../ModulePrivilegesContext/index.js";
7
+ import "../NetworkContext/index.js";
8
+ import { jsx } from "react/jsx-runtime";
9
+ const initialState = {
10
+ isSkeleton: false
11
+ };
12
+ const ModuleSkeletonContext = createContext(initialState);
13
+ function ModuleSkeletonProvider(props) {
14
+ const {
15
+ children,
16
+ flags
17
+ } = props;
18
+ const isSkeleton = !useFlagsPresent(flags);
19
+ return /* @__PURE__ */ jsx(ModuleSkeletonContext.Provider, {
20
+ value: {
21
+ isSkeleton
22
+ },
23
+ children
24
+ });
25
+ }
26
+ export { ModuleSkeletonContext as M, ModuleSkeletonProvider as a };
@@ -0,0 +1,8 @@
1
+ import { ReactNode } from 'react';
2
+ export interface ModuleSkeletonProviderProps {
3
+ flags: string[];
4
+ children: ReactNode;
5
+ }
6
+ export interface ModuleSkeletonContextProps {
7
+ isSkeleton: boolean;
8
+ }
@@ -4,3 +4,4 @@ export { NetworkContext, NetworkProvider } from './NetworkContext';
4
4
  export { FlagsContext, FlagsProvider } from './FlagsContext';
5
5
  export { ModuleDictionaryContext, ModuleDictionaryProvider } from './ModuleDictionaryContext';
6
6
  export { ModulePrivilegesContext, ModulePrivilegesProvider } from './ModulePrivilegesContext';
7
+ export { ModuleSkeletonContext, ModuleSkeletonProvider } from './ModuleSkeletonContext';
@@ -4,6 +4,7 @@ export { useHostTools } from './useHostTools';
4
4
  export { useLocalStorage } from './useLocalStorage';
5
5
  export { useModuleDictionary } from './useModuleDictionary';
6
6
  export { useModulePrivileges } from './useModulePrivileges';
7
+ export { useModuleSkeleton } from './useModuleSkeleton';
7
8
  export { useNetwork } from './useNetwork';
8
9
  export { usePaginate } from './usePaginate';
9
10
  export type { PagerState } from './usePaginate/types';
@@ -0,0 +1 @@
1
+ export declare const useModuleSkeleton: () => boolean;
@@ -0,0 +1,9 @@
1
+ import { useContext } from "react";
2
+ import { M as ModuleSkeletonContext } from "../../contexts/ModuleSkeletonContext/index.js";
3
+ const useModuleSkeleton = () => {
4
+ const context = useContext(ModuleSkeletonContext);
5
+ if (!context)
6
+ throw new Error("useModuleSkeleton context must be use inside ModuleSkeletonContext");
7
+ return context.isSkeleton;
8
+ };
9
+ export { useModuleSkeleton as u };
@@ -1,11 +1,6 @@
1
+ import { UsePaginateProps } from './types';
1
2
  import type { PagerState } from './types';
2
- export interface propsUsePaginate {
3
- endPoint: string;
4
- timeout?: number;
5
- fireOnEnter?: boolean;
6
- queryParams?: Record<string, unknown>;
7
- }
8
- export declare const usePaginate: <TRow>(props: propsUsePaginate) => {
3
+ export declare const usePaginate: <TRow>(props: UsePaginateProps) => {
9
4
  onPageChange: (newPage: number) => void;
10
5
  onRowsPerPageChange: (newRowsPerPage: number) => void;
11
6
  pagerState: PagerState;
@@ -7,23 +7,25 @@ const initialPagerState = {
7
7
  totalRecords: 0
8
8
  };
9
9
  const usePaginate = (props) => {
10
- const { endPoint, timeout = 5e3, queryParams = {}, fireOnEnter = true } = props;
11
- const [refresh, setRefresh] = useState(0);
10
+ const { endPoint, timeout = 5e3, queryParams = {}, fireOnChangeParms } = props;
11
+ const [refresh, setRefresh] = useState(fireOnChangeParms ? 1 : 0);
12
12
  const [rows, setRows] = useState([]);
13
13
  const [pagerState, setPagerState] = useState(initialPagerState);
14
14
  const refPagerState = useRef(initialPagerState);
15
- const [fire, setFire] = useState(fireOnEnter);
16
15
  const { startProgress, stopProgress } = useHostTools();
17
16
  const { networkOperation } = useNetwork();
18
17
  const Refresh = useCallback(() => {
19
18
  setRefresh((oldValue) => oldValue + 1);
20
19
  }, []);
20
+ useEffect(() => {
21
+ if (fireOnChangeParms) {
22
+ Refresh();
23
+ }
24
+ }, [queryParams]);
21
25
  useEffect(() => {
22
26
  let mounted = true;
23
- if (!fire) {
24
- setFire(true);
27
+ if (refresh === 0)
25
28
  return;
26
- }
27
29
  startProgress();
28
30
  networkOperation({
29
31
  method: "GET",
@@ -53,7 +55,7 @@ const usePaginate = (props) => {
53
55
  stopProgress();
54
56
  mounted = false;
55
57
  };
56
- }, [refresh, queryParams]);
58
+ }, [refresh]);
57
59
  const onPageChange = (newPage) => {
58
60
  refPagerState.current.page = newPage;
59
61
  setRefresh((oldValue) => oldValue + 1);
@@ -4,3 +4,9 @@ export declare interface PagerState {
4
4
  totalRecords: number;
5
5
  }
6
6
  export declare const initialPagerState: PagerState;
7
+ export interface UsePaginateProps {
8
+ endPoint: string;
9
+ timeout?: number;
10
+ fireOnChangeParms?: boolean;
11
+ queryParams?: Record<string, unknown>;
12
+ }
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ export { F as FlagsContext, a as FlagsProvider } from "./contexts/FlagsContext/i
4
4
  export { H as HostToolsContext, a as HostToolsProvider } from "./contexts/HostToolsContext/index.js";
5
5
  export { M as ModuleDictionaryContext, a as ModuleDictionaryProvider } from "./contexts/ModuleDictionaryContext/index.js";
6
6
  export { M as ModulePrivilegesContext, a as ModulePrivilegesProvider } from "./contexts/ModulePrivilegesContext/index.js";
7
+ export { M as ModuleSkeletonContext, a as ModuleSkeletonProvider } from "./contexts/ModuleSkeletonContext/index.js";
7
8
  export { N as NetworkContext, a as NetworkProvider } from "./contexts/NetworkContext/index.js";
8
9
  export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
9
10
  export { u as useFlags, a as useFlagsPresent } from "./hooks/useFlags/index.js";
@@ -11,6 +12,7 @@ export { u as useHostTools } from "./hooks/useHostTools/index.js";
11
12
  export { u as useLocalStorage } from "./hooks/useLocalStorage/index.js";
12
13
  export { u as useModuleDictionary } from "./hooks/useModuleDictionary/index.js";
13
14
  export { u as useModulePrivileges } from "./hooks/useModulePrivileges/index.js";
15
+ export { u as useModuleSkeleton } from "./hooks/useModuleSkeleton/index.js";
14
16
  export { u as useNetwork } from "./hooks/useNetwork/index.js";
15
17
  export { i as initialPagerState, u as usePaginate } from "./hooks/usePaginate/index.js";
16
18
  export { E as EmitEvents } from "./types/index.js";
@@ -37,6 +37,7 @@ export declare interface HostToolsType {
37
37
  toast: ToastFunction;
38
38
  startProgress: VoidFunction;
39
39
  stopProgress: VoidFunction;
40
+ formatDate: (date: Date | number, format: string, options?: any) => string;
40
41
  events_add_listener: (eventName: string, handler: EventFunListener) => void;
41
42
  events_remove_listener: (eventName: string, handler: Maybe<EventFunListener>) => void;
42
43
  events_emit: (eventName: string, arg: any) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
3
  "private": false,
4
- "version": "0.0.37",
4
+ "version": "0.0.40",
5
5
  "license": "UNLICENSED",
6
6
  "author": "M4L Team",
7
7
  "scripts": {