@citruslime/vue-utils 1.2.1 → 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,102 +1,110 @@
|
|
|
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
|
-
X && ((ne = window == null ? void 0 : window.navigator) != null && ne.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
|
|
29
|
-
function E(e) {
|
|
30
|
-
return typeof e == "function" ? e() : he(e);
|
|
31
|
-
}
|
|
32
|
-
function re(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
|
-
return n((u) =>
|
|
107
|
+
return n((u) => !!u, i);
|
|
100
108
|
}
|
|
101
109
|
function r(i) {
|
|
102
110
|
return s(null, i);
|
|
@@ -104,91 +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
|
-
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) => {
|
|
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) => {
|
|
174
180
|
for (var n in t || (t = {}))
|
|
175
|
-
|
|
176
|
-
if (
|
|
177
|
-
for (var n of
|
|
178
|
-
|
|
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]);
|
|
179
185
|
return e;
|
|
180
|
-
},
|
|
181
|
-
const
|
|
186
|
+
}, N = (e, t) => Oe(e, Fe(t));
|
|
187
|
+
const je = {
|
|
182
188
|
json: "application/json",
|
|
183
189
|
text: "text/plain"
|
|
184
190
|
};
|
|
185
|
-
function
|
|
186
|
-
return e &&
|
|
191
|
+
function ne(e) {
|
|
192
|
+
return e && we(e, "immediate", "refetch", "initialData", "timeout", "beforeFetch", "afterFetch", "onFetchError", "fetch");
|
|
187
193
|
}
|
|
188
|
-
function
|
|
194
|
+
function W(e) {
|
|
189
195
|
return typeof Headers < "u" && e instanceof Headers ? Object.fromEntries([...e.entries()]) : e;
|
|
190
196
|
}
|
|
191
|
-
function
|
|
197
|
+
function De(e, ...t) {
|
|
192
198
|
var n;
|
|
193
199
|
const s = typeof AbortController == "function";
|
|
194
200
|
let a = {}, r = { immediate: !0, refetch: !1, timeout: 0 };
|
|
@@ -197,191 +203,163 @@ function Ce(e, ...t) {
|
|
|
197
203
|
type: "text",
|
|
198
204
|
payload: void 0
|
|
199
205
|
};
|
|
200
|
-
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]));
|
|
201
207
|
const {
|
|
202
|
-
fetch:
|
|
203
|
-
initialData:
|
|
204
|
-
timeout:
|
|
205
|
-
} = r,
|
|
206
|
-
let
|
|
207
|
-
const
|
|
208
|
-
s &&
|
|
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
|
+
}));
|
|
209
217
|
}, K = (l) => {
|
|
210
|
-
|
|
218
|
+
p.value = l, h.value = !l;
|
|
211
219
|
};
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
var
|
|
215
|
-
K(!0),
|
|
216
|
-
signal: P.signal
|
|
217
|
-
}));
|
|
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;
|
|
218
224
|
const m = {
|
|
219
225
|
method: o.method,
|
|
220
226
|
headers: {}
|
|
221
227
|
};
|
|
222
228
|
if (o.payload) {
|
|
223
|
-
const
|
|
224
|
-
o.payloadType && (
|
|
225
|
-
const
|
|
226
|
-
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;
|
|
227
233
|
}
|
|
228
|
-
let
|
|
234
|
+
let H = !1;
|
|
229
235
|
const T = {
|
|
230
|
-
url:
|
|
236
|
+
url: O(e),
|
|
231
237
|
options: f(f({}, m), a),
|
|
232
238
|
cancel: () => {
|
|
233
|
-
|
|
239
|
+
H = !0;
|
|
234
240
|
}
|
|
235
241
|
};
|
|
236
|
-
if (r.beforeFetch && Object.assign(T, await r.beforeFetch(T)),
|
|
242
|
+
if (r.beforeFetch && Object.assign(T, await r.beforeFetch(T)), H || !b)
|
|
237
243
|
return K(!1), Promise.resolve(null);
|
|
238
|
-
let
|
|
239
|
-
return S && S.start(), new Promise((
|
|
240
|
-
var
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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);
|
|
247
256
|
}).catch(async (c) => {
|
|
248
|
-
let
|
|
249
|
-
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);
|
|
250
259
|
}).finally(() => {
|
|
251
260
|
K(!1), S && S.stop(), u.trigger(null);
|
|
252
261
|
});
|
|
253
262
|
});
|
|
254
|
-
},
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
263
|
+
}, z = R(r.refetch);
|
|
264
|
+
I(
|
|
265
|
+
[
|
|
266
|
+
z,
|
|
267
|
+
R(e)
|
|
268
|
+
],
|
|
269
|
+
([l]) => l && U(),
|
|
270
|
+
{ deep: !0 }
|
|
271
|
+
);
|
|
259
272
|
const x = {
|
|
260
273
|
isFinished: h,
|
|
261
|
-
statusCode:
|
|
262
|
-
response:
|
|
263
|
-
error:
|
|
264
|
-
data:
|
|
265
|
-
isFetching:
|
|
266
|
-
canAbort:
|
|
274
|
+
statusCode: y,
|
|
275
|
+
response: w,
|
|
276
|
+
error: D,
|
|
277
|
+
data: E,
|
|
278
|
+
isFetching: p,
|
|
279
|
+
canAbort: _,
|
|
267
280
|
aborted: F,
|
|
268
|
-
abort:
|
|
269
|
-
execute:
|
|
270
|
-
onFetchResponse:
|
|
281
|
+
abort: M,
|
|
282
|
+
execute: U,
|
|
283
|
+
onFetchResponse: g.on,
|
|
271
284
|
onFetchError: i.on,
|
|
272
285
|
onFetchFinally: u.on,
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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")
|
|
285
300
|
};
|
|
286
|
-
function
|
|
287
|
-
return (
|
|
288
|
-
if (!
|
|
289
|
-
o.method = l, o.payload =
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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);
|
|
297
316
|
}
|
|
298
317
|
});
|
|
299
318
|
}
|
|
300
319
|
};
|
|
301
320
|
}
|
|
302
|
-
function
|
|
303
|
-
return new Promise((l,
|
|
304
|
-
|
|
321
|
+
function V() {
|
|
322
|
+
return new Promise((l, P) => {
|
|
323
|
+
Pe(h).toBe(!0).then(() => l(x)).catch((m) => P(m));
|
|
305
324
|
});
|
|
306
325
|
}
|
|
307
|
-
function
|
|
326
|
+
function C(l) {
|
|
308
327
|
return () => {
|
|
309
|
-
if (!
|
|
310
|
-
return o.type = l,
|
|
311
|
-
then(
|
|
312
|
-
return
|
|
328
|
+
if (!p.value)
|
|
329
|
+
return o.type = l, N(f({}, x), {
|
|
330
|
+
then(P, m) {
|
|
331
|
+
return V().then(P, m);
|
|
313
332
|
}
|
|
314
333
|
});
|
|
315
334
|
};
|
|
316
335
|
}
|
|
317
|
-
return r.immediate &&
|
|
318
|
-
then(l,
|
|
319
|
-
return
|
|
336
|
+
return r.immediate && Promise.resolve().then(() => U()), N(f({}, x), {
|
|
337
|
+
then(l, P) {
|
|
338
|
+
return V().then(l, P);
|
|
320
339
|
}
|
|
321
340
|
});
|
|
322
341
|
}
|
|
323
|
-
|
|
324
|
-
(function(e) {
|
|
325
|
-
e.UP = "UP", e.RIGHT = "RIGHT", e.DOWN = "DOWN", e.LEFT = "LEFT", e.NONE = "NONE";
|
|
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
|
-
for (var n in t || (t = {}))
|
|
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
|
-
return e;
|
|
334
|
-
};
|
|
335
|
-
const xe = {
|
|
336
|
-
easeInSine: [0.12, 0, 0.39, 0],
|
|
337
|
-
easeOutSine: [0.61, 1, 0.88, 1],
|
|
338
|
-
easeInOutSine: [0.37, 0, 0.63, 1],
|
|
339
|
-
easeInQuad: [0.11, 0, 0.5, 0],
|
|
340
|
-
easeOutQuad: [0.5, 1, 0.89, 1],
|
|
341
|
-
easeInOutQuad: [0.45, 0, 0.55, 1],
|
|
342
|
-
easeInCubic: [0.32, 0, 0.67, 0],
|
|
343
|
-
easeOutCubic: [0.33, 1, 0.68, 1],
|
|
344
|
-
easeInOutCubic: [0.65, 0, 0.35, 1],
|
|
345
|
-
easeInQuart: [0.5, 0, 0.75, 0],
|
|
346
|
-
easeOutQuart: [0.25, 1, 0.5, 1],
|
|
347
|
-
easeInOutQuart: [0.76, 0, 0.24, 1],
|
|
348
|
-
easeInQuint: [0.64, 0, 0.78, 0],
|
|
349
|
-
easeOutQuint: [0.22, 1, 0.36, 1],
|
|
350
|
-
easeInOutQuint: [0.83, 0, 0.17, 1],
|
|
351
|
-
easeInExpo: [0.7, 0, 0.84, 0],
|
|
352
|
-
easeOutExpo: [0.16, 1, 0.3, 1],
|
|
353
|
-
easeInOutExpo: [0.87, 0, 0.13, 1],
|
|
354
|
-
easeInCirc: [0.55, 0, 1, 0.45],
|
|
355
|
-
easeOutCirc: [0, 0.55, 0.45, 1],
|
|
356
|
-
easeInOutCirc: [0.85, 0, 0.15, 1],
|
|
357
|
-
easeInBack: [0.36, 0, 0.66, -0.56],
|
|
358
|
-
easeOutBack: [0.34, 1.56, 0.64, 1],
|
|
359
|
-
easeInOutBack: [0.68, -0.6, 0.32, 1.6]
|
|
360
|
-
};
|
|
361
|
-
$e({
|
|
362
|
-
linear: be
|
|
363
|
-
}, xe);
|
|
364
|
-
function Le(e, t) {
|
|
342
|
+
function Ce(e, t) {
|
|
365
343
|
const n = {};
|
|
366
344
|
return Object.keys(e).forEach((a) => {
|
|
367
345
|
n[a] = (...r) => {
|
|
368
|
-
const o = e[a],
|
|
369
|
-
let
|
|
370
|
-
o.hasBody ?
|
|
371
|
-
const
|
|
372
|
-
...
|
|
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(),
|
|
373
351
|
...o.headers()
|
|
374
|
-
},
|
|
375
|
-
|
|
352
|
+
}, g = De(
|
|
353
|
+
d,
|
|
376
354
|
{
|
|
377
|
-
method:
|
|
355
|
+
method: b
|
|
378
356
|
},
|
|
379
357
|
{
|
|
380
358
|
immediate: !1,
|
|
381
359
|
beforeFetch({ options: u }) {
|
|
382
360
|
return u.headers = {
|
|
383
361
|
...u.headers,
|
|
384
|
-
...
|
|
362
|
+
...v
|
|
385
363
|
}, o.hasBody && r.length && (u.body = JSON.stringify(r[0])), {
|
|
386
364
|
options: u
|
|
387
365
|
};
|
|
@@ -392,19 +370,19 @@ function Le(e, t) {
|
|
|
392
370
|
}
|
|
393
371
|
);
|
|
394
372
|
return {
|
|
395
|
-
...
|
|
373
|
+
...Se(v) === "application/json" ? g.json() : g.text()
|
|
396
374
|
};
|
|
397
375
|
};
|
|
398
376
|
}), n;
|
|
399
377
|
}
|
|
400
|
-
function
|
|
378
|
+
function Se(e) {
|
|
401
379
|
return e.accept ?? "*/*";
|
|
402
380
|
}
|
|
403
|
-
function
|
|
381
|
+
function Ne(e) {
|
|
404
382
|
return JSON.parse(JSON.stringify(e));
|
|
405
383
|
}
|
|
406
|
-
function
|
|
407
|
-
const t =
|
|
384
|
+
function Ue(e = 500) {
|
|
385
|
+
const t = he({
|
|
408
386
|
debouncer: null,
|
|
409
387
|
timeout: e
|
|
410
388
|
});
|
|
@@ -412,15 +390,15 @@ function We(e = 500) {
|
|
|
412
390
|
t.debouncer !== null && window.clearTimeout(t.debouncer), t.debouncer = window.setTimeout(() => s(...a), t.timeout);
|
|
413
391
|
}
|
|
414
392
|
return {
|
|
415
|
-
...
|
|
393
|
+
...me(t),
|
|
416
394
|
debounce: n
|
|
417
395
|
};
|
|
418
396
|
}
|
|
419
397
|
export {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
398
|
+
Ne as copy,
|
|
399
|
+
$e as createEndpoint,
|
|
400
|
+
ae as getDefaultHeaders,
|
|
401
|
+
He as requestTypes,
|
|
402
|
+
Ce as useApi,
|
|
403
|
+
Ue as useDebouncer
|
|
426
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",
|
|
@@ -23,17 +23,20 @@
|
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
25
|
"import": "./dist/citrus-lime-vue-utils.es.js",
|
|
26
|
-
"require": "./dist/citrus-lime-vue-utils.umd.js"
|
|
26
|
+
"require": "./dist/citrus-lime-vue-utils.umd.js",
|
|
27
|
+
"types": "./dist/main.d.ts"
|
|
27
28
|
}
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
30
|
-
"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"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"@citruslime/utils": "^1.1.
|
|
36
|
+
"@citruslime/utils": "^1.1.2-beta.0"
|
|
34
37
|
},
|
|
35
38
|
"peerDependencies": {
|
|
36
|
-
"@vueuse/core": "^
|
|
39
|
+
"@vueuse/core": "^10.1.2",
|
|
37
40
|
"vue": "^3.2.47"
|
|
38
41
|
}
|
|
39
42
|
}
|