@trinityui/design-system 2.2.3 → 2.3.0
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/CHANGELOG.md +78 -0
- package/dist/app-shell.js +3985 -3338
- package/dist/components/AI/AIVoiceMode.d.ts +55 -0
- package/dist/components/AI/AIVoiceMode.d.ts.map +1 -0
- package/dist/components/AI/InsightEngineInput.d.ts +81 -4
- package/dist/components/AI/InsightEngineInput.d.ts.map +1 -1
- package/dist/components/AI/index.d.ts +3 -1
- package/dist/components/AI/index.d.ts.map +1 -1
- package/dist/components/AI/tokens.d.ts +7 -0
- package/dist/components/AI/tokens.d.ts.map +1 -1
- package/dist/components/AI/useBrowserVoiceMode.d.ts +61 -0
- package/dist/components/AI/useBrowserVoiceMode.d.ts.map +1 -0
- package/dist/components/Combobox/Combobox.d.ts.map +1 -1
- package/dist/components/Icon.d.ts.map +1 -1
- package/dist/components/TrinityLoader.d.ts +43 -0
- package/dist/components/TrinityLoader.d.ts.map +1 -0
- package/dist/forms.js +279 -266
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17803 -17594
- package/dist/tokens.js +4 -4
- package/dist/trinity.css +1 -1
- package/package.json +1 -1
package/dist/forms.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { jsxs as f, jsx as e, Fragment as
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
4
|
-
import { useTheme as Me, Paper as
|
|
5
|
-
import { Check as
|
|
6
|
-
import
|
|
1
|
+
import { jsxs as f, jsx as e, Fragment as Se } from "react/jsx-runtime";
|
|
2
|
+
import * as M from "react";
|
|
3
|
+
import Oe, { createElement as Re, useState as le, useRef as Fe, useCallback as A } from "react";
|
|
4
|
+
import { useTheme as Me, Paper as pe, Box as L, ListItem as ue, alpha as he, ListItemIcon as te, Checkbox as ge, ListItemText as me, Divider as ye, Button as fe, Autocomplete as Ae, Typography as _, Popper as Be, Chip as Ie, TextField as Ee, Alert as ve, Stack as ze, List as We, LinearProgress as je, ListItemSecondaryAction as Te, IconButton as $e } from "@mui/material";
|
|
5
|
+
import { Check as ce, Add as Ue, Close as be } from "@mui/icons-material";
|
|
6
|
+
import de from "@mui/icons-material/CloudUpload";
|
|
7
7
|
import Ve from "@mui/icons-material/InsertDriveFile";
|
|
8
|
-
import
|
|
8
|
+
import Ke from "@mui/icons-material/Delete";
|
|
9
9
|
import ke from "@mui/icons-material/CheckCircle";
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
10
|
+
import _e from "@mui/icons-material/Error";
|
|
11
|
+
import qe from "@mui/icons-material/PictureAsPdf";
|
|
12
|
+
import Ge from "@mui/icons-material/Image";
|
|
13
13
|
import Ne from "@mui/icons-material/VideoLibrary";
|
|
14
14
|
import He from "@mui/icons-material/Description";
|
|
15
15
|
import { s as Ce } from "./app-shell.js";
|
|
16
|
-
const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, Je = (
|
|
16
|
+
const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, Je = (d) => /* @__PURE__ */ e(
|
|
17
17
|
Be,
|
|
18
18
|
{
|
|
19
|
-
...
|
|
19
|
+
...d,
|
|
20
20
|
placement: "bottom-start",
|
|
21
21
|
modifiers: [
|
|
22
22
|
{
|
|
@@ -27,100 +27,110 @@ const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
|
27
27
|
}
|
|
28
28
|
]
|
|
29
29
|
}
|
|
30
|
-
), pr =
|
|
31
|
-
options:
|
|
32
|
-
value:
|
|
33
|
-
defaultValue:
|
|
34
|
-
onChange:
|
|
35
|
-
creatable:
|
|
36
|
-
onCreate:
|
|
37
|
-
createText:
|
|
38
|
-
multiple:
|
|
39
|
-
placeholder:
|
|
40
|
-
label:
|
|
41
|
-
helperText:
|
|
42
|
-
error:
|
|
43
|
-
errorMessage:
|
|
44
|
-
disabled:
|
|
45
|
-
fullWidth:
|
|
46
|
-
size:
|
|
47
|
-
limitTags:
|
|
48
|
-
showCheckbox:
|
|
49
|
-
groupBy:
|
|
50
|
-
loading:
|
|
51
|
-
noOptionsText:
|
|
52
|
-
filterOptions:
|
|
53
|
-
renderOption:
|
|
54
|
-
renderTag:
|
|
30
|
+
), pr = M.forwardRef(function({
|
|
31
|
+
options: p,
|
|
32
|
+
value: s,
|
|
33
|
+
defaultValue: S,
|
|
34
|
+
onChange: x,
|
|
35
|
+
creatable: w = !1,
|
|
36
|
+
onCreate: I,
|
|
37
|
+
createText: B = 'Create "{value}"',
|
|
38
|
+
multiple: u = !1,
|
|
39
|
+
placeholder: Y = "Select...",
|
|
40
|
+
label: q,
|
|
41
|
+
helperText: l,
|
|
42
|
+
error: G = !1,
|
|
43
|
+
errorMessage: oe,
|
|
44
|
+
disabled: Z = !1,
|
|
45
|
+
fullWidth: V = !1,
|
|
46
|
+
size: j = "medium",
|
|
47
|
+
limitTags: N = 3,
|
|
48
|
+
showCheckbox: T = !0,
|
|
49
|
+
groupBy: ee = !1,
|
|
50
|
+
loading: K = !1,
|
|
51
|
+
noOptionsText: H = "No options",
|
|
52
|
+
filterOptions: J,
|
|
53
|
+
renderOption: Q,
|
|
54
|
+
renderTag: $,
|
|
55
55
|
freeSolo: g = !1,
|
|
56
|
-
autoHighlight:
|
|
57
|
-
clearOnEscape:
|
|
58
|
-
showSelectAll:
|
|
59
|
-
selectAllText:
|
|
60
|
-
className:
|
|
61
|
-
sx:
|
|
56
|
+
autoHighlight: C = !0,
|
|
57
|
+
clearOnEscape: ne = !0,
|
|
58
|
+
showSelectAll: E = !1,
|
|
59
|
+
selectAllText: re = "Select All",
|
|
60
|
+
className: se,
|
|
61
|
+
sx: ae
|
|
62
62
|
}, ie) {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
),
|
|
63
|
+
const X = Me(), [y, U] = M.useState(""), [O, z] = M.useState(
|
|
64
|
+
S || []
|
|
65
|
+
), k = s !== void 0 ? s : O, r = M.useCallback(
|
|
66
66
|
(t, o) => {
|
|
67
|
-
if (
|
|
68
|
-
return
|
|
69
|
-
const
|
|
67
|
+
if (J)
|
|
68
|
+
return J(t, o);
|
|
69
|
+
const n = o.inputValue.toLowerCase();
|
|
70
70
|
return t.filter(
|
|
71
|
-
(
|
|
71
|
+
(a) => a.label.toLowerCase().includes(n) || a.secondary?.toLowerCase().includes(n)
|
|
72
72
|
);
|
|
73
73
|
},
|
|
74
|
-
[
|
|
75
|
-
),
|
|
76
|
-
(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
[J]
|
|
75
|
+
), c = M.useMemo(() => {
|
|
76
|
+
if (!w || !y.trim()) return !1;
|
|
77
|
+
const t = y.trim().toLowerCase(), o = p.some(
|
|
78
|
+
(a) => a.label.toLowerCase() === t
|
|
79
|
+
), n = k.some(
|
|
80
|
+
(a) => a.label.toLowerCase() === t
|
|
81
|
+
);
|
|
82
|
+
return !o && !n;
|
|
83
|
+
}, [w, y, p, k]), D = async (t, o) => {
|
|
84
|
+
let n;
|
|
85
|
+
if (u) {
|
|
86
|
+
const m = o || [];
|
|
87
|
+
n = await Promise.all(
|
|
88
|
+
m.map(async (P) => typeof P == "string" ? w && I ? await I(P) : { id: xe(), label: P } : P)
|
|
83
89
|
);
|
|
84
90
|
} else
|
|
85
|
-
o === null ?
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
o === null ? n = [] : typeof o == "string" ? w && I ? n = [await I(o)] : n = [{ id: xe(), label: o }] : n = [o];
|
|
92
|
+
const a = /* @__PURE__ */ new Set(), b = /* @__PURE__ */ new Set();
|
|
93
|
+
n = n.filter((m) => {
|
|
94
|
+
const P = m.label.toLowerCase();
|
|
95
|
+
return a.has(m.id) || b.has(P) ? !1 : (a.add(m.id), b.add(P), !0);
|
|
96
|
+
}), z(n), x?.(n);
|
|
97
|
+
}, R = M.useMemo(() => {
|
|
98
|
+
const t = p.filter((o) => !o.disabled);
|
|
89
99
|
return t.length > 0 && t.every(
|
|
90
|
-
(o) =>
|
|
100
|
+
(o) => k.some((n) => n.id === o.id)
|
|
91
101
|
);
|
|
92
|
-
}, [
|
|
102
|
+
}, [p, k]), v = M.useCallback(() => {
|
|
93
103
|
if (R)
|
|
94
|
-
|
|
104
|
+
z([]), x?.([]);
|
|
95
105
|
else {
|
|
96
|
-
const t =
|
|
97
|
-
|
|
106
|
+
const t = p.filter((o) => !o.disabled);
|
|
107
|
+
z(t), x?.(t);
|
|
98
108
|
}
|
|
99
|
-
}, [R,
|
|
100
|
-
if (!
|
|
101
|
-
const t = await
|
|
102
|
-
|
|
103
|
-
}, [
|
|
109
|
+
}, [R, p, x]), h = M.useCallback(async () => {
|
|
110
|
+
if (!c || !I) return;
|
|
111
|
+
const t = await I(y), o = u ? [...k, t] : [t];
|
|
112
|
+
z(o), x?.(o), U("");
|
|
113
|
+
}, [c, I, y, u, k, x]), W = (t) => /* @__PURE__ */ e(
|
|
104
114
|
Ee,
|
|
105
115
|
{
|
|
106
116
|
...t,
|
|
107
|
-
label:
|
|
108
|
-
placeholder:
|
|
109
|
-
error:
|
|
110
|
-
helperText:
|
|
111
|
-
size:
|
|
117
|
+
label: q,
|
|
118
|
+
placeholder: k.length === 0 ? Y : void 0,
|
|
119
|
+
error: G,
|
|
120
|
+
helperText: G ? oe : l,
|
|
121
|
+
size: j
|
|
112
122
|
}
|
|
113
123
|
), F = (t, o) => {
|
|
114
|
-
const
|
|
115
|
-
return (Array.isArray(t) ? t : []).map((
|
|
116
|
-
const
|
|
117
|
-
return
|
|
124
|
+
const n = o;
|
|
125
|
+
return (Array.isArray(t) ? t : []).map((b, m) => {
|
|
126
|
+
const P = n({ index: m });
|
|
127
|
+
return $ ? $(b, P.onDelete) : /* @__PURE__ */ Re(
|
|
118
128
|
Ie,
|
|
119
129
|
{
|
|
120
|
-
...
|
|
121
|
-
key: typeof
|
|
122
|
-
label: typeof
|
|
123
|
-
size:
|
|
130
|
+
...P,
|
|
131
|
+
key: typeof b == "object" ? b.id : m,
|
|
132
|
+
label: typeof b == "object" ? b.label : String(b),
|
|
133
|
+
size: j,
|
|
124
134
|
deleteIcon: /* @__PURE__ */ e(be, { fontSize: "small" }),
|
|
125
135
|
sx: {
|
|
126
136
|
maxWidth: 150,
|
|
@@ -132,36 +142,36 @@ const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
|
132
142
|
}
|
|
133
143
|
);
|
|
134
144
|
});
|
|
135
|
-
}, i =
|
|
145
|
+
}, i = M.useCallback(
|
|
136
146
|
(t) => {
|
|
137
|
-
const { children: o, ...
|
|
138
|
-
return /* @__PURE__ */ f(
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
const { children: o, ...n } = t;
|
|
148
|
+
return /* @__PURE__ */ f(pe, { ...n, elevation: 8, children: [
|
|
149
|
+
u && E && /* @__PURE__ */ f(
|
|
150
|
+
L,
|
|
141
151
|
{
|
|
142
|
-
onMouseDown: (
|
|
143
|
-
|
|
152
|
+
onMouseDown: (a) => {
|
|
153
|
+
a.preventDefault(), a.stopPropagation();
|
|
144
154
|
},
|
|
145
|
-
onClick: (
|
|
146
|
-
|
|
155
|
+
onClick: (a) => {
|
|
156
|
+
a.preventDefault(), a.stopPropagation(), v();
|
|
147
157
|
},
|
|
148
158
|
children: [
|
|
149
159
|
/* @__PURE__ */ f(
|
|
150
|
-
|
|
160
|
+
ue,
|
|
151
161
|
{
|
|
152
162
|
dense: !0,
|
|
153
163
|
sx: {
|
|
154
164
|
cursor: "pointer",
|
|
155
165
|
"&:hover": {
|
|
156
|
-
backgroundColor: he(
|
|
166
|
+
backgroundColor: he(X.palette.primary.main, 0.08)
|
|
157
167
|
}
|
|
158
168
|
},
|
|
159
169
|
children: [
|
|
160
|
-
|
|
170
|
+
T && /* @__PURE__ */ e(te, { sx: { minWidth: 36, pointerEvents: "none" }, children: /* @__PURE__ */ e(
|
|
161
171
|
ge,
|
|
162
172
|
{
|
|
163
173
|
icon: /* @__PURE__ */ e(
|
|
164
|
-
|
|
174
|
+
L,
|
|
165
175
|
{
|
|
166
176
|
sx: {
|
|
167
177
|
width: 18,
|
|
@@ -174,7 +184,7 @@ const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
|
174
184
|
}
|
|
175
185
|
),
|
|
176
186
|
checkedIcon: /* @__PURE__ */ e(
|
|
177
|
-
|
|
187
|
+
L,
|
|
178
188
|
{
|
|
179
189
|
sx: {
|
|
180
190
|
width: 18,
|
|
@@ -188,7 +198,7 @@ const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
|
188
198
|
justifyContent: "center"
|
|
189
199
|
},
|
|
190
200
|
children: /* @__PURE__ */ e(
|
|
191
|
-
|
|
201
|
+
ce,
|
|
192
202
|
{
|
|
193
203
|
sx: {
|
|
194
204
|
width: 14,
|
|
@@ -206,9 +216,9 @@ const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
|
206
216
|
}
|
|
207
217
|
) }),
|
|
208
218
|
/* @__PURE__ */ e(
|
|
209
|
-
|
|
219
|
+
me,
|
|
210
220
|
{
|
|
211
|
-
primary: R ? "Deselect All" :
|
|
221
|
+
primary: R ? "Deselect All" : re,
|
|
212
222
|
slotProps: { primary: {
|
|
213
223
|
variant: "body2",
|
|
214
224
|
sx: { fontWeight: 500 }
|
|
@@ -223,13 +233,16 @@ const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
|
223
233
|
}
|
|
224
234
|
),
|
|
225
235
|
o,
|
|
226
|
-
|
|
236
|
+
c && /* @__PURE__ */ f(Se, { children: [
|
|
227
237
|
/* @__PURE__ */ e(ye, {}),
|
|
228
238
|
/* @__PURE__ */ e(
|
|
229
|
-
|
|
239
|
+
fe,
|
|
230
240
|
{
|
|
231
241
|
fullWidth: !0,
|
|
232
242
|
startIcon: /* @__PURE__ */ e(Ue, {}),
|
|
243
|
+
onMouseDown: (a) => {
|
|
244
|
+
a.preventDefault();
|
|
245
|
+
},
|
|
233
246
|
onClick: h,
|
|
234
247
|
sx: {
|
|
235
248
|
justifyContent: "flex-start",
|
|
@@ -239,109 +252,109 @@ const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
|
239
252
|
color: "primary.main",
|
|
240
253
|
borderRadius: 0,
|
|
241
254
|
"&:hover": {
|
|
242
|
-
backgroundColor: he(
|
|
255
|
+
backgroundColor: he(X.palette.primary.main, 0.08)
|
|
243
256
|
}
|
|
244
257
|
},
|
|
245
|
-
children:
|
|
258
|
+
children: B.replace("{value}", y)
|
|
246
259
|
}
|
|
247
260
|
)
|
|
248
261
|
] })
|
|
249
262
|
] });
|
|
250
263
|
},
|
|
251
|
-
[
|
|
252
|
-
), Le =
|
|
264
|
+
[c, B, y, X.palette.primary.main, h, u, E, T, v, R, re]
|
|
265
|
+
), Le = p;
|
|
253
266
|
return /* @__PURE__ */ e(
|
|
254
267
|
Ae,
|
|
255
268
|
{
|
|
256
269
|
ref: ie,
|
|
257
|
-
className:
|
|
258
|
-
sx: { width:
|
|
259
|
-
multiple:
|
|
270
|
+
className: se,
|
|
271
|
+
sx: { width: V ? "100%" : 300, ...ae },
|
|
272
|
+
multiple: u,
|
|
260
273
|
options: Le,
|
|
261
|
-
value:
|
|
262
|
-
onChange:
|
|
274
|
+
value: u ? k : k[0] || null,
|
|
275
|
+
onChange: D,
|
|
263
276
|
inputValue: y,
|
|
264
|
-
onInputChange: (t, o) =>
|
|
277
|
+
onInputChange: (t, o) => U(o),
|
|
265
278
|
getOptionLabel: (t) => typeof t == "string" ? t : t.label,
|
|
266
279
|
isOptionEqualToValue: (t, o) => t.id === o.id,
|
|
267
280
|
getOptionDisabled: (t) => typeof t == "object" && t.disabled === !0,
|
|
268
|
-
groupBy:
|
|
281
|
+
groupBy: ee ? (t) => t.group || "" : void 0,
|
|
269
282
|
filterOptions: r,
|
|
270
|
-
renderInput:
|
|
271
|
-
renderValue:
|
|
272
|
-
renderOption: (t, o, { selected:
|
|
273
|
-
const { key:
|
|
274
|
-
return
|
|
275
|
-
|
|
283
|
+
renderInput: W,
|
|
284
|
+
renderValue: u ? F : void 0,
|
|
285
|
+
renderOption: (t, o, { selected: n }) => {
|
|
286
|
+
const { key: a, ...b } = t, m = o;
|
|
287
|
+
return Q ? /* @__PURE__ */ e("li", { ...b, children: Q(m, { selected: n }) }, a) : /* @__PURE__ */ f(ue, { ...b, dense: !0, children: [
|
|
288
|
+
u && T && /* @__PURE__ */ e(te, { sx: { minWidth: 36 }, children: /* @__PURE__ */ e(
|
|
276
289
|
ge,
|
|
277
290
|
{
|
|
278
|
-
icon: /* @__PURE__ */ e(
|
|
279
|
-
checkedIcon: /* @__PURE__ */ e(
|
|
280
|
-
checked:
|
|
291
|
+
icon: /* @__PURE__ */ e(L, { sx: { width: 18, height: 18, border: "2px solid", borderColor: "action.active", borderRadius: 0.5, backgroundColor: "transparent" } }),
|
|
292
|
+
checkedIcon: /* @__PURE__ */ e(L, { sx: { width: 18, height: 18, border: "2px solid", borderColor: "primary.main", borderRadius: 0.5, backgroundColor: "primary.main", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(ce, { sx: { width: 14, height: 14, color: "primary.contrastText" } }) }),
|
|
293
|
+
checked: n,
|
|
281
294
|
size: "small"
|
|
282
295
|
}
|
|
283
296
|
) }),
|
|
284
|
-
|
|
297
|
+
m.icon && /* @__PURE__ */ e(te, { sx: { minWidth: 36 }, children: m.icon }),
|
|
285
298
|
/* @__PURE__ */ e(
|
|
286
|
-
|
|
299
|
+
me,
|
|
287
300
|
{
|
|
288
|
-
primary:
|
|
289
|
-
secondary:
|
|
301
|
+
primary: m.label,
|
|
302
|
+
secondary: m.secondary,
|
|
290
303
|
slotProps: { primary: { variant: "body2" }, secondary: { variant: "caption" } }
|
|
291
304
|
}
|
|
292
305
|
),
|
|
293
|
-
!
|
|
294
|
-
] },
|
|
306
|
+
!u && n && /* @__PURE__ */ e(ce, { sx: { ml: 1, color: "primary.main" }, fontSize: "small" })
|
|
307
|
+
] }, a);
|
|
295
308
|
},
|
|
296
309
|
slots: {
|
|
297
|
-
paper:
|
|
310
|
+
paper: w || u && E ? i : pe,
|
|
298
311
|
popper: Je
|
|
299
312
|
},
|
|
300
|
-
limitTags:
|
|
301
|
-
disabled:
|
|
302
|
-
loading:
|
|
303
|
-
noOptionsText:
|
|
304
|
-
freeSolo: g ||
|
|
305
|
-
autoHighlight:
|
|
306
|
-
clearOnEscape:
|
|
307
|
-
disableCloseOnSelect:
|
|
308
|
-
slotProps: { chip: { size:
|
|
313
|
+
limitTags: N,
|
|
314
|
+
disabled: Z,
|
|
315
|
+
loading: K,
|
|
316
|
+
noOptionsText: c ? /* @__PURE__ */ e(_, { variant: "body2", color: "text.secondary", children: "Press Enter or click below to create" }) : H,
|
|
317
|
+
freeSolo: g || w,
|
|
318
|
+
autoHighlight: C,
|
|
319
|
+
clearOnEscape: ne,
|
|
320
|
+
disableCloseOnSelect: u,
|
|
321
|
+
slotProps: { chip: { size: j, deleteIcon: /* @__PURE__ */ e(be, { fontSize: "small" }) } }
|
|
309
322
|
}
|
|
310
323
|
);
|
|
311
|
-
}), De = (
|
|
312
|
-
if (
|
|
313
|
-
const
|
|
314
|
-
return parseFloat((
|
|
315
|
-
}, Pe = (
|
|
316
|
-
variant:
|
|
317
|
-
accept:
|
|
318
|
-
multiple:
|
|
319
|
-
maxSize:
|
|
320
|
-
maxFiles:
|
|
321
|
-
files:
|
|
322
|
-
onFilesChange:
|
|
323
|
-
onFileSelect:
|
|
324
|
-
onFileRemove:
|
|
325
|
-
onUpload:
|
|
326
|
-
disabled:
|
|
327
|
-
helperText:
|
|
328
|
-
error:
|
|
329
|
-
showFileList:
|
|
330
|
-
size:
|
|
331
|
-
sx:
|
|
332
|
-
},
|
|
333
|
-
const [
|
|
334
|
-
typeof r == "function" ?
|
|
335
|
-
}, [
|
|
324
|
+
}), De = (d) => {
|
|
325
|
+
if (d === 0) return "0 Bytes";
|
|
326
|
+
const p = 1024, s = ["Bytes", "KB", "MB", "GB"], S = Math.floor(Math.log(d) / Math.log(p));
|
|
327
|
+
return parseFloat((d / Math.pow(p, S)).toFixed(2)) + " " + s[S];
|
|
328
|
+
}, Pe = (d) => d.startsWith("image/") ? /* @__PURE__ */ e(Ge, {}) : d.startsWith("video/") ? /* @__PURE__ */ e(Ne, {}) : d === "application/pdf" ? /* @__PURE__ */ e(qe, {}) : d.includes("document") || d.includes("text") ? /* @__PURE__ */ e(He, {}) : /* @__PURE__ */ e(Ve, {}), Qe = () => `file-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, ur = Oe.forwardRef(function({
|
|
329
|
+
variant: p = "dropzone",
|
|
330
|
+
accept: s,
|
|
331
|
+
multiple: S = !1,
|
|
332
|
+
maxSize: x,
|
|
333
|
+
maxFiles: w,
|
|
334
|
+
files: I,
|
|
335
|
+
onFilesChange: B,
|
|
336
|
+
onFileSelect: u,
|
|
337
|
+
onFileRemove: Y,
|
|
338
|
+
onUpload: q,
|
|
339
|
+
disabled: l = !1,
|
|
340
|
+
helperText: G,
|
|
341
|
+
error: oe,
|
|
342
|
+
showFileList: Z = !0,
|
|
343
|
+
size: V = "medium",
|
|
344
|
+
sx: j
|
|
345
|
+
}, N) {
|
|
346
|
+
const [T, ee] = le([]), [K, H] = le(!1), [J, Q] = le(null), $ = Fe(null), g = I ?? T, C = A((r) => {
|
|
347
|
+
typeof r == "function" ? B ? B(r(I ?? T)) : ee(r) : B ? B(r) : ee(r);
|
|
348
|
+
}, [I, T, B]), ne = (r) => x && r.size > x ? `File "${r.name}" exceeds maximum size of ${De(x)}` : w && g.length >= w ? `Maximum ${w} files allowed` : null, E = A(
|
|
336
349
|
async (r) => {
|
|
337
|
-
const
|
|
338
|
-
for (const v of
|
|
339
|
-
const h =
|
|
350
|
+
const c = Array.from(r), D = [], R = [];
|
|
351
|
+
for (const v of c) {
|
|
352
|
+
const h = ne(v);
|
|
340
353
|
if (h) {
|
|
341
354
|
R.push(h);
|
|
342
355
|
continue;
|
|
343
356
|
}
|
|
344
|
-
const
|
|
357
|
+
const W = {
|
|
345
358
|
id: Qe(),
|
|
346
359
|
file: v,
|
|
347
360
|
name: v.name,
|
|
@@ -351,166 +364,166 @@ const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
|
351
364
|
status: "pending",
|
|
352
365
|
preview: v.type.startsWith("image/") ? URL.createObjectURL(v) : void 0
|
|
353
366
|
};
|
|
354
|
-
|
|
367
|
+
D.push(W);
|
|
355
368
|
}
|
|
356
|
-
if (R.length > 0 ?
|
|
357
|
-
const v =
|
|
358
|
-
if (
|
|
359
|
-
for (const h of
|
|
369
|
+
if (R.length > 0 ? Q(R[0]) : Q(null), D.length > 0) {
|
|
370
|
+
const v = S ? [...g, ...D] : D;
|
|
371
|
+
if (C(v), u?.(D.map((h) => h.file)), q)
|
|
372
|
+
for (const h of D)
|
|
360
373
|
try {
|
|
361
|
-
|
|
374
|
+
C(
|
|
362
375
|
(F) => F.map(
|
|
363
376
|
(i) => i.id === h.id ? { ...i, status: "uploading" } : i
|
|
364
377
|
)
|
|
365
378
|
);
|
|
366
|
-
const
|
|
367
|
-
|
|
379
|
+
const W = setInterval(() => {
|
|
380
|
+
C(
|
|
368
381
|
(F) => F.map(
|
|
369
382
|
(i) => i.id === h.id && i.progress < 90 ? { ...i, progress: i.progress + 10 } : i
|
|
370
383
|
)
|
|
371
384
|
);
|
|
372
385
|
}, 200);
|
|
373
|
-
await
|
|
386
|
+
await q(h.file), clearInterval(W), C(
|
|
374
387
|
(F) => F.map(
|
|
375
388
|
(i) => i.id === h.id ? { ...i, status: "complete", progress: 100 } : i
|
|
376
389
|
)
|
|
377
390
|
);
|
|
378
|
-
} catch (
|
|
379
|
-
|
|
391
|
+
} catch (W) {
|
|
392
|
+
C(
|
|
380
393
|
(F) => F.map(
|
|
381
394
|
(i) => i.id === h.id ? {
|
|
382
395
|
...i,
|
|
383
396
|
status: "error",
|
|
384
|
-
error:
|
|
397
|
+
error: W instanceof Error ? W.message : "Upload failed"
|
|
385
398
|
} : i
|
|
386
399
|
)
|
|
387
400
|
);
|
|
388
401
|
}
|
|
389
402
|
}
|
|
390
403
|
},
|
|
391
|
-
[g,
|
|
392
|
-
),
|
|
393
|
-
r.preventDefault(), r.stopPropagation(),
|
|
394
|
-
}, [
|
|
395
|
-
r.preventDefault(), r.stopPropagation(),
|
|
396
|
-
}, []),
|
|
404
|
+
[g, C, x, w, S, u, q]
|
|
405
|
+
), re = A((r) => {
|
|
406
|
+
r.preventDefault(), r.stopPropagation(), l || H(!0);
|
|
407
|
+
}, [l]), se = A((r) => {
|
|
408
|
+
r.preventDefault(), r.stopPropagation(), H(!1);
|
|
409
|
+
}, []), ae = A((r) => {
|
|
397
410
|
r.preventDefault(), r.stopPropagation();
|
|
398
|
-
}, []), ie =
|
|
411
|
+
}, []), ie = A(
|
|
399
412
|
(r) => {
|
|
400
|
-
if (r.preventDefault(), r.stopPropagation(),
|
|
401
|
-
const
|
|
402
|
-
|
|
413
|
+
if (r.preventDefault(), r.stopPropagation(), H(!1), l) return;
|
|
414
|
+
const c = r.dataTransfer.files;
|
|
415
|
+
c.length > 0 && E(c);
|
|
403
416
|
},
|
|
404
|
-
[
|
|
405
|
-
),
|
|
417
|
+
[l, E]
|
|
418
|
+
), X = A(
|
|
406
419
|
(r) => {
|
|
407
|
-
const
|
|
408
|
-
|
|
420
|
+
const c = r.target.files;
|
|
421
|
+
c && c.length > 0 && E(c), $.current && ($.current.value = "");
|
|
409
422
|
},
|
|
410
|
-
[
|
|
411
|
-
), y =
|
|
423
|
+
[E]
|
|
424
|
+
), y = A(
|
|
412
425
|
(r) => {
|
|
413
426
|
r.preview && URL.revokeObjectURL(r.preview);
|
|
414
|
-
const
|
|
415
|
-
|
|
427
|
+
const c = g.filter((D) => D.id !== r.id);
|
|
428
|
+
C(c), Y?.(r);
|
|
416
429
|
},
|
|
417
|
-
[g,
|
|
418
|
-
),
|
|
419
|
-
|
|
420
|
-
},
|
|
430
|
+
[g, C, Y]
|
|
431
|
+
), U = () => {
|
|
432
|
+
$.current?.click();
|
|
433
|
+
}, O = oe || J, z = /* @__PURE__ */ e(
|
|
421
434
|
"input",
|
|
422
435
|
{
|
|
423
|
-
ref:
|
|
436
|
+
ref: $,
|
|
424
437
|
type: "file",
|
|
425
|
-
accept:
|
|
426
|
-
multiple:
|
|
427
|
-
onChange:
|
|
438
|
+
accept: s,
|
|
439
|
+
multiple: S,
|
|
440
|
+
onChange: X,
|
|
428
441
|
style: { display: "none" },
|
|
429
|
-
disabled:
|
|
442
|
+
disabled: l
|
|
430
443
|
}
|
|
431
|
-
),
|
|
444
|
+
), k = A(
|
|
432
445
|
(r) => {
|
|
433
|
-
(r.key === "Enter" || r.key === " ") && !
|
|
446
|
+
(r.key === "Enter" || r.key === " ") && !l && (r.preventDefault(), U());
|
|
434
447
|
},
|
|
435
|
-
[
|
|
448
|
+
[l]
|
|
436
449
|
);
|
|
437
|
-
return
|
|
438
|
-
|
|
450
|
+
return p === "dropzone" ? /* @__PURE__ */ f(L, { ref: N, sx: j, children: [
|
|
451
|
+
z,
|
|
439
452
|
/* @__PURE__ */ f(
|
|
440
|
-
|
|
453
|
+
pe,
|
|
441
454
|
{
|
|
442
455
|
role: "button",
|
|
443
|
-
tabIndex:
|
|
444
|
-
"aria-label": `Upload files${
|
|
445
|
-
"aria-disabled":
|
|
446
|
-
onDragEnter:
|
|
447
|
-
onDragLeave:
|
|
448
|
-
onDragOver:
|
|
456
|
+
tabIndex: l ? -1 : 0,
|
|
457
|
+
"aria-label": `Upload files${s ? `. Accepted formats: ${s}` : ""}. Drag and drop or press Enter to browse`,
|
|
458
|
+
"aria-disabled": l,
|
|
459
|
+
onDragEnter: re,
|
|
460
|
+
onDragLeave: se,
|
|
461
|
+
onDragOver: ae,
|
|
449
462
|
onDrop: ie,
|
|
450
|
-
onClick:
|
|
451
|
-
onKeyDown:
|
|
463
|
+
onClick: U,
|
|
464
|
+
onKeyDown: k,
|
|
452
465
|
sx: {
|
|
453
|
-
p:
|
|
466
|
+
p: V === "small" ? 3 : 4,
|
|
454
467
|
border: "2px dashed",
|
|
455
|
-
borderColor:
|
|
468
|
+
borderColor: O ? "error.main" : K ? "primary.main" : "divider",
|
|
456
469
|
borderRadius: Ce.borders.radiusPx.lg,
|
|
457
|
-
bgcolor:
|
|
470
|
+
bgcolor: K ? "action.hover" : l ? "action.disabledBackground" : "background.paper",
|
|
458
471
|
textAlign: "center",
|
|
459
|
-
cursor:
|
|
472
|
+
cursor: l ? "not-allowed" : "pointer",
|
|
460
473
|
transition: "all 0.2s ease",
|
|
461
474
|
"&:hover": {
|
|
462
|
-
bgcolor:
|
|
463
|
-
borderColor:
|
|
475
|
+
bgcolor: l ? void 0 : "action.hover",
|
|
476
|
+
borderColor: l ? void 0 : "primary.main"
|
|
464
477
|
}
|
|
465
478
|
},
|
|
466
479
|
children: [
|
|
467
480
|
/* @__PURE__ */ e(
|
|
468
|
-
|
|
481
|
+
de,
|
|
469
482
|
{
|
|
470
483
|
sx: {
|
|
471
|
-
fontSize:
|
|
472
|
-
color:
|
|
484
|
+
fontSize: V === "small" ? 40 : 56,
|
|
485
|
+
color: K ? "primary.main" : "action.active",
|
|
473
486
|
mb: 2
|
|
474
487
|
}
|
|
475
488
|
}
|
|
476
489
|
),
|
|
477
|
-
/* @__PURE__ */ e(_, { variant:
|
|
490
|
+
/* @__PURE__ */ e(_, { variant: V === "small" ? "body1" : "h6", gutterBottom: !0, children: K ? "Drop files here" : "Drag & drop files here" }),
|
|
478
491
|
/* @__PURE__ */ e(_, { variant: "body2", color: "text.secondary", gutterBottom: !0, children: "or click to browse" }),
|
|
479
|
-
|
|
492
|
+
G && /* @__PURE__ */ e(_, { variant: "caption", color: "text.secondary", children: G })
|
|
480
493
|
]
|
|
481
494
|
}
|
|
482
495
|
),
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
] }) :
|
|
486
|
-
|
|
496
|
+
O && /* @__PURE__ */ e(ve, { severity: "error", sx: { mt: 2 }, children: O }),
|
|
497
|
+
Z && g.length > 0 && /* @__PURE__ */ e(we, { files: g, onRemove: y })
|
|
498
|
+
] }) : p === "button" ? /* @__PURE__ */ f(L, { ref: N, sx: j, children: [
|
|
499
|
+
z,
|
|
487
500
|
/* @__PURE__ */ f(
|
|
488
|
-
|
|
501
|
+
fe,
|
|
489
502
|
{
|
|
490
503
|
variant: "contained",
|
|
491
|
-
startIcon: /* @__PURE__ */ e(
|
|
492
|
-
onClick:
|
|
493
|
-
disabled:
|
|
494
|
-
size:
|
|
504
|
+
startIcon: /* @__PURE__ */ e(de, {}),
|
|
505
|
+
onClick: U,
|
|
506
|
+
disabled: l,
|
|
507
|
+
size: V,
|
|
495
508
|
children: [
|
|
496
509
|
"Upload ",
|
|
497
|
-
|
|
510
|
+
S ? "Files" : "File"
|
|
498
511
|
]
|
|
499
512
|
}
|
|
500
513
|
),
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
] }) : /* @__PURE__ */ f(
|
|
504
|
-
|
|
514
|
+
O && /* @__PURE__ */ e(ve, { severity: "error", sx: { mt: 2 }, children: O }),
|
|
515
|
+
Z && g.length > 0 && /* @__PURE__ */ e(we, { files: g, onRemove: y })
|
|
516
|
+
] }) : /* @__PURE__ */ f(L, { ref: N, sx: j, children: [
|
|
517
|
+
z,
|
|
505
518
|
/* @__PURE__ */ f(ze, { direction: "row", spacing: 1, useFlexGap: !0, sx: { alignItems: "center", flexWrap: "wrap" }, children: [
|
|
506
519
|
/* @__PURE__ */ e(
|
|
507
|
-
|
|
520
|
+
fe,
|
|
508
521
|
{
|
|
509
522
|
variant: "outlined",
|
|
510
523
|
size: "small",
|
|
511
|
-
startIcon: /* @__PURE__ */ e(
|
|
512
|
-
onClick:
|
|
513
|
-
disabled:
|
|
524
|
+
startIcon: /* @__PURE__ */ e(de, {}),
|
|
525
|
+
onClick: U,
|
|
526
|
+
disabled: l,
|
|
514
527
|
children: "Browse"
|
|
515
528
|
}
|
|
516
529
|
),
|
|
@@ -533,29 +546,29 @@ const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
|
533
546
|
r.id
|
|
534
547
|
))
|
|
535
548
|
] }),
|
|
536
|
-
|
|
549
|
+
O && /* @__PURE__ */ e(_, { variant: "caption", color: "error", sx: { mt: 0.5, display: "block" }, children: O })
|
|
537
550
|
] });
|
|
538
|
-
}), we = ({ files:
|
|
539
|
-
|
|
551
|
+
}), we = ({ files: d, onRemove: p }) => /* @__PURE__ */ e(We, { dense: !0, sx: { mt: 2 }, children: d.map((s) => /* @__PURE__ */ f(
|
|
552
|
+
ue,
|
|
540
553
|
{
|
|
541
554
|
sx: {
|
|
542
555
|
bgcolor: "background.paper",
|
|
543
556
|
borderRadius: Ce.borders.radiusPx.md,
|
|
544
557
|
mb: 1,
|
|
545
558
|
border: "1px solid",
|
|
546
|
-
borderColor:
|
|
559
|
+
borderColor: s.status === "error" ? "error.light" : "divider"
|
|
547
560
|
},
|
|
548
561
|
children: [
|
|
549
|
-
/* @__PURE__ */ e(
|
|
562
|
+
/* @__PURE__ */ e(te, { children: s.status === "complete" ? /* @__PURE__ */ e(ke, { color: "success" }) : s.status === "error" ? /* @__PURE__ */ e(_e, { color: "error" }) : Pe(s.type) }),
|
|
550
563
|
/* @__PURE__ */ e(
|
|
551
|
-
|
|
564
|
+
me,
|
|
552
565
|
{
|
|
553
|
-
primary:
|
|
554
|
-
secondary: /* @__PURE__ */ f(
|
|
555
|
-
De(
|
|
556
|
-
|
|
566
|
+
primary: s.name,
|
|
567
|
+
secondary: /* @__PURE__ */ f(L, { component: "span", children: [
|
|
568
|
+
De(s.size),
|
|
569
|
+
s.error && /* @__PURE__ */ f(_, { component: "span", color: "error", sx: { ml: 1 }, children: [
|
|
557
570
|
"• ",
|
|
558
|
-
|
|
571
|
+
s.error
|
|
559
572
|
] })
|
|
560
573
|
] }),
|
|
561
574
|
sx: {
|
|
@@ -567,11 +580,11 @@ const xe = () => `new-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
|
567
580
|
}
|
|
568
581
|
}
|
|
569
582
|
),
|
|
570
|
-
|
|
571
|
-
/* @__PURE__ */ e(Te, { children: /* @__PURE__ */ e($e, { edge: "end", onClick: () =>
|
|
583
|
+
s.status === "uploading" && /* @__PURE__ */ e(L, { sx: { width: 100, mr: 2 }, children: /* @__PURE__ */ e(je, { variant: "determinate", value: s.progress }) }),
|
|
584
|
+
/* @__PURE__ */ e(Te, { children: /* @__PURE__ */ e($e, { edge: "end", onClick: () => p(s), size: "small", children: /* @__PURE__ */ e(Ke, { fontSize: "small" }) }) })
|
|
572
585
|
]
|
|
573
586
|
},
|
|
574
|
-
|
|
587
|
+
s.id
|
|
575
588
|
)) });
|
|
576
589
|
export {
|
|
577
590
|
pr as C,
|