@reactive-vscode/vueuse 0.2.9 → 0.2.10
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 +207 -141
- package/dist/index.d.ts +69 -24
- package/dist/index.js +208 -142
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, watch, customRef, getCurrentScope, onScopeDispose, effectScope, isRef, unref, computed, reactive, toRefs as toRefs$1, readonly, toRef as toRef$1, nextTick, isReactive, shallowRef, watchEffect, isReadonly, markRaw } from "@reactive-vscode/reactivity";
|
|
1
|
+
import { ref, watch, customRef, getCurrentScope, onScopeDispose, effectScope, isRef, unref, toValue as toValue$1, computed, reactive, toRefs as toRefs$1, readonly, toRef as toRef$1, nextTick, isReactive, shallowRef, watchEffect, isReadonly, markRaw } from "@reactive-vscode/reactivity";
|
|
2
2
|
function computedWithControl(source, fn) {
|
|
3
3
|
let v = void 0;
|
|
4
4
|
let track;
|
|
@@ -44,6 +44,9 @@ function createEventHook() {
|
|
|
44
44
|
const off = (fn) => {
|
|
45
45
|
fns.delete(fn);
|
|
46
46
|
};
|
|
47
|
+
const clear = () => {
|
|
48
|
+
fns.clear();
|
|
49
|
+
};
|
|
47
50
|
const on = (fn) => {
|
|
48
51
|
fns.add(fn);
|
|
49
52
|
const offFn = () => off(fn);
|
|
@@ -58,7 +61,8 @@ function createEventHook() {
|
|
|
58
61
|
return {
|
|
59
62
|
on,
|
|
60
63
|
off,
|
|
61
|
-
trigger
|
|
64
|
+
trigger,
|
|
65
|
+
clear
|
|
62
66
|
};
|
|
63
67
|
}
|
|
64
68
|
function createGlobalState(stateFactory) {
|
|
@@ -143,12 +147,8 @@ function makeDestructurable(obj, arr) {
|
|
|
143
147
|
return Object.assign([...arr], obj);
|
|
144
148
|
}
|
|
145
149
|
}
|
|
146
|
-
function toValue(r) {
|
|
147
|
-
return typeof r === "function" ? r() : unref(r);
|
|
148
|
-
}
|
|
149
|
-
const resolveUnref = toValue;
|
|
150
150
|
function reactify(fn, options) {
|
|
151
|
-
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? unref : toValue;
|
|
151
|
+
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? unref : toValue$1;
|
|
152
152
|
return function(...args) {
|
|
153
153
|
return computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
|
|
154
154
|
};
|
|
@@ -213,7 +213,7 @@ function reactiveComputed(fn) {
|
|
|
213
213
|
function reactiveOmit(obj, ...keys) {
|
|
214
214
|
const flatKeys = keys.flat();
|
|
215
215
|
const predicate = flatKeys[0];
|
|
216
|
-
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]))));
|
|
216
|
+
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]))));
|
|
217
217
|
}
|
|
218
218
|
const isClient = typeof window !== "undefined" && typeof document !== "undefined";
|
|
219
219
|
const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
|
|
@@ -256,9 +256,10 @@ function debounceFilter(ms, options = {}) {
|
|
|
256
256
|
lastRejector();
|
|
257
257
|
lastRejector = noop;
|
|
258
258
|
};
|
|
259
|
+
let lastInvoker;
|
|
259
260
|
const filter = (invoke2) => {
|
|
260
|
-
const duration = toValue(ms);
|
|
261
|
-
const maxDuration = toValue(options.maxWait);
|
|
261
|
+
const duration = toValue$1(ms);
|
|
262
|
+
const maxDuration = toValue$1(options.maxWait);
|
|
262
263
|
if (timer)
|
|
263
264
|
_clearTimeout(timer);
|
|
264
265
|
if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
|
|
@@ -270,12 +271,13 @@ function debounceFilter(ms, options = {}) {
|
|
|
270
271
|
}
|
|
271
272
|
return new Promise((resolve, reject) => {
|
|
272
273
|
lastRejector = options.rejectOnCancel ? reject : resolve;
|
|
274
|
+
lastInvoker = invoke2;
|
|
273
275
|
if (maxDuration && !maxTimer) {
|
|
274
276
|
maxTimer = setTimeout(() => {
|
|
275
277
|
if (timer)
|
|
276
278
|
_clearTimeout(timer);
|
|
277
279
|
maxTimer = null;
|
|
278
|
-
resolve(
|
|
280
|
+
resolve(lastInvoker());
|
|
279
281
|
}, maxDuration);
|
|
280
282
|
}
|
|
281
283
|
timer = setTimeout(() => {
|
|
@@ -311,7 +313,7 @@ function throttleFilter(...args) {
|
|
|
311
313
|
}
|
|
312
314
|
};
|
|
313
315
|
const filter = (_invoke) => {
|
|
314
|
-
const duration = toValue(ms);
|
|
316
|
+
const duration = toValue$1(ms);
|
|
315
317
|
const elapsed = Date.now() - lastExec;
|
|
316
318
|
const invoke2 = () => {
|
|
317
319
|
return lastValue = _invoke();
|
|
@@ -432,6 +434,9 @@ function objectEntries(obj) {
|
|
|
432
434
|
function getLifeCycleTarget(target) {
|
|
433
435
|
return target || null;
|
|
434
436
|
}
|
|
437
|
+
function toArray(value) {
|
|
438
|
+
return Array.isArray(value) ? value : [value];
|
|
439
|
+
}
|
|
435
440
|
function toRef(...args) {
|
|
436
441
|
if (args.length !== 1)
|
|
437
442
|
return toRef$1(...args);
|
|
@@ -442,16 +447,16 @@ const resolveRef = toRef;
|
|
|
442
447
|
function reactivePick(obj, ...keys) {
|
|
443
448
|
const flatKeys = keys.flat();
|
|
444
449
|
const predicate = flatKeys[0];
|
|
445
|
-
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, toRef(obj, k)])));
|
|
450
|
+
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)])));
|
|
446
451
|
}
|
|
447
452
|
function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
448
453
|
return customRef((track, trigger) => {
|
|
449
|
-
let value = toValue(defaultValue);
|
|
454
|
+
let value = toValue$1(defaultValue);
|
|
450
455
|
let timer;
|
|
451
456
|
const resetAfter = () => setTimeout(() => {
|
|
452
|
-
value = toValue(defaultValue);
|
|
457
|
+
value = toValue$1(defaultValue);
|
|
453
458
|
trigger();
|
|
454
|
-
}, toValue(afterMs));
|
|
459
|
+
}, toValue$1(afterMs));
|
|
455
460
|
tryOnScopeDispose(() => {
|
|
456
461
|
clearTimeout(timer);
|
|
457
462
|
});
|
|
@@ -645,8 +650,7 @@ function syncRefs(source, targets, options = {}) {
|
|
|
645
650
|
deep = false,
|
|
646
651
|
immediate = true
|
|
647
652
|
} = options;
|
|
648
|
-
|
|
649
|
-
targets = [targets];
|
|
653
|
+
targets = toArray(targets);
|
|
650
654
|
return watch(
|
|
651
655
|
source,
|
|
652
656
|
(newValue) => targets.forEach((target) => target.value = newValue),
|
|
@@ -664,7 +668,7 @@ function toRefs(objectRef, options = {}) {
|
|
|
664
668
|
},
|
|
665
669
|
set(v) {
|
|
666
670
|
var _a;
|
|
667
|
-
const replaceRef = (_a = toValue(options.replaceRef)) != null ? _a : true;
|
|
671
|
+
const replaceRef = (_a = toValue$1(options.replaceRef)) != null ? _a : true;
|
|
668
672
|
if (replaceRef) {
|
|
669
673
|
if (Array.isArray(objectRef.value)) {
|
|
670
674
|
const copy = [...objectRef.value];
|
|
@@ -683,6 +687,8 @@ function toRefs(objectRef, options = {}) {
|
|
|
683
687
|
}
|
|
684
688
|
return result;
|
|
685
689
|
}
|
|
690
|
+
const toValue = toValue$1;
|
|
691
|
+
const resolveUnref = toValue$1;
|
|
686
692
|
function tryOnMounted(fn, sync = true, target) {
|
|
687
693
|
if (sync)
|
|
688
694
|
fn();
|
|
@@ -714,7 +720,7 @@ function createUntil(r, isNot = false) {
|
|
|
714
720
|
const promises = [watcher];
|
|
715
721
|
if (timeout != null) {
|
|
716
722
|
promises.push(
|
|
717
|
-
promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => stop == null ? void 0 : stop())
|
|
723
|
+
promiseTimeout(timeout, throwOnTimeout).then(() => toValue$1(r)).finally(() => stop == null ? void 0 : stop())
|
|
718
724
|
);
|
|
719
725
|
}
|
|
720
726
|
return Promise.race(promises);
|
|
@@ -746,9 +752,9 @@ function createUntil(r, isNot = false) {
|
|
|
746
752
|
const promises = [watcher];
|
|
747
753
|
if (timeout != null) {
|
|
748
754
|
promises.push(
|
|
749
|
-
promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => {
|
|
755
|
+
promiseTimeout(timeout, throwOnTimeout).then(() => toValue$1(r)).finally(() => {
|
|
750
756
|
stop == null ? void 0 : stop();
|
|
751
|
-
return toValue(r);
|
|
757
|
+
return toValue$1(r);
|
|
752
758
|
})
|
|
753
759
|
);
|
|
754
760
|
}
|
|
@@ -769,7 +775,7 @@ function createUntil(r, isNot = false) {
|
|
|
769
775
|
function toContains(value, options) {
|
|
770
776
|
return toMatch((v) => {
|
|
771
777
|
const array = Array.from(v);
|
|
772
|
-
return array.includes(value) || array.includes(toValue(value));
|
|
778
|
+
return array.includes(value) || array.includes(toValue$1(value));
|
|
773
779
|
}, options);
|
|
774
780
|
}
|
|
775
781
|
function changed(options) {
|
|
@@ -782,7 +788,7 @@ function createUntil(r, isNot = false) {
|
|
|
782
788
|
return count >= n;
|
|
783
789
|
}, options);
|
|
784
790
|
}
|
|
785
|
-
if (Array.isArray(toValue(r))) {
|
|
791
|
+
if (Array.isArray(toValue$1(r))) {
|
|
786
792
|
const instance = {
|
|
787
793
|
toMatch,
|
|
788
794
|
toContains,
|
|
@@ -817,29 +823,38 @@ function defaultComparator(value, othVal) {
|
|
|
817
823
|
return value === othVal;
|
|
818
824
|
}
|
|
819
825
|
function useArrayDifference(...args) {
|
|
820
|
-
var _a;
|
|
826
|
+
var _a, _b;
|
|
821
827
|
const list = args[0];
|
|
822
828
|
const values = args[1];
|
|
823
829
|
let compareFn = (_a = args[2]) != null ? _a : defaultComparator;
|
|
830
|
+
const {
|
|
831
|
+
symmetric = false
|
|
832
|
+
} = (_b = args[3]) != null ? _b : {};
|
|
824
833
|
if (typeof compareFn === "string") {
|
|
825
834
|
const key = compareFn;
|
|
826
835
|
compareFn = (value, othVal) => value[key] === othVal[key];
|
|
827
836
|
}
|
|
828
|
-
|
|
837
|
+
const diff1 = computed(() => toValue$1(list).filter((x) => toValue$1(values).findIndex((y) => compareFn(x, y)) === -1));
|
|
838
|
+
if (symmetric) {
|
|
839
|
+
const diff2 = computed(() => toValue$1(values).filter((x) => toValue$1(list).findIndex((y) => compareFn(x, y)) === -1));
|
|
840
|
+
return computed(() => symmetric ? [...toValue$1(diff1), ...toValue$1(diff2)] : toValue$1(diff1));
|
|
841
|
+
} else {
|
|
842
|
+
return diff1;
|
|
843
|
+
}
|
|
829
844
|
}
|
|
830
845
|
function useArrayEvery(list, fn) {
|
|
831
|
-
return computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
|
|
846
|
+
return computed(() => toValue$1(list).every((element, index, array) => fn(toValue$1(element), index, array)));
|
|
832
847
|
}
|
|
833
848
|
function useArrayFilter(list, fn) {
|
|
834
|
-
return computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
|
|
849
|
+
return computed(() => toValue$1(list).map((i) => toValue$1(i)).filter(fn));
|
|
835
850
|
}
|
|
836
851
|
function useArrayFind(list, fn) {
|
|
837
|
-
return computed(() => toValue(
|
|
838
|
-
toValue(list).find((element, index, array) => fn(toValue(element), index, array))
|
|
852
|
+
return computed(() => toValue$1(
|
|
853
|
+
toValue$1(list).find((element, index, array) => fn(toValue$1(element), index, array))
|
|
839
854
|
));
|
|
840
855
|
}
|
|
841
856
|
function useArrayFindIndex(list, fn) {
|
|
842
|
-
return computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
|
|
857
|
+
return computed(() => toValue$1(list).findIndex((element, index, array) => fn(toValue$1(element), index, array)));
|
|
843
858
|
}
|
|
844
859
|
function findLast(arr, cb) {
|
|
845
860
|
let index = arr.length;
|
|
@@ -850,8 +865,8 @@ function findLast(arr, cb) {
|
|
|
850
865
|
return void 0;
|
|
851
866
|
}
|
|
852
867
|
function useArrayFindLast(list, fn) {
|
|
853
|
-
return computed(() => toValue(
|
|
854
|
-
!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))
|
|
868
|
+
return computed(() => toValue$1(
|
|
869
|
+
!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))
|
|
855
870
|
));
|
|
856
871
|
}
|
|
857
872
|
function isArrayIncludesOptions(obj) {
|
|
@@ -869,31 +884,31 @@ function useArrayIncludes(...args) {
|
|
|
869
884
|
}
|
|
870
885
|
if (typeof comparator === "string") {
|
|
871
886
|
const key = comparator;
|
|
872
|
-
comparator = (element, value2) => element[key] === toValue(value2);
|
|
887
|
+
comparator = (element, value2) => element[key] === toValue$1(value2);
|
|
873
888
|
}
|
|
874
|
-
comparator = comparator != null ? comparator : (element, value2) => element === toValue(value2);
|
|
875
|
-
return computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(
|
|
876
|
-
toValue(element),
|
|
877
|
-
toValue(value),
|
|
889
|
+
comparator = comparator != null ? comparator : (element, value2) => element === toValue$1(value2);
|
|
890
|
+
return computed(() => toValue$1(list).slice(formIndex).some((element, index, array) => comparator(
|
|
891
|
+
toValue$1(element),
|
|
892
|
+
toValue$1(value),
|
|
878
893
|
index,
|
|
879
|
-
toValue(array)
|
|
894
|
+
toValue$1(array)
|
|
880
895
|
)));
|
|
881
896
|
}
|
|
882
897
|
function useArrayJoin(list, separator) {
|
|
883
|
-
return computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
|
|
898
|
+
return computed(() => toValue$1(list).map((i) => toValue$1(i)).join(toValue$1(separator)));
|
|
884
899
|
}
|
|
885
900
|
function useArrayMap(list, fn) {
|
|
886
|
-
return computed(() => toValue(list).map((i) => toValue(i)).map(fn));
|
|
901
|
+
return computed(() => toValue$1(list).map((i) => toValue$1(i)).map(fn));
|
|
887
902
|
}
|
|
888
903
|
function useArrayReduce(list, reducer, ...args) {
|
|
889
|
-
const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
|
|
904
|
+
const reduceCallback = (sum, value, index) => reducer(toValue$1(sum), toValue$1(value), index);
|
|
890
905
|
return computed(() => {
|
|
891
|
-
const resolved = toValue(list);
|
|
892
|
-
return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue(args[0]()) : toValue(args[0])) : resolved.reduce(reduceCallback);
|
|
906
|
+
const resolved = toValue$1(list);
|
|
907
|
+
return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue$1(args[0]()) : toValue$1(args[0])) : resolved.reduce(reduceCallback);
|
|
893
908
|
});
|
|
894
909
|
}
|
|
895
910
|
function useArraySome(list, fn) {
|
|
896
|
-
return computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
|
|
911
|
+
return computed(() => toValue$1(list).some((element, index, array) => fn(toValue$1(element), index, array)));
|
|
897
912
|
}
|
|
898
913
|
function uniq(array) {
|
|
899
914
|
return Array.from(new Set(array));
|
|
@@ -907,7 +922,7 @@ function uniqueElementsBy(array, fn) {
|
|
|
907
922
|
}
|
|
908
923
|
function useArrayUnique(list, compareFn) {
|
|
909
924
|
return computed(() => {
|
|
910
|
-
const resolvedList = toValue(list).map((element) => toValue(element));
|
|
925
|
+
const resolvedList = toValue$1(list).map((element) => toValue$1(element));
|
|
911
926
|
return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
|
|
912
927
|
});
|
|
913
928
|
}
|
|
@@ -959,8 +974,8 @@ function formatDate(date, formatStr, options = {}) {
|
|
|
959
974
|
M: () => month + 1,
|
|
960
975
|
Mo: () => formatOrdinal(month + 1),
|
|
961
976
|
MM: () => `${month + 1}`.padStart(2, "0"),
|
|
962
|
-
MMM: () => date.toLocaleDateString(toValue(options.locales), { month: "short" }),
|
|
963
|
-
MMMM: () => date.toLocaleDateString(toValue(options.locales), { month: "long" }),
|
|
977
|
+
MMM: () => date.toLocaleDateString(toValue$1(options.locales), { month: "short" }),
|
|
978
|
+
MMMM: () => date.toLocaleDateString(toValue$1(options.locales), { month: "long" }),
|
|
964
979
|
D: () => String(days),
|
|
965
980
|
Do: () => formatOrdinal(days),
|
|
966
981
|
DD: () => `${days}`.padStart(2, "0"),
|
|
@@ -978,9 +993,9 @@ function formatDate(date, formatStr, options = {}) {
|
|
|
978
993
|
ss: () => `${seconds}`.padStart(2, "0"),
|
|
979
994
|
SSS: () => `${milliseconds}`.padStart(3, "0"),
|
|
980
995
|
d: () => day,
|
|
981
|
-
dd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "narrow" }),
|
|
982
|
-
ddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "short" }),
|
|
983
|
-
dddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "long" }),
|
|
996
|
+
dd: () => date.toLocaleDateString(toValue$1(options.locales), { weekday: "narrow" }),
|
|
997
|
+
ddd: () => date.toLocaleDateString(toValue$1(options.locales), { weekday: "short" }),
|
|
998
|
+
dddd: () => date.toLocaleDateString(toValue$1(options.locales), { weekday: "long" }),
|
|
984
999
|
A: () => meridiem(hours, minutes),
|
|
985
1000
|
AA: () => meridiem(hours, minutes, false, true),
|
|
986
1001
|
a: () => meridiem(hours, minutes, true),
|
|
@@ -1009,7 +1024,7 @@ function normalizeDate(date) {
|
|
|
1009
1024
|
return new Date(date);
|
|
1010
1025
|
}
|
|
1011
1026
|
function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
|
|
1012
|
-
return computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
|
|
1027
|
+
return computed(() => formatDate(normalizeDate(toValue$1(date)), toValue$1(formatStr), options));
|
|
1013
1028
|
}
|
|
1014
1029
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
1015
1030
|
const {
|
|
@@ -1029,7 +1044,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
1029
1044
|
clean();
|
|
1030
1045
|
}
|
|
1031
1046
|
function resume() {
|
|
1032
|
-
const intervalValue = toValue(interval);
|
|
1047
|
+
const intervalValue = toValue$1(interval);
|
|
1033
1048
|
if (intervalValue <= 0)
|
|
1034
1049
|
return;
|
|
1035
1050
|
isActive.value = true;
|
|
@@ -1117,7 +1132,7 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1117
1132
|
isPending.value = false;
|
|
1118
1133
|
timer = null;
|
|
1119
1134
|
cb(...args);
|
|
1120
|
-
}, toValue(interval));
|
|
1135
|
+
}, toValue$1(interval));
|
|
1121
1136
|
}
|
|
1122
1137
|
if (immediate) {
|
|
1123
1138
|
isPending.value = true;
|
|
@@ -1158,8 +1173,10 @@ function useToNumber(value, options = {}) {
|
|
|
1158
1173
|
nanToZero
|
|
1159
1174
|
} = options;
|
|
1160
1175
|
return computed(() => {
|
|
1161
|
-
let resolved = toValue(value);
|
|
1162
|
-
if (typeof
|
|
1176
|
+
let resolved = toValue$1(value);
|
|
1177
|
+
if (typeof method === "function")
|
|
1178
|
+
resolved = method(resolved);
|
|
1179
|
+
else if (typeof resolved === "string")
|
|
1163
1180
|
resolved = Number[method](resolved, radix);
|
|
1164
1181
|
if (nanToZero && Number.isNaN(resolved))
|
|
1165
1182
|
resolved = 0;
|
|
@@ -1167,7 +1184,7 @@ function useToNumber(value, options = {}) {
|
|
|
1167
1184
|
});
|
|
1168
1185
|
}
|
|
1169
1186
|
function useToString(value) {
|
|
1170
|
-
return computed(() => `${toValue(value)}`);
|
|
1187
|
+
return computed(() => `${toValue$1(value)}`);
|
|
1171
1188
|
}
|
|
1172
1189
|
function useToggle(initialValue = false, options = {}) {
|
|
1173
1190
|
const {
|
|
@@ -1181,8 +1198,8 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1181
1198
|
_value.value = value;
|
|
1182
1199
|
return _value.value;
|
|
1183
1200
|
} else {
|
|
1184
|
-
const truthy = toValue(truthyValue);
|
|
1185
|
-
_value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
|
|
1201
|
+
const truthy = toValue$1(truthyValue);
|
|
1202
|
+
_value.value = _value.value === truthy ? toValue$1(falsyValue) : truthy;
|
|
1186
1203
|
return _value.value;
|
|
1187
1204
|
}
|
|
1188
1205
|
}
|
|
@@ -1192,7 +1209,7 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1192
1209
|
return [_value, toggle];
|
|
1193
1210
|
}
|
|
1194
1211
|
function watchArray(source, cb, options) {
|
|
1195
|
-
let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)];
|
|
1212
|
+
let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue$1(source)];
|
|
1196
1213
|
return watch(source, (newList, _, onCleanup) => {
|
|
1197
1214
|
const oldListRemains = Array.from({ length: oldList.length });
|
|
1198
1215
|
const added = [];
|
|
@@ -1223,7 +1240,7 @@ function watchAtMost(source, cb, options) {
|
|
|
1223
1240
|
source,
|
|
1224
1241
|
(...args) => {
|
|
1225
1242
|
current.value += 1;
|
|
1226
|
-
if (current.value >= toValue(count))
|
|
1243
|
+
if (current.value >= toValue$1(count))
|
|
1227
1244
|
nextTick(() => stop());
|
|
1228
1245
|
cb(...args);
|
|
1229
1246
|
},
|
|
@@ -1393,8 +1410,8 @@ function getWatchSources(sources) {
|
|
|
1393
1410
|
if (isReactive(sources))
|
|
1394
1411
|
return sources;
|
|
1395
1412
|
if (Array.isArray(sources))
|
|
1396
|
-
return sources.map((item) => toValue(item));
|
|
1397
|
-
return toValue(sources);
|
|
1413
|
+
return sources.map((item) => toValue$1(item));
|
|
1414
|
+
return toValue$1(sources);
|
|
1398
1415
|
}
|
|
1399
1416
|
function getOldValue(source) {
|
|
1400
1417
|
return Array.isArray(source) ? source.map(() => void 0) : void 0;
|
|
@@ -1475,61 +1492,60 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
|
|
|
1475
1492
|
}
|
|
1476
1493
|
function createUnrefFn(fn) {
|
|
1477
1494
|
return function(...args) {
|
|
1478
|
-
return fn.apply(this, args.map((i) => toValue(i)));
|
|
1495
|
+
return fn.apply(this, args.map((i) => toValue$1(i)));
|
|
1479
1496
|
};
|
|
1480
1497
|
}
|
|
1481
1498
|
const defaultWindow = isClient ? window : void 0;
|
|
1482
1499
|
function unrefElement(elRef) {
|
|
1483
1500
|
var _a;
|
|
1484
|
-
const plain = toValue(elRef);
|
|
1501
|
+
const plain = toValue$1(elRef);
|
|
1485
1502
|
return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
|
|
1486
1503
|
}
|
|
1487
1504
|
function useEventListener(...args) {
|
|
1488
|
-
let target;
|
|
1489
|
-
let events2;
|
|
1490
|
-
let listeners;
|
|
1491
|
-
let options;
|
|
1492
|
-
if (typeof args[0] === "string" || Array.isArray(args[0])) {
|
|
1493
|
-
[events2, listeners, options] = args;
|
|
1494
|
-
target = defaultWindow;
|
|
1495
|
-
} else {
|
|
1496
|
-
[target, events2, listeners, options] = args;
|
|
1497
|
-
}
|
|
1498
|
-
if (!target)
|
|
1499
|
-
return noop;
|
|
1500
|
-
if (!Array.isArray(events2))
|
|
1501
|
-
events2 = [events2];
|
|
1502
|
-
if (!Array.isArray(listeners))
|
|
1503
|
-
listeners = [listeners];
|
|
1504
1505
|
const cleanups = [];
|
|
1505
1506
|
const cleanup = () => {
|
|
1506
1507
|
cleanups.forEach((fn) => fn());
|
|
1507
1508
|
cleanups.length = 0;
|
|
1508
1509
|
};
|
|
1509
|
-
const register = (el, event, listener,
|
|
1510
|
-
el.addEventListener(event, listener,
|
|
1511
|
-
return () => el.removeEventListener(event, listener,
|
|
1510
|
+
const register = (el, event, listener, options) => {
|
|
1511
|
+
el.addEventListener(event, listener, options);
|
|
1512
|
+
return () => el.removeEventListener(event, listener, options);
|
|
1512
1513
|
};
|
|
1513
|
-
const
|
|
1514
|
-
|
|
1515
|
-
(
|
|
1514
|
+
const firstParamTargets = computed(() => {
|
|
1515
|
+
const test = toArray(toValue$1(args[0])).filter((e) => e != null);
|
|
1516
|
+
return test.every((e) => typeof e !== "string") ? test : void 0;
|
|
1517
|
+
});
|
|
1518
|
+
const stopWatch = watchImmediate(
|
|
1519
|
+
() => {
|
|
1520
|
+
var _a, _b;
|
|
1521
|
+
return [
|
|
1522
|
+
(_b = (_a = firstParamTargets.value) == null ? void 0 : _a.map((e) => unrefElement(e))) != null ? _b : [defaultWindow].filter((e) => e != null),
|
|
1523
|
+
toArray(toValue$1(firstParamTargets.value ? args[1] : args[0])),
|
|
1524
|
+
toArray(unref(firstParamTargets.value ? args[2] : args[1])),
|
|
1525
|
+
// @ts-expect-error - TypeScript gets the correct types, but somehow still complains
|
|
1526
|
+
toValue$1(firstParamTargets.value ? args[3] : args[2])
|
|
1527
|
+
];
|
|
1528
|
+
},
|
|
1529
|
+
([raw_targets, raw_events, raw_listeners, raw_options]) => {
|
|
1516
1530
|
cleanup();
|
|
1517
|
-
if (!
|
|
1531
|
+
if (!(raw_targets == null ? void 0 : raw_targets.length) || !(raw_events == null ? void 0 : raw_events.length) || !(raw_listeners == null ? void 0 : raw_listeners.length))
|
|
1518
1532
|
return;
|
|
1519
|
-
const optionsClone = isObject(
|
|
1533
|
+
const optionsClone = isObject(raw_options) ? { ...raw_options } : raw_options;
|
|
1520
1534
|
cleanups.push(
|
|
1521
|
-
...
|
|
1522
|
-
|
|
1523
|
-
|
|
1535
|
+
...raw_targets.flatMap(
|
|
1536
|
+
(el) => raw_events.flatMap(
|
|
1537
|
+
(event) => raw_listeners.map((listener) => register(el, event, listener, optionsClone))
|
|
1538
|
+
)
|
|
1539
|
+
)
|
|
1524
1540
|
);
|
|
1525
1541
|
},
|
|
1526
|
-
{
|
|
1542
|
+
{ flush: "post" }
|
|
1527
1543
|
);
|
|
1528
1544
|
const stop = () => {
|
|
1529
1545
|
stopWatch();
|
|
1530
1546
|
cleanup();
|
|
1531
1547
|
};
|
|
1532
|
-
tryOnScopeDispose(
|
|
1548
|
+
tryOnScopeDispose(cleanup);
|
|
1533
1549
|
return stop;
|
|
1534
1550
|
}
|
|
1535
1551
|
function useMounted() {
|
|
@@ -1550,7 +1566,9 @@ function useRafFn(fn, options = {}) {
|
|
|
1550
1566
|
window: window2 = defaultWindow
|
|
1551
1567
|
} = options;
|
|
1552
1568
|
const isActive = ref(false);
|
|
1553
|
-
const intervalLimit =
|
|
1569
|
+
const intervalLimit = computed(() => {
|
|
1570
|
+
return fpsLimit ? 1e3 / toValue$1(fpsLimit) : null;
|
|
1571
|
+
});
|
|
1554
1572
|
let previousFrameTimestamp = 0;
|
|
1555
1573
|
let rafId = null;
|
|
1556
1574
|
function loop(timestamp2) {
|
|
@@ -1559,7 +1577,7 @@ function useRafFn(fn, options = {}) {
|
|
|
1559
1577
|
if (!previousFrameTimestamp)
|
|
1560
1578
|
previousFrameTimestamp = timestamp2;
|
|
1561
1579
|
const delta = timestamp2 - previousFrameTimestamp;
|
|
1562
|
-
if (intervalLimit && delta < intervalLimit) {
|
|
1580
|
+
if (intervalLimit.value && delta < intervalLimit.value) {
|
|
1563
1581
|
rafId = window2.requestAnimationFrame(loop);
|
|
1564
1582
|
return;
|
|
1565
1583
|
}
|
|
@@ -1700,8 +1718,9 @@ function useAsyncState(promise, initialState, options) {
|
|
|
1700
1718
|
}
|
|
1701
1719
|
return state.value;
|
|
1702
1720
|
}
|
|
1703
|
-
if (immediate)
|
|
1721
|
+
if (immediate) {
|
|
1704
1722
|
execute(delay);
|
|
1723
|
+
}
|
|
1705
1724
|
const shell = {
|
|
1706
1725
|
state,
|
|
1707
1726
|
isReady,
|
|
@@ -1748,7 +1767,7 @@ function useBase64(target, options) {
|
|
|
1748
1767
|
return;
|
|
1749
1768
|
promise.value = new Promise((resolve, reject) => {
|
|
1750
1769
|
try {
|
|
1751
|
-
const _target = toValue(target);
|
|
1770
|
+
const _target = toValue$1(target);
|
|
1752
1771
|
if (_target == null) {
|
|
1753
1772
|
resolve("");
|
|
1754
1773
|
} else if (typeof _target === "string") {
|
|
@@ -1781,7 +1800,9 @@ function useBase64(target, options) {
|
|
|
1781
1800
|
reject(error);
|
|
1782
1801
|
}
|
|
1783
1802
|
});
|
|
1784
|
-
promise.value.then((res) =>
|
|
1803
|
+
promise.value.then((res) => {
|
|
1804
|
+
base64.value = (options == null ? void 0 : options.dataUrl) === false ? res.replace(/^data:.*?;base64,/, "") : res;
|
|
1805
|
+
});
|
|
1785
1806
|
return promise.value;
|
|
1786
1807
|
}
|
|
1787
1808
|
if (isRef(target) || typeof target === "function")
|
|
@@ -1839,15 +1860,18 @@ function useBroadcastChannel(options) {
|
|
|
1839
1860
|
tryOnMounted(() => {
|
|
1840
1861
|
error.value = null;
|
|
1841
1862
|
channel.value = new BroadcastChannel(name);
|
|
1842
|
-
|
|
1863
|
+
const listenerOptions = {
|
|
1864
|
+
passive: true
|
|
1865
|
+
};
|
|
1866
|
+
useEventListener(channel, "message", (e) => {
|
|
1843
1867
|
data.value = e.data;
|
|
1844
|
-
},
|
|
1845
|
-
channel
|
|
1868
|
+
}, listenerOptions);
|
|
1869
|
+
useEventListener(channel, "messageerror", (e) => {
|
|
1846
1870
|
error.value = e;
|
|
1847
|
-
},
|
|
1848
|
-
channel
|
|
1871
|
+
}, listenerOptions);
|
|
1872
|
+
useEventListener(channel, "close", () => {
|
|
1849
1873
|
isClosed.value = true;
|
|
1850
|
-
});
|
|
1874
|
+
}, listenerOptions);
|
|
1851
1875
|
});
|
|
1852
1876
|
}
|
|
1853
1877
|
tryOnScopeDispose(() => {
|
|
@@ -1876,6 +1900,8 @@ function cloneFnJSON(source) {
|
|
|
1876
1900
|
}
|
|
1877
1901
|
function useCloned(source, options = {}) {
|
|
1878
1902
|
const cloned = ref({});
|
|
1903
|
+
const isModified = ref(false);
|
|
1904
|
+
let _lastSync = false;
|
|
1879
1905
|
const {
|
|
1880
1906
|
manual,
|
|
1881
1907
|
clone = cloneFnJSON,
|
|
@@ -1883,8 +1909,20 @@ function useCloned(source, options = {}) {
|
|
|
1883
1909
|
deep = true,
|
|
1884
1910
|
immediate = true
|
|
1885
1911
|
} = options;
|
|
1912
|
+
watch(cloned, () => {
|
|
1913
|
+
if (_lastSync) {
|
|
1914
|
+
_lastSync = false;
|
|
1915
|
+
return;
|
|
1916
|
+
}
|
|
1917
|
+
isModified.value = true;
|
|
1918
|
+
}, {
|
|
1919
|
+
deep: true,
|
|
1920
|
+
flush: "sync"
|
|
1921
|
+
});
|
|
1886
1922
|
function sync() {
|
|
1887
|
-
|
|
1923
|
+
_lastSync = true;
|
|
1924
|
+
isModified.value = false;
|
|
1925
|
+
cloned.value = clone(toValue$1(source));
|
|
1888
1926
|
}
|
|
1889
1927
|
if (!manual && (isRef(source) || typeof source === "function")) {
|
|
1890
1928
|
watch(source, sync, {
|
|
@@ -1895,7 +1933,7 @@ function useCloned(source, options = {}) {
|
|
|
1895
1933
|
} else {
|
|
1896
1934
|
sync();
|
|
1897
1935
|
}
|
|
1898
|
-
return { cloned, sync };
|
|
1936
|
+
return { cloned, isModified, sync };
|
|
1899
1937
|
}
|
|
1900
1938
|
function useCycleList(list, options) {
|
|
1901
1939
|
const state = shallowRef(getInitialValue());
|
|
@@ -1932,7 +1970,7 @@ function useCycleList(list, options) {
|
|
|
1932
1970
|
}
|
|
1933
1971
|
function getInitialValue() {
|
|
1934
1972
|
var _a, _b;
|
|
1935
|
-
return (_b = toValue((_a = options == null ? void 0 : options.initialValue) != null ? _a : toValue(list)[0])) != null ? _b : void 0;
|
|
1973
|
+
return (_b = toValue$1((_a = options == null ? void 0 : options.initialValue) != null ? _a : toValue$1(list)[0])) != null ? _b : void 0;
|
|
1936
1974
|
}
|
|
1937
1975
|
watch(listRef, () => set2(index.value));
|
|
1938
1976
|
return {
|
|
@@ -2166,8 +2204,8 @@ function createFetch(config = {}) {
|
|
|
2166
2204
|
const _fetchOptions = config.fetchOptions || {};
|
|
2167
2205
|
function useFactoryFetch(url, ...args) {
|
|
2168
2206
|
const computedUrl = computed(() => {
|
|
2169
|
-
const baseUrl = toValue(config.baseUrl);
|
|
2170
|
-
const targetUrl = toValue(url);
|
|
2207
|
+
const baseUrl = toValue$1(config.baseUrl);
|
|
2208
|
+
const targetUrl = toValue$1(url);
|
|
2171
2209
|
return baseUrl && !isAbsoluteURL(targetUrl) ? joinPaths(baseUrl, targetUrl) : targetUrl;
|
|
2172
2210
|
});
|
|
2173
2211
|
let options = _options;
|
|
@@ -2279,9 +2317,9 @@ function useFetch(url, ...args) {
|
|
|
2279
2317
|
method: config.method,
|
|
2280
2318
|
headers: {}
|
|
2281
2319
|
};
|
|
2282
|
-
|
|
2320
|
+
const payload = toValue$1(config.payload);
|
|
2321
|
+
if (payload) {
|
|
2283
2322
|
const headers = headersToObject(defaultFetchOptions.headers);
|
|
2284
|
-
const payload = toValue(config.payload);
|
|
2285
2323
|
const proto = Object.getPrototypeOf(payload);
|
|
2286
2324
|
if (!config.payloadType && payload && (proto === Object.prototype || Array.isArray(proto)) && !(payload instanceof FormData))
|
|
2287
2325
|
config.payloadType = "json";
|
|
@@ -2291,7 +2329,7 @@ function useFetch(url, ...args) {
|
|
|
2291
2329
|
}
|
|
2292
2330
|
let isCanceled = false;
|
|
2293
2331
|
const context = {
|
|
2294
|
-
url: toValue(url),
|
|
2332
|
+
url: toValue$1(url),
|
|
2295
2333
|
options: {
|
|
2296
2334
|
...defaultFetchOptions,
|
|
2297
2335
|
...fetchOptions
|
|
@@ -2330,7 +2368,9 @@ function useFetch(url, ...args) {
|
|
|
2330
2368
|
if (options.afterFetch) {
|
|
2331
2369
|
({ data: responseData } = await options.afterFetch({
|
|
2332
2370
|
data: responseData,
|
|
2333
|
-
response: fetchResponse
|
|
2371
|
+
response: fetchResponse,
|
|
2372
|
+
context,
|
|
2373
|
+
execute
|
|
2334
2374
|
}));
|
|
2335
2375
|
}
|
|
2336
2376
|
data.value = responseData;
|
|
@@ -2342,7 +2382,9 @@ function useFetch(url, ...args) {
|
|
|
2342
2382
|
({ error: errorData, data: responseData } = await options.onFetchError({
|
|
2343
2383
|
data: responseData,
|
|
2344
2384
|
error: fetchError,
|
|
2345
|
-
response: response.value
|
|
2385
|
+
response: response.value,
|
|
2386
|
+
context,
|
|
2387
|
+
execute
|
|
2346
2388
|
}));
|
|
2347
2389
|
}
|
|
2348
2390
|
error.value = errorData;
|
|
@@ -2488,13 +2530,14 @@ function useIdle(timeout = oneMinute, options = {}) {
|
|
|
2488
2530
|
);
|
|
2489
2531
|
if (window2) {
|
|
2490
2532
|
const document2 = window2.document;
|
|
2533
|
+
const listenerOptions = { passive: true };
|
|
2491
2534
|
for (const event of events2)
|
|
2492
|
-
useEventListener(window2, event, onEvent,
|
|
2535
|
+
useEventListener(window2, event, onEvent, listenerOptions);
|
|
2493
2536
|
if (listenForVisibilityChange) {
|
|
2494
2537
|
useEventListener(document2, "visibilitychange", () => {
|
|
2495
2538
|
if (!document2.hidden)
|
|
2496
2539
|
onEvent();
|
|
2497
|
-
});
|
|
2540
|
+
}, listenerOptions);
|
|
2498
2541
|
}
|
|
2499
2542
|
reset();
|
|
2500
2543
|
}
|
|
@@ -2529,7 +2572,7 @@ function useObjectUrl(object) {
|
|
|
2529
2572
|
url.value = void 0;
|
|
2530
2573
|
};
|
|
2531
2574
|
watch(
|
|
2532
|
-
() => toValue(object),
|
|
2575
|
+
() => toValue$1(object),
|
|
2533
2576
|
(newObject) => {
|
|
2534
2577
|
release();
|
|
2535
2578
|
if (newObject)
|
|
@@ -2542,14 +2585,14 @@ function useObjectUrl(object) {
|
|
|
2542
2585
|
}
|
|
2543
2586
|
function useClamp(value, min, max) {
|
|
2544
2587
|
if (typeof value === "function" || isReadonly(value))
|
|
2545
|
-
return computed(() => clamp(toValue(value), toValue(min), toValue(max)));
|
|
2588
|
+
return computed(() => clamp(toValue$1(value), toValue$1(min), toValue$1(max)));
|
|
2546
2589
|
const _value = ref(value);
|
|
2547
2590
|
return computed({
|
|
2548
2591
|
get() {
|
|
2549
|
-
return _value.value = clamp(_value.value, toValue(min), toValue(max));
|
|
2592
|
+
return _value.value = clamp(_value.value, toValue$1(min), toValue$1(max));
|
|
2550
2593
|
},
|
|
2551
2594
|
set(value2) {
|
|
2552
|
-
_value.value = clamp(value2, toValue(min), toValue(max));
|
|
2595
|
+
_value.value = clamp(value2, toValue$1(min), toValue$1(max));
|
|
2553
2596
|
}
|
|
2554
2597
|
});
|
|
2555
2598
|
}
|
|
@@ -2565,7 +2608,7 @@ function useOffsetPagination(options) {
|
|
|
2565
2608
|
const currentPageSize = useClamp(pageSize, 1, Number.POSITIVE_INFINITY);
|
|
2566
2609
|
const pageCount = computed(() => Math.max(
|
|
2567
2610
|
1,
|
|
2568
|
-
Math.ceil(toValue(total) / toValue(currentPageSize))
|
|
2611
|
+
Math.ceil(toValue$1(total) / toValue$1(currentPageSize))
|
|
2569
2612
|
));
|
|
2570
2613
|
const currentPage = useClamp(page, 1, pageCount);
|
|
2571
2614
|
const isFirstPage = computed(() => currentPage.value === 1);
|
|
@@ -2640,9 +2683,9 @@ function useSorted(...args) {
|
|
|
2640
2683
|
sortFn = defaultSortFn
|
|
2641
2684
|
} = options;
|
|
2642
2685
|
if (!dirty)
|
|
2643
|
-
return computed(() => sortFn([...toValue(source)], compareFn));
|
|
2686
|
+
return computed(() => sortFn([...toValue$1(source)], compareFn));
|
|
2644
2687
|
watchEffect(() => {
|
|
2645
|
-
const result = sortFn(toValue(source), compareFn);
|
|
2688
|
+
const result = sortFn(toValue$1(source), compareFn);
|
|
2646
2689
|
if (isRef(source))
|
|
2647
2690
|
source.value = result;
|
|
2648
2691
|
else
|
|
@@ -2763,7 +2806,7 @@ function useTimeAgo(time, options = {}) {
|
|
|
2763
2806
|
updateInterval = 3e4
|
|
2764
2807
|
} = options;
|
|
2765
2808
|
const { now: now2, ...controls } = useNow({ interval: updateInterval, controls: true });
|
|
2766
|
-
const timeAgo = computed(() => formatTimeAgo(new Date(toValue(time)), options, toValue(now2)));
|
|
2809
|
+
const timeAgo = computed(() => formatTimeAgo(new Date(toValue$1(time)), options, toValue$1(now2)));
|
|
2767
2810
|
if (exposeControls) {
|
|
2768
2811
|
return {
|
|
2769
2812
|
timeAgo,
|
|
@@ -2819,7 +2862,10 @@ function formatTimeAgo(from, options = {}, now2 = Date.now()) {
|
|
|
2819
2862
|
}
|
|
2820
2863
|
return messages.invalid;
|
|
2821
2864
|
}
|
|
2822
|
-
function useTimeoutPoll(fn, interval,
|
|
2865
|
+
function useTimeoutPoll(fn, interval, options = {}) {
|
|
2866
|
+
const {
|
|
2867
|
+
immediate = true
|
|
2868
|
+
} = options;
|
|
2823
2869
|
const { start } = useTimeoutFn(loop, interval, { immediate: false });
|
|
2824
2870
|
const isActive = ref(false);
|
|
2825
2871
|
async function loop() {
|
|
@@ -2837,7 +2883,7 @@ function useTimeoutPoll(fn, interval, timeoutPollOptions) {
|
|
|
2837
2883
|
function pause() {
|
|
2838
2884
|
isActive.value = false;
|
|
2839
2885
|
}
|
|
2840
|
-
if (
|
|
2886
|
+
if (immediate && isClient)
|
|
2841
2887
|
resume();
|
|
2842
2888
|
tryOnScopeDispose(pause);
|
|
2843
2889
|
return {
|
|
@@ -2876,6 +2922,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
2876
2922
|
removeNullishValues = true,
|
|
2877
2923
|
removeFalsyValues = false,
|
|
2878
2924
|
write: enableWrite = true,
|
|
2925
|
+
writeMode = "replace",
|
|
2879
2926
|
window: window2 = defaultWindow
|
|
2880
2927
|
} = options;
|
|
2881
2928
|
if (!window2)
|
|
@@ -2931,7 +2978,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
2931
2978
|
else
|
|
2932
2979
|
params.set(key, mapEntry);
|
|
2933
2980
|
});
|
|
2934
|
-
write(params);
|
|
2981
|
+
write(params, false);
|
|
2935
2982
|
},
|
|
2936
2983
|
{ deep: true }
|
|
2937
2984
|
);
|
|
@@ -2939,11 +2986,19 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
2939
2986
|
pause();
|
|
2940
2987
|
if (shouldUpdate)
|
|
2941
2988
|
updateState(params);
|
|
2942
|
-
|
|
2943
|
-
window2.history.
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2989
|
+
if (writeMode === "replace") {
|
|
2990
|
+
window2.history.replaceState(
|
|
2991
|
+
window2.history.state,
|
|
2992
|
+
window2.document.title,
|
|
2993
|
+
window2.location.pathname + constructQuery(params)
|
|
2994
|
+
);
|
|
2995
|
+
} else {
|
|
2996
|
+
window2.history.pushState(
|
|
2997
|
+
window2.history.state,
|
|
2998
|
+
window2.document.title,
|
|
2999
|
+
window2.location.pathname + constructQuery(params)
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
2947
3002
|
resume();
|
|
2948
3003
|
}
|
|
2949
3004
|
function onChanged() {
|
|
@@ -2951,9 +3006,10 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
2951
3006
|
return;
|
|
2952
3007
|
write(read(), true);
|
|
2953
3008
|
}
|
|
2954
|
-
|
|
3009
|
+
const listenerOptions = { passive: true };
|
|
3010
|
+
useEventListener(window2, "popstate", onChanged, listenerOptions);
|
|
2955
3011
|
if (mode !== "history")
|
|
2956
|
-
useEventListener(window2, "hashchange", onChanged,
|
|
3012
|
+
useEventListener(window2, "hashchange", onChanged, listenerOptions);
|
|
2957
3013
|
const initial = read();
|
|
2958
3014
|
if (initial.keys().next().value)
|
|
2959
3015
|
updateState(initial);
|
|
@@ -2974,6 +3030,7 @@ function useWebSocket(url, options = {}) {
|
|
|
2974
3030
|
onError,
|
|
2975
3031
|
onMessage,
|
|
2976
3032
|
immediate = true,
|
|
3033
|
+
autoConnect = true,
|
|
2977
3034
|
autoClose = true,
|
|
2978
3035
|
protocols = []
|
|
2979
3036
|
} = options;
|
|
@@ -2986,6 +3043,7 @@ function useWebSocket(url, options = {}) {
|
|
|
2986
3043
|
let explicitlyClosed = false;
|
|
2987
3044
|
let retried = 0;
|
|
2988
3045
|
let bufferedData = [];
|
|
3046
|
+
let retryTimeout;
|
|
2989
3047
|
let pongTimeoutWait;
|
|
2990
3048
|
const _sendBuffer = () => {
|
|
2991
3049
|
if (bufferedData.length && wsRef.value && status.value === "OPEN") {
|
|
@@ -2994,12 +3052,19 @@ function useWebSocket(url, options = {}) {
|
|
|
2994
3052
|
bufferedData = [];
|
|
2995
3053
|
}
|
|
2996
3054
|
};
|
|
3055
|
+
const resetRetry = () => {
|
|
3056
|
+
if (retryTimeout != null) {
|
|
3057
|
+
clearTimeout(retryTimeout);
|
|
3058
|
+
retryTimeout = void 0;
|
|
3059
|
+
}
|
|
3060
|
+
};
|
|
2997
3061
|
const resetHeartbeat = () => {
|
|
2998
3062
|
clearTimeout(pongTimeoutWait);
|
|
2999
3063
|
pongTimeoutWait = void 0;
|
|
3000
3064
|
};
|
|
3001
3065
|
const close = (code = 1e3, reason) => {
|
|
3002
|
-
|
|
3066
|
+
resetRetry();
|
|
3067
|
+
if (!isClient && !isWorker || !wsRef.value)
|
|
3003
3068
|
return;
|
|
3004
3069
|
explicitlyClosed = true;
|
|
3005
3070
|
resetHeartbeat();
|
|
@@ -3041,9 +3106,9 @@ function useWebSocket(url, options = {}) {
|
|
|
3041
3106
|
} = resolveNestedOptions(options.autoReconnect);
|
|
3042
3107
|
if (typeof retries === "number" && (retries < 0 || retried < retries)) {
|
|
3043
3108
|
retried += 1;
|
|
3044
|
-
setTimeout(_init, delay);
|
|
3109
|
+
retryTimeout = setTimeout(_init, delay);
|
|
3045
3110
|
} else if (typeof retries === "function" && retries()) {
|
|
3046
|
-
setTimeout(_init, delay);
|
|
3111
|
+
retryTimeout = setTimeout(_init, delay);
|
|
3047
3112
|
} else {
|
|
3048
3113
|
onFailed == null ? void 0 : onFailed();
|
|
3049
3114
|
}
|
|
@@ -3059,7 +3124,7 @@ function useWebSocket(url, options = {}) {
|
|
|
3059
3124
|
message = DEFAULT_PING_MESSAGE,
|
|
3060
3125
|
responseMessage = message
|
|
3061
3126
|
} = resolveNestedOptions(options.heartbeat);
|
|
3062
|
-
if (e.data === responseMessage)
|
|
3127
|
+
if (e.data === toValue$1(responseMessage))
|
|
3063
3128
|
return;
|
|
3064
3129
|
}
|
|
3065
3130
|
data.value = e.data;
|
|
@@ -3074,7 +3139,7 @@ function useWebSocket(url, options = {}) {
|
|
|
3074
3139
|
} = resolveNestedOptions(options.heartbeat);
|
|
3075
3140
|
const { pause, resume } = useIntervalFn(
|
|
3076
3141
|
() => {
|
|
3077
|
-
send(message, false);
|
|
3142
|
+
send(toValue$1(message), false);
|
|
3078
3143
|
if (pongTimeoutWait != null)
|
|
3079
3144
|
return;
|
|
3080
3145
|
pongTimeoutWait = setTimeout(() => {
|
|
@@ -3090,7 +3155,7 @@ function useWebSocket(url, options = {}) {
|
|
|
3090
3155
|
}
|
|
3091
3156
|
if (autoClose) {
|
|
3092
3157
|
if (isClient)
|
|
3093
|
-
useEventListener("beforeunload", () => close());
|
|
3158
|
+
useEventListener("beforeunload", () => close(), { passive: true });
|
|
3094
3159
|
tryOnScopeDispose(close);
|
|
3095
3160
|
}
|
|
3096
3161
|
const open = () => {
|
|
@@ -3103,7 +3168,8 @@ function useWebSocket(url, options = {}) {
|
|
|
3103
3168
|
};
|
|
3104
3169
|
if (immediate)
|
|
3105
3170
|
open();
|
|
3106
|
-
|
|
3171
|
+
if (autoConnect)
|
|
3172
|
+
watch(urlRef, open);
|
|
3107
3173
|
return {
|
|
3108
3174
|
data,
|
|
3109
3175
|
status,
|