@reactive-vscode/vueuse 0.2.8 → 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 +222 -152
- package/dist/index.d.ts +73 -36
- package/dist/index.js +223 -153
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,9 @@ function createEventHook() {
|
|
|
46
46
|
const off = (fn) => {
|
|
47
47
|
fns.delete(fn);
|
|
48
48
|
};
|
|
49
|
+
const clear = () => {
|
|
50
|
+
fns.clear();
|
|
51
|
+
};
|
|
49
52
|
const on = (fn) => {
|
|
50
53
|
fns.add(fn);
|
|
51
54
|
const offFn = () => off(fn);
|
|
@@ -60,7 +63,8 @@ function createEventHook() {
|
|
|
60
63
|
return {
|
|
61
64
|
on,
|
|
62
65
|
off,
|
|
63
|
-
trigger
|
|
66
|
+
trigger,
|
|
67
|
+
clear
|
|
64
68
|
};
|
|
65
69
|
}
|
|
66
70
|
function createGlobalState(stateFactory) {
|
|
@@ -145,12 +149,8 @@ function makeDestructurable(obj, arr) {
|
|
|
145
149
|
return Object.assign([...arr], obj);
|
|
146
150
|
}
|
|
147
151
|
}
|
|
148
|
-
function toValue(r) {
|
|
149
|
-
return typeof r === "function" ? r() : reactivity.unref(r);
|
|
150
|
-
}
|
|
151
|
-
const resolveUnref = toValue;
|
|
152
152
|
function reactify(fn, options) {
|
|
153
|
-
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? reactivity.unref : toValue;
|
|
153
|
+
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? reactivity.unref : reactivity.toValue;
|
|
154
154
|
return function(...args) {
|
|
155
155
|
return reactivity.computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
|
|
156
156
|
};
|
|
@@ -215,7 +215,7 @@ function reactiveComputed(fn) {
|
|
|
215
215
|
function reactiveOmit(obj, ...keys) {
|
|
216
216
|
const flatKeys = keys.flat();
|
|
217
217
|
const predicate = flatKeys[0];
|
|
218
|
-
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter((e) => !flatKeys.includes(e[0]))));
|
|
218
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter(([k, v]) => !predicate(reactivity.toValue(v), k))) : Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter((e) => !flatKeys.includes(e[0]))));
|
|
219
219
|
}
|
|
220
220
|
const isClient = typeof window !== "undefined" && typeof document !== "undefined";
|
|
221
221
|
const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
|
|
@@ -258,9 +258,10 @@ function debounceFilter(ms, options = {}) {
|
|
|
258
258
|
lastRejector();
|
|
259
259
|
lastRejector = noop;
|
|
260
260
|
};
|
|
261
|
+
let lastInvoker;
|
|
261
262
|
const filter = (invoke2) => {
|
|
262
|
-
const duration = toValue(ms);
|
|
263
|
-
const maxDuration = toValue(options.maxWait);
|
|
263
|
+
const duration = reactivity.toValue(ms);
|
|
264
|
+
const maxDuration = reactivity.toValue(options.maxWait);
|
|
264
265
|
if (timer)
|
|
265
266
|
_clearTimeout(timer);
|
|
266
267
|
if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
|
|
@@ -272,12 +273,13 @@ function debounceFilter(ms, options = {}) {
|
|
|
272
273
|
}
|
|
273
274
|
return new Promise((resolve, reject) => {
|
|
274
275
|
lastRejector = options.rejectOnCancel ? reject : resolve;
|
|
276
|
+
lastInvoker = invoke2;
|
|
275
277
|
if (maxDuration && !maxTimer) {
|
|
276
278
|
maxTimer = setTimeout(() => {
|
|
277
279
|
if (timer)
|
|
278
280
|
_clearTimeout(timer);
|
|
279
281
|
maxTimer = null;
|
|
280
|
-
resolve(
|
|
282
|
+
resolve(lastInvoker());
|
|
281
283
|
}, maxDuration);
|
|
282
284
|
}
|
|
283
285
|
timer = setTimeout(() => {
|
|
@@ -313,7 +315,7 @@ function throttleFilter(...args) {
|
|
|
313
315
|
}
|
|
314
316
|
};
|
|
315
317
|
const filter = (_invoke) => {
|
|
316
|
-
const duration = toValue(ms);
|
|
318
|
+
const duration = reactivity.toValue(ms);
|
|
317
319
|
const elapsed = Date.now() - lastExec;
|
|
318
320
|
const invoke2 = () => {
|
|
319
321
|
return lastValue = _invoke();
|
|
@@ -434,6 +436,9 @@ function objectEntries(obj) {
|
|
|
434
436
|
function getLifeCycleTarget(target) {
|
|
435
437
|
return target || null;
|
|
436
438
|
}
|
|
439
|
+
function toArray(value) {
|
|
440
|
+
return Array.isArray(value) ? value : [value];
|
|
441
|
+
}
|
|
437
442
|
function toRef(...args) {
|
|
438
443
|
if (args.length !== 1)
|
|
439
444
|
return reactivity.toRef(...args);
|
|
@@ -444,16 +449,16 @@ const resolveRef = toRef;
|
|
|
444
449
|
function reactivePick(obj, ...keys) {
|
|
445
450
|
const flatKeys = keys.flat();
|
|
446
451
|
const predicate = flatKeys[0];
|
|
447
|
-
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter(([k, v]) => predicate(toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
|
|
452
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(reactivity.toRefs(obj)).filter(([k, v]) => predicate(reactivity.toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
|
|
448
453
|
}
|
|
449
454
|
function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
450
455
|
return reactivity.customRef((track, trigger) => {
|
|
451
|
-
let value = toValue(defaultValue);
|
|
456
|
+
let value = reactivity.toValue(defaultValue);
|
|
452
457
|
let timer;
|
|
453
458
|
const resetAfter = () => setTimeout(() => {
|
|
454
|
-
value = toValue(defaultValue);
|
|
459
|
+
value = reactivity.toValue(defaultValue);
|
|
455
460
|
trigger();
|
|
456
|
-
}, toValue(afterMs));
|
|
461
|
+
}, reactivity.toValue(afterMs));
|
|
457
462
|
tryOnScopeDispose(() => {
|
|
458
463
|
clearTimeout(timer);
|
|
459
464
|
});
|
|
@@ -569,10 +574,8 @@ function set(...args) {
|
|
|
569
574
|
ref.value = value;
|
|
570
575
|
}
|
|
571
576
|
if (args.length === 3) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
target[key] = value;
|
|
575
|
-
}
|
|
577
|
+
const [target, key, value] = args;
|
|
578
|
+
target[key] = value;
|
|
576
579
|
}
|
|
577
580
|
}
|
|
578
581
|
function watchWithFilter(source, cb, options = {}) {
|
|
@@ -649,8 +652,7 @@ function syncRefs(source, targets, options = {}) {
|
|
|
649
652
|
deep = false,
|
|
650
653
|
immediate = true
|
|
651
654
|
} = options;
|
|
652
|
-
|
|
653
|
-
targets = [targets];
|
|
655
|
+
targets = toArray(targets);
|
|
654
656
|
return reactivity.watch(
|
|
655
657
|
source,
|
|
656
658
|
(newValue) => targets.forEach((target) => target.value = newValue),
|
|
@@ -668,7 +670,7 @@ function toRefs(objectRef, options = {}) {
|
|
|
668
670
|
},
|
|
669
671
|
set(v) {
|
|
670
672
|
var _a;
|
|
671
|
-
const replaceRef = (_a = toValue(options.replaceRef)) != null ? _a : true;
|
|
673
|
+
const replaceRef = (_a = reactivity.toValue(options.replaceRef)) != null ? _a : true;
|
|
672
674
|
if (replaceRef) {
|
|
673
675
|
if (Array.isArray(objectRef.value)) {
|
|
674
676
|
const copy = [...objectRef.value];
|
|
@@ -687,6 +689,8 @@ function toRefs(objectRef, options = {}) {
|
|
|
687
689
|
}
|
|
688
690
|
return result;
|
|
689
691
|
}
|
|
692
|
+
const toValue = reactivity.toValue;
|
|
693
|
+
const resolveUnref = reactivity.toValue;
|
|
690
694
|
function tryOnMounted(fn, sync = true, target) {
|
|
691
695
|
if (sync)
|
|
692
696
|
fn();
|
|
@@ -718,7 +722,7 @@ function createUntil(r, isNot = false) {
|
|
|
718
722
|
const promises = [watcher];
|
|
719
723
|
if (timeout != null) {
|
|
720
724
|
promises.push(
|
|
721
|
-
promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => stop == null ? void 0 : stop())
|
|
725
|
+
promiseTimeout(timeout, throwOnTimeout).then(() => reactivity.toValue(r)).finally(() => stop == null ? void 0 : stop())
|
|
722
726
|
);
|
|
723
727
|
}
|
|
724
728
|
return Promise.race(promises);
|
|
@@ -750,9 +754,9 @@ function createUntil(r, isNot = false) {
|
|
|
750
754
|
const promises = [watcher];
|
|
751
755
|
if (timeout != null) {
|
|
752
756
|
promises.push(
|
|
753
|
-
promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => {
|
|
757
|
+
promiseTimeout(timeout, throwOnTimeout).then(() => reactivity.toValue(r)).finally(() => {
|
|
754
758
|
stop == null ? void 0 : stop();
|
|
755
|
-
return toValue(r);
|
|
759
|
+
return reactivity.toValue(r);
|
|
756
760
|
})
|
|
757
761
|
);
|
|
758
762
|
}
|
|
@@ -773,7 +777,7 @@ function createUntil(r, isNot = false) {
|
|
|
773
777
|
function toContains(value, options) {
|
|
774
778
|
return toMatch((v) => {
|
|
775
779
|
const array = Array.from(v);
|
|
776
|
-
return array.includes(value) || array.includes(toValue(value));
|
|
780
|
+
return array.includes(value) || array.includes(reactivity.toValue(value));
|
|
777
781
|
}, options);
|
|
778
782
|
}
|
|
779
783
|
function changed(options) {
|
|
@@ -786,7 +790,7 @@ function createUntil(r, isNot = false) {
|
|
|
786
790
|
return count >= n;
|
|
787
791
|
}, options);
|
|
788
792
|
}
|
|
789
|
-
if (Array.isArray(toValue(r))) {
|
|
793
|
+
if (Array.isArray(reactivity.toValue(r))) {
|
|
790
794
|
const instance = {
|
|
791
795
|
toMatch,
|
|
792
796
|
toContains,
|
|
@@ -821,29 +825,38 @@ function defaultComparator(value, othVal) {
|
|
|
821
825
|
return value === othVal;
|
|
822
826
|
}
|
|
823
827
|
function useArrayDifference(...args) {
|
|
824
|
-
var _a;
|
|
828
|
+
var _a, _b;
|
|
825
829
|
const list = args[0];
|
|
826
830
|
const values = args[1];
|
|
827
831
|
let compareFn = (_a = args[2]) != null ? _a : defaultComparator;
|
|
832
|
+
const {
|
|
833
|
+
symmetric = false
|
|
834
|
+
} = (_b = args[3]) != null ? _b : {};
|
|
828
835
|
if (typeof compareFn === "string") {
|
|
829
836
|
const key = compareFn;
|
|
830
837
|
compareFn = (value, othVal) => value[key] === othVal[key];
|
|
831
838
|
}
|
|
832
|
-
|
|
839
|
+
const diff1 = reactivity.computed(() => reactivity.toValue(list).filter((x) => reactivity.toValue(values).findIndex((y) => compareFn(x, y)) === -1));
|
|
840
|
+
if (symmetric) {
|
|
841
|
+
const diff2 = reactivity.computed(() => reactivity.toValue(values).filter((x) => reactivity.toValue(list).findIndex((y) => compareFn(x, y)) === -1));
|
|
842
|
+
return reactivity.computed(() => symmetric ? [...reactivity.toValue(diff1), ...reactivity.toValue(diff2)] : reactivity.toValue(diff1));
|
|
843
|
+
} else {
|
|
844
|
+
return diff1;
|
|
845
|
+
}
|
|
833
846
|
}
|
|
834
847
|
function useArrayEvery(list, fn) {
|
|
835
|
-
return reactivity.computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
|
|
848
|
+
return reactivity.computed(() => reactivity.toValue(list).every((element, index, array) => fn(reactivity.toValue(element), index, array)));
|
|
836
849
|
}
|
|
837
850
|
function useArrayFilter(list, fn) {
|
|
838
|
-
return reactivity.computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
|
|
851
|
+
return reactivity.computed(() => reactivity.toValue(list).map((i) => reactivity.toValue(i)).filter(fn));
|
|
839
852
|
}
|
|
840
853
|
function useArrayFind(list, fn) {
|
|
841
|
-
return reactivity.computed(() => toValue(
|
|
842
|
-
toValue(list).find((element, index, array) => fn(toValue(element), index, array))
|
|
854
|
+
return reactivity.computed(() => reactivity.toValue(
|
|
855
|
+
reactivity.toValue(list).find((element, index, array) => fn(reactivity.toValue(element), index, array))
|
|
843
856
|
));
|
|
844
857
|
}
|
|
845
858
|
function useArrayFindIndex(list, fn) {
|
|
846
|
-
return reactivity.computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
|
|
859
|
+
return reactivity.computed(() => reactivity.toValue(list).findIndex((element, index, array) => fn(reactivity.toValue(element), index, array)));
|
|
847
860
|
}
|
|
848
861
|
function findLast(arr, cb) {
|
|
849
862
|
let index = arr.length;
|
|
@@ -854,8 +867,8 @@ function findLast(arr, cb) {
|
|
|
854
867
|
return void 0;
|
|
855
868
|
}
|
|
856
869
|
function useArrayFindLast(list, fn) {
|
|
857
|
-
return reactivity.computed(() => toValue(
|
|
858
|
-
!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))
|
|
870
|
+
return reactivity.computed(() => reactivity.toValue(
|
|
871
|
+
!Array.prototype.findLast ? findLast(reactivity.toValue(list), (element, index, array) => fn(reactivity.toValue(element), index, array)) : reactivity.toValue(list).findLast((element, index, array) => fn(reactivity.toValue(element), index, array))
|
|
859
872
|
));
|
|
860
873
|
}
|
|
861
874
|
function isArrayIncludesOptions(obj) {
|
|
@@ -873,31 +886,31 @@ function useArrayIncludes(...args) {
|
|
|
873
886
|
}
|
|
874
887
|
if (typeof comparator === "string") {
|
|
875
888
|
const key = comparator;
|
|
876
|
-
comparator = (element, value2) => element[key] === toValue(value2);
|
|
889
|
+
comparator = (element, value2) => element[key] === reactivity.toValue(value2);
|
|
877
890
|
}
|
|
878
|
-
comparator = comparator != null ? comparator : (element, value2) => element === toValue(value2);
|
|
879
|
-
return reactivity.computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(
|
|
880
|
-
toValue(element),
|
|
881
|
-
toValue(value),
|
|
891
|
+
comparator = comparator != null ? comparator : (element, value2) => element === reactivity.toValue(value2);
|
|
892
|
+
return reactivity.computed(() => reactivity.toValue(list).slice(formIndex).some((element, index, array) => comparator(
|
|
893
|
+
reactivity.toValue(element),
|
|
894
|
+
reactivity.toValue(value),
|
|
882
895
|
index,
|
|
883
|
-
toValue(array)
|
|
896
|
+
reactivity.toValue(array)
|
|
884
897
|
)));
|
|
885
898
|
}
|
|
886
899
|
function useArrayJoin(list, separator) {
|
|
887
|
-
return reactivity.computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
|
|
900
|
+
return reactivity.computed(() => reactivity.toValue(list).map((i) => reactivity.toValue(i)).join(reactivity.toValue(separator)));
|
|
888
901
|
}
|
|
889
902
|
function useArrayMap(list, fn) {
|
|
890
|
-
return reactivity.computed(() => toValue(list).map((i) => toValue(i)).map(fn));
|
|
903
|
+
return reactivity.computed(() => reactivity.toValue(list).map((i) => reactivity.toValue(i)).map(fn));
|
|
891
904
|
}
|
|
892
905
|
function useArrayReduce(list, reducer, ...args) {
|
|
893
|
-
const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
|
|
906
|
+
const reduceCallback = (sum, value, index) => reducer(reactivity.toValue(sum), reactivity.toValue(value), index);
|
|
894
907
|
return reactivity.computed(() => {
|
|
895
|
-
const resolved = toValue(list);
|
|
896
|
-
return args.length ? resolved.reduce(reduceCallback, toValue(args[0])) : resolved.reduce(reduceCallback);
|
|
908
|
+
const resolved = reactivity.toValue(list);
|
|
909
|
+
return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? reactivity.toValue(args[0]()) : reactivity.toValue(args[0])) : resolved.reduce(reduceCallback);
|
|
897
910
|
});
|
|
898
911
|
}
|
|
899
912
|
function useArraySome(list, fn) {
|
|
900
|
-
return reactivity.computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
|
|
913
|
+
return reactivity.computed(() => reactivity.toValue(list).some((element, index, array) => fn(reactivity.toValue(element), index, array)));
|
|
901
914
|
}
|
|
902
915
|
function uniq(array) {
|
|
903
916
|
return Array.from(new Set(array));
|
|
@@ -911,7 +924,7 @@ function uniqueElementsBy(array, fn) {
|
|
|
911
924
|
}
|
|
912
925
|
function useArrayUnique(list, compareFn) {
|
|
913
926
|
return reactivity.computed(() => {
|
|
914
|
-
const resolvedList = toValue(list).map((element) => toValue(element));
|
|
927
|
+
const resolvedList = reactivity.toValue(list).map((element) => reactivity.toValue(element));
|
|
915
928
|
return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
|
|
916
929
|
});
|
|
917
930
|
}
|
|
@@ -963,8 +976,8 @@ function formatDate(date, formatStr, options = {}) {
|
|
|
963
976
|
M: () => month + 1,
|
|
964
977
|
Mo: () => formatOrdinal(month + 1),
|
|
965
978
|
MM: () => `${month + 1}`.padStart(2, "0"),
|
|
966
|
-
MMM: () => date.toLocaleDateString(toValue(options.locales), { month: "short" }),
|
|
967
|
-
MMMM: () => date.toLocaleDateString(toValue(options.locales), { month: "long" }),
|
|
979
|
+
MMM: () => date.toLocaleDateString(reactivity.toValue(options.locales), { month: "short" }),
|
|
980
|
+
MMMM: () => date.toLocaleDateString(reactivity.toValue(options.locales), { month: "long" }),
|
|
968
981
|
D: () => String(days),
|
|
969
982
|
Do: () => formatOrdinal(days),
|
|
970
983
|
DD: () => `${days}`.padStart(2, "0"),
|
|
@@ -982,9 +995,9 @@ function formatDate(date, formatStr, options = {}) {
|
|
|
982
995
|
ss: () => `${seconds}`.padStart(2, "0"),
|
|
983
996
|
SSS: () => `${milliseconds}`.padStart(3, "0"),
|
|
984
997
|
d: () => day,
|
|
985
|
-
dd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "narrow" }),
|
|
986
|
-
ddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "short" }),
|
|
987
|
-
dddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "long" }),
|
|
998
|
+
dd: () => date.toLocaleDateString(reactivity.toValue(options.locales), { weekday: "narrow" }),
|
|
999
|
+
ddd: () => date.toLocaleDateString(reactivity.toValue(options.locales), { weekday: "short" }),
|
|
1000
|
+
dddd: () => date.toLocaleDateString(reactivity.toValue(options.locales), { weekday: "long" }),
|
|
988
1001
|
A: () => meridiem(hours, minutes),
|
|
989
1002
|
AA: () => meridiem(hours, minutes, false, true),
|
|
990
1003
|
a: () => meridiem(hours, minutes, true),
|
|
@@ -1013,7 +1026,7 @@ function normalizeDate(date) {
|
|
|
1013
1026
|
return new Date(date);
|
|
1014
1027
|
}
|
|
1015
1028
|
function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
|
|
1016
|
-
return reactivity.computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
|
|
1029
|
+
return reactivity.computed(() => formatDate(normalizeDate(reactivity.toValue(date)), reactivity.toValue(formatStr), options));
|
|
1017
1030
|
}
|
|
1018
1031
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
1019
1032
|
const {
|
|
@@ -1033,14 +1046,15 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
1033
1046
|
clean();
|
|
1034
1047
|
}
|
|
1035
1048
|
function resume() {
|
|
1036
|
-
const intervalValue = toValue(interval);
|
|
1049
|
+
const intervalValue = reactivity.toValue(interval);
|
|
1037
1050
|
if (intervalValue <= 0)
|
|
1038
1051
|
return;
|
|
1039
1052
|
isActive.value = true;
|
|
1040
1053
|
if (immediateCallback)
|
|
1041
1054
|
cb();
|
|
1042
1055
|
clean();
|
|
1043
|
-
|
|
1056
|
+
if (isActive.value)
|
|
1057
|
+
timer = setInterval(cb, intervalValue);
|
|
1044
1058
|
}
|
|
1045
1059
|
if (immediate && isClient)
|
|
1046
1060
|
resume();
|
|
@@ -1120,7 +1134,7 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1120
1134
|
isPending.value = false;
|
|
1121
1135
|
timer = null;
|
|
1122
1136
|
cb(...args);
|
|
1123
|
-
}, toValue(interval));
|
|
1137
|
+
}, reactivity.toValue(interval));
|
|
1124
1138
|
}
|
|
1125
1139
|
if (immediate) {
|
|
1126
1140
|
isPending.value = true;
|
|
@@ -1161,8 +1175,10 @@ function useToNumber(value, options = {}) {
|
|
|
1161
1175
|
nanToZero
|
|
1162
1176
|
} = options;
|
|
1163
1177
|
return reactivity.computed(() => {
|
|
1164
|
-
let resolved = toValue(value);
|
|
1165
|
-
if (typeof
|
|
1178
|
+
let resolved = reactivity.toValue(value);
|
|
1179
|
+
if (typeof method === "function")
|
|
1180
|
+
resolved = method(resolved);
|
|
1181
|
+
else if (typeof resolved === "string")
|
|
1166
1182
|
resolved = Number[method](resolved, radix);
|
|
1167
1183
|
if (nanToZero && Number.isNaN(resolved))
|
|
1168
1184
|
resolved = 0;
|
|
@@ -1170,7 +1186,7 @@ function useToNumber(value, options = {}) {
|
|
|
1170
1186
|
});
|
|
1171
1187
|
}
|
|
1172
1188
|
function useToString(value) {
|
|
1173
|
-
return reactivity.computed(() => `${toValue(value)}`);
|
|
1189
|
+
return reactivity.computed(() => `${reactivity.toValue(value)}`);
|
|
1174
1190
|
}
|
|
1175
1191
|
function useToggle(initialValue = false, options = {}) {
|
|
1176
1192
|
const {
|
|
@@ -1184,8 +1200,8 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1184
1200
|
_value.value = value;
|
|
1185
1201
|
return _value.value;
|
|
1186
1202
|
} else {
|
|
1187
|
-
const truthy = toValue(truthyValue);
|
|
1188
|
-
_value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
|
|
1203
|
+
const truthy = reactivity.toValue(truthyValue);
|
|
1204
|
+
_value.value = _value.value === truthy ? reactivity.toValue(falsyValue) : truthy;
|
|
1189
1205
|
return _value.value;
|
|
1190
1206
|
}
|
|
1191
1207
|
}
|
|
@@ -1195,7 +1211,7 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1195
1211
|
return [_value, toggle];
|
|
1196
1212
|
}
|
|
1197
1213
|
function watchArray(source, cb, options) {
|
|
1198
|
-
let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)];
|
|
1214
|
+
let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : reactivity.toValue(source)];
|
|
1199
1215
|
return reactivity.watch(source, (newList, _, onCleanup) => {
|
|
1200
1216
|
const oldListRemains = Array.from({ length: oldList.length });
|
|
1201
1217
|
const added = [];
|
|
@@ -1226,7 +1242,7 @@ function watchAtMost(source, cb, options) {
|
|
|
1226
1242
|
source,
|
|
1227
1243
|
(...args) => {
|
|
1228
1244
|
current.value += 1;
|
|
1229
|
-
if (current.value >= toValue(count))
|
|
1245
|
+
if (current.value >= reactivity.toValue(count))
|
|
1230
1246
|
reactivity.nextTick(() => stop());
|
|
1231
1247
|
cb(...args);
|
|
1232
1248
|
},
|
|
@@ -1396,8 +1412,8 @@ function getWatchSources(sources) {
|
|
|
1396
1412
|
if (reactivity.isReactive(sources))
|
|
1397
1413
|
return sources;
|
|
1398
1414
|
if (Array.isArray(sources))
|
|
1399
|
-
return sources.map((item) => toValue(item));
|
|
1400
|
-
return toValue(sources);
|
|
1415
|
+
return sources.map((item) => reactivity.toValue(item));
|
|
1416
|
+
return reactivity.toValue(sources);
|
|
1401
1417
|
}
|
|
1402
1418
|
function getOldValue(source) {
|
|
1403
1419
|
return Array.isArray(source) ? source.map(() => void 0) : void 0;
|
|
@@ -1478,61 +1494,60 @@ function computedAsync(evaluationCallback, initialState, optionsOrRef) {
|
|
|
1478
1494
|
}
|
|
1479
1495
|
function createUnrefFn(fn) {
|
|
1480
1496
|
return function(...args) {
|
|
1481
|
-
return fn.apply(this, args.map((i) => toValue(i)));
|
|
1497
|
+
return fn.apply(this, args.map((i) => reactivity.toValue(i)));
|
|
1482
1498
|
};
|
|
1483
1499
|
}
|
|
1484
1500
|
const defaultWindow = isClient ? window : void 0;
|
|
1485
1501
|
function unrefElement(elRef) {
|
|
1486
1502
|
var _a;
|
|
1487
|
-
const plain = toValue(elRef);
|
|
1503
|
+
const plain = reactivity.toValue(elRef);
|
|
1488
1504
|
return (_a = plain == null ? void 0 : plain.$el) != null ? _a : plain;
|
|
1489
1505
|
}
|
|
1490
1506
|
function useEventListener(...args) {
|
|
1491
|
-
let target;
|
|
1492
|
-
let events2;
|
|
1493
|
-
let listeners;
|
|
1494
|
-
let options;
|
|
1495
|
-
if (typeof args[0] === "string" || Array.isArray(args[0])) {
|
|
1496
|
-
[events2, listeners, options] = args;
|
|
1497
|
-
target = defaultWindow;
|
|
1498
|
-
} else {
|
|
1499
|
-
[target, events2, listeners, options] = args;
|
|
1500
|
-
}
|
|
1501
|
-
if (!target)
|
|
1502
|
-
return noop;
|
|
1503
|
-
if (!Array.isArray(events2))
|
|
1504
|
-
events2 = [events2];
|
|
1505
|
-
if (!Array.isArray(listeners))
|
|
1506
|
-
listeners = [listeners];
|
|
1507
1507
|
const cleanups = [];
|
|
1508
1508
|
const cleanup = () => {
|
|
1509
1509
|
cleanups.forEach((fn) => fn());
|
|
1510
1510
|
cleanups.length = 0;
|
|
1511
1511
|
};
|
|
1512
|
-
const register = (el, event, listener,
|
|
1513
|
-
el.addEventListener(event, listener,
|
|
1514
|
-
return () => el.removeEventListener(event, listener,
|
|
1512
|
+
const register = (el, event, listener, options) => {
|
|
1513
|
+
el.addEventListener(event, listener, options);
|
|
1514
|
+
return () => el.removeEventListener(event, listener, options);
|
|
1515
1515
|
};
|
|
1516
|
-
const
|
|
1517
|
-
|
|
1518
|
-
(
|
|
1516
|
+
const firstParamTargets = reactivity.computed(() => {
|
|
1517
|
+
const test = toArray(reactivity.toValue(args[0])).filter((e) => e != null);
|
|
1518
|
+
return test.every((e) => typeof e !== "string") ? test : void 0;
|
|
1519
|
+
});
|
|
1520
|
+
const stopWatch = watchImmediate(
|
|
1521
|
+
() => {
|
|
1522
|
+
var _a, _b;
|
|
1523
|
+
return [
|
|
1524
|
+
(_b = (_a = firstParamTargets.value) == null ? void 0 : _a.map((e) => unrefElement(e))) != null ? _b : [defaultWindow].filter((e) => e != null),
|
|
1525
|
+
toArray(reactivity.toValue(firstParamTargets.value ? args[1] : args[0])),
|
|
1526
|
+
toArray(reactivity.unref(firstParamTargets.value ? args[2] : args[1])),
|
|
1527
|
+
// @ts-expect-error - TypeScript gets the correct types, but somehow still complains
|
|
1528
|
+
reactivity.toValue(firstParamTargets.value ? args[3] : args[2])
|
|
1529
|
+
];
|
|
1530
|
+
},
|
|
1531
|
+
([raw_targets, raw_events, raw_listeners, raw_options]) => {
|
|
1519
1532
|
cleanup();
|
|
1520
|
-
if (!
|
|
1533
|
+
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))
|
|
1521
1534
|
return;
|
|
1522
|
-
const optionsClone = isObject(
|
|
1535
|
+
const optionsClone = isObject(raw_options) ? { ...raw_options } : raw_options;
|
|
1523
1536
|
cleanups.push(
|
|
1524
|
-
...
|
|
1525
|
-
|
|
1526
|
-
|
|
1537
|
+
...raw_targets.flatMap(
|
|
1538
|
+
(el) => raw_events.flatMap(
|
|
1539
|
+
(event) => raw_listeners.map((listener) => register(el, event, listener, optionsClone))
|
|
1540
|
+
)
|
|
1541
|
+
)
|
|
1527
1542
|
);
|
|
1528
1543
|
},
|
|
1529
|
-
{
|
|
1544
|
+
{ flush: "post" }
|
|
1530
1545
|
);
|
|
1531
1546
|
const stop = () => {
|
|
1532
1547
|
stopWatch();
|
|
1533
1548
|
cleanup();
|
|
1534
1549
|
};
|
|
1535
|
-
tryOnScopeDispose(
|
|
1550
|
+
tryOnScopeDispose(cleanup);
|
|
1536
1551
|
return stop;
|
|
1537
1552
|
}
|
|
1538
1553
|
function useMounted() {
|
|
@@ -1553,7 +1568,9 @@ function useRafFn(fn, options = {}) {
|
|
|
1553
1568
|
window: window2 = defaultWindow
|
|
1554
1569
|
} = options;
|
|
1555
1570
|
const isActive = reactivity.ref(false);
|
|
1556
|
-
const intervalLimit =
|
|
1571
|
+
const intervalLimit = reactivity.computed(() => {
|
|
1572
|
+
return fpsLimit ? 1e3 / reactivity.toValue(fpsLimit) : null;
|
|
1573
|
+
});
|
|
1557
1574
|
let previousFrameTimestamp = 0;
|
|
1558
1575
|
let rafId = null;
|
|
1559
1576
|
function loop(timestamp2) {
|
|
@@ -1562,7 +1579,7 @@ function useRafFn(fn, options = {}) {
|
|
|
1562
1579
|
if (!previousFrameTimestamp)
|
|
1563
1580
|
previousFrameTimestamp = timestamp2;
|
|
1564
1581
|
const delta = timestamp2 - previousFrameTimestamp;
|
|
1565
|
-
if (intervalLimit && delta < intervalLimit) {
|
|
1582
|
+
if (intervalLimit.value && delta < intervalLimit.value) {
|
|
1566
1583
|
rafId = window2.requestAnimationFrame(loop);
|
|
1567
1584
|
return;
|
|
1568
1585
|
}
|
|
@@ -1703,8 +1720,9 @@ function useAsyncState(promise, initialState, options) {
|
|
|
1703
1720
|
}
|
|
1704
1721
|
return state.value;
|
|
1705
1722
|
}
|
|
1706
|
-
if (immediate)
|
|
1723
|
+
if (immediate) {
|
|
1707
1724
|
execute(delay);
|
|
1725
|
+
}
|
|
1708
1726
|
const shell = {
|
|
1709
1727
|
state,
|
|
1710
1728
|
isReady,
|
|
@@ -1751,7 +1769,7 @@ function useBase64(target, options) {
|
|
|
1751
1769
|
return;
|
|
1752
1770
|
promise.value = new Promise((resolve, reject) => {
|
|
1753
1771
|
try {
|
|
1754
|
-
const _target = toValue(target);
|
|
1772
|
+
const _target = reactivity.toValue(target);
|
|
1755
1773
|
if (_target == null) {
|
|
1756
1774
|
resolve("");
|
|
1757
1775
|
} else if (typeof _target === "string") {
|
|
@@ -1784,7 +1802,9 @@ function useBase64(target, options) {
|
|
|
1784
1802
|
reject(error);
|
|
1785
1803
|
}
|
|
1786
1804
|
});
|
|
1787
|
-
promise.value.then((res) =>
|
|
1805
|
+
promise.value.then((res) => {
|
|
1806
|
+
base64.value = (options == null ? void 0 : options.dataUrl) === false ? res.replace(/^data:.*?;base64,/, "") : res;
|
|
1807
|
+
});
|
|
1788
1808
|
return promise.value;
|
|
1789
1809
|
}
|
|
1790
1810
|
if (reactivity.isRef(target) || typeof target === "function")
|
|
@@ -1842,15 +1862,18 @@ function useBroadcastChannel(options) {
|
|
|
1842
1862
|
tryOnMounted(() => {
|
|
1843
1863
|
error.value = null;
|
|
1844
1864
|
channel.value = new BroadcastChannel(name);
|
|
1845
|
-
|
|
1865
|
+
const listenerOptions = {
|
|
1866
|
+
passive: true
|
|
1867
|
+
};
|
|
1868
|
+
useEventListener(channel, "message", (e) => {
|
|
1846
1869
|
data.value = e.data;
|
|
1847
|
-
},
|
|
1848
|
-
channel
|
|
1870
|
+
}, listenerOptions);
|
|
1871
|
+
useEventListener(channel, "messageerror", (e) => {
|
|
1849
1872
|
error.value = e;
|
|
1850
|
-
},
|
|
1851
|
-
channel
|
|
1873
|
+
}, listenerOptions);
|
|
1874
|
+
useEventListener(channel, "close", () => {
|
|
1852
1875
|
isClosed.value = true;
|
|
1853
|
-
});
|
|
1876
|
+
}, listenerOptions);
|
|
1854
1877
|
});
|
|
1855
1878
|
}
|
|
1856
1879
|
tryOnScopeDispose(() => {
|
|
@@ -1879,6 +1902,8 @@ function cloneFnJSON(source) {
|
|
|
1879
1902
|
}
|
|
1880
1903
|
function useCloned(source, options = {}) {
|
|
1881
1904
|
const cloned = reactivity.ref({});
|
|
1905
|
+
const isModified = reactivity.ref(false);
|
|
1906
|
+
let _lastSync = false;
|
|
1882
1907
|
const {
|
|
1883
1908
|
manual,
|
|
1884
1909
|
clone = cloneFnJSON,
|
|
@@ -1886,8 +1911,20 @@ function useCloned(source, options = {}) {
|
|
|
1886
1911
|
deep = true,
|
|
1887
1912
|
immediate = true
|
|
1888
1913
|
} = options;
|
|
1914
|
+
reactivity.watch(cloned, () => {
|
|
1915
|
+
if (_lastSync) {
|
|
1916
|
+
_lastSync = false;
|
|
1917
|
+
return;
|
|
1918
|
+
}
|
|
1919
|
+
isModified.value = true;
|
|
1920
|
+
}, {
|
|
1921
|
+
deep: true,
|
|
1922
|
+
flush: "sync"
|
|
1923
|
+
});
|
|
1889
1924
|
function sync() {
|
|
1890
|
-
|
|
1925
|
+
_lastSync = true;
|
|
1926
|
+
isModified.value = false;
|
|
1927
|
+
cloned.value = clone(reactivity.toValue(source));
|
|
1891
1928
|
}
|
|
1892
1929
|
if (!manual && (reactivity.isRef(source) || typeof source === "function")) {
|
|
1893
1930
|
reactivity.watch(source, sync, {
|
|
@@ -1898,7 +1935,7 @@ function useCloned(source, options = {}) {
|
|
|
1898
1935
|
} else {
|
|
1899
1936
|
sync();
|
|
1900
1937
|
}
|
|
1901
|
-
return { cloned, sync };
|
|
1938
|
+
return { cloned, isModified, sync };
|
|
1902
1939
|
}
|
|
1903
1940
|
function useCycleList(list, options) {
|
|
1904
1941
|
const state = reactivity.shallowRef(getInitialValue());
|
|
@@ -1935,7 +1972,7 @@ function useCycleList(list, options) {
|
|
|
1935
1972
|
}
|
|
1936
1973
|
function getInitialValue() {
|
|
1937
1974
|
var _a, _b;
|
|
1938
|
-
return (_b = toValue((_a = options == null ? void 0 : options.initialValue) != null ? _a : toValue(list)[0])) != null ? _b : void 0;
|
|
1975
|
+
return (_b = reactivity.toValue((_a = options == null ? void 0 : options.initialValue) != null ? _a : reactivity.toValue(list)[0])) != null ? _b : void 0;
|
|
1939
1976
|
}
|
|
1940
1977
|
reactivity.watch(listRef, () => set2(index.value));
|
|
1941
1978
|
return {
|
|
@@ -2169,8 +2206,8 @@ function createFetch(config = {}) {
|
|
|
2169
2206
|
const _fetchOptions = config.fetchOptions || {};
|
|
2170
2207
|
function useFactoryFetch(url, ...args) {
|
|
2171
2208
|
const computedUrl = reactivity.computed(() => {
|
|
2172
|
-
const baseUrl = toValue(config.baseUrl);
|
|
2173
|
-
const targetUrl = toValue(url);
|
|
2209
|
+
const baseUrl = reactivity.toValue(config.baseUrl);
|
|
2210
|
+
const targetUrl = reactivity.toValue(url);
|
|
2174
2211
|
return baseUrl && !isAbsoluteURL(targetUrl) ? joinPaths(baseUrl, targetUrl) : targetUrl;
|
|
2175
2212
|
});
|
|
2176
2213
|
let options = _options;
|
|
@@ -2282,10 +2319,11 @@ function useFetch(url, ...args) {
|
|
|
2282
2319
|
method: config.method,
|
|
2283
2320
|
headers: {}
|
|
2284
2321
|
};
|
|
2285
|
-
|
|
2322
|
+
const payload = reactivity.toValue(config.payload);
|
|
2323
|
+
if (payload) {
|
|
2286
2324
|
const headers = headersToObject(defaultFetchOptions.headers);
|
|
2287
|
-
const
|
|
2288
|
-
if (!config.payloadType && payload &&
|
|
2325
|
+
const proto = Object.getPrototypeOf(payload);
|
|
2326
|
+
if (!config.payloadType && payload && (proto === Object.prototype || Array.isArray(proto)) && !(payload instanceof FormData))
|
|
2289
2327
|
config.payloadType = "json";
|
|
2290
2328
|
if (config.payloadType)
|
|
2291
2329
|
headers["Content-Type"] = (_a2 = payloadMapping[config.payloadType]) != null ? _a2 : config.payloadType;
|
|
@@ -2293,7 +2331,7 @@ function useFetch(url, ...args) {
|
|
|
2293
2331
|
}
|
|
2294
2332
|
let isCanceled = false;
|
|
2295
2333
|
const context = {
|
|
2296
|
-
url: toValue(url),
|
|
2334
|
+
url: reactivity.toValue(url),
|
|
2297
2335
|
options: {
|
|
2298
2336
|
...defaultFetchOptions,
|
|
2299
2337
|
...fetchOptions
|
|
@@ -2332,7 +2370,9 @@ function useFetch(url, ...args) {
|
|
|
2332
2370
|
if (options.afterFetch) {
|
|
2333
2371
|
({ data: responseData } = await options.afterFetch({
|
|
2334
2372
|
data: responseData,
|
|
2335
|
-
response: fetchResponse
|
|
2373
|
+
response: fetchResponse,
|
|
2374
|
+
context,
|
|
2375
|
+
execute
|
|
2336
2376
|
}));
|
|
2337
2377
|
}
|
|
2338
2378
|
data.value = responseData;
|
|
@@ -2344,7 +2384,9 @@ function useFetch(url, ...args) {
|
|
|
2344
2384
|
({ error: errorData, data: responseData } = await options.onFetchError({
|
|
2345
2385
|
data: responseData,
|
|
2346
2386
|
error: fetchError,
|
|
2347
|
-
response: response.value
|
|
2387
|
+
response: response.value,
|
|
2388
|
+
context,
|
|
2389
|
+
execute
|
|
2348
2390
|
}));
|
|
2349
2391
|
}
|
|
2350
2392
|
error.value = errorData;
|
|
@@ -2428,7 +2470,7 @@ function useFetch(url, ...args) {
|
|
|
2428
2470
|
}
|
|
2429
2471
|
function waitUntilFinished() {
|
|
2430
2472
|
return new Promise((resolve, reject) => {
|
|
2431
|
-
until(isFinished).toBe(true).then(() => resolve(shell)).catch(
|
|
2473
|
+
until(isFinished).toBe(true).then(() => resolve(shell)).catch(reject);
|
|
2432
2474
|
});
|
|
2433
2475
|
}
|
|
2434
2476
|
function setType(type) {
|
|
@@ -2455,8 +2497,12 @@ function useFetch(url, ...args) {
|
|
|
2455
2497
|
};
|
|
2456
2498
|
}
|
|
2457
2499
|
function joinPaths(start, end) {
|
|
2458
|
-
if (!start.endsWith("/") && !end.startsWith("/"))
|
|
2500
|
+
if (!start.endsWith("/") && !end.startsWith("/")) {
|
|
2459
2501
|
return `${start}/${end}`;
|
|
2502
|
+
}
|
|
2503
|
+
if (start.endsWith("/") && end.startsWith("/")) {
|
|
2504
|
+
return `${start.slice(0, -1)}${end}`;
|
|
2505
|
+
}
|
|
2460
2506
|
return `${start}${end}`;
|
|
2461
2507
|
}
|
|
2462
2508
|
const defaultEvents$1 = ["mousemove", "mousedown", "resize", "keydown", "touchstart", "wheel"];
|
|
@@ -2486,13 +2532,14 @@ function useIdle(timeout = oneMinute, options = {}) {
|
|
|
2486
2532
|
);
|
|
2487
2533
|
if (window2) {
|
|
2488
2534
|
const document2 = window2.document;
|
|
2535
|
+
const listenerOptions = { passive: true };
|
|
2489
2536
|
for (const event of events2)
|
|
2490
|
-
useEventListener(window2, event, onEvent,
|
|
2537
|
+
useEventListener(window2, event, onEvent, listenerOptions);
|
|
2491
2538
|
if (listenForVisibilityChange) {
|
|
2492
2539
|
useEventListener(document2, "visibilitychange", () => {
|
|
2493
2540
|
if (!document2.hidden)
|
|
2494
2541
|
onEvent();
|
|
2495
|
-
});
|
|
2542
|
+
}, listenerOptions);
|
|
2496
2543
|
}
|
|
2497
2544
|
reset();
|
|
2498
2545
|
}
|
|
@@ -2527,7 +2574,7 @@ function useObjectUrl(object) {
|
|
|
2527
2574
|
url.value = void 0;
|
|
2528
2575
|
};
|
|
2529
2576
|
reactivity.watch(
|
|
2530
|
-
() => toValue(object),
|
|
2577
|
+
() => reactivity.toValue(object),
|
|
2531
2578
|
(newObject) => {
|
|
2532
2579
|
release();
|
|
2533
2580
|
if (newObject)
|
|
@@ -2540,14 +2587,14 @@ function useObjectUrl(object) {
|
|
|
2540
2587
|
}
|
|
2541
2588
|
function useClamp(value, min, max) {
|
|
2542
2589
|
if (typeof value === "function" || reactivity.isReadonly(value))
|
|
2543
|
-
return reactivity.computed(() => clamp(toValue(value), toValue(min), toValue(max)));
|
|
2590
|
+
return reactivity.computed(() => clamp(reactivity.toValue(value), reactivity.toValue(min), reactivity.toValue(max)));
|
|
2544
2591
|
const _value = reactivity.ref(value);
|
|
2545
2592
|
return reactivity.computed({
|
|
2546
2593
|
get() {
|
|
2547
|
-
return _value.value = clamp(_value.value, toValue(min), toValue(max));
|
|
2594
|
+
return _value.value = clamp(_value.value, reactivity.toValue(min), reactivity.toValue(max));
|
|
2548
2595
|
},
|
|
2549
2596
|
set(value2) {
|
|
2550
|
-
_value.value = clamp(value2, toValue(min), toValue(max));
|
|
2597
|
+
_value.value = clamp(value2, reactivity.toValue(min), reactivity.toValue(max));
|
|
2551
2598
|
}
|
|
2552
2599
|
});
|
|
2553
2600
|
}
|
|
@@ -2563,7 +2610,7 @@ function useOffsetPagination(options) {
|
|
|
2563
2610
|
const currentPageSize = useClamp(pageSize, 1, Number.POSITIVE_INFINITY);
|
|
2564
2611
|
const pageCount = reactivity.computed(() => Math.max(
|
|
2565
2612
|
1,
|
|
2566
|
-
Math.ceil(toValue(total) / toValue(currentPageSize))
|
|
2613
|
+
Math.ceil(reactivity.toValue(total) / reactivity.toValue(currentPageSize))
|
|
2567
2614
|
));
|
|
2568
2615
|
const currentPage = useClamp(page, 1, pageCount);
|
|
2569
2616
|
const isFirstPage = reactivity.computed(() => currentPage.value === 1);
|
|
@@ -2638,9 +2685,9 @@ function useSorted(...args) {
|
|
|
2638
2685
|
sortFn = defaultSortFn
|
|
2639
2686
|
} = options;
|
|
2640
2687
|
if (!dirty)
|
|
2641
|
-
return reactivity.computed(() => sortFn([...toValue(source)], compareFn));
|
|
2688
|
+
return reactivity.computed(() => sortFn([...reactivity.toValue(source)], compareFn));
|
|
2642
2689
|
reactivity.watchEffect(() => {
|
|
2643
|
-
const result = sortFn(toValue(source), compareFn);
|
|
2690
|
+
const result = sortFn(reactivity.toValue(source), compareFn);
|
|
2644
2691
|
if (reactivity.isRef(source))
|
|
2645
2692
|
source.value = result;
|
|
2646
2693
|
else
|
|
@@ -2761,7 +2808,7 @@ function useTimeAgo(time, options = {}) {
|
|
|
2761
2808
|
updateInterval = 3e4
|
|
2762
2809
|
} = options;
|
|
2763
2810
|
const { now: now2, ...controls } = useNow({ interval: updateInterval, controls: true });
|
|
2764
|
-
const timeAgo = reactivity.computed(() => formatTimeAgo(new Date(toValue(time)), options, toValue(now2)));
|
|
2811
|
+
const timeAgo = reactivity.computed(() => formatTimeAgo(new Date(reactivity.toValue(time)), options, reactivity.toValue(now2)));
|
|
2765
2812
|
if (exposeControls) {
|
|
2766
2813
|
return {
|
|
2767
2814
|
timeAgo,
|
|
@@ -2817,7 +2864,10 @@ function formatTimeAgo(from, options = {}, now2 = Date.now()) {
|
|
|
2817
2864
|
}
|
|
2818
2865
|
return messages.invalid;
|
|
2819
2866
|
}
|
|
2820
|
-
function useTimeoutPoll(fn, interval,
|
|
2867
|
+
function useTimeoutPoll(fn, interval, options = {}) {
|
|
2868
|
+
const {
|
|
2869
|
+
immediate = true
|
|
2870
|
+
} = options;
|
|
2821
2871
|
const { start } = useTimeoutFn(loop, interval, { immediate: false });
|
|
2822
2872
|
const isActive = reactivity.ref(false);
|
|
2823
2873
|
async function loop() {
|
|
@@ -2835,7 +2885,7 @@ function useTimeoutPoll(fn, interval, timeoutPollOptions) {
|
|
|
2835
2885
|
function pause() {
|
|
2836
2886
|
isActive.value = false;
|
|
2837
2887
|
}
|
|
2838
|
-
if (
|
|
2888
|
+
if (immediate && isClient)
|
|
2839
2889
|
resume();
|
|
2840
2890
|
tryOnScopeDispose(pause);
|
|
2841
2891
|
return {
|
|
@@ -2874,6 +2924,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
2874
2924
|
removeNullishValues = true,
|
|
2875
2925
|
removeFalsyValues = false,
|
|
2876
2926
|
write: enableWrite = true,
|
|
2927
|
+
writeMode = "replace",
|
|
2877
2928
|
window: window2 = defaultWindow
|
|
2878
2929
|
} = options;
|
|
2879
2930
|
if (!window2)
|
|
@@ -2899,8 +2950,8 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
2899
2950
|
const hash = window2.location.hash || "#";
|
|
2900
2951
|
const index = hash.indexOf("?");
|
|
2901
2952
|
if (index > 0)
|
|
2902
|
-
return `${hash.slice(0, index)}${stringified ? `?${stringified}` : ""}`;
|
|
2903
|
-
return `${hash}${stringified ? `?${stringified}` : ""}`;
|
|
2953
|
+
return `${window2.location.search || ""}${hash.slice(0, index)}${stringified ? `?${stringified}` : ""}`;
|
|
2954
|
+
return `${window2.location.search || ""}${hash}${stringified ? `?${stringified}` : ""}`;
|
|
2904
2955
|
}
|
|
2905
2956
|
function read() {
|
|
2906
2957
|
return new URLSearchParams(getRawParams());
|
|
@@ -2929,7 +2980,7 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
2929
2980
|
else
|
|
2930
2981
|
params.set(key, mapEntry);
|
|
2931
2982
|
});
|
|
2932
|
-
write(params);
|
|
2983
|
+
write(params, false);
|
|
2933
2984
|
},
|
|
2934
2985
|
{ deep: true }
|
|
2935
2986
|
);
|
|
@@ -2937,11 +2988,19 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
2937
2988
|
pause();
|
|
2938
2989
|
if (shouldUpdate)
|
|
2939
2990
|
updateState(params);
|
|
2940
|
-
|
|
2941
|
-
window2.history.
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2991
|
+
if (writeMode === "replace") {
|
|
2992
|
+
window2.history.replaceState(
|
|
2993
|
+
window2.history.state,
|
|
2994
|
+
window2.document.title,
|
|
2995
|
+
window2.location.pathname + constructQuery(params)
|
|
2996
|
+
);
|
|
2997
|
+
} else {
|
|
2998
|
+
window2.history.pushState(
|
|
2999
|
+
window2.history.state,
|
|
3000
|
+
window2.document.title,
|
|
3001
|
+
window2.location.pathname + constructQuery(params)
|
|
3002
|
+
);
|
|
3003
|
+
}
|
|
2945
3004
|
resume();
|
|
2946
3005
|
}
|
|
2947
3006
|
function onChanged() {
|
|
@@ -2949,9 +3008,10 @@ function useUrlSearchParams(mode = "history", options = {}) {
|
|
|
2949
3008
|
return;
|
|
2950
3009
|
write(read(), true);
|
|
2951
3010
|
}
|
|
2952
|
-
|
|
3011
|
+
const listenerOptions = { passive: true };
|
|
3012
|
+
useEventListener(window2, "popstate", onChanged, listenerOptions);
|
|
2953
3013
|
if (mode !== "history")
|
|
2954
|
-
useEventListener(window2, "hashchange", onChanged,
|
|
3014
|
+
useEventListener(window2, "hashchange", onChanged, listenerOptions);
|
|
2955
3015
|
const initial = read();
|
|
2956
3016
|
if (initial.keys().next().value)
|
|
2957
3017
|
updateState(initial);
|
|
@@ -2972,6 +3032,7 @@ function useWebSocket(url, options = {}) {
|
|
|
2972
3032
|
onError,
|
|
2973
3033
|
onMessage,
|
|
2974
3034
|
immediate = true,
|
|
3035
|
+
autoConnect = true,
|
|
2975
3036
|
autoClose = true,
|
|
2976
3037
|
protocols = []
|
|
2977
3038
|
} = options;
|
|
@@ -2984,6 +3045,7 @@ function useWebSocket(url, options = {}) {
|
|
|
2984
3045
|
let explicitlyClosed = false;
|
|
2985
3046
|
let retried = 0;
|
|
2986
3047
|
let bufferedData = [];
|
|
3048
|
+
let retryTimeout;
|
|
2987
3049
|
let pongTimeoutWait;
|
|
2988
3050
|
const _sendBuffer = () => {
|
|
2989
3051
|
if (bufferedData.length && wsRef.value && status.value === "OPEN") {
|
|
@@ -2992,12 +3054,19 @@ function useWebSocket(url, options = {}) {
|
|
|
2992
3054
|
bufferedData = [];
|
|
2993
3055
|
}
|
|
2994
3056
|
};
|
|
3057
|
+
const resetRetry = () => {
|
|
3058
|
+
if (retryTimeout != null) {
|
|
3059
|
+
clearTimeout(retryTimeout);
|
|
3060
|
+
retryTimeout = void 0;
|
|
3061
|
+
}
|
|
3062
|
+
};
|
|
2995
3063
|
const resetHeartbeat = () => {
|
|
2996
3064
|
clearTimeout(pongTimeoutWait);
|
|
2997
3065
|
pongTimeoutWait = void 0;
|
|
2998
3066
|
};
|
|
2999
3067
|
const close = (code = 1e3, reason) => {
|
|
3000
|
-
|
|
3068
|
+
resetRetry();
|
|
3069
|
+
if (!isClient && !isWorker || !wsRef.value)
|
|
3001
3070
|
return;
|
|
3002
3071
|
explicitlyClosed = true;
|
|
3003
3072
|
resetHeartbeat();
|
|
@@ -3031,7 +3100,7 @@ function useWebSocket(url, options = {}) {
|
|
|
3031
3100
|
ws.onclose = (ev) => {
|
|
3032
3101
|
status.value = "CLOSED";
|
|
3033
3102
|
onDisconnected == null ? void 0 : onDisconnected(ws, ev);
|
|
3034
|
-
if (!explicitlyClosed && options.autoReconnect && ws === wsRef.value) {
|
|
3103
|
+
if (!explicitlyClosed && options.autoReconnect && (wsRef.value == null || ws === wsRef.value)) {
|
|
3035
3104
|
const {
|
|
3036
3105
|
retries = -1,
|
|
3037
3106
|
delay = 1e3,
|
|
@@ -3039,9 +3108,9 @@ function useWebSocket(url, options = {}) {
|
|
|
3039
3108
|
} = resolveNestedOptions(options.autoReconnect);
|
|
3040
3109
|
if (typeof retries === "number" && (retries < 0 || retried < retries)) {
|
|
3041
3110
|
retried += 1;
|
|
3042
|
-
setTimeout(_init, delay);
|
|
3111
|
+
retryTimeout = setTimeout(_init, delay);
|
|
3043
3112
|
} else if (typeof retries === "function" && retries()) {
|
|
3044
|
-
setTimeout(_init, delay);
|
|
3113
|
+
retryTimeout = setTimeout(_init, delay);
|
|
3045
3114
|
} else {
|
|
3046
3115
|
onFailed == null ? void 0 : onFailed();
|
|
3047
3116
|
}
|
|
@@ -3057,7 +3126,7 @@ function useWebSocket(url, options = {}) {
|
|
|
3057
3126
|
message = DEFAULT_PING_MESSAGE,
|
|
3058
3127
|
responseMessage = message
|
|
3059
3128
|
} = resolveNestedOptions(options.heartbeat);
|
|
3060
|
-
if (e.data === responseMessage)
|
|
3129
|
+
if (e.data === reactivity.toValue(responseMessage))
|
|
3061
3130
|
return;
|
|
3062
3131
|
}
|
|
3063
3132
|
data.value = e.data;
|
|
@@ -3072,7 +3141,7 @@ function useWebSocket(url, options = {}) {
|
|
|
3072
3141
|
} = resolveNestedOptions(options.heartbeat);
|
|
3073
3142
|
const { pause, resume } = useIntervalFn(
|
|
3074
3143
|
() => {
|
|
3075
|
-
send(message, false);
|
|
3144
|
+
send(reactivity.toValue(message), false);
|
|
3076
3145
|
if (pongTimeoutWait != null)
|
|
3077
3146
|
return;
|
|
3078
3147
|
pongTimeoutWait = setTimeout(() => {
|
|
@@ -3088,7 +3157,7 @@ function useWebSocket(url, options = {}) {
|
|
|
3088
3157
|
}
|
|
3089
3158
|
if (autoClose) {
|
|
3090
3159
|
if (isClient)
|
|
3091
|
-
useEventListener("beforeunload", () => close());
|
|
3160
|
+
useEventListener("beforeunload", () => close(), { passive: true });
|
|
3092
3161
|
tryOnScopeDispose(close);
|
|
3093
3162
|
}
|
|
3094
3163
|
const open = () => {
|
|
@@ -3101,7 +3170,8 @@ function useWebSocket(url, options = {}) {
|
|
|
3101
3170
|
};
|
|
3102
3171
|
if (immediate)
|
|
3103
3172
|
open();
|
|
3104
|
-
|
|
3173
|
+
if (autoConnect)
|
|
3174
|
+
reactivity.watch(urlRef, open);
|
|
3105
3175
|
return {
|
|
3106
3176
|
data,
|
|
3107
3177
|
status,
|