@m4l/graphics 7.0.9 → 7.0.11-beta.1

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,11 +1,11 @@
1
1
  import o from "date-fns/locale/en-US";
2
2
  async function g(n, e, s) {
3
- const r = l(n), i = { ...n };
4
- let t;
5
- return r === "es" ? t = (await import("date-fns/locale/es")).default : r === "fr" ? t = (await import("date-fns/locale/fr")).default : r === "en-US" ? t = o : (t = o, i.lang = "en", i.script = void 0, i.region = "US", i.url_icon = `${e}/${s}/frontend/commons/assets/icons/langs/lang_en.svg`, i.name = "English US*"), {
6
- ...i,
7
- module: t,
8
- localeString: l(i)
3
+ const r = l(n), t = { ...n };
4
+ let i;
5
+ return r === "es" ? i = (await import("date-fns/locale/es")).default : r === "fr" ? i = (await import("date-fns/locale/fr")).default : r === "en-US" ? i = o : (i = o, t.lang = "en", t.script = void 0, t.region = "US", t.urlIcon = `${e}/${s}/frontend/commons/assets/icons/langs/lang_en.svg`, t.name = "English US*"), {
6
+ ...t,
7
+ module: i,
8
+ localeString: l(t)
9
9
  };
10
10
  }
11
11
  function l(n) {
@@ -1,38 +1,40 @@
1
- import { jsx as m } from "react/jsx-runtime";
1
+ import { jsx as f } from "react/jsx-runtime";
2
2
  import { createContext as A, useState as d, useCallback as O, useEffect as E } from "react";
3
3
  import { AdapterDateFns as k } from "@mui/x-date-pickers/AdapterDateFns";
4
4
  import { LocalizationProvider as x } from "@mui/x-date-pickers";
5
- import { useEnvironment as F, useNetwork as P, useHostTools as j, useLocalStorageWithListener as G, EmitEvents as i } from "@m4l/core";
5
+ import { useEnvironment as F, useNetwork as P, useHostTools as j, useLocalStorageWithListener as G, EmitEvents as a } from "@m4l/core";
6
6
  import { s as I, j as V } from "./helper.js";
7
- const U = A(null);
7
+ const b = A(null);
8
8
  function B(_) {
9
- const { children: g, isMicroFrontEnd: e, localeHost: a, getLocaleFromNetwork: s } = _;
10
- if (e && !a)
9
+ const { children: g, isMicroFrontEnd: e, localeHost: i, getLocaleFromNetwork: s } = _;
10
+ if (e && !i)
11
11
  throw Error("Must set localeHost in microfrontend");
12
12
  if (!e && !s)
13
13
  throw Error("Must set getLocaleFromNetwork in host");
14
- const { domain_token: L, host_static_assets: p, environment_assets: h } = F(), { networkOperation: v } = P(), { events_add_listener: S, events_remove_listener: C, events_emit: T } = j(), [r, l] = d(() => {
14
+ const { domain_token: L, host_static_assets: p, environment_assets: C } = F(), { networkOperation: S } = P(), { events_add_listener: h, events_remove_listener: v, events_emit: T } = j(), [r, l] = d(() => {
15
15
  if (e)
16
- return a;
16
+ return i;
17
17
  }), [o, c] = G(
18
18
  "localeHost",
19
19
  navigator.language
20
20
  ), [H, N] = d(""), u = O((t) => {
21
21
  l(t);
22
22
  }, []);
23
- if (E(() => (e && S(i.EMMIT_EVENT_HOST_LOCALE_CHANGE, u), () => {
24
- e && C(i.EMMIT_EVENT_HOST_LOCALE_CHANGE, u);
23
+ if (E(() => (e && h(a.EMMIT_EVENT_HOST_LOCALE_CHANGE, u), () => {
24
+ e && v(a.EMMIT_EVENT_HOST_LOCALE_CHANGE, u);
25
25
  }), []), E(() => {
26
26
  let t = !0;
27
27
  if (!e && s && !(o === H && o !== ""))
28
- return v({
28
+ return S({
29
29
  method: "POST",
30
30
  endPoint: "na/locales",
31
- data: { ...I(o), domain_token: L }
32
- }).then((f) => {
33
- t && s(f.data, p, h).then(
31
+ data: { ...I(o), domain_token: L },
32
+ responseToCamelCase: !0,
33
+ bodyToSnakeCase: !0
34
+ }).then((m) => {
35
+ t && s(m.data, p, C).then(
34
36
  (n) => {
35
- l(n), N(n.localeString), o !== n.localeString && c(n.localeString), T(i.EMMIT_EVENT_HOST_LOCALE_CHANGE, n);
37
+ l(n), N(n.localeString), o !== n.localeString && c(n.localeString), T(a.EMMIT_EVENT_HOST_LOCALE_CHANGE, n);
36
38
  }
37
39
  );
38
40
  }).finally(() => {
@@ -44,14 +46,14 @@ function B(_) {
44
46
  const M = (t) => {
45
47
  (t.lang !== r.lang || t.script !== r.script || t.region !== r.region) && c(V(t));
46
48
  };
47
- return /* @__PURE__ */ m(
48
- U.Provider,
49
+ return /* @__PURE__ */ f(
50
+ b.Provider,
49
51
  {
50
52
  value: {
51
53
  currentLocale: r,
52
54
  onChangeLocale: M
53
55
  },
54
- children: /* @__PURE__ */ m(
56
+ children: /* @__PURE__ */ f(
55
57
  x,
56
58
  {
57
59
  dateAdapter: k,
@@ -64,6 +66,6 @@ function B(_) {
64
66
  );
65
67
  }
66
68
  export {
67
- U as L,
69
+ b as L,
68
70
  B as a
69
71
  };
@@ -8,7 +8,7 @@ export interface BaseLocale {
8
8
  }
9
9
  export interface NetworkLocaleType extends BaseLocale {
10
10
  name: string;
11
- url_icon: string;
11
+ urlIcon: string;
12
12
  }
13
13
  export interface LocaleType extends NetworkLocaleType {
14
14
  module: Locale;
@@ -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
@@ -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,72 @@
1
+ import { useState as n, useRef as H, useCallback as L, useEffect as m } from "react";
2
+ import { i as s } from "./types.js";
3
+ import { useHostTools as U, useNetwork as j } from "@m4l/core";
4
+ const J = (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: E = [],
20
+ externalCondition: c = !0,
21
+ onNetworkError: f
22
+ } = h, [p, g] = n(i ? 1 : 0), [O, a] = n(E), [b, o] = n({ ...s, rowsPerPage: u }), t = H({ ...s, rowsPerPage: u }), [x, F] = n(R), { startProgress: N, stopProgress: Q } = U(), { networkOperation: q } = j(), l = L(() => {
23
+ g((r) => r + 1);
24
+ }, []);
25
+ return m(() => {
26
+ if (x) {
27
+ F(!1);
28
+ return;
29
+ }
30
+ t.current.page = 0, i && l();
31
+ }, [P]), m(() => {
32
+ let r = !0;
33
+ if (!(!c || p === 0))
34
+ return q({
35
+ method: "GET",
36
+ endPoint: w,
37
+ timeout: C,
38
+ parms: {
39
+ ...P,
40
+ page: t.current.page,
41
+ limit: t.current.rowsPerPage
42
+ },
43
+ bodyToSnakeCase: y,
44
+ responseToCamelCase: T,
45
+ options: {
46
+ startProgress: d || N,
47
+ stopProgress: S || Q
48
+ },
49
+ isRemote: k
50
+ }).then((e) => {
51
+ r && (a(e.data), t.current.page = e.pager.page, o((G) => ({
52
+ ...G,
53
+ page: e.pager.page,
54
+ // rowsPerPage: response.pager.limit,
55
+ totalRecords: e.pager.total
56
+ })));
57
+ }).catch((e) => {
58
+ a([]), o(s), f && f(e.status);
59
+ }), function() {
60
+ r = !1;
61
+ };
62
+ }, [p, c]), { onPageChange: (r) => {
63
+ t.current.page = r, g((e) => e + 1);
64
+ }, onRowsPerPageChange: (r) => {
65
+ t.current.rowsPerPage = r, o((e) => ({ ...e, rowsPerPage: r })), g((e) => e + 1);
66
+ }, pagerState: b, rows: O, clearRows: () => {
67
+ a([]), o(s);
68
+ }, Refresh: l, setRows: a };
69
+ };
70
+ export {
71
+ J as u
72
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { AxiosOptions, 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
+ }
@@ -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.9",
3
+ "version": "7.0.11-beta.1",
4
4
  "license": "UNLICENSED",
5
5
  "author": "M4L Team*",
6
6
  "type": "module",
@@ -17,7 +17,7 @@
17
17
  "zustand": "4.3.6"
18
18
  },
19
19
  "peerDependencies": {
20
- "@m4l/core": "^2.0.15",
20
+ "@m4l/core": "2.0.20-beta.1",
21
21
  "@m4l/styles": "^7.1.18",
22
22
  "@mui/material": "5.16.7",
23
23
  "@mui/x-date-pickers": "6.20.2",