@chimera-pe/mui-saas 3.0.17 → 3.0.18

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