upload-pulse 1.0.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/README.md +127 -0
- package/dist/components/upload/Dropzone.d.ts +19 -0
- package/dist/components/upload/FileTypeIcon.d.ts +6 -0
- package/dist/components/upload/MockUpload.d.ts +2 -0
- package/dist/components/upload/Picker.d.ts +2 -0
- package/dist/components/upload/Upload.d.ts +2 -0
- package/dist/components/upload/UploadActions.d.ts +11 -0
- package/dist/components/upload/UploadRequest.d.ts +2 -0
- package/dist/components/upload/config.d.ts +116 -0
- package/dist/components/upload/hooks/useMockUpload.d.ts +15 -0
- package/dist/components/upload/hooks/useUpload.d.ts +9 -0
- package/dist/components/upload/hooks/useUploadDisplay.d.ts +34 -0
- package/dist/components/upload/hooks/useUploadDragDrop.d.ts +22 -0
- package/dist/components/upload/hooks/useUploadPicker.d.ts +17 -0
- package/dist/components/upload/icons.d.ts +10 -0
- package/dist/components/upload/index.d.ts +26 -0
- package/dist/components/upload/interface.d.ts +237 -0
- package/dist/components/upload/utils/fileAccept.d.ts +10 -0
- package/dist/components/upload/utils/index.d.ts +3 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1088 -0
- package/dist/upload-pulse.css +3 -0
- package/package.json +60 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1088 @@
|
|
|
1
|
+
import { Fragment as e, jsx as t, jsxs as n } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback as r, useEffect as i, useMemo as a, useRef as o, useState as s } from "react";
|
|
3
|
+
//#region src/components/upload/utils/index.ts
|
|
4
|
+
function c(...e) {
|
|
5
|
+
return e.filter(Boolean).join(" ");
|
|
6
|
+
}
|
|
7
|
+
function l(e) {
|
|
8
|
+
if (e === 0) return "0.0MB";
|
|
9
|
+
let t = e / (1024 * 1024);
|
|
10
|
+
if (t >= 10) return `${Math.round(t)}MB`;
|
|
11
|
+
if (t >= 1) return `${t.toFixed(1)}MB`;
|
|
12
|
+
let n = e / 1024;
|
|
13
|
+
return n >= 1 ? `${n.toFixed(1)}KB` : `${e}B`;
|
|
14
|
+
}
|
|
15
|
+
function u(e) {
|
|
16
|
+
let t = e.split(".");
|
|
17
|
+
return t.length < 2 ? "default" : t[t.length - 1].toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/components/upload/FileTypeIcon.tsx
|
|
21
|
+
var d = {
|
|
22
|
+
xlsx: "#10B981",
|
|
23
|
+
xls: "#10B981",
|
|
24
|
+
csv: "#10B981",
|
|
25
|
+
pdf: "#EF4444",
|
|
26
|
+
doc: "#3B82F6",
|
|
27
|
+
docx: "#3B82F6",
|
|
28
|
+
png: "#8B5CF6",
|
|
29
|
+
jpg: "#8B5CF6",
|
|
30
|
+
jpeg: "#8B5CF6",
|
|
31
|
+
default: "#6B7280"
|
|
32
|
+
}, f = {
|
|
33
|
+
xlsx: "XLSX",
|
|
34
|
+
xls: "XLS",
|
|
35
|
+
csv: "CSV",
|
|
36
|
+
pdf: "PDF",
|
|
37
|
+
doc: "DOC",
|
|
38
|
+
docx: "DOCX",
|
|
39
|
+
png: "PNG",
|
|
40
|
+
jpg: "JPG",
|
|
41
|
+
jpeg: "JPG",
|
|
42
|
+
default: "FILE"
|
|
43
|
+
};
|
|
44
|
+
function p({ filename: e, className: r }) {
|
|
45
|
+
let i = u(e), a = d[i] ?? d.default, o = f[i] ?? (i.toUpperCase().slice(0, 4) || "FILE");
|
|
46
|
+
return /* @__PURE__ */ n("svg", {
|
|
47
|
+
className: r,
|
|
48
|
+
width: "40",
|
|
49
|
+
height: "48",
|
|
50
|
+
viewBox: "0 0 40 48",
|
|
51
|
+
fill: "none",
|
|
52
|
+
"aria-hidden": "true",
|
|
53
|
+
children: [
|
|
54
|
+
/* @__PURE__ */ t("path", {
|
|
55
|
+
d: "M4 4C4 1.79 5.79 0 8 0H26L36 10V44C36 46.21 34.21 48 32 48H8C5.79 48 4 46.21 4 44V4Z",
|
|
56
|
+
fill: a
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ t("path", {
|
|
59
|
+
d: "M26 0L36 10H30C27.79 10 26 8.21 26 6V0Z",
|
|
60
|
+
fill: "rgba(0,0,0,0.15)"
|
|
61
|
+
}),
|
|
62
|
+
/* @__PURE__ */ t("rect", {
|
|
63
|
+
x: "10",
|
|
64
|
+
y: "12",
|
|
65
|
+
width: "6",
|
|
66
|
+
height: "6",
|
|
67
|
+
rx: "1",
|
|
68
|
+
fill: "rgba(0,0,0,0.25)"
|
|
69
|
+
}),
|
|
70
|
+
/* @__PURE__ */ t("rect", {
|
|
71
|
+
x: "18",
|
|
72
|
+
y: "12",
|
|
73
|
+
width: "6",
|
|
74
|
+
height: "6",
|
|
75
|
+
rx: "1",
|
|
76
|
+
fill: "rgba(0,0,0,0.25)"
|
|
77
|
+
}),
|
|
78
|
+
/* @__PURE__ */ t("rect", {
|
|
79
|
+
x: "10",
|
|
80
|
+
y: "20",
|
|
81
|
+
width: "6",
|
|
82
|
+
height: "6",
|
|
83
|
+
rx: "1",
|
|
84
|
+
fill: "rgba(0,0,0,0.25)"
|
|
85
|
+
}),
|
|
86
|
+
/* @__PURE__ */ t("rect", {
|
|
87
|
+
x: "18",
|
|
88
|
+
y: "20",
|
|
89
|
+
width: "6",
|
|
90
|
+
height: "6",
|
|
91
|
+
rx: "1",
|
|
92
|
+
fill: "rgba(0,0,0,0.25)"
|
|
93
|
+
}),
|
|
94
|
+
/* @__PURE__ */ t("text", {
|
|
95
|
+
x: "20",
|
|
96
|
+
y: "40",
|
|
97
|
+
textAnchor: "middle",
|
|
98
|
+
fill: "#000",
|
|
99
|
+
fontSize: "8",
|
|
100
|
+
fontWeight: "700",
|
|
101
|
+
fontFamily: "system-ui, sans-serif",
|
|
102
|
+
children: o
|
|
103
|
+
})
|
|
104
|
+
]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/components/upload/icons.tsx
|
|
109
|
+
function m({ className: e }) {
|
|
110
|
+
return /* @__PURE__ */ n("svg", {
|
|
111
|
+
className: e,
|
|
112
|
+
width: "10",
|
|
113
|
+
height: "12",
|
|
114
|
+
viewBox: "0 0 10 12",
|
|
115
|
+
fill: "none",
|
|
116
|
+
"aria-hidden": "true",
|
|
117
|
+
children: [/* @__PURE__ */ t("rect", {
|
|
118
|
+
x: "0",
|
|
119
|
+
y: "0",
|
|
120
|
+
width: "3",
|
|
121
|
+
height: "12",
|
|
122
|
+
rx: "1",
|
|
123
|
+
fill: "currentColor"
|
|
124
|
+
}), /* @__PURE__ */ t("rect", {
|
|
125
|
+
x: "7",
|
|
126
|
+
y: "0",
|
|
127
|
+
width: "3",
|
|
128
|
+
height: "12",
|
|
129
|
+
rx: "1",
|
|
130
|
+
fill: "currentColor"
|
|
131
|
+
})]
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function h({ className: e }) {
|
|
135
|
+
return /* @__PURE__ */ t("svg", {
|
|
136
|
+
className: e,
|
|
137
|
+
width: "10",
|
|
138
|
+
height: "12",
|
|
139
|
+
viewBox: "0 0 10 12",
|
|
140
|
+
fill: "none",
|
|
141
|
+
"aria-hidden": "true",
|
|
142
|
+
children: /* @__PURE__ */ t("path", {
|
|
143
|
+
d: "M0 0L10 6L0 12V0Z",
|
|
144
|
+
fill: "currentColor"
|
|
145
|
+
})
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function g({ className: e }) {
|
|
149
|
+
return /* @__PURE__ */ t("svg", {
|
|
150
|
+
className: e,
|
|
151
|
+
width: "14",
|
|
152
|
+
height: "14",
|
|
153
|
+
viewBox: "0 0 14 14",
|
|
154
|
+
fill: "none",
|
|
155
|
+
"aria-hidden": "true",
|
|
156
|
+
children: /* @__PURE__ */ t("path", {
|
|
157
|
+
d: "M1 1L13 13M13 1L1 13",
|
|
158
|
+
stroke: "currentColor",
|
|
159
|
+
strokeWidth: "1.5",
|
|
160
|
+
strokeLinecap: "round"
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function _({ className: e }) {
|
|
165
|
+
return /* @__PURE__ */ n("svg", {
|
|
166
|
+
className: e,
|
|
167
|
+
width: "14",
|
|
168
|
+
height: "16",
|
|
169
|
+
viewBox: "0 0 14 16",
|
|
170
|
+
fill: "none",
|
|
171
|
+
"aria-hidden": "true",
|
|
172
|
+
children: [/* @__PURE__ */ t("path", {
|
|
173
|
+
d: "M1 4H13M5 4V2.5C5 1.67 5.67 1 6.5 1H7.5C8.33 1 9 1.67 9 2.5V4M11 4V14.5C11 15.33 10.33 16 9.5 16H4.5C3.67 16 3 15.33 3 14.5V4H11Z",
|
|
174
|
+
stroke: "currentColor",
|
|
175
|
+
strokeWidth: "1.5",
|
|
176
|
+
strokeLinecap: "round",
|
|
177
|
+
strokeLinejoin: "round"
|
|
178
|
+
}), /* @__PURE__ */ t("path", {
|
|
179
|
+
d: "M5.5 7.5V12.5M8.5 7.5V12.5",
|
|
180
|
+
stroke: "currentColor",
|
|
181
|
+
strokeWidth: "1.5",
|
|
182
|
+
strokeLinecap: "round"
|
|
183
|
+
})]
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function v({ className: e }) {
|
|
187
|
+
return /* @__PURE__ */ t("svg", {
|
|
188
|
+
className: e,
|
|
189
|
+
width: "10",
|
|
190
|
+
height: "8",
|
|
191
|
+
viewBox: "0 0 10 8",
|
|
192
|
+
fill: "none",
|
|
193
|
+
"aria-hidden": "true",
|
|
194
|
+
children: /* @__PURE__ */ t("path", {
|
|
195
|
+
d: "M1 4L3.5 6.5L9 1",
|
|
196
|
+
stroke: "currentColor",
|
|
197
|
+
strokeWidth: "1.5",
|
|
198
|
+
strokeLinecap: "round",
|
|
199
|
+
strokeLinejoin: "round"
|
|
200
|
+
})
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function y({ className: e }) {
|
|
204
|
+
return /* @__PURE__ */ t("svg", {
|
|
205
|
+
className: e,
|
|
206
|
+
width: "14",
|
|
207
|
+
height: "14",
|
|
208
|
+
viewBox: "0 0 14 14",
|
|
209
|
+
fill: "none",
|
|
210
|
+
"aria-hidden": "true",
|
|
211
|
+
children: /* @__PURE__ */ t("path", {
|
|
212
|
+
d: "M12 7A5 5 0 1 1 9.5 2.5M12 2V5.5H8.5",
|
|
213
|
+
stroke: "currentColor",
|
|
214
|
+
strokeWidth: "1.5",
|
|
215
|
+
strokeLinecap: "round",
|
|
216
|
+
strokeLinejoin: "round"
|
|
217
|
+
})
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/components/upload/config.ts
|
|
222
|
+
var b = {
|
|
223
|
+
cardBackground: "#000000",
|
|
224
|
+
cardShadow: "0 4px 24px rgba(0, 0, 0, 0.4)",
|
|
225
|
+
fileName: "#ffffff",
|
|
226
|
+
statusUploading: "#a5b4fc",
|
|
227
|
+
statusPaused: "#9ca3af",
|
|
228
|
+
statusError: "#f87171",
|
|
229
|
+
statusCompleted: "#ffffff",
|
|
230
|
+
metaMuted: "#9ca3af",
|
|
231
|
+
metaSeparator: "#6b7280",
|
|
232
|
+
progressTrack: "#374151",
|
|
233
|
+
progressBackground: "linear-gradient(to bottom right, #1e1b4b, #312e81, #3730a3)",
|
|
234
|
+
progressFill: "linear-gradient(to right, #6366f1, #818cf8)",
|
|
235
|
+
progressGlow: "rgba(129, 140, 248, 0.6)",
|
|
236
|
+
iconButtonBackground: "rgba(55, 65, 81, 0.8)",
|
|
237
|
+
iconButtonHover: "rgba(75, 85, 99, 0.9)",
|
|
238
|
+
iconButtonText: "#ffffff",
|
|
239
|
+
closeButtonText: "#d1d5db",
|
|
240
|
+
closeButtonHover: "#ffffff",
|
|
241
|
+
deleteButtonBackground: "rgba(239, 68, 68, 0.2)",
|
|
242
|
+
deleteButtonText: "#f87171",
|
|
243
|
+
deleteButtonHoverBackground: "rgba(239, 68, 68, 0.35)",
|
|
244
|
+
deleteButtonHoverText: "#fca5a5",
|
|
245
|
+
deleteButtonShadow: "0 0 16px rgba(239, 68, 68, 0.3)",
|
|
246
|
+
deleteButtonHoverShadow: "0 0 20px rgba(239, 68, 68, 0.45)",
|
|
247
|
+
successBadgeBackground: "#10b981",
|
|
248
|
+
changeButtonBackground: "#374151",
|
|
249
|
+
changeButtonHover: "#4b5563",
|
|
250
|
+
changeButtonText: "#ffffff",
|
|
251
|
+
downloadButtonBackground: "#e5e7eb",
|
|
252
|
+
downloadButtonHover: "#f3f4f6",
|
|
253
|
+
downloadButtonText: "#111827"
|
|
254
|
+
}, x = {
|
|
255
|
+
cardBackground: "#ffffff",
|
|
256
|
+
cardShadow: "0 4px 24px rgba(15, 23, 42, 0.08)",
|
|
257
|
+
fileName: "#111827",
|
|
258
|
+
statusUploading: "#4f46e5",
|
|
259
|
+
statusPaused: "#6b7280",
|
|
260
|
+
statusError: "#dc2626",
|
|
261
|
+
statusCompleted: "#111827",
|
|
262
|
+
metaMuted: "#6b7280",
|
|
263
|
+
metaSeparator: "#d1d5db",
|
|
264
|
+
progressTrack: "#e5e7eb",
|
|
265
|
+
progressBackground: "linear-gradient(to bottom right, #eef2ff, #e0e7ff, #c7d2fe)",
|
|
266
|
+
progressFill: "linear-gradient(to right, #6366f1, #818cf8)",
|
|
267
|
+
progressGlow: "rgba(99, 102, 241, 0.45)",
|
|
268
|
+
iconButtonBackground: "rgba(243, 244, 246, 0.95)",
|
|
269
|
+
iconButtonHover: "rgba(229, 231, 235, 1)",
|
|
270
|
+
iconButtonText: "#374151",
|
|
271
|
+
closeButtonText: "#9ca3af",
|
|
272
|
+
closeButtonHover: "#374151",
|
|
273
|
+
deleteButtonBackground: "rgba(254, 226, 226, 0.9)",
|
|
274
|
+
deleteButtonText: "#dc2626",
|
|
275
|
+
deleteButtonHoverBackground: "rgba(254, 202, 202, 0.95)",
|
|
276
|
+
deleteButtonHoverText: "#b91c1c",
|
|
277
|
+
deleteButtonShadow: "0 0 12px rgba(220, 38, 38, 0.15)",
|
|
278
|
+
deleteButtonHoverShadow: "0 0 16px rgba(220, 38, 38, 0.25)",
|
|
279
|
+
successBadgeBackground: "#10b981",
|
|
280
|
+
changeButtonBackground: "#f3f4f6",
|
|
281
|
+
changeButtonHover: "#e5e7eb",
|
|
282
|
+
changeButtonText: "#111827",
|
|
283
|
+
downloadButtonBackground: "#111827",
|
|
284
|
+
downloadButtonHover: "#1f2937",
|
|
285
|
+
downloadButtonText: "#ffffff"
|
|
286
|
+
}, S = {
|
|
287
|
+
theme: "light",
|
|
288
|
+
colors: x,
|
|
289
|
+
progressInset: 10,
|
|
290
|
+
maxWidth: 480,
|
|
291
|
+
showProgressBar: !0,
|
|
292
|
+
showBackgroundProgress: !0,
|
|
293
|
+
pausable: !0,
|
|
294
|
+
cancelable: !0,
|
|
295
|
+
deletable: !0,
|
|
296
|
+
retryable: !0,
|
|
297
|
+
labels: {
|
|
298
|
+
uploading: (e) => `Uploading ${e}%`,
|
|
299
|
+
paused: (e) => `Paused ${e}%`,
|
|
300
|
+
completed: "Completed",
|
|
301
|
+
error: (e) => e ? `Failed · ${e}` : "Failed",
|
|
302
|
+
change: "Change",
|
|
303
|
+
download: "Download",
|
|
304
|
+
retry: "Retry"
|
|
305
|
+
}
|
|
306
|
+
}, C = {
|
|
307
|
+
maxCountExceeded: (e) => `最多只能上传 ${e} 个文件`,
|
|
308
|
+
invalidFormat: (e) => `文件格式不支持:${e}`
|
|
309
|
+
}, w = {
|
|
310
|
+
hint: "拖拽文件到此处上传",
|
|
311
|
+
hintActive: "释放文件开始上传",
|
|
312
|
+
hintDisabled: "已达上传上限",
|
|
313
|
+
clickHint: "或点击选择文件"
|
|
314
|
+
}, T = {
|
|
315
|
+
borderColor: "#d1d5db",
|
|
316
|
+
borderColorActive: "#6366f1",
|
|
317
|
+
borderColorDisabled: "#e5e7eb",
|
|
318
|
+
background: "#ffffff",
|
|
319
|
+
backgroundActive: "rgba(99, 102, 241, 0.06)",
|
|
320
|
+
textColor: "#6b7280",
|
|
321
|
+
textColorActive: "#4f46e5",
|
|
322
|
+
textColorDisabled: "#9ca3af",
|
|
323
|
+
minHeight: 120,
|
|
324
|
+
borderRadius: 16
|
|
325
|
+
}, E = {
|
|
326
|
+
borderColor: "#374151",
|
|
327
|
+
borderColorActive: "#6366f1",
|
|
328
|
+
borderColorDisabled: "#1f2937",
|
|
329
|
+
background: "transparent",
|
|
330
|
+
backgroundActive: "rgba(99, 102, 241, 0.08)",
|
|
331
|
+
textColor: "#9ca3af",
|
|
332
|
+
textColorActive: "#a5b4fc",
|
|
333
|
+
textColorDisabled: "#4b5563",
|
|
334
|
+
minHeight: 120,
|
|
335
|
+
borderRadius: 16
|
|
336
|
+
}, D = {
|
|
337
|
+
enabled: !1,
|
|
338
|
+
showDropzone: !0,
|
|
339
|
+
global: !1,
|
|
340
|
+
preventDocumentDrop: !0,
|
|
341
|
+
labels: w,
|
|
342
|
+
style: T
|
|
343
|
+
}, O = {
|
|
344
|
+
dark: "cursor-pointer rounded-lg border border-gray-700 bg-neutral-800 px-4 py-2 text-[13px] text-gray-100 transition-colors duration-150 hover:bg-gray-700 disabled:cursor-not-allowed disabled:opacity-50",
|
|
345
|
+
light: "cursor-pointer rounded-lg border border-gray-300 bg-white px-4 py-2 text-[13px] text-gray-900 transition-colors duration-150 hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50"
|
|
346
|
+
}, k = {
|
|
347
|
+
dark: E,
|
|
348
|
+
light: T
|
|
349
|
+
}, A = {
|
|
350
|
+
theme: "light",
|
|
351
|
+
multiple: !1,
|
|
352
|
+
showButton: !0,
|
|
353
|
+
buttonLabel: "选择文件",
|
|
354
|
+
labels: C,
|
|
355
|
+
drag: D
|
|
356
|
+
}, j = {
|
|
357
|
+
dark: b,
|
|
358
|
+
light: x
|
|
359
|
+
};
|
|
360
|
+
function M(e) {
|
|
361
|
+
let t = e?.theme ?? S.theme, n = j[t];
|
|
362
|
+
return {
|
|
363
|
+
...S,
|
|
364
|
+
...e,
|
|
365
|
+
theme: t,
|
|
366
|
+
colors: {
|
|
367
|
+
...n,
|
|
368
|
+
...e?.colors
|
|
369
|
+
},
|
|
370
|
+
labels: {
|
|
371
|
+
...S.labels,
|
|
372
|
+
...e?.labels
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function N(e) {
|
|
377
|
+
let t = e?.theme ?? A.theme, n = k[t];
|
|
378
|
+
return {
|
|
379
|
+
...A,
|
|
380
|
+
...e,
|
|
381
|
+
theme: t,
|
|
382
|
+
buttonClassName: O[t],
|
|
383
|
+
labels: {
|
|
384
|
+
...C,
|
|
385
|
+
...e?.labels
|
|
386
|
+
},
|
|
387
|
+
drag: {
|
|
388
|
+
...D,
|
|
389
|
+
...e?.drag,
|
|
390
|
+
labels: {
|
|
391
|
+
...w,
|
|
392
|
+
...e?.drag?.labels
|
|
393
|
+
},
|
|
394
|
+
style: {
|
|
395
|
+
...n,
|
|
396
|
+
...e?.drag?.style
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function P(e) {
|
|
402
|
+
return {
|
|
403
|
+
"--upload-card-bg": e.cardBackground,
|
|
404
|
+
"--upload-card-shadow": e.cardShadow,
|
|
405
|
+
"--upload-file-name": e.fileName,
|
|
406
|
+
"--upload-status-uploading": e.statusUploading,
|
|
407
|
+
"--upload-status-paused": e.statusPaused,
|
|
408
|
+
"--upload-status-error": e.statusError,
|
|
409
|
+
"--upload-status-completed": e.statusCompleted,
|
|
410
|
+
"--upload-meta-muted": e.metaMuted,
|
|
411
|
+
"--upload-meta-separator": e.metaSeparator,
|
|
412
|
+
"--upload-progress-track": e.progressTrack,
|
|
413
|
+
"--upload-progress-bg": e.progressBackground,
|
|
414
|
+
"--upload-progress-fill": e.progressFill,
|
|
415
|
+
"--upload-progress-glow": e.progressGlow,
|
|
416
|
+
"--upload-icon-btn-bg": e.iconButtonBackground,
|
|
417
|
+
"--upload-icon-btn-hover": e.iconButtonHover,
|
|
418
|
+
"--upload-icon-btn-text": e.iconButtonText,
|
|
419
|
+
"--upload-close-text": e.closeButtonText,
|
|
420
|
+
"--upload-close-hover": e.closeButtonHover,
|
|
421
|
+
"--upload-delete-bg": e.deleteButtonBackground,
|
|
422
|
+
"--upload-delete-text": e.deleteButtonText,
|
|
423
|
+
"--upload-delete-hover-bg": e.deleteButtonHoverBackground,
|
|
424
|
+
"--upload-delete-hover-text": e.deleteButtonHoverText,
|
|
425
|
+
"--upload-delete-shadow": e.deleteButtonShadow,
|
|
426
|
+
"--upload-delete-hover-shadow": e.deleteButtonHoverShadow,
|
|
427
|
+
"--upload-success-badge": e.successBadgeBackground,
|
|
428
|
+
"--upload-change-bg": e.changeButtonBackground,
|
|
429
|
+
"--upload-change-hover": e.changeButtonHover,
|
|
430
|
+
"--upload-change-text": e.changeButtonText,
|
|
431
|
+
"--upload-download-bg": e.downloadButtonBackground,
|
|
432
|
+
"--upload-download-hover": e.downloadButtonHover,
|
|
433
|
+
"--upload-download-text": e.downloadButtonText
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
var F = "inline-flex items-center justify-center border-none cursor-pointer p-0 transition-[background,opacity,transform,color,box-shadow] duration-150 hover:opacity-85 active:scale-95", ee = "relative w-full overflow-hidden rounded-2xl font-sans bg-[var(--upload-card-bg)] shadow-[var(--upload-card-shadow)]", I = c(F, "h-8 w-8 rounded-full bg-[var(--upload-icon-btn-bg)] text-[var(--upload-icon-btn-text)] hover:bg-[var(--upload-icon-btn-hover)]"), L = c(F, "h-7 w-7 text-[var(--upload-close-text)] hover:text-[var(--upload-close-hover)]"), te = c(F, "h-8 rounded-full bg-[var(--upload-icon-btn-bg)] px-3 text-xs font-medium text-[var(--upload-icon-btn-text)] hover:bg-[var(--upload-icon-btn-hover)]"), ne = c(F, "h-9 w-9 rounded-full bg-[var(--upload-delete-bg)] text-[var(--upload-delete-text)] shadow-[var(--upload-delete-shadow)] hover:bg-[var(--upload-delete-hover-bg)] hover:text-[var(--upload-delete-hover-text)] hover:shadow-[var(--upload-delete-hover-shadow)]");
|
|
437
|
+
function R({ status: e, pausable: r, cancelable: i, deletable: a, retryable: o, retryLabel: s, onPause: c, onResume: l, onCancel: u, onDelete: d, onRetry: f }) {
|
|
438
|
+
return e === "uploading" && (r || i) ? /* @__PURE__ */ n("div", {
|
|
439
|
+
className: "flex shrink-0 items-center gap-2",
|
|
440
|
+
children: [r && /* @__PURE__ */ t("button", {
|
|
441
|
+
type: "button",
|
|
442
|
+
className: I,
|
|
443
|
+
onClick: c,
|
|
444
|
+
"aria-label": "Pause upload",
|
|
445
|
+
children: /* @__PURE__ */ t(m, {})
|
|
446
|
+
}), i && /* @__PURE__ */ t("button", {
|
|
447
|
+
type: "button",
|
|
448
|
+
className: L,
|
|
449
|
+
onClick: u,
|
|
450
|
+
"aria-label": "Cancel upload",
|
|
451
|
+
children: /* @__PURE__ */ t(g, {})
|
|
452
|
+
})]
|
|
453
|
+
}) : e === "paused" && (r || i) ? /* @__PURE__ */ n("div", {
|
|
454
|
+
className: "flex shrink-0 items-center gap-2",
|
|
455
|
+
children: [r && /* @__PURE__ */ t("button", {
|
|
456
|
+
type: "button",
|
|
457
|
+
className: I,
|
|
458
|
+
onClick: l,
|
|
459
|
+
"aria-label": "Resume upload",
|
|
460
|
+
children: /* @__PURE__ */ t(h, {})
|
|
461
|
+
}), i && /* @__PURE__ */ t("button", {
|
|
462
|
+
type: "button",
|
|
463
|
+
className: L,
|
|
464
|
+
onClick: u,
|
|
465
|
+
"aria-label": "Cancel upload",
|
|
466
|
+
children: /* @__PURE__ */ t(g, {})
|
|
467
|
+
})]
|
|
468
|
+
}) : e === "error" && (o || i) ? /* @__PURE__ */ n("div", {
|
|
469
|
+
className: "flex shrink-0 items-center gap-2",
|
|
470
|
+
children: [o && f && /* @__PURE__ */ n("button", {
|
|
471
|
+
type: "button",
|
|
472
|
+
className: te,
|
|
473
|
+
onClick: f,
|
|
474
|
+
"aria-label": s,
|
|
475
|
+
children: [/* @__PURE__ */ t(y, { className: "mr-1" }), s]
|
|
476
|
+
}), i && /* @__PURE__ */ t("button", {
|
|
477
|
+
type: "button",
|
|
478
|
+
className: L,
|
|
479
|
+
onClick: u,
|
|
480
|
+
"aria-label": "Cancel upload",
|
|
481
|
+
children: /* @__PURE__ */ t(g, {})
|
|
482
|
+
})]
|
|
483
|
+
}) : e === "completed" && a ? /* @__PURE__ */ t("button", {
|
|
484
|
+
type: "button",
|
|
485
|
+
className: ne,
|
|
486
|
+
onClick: d,
|
|
487
|
+
"aria-label": "Delete file",
|
|
488
|
+
children: /* @__PURE__ */ t(_, {})
|
|
489
|
+
}) : null;
|
|
490
|
+
}
|
|
491
|
+
//#endregion
|
|
492
|
+
//#region src/components/upload/hooks/useUploadDisplay.ts
|
|
493
|
+
function z({ file: e, status: t, progress: n, progressInset: r, errorMessage: i, colors: o, labels: s }) {
|
|
494
|
+
let c = t === "completed" ? 100 : Math.min(100, Math.round(Math.min(100, Math.max(0, n)))), u = t === "uploading" || t === "paused" || t === "error", d = r * 2, f = `${c}%`, p = {
|
|
495
|
+
width: !u || c === 0 ? "0%" : `calc(${r}px + (100% - ${d}px) * ${c} / 100)`,
|
|
496
|
+
background: o.progressBackground
|
|
497
|
+
}, m = Math.round(e.size * c / 100), h = a(() => t === "completed" ? s.completed : t === "error" ? typeof s.error == "function" ? s.error(i) : s.error : t === "paused" ? s.paused(c) : s.uploading(c), [
|
|
498
|
+
t,
|
|
499
|
+
c,
|
|
500
|
+
i,
|
|
501
|
+
s
|
|
502
|
+
]), g = a(() => t === "completed" || t === "error" ? l(e.size) : `${l(m)} of ${l(e.size)}`, [
|
|
503
|
+
t,
|
|
504
|
+
m,
|
|
505
|
+
e.size
|
|
506
|
+
]), _ = t === "uploading" ? o.statusUploading : t === "paused" ? o.statusPaused : t === "error" ? o.statusError : o.statusCompleted;
|
|
507
|
+
return {
|
|
508
|
+
displayPct: c,
|
|
509
|
+
isActive: u,
|
|
510
|
+
progressWidth: f,
|
|
511
|
+
bgProgressStyle: p,
|
|
512
|
+
progressFillStyle: {
|
|
513
|
+
width: f,
|
|
514
|
+
background: o.progressFill
|
|
515
|
+
},
|
|
516
|
+
statusText: h,
|
|
517
|
+
sizeText: g,
|
|
518
|
+
statusColor: _,
|
|
519
|
+
progressInsetPx: r,
|
|
520
|
+
showProgressGlow: t === "uploading"
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region src/components/upload/Upload.tsx
|
|
525
|
+
function B({ file: r, status: i = "uploading", progress: a = 0, errorMessage: o, completedVariant: s = "compact", config: l, onPause: u, onResume: d, onCancel: f, onDelete: m, onChange: h, onDownload: g, onRetry: _, className: y = "", exiting: b = !1 }) {
|
|
526
|
+
let x = M(l), S = s === "expanded" && i === "completed", C = P(x.colors), { isActive: w, bgProgressStyle: T, progressFillStyle: E, statusText: D, sizeText: O, statusColor: k, progressInsetPx: A, showProgressGlow: j } = z({
|
|
527
|
+
file: r,
|
|
528
|
+
status: i,
|
|
529
|
+
progress: a,
|
|
530
|
+
progressInset: x.progressInset,
|
|
531
|
+
errorMessage: o,
|
|
532
|
+
colors: x.colors,
|
|
533
|
+
labels: x.labels
|
|
534
|
+
}), N = c(ee, b ? "animate-upload-exit" : "animate-upload-enter", y), F = {
|
|
535
|
+
...C,
|
|
536
|
+
maxWidth: x.maxWidth,
|
|
537
|
+
backgroundColor: x.colors.cardBackground,
|
|
538
|
+
boxShadow: x.colors.cardShadow
|
|
539
|
+
}, I = /* @__PURE__ */ n(e, { children: [
|
|
540
|
+
x.showBackgroundProgress && w && /* @__PURE__ */ t("div", {
|
|
541
|
+
className: "pointer-events-none absolute inset-y-0 left-0 z-0 shadow-[inset_-20px_0_40px_rgba(129,140,248,0.15)]",
|
|
542
|
+
style: T
|
|
543
|
+
}),
|
|
544
|
+
/* @__PURE__ */ n("div", {
|
|
545
|
+
className: "relative z-[1] flex items-center gap-3 px-4 pt-4 pb-3",
|
|
546
|
+
children: [
|
|
547
|
+
/* @__PURE__ */ t(p, {
|
|
548
|
+
filename: r.name,
|
|
549
|
+
className: "h-12 w-10 shrink-0"
|
|
550
|
+
}),
|
|
551
|
+
/* @__PURE__ */ n("div", {
|
|
552
|
+
className: "min-w-0 flex-1",
|
|
553
|
+
children: [/* @__PURE__ */ t("p", {
|
|
554
|
+
className: "mb-1 truncate text-[15px] font-semibold",
|
|
555
|
+
style: { color: x.colors.fileName },
|
|
556
|
+
children: r.name
|
|
557
|
+
}), /* @__PURE__ */ n("p", {
|
|
558
|
+
className: "m-0 flex items-center gap-1.5 text-[13px] leading-snug",
|
|
559
|
+
"aria-live": "polite",
|
|
560
|
+
children: [
|
|
561
|
+
i === "completed" && /* @__PURE__ */ t("span", {
|
|
562
|
+
className: "inline-flex h-4 w-4 shrink-0 animate-check-in items-center justify-center rounded-full text-white",
|
|
563
|
+
style: { backgroundColor: x.colors.successBadgeBackground },
|
|
564
|
+
children: /* @__PURE__ */ t(v, {})
|
|
565
|
+
}),
|
|
566
|
+
/* @__PURE__ */ t("span", {
|
|
567
|
+
className: "font-medium",
|
|
568
|
+
style: { color: k },
|
|
569
|
+
children: D
|
|
570
|
+
}),
|
|
571
|
+
/* @__PURE__ */ t("span", {
|
|
572
|
+
style: { color: x.colors.metaSeparator },
|
|
573
|
+
children: "•"
|
|
574
|
+
}),
|
|
575
|
+
/* @__PURE__ */ t("span", {
|
|
576
|
+
style: { color: x.colors.metaMuted },
|
|
577
|
+
children: O
|
|
578
|
+
})
|
|
579
|
+
]
|
|
580
|
+
})]
|
|
581
|
+
}),
|
|
582
|
+
/* @__PURE__ */ t(R, {
|
|
583
|
+
status: i,
|
|
584
|
+
pausable: x.pausable,
|
|
585
|
+
cancelable: x.cancelable,
|
|
586
|
+
deletable: x.deletable,
|
|
587
|
+
retryable: x.retryable,
|
|
588
|
+
retryLabel: x.labels.retry,
|
|
589
|
+
onPause: u,
|
|
590
|
+
onResume: d,
|
|
591
|
+
onCancel: f,
|
|
592
|
+
onDelete: m,
|
|
593
|
+
onRetry: _
|
|
594
|
+
})
|
|
595
|
+
]
|
|
596
|
+
}),
|
|
597
|
+
x.showProgressBar && w && /* @__PURE__ */ t("div", {
|
|
598
|
+
className: "relative z-[1] pb-3.5",
|
|
599
|
+
style: {
|
|
600
|
+
paddingLeft: A,
|
|
601
|
+
paddingRight: A
|
|
602
|
+
},
|
|
603
|
+
children: /* @__PURE__ */ t("div", {
|
|
604
|
+
className: "h-[3px] overflow-hidden",
|
|
605
|
+
style: { backgroundColor: x.colors.progressTrack },
|
|
606
|
+
children: /* @__PURE__ */ t("div", {
|
|
607
|
+
className: c("h-full rounded-full", j && "animate-progress-glow"),
|
|
608
|
+
style: E
|
|
609
|
+
})
|
|
610
|
+
})
|
|
611
|
+
})
|
|
612
|
+
] });
|
|
613
|
+
return S ? /* @__PURE__ */ n("div", {
|
|
614
|
+
className: "w-full overflow-visible bg-transparent shadow-none",
|
|
615
|
+
style: { maxWidth: x.maxWidth },
|
|
616
|
+
children: [/* @__PURE__ */ t("div", {
|
|
617
|
+
className: N,
|
|
618
|
+
style: {
|
|
619
|
+
...C,
|
|
620
|
+
backgroundColor: x.colors.cardBackground,
|
|
621
|
+
boxShadow: x.colors.cardShadow
|
|
622
|
+
},
|
|
623
|
+
children: I
|
|
624
|
+
}), /* @__PURE__ */ n("div", {
|
|
625
|
+
className: "mt-2 flex gap-2",
|
|
626
|
+
children: [/* @__PURE__ */ t("button", {
|
|
627
|
+
type: "button",
|
|
628
|
+
className: "flex-1 cursor-pointer rounded-[10px] border-none px-4 py-2.5 text-sm font-medium transition-colors duration-150",
|
|
629
|
+
style: {
|
|
630
|
+
backgroundColor: x.colors.changeButtonBackground,
|
|
631
|
+
color: x.colors.changeButtonText
|
|
632
|
+
},
|
|
633
|
+
onMouseEnter: (e) => {
|
|
634
|
+
e.currentTarget.style.backgroundColor = x.colors.changeButtonHover;
|
|
635
|
+
},
|
|
636
|
+
onMouseLeave: (e) => {
|
|
637
|
+
e.currentTarget.style.backgroundColor = x.colors.changeButtonBackground;
|
|
638
|
+
},
|
|
639
|
+
onClick: h,
|
|
640
|
+
children: x.labels.change
|
|
641
|
+
}), /* @__PURE__ */ t("button", {
|
|
642
|
+
type: "button",
|
|
643
|
+
className: "flex-1 cursor-pointer rounded-[10px] border-none px-4 py-2.5 text-sm font-medium transition-colors duration-150",
|
|
644
|
+
style: {
|
|
645
|
+
backgroundColor: x.colors.downloadButtonBackground,
|
|
646
|
+
color: x.colors.downloadButtonText
|
|
647
|
+
},
|
|
648
|
+
onMouseEnter: (e) => {
|
|
649
|
+
e.currentTarget.style.backgroundColor = x.colors.downloadButtonHover;
|
|
650
|
+
},
|
|
651
|
+
onMouseLeave: (e) => {
|
|
652
|
+
e.currentTarget.style.backgroundColor = x.colors.downloadButtonBackground;
|
|
653
|
+
},
|
|
654
|
+
onClick: g,
|
|
655
|
+
children: x.labels.download
|
|
656
|
+
})]
|
|
657
|
+
})]
|
|
658
|
+
}) : /* @__PURE__ */ t("div", {
|
|
659
|
+
className: N,
|
|
660
|
+
style: F,
|
|
661
|
+
children: I
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
//#endregion
|
|
665
|
+
//#region src/components/upload/Dropzone.tsx
|
|
666
|
+
function V({ disabled: e, isDragging: r, labels: i, style: a, dropHandlers: o, onOpen: s, className: l, showClickHint: u = !0 }) {
|
|
667
|
+
let d = r && !e, f = e ? i.hintDisabled : d ? i.hintActive : i.hint, p = e ? a.borderColorDisabled : d ? a.borderColorActive : a.borderColor, m = d ? a.backgroundActive : a.background, h = e ? a.textColorDisabled : d ? a.textColorActive : a.textColor;
|
|
668
|
+
return /* @__PURE__ */ n("div", {
|
|
669
|
+
role: "button",
|
|
670
|
+
tabIndex: e ? -1 : 0,
|
|
671
|
+
"aria-disabled": e,
|
|
672
|
+
className: c("flex cursor-pointer flex-col items-center justify-center border border-dashed px-4 py-6 text-center transition-[border-color,background,color,box-shadow] duration-150", e && "cursor-not-allowed opacity-70", d && "shadow-[0_0_0_1px_var(--upload-dropzone-border)]", l),
|
|
673
|
+
style: {
|
|
674
|
+
"--upload-dropzone-border": p,
|
|
675
|
+
minHeight: a.minHeight,
|
|
676
|
+
borderRadius: a.borderRadius,
|
|
677
|
+
borderColor: p,
|
|
678
|
+
background: m,
|
|
679
|
+
color: h,
|
|
680
|
+
boxShadow: d ? `0 0 0 1px ${p}` : void 0
|
|
681
|
+
},
|
|
682
|
+
onClick: () => {
|
|
683
|
+
e || s();
|
|
684
|
+
},
|
|
685
|
+
onKeyDown: (t) => {
|
|
686
|
+
e || (t.key === "Enter" || t.key === " ") && (t.preventDefault(), s());
|
|
687
|
+
},
|
|
688
|
+
...o,
|
|
689
|
+
children: [/* @__PURE__ */ t("p", {
|
|
690
|
+
className: "m-0 text-sm",
|
|
691
|
+
children: f
|
|
692
|
+
}), u && !e && /* @__PURE__ */ t("button", {
|
|
693
|
+
type: "button",
|
|
694
|
+
className: "mt-2 cursor-pointer border-none bg-transparent p-0 text-[13px] underline-offset-2 hover:underline",
|
|
695
|
+
style: { color: h },
|
|
696
|
+
onClick: (e) => {
|
|
697
|
+
e.stopPropagation(), s();
|
|
698
|
+
},
|
|
699
|
+
children: i.clickHint
|
|
700
|
+
})]
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
//#endregion
|
|
704
|
+
//#region src/components/upload/hooks/useUploadDragDrop.ts
|
|
705
|
+
function re(e) {
|
|
706
|
+
let t = [];
|
|
707
|
+
if (e.items?.length) {
|
|
708
|
+
for (let n of e.items) if (n.kind === "file") {
|
|
709
|
+
let e = n.getAsFile();
|
|
710
|
+
e && t.push(e);
|
|
711
|
+
}
|
|
712
|
+
return t;
|
|
713
|
+
}
|
|
714
|
+
return Array.from(e.files);
|
|
715
|
+
}
|
|
716
|
+
function H(e) {
|
|
717
|
+
return e?.types ? Array.from(e.types).includes("Files") : !1;
|
|
718
|
+
}
|
|
719
|
+
function U({ enabled: e, global: t = !1, preventDocumentDrop: n = !0, disabled: a = !1, onDropFiles: c }) {
|
|
720
|
+
let [l, u] = s(!1), d = o(0), f = r(() => {
|
|
721
|
+
d.current = 0, u(!1);
|
|
722
|
+
}, []), p = r((t) => {
|
|
723
|
+
if (a || !e) return;
|
|
724
|
+
let n = re(t ?? new DataTransfer());
|
|
725
|
+
n.length > 0 && c(n);
|
|
726
|
+
}, [
|
|
727
|
+
a,
|
|
728
|
+
e,
|
|
729
|
+
c
|
|
730
|
+
]), m = r((t) => {
|
|
731
|
+
t.preventDefault(), t.stopPropagation(), !(a || !e || !H(t.dataTransfer)) && (d.current += 1, u(!0));
|
|
732
|
+
}, [a, e]), h = r((e) => {
|
|
733
|
+
e.preventDefault(), e.stopPropagation(), d.current = Math.max(0, d.current - 1), d.current === 0 && u(!1);
|
|
734
|
+
}, []), g = r((t) => {
|
|
735
|
+
t.preventDefault(), t.stopPropagation(), !(a || !e || !H(t.dataTransfer)) && (t.dataTransfer.dropEffect = "copy");
|
|
736
|
+
}, [a, e]), _ = r((e) => {
|
|
737
|
+
e.preventDefault(), e.stopPropagation(), f(), p(e.dataTransfer);
|
|
738
|
+
}, [p, f]);
|
|
739
|
+
return i(() => {
|
|
740
|
+
if (!e || !t) return;
|
|
741
|
+
let n = (e) => {
|
|
742
|
+
a || !H(e.dataTransfer) || (e.preventDefault(), d.current += 1, u(!0));
|
|
743
|
+
}, r = (e) => {
|
|
744
|
+
H(e.dataTransfer) && (e.preventDefault(), d.current = Math.max(0, d.current - 1), d.current === 0 && u(!1));
|
|
745
|
+
}, i = (e) => {
|
|
746
|
+
a || !H(e.dataTransfer) || (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "copy"));
|
|
747
|
+
}, o = (e) => {
|
|
748
|
+
e.preventDefault(), f(), p(e.dataTransfer);
|
|
749
|
+
};
|
|
750
|
+
return document.addEventListener("dragenter", n), document.addEventListener("dragleave", r), document.addEventListener("dragover", i), document.addEventListener("drop", o), () => {
|
|
751
|
+
document.removeEventListener("dragenter", n), document.removeEventListener("dragleave", r), document.removeEventListener("dragover", i), document.removeEventListener("drop", o);
|
|
752
|
+
};
|
|
753
|
+
}, [
|
|
754
|
+
a,
|
|
755
|
+
e,
|
|
756
|
+
t,
|
|
757
|
+
p,
|
|
758
|
+
f
|
|
759
|
+
]), i(() => {
|
|
760
|
+
if (!e || !n) return;
|
|
761
|
+
let t = (e) => {
|
|
762
|
+
e.preventDefault();
|
|
763
|
+
};
|
|
764
|
+
return document.addEventListener("dragover", t), document.addEventListener("drop", t), () => {
|
|
765
|
+
document.removeEventListener("dragover", t), document.removeEventListener("drop", t);
|
|
766
|
+
};
|
|
767
|
+
}, [e, n]), {
|
|
768
|
+
isDragging: l,
|
|
769
|
+
dropHandlers: e ? {
|
|
770
|
+
onDragEnter: m,
|
|
771
|
+
onDragLeave: h,
|
|
772
|
+
onDragOver: g,
|
|
773
|
+
onDrop: _
|
|
774
|
+
} : {}
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
//#endregion
|
|
778
|
+
//#region src/components/upload/utils/fileAccept.ts
|
|
779
|
+
function W(e) {
|
|
780
|
+
if (e) {
|
|
781
|
+
if (Array.isArray(e)) {
|
|
782
|
+
let t = e.map((e) => e.trim()).filter(Boolean);
|
|
783
|
+
return t.length > 0 ? t.join(",") : void 0;
|
|
784
|
+
}
|
|
785
|
+
return e.trim() || void 0;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
function ie(e, t) {
|
|
789
|
+
let n = t.trim().toLowerCase();
|
|
790
|
+
if (!n) return !0;
|
|
791
|
+
if (n.startsWith(".")) return (e.name.includes(".") ? `.${e.name.split(".").pop().toLowerCase()}` : "") === n;
|
|
792
|
+
if (n.endsWith("/*")) {
|
|
793
|
+
let t = n.slice(0, -1);
|
|
794
|
+
return e.type.toLowerCase().startsWith(t);
|
|
795
|
+
}
|
|
796
|
+
return n.includes("/") ? e.type.toLowerCase() === n : (e.name.includes(".") ? e.name.split(".").pop().toLowerCase() : "") === n.replace(/^\./, "");
|
|
797
|
+
}
|
|
798
|
+
function G(e, t) {
|
|
799
|
+
let n = W(t);
|
|
800
|
+
return n ? n.split(",").some((t) => ie(e, t)) : !0;
|
|
801
|
+
}
|
|
802
|
+
function K(e, t) {
|
|
803
|
+
let n = [], r = [];
|
|
804
|
+
for (let i of e) G(i, t) ? n.push(i) : r.push(i);
|
|
805
|
+
return {
|
|
806
|
+
accepted: n,
|
|
807
|
+
rejected: r
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
function q(e, t, n) {
|
|
811
|
+
if (n == null || n <= 0) return {
|
|
812
|
+
accepted: e,
|
|
813
|
+
rejected: []
|
|
814
|
+
};
|
|
815
|
+
let r = n - t;
|
|
816
|
+
return r <= 0 ? {
|
|
817
|
+
accepted: [],
|
|
818
|
+
rejected: e
|
|
819
|
+
} : {
|
|
820
|
+
accepted: e.slice(0, r),
|
|
821
|
+
rejected: e.slice(r)
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
//#endregion
|
|
825
|
+
//#region src/components/upload/hooks/useUploadPicker.ts
|
|
826
|
+
function J({ config: e, currentCount: t = 0, onFilesSelected: n, onReject: i }) {
|
|
827
|
+
let a = N(e), o = W(a.accept), s = r((e) => {
|
|
828
|
+
let r = Array.from(e);
|
|
829
|
+
if (r.length === 0) return;
|
|
830
|
+
let { accepted: o, rejected: s } = K(r, a.accept);
|
|
831
|
+
if (s.length > 0 && i?.("invalid-format", s), o.length === 0) return;
|
|
832
|
+
let { accepted: c, rejected: l } = q(o, t, a.maxCount);
|
|
833
|
+
l.length > 0 && i?.("max-count", l), c.length > 0 && n(c);
|
|
834
|
+
}, [
|
|
835
|
+
t,
|
|
836
|
+
n,
|
|
837
|
+
i,
|
|
838
|
+
a.accept,
|
|
839
|
+
a.maxCount
|
|
840
|
+
]);
|
|
841
|
+
return {
|
|
842
|
+
accept: o,
|
|
843
|
+
multiple: a.multiple,
|
|
844
|
+
labels: a.labels,
|
|
845
|
+
processFiles: s
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
//#endregion
|
|
849
|
+
//#region src/components/upload/Picker.tsx
|
|
850
|
+
function Y({ config: r, currentCount: i = 0, onFilesSelected: a, onReject: s, disabled: l = !1, className: u, buttonClassName: d, dropzoneClassName: f, wrapperClassName: p, children: m }) {
|
|
851
|
+
let h = o(null), g = N(r), _ = g.drag, { accept: v, multiple: y, processFiles: b } = J({
|
|
852
|
+
config: r,
|
|
853
|
+
currentCount: i,
|
|
854
|
+
onFilesSelected: a,
|
|
855
|
+
onReject: s
|
|
856
|
+
}), { isDragging: x, dropHandlers: S } = U({
|
|
857
|
+
enabled: _.enabled,
|
|
858
|
+
global: _.global,
|
|
859
|
+
preventDocumentDrop: _.preventDocumentDrop,
|
|
860
|
+
disabled: l,
|
|
861
|
+
onDropFiles: b
|
|
862
|
+
}), C = () => {
|
|
863
|
+
l || h.current?.click();
|
|
864
|
+
}, w = (e) => {
|
|
865
|
+
e.target.files && b(e.target.files), e.target.value = "";
|
|
866
|
+
}, T = _.enabled && _.showDropzone, E = g.showButton, D = _.global ? {} : S, O = _.enabled ? S : {}, k = E ? /* @__PURE__ */ t("button", {
|
|
867
|
+
type: "button",
|
|
868
|
+
className: c(d ?? g.buttonClassName, u),
|
|
869
|
+
onClick: C,
|
|
870
|
+
disabled: l,
|
|
871
|
+
...!T && _.enabled ? O : {},
|
|
872
|
+
children: g.buttonLabel
|
|
873
|
+
}) : null, A = T ? /* @__PURE__ */ t(V, {
|
|
874
|
+
disabled: l,
|
|
875
|
+
isDragging: x,
|
|
876
|
+
labels: _.labels,
|
|
877
|
+
style: _.style,
|
|
878
|
+
dropHandlers: D,
|
|
879
|
+
onOpen: C,
|
|
880
|
+
showClickHint: !E,
|
|
881
|
+
className: f
|
|
882
|
+
}) : null;
|
|
883
|
+
return /* @__PURE__ */ n(e, { children: [/* @__PURE__ */ t("input", {
|
|
884
|
+
ref: h,
|
|
885
|
+
type: "file",
|
|
886
|
+
hidden: !0,
|
|
887
|
+
accept: v,
|
|
888
|
+
multiple: y,
|
|
889
|
+
disabled: l,
|
|
890
|
+
onChange: w
|
|
891
|
+
}), m ? m({
|
|
892
|
+
open: C,
|
|
893
|
+
disabled: l,
|
|
894
|
+
isDragging: x,
|
|
895
|
+
dropHandlers: O,
|
|
896
|
+
button: k,
|
|
897
|
+
dropzone: A
|
|
898
|
+
}) : E && T ? /* @__PURE__ */ n("div", {
|
|
899
|
+
className: c("flex flex-col gap-3", p),
|
|
900
|
+
children: [/* @__PURE__ */ t("div", {
|
|
901
|
+
className: "flex justify-end",
|
|
902
|
+
children: k
|
|
903
|
+
}), A]
|
|
904
|
+
}) : T ? A : k] });
|
|
905
|
+
}
|
|
906
|
+
//#endregion
|
|
907
|
+
//#region src/components/upload/hooks/useMockUpload.ts
|
|
908
|
+
var ae = 20;
|
|
909
|
+
function X({ file: e, speed: t = ae, onComplete: n }) {
|
|
910
|
+
let [a, c] = s("uploading"), [l, u] = s(0), d = o(null), f = o(null), p = o(0), m = o("uploading"), h = o(n);
|
|
911
|
+
h.current = n;
|
|
912
|
+
let g = r(() => {
|
|
913
|
+
d.current !== null && (cancelAnimationFrame(d.current), d.current = null), f.current = null;
|
|
914
|
+
}, []), _ = r((e) => {
|
|
915
|
+
if (m.current !== "uploading") {
|
|
916
|
+
g();
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
f.current === null && (f.current = e);
|
|
920
|
+
let n = e - f.current;
|
|
921
|
+
f.current = e;
|
|
922
|
+
let r = n / 1e3 * t, i = Math.min(100, p.current + r);
|
|
923
|
+
if (p.current = i, u(i), i >= 100) {
|
|
924
|
+
m.current = "completed", c("completed"), g(), h.current?.();
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
d.current = requestAnimationFrame(_);
|
|
928
|
+
}, [t, g]), v = r(() => {
|
|
929
|
+
g(), f.current = null, d.current = requestAnimationFrame(_);
|
|
930
|
+
}, [g, _]);
|
|
931
|
+
return i(() => (p.current = 0, m.current = "uploading", u(0), c("uploading"), v(), () => {
|
|
932
|
+
g();
|
|
933
|
+
}), [
|
|
934
|
+
e,
|
|
935
|
+
v,
|
|
936
|
+
g
|
|
937
|
+
]), {
|
|
938
|
+
status: a,
|
|
939
|
+
progress: l,
|
|
940
|
+
pause: r(() => {
|
|
941
|
+
m.current === "uploading" && (m.current = "paused", c("paused"), g());
|
|
942
|
+
}, [g]),
|
|
943
|
+
resume: r(() => {
|
|
944
|
+
m.current === "paused" && (m.current = "uploading", c("uploading"), v());
|
|
945
|
+
}, [v]),
|
|
946
|
+
cancel: r(() => {
|
|
947
|
+
g(), m.current = "uploading", p.current = 0;
|
|
948
|
+
}, [g])
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
//#endregion
|
|
952
|
+
//#region src/components/upload/MockUpload.tsx
|
|
953
|
+
function Z({ file: e, completedVariant: n = "compact", config: i, speed: a, onComplete: o, onCancel: c, onDelete: l, onChange: u, onDownload: d, className: f }) {
|
|
954
|
+
let [p, m] = s(!1), [h, g] = s(!0), { status: _, progress: v, pause: y, resume: b, cancel: x } = X({
|
|
955
|
+
file: e,
|
|
956
|
+
speed: a,
|
|
957
|
+
onComplete: o
|
|
958
|
+
}), S = r((e) => {
|
|
959
|
+
m(!0), setTimeout(() => {
|
|
960
|
+
g(!1), e?.();
|
|
961
|
+
}, 250);
|
|
962
|
+
}, []);
|
|
963
|
+
return h ? /* @__PURE__ */ t(B, {
|
|
964
|
+
file: e,
|
|
965
|
+
status: _,
|
|
966
|
+
progress: v,
|
|
967
|
+
completedVariant: n,
|
|
968
|
+
config: i,
|
|
969
|
+
onPause: y,
|
|
970
|
+
onResume: b,
|
|
971
|
+
onCancel: () => {
|
|
972
|
+
x(), S(c);
|
|
973
|
+
},
|
|
974
|
+
onDelete: () => S(l),
|
|
975
|
+
onChange: u,
|
|
976
|
+
onDownload: d,
|
|
977
|
+
className: f,
|
|
978
|
+
exiting: p
|
|
979
|
+
}) : null;
|
|
980
|
+
}
|
|
981
|
+
//#endregion
|
|
982
|
+
//#region src/components/upload/hooks/useUpload.ts
|
|
983
|
+
function Q({ file: e, url: t, method: n = "POST", fieldName: a = "file", headers: c, withCredentials: l = !1, extraFields: u, onComplete: d, onError: f }) {
|
|
984
|
+
let [p, m] = s("uploading"), [h, g] = s(0), [_, v] = s(null), y = o(null), b = o(d), x = o(f);
|
|
985
|
+
b.current = d, x.current = f;
|
|
986
|
+
let S = r(() => {
|
|
987
|
+
y.current?.abort(), y.current = null;
|
|
988
|
+
}, []), C = r(() => {
|
|
989
|
+
S();
|
|
990
|
+
let r = new XMLHttpRequest();
|
|
991
|
+
y.current = r;
|
|
992
|
+
let i = new FormData();
|
|
993
|
+
i.append(a, e), u && Object.entries(u).forEach(([e, t]) => {
|
|
994
|
+
i.append(e, t);
|
|
995
|
+
}), r.upload.onprogress = (e) => {
|
|
996
|
+
e.lengthComputable && g(Math.min(100, e.loaded / e.total * 100));
|
|
997
|
+
}, r.onload = () => {
|
|
998
|
+
if (y.current = null, r.status >= 200 && r.status < 300) {
|
|
999
|
+
m("completed"), g(100), v(null), b.current?.(r);
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
let e = `HTTP ${r.status}`;
|
|
1003
|
+
m("error"), v(e), x.current?.(Error(e));
|
|
1004
|
+
}, r.onerror = () => {
|
|
1005
|
+
y.current = null;
|
|
1006
|
+
let e = "Network error";
|
|
1007
|
+
m("error"), v(e), x.current?.(/* @__PURE__ */ Error(e));
|
|
1008
|
+
}, r.onabort = () => {
|
|
1009
|
+
y.current = null;
|
|
1010
|
+
}, r.open(n, t), r.withCredentials = l, c && Object.entries(c).forEach(([e, t]) => {
|
|
1011
|
+
r.setRequestHeader(e, t);
|
|
1012
|
+
}), m("uploading"), g(0), v(null), r.send(i);
|
|
1013
|
+
}, [
|
|
1014
|
+
S,
|
|
1015
|
+
u,
|
|
1016
|
+
a,
|
|
1017
|
+
e,
|
|
1018
|
+
c,
|
|
1019
|
+
n,
|
|
1020
|
+
t,
|
|
1021
|
+
l
|
|
1022
|
+
]);
|
|
1023
|
+
return i(() => (C(), S), [
|
|
1024
|
+
e,
|
|
1025
|
+
t,
|
|
1026
|
+
C,
|
|
1027
|
+
S
|
|
1028
|
+
]), {
|
|
1029
|
+
status: p,
|
|
1030
|
+
progress: h,
|
|
1031
|
+
error: _,
|
|
1032
|
+
cancel: r(() => {
|
|
1033
|
+
S(), g(0), v(null), m("uploading");
|
|
1034
|
+
}, [S]),
|
|
1035
|
+
retry: r(() => {
|
|
1036
|
+
C();
|
|
1037
|
+
}, [C])
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region src/components/upload/UploadRequest.tsx
|
|
1042
|
+
function $({ file: e, url: n, method: i, fieldName: a, headers: o, withCredentials: c, extraFields: l, completedVariant: u = "compact", config: d, onComplete: f, onError: p, onCancel: m, onDelete: h, onChange: g, onDownload: _, onRetry: v, className: y }) {
|
|
1043
|
+
let [b, x] = s(!1), [S, C] = s(!0), { status: w, progress: T, error: E, cancel: D, retry: O } = Q({
|
|
1044
|
+
file: e,
|
|
1045
|
+
url: n,
|
|
1046
|
+
method: i,
|
|
1047
|
+
fieldName: a,
|
|
1048
|
+
headers: o,
|
|
1049
|
+
withCredentials: c,
|
|
1050
|
+
extraFields: l,
|
|
1051
|
+
onComplete: f,
|
|
1052
|
+
onError: p
|
|
1053
|
+
}), k = r((e) => {
|
|
1054
|
+
x(!0), setTimeout(() => {
|
|
1055
|
+
C(!1), e?.();
|
|
1056
|
+
}, 250);
|
|
1057
|
+
}, []);
|
|
1058
|
+
return S ? /* @__PURE__ */ t(B, {
|
|
1059
|
+
file: e,
|
|
1060
|
+
status: w,
|
|
1061
|
+
progress: T,
|
|
1062
|
+
errorMessage: E ?? void 0,
|
|
1063
|
+
completedVariant: u,
|
|
1064
|
+
config: {
|
|
1065
|
+
pausable: !1,
|
|
1066
|
+
...d
|
|
1067
|
+
},
|
|
1068
|
+
onCancel: () => {
|
|
1069
|
+
D(), k(m);
|
|
1070
|
+
},
|
|
1071
|
+
onRetry: () => {
|
|
1072
|
+
O(), v?.();
|
|
1073
|
+
},
|
|
1074
|
+
onDelete: () => k(h),
|
|
1075
|
+
onChange: g,
|
|
1076
|
+
onDownload: _,
|
|
1077
|
+
className: y,
|
|
1078
|
+
exiting: b
|
|
1079
|
+
}) : null;
|
|
1080
|
+
}
|
|
1081
|
+
//#endregion
|
|
1082
|
+
//#region src/components/upload/index.tsx
|
|
1083
|
+
var oe = Object.assign(B, {
|
|
1084
|
+
Dropzone: V,
|
|
1085
|
+
Picker: Y
|
|
1086
|
+
});
|
|
1087
|
+
//#endregion
|
|
1088
|
+
export { b as DARK_THEME_COLORS, D as DEFAULT_DRAG_CONFIG, E as DEFAULT_DROPZONE_STYLE, A as DEFAULT_PICKER_CONFIG, S as DEFAULT_UPLOAD_CONFIG, V as Dropzone, V as UploadDropzone, p as FileTypeIcon, x as LIGHT_THEME_COLORS, Z as MockUpload, Z as UploadWithMock, Y as Picker, Y as UploadPicker, oe as Upload, R as UploadActions, $ as UploadRequest, $ as UploadWithUpload, q as applyMaxCount, c as cn, K as filterAcceptedFiles, l as formatBytes, u as getFileExtension, G as isFileAccepted, W as normalizeAccept, M as resolveUploadConfig, N as resolveUploadPickerConfig, X as useMockUpload, Q as useUpload, z as useUploadDisplay, U as useUploadDragDrop, J as useUploadPicker };
|