@chimera-pe/mui-saas 3.0.9 → 3.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/dist/mui-saas.js CHANGED
@@ -1,39 +1,39 @@
1
- import { jsxs as d, jsx as i, Fragment as M } from "react/jsx-runtime";
2
- import n from "prop-types";
3
- import { useSaasStore as E, SaasApp as L } from "@chimera-pe/react-saas";
4
- import { useEffect as b, useMemo as O, useState as v, Children as B, cloneElement as F, useCallback as G } from "react";
5
- import { useMediaQuery as H, createTheme as Q, ThemeProvider as U, CssBaseline as $, Snackbar as J, Alert as j, Box as z, CircularProgress as K, AlertTitle as V, List as W, ListItem as X, ListItemText as Y, Skeleton as Z, Card as T, CardHeader as P, CardContent as S, LinearProgress as _, Typography as ee, CardActions as ie, TablePagination as re } from "@mui/material";
6
- import { grey as x } from "@mui/material/colors";
7
- import { create as ne } from "zustand";
1
+ import { jsxs as u, jsx as n, Fragment as B } from "react/jsx-runtime";
2
+ import i from "prop-types";
3
+ import { useSaasStore as G, SaasApp as H } from "@chimera-pe/react-saas";
4
+ import { useEffect as b, useMemo as Q, useState as z, Children as U, cloneElement as $, useCallback as J } from "react";
5
+ import { useMediaQuery as K, createTheme as _, ThemeProvider as V, CssBaseline as W, Snackbar as X, Alert as R, Box as k, CircularProgress as Y, AlertTitle as Z, List as ee, ListItem as ne, ListItemText as re, Skeleton as ie, Card as S, CardHeader as x, CardContent as v, LinearProgress as ae, Typography as oe, CardActions as te, TablePagination as se } from "@mui/material";
6
+ import { grey as j } from "@mui/material/colors";
7
+ import { create as ce } from "zustand";
8
8
  import { useTranslate as C } from "react-polyglot";
9
- import { get as oe } from "lodash";
10
- import { useQuery as te } from "@tanstack/react-query";
11
- const f = ne((o) => ({
9
+ import { get as le } from "lodash";
10
+ import { useQuery as pe } from "@tanstack/react-query";
11
+ const f = ce((a) => ({
12
12
  tema: "light",
13
13
  notificaciones: [],
14
14
  cambiarTema: (r) => {
15
- o({
15
+ a({
16
16
  tema: r
17
17
  });
18
18
  },
19
19
  mostrarNotificacion: (r) => {
20
- o((t) => ({
21
- notificaciones: [r, ...t.notificaciones]
20
+ a((o) => ({
21
+ notificaciones: [r, ...o.notificaciones]
22
22
  }));
23
23
  },
24
24
  ocultarNotificacion: () => {
25
- o((r) => ({
25
+ a((r) => ({
26
26
  notificaciones: r.notificaciones.slice(1)
27
27
  }));
28
28
  }
29
- })), R = ({ children: o }) => {
30
- const r = f((s) => s.cambiarTema), t = H("(prefers-color-scheme: dark)"), a = f((s) => s.tema), e = E((s) => s.instancia);
29
+ })), A = ({ children: a }) => {
30
+ const r = f((s) => s.cambiarTema), o = K("(prefers-color-scheme: dark)"), t = f((s) => s.tema), e = G((s) => s.instancia);
31
31
  b(() => {
32
- r(t ? "dark" : "light");
33
- }, [r, t]);
34
- const l = O(() => Q({
32
+ r(o ? "dark" : "light");
33
+ }, [r, o]);
34
+ const c = Q(() => _({
35
35
  palette: {
36
- mode: a,
36
+ mode: t,
37
37
  primary: {
38
38
  main: e.color.primary
39
39
  },
@@ -52,190 +52,192 @@ const f = ne((o) => ({
52
52
  success: {
53
53
  main: e.color.success
54
54
  },
55
- ...a === "light" && {
55
+ ...t === "light" && {
56
56
  background: {
57
- default: x.A200,
58
- paper: x[100]
57
+ default: j.A200,
58
+ paper: j[100]
59
59
  }
60
60
  }
61
61
  },
62
62
  shape: {
63
63
  borderRadius: 6
64
64
  }
65
- }), [a, e]);
66
- return /* @__PURE__ */ d(U, { theme: l, children: [
67
- /* @__PURE__ */ i($, {}),
68
- o
65
+ }), [t, e]);
66
+ return /* @__PURE__ */ u(V, { theme: c, children: [
67
+ /* @__PURE__ */ n(W, {}),
68
+ a
69
69
  ] });
70
70
  };
71
- R.propTypes = {
72
- children: n.element.isRequired
71
+ A.propTypes = {
72
+ children: i.element.isRequired
73
73
  };
74
- const ae = () => {
75
- const o = C(), [r, t] = v(!1), a = f((s) => s.ocultarNotificacion), e = f((s) => s.notificaciones[0]);
74
+ const me = () => {
75
+ const a = C(), [r, o] = z(!1), t = f((s) => s.ocultarNotificacion), e = f((s) => s.notificaciones[0]);
76
76
  b(() => {
77
- t(!!e);
77
+ o(!!e);
78
78
  }, [e]);
79
- const l = () => {
80
- t(!1), a();
79
+ const c = () => {
80
+ o(!1), t();
81
81
  };
82
- return /* @__PURE__ */ i(
83
- J,
82
+ return /* @__PURE__ */ n(
83
+ X,
84
84
  {
85
85
  open: r,
86
- message: e ? e.tipo === "default" && o(e?.mensaje) : null,
86
+ message: e ? e.tipo === "default" && a(e?.mensaje) : null,
87
87
  autoHideDuration: 5e3,
88
- onClose: l,
88
+ onClose: c,
89
89
  anchorOrigin: e && {
90
90
  vertical: e?.posicion.vertical,
91
91
  horizontal: e?.posicion.horizontal
92
92
  },
93
- children: e && e?.tipo !== "default" && /* @__PURE__ */ i(j, { severity: e.tipo, children: o(e.mensaje) })
93
+ children: e && e?.tipo !== "default" && /* @__PURE__ */ n(R, { severity: e.tipo, children: a(e.mensaje) })
94
94
  }
95
95
  );
96
- }, se = ({
97
- aplicacion: o,
96
+ }, ge = ({
97
+ aplicacion: a,
98
98
  dev: r = !1,
99
- devBackendUrl: t,
100
- devAuthUrl: a,
99
+ devBackendUrl: o,
100
+ devAuthUrl: t,
101
101
  mensajes: e = {
102
102
  en: {},
103
103
  es: {}
104
104
  },
105
- children: l
106
- }) => /* @__PURE__ */ i(
107
- L,
105
+ children: c
106
+ }) => /* @__PURE__ */ n(
107
+ H,
108
108
  {
109
- aplicacion: o,
109
+ aplicacion: a,
110
110
  dev: r,
111
- devBackendUrl: t,
112
- devAuthUrl: a,
111
+ devBackendUrl: o,
112
+ devAuthUrl: t,
113
113
  mensajes: e,
114
- children: /* @__PURE__ */ i(R, { children: /* @__PURE__ */ d(M, { children: [
115
- l,
116
- /* @__PURE__ */ i(ae, {})
114
+ children: /* @__PURE__ */ n(A, { children: /* @__PURE__ */ u(B, { children: [
115
+ c,
116
+ /* @__PURE__ */ n(me, {})
117
117
  ] }) })
118
118
  }
119
119
  );
120
- se.propTypes = {
121
- aplicacion: n.string.isRequired,
122
- dev: n.bool,
123
- devBackendUrl: n.string,
124
- devAuthUrl: n.string,
125
- mensajes: n.object,
126
- children: n.element.isRequired
120
+ ge.propTypes = {
121
+ aplicacion: i.string.isRequired,
122
+ dev: i.bool,
123
+ devBackendUrl: i.string,
124
+ devAuthUrl: i.string,
125
+ mensajes: i.object,
126
+ children: i.element.isRequired
127
127
  };
128
- const Ce = () => /* @__PURE__ */ i(z, { sx: {
128
+ const ve = () => /* @__PURE__ */ n(k, { sx: {
129
129
  display: "flex",
130
130
  flexDirection: "column",
131
131
  flexGrow: 1,
132
132
  justifyContent: "center",
133
133
  alignItems: "center"
134
- }, children: /* @__PURE__ */ i(K, {}) }), k = ({ titulo: o, texto: r, align: t = "center", severity: a = "error" }) => {
134
+ }, children: /* @__PURE__ */ n(Y, {}) }), N = ({ titulo: a, texto: r, align: o = "center", severity: t = "error" }) => {
135
135
  const e = C();
136
- return /* @__PURE__ */ i(z, { sx: {
136
+ return /* @__PURE__ */ n(k, { sx: {
137
137
  display: "flex",
138
138
  flexDirection: "column",
139
139
  flexGrow: 1,
140
140
  justifyContent: "center",
141
- alignItems: t
142
- }, children: /* @__PURE__ */ d(j, { severity: a, children: [
143
- /* @__PURE__ */ i(V, { children: e(o) }),
141
+ alignItems: o
142
+ }, children: /* @__PURE__ */ u(R, { severity: t, children: [
143
+ /* @__PURE__ */ n(Z, { children: e(a) }),
144
144
  r && e(r)
145
145
  ] }) });
146
146
  };
147
- k.propTypes = {
148
- titulo: n.string.isRequired,
149
- texto: n.string,
150
- align: n.string,
151
- severity: n.string
147
+ N.propTypes = {
148
+ titulo: i.string.isRequired,
149
+ texto: i.string,
150
+ align: i.string,
151
+ severity: i.string
152
152
  };
153
- const ce = ({
154
- nombre: o,
153
+ const w = (a) => (a.match(/(\w+)(\.\w+)+/g) || []).length > 0, de = ({
154
+ nombre: a,
155
155
  elevation: r = 1,
156
- api: t,
157
- filtros: a,
156
+ api: o,
157
+ filtros: t,
158
158
  titulo: e,
159
- tamanioInicial: l = 10,
160
- ubicacionTotal: s = "totalElements",
161
- children: w
159
+ subtitulo: c,
160
+ tamanioInicial: s = 10,
161
+ ubicacionTotal: q = "totalElements",
162
+ children: D
162
163
  }) => {
163
- const u = C(), [p, y] = v({
164
+ const g = C(), [p, y] = z({
164
165
  page: 0,
165
- pageSize: l
166
- });
166
+ pageSize: s
167
+ }), I = JSON.stringify(t);
167
168
  b(() => {
168
- y((c) => ({
169
- ...c,
169
+ y((l) => ({
170
+ ...l,
170
171
  page: 0
171
172
  }));
172
- }, [JSON.stringify(a)]);
173
- const { isLoading: h, isError: A, data: g } = te({
174
- queryKey: [`paginable-${o}`, p, a],
175
- queryFn: () => t(a, p.page, p.pageSize),
173
+ }, [I]);
174
+ const { isLoading: h, isError: M, data: d } = pe({
175
+ queryKey: [`paginable-${a}`, p, t],
176
+ queryFn: () => o(t, p.page, p.pageSize),
176
177
  keepPreviousData: !0
177
- });
178
+ }), T = e && w(e) ? g(e) : e, L = c && w(c) ? g(c) : c;
178
179
  if (h)
179
- return /* @__PURE__ */ i(W, { children: Array.from(Array(l).keys()).map((c) => /* @__PURE__ */ i(X, { children: /* @__PURE__ */ i(Y, { primary: /* @__PURE__ */ i(Z, {}) }) }, `row-${c}`)) });
180
- if (A)
181
- return /* @__PURE__ */ d(T, { children: [
182
- /* @__PURE__ */ i(P, { titulo: u(e) }),
183
- /* @__PURE__ */ i(S, { children: /* @__PURE__ */ i(k, { titulo: "main.paginable.error.carga" }) })
180
+ return /* @__PURE__ */ n(ee, { children: Array.from(Array(s).keys()).map((l) => /* @__PURE__ */ n(ne, { children: /* @__PURE__ */ n(re, { primary: /* @__PURE__ */ n(ie, {}) }) }, `row-${l}`)) });
181
+ if (M)
182
+ return /* @__PURE__ */ u(S, { children: [
183
+ /* @__PURE__ */ n(x, { titulo: g(e) }),
184
+ /* @__PURE__ */ n(v, { children: /* @__PURE__ */ n(N, { titulo: "main.paginable.error.carga" }) })
184
185
  ] });
185
- const N = (c, m) => {
186
+ const E = (l, m) => {
186
187
  h || m === p.page || y({
187
188
  page: m,
188
189
  pageSize: p.pageSize
189
190
  });
190
- }, q = (c) => {
191
- const m = c.target.value;
191
+ }, F = (l) => {
192
+ const m = l.target.value;
192
193
  h || m === p.pageSize || y({
193
194
  page: 0,
194
195
  pageSize: m
195
196
  });
196
- }, D = oe(g, s, 0);
197
- return /* @__PURE__ */ d(T, { elevation: r, children: [
198
- e && /* @__PURE__ */ i(P, { titulo: u(e) }),
199
- /* @__PURE__ */ i(S, { children: h ? /* @__PURE__ */ i(_, {}) : g && g.content.length > 0 ? B.map(w, (c) => F(c, {
200
- data: g.content
201
- })) : /* @__PURE__ */ i(ee, { children: u("main.paginable.sinResultados") }) }),
202
- g && g.totalElements > 0 && /* @__PURE__ */ i(ie, { sx: { justifyContent: "flex-end" }, children: /* @__PURE__ */ i(
203
- re,
197
+ }, P = le(d, q, 0);
198
+ return /* @__PURE__ */ u(S, { elevation: r, children: [
199
+ T && /* @__PURE__ */ n(x, { title: T, subheader: L }),
200
+ /* @__PURE__ */ n(v, { children: h ? /* @__PURE__ */ n(ae, {}) : d && d.content.length > 0 ? U.map(D, (l) => $(l, {
201
+ data: d.content
202
+ })) : /* @__PURE__ */ n(oe, { children: g("main.paginable.sinResultados") }) }),
203
+ d && P > 0 && /* @__PURE__ */ n(te, { sx: { justifyContent: "flex-end" }, children: /* @__PURE__ */ n(
204
+ se,
204
205
  {
205
206
  component: "div",
206
- count: D,
207
+ count: P,
207
208
  page: p.page,
208
209
  rowsPerPage: p.pageSize,
209
- labelRowsPerPage: u("main.paginable.filas"),
210
- labelDisplayedRows: ({ from: c, to: m, count: I }) => u("main.paginable.resultados", { inicial: c, final: m, total: I }),
210
+ labelRowsPerPage: g("main.paginable.filas"),
211
+ labelDisplayedRows: ({ from: l, to: m, count: O }) => g("main.paginable.resultados", { inicial: l, final: m, total: O }),
211
212
  rowsPerPageOptions: [5, 10, 15, 20, 25, 50],
212
- onRowsPerPageChange: q,
213
- onPageChange: N
213
+ onRowsPerPageChange: F,
214
+ onPageChange: E
214
215
  }
215
216
  ) })
216
217
  ] });
217
218
  };
218
- ce.propTypes = {
219
- nombre: n.string.isRequired,
220
- elevation: n.number,
221
- api: n.func.isRequired,
222
- filtros: n.object,
223
- titulo: n.string,
224
- tamanioInicial: n.number,
225
- ubicacionTotal: n.string,
226
- children: n.element
219
+ de.propTypes = {
220
+ nombre: i.string.isRequired,
221
+ elevation: i.number,
222
+ api: i.func.isRequired,
223
+ filtros: i.object,
224
+ titulo: i.string,
225
+ subtitulo: i.string,
226
+ tamanioInicial: i.number,
227
+ ubicacionTotal: i.string,
228
+ children: i.element
227
229
  };
228
- const Te = () => {
229
- const o = f((r) => r.mostrarNotificacion);
230
- return G((r, t = "default", a = { vertical: "botton", horizontal: "center" }) => {
231
- o({ mensaje: r, tipo: t, posicion: a });
232
- }, [o]);
230
+ const je = () => {
231
+ const a = f((r) => r.mostrarNotificacion);
232
+ return J((r, o = "default", t = { vertical: "botton", horizontal: "center" }) => {
233
+ a({ mensaje: r, tipo: o, posicion: t });
234
+ }, [a]);
233
235
  };
234
236
  export {
235
- Ce as Cargando,
236
- k as Mensaje,
237
- se as MuiApp,
238
- ce as Paginable,
237
+ ve as Cargando,
238
+ N as Mensaje,
239
+ ge as MuiApp,
240
+ de as Paginable,
239
241
  f as useMuiStore,
240
- Te as useNotificar
242
+ je as useNotificar
241
243
  };
@@ -1 +1 @@
1
- (function(r,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("prop-types"),require("@chimera-pe/react-saas"),require("react"),require("@mui/material"),require("@mui/material/colors"),require("zustand"),require("react-polyglot"),require("lodash"),require("@tanstack/react-query")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","prop-types","@chimera-pe/react-saas","react","@mui/material","@mui/material/colors","zustand","react-polyglot","lodash","@tanstack/react-query"],e):(r=typeof globalThis<"u"?globalThis:r||self,e(r["mui-saas"]={},r.ReactJSX,r.PropTypes,r.ReactSaas,r.React,r.MuiMaterial,r.MuiMaterialColors,r.Zustand,r.ReactPolyglot,r.Lodash,r.ReactQuery))})(this,(function(r,e,t,v,u,i,j,x,m,A,N){"use strict";const p=x.create(o=>({tema:"light",notificaciones:[],cambiarTema:a=>{o({tema:a})},mostrarNotificacion:a=>{o(s=>({notificaciones:[a,...s.notificaciones]}))},ocultarNotificacion:()=>{o(a=>({notificaciones:a.notificaciones.slice(1)}))}})),M=({children:o})=>{const a=p(l=>l.cambiarTema),s=i.useMediaQuery("(prefers-color-scheme: dark)"),c=p(l=>l.tema),n=v.useSaasStore(l=>l.instancia);u.useEffect(()=>{a(s?"dark":"light")},[a,s]);const f=u.useMemo(()=>i.createTheme({palette:{mode:c,primary:{main:n.color.primary},secondary:{main:n.color.secondary},error:{main:n.color.error},warning:{main:n.color.warning},info:{main:n.color.info},success:{main:n.color.success},...c==="light"&&{background:{default:j.grey.A200,paper:j.grey[100]}}},shape:{borderRadius:6}}),[c,n]);return e.jsxs(i.ThemeProvider,{theme:f,children:[e.jsx(i.CssBaseline,{}),o]})};M.propTypes={children:t.element.isRequired};const w=()=>{const o=m.useTranslate(),[a,s]=u.useState(!1),c=p(l=>l.ocultarNotificacion),n=p(l=>l.notificaciones[0]);u.useEffect(()=>{s(!!n)},[n]);const f=()=>{s(!1),c()};return e.jsx(i.Snackbar,{open:a,message:n?n.tipo==="default"&&o(n?.mensaje):null,autoHideDuration:5e3,onClose:f,anchorOrigin:n&&{vertical:n?.posicion.vertical,horizontal:n?.posicion.horizontal},children:n&&n?.tipo!=="default"&&e.jsx(i.Alert,{severity:n.tipo,children:o(n.mensaje)})})},z=({aplicacion:o,dev:a=!1,devBackendUrl:s,devAuthUrl:c,mensajes:n={en:{},es:{}},children:f})=>e.jsx(v.SaasApp,{aplicacion:o,dev:a,devBackendUrl:s,devAuthUrl:c,mensajes:n,children:e.jsx(M,{children:e.jsxs(e.Fragment,{children:[f,e.jsx(w,{})]})})});z.propTypes={aplicacion:t.string.isRequired,dev:t.bool,devBackendUrl:t.string,devAuthUrl:t.string,mensajes:t.object,children:t.element.isRequired};const E=()=>e.jsx(i.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:"center"},children:e.jsx(i.CircularProgress,{})}),q=({titulo:o,texto:a,align:s="center",severity:c="error"})=>{const n=m.useTranslate();return e.jsx(i.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:s},children:e.jsxs(i.Alert,{severity:c,children:[e.jsx(i.AlertTitle,{children:n(o)}),a&&n(a)]})})};q.propTypes={titulo:t.string.isRequired,texto:t.string,align:t.string,severity:t.string};const k=({nombre:o,elevation:a=1,api:s,filtros:c,titulo:n,tamanioInicial:f=10,ubicacionTotal:l="totalElements",children:I})=>{const y=m.useTranslate(),[g,b]=u.useState({page:0,pageSize:f});u.useEffect(()=>{b(d=>({...d,page:0}))},[JSON.stringify(c)]);const{isLoading:S,isError:L,data:C}=N.useQuery({queryKey:[`paginable-${o}`,g,c],queryFn:()=>s(c,g.page,g.pageSize),keepPreviousData:!0});if(S)return e.jsx(i.List,{children:Array.from(Array(f).keys()).map(d=>e.jsx(i.ListItem,{children:e.jsx(i.ListItemText,{primary:e.jsx(i.Skeleton,{})})},`row-${d}`))});if(L)return e.jsxs(i.Card,{children:[e.jsx(i.CardHeader,{titulo:y(n)}),e.jsx(i.CardContent,{children:e.jsx(q,{titulo:"main.paginable.error.carga"})})]});const O=(d,h)=>{S||h===g.page||b({page:h,pageSize:g.pageSize})},B=d=>{const h=d.target.value;S||h===g.pageSize||b({page:0,pageSize:h})},T=A.get(C,l,0);return e.jsxs(i.Card,{elevation:a,children:[n&&e.jsx(i.CardHeader,{titulo:y(n)}),e.jsx(i.CardContent,{children:S?e.jsx(i.LinearProgress,{}):C&&C.content.length>0?u.Children.map(I,d=>u.cloneElement(d,{data:C.content})):e.jsx(i.Typography,{children:y("main.paginable.sinResultados")})}),C&&C.totalElements>0&&e.jsx(i.CardActions,{sx:{justifyContent:"flex-end"},children:e.jsx(i.TablePagination,{component:"div",count:T,page:g.page,rowsPerPage:g.pageSize,labelRowsPerPage:y("main.paginable.filas"),labelDisplayedRows:({from:d,to:h,count:H})=>y("main.paginable.resultados",{inicial:d,final:h,total:H}),rowsPerPageOptions:[5,10,15,20,25,50],onRowsPerPageChange:B,onPageChange:O})})]})};k.propTypes={nombre:t.string.isRequired,elevation:t.number,api:t.func.isRequired,filtros:t.object,titulo:t.string,tamanioInicial:t.number,ubicacionTotal:t.string,children:t.element};const D=()=>{const o=p(a=>a.mostrarNotificacion);return u.useCallback((a,s="default",c={vertical:"botton",horizontal:"center"})=>{o({mensaje:a,tipo:s,posicion:c})},[o])};r.Cargando=E,r.Mensaje=q,r.MuiApp=z,r.Paginable=k,r.useMuiStore=p,r.useNotificar=D,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(r,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("prop-types"),require("@chimera-pe/react-saas"),require("react"),require("@mui/material"),require("@mui/material/colors"),require("zustand"),require("react-polyglot"),require("lodash"),require("@tanstack/react-query")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","prop-types","@chimera-pe/react-saas","react","@mui/material","@mui/material/colors","zustand","react-polyglot","lodash","@tanstack/react-query"],e):(r=typeof globalThis<"u"?globalThis:r||self,e(r["mui-saas"]={},r.ReactJSX,r.PropTypes,r.ReactSaas,r.React,r.MuiMaterial,r.MuiMaterialColors,r.Zustand,r.ReactPolyglot,r.Lodash,r.ReactQuery))})(this,(function(r,e,t,v,f,i,j,N,m,D,E){"use strict";const p=N.create(o=>({tema:"light",notificaciones:[],cambiarTema:a=>{o({tema:a})},mostrarNotificacion:a=>{o(s=>({notificaciones:[a,...s.notificaciones]}))},ocultarNotificacion:()=>{o(a=>({notificaciones:a.notificaciones.slice(1)}))}})),M=({children:o})=>{const a=p(l=>l.cambiarTema),s=i.useMediaQuery("(prefers-color-scheme: dark)"),c=p(l=>l.tema),n=v.useSaasStore(l=>l.instancia);f.useEffect(()=>{a(s?"dark":"light")},[a,s]);const d=f.useMemo(()=>i.createTheme({palette:{mode:c,primary:{main:n.color.primary},secondary:{main:n.color.secondary},error:{main:n.color.error},warning:{main:n.color.warning},info:{main:n.color.info},success:{main:n.color.success},...c==="light"&&{background:{default:j.grey.A200,paper:j.grey[100]}}},shape:{borderRadius:6}}),[c,n]);return e.jsxs(i.ThemeProvider,{theme:d,children:[e.jsx(i.CssBaseline,{}),o]})};M.propTypes={children:t.element.isRequired};const I=()=>{const o=m.useTranslate(),[a,s]=f.useState(!1),c=p(l=>l.ocultarNotificacion),n=p(l=>l.notificaciones[0]);f.useEffect(()=>{s(!!n)},[n]);const d=()=>{s(!1),c()};return e.jsx(i.Snackbar,{open:a,message:n?n.tipo==="default"&&o(n?.mensaje):null,autoHideDuration:5e3,onClose:d,anchorOrigin:n&&{vertical:n?.posicion.vertical,horizontal:n?.posicion.horizontal},children:n&&n?.tipo!=="default"&&e.jsx(i.Alert,{severity:n.tipo,children:o(n.mensaje)})})},z=({aplicacion:o,dev:a=!1,devBackendUrl:s,devAuthUrl:c,mensajes:n={en:{},es:{}},children:d})=>e.jsx(v.SaasApp,{aplicacion:o,dev:a,devBackendUrl:s,devAuthUrl:c,mensajes:n,children:e.jsx(M,{children:e.jsxs(e.Fragment,{children:[d,e.jsx(I,{})]})})});z.propTypes={aplicacion:t.string.isRequired,dev:t.bool,devBackendUrl:t.string,devAuthUrl:t.string,mensajes:t.object,children:t.element.isRequired};const L=()=>e.jsx(i.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:"center"},children:e.jsx(i.CircularProgress,{})}),q=({titulo:o,texto:a,align:s="center",severity:c="error"})=>{const n=m.useTranslate();return e.jsx(i.Box,{sx:{display:"flex",flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:s},children:e.jsxs(i.Alert,{severity:c,children:[e.jsx(i.AlertTitle,{children:n(o)}),a&&n(a)]})})};q.propTypes={titulo:t.string.isRequired,texto:t.string,align:t.string,severity:t.string};const k=o=>(o.match(/(\w+)(\.\w+)+/g)||[]).length>0,x=({nombre:o,elevation:a=1,api:s,filtros:c,titulo:n,subtitulo:d,tamanioInicial:l=10,ubicacionTotal:B="totalElements",children:F})=>{const C=m.useTranslate(),[g,b]=f.useState({page:0,pageSize:l}),T=JSON.stringify(c);f.useEffect(()=>{b(u=>({...u,page:0}))},[T]);const{isLoading:S,isError:H,data:y}=E.useQuery({queryKey:[`paginable-${o}`,g,c],queryFn:()=>s(c,g.page,g.pageSize),keepPreviousData:!0}),w=n&&k(n)?C(n):n,Q=d&&k(d)?C(d):d;if(S)return e.jsx(i.List,{children:Array.from(Array(l).keys()).map(u=>e.jsx(i.ListItem,{children:e.jsx(i.ListItemText,{primary:e.jsx(i.Skeleton,{})})},`row-${u}`))});if(H)return e.jsxs(i.Card,{children:[e.jsx(i.CardHeader,{titulo:C(n)}),e.jsx(i.CardContent,{children:e.jsx(q,{titulo:"main.paginable.error.carga"})})]});const G=(u,h)=>{S||h===g.page||b({page:h,pageSize:g.pageSize})},J=u=>{const h=u.target.value;S||h===g.pageSize||b({page:0,pageSize:h})},A=D.get(y,B,0);return e.jsxs(i.Card,{elevation:a,children:[w&&e.jsx(i.CardHeader,{title:w,subheader:Q}),e.jsx(i.CardContent,{children:S?e.jsx(i.LinearProgress,{}):y&&y.content.length>0?f.Children.map(F,u=>f.cloneElement(u,{data:y.content})):e.jsx(i.Typography,{children:C("main.paginable.sinResultados")})}),y&&A>0&&e.jsx(i.CardActions,{sx:{justifyContent:"flex-end"},children:e.jsx(i.TablePagination,{component:"div",count:A,page:g.page,rowsPerPage:g.pageSize,labelRowsPerPage:C("main.paginable.filas"),labelDisplayedRows:({from:u,to:h,count:U})=>C("main.paginable.resultados",{inicial:u,final:h,total:U}),rowsPerPageOptions:[5,10,15,20,25,50],onRowsPerPageChange:J,onPageChange:G})})]})};x.propTypes={nombre:t.string.isRequired,elevation:t.number,api:t.func.isRequired,filtros:t.object,titulo:t.string,subtitulo:t.string,tamanioInicial:t.number,ubicacionTotal:t.string,children:t.element};const O=()=>{const o=p(a=>a.mostrarNotificacion);return f.useCallback((a,s="default",c={vertical:"botton",horizontal:"center"})=>{o({mensaje:a,tipo:s,posicion:c})},[o])};r.Cargando=L,r.Mensaje=q,r.MuiApp=z,r.Paginable=x,r.useMuiStore=p,r.useNotificar=O,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chimera-pe/mui-saas",
3
3
  "description": "Librería con componentes comunes para MUI, usando SaaS",
4
- "version": "3.0.9",
4
+ "version": "3.0.11",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -52,6 +52,6 @@
52
52
  "eslint-plugin-react-hooks": "^5.2.0",
53
53
  "eslint-plugin-react-refresh": "^0.4.20",
54
54
  "globals": "^16.3.0",
55
- "vite": "^7.1.3"
55
+ "vite": "^7.1.4"
56
56
  }
57
57
  }