inertia-bootstrap-forms 1.0.56 → 1.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-BNTFmIVu.js +604 -0
- package/dist/index-Cr0ZhLal.js +13183 -0
- package/dist/inertia-bootstrap-forms.es.js +29 -10748
- package/dist/inertia-bootstrap-forms.umd.js +17 -3
- package/dist/style.css +1 -1
- package/index.d.ts +41 -0
- package/package.json +9 -1
- package/src/RangeSliderInput.vue +0 -1
- package/src/UppyInput.vue +181 -0
- package/src/index.js +2 -0
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
var pt = Object.defineProperty;
|
|
2
|
+
var et = (i) => {
|
|
3
|
+
throw TypeError(i);
|
|
4
|
+
};
|
|
5
|
+
var ct = (i, e, t) => e in i ? pt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
6
|
+
var y = (i, e, t) => ct(i, typeof e != "symbol" ? e + "" : e, t), G = (i, e, t) => e.has(i) || et("Cannot " + t);
|
|
7
|
+
var r = (i, e, t) => (G(i, e, "read from private field"), t ? t.call(i) : e.get(i)), m = (i, e, t) => e.has(i) ? et("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, t), c = (i, e, t, s) => (G(i, e, "write to private field"), s ? s.call(i, t) : e.set(i, t), t), g = (i, e, t) => (G(i, e, "access private method"), t);
|
|
8
|
+
import { T as mt } from "./index-Cr0ZhLal.js";
|
|
9
|
+
class K extends Error {
|
|
10
|
+
constructor(t, s = null) {
|
|
11
|
+
super("This looks like a network error, the endpoint might be blocked by an internet provider or a firewall.");
|
|
12
|
+
y(this, "cause");
|
|
13
|
+
y(this, "isNetworkError");
|
|
14
|
+
y(this, "request");
|
|
15
|
+
this.cause = t, this.isNetworkError = !0, this.request = s;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
var O, M, W, N;
|
|
19
|
+
class ft {
|
|
20
|
+
constructor(e, t) {
|
|
21
|
+
m(this, O);
|
|
22
|
+
m(this, M, !1);
|
|
23
|
+
m(this, W);
|
|
24
|
+
m(this, N);
|
|
25
|
+
c(this, N, e), c(this, W, () => t(e));
|
|
26
|
+
}
|
|
27
|
+
progress() {
|
|
28
|
+
r(this, M) || r(this, N) > 0 && (clearTimeout(r(this, O)), c(this, O, setTimeout(r(this, W), r(this, N))));
|
|
29
|
+
}
|
|
30
|
+
done() {
|
|
31
|
+
r(this, M) || (clearTimeout(r(this, O)), c(this, O, void 0), c(this, M, !0));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
O = new WeakMap(), M = new WeakMap(), W = new WeakMap(), N = new WeakMap();
|
|
35
|
+
const j = () => {
|
|
36
|
+
};
|
|
37
|
+
function yt(i, e = {}) {
|
|
38
|
+
const { body: t = null, headers: s = {}, method: o = "GET", onBeforeRequest: a = j, onUploadProgress: n = j, shouldRetry: l = () => !0, onAfterResponse: u = j, onTimeout: h = j, responseType: d, retries: x = 3, signal: f = null, timeout: P = 3e4, withCredentials: b = !1 } = e, B = (F) => 0.3 * 2 ** (F - 1) * 1e3, X = new ft(P, h);
|
|
39
|
+
function _(F = 0) {
|
|
40
|
+
return new Promise(async (V, I) => {
|
|
41
|
+
const p = new XMLHttpRequest(), $ = (S) => {
|
|
42
|
+
l(p) && F < x ? setTimeout(() => {
|
|
43
|
+
_(F + 1).then(V, I);
|
|
44
|
+
}, B(F)) : (X.done(), I(S));
|
|
45
|
+
};
|
|
46
|
+
p.open(o, i, !0), p.withCredentials = b, d && (p.responseType = d), p.onload = async () => {
|
|
47
|
+
try {
|
|
48
|
+
await u(p, F);
|
|
49
|
+
} catch (S) {
|
|
50
|
+
S.request = p, $(S);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
p.status >= 200 && p.status < 300 ? (X.done(), V(p)) : l(p) && F < x ? setTimeout(() => {
|
|
54
|
+
_(F + 1).then(V, I);
|
|
55
|
+
}, B(F)) : (X.done(), I(new K(p.statusText, p)));
|
|
56
|
+
}, p.onerror = () => $(new K(p.statusText, p)), p.upload.onprogress = (S) => {
|
|
57
|
+
X.progress(), n(S);
|
|
58
|
+
}, s && Object.keys(s).forEach((S) => {
|
|
59
|
+
p.setRequestHeader(S, s[S]);
|
|
60
|
+
});
|
|
61
|
+
function tt() {
|
|
62
|
+
p.abort(), I(new DOMException("Aborted", "AbortError"));
|
|
63
|
+
}
|
|
64
|
+
if (f == null || f.addEventListener("abort", tt), f != null && f.aborted) {
|
|
65
|
+
tt();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
await a(p, F), p.send(t);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return _();
|
|
72
|
+
}
|
|
73
|
+
const wt = (i) => "error" in i && !!i.error, gt = (i) => i.progress.uploadComplete;
|
|
74
|
+
function bt(i) {
|
|
75
|
+
return i.filter((e) => !wt(e) && !gt(e));
|
|
76
|
+
}
|
|
77
|
+
function Ft(i) {
|
|
78
|
+
return i.filter((e) => {
|
|
79
|
+
var t;
|
|
80
|
+
return !((t = e.progress) != null && t.uploadStarted) || !e.isRestored;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function st(i, e) {
|
|
84
|
+
return i === !0 ? Object.keys(e) : Array.isArray(i) ? i : [];
|
|
85
|
+
}
|
|
86
|
+
function Et(i) {
|
|
87
|
+
return i ? i.readyState === 4 && i.status === 0 : !1;
|
|
88
|
+
}
|
|
89
|
+
function Tt(i) {
|
|
90
|
+
return new Error("Cancelled", { cause: i });
|
|
91
|
+
}
|
|
92
|
+
function it(i) {
|
|
93
|
+
var e;
|
|
94
|
+
if (i != null) {
|
|
95
|
+
const t = () => this.abort(i.reason);
|
|
96
|
+
i.addEventListener("abort", t, { once: !0 });
|
|
97
|
+
const s = () => {
|
|
98
|
+
i.removeEventListener("abort", t);
|
|
99
|
+
};
|
|
100
|
+
(e = this.then) == null || e.call(this, s, s);
|
|
101
|
+
}
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
var U, E, v, L, T, C, A, w, Z, H, rt, nt, at, Q, k;
|
|
105
|
+
class Rt {
|
|
106
|
+
constructor(e) {
|
|
107
|
+
m(this, w);
|
|
108
|
+
m(this, U, 0);
|
|
109
|
+
m(this, E, []);
|
|
110
|
+
m(this, v, !1);
|
|
111
|
+
m(this, L);
|
|
112
|
+
m(this, T, 1);
|
|
113
|
+
m(this, C);
|
|
114
|
+
m(this, A);
|
|
115
|
+
y(this, "limit");
|
|
116
|
+
m(this, Q, () => this.resume());
|
|
117
|
+
m(this, k, () => {
|
|
118
|
+
if (r(this, v)) {
|
|
119
|
+
c(this, A, setTimeout(r(this, k), 0));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
c(this, T, this.limit), this.limit = Math.ceil((r(this, C) + r(this, T)) / 2);
|
|
123
|
+
for (let e = r(this, T); e <= this.limit; e++)
|
|
124
|
+
g(this, w, H).call(this);
|
|
125
|
+
r(this, C) - r(this, T) > 3 ? c(this, A, setTimeout(r(this, k), 2e3)) : c(this, T, Math.floor(r(this, T) / 2));
|
|
126
|
+
});
|
|
127
|
+
typeof e != "number" || e === 0 ? this.limit = 1 / 0 : this.limit = e;
|
|
128
|
+
}
|
|
129
|
+
run(e, t) {
|
|
130
|
+
return !r(this, v) && r(this, U) < this.limit ? g(this, w, Z).call(this, e) : g(this, w, nt).call(this, e, t);
|
|
131
|
+
}
|
|
132
|
+
wrapSyncFunction(e, t) {
|
|
133
|
+
return (...s) => {
|
|
134
|
+
const o = this.run(() => (e(...s), queueMicrotask(() => o.done()), () => {
|
|
135
|
+
}), t);
|
|
136
|
+
return {
|
|
137
|
+
abortOn: it,
|
|
138
|
+
abort() {
|
|
139
|
+
o.abort();
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
wrapPromiseFunction(e, t) {
|
|
145
|
+
return (...s) => {
|
|
146
|
+
let o;
|
|
147
|
+
const a = new Promise((n, l) => {
|
|
148
|
+
o = this.run(() => {
|
|
149
|
+
let u, h;
|
|
150
|
+
try {
|
|
151
|
+
h = Promise.resolve(e(...s));
|
|
152
|
+
} catch (d) {
|
|
153
|
+
h = Promise.reject(d);
|
|
154
|
+
}
|
|
155
|
+
return h.then((d) => {
|
|
156
|
+
u ? l(u) : (o.done(), n(d));
|
|
157
|
+
}, (d) => {
|
|
158
|
+
u ? l(u) : (o.done(), l(d));
|
|
159
|
+
}), (d) => {
|
|
160
|
+
u = Tt(d);
|
|
161
|
+
};
|
|
162
|
+
}, t);
|
|
163
|
+
});
|
|
164
|
+
return a.abort = (n) => {
|
|
165
|
+
o.abort(n);
|
|
166
|
+
}, a.abortOn = it, a;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
resume() {
|
|
170
|
+
c(this, v, !1), clearTimeout(r(this, L));
|
|
171
|
+
for (let e = 0; e < this.limit; e++)
|
|
172
|
+
g(this, w, H).call(this);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Freezes the queue for a while or indefinitely.
|
|
176
|
+
*
|
|
177
|
+
* @param {number | null } [duration] Duration for the pause to happen, in milliseconds.
|
|
178
|
+
* If omitted, the queue won't resume automatically.
|
|
179
|
+
*/
|
|
180
|
+
pause(e = null) {
|
|
181
|
+
c(this, v, !0), clearTimeout(r(this, L)), e != null && c(this, L, setTimeout(r(this, Q), e));
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Pauses the queue for a duration, and lower the limit of concurrent requests
|
|
185
|
+
* when the queue resumes. When the queue resumes, it tries to progressively
|
|
186
|
+
* increase the limit in `this.#increaseLimit` until another call is made to
|
|
187
|
+
* `this.rateLimit`.
|
|
188
|
+
* Call this function when using the RateLimitedQueue for network requests and
|
|
189
|
+
* the remote server responds with 429 HTTP code.
|
|
190
|
+
*
|
|
191
|
+
* @param {number} duration in milliseconds.
|
|
192
|
+
*/
|
|
193
|
+
rateLimit(e) {
|
|
194
|
+
clearTimeout(r(this, A)), this.pause(e), this.limit > 1 && Number.isFinite(this.limit) && (c(this, C, this.limit - 1), this.limit = r(this, T), c(this, A, setTimeout(r(this, k), e)));
|
|
195
|
+
}
|
|
196
|
+
get isPaused() {
|
|
197
|
+
return r(this, v);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
U = new WeakMap(), E = new WeakMap(), v = new WeakMap(), L = new WeakMap(), T = new WeakMap(), C = new WeakMap(), A = new WeakMap(), w = new WeakSet(), Z = function(e) {
|
|
201
|
+
c(this, U, r(this, U) + 1);
|
|
202
|
+
let t = !1, s;
|
|
203
|
+
try {
|
|
204
|
+
s = e();
|
|
205
|
+
} catch (o) {
|
|
206
|
+
throw c(this, U, r(this, U) - 1), o;
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
abort: (o) => {
|
|
210
|
+
t || (t = !0, c(this, U, r(this, U) - 1), s == null || s(o), g(this, w, H).call(this));
|
|
211
|
+
},
|
|
212
|
+
done: () => {
|
|
213
|
+
t || (t = !0, c(this, U, r(this, U) - 1), g(this, w, H).call(this));
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}, H = function() {
|
|
217
|
+
queueMicrotask(() => g(this, w, rt).call(this));
|
|
218
|
+
}, rt = function() {
|
|
219
|
+
if (r(this, v) || r(this, U) >= this.limit || r(this, E).length === 0)
|
|
220
|
+
return;
|
|
221
|
+
const e = r(this, E).shift();
|
|
222
|
+
if (e == null)
|
|
223
|
+
throw new Error("Invariant violation: next is null");
|
|
224
|
+
const t = g(this, w, Z).call(this, e.fn);
|
|
225
|
+
e.abort = t.abort, e.done = t.done;
|
|
226
|
+
}, nt = function(e, t) {
|
|
227
|
+
const s = {
|
|
228
|
+
fn: e,
|
|
229
|
+
priority: (t == null ? void 0 : t.priority) || 0,
|
|
230
|
+
abort: () => {
|
|
231
|
+
g(this, w, at).call(this, s);
|
|
232
|
+
},
|
|
233
|
+
done: () => {
|
|
234
|
+
throw new Error("Cannot mark a queued request as done: this indicates a bug");
|
|
235
|
+
}
|
|
236
|
+
}, o = r(this, E).findIndex((a) => s.priority > a.priority);
|
|
237
|
+
return o === -1 ? r(this, E).push(s) : r(this, E).splice(o, 0, s), s;
|
|
238
|
+
}, at = function(e) {
|
|
239
|
+
const t = r(this, E).indexOf(e);
|
|
240
|
+
t !== -1 && r(this, E).splice(t, 1);
|
|
241
|
+
}, Q = new WeakMap(), k = new WeakMap();
|
|
242
|
+
const Y = Symbol("__queue");
|
|
243
|
+
class qt {
|
|
244
|
+
constructor(e, t) {
|
|
245
|
+
y(this, "uppy");
|
|
246
|
+
y(this, "opts");
|
|
247
|
+
y(this, "id");
|
|
248
|
+
y(this, "defaultLocale");
|
|
249
|
+
y(this, "i18n");
|
|
250
|
+
y(this, "i18nArray");
|
|
251
|
+
y(this, "type");
|
|
252
|
+
y(this, "VERSION");
|
|
253
|
+
this.uppy = e, this.opts = t ?? {};
|
|
254
|
+
}
|
|
255
|
+
getPluginState() {
|
|
256
|
+
const { plugins: e } = this.uppy.getState();
|
|
257
|
+
return (e == null ? void 0 : e[this.id]) || {};
|
|
258
|
+
}
|
|
259
|
+
setPluginState(e) {
|
|
260
|
+
const { plugins: t } = this.uppy.getState();
|
|
261
|
+
this.uppy.setState({
|
|
262
|
+
plugins: {
|
|
263
|
+
...t,
|
|
264
|
+
[this.id]: {
|
|
265
|
+
...t[this.id],
|
|
266
|
+
...e
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
setOptions(e) {
|
|
272
|
+
this.opts = { ...this.opts, ...e }, this.setPluginState(void 0), this.i18nInit();
|
|
273
|
+
}
|
|
274
|
+
i18nInit() {
|
|
275
|
+
const e = new mt([
|
|
276
|
+
this.defaultLocale,
|
|
277
|
+
this.uppy.locale,
|
|
278
|
+
this.opts.locale
|
|
279
|
+
]);
|
|
280
|
+
this.i18n = e.translate.bind(e), this.i18nArray = e.translateArray.bind(e), this.setPluginState(void 0);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Extendable methods
|
|
284
|
+
* ==================
|
|
285
|
+
* These methods are here to serve as an overview of the extendable methods as well as
|
|
286
|
+
* making them not conditional in use, such as `if (this.afterUpdate)`.
|
|
287
|
+
*/
|
|
288
|
+
addTarget(e) {
|
|
289
|
+
throw new Error("Extend the addTarget method to add your plugin to another plugin's target");
|
|
290
|
+
}
|
|
291
|
+
install() {
|
|
292
|
+
}
|
|
293
|
+
uninstall() {
|
|
294
|
+
}
|
|
295
|
+
update(e) {
|
|
296
|
+
}
|
|
297
|
+
// Called after every state update, after everything's mounted. Debounced.
|
|
298
|
+
afterUpdate() {
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
var R, z;
|
|
302
|
+
class St {
|
|
303
|
+
constructor(e) {
|
|
304
|
+
m(this, R);
|
|
305
|
+
m(this, z, []);
|
|
306
|
+
c(this, R, e);
|
|
307
|
+
}
|
|
308
|
+
on(e, t) {
|
|
309
|
+
return r(this, z).push([e, t]), r(this, R).on(e, t);
|
|
310
|
+
}
|
|
311
|
+
remove() {
|
|
312
|
+
for (const [e, t] of r(this, z).splice(0))
|
|
313
|
+
r(this, R).off(e, t);
|
|
314
|
+
}
|
|
315
|
+
onFilePause(e, t) {
|
|
316
|
+
this.on("upload-pause", (s, o) => {
|
|
317
|
+
e === (s == null ? void 0 : s.id) && t(o);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
onFileRemove(e, t) {
|
|
321
|
+
this.on("file-removed", (s) => {
|
|
322
|
+
e === s.id && t(s.id);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
onPause(e, t) {
|
|
326
|
+
this.on("upload-pause", (s, o) => {
|
|
327
|
+
e === (s == null ? void 0 : s.id) && t(o);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
onRetry(e, t) {
|
|
331
|
+
this.on("upload-retry", (s) => {
|
|
332
|
+
e === (s == null ? void 0 : s.id) && t();
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
onRetryAll(e, t) {
|
|
336
|
+
this.on("retry-all", () => {
|
|
337
|
+
r(this, R).getFile(e) && t();
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
onPauseAll(e, t) {
|
|
341
|
+
this.on("pause-all", () => {
|
|
342
|
+
r(this, R).getFile(e) && t();
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
onCancelAll(e, t) {
|
|
346
|
+
this.on("cancel-all", (...s) => {
|
|
347
|
+
r(this, R).getFile(e) && t(...s);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
onResumeAll(e, t) {
|
|
351
|
+
this.on("resume-all", () => {
|
|
352
|
+
r(this, R).getFile(e) && t();
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
R = new WeakMap(), z = new WeakMap();
|
|
357
|
+
const Ut = "5.1.1", vt = {
|
|
358
|
+
version: Ut
|
|
359
|
+
}, Pt = {
|
|
360
|
+
strings: {
|
|
361
|
+
// Shown in the Informer if an upload is being canceled because it stalled for too long.
|
|
362
|
+
uploadStalled: "Upload has not made any progress for %{seconds} seconds. You may want to retry it."
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
function Ot(i, e) {
|
|
366
|
+
let t = e;
|
|
367
|
+
return t || (t = new Error("Upload error")), typeof t == "string" && (t = new Error(t)), t instanceof Error || (t = Object.assign(new Error("Upload error"), { data: t })), Et(i) ? (t = new K(t, i), t) : (t.request = i, t);
|
|
368
|
+
}
|
|
369
|
+
function ot(i) {
|
|
370
|
+
return i.data.slice(0, i.data.size, i.meta.type);
|
|
371
|
+
}
|
|
372
|
+
const At = {
|
|
373
|
+
formData: !0,
|
|
374
|
+
fieldName: "file",
|
|
375
|
+
method: "post",
|
|
376
|
+
allowedMetaFields: !0,
|
|
377
|
+
bundle: !1,
|
|
378
|
+
headers: {},
|
|
379
|
+
timeout: 30 * 1e3,
|
|
380
|
+
limit: 5,
|
|
381
|
+
withCredentials: !1,
|
|
382
|
+
responseType: ""
|
|
383
|
+
};
|
|
384
|
+
var D, q, lt, ut, ht, dt, J;
|
|
385
|
+
class xt extends qt {
|
|
386
|
+
constructor(t, s) {
|
|
387
|
+
super(t, {
|
|
388
|
+
...At,
|
|
389
|
+
fieldName: s.bundle ? "files[]" : "file",
|
|
390
|
+
...s
|
|
391
|
+
});
|
|
392
|
+
m(this, q);
|
|
393
|
+
m(this, D);
|
|
394
|
+
y(this, "requests");
|
|
395
|
+
y(this, "uploaderEvents");
|
|
396
|
+
m(this, J, async (t) => {
|
|
397
|
+
if (t.length === 0) {
|
|
398
|
+
this.uppy.log("[XHRUpload] No files to upload!");
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
this.opts.limit === 0 && !this.opts[Y] && this.uppy.log("[XHRUpload] When uploading multiple files at once, consider setting the `limit` option (to `10` for example), to limit the number of concurrent uploads, which helps prevent memory and network issues: https://uppy.io/docs/xhr-upload/#limit-0", "warning"), this.uppy.log("[XHRUpload] Uploading...");
|
|
402
|
+
const s = this.uppy.getFilesByIds(t), o = bt(s), a = Ft(o);
|
|
403
|
+
if (this.uppy.emit("upload-start", a), this.opts.bundle) {
|
|
404
|
+
if (o.some((l) => l.isRemote))
|
|
405
|
+
throw new Error("Can’t upload remote files when the `bundle: true` option is set");
|
|
406
|
+
if (typeof this.opts.headers == "function")
|
|
407
|
+
throw new TypeError("`headers` may not be a function when the `bundle: true` option is set");
|
|
408
|
+
await g(this, q, ut).call(this, o);
|
|
409
|
+
} else
|
|
410
|
+
await g(this, q, dt).call(this, o);
|
|
411
|
+
});
|
|
412
|
+
if (this.type = "uploader", this.id = this.opts.id || "XHRUpload", this.defaultLocale = Pt, this.i18nInit(), Y in this.opts ? this.requests = this.opts[Y] : this.requests = new Rt(this.opts.limit), this.opts.bundle && !this.opts.formData)
|
|
413
|
+
throw new Error("`opts.formData` must be true when `opts.bundle` is enabled.");
|
|
414
|
+
if (this.opts.bundle && typeof this.opts.headers == "function")
|
|
415
|
+
throw new Error("`opts.headers` can not be a function when the `bundle: true` option is set.");
|
|
416
|
+
if ((s == null ? void 0 : s.allowedMetaFields) === void 0 && "metaFields" in this.opts)
|
|
417
|
+
throw new Error("The `metaFields` option has been renamed to `allowedMetaFields`.");
|
|
418
|
+
this.uploaderEvents = /* @__PURE__ */ Object.create(null), c(this, D, (o) => async (a, n) => {
|
|
419
|
+
var l, u;
|
|
420
|
+
try {
|
|
421
|
+
const h = await yt(a, {
|
|
422
|
+
...n,
|
|
423
|
+
onBeforeRequest: (f, P) => {
|
|
424
|
+
var b, B;
|
|
425
|
+
return (B = (b = this.opts).onBeforeRequest) == null ? void 0 : B.call(b, f, P, o);
|
|
426
|
+
},
|
|
427
|
+
shouldRetry: this.opts.shouldRetry,
|
|
428
|
+
onAfterResponse: this.opts.onAfterResponse,
|
|
429
|
+
onTimeout: (f) => {
|
|
430
|
+
const P = Math.ceil(f / 1e3), b = new Error(this.i18n("uploadStalled", { seconds: P }));
|
|
431
|
+
this.uppy.emit("upload-stalled", b, o);
|
|
432
|
+
},
|
|
433
|
+
onUploadProgress: (f) => {
|
|
434
|
+
if (f.lengthComputable)
|
|
435
|
+
for (const { id: P } of o) {
|
|
436
|
+
const b = this.uppy.getFile(P);
|
|
437
|
+
b != null && this.uppy.emit("upload-progress", b, {
|
|
438
|
+
uploadStarted: b.progress.uploadStarted ?? 0,
|
|
439
|
+
bytesUploaded: f.loaded / f.total * b.size,
|
|
440
|
+
bytesTotal: b.size
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
let d = await ((u = (l = this.opts).getResponseData) == null ? void 0 : u.call(l, h));
|
|
446
|
+
if (h.responseType === "json")
|
|
447
|
+
d ?? (d = h.response);
|
|
448
|
+
else
|
|
449
|
+
try {
|
|
450
|
+
d ?? (d = JSON.parse(h.responseText));
|
|
451
|
+
} catch (f) {
|
|
452
|
+
throw new Error("@uppy/xhr-upload expects a JSON response (with a `url` property). To parse non-JSON responses, use `getResponseData` to turn your response into JSON.", { cause: f });
|
|
453
|
+
}
|
|
454
|
+
const x = typeof (d == null ? void 0 : d.url) == "string" ? d.url : void 0;
|
|
455
|
+
for (const { id: f } of o)
|
|
456
|
+
this.uppy.emit("upload-success", this.uppy.getFile(f), {
|
|
457
|
+
status: h.status,
|
|
458
|
+
body: d,
|
|
459
|
+
uploadURL: x
|
|
460
|
+
});
|
|
461
|
+
return h;
|
|
462
|
+
} catch (h) {
|
|
463
|
+
if (h.name === "AbortError")
|
|
464
|
+
return;
|
|
465
|
+
const d = h.request;
|
|
466
|
+
for (const x of o)
|
|
467
|
+
this.uppy.emit("upload-error", this.uppy.getFile(x.id), Ot(d, h), d);
|
|
468
|
+
throw h;
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
getOptions(t) {
|
|
473
|
+
const s = this.uppy.getState().xhrUpload, { headers: o } = this.opts, a = {
|
|
474
|
+
...this.opts,
|
|
475
|
+
...s || {},
|
|
476
|
+
...t.xhrUpload || {},
|
|
477
|
+
headers: {}
|
|
478
|
+
};
|
|
479
|
+
return typeof o == "function" ? a.headers = o(t) : Object.assign(a.headers, this.opts.headers), s && Object.assign(a.headers, s.headers), t.xhrUpload && Object.assign(a.headers, t.xhrUpload.headers), a;
|
|
480
|
+
}
|
|
481
|
+
addMetadata(t, s, o) {
|
|
482
|
+
st(o.allowedMetaFields, s).forEach((n) => {
|
|
483
|
+
const l = s[n];
|
|
484
|
+
Array.isArray(l) ? l.forEach((u) => t.append(n, u)) : t.append(n, l);
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
createFormDataUpload(t, s) {
|
|
488
|
+
const o = new FormData();
|
|
489
|
+
this.addMetadata(o, t.meta, s);
|
|
490
|
+
const a = ot(t);
|
|
491
|
+
return t.name ? o.append(s.fieldName, a, t.meta.name) : o.append(s.fieldName, a), o;
|
|
492
|
+
}
|
|
493
|
+
createBundledUpload(t, s) {
|
|
494
|
+
const o = new FormData(), { meta: a } = this.uppy.getState();
|
|
495
|
+
return this.addMetadata(o, a, s), t.forEach((n) => {
|
|
496
|
+
const l = this.getOptions(n), u = ot(n);
|
|
497
|
+
n.name ? o.append(l.fieldName, u, n.name) : o.append(l.fieldName, u);
|
|
498
|
+
}), o;
|
|
499
|
+
}
|
|
500
|
+
install() {
|
|
501
|
+
if (this.opts.bundle) {
|
|
502
|
+
const { capabilities: t } = this.uppy.getState();
|
|
503
|
+
this.uppy.setState({
|
|
504
|
+
capabilities: {
|
|
505
|
+
...t,
|
|
506
|
+
individualCancellation: !1
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
this.uppy.addUploader(r(this, J));
|
|
511
|
+
}
|
|
512
|
+
uninstall() {
|
|
513
|
+
if (this.opts.bundle) {
|
|
514
|
+
const { capabilities: t } = this.uppy.getState();
|
|
515
|
+
this.uppy.setState({
|
|
516
|
+
capabilities: {
|
|
517
|
+
...t,
|
|
518
|
+
individualCancellation: !0
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
this.uppy.removeUploader(r(this, J));
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
D = new WeakMap(), q = new WeakSet(), lt = async function(t) {
|
|
526
|
+
const s = new St(this.uppy), o = new AbortController(), a = this.requests.wrapPromiseFunction(async () => {
|
|
527
|
+
const n = this.getOptions(t), l = r(this, D).call(this, [t]), u = n.formData ? this.createFormDataUpload(t, n) : t.data, h = typeof n.endpoint == "string" ? n.endpoint : await n.endpoint(t);
|
|
528
|
+
return l(h, {
|
|
529
|
+
...n,
|
|
530
|
+
body: u,
|
|
531
|
+
signal: o.signal
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
s.onFileRemove(t.id, () => o.abort()), s.onCancelAll(t.id, () => {
|
|
535
|
+
o.abort();
|
|
536
|
+
});
|
|
537
|
+
try {
|
|
538
|
+
await a();
|
|
539
|
+
} catch (n) {
|
|
540
|
+
if (n.message !== "Cancelled")
|
|
541
|
+
throw n;
|
|
542
|
+
} finally {
|
|
543
|
+
s.remove();
|
|
544
|
+
}
|
|
545
|
+
}, ut = async function(t) {
|
|
546
|
+
const s = new AbortController(), o = this.requests.wrapPromiseFunction(async () => {
|
|
547
|
+
const n = this.uppy.getState().xhrUpload ?? {}, l = r(this, D).call(this, t), u = this.createBundledUpload(t, {
|
|
548
|
+
...this.opts,
|
|
549
|
+
...n
|
|
550
|
+
}), h = typeof this.opts.endpoint == "string" ? this.opts.endpoint : await this.opts.endpoint(t);
|
|
551
|
+
return l(h, {
|
|
552
|
+
// headers can't be a function with bundle: true
|
|
553
|
+
...this.opts,
|
|
554
|
+
body: u,
|
|
555
|
+
signal: s.signal
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
function a() {
|
|
559
|
+
s.abort();
|
|
560
|
+
}
|
|
561
|
+
this.uppy.once("cancel-all", a);
|
|
562
|
+
try {
|
|
563
|
+
await o();
|
|
564
|
+
} catch (n) {
|
|
565
|
+
if (n.message !== "Cancelled")
|
|
566
|
+
throw n;
|
|
567
|
+
} finally {
|
|
568
|
+
this.uppy.off("cancel-all", a);
|
|
569
|
+
}
|
|
570
|
+
}, ht = function(t) {
|
|
571
|
+
var a;
|
|
572
|
+
const s = this.getOptions(t), o = st(s.allowedMetaFields, t.meta);
|
|
573
|
+
return {
|
|
574
|
+
...(a = t.remote) == null ? void 0 : a.body,
|
|
575
|
+
protocol: "multipart",
|
|
576
|
+
endpoint: s.endpoint,
|
|
577
|
+
size: t.data.size,
|
|
578
|
+
fieldname: s.fieldName,
|
|
579
|
+
metadata: Object.fromEntries(o.map((n) => [n, t.meta[n]])),
|
|
580
|
+
httpMethod: s.method,
|
|
581
|
+
useFormData: s.formData,
|
|
582
|
+
headers: s.headers
|
|
583
|
+
};
|
|
584
|
+
}, dt = async function(t) {
|
|
585
|
+
await Promise.allSettled(t.map((s) => {
|
|
586
|
+
if (s.isRemote) {
|
|
587
|
+
const o = () => this.requests, a = new AbortController(), n = (u) => {
|
|
588
|
+
u.id === s.id && a.abort();
|
|
589
|
+
};
|
|
590
|
+
this.uppy.on("file-removed", n);
|
|
591
|
+
const l = this.uppy.getRequestClientForFile(s).uploadRemoteFile(s, g(this, q, ht).call(this, s), {
|
|
592
|
+
signal: a.signal,
|
|
593
|
+
getQueue: o
|
|
594
|
+
});
|
|
595
|
+
return this.requests.wrapSyncFunction(() => {
|
|
596
|
+
this.uppy.off("file-removed", n);
|
|
597
|
+
}, { priority: -1 })(), l;
|
|
598
|
+
}
|
|
599
|
+
return g(this, q, lt).call(this, s);
|
|
600
|
+
}));
|
|
601
|
+
}, J = new WeakMap(), y(xt, "VERSION", vt.version);
|
|
602
|
+
export {
|
|
603
|
+
xt as default
|
|
604
|
+
};
|