@reactive-vscode/vueuse 0.3.3 → 0.4.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.cjs +1059 -1578
- package/dist/index.d.ts +264 -300
- package/dist/index.js +1105 -1632
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { customRef, toValue, watch, effectScope, unref, computed, ref, shallowReadonly, isRef, readonly, toRefs as toRefs$1, reactive, toRef as toRef$1, getCurrentScope, onScopeDispose, shallowRef, nextTick, isReactive, watchEffect, isReadonly, markRaw } from "@reactive-vscode/reactivity";
|
|
2
|
+
import { toRef, toValue as toValue2, toValue as toValue3 } from "@reactive-vscode/reactivity";
|
|
3
|
+
function getCurrentInstance() {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
2
6
|
function computedWithControl(source, fn, options = {}) {
|
|
3
7
|
let v = void 0;
|
|
4
8
|
let track;
|
|
@@ -8,32 +12,35 @@ function computedWithControl(source, fn, options = {}) {
|
|
|
8
12
|
dirty = true;
|
|
9
13
|
trigger();
|
|
10
14
|
};
|
|
11
|
-
watch(source, update, {
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
watch(source, update, {
|
|
16
|
+
flush: "sync",
|
|
17
|
+
...options
|
|
18
|
+
});
|
|
19
|
+
const get$1 = typeof fn === "function" ? fn : fn.get;
|
|
20
|
+
const set$1 = typeof fn === "function" ? void 0 : fn.set;
|
|
14
21
|
const result = customRef((_track, _trigger) => {
|
|
15
22
|
track = _track;
|
|
16
23
|
trigger = _trigger;
|
|
17
24
|
return {
|
|
18
25
|
get() {
|
|
19
26
|
if (dirty) {
|
|
20
|
-
v =
|
|
27
|
+
v = get$1(v);
|
|
21
28
|
dirty = false;
|
|
22
29
|
}
|
|
23
30
|
track();
|
|
24
31
|
return v;
|
|
25
32
|
},
|
|
26
|
-
set(
|
|
27
|
-
|
|
33
|
+
set(v$1) {
|
|
34
|
+
set$1 === null || set$1 === void 0 || set$1(v$1);
|
|
28
35
|
}
|
|
29
36
|
};
|
|
30
37
|
});
|
|
31
38
|
result.trigger = update;
|
|
32
39
|
return result;
|
|
33
40
|
}
|
|
34
|
-
function tryOnScopeDispose(fn) {
|
|
41
|
+
function tryOnScopeDispose(fn, failSilently) {
|
|
35
42
|
if (getCurrentScope()) {
|
|
36
|
-
onScopeDispose(fn);
|
|
43
|
+
onScopeDispose(fn, failSilently);
|
|
37
44
|
return true;
|
|
38
45
|
}
|
|
39
46
|
return false;
|
|
@@ -51,9 +58,7 @@ function createEventHook() {
|
|
|
51
58
|
fns.add(fn);
|
|
52
59
|
const offFn = () => off(fn);
|
|
53
60
|
tryOnScopeDispose(offFn);
|
|
54
|
-
return {
|
|
55
|
-
off: offFn
|
|
56
|
-
};
|
|
61
|
+
return { off: offFn };
|
|
57
62
|
};
|
|
58
63
|
const trigger = (...args) => {
|
|
59
64
|
return Promise.all(Array.from(fns).map((fn) => fn(...args)));
|
|
@@ -70,171 +75,25 @@ function createGlobalState(stateFactory) {
|
|
|
70
75
|
let initialized = false;
|
|
71
76
|
let state;
|
|
72
77
|
const scope = effectScope(true);
|
|
73
|
-
return (...args) => {
|
|
78
|
+
return ((...args) => {
|
|
74
79
|
if (!initialized) {
|
|
75
80
|
state = scope.run(() => stateFactory(...args));
|
|
76
81
|
initialized = true;
|
|
77
82
|
}
|
|
78
83
|
return state;
|
|
79
|
-
};
|
|
84
|
+
});
|
|
80
85
|
}
|
|
81
86
|
// @__NO_SIDE_EFFECTS__
|
|
82
87
|
function createRef(value, deep) {
|
|
83
|
-
if (deep === true)
|
|
84
|
-
|
|
85
|
-
} else {
|
|
86
|
-
return shallowRef(value);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
// @__NO_SIDE_EFFECTS__
|
|
90
|
-
function createSharedComposable(composable) {
|
|
91
|
-
let subscribers = 0;
|
|
92
|
-
let state;
|
|
93
|
-
let scope;
|
|
94
|
-
const dispose = () => {
|
|
95
|
-
subscribers -= 1;
|
|
96
|
-
if (scope && subscribers <= 0) {
|
|
97
|
-
scope.stop();
|
|
98
|
-
state = void 0;
|
|
99
|
-
scope = void 0;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
return (...args) => {
|
|
103
|
-
subscribers += 1;
|
|
104
|
-
if (!scope) {
|
|
105
|
-
scope = effectScope(true);
|
|
106
|
-
state = scope.run(() => composable(...args));
|
|
107
|
-
}
|
|
108
|
-
tryOnScopeDispose(dispose);
|
|
109
|
-
return state;
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function extendRef(ref2, extend, { enumerable = false, unwrap = true } = {}) {
|
|
113
|
-
for (const [key, value] of Object.entries(extend)) {
|
|
114
|
-
if (key === "value")
|
|
115
|
-
continue;
|
|
116
|
-
if (isRef(value) && unwrap) {
|
|
117
|
-
Object.defineProperty(ref2, key, {
|
|
118
|
-
get() {
|
|
119
|
-
return value.value;
|
|
120
|
-
},
|
|
121
|
-
set(v) {
|
|
122
|
-
value.value = v;
|
|
123
|
-
},
|
|
124
|
-
enumerable
|
|
125
|
-
});
|
|
126
|
-
} else {
|
|
127
|
-
Object.defineProperty(ref2, key, { value, enumerable });
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return ref2;
|
|
131
|
-
}
|
|
132
|
-
function get(obj, key) {
|
|
133
|
-
if (key == null)
|
|
134
|
-
return unref(obj);
|
|
135
|
-
return unref(obj)[key];
|
|
136
|
-
}
|
|
137
|
-
function isDefined(v) {
|
|
138
|
-
return unref(v) != null;
|
|
139
|
-
}
|
|
140
|
-
// @__NO_SIDE_EFFECTS__
|
|
141
|
-
function makeDestructurable(obj, arr) {
|
|
142
|
-
if (typeof Symbol !== "undefined") {
|
|
143
|
-
const clone = { ...obj };
|
|
144
|
-
Object.defineProperty(clone, Symbol.iterator, {
|
|
145
|
-
enumerable: false,
|
|
146
|
-
value() {
|
|
147
|
-
let index = 0;
|
|
148
|
-
return {
|
|
149
|
-
next: () => ({
|
|
150
|
-
value: arr[index++],
|
|
151
|
-
done: index > arr.length
|
|
152
|
-
})
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
return clone;
|
|
157
|
-
} else {
|
|
158
|
-
return Object.assign([...arr], obj);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
// @__NO_SIDE_EFFECTS__
|
|
162
|
-
function reactify(fn, options) {
|
|
163
|
-
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? unref : toValue$1;
|
|
164
|
-
return function(...args) {
|
|
165
|
-
return computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
// @__NO_SIDE_EFFECTS__
|
|
169
|
-
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
170
|
-
let keys = [];
|
|
171
|
-
let options;
|
|
172
|
-
if (Array.isArray(optionsOrKeys)) {
|
|
173
|
-
keys = optionsOrKeys;
|
|
174
|
-
} else {
|
|
175
|
-
options = optionsOrKeys;
|
|
176
|
-
const { includeOwnProperties = true } = optionsOrKeys;
|
|
177
|
-
keys.push(...Object.keys(obj));
|
|
178
|
-
if (includeOwnProperties)
|
|
179
|
-
keys.push(...Object.getOwnPropertyNames(obj));
|
|
180
|
-
}
|
|
181
|
-
return Object.fromEntries(
|
|
182
|
-
keys.map((key) => {
|
|
183
|
-
const value = obj[key];
|
|
184
|
-
return [
|
|
185
|
-
key,
|
|
186
|
-
typeof value === "function" ? /* @__PURE__ */ reactify(value.bind(obj), options) : value
|
|
187
|
-
];
|
|
188
|
-
})
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
function toReactive(objectRef) {
|
|
192
|
-
if (!isRef(objectRef))
|
|
193
|
-
return reactive(objectRef);
|
|
194
|
-
const proxy = new Proxy({}, {
|
|
195
|
-
get(_, p, receiver) {
|
|
196
|
-
return unref(Reflect.get(objectRef.value, p, receiver));
|
|
197
|
-
},
|
|
198
|
-
set(_, p, value) {
|
|
199
|
-
if (isRef(objectRef.value[p]) && !isRef(value))
|
|
200
|
-
objectRef.value[p].value = value;
|
|
201
|
-
else
|
|
202
|
-
objectRef.value[p] = value;
|
|
203
|
-
return true;
|
|
204
|
-
},
|
|
205
|
-
deleteProperty(_, p) {
|
|
206
|
-
return Reflect.deleteProperty(objectRef.value, p);
|
|
207
|
-
},
|
|
208
|
-
has(_, p) {
|
|
209
|
-
return Reflect.has(objectRef.value, p);
|
|
210
|
-
},
|
|
211
|
-
ownKeys() {
|
|
212
|
-
return Object.keys(objectRef.value);
|
|
213
|
-
},
|
|
214
|
-
getOwnPropertyDescriptor() {
|
|
215
|
-
return {
|
|
216
|
-
enumerable: true,
|
|
217
|
-
configurable: true
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
return reactive(proxy);
|
|
222
|
-
}
|
|
223
|
-
function reactiveComputed(fn) {
|
|
224
|
-
return toReactive(computed(fn));
|
|
225
|
-
}
|
|
226
|
-
function reactiveOmit(obj, ...keys) {
|
|
227
|
-
const flatKeys = keys.flat();
|
|
228
|
-
const predicate = flatKeys[0];
|
|
229
|
-
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => !predicate(toValue$1(v), k))) : Object.fromEntries(Object.entries(toRefs$1(obj)).filter((e) => !flatKeys.includes(e[0]))));
|
|
88
|
+
if (deep === true) return ref(value);
|
|
89
|
+
else return shallowRef(value);
|
|
230
90
|
}
|
|
231
91
|
const isClient = typeof window !== "undefined" && typeof document !== "undefined";
|
|
232
92
|
const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
|
|
233
93
|
const isDef = (val) => typeof val !== "undefined";
|
|
234
94
|
const notNullish = (val) => val != null;
|
|
235
95
|
const assert = (condition, ...infos) => {
|
|
236
|
-
if (!condition)
|
|
237
|
-
console.warn(...infos);
|
|
96
|
+
if (!condition) console.warn(...infos);
|
|
238
97
|
};
|
|
239
98
|
const toString = Object.prototype.toString;
|
|
240
99
|
const isObject = (val) => toString.call(val) === "[object Object]";
|
|
@@ -249,92 +108,62 @@ const rand = (min, max) => {
|
|
|
249
108
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
250
109
|
};
|
|
251
110
|
const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
|
|
252
|
-
function
|
|
253
|
-
if (args.length !== 1)
|
|
254
|
-
return toRef$1(...args);
|
|
111
|
+
function toRef2(...args) {
|
|
112
|
+
if (args.length !== 1) return toRef$1(...args);
|
|
255
113
|
const r = args[0];
|
|
256
|
-
return typeof r === "function" ? readonly(customRef(() => ({
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const flatKeys = keys.flat();
|
|
261
|
-
const predicate = flatKeys[0];
|
|
262
|
-
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => predicate(toValue$1(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
|
|
263
|
-
}
|
|
264
|
-
function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
265
|
-
return customRef((track, trigger) => {
|
|
266
|
-
let value = toValue$1(defaultValue);
|
|
267
|
-
let timer;
|
|
268
|
-
const resetAfter = () => setTimeout(() => {
|
|
269
|
-
value = toValue$1(defaultValue);
|
|
270
|
-
trigger();
|
|
271
|
-
}, toValue$1(afterMs));
|
|
272
|
-
tryOnScopeDispose(() => {
|
|
273
|
-
clearTimeout(timer);
|
|
274
|
-
});
|
|
275
|
-
return {
|
|
276
|
-
get() {
|
|
277
|
-
track();
|
|
278
|
-
return value;
|
|
279
|
-
},
|
|
280
|
-
set(newValue) {
|
|
281
|
-
value = newValue;
|
|
282
|
-
trigger();
|
|
283
|
-
clearTimeout(timer);
|
|
284
|
-
timer = resetAfter();
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
});
|
|
114
|
+
return typeof r === "function" ? readonly(customRef(() => ({
|
|
115
|
+
get: r,
|
|
116
|
+
set: noop
|
|
117
|
+
}))) : ref(r);
|
|
288
118
|
}
|
|
289
119
|
function createFilterWrapper(filter, fn) {
|
|
290
120
|
function wrapper(...args) {
|
|
291
121
|
return new Promise((resolve, reject) => {
|
|
292
|
-
Promise.resolve(filter(() => fn.apply(this, args), {
|
|
122
|
+
Promise.resolve(filter(() => fn.apply(this, args), {
|
|
123
|
+
fn,
|
|
124
|
+
thisArg: this,
|
|
125
|
+
args
|
|
126
|
+
})).then(resolve).catch(reject);
|
|
293
127
|
});
|
|
294
128
|
}
|
|
295
129
|
return wrapper;
|
|
296
130
|
}
|
|
297
|
-
const bypassFilter = (
|
|
298
|
-
return
|
|
131
|
+
const bypassFilter = (invoke$1) => {
|
|
132
|
+
return invoke$1();
|
|
299
133
|
};
|
|
300
134
|
function debounceFilter(ms, options = {}) {
|
|
301
135
|
let timer;
|
|
302
136
|
let maxTimer;
|
|
303
137
|
let lastRejector = noop;
|
|
304
|
-
const _clearTimeout = (
|
|
305
|
-
clearTimeout(
|
|
138
|
+
const _clearTimeout = (timer$1) => {
|
|
139
|
+
clearTimeout(timer$1);
|
|
306
140
|
lastRejector();
|
|
307
141
|
lastRejector = noop;
|
|
308
142
|
};
|
|
309
143
|
let lastInvoker;
|
|
310
|
-
const filter = (
|
|
311
|
-
const duration = toValue
|
|
312
|
-
const maxDuration = toValue
|
|
313
|
-
if (timer)
|
|
314
|
-
_clearTimeout(timer);
|
|
144
|
+
const filter = (invoke$1) => {
|
|
145
|
+
const duration = toValue(ms);
|
|
146
|
+
const maxDuration = toValue(options.maxWait);
|
|
147
|
+
if (timer) _clearTimeout(timer);
|
|
315
148
|
if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
|
|
316
149
|
if (maxTimer) {
|
|
317
150
|
_clearTimeout(maxTimer);
|
|
318
151
|
maxTimer = void 0;
|
|
319
152
|
}
|
|
320
|
-
return Promise.resolve(
|
|
153
|
+
return Promise.resolve(invoke$1());
|
|
321
154
|
}
|
|
322
155
|
return new Promise((resolve, reject) => {
|
|
323
156
|
lastRejector = options.rejectOnCancel ? reject : resolve;
|
|
324
|
-
lastInvoker =
|
|
325
|
-
if (maxDuration && !maxTimer) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
resolve(lastInvoker());
|
|
331
|
-
}, maxDuration);
|
|
332
|
-
}
|
|
157
|
+
lastInvoker = invoke$1;
|
|
158
|
+
if (maxDuration && !maxTimer) maxTimer = setTimeout(() => {
|
|
159
|
+
if (timer) _clearTimeout(timer);
|
|
160
|
+
maxTimer = void 0;
|
|
161
|
+
resolve(lastInvoker());
|
|
162
|
+
}, maxDuration);
|
|
333
163
|
timer = setTimeout(() => {
|
|
334
|
-
if (maxTimer)
|
|
335
|
-
_clearTimeout(maxTimer);
|
|
164
|
+
if (maxTimer) _clearTimeout(maxTimer);
|
|
336
165
|
maxTimer = void 0;
|
|
337
|
-
resolve(
|
|
166
|
+
resolve(invoke$1());
|
|
338
167
|
}, duration);
|
|
339
168
|
});
|
|
340
169
|
};
|
|
@@ -350,10 +179,8 @@ function throttleFilter(...args) {
|
|
|
350
179
|
let trailing;
|
|
351
180
|
let leading;
|
|
352
181
|
let rejectOnCancel;
|
|
353
|
-
if (!isRef(args[0]) && typeof args[0] === "object")
|
|
354
|
-
|
|
355
|
-
else
|
|
356
|
-
[ms, trailing = true, leading = true, rejectOnCancel = false] = args;
|
|
182
|
+
if (!isRef(args[0]) && typeof args[0] === "object") ({ delay: ms, trailing = true, leading = true, rejectOnCancel = false } = args[0]);
|
|
183
|
+
else [ms, trailing = true, leading = true, rejectOnCancel = false] = args;
|
|
357
184
|
const clear = () => {
|
|
358
185
|
if (timer) {
|
|
359
186
|
clearTimeout(timer);
|
|
@@ -363,42 +190,37 @@ function throttleFilter(...args) {
|
|
|
363
190
|
}
|
|
364
191
|
};
|
|
365
192
|
const filter = (_invoke) => {
|
|
366
|
-
const duration = toValue
|
|
193
|
+
const duration = toValue(ms);
|
|
367
194
|
const elapsed = Date.now() - lastExec;
|
|
368
|
-
const
|
|
195
|
+
const invoke$1 = () => {
|
|
369
196
|
return lastValue = _invoke();
|
|
370
197
|
};
|
|
371
198
|
clear();
|
|
372
199
|
if (duration <= 0) {
|
|
373
200
|
lastExec = Date.now();
|
|
374
|
-
return
|
|
201
|
+
return invoke$1();
|
|
375
202
|
}
|
|
376
|
-
if (elapsed > duration
|
|
203
|
+
if (elapsed > duration) {
|
|
377
204
|
lastExec = Date.now();
|
|
378
|
-
|
|
379
|
-
} else if (trailing) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
if (!leading && !timer)
|
|
391
|
-
timer = setTimeout(() => isLeading = true, duration);
|
|
205
|
+
if (leading || !isLeading) invoke$1();
|
|
206
|
+
} else if (trailing) lastValue = new Promise((resolve, reject) => {
|
|
207
|
+
lastRejector = rejectOnCancel ? reject : resolve;
|
|
208
|
+
timer = setTimeout(() => {
|
|
209
|
+
lastExec = Date.now();
|
|
210
|
+
isLeading = true;
|
|
211
|
+
resolve(invoke$1());
|
|
212
|
+
clear();
|
|
213
|
+
}, Math.max(0, duration - elapsed));
|
|
214
|
+
});
|
|
215
|
+
if (!leading && !timer) timer = setTimeout(() => isLeading = true, duration);
|
|
392
216
|
isLeading = false;
|
|
393
217
|
return lastValue;
|
|
394
218
|
};
|
|
395
219
|
return filter;
|
|
396
220
|
}
|
|
397
221
|
function pausableFilter(extendFilter = bypassFilter, options = {}) {
|
|
398
|
-
const {
|
|
399
|
-
|
|
400
|
-
} = options;
|
|
401
|
-
const isActive = toRef(initialState === "active");
|
|
222
|
+
const { initialState = "active" } = options;
|
|
223
|
+
const isActive = toRef2(initialState === "active");
|
|
402
224
|
function pause() {
|
|
403
225
|
isActive.value = false;
|
|
404
226
|
}
|
|
@@ -406,17 +228,19 @@ function pausableFilter(extendFilter = bypassFilter, options = {}) {
|
|
|
406
228
|
isActive.value = true;
|
|
407
229
|
}
|
|
408
230
|
const eventFilter = (...args) => {
|
|
409
|
-
if (isActive.value)
|
|
410
|
-
|
|
231
|
+
if (isActive.value) extendFilter(...args);
|
|
232
|
+
};
|
|
233
|
+
return {
|
|
234
|
+
isActive: readonly(isActive),
|
|
235
|
+
pause,
|
|
236
|
+
resume,
|
|
237
|
+
eventFilter
|
|
411
238
|
};
|
|
412
|
-
return { isActive: readonly(isActive), pause, resume, eventFilter };
|
|
413
239
|
}
|
|
414
240
|
function promiseTimeout(ms, throwOnTimeout = false, reason = "Timeout") {
|
|
415
241
|
return new Promise((resolve, reject) => {
|
|
416
|
-
if (throwOnTimeout)
|
|
417
|
-
|
|
418
|
-
else
|
|
419
|
-
setTimeout(resolve, ms);
|
|
242
|
+
if (throwOnTimeout) setTimeout(() => reject(reason), ms);
|
|
243
|
+
else setTimeout(resolve, ms);
|
|
420
244
|
});
|
|
421
245
|
}
|
|
422
246
|
function identity(arg) {
|
|
@@ -425,15 +249,13 @@ function identity(arg) {
|
|
|
425
249
|
function createSingletonPromise(fn) {
|
|
426
250
|
let _promise;
|
|
427
251
|
function wrapper() {
|
|
428
|
-
if (!_promise)
|
|
429
|
-
_promise = fn();
|
|
252
|
+
if (!_promise) _promise = fn();
|
|
430
253
|
return _promise;
|
|
431
254
|
}
|
|
432
255
|
wrapper.reset = async () => {
|
|
433
256
|
const _prev = _promise;
|
|
434
257
|
_promise = void 0;
|
|
435
|
-
if (_prev)
|
|
436
|
-
await _prev;
|
|
258
|
+
if (_prev) await _prev;
|
|
437
259
|
};
|
|
438
260
|
return wrapper;
|
|
439
261
|
}
|
|
@@ -444,21 +266,18 @@ function containsProp(obj, ...props) {
|
|
|
444
266
|
return props.some((k) => k in obj);
|
|
445
267
|
}
|
|
446
268
|
function increaseWithUnit(target, delta) {
|
|
447
|
-
var
|
|
448
|
-
if (typeof target === "number")
|
|
449
|
-
|
|
450
|
-
const value = ((_a = target.match(/^-?\d+\.?\d*/)) == null ? void 0 : _a[0]) || "";
|
|
269
|
+
var _target$match;
|
|
270
|
+
if (typeof target === "number") return target + delta;
|
|
271
|
+
const value = ((_target$match = target.match(/^-?\d+\.?\d*/)) === null || _target$match === void 0 ? void 0 : _target$match[0]) || "";
|
|
451
272
|
const unit = target.slice(value.length);
|
|
452
273
|
const result = Number.parseFloat(value) + delta;
|
|
453
|
-
if (Number.isNaN(result))
|
|
454
|
-
return target;
|
|
274
|
+
if (Number.isNaN(result)) return target;
|
|
455
275
|
return result + unit;
|
|
456
276
|
}
|
|
457
277
|
function objectPick(obj, keys, omitUndefined = false) {
|
|
458
278
|
return keys.reduce((n, k) => {
|
|
459
279
|
if (k in obj) {
|
|
460
|
-
if (!omitUndefined || obj[k] !== void 0)
|
|
461
|
-
n[k] = obj[k];
|
|
280
|
+
if (!omitUndefined || obj[k] !== void 0) n[k] = obj[k];
|
|
462
281
|
}
|
|
463
282
|
return n;
|
|
464
283
|
}, {});
|
|
@@ -476,10 +295,9 @@ function toArray(value) {
|
|
|
476
295
|
}
|
|
477
296
|
function cacheStringFunction(fn) {
|
|
478
297
|
const cache = /* @__PURE__ */ Object.create(null);
|
|
479
|
-
return (str) => {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
};
|
|
298
|
+
return ((str) => {
|
|
299
|
+
return cache[str] || (cache[str] = fn(str));
|
|
300
|
+
});
|
|
483
301
|
}
|
|
484
302
|
const hyphenateRE = /\B([A-Z])/g;
|
|
485
303
|
const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
@@ -488,17 +306,170 @@ const camelize = cacheStringFunction((str) => {
|
|
|
488
306
|
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
|
489
307
|
});
|
|
490
308
|
function getLifeCycleTarget(target) {
|
|
491
|
-
return target ||
|
|
309
|
+
return target || getCurrentInstance();
|
|
310
|
+
}
|
|
311
|
+
// @__NO_SIDE_EFFECTS__
|
|
312
|
+
function createSharedComposable(composable) {
|
|
313
|
+
if (!isClient) return composable;
|
|
314
|
+
let subscribers = 0;
|
|
315
|
+
let state;
|
|
316
|
+
let scope;
|
|
317
|
+
const dispose = () => {
|
|
318
|
+
subscribers -= 1;
|
|
319
|
+
if (scope && subscribers <= 0) {
|
|
320
|
+
scope.stop();
|
|
321
|
+
state = void 0;
|
|
322
|
+
scope = void 0;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
return ((...args) => {
|
|
326
|
+
subscribers += 1;
|
|
327
|
+
if (!scope) {
|
|
328
|
+
scope = effectScope(true);
|
|
329
|
+
state = scope.run(() => composable(...args));
|
|
330
|
+
}
|
|
331
|
+
tryOnScopeDispose(dispose);
|
|
332
|
+
return state;
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function extendRef(ref$1, extend, { enumerable = false, unwrap = true } = {}) {
|
|
336
|
+
for (const [key, value] of Object.entries(extend)) {
|
|
337
|
+
if (key === "value") continue;
|
|
338
|
+
if (isRef(value) && unwrap) Object.defineProperty(ref$1, key, {
|
|
339
|
+
get() {
|
|
340
|
+
return value.value;
|
|
341
|
+
},
|
|
342
|
+
set(v) {
|
|
343
|
+
value.value = v;
|
|
344
|
+
},
|
|
345
|
+
enumerable
|
|
346
|
+
});
|
|
347
|
+
else Object.defineProperty(ref$1, key, {
|
|
348
|
+
value,
|
|
349
|
+
enumerable
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
return ref$1;
|
|
353
|
+
}
|
|
354
|
+
function get(obj, key) {
|
|
355
|
+
if (key == null) return unref(obj);
|
|
356
|
+
return unref(obj)[key];
|
|
357
|
+
}
|
|
358
|
+
function isDefined(v) {
|
|
359
|
+
return unref(v) != null;
|
|
360
|
+
}
|
|
361
|
+
// @__NO_SIDE_EFFECTS__
|
|
362
|
+
function makeDestructurable(obj, arr) {
|
|
363
|
+
if (typeof Symbol !== "undefined") {
|
|
364
|
+
const clone = { ...obj };
|
|
365
|
+
Object.defineProperty(clone, Symbol.iterator, {
|
|
366
|
+
enumerable: false,
|
|
367
|
+
value() {
|
|
368
|
+
let index = 0;
|
|
369
|
+
return { next: () => ({
|
|
370
|
+
value: arr[index++],
|
|
371
|
+
done: index > arr.length
|
|
372
|
+
}) };
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
return clone;
|
|
376
|
+
} else return Object.assign([...arr], obj);
|
|
377
|
+
}
|
|
378
|
+
// @__NO_SIDE_EFFECTS__
|
|
379
|
+
function reactify(fn, options) {
|
|
380
|
+
const unrefFn = (options === null || options === void 0 ? void 0 : options.computedGetter) === false ? unref : toValue;
|
|
381
|
+
return function(...args) {
|
|
382
|
+
return computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
// @__NO_SIDE_EFFECTS__
|
|
386
|
+
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
387
|
+
let keys = [];
|
|
388
|
+
let options;
|
|
389
|
+
if (Array.isArray(optionsOrKeys)) keys = optionsOrKeys;
|
|
390
|
+
else {
|
|
391
|
+
options = optionsOrKeys;
|
|
392
|
+
const { includeOwnProperties = true } = optionsOrKeys;
|
|
393
|
+
keys.push(...Object.keys(obj));
|
|
394
|
+
if (includeOwnProperties) keys.push(...Object.getOwnPropertyNames(obj));
|
|
395
|
+
}
|
|
396
|
+
return Object.fromEntries(keys.map((key) => {
|
|
397
|
+
const value = obj[key];
|
|
398
|
+
return [key, typeof value === "function" ? /* @__PURE__ */ reactify(value.bind(obj), options) : value];
|
|
399
|
+
}));
|
|
400
|
+
}
|
|
401
|
+
function toReactive(objectRef) {
|
|
402
|
+
if (!isRef(objectRef)) return reactive(objectRef);
|
|
403
|
+
return reactive(new Proxy({}, {
|
|
404
|
+
get(_, p, receiver) {
|
|
405
|
+
return unref(Reflect.get(objectRef.value, p, receiver));
|
|
406
|
+
},
|
|
407
|
+
set(_, p, value) {
|
|
408
|
+
if (isRef(objectRef.value[p]) && !isRef(value)) objectRef.value[p].value = value;
|
|
409
|
+
else objectRef.value[p] = value;
|
|
410
|
+
return true;
|
|
411
|
+
},
|
|
412
|
+
deleteProperty(_, p) {
|
|
413
|
+
return Reflect.deleteProperty(objectRef.value, p);
|
|
414
|
+
},
|
|
415
|
+
has(_, p) {
|
|
416
|
+
return Reflect.has(objectRef.value, p);
|
|
417
|
+
},
|
|
418
|
+
ownKeys() {
|
|
419
|
+
return Object.keys(objectRef.value);
|
|
420
|
+
},
|
|
421
|
+
getOwnPropertyDescriptor() {
|
|
422
|
+
return {
|
|
423
|
+
enumerable: true,
|
|
424
|
+
configurable: true
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
}));
|
|
428
|
+
}
|
|
429
|
+
function reactiveComputed(fn) {
|
|
430
|
+
return toReactive(computed(fn));
|
|
431
|
+
}
|
|
432
|
+
function reactiveOmit(obj, ...keys) {
|
|
433
|
+
const flatKeys = keys.flat();
|
|
434
|
+
const predicate = flatKeys[0];
|
|
435
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(toRefs$1(obj)).filter((e) => !flatKeys.includes(e[0]))));
|
|
436
|
+
}
|
|
437
|
+
function reactivePick(obj, ...keys) {
|
|
438
|
+
const flatKeys = keys.flat();
|
|
439
|
+
const predicate = flatKeys[0];
|
|
440
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => predicate(toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef2(obj, k)])));
|
|
441
|
+
}
|
|
442
|
+
function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
443
|
+
return customRef((track, trigger) => {
|
|
444
|
+
let value = toValue(defaultValue);
|
|
445
|
+
let timer;
|
|
446
|
+
const resetAfter = () => setTimeout(() => {
|
|
447
|
+
value = toValue(defaultValue);
|
|
448
|
+
trigger();
|
|
449
|
+
}, toValue(afterMs));
|
|
450
|
+
tryOnScopeDispose(() => {
|
|
451
|
+
clearTimeout(timer);
|
|
452
|
+
});
|
|
453
|
+
return {
|
|
454
|
+
get() {
|
|
455
|
+
track();
|
|
456
|
+
return value;
|
|
457
|
+
},
|
|
458
|
+
set(newValue) {
|
|
459
|
+
value = newValue;
|
|
460
|
+
trigger();
|
|
461
|
+
clearTimeout(timer);
|
|
462
|
+
timer = resetAfter();
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
});
|
|
492
466
|
}
|
|
493
467
|
// @__NO_SIDE_EFFECTS__
|
|
494
468
|
function useDebounceFn(fn, ms = 200, options = {}) {
|
|
495
|
-
return createFilterWrapper(
|
|
496
|
-
debounceFilter(ms, options),
|
|
497
|
-
fn
|
|
498
|
-
);
|
|
469
|
+
return createFilterWrapper(debounceFilter(ms, options), fn);
|
|
499
470
|
}
|
|
500
471
|
function refDebounced(value, ms = 200, options = {}) {
|
|
501
|
-
const debounced = ref(toValue
|
|
472
|
+
const debounced = ref(toValue(value));
|
|
502
473
|
const updater = /* @__PURE__ */ useDebounceFn(() => {
|
|
503
474
|
debounced.value = value.value;
|
|
504
475
|
}, ms, options);
|
|
@@ -509,8 +480,8 @@ function refDebounced(value, ms = 200, options = {}) {
|
|
|
509
480
|
function refDefault(source, defaultValue) {
|
|
510
481
|
return computed({
|
|
511
482
|
get() {
|
|
512
|
-
var
|
|
513
|
-
return (
|
|
483
|
+
var _source$value;
|
|
484
|
+
return (_source$value = source.value) !== null && _source$value !== void 0 ? _source$value : defaultValue;
|
|
514
485
|
},
|
|
515
486
|
set(value) {
|
|
516
487
|
source.value = value;
|
|
@@ -519,15 +490,11 @@ function refDefault(source, defaultValue) {
|
|
|
519
490
|
}
|
|
520
491
|
// @__NO_SIDE_EFFECTS__
|
|
521
492
|
function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
|
|
522
|
-
return createFilterWrapper(
|
|
523
|
-
throttleFilter(ms, trailing, leading, rejectOnCancel),
|
|
524
|
-
fn
|
|
525
|
-
);
|
|
493
|
+
return createFilterWrapper(throttleFilter(ms, trailing, leading, rejectOnCancel), fn);
|
|
526
494
|
}
|
|
527
495
|
function refThrottled(value, delay = 200, trailing = true, leading = true) {
|
|
528
|
-
if (delay <= 0)
|
|
529
|
-
|
|
530
|
-
const throttled = ref(toValue$1(value));
|
|
496
|
+
if (delay <= 0) return value;
|
|
497
|
+
const throttled = ref(toValue(value));
|
|
531
498
|
const updater = /* @__PURE__ */ useThrottleFn(() => {
|
|
532
499
|
throttled.value = value.value;
|
|
533
500
|
}, delay, trailing, leading);
|
|
@@ -539,57 +506,49 @@ function refWithControl(initial, options = {}) {
|
|
|
539
506
|
let source = initial;
|
|
540
507
|
let track;
|
|
541
508
|
let trigger;
|
|
542
|
-
const
|
|
509
|
+
const ref$1 = customRef((_track, _trigger) => {
|
|
543
510
|
track = _track;
|
|
544
511
|
trigger = _trigger;
|
|
545
512
|
return {
|
|
546
513
|
get() {
|
|
547
|
-
return
|
|
514
|
+
return get$1();
|
|
548
515
|
},
|
|
549
516
|
set(v) {
|
|
550
|
-
|
|
517
|
+
set$1(v);
|
|
551
518
|
}
|
|
552
519
|
};
|
|
553
520
|
});
|
|
554
|
-
function
|
|
555
|
-
if (tracking)
|
|
556
|
-
track();
|
|
521
|
+
function get$1(tracking = true) {
|
|
522
|
+
if (tracking) track();
|
|
557
523
|
return source;
|
|
558
524
|
}
|
|
559
|
-
function
|
|
560
|
-
var
|
|
561
|
-
if (value === source)
|
|
562
|
-
return;
|
|
525
|
+
function set$1(value, triggering = true) {
|
|
526
|
+
var _options$onBeforeChan, _options$onChanged;
|
|
527
|
+
if (value === source) return;
|
|
563
528
|
const old = source;
|
|
564
|
-
if (((
|
|
565
|
-
return;
|
|
529
|
+
if (((_options$onBeforeChan = options.onBeforeChange) === null || _options$onBeforeChan === void 0 ? void 0 : _options$onBeforeChan.call(options, value, old)) === false) return;
|
|
566
530
|
source = value;
|
|
567
|
-
(
|
|
568
|
-
if (triggering)
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
const
|
|
572
|
-
const
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
peek,
|
|
583
|
-
lay
|
|
584
|
-
},
|
|
585
|
-
{ enumerable: true }
|
|
586
|
-
);
|
|
531
|
+
(_options$onChanged = options.onChanged) === null || _options$onChanged === void 0 || _options$onChanged.call(options, value, old);
|
|
532
|
+
if (triggering) trigger();
|
|
533
|
+
}
|
|
534
|
+
const untrackedGet = () => get$1(false);
|
|
535
|
+
const silentSet = (v) => set$1(v, false);
|
|
536
|
+
const peek = () => get$1(false);
|
|
537
|
+
const lay = (v) => set$1(v, false);
|
|
538
|
+
return extendRef(ref$1, {
|
|
539
|
+
get: get$1,
|
|
540
|
+
set: set$1,
|
|
541
|
+
untrackedGet,
|
|
542
|
+
silentSet,
|
|
543
|
+
peek,
|
|
544
|
+
lay
|
|
545
|
+
}, { enumerable: true });
|
|
587
546
|
}
|
|
588
547
|
const controlledRef = refWithControl;
|
|
589
548
|
function set(...args) {
|
|
590
549
|
if (args.length === 2) {
|
|
591
|
-
const [
|
|
592
|
-
|
|
550
|
+
const [ref$1, value] = args;
|
|
551
|
+
ref$1.value = value;
|
|
593
552
|
}
|
|
594
553
|
if (args.length === 3) {
|
|
595
554
|
const [target, key, value] = args;
|
|
@@ -597,191 +556,131 @@ function set(...args) {
|
|
|
597
556
|
}
|
|
598
557
|
}
|
|
599
558
|
function watchWithFilter(source, cb, options = {}) {
|
|
600
|
-
const {
|
|
601
|
-
|
|
602
|
-
...watchOptions
|
|
603
|
-
} = options;
|
|
604
|
-
return watch(
|
|
605
|
-
source,
|
|
606
|
-
createFilterWrapper(
|
|
607
|
-
eventFilter,
|
|
608
|
-
cb
|
|
609
|
-
),
|
|
610
|
-
watchOptions
|
|
611
|
-
);
|
|
559
|
+
const { eventFilter = bypassFilter, ...watchOptions } = options;
|
|
560
|
+
return watch(source, createFilterWrapper(eventFilter, cb), watchOptions);
|
|
612
561
|
}
|
|
613
562
|
function watchPausable(source, cb, options = {}) {
|
|
614
|
-
const {
|
|
615
|
-
eventFilter: filter,
|
|
616
|
-
initialState = "active",
|
|
617
|
-
...watchOptions
|
|
618
|
-
} = options;
|
|
563
|
+
const { eventFilter: filter, initialState = "active", ...watchOptions } = options;
|
|
619
564
|
const { eventFilter, pause, resume, isActive } = pausableFilter(filter, { initialState });
|
|
620
|
-
|
|
621
|
-
source,
|
|
622
|
-
cb,
|
|
623
|
-
{
|
|
565
|
+
return {
|
|
566
|
+
stop: watchWithFilter(source, cb, {
|
|
624
567
|
...watchOptions,
|
|
625
568
|
eventFilter
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
|
|
569
|
+
}),
|
|
570
|
+
pause,
|
|
571
|
+
resume,
|
|
572
|
+
isActive
|
|
573
|
+
};
|
|
629
574
|
}
|
|
575
|
+
const pausableWatch = watchPausable;
|
|
630
576
|
function syncRef(left, right, ...[options]) {
|
|
631
|
-
const {
|
|
632
|
-
flush = "sync",
|
|
633
|
-
deep = false,
|
|
634
|
-
immediate = true,
|
|
635
|
-
direction = "both",
|
|
636
|
-
transform = {}
|
|
637
|
-
} = options || {};
|
|
577
|
+
const { flush = "sync", deep = false, immediate = true, direction = "both", transform = {} } = options || {};
|
|
638
578
|
const watchers = [];
|
|
639
579
|
const transformLTR = "ltr" in transform && transform.ltr || ((v) => v);
|
|
640
580
|
const transformRTL = "rtl" in transform && transform.rtl || ((v) => v);
|
|
641
|
-
if (direction === "both" || direction === "ltr") {
|
|
642
|
-
watchers.
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
watchers.
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
},
|
|
660
|
-
{ flush, deep, immediate }
|
|
661
|
-
));
|
|
662
|
-
}
|
|
581
|
+
if (direction === "both" || direction === "ltr") watchers.push(pausableWatch(left, (newValue) => {
|
|
582
|
+
watchers.forEach((w) => w.pause());
|
|
583
|
+
right.value = transformLTR(newValue);
|
|
584
|
+
watchers.forEach((w) => w.resume());
|
|
585
|
+
}, {
|
|
586
|
+
flush,
|
|
587
|
+
deep,
|
|
588
|
+
immediate
|
|
589
|
+
}));
|
|
590
|
+
if (direction === "both" || direction === "rtl") watchers.push(pausableWatch(right, (newValue) => {
|
|
591
|
+
watchers.forEach((w) => w.pause());
|
|
592
|
+
left.value = transformRTL(newValue);
|
|
593
|
+
watchers.forEach((w) => w.resume());
|
|
594
|
+
}, {
|
|
595
|
+
flush,
|
|
596
|
+
deep,
|
|
597
|
+
immediate
|
|
598
|
+
}));
|
|
663
599
|
const stop = () => {
|
|
664
600
|
watchers.forEach((w) => w.stop());
|
|
665
601
|
};
|
|
666
602
|
return stop;
|
|
667
603
|
}
|
|
668
604
|
function syncRefs(source, targets, options = {}) {
|
|
669
|
-
const {
|
|
670
|
-
flush = "sync",
|
|
671
|
-
deep = false,
|
|
672
|
-
immediate = true
|
|
673
|
-
} = options;
|
|
605
|
+
const { flush = "sync", deep = false, immediate = true } = options;
|
|
674
606
|
const targetsArray = toArray(targets);
|
|
675
|
-
return watch(
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
);
|
|
607
|
+
return watch(source, (newValue) => targetsArray.forEach((target) => target.value = newValue), {
|
|
608
|
+
flush,
|
|
609
|
+
deep,
|
|
610
|
+
immediate
|
|
611
|
+
});
|
|
680
612
|
}
|
|
681
613
|
function toRefs(objectRef, options = {}) {
|
|
682
|
-
if (!isRef(objectRef))
|
|
683
|
-
return toRefs$1(objectRef);
|
|
614
|
+
if (!isRef(objectRef)) return toRefs$1(objectRef);
|
|
684
615
|
const result = Array.isArray(objectRef.value) ? Array.from({ length: objectRef.value.length }) : {};
|
|
685
|
-
for (const key in objectRef.value) {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
}
|
|
703
|
-
} else {
|
|
704
|
-
objectRef.value[key] = v;
|
|
705
|
-
}
|
|
616
|
+
for (const key in objectRef.value) result[key] = customRef(() => ({
|
|
617
|
+
get() {
|
|
618
|
+
return objectRef.value[key];
|
|
619
|
+
},
|
|
620
|
+
set(v) {
|
|
621
|
+
var _toValue;
|
|
622
|
+
if ((_toValue = toValue(options.replaceRef)) !== null && _toValue !== void 0 ? _toValue : true) if (Array.isArray(objectRef.value)) {
|
|
623
|
+
const copy = [...objectRef.value];
|
|
624
|
+
copy[key] = v;
|
|
625
|
+
objectRef.value = copy;
|
|
626
|
+
} else {
|
|
627
|
+
const newObject = {
|
|
628
|
+
...objectRef.value,
|
|
629
|
+
[key]: v
|
|
630
|
+
};
|
|
631
|
+
Object.setPrototypeOf(newObject, Object.getPrototypeOf(objectRef.value));
|
|
632
|
+
objectRef.value = newObject;
|
|
706
633
|
}
|
|
707
|
-
|
|
708
|
-
|
|
634
|
+
else objectRef.value[key] = v;
|
|
635
|
+
}
|
|
636
|
+
}));
|
|
709
637
|
return result;
|
|
710
638
|
}
|
|
711
|
-
const toValue = toValue$1;
|
|
712
|
-
const resolveUnref = toValue$1;
|
|
713
639
|
function tryOnMounted(fn, sync = true, target) {
|
|
714
|
-
|
|
715
|
-
if (
|
|
716
|
-
|
|
717
|
-
else if (sync)
|
|
718
|
-
fn();
|
|
719
|
-
else
|
|
720
|
-
nextTick(fn);
|
|
640
|
+
if (getLifeCycleTarget(target)) ;
|
|
641
|
+
else if (sync) fn();
|
|
642
|
+
else nextTick(fn);
|
|
721
643
|
}
|
|
722
644
|
function createUntil(r, isNot = false) {
|
|
723
645
|
function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
|
|
724
646
|
let stop = null;
|
|
725
|
-
const
|
|
726
|
-
stop = watch(
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
stop();
|
|
732
|
-
else
|
|
733
|
-
nextTick(() => stop == null ? void 0 : stop());
|
|
734
|
-
resolve(v);
|
|
735
|
-
}
|
|
736
|
-
},
|
|
737
|
-
{
|
|
738
|
-
flush,
|
|
739
|
-
deep,
|
|
740
|
-
immediate: true
|
|
647
|
+
const promises = [new Promise((resolve) => {
|
|
648
|
+
stop = watch(r, (v) => {
|
|
649
|
+
if (condition(v) !== isNot) {
|
|
650
|
+
if (stop) stop();
|
|
651
|
+
else nextTick(() => stop === null || stop === void 0 ? void 0 : stop());
|
|
652
|
+
resolve(v);
|
|
741
653
|
}
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
}
|
|
654
|
+
}, {
|
|
655
|
+
flush,
|
|
656
|
+
deep,
|
|
657
|
+
immediate: true
|
|
658
|
+
});
|
|
659
|
+
})];
|
|
660
|
+
if (timeout != null) promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => stop === null || stop === void 0 ? void 0 : stop()));
|
|
750
661
|
return Promise.race(promises);
|
|
751
662
|
}
|
|
752
663
|
function toBe(value, options) {
|
|
753
|
-
if (!isRef(value))
|
|
754
|
-
|
|
755
|
-
const { flush = "sync", deep = false, timeout, throwOnTimeout } = options != null ? options : {};
|
|
664
|
+
if (!isRef(value)) return toMatch((v) => v === value, options);
|
|
665
|
+
const { flush = "sync", deep = false, timeout, throwOnTimeout } = options !== null && options !== void 0 ? options : {};
|
|
756
666
|
let stop = null;
|
|
757
|
-
const
|
|
758
|
-
stop = watch(
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
stop();
|
|
764
|
-
else
|
|
765
|
-
nextTick(() => stop == null ? void 0 : stop());
|
|
766
|
-
resolve(v1);
|
|
767
|
-
}
|
|
768
|
-
},
|
|
769
|
-
{
|
|
770
|
-
flush,
|
|
771
|
-
deep,
|
|
772
|
-
immediate: true
|
|
667
|
+
const promises = [new Promise((resolve) => {
|
|
668
|
+
stop = watch([r, value], ([v1, v2]) => {
|
|
669
|
+
if (isNot !== (v1 === v2)) {
|
|
670
|
+
if (stop) stop();
|
|
671
|
+
else nextTick(() => stop === null || stop === void 0 ? void 0 : stop());
|
|
672
|
+
resolve(v1);
|
|
773
673
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
}
|
|
674
|
+
}, {
|
|
675
|
+
flush,
|
|
676
|
+
deep,
|
|
677
|
+
immediate: true
|
|
678
|
+
});
|
|
679
|
+
})];
|
|
680
|
+
if (timeout != null) promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => {
|
|
681
|
+
stop === null || stop === void 0 || stop();
|
|
682
|
+
return toValue(r);
|
|
683
|
+
}));
|
|
785
684
|
return Promise.race(promises);
|
|
786
685
|
}
|
|
787
686
|
function toBeTruthy(options) {
|
|
@@ -799,7 +698,7 @@ function createUntil(r, isNot = false) {
|
|
|
799
698
|
function toContains(value, options) {
|
|
800
699
|
return toMatch((v) => {
|
|
801
700
|
const array = Array.from(v);
|
|
802
|
-
return array.includes(value) || array.includes(toValue
|
|
701
|
+
return array.includes(value) || array.includes(toValue(value));
|
|
803
702
|
}, options);
|
|
804
703
|
}
|
|
805
704
|
function changed(options) {
|
|
@@ -812,33 +711,28 @@ function createUntil(r, isNot = false) {
|
|
|
812
711
|
return count >= n;
|
|
813
712
|
}, options);
|
|
814
713
|
}
|
|
815
|
-
if (Array.isArray(toValue
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
return createUntil(r, !isNot);
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
return instance;
|
|
841
|
-
}
|
|
714
|
+
if (Array.isArray(toValue(r))) return {
|
|
715
|
+
toMatch,
|
|
716
|
+
toContains,
|
|
717
|
+
changed,
|
|
718
|
+
changedTimes,
|
|
719
|
+
get not() {
|
|
720
|
+
return createUntil(r, !isNot);
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
else return {
|
|
724
|
+
toMatch,
|
|
725
|
+
toBe,
|
|
726
|
+
toBeTruthy,
|
|
727
|
+
toBeNull,
|
|
728
|
+
toBeNaN,
|
|
729
|
+
toBeUndefined,
|
|
730
|
+
changed,
|
|
731
|
+
changedTimes,
|
|
732
|
+
get not() {
|
|
733
|
+
return createUntil(r, !isNot);
|
|
734
|
+
}
|
|
735
|
+
};
|
|
842
736
|
}
|
|
843
737
|
function until(r) {
|
|
844
738
|
return createUntil(r);
|
|
@@ -848,152 +742,143 @@ function defaultComparator(value, othVal) {
|
|
|
848
742
|
}
|
|
849
743
|
// @__NO_SIDE_EFFECTS__
|
|
850
744
|
function useArrayDifference(...args) {
|
|
851
|
-
var
|
|
745
|
+
var _args$, _args$2;
|
|
852
746
|
const list = args[0];
|
|
853
747
|
const values = args[1];
|
|
854
|
-
let compareFn = (
|
|
855
|
-
const {
|
|
856
|
-
symmetric = false
|
|
857
|
-
} = (_b = args[3]) != null ? _b : {};
|
|
748
|
+
let compareFn = (_args$ = args[2]) !== null && _args$ !== void 0 ? _args$ : defaultComparator;
|
|
749
|
+
const { symmetric = false } = (_args$2 = args[3]) !== null && _args$2 !== void 0 ? _args$2 : {};
|
|
858
750
|
if (typeof compareFn === "string") {
|
|
859
751
|
const key = compareFn;
|
|
860
752
|
compareFn = (value, othVal) => value[key] === othVal[key];
|
|
861
753
|
}
|
|
862
|
-
const diff1 = computed(() => toValue
|
|
754
|
+
const diff1 = computed(() => toValue(list).filter((x) => toValue(values).findIndex((y) => compareFn(x, y)) === -1));
|
|
863
755
|
if (symmetric) {
|
|
864
|
-
const diff2 = computed(() => toValue
|
|
865
|
-
return computed(() => symmetric ? [...toValue
|
|
866
|
-
} else
|
|
867
|
-
return diff1;
|
|
868
|
-
}
|
|
756
|
+
const diff2 = computed(() => toValue(values).filter((x) => toValue(list).findIndex((y) => compareFn(x, y)) === -1));
|
|
757
|
+
return computed(() => symmetric ? [...toValue(diff1), ...toValue(diff2)] : toValue(diff1));
|
|
758
|
+
} else return diff1;
|
|
869
759
|
}
|
|
870
760
|
// @__NO_SIDE_EFFECTS__
|
|
871
761
|
function useArrayEvery(list, fn) {
|
|
872
|
-
return computed(() => toValue
|
|
762
|
+
return computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
|
|
873
763
|
}
|
|
874
764
|
// @__NO_SIDE_EFFECTS__
|
|
875
765
|
function useArrayFilter(list, fn) {
|
|
876
|
-
return computed(() => toValue
|
|
766
|
+
return computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
|
|
877
767
|
}
|
|
878
768
|
// @__NO_SIDE_EFFECTS__
|
|
879
769
|
function useArrayFind(list, fn) {
|
|
880
|
-
return computed(() => toValue
|
|
881
|
-
toValue$1(list).find((element, index, array) => fn(toValue$1(element), index, array))
|
|
882
|
-
));
|
|
770
|
+
return computed(() => toValue(toValue(list).find((element, index, array) => fn(toValue(element), index, array))));
|
|
883
771
|
}
|
|
884
772
|
// @__NO_SIDE_EFFECTS__
|
|
885
773
|
function useArrayFindIndex(list, fn) {
|
|
886
|
-
return computed(() => toValue
|
|
774
|
+
return computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
|
|
887
775
|
}
|
|
888
776
|
function findLast(arr, cb) {
|
|
889
777
|
let index = arr.length;
|
|
890
|
-
while (index-- > 0)
|
|
891
|
-
if (cb(arr[index], index, arr))
|
|
892
|
-
return arr[index];
|
|
893
|
-
}
|
|
894
|
-
return void 0;
|
|
778
|
+
while (index-- > 0) if (cb(arr[index], index, arr)) return arr[index];
|
|
895
779
|
}
|
|
896
780
|
// @__NO_SIDE_EFFECTS__
|
|
897
781
|
function useArrayFindLast(list, fn) {
|
|
898
|
-
return computed(() => toValue
|
|
899
|
-
!Array.prototype.findLast ? findLast(toValue$1(list), (element, index, array) => fn(toValue$1(element), index, array)) : toValue$1(list).findLast((element, index, array) => fn(toValue$1(element), index, array))
|
|
900
|
-
));
|
|
782
|
+
return computed(() => toValue(!Array.prototype.findLast ? findLast(toValue(list), (element, index, array) => fn(toValue(element), index, array)) : toValue(list).findLast((element, index, array) => fn(toValue(element), index, array))));
|
|
901
783
|
}
|
|
902
784
|
function isArrayIncludesOptions(obj) {
|
|
903
785
|
return isObject(obj) && containsProp(obj, "formIndex", "comparator");
|
|
904
786
|
}
|
|
905
787
|
// @__NO_SIDE_EFFECTS__
|
|
906
788
|
function useArrayIncludes(...args) {
|
|
907
|
-
var
|
|
789
|
+
var _comparator;
|
|
908
790
|
const list = args[0];
|
|
909
791
|
const value = args[1];
|
|
910
792
|
let comparator = args[2];
|
|
911
793
|
let formIndex = 0;
|
|
912
794
|
if (isArrayIncludesOptions(comparator)) {
|
|
913
|
-
|
|
795
|
+
var _comparator$fromIndex;
|
|
796
|
+
formIndex = (_comparator$fromIndex = comparator.fromIndex) !== null && _comparator$fromIndex !== void 0 ? _comparator$fromIndex : 0;
|
|
914
797
|
comparator = comparator.comparator;
|
|
915
798
|
}
|
|
916
799
|
if (typeof comparator === "string") {
|
|
917
800
|
const key = comparator;
|
|
918
|
-
comparator = (element,
|
|
801
|
+
comparator = (element, value$1) => element[key] === toValue(value$1);
|
|
919
802
|
}
|
|
920
|
-
comparator = comparator
|
|
921
|
-
return computed(() => toValue
|
|
922
|
-
toValue$1(element),
|
|
923
|
-
toValue$1(value),
|
|
924
|
-
index,
|
|
925
|
-
toValue$1(array)
|
|
926
|
-
)));
|
|
803
|
+
comparator = (_comparator = comparator) !== null && _comparator !== void 0 ? _comparator : ((element, value$1) => element === toValue(value$1));
|
|
804
|
+
return computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(toValue(element), toValue(value), index, toValue(array))));
|
|
927
805
|
}
|
|
928
806
|
// @__NO_SIDE_EFFECTS__
|
|
929
807
|
function useArrayJoin(list, separator) {
|
|
930
|
-
return computed(() => toValue
|
|
808
|
+
return computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
|
|
931
809
|
}
|
|
932
810
|
// @__NO_SIDE_EFFECTS__
|
|
933
811
|
function useArrayMap(list, fn) {
|
|
934
|
-
return computed(() => toValue
|
|
812
|
+
return computed(() => toValue(list).map((i) => toValue(i)).map(fn));
|
|
935
813
|
}
|
|
936
814
|
// @__NO_SIDE_EFFECTS__
|
|
937
815
|
function useArrayReduce(list, reducer, ...args) {
|
|
938
|
-
const reduceCallback = (sum, value, index) => reducer(toValue
|
|
816
|
+
const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
|
|
939
817
|
return computed(() => {
|
|
940
|
-
const resolved = toValue
|
|
941
|
-
return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue
|
|
818
|
+
const resolved = toValue(list);
|
|
819
|
+
return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue(args[0]()) : toValue(args[0])) : resolved.reduce(reduceCallback);
|
|
942
820
|
});
|
|
943
821
|
}
|
|
944
822
|
// @__NO_SIDE_EFFECTS__
|
|
945
823
|
function useArraySome(list, fn) {
|
|
946
|
-
return computed(() => toValue
|
|
824
|
+
return computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
|
|
947
825
|
}
|
|
948
826
|
function uniq(array) {
|
|
949
827
|
return Array.from(new Set(array));
|
|
950
828
|
}
|
|
951
829
|
function uniqueElementsBy(array, fn) {
|
|
952
830
|
return array.reduce((acc, v) => {
|
|
953
|
-
if (!acc.some((x) => fn(v, x, array)))
|
|
954
|
-
acc.push(v);
|
|
831
|
+
if (!acc.some((x) => fn(v, x, array))) acc.push(v);
|
|
955
832
|
return acc;
|
|
956
833
|
}, []);
|
|
957
834
|
}
|
|
958
835
|
// @__NO_SIDE_EFFECTS__
|
|
959
836
|
function useArrayUnique(list, compareFn) {
|
|
960
837
|
return computed(() => {
|
|
961
|
-
const resolvedList = toValue
|
|
838
|
+
const resolvedList = toValue(list).map((element) => toValue(element));
|
|
962
839
|
return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
|
|
963
840
|
});
|
|
964
841
|
}
|
|
965
842
|
function useCounter(initialValue = 0, options = {}) {
|
|
966
843
|
let _initialValue = unref(initialValue);
|
|
967
844
|
const count = shallowRef(initialValue);
|
|
968
|
-
const {
|
|
969
|
-
max = Number.POSITIVE_INFINITY,
|
|
970
|
-
min = Number.NEGATIVE_INFINITY
|
|
971
|
-
} = options;
|
|
845
|
+
const { max = Number.POSITIVE_INFINITY, min = Number.NEGATIVE_INFINITY } = options;
|
|
972
846
|
const inc = (delta = 1) => count.value = Math.max(Math.min(max, count.value + delta), min);
|
|
973
847
|
const dec = (delta = 1) => count.value = Math.min(Math.max(min, count.value - delta), max);
|
|
974
|
-
const
|
|
975
|
-
const
|
|
848
|
+
const get$1 = () => count.value;
|
|
849
|
+
const set$1 = (val) => count.value = Math.max(min, Math.min(max, val));
|
|
976
850
|
const reset = (val = _initialValue) => {
|
|
977
851
|
_initialValue = val;
|
|
978
|
-
return
|
|
852
|
+
return set$1(val);
|
|
853
|
+
};
|
|
854
|
+
return {
|
|
855
|
+
count: shallowReadonly(count),
|
|
856
|
+
inc,
|
|
857
|
+
dec,
|
|
858
|
+
get: get$1,
|
|
859
|
+
set: set$1,
|
|
860
|
+
reset
|
|
979
861
|
};
|
|
980
|
-
return { count: shallowReadonly(count), inc, dec, get: get2, set: set2, reset };
|
|
981
862
|
}
|
|
982
863
|
const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i;
|
|
983
864
|
const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|z{1,4}|SSS/g;
|
|
984
865
|
function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
|
|
985
866
|
let m = hours < 12 ? "AM" : "PM";
|
|
986
|
-
if (hasPeriod)
|
|
987
|
-
m = m.split("").reduce((acc, curr) => acc += `${curr}.`, "");
|
|
867
|
+
if (hasPeriod) m = m.split("").reduce((acc, curr) => acc += `${curr}.`, "");
|
|
988
868
|
return isLowercase ? m.toLowerCase() : m;
|
|
989
869
|
}
|
|
990
870
|
function formatOrdinal(num) {
|
|
991
|
-
const suffixes = [
|
|
871
|
+
const suffixes = [
|
|
872
|
+
"th",
|
|
873
|
+
"st",
|
|
874
|
+
"nd",
|
|
875
|
+
"rd"
|
|
876
|
+
];
|
|
992
877
|
const v = num % 100;
|
|
993
878
|
return num + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]);
|
|
994
879
|
}
|
|
995
880
|
function formatDate(date, formatStr, options = {}) {
|
|
996
|
-
var
|
|
881
|
+
var _options$customMeridi;
|
|
997
882
|
const years = date.getFullYear();
|
|
998
883
|
const month = date.getMonth();
|
|
999
884
|
const days = date.getDate();
|
|
@@ -1002,10 +887,10 @@ function formatDate(date, formatStr, options = {}) {
|
|
|
1002
887
|
const seconds = date.getSeconds();
|
|
1003
888
|
const milliseconds = date.getMilliseconds();
|
|
1004
889
|
const day = date.getDay();
|
|
1005
|
-
const meridiem = (
|
|
890
|
+
const meridiem = (_options$customMeridi = options.customMeridiem) !== null && _options$customMeridi !== void 0 ? _options$customMeridi : defaultMeridiem;
|
|
1006
891
|
const stripTimeZone = (dateString) => {
|
|
1007
|
-
var
|
|
1008
|
-
return (
|
|
892
|
+
var _dateString$split$;
|
|
893
|
+
return (_dateString$split$ = dateString.split(" ")[1]) !== null && _dateString$split$ !== void 0 ? _dateString$split$ : "";
|
|
1009
894
|
};
|
|
1010
895
|
const matches = {
|
|
1011
896
|
Yo: () => formatOrdinal(years),
|
|
@@ -1014,8 +899,8 @@ function formatDate(date, formatStr, options = {}) {
|
|
|
1014
899
|
M: () => month + 1,
|
|
1015
900
|
Mo: () => formatOrdinal(month + 1),
|
|
1016
901
|
MM: () => `${month + 1}`.padStart(2, "0"),
|
|
1017
|
-
MMM: () => date.toLocaleDateString(toValue
|
|
1018
|
-
MMMM: () => date.toLocaleDateString(toValue
|
|
902
|
+
MMM: () => date.toLocaleDateString(toValue(options.locales), { month: "short" }),
|
|
903
|
+
MMMM: () => date.toLocaleDateString(toValue(options.locales), { month: "long" }),
|
|
1019
904
|
D: () => String(days),
|
|
1020
905
|
Do: () => formatOrdinal(days),
|
|
1021
906
|
DD: () => `${days}`.padStart(2, "0"),
|
|
@@ -1033,30 +918,27 @@ function formatDate(date, formatStr, options = {}) {
|
|
|
1033
918
|
ss: () => `${seconds}`.padStart(2, "0"),
|
|
1034
919
|
SSS: () => `${milliseconds}`.padStart(3, "0"),
|
|
1035
920
|
d: () => day,
|
|
1036
|
-
dd: () => date.toLocaleDateString(toValue
|
|
1037
|
-
ddd: () => date.toLocaleDateString(toValue
|
|
1038
|
-
dddd: () => date.toLocaleDateString(toValue
|
|
921
|
+
dd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "narrow" }),
|
|
922
|
+
ddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "short" }),
|
|
923
|
+
dddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "long" }),
|
|
1039
924
|
A: () => meridiem(hours, minutes),
|
|
1040
925
|
AA: () => meridiem(hours, minutes, false, true),
|
|
1041
926
|
a: () => meridiem(hours, minutes, true),
|
|
1042
927
|
aa: () => meridiem(hours, minutes, true, true),
|
|
1043
|
-
z: () => stripTimeZone(date.toLocaleDateString(toValue
|
|
1044
|
-
zz: () => stripTimeZone(date.toLocaleDateString(toValue
|
|
1045
|
-
zzz: () => stripTimeZone(date.toLocaleDateString(toValue
|
|
1046
|
-
zzzz: () => stripTimeZone(date.toLocaleDateString(toValue
|
|
928
|
+
z: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "shortOffset" })),
|
|
929
|
+
zz: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "shortOffset" })),
|
|
930
|
+
zzz: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "shortOffset" })),
|
|
931
|
+
zzzz: () => stripTimeZone(date.toLocaleDateString(toValue(options.locales), { timeZoneName: "longOffset" }))
|
|
1047
932
|
};
|
|
1048
933
|
return formatStr.replace(REGEX_FORMAT, (match, $1) => {
|
|
1049
|
-
var
|
|
1050
|
-
return (
|
|
934
|
+
var _ref, _matches$match;
|
|
935
|
+
return (_ref = $1 !== null && $1 !== void 0 ? $1 : (_matches$match = matches[match]) === null || _matches$match === void 0 ? void 0 : _matches$match.call(matches)) !== null && _ref !== void 0 ? _ref : match;
|
|
1051
936
|
});
|
|
1052
937
|
}
|
|
1053
938
|
function normalizeDate(date) {
|
|
1054
|
-
if (date === null)
|
|
1055
|
-
|
|
1056
|
-
if (date
|
|
1057
|
-
return /* @__PURE__ */ new Date();
|
|
1058
|
-
if (date instanceof Date)
|
|
1059
|
-
return new Date(date);
|
|
939
|
+
if (date === null) return /* @__PURE__ */ new Date(NaN);
|
|
940
|
+
if (date === void 0) return /* @__PURE__ */ new Date();
|
|
941
|
+
if (date instanceof Date) return new Date(date);
|
|
1060
942
|
if (typeof date === "string" && !/Z$/i.test(date)) {
|
|
1061
943
|
const d = date.match(REGEX_PARSE);
|
|
1062
944
|
if (d) {
|
|
@@ -1069,13 +951,10 @@ function normalizeDate(date) {
|
|
|
1069
951
|
}
|
|
1070
952
|
// @__NO_SIDE_EFFECTS__
|
|
1071
953
|
function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
|
|
1072
|
-
return computed(() => formatDate(normalizeDate(toValue
|
|
954
|
+
return computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
|
|
1073
955
|
}
|
|
1074
956
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
1075
|
-
const {
|
|
1076
|
-
immediate = true,
|
|
1077
|
-
immediateCallback = false
|
|
1078
|
-
} = options;
|
|
957
|
+
const { immediate = true, immediateCallback = false } = options;
|
|
1079
958
|
let timer = null;
|
|
1080
959
|
const isActive = shallowRef(false);
|
|
1081
960
|
function clean() {
|
|
@@ -1089,25 +968,17 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
1089
968
|
clean();
|
|
1090
969
|
}
|
|
1091
970
|
function resume() {
|
|
1092
|
-
const intervalValue = toValue
|
|
1093
|
-
if (intervalValue <= 0)
|
|
1094
|
-
return;
|
|
971
|
+
const intervalValue = toValue(interval);
|
|
972
|
+
if (intervalValue <= 0) return;
|
|
1095
973
|
isActive.value = true;
|
|
1096
|
-
if (immediateCallback)
|
|
1097
|
-
cb();
|
|
974
|
+
if (immediateCallback) cb();
|
|
1098
975
|
clean();
|
|
1099
|
-
if (isActive.value)
|
|
1100
|
-
timer = setInterval(cb, intervalValue);
|
|
1101
|
-
}
|
|
1102
|
-
if (immediate && isClient)
|
|
1103
|
-
resume();
|
|
1104
|
-
if (isRef(interval) || typeof interval === "function") {
|
|
1105
|
-
const stopWatch = watch(interval, () => {
|
|
1106
|
-
if (isActive.value && isClient)
|
|
1107
|
-
resume();
|
|
1108
|
-
});
|
|
1109
|
-
tryOnScopeDispose(stopWatch);
|
|
976
|
+
if (isActive.value) timer = setInterval(cb, intervalValue);
|
|
1110
977
|
}
|
|
978
|
+
if (immediate && isClient) resume();
|
|
979
|
+
if (isRef(interval) || typeof interval === "function") tryOnScopeDispose(watch(interval, () => {
|
|
980
|
+
if (isActive.value && isClient) resume();
|
|
981
|
+
}));
|
|
1111
982
|
tryOnScopeDispose(pause);
|
|
1112
983
|
return {
|
|
1113
984
|
isActive: shallowReadonly(isActive),
|
|
@@ -1116,49 +987,31 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
1116
987
|
};
|
|
1117
988
|
}
|
|
1118
989
|
function useInterval(interval = 1e3, options = {}) {
|
|
1119
|
-
const {
|
|
1120
|
-
controls: exposeControls = false,
|
|
1121
|
-
immediate = true,
|
|
1122
|
-
callback
|
|
1123
|
-
} = options;
|
|
990
|
+
const { controls: exposeControls = false, immediate = true, callback } = options;
|
|
1124
991
|
const counter = shallowRef(0);
|
|
1125
992
|
const update = () => counter.value += 1;
|
|
1126
993
|
const reset = () => {
|
|
1127
994
|
counter.value = 0;
|
|
1128
995
|
};
|
|
1129
|
-
const controls = useIntervalFn(
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
counter: shallowReadonly(counter),
|
|
1140
|
-
reset,
|
|
1141
|
-
...controls
|
|
1142
|
-
};
|
|
1143
|
-
} else {
|
|
1144
|
-
return shallowReadonly(counter);
|
|
1145
|
-
}
|
|
996
|
+
const controls = useIntervalFn(callback ? () => {
|
|
997
|
+
update();
|
|
998
|
+
callback(counter.value);
|
|
999
|
+
} : update, interval, { immediate });
|
|
1000
|
+
if (exposeControls) return {
|
|
1001
|
+
counter: shallowReadonly(counter),
|
|
1002
|
+
reset,
|
|
1003
|
+
...controls
|
|
1004
|
+
};
|
|
1005
|
+
else return shallowReadonly(counter);
|
|
1146
1006
|
}
|
|
1147
1007
|
function useLastChanged(source, options = {}) {
|
|
1148
|
-
var
|
|
1149
|
-
const ms = shallowRef((
|
|
1150
|
-
watch(
|
|
1151
|
-
source,
|
|
1152
|
-
() => ms.value = timestamp(),
|
|
1153
|
-
options
|
|
1154
|
-
);
|
|
1008
|
+
var _options$initialValue;
|
|
1009
|
+
const ms = shallowRef((_options$initialValue = options.initialValue) !== null && _options$initialValue !== void 0 ? _options$initialValue : null);
|
|
1010
|
+
watch(source, () => ms.value = timestamp(), options);
|
|
1155
1011
|
return shallowReadonly(ms);
|
|
1156
1012
|
}
|
|
1157
1013
|
function useTimeoutFn(cb, interval, options = {}) {
|
|
1158
|
-
const {
|
|
1159
|
-
immediate = true,
|
|
1160
|
-
immediateCallback = false
|
|
1161
|
-
} = options;
|
|
1014
|
+
const { immediate = true, immediateCallback = false } = options;
|
|
1162
1015
|
const isPending = shallowRef(false);
|
|
1163
1016
|
let timer;
|
|
1164
1017
|
function clear() {
|
|
@@ -1172,20 +1025,18 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1172
1025
|
clear();
|
|
1173
1026
|
}
|
|
1174
1027
|
function start(...args) {
|
|
1175
|
-
if (immediateCallback)
|
|
1176
|
-
cb();
|
|
1028
|
+
if (immediateCallback) cb();
|
|
1177
1029
|
clear();
|
|
1178
1030
|
isPending.value = true;
|
|
1179
1031
|
timer = setTimeout(() => {
|
|
1180
1032
|
isPending.value = false;
|
|
1181
1033
|
timer = void 0;
|
|
1182
1034
|
cb(...args);
|
|
1183
|
-
}, toValue
|
|
1035
|
+
}, toValue(interval));
|
|
1184
1036
|
}
|
|
1185
1037
|
if (immediate) {
|
|
1186
1038
|
isPending.value = true;
|
|
1187
|
-
if (isClient)
|
|
1188
|
-
start();
|
|
1039
|
+
if (isClient) start();
|
|
1189
1040
|
}
|
|
1190
1041
|
tryOnScopeDispose(stop);
|
|
1191
1042
|
return {
|
|
@@ -1195,53 +1046,33 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1195
1046
|
};
|
|
1196
1047
|
}
|
|
1197
1048
|
function useTimeout(interval = 1e3, options = {}) {
|
|
1198
|
-
const {
|
|
1199
|
-
|
|
1200
|
-
callback
|
|
1201
|
-
} = options;
|
|
1202
|
-
const controls = useTimeoutFn(
|
|
1203
|
-
callback != null ? callback : noop,
|
|
1204
|
-
interval,
|
|
1205
|
-
options
|
|
1206
|
-
);
|
|
1049
|
+
const { controls: exposeControls = false, callback } = options;
|
|
1050
|
+
const controls = useTimeoutFn(callback !== null && callback !== void 0 ? callback : noop, interval, options);
|
|
1207
1051
|
const ready = computed(() => !controls.isPending.value);
|
|
1208
|
-
if (exposeControls) {
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
} else {
|
|
1214
|
-
return ready;
|
|
1215
|
-
}
|
|
1052
|
+
if (exposeControls) return {
|
|
1053
|
+
ready,
|
|
1054
|
+
...controls
|
|
1055
|
+
};
|
|
1056
|
+
else return ready;
|
|
1216
1057
|
}
|
|
1217
1058
|
// @__NO_SIDE_EFFECTS__
|
|
1218
1059
|
function useToNumber(value, options = {}) {
|
|
1219
|
-
const {
|
|
1220
|
-
method = "parseFloat",
|
|
1221
|
-
radix,
|
|
1222
|
-
nanToZero
|
|
1223
|
-
} = options;
|
|
1060
|
+
const { method = "parseFloat", radix, nanToZero } = options;
|
|
1224
1061
|
return computed(() => {
|
|
1225
|
-
let resolved = toValue
|
|
1226
|
-
if (typeof method === "function")
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
resolved = Number[method](resolved, radix);
|
|
1230
|
-
if (nanToZero && Number.isNaN(resolved))
|
|
1231
|
-
resolved = 0;
|
|
1062
|
+
let resolved = toValue(value);
|
|
1063
|
+
if (typeof method === "function") resolved = method(resolved);
|
|
1064
|
+
else if (typeof resolved === "string") resolved = Number[method](resolved, radix);
|
|
1065
|
+
if (nanToZero && Number.isNaN(resolved)) resolved = 0;
|
|
1232
1066
|
return resolved;
|
|
1233
1067
|
});
|
|
1234
1068
|
}
|
|
1235
1069
|
// @__NO_SIDE_EFFECTS__
|
|
1236
1070
|
function useToString(value) {
|
|
1237
|
-
return computed(() => `${toValue
|
|
1071
|
+
return computed(() => `${toValue(value)}`);
|
|
1238
1072
|
}
|
|
1239
1073
|
// @__NO_SIDE_EFFECTS__
|
|
1240
1074
|
function useToggle(initialValue = false, options = {}) {
|
|
1241
|
-
const {
|
|
1242
|
-
truthyValue = true,
|
|
1243
|
-
falsyValue = false
|
|
1244
|
-
} = options;
|
|
1075
|
+
const { truthyValue = true, falsyValue = false } = options;
|
|
1245
1076
|
const valueIsRef = isRef(initialValue);
|
|
1246
1077
|
const _value = shallowRef(initialValue);
|
|
1247
1078
|
function toggle(value) {
|
|
@@ -1249,90 +1080,64 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1249
1080
|
_value.value = value;
|
|
1250
1081
|
return _value.value;
|
|
1251
1082
|
} else {
|
|
1252
|
-
const truthy = toValue
|
|
1253
|
-
_value.value = _value.value === truthy ? toValue
|
|
1083
|
+
const truthy = toValue(truthyValue);
|
|
1084
|
+
_value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
|
|
1254
1085
|
return _value.value;
|
|
1255
1086
|
}
|
|
1256
1087
|
}
|
|
1257
|
-
if (valueIsRef)
|
|
1258
|
-
|
|
1259
|
-
else
|
|
1260
|
-
return [_value, toggle];
|
|
1088
|
+
if (valueIsRef) return toggle;
|
|
1089
|
+
else return [_value, toggle];
|
|
1261
1090
|
}
|
|
1262
1091
|
function watchArray(source, cb, options) {
|
|
1263
|
-
let oldList = (options
|
|
1092
|
+
let oldList = (options === null || options === void 0 ? void 0 : options.immediate) ? [] : [...typeof source === "function" ? source() : Array.isArray(source) ? source : toValue(source)];
|
|
1264
1093
|
return watch(source, (newList, _, onCleanup) => {
|
|
1265
1094
|
const oldListRemains = Array.from({ length: oldList.length });
|
|
1266
1095
|
const added = [];
|
|
1267
1096
|
for (const obj of newList) {
|
|
1268
1097
|
let found = false;
|
|
1269
|
-
for (let i = 0; i < oldList.length; i++) {
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
break;
|
|
1274
|
-
}
|
|
1098
|
+
for (let i = 0; i < oldList.length; i++) if (!oldListRemains[i] && obj === oldList[i]) {
|
|
1099
|
+
oldListRemains[i] = true;
|
|
1100
|
+
found = true;
|
|
1101
|
+
break;
|
|
1275
1102
|
}
|
|
1276
|
-
if (!found)
|
|
1277
|
-
added.push(obj);
|
|
1103
|
+
if (!found) added.push(obj);
|
|
1278
1104
|
}
|
|
1279
|
-
const removed = oldList.filter((
|
|
1105
|
+
const removed = oldList.filter((_$1, i) => !oldListRemains[i]);
|
|
1280
1106
|
cb(newList, oldList, added, removed, onCleanup);
|
|
1281
1107
|
oldList = [...newList];
|
|
1282
1108
|
}, options);
|
|
1283
1109
|
}
|
|
1284
1110
|
function watchAtMost(source, cb, options) {
|
|
1285
|
-
const {
|
|
1286
|
-
count,
|
|
1287
|
-
...watchOptions
|
|
1288
|
-
} = options;
|
|
1111
|
+
const { count, ...watchOptions } = options;
|
|
1289
1112
|
const current = shallowRef(0);
|
|
1290
|
-
const stop = watchWithFilter(
|
|
1291
|
-
|
|
1292
|
-
(
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1113
|
+
const { stop, resume, pause } = watchWithFilter(source, (...args) => {
|
|
1114
|
+
current.value += 1;
|
|
1115
|
+
if (current.value >= toValue(count)) nextTick(() => stop());
|
|
1116
|
+
cb(...args);
|
|
1117
|
+
}, watchOptions);
|
|
1118
|
+
return {
|
|
1119
|
+
count: current,
|
|
1120
|
+
stop,
|
|
1121
|
+
resume,
|
|
1122
|
+
pause
|
|
1123
|
+
};
|
|
1301
1124
|
}
|
|
1302
1125
|
function watchDebounced(source, cb, options = {}) {
|
|
1303
|
-
const {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
}
|
|
1308
|
-
return watchWithFilter(
|
|
1309
|
-
source,
|
|
1310
|
-
cb,
|
|
1311
|
-
{
|
|
1312
|
-
...watchOptions,
|
|
1313
|
-
eventFilter: debounceFilter(debounce, { maxWait })
|
|
1314
|
-
}
|
|
1315
|
-
);
|
|
1126
|
+
const { debounce = 0, maxWait = void 0, ...watchOptions } = options;
|
|
1127
|
+
return watchWithFilter(source, cb, {
|
|
1128
|
+
...watchOptions,
|
|
1129
|
+
eventFilter: debounceFilter(debounce, { maxWait })
|
|
1130
|
+
});
|
|
1316
1131
|
}
|
|
1317
1132
|
function watchDeep(source, cb, options) {
|
|
1318
|
-
return watch(
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
...options,
|
|
1323
|
-
deep: true
|
|
1324
|
-
}
|
|
1325
|
-
);
|
|
1133
|
+
return watch(source, cb, {
|
|
1134
|
+
...options,
|
|
1135
|
+
deep: true
|
|
1136
|
+
});
|
|
1326
1137
|
}
|
|
1327
1138
|
function watchIgnorable(source, cb, options = {}) {
|
|
1328
|
-
const {
|
|
1329
|
-
|
|
1330
|
-
...watchOptions
|
|
1331
|
-
} = options;
|
|
1332
|
-
const filteredCb = createFilterWrapper(
|
|
1333
|
-
eventFilter,
|
|
1334
|
-
cb
|
|
1335
|
-
);
|
|
1139
|
+
const { eventFilter = bypassFilter, ...watchOptions } = options;
|
|
1140
|
+
const filteredCb = createFilterWrapper(eventFilter, cb);
|
|
1336
1141
|
let ignoreUpdates;
|
|
1337
1142
|
let ignorePrevAsyncUpdates;
|
|
1338
1143
|
let stop;
|
|
@@ -1345,14 +1150,9 @@ function watchIgnorable(source, cb, options = {}) {
|
|
|
1345
1150
|
updater();
|
|
1346
1151
|
ignore = false;
|
|
1347
1152
|
};
|
|
1348
|
-
stop = watch(
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
if (!ignore)
|
|
1352
|
-
filteredCb(...args);
|
|
1353
|
-
},
|
|
1354
|
-
watchOptions
|
|
1355
|
-
);
|
|
1153
|
+
stop = watch(source, (...args) => {
|
|
1154
|
+
if (!ignore) filteredCb(...args);
|
|
1155
|
+
}, watchOptions);
|
|
1356
1156
|
} else {
|
|
1357
1157
|
const disposables = [];
|
|
1358
1158
|
let ignoreCounter = 0;
|
|
@@ -1360,81 +1160,57 @@ function watchIgnorable(source, cb, options = {}) {
|
|
|
1360
1160
|
ignorePrevAsyncUpdates = () => {
|
|
1361
1161
|
ignoreCounter = syncCounter;
|
|
1362
1162
|
};
|
|
1363
|
-
disposables.push(
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
{ ...watchOptions, flush: "sync" }
|
|
1370
|
-
)
|
|
1371
|
-
);
|
|
1163
|
+
disposables.push(watch(source, () => {
|
|
1164
|
+
syncCounter++;
|
|
1165
|
+
}, {
|
|
1166
|
+
...watchOptions,
|
|
1167
|
+
flush: "sync"
|
|
1168
|
+
}));
|
|
1372
1169
|
ignoreUpdates = (updater) => {
|
|
1373
1170
|
const syncCounterPrev = syncCounter;
|
|
1374
1171
|
updater();
|
|
1375
1172
|
ignoreCounter += syncCounter - syncCounterPrev;
|
|
1376
1173
|
};
|
|
1377
|
-
disposables.push(
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
if (ignore)
|
|
1385
|
-
return;
|
|
1386
|
-
filteredCb(...args);
|
|
1387
|
-
},
|
|
1388
|
-
watchOptions
|
|
1389
|
-
)
|
|
1390
|
-
);
|
|
1174
|
+
disposables.push(watch(source, (...args) => {
|
|
1175
|
+
const ignore = ignoreCounter > 0 && ignoreCounter === syncCounter;
|
|
1176
|
+
ignoreCounter = 0;
|
|
1177
|
+
syncCounter = 0;
|
|
1178
|
+
if (ignore) return;
|
|
1179
|
+
filteredCb(...args);
|
|
1180
|
+
}, watchOptions));
|
|
1391
1181
|
stop = () => {
|
|
1392
1182
|
disposables.forEach((fn) => fn());
|
|
1393
1183
|
};
|
|
1394
1184
|
}
|
|
1395
|
-
return {
|
|
1185
|
+
return {
|
|
1186
|
+
stop,
|
|
1187
|
+
ignoreUpdates,
|
|
1188
|
+
ignorePrevAsyncUpdates
|
|
1189
|
+
};
|
|
1396
1190
|
}
|
|
1397
1191
|
function watchImmediate(source, cb, options) {
|
|
1398
|
-
return watch(
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
...options,
|
|
1403
|
-
immediate: true
|
|
1404
|
-
}
|
|
1405
|
-
);
|
|
1192
|
+
return watch(source, cb, {
|
|
1193
|
+
...options,
|
|
1194
|
+
immediate: true
|
|
1195
|
+
});
|
|
1406
1196
|
}
|
|
1407
1197
|
function watchOnce(source, cb, options) {
|
|
1408
|
-
return watch(
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
...options,
|
|
1413
|
-
once: true
|
|
1414
|
-
}
|
|
1415
|
-
);
|
|
1198
|
+
return watch(source, cb, {
|
|
1199
|
+
...options,
|
|
1200
|
+
once: true
|
|
1201
|
+
});
|
|
1416
1202
|
}
|
|
1417
1203
|
function watchThrottled(source, cb, options = {}) {
|
|
1418
|
-
const {
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
} = options;
|
|
1424
|
-
return watchWithFilter(
|
|
1425
|
-
source,
|
|
1426
|
-
cb,
|
|
1427
|
-
{
|
|
1428
|
-
...watchOptions,
|
|
1429
|
-
eventFilter: throttleFilter(throttle, trailing, leading)
|
|
1430
|
-
}
|
|
1431
|
-
);
|
|
1204
|
+
const { throttle = 0, trailing = true, leading = true, ...watchOptions } = options;
|
|
1205
|
+
return watchWithFilter(source, cb, {
|
|
1206
|
+
...watchOptions,
|
|
1207
|
+
eventFilter: throttleFilter(throttle, trailing, leading)
|
|
1208
|
+
});
|
|
1432
1209
|
}
|
|
1433
1210
|
function watchTriggerable(source, cb, options = {}) {
|
|
1434
1211
|
let cleanupFn;
|
|
1435
1212
|
function onEffect() {
|
|
1436
|
-
if (!cleanupFn)
|
|
1437
|
-
return;
|
|
1213
|
+
if (!cleanupFn) return;
|
|
1438
1214
|
const fn = cleanupFn;
|
|
1439
1215
|
cleanupFn = void 0;
|
|
1440
1216
|
fn();
|
|
@@ -1449,11 +1225,11 @@ function watchTriggerable(source, cb, options = {}) {
|
|
|
1449
1225
|
const res = watchIgnorable(source, _cb, options);
|
|
1450
1226
|
const { ignoreUpdates } = res;
|
|
1451
1227
|
const trigger = () => {
|
|
1452
|
-
let
|
|
1228
|
+
let res$1;
|
|
1453
1229
|
ignoreUpdates(() => {
|
|
1454
|
-
|
|
1230
|
+
res$1 = _cb(getWatchSources(source), getOldValue(source));
|
|
1455
1231
|
});
|
|
1456
|
-
return
|
|
1232
|
+
return res$1;
|
|
1457
1233
|
};
|
|
1458
1234
|
return {
|
|
1459
1235
|
...res,
|
|
@@ -1461,102 +1237,74 @@ function watchTriggerable(source, cb, options = {}) {
|
|
|
1461
1237
|
};
|
|
1462
1238
|
}
|
|
1463
1239
|
function getWatchSources(sources) {
|
|
1464
|
-
if (isReactive(sources))
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
return sources.map((item) => toValue$1(item));
|
|
1468
|
-
return toValue$1(sources);
|
|
1240
|
+
if (isReactive(sources)) return sources;
|
|
1241
|
+
if (Array.isArray(sources)) return sources.map((item) => toValue(item));
|
|
1242
|
+
return toValue(sources);
|
|
1469
1243
|
}
|
|
1470
1244
|
function getOldValue(source) {
|
|
1471
1245
|
return Array.isArray(source) ? source.map(() => void 0) : void 0;
|
|
1472
1246
|
}
|
|
1473
1247
|
function whenever(source, cb, options) {
|
|
1474
|
-
const stop = watch(
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
if (options == null ? void 0 : options.once)
|
|
1479
|
-
nextTick(() => stop());
|
|
1480
|
-
cb(v, ov, onInvalidate);
|
|
1481
|
-
}
|
|
1482
|
-
},
|
|
1483
|
-
{
|
|
1484
|
-
...options,
|
|
1485
|
-
once: false
|
|
1248
|
+
const stop = watch(source, (v, ov, onInvalidate) => {
|
|
1249
|
+
if (v) {
|
|
1250
|
+
if (options === null || options === void 0 ? void 0 : options.once) nextTick(() => stop());
|
|
1251
|
+
cb(v, ov, onInvalidate);
|
|
1486
1252
|
}
|
|
1487
|
-
|
|
1253
|
+
}, {
|
|
1254
|
+
...options,
|
|
1255
|
+
once: false
|
|
1256
|
+
});
|
|
1488
1257
|
return stop;
|
|
1489
1258
|
}
|
|
1490
1259
|
function computedAsync(evaluationCallback, initialState, optionsOrRef) {
|
|
1491
|
-
var
|
|
1260
|
+
var _globalThis$reportErr;
|
|
1492
1261
|
let options;
|
|
1493
|
-
if (isRef(optionsOrRef)) {
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
};
|
|
1497
|
-
} else {
|
|
1498
|
-
options = optionsOrRef || {};
|
|
1499
|
-
}
|
|
1500
|
-
const {
|
|
1501
|
-
lazy = false,
|
|
1502
|
-
flush = "pre",
|
|
1503
|
-
evaluating = void 0,
|
|
1504
|
-
shallow = true,
|
|
1505
|
-
onError = (_a = globalThis.reportError) != null ? _a : noop
|
|
1506
|
-
} = options;
|
|
1262
|
+
if (isRef(optionsOrRef)) options = { evaluating: optionsOrRef };
|
|
1263
|
+
else options = optionsOrRef || {};
|
|
1264
|
+
const { lazy = false, flush = "sync", evaluating = void 0, shallow = true, onError = (_globalThis$reportErr = globalThis.reportError) !== null && _globalThis$reportErr !== void 0 ? _globalThis$reportErr : noop } = options;
|
|
1507
1265
|
const started = shallowRef(!lazy);
|
|
1508
1266
|
const current = shallow ? shallowRef(initialState) : ref(initialState);
|
|
1509
1267
|
let counter = 0;
|
|
1510
1268
|
watchEffect(async (onInvalidate) => {
|
|
1511
|
-
if (!started.value)
|
|
1512
|
-
return;
|
|
1269
|
+
if (!started.value) return;
|
|
1513
1270
|
counter++;
|
|
1514
1271
|
const counterAtBeginning = counter;
|
|
1515
1272
|
let hasFinished = false;
|
|
1516
|
-
if (evaluating) {
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
});
|
|
1520
|
-
}
|
|
1273
|
+
if (evaluating) Promise.resolve().then(() => {
|
|
1274
|
+
evaluating.value = true;
|
|
1275
|
+
});
|
|
1521
1276
|
try {
|
|
1522
1277
|
const result = await evaluationCallback((cancelCallback) => {
|
|
1523
1278
|
onInvalidate(() => {
|
|
1524
|
-
if (evaluating)
|
|
1525
|
-
|
|
1526
|
-
if (!hasFinished)
|
|
1527
|
-
cancelCallback();
|
|
1279
|
+
if (evaluating) evaluating.value = false;
|
|
1280
|
+
if (!hasFinished) cancelCallback();
|
|
1528
1281
|
});
|
|
1529
1282
|
});
|
|
1530
|
-
if (counterAtBeginning === counter)
|
|
1531
|
-
current.value = result;
|
|
1283
|
+
if (counterAtBeginning === counter) current.value = result;
|
|
1532
1284
|
} catch (e) {
|
|
1533
1285
|
onError(e);
|
|
1534
1286
|
} finally {
|
|
1535
|
-
if (evaluating && counterAtBeginning === counter)
|
|
1536
|
-
evaluating.value = false;
|
|
1287
|
+
if (evaluating && counterAtBeginning === counter) evaluating.value = false;
|
|
1537
1288
|
hasFinished = true;
|
|
1538
1289
|
}
|
|
1539
1290
|
}, { flush });
|
|
1540
|
-
if (lazy) {
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
} else {
|
|
1546
|
-
return current;
|
|
1547
|
-
}
|
|
1291
|
+
if (lazy) return computed(() => {
|
|
1292
|
+
started.value = true;
|
|
1293
|
+
return current.value;
|
|
1294
|
+
});
|
|
1295
|
+
else return current;
|
|
1548
1296
|
}
|
|
1549
1297
|
// @__NO_SIDE_EFFECTS__
|
|
1550
1298
|
function createUnrefFn(fn) {
|
|
1551
1299
|
return function(...args) {
|
|
1552
|
-
return fn.apply(this, args.map((i) => toValue
|
|
1300
|
+
return fn.apply(this, args.map((i) => toValue(i)));
|
|
1553
1301
|
};
|
|
1554
1302
|
}
|
|
1555
1303
|
const defaultWindow = isClient ? window : void 0;
|
|
1556
1304
|
function unrefElement(elRef) {
|
|
1557
|
-
var
|
|
1558
|
-
const plain = toValue
|
|
1559
|
-
return (
|
|
1305
|
+
var _$el;
|
|
1306
|
+
const plain = toValue(elRef);
|
|
1307
|
+
return (_$el = plain === null || plain === void 0 ? void 0 : plain.$el) !== null && _$el !== void 0 ? _$el : plain;
|
|
1560
1308
|
}
|
|
1561
1309
|
function useEventListener(...args) {
|
|
1562
1310
|
const cleanups = [];
|
|
@@ -1569,35 +1317,23 @@ function useEventListener(...args) {
|
|
|
1569
1317
|
return () => el.removeEventListener(event, listener, options);
|
|
1570
1318
|
};
|
|
1571
1319
|
const firstParamTargets = computed(() => {
|
|
1572
|
-
const test = toArray(toValue
|
|
1320
|
+
const test = toArray(toValue(args[0])).filter((e) => e != null);
|
|
1573
1321
|
return test.every((e) => typeof e !== "string") ? test : void 0;
|
|
1574
1322
|
});
|
|
1575
|
-
const stopWatch = watchImmediate(
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
return;
|
|
1590
|
-
const optionsClone = isObject(raw_options) ? { ...raw_options } : raw_options;
|
|
1591
|
-
cleanups.push(
|
|
1592
|
-
...raw_targets.flatMap(
|
|
1593
|
-
(el) => raw_events.flatMap(
|
|
1594
|
-
(event) => raw_listeners.map((listener) => register(el, event, listener, optionsClone))
|
|
1595
|
-
)
|
|
1596
|
-
)
|
|
1597
|
-
);
|
|
1598
|
-
},
|
|
1599
|
-
{ flush: "post" }
|
|
1600
|
-
);
|
|
1323
|
+
const stopWatch = watchImmediate(() => {
|
|
1324
|
+
var _firstParamTargets$va, _firstParamTargets$va2;
|
|
1325
|
+
return [
|
|
1326
|
+
(_firstParamTargets$va = (_firstParamTargets$va2 = firstParamTargets.value) === null || _firstParamTargets$va2 === void 0 ? void 0 : _firstParamTargets$va2.map((e) => unrefElement(e))) !== null && _firstParamTargets$va !== void 0 ? _firstParamTargets$va : [defaultWindow].filter((e) => e != null),
|
|
1327
|
+
toArray(toValue(firstParamTargets.value ? args[1] : args[0])),
|
|
1328
|
+
toArray(unref(firstParamTargets.value ? args[2] : args[1])),
|
|
1329
|
+
toValue(firstParamTargets.value ? args[3] : args[2])
|
|
1330
|
+
];
|
|
1331
|
+
}, ([raw_targets, raw_events, raw_listeners, raw_options]) => {
|
|
1332
|
+
cleanup();
|
|
1333
|
+
if (!(raw_targets === null || raw_targets === void 0 ? void 0 : raw_targets.length) || !(raw_events === null || raw_events === void 0 ? void 0 : raw_events.length) || !(raw_listeners === null || raw_listeners === void 0 ? void 0 : raw_listeners.length)) return;
|
|
1334
|
+
const optionsClone = isObject(raw_options) ? { ...raw_options } : raw_options;
|
|
1335
|
+
cleanups.push(...raw_targets.flatMap((el) => raw_events.flatMap((event) => raw_listeners.map((listener) => register(el, event, listener, optionsClone)))));
|
|
1336
|
+
}, { flush: "post" });
|
|
1601
1337
|
const stop = () => {
|
|
1602
1338
|
stopWatch();
|
|
1603
1339
|
cleanup();
|
|
@@ -1619,53 +1355,48 @@ function useSupported(callback) {
|
|
|
1619
1355
|
});
|
|
1620
1356
|
}
|
|
1621
1357
|
function useRafFn(fn, options = {}) {
|
|
1622
|
-
const {
|
|
1623
|
-
immediate = true,
|
|
1624
|
-
fpsLimit = void 0,
|
|
1625
|
-
window: window2 = defaultWindow,
|
|
1626
|
-
once = false
|
|
1627
|
-
} = options;
|
|
1358
|
+
const { immediate = true, fpsLimit = void 0, window: window$1 = defaultWindow, once = false } = options;
|
|
1628
1359
|
const isActive = shallowRef(false);
|
|
1629
1360
|
const intervalLimit = computed(() => {
|
|
1630
|
-
return fpsLimit ? 1e3 / toValue
|
|
1361
|
+
return fpsLimit ? 1e3 / toValue(fpsLimit) : null;
|
|
1631
1362
|
});
|
|
1632
1363
|
let previousFrameTimestamp = 0;
|
|
1633
1364
|
let rafId = null;
|
|
1634
|
-
function loop(
|
|
1635
|
-
if (!isActive.value || !
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
previousFrameTimestamp = timestamp2;
|
|
1639
|
-
const delta = timestamp2 - previousFrameTimestamp;
|
|
1365
|
+
function loop(timestamp$1) {
|
|
1366
|
+
if (!isActive.value || !window$1) return;
|
|
1367
|
+
if (!previousFrameTimestamp) previousFrameTimestamp = timestamp$1;
|
|
1368
|
+
const delta = timestamp$1 - previousFrameTimestamp;
|
|
1640
1369
|
if (intervalLimit.value && delta < intervalLimit.value) {
|
|
1641
|
-
rafId =
|
|
1370
|
+
rafId = window$1.requestAnimationFrame(loop);
|
|
1642
1371
|
return;
|
|
1643
1372
|
}
|
|
1644
|
-
previousFrameTimestamp =
|
|
1645
|
-
fn({
|
|
1373
|
+
previousFrameTimestamp = timestamp$1;
|
|
1374
|
+
fn({
|
|
1375
|
+
delta,
|
|
1376
|
+
timestamp: timestamp$1
|
|
1377
|
+
});
|
|
1646
1378
|
if (once) {
|
|
1647
1379
|
isActive.value = false;
|
|
1648
1380
|
rafId = null;
|
|
1649
1381
|
return;
|
|
1650
1382
|
}
|
|
1651
|
-
rafId =
|
|
1383
|
+
rafId = window$1.requestAnimationFrame(loop);
|
|
1652
1384
|
}
|
|
1653
1385
|
function resume() {
|
|
1654
|
-
if (!isActive.value &&
|
|
1386
|
+
if (!isActive.value && window$1) {
|
|
1655
1387
|
isActive.value = true;
|
|
1656
1388
|
previousFrameTimestamp = 0;
|
|
1657
|
-
rafId =
|
|
1389
|
+
rafId = window$1.requestAnimationFrame(loop);
|
|
1658
1390
|
}
|
|
1659
1391
|
}
|
|
1660
1392
|
function pause() {
|
|
1661
1393
|
isActive.value = false;
|
|
1662
|
-
if (rafId != null &&
|
|
1663
|
-
|
|
1394
|
+
if (rafId != null && window$1) {
|
|
1395
|
+
window$1.cancelAnimationFrame(rafId);
|
|
1664
1396
|
rafId = null;
|
|
1665
1397
|
}
|
|
1666
1398
|
}
|
|
1667
|
-
if (immediate)
|
|
1668
|
-
resume();
|
|
1399
|
+
if (immediate) resume();
|
|
1669
1400
|
tryOnScopeDispose(pause);
|
|
1670
1401
|
return {
|
|
1671
1402
|
isActive: readonly(isActive),
|
|
@@ -1674,20 +1405,17 @@ function useRafFn(fn, options = {}) {
|
|
|
1674
1405
|
};
|
|
1675
1406
|
}
|
|
1676
1407
|
function useAsyncQueue(tasks, options) {
|
|
1677
|
-
const {
|
|
1678
|
-
interrupt = true,
|
|
1679
|
-
onError = noop,
|
|
1680
|
-
onFinished = noop,
|
|
1681
|
-
signal
|
|
1682
|
-
} = options || {};
|
|
1408
|
+
const { interrupt = true, onError = noop, onFinished = noop, signal } = options || {};
|
|
1683
1409
|
const promiseState = {
|
|
1684
1410
|
aborted: "aborted",
|
|
1685
1411
|
fulfilled: "fulfilled",
|
|
1686
1412
|
pending: "pending",
|
|
1687
1413
|
rejected: "rejected"
|
|
1688
1414
|
};
|
|
1689
|
-
const
|
|
1690
|
-
|
|
1415
|
+
const result = reactive(Array.from(Array.from({ length: tasks.length }), () => ({
|
|
1416
|
+
state: promiseState.pending,
|
|
1417
|
+
data: null
|
|
1418
|
+
})));
|
|
1691
1419
|
const activeIndex = shallowRef(-1);
|
|
1692
1420
|
if (!tasks || tasks.length === 0) {
|
|
1693
1421
|
onFinished();
|
|
@@ -1703,26 +1431,24 @@ function useAsyncQueue(tasks, options) {
|
|
|
1703
1431
|
}
|
|
1704
1432
|
tasks.reduce((prev, curr) => {
|
|
1705
1433
|
return prev.then((prevRes) => {
|
|
1706
|
-
var
|
|
1707
|
-
if (signal
|
|
1708
|
-
updateResult(promiseState.aborted, new Error("aborted"));
|
|
1434
|
+
var _result$activeIndex$v;
|
|
1435
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
1436
|
+
updateResult(promiseState.aborted, /* @__PURE__ */ new Error("aborted"));
|
|
1709
1437
|
return;
|
|
1710
1438
|
}
|
|
1711
|
-
if (((
|
|
1439
|
+
if (((_result$activeIndex$v = result[activeIndex.value]) === null || _result$activeIndex$v === void 0 ? void 0 : _result$activeIndex$v.state) === promiseState.rejected && interrupt) {
|
|
1712
1440
|
onFinished();
|
|
1713
1441
|
return;
|
|
1714
1442
|
}
|
|
1715
1443
|
const done = curr(prevRes).then((currentRes) => {
|
|
1716
1444
|
updateResult(promiseState.fulfilled, currentRes);
|
|
1717
|
-
if (activeIndex.value === tasks.length - 1)
|
|
1718
|
-
onFinished();
|
|
1445
|
+
if (activeIndex.value === tasks.length - 1) onFinished();
|
|
1719
1446
|
return currentRes;
|
|
1720
1447
|
});
|
|
1721
|
-
if (!signal)
|
|
1722
|
-
return done;
|
|
1448
|
+
if (!signal) return done;
|
|
1723
1449
|
return Promise.race([done, whenAborted(signal)]);
|
|
1724
1450
|
}).catch((e) => {
|
|
1725
|
-
if (signal
|
|
1451
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
1726
1452
|
updateResult(promiseState.aborted, e);
|
|
1727
1453
|
return e;
|
|
1728
1454
|
}
|
|
@@ -1738,55 +1464,44 @@ function useAsyncQueue(tasks, options) {
|
|
|
1738
1464
|
}
|
|
1739
1465
|
function whenAborted(signal) {
|
|
1740
1466
|
return new Promise((resolve, reject) => {
|
|
1741
|
-
const error = new Error("aborted");
|
|
1742
|
-
if (signal.aborted)
|
|
1743
|
-
|
|
1744
|
-
else
|
|
1745
|
-
signal.addEventListener("abort", () => reject(error), { once: true });
|
|
1467
|
+
const error = /* @__PURE__ */ new Error("aborted");
|
|
1468
|
+
if (signal.aborted) reject(error);
|
|
1469
|
+
else signal.addEventListener("abort", () => reject(error), { once: true });
|
|
1746
1470
|
});
|
|
1747
1471
|
}
|
|
1748
1472
|
function useAsyncState(promise, initialState, options) {
|
|
1749
|
-
var
|
|
1750
|
-
const {
|
|
1751
|
-
immediate = true,
|
|
1752
|
-
delay = 0,
|
|
1753
|
-
onError = (_a = globalThis.reportError) != null ? _a : noop,
|
|
1754
|
-
onSuccess = noop,
|
|
1755
|
-
resetOnExecute = true,
|
|
1756
|
-
shallow = true,
|
|
1757
|
-
throwError
|
|
1758
|
-
} = options != null ? options : {};
|
|
1473
|
+
var _globalThis$reportErr;
|
|
1474
|
+
const { immediate = true, delay = 0, onError = (_globalThis$reportErr = globalThis.reportError) !== null && _globalThis$reportErr !== void 0 ? _globalThis$reportErr : noop, onSuccess = noop, resetOnExecute = true, shallow = true, throwError } = options !== null && options !== void 0 ? options : {};
|
|
1759
1475
|
const state = shallow ? shallowRef(initialState) : ref(initialState);
|
|
1760
1476
|
const isReady = shallowRef(false);
|
|
1761
1477
|
const isLoading = shallowRef(false);
|
|
1762
1478
|
const error = shallowRef(void 0);
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1479
|
+
let executionsCount = 0;
|
|
1480
|
+
async function execute(delay$1 = 0, ...args) {
|
|
1481
|
+
const executionId = executionsCount += 1;
|
|
1482
|
+
if (resetOnExecute) state.value = toValue(initialState);
|
|
1766
1483
|
error.value = void 0;
|
|
1767
1484
|
isReady.value = false;
|
|
1768
1485
|
isLoading.value = true;
|
|
1769
|
-
if (
|
|
1770
|
-
await promiseTimeout(delay2);
|
|
1486
|
+
if (delay$1 > 0) await promiseTimeout(delay$1);
|
|
1771
1487
|
const _promise = typeof promise === "function" ? promise(...args) : promise;
|
|
1772
1488
|
try {
|
|
1773
1489
|
const data = await _promise;
|
|
1774
|
-
|
|
1775
|
-
|
|
1490
|
+
if (executionId === executionsCount) {
|
|
1491
|
+
state.value = data;
|
|
1492
|
+
isReady.value = true;
|
|
1493
|
+
}
|
|
1776
1494
|
onSuccess(data);
|
|
1777
1495
|
} catch (e) {
|
|
1778
|
-
error.value = e;
|
|
1496
|
+
if (executionId === executionsCount) error.value = e;
|
|
1779
1497
|
onError(e);
|
|
1780
|
-
if (throwError)
|
|
1781
|
-
throw e;
|
|
1498
|
+
if (throwError) throw e;
|
|
1782
1499
|
} finally {
|
|
1783
|
-
isLoading.value = false;
|
|
1500
|
+
if (executionId === executionsCount) isLoading.value = false;
|
|
1784
1501
|
}
|
|
1785
1502
|
return state.value;
|
|
1786
1503
|
}
|
|
1787
|
-
if (immediate)
|
|
1788
|
-
execute(delay);
|
|
1789
|
-
}
|
|
1504
|
+
if (immediate) execute(delay);
|
|
1790
1505
|
const shell = {
|
|
1791
1506
|
state,
|
|
1792
1507
|
isReady,
|
|
@@ -1815,37 +1530,26 @@ const defaults = {
|
|
|
1815
1530
|
null: () => ""
|
|
1816
1531
|
};
|
|
1817
1532
|
function getDefaultSerialization(target) {
|
|
1818
|
-
if (!target)
|
|
1819
|
-
|
|
1820
|
-
if (target instanceof
|
|
1821
|
-
|
|
1822
|
-
else
|
|
1823
|
-
return defaults.set;
|
|
1824
|
-
else if (Array.isArray(target))
|
|
1825
|
-
return defaults.array;
|
|
1826
|
-
else
|
|
1827
|
-
return defaults.object;
|
|
1533
|
+
if (!target) return defaults.null;
|
|
1534
|
+
if (target instanceof Map) return defaults.map;
|
|
1535
|
+
else if (target instanceof Set) return defaults.set;
|
|
1536
|
+
else if (Array.isArray(target)) return defaults.array;
|
|
1537
|
+
else return defaults.object;
|
|
1828
1538
|
}
|
|
1829
1539
|
function useBase64(target, options) {
|
|
1830
1540
|
const base64 = shallowRef("");
|
|
1831
1541
|
const promise = shallowRef();
|
|
1832
1542
|
function execute() {
|
|
1833
|
-
if (!isClient)
|
|
1834
|
-
return;
|
|
1543
|
+
if (!isClient) return;
|
|
1835
1544
|
promise.value = new Promise((resolve, reject) => {
|
|
1836
1545
|
try {
|
|
1837
|
-
const _target = toValue
|
|
1838
|
-
if (_target == null)
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
} else if (_target instanceof ArrayBuffer) {
|
|
1845
|
-
resolve(window.btoa(String.fromCharCode(...new Uint8Array(_target))));
|
|
1846
|
-
} else if (_target instanceof HTMLCanvasElement) {
|
|
1847
|
-
resolve(_target.toDataURL(options == null ? void 0 : options.type, options == null ? void 0 : options.quality));
|
|
1848
|
-
} else if (_target instanceof HTMLImageElement) {
|
|
1546
|
+
const _target = toValue(target);
|
|
1547
|
+
if (_target == null) resolve("");
|
|
1548
|
+
else if (typeof _target === "string") resolve(blobToBase64(new Blob([_target], { type: "text/plain" })));
|
|
1549
|
+
else if (_target instanceof Blob) resolve(blobToBase64(_target));
|
|
1550
|
+
else if (_target instanceof ArrayBuffer) resolve(window.btoa(String.fromCharCode(...new Uint8Array(_target))));
|
|
1551
|
+
else if (_target instanceof HTMLCanvasElement) resolve(_target.toDataURL(options === null || options === void 0 ? void 0 : options.type, options === null || options === void 0 ? void 0 : options.quality));
|
|
1552
|
+
else if (_target instanceof HTMLImageElement) {
|
|
1849
1553
|
const img = _target.cloneNode(false);
|
|
1850
1554
|
img.crossOrigin = "Anonymous";
|
|
1851
1555
|
imgLoaded(img).then(() => {
|
|
@@ -1854,28 +1558,23 @@ function useBase64(target, options) {
|
|
|
1854
1558
|
canvas.width = img.width;
|
|
1855
1559
|
canvas.height = img.height;
|
|
1856
1560
|
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
1857
|
-
resolve(canvas.toDataURL(options
|
|
1561
|
+
resolve(canvas.toDataURL(options === null || options === void 0 ? void 0 : options.type, options === null || options === void 0 ? void 0 : options.quality));
|
|
1858
1562
|
}).catch(reject);
|
|
1859
1563
|
} else if (typeof _target === "object") {
|
|
1860
|
-
const
|
|
1861
|
-
const serialized = _serializeFn(_target);
|
|
1564
|
+
const serialized = ((options === null || options === void 0 ? void 0 : options.serializer) || getDefaultSerialization(_target))(_target);
|
|
1862
1565
|
return resolve(blobToBase64(new Blob([serialized], { type: "application/json" })));
|
|
1863
|
-
} else
|
|
1864
|
-
reject(new Error("target is unsupported types"));
|
|
1865
|
-
}
|
|
1566
|
+
} else reject(/* @__PURE__ */ new Error("target is unsupported types"));
|
|
1866
1567
|
} catch (error) {
|
|
1867
1568
|
reject(error);
|
|
1868
1569
|
}
|
|
1869
1570
|
});
|
|
1870
1571
|
promise.value.then((res) => {
|
|
1871
|
-
base64.value = (options
|
|
1572
|
+
base64.value = (options === null || options === void 0 ? void 0 : options.dataUrl) === false ? res.replace(/^data:.*?;base64,/, "") : res;
|
|
1872
1573
|
});
|
|
1873
1574
|
return promise.value;
|
|
1874
1575
|
}
|
|
1875
|
-
if (isRef(target) || typeof target === "function")
|
|
1876
|
-
|
|
1877
|
-
else
|
|
1878
|
-
execute();
|
|
1576
|
+
if (isRef(target) || typeof target === "function") watch(target, execute, { immediate: true });
|
|
1577
|
+
else execute();
|
|
1879
1578
|
return {
|
|
1880
1579
|
base64,
|
|
1881
1580
|
promise,
|
|
@@ -1889,9 +1588,7 @@ function imgLoaded(img) {
|
|
|
1889
1588
|
resolve();
|
|
1890
1589
|
};
|
|
1891
1590
|
img.onerror = reject;
|
|
1892
|
-
} else
|
|
1893
|
-
resolve();
|
|
1894
|
-
}
|
|
1591
|
+
} else resolve();
|
|
1895
1592
|
});
|
|
1896
1593
|
}
|
|
1897
1594
|
function blobToBase64(blob) {
|
|
@@ -1905,42 +1602,33 @@ function blobToBase64(blob) {
|
|
|
1905
1602
|
});
|
|
1906
1603
|
}
|
|
1907
1604
|
function useBroadcastChannel(options) {
|
|
1908
|
-
const {
|
|
1909
|
-
|
|
1910
|
-
window: window2 = defaultWindow
|
|
1911
|
-
} = options;
|
|
1912
|
-
const isSupported = /* @__PURE__ */ useSupported(() => window2 && "BroadcastChannel" in window2);
|
|
1605
|
+
const { name, window: window$1 = defaultWindow } = options;
|
|
1606
|
+
const isSupported = /* @__PURE__ */ useSupported(() => window$1 && "BroadcastChannel" in window$1);
|
|
1913
1607
|
const isClosed = shallowRef(false);
|
|
1914
1608
|
const channel = ref();
|
|
1915
1609
|
const data = ref();
|
|
1916
1610
|
const error = shallowRef(null);
|
|
1917
|
-
const post = (
|
|
1918
|
-
if (channel.value)
|
|
1919
|
-
channel.value.postMessage(data2);
|
|
1611
|
+
const post = (data$1) => {
|
|
1612
|
+
if (channel.value) channel.value.postMessage(data$1);
|
|
1920
1613
|
};
|
|
1921
1614
|
const close = () => {
|
|
1922
|
-
if (channel.value)
|
|
1923
|
-
channel.value.close();
|
|
1615
|
+
if (channel.value) channel.value.close();
|
|
1924
1616
|
isClosed.value = true;
|
|
1925
1617
|
};
|
|
1926
|
-
if (isSupported.value) {
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
isClosed.value = true;
|
|
1941
|
-
}, listenerOptions);
|
|
1942
|
-
});
|
|
1943
|
-
}
|
|
1618
|
+
if (isSupported.value) tryOnMounted(() => {
|
|
1619
|
+
error.value = null;
|
|
1620
|
+
channel.value = new BroadcastChannel(name);
|
|
1621
|
+
const listenerOptions = { passive: true };
|
|
1622
|
+
useEventListener(channel, "message", (e) => {
|
|
1623
|
+
data.value = e.data;
|
|
1624
|
+
}, listenerOptions);
|
|
1625
|
+
useEventListener(channel, "messageerror", (e) => {
|
|
1626
|
+
error.value = e;
|
|
1627
|
+
}, listenerOptions);
|
|
1628
|
+
useEventListener(channel, "close", () => {
|
|
1629
|
+
isClosed.value = true;
|
|
1630
|
+
}, listenerOptions);
|
|
1631
|
+
});
|
|
1944
1632
|
tryOnScopeDispose(() => {
|
|
1945
1633
|
close();
|
|
1946
1634
|
});
|
|
@@ -1958,8 +1646,7 @@ function useCached(refValue, comparator = (a, b) => a === b, options) {
|
|
|
1958
1646
|
const { deepRefs = true, ...watchOptions } = options || {};
|
|
1959
1647
|
const cachedValue = /* @__PURE__ */ createRef(refValue.value, deepRefs);
|
|
1960
1648
|
watch(() => refValue.value, (value) => {
|
|
1961
|
-
if (!comparator(value, cachedValue.value))
|
|
1962
|
-
cachedValue.value = value;
|
|
1649
|
+
if (!comparator(value, cachedValue.value)) cachedValue.value = value;
|
|
1963
1650
|
}, watchOptions);
|
|
1964
1651
|
return cachedValue;
|
|
1965
1652
|
}
|
|
@@ -1970,13 +1657,7 @@ function useCloned(source, options = {}) {
|
|
|
1970
1657
|
const cloned = ref({});
|
|
1971
1658
|
const isModified = shallowRef(false);
|
|
1972
1659
|
let _lastSync = false;
|
|
1973
|
-
const {
|
|
1974
|
-
manual,
|
|
1975
|
-
clone = cloneFnJSON,
|
|
1976
|
-
// watch options
|
|
1977
|
-
deep = true,
|
|
1978
|
-
immediate = true
|
|
1979
|
-
} = options;
|
|
1660
|
+
const { manual, clone = cloneFnJSON, deep = true, immediate = true } = options;
|
|
1980
1661
|
watch(cloned, () => {
|
|
1981
1662
|
if (_lastSync) {
|
|
1982
1663
|
_lastSync = false;
|
|
@@ -1990,30 +1671,30 @@ function useCloned(source, options = {}) {
|
|
|
1990
1671
|
function sync() {
|
|
1991
1672
|
_lastSync = true;
|
|
1992
1673
|
isModified.value = false;
|
|
1993
|
-
cloned.value = clone(toValue
|
|
1994
|
-
}
|
|
1995
|
-
if (!manual && (isRef(source) || typeof source === "function")) {
|
|
1996
|
-
watch(source, sync, {
|
|
1997
|
-
...options,
|
|
1998
|
-
deep,
|
|
1999
|
-
immediate
|
|
2000
|
-
});
|
|
2001
|
-
} else {
|
|
2002
|
-
sync();
|
|
1674
|
+
cloned.value = clone(toValue(source));
|
|
2003
1675
|
}
|
|
2004
|
-
|
|
1676
|
+
if (!manual && (isRef(source) || typeof source === "function")) watch(source, sync, {
|
|
1677
|
+
...options,
|
|
1678
|
+
deep,
|
|
1679
|
+
immediate
|
|
1680
|
+
});
|
|
1681
|
+
else sync();
|
|
1682
|
+
return {
|
|
1683
|
+
cloned,
|
|
1684
|
+
isModified,
|
|
1685
|
+
sync
|
|
1686
|
+
};
|
|
2005
1687
|
}
|
|
2006
1688
|
function useCycleList(list, options) {
|
|
2007
1689
|
const state = shallowRef(getInitialValue());
|
|
2008
|
-
const listRef =
|
|
1690
|
+
const listRef = toRef2(list);
|
|
2009
1691
|
const index = computed({
|
|
2010
1692
|
get() {
|
|
2011
|
-
var
|
|
1693
|
+
var _options$fallbackInde;
|
|
2012
1694
|
const targetList = listRef.value;
|
|
2013
|
-
let
|
|
2014
|
-
if (
|
|
2015
|
-
|
|
2016
|
-
return index2;
|
|
1695
|
+
let index$1 = (options === null || options === void 0 ? void 0 : options.getIndexOf) ? options.getIndexOf(state.value, targetList) : targetList.indexOf(state.value);
|
|
1696
|
+
if (index$1 < 0) index$1 = (_options$fallbackInde = options === null || options === void 0 ? void 0 : options.fallbackIndex) !== null && _options$fallbackInde !== void 0 ? _options$fallbackInde : 0;
|
|
1697
|
+
return index$1;
|
|
2017
1698
|
},
|
|
2018
1699
|
set(v) {
|
|
2019
1700
|
set2(v);
|
|
@@ -2022,8 +1703,7 @@ function useCycleList(list, options) {
|
|
|
2022
1703
|
function set2(i) {
|
|
2023
1704
|
const targetList = listRef.value;
|
|
2024
1705
|
const length = targetList.length;
|
|
2025
|
-
const
|
|
2026
|
-
const value = targetList[index2];
|
|
1706
|
+
const value = targetList[(i % length + length) % length];
|
|
2027
1707
|
state.value = value;
|
|
2028
1708
|
return value;
|
|
2029
1709
|
}
|
|
@@ -2037,8 +1717,8 @@ function useCycleList(list, options) {
|
|
|
2037
1717
|
return shift(-n);
|
|
2038
1718
|
}
|
|
2039
1719
|
function getInitialValue() {
|
|
2040
|
-
var
|
|
2041
|
-
return (
|
|
1720
|
+
var _toValue, _options$initialValue;
|
|
1721
|
+
return (_toValue = toValue((_options$initialValue = options === null || options === void 0 ? void 0 : options.initialValue) !== null && _options$initialValue !== void 0 ? _options$initialValue : toValue(list)[0])) !== null && _toValue !== void 0 ? _toValue : void 0;
|
|
2042
1722
|
}
|
|
2043
1723
|
watch(listRef, () => set2(index.value));
|
|
2044
1724
|
return {
|
|
@@ -2062,12 +1742,7 @@ function defaultParse(clone) {
|
|
|
2062
1742
|
return clone ? typeof clone === "function" ? clone : cloneFnJSON : fnBypass;
|
|
2063
1743
|
}
|
|
2064
1744
|
function useManualRefHistory(source, options = {}) {
|
|
2065
|
-
const {
|
|
2066
|
-
clone = false,
|
|
2067
|
-
dump = defaultDump(clone),
|
|
2068
|
-
parse = defaultParse(clone),
|
|
2069
|
-
setSource = fnSetSource
|
|
2070
|
-
} = options;
|
|
1745
|
+
const { clone = false, dump = defaultDump(clone), parse = defaultParse(clone), setSource = fnSetSource } = options;
|
|
2071
1746
|
function _createHistoryRecord() {
|
|
2072
1747
|
return markRaw({
|
|
2073
1748
|
snapshot: dump(source.value),
|
|
@@ -2084,10 +1759,8 @@ function useManualRefHistory(source, options = {}) {
|
|
|
2084
1759
|
const commit = () => {
|
|
2085
1760
|
undoStack.value.unshift(last.value);
|
|
2086
1761
|
last.value = _createHistoryRecord();
|
|
2087
|
-
if (options.capacity && undoStack.value.length > options.capacity)
|
|
2088
|
-
|
|
2089
|
-
if (redoStack.value.length)
|
|
2090
|
-
redoStack.value.splice(0, redoStack.value.length);
|
|
1762
|
+
if (options.capacity && undoStack.value.length > options.capacity) undoStack.value.splice(options.capacity, Number.POSITIVE_INFINITY);
|
|
1763
|
+
if (redoStack.value.length) redoStack.value.splice(0, redoStack.value.length);
|
|
2091
1764
|
};
|
|
2092
1765
|
const clear = () => {
|
|
2093
1766
|
undoStack.value.splice(0, undoStack.value.length);
|
|
@@ -2110,17 +1783,14 @@ function useManualRefHistory(source, options = {}) {
|
|
|
2110
1783
|
const reset = () => {
|
|
2111
1784
|
_setSource(last.value);
|
|
2112
1785
|
};
|
|
2113
|
-
const history = computed(() => [last.value, ...undoStack.value]);
|
|
2114
|
-
const canUndo = computed(() => undoStack.value.length > 0);
|
|
2115
|
-
const canRedo = computed(() => redoStack.value.length > 0);
|
|
2116
1786
|
return {
|
|
2117
1787
|
source,
|
|
2118
1788
|
undoStack,
|
|
2119
1789
|
redoStack,
|
|
2120
1790
|
last,
|
|
2121
|
-
history,
|
|
2122
|
-
canUndo,
|
|
2123
|
-
canRedo,
|
|
1791
|
+
history: computed(() => [last.value, ...undoStack.value]),
|
|
1792
|
+
canUndo: computed(() => undoStack.value.length > 0),
|
|
1793
|
+
canRedo: computed(() => redoStack.value.length > 0),
|
|
2124
1794
|
clear,
|
|
2125
1795
|
commit,
|
|
2126
1796
|
reset,
|
|
@@ -2129,48 +1799,36 @@ function useManualRefHistory(source, options = {}) {
|
|
|
2129
1799
|
};
|
|
2130
1800
|
}
|
|
2131
1801
|
function useRefHistory(source, options = {}) {
|
|
2132
|
-
const {
|
|
2133
|
-
|
|
2134
|
-
flush = "pre",
|
|
2135
|
-
eventFilter,
|
|
2136
|
-
shouldCommit = () => true
|
|
2137
|
-
} = options;
|
|
2138
|
-
const {
|
|
2139
|
-
eventFilter: composedFilter,
|
|
2140
|
-
pause,
|
|
2141
|
-
resume: resumeTracking,
|
|
2142
|
-
isActive: isTracking
|
|
2143
|
-
} = pausableFilter(eventFilter);
|
|
1802
|
+
const { deep = false, flush = "pre", eventFilter, shouldCommit = () => true } = options;
|
|
1803
|
+
const { eventFilter: composedFilter, pause, resume: resumeTracking, isActive: isTracking } = pausableFilter(eventFilter);
|
|
2144
1804
|
let lastRawValue = source.value;
|
|
2145
|
-
const {
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
}
|
|
2150
|
-
|
|
2151
|
-
commit,
|
|
2152
|
-
{ deep, flush, eventFilter: composedFilter }
|
|
2153
|
-
);
|
|
2154
|
-
function setSource(source2, value) {
|
|
1805
|
+
const { ignoreUpdates, ignorePrevAsyncUpdates, stop } = watchIgnorable(source, commit, {
|
|
1806
|
+
deep,
|
|
1807
|
+
flush,
|
|
1808
|
+
eventFilter: composedFilter
|
|
1809
|
+
});
|
|
1810
|
+
function setSource(source$1, value) {
|
|
2155
1811
|
ignorePrevAsyncUpdates();
|
|
2156
1812
|
ignoreUpdates(() => {
|
|
2157
|
-
|
|
1813
|
+
source$1.value = value;
|
|
2158
1814
|
lastRawValue = value;
|
|
2159
1815
|
});
|
|
2160
1816
|
}
|
|
2161
|
-
const manualHistory = useManualRefHistory(source, {
|
|
1817
|
+
const manualHistory = useManualRefHistory(source, {
|
|
1818
|
+
...options,
|
|
1819
|
+
clone: options.clone || deep,
|
|
1820
|
+
setSource
|
|
1821
|
+
});
|
|
2162
1822
|
const { clear, commit: manualCommit } = manualHistory;
|
|
2163
1823
|
function commit() {
|
|
2164
1824
|
ignorePrevAsyncUpdates();
|
|
2165
|
-
if (!shouldCommit(lastRawValue, source.value))
|
|
2166
|
-
return;
|
|
1825
|
+
if (!shouldCommit(lastRawValue, source.value)) return;
|
|
2167
1826
|
lastRawValue = source.value;
|
|
2168
1827
|
manualCommit();
|
|
2169
1828
|
}
|
|
2170
1829
|
function resume(commitNow) {
|
|
2171
1830
|
resumeTracking();
|
|
2172
|
-
if (commitNow)
|
|
2173
|
-
commit();
|
|
1831
|
+
if (commitNow) commit();
|
|
2174
1832
|
}
|
|
2175
1833
|
function batch(fn) {
|
|
2176
1834
|
let canceled = false;
|
|
@@ -2178,8 +1836,7 @@ function useRefHistory(source, options = {}) {
|
|
|
2178
1836
|
ignoreUpdates(() => {
|
|
2179
1837
|
fn(cancel);
|
|
2180
1838
|
});
|
|
2181
|
-
if (!canceled)
|
|
2182
|
-
commit();
|
|
1839
|
+
if (!canceled) commit();
|
|
2183
1840
|
}
|
|
2184
1841
|
function dispose() {
|
|
2185
1842
|
stop();
|
|
@@ -2197,22 +1854,22 @@ function useRefHistory(source, options = {}) {
|
|
|
2197
1854
|
}
|
|
2198
1855
|
function useDebouncedRefHistory(source, options = {}) {
|
|
2199
1856
|
const filter = options.debounce ? debounceFilter(options.debounce) : void 0;
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
};
|
|
1857
|
+
return { ...useRefHistory(source, {
|
|
1858
|
+
...options,
|
|
1859
|
+
eventFilter: filter
|
|
1860
|
+
}) };
|
|
2204
1861
|
}
|
|
2205
1862
|
const events = /* @__PURE__ */ new Map();
|
|
2206
1863
|
// @__NO_SIDE_EFFECTS__
|
|
2207
1864
|
function useEventBus(key) {
|
|
2208
1865
|
const scope = getCurrentScope();
|
|
2209
1866
|
function on(listener) {
|
|
2210
|
-
var
|
|
1867
|
+
var _scope$cleanups;
|
|
2211
1868
|
const listeners = events.get(key) || /* @__PURE__ */ new Set();
|
|
2212
1869
|
listeners.add(listener);
|
|
2213
1870
|
events.set(key, listeners);
|
|
2214
1871
|
const _off = () => off(listener);
|
|
2215
|
-
|
|
1872
|
+
scope === null || scope === void 0 || (_scope$cleanups = scope.cleanups) === null || _scope$cleanups === void 0 || _scope$cleanups.push(_off);
|
|
2216
1873
|
return _off;
|
|
2217
1874
|
}
|
|
2218
1875
|
function once(listener) {
|
|
@@ -2224,20 +1881,24 @@ function useEventBus(key) {
|
|
|
2224
1881
|
}
|
|
2225
1882
|
function off(listener) {
|
|
2226
1883
|
const listeners = events.get(key);
|
|
2227
|
-
if (!listeners)
|
|
2228
|
-
return;
|
|
1884
|
+
if (!listeners) return;
|
|
2229
1885
|
listeners.delete(listener);
|
|
2230
|
-
if (!listeners.size)
|
|
2231
|
-
reset();
|
|
1886
|
+
if (!listeners.size) reset();
|
|
2232
1887
|
}
|
|
2233
1888
|
function reset() {
|
|
2234
1889
|
events.delete(key);
|
|
2235
1890
|
}
|
|
2236
1891
|
function emit(event, payload) {
|
|
2237
|
-
var
|
|
2238
|
-
(
|
|
1892
|
+
var _events$get;
|
|
1893
|
+
(_events$get = events.get(key)) === null || _events$get === void 0 || _events$get.forEach((v) => v(event, payload));
|
|
2239
1894
|
}
|
|
2240
|
-
return {
|
|
1895
|
+
return {
|
|
1896
|
+
on,
|
|
1897
|
+
once,
|
|
1898
|
+
off,
|
|
1899
|
+
emit,
|
|
1900
|
+
reset
|
|
1901
|
+
};
|
|
2241
1902
|
}
|
|
2242
1903
|
const payloadMapping = {
|
|
2243
1904
|
json: "application/json",
|
|
@@ -2251,33 +1912,29 @@ function isAbsoluteURL(url) {
|
|
|
2251
1912
|
return reAbsolute.test(url);
|
|
2252
1913
|
}
|
|
2253
1914
|
function headersToObject(headers) {
|
|
2254
|
-
if (typeof Headers !== "undefined" && headers instanceof Headers)
|
|
2255
|
-
return Object.fromEntries(headers.entries());
|
|
1915
|
+
if (typeof Headers !== "undefined" && headers instanceof Headers) return Object.fromEntries(headers.entries());
|
|
2256
1916
|
return headers;
|
|
2257
1917
|
}
|
|
2258
1918
|
function combineCallbacks(combination, ...callbacks) {
|
|
2259
|
-
if (combination === "overwrite") {
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
if (callback)
|
|
2269
|
-
return { ...ctx, ...await callback(ctx) };
|
|
2270
|
-
return ctx;
|
|
1919
|
+
if (combination === "overwrite") return async (ctx) => {
|
|
1920
|
+
let callback;
|
|
1921
|
+
for (let i = callbacks.length - 1; i >= 0; i--) if (callbacks[i] != null) {
|
|
1922
|
+
callback = callbacks[i];
|
|
1923
|
+
break;
|
|
1924
|
+
}
|
|
1925
|
+
if (callback) return {
|
|
1926
|
+
...ctx,
|
|
1927
|
+
...await callback(ctx)
|
|
2271
1928
|
};
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
return ctx;
|
|
1929
|
+
return ctx;
|
|
1930
|
+
};
|
|
1931
|
+
else return async (ctx) => {
|
|
1932
|
+
for (const callback of callbacks) if (callback) ctx = {
|
|
1933
|
+
...ctx,
|
|
1934
|
+
...await callback(ctx)
|
|
2279
1935
|
};
|
|
2280
|
-
|
|
1936
|
+
return ctx;
|
|
1937
|
+
};
|
|
2281
1938
|
}
|
|
2282
1939
|
function createFetch(config = {}) {
|
|
2283
1940
|
const _combination = config.combination || "chain";
|
|
@@ -2285,47 +1942,40 @@ function createFetch(config = {}) {
|
|
|
2285
1942
|
const _fetchOptions = config.fetchOptions || {};
|
|
2286
1943
|
function useFactoryFetch(url, ...args) {
|
|
2287
1944
|
const computedUrl = computed(() => {
|
|
2288
|
-
const baseUrl = toValue
|
|
2289
|
-
const targetUrl = toValue
|
|
1945
|
+
const baseUrl = toValue(config.baseUrl);
|
|
1946
|
+
const targetUrl = toValue(url);
|
|
2290
1947
|
return baseUrl && !isAbsoluteURL(targetUrl) ? joinPaths(baseUrl, targetUrl) : targetUrl;
|
|
2291
1948
|
});
|
|
2292
1949
|
let options = _options;
|
|
2293
1950
|
let fetchOptions = _fetchOptions;
|
|
2294
|
-
if (args.length > 0) {
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
headers: {
|
|
2308
|
-
...headersToObject(fetchOptions.headers) || {},
|
|
2309
|
-
...headersToObject(args[0].headers) || {}
|
|
2310
|
-
}
|
|
2311
|
-
};
|
|
1951
|
+
if (args.length > 0) if (isFetchOptions(args[0])) options = {
|
|
1952
|
+
...options,
|
|
1953
|
+
...args[0],
|
|
1954
|
+
beforeFetch: combineCallbacks(_combination, _options.beforeFetch, args[0].beforeFetch),
|
|
1955
|
+
afterFetch: combineCallbacks(_combination, _options.afterFetch, args[0].afterFetch),
|
|
1956
|
+
onFetchError: combineCallbacks(_combination, _options.onFetchError, args[0].onFetchError)
|
|
1957
|
+
};
|
|
1958
|
+
else fetchOptions = {
|
|
1959
|
+
...fetchOptions,
|
|
1960
|
+
...args[0],
|
|
1961
|
+
headers: {
|
|
1962
|
+
...headersToObject(fetchOptions.headers) || {},
|
|
1963
|
+
...headersToObject(args[0].headers) || {}
|
|
2312
1964
|
}
|
|
2313
|
-
}
|
|
2314
|
-
if (args.length > 1 && isFetchOptions(args[1])) {
|
|
2315
|
-
options
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
};
|
|
2322
|
-
}
|
|
1965
|
+
};
|
|
1966
|
+
if (args.length > 1 && isFetchOptions(args[1])) options = {
|
|
1967
|
+
...options,
|
|
1968
|
+
...args[1],
|
|
1969
|
+
beforeFetch: combineCallbacks(_combination, _options.beforeFetch, args[1].beforeFetch),
|
|
1970
|
+
afterFetch: combineCallbacks(_combination, _options.afterFetch, args[1].afterFetch),
|
|
1971
|
+
onFetchError: combineCallbacks(_combination, _options.onFetchError, args[1].onFetchError)
|
|
1972
|
+
};
|
|
2323
1973
|
return useFetch(computedUrl, fetchOptions, options);
|
|
2324
1974
|
}
|
|
2325
1975
|
return useFactoryFetch;
|
|
2326
1976
|
}
|
|
2327
1977
|
function useFetch(url, ...args) {
|
|
2328
|
-
var
|
|
1978
|
+
var _defaultWindow$fetch, _globalThis;
|
|
2329
1979
|
const supportsAbort = typeof AbortController === "function";
|
|
2330
1980
|
let fetchOptions = {};
|
|
2331
1981
|
let options = {
|
|
@@ -2339,21 +1989,18 @@ function useFetch(url, ...args) {
|
|
|
2339
1989
|
type: "text",
|
|
2340
1990
|
payload: void 0
|
|
2341
1991
|
};
|
|
2342
|
-
if (args.length > 0) {
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
}
|
|
1992
|
+
if (args.length > 0) if (isFetchOptions(args[0])) options = {
|
|
1993
|
+
...options,
|
|
1994
|
+
...args[0]
|
|
1995
|
+
};
|
|
1996
|
+
else fetchOptions = args[0];
|
|
2348
1997
|
if (args.length > 1) {
|
|
2349
|
-
if (isFetchOptions(args[1]))
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
timeout
|
|
2356
|
-
} = options;
|
|
1998
|
+
if (isFetchOptions(args[1])) options = {
|
|
1999
|
+
...options,
|
|
2000
|
+
...args[1]
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
const { fetch = (_defaultWindow$fetch = defaultWindow === null || defaultWindow === void 0 ? void 0 : defaultWindow.fetch) !== null && _defaultWindow$fetch !== void 0 ? _defaultWindow$fetch : (_globalThis = globalThis) === null || _globalThis === void 0 ? void 0 : _globalThis.fetch, initialData, timeout } = options;
|
|
2357
2004
|
const responseEvent = /* @__PURE__ */ createEventHook();
|
|
2358
2005
|
const errorEvent = /* @__PURE__ */ createEventHook();
|
|
2359
2006
|
const finallyEvent = /* @__PURE__ */ createEventHook();
|
|
@@ -2369,7 +2016,7 @@ function useFetch(url, ...args) {
|
|
|
2369
2016
|
let timer;
|
|
2370
2017
|
const abort = (reason) => {
|
|
2371
2018
|
if (supportsAbort) {
|
|
2372
|
-
controller
|
|
2019
|
+
controller === null || controller === void 0 || controller.abort(reason);
|
|
2373
2020
|
controller = new AbortController();
|
|
2374
2021
|
controller.signal.onabort = () => aborted.value = true;
|
|
2375
2022
|
fetchOptions = {
|
|
@@ -2382,11 +2029,10 @@ function useFetch(url, ...args) {
|
|
|
2382
2029
|
isFetching.value = isLoading;
|
|
2383
2030
|
isFinished.value = !isLoading;
|
|
2384
2031
|
};
|
|
2385
|
-
if (timeout)
|
|
2386
|
-
timer = useTimeoutFn(abort, timeout, { immediate: false });
|
|
2032
|
+
if (timeout) timer = useTimeoutFn(abort, timeout, { immediate: false });
|
|
2387
2033
|
let executeCounter = 0;
|
|
2388
2034
|
const execute = async (throwOnFailed = false) => {
|
|
2389
|
-
var
|
|
2035
|
+
var _context$options;
|
|
2390
2036
|
abort();
|
|
2391
2037
|
loading(true);
|
|
2392
2038
|
error.value = null;
|
|
@@ -2398,19 +2044,18 @@ function useFetch(url, ...args) {
|
|
|
2398
2044
|
method: config.method,
|
|
2399
2045
|
headers: {}
|
|
2400
2046
|
};
|
|
2401
|
-
const payload = toValue
|
|
2047
|
+
const payload = toValue(config.payload);
|
|
2402
2048
|
if (payload) {
|
|
2049
|
+
var _payloadMapping$confi;
|
|
2403
2050
|
const headers = headersToObject(defaultFetchOptions.headers);
|
|
2404
2051
|
const proto = Object.getPrototypeOf(payload);
|
|
2405
|
-
if (!config.payloadType && payload && (proto === Object.prototype || Array.isArray(proto)) && !(payload instanceof FormData))
|
|
2406
|
-
|
|
2407
|
-
if (config.payloadType)
|
|
2408
|
-
headers["Content-Type"] = (_a2 = payloadMapping[config.payloadType]) != null ? _a2 : config.payloadType;
|
|
2052
|
+
if (!config.payloadType && payload && (proto === Object.prototype || Array.isArray(proto)) && !(payload instanceof FormData)) config.payloadType = "json";
|
|
2053
|
+
if (config.payloadType) headers["Content-Type"] = (_payloadMapping$confi = payloadMapping[config.payloadType]) !== null && _payloadMapping$confi !== void 0 ? _payloadMapping$confi : config.payloadType;
|
|
2409
2054
|
defaultFetchOptions.body = config.payloadType === "json" ? JSON.stringify(payload) : payload;
|
|
2410
2055
|
}
|
|
2411
2056
|
let isCanceled = false;
|
|
2412
2057
|
const context = {
|
|
2413
|
-
url: toValue
|
|
2058
|
+
url: toValue(url),
|
|
2414
2059
|
options: {
|
|
2415
2060
|
...defaultFetchOptions,
|
|
2416
2061
|
...fetchOptions
|
|
@@ -2419,26 +2064,21 @@ function useFetch(url, ...args) {
|
|
|
2419
2064
|
isCanceled = true;
|
|
2420
2065
|
}
|
|
2421
2066
|
};
|
|
2422
|
-
if (options.beforeFetch)
|
|
2423
|
-
Object.assign(context, await options.beforeFetch(context));
|
|
2067
|
+
if (options.beforeFetch) Object.assign(context, await options.beforeFetch(context));
|
|
2424
2068
|
if (isCanceled || !fetch) {
|
|
2425
2069
|
loading(false);
|
|
2426
2070
|
return Promise.resolve(null);
|
|
2427
2071
|
}
|
|
2428
2072
|
let responseData = null;
|
|
2429
|
-
if (timer)
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
context.
|
|
2433
|
-
{
|
|
2434
|
-
...defaultFetchOptions,
|
|
2435
|
-
...context.options
|
|
2436
|
-
headers: {
|
|
2437
|
-
...headersToObject(defaultFetchOptions.headers),
|
|
2438
|
-
...headersToObject((_b2 = context.options) == null ? void 0 : _b2.headers)
|
|
2439
|
-
}
|
|
2073
|
+
if (timer) timer.start();
|
|
2074
|
+
return fetch(context.url, {
|
|
2075
|
+
...defaultFetchOptions,
|
|
2076
|
+
...context.options,
|
|
2077
|
+
headers: {
|
|
2078
|
+
...headersToObject(defaultFetchOptions.headers),
|
|
2079
|
+
...headersToObject((_context$options = context.options) === null || _context$options === void 0 ? void 0 : _context$options.headers)
|
|
2440
2080
|
}
|
|
2441
|
-
).then(async (fetchResponse) => {
|
|
2081
|
+
}).then(async (fetchResponse) => {
|
|
2442
2082
|
response.value = fetchResponse;
|
|
2443
2083
|
statusCode.value = fetchResponse.status;
|
|
2444
2084
|
responseData = await fetchResponse.clone()[config.type]();
|
|
@@ -2446,52 +2086,37 @@ function useFetch(url, ...args) {
|
|
|
2446
2086
|
data.value = initialData || null;
|
|
2447
2087
|
throw new Error(fetchResponse.statusText);
|
|
2448
2088
|
}
|
|
2449
|
-
if (options.afterFetch) {
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
}));
|
|
2456
|
-
}
|
|
2089
|
+
if (options.afterFetch) ({ data: responseData } = await options.afterFetch({
|
|
2090
|
+
data: responseData,
|
|
2091
|
+
response: fetchResponse,
|
|
2092
|
+
context,
|
|
2093
|
+
execute
|
|
2094
|
+
}));
|
|
2457
2095
|
data.value = responseData;
|
|
2458
2096
|
responseEvent.trigger(fetchResponse);
|
|
2459
2097
|
return fetchResponse;
|
|
2460
2098
|
}).catch(async (fetchError) => {
|
|
2461
2099
|
let errorData = fetchError.message || fetchError.name;
|
|
2462
|
-
if (options.onFetchError) {
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
}));
|
|
2470
|
-
}
|
|
2100
|
+
if (options.onFetchError) ({ error: errorData, data: responseData } = await options.onFetchError({
|
|
2101
|
+
data: responseData,
|
|
2102
|
+
error: fetchError,
|
|
2103
|
+
response: response.value,
|
|
2104
|
+
context,
|
|
2105
|
+
execute
|
|
2106
|
+
}));
|
|
2471
2107
|
error.value = errorData;
|
|
2472
|
-
if (options.updateDataOnError)
|
|
2473
|
-
data.value = responseData;
|
|
2108
|
+
if (options.updateDataOnError) data.value = responseData;
|
|
2474
2109
|
errorEvent.trigger(fetchError);
|
|
2475
|
-
if (throwOnFailed)
|
|
2476
|
-
throw fetchError;
|
|
2110
|
+
if (throwOnFailed) throw fetchError;
|
|
2477
2111
|
return null;
|
|
2478
2112
|
}).finally(() => {
|
|
2479
|
-
if (currentExecuteCounter === executeCounter)
|
|
2480
|
-
|
|
2481
|
-
if (timer)
|
|
2482
|
-
timer.stop();
|
|
2113
|
+
if (currentExecuteCounter === executeCounter) loading(false);
|
|
2114
|
+
if (timer) timer.stop();
|
|
2483
2115
|
finallyEvent.trigger(null);
|
|
2484
2116
|
});
|
|
2485
2117
|
};
|
|
2486
|
-
const refetch =
|
|
2487
|
-
watch(
|
|
2488
|
-
[
|
|
2489
|
-
refetch,
|
|
2490
|
-
toRef(url)
|
|
2491
|
-
],
|
|
2492
|
-
([refetch2]) => refetch2 && execute(),
|
|
2493
|
-
{ deep: true }
|
|
2494
|
-
);
|
|
2118
|
+
const refetch = toRef2(options.refetch);
|
|
2119
|
+
watch([refetch, toRef2(url)], ([refetch$1]) => refetch$1 && execute(), { deep: true });
|
|
2495
2120
|
const shell = {
|
|
2496
2121
|
isFinished: readonly(isFinished),
|
|
2497
2122
|
isFetching: readonly(isFetching),
|
|
@@ -2506,7 +2131,6 @@ function useFetch(url, ...args) {
|
|
|
2506
2131
|
onFetchResponse: responseEvent.on,
|
|
2507
2132
|
onFetchError: errorEvent.on,
|
|
2508
2133
|
onFetchFinally: finallyEvent.on,
|
|
2509
|
-
// method
|
|
2510
2134
|
get: setMethod("GET"),
|
|
2511
2135
|
put: setMethod("PUT"),
|
|
2512
2136
|
post: setMethod("POST"),
|
|
@@ -2514,7 +2138,6 @@ function useFetch(url, ...args) {
|
|
|
2514
2138
|
patch: setMethod("PATCH"),
|
|
2515
2139
|
head: setMethod("HEAD"),
|
|
2516
2140
|
options: setMethod("OPTIONS"),
|
|
2517
|
-
// type
|
|
2518
2141
|
json: setType("json"),
|
|
2519
2142
|
text: setType("text"),
|
|
2520
2143
|
blob: setType("blob"),
|
|
@@ -2527,16 +2150,7 @@ function useFetch(url, ...args) {
|
|
|
2527
2150
|
config.method = method;
|
|
2528
2151
|
config.payload = payload;
|
|
2529
2152
|
config.payloadType = payloadType;
|
|
2530
|
-
if (isRef(config.payload)) {
|
|
2531
|
-
watch(
|
|
2532
|
-
[
|
|
2533
|
-
refetch,
|
|
2534
|
-
toRef(config.payload)
|
|
2535
|
-
],
|
|
2536
|
-
([refetch2]) => refetch2 && execute(),
|
|
2537
|
-
{ deep: true }
|
|
2538
|
-
);
|
|
2539
|
-
}
|
|
2153
|
+
if (isRef(config.payload)) watch([refetch, toRef2(config.payload)], ([refetch$1]) => refetch$1 && execute(), { deep: true });
|
|
2540
2154
|
return {
|
|
2541
2155
|
...shell,
|
|
2542
2156
|
then(onFulfilled, onRejected) {
|
|
@@ -2544,7 +2158,6 @@ function useFetch(url, ...args) {
|
|
|
2544
2158
|
}
|
|
2545
2159
|
};
|
|
2546
2160
|
}
|
|
2547
|
-
return void 0;
|
|
2548
2161
|
};
|
|
2549
2162
|
}
|
|
2550
2163
|
function waitUntilFinished() {
|
|
@@ -2563,11 +2176,9 @@ function useFetch(url, ...args) {
|
|
|
2563
2176
|
}
|
|
2564
2177
|
};
|
|
2565
2178
|
}
|
|
2566
|
-
return void 0;
|
|
2567
2179
|
};
|
|
2568
2180
|
}
|
|
2569
|
-
if (options.immediate)
|
|
2570
|
-
Promise.resolve().then(() => execute());
|
|
2181
|
+
if (options.immediate) Promise.resolve().then(() => execute());
|
|
2571
2182
|
return {
|
|
2572
2183
|
...shell,
|
|
2573
2184
|
then(onFulfilled, onRejected) {
|
|
@@ -2576,138 +2187,113 @@ function useFetch(url, ...args) {
|
|
|
2576
2187
|
};
|
|
2577
2188
|
}
|
|
2578
2189
|
function joinPaths(start, end) {
|
|
2579
|
-
if (!start.endsWith("/") && !end.startsWith("/")) {
|
|
2580
|
-
|
|
2581
|
-
}
|
|
2582
|
-
if (start.endsWith("/") && end.startsWith("/")) {
|
|
2583
|
-
return `${start.slice(0, -1)}${end}`;
|
|
2584
|
-
}
|
|
2190
|
+
if (!start.endsWith("/") && !end.startsWith("/")) return `${start}/${end}`;
|
|
2191
|
+
if (start.endsWith("/") && end.startsWith("/")) return `${start.slice(0, -1)}${end}`;
|
|
2585
2192
|
return `${start}${end}`;
|
|
2586
2193
|
}
|
|
2587
|
-
const defaultEvents$1 = [
|
|
2194
|
+
const defaultEvents$1 = [
|
|
2195
|
+
"mousemove",
|
|
2196
|
+
"mousedown",
|
|
2197
|
+
"resize",
|
|
2198
|
+
"keydown",
|
|
2199
|
+
"touchstart",
|
|
2200
|
+
"wheel"
|
|
2201
|
+
];
|
|
2588
2202
|
const oneMinute = 6e4;
|
|
2589
2203
|
function useIdle(timeout = oneMinute, options = {}) {
|
|
2590
|
-
const {
|
|
2591
|
-
initialState = false,
|
|
2592
|
-
listenForVisibilityChange = true,
|
|
2593
|
-
events: events2 = defaultEvents$1,
|
|
2594
|
-
window: window2 = defaultWindow,
|
|
2595
|
-
eventFilter = throttleFilter(50)
|
|
2596
|
-
} = options;
|
|
2204
|
+
const { initialState = false, listenForVisibilityChange = true, events: events$1 = defaultEvents$1, window: window$1 = defaultWindow, eventFilter = throttleFilter(50) } = options;
|
|
2597
2205
|
const idle = shallowRef(initialState);
|
|
2598
2206
|
const lastActive = shallowRef(timestamp());
|
|
2207
|
+
const isPending = shallowRef(false);
|
|
2599
2208
|
let timer;
|
|
2600
2209
|
const reset = () => {
|
|
2601
2210
|
idle.value = false;
|
|
2602
2211
|
clearTimeout(timer);
|
|
2603
2212
|
timer = setTimeout(() => idle.value = true, timeout);
|
|
2604
2213
|
};
|
|
2605
|
-
const onEvent = createFilterWrapper(
|
|
2606
|
-
|
|
2607
|
-
()
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
);
|
|
2612
|
-
if (window2) {
|
|
2613
|
-
const document2 = window2.document;
|
|
2214
|
+
const onEvent = createFilterWrapper(eventFilter, () => {
|
|
2215
|
+
lastActive.value = timestamp();
|
|
2216
|
+
reset();
|
|
2217
|
+
});
|
|
2218
|
+
if (window$1) {
|
|
2219
|
+
const document$1 = window$1.document;
|
|
2614
2220
|
const listenerOptions = { passive: true };
|
|
2615
|
-
for (const event of
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
}
|
|
2623
|
-
|
|
2624
|
-
|
|
2221
|
+
for (const event of events$1) useEventListener(window$1, event, () => {
|
|
2222
|
+
if (!isPending.value) return;
|
|
2223
|
+
onEvent();
|
|
2224
|
+
}, listenerOptions);
|
|
2225
|
+
if (listenForVisibilityChange) useEventListener(document$1, "visibilitychange", () => {
|
|
2226
|
+
if (document$1.hidden || !isPending.value) return;
|
|
2227
|
+
onEvent();
|
|
2228
|
+
}, listenerOptions);
|
|
2229
|
+
start();
|
|
2230
|
+
}
|
|
2231
|
+
function start() {
|
|
2232
|
+
if (isPending.value) return;
|
|
2233
|
+
isPending.value = true;
|
|
2234
|
+
if (!initialState) reset();
|
|
2235
|
+
}
|
|
2236
|
+
function stop() {
|
|
2237
|
+
idle.value = initialState;
|
|
2238
|
+
clearTimeout(timer);
|
|
2239
|
+
isPending.value = false;
|
|
2625
2240
|
}
|
|
2626
2241
|
return {
|
|
2627
2242
|
idle,
|
|
2628
2243
|
lastActive,
|
|
2629
|
-
reset
|
|
2244
|
+
reset,
|
|
2245
|
+
stop,
|
|
2246
|
+
start,
|
|
2247
|
+
isPending: shallowReadonly(isPending)
|
|
2630
2248
|
};
|
|
2631
2249
|
}
|
|
2632
2250
|
// @__NO_SIDE_EFFECTS__
|
|
2633
2251
|
function useNow(options = {}) {
|
|
2634
|
-
const {
|
|
2635
|
-
controls: exposeControls = false,
|
|
2636
|
-
interval = "requestAnimationFrame",
|
|
2637
|
-
immediate = true
|
|
2638
|
-
} = options;
|
|
2252
|
+
const { controls: exposeControls = false, interval = "requestAnimationFrame", immediate = true } = options;
|
|
2639
2253
|
const now2 = ref(/* @__PURE__ */ new Date());
|
|
2640
2254
|
const update = () => now2.value = /* @__PURE__ */ new Date();
|
|
2641
2255
|
const controls = interval === "requestAnimationFrame" ? useRafFn(update, { immediate }) : useIntervalFn(update, interval, { immediate });
|
|
2642
|
-
if (exposeControls) {
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
} else {
|
|
2648
|
-
return now2;
|
|
2649
|
-
}
|
|
2256
|
+
if (exposeControls) return {
|
|
2257
|
+
now: now2,
|
|
2258
|
+
...controls
|
|
2259
|
+
};
|
|
2260
|
+
else return now2;
|
|
2650
2261
|
}
|
|
2651
2262
|
function useObjectUrl(object) {
|
|
2652
2263
|
const url = shallowRef();
|
|
2653
2264
|
const release = () => {
|
|
2654
|
-
if (url.value)
|
|
2655
|
-
URL.revokeObjectURL(url.value);
|
|
2265
|
+
if (url.value) URL.revokeObjectURL(url.value);
|
|
2656
2266
|
url.value = void 0;
|
|
2657
2267
|
};
|
|
2658
|
-
watch(
|
|
2659
|
-
()
|
|
2660
|
-
(newObject)
|
|
2661
|
-
|
|
2662
|
-
if (newObject)
|
|
2663
|
-
url.value = URL.createObjectURL(newObject);
|
|
2664
|
-
},
|
|
2665
|
-
{ immediate: true }
|
|
2666
|
-
);
|
|
2268
|
+
watch(() => toValue(object), (newObject) => {
|
|
2269
|
+
release();
|
|
2270
|
+
if (newObject) url.value = URL.createObjectURL(newObject);
|
|
2271
|
+
}, { immediate: true });
|
|
2667
2272
|
tryOnScopeDispose(release);
|
|
2668
2273
|
return readonly(url);
|
|
2669
2274
|
}
|
|
2670
2275
|
// @__NO_SIDE_EFFECTS__
|
|
2671
2276
|
function useClamp(value, min, max) {
|
|
2672
|
-
if (typeof value === "function" || isReadonly(value))
|
|
2673
|
-
return computed(() => clamp(toValue$1(value), toValue$1(min), toValue$1(max)));
|
|
2277
|
+
if (typeof value === "function" || isReadonly(value)) return computed(() => clamp(toValue(value), toValue(min), toValue(max)));
|
|
2674
2278
|
const _value = ref(value);
|
|
2675
2279
|
return computed({
|
|
2676
2280
|
get() {
|
|
2677
|
-
return _value.value = clamp(_value.value, toValue
|
|
2281
|
+
return _value.value = clamp(_value.value, toValue(min), toValue(max));
|
|
2678
2282
|
},
|
|
2679
|
-
set(
|
|
2680
|
-
_value.value = clamp(
|
|
2283
|
+
set(value$1) {
|
|
2284
|
+
_value.value = clamp(value$1, toValue(min), toValue(max));
|
|
2681
2285
|
}
|
|
2682
2286
|
});
|
|
2683
2287
|
}
|
|
2684
2288
|
function useOffsetPagination(options) {
|
|
2685
|
-
const {
|
|
2686
|
-
total = Number.POSITIVE_INFINITY,
|
|
2687
|
-
pageSize = 10,
|
|
2688
|
-
page = 1,
|
|
2689
|
-
onPageChange = noop,
|
|
2690
|
-
onPageSizeChange = noop,
|
|
2691
|
-
onPageCountChange = noop
|
|
2692
|
-
} = options;
|
|
2289
|
+
const { total = Number.POSITIVE_INFINITY, pageSize = 10, page = 1, onPageChange = noop, onPageSizeChange = noop, onPageCountChange = noop } = options;
|
|
2693
2290
|
const currentPageSize = /* @__PURE__ */ useClamp(pageSize, 1, Number.POSITIVE_INFINITY);
|
|
2694
|
-
const pageCount = computed(() => Math.max(
|
|
2695
|
-
1,
|
|
2696
|
-
Math.ceil(toValue$1(total) / toValue$1(currentPageSize))
|
|
2697
|
-
));
|
|
2291
|
+
const pageCount = computed(() => Math.max(1, Math.ceil(toValue(total) / toValue(currentPageSize))));
|
|
2698
2292
|
const currentPage = /* @__PURE__ */ useClamp(page, 1, pageCount);
|
|
2699
2293
|
const isFirstPage = computed(() => currentPage.value === 1);
|
|
2700
2294
|
const isLastPage = computed(() => currentPage.value === pageCount.value);
|
|
2701
|
-
if (isRef(page)) {
|
|
2702
|
-
|
|
2703
|
-
direction: isReadonly(page) ? "ltr" : "both"
|
|
2704
|
-
});
|
|
2705
|
-
}
|
|
2706
|
-
if (isRef(pageSize)) {
|
|
2707
|
-
syncRef(pageSize, currentPageSize, {
|
|
2708
|
-
direction: isReadonly(pageSize) ? "ltr" : "both"
|
|
2709
|
-
});
|
|
2710
|
-
}
|
|
2295
|
+
if (isRef(page)) syncRef(page, currentPage, { direction: isReadonly(page) ? "ltr" : "both" });
|
|
2296
|
+
if (isRef(pageSize)) syncRef(pageSize, currentPageSize, { direction: isReadonly(pageSize) ? "ltr" : "both" });
|
|
2711
2297
|
function prev() {
|
|
2712
2298
|
currentPage.value--;
|
|
2713
2299
|
}
|
|
@@ -2736,45 +2322,36 @@ function useOffsetPagination(options) {
|
|
|
2736
2322
|
}
|
|
2737
2323
|
function usePrevious(value, initialValue) {
|
|
2738
2324
|
const previous = shallowRef(initialValue);
|
|
2739
|
-
watch(
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
previous.value = oldValue;
|
|
2743
|
-
},
|
|
2744
|
-
{ flush: "sync" }
|
|
2745
|
-
);
|
|
2325
|
+
watch(toRef2(value), (_, oldValue) => {
|
|
2326
|
+
previous.value = oldValue;
|
|
2327
|
+
}, { flush: "sync" });
|
|
2746
2328
|
return readonly(previous);
|
|
2747
2329
|
}
|
|
2748
2330
|
const defaultSortFn = (source, compareFn) => source.sort(compareFn);
|
|
2749
2331
|
const defaultCompare = (a, b) => a - b;
|
|
2750
2332
|
function useSorted(...args) {
|
|
2751
|
-
var _a, _b, _c, _d;
|
|
2752
2333
|
const [source] = args;
|
|
2753
2334
|
let compareFn = defaultCompare;
|
|
2754
2335
|
let options = {};
|
|
2755
|
-
if (args.length === 2) {
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
}
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
if (!dirty)
|
|
2771
|
-
return computed(() => sortFn([...toValue$1(source)], compareFn));
|
|
2336
|
+
if (args.length === 2) if (typeof args[1] === "object") {
|
|
2337
|
+
var _options$compareFn;
|
|
2338
|
+
options = args[1];
|
|
2339
|
+
compareFn = (_options$compareFn = options.compareFn) !== null && _options$compareFn !== void 0 ? _options$compareFn : defaultCompare;
|
|
2340
|
+
} else {
|
|
2341
|
+
var _args$;
|
|
2342
|
+
compareFn = (_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : defaultCompare;
|
|
2343
|
+
}
|
|
2344
|
+
else if (args.length > 2) {
|
|
2345
|
+
var _args$2, _args$3;
|
|
2346
|
+
compareFn = (_args$2 = args[1]) !== null && _args$2 !== void 0 ? _args$2 : defaultCompare;
|
|
2347
|
+
options = (_args$3 = args[2]) !== null && _args$3 !== void 0 ? _args$3 : {};
|
|
2348
|
+
}
|
|
2349
|
+
const { dirty = false, sortFn = defaultSortFn } = options;
|
|
2350
|
+
if (!dirty) return computed(() => sortFn([...toValue(source)], compareFn));
|
|
2772
2351
|
watchEffect(() => {
|
|
2773
|
-
const result = sortFn(toValue
|
|
2774
|
-
if (isRef(source))
|
|
2775
|
-
|
|
2776
|
-
else
|
|
2777
|
-
source.splice(0, source.length, ...result);
|
|
2352
|
+
const result = sortFn(toValue(source), compareFn);
|
|
2353
|
+
if (isRef(source)) source.value = result;
|
|
2354
|
+
else source.splice(0, source.length, ...result);
|
|
2778
2355
|
});
|
|
2779
2356
|
return source;
|
|
2780
2357
|
}
|
|
@@ -2782,39 +2359,33 @@ function useSorted(...args) {
|
|
|
2782
2359
|
function useStepper(steps, initialStep) {
|
|
2783
2360
|
const stepsRef = ref(steps);
|
|
2784
2361
|
const stepNames = computed(() => Array.isArray(stepsRef.value) ? stepsRef.value : Object.keys(stepsRef.value));
|
|
2785
|
-
const index = ref(stepNames.value.indexOf(initialStep
|
|
2362
|
+
const index = ref(stepNames.value.indexOf(initialStep !== null && initialStep !== void 0 ? initialStep : stepNames.value[0]));
|
|
2786
2363
|
const current = computed(() => at(index.value));
|
|
2787
2364
|
const isFirst = computed(() => index.value === 0);
|
|
2788
2365
|
const isLast = computed(() => index.value === stepNames.value.length - 1);
|
|
2789
2366
|
const next = computed(() => stepNames.value[index.value + 1]);
|
|
2790
2367
|
const previous = computed(() => stepNames.value[index.value - 1]);
|
|
2791
|
-
function at(
|
|
2792
|
-
if (Array.isArray(stepsRef.value))
|
|
2793
|
-
|
|
2794
|
-
return stepsRef.value[stepNames.value[index2]];
|
|
2368
|
+
function at(index$1) {
|
|
2369
|
+
if (Array.isArray(stepsRef.value)) return stepsRef.value[index$1];
|
|
2370
|
+
return stepsRef.value[stepNames.value[index$1]];
|
|
2795
2371
|
}
|
|
2796
2372
|
function get2(step) {
|
|
2797
|
-
if (!stepNames.value.includes(step))
|
|
2798
|
-
return;
|
|
2373
|
+
if (!stepNames.value.includes(step)) return;
|
|
2799
2374
|
return at(stepNames.value.indexOf(step));
|
|
2800
2375
|
}
|
|
2801
2376
|
function goTo(step) {
|
|
2802
|
-
if (stepNames.value.includes(step))
|
|
2803
|
-
index.value = stepNames.value.indexOf(step);
|
|
2377
|
+
if (stepNames.value.includes(step)) index.value = stepNames.value.indexOf(step);
|
|
2804
2378
|
}
|
|
2805
2379
|
function goToNext() {
|
|
2806
|
-
if (isLast.value)
|
|
2807
|
-
return;
|
|
2380
|
+
if (isLast.value) return;
|
|
2808
2381
|
index.value++;
|
|
2809
2382
|
}
|
|
2810
2383
|
function goToPrevious() {
|
|
2811
|
-
if (isFirst.value)
|
|
2812
|
-
return;
|
|
2384
|
+
if (isFirst.value) return;
|
|
2813
2385
|
index.value--;
|
|
2814
2386
|
}
|
|
2815
2387
|
function goBackTo(step) {
|
|
2816
|
-
if (isAfter(step))
|
|
2817
|
-
goTo(step);
|
|
2388
|
+
if (isAfter(step)) goTo(step);
|
|
2818
2389
|
}
|
|
2819
2390
|
function isNext(step) {
|
|
2820
2391
|
return stepNames.value.indexOf(step) === index.value + 1;
|
|
@@ -2856,19 +2427,47 @@ function useStepper(steps, initialStep) {
|
|
|
2856
2427
|
function useThrottledRefHistory(source, options = {}) {
|
|
2857
2428
|
const { throttle = 200, trailing = true } = options;
|
|
2858
2429
|
const filter = throttleFilter(throttle, trailing);
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
};
|
|
2430
|
+
return { ...useRefHistory(source, {
|
|
2431
|
+
...options,
|
|
2432
|
+
eventFilter: filter
|
|
2433
|
+
}) };
|
|
2863
2434
|
}
|
|
2864
2435
|
const DEFAULT_UNITS = [
|
|
2865
|
-
{
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
{
|
|
2871
|
-
|
|
2436
|
+
{
|
|
2437
|
+
max: 6e4,
|
|
2438
|
+
value: 1e3,
|
|
2439
|
+
name: "second"
|
|
2440
|
+
},
|
|
2441
|
+
{
|
|
2442
|
+
max: 276e4,
|
|
2443
|
+
value: 6e4,
|
|
2444
|
+
name: "minute"
|
|
2445
|
+
},
|
|
2446
|
+
{
|
|
2447
|
+
max: 72e6,
|
|
2448
|
+
value: 36e5,
|
|
2449
|
+
name: "hour"
|
|
2450
|
+
},
|
|
2451
|
+
{
|
|
2452
|
+
max: 5184e5,
|
|
2453
|
+
value: 864e5,
|
|
2454
|
+
name: "day"
|
|
2455
|
+
},
|
|
2456
|
+
{
|
|
2457
|
+
max: 24192e5,
|
|
2458
|
+
value: 6048e5,
|
|
2459
|
+
name: "week"
|
|
2460
|
+
},
|
|
2461
|
+
{
|
|
2462
|
+
max: 28512e6,
|
|
2463
|
+
value: 2592e6,
|
|
2464
|
+
name: "month"
|
|
2465
|
+
},
|
|
2466
|
+
{
|
|
2467
|
+
max: Number.POSITIVE_INFINITY,
|
|
2468
|
+
value: 31536e6,
|
|
2469
|
+
name: "year"
|
|
2470
|
+
}
|
|
2872
2471
|
];
|
|
2873
2472
|
const DEFAULT_MESSAGES = {
|
|
2874
2473
|
justNow: "just now",
|
|
@@ -2888,93 +2487,70 @@ function DEFAULT_FORMATTER(date) {
|
|
|
2888
2487
|
}
|
|
2889
2488
|
// @__NO_SIDE_EFFECTS__
|
|
2890
2489
|
function useTimeAgo(time, options = {}) {
|
|
2891
|
-
const {
|
|
2892
|
-
|
|
2893
|
-
updateInterval
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
const timeAgo = computed(() => formatTimeAgo(new Date(toValue
|
|
2897
|
-
if (exposeControls) {
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
} else {
|
|
2903
|
-
return timeAgo;
|
|
2904
|
-
}
|
|
2490
|
+
const { controls: exposeControls = false, updateInterval = 3e4 } = options;
|
|
2491
|
+
const { now: now2, ...controls } = /* @__PURE__ */ useNow({
|
|
2492
|
+
interval: updateInterval,
|
|
2493
|
+
controls: true
|
|
2494
|
+
});
|
|
2495
|
+
const timeAgo = computed(() => formatTimeAgo(new Date(toValue(time)), options, toValue(now2)));
|
|
2496
|
+
if (exposeControls) return {
|
|
2497
|
+
timeAgo,
|
|
2498
|
+
...controls
|
|
2499
|
+
};
|
|
2500
|
+
else return timeAgo;
|
|
2905
2501
|
}
|
|
2906
2502
|
function formatTimeAgo(from, options = {}, now2 = Date.now()) {
|
|
2907
|
-
|
|
2908
|
-
const {
|
|
2909
|
-
max,
|
|
2910
|
-
messages = DEFAULT_MESSAGES,
|
|
2911
|
-
fullDateFormatter = DEFAULT_FORMATTER,
|
|
2912
|
-
units = DEFAULT_UNITS,
|
|
2913
|
-
showSecond = false,
|
|
2914
|
-
rounding = "round"
|
|
2915
|
-
} = options;
|
|
2503
|
+
const { max, messages = DEFAULT_MESSAGES, fullDateFormatter = DEFAULT_FORMATTER, units = DEFAULT_UNITS, showSecond = false, rounding = "round" } = options;
|
|
2916
2504
|
const roundFn = typeof rounding === "number" ? (n) => +n.toFixed(rounding) : Math[rounding];
|
|
2917
2505
|
const diff = +now2 - +from;
|
|
2918
2506
|
const absDiff = Math.abs(diff);
|
|
2919
|
-
function getValue(
|
|
2920
|
-
return roundFn(Math.abs(
|
|
2507
|
+
function getValue$1(diff$1, unit) {
|
|
2508
|
+
return roundFn(Math.abs(diff$1) / unit.value);
|
|
2921
2509
|
}
|
|
2922
|
-
function format(
|
|
2923
|
-
const val = getValue(
|
|
2924
|
-
const past =
|
|
2510
|
+
function format(diff$1, unit) {
|
|
2511
|
+
const val = getValue$1(diff$1, unit);
|
|
2512
|
+
const past = diff$1 > 0;
|
|
2925
2513
|
const str = applyFormat(unit.name, val, past);
|
|
2926
2514
|
return applyFormat(past ? "past" : "future", str, past);
|
|
2927
2515
|
}
|
|
2928
2516
|
function applyFormat(name, val, isPast) {
|
|
2929
2517
|
const formatter = messages[name];
|
|
2930
|
-
if (typeof formatter === "function")
|
|
2931
|
-
return formatter(val, isPast);
|
|
2518
|
+
if (typeof formatter === "function") return formatter(val, isPast);
|
|
2932
2519
|
return formatter.replace("{0}", val.toString());
|
|
2933
2520
|
}
|
|
2934
|
-
if (absDiff < 6e4 && !showSecond)
|
|
2935
|
-
|
|
2936
|
-
if (typeof max === "number" && absDiff > max)
|
|
2937
|
-
return fullDateFormatter(new Date(from));
|
|
2521
|
+
if (absDiff < 6e4 && !showSecond) return messages.justNow;
|
|
2522
|
+
if (typeof max === "number" && absDiff > max) return fullDateFormatter(new Date(from));
|
|
2938
2523
|
if (typeof max === "string") {
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2524
|
+
var _units$find;
|
|
2525
|
+
const unitMax = (_units$find = units.find((i) => i.name === max)) === null || _units$find === void 0 ? void 0 : _units$find.max;
|
|
2526
|
+
if (unitMax && absDiff > unitMax) return fullDateFormatter(new Date(from));
|
|
2942
2527
|
}
|
|
2943
2528
|
for (const [idx, unit] of units.entries()) {
|
|
2944
|
-
|
|
2945
|
-
if (
|
|
2946
|
-
return format(diff, units[idx - 1]);
|
|
2947
|
-
if (absDiff < unit.max)
|
|
2948
|
-
return format(diff, unit);
|
|
2529
|
+
if (getValue$1(diff, unit) <= 0 && units[idx - 1]) return format(diff, units[idx - 1]);
|
|
2530
|
+
if (absDiff < unit.max) return format(diff, unit);
|
|
2949
2531
|
}
|
|
2950
2532
|
return messages.invalid;
|
|
2951
2533
|
}
|
|
2952
2534
|
function useTimeoutPoll(fn, interval, options = {}) {
|
|
2953
|
-
const {
|
|
2954
|
-
immediate = true,
|
|
2955
|
-
immediateCallback = false
|
|
2956
|
-
} = options;
|
|
2535
|
+
const { immediate = true, immediateCallback = false } = options;
|
|
2957
2536
|
const { start } = useTimeoutFn(loop, interval, { immediate });
|
|
2958
2537
|
const isActive = shallowRef(false);
|
|
2959
2538
|
async function loop() {
|
|
2960
|
-
if (!isActive.value)
|
|
2961
|
-
return;
|
|
2539
|
+
if (!isActive.value) return;
|
|
2962
2540
|
await fn();
|
|
2963
2541
|
start();
|
|
2964
2542
|
}
|
|
2965
2543
|
function resume() {
|
|
2966
2544
|
if (!isActive.value) {
|
|
2967
2545
|
isActive.value = true;
|
|
2968
|
-
if (immediateCallback)
|
|
2969
|
-
fn();
|
|
2546
|
+
if (immediateCallback) fn();
|
|
2970
2547
|
start();
|
|
2971
2548
|
}
|
|
2972
2549
|
}
|
|
2973
2550
|
function pause() {
|
|
2974
2551
|
isActive.value = false;
|
|
2975
2552
|
}
|
|
2976
|
-
if (immediate && isClient)
|
|
2977
|
-
resume();
|
|
2553
|
+
if (immediate && isClient) resume();
|
|
2978
2554
|
tryOnScopeDispose(pause);
|
|
2979
2555
|
return {
|
|
2980
2556
|
isActive,
|
|
@@ -2983,13 +2559,7 @@ function useTimeoutPoll(fn, interval, options = {}) {
|
|
|
2983
2559
|
};
|
|
2984
2560
|
}
|
|
2985
2561
|
function useTimestamp(options = {}) {
|
|
2986
|
-
const {
|
|
2987
|
-
controls: exposeControls = false,
|
|
2988
|
-
offset = 0,
|
|
2989
|
-
immediate = true,
|
|
2990
|
-
interval = "requestAnimationFrame",
|
|
2991
|
-
callback
|
|
2992
|
-
} = options;
|
|
2562
|
+
const { controls: exposeControls = false, offset = 0, immediate = true, interval = "requestAnimationFrame", callback } = options;
|
|
2993
2563
|
const ts = shallowRef(timestamp() + offset);
|
|
2994
2564
|
const update = () => ts.value = timestamp() + offset;
|
|
2995
2565
|
const cb = callback ? () => {
|
|
@@ -2997,50 +2567,32 @@ function useTimestamp(options = {}) {
|
|
|
2997
2567
|
callback(ts.value);
|
|
2998
2568
|
} : update;
|
|
2999
2569
|
const controls = interval === "requestAnimationFrame" ? useRafFn(cb, { immediate }) : useIntervalFn(cb, interval, { immediate });
|
|
3000
|
-
if (exposeControls) {
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
} else {
|
|
3006
|
-
return ts;
|
|
3007
|
-
}
|
|
2570
|
+
if (exposeControls) return {
|
|
2571
|
+
timestamp: ts,
|
|
2572
|
+
...controls
|
|
2573
|
+
};
|
|
2574
|
+
else return ts;
|
|
3008
2575
|
}
|
|
3009
2576
|
function useUrlSearchParams(mode = "history", options = {}) {
|
|
3010
|
-
const {
|
|
3011
|
-
|
|
3012
|
-
removeNullishValues = true,
|
|
3013
|
-
removeFalsyValues = false,
|
|
3014
|
-
write: enableWrite = true,
|
|
3015
|
-
writeMode = "replace",
|
|
3016
|
-
window: window2 = defaultWindow,
|
|
3017
|
-
stringify = (params) => params.toString()
|
|
3018
|
-
} = options;
|
|
3019
|
-
if (!window2)
|
|
3020
|
-
return reactive(initialValue);
|
|
2577
|
+
const { initialValue = {}, removeNullishValues = true, removeFalsyValues = false, write: enableWrite = true, writeMode = "replace", window: window$1 = defaultWindow, stringify = (params) => params.toString() } = options;
|
|
2578
|
+
if (!window$1) return reactive(initialValue);
|
|
3021
2579
|
const state = reactive({});
|
|
3022
2580
|
function getRawParams() {
|
|
3023
|
-
if (mode === "history")
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
const hash = window2.location.hash || "";
|
|
2581
|
+
if (mode === "history") return window$1.location.search || "";
|
|
2582
|
+
else if (mode === "hash") {
|
|
2583
|
+
const hash = window$1.location.hash || "";
|
|
3027
2584
|
const index = hash.indexOf("?");
|
|
3028
2585
|
return index > 0 ? hash.slice(index) : "";
|
|
3029
|
-
} else
|
|
3030
|
-
return (window2.location.hash || "").replace(/^#/, "");
|
|
3031
|
-
}
|
|
2586
|
+
} else return (window$1.location.hash || "").replace(/^#/, "");
|
|
3032
2587
|
}
|
|
3033
2588
|
function constructQuery(params) {
|
|
3034
2589
|
const stringified = stringify(params);
|
|
3035
|
-
if (mode === "history")
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
return `${window2.location.search || ""}${stringified ? `#${stringified}` : ""}`;
|
|
3039
|
-
const hash = window2.location.hash || "#";
|
|
2590
|
+
if (mode === "history") return `${stringified ? `?${stringified}` : ""}${window$1.location.hash || ""}`;
|
|
2591
|
+
if (mode === "hash-params") return `${window$1.location.search || ""}${stringified ? `#${stringified}` : ""}`;
|
|
2592
|
+
const hash = window$1.location.hash || "#";
|
|
3040
2593
|
const index = hash.indexOf("?");
|
|
3041
|
-
if (index > 0)
|
|
3042
|
-
|
|
3043
|
-
return `${window2.location.search || ""}${hash}${stringified ? `?${stringified}` : ""}`;
|
|
2594
|
+
if (index > 0) return `${window$1.location.search || ""}${hash.slice(0, index)}${stringified ? `?${stringified}` : ""}`;
|
|
2595
|
+
return `${window$1.location.search || ""}${hash}${stringified ? `?${stringified}` : ""}`;
|
|
3044
2596
|
}
|
|
3045
2597
|
function read() {
|
|
3046
2598
|
return new URLSearchParams(getRawParams());
|
|
@@ -3054,83 +2606,47 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
3054
2606
|
}
|
|
3055
2607
|
Array.from(unusedKeys).forEach((key) => delete state[key]);
|
|
3056
2608
|
}
|
|
3057
|
-
const { pause, resume } =
|
|
3058
|
-
|
|
3059
|
-
() => {
|
|
3060
|
-
const
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
params.delete(key);
|
|
3069
|
-
else
|
|
3070
|
-
params.set(key, mapEntry);
|
|
3071
|
-
});
|
|
3072
|
-
write(params, false);
|
|
3073
|
-
},
|
|
3074
|
-
{ deep: true }
|
|
3075
|
-
);
|
|
2609
|
+
const { pause, resume } = pausableWatch(state, () => {
|
|
2610
|
+
const params = new URLSearchParams("");
|
|
2611
|
+
Object.keys(state).forEach((key) => {
|
|
2612
|
+
const mapEntry = state[key];
|
|
2613
|
+
if (Array.isArray(mapEntry)) mapEntry.forEach((value) => params.append(key, value));
|
|
2614
|
+
else if (removeNullishValues && mapEntry == null) params.delete(key);
|
|
2615
|
+
else if (removeFalsyValues && !mapEntry) params.delete(key);
|
|
2616
|
+
else params.set(key, mapEntry);
|
|
2617
|
+
});
|
|
2618
|
+
write(params, false);
|
|
2619
|
+
}, { deep: true });
|
|
3076
2620
|
function write(params, shouldUpdate, shouldWriteHistory = true) {
|
|
3077
2621
|
pause();
|
|
3078
|
-
if (shouldUpdate)
|
|
3079
|
-
|
|
3080
|
-
if (
|
|
3081
|
-
window2.history.replaceState(
|
|
3082
|
-
window2.history.state,
|
|
3083
|
-
window2.document.title,
|
|
3084
|
-
window2.location.pathname + constructQuery(params)
|
|
3085
|
-
);
|
|
3086
|
-
} else {
|
|
3087
|
-
if (shouldWriteHistory) {
|
|
3088
|
-
window2.history.pushState(
|
|
3089
|
-
window2.history.state,
|
|
3090
|
-
window2.document.title,
|
|
3091
|
-
window2.location.pathname + constructQuery(params)
|
|
3092
|
-
);
|
|
3093
|
-
}
|
|
3094
|
-
}
|
|
2622
|
+
if (shouldUpdate) updateState(params);
|
|
2623
|
+
if (writeMode === "replace") window$1.history.replaceState(window$1.history.state, window$1.document.title, window$1.location.pathname + constructQuery(params));
|
|
2624
|
+
else if (shouldWriteHistory) window$1.history.pushState(window$1.history.state, window$1.document.title, window$1.location.pathname + constructQuery(params));
|
|
3095
2625
|
nextTick(() => resume());
|
|
3096
2626
|
}
|
|
3097
2627
|
function onChanged() {
|
|
3098
|
-
if (!enableWrite)
|
|
3099
|
-
return;
|
|
2628
|
+
if (!enableWrite) return;
|
|
3100
2629
|
write(read(), true, false);
|
|
3101
2630
|
}
|
|
3102
2631
|
const listenerOptions = { passive: true };
|
|
3103
|
-
useEventListener(
|
|
3104
|
-
if (mode !== "history")
|
|
3105
|
-
useEventListener(window2, "hashchange", onChanged, listenerOptions);
|
|
2632
|
+
useEventListener(window$1, "popstate", onChanged, listenerOptions);
|
|
2633
|
+
if (mode !== "history") useEventListener(window$1, "hashchange", onChanged, listenerOptions);
|
|
3106
2634
|
const initial = read();
|
|
3107
|
-
if (initial.keys().next().value)
|
|
3108
|
-
|
|
3109
|
-
else
|
|
3110
|
-
Object.assign(state, initialValue);
|
|
2635
|
+
if (initial.keys().next().value) updateState(initial);
|
|
2636
|
+
else Object.assign(state, initialValue);
|
|
3111
2637
|
return state;
|
|
3112
2638
|
}
|
|
3113
2639
|
const DEFAULT_PING_MESSAGE = "ping";
|
|
3114
2640
|
function resolveNestedOptions(options) {
|
|
3115
|
-
if (options === true)
|
|
3116
|
-
return {};
|
|
2641
|
+
if (options === true) return {};
|
|
3117
2642
|
return options;
|
|
3118
2643
|
}
|
|
3119
2644
|
function useWebSocket(url, options = {}) {
|
|
3120
|
-
const {
|
|
3121
|
-
onConnected,
|
|
3122
|
-
onDisconnected,
|
|
3123
|
-
onError,
|
|
3124
|
-
onMessage,
|
|
3125
|
-
immediate = true,
|
|
3126
|
-
autoConnect = true,
|
|
3127
|
-
autoClose = true,
|
|
3128
|
-
protocols = []
|
|
3129
|
-
} = options;
|
|
2645
|
+
const { onConnected, onDisconnected, onError, onMessage, immediate = true, autoConnect = true, autoClose = true, protocols = [] } = options;
|
|
3130
2646
|
const data = ref(null);
|
|
3131
2647
|
const status = shallowRef("CLOSED");
|
|
3132
2648
|
const wsRef = ref();
|
|
3133
|
-
const urlRef =
|
|
2649
|
+
const urlRef = toRef2(url);
|
|
3134
2650
|
let heartbeatPause;
|
|
3135
2651
|
let heartbeatResume;
|
|
3136
2652
|
let explicitlyClosed = false;
|
|
@@ -3140,8 +2656,7 @@ function useWebSocket(url, options = {}) {
|
|
|
3140
2656
|
let pongTimeoutWait;
|
|
3141
2657
|
const _sendBuffer = () => {
|
|
3142
2658
|
if (bufferedData.length && wsRef.value && status.value === "OPEN") {
|
|
3143
|
-
for (const buffer of bufferedData)
|
|
3144
|
-
wsRef.value.send(buffer);
|
|
2659
|
+
for (const buffer of bufferedData) wsRef.value.send(buffer);
|
|
3145
2660
|
bufferedData = [];
|
|
3146
2661
|
}
|
|
3147
2662
|
};
|
|
@@ -3157,113 +2672,86 @@ function useWebSocket(url, options = {}) {
|
|
|
3157
2672
|
};
|
|
3158
2673
|
const close = (code = 1e3, reason) => {
|
|
3159
2674
|
resetRetry();
|
|
3160
|
-
if (!isClient && !isWorker || !wsRef.value)
|
|
3161
|
-
return;
|
|
2675
|
+
if (!isClient && !isWorker || !wsRef.value) return;
|
|
3162
2676
|
explicitlyClosed = true;
|
|
3163
2677
|
resetHeartbeat();
|
|
3164
|
-
heartbeatPause
|
|
2678
|
+
heartbeatPause === null || heartbeatPause === void 0 || heartbeatPause();
|
|
3165
2679
|
wsRef.value.close(code, reason);
|
|
3166
2680
|
wsRef.value = void 0;
|
|
3167
2681
|
};
|
|
3168
|
-
const send = (
|
|
2682
|
+
const send = (data$1, useBuffer = true) => {
|
|
3169
2683
|
if (!wsRef.value || status.value !== "OPEN") {
|
|
3170
|
-
if (useBuffer)
|
|
3171
|
-
bufferedData.push(data2);
|
|
2684
|
+
if (useBuffer) bufferedData.push(data$1);
|
|
3172
2685
|
return false;
|
|
3173
2686
|
}
|
|
3174
2687
|
_sendBuffer();
|
|
3175
|
-
wsRef.value.send(
|
|
2688
|
+
wsRef.value.send(data$1);
|
|
3176
2689
|
return true;
|
|
3177
2690
|
};
|
|
3178
2691
|
const _init = () => {
|
|
3179
|
-
if (explicitlyClosed || typeof urlRef.value === "undefined")
|
|
3180
|
-
return;
|
|
2692
|
+
if (explicitlyClosed || typeof urlRef.value === "undefined") return;
|
|
3181
2693
|
const ws = new WebSocket(urlRef.value, protocols);
|
|
3182
2694
|
wsRef.value = ws;
|
|
3183
2695
|
status.value = "CONNECTING";
|
|
3184
2696
|
ws.onopen = () => {
|
|
3185
2697
|
status.value = "OPEN";
|
|
3186
2698
|
retried = 0;
|
|
3187
|
-
onConnected
|
|
3188
|
-
heartbeatResume
|
|
2699
|
+
onConnected === null || onConnected === void 0 || onConnected(ws);
|
|
2700
|
+
heartbeatResume === null || heartbeatResume === void 0 || heartbeatResume();
|
|
3189
2701
|
_sendBuffer();
|
|
3190
2702
|
};
|
|
3191
2703
|
ws.onclose = (ev) => {
|
|
3192
2704
|
status.value = "CLOSED";
|
|
3193
2705
|
resetHeartbeat();
|
|
3194
|
-
heartbeatPause
|
|
3195
|
-
onDisconnected
|
|
2706
|
+
heartbeatPause === null || heartbeatPause === void 0 || heartbeatPause();
|
|
2707
|
+
onDisconnected === null || onDisconnected === void 0 || onDisconnected(ws, ev);
|
|
3196
2708
|
if (!explicitlyClosed && options.autoReconnect && (wsRef.value == null || ws === wsRef.value)) {
|
|
3197
|
-
const {
|
|
3198
|
-
|
|
3199
|
-
delay = 1e3,
|
|
3200
|
-
onFailed
|
|
3201
|
-
} = resolveNestedOptions(options.autoReconnect);
|
|
3202
|
-
const checkRetires = typeof retries === "function" ? retries : () => typeof retries === "number" && (retries < 0 || retried < retries);
|
|
3203
|
-
if (checkRetires(retried)) {
|
|
2709
|
+
const { retries = -1, delay = 1e3, onFailed } = resolveNestedOptions(options.autoReconnect);
|
|
2710
|
+
if ((typeof retries === "function" ? retries : () => typeof retries === "number" && (retries < 0 || retried < retries))(retried)) {
|
|
3204
2711
|
retried += 1;
|
|
3205
2712
|
retryTimeout = setTimeout(_init, delay);
|
|
3206
|
-
} else
|
|
3207
|
-
onFailed == null ? void 0 : onFailed();
|
|
3208
|
-
}
|
|
2713
|
+
} else onFailed === null || onFailed === void 0 || onFailed();
|
|
3209
2714
|
}
|
|
3210
2715
|
};
|
|
3211
2716
|
ws.onerror = (e) => {
|
|
3212
|
-
onError
|
|
2717
|
+
onError === null || onError === void 0 || onError(ws, e);
|
|
3213
2718
|
};
|
|
3214
2719
|
ws.onmessage = (e) => {
|
|
3215
2720
|
if (options.heartbeat) {
|
|
3216
2721
|
resetHeartbeat();
|
|
3217
|
-
const {
|
|
3218
|
-
|
|
3219
|
-
responseMessage = message
|
|
3220
|
-
} = resolveNestedOptions(options.heartbeat);
|
|
3221
|
-
if (e.data === toValue$1(responseMessage))
|
|
3222
|
-
return;
|
|
2722
|
+
const { message = DEFAULT_PING_MESSAGE, responseMessage = message } = resolveNestedOptions(options.heartbeat);
|
|
2723
|
+
if (e.data === toValue(responseMessage)) return;
|
|
3223
2724
|
}
|
|
3224
2725
|
data.value = e.data;
|
|
3225
|
-
onMessage
|
|
2726
|
+
onMessage === null || onMessage === void 0 || onMessage(ws, e);
|
|
3226
2727
|
};
|
|
3227
2728
|
};
|
|
3228
2729
|
if (options.heartbeat) {
|
|
3229
|
-
const {
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
return;
|
|
3239
|
-
pongTimeoutWait = setTimeout(() => {
|
|
3240
|
-
close();
|
|
3241
|
-
explicitlyClosed = false;
|
|
3242
|
-
}, pongTimeout);
|
|
3243
|
-
},
|
|
3244
|
-
interval,
|
|
3245
|
-
{ immediate: false }
|
|
3246
|
-
);
|
|
2730
|
+
const { message = DEFAULT_PING_MESSAGE, interval = 1e3, pongTimeout = 1e3 } = resolveNestedOptions(options.heartbeat);
|
|
2731
|
+
const { pause, resume } = useIntervalFn(() => {
|
|
2732
|
+
send(toValue(message), false);
|
|
2733
|
+
if (pongTimeoutWait != null) return;
|
|
2734
|
+
pongTimeoutWait = setTimeout(() => {
|
|
2735
|
+
close();
|
|
2736
|
+
explicitlyClosed = false;
|
|
2737
|
+
}, pongTimeout);
|
|
2738
|
+
}, interval, { immediate: false });
|
|
3247
2739
|
heartbeatPause = pause;
|
|
3248
2740
|
heartbeatResume = resume;
|
|
3249
2741
|
}
|
|
3250
2742
|
if (autoClose) {
|
|
3251
|
-
if (isClient)
|
|
3252
|
-
useEventListener("beforeunload", () => close(), { passive: true });
|
|
2743
|
+
if (isClient) useEventListener("beforeunload", () => close(), { passive: true });
|
|
3253
2744
|
tryOnScopeDispose(close);
|
|
3254
2745
|
}
|
|
3255
2746
|
const open = () => {
|
|
3256
|
-
if (!isClient && !isWorker)
|
|
3257
|
-
return;
|
|
2747
|
+
if (!isClient && !isWorker) return;
|
|
3258
2748
|
close();
|
|
3259
2749
|
explicitlyClosed = false;
|
|
3260
2750
|
retried = 0;
|
|
3261
2751
|
_init();
|
|
3262
2752
|
};
|
|
3263
|
-
if (immediate)
|
|
3264
|
-
|
|
3265
|
-
if (autoConnect)
|
|
3266
|
-
watch(urlRef, open);
|
|
2753
|
+
if (immediate) open();
|
|
2754
|
+
if (autoConnect) watch(urlRef, open);
|
|
3267
2755
|
return {
|
|
3268
2756
|
data,
|
|
3269
2757
|
status,
|
|
@@ -3274,21 +2762,17 @@ function useWebSocket(url, options = {}) {
|
|
|
3274
2762
|
};
|
|
3275
2763
|
}
|
|
3276
2764
|
function depsParser(deps, localDeps) {
|
|
3277
|
-
if (deps.length === 0 && localDeps.length === 0)
|
|
3278
|
-
return "";
|
|
2765
|
+
if (deps.length === 0 && localDeps.length === 0) return "";
|
|
3279
2766
|
const depsString = deps.map((dep) => `'${dep}'`).toString();
|
|
3280
2767
|
const depsFunctionString = localDeps.filter((dep) => typeof dep === "function").map((fn) => {
|
|
3281
2768
|
const str = fn.toString();
|
|
3282
|
-
if (str.trim().startsWith("function"))
|
|
3283
|
-
|
|
3284
|
-
} else {
|
|
3285
|
-
const name = fn.name;
|
|
3286
|
-
return `const ${name} = ${str}`;
|
|
3287
|
-
}
|
|
2769
|
+
if (str.trim().startsWith("function")) return str;
|
|
2770
|
+
else return `const ${fn.name} = ${str}`;
|
|
3288
2771
|
}).join(";");
|
|
3289
2772
|
const importString = `importScripts(${depsString});`;
|
|
3290
2773
|
return `${depsString.trim() === "" ? "" : importString} ${depsFunctionString}`;
|
|
3291
2774
|
}
|
|
2775
|
+
var depsParser_default = depsParser;
|
|
3292
2776
|
function jobRunner(userFunc) {
|
|
3293
2777
|
return (e) => {
|
|
3294
2778
|
const userFuncArgs = e.data[0];
|
|
@@ -3299,37 +2783,33 @@ function jobRunner(userFunc) {
|
|
|
3299
2783
|
});
|
|
3300
2784
|
};
|
|
3301
2785
|
}
|
|
2786
|
+
var jobRunner_default = jobRunner;
|
|
3302
2787
|
function createWorkerBlobUrl(fn, deps, localDeps) {
|
|
3303
|
-
const blobCode = `${
|
|
2788
|
+
const blobCode = `${depsParser_default(deps, localDeps)}; onmessage=(${jobRunner_default})(${fn})`;
|
|
3304
2789
|
const blob = new Blob([blobCode], { type: "text/javascript" });
|
|
3305
|
-
|
|
3306
|
-
return url;
|
|
2790
|
+
return URL.createObjectURL(blob);
|
|
3307
2791
|
}
|
|
2792
|
+
var createWorkerBlobUrl_default = createWorkerBlobUrl;
|
|
3308
2793
|
function useWebWorkerFn(fn, options = {}) {
|
|
3309
|
-
const {
|
|
3310
|
-
dependencies = [],
|
|
3311
|
-
localDependencies = [],
|
|
3312
|
-
timeout,
|
|
3313
|
-
window: window2 = defaultWindow
|
|
3314
|
-
} = options;
|
|
2794
|
+
const { dependencies = [], localDependencies = [], timeout, window: window$1 = defaultWindow } = options;
|
|
3315
2795
|
const worker = ref();
|
|
3316
2796
|
const workerStatus = shallowRef("PENDING");
|
|
3317
2797
|
const promise = ref({});
|
|
3318
2798
|
const timeoutId = shallowRef();
|
|
3319
2799
|
const workerTerminate = (status = "PENDING") => {
|
|
3320
|
-
if (worker.value && worker.value._url &&
|
|
2800
|
+
if (worker.value && worker.value._url && window$1) {
|
|
3321
2801
|
worker.value.terminate();
|
|
3322
2802
|
URL.revokeObjectURL(worker.value._url);
|
|
3323
2803
|
promise.value = {};
|
|
3324
2804
|
worker.value = void 0;
|
|
3325
|
-
|
|
2805
|
+
window$1.clearTimeout(timeoutId.value);
|
|
3326
2806
|
workerStatus.value = status;
|
|
3327
2807
|
}
|
|
3328
2808
|
};
|
|
3329
2809
|
workerTerminate();
|
|
3330
2810
|
tryOnScopeDispose(workerTerminate);
|
|
3331
2811
|
const generateWorker = () => {
|
|
3332
|
-
const blobUrl =
|
|
2812
|
+
const blobUrl = createWorkerBlobUrl_default(fn, dependencies, localDependencies);
|
|
3333
2813
|
const newWorker = new Worker(blobUrl);
|
|
3334
2814
|
newWorker._url = blobUrl;
|
|
3335
2815
|
newWorker.onmessage = (e) => {
|
|
@@ -3355,28 +2835,21 @@ function useWebWorkerFn(fn, options = {}) {
|
|
|
3355
2835
|
reject(e);
|
|
3356
2836
|
workerTerminate("ERROR");
|
|
3357
2837
|
};
|
|
3358
|
-
if (timeout)
|
|
3359
|
-
timeoutId.value = setTimeout(
|
|
3360
|
-
() => workerTerminate("TIMEOUT_EXPIRED"),
|
|
3361
|
-
timeout
|
|
3362
|
-
);
|
|
3363
|
-
}
|
|
2838
|
+
if (timeout) timeoutId.value = setTimeout(() => workerTerminate("TIMEOUT_EXPIRED"), timeout);
|
|
3364
2839
|
return newWorker;
|
|
3365
2840
|
};
|
|
3366
2841
|
const callWorker = (...fnArgs) => new Promise((resolve, reject) => {
|
|
3367
|
-
var
|
|
2842
|
+
var _worker$value;
|
|
3368
2843
|
promise.value = {
|
|
3369
2844
|
resolve,
|
|
3370
2845
|
reject
|
|
3371
2846
|
};
|
|
3372
|
-
(
|
|
2847
|
+
(_worker$value = worker.value) === null || _worker$value === void 0 || _worker$value.postMessage([[...fnArgs]]);
|
|
3373
2848
|
workerStatus.value = "RUNNING";
|
|
3374
2849
|
});
|
|
3375
2850
|
const workerFn = (...fnArgs) => {
|
|
3376
2851
|
if (workerStatus.value === "RUNNING") {
|
|
3377
|
-
console.error(
|
|
3378
|
-
"[useWebWorkerFn] You can only run one instance of the worker at a time."
|
|
3379
|
-
);
|
|
2852
|
+
console.error("[useWebWorkerFn] You can only run one instance of the worker at a time.");
|
|
3380
2853
|
return Promise.reject();
|
|
3381
2854
|
}
|
|
3382
2855
|
worker.value = generateWorker();
|
|
@@ -3448,8 +2921,8 @@ export {
|
|
|
3448
2921
|
refDefault,
|
|
3449
2922
|
refThrottled,
|
|
3450
2923
|
refWithControl,
|
|
3451
|
-
resolveRef,
|
|
3452
|
-
resolveUnref,
|
|
2924
|
+
toRef as resolveRef,
|
|
2925
|
+
toValue2 as resolveUnref,
|
|
3453
2926
|
set,
|
|
3454
2927
|
syncRef,
|
|
3455
2928
|
syncRefs,
|
|
@@ -3457,9 +2930,9 @@ export {
|
|
|
3457
2930
|
refThrottled as throttledRef,
|
|
3458
2931
|
watchThrottled as throttledWatch,
|
|
3459
2932
|
toReactive,
|
|
3460
|
-
toRef,
|
|
2933
|
+
toRef2 as toRef,
|
|
3461
2934
|
toRefs,
|
|
3462
|
-
toValue,
|
|
2935
|
+
toValue3 as toValue,
|
|
3463
2936
|
tryOnScopeDispose,
|
|
3464
2937
|
until,
|
|
3465
2938
|
useArrayDifference,
|