@citruslime/vue-utils 1.2.2-beta.0 → 1.3.0-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,99 +1,107 @@
|
|
|
1
|
-
import { replacePlaceholders as
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
1
|
+
import { replacePlaceholders as Y } from "@citruslime/utils";
|
|
2
|
+
import { toRef as se, readonly as re, customRef as le, ref as $, getCurrentScope as ce, onScopeDispose as fe, unref as de, watch as I, isRef as oe, shallowRef as q, computed as pe, reactive as he, toRefs as me } from "vue";
|
|
3
|
+
const He = [
|
|
4
4
|
"GET",
|
|
5
5
|
"POST",
|
|
6
6
|
"PUT",
|
|
7
7
|
"DELETE"
|
|
8
8
|
];
|
|
9
|
-
function
|
|
9
|
+
function $e(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 ?? ae,
|
|
14
|
+
hasBody: ye(t, s)
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function ae() {
|
|
18
18
|
return {
|
|
19
19
|
accept: "application/json",
|
|
20
20
|
"content-type": "application/json"
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function ye(e, t) {
|
|
24
24
|
return !!(t === null && (e === "PUT" || e === "POST") || t);
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
z && ((ee = window == null ? void 0 : window.navigator) != null && ee.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
|
|
29
|
-
function E(e) {
|
|
30
|
-
return typeof e == "function" ? e() : he(e);
|
|
31
|
-
}
|
|
32
|
-
function te(e, t = !1, n = "Timeout") {
|
|
33
|
-
return new Promise((s, a) => {
|
|
34
|
-
setTimeout(t ? () => a(n) : s, e);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function be(e) {
|
|
38
|
-
return e;
|
|
39
|
-
}
|
|
40
|
-
function Pe(e, ...t) {
|
|
41
|
-
return t.some((n) => n in e);
|
|
42
|
-
}
|
|
43
|
-
function pe(e) {
|
|
44
|
-
return me() ? (Oe(e), !0) : !1;
|
|
26
|
+
function ie(e) {
|
|
27
|
+
return ce() ? (fe(e), !0) : !1;
|
|
45
28
|
}
|
|
46
|
-
function
|
|
47
|
-
const e =
|
|
48
|
-
|
|
49
|
-
r !== -1 && e.splice(r, 1);
|
|
29
|
+
function L() {
|
|
30
|
+
const e = /* @__PURE__ */ new Set(), t = (a) => {
|
|
31
|
+
e.delete(a);
|
|
50
32
|
};
|
|
51
33
|
return {
|
|
52
34
|
on: (a) => {
|
|
53
|
-
e.
|
|
35
|
+
e.add(a);
|
|
54
36
|
const r = () => t(a);
|
|
55
|
-
return
|
|
37
|
+
return ie(r), {
|
|
56
38
|
off: r
|
|
57
39
|
};
|
|
58
40
|
},
|
|
59
41
|
off: t,
|
|
60
|
-
trigger: (a) =>
|
|
61
|
-
e.forEach((r) => r(a));
|
|
62
|
-
}
|
|
42
|
+
trigger: (a) => Promise.all(Array.from(e).map((r) => r(a)))
|
|
63
43
|
};
|
|
64
44
|
}
|
|
65
|
-
function
|
|
66
|
-
return typeof e == "function" ?
|
|
45
|
+
function O(e) {
|
|
46
|
+
return typeof e == "function" ? e() : de(e);
|
|
67
47
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
48
|
+
const ue = typeof window < "u", ve = () => {
|
|
49
|
+
};
|
|
50
|
+
function Z(e, t = !1, n = "Timeout") {
|
|
51
|
+
return new Promise((s, a) => {
|
|
52
|
+
setTimeout(t ? () => a(n) : s, e);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function we(e, ...t) {
|
|
56
|
+
return t.some((n) => n in e);
|
|
57
|
+
}
|
|
58
|
+
function R(...e) {
|
|
59
|
+
if (e.length !== 1)
|
|
60
|
+
return se(...e);
|
|
61
|
+
const t = e[0];
|
|
62
|
+
return typeof t == "function" ? re(le(() => ({ get: t, set: ve }))) : $(t);
|
|
63
|
+
}
|
|
64
|
+
function k(e, t = !1) {
|
|
65
|
+
function n(i, { flush: u = "sync", deep: h = !1, timeout: p, throwOnTimeout: F } = {}) {
|
|
66
|
+
let y = null;
|
|
67
|
+
const D = [new Promise((E) => {
|
|
68
|
+
y = I(
|
|
69
|
+
e,
|
|
70
|
+
(_) => {
|
|
71
|
+
i(_) !== t && (y == null || y(), E(_));
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
flush: u,
|
|
75
|
+
deep: h,
|
|
76
|
+
immediate: !0
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
79
|
})];
|
|
80
|
-
return
|
|
80
|
+
return p != null && D.push(
|
|
81
|
+
Z(p, F).then(() => O(e)).finally(() => y == null ? void 0 : y())
|
|
82
|
+
), Promise.race(D);
|
|
81
83
|
}
|
|
82
84
|
function s(i, u) {
|
|
83
|
-
if (!
|
|
84
|
-
return n((
|
|
85
|
-
const { flush: h = "sync", deep:
|
|
86
|
-
let
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
if (!oe(i))
|
|
86
|
+
return n((_) => _ === i, u);
|
|
87
|
+
const { flush: h = "sync", deep: p = !1, timeout: F, throwOnTimeout: y } = u ?? {};
|
|
88
|
+
let w = null;
|
|
89
|
+
const E = [new Promise((_) => {
|
|
90
|
+
w = I(
|
|
91
|
+
[e, i],
|
|
92
|
+
([j, S]) => {
|
|
93
|
+
t !== (j === S) && (w == null || w(), _(j));
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
flush: h,
|
|
97
|
+
deep: p,
|
|
98
|
+
immediate: !0
|
|
99
|
+
}
|
|
100
|
+
);
|
|
95
101
|
})];
|
|
96
|
-
return F != null &&
|
|
102
|
+
return F != null && E.push(
|
|
103
|
+
Z(F, y).then(() => O(e)).finally(() => (w == null || w(), O(e)))
|
|
104
|
+
), Promise.race(E);
|
|
97
105
|
}
|
|
98
106
|
function a(i) {
|
|
99
107
|
return n((u) => !!u, i);
|
|
@@ -104,90 +112,89 @@ function q(e, t = !1) {
|
|
|
104
112
|
function o(i) {
|
|
105
113
|
return s(void 0, i);
|
|
106
114
|
}
|
|
107
|
-
function
|
|
115
|
+
function b(i) {
|
|
108
116
|
return n(Number.isNaN, i);
|
|
109
117
|
}
|
|
110
|
-
function
|
|
118
|
+
function d(i, u) {
|
|
111
119
|
return n((h) => {
|
|
112
|
-
const
|
|
113
|
-
return
|
|
120
|
+
const p = Array.from(h);
|
|
121
|
+
return p.includes(i) || p.includes(O(i));
|
|
114
122
|
}, u);
|
|
115
123
|
}
|
|
116
|
-
function
|
|
117
|
-
return
|
|
124
|
+
function v(i) {
|
|
125
|
+
return g(1, i);
|
|
118
126
|
}
|
|
119
|
-
function
|
|
127
|
+
function g(i = 1, u) {
|
|
120
128
|
let h = -1;
|
|
121
129
|
return n(() => (h += 1, h >= i), u);
|
|
122
130
|
}
|
|
123
|
-
return Array.isArray(
|
|
131
|
+
return Array.isArray(O(e)) ? {
|
|
124
132
|
toMatch: n,
|
|
125
|
-
toContains:
|
|
126
|
-
changed:
|
|
127
|
-
changedTimes:
|
|
133
|
+
toContains: d,
|
|
134
|
+
changed: v,
|
|
135
|
+
changedTimes: g,
|
|
128
136
|
get not() {
|
|
129
|
-
return
|
|
137
|
+
return k(e, !t);
|
|
130
138
|
}
|
|
131
139
|
} : {
|
|
132
140
|
toMatch: n,
|
|
133
141
|
toBe: s,
|
|
134
142
|
toBeTruthy: a,
|
|
135
143
|
toBeNull: r,
|
|
136
|
-
toBeNaN:
|
|
144
|
+
toBeNaN: b,
|
|
137
145
|
toBeUndefined: o,
|
|
138
|
-
changed:
|
|
139
|
-
changedTimes:
|
|
146
|
+
changed: v,
|
|
147
|
+
changedTimes: g,
|
|
140
148
|
get not() {
|
|
141
|
-
return
|
|
149
|
+
return k(e, !t);
|
|
142
150
|
}
|
|
143
151
|
};
|
|
144
152
|
}
|
|
145
|
-
function
|
|
146
|
-
return
|
|
153
|
+
function Pe(e) {
|
|
154
|
+
return k(e);
|
|
147
155
|
}
|
|
148
|
-
function
|
|
156
|
+
function be(e, t, n = {}) {
|
|
149
157
|
const {
|
|
150
158
|
immediate: s = !0
|
|
151
|
-
} = n, a =
|
|
159
|
+
} = n, a = $(!1);
|
|
152
160
|
let r = null;
|
|
153
161
|
function o() {
|
|
154
162
|
r && (clearTimeout(r), r = null);
|
|
155
163
|
}
|
|
156
|
-
function
|
|
164
|
+
function b() {
|
|
157
165
|
a.value = !1, o();
|
|
158
166
|
}
|
|
159
|
-
function
|
|
167
|
+
function d(...v) {
|
|
160
168
|
o(), a.value = !0, r = setTimeout(() => {
|
|
161
|
-
a.value = !1, r = null, e(...
|
|
162
|
-
},
|
|
169
|
+
a.value = !1, r = null, e(...v);
|
|
170
|
+
}, O(t));
|
|
163
171
|
}
|
|
164
|
-
return s && (a.value = !0,
|
|
165
|
-
isPending:
|
|
166
|
-
start:
|
|
167
|
-
stop:
|
|
172
|
+
return s && (a.value = !0, ue && d()), ie(b), {
|
|
173
|
+
isPending: re(a),
|
|
174
|
+
start: d,
|
|
175
|
+
stop: b
|
|
168
176
|
};
|
|
169
177
|
}
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
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) => {
|
|
178
|
+
const ge = ue ? window : void 0;
|
|
179
|
+
var Te = Object.defineProperty, Oe = Object.defineProperties, Fe = Object.getOwnPropertyDescriptors, ee = Object.getOwnPropertySymbols, Ee = Object.prototype.hasOwnProperty, _e = Object.prototype.propertyIsEnumerable, te = (e, t, n) => t in e ? Te(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, f = (e, t) => {
|
|
173
180
|
for (var n in t || (t = {}))
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
for (var n of
|
|
177
|
-
|
|
181
|
+
Ee.call(t, n) && te(e, n, t[n]);
|
|
182
|
+
if (ee)
|
|
183
|
+
for (var n of ee(t))
|
|
184
|
+
_e.call(t, n) && te(e, n, t[n]);
|
|
178
185
|
return e;
|
|
179
|
-
},
|
|
180
|
-
const
|
|
186
|
+
}, N = (e, t) => Oe(e, Fe(t));
|
|
187
|
+
const je = {
|
|
181
188
|
json: "application/json",
|
|
182
189
|
text: "text/plain"
|
|
183
190
|
};
|
|
184
|
-
function
|
|
185
|
-
return e &&
|
|
191
|
+
function ne(e) {
|
|
192
|
+
return e && we(e, "immediate", "refetch", "initialData", "timeout", "beforeFetch", "afterFetch", "onFetchError", "fetch");
|
|
186
193
|
}
|
|
187
|
-
function
|
|
194
|
+
function W(e) {
|
|
188
195
|
return typeof Headers < "u" && e instanceof Headers ? Object.fromEntries([...e.entries()]) : e;
|
|
189
196
|
}
|
|
190
|
-
function
|
|
197
|
+
function De(e, ...t) {
|
|
191
198
|
var n;
|
|
192
199
|
const s = typeof AbortController == "function";
|
|
193
200
|
let a = {}, r = { immediate: !0, refetch: !1, timeout: 0 };
|
|
@@ -196,191 +203,163 @@ function Ce(e, ...t) {
|
|
|
196
203
|
type: "text",
|
|
197
204
|
payload: void 0
|
|
198
205
|
};
|
|
199
|
-
t.length > 0 && (
|
|
206
|
+
t.length > 0 && (ne(t[0]) ? r = f(f({}, r), t[0]) : a = t[0]), t.length > 1 && ne(t[1]) && (r = f(f({}, r), t[1]));
|
|
200
207
|
const {
|
|
201
|
-
fetch:
|
|
202
|
-
initialData:
|
|
203
|
-
timeout:
|
|
204
|
-
} = r,
|
|
205
|
-
let
|
|
206
|
-
const
|
|
207
|
-
s &&
|
|
208
|
-
|
|
209
|
-
d.value = l, h.value = !l;
|
|
210
|
-
};
|
|
211
|
-
O && (S = _e(J, O, { immediate: !1 }));
|
|
212
|
-
const $ = async (l = !1) => {
|
|
213
|
-
var w;
|
|
214
|
-
M(!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), {
|
|
215
|
-
signal: P.signal
|
|
208
|
+
fetch: b = (n = ge) == null ? void 0 : n.fetch,
|
|
209
|
+
initialData: d,
|
|
210
|
+
timeout: v
|
|
211
|
+
} = r, g = L(), i = L(), u = L(), h = $(!1), p = $(!1), F = $(!1), y = $(null), w = q(null), D = q(null), E = q(d || null), _ = pe(() => s && p.value);
|
|
212
|
+
let j, S;
|
|
213
|
+
const M = () => {
|
|
214
|
+
s && (j == null || j.abort(), j = new AbortController(), j.signal.onabort = () => F.value = !0, a = N(f({}, a), {
|
|
215
|
+
signal: j.signal
|
|
216
216
|
}));
|
|
217
|
+
}, K = (l) => {
|
|
218
|
+
p.value = l, h.value = !l;
|
|
219
|
+
};
|
|
220
|
+
v && (S = be(M, v, { immediate: !1 }));
|
|
221
|
+
const U = async (l = !1) => {
|
|
222
|
+
var P;
|
|
223
|
+
M(), K(!0), D.value = null, y.value = null, F.value = !1;
|
|
217
224
|
const m = {
|
|
218
225
|
method: o.method,
|
|
219
226
|
headers: {}
|
|
220
227
|
};
|
|
221
228
|
if (o.payload) {
|
|
222
|
-
const
|
|
223
|
-
o.payloadType && (
|
|
224
|
-
const
|
|
225
|
-
m.body = o.payloadType === "json" ? JSON.stringify(
|
|
229
|
+
const J = W(m.headers);
|
|
230
|
+
o.payloadType && (J["Content-Type"] = (P = je[o.payloadType]) != null ? P : o.payloadType);
|
|
231
|
+
const G = O(o.payload);
|
|
232
|
+
m.body = o.payloadType === "json" ? JSON.stringify(G) : G;
|
|
226
233
|
}
|
|
227
|
-
let
|
|
234
|
+
let H = !1;
|
|
228
235
|
const T = {
|
|
229
|
-
url:
|
|
236
|
+
url: O(e),
|
|
230
237
|
options: f(f({}, m), a),
|
|
231
238
|
cancel: () => {
|
|
232
|
-
|
|
239
|
+
H = !0;
|
|
233
240
|
}
|
|
234
241
|
};
|
|
235
|
-
if (r.beforeFetch && Object.assign(T, await r.beforeFetch(T)),
|
|
236
|
-
return
|
|
237
|
-
let
|
|
238
|
-
return S && S.start(), new Promise((
|
|
239
|
-
var
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
if (r.beforeFetch && Object.assign(T, await r.beforeFetch(T)), H || !b)
|
|
243
|
+
return K(!1), Promise.resolve(null);
|
|
244
|
+
let B = null;
|
|
245
|
+
return S && S.start(), new Promise((J, G) => {
|
|
246
|
+
var Q;
|
|
247
|
+
b(
|
|
248
|
+
T.url,
|
|
249
|
+
N(f(f({}, m), T.options), {
|
|
250
|
+
headers: f(f({}, W(m.headers)), W((Q = T.options) == null ? void 0 : Q.headers))
|
|
251
|
+
})
|
|
252
|
+
).then(async (c) => {
|
|
253
|
+
if (w.value = c, y.value = c.status, B = await c[o.type](), !c.ok)
|
|
254
|
+
throw E.value = d || null, new Error(c.statusText);
|
|
255
|
+
return r.afterFetch && ({ data: B } = await r.afterFetch({ data: B, response: c })), E.value = B, g.trigger(c), J(c);
|
|
246
256
|
}).catch(async (c) => {
|
|
247
|
-
let
|
|
248
|
-
return r.onFetchError && ({
|
|
257
|
+
let X = c.message || c.name;
|
|
258
|
+
return r.onFetchError && ({ error: X } = await r.onFetchError({ data: B, error: c, response: w.value })), D.value = X, i.trigger(c), l ? G(c) : J(null);
|
|
249
259
|
}).finally(() => {
|
|
250
|
-
|
|
260
|
+
K(!1), S && S.stop(), u.trigger(null);
|
|
251
261
|
});
|
|
252
262
|
});
|
|
253
|
-
},
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
263
|
+
}, z = R(r.refetch);
|
|
264
|
+
I(
|
|
265
|
+
[
|
|
266
|
+
z,
|
|
267
|
+
R(e)
|
|
268
|
+
],
|
|
269
|
+
([l]) => l && U(),
|
|
270
|
+
{ deep: !0 }
|
|
271
|
+
);
|
|
258
272
|
const x = {
|
|
259
273
|
isFinished: h,
|
|
260
|
-
statusCode:
|
|
261
|
-
response:
|
|
262
|
-
error:
|
|
263
|
-
data:
|
|
264
|
-
isFetching:
|
|
265
|
-
canAbort:
|
|
274
|
+
statusCode: y,
|
|
275
|
+
response: w,
|
|
276
|
+
error: D,
|
|
277
|
+
data: E,
|
|
278
|
+
isFetching: p,
|
|
279
|
+
canAbort: _,
|
|
266
280
|
aborted: F,
|
|
267
|
-
abort:
|
|
268
|
-
execute:
|
|
269
|
-
onFetchResponse:
|
|
281
|
+
abort: M,
|
|
282
|
+
execute: U,
|
|
283
|
+
onFetchResponse: g.on,
|
|
270
284
|
onFetchError: i.on,
|
|
271
285
|
onFetchFinally: u.on,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
286
|
+
// method
|
|
287
|
+
get: A("GET"),
|
|
288
|
+
put: A("PUT"),
|
|
289
|
+
post: A("POST"),
|
|
290
|
+
delete: A("DELETE"),
|
|
291
|
+
patch: A("PATCH"),
|
|
292
|
+
head: A("HEAD"),
|
|
293
|
+
options: A("OPTIONS"),
|
|
294
|
+
// type
|
|
295
|
+
json: C("json"),
|
|
296
|
+
text: C("text"),
|
|
297
|
+
blob: C("blob"),
|
|
298
|
+
arrayBuffer: C("arrayBuffer"),
|
|
299
|
+
formData: C("formData")
|
|
284
300
|
};
|
|
285
|
-
function
|
|
286
|
-
return (
|
|
287
|
-
if (!
|
|
288
|
-
o.method = l, o.payload =
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
301
|
+
function A(l) {
|
|
302
|
+
return (P, m) => {
|
|
303
|
+
if (!p.value) {
|
|
304
|
+
o.method = l, o.payload = P, o.payloadType = m, oe(o.payload) && I(
|
|
305
|
+
[
|
|
306
|
+
z,
|
|
307
|
+
R(o.payload)
|
|
308
|
+
],
|
|
309
|
+
([T]) => T && U(),
|
|
310
|
+
{ deep: !0 }
|
|
311
|
+
);
|
|
312
|
+
const H = O(o.payload);
|
|
313
|
+
return !m && H && Object.getPrototypeOf(H) === Object.prototype && !(H instanceof FormData) && (o.payloadType = "json"), N(f({}, x), {
|
|
314
|
+
then(T, B) {
|
|
315
|
+
return V().then(T, B);
|
|
296
316
|
}
|
|
297
317
|
});
|
|
298
318
|
}
|
|
299
319
|
};
|
|
300
320
|
}
|
|
301
|
-
function
|
|
302
|
-
return new Promise((l,
|
|
303
|
-
|
|
321
|
+
function V() {
|
|
322
|
+
return new Promise((l, P) => {
|
|
323
|
+
Pe(h).toBe(!0).then(() => l(x)).catch((m) => P(m));
|
|
304
324
|
});
|
|
305
325
|
}
|
|
306
|
-
function
|
|
326
|
+
function C(l) {
|
|
307
327
|
return () => {
|
|
308
|
-
if (!
|
|
309
|
-
return o.type = l,
|
|
310
|
-
then(
|
|
311
|
-
return
|
|
328
|
+
if (!p.value)
|
|
329
|
+
return o.type = l, N(f({}, x), {
|
|
330
|
+
then(P, m) {
|
|
331
|
+
return V().then(P, m);
|
|
312
332
|
}
|
|
313
333
|
});
|
|
314
334
|
};
|
|
315
335
|
}
|
|
316
|
-
return r.immediate &&
|
|
317
|
-
then(l,
|
|
318
|
-
return
|
|
336
|
+
return r.immediate && Promise.resolve().then(() => U()), N(f({}, x), {
|
|
337
|
+
then(l, P) {
|
|
338
|
+
return V().then(l, P);
|
|
319
339
|
}
|
|
320
340
|
});
|
|
321
341
|
}
|
|
322
|
-
|
|
323
|
-
(function(e) {
|
|
324
|
-
e.UP = "UP", e.RIGHT = "RIGHT", e.DOWN = "DOWN", e.LEFT = "LEFT", e.NONE = "NONE";
|
|
325
|
-
})(ue || (ue = {}));
|
|
326
|
-
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) => {
|
|
327
|
-
for (var n in t || (t = {}))
|
|
328
|
-
Ae.call(t, n) && le(e, n, t[n]);
|
|
329
|
-
if (se)
|
|
330
|
-
for (var n of se(t))
|
|
331
|
-
He.call(t, n) && le(e, n, t[n]);
|
|
332
|
-
return e;
|
|
333
|
-
};
|
|
334
|
-
const xe = {
|
|
335
|
-
easeInSine: [0.12, 0, 0.39, 0],
|
|
336
|
-
easeOutSine: [0.61, 1, 0.88, 1],
|
|
337
|
-
easeInOutSine: [0.37, 0, 0.63, 1],
|
|
338
|
-
easeInQuad: [0.11, 0, 0.5, 0],
|
|
339
|
-
easeOutQuad: [0.5, 1, 0.89, 1],
|
|
340
|
-
easeInOutQuad: [0.45, 0, 0.55, 1],
|
|
341
|
-
easeInCubic: [0.32, 0, 0.67, 0],
|
|
342
|
-
easeOutCubic: [0.33, 1, 0.68, 1],
|
|
343
|
-
easeInOutCubic: [0.65, 0, 0.35, 1],
|
|
344
|
-
easeInQuart: [0.5, 0, 0.75, 0],
|
|
345
|
-
easeOutQuart: [0.25, 1, 0.5, 1],
|
|
346
|
-
easeInOutQuart: [0.76, 0, 0.24, 1],
|
|
347
|
-
easeInQuint: [0.64, 0, 0.78, 0],
|
|
348
|
-
easeOutQuint: [0.22, 1, 0.36, 1],
|
|
349
|
-
easeInOutQuint: [0.83, 0, 0.17, 1],
|
|
350
|
-
easeInExpo: [0.7, 0, 0.84, 0],
|
|
351
|
-
easeOutExpo: [0.16, 1, 0.3, 1],
|
|
352
|
-
easeInOutExpo: [0.87, 0, 0.13, 1],
|
|
353
|
-
easeInCirc: [0.55, 0, 1, 0.45],
|
|
354
|
-
easeOutCirc: [0, 0.55, 0.45, 1],
|
|
355
|
-
easeInOutCirc: [0.85, 0, 0.15, 1],
|
|
356
|
-
easeInBack: [0.36, 0, 0.66, -0.56],
|
|
357
|
-
easeOutBack: [0.34, 1.56, 0.64, 1],
|
|
358
|
-
easeInOutBack: [0.68, -0.6, 0.32, 1.6]
|
|
359
|
-
};
|
|
360
|
-
$e({
|
|
361
|
-
linear: be
|
|
362
|
-
}, xe);
|
|
363
|
-
function Ke(e, t) {
|
|
342
|
+
function Ce(e, t) {
|
|
364
343
|
const n = {};
|
|
365
344
|
return Object.keys(e).forEach((a) => {
|
|
366
345
|
n[a] = (...r) => {
|
|
367
|
-
const o = e[a],
|
|
368
|
-
let
|
|
369
|
-
o.hasBody ?
|
|
370
|
-
const
|
|
371
|
-
...
|
|
346
|
+
const o = e[a], b = o.type;
|
|
347
|
+
let d = `/api/${o.url}`;
|
|
348
|
+
o.hasBody ? d = Y(d, ...r.splice(1)) : d = Y(d, ...r);
|
|
349
|
+
const v = {
|
|
350
|
+
...ae(),
|
|
372
351
|
...o.headers()
|
|
373
|
-
},
|
|
374
|
-
|
|
352
|
+
}, g = De(
|
|
353
|
+
d,
|
|
375
354
|
{
|
|
376
|
-
method:
|
|
355
|
+
method: b
|
|
377
356
|
},
|
|
378
357
|
{
|
|
379
358
|
immediate: !1,
|
|
380
359
|
beforeFetch({ options: u }) {
|
|
381
360
|
return u.headers = {
|
|
382
361
|
...u.headers,
|
|
383
|
-
...
|
|
362
|
+
...v
|
|
384
363
|
}, o.hasBody && r.length && (u.body = JSON.stringify(r[0])), {
|
|
385
364
|
options: u
|
|
386
365
|
};
|
|
@@ -391,19 +370,19 @@ function Ke(e, t) {
|
|
|
391
370
|
}
|
|
392
371
|
);
|
|
393
372
|
return {
|
|
394
|
-
...
|
|
373
|
+
...Se(v) === "application/json" ? g.json() : g.text()
|
|
395
374
|
};
|
|
396
375
|
};
|
|
397
376
|
}), n;
|
|
398
377
|
}
|
|
399
|
-
function
|
|
378
|
+
function Se(e) {
|
|
400
379
|
return e.accept ?? "*/*";
|
|
401
380
|
}
|
|
402
|
-
function
|
|
381
|
+
function Ne(e) {
|
|
403
382
|
return JSON.parse(JSON.stringify(e));
|
|
404
383
|
}
|
|
405
|
-
function
|
|
406
|
-
const t =
|
|
384
|
+
function Ue(e = 500) {
|
|
385
|
+
const t = he({
|
|
407
386
|
debouncer: null,
|
|
408
387
|
timeout: e
|
|
409
388
|
});
|
|
@@ -411,15 +390,15 @@ function We(e = 500) {
|
|
|
411
390
|
t.debouncer !== null && window.clearTimeout(t.debouncer), t.debouncer = window.setTimeout(() => s(...a), t.timeout);
|
|
412
391
|
}
|
|
413
392
|
return {
|
|
414
|
-
...
|
|
393
|
+
...me(t),
|
|
415
394
|
debounce: n
|
|
416
395
|
};
|
|
417
396
|
}
|
|
418
397
|
export {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
398
|
+
Ne as copy,
|
|
399
|
+
$e as createEndpoint,
|
|
400
|
+
ae as getDefaultHeaders,
|
|
401
|
+
He as requestTypes,
|
|
402
|
+
Ce as useApi,
|
|
403
|
+
Ue as useDebouncer
|
|
425
404
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(p
|
|
1
|
+
(function(p,$){typeof exports=="object"&&typeof module<"u"?$(exports,require("@citruslime/utils"),require("vue")):typeof define=="function"&&define.amd?define(["exports","@citruslime/utils","vue"],$):(p=typeof globalThis<"u"?globalThis:p||self,$(p.CitrusLimeVueUtils={},p.CLUtils,p.Vue))})(this,function(p,$,s){"use strict";const ie=["GET","POST","PUT","DELETE"];function ae(e,t,n=null,u=null){return{url:e,type:t,headers:n??I,hasBody:se(t,u)}}function I(){return{accept:"application/json","content-type":"application/json"}}function se(e,t){return!!(t===null&&(e==="PUT"||e==="POST")||t)}function Q(e){return s.getCurrentScope()?(s.onScopeDispose(e),!0):!1}function L(){const e=new Set,t=i=>{e.delete(i)};return{on:i=>{e.add(i);const r=()=>t(i);return Q(r),{off:r}},off:t,trigger:i=>Promise.all(Array.from(e).map(r=>r(i)))}}function O(e){return typeof e=="function"?e():s.unref(e)}const X=typeof window<"u",le=()=>{};function Y(e,t=!1,n="Timeout"){return new Promise((u,i)=>{setTimeout(t?()=>i(n):u,e)})}function ue(e,...t){return t.some(n=>n in e)}function R(...e){if(e.length!==1)return s.toRef(...e);const t=e[0];return typeof t=="function"?s.readonly(s.customRef(()=>({get:t,set:le}))):s.ref(t)}function K(e,t=!1){function n(a,{flush:l="sync",deep:m=!1,timeout:y,throwOnTimeout:v}={}){let T=null;const A=[new Promise(_=>{T=s.watch(e,D=>{a(D)!==t&&(T==null||T(),_(D))},{flush:l,deep:m,immediate:!0})})];return y!=null&&A.push(Y(y,v).then(()=>O(e)).finally(()=>T==null?void 0:T())),Promise.race(A)}function u(a,l){if(!s.isRef(a))return n(D=>D===a,l);const{flush:m="sync",deep:y=!1,timeout:v,throwOnTimeout:T}=l??{};let b=null;const _=[new Promise(D=>{b=s.watch([e,a],([S,B])=>{t!==(S===B)&&(b==null||b(),D(S))},{flush:m,deep:y,immediate:!0})})];return v!=null&&_.push(Y(v,T).then(()=>O(e)).finally(()=>(b==null||b(),O(e)))),Promise.race(_)}function i(a){return n(l=>!!l,a)}function r(a){return u(null,a)}function o(a){return u(void 0,a)}function F(a){return n(Number.isNaN,a)}function h(a,l){return n(m=>{const y=Array.from(m);return y.includes(a)||y.includes(O(a))},l)}function P(a){return E(1,a)}function E(a=1,l){let m=-1;return n(()=>(m+=1,m>=a),l)}return Array.isArray(O(e))?{toMatch:n,toContains:h,changed:P,changedTimes:E,get not(){return K(e,!t)}}:{toMatch:n,toBe:u,toBeTruthy:i,toBeNull:r,toBeNaN:F,toBeUndefined:o,changed:P,changedTimes:E,get not(){return K(e,!t)}}}function ce(e){return K(e)}function fe(e,t,n={}){const{immediate:u=!0}=n,i=s.ref(!1);let r=null;function o(){r&&(clearTimeout(r),r=null)}function F(){i.value=!1,o()}function h(...P){o(),i.value=!0,r=setTimeout(()=>{i.value=!1,r=null,e(...P)},O(t))}return u&&(i.value=!0,X&&h()),Q(F),{isPending:s.readonly(i),start:h,stop:F}}const de=X?window:void 0;var pe=Object.defineProperty,he=Object.defineProperties,ye=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,me=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable,ee=(e,t,n)=>t in e?pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c=(e,t)=>{for(var n in t||(t={}))me.call(t,n)&&ee(e,n,t[n]);if(Z)for(var n of Z(t))we.call(t,n)&&ee(e,n,t[n]);return e},U=(e,t)=>he(e,ye(t));const Te={json:"application/json",text:"text/plain"};function te(e){return e&&ue(e,"immediate","refetch","initialData","timeout","beforeFetch","afterFetch","onFetchError","fetch")}function W(e){return typeof Headers<"u"&&e instanceof Headers?Object.fromEntries([...e.entries()]):e}function Pe(e,...t){var n;const u=typeof AbortController=="function";let i={},r={immediate:!0,refetch:!1,timeout:0};const o={method:"GET",type:"text",payload:void 0};t.length>0&&(te(t[0])?r=c(c({},r),t[0]):i=t[0]),t.length>1&&te(t[1])&&(r=c(c({},r),t[1]));const{fetch:F=(n=de)==null?void 0:n.fetch,initialData:h,timeout:P}=r,E=L(),a=L(),l=L(),m=s.ref(!1),y=s.ref(!1),v=s.ref(!1),T=s.ref(null),b=s.shallowRef(null),A=s.shallowRef(null),_=s.shallowRef(h||null),D=s.computed(()=>u&&y.value);let S,B;const k=()=>{u&&(S==null||S.abort(),S=new AbortController,S.signal.onabort=()=>v.value=!0,i=U(c({},i),{signal:S.signal}))},x=f=>{y.value=f,m.value=!f};P&&(B=fe(k,P,{immediate:!1}));const J=async(f=!1)=>{var g;k(),x(!0),A.value=null,T.value=null,v.value=!1;const w={method:o.method,headers:{}};if(o.payload){const V=W(w.headers);o.payloadType&&(V["Content-Type"]=(g=Te[o.payloadType])!=null?g:o.payloadType);const G=O(o.payload);w.body=o.payloadType==="json"?JSON.stringify(G):G}let N=!1;const j={url:O(e),options:c(c({},w),i),cancel:()=>{N=!0}};if(r.beforeFetch&&Object.assign(j,await r.beforeFetch(j)),N||!F)return x(!1),Promise.resolve(null);let C=null;return B&&B.start(),new Promise((V,G)=>{var re;F(j.url,U(c(c({},w),j.options),{headers:c(c({},W(w.headers)),W((re=j.options)==null?void 0:re.headers))})).then(async d=>{if(b.value=d,T.value=d.status,C=await d[o.type](),!d.ok)throw _.value=h||null,new Error(d.statusText);return r.afterFetch&&({data:C}=await r.afterFetch({data:C,response:d})),_.value=C,E.trigger(d),V(d)}).catch(async d=>{let oe=d.message||d.name;return r.onFetchError&&({error:oe}=await r.onFetchError({data:C,error:d,response:b.value})),A.value=oe,a.trigger(d),f?G(d):V(null)}).finally(()=>{x(!1),B&&B.stop(),l.trigger(null)})})},ne=R(r.refetch);s.watch([ne,R(e)],([f])=>f&&J(),{deep:!0});const M={isFinished:m,statusCode:T,response:b,error:A,data:_,isFetching:y,canAbort:D,aborted:v,abort:k,execute:J,onFetchResponse:E.on,onFetchError:a.on,onFetchFinally:l.on,get:H("GET"),put:H("PUT"),post:H("POST"),delete:H("DELETE"),patch:H("PATCH"),head:H("HEAD"),options:H("OPTIONS"),json:q("json"),text:q("text"),blob:q("blob"),arrayBuffer:q("arrayBuffer"),formData:q("formData")};function H(f){return(g,w)=>{if(!y.value){o.method=f,o.payload=g,o.payloadType=w,s.isRef(o.payload)&&s.watch([ne,R(o.payload)],([j])=>j&&J(),{deep:!0});const N=O(o.payload);return!w&&N&&Object.getPrototypeOf(N)===Object.prototype&&!(N instanceof FormData)&&(o.payloadType="json"),U(c({},M),{then(j,C){return z().then(j,C)}})}}}function z(){return new Promise((f,g)=>{ce(m).toBe(!0).then(()=>f(M)).catch(w=>g(w))})}function q(f){return()=>{if(!y.value)return o.type=f,U(c({},M),{then(g,w){return z().then(g,w)}})}}return r.immediate&&Promise.resolve().then(()=>J()),U(c({},M),{then(f,g){return z().then(f,g)}})}function be(e,t){const n={};return Object.keys(e).forEach(i=>{n[i]=(...r)=>{const o=e[i],F=o.type;let h=`/api/${o.url}`;o.hasBody?h=$.replacePlaceholders(h,...r.splice(1)):h=$.replacePlaceholders(h,...r);const P={...I(),...o.headers()},E=Pe(h,{method:F},{immediate:!1,beforeFetch({options:l}){return l.headers={...l.headers,...P},o.hasBody&&r.length&&(l.body=JSON.stringify(r[0])),{options:l}},onFetchError(l){return l!=null&&l.response&&t(l),l}});return{...ge(P)==="application/json"?E.json():E.text()}}}),n}function ge(e){return e.accept??"*/*"}function Oe(e){return JSON.parse(JSON.stringify(e))}function Fe(e=500){const t=s.reactive({debouncer:null,timeout:e});function n(u,...i){t.debouncer!==null&&window.clearTimeout(t.debouncer),t.debouncer=window.setTimeout(()=>u(...i),t.timeout)}return{...s.toRefs(t),debounce:n}}p.copy=Oe,p.createEndpoint=ae,p.getDefaultHeaders=I,p.requestTypes=ie,p.useApi=be,p.useDebouncer=Fe,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@citruslime/vue-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Citrus-Lime Ltd",
|
|
@@ -28,13 +28,15 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "
|
|
31
|
+
"build": "run-p build-source build-types",
|
|
32
|
+
"build-source": "vite build",
|
|
33
|
+
"build-types": "vue-tsc --declaration --emitDeclarationOnly --declarationDir ./dist --project ./tsconfig.app.json --composite false"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
|
34
36
|
"@citruslime/utils": "^1.1.2-beta.0"
|
|
35
37
|
},
|
|
36
38
|
"peerDependencies": {
|
|
37
|
-
"@vueuse/core": "^
|
|
39
|
+
"@vueuse/core": "^10.1.2",
|
|
38
40
|
"vue": "^3.2.47"
|
|
39
41
|
}
|
|
40
42
|
}
|