web-core-tcm 0.0.51 → 0.0.53
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/node_modules/@alova/shared/dist/alova-shared.esm.js +249 -101
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/clone.js +35 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/embed.js +109 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/enum.js +16 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/extension.js +9 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/file.js +9 -10
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/index.js +28 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/scalar.js +48 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/service.js +8 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/symbols.js +49 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/types.js +1 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/equals.js +127 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/extensions.js +86 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/fields.js +11 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/from-binary.js +60 -56
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/from-json.js +434 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/index.js +49 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/merge.js +33 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/reflect/error.js +12 -3
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/reflect/guard.js +14 -10
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/reflect/names.js +32 -12
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/reflect/nested-types.js +42 -6
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/reflect/reflect.js +58 -50
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/reflect/scalar.js +26 -4
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/registry.js +130 -99
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/to-json.js +279 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/types.js +1 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wire/base64-encoding.js +48 -27
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wire/index.js +24 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wire/size-delimited.js +123 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wire/text-encoding.js +9 -5
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/any.js +40 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/duration.js +18 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/any_pb.js +7 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/api_pb.js +11 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.js +19 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/cpp_features_pb.js +18 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/descriptor_pb.js +134 -60
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/duration_pb.js +7 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/empty_pb.js +7 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/field_mask_pb.js +7 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/go_features_pb.js +25 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/java_features_pb.js +26 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/source_context_pb.js +7 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/struct_pb.js +17 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/timestamp_pb.js +7 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/type_pb.js +35 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/wrappers_pb.js +15 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/index.js +180 -0
- package/dist/node_modules/@bufbuild/protobuf/dist/esm/wkt/timestamp.js +29 -0
- package/dist/node_modules/alova/dist/adapter/fetch.esm.js +10 -10
- package/dist/node_modules/alova/dist/alova.esm.js +263 -211
- package/dist/node_modules/alova/dist/clienthook/index.esm.js +2110 -70
- package/dist/node_modules/builder-pattern/dist/index.js +25 -13
- package/dist/node_modules/pinyin/lib/esm/pinyin.js +2 -2
- package/dist/node_modules/punycode/punycode.es6.js +17 -17
- package/dist/src/api/algorithm/alova/implement/comprehensiveAlgorithm.js +4 -7
- package/dist/src/api/algorithm/alova/implement/index.js +12 -0
- package/dist/src/api/algorithm/alova/implement/inquiriesAlgorithm.js +4 -7
- package/dist/src/api/algorithm/alova/implement/inspectionsAlgorithm.js +7 -10
- package/dist/src/api/algorithm/alova/implement/lisemsAlgorithm.js +6 -9
- package/dist/src/api/algorithm/alova/implement/pulsationsAlgorithm.js +7 -10
- package/dist/src/api/algorithm/alova/index.js +11 -15
- package/dist/src/api/algorithm/comprehensiveAlgorithm.js +5 -6
- package/dist/src/api/authorization/alova/globals.js +1 -0
- package/dist/src/api/authorization/alova/implement/index.js +4 -0
- package/dist/src/api/authorization/alova/index.js +10 -8
- package/dist/src/api/check/alova/globals.js +1 -0
- package/dist/src/api/check/alova/implement/index.js +5 -0
- package/dist/src/api/check/alova/index.js +5 -6
- package/dist/src/api/check/check.js +2 -2
- package/dist/src/api/config/index.d.ts +1 -1
- package/dist/src/api/config/index.js +2 -2
- package/dist/src/api/core/index.js +9 -0
- package/dist/src/api/device/device.d.ts +4 -5
- package/dist/src/api/device/device.js +20 -29
- package/dist/src/api/doctor/alova/globals.js +1 -0
- package/dist/src/api/doctor/alova/implement/index.js +4 -0
- package/dist/src/api/doctor/alova/index.js +10 -9
- package/dist/src/api/index.d.ts +12 -11
- package/dist/src/api/index.js +28 -0
- package/dist/src/api/metric/alova/implement/index.js +4 -0
- package/dist/src/api/metric/alova/index.js +1 -0
- package/dist/src/api/metric/index.js +5 -4
- package/dist/src/api/oauth/alova/globals.js +1 -0
- package/dist/src/api/oauth/alova/implement/index.js +4 -0
- package/dist/src/api/oauth/alova/index.js +13 -11
- package/dist/src/api/outpatient/alova/globals.js +1 -0
- package/dist/src/api/outpatient/alova/implement/index.js +4 -0
- package/dist/src/api/outpatient/alova/index.js +5 -5
- package/dist/src/api/patient/alova/globals.js +1 -0
- package/dist/src/api/patient/alova/implement/index.js +16 -0
- package/dist/src/api/patient/alova/index.js +9 -12
- package/dist/src/api/patient/meta.js +1 -0
- package/dist/src/api/prescription/alova/globals.js +1 -0
- package/dist/src/api/prescription/alova/implement/index.js +6 -0
- package/dist/src/api/prescription/alova/index.js +8 -7
- package/dist/src/api/scientist/alova/globals.js +1 -0
- package/dist/src/api/scientist/alova/implement/index.js +4 -0
- package/dist/src/api/scientist/alova/index.js +5 -5
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +34 -32
- package/dist/src/proto/index.js +10 -0
- package/dist/src/proto/types/Images_pb.js +7 -6
- package/dist/src/proto/types/WaveMap_pb.js +4 -3
- package/dist/src/util/helper.js +38 -2
- package/dist/src/util/string.js +47 -5
- package/package.json +1 -1
- package/dist/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js +0 -556
- package/dist/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js +0 -36
- package/dist/node_modules/@vue/shared/dist/shared.esm-bundler.js +0 -26
- package/dist/node_modules/quasar/src/composables/use-quasar/use-quasar.js +0 -8
- package/dist/node_modules/quasar/src/utils/private.symbols/symbols.js +0 -4
|
@@ -1,89 +1,2129 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { isPlainObject as oe, instanceOf as k, trueValue as D, falseValue as w, newInstance as F, PromiseCls as Ut, pushItem as at, isFn as Y, noop as Z, len as N, forEach as X, undefinedValue as p, splice as xt, $self as se, filterItem as Dt, nullValue as Wt, isNumber as At, clearTimeoutTimer as Bs, setTimeoutFn as jt, createAssert as _t, injectReferingObject as Ks, mapItem as vt, FrameworkReadableState as Le, FrameworkState as Bn, objAssign as Ge, includes as Tt, ObjectCls as Me, deleteAttr as pn, objectKeys as yt, getHandlerMethod as es, getContext as He, getMethodInternalKey as Kt, promiseResolve as Ot, sloughConfig as re, omit as Ns, promiseThen as mt, buildNamespacedCacheKey as qs, getTime as ns, createEventManager as qt, createSyncOnceRunner as zs, isArray as lt, objectValues as Ie, usePromise as Ce, getLocalCacheConfigParam as Gs, MEMORY as Hs, promiseCatch as ye, createAsyncQueue as $s, promiseFinally as ue, promiseAll as Ws, decorateEvent as Re, isObject as bt, walkObject as Nt, valueObject as ss, uuid as an, defineProperty as Ze, globalToString as ks, isString as Pe, RegExpCls as rs, regexpTest as fe, shift as Kn, delayWithBackoff as os, getConfig as Ve, AlovaError as $e, getOptions as Ys, JSONParse as Js, promiseReject as as, buildCompletedURL as Xs, isSpecialRequestBody as Zs, JSONStringify as tr } from "../../../@alova/shared/dist/alova-shared.esm.js";
|
|
2
|
+
import { Method as me, queryCache as cn, promiseStatesHook as Rt, globalConfigMap as cs, setCache as we, invalidateCache as er, hitCacheBySource as nr } from "../alova.esm.js";
|
|
3
|
+
const Oe = {
|
|
3
4
|
authRole: null
|
|
4
|
-
},
|
|
5
|
+
}, de = {
|
|
5
6
|
authRole: "login"
|
|
6
|
-
},
|
|
7
|
+
}, is = {
|
|
7
8
|
authRole: "logout"
|
|
8
|
-
},
|
|
9
|
+
}, be = {
|
|
9
10
|
authRole: "refreshToken"
|
|
10
|
-
},
|
|
11
|
-
if (
|
|
12
|
-
for (const
|
|
13
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
method:
|
|
23
|
-
resolve:
|
|
24
|
-
});
|
|
25
|
-
}),
|
|
26
|
-
if (
|
|
27
|
-
return (
|
|
28
|
-
},
|
|
29
|
-
const
|
|
30
|
-
let
|
|
31
|
-
if (
|
|
11
|
+
}, gt = ({ meta: e }, t) => {
|
|
12
|
+
if (oe(e)) {
|
|
13
|
+
for (const n in e)
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(e, n)) {
|
|
15
|
+
const r = t[n];
|
|
16
|
+
if (k(r, RegExp) ? r.test(e[n]) : e[n] === r)
|
|
17
|
+
return D;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return w;
|
|
21
|
+
}, mn = (e, t) => F(Ut, (n) => {
|
|
22
|
+
at(t, {
|
|
23
|
+
method: e,
|
|
24
|
+
resolve: n
|
|
25
|
+
});
|
|
26
|
+
}), je = (e, t, n, r) => {
|
|
27
|
+
if (gt(e, t?.metaMatches || n))
|
|
28
|
+
return (Y(t) ? t : oe(t) && Y(t.handler) ? t.handler : Z)(r, e);
|
|
29
|
+
}, ln = async (e, t, n, r, s, o) => {
|
|
30
|
+
const c = N(r) >= 2;
|
|
31
|
+
let l = s?.isExpired(...r);
|
|
32
|
+
if (k(l, Ut) && (l = await l), l)
|
|
32
33
|
try {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
let v = D;
|
|
35
|
+
if (c && o && (v = w, await mn(e, t)), v && (n(D), await s?.handler(...r), n(w), X(t, ({ resolve: d }) => d())), c) {
|
|
36
|
+
const { config: d } = e, a = d.transform;
|
|
37
|
+
d.transform = p;
|
|
38
|
+
const i = await e;
|
|
39
|
+
return d.transform = a, i;
|
|
38
40
|
}
|
|
39
41
|
} finally {
|
|
40
|
-
|
|
42
|
+
n(w), xt(t, 0, N(t));
|
|
41
43
|
}
|
|
42
|
-
},
|
|
43
|
-
let
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
else if (
|
|
47
|
-
const { onSuccess:
|
|
48
|
-
|
|
44
|
+
}, ls = (e) => {
|
|
45
|
+
let t = p, n = p, r = p;
|
|
46
|
+
if (Y(e))
|
|
47
|
+
t = e;
|
|
48
|
+
else if (oe(e)) {
|
|
49
|
+
const { onSuccess: s, onError: o, onComplete: c } = e;
|
|
50
|
+
t = Y(s) ? s : t, n = Y(o) ? o : n, r = Y(c) ? c : r;
|
|
49
51
|
}
|
|
50
52
|
return {
|
|
51
|
-
onSuccess:
|
|
52
|
-
onError:
|
|
53
|
-
onComplete:
|
|
53
|
+
onSuccess: t,
|
|
54
|
+
onError: n,
|
|
55
|
+
onComplete: r
|
|
54
56
|
};
|
|
55
|
-
},
|
|
56
|
-
let
|
|
57
|
-
const
|
|
57
|
+
}, Wr = ({ visitorMeta: e, login: t, logout: n, refreshToken: r, assignToken: s = Z }) => {
|
|
58
|
+
let o = w;
|
|
59
|
+
const c = [];
|
|
58
60
|
return {
|
|
59
|
-
waitingList:
|
|
60
|
-
onAuthRequired: (
|
|
61
|
-
const
|
|
62
|
-
return !
|
|
63
|
-
|
|
64
|
-
}, [
|
|
65
|
-
},
|
|
66
|
-
onResponseRefreshToken: (
|
|
67
|
-
const
|
|
61
|
+
waitingList: c,
|
|
62
|
+
onAuthRequired: (d) => async (a) => {
|
|
63
|
+
const i = gt(a, e || Oe), f = gt(a, t?.metaMatches || de);
|
|
64
|
+
return !i && !f && !gt(a, r?.metaMatches || be) && (o && await mn(a, c), await ln(a, c, (u) => {
|
|
65
|
+
o = u;
|
|
66
|
+
}, [a], r)), !i && !f && await s(a), d?.(a);
|
|
67
|
+
},
|
|
68
|
+
onResponseRefreshToken: (d) => {
|
|
69
|
+
const a = ls(d);
|
|
68
70
|
return {
|
|
69
|
-
...
|
|
70
|
-
onSuccess: async (
|
|
71
|
+
...a,
|
|
72
|
+
onSuccess: async (i, f) => (await je(f, t, de, i), await je(f, n, is, i), (a.onSuccess || se)(i, f))
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}, kr = ({ visitorMeta: e, login: t, logout: n, refreshTokenOnSuccess: r, refreshTokenOnError: s, assignToken: o = Z }) => {
|
|
77
|
+
let c = w;
|
|
78
|
+
const l = [];
|
|
79
|
+
return {
|
|
80
|
+
waitingList: l,
|
|
81
|
+
onAuthRequired: (a) => async (i) => {
|
|
82
|
+
const f = gt(i, e || Oe), u = gt(i, t?.metaMatches || de);
|
|
83
|
+
return !f && !u && !gt(i, r?.metaMatches || be) && !gt(i, s?.metaMatches || be) && c && await mn(i, l), !f && !u && await o(i), a?.(i);
|
|
84
|
+
},
|
|
85
|
+
onResponseRefreshToken: (a) => {
|
|
86
|
+
const i = ls(a);
|
|
87
|
+
return {
|
|
88
|
+
...i,
|
|
89
|
+
onSuccess: async (f, u) => {
|
|
90
|
+
if (!gt(u, e || Oe) && !gt(u, t?.metaMatches || de) && !gt(u, r?.metaMatches || be)) {
|
|
91
|
+
const O = await ln(u, l, (I) => {
|
|
92
|
+
c = I;
|
|
93
|
+
}, [f, u], r, c);
|
|
94
|
+
if (O)
|
|
95
|
+
return O;
|
|
96
|
+
}
|
|
97
|
+
return await je(u, t, de, f), await je(u, n, is, f), (i.onSuccess || se)(f, u);
|
|
98
|
+
},
|
|
99
|
+
onError: async (f, u) => {
|
|
100
|
+
if (!gt(u, e || Oe) && !gt(u, t?.metaMatches || de) && !gt(u, s?.metaMatches || be)) {
|
|
101
|
+
const O = await ln(u, l, (I) => {
|
|
102
|
+
c = I;
|
|
103
|
+
}, [f, u], s, c);
|
|
104
|
+
if (O)
|
|
105
|
+
return O;
|
|
106
|
+
}
|
|
107
|
+
return (i.onError || Z)(f, u);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}, Nn = (e) => {
|
|
113
|
+
throw e;
|
|
114
|
+
};
|
|
115
|
+
function sr(e = Z) {
|
|
116
|
+
let t = [];
|
|
117
|
+
return [(o) => (t.includes(o) || (t.push(o), e(t)), () => {
|
|
118
|
+
t = Dt(t, (c) => c !== o), e(t);
|
|
119
|
+
}), (...o) => {
|
|
120
|
+
if (t.length > 0)
|
|
121
|
+
return X(t, (c) => c(...o));
|
|
122
|
+
}, () => {
|
|
123
|
+
t = [], e(t);
|
|
124
|
+
}];
|
|
125
|
+
}
|
|
126
|
+
const rr = (e, t) => {
|
|
127
|
+
let n = Wt;
|
|
128
|
+
return function(...s) {
|
|
129
|
+
const o = e.bind(this, ...s), c = At(t) ? t : t(...s);
|
|
130
|
+
n && Bs(n), c > 0 ? n = jt(o, c) : o();
|
|
131
|
+
};
|
|
132
|
+
}, qn = (e, t = []) => {
|
|
133
|
+
const n = Y(e) ? e(...t) : e;
|
|
134
|
+
return _t("scene")(k(n, me), "hook handler must be a method instance or a function that returns method instance"), n;
|
|
135
|
+
}, or = (e, t) => {
|
|
136
|
+
const n = {};
|
|
137
|
+
for (const r in e)
|
|
138
|
+
n[r] = t(e[r], r, e);
|
|
139
|
+
return n;
|
|
140
|
+
};
|
|
141
|
+
var It;
|
|
142
|
+
(function(e) {
|
|
143
|
+
e[e.USE_REQUEST = 1] = "USE_REQUEST", e[e.USE_WATCHER = 2] = "USE_WATCHER", e[e.USE_FETCHER = 3] = "USE_FETCHER";
|
|
144
|
+
})(It || (It = {}));
|
|
145
|
+
function Ft(e, t = {
|
|
146
|
+
trackedKeys: {},
|
|
147
|
+
bindError: w,
|
|
148
|
+
initialRequest: w,
|
|
149
|
+
...Ks()
|
|
150
|
+
}) {
|
|
151
|
+
const n = (a) => e.ref ? e.ref(a) : { current: a };
|
|
152
|
+
t = n(t).current;
|
|
153
|
+
const r = (a) => (e.export || se)(a, t), s = (a) => {
|
|
154
|
+
if (!Y(e.memorize))
|
|
155
|
+
return a;
|
|
156
|
+
const i = e.memorize(a);
|
|
157
|
+
return i.memorized = D, i;
|
|
158
|
+
}, { dehydrate: o } = e, c = (a, i, f) => a !== o(i, f, t) && t.trackedKeys[f] && e.update(a, i, f, t), l = (a) => vt(a, (i) => k(i, Le) ? i.e : i), v = [], d = {};
|
|
159
|
+
return {
|
|
160
|
+
create: (a, i) => (at(v, i), F(Bn, e.create(a, i, t), i, (f) => o(f, i, t), r, (f, u) => c(u, f, i))),
|
|
161
|
+
computed: (a, i, f) => (X(i, (u) => {
|
|
162
|
+
u.k && (d[u.k] = D);
|
|
163
|
+
}), F(Le, e.computed(a, l(i), f, t), f, (u) => o(u, f, t), r)),
|
|
164
|
+
effectRequest: (a) => e.effectRequest(a, t),
|
|
165
|
+
ref: n,
|
|
166
|
+
watch: (a, i) => e.watch(l(a), i, t),
|
|
167
|
+
onMounted: (a) => e.onMounted(a, t),
|
|
168
|
+
onUnmounted: (a) => e.onUnmounted(a, t),
|
|
169
|
+
memorize: s,
|
|
170
|
+
/**
|
|
171
|
+
* refering object that sharing some value with this object.
|
|
172
|
+
*/
|
|
173
|
+
__referingObj: t,
|
|
174
|
+
/**
|
|
175
|
+
* expose provider for specified use hook.
|
|
176
|
+
* @param object object that contains state proxy, framework state, operating function and event binder.
|
|
177
|
+
* @returns provider component.
|
|
178
|
+
*/
|
|
179
|
+
exposeProvider: (a) => {
|
|
180
|
+
const i = {}, f = {}, u = [];
|
|
181
|
+
for (const b in a) {
|
|
182
|
+
const _ = a[b];
|
|
183
|
+
if (Y(_) && !t.trackedKeys[b])
|
|
184
|
+
i[b] = b.startsWith("on") ? (...q) => (_(...q), Q) : _.memorized ? _ : s(_);
|
|
185
|
+
else {
|
|
186
|
+
!Tt(["uploading", "downloading"], b) && !b.startsWith("__") && at(u, b);
|
|
187
|
+
const q = k(_, Le);
|
|
188
|
+
q && (f[b] = _.s), Me.defineProperty(i, b, {
|
|
189
|
+
get: () => (t.trackedKeys[b] = D, q ? _.e : _),
|
|
190
|
+
// set need to set an function,
|
|
191
|
+
// otherwise it will throw `TypeError: Cannot set property __referingObj of #<Object> which has only a getter` when setting value
|
|
192
|
+
set: Z,
|
|
193
|
+
enumerable: D,
|
|
194
|
+
configurable: D
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const { update: O, __proxyState: I } = i;
|
|
199
|
+
t.trackedKeys = {
|
|
200
|
+
...d
|
|
201
|
+
}, t.bindError = w;
|
|
202
|
+
const { then: g } = i, H = {
|
|
203
|
+
// expose referingObject automatically.
|
|
204
|
+
__referingObj: t,
|
|
205
|
+
// the new updating function that can update the new states and nested hook states.
|
|
206
|
+
update: s((b) => {
|
|
207
|
+
yt(b).forEach((_) => {
|
|
208
|
+
Tt(v, _) ? c(b[_], f[_], _) : _ in i && Y(O) && O({
|
|
209
|
+
[_]: b[_]
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
}),
|
|
213
|
+
__proxyState: s((b) => Tt(v, b) && k(a[b], Le) ? (t.trackedKeys[b] = D, a[b]) : I(b)),
|
|
214
|
+
/**
|
|
215
|
+
* send and wait for responding with `await`
|
|
216
|
+
* this is always used in `nuxt3` and suspense in vue3
|
|
217
|
+
* @example
|
|
218
|
+
* ```js
|
|
219
|
+
* const { loading, data, error } = await useRequest(...);
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
then(b, _) {
|
|
223
|
+
X(u, (q) => {
|
|
224
|
+
t.trackedKeys[q] = D;
|
|
225
|
+
});
|
|
226
|
+
const V = () => {
|
|
227
|
+
pn(Q, "then"), b(Q);
|
|
228
|
+
};
|
|
229
|
+
Y(g) ? g(V, _) : V();
|
|
230
|
+
}
|
|
231
|
+
}, Q = Ge(i, H);
|
|
232
|
+
return Q;
|
|
233
|
+
},
|
|
234
|
+
/**
|
|
235
|
+
* transform state proxies to object.
|
|
236
|
+
* @param states proxy array of framework states
|
|
237
|
+
* @param filterKey filter key of state proxy
|
|
238
|
+
* @returns an object that contains the states of target form
|
|
239
|
+
*/
|
|
240
|
+
objectify: (a, i) => a.reduce((f, u) => (f[u.k] = i ? u[i] : u, f), {}),
|
|
241
|
+
transformState2Proxy: (a, i) => F(Bn, a, i, (f) => o(f, i, t), r, (f, u) => c(u, f, i))
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const ar = _t(""), cr = _t("useRequest"), ds = _t("useWatcher"), us = _t("useFetcher"), fs = (e) => ({
|
|
245
|
+
[It.USE_REQUEST]: cr,
|
|
246
|
+
[It.USE_WATCHER]: ds,
|
|
247
|
+
[It.USE_FETCHER]: us
|
|
248
|
+
})[e], vs = (e, t) => e(k(t, me), "expected a method instance."), te = "success", ee = "error", Gt = "complete";
|
|
249
|
+
var ir = (e, t, n, r) => ({
|
|
250
|
+
/** The method instance of the last request */
|
|
251
|
+
m: p,
|
|
252
|
+
/** sent method keys */
|
|
253
|
+
rf: {},
|
|
254
|
+
/** frontStates */
|
|
255
|
+
fs: {},
|
|
256
|
+
/** eventManager */
|
|
257
|
+
em: n,
|
|
258
|
+
/** hookType, useRequest=1, useWatcher=2, useFetcher=3 */
|
|
259
|
+
ht: e,
|
|
260
|
+
/** hook config */
|
|
261
|
+
c: t,
|
|
262
|
+
/** referingObject */
|
|
263
|
+
ro: r,
|
|
264
|
+
/** merged states */
|
|
265
|
+
ms: {}
|
|
266
|
+
});
|
|
267
|
+
class wt {
|
|
268
|
+
constructor(t, n) {
|
|
269
|
+
this.method = t, this.args = n;
|
|
270
|
+
}
|
|
271
|
+
clone() {
|
|
272
|
+
return { ...this };
|
|
273
|
+
}
|
|
274
|
+
static spawn(t, n) {
|
|
275
|
+
return F(wt, t, n);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
class hs extends wt {
|
|
279
|
+
constructor(t, n, r) {
|
|
280
|
+
super(t.method, t.args), this.data = n, this.fromCache = r;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
class En extends wt {
|
|
284
|
+
constructor(t, n) {
|
|
285
|
+
super(t.method, t.args), this.error = n;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
class dn extends wt {
|
|
289
|
+
constructor(t, n, r, s, o) {
|
|
290
|
+
super(t.method, t.args), this.status = n, this.data = r, this.fromCache = n === "error" ? !1 : s, this.error = o;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
class ps {
|
|
294
|
+
constructor(t, n, r) {
|
|
295
|
+
this.behavior = t, this.method = n, this.silentMethod = r;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
class We extends ps {
|
|
299
|
+
constructor(t, n, r, s, o) {
|
|
300
|
+
super(t, n, r), this.queueName = s, this.retryTimes = o;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
class lr extends We {
|
|
304
|
+
constructor(t, n, r, s, o, c, l) {
|
|
305
|
+
super(t, n, r, s, o), this.data = c, this.vDataResponse = l;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
class dr extends We {
|
|
309
|
+
constructor(t, n, r, s, o, c, l) {
|
|
310
|
+
super(t, n, r, s, o), this.error = c, this.retryDelay = l;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
class ur extends We {
|
|
314
|
+
constructor(t, n, r, s, o, c) {
|
|
315
|
+
super(t, n, r, s, o), this.error = c;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
class xe extends ps {
|
|
319
|
+
constructor(t, n, r, s) {
|
|
320
|
+
super(t, n, r), this.args = s;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
class fr extends xe {
|
|
324
|
+
constructor(t, n, r, s, o) {
|
|
325
|
+
super(t, n, r, s), this.data = o;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
class ms extends xe {
|
|
329
|
+
constructor(t, n, r, s, o) {
|
|
330
|
+
super(t, n, r, s), this.error = o;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
class vr extends xe {
|
|
334
|
+
constructor(t, n, r, s, o, c) {
|
|
335
|
+
super(t, n, r, s), this.retryTimes = o, this.retryDelay = c;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
class hr extends xe {
|
|
339
|
+
constructor(t, n, r, s, o, c, l) {
|
|
340
|
+
super(t, n, r, s), this.status = o, this.data = c, this.error = l;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
class pr extends wt {
|
|
344
|
+
constructor(t, n, r) {
|
|
345
|
+
super(t.method, t.args), this.retryTimes = n, this.retryDelay = r;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
class mr extends En {
|
|
349
|
+
constructor(t, n, r) {
|
|
350
|
+
super(t, n), this.retryTimes = r;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const Er = (e, t) => t(), Be = {}, Es = (e, t) => {
|
|
354
|
+
const n = Be[e] || {};
|
|
355
|
+
return n[t] ? Array.from(n[t]) : [];
|
|
356
|
+
}, Sr = (e, t, n) => {
|
|
357
|
+
const r = Be[e] = Be[e] || {};
|
|
358
|
+
r[t] || (r[t] = F(Set)), r[t].add(n);
|
|
359
|
+
}, gr = (e, t, n) => {
|
|
360
|
+
const r = Be[e], s = r[t];
|
|
361
|
+
r && s && (n ? s.delete(n) : s.clear(), s.size === 0 && pn(r, t));
|
|
362
|
+
};
|
|
363
|
+
function un(e, t, n = []) {
|
|
364
|
+
const r = fs(e.ht);
|
|
365
|
+
let s = es(t, r, n);
|
|
366
|
+
const { fs: o, ht: c, c: l } = e, { loading: v, data: d, error: a } = o, i = c === It.USE_FETCHER, { force: f = w, middleware: u = Er } = l, O = He(s), { id: I } = O, g = Kt(s), { abortLast: H = D } = l, Q = !e.m;
|
|
367
|
+
return e.m = s, (async () => {
|
|
368
|
+
let b = Z, _ = w, V = Ot(p), q = Z, K = Z;
|
|
369
|
+
const j = await cn(s);
|
|
370
|
+
let R = () => !!j, x = w;
|
|
371
|
+
i || (Sr(I, g, e), b = () => gr(I, g, e));
|
|
372
|
+
const T = (M) => {
|
|
373
|
+
_ = D;
|
|
374
|
+
const { force: y = f, method: C = s } = M || {}, z = re(y, [
|
|
375
|
+
F(wt, s, n)
|
|
376
|
+
]), $ = (Et) => ({ loaded: ct, total: Ct }) => {
|
|
377
|
+
o[Et].v = {
|
|
378
|
+
loaded: ct,
|
|
379
|
+
total: Ct
|
|
380
|
+
};
|
|
71
381
|
};
|
|
382
|
+
s = C, e.rf[g] = b, x || (v.v = !!z || !j);
|
|
383
|
+
const { downloading: ot, uploading: ht } = e.ro.trackedKeys;
|
|
384
|
+
return q = ot ? s.onDownload($("downloading")) : q, K = ht ? s.onUpload($("uploading")) : K, V = s.send(z), R = () => s.fromCache || w, V;
|
|
385
|
+
}, J = {
|
|
386
|
+
method: s,
|
|
387
|
+
cachedResponse: j,
|
|
388
|
+
config: l,
|
|
389
|
+
abort: () => s.abort()
|
|
390
|
+
}, et = () => c !== It.USE_WATCHER || !H || e.m === s, h = (M = D) => {
|
|
391
|
+
M && Q && (v.v = w), x = M;
|
|
392
|
+
}, m = u(i ? {
|
|
393
|
+
...J,
|
|
394
|
+
args: n,
|
|
395
|
+
fetch: (M, ...y) => (vs(r, M), un(e, M, y)),
|
|
396
|
+
proxyStates: Ns(o, "data"),
|
|
397
|
+
controlLoading: h
|
|
398
|
+
} : {
|
|
399
|
+
...J,
|
|
400
|
+
args: n,
|
|
401
|
+
send: (...M) => un(e, t, M),
|
|
402
|
+
proxyStates: o,
|
|
403
|
+
controlLoading: h
|
|
404
|
+
}, T);
|
|
405
|
+
let A = p;
|
|
406
|
+
const P = wt.spawn(s, n);
|
|
407
|
+
try {
|
|
408
|
+
const M = await m, y = (C) => (i ? e.c.updateState !== w && X(Es(I, g), (z) => {
|
|
409
|
+
z.fs.data.v = C;
|
|
410
|
+
}) : et() && (d.v = C), et() && (a.v = p, !x && (v.v = w), e.em.emit(te, F(hs, P, C, R())), e.em.emit(Gt, F(dn, P, te, C, R(), p))), C);
|
|
411
|
+
A = // When no data is returned or undefined is returned in the middleware, get the real response data
|
|
412
|
+
// Otherwise, use the returned data and no longer wait for the response promise. At this time, you also need to call the response callback.
|
|
413
|
+
M !== p ? y(M) : _ ? (
|
|
414
|
+
// There are two possibilities when middlewareCompletePromise is resolve
|
|
415
|
+
// 1. The request is normal
|
|
416
|
+
// 2. The request is incorrect, but the error is captured by the middleware function. At this time, the success callback will also be called, that is, afterSuccess(undefinedValue)
|
|
417
|
+
await mt(V, y, () => y(p))
|
|
418
|
+
) : (
|
|
419
|
+
// If is next called is not called, no data is returned
|
|
420
|
+
p
|
|
421
|
+
), !_ && !x && (v.v = w);
|
|
422
|
+
} catch (M) {
|
|
423
|
+
throw et() && (a.v = M, !x && (v.v = w), e.em.emit(ee, F(En, P, M)), e.em.emit(Gt, F(dn, P, ee, p, R(), M))), M;
|
|
424
|
+
}
|
|
425
|
+
return q(), K(), A;
|
|
426
|
+
})();
|
|
427
|
+
}
|
|
428
|
+
const ie = (e) => e.current;
|
|
429
|
+
function Sn(e, t, n, r, s = w, o, c = 0) {
|
|
430
|
+
var l;
|
|
431
|
+
n = { ...n };
|
|
432
|
+
let v = !!s, d = p;
|
|
433
|
+
if (s)
|
|
434
|
+
try {
|
|
435
|
+
const C = es(t, fs(e)), z = He(C), $ = z.l1Cache.get(qs(z.id, Kt(C)));
|
|
436
|
+
if ($ && !k($, Ut)) {
|
|
437
|
+
const [ht, Et] = $;
|
|
438
|
+
(!Et || Et > ns()) && (d = ht);
|
|
439
|
+
}
|
|
440
|
+
v = !!re((l = n.force) !== null && l !== void 0 ? l : w) || !d;
|
|
441
|
+
} catch {
|
|
72
442
|
}
|
|
443
|
+
const { create: a, effectRequest: i, ref: f, objectify: u, exposeProvider: O, transformState2Proxy: I, __referingObj: g } = Ft(Rt(), n.__referingObj), H = {
|
|
444
|
+
total: 0,
|
|
445
|
+
loaded: 0
|
|
446
|
+
}, { managedStates: Q = {} } = n, b = or(Q, (C, z) => I(C, z)), _ = a(d ?? (Y(r) ? r() : r), "data"), V = a(v, "loading"), q = a(p, "error"), K = a({ ...H }, "downloading"), j = a({ ...H }, "uploading"), R = u([_, V, q, K, j]), x = qt(), T = ie(f(ir(e, n, x, g)));
|
|
447
|
+
T.fs = R, T.em = x, T.c = n, T.ms = { ...R, ...b };
|
|
448
|
+
const J = o !== p, et = (C = t, z) => un(T, C, z), h = f(p), m = f(w), A = ie(f(zs())), P = (C = g, z) => {
|
|
449
|
+
A(() => {
|
|
450
|
+
(!cs.ssr || ie(h)) && (g.initialRequest = m.current = D, mt(et(z), () => {
|
|
451
|
+
var $;
|
|
452
|
+
($ = ie(h)) === null || $ === void 0 || $.resolve();
|
|
453
|
+
}, ($) => {
|
|
454
|
+
var ot;
|
|
455
|
+
if (!C.bindError && !C.trackedKeys.error && !ie(h))
|
|
456
|
+
throw $;
|
|
457
|
+
(ot = ie(h)) === null || ot === void 0 || ot.reject($);
|
|
458
|
+
}));
|
|
459
|
+
});
|
|
460
|
+
}, M = f(rr((C, z, $) => P(z, $), (C) => At(C) ? lt(c) ? c[C] : c : 0));
|
|
461
|
+
i({
|
|
462
|
+
handler: (
|
|
463
|
+
// When `watchingStates` is an array, it indicates the watching states (including an empty array). When it is undefined, it indicates the non-watching state.
|
|
464
|
+
J ? (C) => M.current(C, g, t) : () => P(g)
|
|
465
|
+
),
|
|
466
|
+
removeStates: () => {
|
|
467
|
+
X(Ie(T.rf), (C) => C());
|
|
468
|
+
},
|
|
469
|
+
frontStates: { ...R, ...b },
|
|
470
|
+
watchingStates: o,
|
|
471
|
+
immediate: s ?? D
|
|
472
|
+
});
|
|
473
|
+
const y = O({
|
|
474
|
+
...u([_, V, q, K, j]),
|
|
475
|
+
abort: () => T.m && T.m.abort(),
|
|
476
|
+
/**
|
|
477
|
+
* Manually initiate a request by executing this method
|
|
478
|
+
* @param sendCallingArgs Parameters passed in when calling the send function
|
|
479
|
+
* @param methodInstance method object
|
|
480
|
+
* @param isFetcher Whether to call isFetcher
|
|
481
|
+
* @returns Request promise
|
|
482
|
+
*/
|
|
483
|
+
send: (C, z) => et(z, C),
|
|
484
|
+
onSuccess(C) {
|
|
485
|
+
x.on(te, C);
|
|
486
|
+
},
|
|
487
|
+
onError(C) {
|
|
488
|
+
g.bindError = D, x.on(ee, C);
|
|
489
|
+
},
|
|
490
|
+
onComplete(C) {
|
|
491
|
+
x.on(Gt, C);
|
|
492
|
+
},
|
|
493
|
+
/**
|
|
494
|
+
* send and wait for responding with `await`
|
|
495
|
+
* this is always used in `nuxt3` and `<suspense>` in vue3
|
|
496
|
+
* @example
|
|
497
|
+
* ```js
|
|
498
|
+
* const { loading, data, error } = await useRequest(...);
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
then(C, z) {
|
|
502
|
+
const { promise: $, resolve: ot, reject: ht } = Ce();
|
|
503
|
+
h.current = {
|
|
504
|
+
resolve: ot,
|
|
505
|
+
reject: ht
|
|
506
|
+
}, jt(() => {
|
|
507
|
+
!m.current && ot();
|
|
508
|
+
}, 10), mt($, () => {
|
|
509
|
+
C(y);
|
|
510
|
+
}, z);
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
return y;
|
|
514
|
+
}
|
|
515
|
+
function br(e = {}) {
|
|
516
|
+
const t = Sn(It.USE_FETCHER, Z, e), { send: n } = t;
|
|
517
|
+
return pn(t, "send"), Ge(t, {
|
|
518
|
+
/**
|
|
519
|
+
* Fetch data fetch will definitely send a request, and if the currently requested data has a corresponding management state, this state will be updated.
|
|
520
|
+
* @param matcher Method object
|
|
521
|
+
*/
|
|
522
|
+
fetch: (r, ...s) => (vs(us, r), n(s, r))
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
function Ee(e, t = {}) {
|
|
526
|
+
const { immediate: n = D, initialData: r } = t, s = Sn(It.USE_REQUEST, e, t, r, !!n), { send: o } = s;
|
|
527
|
+
return Ge(s, {
|
|
528
|
+
send: (...c) => o(c)
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
function Ss(e, t, n = {}) {
|
|
532
|
+
ds(t && N(t) > 0, "expected at least one watching state");
|
|
533
|
+
const { immediate: r, debounce: s = 0, initialData: o } = n, c = Sn(
|
|
534
|
+
It.USE_WATCHER,
|
|
535
|
+
e,
|
|
536
|
+
n,
|
|
537
|
+
o,
|
|
538
|
+
!!r,
|
|
539
|
+
// !!immediate means not send request immediately
|
|
540
|
+
t,
|
|
541
|
+
s
|
|
542
|
+
), { send: l } = c;
|
|
543
|
+
return Ge(c, {
|
|
544
|
+
send: (...v) => l(v)
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
var yr = (e) => {
|
|
548
|
+
let t = {};
|
|
549
|
+
return {
|
|
550
|
+
snapshots: () => t,
|
|
551
|
+
save(n, r = w) {
|
|
552
|
+
const s = Kt(n);
|
|
553
|
+
(!t[s] || r) && (t[s] = {
|
|
554
|
+
entity: n
|
|
555
|
+
});
|
|
556
|
+
},
|
|
557
|
+
get: (n) => t[Kt(k(n, me) ? n : e(n))],
|
|
558
|
+
remove(n) {
|
|
559
|
+
n ? delete t[n] : t = {};
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
};
|
|
563
|
+
const Xt = _t("usePagination"), zn = (e, t) => Xt(At(e) && e < N(t), "index must be a number that less than list length"), Gn = (e) => [
|
|
564
|
+
e[e.length - 2],
|
|
565
|
+
// refreshPage
|
|
566
|
+
e[e.length - 1],
|
|
567
|
+
// isRefresh
|
|
568
|
+
e.slice(0, e.length - 2)
|
|
569
|
+
// send args
|
|
570
|
+
];
|
|
571
|
+
var Yr = (e, t = {}) => {
|
|
572
|
+
const { create: n, computed: r, ref: s, watch: o, exposeProvider: c, objectify: l, __referingObj: v } = Ft(Rt()), { preloadPreviousPage: d = D, preloadNextPage: a = D, total: i = (E) => E.total, data: f = (E) => E.data, append: u = w, initialPage: O = 1, initialPageSize: I = 10, watchingStates: g = [], initialData: H, immediate: Q = D, middleware: b, force: _ = Z, actions: V = {}, ...q } = t, K = s(e), j = s(w), R = n(O, "page"), x = n(I, "pageSize"), T = n(H ? f(H) || [] : [], "data"), J = n(H ? i(H) : p, "total"), { snapshots: et, get: h, save: m, remove: A } = s(yr((E) => K.current(E, x.v))).current, P = (E) => f(E) || E, M = br({
|
|
573
|
+
__referingObj: v,
|
|
574
|
+
updateState: w,
|
|
575
|
+
force: ({ args: E }) => E[N(E) - 1]
|
|
576
|
+
}), { loading: y, fetch: C, abort: z, onSuccess: $ } = M, ot = s(y), ht = (E = R.v, S = []) => {
|
|
577
|
+
const U = e(E, x.v, ...S);
|
|
578
|
+
return m(U), U;
|
|
579
|
+
};
|
|
580
|
+
o(g, () => {
|
|
581
|
+
R.v = O, j.current = D;
|
|
582
|
+
});
|
|
583
|
+
const Et = s({}), ct = n("", "status"), Ct = n([], "removing"), L = n(p, "replacing"), B = r(() => {
|
|
584
|
+
const E = J.v;
|
|
585
|
+
return E !== p ? Math.ceil(E / x.v) : p;
|
|
586
|
+
}, [x, J], "pageCount"), W = (E) => (...S) => Et.current[E](...S), nt = Ss((...E) => {
|
|
587
|
+
const [S, , U] = Gn(E);
|
|
588
|
+
return ht(S, U);
|
|
589
|
+
}, [...g, R.e, x.e], {
|
|
590
|
+
__referingObj: v,
|
|
591
|
+
immediate: Q,
|
|
592
|
+
initialData: H,
|
|
593
|
+
managedStates: l([T, R, x, J], "s"),
|
|
594
|
+
middleware(E, S) {
|
|
595
|
+
return b ? b({
|
|
596
|
+
...E,
|
|
597
|
+
delegatingActions: {
|
|
598
|
+
refresh: W("refresh"),
|
|
599
|
+
insert: W("insert"),
|
|
600
|
+
remove: W("remove"),
|
|
601
|
+
replace: W("replace"),
|
|
602
|
+
reload: W("reload"),
|
|
603
|
+
getState: (U) => ({
|
|
604
|
+
page: R,
|
|
605
|
+
pageSize: x,
|
|
606
|
+
data: T,
|
|
607
|
+
pageCount: B,
|
|
608
|
+
total: J,
|
|
609
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
610
|
+
isLastPage: Fe
|
|
611
|
+
})[U].v
|
|
612
|
+
}
|
|
613
|
+
}, S) : S();
|
|
614
|
+
},
|
|
615
|
+
force: (E) => E.args[1] || (Y(_) ? _(E) : _),
|
|
616
|
+
...q
|
|
617
|
+
}), { send: ut } = nt, Lt = nt.__proxyState("data"), zt = async (E) => {
|
|
618
|
+
const { rawData: S = Lt.v, preloadPage: U, fetchMethod: G, forceRequest: tt = w, isNextPage: st = w } = E, it = B.v, ft = it ? U > it : st ? N(P(S)) < x.v : w;
|
|
619
|
+
if (!(U > 0 && !ft))
|
|
620
|
+
return w;
|
|
621
|
+
const { e: rt } = Gs(G), Mt = await cn(G);
|
|
622
|
+
return rt(Hs) <= ns() ? w : tt || !Mt;
|
|
623
|
+
}, Pt = async (E, S, U = []) => {
|
|
624
|
+
const G = R.v + 1, tt = ht(G, U);
|
|
625
|
+
a && await zt({
|
|
626
|
+
rawData: E,
|
|
627
|
+
preloadPage: G,
|
|
628
|
+
fetchMethod: tt,
|
|
629
|
+
isNextPage: D,
|
|
630
|
+
forceRequest: S
|
|
631
|
+
}) && ye(C(tt, ...U, S), Z);
|
|
632
|
+
}, Bt = async (E, S = []) => {
|
|
633
|
+
const U = R.v - 1, G = ht(U, S);
|
|
634
|
+
d && await zt({
|
|
635
|
+
rawData: E,
|
|
636
|
+
preloadPage: U,
|
|
637
|
+
fetchMethod: G
|
|
638
|
+
}) && ye(C(G, ...S, p), Z);
|
|
639
|
+
}, pt = () => {
|
|
640
|
+
const E = Lt.v;
|
|
641
|
+
if (!E)
|
|
642
|
+
return D;
|
|
643
|
+
const S = P(E), U = R.v, G = B.v, tt = lt(S) ? N(S) : 0;
|
|
644
|
+
return G ? U >= G : tt < x.v;
|
|
645
|
+
}, Fe = n(pt(), "isLastPage");
|
|
646
|
+
o([R, B, Lt, x], async () => {
|
|
647
|
+
jt(() => {
|
|
648
|
+
Fe.v = pt();
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
const Yt = async () => {
|
|
652
|
+
const E = h(R.v);
|
|
653
|
+
E && await we(E.entity, (S) => {
|
|
654
|
+
if (S) {
|
|
655
|
+
const U = P(S) || [];
|
|
656
|
+
return xt(U, 0, N(U), ...T.v), S;
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
};
|
|
660
|
+
$(({ method: E, data: S }) => {
|
|
661
|
+
const U = h(R.v);
|
|
662
|
+
if (U && Kt(U.entity) === Kt(E)) {
|
|
663
|
+
const G = P(S);
|
|
664
|
+
if (u) {
|
|
665
|
+
const tt = T.v, st = x.v, it = N(tt) % st;
|
|
666
|
+
if (it > 0) {
|
|
667
|
+
const ft = [...T.v];
|
|
668
|
+
xt(ft, (R.v - 1) * st, it, ...G), T.v = ft;
|
|
669
|
+
}
|
|
670
|
+
} else
|
|
671
|
+
T.v = G;
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
const Se = s(p), ae = s(p);
|
|
675
|
+
nt.onSuccess(({ data: E, args: S, method: U }) => {
|
|
676
|
+
const [G, tt, st] = Gn(S), { total: it } = h(U) || {}, ft = E;
|
|
677
|
+
J.v = it !== p ? it : i(ft), tt || (Bt(ft, st), Pt(ft, w, st));
|
|
678
|
+
const Jt = x.v, rt = P(ft);
|
|
679
|
+
if (Xt(lt(rt), "Got wrong array, did you return the correct array of list in `data` function"), u) {
|
|
680
|
+
if (j.current && (T.v = []), G === p)
|
|
681
|
+
T.v = [...T.v, ...rt];
|
|
682
|
+
else if (G) {
|
|
683
|
+
const Mt = [...T.v];
|
|
684
|
+
xt(Mt, (G - 1) * Jt, Jt, ...rt), T.v = Mt;
|
|
685
|
+
}
|
|
686
|
+
} else
|
|
687
|
+
T.v = rt;
|
|
688
|
+
}).onSuccess(({ data: E }) => {
|
|
689
|
+
var S;
|
|
690
|
+
(S = Se.current) === null || S === void 0 || S.call(Se, E);
|
|
691
|
+
}).onError(({ error: E }) => {
|
|
692
|
+
var S;
|
|
693
|
+
(S = ae.current) === null || S === void 0 || S.call(ae, E);
|
|
694
|
+
}).onComplete(() => {
|
|
695
|
+
j.current = w;
|
|
696
|
+
});
|
|
697
|
+
const ce = (E) => {
|
|
698
|
+
const S = T.v.indexOf(E);
|
|
699
|
+
return Xt(S >= 0, "item is not found in list"), S;
|
|
700
|
+
}, { addQueue: Je, onComplete: Ln } = s($s()).current, Xe = async (E = R.v) => {
|
|
701
|
+
let S = E, U = Ot();
|
|
702
|
+
if (u) {
|
|
703
|
+
if (!At(E)) {
|
|
704
|
+
const G = ce(E);
|
|
705
|
+
S = Math.floor(G / x.v) + 1;
|
|
706
|
+
}
|
|
707
|
+
Xt(S <= R.v, "refresh page can't greater than page"), U = ut(S, D);
|
|
708
|
+
} else
|
|
709
|
+
Xt(At(S), "unable to calculate refresh page by item in pagination mode"), U = S === R.v ? ut(p, D) : C(e(S, x.v), D);
|
|
710
|
+
return U;
|
|
711
|
+
}, Tn = async (E = w) => {
|
|
712
|
+
const S = R.v, U = et();
|
|
713
|
+
let G = Ie(U);
|
|
714
|
+
if (E)
|
|
715
|
+
A();
|
|
716
|
+
else {
|
|
717
|
+
const tt = vt(Dt([h(S - 1), h(S), h(S + 1)], Boolean), ({ entity: st }) => Kt(st));
|
|
718
|
+
G = vt(Dt(yt(U), (st) => !Tt(tt, st)), (st) => {
|
|
719
|
+
const it = U[st];
|
|
720
|
+
return delete U[st], it;
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
await er(vt(G, ({ entity: tt }) => tt));
|
|
724
|
+
}, On = async () => {
|
|
725
|
+
ot.current && z(), await Tn();
|
|
726
|
+
const E = h(R.v + 1);
|
|
727
|
+
if (E) {
|
|
728
|
+
const S = P(await cn(E.entity) || {}) || [];
|
|
729
|
+
Pt(p, N(S) < x.v);
|
|
730
|
+
}
|
|
731
|
+
}, Un = (E) => {
|
|
732
|
+
if (E === 0)
|
|
733
|
+
return;
|
|
734
|
+
const S = J.v;
|
|
735
|
+
if (At(S)) {
|
|
736
|
+
const U = Math.max(S + E, 0);
|
|
737
|
+
J.v = U;
|
|
738
|
+
const G = R.v;
|
|
739
|
+
X([h(G - 1), h(G), h(G + 1)], (tt) => {
|
|
740
|
+
tt && (tt.total = U);
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
}, Qn = (E, S = 0) => (Ln(On), Je(async () => {
|
|
744
|
+
const U = At(S) ? S : ce(S) + 1;
|
|
745
|
+
Xt(U >= 0, "illegal insert position"), Y(V.insert) && (ct.v = "inserting", await ue(V.insert(E, S), () => {
|
|
746
|
+
ct.v = "";
|
|
747
|
+
}));
|
|
748
|
+
let G = p;
|
|
749
|
+
const tt = [...T.v];
|
|
750
|
+
if (N(tt) % x.v === 0 && (G = tt.pop()), xt(tt, U, 0, E), T.v = tt, Un(1), await Yt(), G) {
|
|
751
|
+
const st = h(R.v + 1);
|
|
752
|
+
st && await we(st.entity, (it) => {
|
|
753
|
+
if (it) {
|
|
754
|
+
const ft = P(it) || [];
|
|
755
|
+
return ft.unshift(G), ft.pop(), it;
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
})), In = (...E) => (Ln(On), Je(async () => {
|
|
760
|
+
const S = vt(E, (rt) => {
|
|
761
|
+
const Mt = At(rt) ? rt : ce(rt);
|
|
762
|
+
return zn(Mt, T.v), Mt;
|
|
763
|
+
});
|
|
764
|
+
if (Y(V.remove)) {
|
|
765
|
+
ct.v = "removing", Ct.v = [...S];
|
|
766
|
+
const rt = Ws(vt(E, (Mt) => V.remove(Mt)));
|
|
767
|
+
await ue(rt, () => {
|
|
768
|
+
ct.v = "", Ct.v = [];
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
const U = R.v, G = U + 1, tt = h(G), st = [];
|
|
772
|
+
tt && await we(tt.entity, (rt) => {
|
|
773
|
+
if (rt) {
|
|
774
|
+
const Mt = P(rt);
|
|
775
|
+
return lt(Mt) && at(st, ...xt(Mt, 0, N(S))), rt;
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
const it = pt(), ft = N(st);
|
|
779
|
+
let Jt = !1;
|
|
780
|
+
if (ft > 0 || it) {
|
|
781
|
+
const rt = Dt(T.v, (Mt, js) => !Tt(S, js));
|
|
782
|
+
Jt = !u && it && N(rt) <= 0, !Jt && ft > 0 && at(rt, ...st), T.v = rt;
|
|
783
|
+
} else ft <= 0 && !it && Xe(U);
|
|
784
|
+
return Un(-N(S)), Yt().then(() => {
|
|
785
|
+
Jt && (R.v = U - 1);
|
|
786
|
+
});
|
|
787
|
+
})), Vn = (E, S) => Je(async () => {
|
|
788
|
+
Xt(S !== p, "expect specify the replace position");
|
|
789
|
+
const U = At(S) ? S : ce(S);
|
|
790
|
+
zn(U, T.v), Y(V.replace) && (ct.v = "replacing", L.v = U, await ue(V.replace(E, S), () => {
|
|
791
|
+
ct.v = "", L.v = p;
|
|
792
|
+
}));
|
|
793
|
+
const G = [...T.v];
|
|
794
|
+
xt(G, U, 1, E), T.v = G, await Yt();
|
|
795
|
+
}), jn = async () => {
|
|
796
|
+
await Tn(D), j.current = D, R.v === O ? ye(ut(), Z) : R.v = O;
|
|
797
|
+
const { resolve: E, reject: S, promise: U } = Ce();
|
|
798
|
+
return Se.current = E, ae.current = S, U;
|
|
799
|
+
};
|
|
800
|
+
return Et.current = {
|
|
801
|
+
refresh: Xe,
|
|
802
|
+
insert: Qn,
|
|
803
|
+
remove: In,
|
|
804
|
+
replace: Vn,
|
|
805
|
+
reload: jn
|
|
806
|
+
}, c({
|
|
807
|
+
...nt,
|
|
808
|
+
...l([T, R, B, x, J, Fe, ct, Ct, L]),
|
|
809
|
+
send: (...E) => ut(...E, p, p),
|
|
810
|
+
fetching: M.loading,
|
|
811
|
+
onFetchSuccess: M.onSuccess,
|
|
812
|
+
onFetchError: M.onError,
|
|
813
|
+
onFetchComplete: M.onComplete,
|
|
814
|
+
refresh: Xe,
|
|
815
|
+
insert: Qn,
|
|
816
|
+
remove: In,
|
|
817
|
+
replace: Vn,
|
|
818
|
+
reload: jn
|
|
819
|
+
});
|
|
820
|
+
};
|
|
821
|
+
const gs = (e, t) => _t(e)(lt(t) && N(t) > 0, "please use an array to represent serial requests"), bs = (e, t, n = []) => (e.shift(), ((r, s) => {
|
|
822
|
+
t?.(r, () => Ot(p)), r.controlLoading();
|
|
823
|
+
const o = r.proxyStates.loading;
|
|
824
|
+
o.v = D;
|
|
825
|
+
let c = s();
|
|
826
|
+
for (const l of e)
|
|
827
|
+
c = mt(c, (v) => {
|
|
828
|
+
const d = l(v, ...r.args);
|
|
829
|
+
return at(n, d), d.send();
|
|
830
|
+
});
|
|
831
|
+
return c.finally(() => {
|
|
832
|
+
o.v = w;
|
|
833
|
+
});
|
|
834
|
+
}));
|
|
835
|
+
var Jr = (e, t = {}) => {
|
|
836
|
+
gs("useSerialRequest", e);
|
|
837
|
+
const { ref: n, __referingObj: r } = Ft(Rt()), s = n([]).current, o = Ee(e[0], {
|
|
838
|
+
...t,
|
|
839
|
+
__referingObj: r,
|
|
840
|
+
middleware: bs(e, t.middleware, s)
|
|
841
|
+
});
|
|
842
|
+
return o.onError = Re(o.onError, (c, l) => {
|
|
843
|
+
l.method = s[N(s) - 1], c(l);
|
|
844
|
+
}), o;
|
|
845
|
+
}, Xr = (e, t, n = {}) => {
|
|
846
|
+
gs("useSerialWatcher", e);
|
|
847
|
+
const { ref: r, __referingObj: s } = Ft(Rt()), o = r([]).current, c = Ss(e[0], t, {
|
|
848
|
+
...n,
|
|
849
|
+
__referingObj: s,
|
|
850
|
+
middleware: bs(e, n.middleware, o)
|
|
851
|
+
});
|
|
852
|
+
return c.onError = Re(c.onError, (l, v) => {
|
|
853
|
+
v.method = o[N(o) - 1], l(v);
|
|
854
|
+
}), c;
|
|
855
|
+
};
|
|
856
|
+
const gn = "valueOf", pe = "default", fn = "silent", Rr = "queue", wr = "static";
|
|
857
|
+
let ne;
|
|
858
|
+
const Hn = (e) => {
|
|
859
|
+
ne = e;
|
|
860
|
+
};
|
|
861
|
+
let Ke;
|
|
862
|
+
const _r = (e) => {
|
|
863
|
+
Ke = e;
|
|
864
|
+
};
|
|
865
|
+
let bn = {};
|
|
866
|
+
const Cr = (e = {}) => {
|
|
867
|
+
bn = e;
|
|
868
|
+
};
|
|
869
|
+
let ke = 0;
|
|
870
|
+
const ys = (e) => {
|
|
871
|
+
ke = e;
|
|
872
|
+
};
|
|
873
|
+
let Rs = [];
|
|
874
|
+
const Pr = (e = 0) => {
|
|
875
|
+
Rs = lt(e) ? e : [
|
|
876
|
+
{
|
|
877
|
+
queue: pe,
|
|
878
|
+
wait: e
|
|
879
|
+
}
|
|
880
|
+
];
|
|
881
|
+
}, ws = Symbol("GlobalSQBoot"), _s = Symbol("GlobalSQBefore"), Cs = Symbol("GlobalSQSuccess"), Ps = Symbol("GlobalSQError"), Ms = Symbol("GlobalSQFail"), Qt = qt(), yn = _t("useSQRequest");
|
|
882
|
+
async function Ue(e, t) {
|
|
883
|
+
let n = w;
|
|
884
|
+
if (e) {
|
|
885
|
+
const { update: r } = Rt(), s = Kt(e), { id: o } = He(e), c = Es(o, s), l = Y(t) ? { data: t } : t, v = vt(c, async (d) => {
|
|
886
|
+
let a = p;
|
|
887
|
+
if (d) {
|
|
888
|
+
const { ms: i, ro: f } = d;
|
|
889
|
+
X(yt(l), (u) => {
|
|
890
|
+
ar(u in i, `state named \`${u}\` is not found`);
|
|
891
|
+
const O = i[u];
|
|
892
|
+
let I = l[u](O.v);
|
|
893
|
+
I = lt(I) ? [...I] : bt(I) ? { ...I } : I, u === "data" && (a = I), r(I, i[u].s, u, f);
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
a !== p && await we(e, a);
|
|
897
|
+
});
|
|
898
|
+
N(v) > 0 && (await Ut.all(v), n = D);
|
|
899
|
+
}
|
|
900
|
+
return n;
|
|
901
|
+
}
|
|
902
|
+
var Mr = {
|
|
903
|
+
forward: (e) => k(e, Date) ? e.getTime() : p,
|
|
904
|
+
backward: (e) => F(Date, e)
|
|
905
|
+
}, xr = {
|
|
906
|
+
forward: (e) => k(e, RegExp) ? e.source : void 0,
|
|
907
|
+
backward: (e) => F(RegExp, e)
|
|
908
|
+
};
|
|
909
|
+
const Rn = (e = {}) => {
|
|
910
|
+
const t = {
|
|
911
|
+
date: Mr,
|
|
912
|
+
regexp: xr,
|
|
913
|
+
...e
|
|
914
|
+
};
|
|
915
|
+
return {
|
|
916
|
+
serialize: (s) => {
|
|
917
|
+
if (bt(s)) {
|
|
918
|
+
const { data: o } = Nt({ data: s }, (c) => {
|
|
919
|
+
let l = p;
|
|
920
|
+
const v = yt(t).reduce((a, i) => {
|
|
921
|
+
if (!l) {
|
|
922
|
+
const f = t[i].forward(a);
|
|
923
|
+
f !== p && (l = i, a = f);
|
|
924
|
+
}
|
|
925
|
+
return a;
|
|
926
|
+
}, c);
|
|
927
|
+
return Me.prototype.toString.call(c) === "[object Object]" ? c = { ...c } : lt(c) && (c = [...c]), l !== p ? [l, v] : c;
|
|
928
|
+
});
|
|
929
|
+
s = o;
|
|
930
|
+
}
|
|
931
|
+
return s;
|
|
932
|
+
},
|
|
933
|
+
deserialize: (s) => bt(s) ? Nt({ data: s }, (o) => {
|
|
934
|
+
if (lt(o) && N(o) === 2) {
|
|
935
|
+
const c = t[o[0]];
|
|
936
|
+
o = c ? c.backward(o[1]) : o;
|
|
937
|
+
}
|
|
938
|
+
return o;
|
|
939
|
+
}, w).data : s
|
|
940
|
+
};
|
|
941
|
+
}, Ae = Symbol("vdid"), xs = Symbol("original"), wn = /\[vd:([0-9a-z]+)\]/, As = (e) => {
|
|
942
|
+
const t = e?.[Ae];
|
|
943
|
+
t && ne && (ne[t] = p);
|
|
944
|
+
}, kt = (e, t = D) => {
|
|
945
|
+
As(e);
|
|
946
|
+
const n = e?.[Ae];
|
|
947
|
+
return (n ? `[vd:${n}]` : p) || (t ? e : p);
|
|
948
|
+
};
|
|
949
|
+
function _n() {
|
|
950
|
+
return kt(this);
|
|
951
|
+
}
|
|
952
|
+
const Cn = function() {
|
|
953
|
+
};
|
|
954
|
+
Cn.prototype = Me.create(Wt, {
|
|
955
|
+
[gn]: ss(_n)
|
|
956
|
+
});
|
|
957
|
+
const Pn = function() {
|
|
958
|
+
};
|
|
959
|
+
Pn.prototype = Me.create(Wt, {
|
|
960
|
+
[gn]: ss(_n)
|
|
961
|
+
});
|
|
962
|
+
var Ds = (e, t = an()) => {
|
|
963
|
+
const n = (s, o = an()) => {
|
|
964
|
+
if (s === Wt)
|
|
965
|
+
s = F(Cn);
|
|
966
|
+
else if (s === p)
|
|
967
|
+
s = F(Pn);
|
|
968
|
+
else {
|
|
969
|
+
const c = Me(s);
|
|
970
|
+
Ze(c, gn, _n), Ze(c, xs, s), s = c;
|
|
971
|
+
}
|
|
972
|
+
return Ze(s, Ae, o), s;
|
|
973
|
+
}, r = n(e, t);
|
|
974
|
+
return (oe(r) || lt(r)) && Nt(r, (s) => n(s)), r;
|
|
975
|
+
};
|
|
976
|
+
const Fs = (e, t = D) => {
|
|
977
|
+
const n = (s) => (As(s), s?.[Ae] && (k(s, Pn) ? s = p : k(s, Cn) ? s = Wt : (k(s, Number) || k(s, String) || k(s, Boolean)) && (s = s[xs])), s), r = n(e);
|
|
978
|
+
return t && (bt(r) || lt(r)) && Nt(r, (s) => n(s)), r;
|
|
979
|
+
};
|
|
980
|
+
var Zr = (e) => Fs(e);
|
|
981
|
+
const _e = "__$k", Ne = "__$v", Mn = () => (yn(!!Ke, "alova instance is not found, Do you forget to set `alova` or call `bootSilentFactory`?"), Ke.l2Cache);
|
|
982
|
+
let ve = p;
|
|
983
|
+
const he = "alova.SQ", xn = "alova.SM.", An = async (e, t) => {
|
|
984
|
+
const n = Mn();
|
|
985
|
+
bt(t) && (t = Nt(lt(t) ? [...t] : { ...t }, (r, s, o) => {
|
|
986
|
+
var c;
|
|
987
|
+
if (s === Ne && o[_e])
|
|
988
|
+
return r;
|
|
989
|
+
if (s === "context" && ((c = r?.constructor) === null || c === void 0 ? void 0 : c.name) === "Alova")
|
|
990
|
+
return p;
|
|
991
|
+
const l = r?.[Ae];
|
|
992
|
+
let v = Fs(r, w);
|
|
993
|
+
if (ks(v) === "[object Object]" ? (r = { ...r }, v = {}) : lt(r) && (r = [...r], v = []), l) {
|
|
994
|
+
const a = {
|
|
995
|
+
[_e]: l,
|
|
996
|
+
// For objects and arrays, all their internal properties will be put to the outside through `...value`, so the internal ones do not need to be traversed and converted.
|
|
997
|
+
// Therefore, empty the array or object to avoid repeated conversions and contamination of the original object.
|
|
998
|
+
[Ne]: v,
|
|
999
|
+
...r
|
|
1000
|
+
};
|
|
1001
|
+
if (k(r, String))
|
|
1002
|
+
for (let i = 0; i < N(r); i += 1)
|
|
1003
|
+
a == null || delete a[i];
|
|
1004
|
+
r = a;
|
|
1005
|
+
}
|
|
1006
|
+
return r;
|
|
1007
|
+
})), ve = ve || Rn(bn), await n.set(e, ve.serialize(t));
|
|
1008
|
+
}, qe = async (e) => {
|
|
1009
|
+
const t = await Mn().get(e);
|
|
1010
|
+
return ve = ve || Rn(bn), bt(t) ? Nt(ve.deserialize(t), (n) => {
|
|
1011
|
+
if (bt(n) && n?.[_e]) {
|
|
1012
|
+
const r = n[_e], s = Ds(n[Ne], r);
|
|
1013
|
+
X(yt(n), (o) => {
|
|
1014
|
+
Tt([_e, Ne], o) || (s[o] = n[o]);
|
|
1015
|
+
}), n = s;
|
|
1016
|
+
}
|
|
1017
|
+
return n;
|
|
1018
|
+
}, w) : t;
|
|
1019
|
+
}, $n = async (e) => {
|
|
1020
|
+
await Mn().remove(e);
|
|
1021
|
+
}, Ye = (e) => An(xn + e.id, e), Ar = async (e, t) => {
|
|
1022
|
+
await Ye(e);
|
|
1023
|
+
const n = await qe(he) || {}, r = n[t] = n[t] || [];
|
|
1024
|
+
at(r, e.id), await An(he, n);
|
|
1025
|
+
}, vn = async (e, t, n) => {
|
|
1026
|
+
const r = await qe(he) || {}, s = r[e] || [], o = s.findIndex((c) => c === t);
|
|
1027
|
+
o >= 0 && (n ? (xt(s, o, 1, n.id), await Ye(n)) : xt(s, o, 1), await $n(xn + t), N(s) <= 0 && delete r[e], N(yt(r)) > 0 ? await An(he, r) : await $n(he));
|
|
1028
|
+
};
|
|
1029
|
+
let Vt = {};
|
|
1030
|
+
const Dr = (e) => {
|
|
1031
|
+
X(yt(e), (t) => {
|
|
1032
|
+
const n = Vt[t] = Vt[t] || [];
|
|
1033
|
+
at(n, ...e[t]);
|
|
1034
|
+
});
|
|
1035
|
+
}, hn = (e, t) => {
|
|
1036
|
+
const n = (r) => {
|
|
1037
|
+
const s = kt(r);
|
|
1038
|
+
return s in t ? t[s] : Pe(r) ? r.replace(F(rs, wn.source, "g"), (o) => o in t ? t[o] : o) : r;
|
|
1039
|
+
};
|
|
1040
|
+
return bt(e) && !kt(e, w) ? Nt(e, n) : e = n(e), e;
|
|
1041
|
+
}, Fr = (e, t) => Ut.all(vt(t, async (n) => {
|
|
1042
|
+
hn(n.entity, e), n.cache && await Ye(n);
|
|
1043
|
+
})), Ls = (e, t) => {
|
|
1044
|
+
let n = {};
|
|
1045
|
+
const r = kt(e, w);
|
|
1046
|
+
if (r && (n[r] = t), bt(e))
|
|
1047
|
+
for (const s in e)
|
|
1048
|
+
n = {
|
|
1049
|
+
...n,
|
|
1050
|
+
...Ls(e[s], t?.[s])
|
|
1051
|
+
};
|
|
1052
|
+
return n;
|
|
1053
|
+
}, tn = (e, t) => {
|
|
1054
|
+
t ? e.active = t : delete e.active;
|
|
1055
|
+
}, Lr = 1e3, Ts = (e, t) => {
|
|
1056
|
+
const n = (s) => {
|
|
1057
|
+
const o = e[0];
|
|
1058
|
+
if (o) {
|
|
1059
|
+
const c = Rs.find(({ queue: d }) => k(d, rs) ? fe(d, s) : d === s), l = () => e[0] && r(e[0]), v = c?.wait ? re(c.wait, [o, s]) : 0;
|
|
1060
|
+
v && v > 0 ? jt(l, v) : l();
|
|
1061
|
+
}
|
|
1062
|
+
}, r = (s, o = 0) => {
|
|
1063
|
+
tn(s, D);
|
|
1064
|
+
const { cache: c, id: l, behavior: v, entity: d, retryError: a = /.*/, maxRetryTimes: i = 0, backoff: f = { delay: Lr }, resolveHandler: u = Z, rejectHandler: O = Z, emitter: I, handlerArgs: g = [], virtualResponse: H, force: Q } = s;
|
|
1065
|
+
Qt.emit(_s, F(We, v, d, s, t, o)), mt(d.send(Q), async (b) => {
|
|
1066
|
+
if (Kn(e), c && await vn(t, l), u(b), v === fn) {
|
|
1067
|
+
const _ = Ls(H, b), { targetRefMethod: V, updateStates: q } = s;
|
|
1068
|
+
if (k(V, me) && q && N(q) > 0) {
|
|
1069
|
+
const K = {};
|
|
1070
|
+
X(q, (R) => {
|
|
1071
|
+
K[R] = (x) => hn(x, _);
|
|
1072
|
+
}), Ue(V, K) || await we(V, (R) => hn(R, _));
|
|
1073
|
+
}
|
|
1074
|
+
await Fr(_, e), Qt.emit(Cs, F(lr, v, d, s, t, o, b, _));
|
|
1075
|
+
}
|
|
1076
|
+
tn(s, w), n(t);
|
|
1077
|
+
}, (b) => {
|
|
1078
|
+
if (v !== fn)
|
|
1079
|
+
Kn(e), O(b);
|
|
1080
|
+
else {
|
|
1081
|
+
const _ = (x) => Qt.emit(Ps, F(dr, v, d, s, t, o, b, x)), { name: V = "", message: q = "" } = b || {};
|
|
1082
|
+
let K, j;
|
|
1083
|
+
k(a, RegExp) ? j = a : bt(a) && (K = a.name, j = a.message);
|
|
1084
|
+
const R = K && fe(K, V) || j && fe(j, q);
|
|
1085
|
+
if (o < i && R) {
|
|
1086
|
+
const x = os(f, o + 1);
|
|
1087
|
+
_(x), jt(
|
|
1088
|
+
() => {
|
|
1089
|
+
o += 1, r(s, o), I.emit("retry", F(vr, v, d, s, g, o, x));
|
|
1090
|
+
},
|
|
1091
|
+
// When there are still retry times, use timeout as the next request time.
|
|
1092
|
+
x
|
|
1093
|
+
);
|
|
1094
|
+
} else
|
|
1095
|
+
ys(2), _(), I.emit("fallback", F(ms, v, d, s, g, b)), Qt.emit(Ms, F(ur, v, d, s, t, o, b));
|
|
1096
|
+
}
|
|
1097
|
+
tn(s, w);
|
|
1098
|
+
});
|
|
1099
|
+
};
|
|
1100
|
+
n(t);
|
|
1101
|
+
}, Tr = async (e, t, n = pe, r = () => []) => {
|
|
1102
|
+
e.cache = t;
|
|
1103
|
+
const s = Vt[n] = Vt[n] || [], o = N(s) <= 0, l = !(await Promise.all(r())).some((v) => v === w);
|
|
1104
|
+
return l && (t && await Ar(e, n), at(s, e), o && ke === 1 && Ts(s, n)), l;
|
|
1105
|
+
}, Wn = (e) => {
|
|
1106
|
+
let t = p, n = "", r = 0;
|
|
1107
|
+
for (const s in Vt)
|
|
1108
|
+
if (r = Vt[s].indexOf(e), r >= 0) {
|
|
1109
|
+
t = Vt[s], n = s;
|
|
1110
|
+
break;
|
|
1111
|
+
}
|
|
1112
|
+
return [t, n, r];
|
|
1113
|
+
};
|
|
1114
|
+
class Os {
|
|
1115
|
+
constructor(t, n, r, s = an(), o, c, l, v, d, a, i, f) {
|
|
1116
|
+
const u = this;
|
|
1117
|
+
u.entity = t, u.behavior = n, u.id = s, u.emitter = r, u.force = !!o, u.retryError = c, u.maxRetryTimes = l, u.backoff = v, u.resolveHandler = d, u.rejectHandler = a, u.handlerArgs = i, u.vDatas = f;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Allow cache-time persistent updates to the current instance
|
|
1121
|
+
*/
|
|
1122
|
+
async save() {
|
|
1123
|
+
this.cache && await Ye(this);
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Replace the current instance with a new silentMethod instance in the queue
|
|
1127
|
+
* If there is a persistent cache, the cache will also be updated.
|
|
1128
|
+
* @param newSilentMethod new silentMethod instance
|
|
1129
|
+
*/
|
|
1130
|
+
async replace(t) {
|
|
1131
|
+
const n = this;
|
|
1132
|
+
yn(t.cache === n.cache, "the cache of new silentMethod must equal with this silentMethod");
|
|
1133
|
+
const [r, s, o] = Wn(n);
|
|
1134
|
+
r && (xt(r, o, 1, t), n.cache && await vn(s, n.id, t));
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Remove the current instance. If there is persistent data, it will also be removed synchronously.
|
|
1138
|
+
*/
|
|
1139
|
+
async remove() {
|
|
1140
|
+
const t = this, [n, r, s] = Wn(t);
|
|
1141
|
+
n && (xt(n, s, 1), t.cache && await vn(r, t.id));
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Set the method instance corresponding to the delayed update status and the corresponding status name
|
|
1145
|
+
* It will find the corresponding status data and update vData to the actual data after responding to this silentMethod
|
|
1146
|
+
*
|
|
1147
|
+
* @param method method instance
|
|
1148
|
+
* @param updateStateName Updated status name, the default is data, you can also set multiple
|
|
1149
|
+
*/
|
|
1150
|
+
setUpdateState(t, n = "data") {
|
|
1151
|
+
t && (this.targetRefMethod = t, this.updateStates = lt(n) ? n : [n]);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
var Or = (e) => {
|
|
1155
|
+
const { id: t, behavior: n, entity: r, retryError: s, maxRetryTimes: o, backoff: c, resolveHandler: l, rejectHandler: v, handlerArgs: d, targetRefMethod: a, force: i } = e, f = (O) => {
|
|
1156
|
+
const { type: I, url: g, config: H, data: Q } = O;
|
|
1157
|
+
return F(me, I, Ke, g, H, Q);
|
|
1158
|
+
}, u = F(Os, f(r), n, qt(), t, i, s, o, c, l, v, d);
|
|
1159
|
+
return u.cache = D, a && (u.targetRefMethod = f(a)), X(yt(e), (O) => {
|
|
1160
|
+
Tt([
|
|
1161
|
+
"id",
|
|
1162
|
+
"behavior",
|
|
1163
|
+
"emitter",
|
|
1164
|
+
"entity",
|
|
1165
|
+
"retryError",
|
|
1166
|
+
"maxRetryTimes",
|
|
1167
|
+
"backoff",
|
|
1168
|
+
"resolveHandler",
|
|
1169
|
+
"rejectHandler",
|
|
1170
|
+
"handlerArgs",
|
|
1171
|
+
"targetRefMethod",
|
|
1172
|
+
"force"
|
|
1173
|
+
], O) || (u[O] = e[O]);
|
|
1174
|
+
}), u;
|
|
1175
|
+
}, Us = async () => {
|
|
1176
|
+
const e = await qe(he) || {}, t = {}, n = [];
|
|
1177
|
+
return X(yt(e), (r) => {
|
|
1178
|
+
const s = t[r] = t[r] || [];
|
|
1179
|
+
at(n, ...vt(e[r], async (o) => {
|
|
1180
|
+
const c = await qe(xn + o);
|
|
1181
|
+
c && at(s, Or(c));
|
|
1182
|
+
}));
|
|
1183
|
+
}), await Ut.all(n), t;
|
|
1184
|
+
};
|
|
1185
|
+
const to = (e) => Qt.on(ws, e), eo = (e) => Qt.on(Cs, e), no = (e) => Qt.on(Ps, e), so = (e) => Qt.on(Ms, e), ro = (e) => Qt.on(_s, e), oo = (e) => {
|
|
1186
|
+
if (ke === 0) {
|
|
1187
|
+
const { alova: t, delay: n = 500 } = e;
|
|
1188
|
+
_r(t), Cr(e.serializers), Pr(e.requestWait), jt(async () => {
|
|
1189
|
+
Dr(await Us()), X(yt(Vt), (r) => {
|
|
1190
|
+
Ts(Vt[r], r);
|
|
1191
|
+
}), ys(1), Qt.emit(ws, p);
|
|
1192
|
+
}, n);
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
let Qe = p;
|
|
1196
|
+
var Ur = (e, t) => {
|
|
1197
|
+
const { behavior: n = "queue", queue: r = pe, retryError: s, maxRetryTimes: o, backoff: c } = t || {}, l = qt();
|
|
1198
|
+
let v, d, a = pe, i = w, f;
|
|
1199
|
+
return {
|
|
1200
|
+
c: (...g) => (yn(Y(e), "method handler must be a function. eg. useSQRequest(() => method)"), Hn({}), v = g, e(...g)),
|
|
1201
|
+
m: ({ method: g, args: H, cachedResponse: Q, proxyStates: b, config: _ }, V) => {
|
|
1202
|
+
const { silentDefaultResponse: q, vDataCaptured: K, force: j = w } = _, R = wt.spawn(g, H);
|
|
1203
|
+
d = re(n, [R]), a = re(r, [R]), i = re(j, [R]);
|
|
1204
|
+
const x = () => {
|
|
1205
|
+
Hn(v = p);
|
|
1206
|
+
};
|
|
1207
|
+
if (Y(K)) {
|
|
1208
|
+
let T = ne && N(yt(ne)) > 0;
|
|
1209
|
+
if (!T) {
|
|
1210
|
+
const { url: et, data: h } = g, { params: m, headers: A } = Ve(g);
|
|
1211
|
+
Nt({ url: et, params: m, data: h, headers: A }, (P) => (!T && (kt(P, w) || fe(wn, P)) && (T = D), P));
|
|
1212
|
+
}
|
|
1213
|
+
const J = T ? K(g) : p;
|
|
1214
|
+
if (J !== p)
|
|
1215
|
+
return x(), Ot(J);
|
|
1216
|
+
}
|
|
1217
|
+
if (d !== wr) {
|
|
1218
|
+
const T = () => {
|
|
1219
|
+
const h = F(Ut, (m, A) => {
|
|
1220
|
+
f = F(Os, g, d, l, p, !!i, s, o, c, m, A, v, ne && yt(ne)), x();
|
|
1221
|
+
});
|
|
1222
|
+
return mt(Ot(p), async () => {
|
|
1223
|
+
const m = () => F(xe, d, g, f, H);
|
|
1224
|
+
await Tr(
|
|
1225
|
+
f,
|
|
1226
|
+
// After the onFallback event is bound, even the silent behavior mode is no longer stored.
|
|
1227
|
+
// onFallback will be called synchronously, so it needs to be determined asynchronously whether there are fallbackHandlers
|
|
1228
|
+
N(l.eventMap.fallback || []) <= 0 && d === fn,
|
|
1229
|
+
a,
|
|
1230
|
+
// Execute the callback before putting it into the queue. If false is returned, it will prevent putting it into the queue.
|
|
1231
|
+
() => l.emit("beforePushQueue", m())
|
|
1232
|
+
) && l.emit("pushedQueue", m());
|
|
1233
|
+
}), h;
|
|
1234
|
+
};
|
|
1235
|
+
if (d === Rr) {
|
|
1236
|
+
const h = i || !Q;
|
|
1237
|
+
return h && (b.loading.v = D), h ? T() : mt(Ot(Q));
|
|
1238
|
+
}
|
|
1239
|
+
const J = T(), et = f.virtualResponse = Ds(Y(q) ? q() : p);
|
|
1240
|
+
return mt(J, (h) => {
|
|
1241
|
+
b.data.v = h;
|
|
1242
|
+
}), Ot(et);
|
|
1243
|
+
}
|
|
1244
|
+
return x(), V();
|
|
1245
|
+
},
|
|
1246
|
+
d: (g) => {
|
|
1247
|
+
g.onSuccess = Re(g.onSuccess, (H, Q) => {
|
|
1248
|
+
Qe = f, H(F(fr, d, Q.method, f, Q.args, Q.data));
|
|
1249
|
+
}), g.onError = Re(g.onError, (H, Q) => {
|
|
1250
|
+
H(F(ms, d, Q.method, f, Q.args, Q.error));
|
|
1251
|
+
}), g.onComplete = Re(g.onComplete, (H, Q) => {
|
|
1252
|
+
H(F(hr, d, Q.method, f, Q.args, Q.status, Q.data, Q.error));
|
|
1253
|
+
});
|
|
1254
|
+
},
|
|
1255
|
+
// event binding function
|
|
1256
|
+
b: {
|
|
1257
|
+
/**
|
|
1258
|
+
* Bind fallback event
|
|
1259
|
+
* @param handler Fallback event callback
|
|
1260
|
+
*/
|
|
1261
|
+
onFallback: (g) => {
|
|
1262
|
+
l.on("fallback", g);
|
|
1263
|
+
},
|
|
1264
|
+
/**
|
|
1265
|
+
* Event before binding to queue
|
|
1266
|
+
* @param handler Event callback before enqueuing
|
|
1267
|
+
*/
|
|
1268
|
+
onBeforePushQueue: (g) => {
|
|
1269
|
+
l.on("beforePushQueue", g);
|
|
1270
|
+
},
|
|
1271
|
+
/**
|
|
1272
|
+
* Event after binding to queue
|
|
1273
|
+
* @param handler Event callback after being queued
|
|
1274
|
+
*/
|
|
1275
|
+
onPushedQueue: (g) => {
|
|
1276
|
+
l.on("pushedQueue", g);
|
|
1277
|
+
},
|
|
1278
|
+
/**
|
|
1279
|
+
* retry event
|
|
1280
|
+
* @param handler Retry event callback
|
|
1281
|
+
*/
|
|
1282
|
+
onRetry: (g) => {
|
|
1283
|
+
l.on("retry", g);
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
};
|
|
1288
|
+
function ao(e, t = {}) {
|
|
1289
|
+
const { exposeProvider: n, __referingObj: r } = Ft(Rt()), { middleware: s = Z } = t, { c: o, m: c, b: l, d: v } = Ur(e, t), d = Ee(o, {
|
|
1290
|
+
...t,
|
|
1291
|
+
__referingObj: r,
|
|
1292
|
+
middleware: (a, i) => {
|
|
1293
|
+
const f = c(a, i);
|
|
1294
|
+
return s(a, () => f), f;
|
|
1295
|
+
}
|
|
1296
|
+
});
|
|
1297
|
+
return v(d), n({
|
|
1298
|
+
...d,
|
|
1299
|
+
...l
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
var co = (e, t) => e === t ? D : kt(e) === kt(t);
|
|
1303
|
+
const Qr = async (e, t = pe, n = w) => {
|
|
1304
|
+
const r = (s = []) => s.filter((o) => {
|
|
1305
|
+
if (e === p)
|
|
1306
|
+
return D;
|
|
1307
|
+
const c = Ve(o.entity).name || "";
|
|
1308
|
+
return (k(e, RegExp) ? fe(e, c) : c === e) && (n ? o.active : D);
|
|
1309
|
+
});
|
|
1310
|
+
return [
|
|
1311
|
+
...r(Vt[t]),
|
|
1312
|
+
// If the silent factory is not currently started, you also need to match the silent methods in the persistent storage.
|
|
1313
|
+
...ke === 0 ? r((await Us())[t]) : []
|
|
1314
|
+
];
|
|
1315
|
+
}, io = async (e, t = pe, n = w) => (await Qr(e, t, n))[0];
|
|
1316
|
+
var lo = (e) => !!kt(e, w) || fe(wn, e);
|
|
1317
|
+
const uo = async (e, t) => (Qe && (Qe.setUpdateState(e, Y(Ue) ? p : yt(Ue)), await Qe.save()), Ue(e, t));
|
|
1318
|
+
class De {
|
|
1319
|
+
constructor(t, n = {}) {
|
|
1320
|
+
var r, s, o;
|
|
1321
|
+
this.cancelBubble = w, this.currentTarget = Wt, this.defaultPrevented = w, this.eventPhase = 0, this.isTrusted = w, this.returnValue = D, this.srcElement = Wt, this.target = Wt, this.NONE = 0, this.CAPTURING_PHASE = 1, this.AT_TARGET = 2, this.BUBBLING_PHASE = 3, this.type = t, this.bubbles = (r = n.bubbles) !== null && r !== void 0 ? r : !1, this.cancelable = (s = n.cancelable) !== null && s !== void 0 ? s : !1, this.composed = (o = n.composed) !== null && o !== void 0 ? o : !1, this.timeStamp = Date.now();
|
|
1322
|
+
}
|
|
1323
|
+
// Event 标准方法
|
|
1324
|
+
preventDefault() {
|
|
1325
|
+
this.cancelable && (this.defaultPrevented = !0);
|
|
1326
|
+
}
|
|
1327
|
+
stopImmediatePropagation() {
|
|
1328
|
+
}
|
|
1329
|
+
stopPropagation() {
|
|
1330
|
+
this.cancelBubble = !0;
|
|
1331
|
+
}
|
|
1332
|
+
composedPath() {
|
|
1333
|
+
return [];
|
|
1334
|
+
}
|
|
1335
|
+
initEvent(t, n, r) {
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
De.NONE = 0;
|
|
1339
|
+
De.CAPTURING_PHASE = 1;
|
|
1340
|
+
De.AT_TARGET = 2;
|
|
1341
|
+
De.BUBBLING_PHASE = 3;
|
|
1342
|
+
const Ir = typeof Event < "u" ? Event : De;
|
|
1343
|
+
class en extends Ir {
|
|
1344
|
+
constructor(t, n) {
|
|
1345
|
+
super(t, {
|
|
1346
|
+
bubbles: D,
|
|
1347
|
+
cancelable: D,
|
|
1348
|
+
composed: D
|
|
1349
|
+
}), this.data = n.data, this.lastEventId = n.lastEventId, this.origin = n.origin || "", this.error = n.error;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
class Dn extends wt {
|
|
1353
|
+
constructor(t, n) {
|
|
1354
|
+
super(t.method, t.args), this.eventSource = n;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
class Vr extends Dn {
|
|
1358
|
+
constructor(t, n) {
|
|
1359
|
+
super(t, t.eventSource), this.error = n;
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
class jr extends Dn {
|
|
1363
|
+
constructor(t, n) {
|
|
1364
|
+
super(t, t.eventSource), this.data = n;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
const kn = _t("EventSourceFetch");
|
|
1368
|
+
class dt {
|
|
1369
|
+
/**
|
|
1370
|
+
* Creates a new EventSourceFetch instance
|
|
1371
|
+
*
|
|
1372
|
+
* @param url The URL to connect to
|
|
1373
|
+
* @param options Configuration options (includes all fetch options plus EventSource specific options)
|
|
1374
|
+
*/
|
|
1375
|
+
constructor(t, n, r = {}) {
|
|
1376
|
+
this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, this.onopen = null, this.onmessage = null, this.onerror = null, this._listeners = {}, this._reconnectTime = null, this._controller = null, this._lastEventId = "", this._origin = "", this.url = t, this.readyState = dt.CONNECTING, this._options = { ...r }, this._reconnectTime = n;
|
|
1377
|
+
const s = F(URL, t, window.location.href);
|
|
1378
|
+
this._origin = s.origin, t && jt(() => this._connect());
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Adds an event listener for the specified event
|
|
1382
|
+
*
|
|
1383
|
+
* @param type Event type to listen for
|
|
1384
|
+
* @param listener Function or object to call when event is received
|
|
1385
|
+
* @param options EventListener options
|
|
1386
|
+
*/
|
|
1387
|
+
addEventListener(t, n) {
|
|
1388
|
+
this._listeners[t] = this._listeners[t] || [], this._listeners[t].find((s) => s === n || bt(s) && bt(n) && s?.handleEvent === n.handleEvent) || this._listeners[t].push(n);
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Removes an event listener for the specified event
|
|
1392
|
+
*
|
|
1393
|
+
* @param type Event type to remove listener from
|
|
1394
|
+
* @param listener Function to remove
|
|
1395
|
+
* @param options EventListener options
|
|
1396
|
+
*/
|
|
1397
|
+
removeEventListener(t, n) {
|
|
1398
|
+
!n || !this._listeners[t] || (this._listeners[t] = Dt(this._listeners[t], (r) => r !== n && !(typeof r == "object" && typeof n == "object" && r?.handleEvent === n.handleEvent)));
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Dispatches an event
|
|
1402
|
+
*
|
|
1403
|
+
* @param event Event to dispatch
|
|
1404
|
+
* @returns Whether preventDefault was called
|
|
1405
|
+
*/
|
|
1406
|
+
dispatchEvent(t) {
|
|
1407
|
+
if (!(t instanceof en))
|
|
1408
|
+
return D;
|
|
1409
|
+
const n = this._listeners[t.type] || [];
|
|
1410
|
+
for (const o of n)
|
|
1411
|
+
Y(o) ? o(t) : o && Y(o.handleEvent) && o.handleEvent(t);
|
|
1412
|
+
const r = `on${t.type}`, s = this[r];
|
|
1413
|
+
return Y(s) && s(t), !t.defaultPrevented;
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* Closes the connection
|
|
1417
|
+
*/
|
|
1418
|
+
close() {
|
|
1419
|
+
this.readyState !== dt.CLOSED && (this.readyState = dt.CLOSED, this._dispatchEvent("close", ""), this._controller && (this._controller.abort(), this._controller = null));
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Establishes connection to the event source
|
|
1423
|
+
*/
|
|
1424
|
+
_connect() {
|
|
1425
|
+
if (this.readyState === dt.CLOSED)
|
|
1426
|
+
return;
|
|
1427
|
+
this._controller = F(AbortController);
|
|
1428
|
+
const t = this._options, n = t.headers || {}, r = ["Accept", "text/event-stream"], s = "Last-Event-ID", o = this._lastEventId;
|
|
1429
|
+
if (lt(n))
|
|
1430
|
+
at(n, r), o && at(n, [s, o]);
|
|
1431
|
+
else if (k(n, Headers))
|
|
1432
|
+
n.append(r[0], r[1]), o && n.append(s, o);
|
|
1433
|
+
else if (bt(n)) {
|
|
1434
|
+
const [l, v] = r;
|
|
1435
|
+
n[l] = v, o && (n[s] = o);
|
|
1436
|
+
}
|
|
1437
|
+
const c = {
|
|
1438
|
+
...t,
|
|
1439
|
+
headers: n,
|
|
1440
|
+
signal: this._controller.signal
|
|
1441
|
+
};
|
|
1442
|
+
fetch(this.url, c).then((l) => {
|
|
1443
|
+
kn(l.ok, `HTTP error: ${l.status}`), kn(l.body, "ReadableStream not supported");
|
|
1444
|
+
const v = F(URL, l.url);
|
|
1445
|
+
this._origin = v.origin, this.readyState = dt.OPEN, this._dispatchEvent("open", "");
|
|
1446
|
+
const d = l.body.getReader(), a = new TextDecoder();
|
|
1447
|
+
let i = "";
|
|
1448
|
+
const f = ({ done: u, value: O }) => {
|
|
1449
|
+
if (u)
|
|
1450
|
+
return this.readyState !== dt.CLOSED && this._reconnect(), Ot();
|
|
1451
|
+
i += a.decode(O, { stream: !0 });
|
|
1452
|
+
const I = i.split(/\r\n|\r|\n/);
|
|
1453
|
+
return i = I.pop() || "", this._processEventStream(I), d.read().then(f).catch((g) => (g.name !== "AbortError" && this.readyState !== dt.CLOSED && this._onError(g), Ot()));
|
|
1454
|
+
};
|
|
1455
|
+
return d.read().then(f).catch((u) => {
|
|
1456
|
+
u.name !== "AbortError" && this.readyState !== dt.CLOSED && this._onError(u);
|
|
1457
|
+
});
|
|
1458
|
+
}).catch((l) => {
|
|
1459
|
+
l.name !== "AbortError" && this.readyState !== dt.CLOSED && this._onError(l);
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* Processes received event stream lines
|
|
1464
|
+
*
|
|
1465
|
+
* @param lines Lines received from the event stream
|
|
1466
|
+
*/
|
|
1467
|
+
_processEventStream(t) {
|
|
1468
|
+
let n = "message", r = "", s = null, o = null;
|
|
1469
|
+
const c = () => {
|
|
1470
|
+
if (r) {
|
|
1471
|
+
if (r.endsWith(`
|
|
1472
|
+
`) && (r = r.substring(0, r.length - 1)), s !== null && (this._lastEventId = s), o !== null && this._reconnectTime === null) {
|
|
1473
|
+
const l = parseInt(o, 10);
|
|
1474
|
+
Number.isNaN(l) || (this._reconnectTime = l);
|
|
1475
|
+
}
|
|
1476
|
+
this._dispatchEvent(n, r);
|
|
1477
|
+
}
|
|
1478
|
+
n = "message", r = "", s = null, o = null;
|
|
1479
|
+
};
|
|
1480
|
+
for (const l of t) {
|
|
1481
|
+
if (l === "") {
|
|
1482
|
+
c();
|
|
1483
|
+
continue;
|
|
1484
|
+
}
|
|
1485
|
+
if (l.startsWith(":"))
|
|
1486
|
+
continue;
|
|
1487
|
+
let v, d;
|
|
1488
|
+
const a = l.indexOf(":");
|
|
1489
|
+
switch (a === -1 ? (v = l, d = "") : (v = l.slice(0, a), d = l.slice(a + (l[a + 1] === " " ? 2 : 1))), v) {
|
|
1490
|
+
case "event":
|
|
1491
|
+
n = d;
|
|
1492
|
+
break;
|
|
1493
|
+
case "data":
|
|
1494
|
+
r = r ? `${r}
|
|
1495
|
+
${d}` : d;
|
|
1496
|
+
break;
|
|
1497
|
+
case "id":
|
|
1498
|
+
if (d.includes("\0"))
|
|
1499
|
+
continue;
|
|
1500
|
+
s = d;
|
|
1501
|
+
break;
|
|
1502
|
+
case "retry":
|
|
1503
|
+
o = d;
|
|
1504
|
+
break;
|
|
1505
|
+
default:
|
|
1506
|
+
throw F($e, "EventSource", `EventSource: Unknown field "${v}", ignoring`);
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* Dispatches an event
|
|
1512
|
+
*
|
|
1513
|
+
* @param type Event type
|
|
1514
|
+
* @param data Event data
|
|
1515
|
+
*/
|
|
1516
|
+
_dispatchEvent(t, n) {
|
|
1517
|
+
const r = F(en, t, {
|
|
1518
|
+
type: t,
|
|
1519
|
+
data: n,
|
|
1520
|
+
lastEventId: this._lastEventId,
|
|
1521
|
+
origin: this._origin
|
|
1522
|
+
});
|
|
1523
|
+
this.dispatchEvent(r);
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Handles errors
|
|
1527
|
+
*
|
|
1528
|
+
* @param error Error object
|
|
1529
|
+
*/
|
|
1530
|
+
_onError(t) {
|
|
1531
|
+
const n = F(en, "error", {
|
|
1532
|
+
type: "error",
|
|
1533
|
+
data: "",
|
|
1534
|
+
lastEventId: this._lastEventId,
|
|
1535
|
+
origin: this._origin,
|
|
1536
|
+
error: t
|
|
1537
|
+
});
|
|
1538
|
+
this.dispatchEvent(n), this.readyState !== dt.CLOSED && this._reconnect();
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Attempts to reconnect after connection closed or error
|
|
1542
|
+
*/
|
|
1543
|
+
_reconnect() {
|
|
1544
|
+
var t;
|
|
1545
|
+
if (this._reconnectTime !== null && this._reconnectTime <= 0) {
|
|
1546
|
+
this.close();
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
if (this.readyState !== dt.CLOSED) {
|
|
1550
|
+
this.readyState = dt.CONNECTING;
|
|
1551
|
+
const n = (t = this._reconnectTime) !== null && t !== void 0 ? t : 1e3;
|
|
1552
|
+
jt(() => this._connect(), n);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
dt.CONNECTING = 0;
|
|
1557
|
+
dt.OPEN = 1;
|
|
1558
|
+
dt.CLOSED = 2;
|
|
1559
|
+
const nn = Symbol("SSEOpen"), Te = Symbol("SSEMessage"), sn = Symbol("SSEError");
|
|
1560
|
+
var Zt;
|
|
1561
|
+
(function(e) {
|
|
1562
|
+
e[e.CONNECTING = 0] = "CONNECTING", e[e.OPEN = 1] = "OPEN", e[e.CLOSED = 2] = "CLOSED";
|
|
1563
|
+
})(Zt || (Zt = {}));
|
|
1564
|
+
const Qs = "useSSE", Br = _t(Qs);
|
|
1565
|
+
var St;
|
|
1566
|
+
(function(e) {
|
|
1567
|
+
e.Open = "open", e.Error = "error", e.Message = "message", e.Close = "close";
|
|
1568
|
+
})(St || (St = {}));
|
|
1569
|
+
var fo = (e, t = {}) => {
|
|
1570
|
+
const {
|
|
1571
|
+
initialData: n,
|
|
1572
|
+
withCredentials: r,
|
|
1573
|
+
interceptByGlobalResponded: s = D,
|
|
1574
|
+
/** abortLast = trueValue, */
|
|
1575
|
+
immediate: o = w,
|
|
1576
|
+
responseType: c = "text",
|
|
1577
|
+
reconnectionTime: l = null,
|
|
1578
|
+
...v
|
|
1579
|
+
} = t, d = D, { create: a, ref: i, onMounted: f, onUnmounted: u, objectify: O, exposeProvider: I, memorize: g } = Ft(Rt()), H = i([]), Q = i(p), b = i(p), _ = a(n, "data"), V = a(Zt.CLOSED, "readyState"), q = a(p, "eventSource");
|
|
1580
|
+
let K = qn(e), j;
|
|
1581
|
+
const R = qt(), x = i(/* @__PURE__ */ new Map()), T = (L) => {
|
|
1582
|
+
R.on(nn, L);
|
|
1583
|
+
}, J = (L) => {
|
|
1584
|
+
R.on(Te, L);
|
|
1585
|
+
}, et = (L) => {
|
|
1586
|
+
R.on(sn, L);
|
|
1587
|
+
}, h = i(se), m = i(Nn), A = i(Z), P = (L) => {
|
|
1588
|
+
const { responded: B } = Ys(L);
|
|
1589
|
+
if (j = B, Y(j))
|
|
1590
|
+
h.current = j;
|
|
1591
|
+
else if (j && oe(j)) {
|
|
1592
|
+
const { onSuccess: W, onError: nt, onComplete: ut } = j;
|
|
1593
|
+
h.current = Y(W) ? W : h.current, m.current = Y(nt) ? nt : m.current, A.current = Y(ut) ? ut : A.current;
|
|
1594
|
+
}
|
|
1595
|
+
}, M = async (L) => {
|
|
1596
|
+
const { headers: B, transform: W = se } = Ve(K), nt = await L, ut = await W(nt, B || {});
|
|
1597
|
+
return _.v = ut, nr(K), ut;
|
|
1598
|
+
}, y = async (L, B) => {
|
|
1599
|
+
Br(Q.current, "EventSource is not initialized");
|
|
1600
|
+
const W = Q.current, nt = F(Dn, wt.spawn(K, H.current), W);
|
|
1601
|
+
if (L === St.Open)
|
|
1602
|
+
return nt;
|
|
1603
|
+
const ut = s ? h.current : se, Lt = s ? m.current : Nn, zt = s ? A.current : Z, Pt = Pe(B);
|
|
1604
|
+
if (c === "json" && Pt)
|
|
1605
|
+
try {
|
|
1606
|
+
B = Js(B);
|
|
1607
|
+
} catch (pt) {
|
|
1608
|
+
throw F($e, Qs, pt.message);
|
|
1609
|
+
}
|
|
1610
|
+
const Bt = ue(mt(Pt ? Ot(B) : as(B), (pt) => M(ut(pt, K)), (pt) => M(Lt(pt, K))), () => {
|
|
1611
|
+
zt(K);
|
|
1612
|
+
});
|
|
1613
|
+
return mt(
|
|
1614
|
+
Bt,
|
|
1615
|
+
// Get processed data (data after transform)
|
|
1616
|
+
(pt) => F(jr, nt, pt),
|
|
1617
|
+
// There is an error
|
|
1618
|
+
(pt) => new Vr(nt, pt)
|
|
1619
|
+
);
|
|
1620
|
+
}, C = (L) => (B) => B.error === p ? L(B) : R.emit(sn, B), z = (L, B) => {
|
|
1621
|
+
var W;
|
|
1622
|
+
const nt = x.current;
|
|
1623
|
+
if (!nt.has(L)) {
|
|
1624
|
+
const Lt = sr((Pt) => {
|
|
1625
|
+
var Bt;
|
|
1626
|
+
Pt.length === 0 && ((Bt = Q.current) === null || Bt === void 0 || Bt.removeEventListener(L, Lt[1]), x.current.delete(L));
|
|
1627
|
+
}), zt = Lt[1];
|
|
1628
|
+
nt.set(L, Lt), (W = Q.current) === null || W === void 0 || W.addEventListener(L, (Pt) => {
|
|
1629
|
+
mt(y(L, Pt.data), C(zt));
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
const [ut] = nt.get(L);
|
|
1633
|
+
return ut(B);
|
|
1634
|
+
}, $ = () => {
|
|
1635
|
+
x.current.forEach(([L, B, W]) => {
|
|
1636
|
+
W();
|
|
1637
|
+
});
|
|
1638
|
+
}, ot = g(() => {
|
|
1639
|
+
var L;
|
|
1640
|
+
V.v = Zt.OPEN, mt(y(St.Open), (B) => R.emit(nn, B)), (L = b.current) === null || L === void 0 || L.resolve();
|
|
1641
|
+
}), ht = g((L) => {
|
|
1642
|
+
var B;
|
|
1643
|
+
V.v = Zt.CLOSED, mt(y(St.Error, L.error || F(Error, "SSE Error")), C((W) => R.emit(Te, W))), (B = b.current) === null || B === void 0 || B.resolve();
|
|
1644
|
+
}), Et = g((L) => {
|
|
1645
|
+
mt(y(St.Message, L.data), C((B) => R.emit(Te, B)));
|
|
1646
|
+
}), ct = () => {
|
|
1647
|
+
const L = Q.current;
|
|
1648
|
+
L && (b.current && b.current.resolve(), L.close(), L.removeEventListener(St.Open, ot), L.removeEventListener(St.Error, ht), L.removeEventListener(St.Message, Et), L.removeEventListener(St.Close, ct), V.v = Zt.CLOSED, x.current.forEach(([B, W], nt) => {
|
|
1649
|
+
L.removeEventListener(nt, W);
|
|
1650
|
+
}));
|
|
1651
|
+
}, Ct = (...L) => {
|
|
1652
|
+
let B = Q.current, W = b.current;
|
|
1653
|
+
B && d && ct(), W || (W = b.current = Ce(), W && ue(W.promise, () => {
|
|
1654
|
+
W = p;
|
|
1655
|
+
})), H.current = L, K = qn(e, L), P(K);
|
|
1656
|
+
const { params: nt, headers: ut } = Ve(K), { baseURL: Lt, url: zt, data: Pt, type: Bt } = K, pt = Xs(Lt, zt, nt);
|
|
1657
|
+
return B = F(dt, pt, l, {
|
|
1658
|
+
credentials: r ? "include" : "same-origin",
|
|
1659
|
+
method: Bt || "GET",
|
|
1660
|
+
headers: ut,
|
|
1661
|
+
body: ((Yt) => Pe(Yt) || Zs(Yt))(Pt) ? Pt : tr(Pt),
|
|
1662
|
+
...v
|
|
1663
|
+
}), Q.current = B, q.v = B, V.v = Zt.CONNECTING, B.addEventListener(St.Open, ot), B.addEventListener(St.Error, ht), B.addEventListener(St.Message, Et), B.addEventListener(St.Close, ct), x.current.forEach(([Yt, Se], ae) => {
|
|
1664
|
+
B?.addEventListener(ae, (ce) => {
|
|
1665
|
+
mt(y(ae, ce.data), C(Se));
|
|
1666
|
+
});
|
|
1667
|
+
}), W.promise;
|
|
1668
|
+
};
|
|
1669
|
+
return u(() => {
|
|
1670
|
+
ct(), R.off(nn), R.off(Te), R.off(sn), $();
|
|
1671
|
+
}), f(() => {
|
|
1672
|
+
var L;
|
|
1673
|
+
o && (Ct(), (L = b.current) === null || L === void 0 || L.promise.catch(() => {
|
|
1674
|
+
}));
|
|
1675
|
+
}), I({
|
|
1676
|
+
send: Ct,
|
|
1677
|
+
close: ct,
|
|
1678
|
+
on: z,
|
|
1679
|
+
onMessage: J,
|
|
1680
|
+
onError: et,
|
|
1681
|
+
onOpen: T,
|
|
1682
|
+
...O([V, _, q])
|
|
1683
|
+
});
|
|
1684
|
+
};
|
|
1685
|
+
const le = _t("useUploader");
|
|
1686
|
+
function ze(e, { limit: t = 0, localLink: n, replaceSrc: r, mode: s } = {}) {
|
|
1687
|
+
const { create: o, computed: c, exposeProvider: l, ref: v } = Ft(Rt()), d = qt(), a = o([], "fileList"), i = c(() => a.v[0], [a], "file"), f = o(!1, "uploading"), u = o(0, "successCount"), O = o(0, "failCount"), I = c(() => ({
|
|
1688
|
+
...a.v.reduce((h, { progress: m, status: A }) => (A !== 0 && (h.total += m.total, h.uploaded += m.uploaded), h), {
|
|
1689
|
+
uploaded: 0,
|
|
1690
|
+
total: 0
|
|
1691
|
+
})
|
|
1692
|
+
}), [a], "progress"), g = c(() => {
|
|
1693
|
+
var h;
|
|
1694
|
+
return (h = a.v.find((m) => m.error)) === null || h === void 0 ? void 0 : h.error;
|
|
1695
|
+
}, [a], "error"), H = async (h = {}, m = {}) => {
|
|
1696
|
+
var A;
|
|
1697
|
+
let P = h, M = m;
|
|
1698
|
+
!h.file && !lt(h) && (M = h, P = []);
|
|
1699
|
+
let y = lt(P) ? P : [P];
|
|
1700
|
+
N(y) <= 0 && (y = await ze.selectFile(M)), le(t <= 0 || N(a.v) + N(y) <= t, `The number of files exceeds the limit of ${t}`);
|
|
1701
|
+
const { converters: C } = ze, z = await Ut.all(vt(y, async (Et) => {
|
|
1702
|
+
const ct = C.find(({ is: L }) => L(Et));
|
|
1703
|
+
le(ct, `Invalid file type, only ${vt(C, ({ name: L }) => L).join(", ")} are supported, if other file needs, customize convert function with \`useUploader.convertFile.push({ is: ..., convert: ... })\``);
|
|
1704
|
+
const Ct = await ct.convert(Et);
|
|
1705
|
+
return le(Ct, "Failed to convert file"), {
|
|
1706
|
+
src: Et.src || (n ? URL.createObjectURL(Ct) : void 0),
|
|
1707
|
+
file: Ct,
|
|
1708
|
+
status: 0,
|
|
1709
|
+
progress: { uploaded: 0, total: Ct.size }
|
|
1710
|
+
};
|
|
1711
|
+
})), $ = (A = M.start) !== null && A !== void 0 ? A : N(a.v), ot = Dt(z, Boolean), ht = [...a.v];
|
|
1712
|
+
return xt(ht, $, 0, ...ot), a.v = ht, N(z);
|
|
1713
|
+
}, Q = (h, m = [1, 2], A = "upload") => {
|
|
1714
|
+
const P = {
|
|
1715
|
+
upload: "uploaded",
|
|
1716
|
+
abort: "aborted"
|
|
1717
|
+
}[A], M = a.v;
|
|
1718
|
+
return N(h) > 0 ? vt(h, (y, C) => {
|
|
1719
|
+
const z = At(y), $ = z ? M[y] : y, ot = z ? `index ${y}` : `position ${C}`;
|
|
1720
|
+
return le($, `The file of ${ot} does not exist`), N(m) > 0 && le(!Tt(m, $.status) && bt($.file), `The file of ${ot} cannot be ${P}, which status is ${$.status}`), $;
|
|
1721
|
+
}) : Dt(M, (y) => !Tt(m, y.status));
|
|
1722
|
+
}, b = (h, m) => Dt(h, (A) => N(m) > 0 ? Tt(m, A.status) : D), _ = v([]), V = (h, m) => {
|
|
1723
|
+
a.v.findIndex((P) => P.file === h) > -1 && at(_.current, { f: h, m });
|
|
1724
|
+
}, q = (h) => {
|
|
1725
|
+
_.current = Dt(_.current, ({ m }) => m !== h);
|
|
1726
|
+
}, K = (...h) => {
|
|
1727
|
+
const m = Q(h, [0, 2, 3], "abort"), A = [];
|
|
1728
|
+
N(m) > 0 ? X(m, ({ file: M }) => {
|
|
1729
|
+
const y = _.current.find(({ f: C }) => C === M);
|
|
1730
|
+
y && at(A, y.m);
|
|
1731
|
+
}) : at(A, ...vt(_.current, ({ m: M }) => M));
|
|
1732
|
+
const P = [];
|
|
1733
|
+
X(A, (M) => {
|
|
1734
|
+
P.includes(M) || at(P, M);
|
|
1735
|
+
}), X(P, (M) => M.abort());
|
|
1736
|
+
}, j = (...h) => {
|
|
1737
|
+
const m = Q(h, []);
|
|
1738
|
+
N(m) > 0 ? (K(...b(m, [1])), a.v = Dt(a.v, (A) => !Tt(m, A)), u.v = N(b(a.v, [2])), O.v = N(b(a.v, [3]))) : (K(...b(a.v, [1])), a.v = []);
|
|
1739
|
+
}, R = (h, m, A) => {
|
|
1740
|
+
const P = wt.spawn(h, []);
|
|
1741
|
+
return {
|
|
1742
|
+
successEvent: F(hs, P, m, w),
|
|
1743
|
+
errorEvent: F(En, P, A),
|
|
1744
|
+
completeEvent: F(dn, P, A ? ee : te, m, w, A)
|
|
1745
|
+
};
|
|
1746
|
+
}, x = (h, m, A, P, M = 0) => {
|
|
1747
|
+
if (h.status = m, m === 2) {
|
|
1748
|
+
if (h.progress.uploaded = h.progress.total, r) {
|
|
1749
|
+
const y = r(A, M);
|
|
1750
|
+
y && (h.src = y);
|
|
1751
|
+
}
|
|
1752
|
+
} else m === 3 && (h.error = P);
|
|
1753
|
+
a.v = [...a.v];
|
|
1754
|
+
}, T = (h, m) => {
|
|
1755
|
+
const A = e(m);
|
|
1756
|
+
return A.onUpload((P) => {
|
|
1757
|
+
X(h, (M) => {
|
|
1758
|
+
M.progress.uploaded = P.loaded * (M.progress.total / P.total);
|
|
1759
|
+
});
|
|
1760
|
+
}), X(h, ({ file: P }) => V(P, A)), A.then((P) => {
|
|
1761
|
+
X(h, (C, z) => x(C, 2, P, void 0, z)), u.v = N(b(a.v, [2]));
|
|
1762
|
+
const { successEvent: M, completeEvent: y } = R(A, P);
|
|
1763
|
+
return d.emit(te, M), d.emit(Gt, y), P;
|
|
1764
|
+
}, (P) => {
|
|
1765
|
+
X(h, (C) => x(C, 3, void 0, P)), O.v = N(b(a.v, [3]));
|
|
1766
|
+
const { errorEvent: M, completeEvent: y } = R(A, void 0, P);
|
|
1767
|
+
return d.emit(ee, M), d.emit(Gt, y), P;
|
|
1768
|
+
}).finally(() => {
|
|
1769
|
+
f.v = !1, q(A);
|
|
1770
|
+
});
|
|
1771
|
+
}, J = (h) => {
|
|
1772
|
+
const m = vt(h, (A, P) => {
|
|
1773
|
+
const M = e({ file: A.file, name: A.file.name });
|
|
1774
|
+
return M.onUpload(({ loaded: y, total: C }) => {
|
|
1775
|
+
X(h, (z) => {
|
|
1776
|
+
z.progress.uploaded = y, z.progress.total = C;
|
|
1777
|
+
});
|
|
1778
|
+
}), V(A.file, M), M.then((y) => {
|
|
1779
|
+
x(A, 2, y, p, P), u.v += 1;
|
|
1780
|
+
const { successEvent: C, completeEvent: z } = R(M, y);
|
|
1781
|
+
return d.emit(te, C), d.emit(Gt, z), y;
|
|
1782
|
+
}, (y) => {
|
|
1783
|
+
x(A, 3, p, y), O.v += 1;
|
|
1784
|
+
const { errorEvent: C, completeEvent: z } = R(M, p, y);
|
|
1785
|
+
return d.emit(ee, C), d.emit(Gt, z), y;
|
|
1786
|
+
}).finally(() => {
|
|
1787
|
+
q(M);
|
|
1788
|
+
});
|
|
1789
|
+
});
|
|
1790
|
+
return ue(Ut.all(m), () => {
|
|
1791
|
+
f.v = w;
|
|
1792
|
+
});
|
|
1793
|
+
};
|
|
1794
|
+
return l({
|
|
1795
|
+
fileList: a,
|
|
1796
|
+
uploading: f,
|
|
1797
|
+
file: i,
|
|
1798
|
+
progress: I,
|
|
1799
|
+
successCount: u,
|
|
1800
|
+
failCount: O,
|
|
1801
|
+
error: g,
|
|
1802
|
+
appendFiles: H,
|
|
1803
|
+
removeFiles: j,
|
|
1804
|
+
upload: async (...h) => {
|
|
1805
|
+
const m = Q(h);
|
|
1806
|
+
X(m, (P) => {
|
|
1807
|
+
P.status = 1;
|
|
1808
|
+
});
|
|
1809
|
+
const A = vt(m, ({ file: P }) => ({
|
|
1810
|
+
file: P,
|
|
1811
|
+
name: P.name
|
|
1812
|
+
}));
|
|
1813
|
+
return f.v = D, s === "batch" ? T(m, A) : J(m);
|
|
1814
|
+
},
|
|
1815
|
+
abort: K,
|
|
1816
|
+
onSuccess: (h) => {
|
|
1817
|
+
d.on(te, h);
|
|
1818
|
+
},
|
|
1819
|
+
onError: (h) => {
|
|
1820
|
+
d.on(ee, h);
|
|
1821
|
+
},
|
|
1822
|
+
onComplete: (h) => {
|
|
1823
|
+
d.on(Gt, h);
|
|
1824
|
+
}
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
ze.selectFile = ({ multiple: e, accept: t } = {}) => {
|
|
1828
|
+
const n = document.createElement("input");
|
|
1829
|
+
return n.type = "file", n.multiple = !!e, t && (n.accept = t), n.click(), F(Promise, (r) => {
|
|
1830
|
+
n.addEventListener("change", () => {
|
|
1831
|
+
const s = vt(Array.from(n.files || []), (o) => ({
|
|
1832
|
+
file: o,
|
|
1833
|
+
name: o.name,
|
|
1834
|
+
mimeType: o.type
|
|
1835
|
+
}));
|
|
1836
|
+
r(s);
|
|
1837
|
+
});
|
|
1838
|
+
});
|
|
1839
|
+
};
|
|
1840
|
+
const rn = "text/plain";
|
|
1841
|
+
ze.converters = [
|
|
1842
|
+
{
|
|
1843
|
+
name: "HTMLCanvasElement",
|
|
1844
|
+
is: ({ file: e }) => k(e, HTMLCanvasElement),
|
|
1845
|
+
async convert({ file: e, mimeType: t, name: n }) {
|
|
1846
|
+
const r = await F(Ut, (s) => e?.toBlob(s));
|
|
1847
|
+
if (r)
|
|
1848
|
+
return F(File, [r], n || "image.png", {
|
|
1849
|
+
type: t || r.type
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
},
|
|
1853
|
+
{
|
|
1854
|
+
name: "base64",
|
|
1855
|
+
is: ({ file: e }) => Pe(e),
|
|
1856
|
+
convert({ file: e = "", mimeType: t, name: n }) {
|
|
1857
|
+
var r;
|
|
1858
|
+
le(/data:.+;base64,/.test(e), "Invalid base64 string");
|
|
1859
|
+
const s = e.split(","), o = (r = s[0].match(/:(.*?);/)) === null || r === void 0 ? void 0 : r[1], c = atob(s[1]), l = new Uint8Array(N(c));
|
|
1860
|
+
return X(Array.from(c), (v, d) => {
|
|
1861
|
+
l[d] = v.charCodeAt(0);
|
|
1862
|
+
}), F(File, [l], n || "file", {
|
|
1863
|
+
type: t || o || rn
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
},
|
|
1867
|
+
{
|
|
1868
|
+
name: "File",
|
|
1869
|
+
is: ({ file: e }) => k(e, File),
|
|
1870
|
+
convert({ file: e }) {
|
|
1871
|
+
return e;
|
|
1872
|
+
}
|
|
1873
|
+
},
|
|
1874
|
+
{
|
|
1875
|
+
name: "Blob",
|
|
1876
|
+
is: ({ file: e }) => k(e, Blob),
|
|
1877
|
+
convert({ file: e, name: t, mimeType: n }) {
|
|
1878
|
+
return F(File, [e], t || "file", {
|
|
1879
|
+
type: n || e.type || rn
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1882
|
+
},
|
|
1883
|
+
{
|
|
1884
|
+
name: "ArrayBuffer",
|
|
1885
|
+
is: ({ file: e }) => k(e, ArrayBuffer),
|
|
1886
|
+
convert({ file: e, name: t, mimeType: n }) {
|
|
1887
|
+
return F(File, [F(Blob, [e])], t || "file", {
|
|
1888
|
+
type: n || rn
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
];
|
|
1893
|
+
const Ht = (e, t = {}) => {
|
|
1894
|
+
let n = D;
|
|
1895
|
+
const { enableFocus: r = D, enableVisibility: s = D, enableNetwork: o = D, pollingTime: c = 0, throttle: l = 1e3 } = t, { onMounted: v, onUnmounted: d, __referingObj: a } = Ft(Rt()), i = Ee(e, {
|
|
1896
|
+
...t,
|
|
1897
|
+
__referingObj: a
|
|
1898
|
+
}), f = () => {
|
|
1899
|
+
n && (i.send(), l > 0 && (n = w, setTimeout(() => {
|
|
1900
|
+
n = D;
|
|
1901
|
+
}, l)));
|
|
1902
|
+
};
|
|
1903
|
+
let u = Z, O = Z, I = Z, g = Z;
|
|
1904
|
+
return v(() => {
|
|
1905
|
+
cs.ssr || (u = o ? Ht.onNetwork(f, t) : u, O = r ? Ht.onFocus(f, t) : O, I = s ? Ht.onVisibility(f, t) : I, g = c > 0 ? Ht.onPolling(f, t) : g);
|
|
1906
|
+
}), d(() => {
|
|
1907
|
+
u(), O(), I(), g();
|
|
1908
|
+
}), i;
|
|
1909
|
+
}, Fn = (e, t) => (window.addEventListener(e, t), () => window.removeEventListener(e, t));
|
|
1910
|
+
Ht.onNetwork = (e) => Fn("online", e);
|
|
1911
|
+
Ht.onFocus = (e) => Fn("focus", e);
|
|
1912
|
+
Ht.onVisibility = (e) => Fn("visibilitychange", () => document.visibilityState === "visible" && e());
|
|
1913
|
+
Ht.onPolling = (e, t) => {
|
|
1914
|
+
const n = setInterval(e, t.pollingTime);
|
|
1915
|
+
return () => clearInterval(n);
|
|
1916
|
+
};
|
|
1917
|
+
const Is = "useCaptcha", Kr = _t(Is);
|
|
1918
|
+
var vo = (e, t = {}) => {
|
|
1919
|
+
const { initialCountdown: n, middleware: r } = t;
|
|
1920
|
+
Kr(n === p || n > 0, "initialCountdown must be greater than 0");
|
|
1921
|
+
const { create: s, ref: o, objectify: c, exposeProvider: l, __referingObj: v } = Ft(Rt()), d = s(0, "countdown"), a = Ee(e, {
|
|
1922
|
+
...t,
|
|
1923
|
+
__referingObj: v,
|
|
1924
|
+
immediate: w,
|
|
1925
|
+
managedStates: c([d], "s"),
|
|
1926
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
1927
|
+
middleware: r ? (u, O) => r({ ...u, send: f }, O) : p
|
|
1928
|
+
}), i = o(p), f = (...u) => F(Ut, (O, I) => {
|
|
1929
|
+
d.v <= 0 ? a.send(...u).then((g) => {
|
|
1930
|
+
d.v = t.initialCountdown || 60, i.current = setInterval(() => {
|
|
1931
|
+
d.v -= 1, d.v <= 0 && clearInterval(i.current);
|
|
1932
|
+
}, 1e3), O(g);
|
|
1933
|
+
}).catch((g) => I(g)) : I(F($e, Is, "the countdown is not over yet"));
|
|
1934
|
+
});
|
|
1935
|
+
return l({
|
|
1936
|
+
...a,
|
|
1937
|
+
send: f,
|
|
1938
|
+
...c([d])
|
|
1939
|
+
});
|
|
1940
|
+
};
|
|
1941
|
+
const Yn = Symbol("FormRestore"), Nr = (e) => `alova/form-${k(e, me) ? Kt(e) : e}`, Jn = qt(), ge = {}, Xn = (e) => {
|
|
1942
|
+
const t = (n) => lt(n) ? [...n] : oe(n) ? { ...n } : n;
|
|
1943
|
+
return Nt(t(e), t);
|
|
1944
|
+
};
|
|
1945
|
+
var ho = (e, t = {}) => {
|
|
1946
|
+
const { id: n } = t, r = n ? ge[n] : p, { id: s, initialForm: o, store: c, resetAfterSubmiting: l, immediate: v = w, middleware: d } = r?.config || t;
|
|
1947
|
+
Rt();
|
|
1948
|
+
const { create: a, ref: i, onMounted: f, onUnmounted: u, watch: O, objectify: I, exposeProvider: g, __referingObj: H } = Ft(Rt()), Q = oe(c), b = Q ? c.enable : c, _ = a(Xn(r?.form || o), "form"), V = e, q = qt(), K = i(p);
|
|
1949
|
+
let j = r?.l2Cache;
|
|
1950
|
+
b && !r?.l2Cache && (K.current = re(V, [_.v]), j = He(K.current).l2Cache);
|
|
1951
|
+
const R = Nr(s || K.current || ""), x = i(w), T = i(Rn(Q ? c.serializers : p));
|
|
1952
|
+
s && !ge[s] && (ge[s] = {
|
|
1953
|
+
form: _.v,
|
|
1954
|
+
l2Cache: j,
|
|
1955
|
+
config: t
|
|
1956
|
+
});
|
|
1957
|
+
const J = Ee((...y) => V(_.v, ...y), {
|
|
1958
|
+
...t,
|
|
1959
|
+
__referingObj: H,
|
|
1960
|
+
// Middleware function, also supports subscriber middleware
|
|
1961
|
+
middleware: d ? (y, C) => d({
|
|
1962
|
+
...y,
|
|
1963
|
+
// eslint-disable-next-line
|
|
1964
|
+
delegatingActions: { updateForm: h, reset: et }
|
|
1965
|
+
}, C) : p,
|
|
1966
|
+
// 1. When persistence is required, it will be triggered after data recovery
|
|
1967
|
+
// 2. When there is a shared state, it means that it has been initialized before (regardless of whether there is an immediate request), and subsequent requests will no longer be automatically initiated. This is to be compatible with the issue of repeated requests when multiple forms initiate requests immediately.
|
|
1968
|
+
immediate: b || r ? w : v
|
|
1969
|
+
}), et = () => {
|
|
1970
|
+
x.current = D;
|
|
1971
|
+
const y = Xn(o);
|
|
1972
|
+
y && (_.v = y), b && j?.remove(R);
|
|
1973
|
+
}, h = (y) => {
|
|
1974
|
+
_.v = {
|
|
1975
|
+
..._.v,
|
|
1976
|
+
...y
|
|
1977
|
+
};
|
|
1978
|
+
}, m = g({
|
|
1979
|
+
// The first parameter is fixed to form data
|
|
1980
|
+
...J,
|
|
1981
|
+
...I([_]),
|
|
1982
|
+
updateForm: h,
|
|
1983
|
+
reset: et,
|
|
1984
|
+
// Persistent data recovery event binding
|
|
1985
|
+
onRestore(y) {
|
|
1986
|
+
q.on(Yn, y);
|
|
1987
|
+
}
|
|
1988
|
+
}), A = i(Z), { send: P, onSuccess: M } = m;
|
|
1989
|
+
return f(() => {
|
|
1990
|
+
if (s && (A.current = Jn.on(s, (y) => {
|
|
1991
|
+
_.v = y;
|
|
1992
|
+
})), b && j && !r) {
|
|
1993
|
+
const y = T.current.deserialize(j.get(R));
|
|
1994
|
+
y && (_.v = y, q.emit(Yn, p)), v && P();
|
|
1995
|
+
}
|
|
1996
|
+
}), O([_], () => {
|
|
1997
|
+
if (s && (Jn.emit(s, _.v), ge[s] && (ge[s].form = _.v)), x.current || !b) {
|
|
1998
|
+
x.current = w;
|
|
1999
|
+
return;
|
|
2000
|
+
}
|
|
2001
|
+
j?.set(R, T.current.serialize(_.v));
|
|
2002
|
+
}), u(() => {
|
|
2003
|
+
A.current();
|
|
2004
|
+
}), M(() => {
|
|
2005
|
+
l && et();
|
|
2006
|
+
}), m;
|
|
2007
|
+
};
|
|
2008
|
+
const Zn = Symbol("RetriableRetry"), ts = Symbol("RetriableFail"), Vs = "useRetriableRequest", qr = _t(Vs);
|
|
2009
|
+
var po = (e, t = {}) => {
|
|
2010
|
+
const { retry: n = 3, backoff: r = { delay: 1e3 }, middleware: s = Z } = t, { ref: o, exposeProvider: c, __referingObj: l } = Ft(Rt()), v = qt(), d = o(0), a = o(p), i = o(p), f = o(p), u = o(w), O = o(p), I = o(Ce()), g = (V, q, K) => {
|
|
2011
|
+
jt(() => {
|
|
2012
|
+
v.emit(ts, F(mr, wt.spawn(V, q), K, d.current)), a.current = p, d.current = 0;
|
|
2013
|
+
});
|
|
2014
|
+
}, H = Ee(e, {
|
|
2015
|
+
...t,
|
|
2016
|
+
__referingObj: l,
|
|
2017
|
+
middleware(V, q) {
|
|
2018
|
+
s({
|
|
2019
|
+
...V,
|
|
2020
|
+
delegatingActions: {
|
|
2021
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
2022
|
+
stop: Q
|
|
2023
|
+
}
|
|
2024
|
+
}, () => Ot());
|
|
2025
|
+
const { proxyStates: K, args: j, send: R, method: x, controlLoading: T } = V;
|
|
2026
|
+
T();
|
|
2027
|
+
const { loading: J } = K, et = (m = w) => {
|
|
2028
|
+
J.v = m;
|
|
2029
|
+
}, h = (m) => {
|
|
2030
|
+
et(), K.error.v = m, clearTimeout(O.current), g(x, j, m);
|
|
2031
|
+
};
|
|
2032
|
+
return J.v || ye(I.current.promise, (m) => {
|
|
2033
|
+
h(m), I.current = Ce();
|
|
2034
|
+
}), et(D), u.current = D, i.current = x, f.current = j, q().then(
|
|
2035
|
+
(m) => (et(), m),
|
|
2036
|
+
// Trigger retry mechanism when request fails
|
|
2037
|
+
(m) => {
|
|
2038
|
+
if (!a.current && (At(n) ? d.current < n : n(m, ...j))) {
|
|
2039
|
+
d.current += 1;
|
|
2040
|
+
const A = os(r, d.current);
|
|
2041
|
+
O.current = jt(() => {
|
|
2042
|
+
v.emit(Zn, F(pr, wt.spawn(x, j), d.current, A)), ye(R(...j), Z);
|
|
2043
|
+
}, A);
|
|
2044
|
+
} else
|
|
2045
|
+
m = a.current || m, h(m);
|
|
2046
|
+
return as(m);
|
|
2047
|
+
}
|
|
2048
|
+
).finally(() => {
|
|
2049
|
+
u.current = w;
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
}), Q = () => {
|
|
2053
|
+
qr(H.__proxyState("loading").v, "there is no requests being retried"), a.current = F($e, Vs, "stop retry manually"), u.current ? H.abort() : I.current.reject(a.current);
|
|
2054
|
+
};
|
|
2055
|
+
return c({
|
|
2056
|
+
...H,
|
|
2057
|
+
stop: Q,
|
|
2058
|
+
onRetry: (V) => {
|
|
2059
|
+
v.on(Zn, (q) => V(q));
|
|
2060
|
+
},
|
|
2061
|
+
onFail: (V) => {
|
|
2062
|
+
v.on(ts, (q) => V(q));
|
|
2063
|
+
}
|
|
2064
|
+
});
|
|
2065
|
+
};
|
|
2066
|
+
let on = 0;
|
|
2067
|
+
const $t = {}, zr = (e) => !!e.send, Gr = _t("subscriber"), mo = (e) => {
|
|
2068
|
+
const { ref: t, onUnmounted: n } = Ft(Rt()), r = t(on + 1);
|
|
2069
|
+
return r.current > on && (on += 1), n(() => {
|
|
2070
|
+
var s;
|
|
2071
|
+
!((s = $t[e]) === null || s === void 0) && s[r.current] && delete $t[e][r.current];
|
|
2072
|
+
}), (s, o) => {
|
|
2073
|
+
const { abort: c, proxyStates: l, delegatingActions: v = {} } = s, d = (f) => {
|
|
2074
|
+
for (const u in f)
|
|
2075
|
+
l[u] && (l[u].v = f[u]);
|
|
2076
|
+
}, a = $t[e] = $t[e] || [], i = zr(s) ? {
|
|
2077
|
+
...v,
|
|
2078
|
+
send: s.send,
|
|
2079
|
+
abort: c,
|
|
2080
|
+
update: d
|
|
2081
|
+
} : {
|
|
2082
|
+
...v,
|
|
2083
|
+
fetch: s.fetch,
|
|
2084
|
+
abort: c,
|
|
2085
|
+
update: d
|
|
2086
|
+
};
|
|
2087
|
+
return a[r.current] = i, o();
|
|
73
2088
|
};
|
|
2089
|
+
}, Eo = (e, t, n = !1) => {
|
|
2090
|
+
const r = [];
|
|
2091
|
+
typeof e == "symbol" || Pe(e) || At(e) ? $t[e] && at(r, ...Ie($t[e])) : k(e, RegExp) && X(Dt(yt($t), (s) => e.test(s)), (s) => {
|
|
2092
|
+
at(r, ...Ie($t[s]));
|
|
2093
|
+
}), r.length === 0 && !n && Gr(!1, `no handler can be matched by using \`${e.toString()}\``), X(Dt(r, se), t);
|
|
74
2094
|
};
|
|
75
|
-
var U;
|
|
76
|
-
(function(n) {
|
|
77
|
-
n[n.USE_REQUEST = 1] = "USE_REQUEST", n[n.USE_WATCHER = 2] = "USE_WATCHER", n[n.USE_FETCHER = 3] = "USE_FETCHER";
|
|
78
|
-
})(U || (U = {}));
|
|
79
|
-
var T;
|
|
80
|
-
(function(n) {
|
|
81
|
-
n[n.CONNECTING = 0] = "CONNECTING", n[n.OPEN = 1] = "OPEN", n[n.CLOSED = 2] = "CLOSED";
|
|
82
|
-
})(T || (T = {}));
|
|
83
|
-
var _;
|
|
84
|
-
(function(n) {
|
|
85
|
-
n.Open = "open", n.Error = "error", n.Message = "message", n.Close = "close";
|
|
86
|
-
})(_ || (_ = {}));
|
|
87
2095
|
export {
|
|
88
|
-
|
|
2096
|
+
Eo as accessAction,
|
|
2097
|
+
mo as actionDelegationMiddleware,
|
|
2098
|
+
oo as bootSilentFactory,
|
|
2099
|
+
Wr as createClientTokenAuthentication,
|
|
2100
|
+
kr as createServerTokenAuthentication,
|
|
2101
|
+
Zr as dehydrateVData,
|
|
2102
|
+
co as equals,
|
|
2103
|
+
Qr as filterSilentMethods,
|
|
2104
|
+
io as getSilentMethod,
|
|
2105
|
+
lo as isVData,
|
|
2106
|
+
ro as onBeforeSilentSubmit,
|
|
2107
|
+
to as onSilentSubmitBoot,
|
|
2108
|
+
no as onSilentSubmitError,
|
|
2109
|
+
so as onSilentSubmitFail,
|
|
2110
|
+
eo as onSilentSubmitSuccess,
|
|
2111
|
+
Vt as silentQueueMap,
|
|
2112
|
+
Ft as statesHookHelper,
|
|
2113
|
+
kt as stringifyVData,
|
|
2114
|
+
Ue as updateState,
|
|
2115
|
+
uo as updateStateEffect,
|
|
2116
|
+
Ht as useAutoRequest,
|
|
2117
|
+
vo as useCaptcha,
|
|
2118
|
+
br as useFetcher,
|
|
2119
|
+
ho as useForm,
|
|
2120
|
+
Yr as usePagination,
|
|
2121
|
+
Ee as useRequest,
|
|
2122
|
+
po as useRetriableRequest,
|
|
2123
|
+
ao as useSQRequest,
|
|
2124
|
+
fo as useSSE,
|
|
2125
|
+
Jr as useSerialRequest,
|
|
2126
|
+
Xr as useSerialWatcher,
|
|
2127
|
+
ze as useUploader,
|
|
2128
|
+
Ss as useWatcher
|
|
89
2129
|
};
|