@whitesev/utils 2.2.9 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.amd.js +336 -60
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +336 -60
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +336 -60
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +336 -60
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +336 -60
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +336 -60
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Httpx.d.ts +2 -3
- package/dist/types/src/Log.d.ts +1 -2
- package/dist/types/src/Utils.d.ts +15 -10
- package/dist/types/src/Vue.d.ts +43 -0
- package/dist/types/src/VueObject.d.ts +28 -28
- package/package.json +2 -1
- package/src/Httpx.ts +117 -74
- package/src/Log.ts +1 -2
- package/src/Utils.ts +26 -25
- package/src/Vue.ts +241 -0
- package/src/VueObject.ts +29 -29
package/dist/index.esm.js
CHANGED
|
@@ -1577,7 +1577,7 @@ class Httpx {
|
|
|
1577
1577
|
return uuid;
|
|
1578
1578
|
}
|
|
1579
1579
|
else {
|
|
1580
|
-
console.warn("HttpxRequestHook.addBeforeRequestCallBack
|
|
1580
|
+
console.warn("[Httpx-HttpxRequestHook.addBeforeRequestCallBack] fn is not a function");
|
|
1581
1581
|
}
|
|
1582
1582
|
},
|
|
1583
1583
|
/**
|
|
@@ -2056,65 +2056,81 @@ class Httpx {
|
|
|
2056
2056
|
*/
|
|
2057
2057
|
onLoad(details, resolve, reject, argumentsList) {
|
|
2058
2058
|
/* X浏览器会因为设置了responseType导致不返回responseText */
|
|
2059
|
-
let
|
|
2059
|
+
let originResponse = argumentsList[0];
|
|
2060
2060
|
/* responseText为空,response不为空的情况 */
|
|
2061
|
-
if (utils.isNull(
|
|
2062
|
-
utils.isNotNull(
|
|
2063
|
-
if (typeof
|
|
2061
|
+
if (utils.isNull(originResponse["responseText"]) &&
|
|
2062
|
+
utils.isNotNull(originResponse["response"])) {
|
|
2063
|
+
if (typeof originResponse["response"] === "object") {
|
|
2064
2064
|
utils.tryCatch().run(() => {
|
|
2065
|
-
|
|
2065
|
+
originResponse["responseText"] = JSON.stringify(originResponse["response"]);
|
|
2066
2066
|
});
|
|
2067
2067
|
}
|
|
2068
2068
|
else {
|
|
2069
|
-
|
|
2069
|
+
originResponse["responseText"] = originResponse["response"];
|
|
2070
2070
|
}
|
|
2071
2071
|
}
|
|
2072
2072
|
/* response为空,responseText不为空的情况 */
|
|
2073
|
-
if (
|
|
2074
|
-
typeof
|
|
2075
|
-
|
|
2076
|
-
|
|
2073
|
+
if (originResponse["response"] == null &&
|
|
2074
|
+
typeof originResponse["responseText"] === "string" &&
|
|
2075
|
+
originResponse["responseText"].trim() !== "") {
|
|
2076
|
+
/** 原始的请求text */
|
|
2077
|
+
let httpxResponseText = originResponse.responseText;
|
|
2078
|
+
// 自定义个新的response
|
|
2079
|
+
let httpxResponse = httpxResponseText;
|
|
2077
2080
|
if (details.responseType === "json") {
|
|
2078
|
-
|
|
2081
|
+
httpxResponse = utils.toJSON(httpxResponseText);
|
|
2079
2082
|
}
|
|
2080
2083
|
else if (details.responseType === "document") {
|
|
2081
2084
|
let parser = new DOMParser();
|
|
2082
|
-
|
|
2085
|
+
httpxResponse = parser.parseFromString(httpxResponseText, "text/html");
|
|
2083
2086
|
}
|
|
2084
2087
|
else if (details.responseType === "arraybuffer") {
|
|
2085
2088
|
let encoder = new TextEncoder();
|
|
2086
|
-
let arrayBuffer = encoder.encode(
|
|
2087
|
-
|
|
2089
|
+
let arrayBuffer = encoder.encode(httpxResponseText);
|
|
2090
|
+
httpxResponse = arrayBuffer;
|
|
2088
2091
|
}
|
|
2089
2092
|
else if (details.responseType === "blob") {
|
|
2090
2093
|
let encoder = new TextEncoder();
|
|
2091
|
-
let arrayBuffer = encoder.encode(
|
|
2092
|
-
|
|
2093
|
-
}
|
|
2094
|
-
else {
|
|
2095
|
-
newResponse = Response["responseText"];
|
|
2094
|
+
let arrayBuffer = encoder.encode(httpxResponseText);
|
|
2095
|
+
httpxResponse = new Blob([arrayBuffer]);
|
|
2096
2096
|
}
|
|
2097
|
+
// 尝试覆盖原response
|
|
2097
2098
|
try {
|
|
2098
|
-
|
|
2099
|
+
let setStatus = Reflect.set(originResponse, "response", httpxResponse);
|
|
2100
|
+
if (!setStatus) {
|
|
2101
|
+
console.warn("[Httpx-HttpxCallBack.oonLoad] 覆盖原始 response 失败,尝试添加新的httpxResponse");
|
|
2102
|
+
try {
|
|
2103
|
+
Reflect.set(originResponse, "httpxResponse", httpxResponse);
|
|
2104
|
+
}
|
|
2105
|
+
catch (error) {
|
|
2106
|
+
console.warn("[Httpx-HttpxCallBack.oonLoad] httpxResponse 无法被覆盖");
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2099
2109
|
}
|
|
2100
2110
|
catch (error) {
|
|
2101
|
-
console.warn("response
|
|
2111
|
+
console.warn("[Httpx-HttpxCallBack.oonLoad] 原始 response 无法被覆盖,尝试添加新的httpxResponse");
|
|
2112
|
+
try {
|
|
2113
|
+
Reflect.set(originResponse, "httpxResponse", httpxResponse);
|
|
2114
|
+
}
|
|
2115
|
+
catch (error) {
|
|
2116
|
+
console.warn("[Httpx-HttpxCallBack.oonLoad] httpxResponse 无法被覆盖");
|
|
2117
|
+
}
|
|
2102
2118
|
}
|
|
2103
2119
|
}
|
|
2104
2120
|
/* Stay扩展中没有finalUrl,对应的是responseURL */
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2121
|
+
let originResponseURL = Reflect.get(originResponse, "responseURL");
|
|
2122
|
+
if (originResponse["finalUrl"] == null && originResponseURL != null) {
|
|
2123
|
+
Reflect.set(originResponse, "finalUrl", originResponseURL);
|
|
2108
2124
|
}
|
|
2109
2125
|
/* 状态码2xx都是成功的 */
|
|
2110
|
-
if (Math.floor(
|
|
2111
|
-
if (this.context.HttpxResponseHook.successResponseCallBack(
|
|
2126
|
+
if (Math.floor(originResponse.status / 100) === 2) {
|
|
2127
|
+
if (this.context.HttpxResponseHook.successResponseCallBack(originResponse, details) == null) {
|
|
2112
2128
|
// reject(new TypeError("response is intercept with onloada"));
|
|
2113
2129
|
return;
|
|
2114
2130
|
}
|
|
2115
2131
|
resolve({
|
|
2116
2132
|
status: true,
|
|
2117
|
-
data:
|
|
2133
|
+
data: originResponse,
|
|
2118
2134
|
details: details,
|
|
2119
2135
|
msg: "请求完毕",
|
|
2120
2136
|
type: "onload",
|
|
@@ -2159,7 +2175,7 @@ class Httpx {
|
|
|
2159
2175
|
*/
|
|
2160
2176
|
request(details) {
|
|
2161
2177
|
if (this.context.#LOG_DETAILS) {
|
|
2162
|
-
console.log("Httpx
|
|
2178
|
+
console.log("[Httpx-HttpxRequest.request] 请求前的配置👇", details);
|
|
2163
2179
|
}
|
|
2164
2180
|
if (typeof this.context.HttpxRequestHook.beforeRequestCallBack ===
|
|
2165
2181
|
"function") {
|
|
@@ -2192,33 +2208,38 @@ class Httpx {
|
|
|
2192
2208
|
*/
|
|
2193
2209
|
fetch(details, fetchRequestInit, abortController) {
|
|
2194
2210
|
fetch(details.url, fetchRequestInit)
|
|
2195
|
-
.then(async (
|
|
2196
|
-
/**
|
|
2197
|
-
* @type {HttpxAsyncResultData}
|
|
2198
|
-
*/
|
|
2211
|
+
.then(async (fetchResponse) => {
|
|
2212
|
+
/** 自定义的response */
|
|
2199
2213
|
let httpxResponse = {
|
|
2200
2214
|
isFetch: true,
|
|
2201
|
-
finalUrl:
|
|
2215
|
+
finalUrl: fetchResponse.url,
|
|
2202
2216
|
readyState: 4,
|
|
2203
|
-
|
|
2204
|
-
|
|
2217
|
+
// @ts-ignore
|
|
2218
|
+
status: fetchResponse.status,
|
|
2219
|
+
statusText: fetchResponse.statusText,
|
|
2205
2220
|
response: void 0,
|
|
2206
|
-
responseFetchHeaders:
|
|
2221
|
+
responseFetchHeaders: fetchResponse.headers,
|
|
2207
2222
|
responseHeaders: "",
|
|
2223
|
+
// @ts-ignore
|
|
2208
2224
|
responseText: void 0,
|
|
2209
2225
|
responseType: details.responseType,
|
|
2210
2226
|
responseXML: void 0,
|
|
2211
2227
|
};
|
|
2212
2228
|
Object.assign(httpxResponse, details.context || {});
|
|
2213
|
-
|
|
2229
|
+
// 把headers转为字符串
|
|
2230
|
+
for (const [key, value] of fetchResponse.headers.entries()) {
|
|
2214
2231
|
httpxResponse.responseHeaders += `${key}: ${value}\n`;
|
|
2215
2232
|
}
|
|
2216
|
-
|
|
2233
|
+
/** 请求返回的类型 */
|
|
2234
|
+
const fetchResponseType = fetchResponse.headers.get("Content-Type");
|
|
2235
|
+
/* 如果需要stream,且获取到的是stream,那直接返回 */
|
|
2217
2236
|
if (details.responseType === "stream" ||
|
|
2218
|
-
(
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2237
|
+
(fetchResponse.headers.has("Content-Type") &&
|
|
2238
|
+
fetchResponse.headers
|
|
2239
|
+
.get("Content-Type")
|
|
2240
|
+
.includes("text/event-stream"))) {
|
|
2241
|
+
Reflect.set(httpxResponse, "isStream", true);
|
|
2242
|
+
Reflect.set(httpxResponse, "response", fetchResponse.body);
|
|
2222
2243
|
Reflect.deleteProperty(httpxResponse, "responseText");
|
|
2223
2244
|
Reflect.deleteProperty(httpxResponse, "responseXML");
|
|
2224
2245
|
details.onload(httpxResponse);
|
|
@@ -2230,42 +2251,57 @@ class Httpx {
|
|
|
2230
2251
|
let responseText = "";
|
|
2231
2252
|
/** 响应xml文档 */
|
|
2232
2253
|
let responseXML = "";
|
|
2233
|
-
|
|
2254
|
+
/** 先获取二进制数据 */
|
|
2255
|
+
let arrayBuffer = await fetchResponse.arrayBuffer();
|
|
2256
|
+
/** 数据编码 */
|
|
2234
2257
|
let encoding = "utf-8";
|
|
2235
|
-
if (
|
|
2236
|
-
let charsetMatched =
|
|
2258
|
+
if (fetchResponse.headers.has("Content-Type")) {
|
|
2259
|
+
let charsetMatched = fetchResponse.headers
|
|
2237
2260
|
.get("Content-Type")
|
|
2238
2261
|
?.match(/charset=(.+)/);
|
|
2239
2262
|
if (charsetMatched) {
|
|
2240
2263
|
encoding = charsetMatched[1];
|
|
2264
|
+
encoding = encoding.toLowerCase();
|
|
2241
2265
|
}
|
|
2242
2266
|
}
|
|
2267
|
+
// Failed to construct 'TextDecoder': The encoding label provided ('"UTF-8"') is invalid.
|
|
2268
|
+
// 去除引号
|
|
2269
|
+
encoding = encoding.replace(/('|")/gi, "");
|
|
2270
|
+
// 编码
|
|
2243
2271
|
let textDecoder = new TextDecoder(encoding);
|
|
2244
2272
|
responseText = textDecoder.decode(arrayBuffer);
|
|
2245
2273
|
response = responseText;
|
|
2246
2274
|
if (details.responseType === "arraybuffer") {
|
|
2275
|
+
// response返回格式是二进制流
|
|
2247
2276
|
response = arrayBuffer;
|
|
2248
2277
|
}
|
|
2249
2278
|
else if (details.responseType === "blob") {
|
|
2279
|
+
// response返回格式是blob
|
|
2250
2280
|
response = new Blob([arrayBuffer]);
|
|
2251
2281
|
}
|
|
2282
|
+
else if (details.responseType === "json" ||
|
|
2283
|
+
(typeof fetchResponseType === "string" &&
|
|
2284
|
+
fetchResponseType.includes("application/json"))) {
|
|
2285
|
+
// response返回格式是JSON格式
|
|
2286
|
+
response = utils.toJSON(responseText);
|
|
2287
|
+
}
|
|
2252
2288
|
else if (details.responseType === "document" ||
|
|
2253
2289
|
details.responseType == null) {
|
|
2290
|
+
// response返回格式是文档格式
|
|
2254
2291
|
let parser = new DOMParser();
|
|
2255
2292
|
response = parser.parseFromString(responseText, "text/html");
|
|
2256
2293
|
}
|
|
2257
|
-
|
|
2258
|
-
response = utils.toJSON(responseText);
|
|
2259
|
-
}
|
|
2294
|
+
// 转为XML结构
|
|
2260
2295
|
let parser = new DOMParser();
|
|
2261
2296
|
responseXML = parser.parseFromString(responseText, "text/xml");
|
|
2262
|
-
httpxResponse
|
|
2263
|
-
httpxResponse
|
|
2264
|
-
httpxResponse
|
|
2297
|
+
Reflect.set(httpxResponse, "response", response);
|
|
2298
|
+
Reflect.set(httpxResponse, "responseText", responseText);
|
|
2299
|
+
Reflect.set(httpxResponse, "responseXML", responseXML);
|
|
2300
|
+
// 执行回调
|
|
2265
2301
|
details.onload(httpxResponse);
|
|
2266
2302
|
})
|
|
2267
|
-
.catch((
|
|
2268
|
-
if (
|
|
2303
|
+
.catch((error) => {
|
|
2304
|
+
if (error.name === "AbortError") {
|
|
2269
2305
|
return;
|
|
2270
2306
|
}
|
|
2271
2307
|
details.onerror({
|
|
@@ -2276,7 +2312,7 @@ class Httpx {
|
|
|
2276
2312
|
statusText: "",
|
|
2277
2313
|
responseHeaders: "",
|
|
2278
2314
|
responseText: "",
|
|
2279
|
-
error:
|
|
2315
|
+
error: error,
|
|
2280
2316
|
});
|
|
2281
2317
|
});
|
|
2282
2318
|
details.onloadstart({
|
|
@@ -2339,7 +2375,7 @@ class Httpx {
|
|
|
2339
2375
|
*/
|
|
2340
2376
|
constructor(__xmlHttpRequest__) {
|
|
2341
2377
|
if (typeof __xmlHttpRequest__ !== "function") {
|
|
2342
|
-
console.warn("Httpx未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function
|
|
2378
|
+
console.warn("[Httpx-constructor] 未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,将默认使用window.fetch");
|
|
2343
2379
|
}
|
|
2344
2380
|
this.interceptors.request.context = this;
|
|
2345
2381
|
this.interceptors.response.context = this;
|
|
@@ -3645,6 +3681,245 @@ class WindowApi {
|
|
|
3645
3681
|
}
|
|
3646
3682
|
}
|
|
3647
3683
|
|
|
3684
|
+
const VueUtils = {
|
|
3685
|
+
/** 标签 */
|
|
3686
|
+
ReactiveFlags: {
|
|
3687
|
+
IS_REACTIVE: Symbol("isReactive"),
|
|
3688
|
+
},
|
|
3689
|
+
/**
|
|
3690
|
+
* 判断是否是对象
|
|
3691
|
+
* @param value
|
|
3692
|
+
*/
|
|
3693
|
+
isObject(value) {
|
|
3694
|
+
return typeof value === "object" && value !== null;
|
|
3695
|
+
},
|
|
3696
|
+
/**
|
|
3697
|
+
* 判断是否是函数
|
|
3698
|
+
* @param val
|
|
3699
|
+
*/
|
|
3700
|
+
isFunction(val) {
|
|
3701
|
+
return typeof val === "function";
|
|
3702
|
+
},
|
|
3703
|
+
/**
|
|
3704
|
+
* 处理对象再次代理,可以直接返回
|
|
3705
|
+
* @param value
|
|
3706
|
+
*/
|
|
3707
|
+
isReactive(value) {
|
|
3708
|
+
return !!(value && value[VueUtils.ReactiveFlags.IS_REACTIVE]);
|
|
3709
|
+
},
|
|
3710
|
+
/**
|
|
3711
|
+
* 判断是否是数组
|
|
3712
|
+
* @param value
|
|
3713
|
+
*/
|
|
3714
|
+
isArray(value) {
|
|
3715
|
+
return Array.isArray(value);
|
|
3716
|
+
},
|
|
3717
|
+
};
|
|
3718
|
+
class ReactiveEffect {
|
|
3719
|
+
deps = [];
|
|
3720
|
+
active = true;
|
|
3721
|
+
fn;
|
|
3722
|
+
// @ts-ignore
|
|
3723
|
+
scheduler;
|
|
3724
|
+
constructor(fn, scheduler) {
|
|
3725
|
+
this.fn = fn;
|
|
3726
|
+
this.scheduler = scheduler;
|
|
3727
|
+
}
|
|
3728
|
+
run(cb) {
|
|
3729
|
+
if (!this.active) {
|
|
3730
|
+
this.fn();
|
|
3731
|
+
}
|
|
3732
|
+
try {
|
|
3733
|
+
if (typeof cb === "function") {
|
|
3734
|
+
cb(this);
|
|
3735
|
+
}
|
|
3736
|
+
return this.fn();
|
|
3737
|
+
}
|
|
3738
|
+
finally {
|
|
3739
|
+
if (typeof cb === "function") {
|
|
3740
|
+
cb(undefined);
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
class RefImpl {
|
|
3746
|
+
_value;
|
|
3747
|
+
_isRef = true;
|
|
3748
|
+
_rawValue;
|
|
3749
|
+
_vue;
|
|
3750
|
+
constructor(vueIns, rawValue) {
|
|
3751
|
+
this._vue = vueIns;
|
|
3752
|
+
this._rawValue = rawValue;
|
|
3753
|
+
this._value = this._vue.toReactive(rawValue);
|
|
3754
|
+
}
|
|
3755
|
+
get value() {
|
|
3756
|
+
return this._value;
|
|
3757
|
+
}
|
|
3758
|
+
set value(newValue) {
|
|
3759
|
+
if (newValue !== this._rawValue) {
|
|
3760
|
+
this._value = this._vue.toReactive(newValue);
|
|
3761
|
+
this._rawValue = newValue;
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
}
|
|
3765
|
+
class ObjectRefImpl {
|
|
3766
|
+
object;
|
|
3767
|
+
key;
|
|
3768
|
+
constructor(object, key) {
|
|
3769
|
+
this.object = object;
|
|
3770
|
+
this.key = key;
|
|
3771
|
+
}
|
|
3772
|
+
get value() {
|
|
3773
|
+
return this.object[this.key];
|
|
3774
|
+
}
|
|
3775
|
+
set value(newValue) {
|
|
3776
|
+
this.object[this.key] = newValue;
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
class Vue {
|
|
3780
|
+
reactMap = new WeakMap();
|
|
3781
|
+
targetMap = new WeakMap();
|
|
3782
|
+
activeEffect = undefined;
|
|
3783
|
+
constructor() {
|
|
3784
|
+
// 将数据转化成响应式的数据,只能做对象的代理
|
|
3785
|
+
}
|
|
3786
|
+
/**
|
|
3787
|
+
* 生成一个被代理的对象
|
|
3788
|
+
* @param target 需要代理的对象
|
|
3789
|
+
*/
|
|
3790
|
+
reactive(target) {
|
|
3791
|
+
const that = this;
|
|
3792
|
+
if (!(typeof target === "object" && target !== null)) {
|
|
3793
|
+
// @ts-ignore
|
|
3794
|
+
return;
|
|
3795
|
+
}
|
|
3796
|
+
if (VueUtils.isReactive(target)) {
|
|
3797
|
+
return target;
|
|
3798
|
+
}
|
|
3799
|
+
let exisProxy = this.reactMap.get(target);
|
|
3800
|
+
if (exisProxy) {
|
|
3801
|
+
return exisProxy;
|
|
3802
|
+
}
|
|
3803
|
+
const proxy = new Proxy(target, {
|
|
3804
|
+
get(target, key, receiver) {
|
|
3805
|
+
if (key === VueUtils.ReactiveFlags.IS_REACTIVE) {
|
|
3806
|
+
return true;
|
|
3807
|
+
}
|
|
3808
|
+
that.track(target, "get", key);
|
|
3809
|
+
return Reflect.get(target, key, receiver);
|
|
3810
|
+
},
|
|
3811
|
+
set(target, key, value, receiver) {
|
|
3812
|
+
let oldValue = target[key];
|
|
3813
|
+
let result = Reflect.set(target, key, value, receiver);
|
|
3814
|
+
if (oldValue !== value) {
|
|
3815
|
+
that.trigger(target, "set", key, oldValue, value);
|
|
3816
|
+
}
|
|
3817
|
+
return result;
|
|
3818
|
+
},
|
|
3819
|
+
});
|
|
3820
|
+
that.reactMap.set(target, proxy);
|
|
3821
|
+
return proxy;
|
|
3822
|
+
}
|
|
3823
|
+
/**
|
|
3824
|
+
* 观察被reactive的对象值改变
|
|
3825
|
+
* @param source 被观察的对象,这里采用函数返回对象
|
|
3826
|
+
* @param changeCallBack 值改变的回调
|
|
3827
|
+
*/
|
|
3828
|
+
watch(source, changeCallBack) {
|
|
3829
|
+
let getter;
|
|
3830
|
+
if (VueUtils.isReactive(source)) {
|
|
3831
|
+
getter = () => this.traversal(source);
|
|
3832
|
+
}
|
|
3833
|
+
else if (VueUtils.isFunction(source)) {
|
|
3834
|
+
getter = source;
|
|
3835
|
+
}
|
|
3836
|
+
else {
|
|
3837
|
+
return;
|
|
3838
|
+
}
|
|
3839
|
+
let oldValue;
|
|
3840
|
+
const job = () => {
|
|
3841
|
+
const newValue = effect.run((activeEffect) => {
|
|
3842
|
+
this.activeEffect = activeEffect;
|
|
3843
|
+
});
|
|
3844
|
+
changeCallBack(newValue, oldValue);
|
|
3845
|
+
oldValue = newValue;
|
|
3846
|
+
};
|
|
3847
|
+
const effect = new ReactiveEffect(getter, job);
|
|
3848
|
+
oldValue = effect.run((activeEffect) => {
|
|
3849
|
+
this.activeEffect = activeEffect;
|
|
3850
|
+
});
|
|
3851
|
+
}
|
|
3852
|
+
toReactive(value) {
|
|
3853
|
+
return VueUtils.isObject(value) ? this.reactive(value) : value;
|
|
3854
|
+
}
|
|
3855
|
+
ref(value) {
|
|
3856
|
+
return new RefImpl(this, value);
|
|
3857
|
+
}
|
|
3858
|
+
toRef(object, key) {
|
|
3859
|
+
return new ObjectRefImpl(object, key);
|
|
3860
|
+
}
|
|
3861
|
+
toRefs(object) {
|
|
3862
|
+
const result = VueUtils.isArray(object) ? new Array(object.length) : {};
|
|
3863
|
+
for (let key in object) {
|
|
3864
|
+
// @ts-ignore
|
|
3865
|
+
result[key] = this.toRef(object, key);
|
|
3866
|
+
}
|
|
3867
|
+
return result;
|
|
3868
|
+
}
|
|
3869
|
+
trigger(target, type, key, oldValue, value) {
|
|
3870
|
+
const depsMap = this.targetMap.get(target);
|
|
3871
|
+
if (!depsMap)
|
|
3872
|
+
return;
|
|
3873
|
+
const effects = depsMap.get(key);
|
|
3874
|
+
this.triggerEffect(effects, "effects");
|
|
3875
|
+
}
|
|
3876
|
+
triggerEffect(effects, name) {
|
|
3877
|
+
effects &&
|
|
3878
|
+
effects.forEach((effect) => {
|
|
3879
|
+
if (effect.scheduler) {
|
|
3880
|
+
effect.scheduler();
|
|
3881
|
+
}
|
|
3882
|
+
else {
|
|
3883
|
+
effect.run();
|
|
3884
|
+
}
|
|
3885
|
+
});
|
|
3886
|
+
}
|
|
3887
|
+
track(target, type, key) {
|
|
3888
|
+
if (!this.activeEffect)
|
|
3889
|
+
return;
|
|
3890
|
+
let depsMap = this.targetMap.get(target);
|
|
3891
|
+
if (!depsMap) {
|
|
3892
|
+
this.targetMap.set(target, (depsMap = new Map()));
|
|
3893
|
+
}
|
|
3894
|
+
let dep = depsMap.get(key);
|
|
3895
|
+
if (!dep) {
|
|
3896
|
+
depsMap.set(key, (dep = new Set()));
|
|
3897
|
+
}
|
|
3898
|
+
this.trackEffect(dep);
|
|
3899
|
+
}
|
|
3900
|
+
trackEffect(dep) {
|
|
3901
|
+
if (this.activeEffect) {
|
|
3902
|
+
let shouldTrack = !dep.has(this.activeEffect);
|
|
3903
|
+
if (shouldTrack) {
|
|
3904
|
+
dep.add(this.activeEffect);
|
|
3905
|
+
this.activeEffect.deps.push(dep);
|
|
3906
|
+
}
|
|
3907
|
+
}
|
|
3908
|
+
}
|
|
3909
|
+
traversal(value, set = new Set()) {
|
|
3910
|
+
if (!VueUtils.isObject(value))
|
|
3911
|
+
return value;
|
|
3912
|
+
if (set.has(value)) {
|
|
3913
|
+
return value;
|
|
3914
|
+
}
|
|
3915
|
+
set.add(value);
|
|
3916
|
+
for (let key in value) {
|
|
3917
|
+
this.traversal(value[key], set);
|
|
3918
|
+
}
|
|
3919
|
+
return value;
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
|
|
3648
3923
|
class Utils {
|
|
3649
3924
|
windowApi;
|
|
3650
3925
|
constructor(option) {
|
|
@@ -5764,7 +6039,6 @@ class Utils {
|
|
|
5764
6039
|
}
|
|
5765
6040
|
/**
|
|
5766
6041
|
* 申请剪贴板权限
|
|
5767
|
-
* @returns {Promise<boolean>}
|
|
5768
6042
|
*/
|
|
5769
6043
|
requestClipboardPermission() {
|
|
5770
6044
|
return new Promise((resolve, reject) => {
|
|
@@ -5777,9 +6051,7 @@ class Utils {
|
|
|
5777
6051
|
.then((permissionStatus) => {
|
|
5778
6052
|
resolve(true);
|
|
5779
6053
|
})
|
|
5780
|
-
.catch(
|
|
5781
|
-
/** @param {TypeError} error */
|
|
5782
|
-
(error) => {
|
|
6054
|
+
.catch((error) => {
|
|
5783
6055
|
console.error([
|
|
5784
6056
|
"申请剪贴板权限失败,尝试直接写入👉",
|
|
5785
6057
|
error.message ?? error.name ?? error.stack,
|
|
@@ -6712,6 +6984,10 @@ class Utils {
|
|
|
6712
6984
|
* Utils.generateUUID()
|
|
6713
6985
|
*/
|
|
6714
6986
|
generateUUID = GenerateUUID;
|
|
6987
|
+
/**
|
|
6988
|
+
* 自定义的动态响应对象
|
|
6989
|
+
*/
|
|
6990
|
+
Vue = Vue;
|
|
6715
6991
|
}
|
|
6716
6992
|
let utils = new Utils();
|
|
6717
6993
|
|