@m4l/core 0.0.25 → 0.0.28

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,8 +1,8 @@
1
1
  import { createContext, useState, useLayoutEffect, useCallback } from "react";
2
+ import { u as useFlags } from "../../hooks/useFlags/index.js";
2
3
  import { u as useHostTools } from "../../hooks/useHostTools/index.js";
3
4
  import { u as useNetwork } from "../../hooks/useNetwork/index.js";
4
5
  import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
5
- import { u as useFlags } from "../../hooks/useFlags/index.js";
6
6
  import { jsx } from "react/jsx-runtime";
7
7
  const initialState = {
8
8
  getLabel: () => "..",
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import type { GetLabelType, ModuleDictionary } from 'src/types/dictionary';
2
+ import type { GetLabelType, ModuleDictionary } from '../../types/dictionary';
3
3
  export interface ModuleDictionaryProviderProps {
4
4
  currentLang?: string;
5
5
  isAuth?: boolean;
@@ -1275,7 +1275,8 @@ const axiosOperation = async (props, enviroment, hostTools) => {
1275
1275
  parms = {},
1276
1276
  data: data2 = {},
1277
1277
  isRemote = true,
1278
- checkUnAuthorized = true
1278
+ checkUnAuthorized = true,
1279
+ headers
1279
1280
  } = props;
1280
1281
  let baseURL;
1281
1282
  if (isRemote) {
@@ -1289,8 +1290,9 @@ const axiosOperation = async (props, enviroment, hostTools) => {
1289
1290
  withCredentials: isRemote,
1290
1291
  method,
1291
1292
  url: `/${endPoint}`,
1292
- data: snakecaseKeys(data2, { deep: true }),
1293
+ data: data2,
1293
1294
  params: snakecaseKeys(parms, { deep: true }),
1295
+ headers,
1294
1296
  timeout
1295
1297
  }).then((response) => getResponse(endPoint, response)).catch((error) => Promise.reject(getError(error, hostTools, checkUnAuthorized))).finally(() => {
1296
1298
  hostTools.stopProgress();
@@ -1,6 +1,9 @@
1
- export { useLocalStorage } from './useLocalStorage';
1
+ export { useFlags, useFlagsPresent } from './useFlags';
2
2
  export { useHostTools } from './useHostTools';
3
+ export { useLocalStorage } from './useLocalStorage';
4
+ export { useModuleDictionary } from './useModuleDictionary';
3
5
  export { useNetwork } from './useNetwork';
4
6
  export { useEnvironment } from './useEnvironment';
5
- export { useFlags, useFlagsPresent } from './useFlags';
6
- export { useModuleDictionary } from './useModuleDictionary';
7
+ export { usePaginate } from './usePaginate';
8
+ export type { PagerState } from './usePaginate/types';
9
+ export { initialPagerState } from './usePaginate/types';
@@ -1,4 +1,4 @@
1
- import { useContext } from "react";
1
+ import { useContext, useState, useEffect } from "react";
2
2
  import { F as FlagsContext } from "../../contexts/FlagsContext/index.js";
3
3
  const useFlags = () => {
4
4
  const context = useContext(FlagsContext);
@@ -6,4 +6,18 @@ const useFlags = () => {
6
6
  throw new Error("useFlags context must be use inside FlagsProvider");
7
7
  return context;
8
8
  };
9
- export { useFlags as u };
9
+ function isFlagsPresent(compareFlags, flags) {
10
+ const filterFlags = compareFlags.filter((findFlag) => flags.findIndex((sFlag) => sFlag === findFlag) !== -1);
11
+ return filterFlags.length === compareFlags.length;
12
+ }
13
+ const useFlagsPresent = (compareFlags) => {
14
+ const context = useFlags();
15
+ const [isPresent, setIsPresent] = useState(isFlagsPresent(compareFlags, context.flags));
16
+ useEffect(() => {
17
+ if (isFlagsPresent(compareFlags, context.flags)) {
18
+ setIsPresent(true);
19
+ }
20
+ }, [context.flags, compareFlags]);
21
+ return isPresent;
22
+ };
23
+ export { useFlagsPresent as a, useFlags as u };
@@ -1,2 +1,9 @@
1
- import "react";
2
- import "../../contexts/ModuleDictionaryContext/index.js";
1
+ import { useContext } from "react";
2
+ import { M as ModuleDictionaryContext } from "../../contexts/ModuleDictionaryContext/index.js";
3
+ const useModuleDictionary = () => {
4
+ const context = useContext(ModuleDictionaryContext);
5
+ if (!context)
6
+ throw new Error("useModuleDictionary context must be use inside ModuleDictionaryProvider");
7
+ return context;
8
+ };
9
+ export { useModuleDictionary as u };
@@ -0,0 +1,15 @@
1
+ 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) => {
9
+ onPageChange: (newPage: number) => void;
10
+ onRowsPerPageChange: (newRowsPerPage: number) => void;
11
+ pagerState: PagerState;
12
+ rows: TRow[];
13
+ clearRows: () => void;
14
+ Refresh: () => void;
15
+ };
@@ -0,0 +1,72 @@
1
+ import { useState, useRef, useCallback, useEffect } from "react";
2
+ import { u as useHostTools } from "../useHostTools/index.js";
3
+ import { u as useNetwork } from "../useNetwork/index.js";
4
+ const initialPagerState = {
5
+ page: 0,
6
+ rowsPerPage: 25,
7
+ totalRecords: 0
8
+ };
9
+ const usePaginate = (props) => {
10
+ const { endPoint, timeout = 5e3, queryParams = {}, fireOnEnter = true } = props;
11
+ const [refresh, setRefresh] = useState(0);
12
+ const [rows, setRows] = useState([]);
13
+ const [pagerState, setPagerState] = useState(initialPagerState);
14
+ const refPagerState = useRef(initialPagerState);
15
+ const [fire, setFire] = useState(fireOnEnter);
16
+ const { startProgress, stopProgress } = useHostTools();
17
+ const { networkOperation } = useNetwork();
18
+ const Refresh = useCallback(() => {
19
+ setRefresh((oldValue) => oldValue + 1);
20
+ }, []);
21
+ useEffect(() => {
22
+ let mounted = true;
23
+ if (!fire) {
24
+ setFire(true);
25
+ return;
26
+ }
27
+ startProgress();
28
+ networkOperation({
29
+ method: "GET",
30
+ endPoint,
31
+ timeout,
32
+ parms: {
33
+ ...queryParams,
34
+ page: refPagerState.current.page,
35
+ limit: refPagerState.current.rowsPerPage
36
+ }
37
+ }).then((response) => {
38
+ if (mounted) {
39
+ setRows(response.data);
40
+ refPagerState.current.page = response.pager.page;
41
+ setPagerState((oldPagerState) => ({
42
+ ...oldPagerState,
43
+ page: response.pager.page,
44
+ totalRecords: response.pager.total
45
+ }));
46
+ }
47
+ }).finally(() => {
48
+ if (mounted) {
49
+ stopProgress();
50
+ }
51
+ });
52
+ return function cleanUp() {
53
+ stopProgress();
54
+ mounted = false;
55
+ };
56
+ }, [refresh, queryParams]);
57
+ const onPageChange = (newPage) => {
58
+ refPagerState.current.page = newPage;
59
+ setRefresh((oldValue) => oldValue + 1);
60
+ };
61
+ const onRowsPerPageChange = (newRowsPerPage) => {
62
+ refPagerState.current.rowsPerPage = newRowsPerPage;
63
+ setPagerState((oldPagerState) => ({ ...oldPagerState, rowsPerPage: newRowsPerPage }));
64
+ setRefresh((oldValue) => oldValue + 1);
65
+ };
66
+ const clearRows = () => {
67
+ setRows([]);
68
+ setPagerState(initialPagerState);
69
+ };
70
+ return { onPageChange, onRowsPerPageChange, pagerState, rows, clearRows, Refresh };
71
+ };
72
+ export { initialPagerState as i, usePaginate as u };
@@ -0,0 +1,6 @@
1
+ export declare interface PagerState {
2
+ page: number;
3
+ rowsPerPage: number;
4
+ totalRecords: number;
5
+ }
6
+ export declare const initialPagerState: PagerState;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,5 @@
1
1
  export * from './contexts';
2
- export { useEnvironment } from './hooks/useEnvironment';
3
- export { useFlags } from './hooks/useFlags';
4
- export { useHostTools } from './hooks/useHostTools';
5
- export { useLocalStorage } from './hooks/useLocalStorage';
6
- export { useNetwork } from './hooks/useNetwork';
2
+ export * from './hooks';
7
3
  export { EmitEvents } from './types';
8
4
  export type { Maybe, HostToolsType, NetworkProps, EnvironmentType, AxiosOperation, EventFunListener, } from './types';
9
5
  export type { GetLabelType, Dictionary, ModuleDictionary, ComponentDictionary, } from './types/dictionary';
package/dist/index.js CHANGED
@@ -3,11 +3,13 @@ export { H as HostToolsContext, a as HostToolsProvider } from "./contexts/HostTo
3
3
  export { N as NetworkContext, a as NetworkProvider } from "./contexts/NetworkContext/index.js";
4
4
  export { F as FlagsContext, a as FlagsProvider } from "./contexts/FlagsContext/index.js";
5
5
  export { M as ModuleDictionaryContext, a as ModuleDictionaryProvider } from "./contexts/ModuleDictionaryContext/index.js";
6
- export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
7
- export { u as useFlags } from "./hooks/useFlags/index.js";
6
+ export { u as useFlags, a as useFlagsPresent } from "./hooks/useFlags/index.js";
8
7
  export { u as useHostTools } from "./hooks/useHostTools/index.js";
9
8
  export { u as useLocalStorage } from "./hooks/useLocalStorage/index.js";
9
+ export { u as useModuleDictionary } from "./hooks/useModuleDictionary/index.js";
10
10
  export { u as useNetwork } from "./hooks/useNetwork/index.js";
11
+ export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
12
+ export { i as initialPagerState, u as usePaginate } from "./hooks/usePaginate/index.js";
11
13
  export { E as EmitEvents } from "./types/index.js";
12
14
  export { a as getLocalStorage, g as getPropertyByString, s as setLocalStorage, v as voidFunction } from "./utils/index.js";
13
15
  export { a as axiosOperation } from "./external/axios.js";
@@ -16,6 +16,7 @@ export declare type NetworkProps = {
16
16
  timeout?: number;
17
17
  parms?: object;
18
18
  data?: object;
19
+ headers?: Record<string, string | number | boolean>;
19
20
  checkUnAuthorized?: boolean;
20
21
  isRemote?: boolean;
21
22
  showSuccesInfo?: boolean;
package/dist/vendor.js CHANGED
@@ -1,14 +1,16 @@
1
1
  import "react";
2
+ import "./contexts/FlagsContext/index.js";
2
3
  import "./contexts/HostToolsContext/index.js";
4
+ import "./contexts/ModuleDictionaryContext/index.js";
3
5
  import "./contexts/NetworkContext/index.js";
4
6
  import "./contexts/EnvironmentContext/index.js";
5
- import "./contexts/FlagsContext/index.js";
6
- import "./contexts/ModuleDictionaryContext/index.js";
7
- import "./hooks/useEnvironment/index.js";
8
7
  import "./hooks/useFlags/index.js";
9
8
  import "./hooks/useHostTools/index.js";
10
9
  import "./hooks/useLocalStorage/index.js";
10
+ import "./hooks/useModuleDictionary/index.js";
11
11
  import "./hooks/useNetwork/index.js";
12
+ import "./hooks/useEnvironment/index.js";
13
+ import "./hooks/usePaginate/index.js";
12
14
  import "./types/index.js";
13
15
  import "./utils/index.js";
14
16
  import "./external/axios.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
3
  "private": false,
4
- "version": "0.0.25",
4
+ "version": "0.0.28",
5
5
  "license": "UNLICENSED",
6
6
  "author": "M4L Team",
7
7
  "scripts": {