@citruslime/vue-utils 1.2.0-beta.2 → 1.2.1-beta.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.
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { replacePlaceholders as
|
|
2
|
-
import { computed as
|
|
3
|
-
const
|
|
1
|
+
import { replacePlaceholders as te } from "@citruslime/utils";
|
|
2
|
+
import { computed as ce, ref as D, readonly as ye, unref as he, getCurrentScope as me, onScopeDispose as Oe, watch as G, isRef as fe, shallowRef as M, reactive as ve, toRefs as we } from "vue";
|
|
3
|
+
const Je = [
|
|
4
4
|
"GET",
|
|
5
5
|
"POST",
|
|
6
6
|
"PUT",
|
|
7
7
|
"DELETE"
|
|
8
8
|
];
|
|
9
|
-
function
|
|
9
|
+
function Ke(e, t, n = null, s = null) {
|
|
10
10
|
return {
|
|
11
11
|
url: e,
|
|
12
12
|
type: t,
|
|
13
|
-
headers: n ??
|
|
14
|
-
hasBody:
|
|
13
|
+
headers: n ?? de,
|
|
14
|
+
hasBody: ge(t, s)
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function de() {
|
|
18
18
|
return {
|
|
19
|
-
|
|
20
|
-
"
|
|
19
|
+
accept: "application/json",
|
|
20
|
+
"content-type": "application/json"
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function ge(e, t) {
|
|
24
24
|
return !!(t === null && (e === "PUT" || e === "POST") || t);
|
|
25
25
|
}
|
|
26
|
-
var
|
|
27
|
-
const
|
|
28
|
-
|
|
26
|
+
var ne;
|
|
27
|
+
const X = typeof window < "u";
|
|
28
|
+
X && ((ne = window == null ? void 0 : window.navigator) != null && ne.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
|
|
29
29
|
function E(e) {
|
|
30
30
|
return typeof e == "function" ? e() : he(e);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function re(e, t = !1, n = "Timeout") {
|
|
33
33
|
return new Promise((s, a) => {
|
|
34
34
|
setTimeout(t ? () => a(n) : s, e);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
function
|
|
37
|
+
function be(e) {
|
|
38
38
|
return e;
|
|
39
39
|
}
|
|
40
40
|
function Pe(e, ...t) {
|
|
41
41
|
return t.some((n) => n in e);
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function pe(e) {
|
|
44
44
|
return me() ? (Oe(e), !0) : !1;
|
|
45
45
|
}
|
|
46
46
|
function W() {
|
|
@@ -52,7 +52,7 @@ function W() {
|
|
|
52
52
|
on: (a) => {
|
|
53
53
|
e.push(a);
|
|
54
54
|
const r = () => t(a);
|
|
55
|
-
return
|
|
55
|
+
return pe(r), {
|
|
56
56
|
off: r
|
|
57
57
|
};
|
|
58
58
|
},
|
|
@@ -63,37 +63,37 @@ function W() {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
function V(e) {
|
|
66
|
-
return typeof e == "function" ?
|
|
66
|
+
return typeof e == "function" ? ce(e) : D(e);
|
|
67
67
|
}
|
|
68
68
|
function q(e, t = !1) {
|
|
69
69
|
function n(i, { flush: u = "sync", deep: h = !1, timeout: d, throwOnTimeout: F } = {}) {
|
|
70
70
|
let p = null;
|
|
71
|
-
const
|
|
72
|
-
p = G(e, (
|
|
73
|
-
i(
|
|
71
|
+
const N = [new Promise((I) => {
|
|
72
|
+
p = G(e, (j) => {
|
|
73
|
+
i(j) !== t && (p == null || p(), I(j));
|
|
74
74
|
}, {
|
|
75
75
|
flush: u,
|
|
76
76
|
deep: h,
|
|
77
77
|
immediate: !0
|
|
78
78
|
});
|
|
79
79
|
})];
|
|
80
|
-
return d != null &&
|
|
80
|
+
return d != null && N.push(re(d, F).then(() => E(e)).finally(() => p == null ? void 0 : p())), Promise.race(N);
|
|
81
81
|
}
|
|
82
82
|
function s(i, u) {
|
|
83
|
-
if (!
|
|
84
|
-
return n((
|
|
83
|
+
if (!fe(i))
|
|
84
|
+
return n((j) => j === i, u);
|
|
85
85
|
const { flush: h = "sync", deep: d = !1, timeout: F, throwOnTimeout: p } = u ?? {};
|
|
86
86
|
let v = null;
|
|
87
|
-
const
|
|
88
|
-
v = G([e, i], ([
|
|
89
|
-
t !== (
|
|
87
|
+
const I = [new Promise((j) => {
|
|
88
|
+
v = G([e, i], ([P, S]) => {
|
|
89
|
+
t !== (P === S) && (v == null || v(), j(P));
|
|
90
90
|
}, {
|
|
91
91
|
flush: h,
|
|
92
92
|
deep: d,
|
|
93
93
|
immediate: !0
|
|
94
94
|
});
|
|
95
95
|
})];
|
|
96
|
-
return F != null &&
|
|
96
|
+
return F != null && I.push(re(F, p).then(() => E(e)).finally(() => (v == null || v(), E(e)))), Promise.race(I);
|
|
97
97
|
}
|
|
98
98
|
function a(i) {
|
|
99
99
|
return n((u) => Boolean(u), i);
|
|
@@ -104,7 +104,7 @@ function q(e, t = !1) {
|
|
|
104
104
|
function o(i) {
|
|
105
105
|
return s(void 0, i);
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function g(i) {
|
|
108
108
|
return n(Number.isNaN, i);
|
|
109
109
|
}
|
|
110
110
|
function y(i, u) {
|
|
@@ -133,7 +133,7 @@ function q(e, t = !1) {
|
|
|
133
133
|
toBe: s,
|
|
134
134
|
toBeTruthy: a,
|
|
135
135
|
toBeNull: r,
|
|
136
|
-
toBeNaN:
|
|
136
|
+
toBeNaN: g,
|
|
137
137
|
toBeUndefined: o,
|
|
138
138
|
changed: O,
|
|
139
139
|
changedTimes: b,
|
|
@@ -142,18 +142,18 @@ function q(e, t = !1) {
|
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
|
-
function
|
|
145
|
+
function Te(e) {
|
|
146
146
|
return q(e);
|
|
147
147
|
}
|
|
148
|
-
function
|
|
148
|
+
function _e(e, t, n = {}) {
|
|
149
149
|
const {
|
|
150
150
|
immediate: s = !0
|
|
151
|
-
} = n, a =
|
|
151
|
+
} = n, a = D(!1);
|
|
152
152
|
let r = null;
|
|
153
153
|
function o() {
|
|
154
154
|
r && (clearTimeout(r), r = null);
|
|
155
155
|
}
|
|
156
|
-
function
|
|
156
|
+
function g() {
|
|
157
157
|
a.value = !1, o();
|
|
158
158
|
}
|
|
159
159
|
function y(...O) {
|
|
@@ -161,34 +161,34 @@ function Ee(e, t, n = {}) {
|
|
|
161
161
|
a.value = !1, r = null, e(...O);
|
|
162
162
|
}, E(t));
|
|
163
163
|
}
|
|
164
|
-
return s && (a.value = !0,
|
|
164
|
+
return s && (a.value = !0, X && y()), pe(g), {
|
|
165
165
|
isPending: ye(a),
|
|
166
166
|
start: y,
|
|
167
|
-
stop:
|
|
167
|
+
stop: g
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
|
-
const
|
|
171
|
-
R
|
|
172
|
-
R
|
|
173
|
-
var
|
|
170
|
+
const Ee = X ? window : void 0, z = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, R = "__vueuse_ssr_handlers__";
|
|
171
|
+
z[R] = z[R] || {};
|
|
172
|
+
z[R];
|
|
173
|
+
var Fe = Object.defineProperty, Ie = Object.defineProperties, je = Object.getOwnPropertyDescriptors, oe = Object.getOwnPropertySymbols, Ne = Object.prototype.hasOwnProperty, Se = Object.prototype.propertyIsEnumerable, ae = (e, t, n) => t in e ? Fe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, f = (e, t) => {
|
|
174
174
|
for (var n in t || (t = {}))
|
|
175
|
-
Ne.call(t, n) &&
|
|
176
|
-
if (
|
|
177
|
-
for (var n of
|
|
178
|
-
Se.call(t, n) &&
|
|
175
|
+
Ne.call(t, n) && ae(e, n, t[n]);
|
|
176
|
+
if (oe)
|
|
177
|
+
for (var n of oe(t))
|
|
178
|
+
Se.call(t, n) && ae(e, n, t[n]);
|
|
179
179
|
return e;
|
|
180
|
-
}, H = (e, t) => Ie(e,
|
|
181
|
-
const
|
|
180
|
+
}, H = (e, t) => Ie(e, je(t));
|
|
181
|
+
const Be = {
|
|
182
182
|
json: "application/json",
|
|
183
183
|
text: "text/plain"
|
|
184
184
|
};
|
|
185
|
-
function
|
|
185
|
+
function ie(e) {
|
|
186
186
|
return e && Pe(e, "immediate", "refetch", "initialData", "timeout", "beforeFetch", "afterFetch", "onFetchError", "fetch");
|
|
187
187
|
}
|
|
188
188
|
function k(e) {
|
|
189
189
|
return typeof Headers < "u" && e instanceof Headers ? Object.fromEntries([...e.entries()]) : e;
|
|
190
190
|
}
|
|
191
|
-
function
|
|
191
|
+
function Ce(e, ...t) {
|
|
192
192
|
var n;
|
|
193
193
|
const s = typeof AbortController == "function";
|
|
194
194
|
let a = {}, r = { immediate: !0, refetch: !1, timeout: 0 };
|
|
@@ -197,23 +197,23 @@ function Be(e, ...t) {
|
|
|
197
197
|
type: "text",
|
|
198
198
|
payload: void 0
|
|
199
199
|
};
|
|
200
|
-
t.length > 0 && (
|
|
200
|
+
t.length > 0 && (ie(t[0]) ? r = f(f({}, r), t[0]) : a = t[0]), t.length > 1 && ie(t[1]) && (r = f(f({}, r), t[1]));
|
|
201
201
|
const {
|
|
202
|
-
fetch:
|
|
202
|
+
fetch: g = (n = Ee) == null ? void 0 : n.fetch,
|
|
203
203
|
initialData: y,
|
|
204
204
|
timeout: O
|
|
205
|
-
} = r, b = W(), i = W(), u = W(), h =
|
|
206
|
-
let
|
|
205
|
+
} = r, b = W(), i = W(), u = W(), h = D(!1), d = D(!1), F = D(!1), p = D(null), v = M(null), N = M(null), I = M(y), j = ce(() => s && d.value);
|
|
206
|
+
let P, S;
|
|
207
207
|
const J = () => {
|
|
208
|
-
s &&
|
|
208
|
+
s && P && (P.abort(), P = void 0);
|
|
209
209
|
}, K = (l) => {
|
|
210
210
|
d.value = l, h.value = !l;
|
|
211
211
|
};
|
|
212
|
-
O && (
|
|
212
|
+
O && (S = _e(J, O, { immediate: !1 }));
|
|
213
213
|
const $ = async (l = !1) => {
|
|
214
|
-
var
|
|
215
|
-
K(!0),
|
|
216
|
-
signal:
|
|
214
|
+
var w;
|
|
215
|
+
K(!0), N.value = null, p.value = null, F.value = !1, s && (J(), P = new AbortController(), P.signal.onabort = () => F.value = !0, a = H(f({}, a), {
|
|
216
|
+
signal: P.signal
|
|
217
217
|
}));
|
|
218
218
|
const m = {
|
|
219
219
|
method: o.method,
|
|
@@ -221,118 +221,118 @@ function Be(e, ...t) {
|
|
|
221
221
|
};
|
|
222
222
|
if (o.payload) {
|
|
223
223
|
const Q = k(m.headers);
|
|
224
|
-
o.payloadType && (Q["Content-Type"] = (
|
|
224
|
+
o.payloadType && (Q["Content-Type"] = (w = Be[o.payloadType]) != null ? w : o.payloadType);
|
|
225
225
|
const U = E(o.payload);
|
|
226
226
|
m.body = o.payloadType === "json" ? JSON.stringify(U) : U;
|
|
227
227
|
}
|
|
228
|
-
let
|
|
229
|
-
const
|
|
228
|
+
let C = !1;
|
|
229
|
+
const T = {
|
|
230
230
|
url: E(e),
|
|
231
231
|
options: f(f({}, m), a),
|
|
232
232
|
cancel: () => {
|
|
233
|
-
|
|
233
|
+
C = !0;
|
|
234
234
|
}
|
|
235
235
|
};
|
|
236
|
-
if (r.beforeFetch && Object.assign(
|
|
236
|
+
if (r.beforeFetch && Object.assign(T, await r.beforeFetch(T)), C || !g)
|
|
237
237
|
return K(!1), Promise.resolve(null);
|
|
238
238
|
let _ = null;
|
|
239
|
-
return
|
|
240
|
-
var
|
|
241
|
-
|
|
242
|
-
headers: f(f({}, k(m.headers)), k((
|
|
239
|
+
return S && S.start(), new Promise((Q, U) => {
|
|
240
|
+
var Z;
|
|
241
|
+
g(T.url, H(f(f({}, m), T.options), {
|
|
242
|
+
headers: f(f({}, k(m.headers)), k((Z = T.options) == null ? void 0 : Z.headers))
|
|
243
243
|
})).then(async (c) => {
|
|
244
|
-
if (v.value = c, p.value = c.status, _ = await c[o.type](), r.afterFetch && p.value >= 200 && p.value < 300 && ({ data: _ } = await r.afterFetch({ data: _, response: c })),
|
|
244
|
+
if (v.value = c, p.value = c.status, _ = await c[o.type](), r.afterFetch && p.value >= 200 && p.value < 300 && ({ data: _ } = await r.afterFetch({ data: _, response: c })), I.value = _, !c.ok)
|
|
245
245
|
throw new Error(c.statusText);
|
|
246
246
|
return b.trigger(c), Q(c);
|
|
247
247
|
}).catch(async (c) => {
|
|
248
|
-
let
|
|
249
|
-
return r.onFetchError && ({ data: _, error:
|
|
248
|
+
let ee = c.message || c.name;
|
|
249
|
+
return r.onFetchError && ({ data: _, error: ee } = await r.onFetchError({ data: _, error: c, response: v.value })), I.value = _, N.value = ee, i.trigger(c), l ? U(c) : Q(null);
|
|
250
250
|
}).finally(() => {
|
|
251
|
-
K(!1),
|
|
251
|
+
K(!1), S && S.stop(), u.trigger(null);
|
|
252
252
|
});
|
|
253
253
|
});
|
|
254
|
-
},
|
|
254
|
+
}, Y = V(r.refetch);
|
|
255
255
|
G([
|
|
256
|
-
|
|
256
|
+
Y,
|
|
257
257
|
V(e)
|
|
258
258
|
], ([l]) => l && $(), { deep: !0 });
|
|
259
259
|
const x = {
|
|
260
260
|
isFinished: h,
|
|
261
261
|
statusCode: p,
|
|
262
262
|
response: v,
|
|
263
|
-
error:
|
|
264
|
-
data:
|
|
263
|
+
error: N,
|
|
264
|
+
data: I,
|
|
265
265
|
isFetching: d,
|
|
266
|
-
canAbort:
|
|
266
|
+
canAbort: j,
|
|
267
267
|
aborted: F,
|
|
268
268
|
abort: J,
|
|
269
269
|
execute: $,
|
|
270
270
|
onFetchResponse: b.on,
|
|
271
271
|
onFetchError: i.on,
|
|
272
272
|
onFetchFinally: u.on,
|
|
273
|
-
get:
|
|
274
|
-
put:
|
|
275
|
-
post:
|
|
276
|
-
delete:
|
|
277
|
-
patch:
|
|
278
|
-
head:
|
|
279
|
-
options:
|
|
280
|
-
json:
|
|
281
|
-
text:
|
|
282
|
-
blob:
|
|
283
|
-
arrayBuffer:
|
|
284
|
-
formData:
|
|
273
|
+
get: B("GET"),
|
|
274
|
+
put: B("PUT"),
|
|
275
|
+
post: B("POST"),
|
|
276
|
+
delete: B("DELETE"),
|
|
277
|
+
patch: B("PATCH"),
|
|
278
|
+
head: B("HEAD"),
|
|
279
|
+
options: B("OPTIONS"),
|
|
280
|
+
json: A("json"),
|
|
281
|
+
text: A("text"),
|
|
282
|
+
blob: A("blob"),
|
|
283
|
+
arrayBuffer: A("arrayBuffer"),
|
|
284
|
+
formData: A("formData")
|
|
285
285
|
};
|
|
286
|
-
function
|
|
287
|
-
return (
|
|
286
|
+
function B(l) {
|
|
287
|
+
return (w, m) => {
|
|
288
288
|
if (!d.value) {
|
|
289
|
-
o.method = l, o.payload =
|
|
290
|
-
|
|
289
|
+
o.method = l, o.payload = w, o.payloadType = m, fe(o.payload) && G([
|
|
290
|
+
Y,
|
|
291
291
|
V(o.payload)
|
|
292
|
-
], ([
|
|
293
|
-
const
|
|
294
|
-
return !m &&
|
|
295
|
-
then(
|
|
296
|
-
return L().then(
|
|
292
|
+
], ([T]) => T && $(), { deep: !0 });
|
|
293
|
+
const C = E(o.payload);
|
|
294
|
+
return !m && C && Object.getPrototypeOf(C) === Object.prototype && !(C instanceof FormData) && (o.payloadType = "json"), H(f({}, x), {
|
|
295
|
+
then(T, _) {
|
|
296
|
+
return L().then(T, _);
|
|
297
297
|
}
|
|
298
298
|
});
|
|
299
299
|
}
|
|
300
300
|
};
|
|
301
301
|
}
|
|
302
302
|
function L() {
|
|
303
|
-
return new Promise((l,
|
|
304
|
-
|
|
303
|
+
return new Promise((l, w) => {
|
|
304
|
+
Te(h).toBe(!0).then(() => l(x)).catch((m) => w(m));
|
|
305
305
|
});
|
|
306
306
|
}
|
|
307
|
-
function
|
|
307
|
+
function A(l) {
|
|
308
308
|
return () => {
|
|
309
309
|
if (!d.value)
|
|
310
310
|
return o.type = l, H(f({}, x), {
|
|
311
|
-
then(
|
|
312
|
-
return L().then(
|
|
311
|
+
then(w, m) {
|
|
312
|
+
return L().then(w, m);
|
|
313
313
|
}
|
|
314
314
|
});
|
|
315
315
|
};
|
|
316
316
|
}
|
|
317
317
|
return r.immediate && setTimeout($, 0), H(f({}, x), {
|
|
318
|
-
then(l,
|
|
319
|
-
return L().then(l,
|
|
318
|
+
then(l, w) {
|
|
319
|
+
return L().then(l, w);
|
|
320
320
|
}
|
|
321
321
|
});
|
|
322
322
|
}
|
|
323
|
-
var
|
|
323
|
+
var ue;
|
|
324
324
|
(function(e) {
|
|
325
325
|
e.UP = "UP", e.RIGHT = "RIGHT", e.DOWN = "DOWN", e.LEFT = "LEFT", e.NONE = "NONE";
|
|
326
|
-
})(
|
|
327
|
-
var De = Object.defineProperty,
|
|
326
|
+
})(ue || (ue = {}));
|
|
327
|
+
var De = Object.defineProperty, se = Object.getOwnPropertySymbols, Ae = Object.prototype.hasOwnProperty, He = Object.prototype.propertyIsEnumerable, le = (e, t, n) => t in e ? De(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, $e = (e, t) => {
|
|
328
328
|
for (var n in t || (t = {}))
|
|
329
|
-
|
|
330
|
-
if (
|
|
331
|
-
for (var n of
|
|
332
|
-
|
|
329
|
+
Ae.call(t, n) && le(e, n, t[n]);
|
|
330
|
+
if (se)
|
|
331
|
+
for (var n of se(t))
|
|
332
|
+
He.call(t, n) && le(e, n, t[n]);
|
|
333
333
|
return e;
|
|
334
334
|
};
|
|
335
|
-
const
|
|
335
|
+
const xe = {
|
|
336
336
|
easeInSine: [0.12, 0, 0.39, 0],
|
|
337
337
|
easeOutSine: [0.61, 1, 0.88, 1],
|
|
338
338
|
easeInOutSine: [0.37, 0, 0.63, 1],
|
|
@@ -358,24 +358,23 @@ const Qe = {
|
|
|
358
358
|
easeOutBack: [0.34, 1.56, 0.64, 1],
|
|
359
359
|
easeInOutBack: [0.68, -0.6, 0.32, 1.6]
|
|
360
360
|
};
|
|
361
|
-
|
|
362
|
-
linear:
|
|
363
|
-
},
|
|
364
|
-
function
|
|
361
|
+
$e({
|
|
362
|
+
linear: be
|
|
363
|
+
}, xe);
|
|
364
|
+
function Le(e, t) {
|
|
365
365
|
const n = {};
|
|
366
366
|
return Object.keys(e).forEach((a) => {
|
|
367
367
|
n[a] = (...r) => {
|
|
368
|
-
const o = e[a],
|
|
368
|
+
const o = e[a], g = o.type;
|
|
369
369
|
let y = `/api/${o.url}`;
|
|
370
|
-
o.hasBody ? y =
|
|
370
|
+
o.hasBody ? y = te(y, ...r.splice(1)) : y = te(y, ...r);
|
|
371
371
|
const O = {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}, b = Be(
|
|
372
|
+
...de(),
|
|
373
|
+
...o.headers()
|
|
374
|
+
}, b = Ce(
|
|
376
375
|
y,
|
|
377
376
|
{
|
|
378
|
-
method:
|
|
377
|
+
method: g
|
|
379
378
|
},
|
|
380
379
|
{
|
|
381
380
|
immediate: !1,
|
|
@@ -393,23 +392,18 @@ function Me(e, t) {
|
|
|
393
392
|
}
|
|
394
393
|
);
|
|
395
394
|
return {
|
|
396
|
-
...
|
|
395
|
+
...Qe(O) === "application/json" ? b.json() : b.text()
|
|
397
396
|
};
|
|
398
397
|
};
|
|
399
398
|
}), n;
|
|
400
399
|
}
|
|
401
|
-
function
|
|
402
|
-
|
|
403
|
-
return (t == null ? void 0 : t.accept) ?? "";
|
|
404
|
-
}
|
|
405
|
-
function pe(e) {
|
|
406
|
-
let t = {};
|
|
407
|
-
return X(e) ? t = e.value : t = e, t;
|
|
400
|
+
function Qe(e) {
|
|
401
|
+
return e.accept ?? "*/*";
|
|
408
402
|
}
|
|
409
|
-
function
|
|
403
|
+
function Me(e) {
|
|
410
404
|
return JSON.parse(JSON.stringify(e));
|
|
411
405
|
}
|
|
412
|
-
function
|
|
406
|
+
function We(e = 500) {
|
|
413
407
|
const t = ve({
|
|
414
408
|
debouncer: null,
|
|
415
409
|
timeout: e
|
|
@@ -418,14 +412,15 @@ function Ve(e = 500) {
|
|
|
418
412
|
t.debouncer !== null && window.clearTimeout(t.debouncer), t.debouncer = window.setTimeout(() => s(...a), t.timeout);
|
|
419
413
|
}
|
|
420
414
|
return {
|
|
421
|
-
...
|
|
415
|
+
...we(t),
|
|
422
416
|
debounce: n
|
|
423
417
|
};
|
|
424
418
|
}
|
|
425
419
|
export {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
420
|
+
Me as copy,
|
|
421
|
+
Ke as createEndpoint,
|
|
422
|
+
de as getDefaultHeaders,
|
|
423
|
+
Je as requestTypes,
|
|
424
|
+
Le as useApi,
|
|
425
|
+
We as useDebouncer
|
|
431
426
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(p,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("@citruslime/utils"),require("vue")):typeof define=="function"&&define.amd?define(["exports","@citruslime/utils","vue"],A):(p=typeof globalThis<"u"?globalThis:p||self,A(p.CitrusLimeVueUtils={},p.CLUtils,p.Vue))})(this,function(p,A,u){"use strict";const fe=["GET","POST","PUT","DELETE"];function de(e,t,n=null,l=null){return{url:e,type:t,headers:n??q,hasBody:pe(t,l)}}function q(){return{accept:"application/json","content-type":"application/json"}}function pe(e,t){return!!(t===null&&(e==="PUT"||e==="POST")||t)}var Z;const J=typeof window<"u";J&&((Z=window==null?void 0:window.navigator)!=null&&Z.userAgent)&&/iP(ad|hone|od)/.test(window.navigator.userAgent);function T(e){return typeof e=="function"?e():u.unref(e)}function ee(e,t=!1,n="Timeout"){return new Promise((l,a)=>{setTimeout(t?()=>a(n):l,e)})}function he(e){return e}function ye(e,...t){return t.some(n=>n in e)}function te(e){return u.getCurrentScope()?(u.onScopeDispose(e),!0):!1}function M(){const e=[],t=a=>{const r=e.indexOf(a);r!==-1&&e.splice(r,1)};return{on:a=>{e.push(a);const r=()=>t(a);return te(r),{off:r}},off:t,trigger:a=>{e.forEach(r=>r(a))}}}function V(e){return typeof e=="function"?u.computed(e):u.ref(e)}function K(e,t=!1){function n(i,{flush:s="sync",deep:O=!1,timeout:h,throwOnTimeout:I}={}){let y=null;const D=[new Promise(S=>{y=u.watch(e,C=>{i(C)!==t&&(y==null||y(),S(C))},{flush:s,deep:O,immediate:!0})})];return h!=null&&D.push(ee(h,I).then(()=>T(e)).finally(()=>y==null?void 0:y())),Promise.race(D)}function l(i,s){if(!u.isRef(i))return n(C=>C===i,s);const{flush:O="sync",deep:h=!1,timeout:I,throwOnTimeout:y}=s??{};let b=null;const S=[new Promise(C=>{b=u.watch([e,i],([E,N])=>{t!==(E===N)&&(b==null||b(),C(E))},{flush:O,deep:h,immediate:!0})})];return I!=null&&S.push(ee(I,y).then(()=>T(e)).finally(()=>(b==null||b(),T(e)))),Promise.race(S)}function a(i){return n(s=>Boolean(s),i)}function r(i){return l(null,i)}function o(i){return l(void 0,i)}function _(i){return n(Number.isNaN,i)}function m(i,s){return n(O=>{const h=Array.from(O);return h.includes(i)||h.includes(T(i))},s)}function g(i){return v(1,i)}function v(i=1,s){let O=-1;return n(()=>(O+=1,O>=i),s)}return Array.isArray(T(e))?{toMatch:n,toContains:m,changed:g,changedTimes:v,get not(){return K(e,!t)}}:{toMatch:n,toBe:l,toBeTruthy:a,toBeNull:r,toBeNaN:_,toBeUndefined:o,changed:g,changedTimes:v,get not(){return K(e,!t)}}}function me(e){return K(e)}function Oe(e,t,n={}){const{immediate:l=!0}=n,a=u.ref(!1);let r=null;function o(){r&&(clearTimeout(r),r=null)}function _(){a.value=!1,o()}function m(...g){o(),a.value=!0,r=setTimeout(()=>{a.value=!1,r=null,e(...g)},T(t))}return l&&(a.value=!0,J&&m()),te(_),{isPending:u.readonly(a),start:m,stop:_}}const we=J?window:void 0,R=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},W="__vueuse_ssr_handlers__";R[W]=R[W]||{},R[W];var ge=Object.defineProperty,be=Object.defineProperties,Pe=Object.getOwnPropertyDescriptors,ne=Object.getOwnPropertySymbols,Te=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable,re=(e,t,n)=>t in e?ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c=(e,t)=>{for(var n in t||(t={}))Te.call(t,n)&&re(e,n,t[n]);if(ne)for(var n of ne(t))_e.call(t,n)&&re(e,n,t[n]);return e},U=(e,t)=>be(e,Pe(t));const ve={json:"application/json",text:"text/plain"};function oe(e){return e&&ye(e,"immediate","refetch","initialData","timeout","beforeFetch","afterFetch","onFetchError","fetch")}function k(e){return typeof Headers<"u"&&e instanceof Headers?Object.fromEntries([...e.entries()]):e}function Ee(e,...t){var n;const l=typeof AbortController=="function";let a={},r={immediate:!0,refetch:!1,timeout:0};const o={method:"GET",type:"text",payload:void 0};t.length>0&&(oe(t[0])?r=c(c({},r),t[0]):a=t[0]),t.length>1&&oe(t[1])&&(r=c(c({},r),t[1]));const{fetch:_=(n=we)==null?void 0:n.fetch,initialData:m,timeout:g}=r,v=M(),i=M(),s=M(),O=u.ref(!1),h=u.ref(!1),I=u.ref(!1),y=u.ref(null),b=u.shallowRef(null),D=u.shallowRef(null),S=u.shallowRef(m),C=u.computed(()=>l&&h.value);let E,N;const z=()=>{l&&E&&(E.abort(),E=void 0)},X=f=>{h.value=f,O.value=!f};g&&(N=Oe(z,g,{immediate:!1}));const Q=async(f=!1)=>{var P;X(!0),D.value=null,y.value=null,I.value=!1,l&&(z(),E=new AbortController,E.signal.onabort=()=>I.value=!0,a=U(c({},a),{signal:E.signal}));const w={method:o.method,headers:{}};if(o.payload){const G=k(w.headers);o.payloadType&&(G["Content-Type"]=(P=ve[o.payloadType])!=null?P:o.payloadType);const L=T(o.payload);w.body=o.payloadType==="json"?JSON.stringify(L):L}let H=!1;const F={url:T(e),options:c(c({},w),a),cancel:()=>{H=!0}};if(r.beforeFetch&&Object.assign(F,await r.beforeFetch(F)),H||!_)return X(!1),Promise.resolve(null);let j=null;return N&&N.start(),new Promise((G,L)=>{var le;_(F.url,U(c(c({},w),F.options),{headers:c(c({},k(w.headers)),k((le=F.options)==null?void 0:le.headers))})).then(async d=>{if(b.value=d,y.value=d.status,j=await d[o.type](),r.afterFetch&&y.value>=200&&y.value<300&&({data:j}=await r.afterFetch({data:j,response:d})),S.value=j,!d.ok)throw new Error(d.statusText);return v.trigger(d),G(d)}).catch(async d=>{let ce=d.message||d.name;return r.onFetchError&&({data:j,error:ce}=await r.onFetchError({data:j,error:d,response:b.value})),S.value=j,D.value=ce,i.trigger(d),f?L(d):G(null)}).finally(()=>{X(!1),N&&N.stop(),s.trigger(null)})})},ue=V(r.refetch);u.watch([ue,V(e)],([f])=>f&&Q(),{deep:!0});const x={isFinished:O,statusCode:y,response:b,error:D,data:S,isFetching:h,canAbort:C,aborted:I,abort:z,execute:Q,onFetchResponse:v.on,onFetchError:i.on,onFetchFinally:s.on,get:B("GET"),put:B("PUT"),post:B("POST"),delete:B("DELETE"),patch:B("PATCH"),head:B("HEAD"),options:B("OPTIONS"),json:$("json"),text:$("text"),blob:$("blob"),arrayBuffer:$("arrayBuffer"),formData:$("formData")};function B(f){return(P,w)=>{if(!h.value){o.method=f,o.payload=P,o.payloadType=w,u.isRef(o.payload)&&u.watch([ue,V(o.payload)],([F])=>F&&Q(),{deep:!0});const H=T(o.payload);return!w&&H&&Object.getPrototypeOf(H)===Object.prototype&&!(H instanceof FormData)&&(o.payloadType="json"),U(c({},x),{then(F,j){return Y().then(F,j)}})}}}function Y(){return new Promise((f,P)=>{me(O).toBe(!0).then(()=>f(x)).catch(w=>P(w))})}function $(f){return()=>{if(!h.value)return o.type=f,U(c({},x),{then(P,w){return Y().then(P,w)}})}}return r.immediate&&setTimeout(Q,0),U(c({},x),{then(f,P){return Y().then(f,P)}})}var ae;(function(e){e.UP="UP",e.RIGHT="RIGHT",e.DOWN="DOWN",e.LEFT="LEFT",e.NONE="NONE"})(ae||(ae={}));var Fe=Object.defineProperty,ie=Object.getOwnPropertySymbols,je=Object.prototype.hasOwnProperty,Ie=Object.prototype.propertyIsEnumerable,se=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Se=(e,t)=>{for(var n in t||(t={}))je.call(t,n)&&se(e,n,t[n]);if(ie)for(var n of ie(t))Ie.call(t,n)&&se(e,n,t[n]);return e};Se({linear:he},{easeInSine:[.12,0,.39,0],easeOutSine:[.61,1,.88,1],easeInOutSine:[.37,0,.63,1],easeInQuad:[.11,0,.5,0],easeOutQuad:[.5,1,.89,1],easeInOutQuad:[.45,0,.55,1],easeInCubic:[.32,0,.67,0],easeOutCubic:[.33,1,.68,1],easeInOutCubic:[.65,0,.35,1],easeInQuart:[.5,0,.75,0],easeOutQuart:[.25,1,.5,1],easeInOutQuart:[.76,0,.24,1],easeInQuint:[.64,0,.78,0],easeOutQuint:[.22,1,.36,1],easeInOutQuint:[.83,0,.17,1],easeInExpo:[.7,0,.84,0],easeOutExpo:[.16,1,.3,1],easeInOutExpo:[.87,0,.13,1],easeInCirc:[.55,0,1,.45],easeOutCirc:[0,.55,.45,1],easeInOutCirc:[.85,0,.15,1],easeInBack:[.36,0,.66,-.56],easeOutBack:[.34,1.56,.64,1],easeInOutBack:[.68,-.6,.32,1.6]});function Ce(e,t){const n={};return Object.keys(e).forEach(a=>{n[a]=(...r)=>{const o=e[a],_=o.type;let m=`/api/${o.url}`;o.hasBody?m=A.replacePlaceholders(m,...r.splice(1)):m=A.replacePlaceholders(m,...r);const g={...q(),...o.headers()},v=Ee(m,{method:_},{immediate:!1,beforeFetch({options:s}){return s.headers={...s.headers,...g},o.hasBody&&r.length&&(s.body=JSON.stringify(r[0])),{options:s}},onFetchError(s){return s!=null&&s.response&&t(s),s}});return{...De(g)==="application/json"?v.json():v.text()}}}),n}function De(e){return e.accept??"*/*"}function Ne(e){return JSON.parse(JSON.stringify(e))}function Be(e=500){const t=u.reactive({debouncer:null,timeout:e});function n(l,...a){t.debouncer!==null&&window.clearTimeout(t.debouncer),t.debouncer=window.setTimeout(()=>l(...a),t.timeout)}return{...u.toRefs(t),debounce:n}}p.copy=Ne,p.createEndpoint=de,p.getDefaultHeaders=q,p.requestTypes=fe,p.useApi=Ce,p.useDebouncer=Be,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { Ref } from 'vue';
|
|
2
1
|
export declare const requestTypes: readonly ["GET", "POST", "PUT", "DELETE"];
|
|
3
2
|
export interface Endpoint {
|
|
4
3
|
url: string;
|
|
5
4
|
type: typeof requestTypes[number];
|
|
6
|
-
headers:
|
|
5
|
+
headers: () => HeadersInit;
|
|
7
6
|
hasBody: boolean;
|
|
8
7
|
}
|
|
9
8
|
/**
|
|
@@ -15,4 +14,10 @@ export interface Endpoint {
|
|
|
15
14
|
* @param hasBody Determines whether or not an endpoint should have a body.
|
|
16
15
|
* @returns The created Endpoint object.
|
|
17
16
|
*/
|
|
18
|
-
export declare function createEndpoint(url: string, type: typeof requestTypes[number], headers?:
|
|
17
|
+
export declare function createEndpoint(url: string, type: typeof requestTypes[number], headers?: (() => HeadersInit) | null, hasBody?: boolean | null): Endpoint;
|
|
18
|
+
/**
|
|
19
|
+
* Gets a set of default headers.
|
|
20
|
+
*
|
|
21
|
+
* @returns A set of default headers.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDefaultHeaders(): HeadersInit;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useFetch } from '@vueuse/core';
|
|
2
|
-
import type
|
|
2
|
+
import { type Endpoint } from './endpoints';
|
|
3
3
|
export type ApiRequest<TResponseModel> = ReturnType<typeof useFetch<TResponseModel>>;
|
|
4
4
|
/**
|
|
5
5
|
* Composable that constructs an API object containing requests defined by the endpoints object.
|