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