@vueuse/shared 10.0.0-beta.3 → 10.0.0-beta.4
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/index.cjs +60 -50
- package/index.d.ts +75 -65
- package/index.iife.js +60 -50
- package/index.iife.min.js +1 -1
- package/index.mjs +59 -52
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -59,9 +59,10 @@ const rand = (min, max) => {
|
|
|
59
59
|
const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
|
|
60
60
|
const isIOS = isClient && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
|
|
61
61
|
|
|
62
|
-
function
|
|
62
|
+
function toValue(r) {
|
|
63
63
|
return typeof r === "function" ? r() : vueDemi.unref(r);
|
|
64
64
|
}
|
|
65
|
+
const resolveUnref = toValue;
|
|
65
66
|
|
|
66
67
|
function createFilterWrapper(filter, fn) {
|
|
67
68
|
function wrapper(...args) {
|
|
@@ -84,8 +85,8 @@ function debounceFilter(ms, options = {}) {
|
|
|
84
85
|
lastRejector = noop;
|
|
85
86
|
};
|
|
86
87
|
const filter = (invoke) => {
|
|
87
|
-
const duration =
|
|
88
|
-
const maxDuration =
|
|
88
|
+
const duration = toValue(ms);
|
|
89
|
+
const maxDuration = toValue(options.maxWait);
|
|
89
90
|
if (timer)
|
|
90
91
|
_clearTimeout(timer);
|
|
91
92
|
if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
|
|
@@ -130,7 +131,7 @@ function throttleFilter(ms, trailing = true, leading = true, rejectOnCancel = fa
|
|
|
130
131
|
}
|
|
131
132
|
};
|
|
132
133
|
const filter = (_invoke) => {
|
|
133
|
-
const duration =
|
|
134
|
+
const duration = toValue(ms);
|
|
134
135
|
const elapsed = Date.now() - lastExec;
|
|
135
136
|
const invoke = () => {
|
|
136
137
|
return lastValue = _invoke();
|
|
@@ -244,6 +245,11 @@ function objectPick(obj, keys, omitUndefined = false) {
|
|
|
244
245
|
return n;
|
|
245
246
|
}, {});
|
|
246
247
|
}
|
|
248
|
+
function objectOmit(obj, keys, omitUndefined = false) {
|
|
249
|
+
return Object.fromEntries(Object.entries(obj).filter(([key, value]) => {
|
|
250
|
+
return (!omitUndefined || value !== void 0) && !keys.includes(key);
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
247
253
|
function objectEntries(obj) {
|
|
248
254
|
return Object.entries(obj);
|
|
249
255
|
}
|
|
@@ -430,7 +436,7 @@ function makeDestructurable(obj, arr) {
|
|
|
430
436
|
}
|
|
431
437
|
|
|
432
438
|
function reactify(fn, options) {
|
|
433
|
-
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? vueDemi.unref :
|
|
439
|
+
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? vueDemi.unref : toValue;
|
|
434
440
|
return function(...args) {
|
|
435
441
|
return vueDemi.computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
|
|
436
442
|
};
|
|
@@ -500,14 +506,22 @@ function reactiveOmit(obj, ...keys) {
|
|
|
500
506
|
const flatKeys = keys.flat();
|
|
501
507
|
const predicate = flatKeys[0];
|
|
502
508
|
return reactiveComputed(
|
|
503
|
-
() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter(([k, v]) => !predicate(
|
|
509
|
+
() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter((e) => !flatKeys.includes(e[0])))
|
|
504
510
|
);
|
|
505
511
|
}
|
|
506
512
|
|
|
513
|
+
function toRef(...args) {
|
|
514
|
+
if (args.length !== 1)
|
|
515
|
+
return vueDemi.toRef(...args);
|
|
516
|
+
const r = args[0];
|
|
517
|
+
return typeof r === "function" ? vueDemi.readonly(vueDemi.customRef(() => ({ get: r, set: noop }))) : vueDemi.ref(r);
|
|
518
|
+
}
|
|
519
|
+
const resolveRef = toRef;
|
|
520
|
+
|
|
507
521
|
function reactivePick(obj, ...keys) {
|
|
508
522
|
const flatKeys = keys.flat();
|
|
509
523
|
const predicate = flatKeys[0];
|
|
510
|
-
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter(([k, v]) => predicate(
|
|
524
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter(([k, v]) => predicate(toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
|
|
511
525
|
}
|
|
512
526
|
|
|
513
527
|
function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
@@ -517,7 +531,7 @@ function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
|
517
531
|
const resetAfter = () => setTimeout(() => {
|
|
518
532
|
value = defaultValue;
|
|
519
533
|
trigger();
|
|
520
|
-
},
|
|
534
|
+
}, toValue(afterMs));
|
|
521
535
|
tryOnScopeDispose(() => {
|
|
522
536
|
clearTimeout(timer);
|
|
523
537
|
});
|
|
@@ -634,10 +648,6 @@ function refWithControl(initial, options = {}) {
|
|
|
634
648
|
}
|
|
635
649
|
const controlledRef = refWithControl;
|
|
636
650
|
|
|
637
|
-
function resolveRef(r) {
|
|
638
|
-
return typeof r === "function" ? vueDemi.computed(r) : vueDemi.ref(r);
|
|
639
|
-
}
|
|
640
|
-
|
|
641
651
|
function set(...args) {
|
|
642
652
|
if (args.length === 2) {
|
|
643
653
|
const [ref, value] = args;
|
|
@@ -795,7 +805,7 @@ function createUntil(r, isNot = false) {
|
|
|
795
805
|
const promises = [watcher];
|
|
796
806
|
if (timeout != null) {
|
|
797
807
|
promises.push(
|
|
798
|
-
promiseTimeout(timeout, throwOnTimeout).then(() =>
|
|
808
|
+
promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => stop == null ? void 0 : stop())
|
|
799
809
|
);
|
|
800
810
|
}
|
|
801
811
|
return Promise.race(promises);
|
|
@@ -824,9 +834,9 @@ function createUntil(r, isNot = false) {
|
|
|
824
834
|
const promises = [watcher];
|
|
825
835
|
if (timeout != null) {
|
|
826
836
|
promises.push(
|
|
827
|
-
promiseTimeout(timeout, throwOnTimeout).then(() =>
|
|
837
|
+
promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => {
|
|
828
838
|
stop == null ? void 0 : stop();
|
|
829
|
-
return
|
|
839
|
+
return toValue(r);
|
|
830
840
|
})
|
|
831
841
|
);
|
|
832
842
|
}
|
|
@@ -847,7 +857,7 @@ function createUntil(r, isNot = false) {
|
|
|
847
857
|
function toContains(value, options) {
|
|
848
858
|
return toMatch((v) => {
|
|
849
859
|
const array = Array.from(v);
|
|
850
|
-
return array.includes(value) || array.includes(
|
|
860
|
+
return array.includes(value) || array.includes(toValue(value));
|
|
851
861
|
}, options);
|
|
852
862
|
}
|
|
853
863
|
function changed(options) {
|
|
@@ -860,7 +870,7 @@ function createUntil(r, isNot = false) {
|
|
|
860
870
|
return count >= n;
|
|
861
871
|
}, options);
|
|
862
872
|
}
|
|
863
|
-
if (Array.isArray(
|
|
873
|
+
if (Array.isArray(toValue(r))) {
|
|
864
874
|
const instance = {
|
|
865
875
|
toMatch,
|
|
866
876
|
toContains,
|
|
@@ -904,27 +914,27 @@ function useArrayDifference(...args) {
|
|
|
904
914
|
const key = compareFn;
|
|
905
915
|
compareFn = (value, othVal) => value[key] === othVal[key];
|
|
906
916
|
}
|
|
907
|
-
return vueDemi.computed(() =>
|
|
917
|
+
return vueDemi.computed(() => toValue(list).filter((x) => toValue(values).findIndex((y) => compareFn(x, y)) === -1));
|
|
908
918
|
}
|
|
909
919
|
|
|
910
920
|
function useArrayEvery(list, fn) {
|
|
911
|
-
return vueDemi.computed(() =>
|
|
921
|
+
return vueDemi.computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
|
|
912
922
|
}
|
|
913
923
|
|
|
914
924
|
function useArrayFilter(list, fn) {
|
|
915
|
-
return vueDemi.computed(() =>
|
|
925
|
+
return vueDemi.computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
|
|
916
926
|
}
|
|
917
927
|
|
|
918
928
|
function useArrayFind(list, fn) {
|
|
919
929
|
return vueDemi.computed(
|
|
920
|
-
() =>
|
|
921
|
-
|
|
930
|
+
() => toValue(
|
|
931
|
+
toValue(list).find((element, index, array) => fn(toValue(element), index, array))
|
|
922
932
|
)
|
|
923
933
|
);
|
|
924
934
|
}
|
|
925
935
|
|
|
926
936
|
function useArrayFindIndex(list, fn) {
|
|
927
|
-
return vueDemi.computed(() =>
|
|
937
|
+
return vueDemi.computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
|
|
928
938
|
}
|
|
929
939
|
|
|
930
940
|
function findLast(arr, cb) {
|
|
@@ -937,8 +947,8 @@ function findLast(arr, cb) {
|
|
|
937
947
|
}
|
|
938
948
|
function useArrayFindLast(list, fn) {
|
|
939
949
|
return vueDemi.computed(
|
|
940
|
-
() =>
|
|
941
|
-
!Array.prototype.findLast ? findLast(
|
|
950
|
+
() => toValue(
|
|
951
|
+
!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))
|
|
942
952
|
)
|
|
943
953
|
);
|
|
944
954
|
}
|
|
@@ -958,34 +968,34 @@ function useArrayIncludes(...args) {
|
|
|
958
968
|
}
|
|
959
969
|
if (typeof comparator === "string") {
|
|
960
970
|
const key = comparator;
|
|
961
|
-
comparator = (element, value2) => element[key] ===
|
|
971
|
+
comparator = (element, value2) => element[key] === toValue(value2);
|
|
962
972
|
}
|
|
963
|
-
comparator = comparator != null ? comparator : (element, value2) => element ===
|
|
973
|
+
comparator = comparator != null ? comparator : (element, value2) => element === toValue(value2);
|
|
964
974
|
return vueDemi.computed(
|
|
965
|
-
() =>
|
|
966
|
-
(element, index, array) => comparator(
|
|
975
|
+
() => toValue(list).slice(formIndex).some(
|
|
976
|
+
(element, index, array) => comparator(toValue(element), toValue(value), index, toValue(array))
|
|
967
977
|
)
|
|
968
978
|
);
|
|
969
979
|
}
|
|
970
980
|
|
|
971
981
|
function useArrayJoin(list, separator) {
|
|
972
|
-
return vueDemi.computed(() =>
|
|
982
|
+
return vueDemi.computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
|
|
973
983
|
}
|
|
974
984
|
|
|
975
985
|
function useArrayMap(list, fn) {
|
|
976
|
-
return vueDemi.computed(() =>
|
|
986
|
+
return vueDemi.computed(() => toValue(list).map((i) => toValue(i)).map(fn));
|
|
977
987
|
}
|
|
978
988
|
|
|
979
989
|
function useArrayReduce(list, reducer, ...args) {
|
|
980
|
-
const reduceCallback = (sum, value, index) => reducer(
|
|
990
|
+
const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
|
|
981
991
|
return vueDemi.computed(() => {
|
|
982
|
-
const resolved =
|
|
983
|
-
return args.length ? resolved.reduce(reduceCallback,
|
|
992
|
+
const resolved = toValue(list);
|
|
993
|
+
return args.length ? resolved.reduce(reduceCallback, toValue(args[0])) : resolved.reduce(reduceCallback);
|
|
984
994
|
});
|
|
985
995
|
}
|
|
986
996
|
|
|
987
997
|
function useArraySome(list, fn) {
|
|
988
|
-
return vueDemi.computed(() =>
|
|
998
|
+
return vueDemi.computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
|
|
989
999
|
}
|
|
990
1000
|
|
|
991
1001
|
function uniq(array) {
|
|
@@ -1000,7 +1010,7 @@ function uniqueElementsBy(array, fn) {
|
|
|
1000
1010
|
}
|
|
1001
1011
|
function useArrayUnique(list, compareFn) {
|
|
1002
1012
|
return vueDemi.computed(() => {
|
|
1003
|
-
const resolvedList =
|
|
1013
|
+
const resolvedList = toValue(list).map((element) => toValue(element));
|
|
1004
1014
|
return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
|
|
1005
1015
|
});
|
|
1006
1016
|
}
|
|
@@ -1088,7 +1098,7 @@ function normalizeDate(date) {
|
|
|
1088
1098
|
return new Date(date);
|
|
1089
1099
|
}
|
|
1090
1100
|
function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
|
|
1091
|
-
return vueDemi.computed(() => formatDate(normalizeDate(
|
|
1101
|
+
return vueDemi.computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
|
|
1092
1102
|
}
|
|
1093
1103
|
|
|
1094
1104
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
@@ -1109,7 +1119,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
1109
1119
|
clean();
|
|
1110
1120
|
}
|
|
1111
1121
|
function resume() {
|
|
1112
|
-
const intervalValue =
|
|
1122
|
+
const intervalValue = toValue(interval);
|
|
1113
1123
|
if (intervalValue <= 0)
|
|
1114
1124
|
return;
|
|
1115
1125
|
isActive.value = true;
|
|
@@ -1214,7 +1224,7 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1214
1224
|
isPending.value = false;
|
|
1215
1225
|
timer = null;
|
|
1216
1226
|
cb(...args);
|
|
1217
|
-
},
|
|
1227
|
+
}, toValue(interval));
|
|
1218
1228
|
}
|
|
1219
1229
|
if (immediate) {
|
|
1220
1230
|
isPending.value = true;
|
|
@@ -1272,7 +1282,7 @@ function useToNumber(value, options = {}) {
|
|
|
1272
1282
|
nanToZero
|
|
1273
1283
|
} = options;
|
|
1274
1284
|
return vueDemi.computed(() => {
|
|
1275
|
-
let resolved =
|
|
1285
|
+
let resolved = toValue(value);
|
|
1276
1286
|
if (typeof resolved === "string")
|
|
1277
1287
|
resolved = Number[method](resolved, radix);
|
|
1278
1288
|
if (nanToZero && isNaN(resolved))
|
|
@@ -1282,7 +1292,7 @@ function useToNumber(value, options = {}) {
|
|
|
1282
1292
|
}
|
|
1283
1293
|
|
|
1284
1294
|
function useToString(value) {
|
|
1285
|
-
return vueDemi.computed(() => `${
|
|
1295
|
+
return vueDemi.computed(() => `${toValue(value)}`);
|
|
1286
1296
|
}
|
|
1287
1297
|
|
|
1288
1298
|
function useToggle(initialValue = false, options = {}) {
|
|
@@ -1297,8 +1307,8 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1297
1307
|
_value.value = value;
|
|
1298
1308
|
return _value.value;
|
|
1299
1309
|
} else {
|
|
1300
|
-
const truthy =
|
|
1301
|
-
_value.value = _value.value === truthy ?
|
|
1310
|
+
const truthy = toValue(truthyValue);
|
|
1311
|
+
_value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
|
|
1302
1312
|
return _value.value;
|
|
1303
1313
|
}
|
|
1304
1314
|
}
|
|
@@ -1310,7 +1320,7 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1310
1320
|
|
|
1311
1321
|
function watchArray(source, cb, options) {
|
|
1312
1322
|
let oldList = (options == null ? void 0 : options.immediate) ? [] : [
|
|
1313
|
-
...source instanceof Function ? source() : Array.isArray(source) ? source :
|
|
1323
|
+
...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)
|
|
1314
1324
|
];
|
|
1315
1325
|
return vueDemi.watch(source, (newList, _, onCleanup) => {
|
|
1316
1326
|
const oldListRemains = new Array(oldList.length);
|
|
@@ -1390,7 +1400,7 @@ function watchAtMost(source, cb, options) {
|
|
|
1390
1400
|
source,
|
|
1391
1401
|
(...args) => {
|
|
1392
1402
|
current.value += 1;
|
|
1393
|
-
if (current.value >=
|
|
1403
|
+
if (current.value >= toValue(count))
|
|
1394
1404
|
vueDemi.nextTick(() => stop());
|
|
1395
1405
|
cb(...args);
|
|
1396
1406
|
},
|
|
@@ -1765,11 +1775,8 @@ function getWatchSources(sources) {
|
|
|
1765
1775
|
if (vueDemi.isReactive(sources))
|
|
1766
1776
|
return sources;
|
|
1767
1777
|
if (Array.isArray(sources))
|
|
1768
|
-
return sources.map((item) =>
|
|
1769
|
-
return
|
|
1770
|
-
}
|
|
1771
|
-
function getOneWatchSource(source) {
|
|
1772
|
-
return typeof source === "function" ? source() : vueDemi.unref(source);
|
|
1778
|
+
return sources.map((item) => toValue(item));
|
|
1779
|
+
return toValue(sources);
|
|
1773
1780
|
}
|
|
1774
1781
|
function getOldValue(source) {
|
|
1775
1782
|
return Array.isArray(source) ? source.map(() => void 0) : void 0;
|
|
@@ -1832,6 +1839,7 @@ exports.noop = noop;
|
|
|
1832
1839
|
exports.normalizeDate = normalizeDate;
|
|
1833
1840
|
exports.now = now;
|
|
1834
1841
|
exports.objectEntries = objectEntries;
|
|
1842
|
+
exports.objectOmit = objectOmit;
|
|
1835
1843
|
exports.objectPick = objectPick;
|
|
1836
1844
|
exports.pausableFilter = pausableFilter;
|
|
1837
1845
|
exports.pausableWatch = watchPausable;
|
|
@@ -1857,7 +1865,9 @@ exports.throttledRef = refThrottled;
|
|
|
1857
1865
|
exports.throttledWatch = watchThrottled;
|
|
1858
1866
|
exports.timestamp = timestamp;
|
|
1859
1867
|
exports.toReactive = toReactive;
|
|
1868
|
+
exports.toRef = toRef;
|
|
1860
1869
|
exports.toRefs = toRefs;
|
|
1870
|
+
exports.toValue = toValue;
|
|
1861
1871
|
exports.tryOnBeforeMount = tryOnBeforeMount;
|
|
1862
1872
|
exports.tryOnBeforeUnmount = tryOnBeforeUnmount;
|
|
1863
1873
|
exports.tryOnMounted = tryOnMounted;
|