@m4l/graphics 7.0.15 → 7.0.16-beta.2

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,7 +1,7 @@
1
1
  import { createStore as S } from "zustand";
2
2
  import { devtools as c } from "zustand/middleware";
3
3
  import { immer as p } from "zustand/middleware/immer";
4
- import { getPaletteByPreset as a, typographyOld as d, shadows as h, getColorPresets as u, createCustomShadows as f } from "@m4l/styles";
4
+ import { getPaletteByPreset as a, createCustomShadows as d, shadows as h, typographyOld as u, getColorPresets as f } from "@m4l/styles";
5
5
  import { alpha as U } from "@mui/system";
6
6
  import { d as s } from "./constants.js";
7
7
  function g(r, o = "m4l") {
@@ -18,7 +18,7 @@ const n = (r) => {
18
18
  const o = r.themeUserSettings || s, m = o.themeMode === "light", t = a(o.themeColor), e = m ? t.light : t.dark;
19
19
  r.themeOptions = {
20
20
  ...r.themeOptions,
21
- ...d,
21
+ ...u,
22
22
  palette: {
23
23
  ...r.themeOptions?.palette ?? {},
24
24
  ...e
@@ -28,10 +28,10 @@ const n = (r) => {
28
28
  shadows: m ? h.light : h.dark,
29
29
  customShadows: {
30
30
  primary: `0 8px 16px 0 ${U(
31
- u(o.themeColor)?.main || "#fff",
31
+ f(o.themeColor)?.main || "#fff",
32
32
  0.2
33
33
  )}`,
34
- ...f(o.themeMode)
34
+ ...d(o.themeMode)
35
35
  },
36
36
  stretch: o.themeStretch
37
37
  }, g(r.themeOptions);
package/hooks/index.d.ts CHANGED
@@ -11,3 +11,4 @@ export { useResizeObserver } from './useResizeObserver';
11
11
  export { useResponsiveDesktop } from './useResponsive';
12
12
  export { useThemeSettingsStore } from './useThemSettingsStore';
13
13
  export { usePaginate } from './usePaginate';
14
+ export { useRows } from './useRows';
@@ -0,0 +1,11 @@
1
+ import { UseRowsProps } from './types';
2
+ /**
3
+ * Hook para obtener las filas de la lista de elementos
4
+ */
5
+ export declare const useRows: <TRow>(props: UseRowsProps<TRow>) => {
6
+ rows: unknown[];
7
+ clearRows: () => void;
8
+ refresh: () => void;
9
+ setRows: (rows: TRow[]) => void;
10
+ loading: boolean;
11
+ };
@@ -0,0 +1,70 @@
1
+ import { useReducer as D, useRef as F, useCallback as i, useEffect as u } from "react";
2
+ import { useHostTools as I, useNetwork as W, useModuleSkeleton as b, useModuleDictionary as A } from "@m4l/core";
3
+ import { u as G } from "../useFirstRender/index.js";
4
+ import { r as M, g as H, s as q } from "./state.js";
5
+ const v = (R) => {
6
+ const {
7
+ endPoint: y,
8
+ timeout: m = 5e3,
9
+ queryParams: s,
10
+ fireOnChangeParms: n = !1,
11
+ fireOnFirstLoad: S = !0,
12
+ startProgress: g,
13
+ stopProgress: h,
14
+ isRemote: E = !0,
15
+ bodyToSnakeCase: P = !1,
16
+ responseToCamelCase: O = !1,
17
+ initialRows: T = [],
18
+ onNetworkError: l,
19
+ refreshOnChangeDictionary: c = !1
20
+ } = R, [t, e] = D(
21
+ M,
22
+ H(n, S, T)
23
+ ), { startProgress: w, stopProgress: C } = I(), { networkOperation: k } = W(), f = b(), { getLabel: _ } = A(), p = F(s), d = G([s]), r = i(() => {
24
+ e({ type: "INCREMENT_REFRESH" });
25
+ }, []);
26
+ u(() => {
27
+ q(d, t, s, p.current, n) && r(), p.current = s;
28
+ }, [s, d, t, n, r]), u(() => {
29
+ let o = !0;
30
+ if (t.countRefresh !== 0)
31
+ return e({ type: "SET_LOADING", payload: !0 }), k({
32
+ method: "GET",
33
+ endPoint: y,
34
+ timeout: m,
35
+ parms: {
36
+ ...s
37
+ },
38
+ bodyToSnakeCase: P,
39
+ responseToCamelCase: O,
40
+ options: {
41
+ startProgress: g || w,
42
+ stopProgress: h || C
43
+ },
44
+ isRemote: E
45
+ }).then((a) => {
46
+ o && e({ type: "SET_ROWS", payload: a.data });
47
+ }).catch((a) => {
48
+ e({ type: "SET_ROWS", payload: [] }), l && l(a.status);
49
+ }).finally(() => {
50
+ e({ type: "SET_LOADING", payload: !1 });
51
+ }), function() {
52
+ o = !1;
53
+ };
54
+ }, [t.countRefresh]), u(() => {
55
+ !f && c && r();
56
+ }, [_, c, f]);
57
+ const N = i(() => {
58
+ e({ type: "CLEAR_ROWS" });
59
+ }, []), L = i((o) => e({ type: "SET_ROWS", payload: o }), [e]);
60
+ return {
61
+ rows: t.rows,
62
+ clearRows: N,
63
+ refresh: r,
64
+ setRows: L,
65
+ loading: t.loading
66
+ };
67
+ };
68
+ export {
69
+ v as u
70
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ export interface State<TRow> {
2
+ countRefresh: number;
3
+ rows: TRow[];
4
+ fireOnFirstLoad: boolean;
5
+ loading: boolean;
6
+ }
7
+ export type Action<TRow> = {
8
+ type: 'INCREMENT_REFRESH';
9
+ } | {
10
+ type: 'SET_ROWS';
11
+ payload: TRow[];
12
+ } | {
13
+ type: 'SET_LOADING';
14
+ payload: boolean;
15
+ } | {
16
+ type: 'CLEAR_ROWS';
17
+ };
18
+ /**
19
+ * Obtiene el estado inicial de la lista de elementos
20
+ */
21
+ export declare const getInitialState: <TRow>(fireOnChangeParms: boolean, fireOnFirstLoad: boolean, initialRows: TRow[]) => State<TRow>;
22
+ /**
23
+ * Reducer para actualizar el estado de la lista de elementos
24
+ */
25
+ export declare const reducer: <TRow>(state: State<TRow>, action: Action<TRow>) => State<TRow>;
26
+ /**
27
+ * Verifica si se debe actualizar la lista de elementos
28
+ */
29
+ export declare const shouldRefresh: <T>(isFirstRender: boolean, state: State<T>, currentParams: any, previousParams: any, fireOnChangeParms: boolean) => boolean;
@@ -0,0 +1,25 @@
1
+ import { deepEqual as n } from "fast-equals";
2
+ const t = (r, e, u) => ({
3
+ countRefresh: r ? 1 : 0,
4
+ rows: u,
5
+ fireOnFirstLoad: e,
6
+ loading: !1
7
+ }), f = (r, e) => {
8
+ switch (e.type) {
9
+ case "INCREMENT_REFRESH":
10
+ return { ...r, countRefresh: r.countRefresh + 1 };
11
+ case "SET_ROWS":
12
+ return { ...r, rows: e.payload };
13
+ case "SET_LOADING":
14
+ return { ...r, loading: e.payload };
15
+ case "CLEAR_ROWS":
16
+ return { ...r, rows: [] };
17
+ default:
18
+ return r;
19
+ }
20
+ }, c = (r, e, u, o, s) => !!(r && e.fireOnFirstLoad || !r && !n(o, u) && s);
21
+ export {
22
+ t as g,
23
+ f as r,
24
+ c as s
25
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { AxiosOptions, NetworkProps } from '@m4l/core';
2
+ export interface UseRowsProps<TRow> extends Pick<NetworkProps, 'endPoint' | 'timeout' | 'isRemote' | 'bodyToSnakeCase' | 'responseToCamelCase'>, AxiosOptions {
3
+ fireOnChangeParms?: boolean;
4
+ fireOnFirstLoad?: boolean;
5
+ queryParams: Record<string, unknown>;
6
+ initialRows?: TRow[];
7
+ onNetworkError?: (code: number) => void;
8
+ refreshOnChangeDictionary?: boolean;
9
+ }
package/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { G as r } from "./components/GlobalStyles/index.js";
2
- import { g as s } from "./contexts/LocalesContext/helper.js";
2
+ import { g as t } from "./contexts/LocalesContext/helper.js";
3
3
  import { F as m, a as p } from "./contexts/FormatterContext/index.js";
4
- import { L as f, a as i } from "./contexts/LocalesContext/index.js";
4
+ import { L as u, a as f } from "./contexts/LocalesContext/index.js";
5
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
7
  import { D as c, a as C } from "./contexts/DeviceTypeContext/index.js";
8
- import { d as P } from "./contexts/ThemeSettingsContext/constants.js";
8
+ import { d as h } from "./contexts/ThemeSettingsContext/constants.js";
9
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
- import { u as k } from "./hooks/useIsMountedRef/index.js";
12
+ import { u as y } from "./hooks/useIsMountedRef/index.js";
13
13
  import { u as z } from "./hooks/useLocales/index.js";
14
14
  import { u as G } from "./hooks/useResponsiveContainer/index.js";
15
15
  import { u as M } from "./hooks/useUserAgent/index.js";
@@ -20,8 +20,9 @@ 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
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";
23
+ import { u as _ } from "./hooks/useRows/index.js";
24
+ import { c as ee } from "./utils/strings.js";
25
+ import { g as re } from "./utils/anchorEl.js";
25
26
  export {
26
27
  c as DeviceTypeContext,
27
28
  C as DeviceTypeProvider,
@@ -30,27 +31,28 @@ export {
30
31
  r as GlobalStyles,
31
32
  l as HostThemeContext,
32
33
  T as HostThemeProvider,
33
- f as LocalesContext,
34
- i as LocalesProvider,
34
+ u as LocalesContext,
35
+ f as LocalesProvider,
35
36
  n as ResponsiveContainerContext,
36
37
  v as ResponsiveContainerProvider,
37
38
  S as ThemeSettingsContext,
38
39
  F as ThemeSettingsProvider,
39
- _ as capitalize,
40
- P as defaultThemeSettings,
41
- ee as getAnchorElPositionWindow,
42
- s as getLocaleFromNetwork,
40
+ ee as capitalize,
41
+ h as defaultThemeSettings,
42
+ re as getAnchorElPositionWindow,
43
+ t as getLocaleFromNetwork,
43
44
  D as useFirstRender,
44
45
  b as useFormatter,
45
46
  j as useHostTheme,
46
47
  E as useIsMobile,
47
- k as useIsMountedRef,
48
+ y as useIsMountedRef,
48
49
  z as useLocales,
49
50
  U as useOffSetTop,
50
51
  Y as usePaginate,
51
52
  B as useResizeObserver,
52
53
  G as useResponsiveContainerStore,
53
54
  K as useResponsiveDesktop,
55
+ _ as useRows,
54
56
  V as useThemeSettingsStore,
55
57
  M as useUserAgent
56
58
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/graphics",
3
- "version": "7.0.15",
3
+ "version": "7.0.16-beta.2",
4
4
  "license": "UNLICENSED",
5
5
  "author": "M4L Team*",
6
6
  "type": "module",