@duxweb/dvha-core 1.1.30 → 1.2.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.
Files changed (159) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -0
  2. package/dist/cjs/components/auth/can.cjs +1 -1
  3. package/dist/cjs/components/auth/index.cjs +1 -0
  4. package/dist/cjs/components/common/icon.cjs +1 -1
  5. package/dist/cjs/components/common/index.cjs +1 -0
  6. package/dist/cjs/components/common/logo.cjs +1 -1
  7. package/dist/cjs/components/index.cjs +1 -0
  8. package/dist/cjs/components/loader/iframe.cjs +1 -1
  9. package/dist/cjs/components/loader/index.cjs +1 -0
  10. package/dist/cjs/components/loader/loader.cjs +1 -1
  11. package/dist/cjs/components/loader/remote/index.cjs +1 -0
  12. package/dist/cjs/components/loader/remote/loader.cjs +1 -1
  13. package/dist/cjs/components/loader/remote/render.cjs +1 -1
  14. package/dist/cjs/components/overlay/index.cjs +1 -0
  15. package/dist/cjs/components/overlay/overlay.cjs +1 -1
  16. package/dist/cjs/components/status/error.cjs +1 -1
  17. package/dist/cjs/components/status/exception.cjs +1 -1
  18. package/dist/cjs/components/status/index.cjs +1 -0
  19. package/dist/cjs/components/status/notAuthorized.cjs +1 -1
  20. package/dist/cjs/components/status/notFound.cjs +1 -1
  21. package/dist/cjs/config/color.cjs +1 -1
  22. package/dist/cjs/directive/index.cjs +1 -0
  23. package/dist/cjs/directive/permission.cjs +1 -1
  24. package/dist/cjs/hooks/auth.cjs +1 -1
  25. package/dist/cjs/hooks/config.cjs +1 -1
  26. package/dist/cjs/hooks/data.cjs +1 -1
  27. package/dist/cjs/hooks/export.cjs +1 -1
  28. package/dist/cjs/hooks/exportCsv.cjs +2 -2
  29. package/dist/cjs/hooks/form.cjs +1 -1
  30. package/dist/cjs/hooks/formExtend.cjs +1 -1
  31. package/dist/cjs/hooks/formValidate.cjs +1 -1
  32. package/dist/cjs/hooks/i18n.cjs +1 -1
  33. package/dist/cjs/hooks/import.cjs +1 -1
  34. package/dist/cjs/hooks/importCsv.cjs +2 -2
  35. package/dist/cjs/hooks/index.cjs +1 -0
  36. package/dist/cjs/hooks/json/index.cjs +1 -1
  37. package/dist/cjs/hooks/json/utils/contextManager.cjs +1 -1
  38. package/dist/cjs/hooks/json/utils/expressionParser.cjs +1 -1
  39. package/dist/cjs/hooks/json/vFor.cjs +1 -1
  40. package/dist/cjs/hooks/json/vIf.cjs +1 -1
  41. package/dist/cjs/hooks/json/vModel.cjs +1 -1
  42. package/dist/cjs/hooks/json/vOn.cjs +1 -1
  43. package/dist/cjs/hooks/json/vShow.cjs +1 -1
  44. package/dist/cjs/hooks/json/vText.cjs +1 -1
  45. package/dist/cjs/hooks/json.cjs +1 -1
  46. package/dist/cjs/hooks/list.cjs +1 -1
  47. package/dist/cjs/hooks/manage.cjs +1 -1
  48. package/dist/cjs/hooks/menu.cjs +1 -1
  49. package/dist/cjs/hooks/overlay.cjs +1 -1
  50. package/dist/cjs/hooks/select.cjs +1 -1
  51. package/dist/cjs/hooks/theme.cjs +4 -8
  52. package/dist/cjs/hooks/tree.cjs +1 -1
  53. package/dist/cjs/hooks/upload/index.cjs +1 -0
  54. package/dist/cjs/hooks/upload/local.cjs +1 -1
  55. package/dist/cjs/hooks/upload/s3.cjs +1 -1
  56. package/dist/cjs/hooks/upload.cjs +1 -1
  57. package/dist/cjs/index.cjs +1 -1
  58. package/dist/cjs/main.cjs +1 -1
  59. package/dist/cjs/preset/authProvider.cjs +1 -1
  60. package/dist/cjs/preset/dataProvider.cjs +1 -1
  61. package/dist/cjs/preset/i18nProvider.cjs +1 -1
  62. package/dist/cjs/preset/index.cjs +1 -0
  63. package/dist/cjs/provider/app.cjs +1 -1
  64. package/dist/cjs/provider/index.cjs +1 -0
  65. package/dist/cjs/provider/tab.cjs +1 -1
  66. package/dist/cjs/router/index.cjs +1 -0
  67. package/dist/cjs/router/route.cjs +1 -1
  68. package/dist/cjs/stores/auth.cjs +1 -1
  69. package/dist/cjs/stores/i18n.cjs +1 -1
  70. package/dist/cjs/stores/index.cjs +1 -0
  71. package/dist/cjs/stores/jsonSchema.cjs +1 -1
  72. package/dist/cjs/stores/manage.cjs +1 -1
  73. package/dist/cjs/stores/route.cjs +1 -1
  74. package/dist/cjs/stores/tab.cjs +1 -1
  75. package/dist/cjs/stores/theme.cjs +1 -1
  76. package/dist/cjs/utils/bus.cjs +1 -1
  77. package/dist/cjs/utils/index.cjs +1 -0
  78. package/dist/cjs/utils/theme.cjs +8 -8
  79. package/dist/cjs/utils/tree.cjs +1 -1
  80. package/dist/esm/_virtual/_rolldown/runtime.js +9 -0
  81. package/dist/esm/components/auth/can.js +17 -36
  82. package/dist/esm/components/auth/index.js +1 -0
  83. package/dist/esm/components/common/icon.js +16 -24
  84. package/dist/esm/components/common/index.js +2 -0
  85. package/dist/esm/components/common/logo.js +50 -49
  86. package/dist/esm/components/index.js +14 -0
  87. package/dist/esm/components/loader/iframe.js +16 -18
  88. package/dist/esm/components/loader/index.js +1 -0
  89. package/dist/esm/components/loader/loader.js +11 -40
  90. package/dist/esm/components/loader/remote/index.js +2 -0
  91. package/dist/esm/components/loader/remote/loader.js +118 -156
  92. package/dist/esm/components/loader/remote/render.js +12 -17
  93. package/dist/esm/components/overlay/index.js +1 -0
  94. package/dist/esm/components/overlay/overlay.js +54 -70
  95. package/dist/esm/components/status/error.js +7 -9
  96. package/dist/esm/components/status/exception.js +21 -37
  97. package/dist/esm/components/status/index.js +4 -0
  98. package/dist/esm/components/status/notAuthorized.js +7 -9
  99. package/dist/esm/components/status/notFound.js +7 -9
  100. package/dist/esm/config/color.js +288 -290
  101. package/dist/esm/directive/index.js +1 -0
  102. package/dist/esm/directive/permission.js +7 -27
  103. package/dist/esm/hooks/auth.js +154 -120
  104. package/dist/esm/hooks/config.js +11 -9
  105. package/dist/esm/hooks/data.js +416 -415
  106. package/dist/esm/hooks/export.js +32 -36
  107. package/dist/esm/hooks/exportCsv.js +42 -46
  108. package/dist/esm/hooks/form.js +86 -95
  109. package/dist/esm/hooks/formExtend.js +36 -40
  110. package/dist/esm/hooks/formValidate.js +22 -25
  111. package/dist/esm/hooks/i18n.js +14 -18
  112. package/dist/esm/hooks/import.js +45 -54
  113. package/dist/esm/hooks/importCsv.js +90 -83
  114. package/dist/esm/hooks/index.js +31 -0
  115. package/dist/esm/hooks/json/index.js +14 -22
  116. package/dist/esm/hooks/json/utils/contextManager.js +35 -26
  117. package/dist/esm/hooks/json/utils/expressionParser.js +100 -123
  118. package/dist/esm/hooks/json/vFor.js +50 -55
  119. package/dist/esm/hooks/json/vIf.js +17 -16
  120. package/dist/esm/hooks/json/vModel.js +96 -106
  121. package/dist/esm/hooks/json/vOn.js +30 -32
  122. package/dist/esm/hooks/json/vShow.js +20 -22
  123. package/dist/esm/hooks/json/vText.js +44 -51
  124. package/dist/esm/hooks/json.js +131 -132
  125. package/dist/esm/hooks/list.js +150 -184
  126. package/dist/esm/hooks/manage.js +25 -22
  127. package/dist/esm/hooks/menu.js +57 -61
  128. package/dist/esm/hooks/overlay.js +6 -23
  129. package/dist/esm/hooks/select.js +84 -94
  130. package/dist/esm/hooks/theme.js +289 -219
  131. package/dist/esm/hooks/tree.js +43 -47
  132. package/dist/esm/hooks/upload/index.js +2 -0
  133. package/dist/esm/hooks/upload/local.js +24 -30
  134. package/dist/esm/hooks/upload/s3.js +70 -80
  135. package/dist/esm/hooks/upload.js +256 -272
  136. package/dist/esm/index.js +150 -141
  137. package/dist/esm/main.js +24 -45
  138. package/dist/esm/preset/authProvider.js +62 -68
  139. package/dist/esm/preset/dataProvider.js +154 -180
  140. package/dist/esm/preset/i18nProvider.js +28 -30
  141. package/dist/esm/preset/index.js +3 -0
  142. package/dist/esm/provider/app.js +124 -151
  143. package/dist/esm/provider/index.js +2 -0
  144. package/dist/esm/provider/tab.js +49 -66
  145. package/dist/esm/router/index.js +1 -0
  146. package/dist/esm/router/route.js +39 -46
  147. package/dist/esm/stores/auth.js +51 -46
  148. package/dist/esm/stores/i18n.js +32 -29
  149. package/dist/esm/stores/index.js +7 -0
  150. package/dist/esm/stores/jsonSchema.js +47 -34
  151. package/dist/esm/stores/manage.js +63 -48
  152. package/dist/esm/stores/route.js +60 -56
  153. package/dist/esm/stores/tab.js +55 -60
  154. package/dist/esm/stores/theme.js +48 -55
  155. package/dist/esm/utils/bus.js +3 -5
  156. package/dist/esm/utils/index.js +3 -0
  157. package/dist/esm/utils/theme.js +110 -93
  158. package/dist/esm/utils/tree.js +28 -37
  159. package/package.json +1 -1
@@ -1,273 +1,257 @@
1
- import { useFileDialog as H } from "@vueuse/core";
2
- import { uniqueId as J } from "lodash-es";
3
- import { ref as g, computed as v, watch as Q } from "vue";
4
- import { createLocalUploadDriver as R } from "./upload/local.js";
5
- function ne(l) {
6
- l = l || {};
7
- const w = g(!1), o = g([]), c = g(-1), u = g(/* @__PURE__ */ new Map()), A = l.driver || R(), P = v(() => {
8
- const { onProgress: e, onDataCallback: t, onCancel: n, onComplete: a, maxFileSize: s, maxFileCount: r, accept: i, multiple: d, autoUpload: f, options: U, onSuccess: S, onError: W, method: X, driver: Y, params: Z, ...j } = l;
9
- return j;
10
- }), $ = v(() => l.method || "POST"), x = v(() => {
11
- const e = o.value.length, t = o.value.reduce((r, i) => r + (i.filesize || 0), 0);
12
- let n = 0, a = 0;
13
- return o.value.forEach((r, i) => {
14
- i < c.value ? n += r.filesize || 0 : i === c.value && (n += Math.min(r.progress?.loaded || 0, r.filesize || 0));
15
- }), t > 0 && (a = Math.max(0, Math.min(100, Math.round(n / t * 100)))), {
16
- index: c.value >= 0 ? c.value + 1 : 0,
17
- totalFiles: e,
18
- currentFile: o.value[c.value],
19
- totalPercent: a,
20
- totalLoaded: n,
21
- totalSize: t
22
- };
23
- }), p = (e) => {
24
- if (e === 0)
25
- return "0 Bytes";
26
- const t = 1024, n = ["Bytes", "KB", "MB", "GB"], a = Math.floor(Math.log(e) / Math.log(t));
27
- return `${Number.parseFloat((e / t ** a).toFixed(2))} ${n[a]}`;
28
- }, h = (e) => {
29
- if (e === 0)
30
- return "0 B/s";
31
- const t = 1024, n = ["B/s", "KB/s", "MB/s", "GB/s"], a = Math.floor(Math.log(e) / Math.log(t));
32
- return `${Number.parseFloat((e / t ** a).toFixed(2))} ${n[a]}`;
33
- }, b = () => J("upload-"), I = async (e, t, n) => {
34
- switch (t) {
35
- case "file": {
36
- if (!(e instanceof File))
37
- throw new TypeError('Payload must be a File when type is "file"');
38
- return e;
39
- }
40
- case "blob": {
41
- if (!(e instanceof Blob))
42
- throw new TypeError('Payload must be a Blob when type is "blob"');
43
- return new File([e], "blob-file", { type: e.type });
44
- }
45
- case "base64": {
46
- if (typeof e != "string")
47
- throw new TypeError('Payload must be a string when type is "base64"');
48
- const a = e.includes(",") ? e.split(",")[1] : e, s = e.includes(",") ? e.split(",")[0].split(":")[1].split(";")[0] : "application/octet-stream", r = atob(a), i = new Uint8Array(r.length);
49
- for (let f = 0; f < r.length; f++)
50
- i[f] = r.charCodeAt(f);
51
- const d = new Blob([i], { type: s });
52
- return new File([d], "base64-file", { type: s });
53
- }
54
- case "arrayBuffer": {
55
- if (!(e instanceof ArrayBuffer))
56
- throw new TypeError('Payload must be ArrayBuffer when type is "arrayBuffer"');
57
- const a = new Blob([e]);
58
- return new File([a], "array-buffer-file", { type: "application/octet-stream" });
59
- }
60
- default:
61
- throw new Error(`Unsupported upload type: ${t}`);
62
- }
63
- }, T = (e) => {
64
- if (l.maxFileSize && e.size > l.maxFileSize)
65
- throw new Error(`File size cannot exceed ${p(l.maxFileSize)}`);
66
- if (l.maxFileCount && o.value.length > l.maxFileCount)
67
- throw new Error(`File count cannot exceed ${l.maxFileCount}`);
68
- }, k = async (e, t, n) => {
69
- const a = await I(e, t);
70
- T(a);
71
- const s = {
72
- id: b(),
73
- file: a,
74
- filename: a.name,
75
- filesize: a.size,
76
- filetype: a.type,
77
- filesizeText: p(a.size),
78
- status: "pending",
79
- progress: {
80
- loaded: 0,
81
- total: a.size,
82
- percent: 0,
83
- speed: 0,
84
- speedText: h(0),
85
- remainingTime: 0,
86
- uploadTime: 0
87
- }
88
- };
89
- return o.value.push(s), s;
90
- }, m = (e, t) => {
91
- const n = o.value.findIndex((a) => a.id === e);
92
- n !== -1 && (o.value[n] = { ...o.value[n], ...t });
93
- }, z = () => {
94
- o.value.every((t) => t.status !== "uploading") && l.onComplete?.(o.value);
95
- }, F = (e) => {
96
- const t = o.value.find((n) => n.id === e);
97
- if (!t || t.status !== "pending" && t.status !== "uploading")
98
- return !1;
99
- if (t.status === "uploading") {
100
- const n = u.value.get(e);
101
- n && (n.abort(), u.value.delete(e));
102
- }
103
- return m(e, {
104
- status: "cancelled"
105
- }), l.onCancel?.(e), z(), !0;
106
- }, D = (e) => {
107
- e ? e.forEach((t) => F(t)) : o.value.forEach((t) => F(t.id));
108
- }, G = async (e) => {
109
- if (!e.file)
110
- throw new Error("File not found");
111
- T(e.file);
112
- const t = new AbortController();
113
- u.value.set(e.id, t);
114
- const n = Date.now();
115
- return m(e.id, { status: "uploading" }), A.upload(e.file, {
116
- ...P.value,
117
- method: $.value,
118
- signal: t.signal,
119
- params: l.params,
120
- onUploadProgress: (a) => {
121
- const i = (Date.now() - n) / 1e3, d = i > 0 ? a.loaded / i : 0, f = (a.total || 0) - a.loaded, U = d > 0 ? f / d : 0, S = {
122
- loaded: a.total ? Math.min(a.loaded, a.total) : a.loaded,
123
- total: a.total,
124
- percent: Math.max(0, Math.min(100, a.percent || 0)),
125
- speed: Math.round(d),
126
- speedText: h(d),
127
- uploadTime: Math.round(i),
128
- remainingTime: Math.round(U)
129
- };
130
- m(e.id, {
131
- status: "uploading",
132
- progress: S
133
- }), l.onProgress?.(x.value);
134
- }
135
- }).then((a) => {
136
- if (e.status === "cancelled")
137
- throw new Error("Upload cancelled");
138
- const s = l.onDataCallback?.(a, e) || a.data, r = Math.round((Date.now() - n) / 1e3), i = {
139
- ...e,
140
- status: "success",
141
- data: a,
142
- ...s,
143
- progress: {
144
- ...e.progress,
145
- loaded: e.filesize || 0,
146
- percent: 100,
147
- speed: 0,
148
- speedText: h(0),
149
- uploadTime: r,
150
- remainingTime: 0
151
- }
152
- };
153
- return m(e.id, i), u.value.delete(e.id), l.onSuccess?.(a), i;
154
- }).catch((a) => {
155
- throw a.message === "canceled" || e.status === "cancelled" ? new Error("Upload cancelled") : (m(e.id, {
156
- status: "error",
157
- error: a.message
158
- }), u.value.delete(e.id), a);
159
- }).finally(() => {
160
- z();
161
- });
162
- }, M = async () => {
163
- const e = o.value.filter((t) => t.status === "pending");
164
- if (e.length === 0)
165
- return [];
166
- w.value = !0;
167
- try {
168
- const t = [];
169
- for (let n = 0; n < e.length; n++) {
170
- const a = e[n], s = o.value.findIndex((i) => i.id === a.id);
171
- c.value = s;
172
- const r = await G(a);
173
- t.push(r);
174
- }
175
- return t;
176
- } catch (t) {
177
- throw l.onError?.({
178
- status: t?.status || 500,
179
- message: t?.message || "upload failed"
180
- }), t;
181
- } finally {
182
- w.value = !1, c.value = -1;
183
- }
184
- }, y = () => {
185
- o.value.forEach((e) => {
186
- F(e.id);
187
- }), u.value.clear(), o.value = [], c.value = -1;
188
- }, C = async (e, t = "file") => {
189
- try {
190
- if (!l.multiple && e.length > 1)
191
- throw new Error("Single file mode: only one file can be selected");
192
- if (!l.multiple && o.value.length > 0 && y(), l.maxFileCount && o.value.length + e.length > l.maxFileCount)
193
- throw new Error(`Adding ${e.length} files would exceed the maximum limit of ${l.maxFileCount}`);
194
- for (const n of e)
195
- await k(n, t);
196
- } catch (n) {
197
- throw l.onError?.({
198
- status: n?.status || 400,
199
- message: n?.message || "Failed to add files"
200
- }), n;
201
- }
202
- l.autoUpload && M().catch((n) => {
203
- console.warn("Auto upload failed:", n);
204
- });
205
- }, E = (e) => {
206
- const t = o.value.find((a) => a.id === e);
207
- if (t && t.status === "uploading") {
208
- m(e, {
209
- status: "cancelled"
210
- });
211
- const a = u.value.get(e);
212
- if (!a)
213
- return;
214
- a.abort(), u.value.delete(e);
215
- }
216
- const n = o.value.findIndex((a) => a.id === e);
217
- n !== -1 && o.value.splice(n, 1);
218
- }, K = (e) => {
219
- e ? e.forEach((t) => E(t)) : o.value.forEach((t) => E(t.id));
220
- }, { files: L, open: N, reset: B } = H({
221
- accept: l.accept,
222
- multiple: l.multiple || !1
223
- }), q = (e) => ({
224
- id: b(),
225
- ...e,
226
- filesizeText: e.filesize ? p(e.filesize) : void 0,
227
- status: e.url ? "success" : "pending",
228
- progress: {
229
- loaded: 0,
230
- total: e.filesize || 0,
231
- percent: e.url ? 100 : 0,
232
- speed: 0,
233
- speedText: h(0),
234
- remainingTime: 0,
235
- uploadTime: 0
236
- }
237
- });
238
- Q(L, async (e) => {
239
- if (e && e.length > 0) {
240
- const t = Array.from(e);
241
- B(), await C(t, "file").catch((n) => {
242
- console.warn("Failed to add selected files:", n);
243
- });
244
- }
245
- });
246
- const O = v(() => o.value.filter((e) => e.status === "success").map((e) => ({
247
- url: e.url,
248
- filename: e.filename,
249
- filesize: e.filesize,
250
- filetype: e.filetype
251
- })));
252
- return {
253
- isUploading: w,
254
- uploadFiles: o,
255
- dataFiles: O,
256
- progress: x,
257
- open: N,
258
- trigger: M,
259
- resetFiles: B,
260
- clearFiles: y,
261
- removeFiles: K,
262
- addFiles: C,
263
- addDataFiles: (e) => {
264
- !l.multiple && o.value.length > 0 && y();
265
- const t = e.map((n) => q(n));
266
- o.value.push(...t);
267
- },
268
- cancelFiles: D
269
- };
1
+ import { createLocalUploadDriver as e } from "./upload/local.js";
2
+ import { computed as t, ref as n, watch as r } from "vue";
3
+ import { uniqueId as i } from "lodash-es";
4
+ import { useFileDialog as a } from "@vueuse/core";
5
+ function o(o) {
6
+ o ||= {};
7
+ let s = n(!1), c = n([]), l = n(-1), u = n(/* @__PURE__ */ new Map()), d = o.driver || e(), f = t(() => {
8
+ let { onProgress: e, onDataCallback: t, onCancel: n, onComplete: r, maxFileSize: i, maxFileCount: a, accept: s, multiple: c, autoUpload: l, options: u, onSuccess: d, onError: f, method: p, driver: m, params: h, ...g } = o;
9
+ return g;
10
+ }), p = t(() => o.method || "POST"), m = t(() => {
11
+ let e = c.value.length, t = c.value.reduce((e, t) => e + (t.filesize || 0), 0), n = 0, r = 0;
12
+ return c.value.forEach((e, t) => {
13
+ t < l.value ? n += e.filesize || 0 : t === l.value && (n += Math.min(e.progress?.loaded || 0, e.filesize || 0));
14
+ }), t > 0 && (r = Math.max(0, Math.min(100, Math.round(n / t * 100)))), {
15
+ index: l.value >= 0 ? l.value + 1 : 0,
16
+ totalFiles: e,
17
+ currentFile: c.value[l.value],
18
+ totalPercent: r,
19
+ totalLoaded: n,
20
+ totalSize: t
21
+ };
22
+ }), h = (e) => {
23
+ if (e === 0) return "0 Bytes";
24
+ let t = 1024, n = [
25
+ "Bytes",
26
+ "KB",
27
+ "MB",
28
+ "GB"
29
+ ], r = Math.floor(Math.log(e) / Math.log(t));
30
+ return `${Number.parseFloat((e / t ** r).toFixed(2))} ${n[r]}`;
31
+ }, g = (e) => {
32
+ if (e === 0) return "0 B/s";
33
+ let t = 1024, n = [
34
+ "B/s",
35
+ "KB/s",
36
+ "MB/s",
37
+ "GB/s"
38
+ ], r = Math.floor(Math.log(e) / Math.log(t));
39
+ return `${Number.parseFloat((e / t ** r).toFixed(2))} ${n[r]}`;
40
+ }, _ = () => i("upload-"), v = async (e, t, n) => {
41
+ switch (t) {
42
+ case "file":
43
+ if (!(e instanceof File)) throw TypeError("Payload must be a File when type is \"file\"");
44
+ return e;
45
+ case "blob":
46
+ if (!(e instanceof Blob)) throw TypeError("Payload must be a Blob when type is \"blob\"");
47
+ return new File([e], n || "blob-file", { type: e.type });
48
+ case "base64": {
49
+ if (typeof e != "string") throw TypeError("Payload must be a string when type is \"base64\"");
50
+ let t = e.includes(",") ? e.split(",")[1] : e, r = e.includes(",") ? e.split(",")[0].split(":")[1].split(";")[0] : "application/octet-stream", i = atob(t), a = new Uint8Array(i.length);
51
+ for (let e = 0; e < i.length; e++) a[e] = i.charCodeAt(e);
52
+ let o = new Blob([a], { type: r });
53
+ return new File([o], n || "base64-file", { type: r });
54
+ }
55
+ case "arrayBuffer": {
56
+ if (!(e instanceof ArrayBuffer)) throw TypeError("Payload must be ArrayBuffer when type is \"arrayBuffer\"");
57
+ let t = new Blob([e]);
58
+ return new File([t], n || "array-buffer-file", { type: "application/octet-stream" });
59
+ }
60
+ default: throw Error(`Unsupported upload type: ${t}`);
61
+ }
62
+ }, y = (e) => {
63
+ if (o.maxFileSize && e.size > o.maxFileSize) throw Error(`File size cannot exceed ${h(o.maxFileSize)}`);
64
+ if (o.maxFileCount && c.value.length > o.maxFileCount) throw Error(`File count cannot exceed ${o.maxFileCount}`);
65
+ }, b = async (e, t, n) => {
66
+ let r = await v(e, t, n);
67
+ y(r);
68
+ let i = {
69
+ id: _(),
70
+ file: r,
71
+ filename: r.name,
72
+ filesize: r.size,
73
+ filetype: r.type,
74
+ filesizeText: h(r.size),
75
+ status: "pending",
76
+ progress: {
77
+ loaded: 0,
78
+ total: r.size,
79
+ percent: 0,
80
+ speed: 0,
81
+ speedText: g(0),
82
+ remainingTime: 0,
83
+ uploadTime: 0
84
+ }
85
+ };
86
+ return c.value.push(i), i;
87
+ }, x = (e, t) => {
88
+ let n = c.value.findIndex((t) => t.id === e);
89
+ n !== -1 && (c.value[n] = {
90
+ ...c.value[n],
91
+ ...t
92
+ });
93
+ }, S = () => {
94
+ c.value.every((e) => e.status !== "uploading") && o.onComplete?.(c.value);
95
+ }, C = (e) => {
96
+ let t = c.value.find((t) => t.id === e);
97
+ if (!t || t.status !== "pending" && t.status !== "uploading") return !1;
98
+ if (t.status === "uploading") {
99
+ let t = u.value.get(e);
100
+ t && (t.abort(), u.value.delete(e));
101
+ }
102
+ return x(e, { status: "cancelled" }), o.onCancel?.(e), S(), !0;
103
+ }, w = (e) => {
104
+ e ? e.forEach((e) => C(e)) : c.value.forEach((e) => C(e.id));
105
+ }, T = async (e) => {
106
+ if (!e.file) throw Error("File not found");
107
+ y(e.file);
108
+ let t = new AbortController();
109
+ u.value.set(e.id, t);
110
+ let n = Date.now();
111
+ return x(e.id, { status: "uploading" }), d.upload(e.file, {
112
+ ...f.value,
113
+ method: p.value,
114
+ signal: t.signal,
115
+ params: o.params,
116
+ onUploadProgress: (t) => {
117
+ let r = (Date.now() - n) / 1e3, i = r > 0 ? t.loaded / r : 0, a = (t.total || 0) - t.loaded, s = i > 0 ? a / i : 0, c = {
118
+ loaded: t.total ? Math.min(t.loaded, t.total) : t.loaded,
119
+ total: t.total,
120
+ percent: Math.max(0, Math.min(100, t.percent || 0)),
121
+ speed: Math.round(i),
122
+ speedText: g(i),
123
+ uploadTime: Math.round(r),
124
+ remainingTime: Math.round(s)
125
+ };
126
+ x(e.id, {
127
+ status: "uploading",
128
+ progress: c
129
+ }), o.onProgress?.(m.value);
130
+ }
131
+ }).then((t) => {
132
+ if (e.status === "cancelled") throw Error("Upload cancelled");
133
+ let r = o.onDataCallback?.(t, e) || t.data, i = Math.round((Date.now() - n) / 1e3), a = {
134
+ ...e,
135
+ status: "success",
136
+ data: t,
137
+ ...r,
138
+ progress: {
139
+ ...e.progress,
140
+ loaded: e.filesize || 0,
141
+ percent: 100,
142
+ speed: 0,
143
+ speedText: g(0),
144
+ uploadTime: i,
145
+ remainingTime: 0
146
+ }
147
+ };
148
+ return x(e.id, a), u.value.delete(e.id), o.onSuccess?.(t), a;
149
+ }).catch((t) => {
150
+ throw t.message === "canceled" || e.status === "cancelled" ? Error("Upload cancelled") : (x(e.id, {
151
+ status: "error",
152
+ error: t.message
153
+ }), u.value.delete(e.id), t);
154
+ }).finally(() => {
155
+ S();
156
+ });
157
+ }, E = async () => {
158
+ let e = c.value.filter((e) => e.status === "pending");
159
+ if (e.length === 0) return [];
160
+ s.value = !0;
161
+ try {
162
+ let t = [];
163
+ for (let n = 0; n < e.length; n++) {
164
+ let r = e[n];
165
+ l.value = c.value.findIndex((e) => e.id === r.id);
166
+ let i = await T(r);
167
+ t.push(i);
168
+ }
169
+ return t;
170
+ } catch (e) {
171
+ throw o.onError?.({
172
+ status: e?.status || 500,
173
+ message: e?.message || "upload failed"
174
+ }), e;
175
+ } finally {
176
+ s.value = !1, l.value = -1;
177
+ }
178
+ }, D = () => {
179
+ c.value.forEach((e) => {
180
+ C(e.id);
181
+ }), u.value.clear(), c.value = [], l.value = -1;
182
+ }, O = async (e, t = "file") => {
183
+ try {
184
+ if (!o.multiple && e.length > 1) throw Error("Single file mode: only one file can be selected");
185
+ if (!o.multiple && c.value.length > 0 && D(), o.maxFileCount && c.value.length + e.length > o.maxFileCount) throw Error(`Adding ${e.length} files would exceed the maximum limit of ${o.maxFileCount}`);
186
+ for (let n of e) await b(n, t);
187
+ } catch (e) {
188
+ throw o.onError?.({
189
+ status: e?.status || 400,
190
+ message: e?.message || "Failed to add files"
191
+ }), e;
192
+ }
193
+ o.autoUpload && E().catch((e) => {
194
+ console.warn("Auto upload failed:", e);
195
+ });
196
+ }, k = (e) => {
197
+ let t = c.value.find((t) => t.id === e);
198
+ if (t && t.status === "uploading") {
199
+ x(e, { status: "cancelled" });
200
+ let t = u.value.get(e);
201
+ if (!t) return;
202
+ t.abort(), u.value.delete(e);
203
+ }
204
+ let n = c.value.findIndex((t) => t.id === e);
205
+ n !== -1 && c.value.splice(n, 1);
206
+ }, A = (e) => {
207
+ e ? e.forEach((e) => k(e)) : c.value.forEach((e) => k(e.id));
208
+ }, { files: j, open: M, reset: N } = a({
209
+ accept: o.accept,
210
+ multiple: o.multiple || !1
211
+ }), P = (e) => ({
212
+ id: _(),
213
+ ...e,
214
+ filesizeText: e.filesize ? h(e.filesize) : void 0,
215
+ status: e.url ? "success" : "pending",
216
+ progress: {
217
+ loaded: 0,
218
+ total: e.filesize || 0,
219
+ percent: e.url ? 100 : 0,
220
+ speed: 0,
221
+ speedText: g(0),
222
+ remainingTime: 0,
223
+ uploadTime: 0
224
+ }
225
+ });
226
+ return r(j, async (e) => {
227
+ if (e && e.length > 0) {
228
+ let t = Array.from(e);
229
+ N(), await O(t, "file").catch((e) => {
230
+ console.warn("Failed to add selected files:", e);
231
+ });
232
+ }
233
+ }), {
234
+ isUploading: s,
235
+ uploadFiles: c,
236
+ dataFiles: t(() => c.value.filter((e) => e.status === "success").map((e) => ({
237
+ url: e.url,
238
+ filename: e.filename,
239
+ filesize: e.filesize,
240
+ filetype: e.filetype
241
+ }))),
242
+ progress: m,
243
+ open: M,
244
+ trigger: E,
245
+ resetFiles: N,
246
+ clearFiles: D,
247
+ removeFiles: A,
248
+ addFiles: O,
249
+ addDataFiles: (e) => {
250
+ !o.multiple && c.value.length > 0 && D();
251
+ let t = e.map((e) => P(e));
252
+ c.value.push(...t);
253
+ },
254
+ cancelFiles: w
255
+ };
270
256
  }
271
- export {
272
- ne as useUpload
273
- };
257
+ export { o as useUpload };