@m4l/graphics 7.0.10 → 7.0.11

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/hooks/index.d.ts CHANGED
@@ -10,3 +10,4 @@ export { useHostTheme } from './useHostTheme';
10
10
  export { useResizeObserver } from './useResizeObserver';
11
11
  export { useResponsiveDesktop } from './useResponsive';
12
12
  export { useThemeSettingsStore } from './useThemSettingsStore';
13
+ export { usePaginate } from './usePaginate';
@@ -0,0 +1,13 @@
1
+ import { UsePaginateProps, PagerState } from './types';
2
+ /**
3
+ * Hook para paginar una lista de elementos
4
+ */
5
+ export declare const usePaginate: <TRow>(props: UsePaginateProps<TRow>) => {
6
+ onPageChange: (newPage: number) => void;
7
+ onRowsPerPageChange: (newRowsPerPage: number) => void;
8
+ pagerState: PagerState;
9
+ rows: TRow[];
10
+ clearRows: () => void;
11
+ Refresh: () => void;
12
+ setRows: import('react').Dispatch<import('react').SetStateAction<TRow[]>>;
13
+ };
@@ -0,0 +1,73 @@
1
+ import { useState as n, useRef as H, useCallback as U, useEffect as m } from "react";
2
+ import { i as s } from "./types.js";
3
+ import { useHostTools as j, useNetwork as v } from "@m4l/core";
4
+ const K = (h) => {
5
+ const {
6
+ endPoint: w,
7
+ timeout: C = 5e3,
8
+ queryParams: P,
9
+ fireOnChangeParms: i,
10
+ // Propiedad para permitir que un cambio en los parametros de la consulta dispare la recarga de la red
11
+ fireOnFirstLoad: R = !0,
12
+ // propiedad que evita que se cargue la red la en el primer render del hook
13
+ rowsPerPage: u = s.rowsPerPage,
14
+ startProgress: d,
15
+ stopProgress: S,
16
+ isRemote: k = !0,
17
+ bodyToSnakeCase: y = !1,
18
+ responseToCamelCase: T = !1,
19
+ initialRows: b = [],
20
+ externalCondition: c = !0,
21
+ onNetworkError: f,
22
+ getLabel: E
23
+ } = h, [p, g] = n(i ? 1 : 0), [O, a] = n(b), [x, o] = n({ ...s, rowsPerPage: u }), t = H({ ...s, rowsPerPage: u }), [F, L] = n(R), { startProgress: N, stopProgress: Q } = j(), { networkOperation: q } = v(), l = U(() => {
24
+ g((r) => r + 1);
25
+ }, []);
26
+ return m(() => {
27
+ if (F) {
28
+ L(!1);
29
+ return;
30
+ }
31
+ t.current.page = 0, i && l();
32
+ }, [P]), m(() => {
33
+ let r = !0;
34
+ if (!(!c || p === 0))
35
+ return q({
36
+ method: "GET",
37
+ endPoint: w,
38
+ timeout: C,
39
+ parms: {
40
+ ...P,
41
+ page: t.current.page,
42
+ limit: t.current.rowsPerPage
43
+ },
44
+ bodyToSnakeCase: y,
45
+ responseToCamelCase: T,
46
+ options: {
47
+ startProgress: d || N,
48
+ stopProgress: S || Q
49
+ },
50
+ isRemote: k
51
+ }).then((e) => {
52
+ r && (a(e.data), t.current.page = e.pager.page, o((G) => ({
53
+ ...G,
54
+ page: e.pager.page,
55
+ // rowsPerPage: response.pager.limit,
56
+ totalRecords: e.pager.total
57
+ })));
58
+ }).catch((e) => {
59
+ a([]), o(s), f && f(e.status);
60
+ }), function() {
61
+ r = !1;
62
+ };
63
+ }, [p, c, E]), { onPageChange: (r) => {
64
+ t.current.page = r, g((e) => e + 1);
65
+ }, onRowsPerPageChange: (r) => {
66
+ t.current.rowsPerPage = r, o((e) => ({ ...e, rowsPerPage: r })), g((e) => e + 1);
67
+ }, pagerState: x, rows: O, clearRows: () => {
68
+ a([]), o(s);
69
+ }, Refresh: l, setRows: a };
70
+ };
71
+ export {
72
+ K as u
73
+ };
@@ -0,0 +1,35 @@
1
+ import { ReactNode } from 'react';
2
+ import { HostToolsType } from '@m4l/core';
3
+ import { Id, ToastOptions } from 'react-toastify';
4
+ export declare const mock_addFlag: import('vitest').Mock<(...args: any[]) => any>;
5
+ export declare const mock_networkOperation: import('vitest').Mock<(...args: any[]) => any>;
6
+ export declare const mock_events_add_listener: import('vitest').Mock<(...args: any[]) => any>;
7
+ export declare const mock_events_remove_listener: import('vitest').Mock<(...args: any[]) => any>;
8
+ export declare const mock_events_emit: import('vitest').Mock<(...args: any[]) => any>;
9
+ export declare const mock_startProgress: import('vitest').Mock<(...args: any[]) => any>;
10
+ export declare const mock_stopProgress: import('vitest').Mock<(...args: any[]) => any>;
11
+ export interface ToasterFunctionProps {
12
+ title: ReactNode;
13
+ description?: ReactNode;
14
+ }
15
+ export type Toaster = {
16
+ (props: ToasterFunctionProps, toastOptions?: ToastOptions): Id;
17
+ success(props: ToasterFunctionProps, toastOptions?: ToastOptions): Id;
18
+ info(props: ToasterFunctionProps, toastOptions?: ToastOptions): Id;
19
+ warning(props: ToasterFunctionProps, toastOptions?: ToastOptions): Id;
20
+ error(props: ToasterFunctionProps, toastOptions?: ToastOptions): Id;
21
+ };
22
+ export declare const mock_toaster: Toaster;
23
+ export declare const environmentDataForTesting: {
24
+ isLocalhost: boolean;
25
+ host: string;
26
+ domain_token: string;
27
+ host_api_local: string;
28
+ host_api_remote: string;
29
+ host_static_assets: string;
30
+ environment_assets: string;
31
+ isMicroFrontend: boolean;
32
+ isIsolatation: boolean;
33
+ database: string;
34
+ };
35
+ export declare const hostToolsDataForTesting: HostToolsType;
@@ -0,0 +1,17 @@
1
+ import { AxiosOptions, GetLabelType, NetworkProps } from '@m4l/core';
2
+ export declare interface PagerState {
3
+ page: number;
4
+ rowsPerPage: number;
5
+ totalRecords: number;
6
+ }
7
+ export declare const initialPagerState: PagerState;
8
+ export interface UsePaginateProps<TRow> extends Pick<NetworkProps, 'endPoint' | 'timeout' | 'isRemote' | 'bodyToSnakeCase' | 'responseToCamelCase'>, AxiosOptions {
9
+ fireOnChangeParms?: boolean;
10
+ fireOnFirstLoad?: boolean;
11
+ queryParams: Record<string, unknown>;
12
+ rowsPerPage?: number;
13
+ initialRows?: TRow[];
14
+ externalCondition?: boolean;
15
+ onNetworkError?: (code: number) => void;
16
+ getLabel?: GetLabelType;
17
+ }
@@ -0,0 +1,8 @@
1
+ const a = {
2
+ page: 0,
3
+ rowsPerPage: 25,
4
+ totalRecords: 0
5
+ };
6
+ export {
7
+ a as i
8
+ };
package/index.js CHANGED
@@ -2,11 +2,11 @@ import { G as r } from "./components/GlobalStyles/index.js";
2
2
  import { g as s } from "./contexts/LocalesContext/helper.js";
3
3
  import { F as m, a as p } from "./contexts/FormatterContext/index.js";
4
4
  import { L as f, a as i } from "./contexts/LocalesContext/index.js";
5
- import { R as u, a as v } from "./contexts/ResponsiveContainerContext/index.js";
5
+ import { R as n, a as v } from "./contexts/ResponsiveContainerContext/index.js";
6
6
  import { H as l, a as T } from "./contexts/HostThemeContext/index.js";
7
- import { D as g, a as C } from "./contexts/DeviceTypeContext/index.js";
8
- import { d as R } from "./contexts/ThemeSettingsContext/constants.js";
9
- import { T as P, a as F } from "./contexts/ThemeSettingsContext/ThemeSettingsContext.js";
7
+ import { D as c, a as C } from "./contexts/DeviceTypeContext/index.js";
8
+ import { d as P } from "./contexts/ThemeSettingsContext/constants.js";
9
+ import { T as S, a as F } from "./contexts/ThemeSettingsContext/ThemeSettingsContext.js";
10
10
  import { u as D } from "./hooks/useFirstRender/index.js";
11
11
  import { u as b } from "./hooks/useFormatter/index.js";
12
12
  import { u as k } from "./hooks/useIsMountedRef/index.js";
@@ -19,10 +19,11 @@ import { u as j } from "./hooks/useHostTheme/index.js";
19
19
  import { u as B } from "./hooks/useResizeObserver/index.js";
20
20
  import { u as K } from "./hooks/useResponsive/index.js";
21
21
  import { u as V } from "./hooks/useThemSettingsStore/index.js";
22
- import { c as Y } from "./utils/strings.js";
23
- import { g as _ } from "./utils/anchorEl.js";
22
+ import { u as Y } from "./hooks/usePaginate/index.js";
23
+ import { c as _ } from "./utils/strings.js";
24
+ import { g as ee } from "./utils/anchorEl.js";
24
25
  export {
25
- g as DeviceTypeContext,
26
+ c as DeviceTypeContext,
26
27
  C as DeviceTypeProvider,
27
28
  m as FormatterContext,
28
29
  p as FormatterProvider,
@@ -31,13 +32,13 @@ export {
31
32
  T as HostThemeProvider,
32
33
  f as LocalesContext,
33
34
  i as LocalesProvider,
34
- u as ResponsiveContainerContext,
35
+ n as ResponsiveContainerContext,
35
36
  v as ResponsiveContainerProvider,
36
- P as ThemeSettingsContext,
37
+ S as ThemeSettingsContext,
37
38
  F as ThemeSettingsProvider,
38
- Y as capitalize,
39
- R as defaultThemeSettings,
40
- _ as getAnchorElPositionWindow,
39
+ _ as capitalize,
40
+ P as defaultThemeSettings,
41
+ ee as getAnchorElPositionWindow,
41
42
  s as getLocaleFromNetwork,
42
43
  D as useFirstRender,
43
44
  b as useFormatter,
@@ -46,6 +47,7 @@ export {
46
47
  k as useIsMountedRef,
47
48
  z as useLocales,
48
49
  U as useOffSetTop,
50
+ Y as usePaginate,
49
51
  B as useResizeObserver,
50
52
  G as useResponsiveContainerStore,
51
53
  K as useResponsiveDesktop,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/graphics",
3
- "version": "7.0.10",
3
+ "version": "7.0.11",
4
4
  "license": "UNLICENSED",
5
5
  "author": "M4L Team*",
6
6
  "type": "module",
@@ -17,8 +17,8 @@
17
17
  "zustand": "4.3.6"
18
18
  },
19
19
  "peerDependencies": {
20
- "@m4l/core": "^2.0.15",
21
- "@m4l/styles": "^7.1.18",
20
+ "@m4l/core": "^2.0.0",
21
+ "@m4l/styles": "^7.0.0",
22
22
  "@mui/material": "5.16.7",
23
23
  "@mui/x-date-pickers": "6.20.2",
24
24
  "@types/react": "^18.0.0",
File without changes
@@ -0,0 +1,9 @@
1
+ import { cleanup, screen } from '@testing-library/react';
2
+ import { renderHook } from '@testing-library/react-hooks';
3
+ import { default as React, act } from 'react';
4
+ /**
5
+ * customRender
6
+ */
7
+ declare const customRender: (ui: React.ReactElement, options?: {}) => import('@testing-library/react').RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>;
8
+ export { default as userEvent } from '@testing-library/user-event';
9
+ export { customRender as render, renderHook, screen, cleanup, act };