@vueuse/shared 8.9.4 → 9.0.0-beta.2
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 +87 -51
- package/index.d.ts +87 -67
- package/index.iife.js +88 -69
- package/index.iife.min.js +1 -1
- package/index.mjs +81 -47
- package/package.json +1 -13
package/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var vueDemi = require('vue-demi');
|
|
6
|
+
var shared = require('@vueuse/shared');
|
|
6
7
|
|
|
7
8
|
var __defProp$9 = Object.defineProperty;
|
|
8
9
|
var __defProps$6 = Object.defineProperties;
|
|
@@ -60,6 +61,10 @@ const rand = (min, max) => {
|
|
|
60
61
|
};
|
|
61
62
|
const isIOS = isClient && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
|
|
62
63
|
|
|
64
|
+
function resolveUnref(r) {
|
|
65
|
+
return typeof r === "function" ? r() : vueDemi.unref(r);
|
|
66
|
+
}
|
|
67
|
+
|
|
63
68
|
function createFilterWrapper(filter, fn) {
|
|
64
69
|
function wrapper(...args) {
|
|
65
70
|
filter(() => fn.apply(this, args), { fn, thisArg: this, args });
|
|
@@ -73,8 +78,8 @@ function debounceFilter(ms, options = {}) {
|
|
|
73
78
|
let timer;
|
|
74
79
|
let maxTimer;
|
|
75
80
|
const filter = (invoke) => {
|
|
76
|
-
const duration =
|
|
77
|
-
const maxDuration =
|
|
81
|
+
const duration = resolveUnref(ms);
|
|
82
|
+
const maxDuration = resolveUnref(options.maxWait);
|
|
78
83
|
if (timer)
|
|
79
84
|
clearTimeout(timer);
|
|
80
85
|
if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
|
|
@@ -112,7 +117,7 @@ function throttleFilter(ms, trailing = true, leading = true) {
|
|
|
112
117
|
}
|
|
113
118
|
};
|
|
114
119
|
const filter = (invoke) => {
|
|
115
|
-
const duration =
|
|
120
|
+
const duration = resolveUnref(ms);
|
|
116
121
|
const elapsed = Date.now() - lastExec;
|
|
117
122
|
clear();
|
|
118
123
|
if (duration <= 0) {
|
|
@@ -357,18 +362,6 @@ function isDefined(v) {
|
|
|
357
362
|
return vueDemi.unref(v) != null;
|
|
358
363
|
}
|
|
359
364
|
|
|
360
|
-
function logicAnd(...args) {
|
|
361
|
-
return vueDemi.computed(() => args.every((i) => vueDemi.unref(i)));
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function logicNot(v) {
|
|
365
|
-
return vueDemi.computed(() => !vueDemi.unref(v));
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
function logicOr(...args) {
|
|
369
|
-
return vueDemi.computed(() => args.some((i) => vueDemi.unref(i)));
|
|
370
|
-
}
|
|
371
|
-
|
|
372
365
|
var __defProp$8 = Object.defineProperty;
|
|
373
366
|
var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
|
|
374
367
|
var __hasOwnProp$a = Object.prototype.hasOwnProperty;
|
|
@@ -406,17 +399,20 @@ function makeDestructurable(obj, arr) {
|
|
|
406
399
|
}
|
|
407
400
|
}
|
|
408
401
|
|
|
409
|
-
function reactify(fn) {
|
|
402
|
+
function reactify(fn, options) {
|
|
403
|
+
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? vueDemi.unref : resolveUnref;
|
|
410
404
|
return function(...args) {
|
|
411
|
-
return vueDemi.computed(() => fn.apply(this, args.map((i) =>
|
|
405
|
+
return vueDemi.computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
|
|
412
406
|
};
|
|
413
407
|
}
|
|
414
408
|
|
|
415
409
|
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
416
410
|
let keys = [];
|
|
411
|
+
let options;
|
|
417
412
|
if (Array.isArray(optionsOrKeys)) {
|
|
418
413
|
keys = optionsOrKeys;
|
|
419
414
|
} else {
|
|
415
|
+
options = optionsOrKeys;
|
|
420
416
|
const { includeOwnProperties = true } = optionsOrKeys;
|
|
421
417
|
keys.push(...Object.keys(obj));
|
|
422
418
|
if (includeOwnProperties)
|
|
@@ -426,7 +422,7 @@ function reactifyObject(obj, optionsOrKeys = {}) {
|
|
|
426
422
|
const value = obj[key];
|
|
427
423
|
return [
|
|
428
424
|
key,
|
|
429
|
-
typeof value === "function" ? reactify(value.bind(obj)) : value
|
|
425
|
+
typeof value === "function" ? reactify(value.bind(obj), options) : value
|
|
430
426
|
];
|
|
431
427
|
}));
|
|
432
428
|
}
|
|
@@ -485,7 +481,7 @@ function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
|
485
481
|
const resetAfter = () => setTimeout(() => {
|
|
486
482
|
value = defaultValue;
|
|
487
483
|
trigger();
|
|
488
|
-
},
|
|
484
|
+
}, shared.resolveUnref(afterMs));
|
|
489
485
|
tryOnScopeDispose(() => {
|
|
490
486
|
clearTimeout(timer);
|
|
491
487
|
});
|
|
@@ -531,7 +527,7 @@ function refDefault(source, defaultValue) {
|
|
|
531
527
|
});
|
|
532
528
|
}
|
|
533
529
|
|
|
534
|
-
function useThrottleFn(fn, ms = 200, trailing =
|
|
530
|
+
function useThrottleFn(fn, ms = 200, trailing = false, leading = true) {
|
|
535
531
|
return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
|
|
536
532
|
}
|
|
537
533
|
|
|
@@ -598,10 +594,6 @@ function resolveRef(r) {
|
|
|
598
594
|
return typeof r === "function" ? vueDemi.computed(r) : vueDemi.ref(r);
|
|
599
595
|
}
|
|
600
596
|
|
|
601
|
-
function resolveUnref(r) {
|
|
602
|
-
return typeof r === "function" ? r() : vueDemi.unref(r);
|
|
603
|
-
}
|
|
604
|
-
|
|
605
597
|
function set(...args) {
|
|
606
598
|
if (args.length === 2) {
|
|
607
599
|
const [ref, value] = args;
|
|
@@ -618,22 +610,27 @@ function set(...args) {
|
|
|
618
610
|
}
|
|
619
611
|
|
|
620
612
|
function syncRef(left, right, options = {}) {
|
|
613
|
+
var _a, _b;
|
|
621
614
|
const {
|
|
622
615
|
flush = "sync",
|
|
623
616
|
deep = false,
|
|
624
617
|
immediate = true,
|
|
625
|
-
direction = "both"
|
|
618
|
+
direction = "both",
|
|
619
|
+
transform = {}
|
|
626
620
|
} = options;
|
|
627
|
-
let
|
|
621
|
+
let watchLeft;
|
|
622
|
+
let watchRight;
|
|
623
|
+
const transformLTR = (_a = transform.ltr) != null ? _a : (v) => v;
|
|
624
|
+
const transformRTL = (_b = transform.rtl) != null ? _b : (v) => v;
|
|
628
625
|
if (direction === "both" || direction === "ltr") {
|
|
629
|
-
|
|
626
|
+
watchLeft = vueDemi.watch(left, (newValue) => right.value = transformLTR(newValue), { flush, deep, immediate });
|
|
630
627
|
}
|
|
631
628
|
if (direction === "both" || direction === "rtl") {
|
|
632
|
-
|
|
629
|
+
watchRight = vueDemi.watch(right, (newValue) => left.value = transformRTL(newValue), { flush, deep, immediate });
|
|
633
630
|
}
|
|
634
631
|
return () => {
|
|
635
|
-
|
|
636
|
-
|
|
632
|
+
watchLeft == null ? void 0 : watchLeft();
|
|
633
|
+
watchRight == null ? void 0 : watchRight();
|
|
637
634
|
};
|
|
638
635
|
}
|
|
639
636
|
|
|
@@ -738,7 +735,7 @@ function until(r) {
|
|
|
738
735
|
});
|
|
739
736
|
const promises = [watcher];
|
|
740
737
|
if (timeout != null) {
|
|
741
|
-
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() =>
|
|
738
|
+
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => resolveUnref(r)).finally(() => stop == null ? void 0 : stop()));
|
|
742
739
|
}
|
|
743
740
|
return Promise.race(promises);
|
|
744
741
|
}
|
|
@@ -761,9 +758,9 @@ function until(r) {
|
|
|
761
758
|
});
|
|
762
759
|
const promises = [watcher];
|
|
763
760
|
if (timeout != null) {
|
|
764
|
-
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() =>
|
|
761
|
+
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => resolveUnref(r)).finally(() => {
|
|
765
762
|
stop == null ? void 0 : stop();
|
|
766
|
-
return
|
|
763
|
+
return resolveUnref(r);
|
|
767
764
|
}));
|
|
768
765
|
}
|
|
769
766
|
return Promise.race(promises);
|
|
@@ -783,7 +780,7 @@ function until(r) {
|
|
|
783
780
|
function toContains(value, options) {
|
|
784
781
|
return toMatch((v) => {
|
|
785
782
|
const array = Array.from(v);
|
|
786
|
-
return array.includes(value) || array.includes(
|
|
783
|
+
return array.includes(value) || array.includes(resolveUnref(value));
|
|
787
784
|
}, options);
|
|
788
785
|
}
|
|
789
786
|
function changed(options) {
|
|
@@ -796,7 +793,7 @@ function until(r) {
|
|
|
796
793
|
return count >= n;
|
|
797
794
|
}, options);
|
|
798
795
|
}
|
|
799
|
-
if (Array.isArray(
|
|
796
|
+
if (Array.isArray(resolveUnref(r))) {
|
|
800
797
|
const instance = {
|
|
801
798
|
toMatch,
|
|
802
799
|
toContains,
|
|
@@ -827,6 +824,42 @@ function until(r) {
|
|
|
827
824
|
}
|
|
828
825
|
}
|
|
829
826
|
|
|
827
|
+
function useArrayEvery(list, fn) {
|
|
828
|
+
return vueDemi.computed(() => shared.resolveUnref(list).every((element, index, array) => fn(shared.resolveUnref(element), index, array)));
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function useArrayFilter(list, fn) {
|
|
832
|
+
return vueDemi.computed(() => shared.resolveUnref(list).map((i) => shared.resolveUnref(i)).filter(fn));
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
function useArrayFind(list, fn) {
|
|
836
|
+
return vueDemi.computed(() => shared.resolveUnref(shared.resolveUnref(list).find((element, index, array) => fn(shared.resolveUnref(element), index, array))));
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
function useArrayFindIndex(list, fn) {
|
|
840
|
+
return vueDemi.computed(() => shared.resolveUnref(list).findIndex((element, index, array) => fn(shared.resolveUnref(element), index, array)));
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
function useArrayJoin(list, separator) {
|
|
844
|
+
return vueDemi.computed(() => shared.resolveUnref(list).map((i) => shared.resolveUnref(i)).join(shared.resolveUnref(separator)));
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
function useArrayMap(list, fn) {
|
|
848
|
+
return vueDemi.computed(() => shared.resolveUnref(list).map((i) => shared.resolveUnref(i)).map(fn));
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
function useArrayReduce(list, reducer, ...args) {
|
|
852
|
+
const reduceCallback = (sum, value, index) => reducer(shared.resolveUnref(sum), shared.resolveUnref(value), index);
|
|
853
|
+
return vueDemi.computed(() => {
|
|
854
|
+
const resolved = shared.resolveUnref(list);
|
|
855
|
+
return args.length ? resolved.reduce(reduceCallback, shared.resolveUnref(args[0])) : resolved.reduce(reduceCallback);
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
function useArraySome(list, fn) {
|
|
860
|
+
return vueDemi.computed(() => shared.resolveUnref(list).some((element, index, array) => fn(shared.resolveUnref(element), index, array)));
|
|
861
|
+
}
|
|
862
|
+
|
|
830
863
|
function useCounter(initialValue = 0, options = {}) {
|
|
831
864
|
const count = vueDemi.ref(initialValue);
|
|
832
865
|
const {
|
|
@@ -893,7 +926,7 @@ const normalizeDate = (date) => {
|
|
|
893
926
|
return new Date(date);
|
|
894
927
|
};
|
|
895
928
|
function useDateFormat(date, formatStr = "HH:mm:ss") {
|
|
896
|
-
return vueDemi.computed(() => formatDate(normalizeDate(
|
|
929
|
+
return vueDemi.computed(() => formatDate(normalizeDate(shared.resolveUnref(date)), shared.resolveUnref(formatStr)));
|
|
897
930
|
}
|
|
898
931
|
|
|
899
932
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
@@ -920,7 +953,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
920
953
|
if (immediateCallback)
|
|
921
954
|
cb();
|
|
922
955
|
clean();
|
|
923
|
-
timer = setInterval(cb,
|
|
956
|
+
timer = setInterval(cb, resolveUnref(interval));
|
|
924
957
|
}
|
|
925
958
|
if (immediate && isClient)
|
|
926
959
|
resume();
|
|
@@ -1001,7 +1034,7 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1001
1034
|
isPending.value = false;
|
|
1002
1035
|
timer = null;
|
|
1003
1036
|
cb(...args);
|
|
1004
|
-
},
|
|
1037
|
+
}, shared.resolveUnref(interval));
|
|
1005
1038
|
}
|
|
1006
1039
|
if (immediate) {
|
|
1007
1040
|
isPending.value = true;
|
|
@@ -1053,20 +1086,21 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1053
1086
|
falsyValue = false
|
|
1054
1087
|
} = options;
|
|
1055
1088
|
const valueIsRef = vueDemi.isRef(initialValue);
|
|
1056
|
-
const
|
|
1089
|
+
const _value = vueDemi.ref(initialValue);
|
|
1057
1090
|
function toggle(value) {
|
|
1058
1091
|
if (arguments.length) {
|
|
1059
|
-
|
|
1060
|
-
return
|
|
1092
|
+
_value.value = value;
|
|
1093
|
+
return _value.value;
|
|
1061
1094
|
} else {
|
|
1062
|
-
|
|
1063
|
-
|
|
1095
|
+
const truthy = resolveUnref(truthyValue);
|
|
1096
|
+
_value.value = _value.value === truthy ? resolveUnref(falsyValue) : truthy;
|
|
1097
|
+
return _value.value;
|
|
1064
1098
|
}
|
|
1065
1099
|
}
|
|
1066
1100
|
if (valueIsRef)
|
|
1067
1101
|
return toggle;
|
|
1068
1102
|
else
|
|
1069
|
-
return [
|
|
1103
|
+
return [_value, toggle];
|
|
1070
1104
|
}
|
|
1071
1105
|
|
|
1072
1106
|
function watchArray(source, cb, options) {
|
|
@@ -1142,7 +1176,7 @@ function watchAtMost(source, cb, options) {
|
|
|
1142
1176
|
const current = vueDemi.ref(0);
|
|
1143
1177
|
const stop = watchWithFilter(source, (...args) => {
|
|
1144
1178
|
current.value += 1;
|
|
1145
|
-
if (current.value >=
|
|
1179
|
+
if (current.value >= resolveUnref(count))
|
|
1146
1180
|
vueDemi.nextTick(() => stop());
|
|
1147
1181
|
cb(...args);
|
|
1148
1182
|
}, watchOptions);
|
|
@@ -1444,7 +1478,6 @@ function whenever(source, cb, options) {
|
|
|
1444
1478
|
}
|
|
1445
1479
|
|
|
1446
1480
|
exports.__onlyVue3 = __onlyVue3;
|
|
1447
|
-
exports.and = logicAnd;
|
|
1448
1481
|
exports.assert = assert;
|
|
1449
1482
|
exports.autoResetRef = refAutoReset;
|
|
1450
1483
|
exports.bypassFilter = bypassFilter;
|
|
@@ -1483,16 +1516,11 @@ exports.isNumber = isNumber;
|
|
|
1483
1516
|
exports.isObject = isObject;
|
|
1484
1517
|
exports.isString = isString;
|
|
1485
1518
|
exports.isWindow = isWindow;
|
|
1486
|
-
exports.logicAnd = logicAnd;
|
|
1487
|
-
exports.logicNot = logicNot;
|
|
1488
|
-
exports.logicOr = logicOr;
|
|
1489
1519
|
exports.makeDestructurable = makeDestructurable;
|
|
1490
1520
|
exports.noop = noop;
|
|
1491
1521
|
exports.normalizeDate = normalizeDate;
|
|
1492
|
-
exports.not = logicNot;
|
|
1493
1522
|
exports.now = now;
|
|
1494
1523
|
exports.objectPick = objectPick;
|
|
1495
|
-
exports.or = logicOr;
|
|
1496
1524
|
exports.pausableFilter = pausableFilter;
|
|
1497
1525
|
exports.pausableWatch = watchPausable;
|
|
1498
1526
|
exports.promiseTimeout = promiseTimeout;
|
|
@@ -1524,6 +1552,14 @@ exports.tryOnMounted = tryOnMounted;
|
|
|
1524
1552
|
exports.tryOnScopeDispose = tryOnScopeDispose;
|
|
1525
1553
|
exports.tryOnUnmounted = tryOnUnmounted;
|
|
1526
1554
|
exports.until = until;
|
|
1555
|
+
exports.useArrayEvery = useArrayEvery;
|
|
1556
|
+
exports.useArrayFilter = useArrayFilter;
|
|
1557
|
+
exports.useArrayFind = useArrayFind;
|
|
1558
|
+
exports.useArrayFindIndex = useArrayFindIndex;
|
|
1559
|
+
exports.useArrayJoin = useArrayJoin;
|
|
1560
|
+
exports.useArrayMap = useArrayMap;
|
|
1561
|
+
exports.useArrayReduce = useArrayReduce;
|
|
1562
|
+
exports.useArraySome = useArraySome;
|
|
1527
1563
|
exports.useCounter = useCounter;
|
|
1528
1564
|
exports.useDateFormat = useDateFormat;
|
|
1529
1565
|
exports.useDebounce = refDebounced;
|