@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.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { shallowRef, watchEffect, readonly,
|
|
1
|
+
import { shallowRef, watchEffect, readonly, unref, ref, isVue3, watch, customRef, effectScope, provide, inject, getCurrentScope, onScopeDispose, isRef, computed, reactive, toRefs as toRefs$1, toRef, isVue2, set as set$1, getCurrentInstance, onBeforeMount, nextTick, onBeforeUnmount, onMounted, onUnmounted, isReactive } from 'vue-demi';
|
|
2
|
+
import { resolveUnref as resolveUnref$1 } from '@vueuse/shared';
|
|
2
3
|
|
|
3
4
|
var __defProp$9 = Object.defineProperty;
|
|
4
5
|
var __defProps$6 = Object.defineProperties;
|
|
@@ -56,6 +57,10 @@ const rand = (min, max) => {
|
|
|
56
57
|
};
|
|
57
58
|
const isIOS = isClient && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
|
|
58
59
|
|
|
60
|
+
function resolveUnref(r) {
|
|
61
|
+
return typeof r === "function" ? r() : unref(r);
|
|
62
|
+
}
|
|
63
|
+
|
|
59
64
|
function createFilterWrapper(filter, fn) {
|
|
60
65
|
function wrapper(...args) {
|
|
61
66
|
filter(() => fn.apply(this, args), { fn, thisArg: this, args });
|
|
@@ -69,8 +74,8 @@ function debounceFilter(ms, options = {}) {
|
|
|
69
74
|
let timer;
|
|
70
75
|
let maxTimer;
|
|
71
76
|
const filter = (invoke) => {
|
|
72
|
-
const duration =
|
|
73
|
-
const maxDuration =
|
|
77
|
+
const duration = resolveUnref(ms);
|
|
78
|
+
const maxDuration = resolveUnref(options.maxWait);
|
|
74
79
|
if (timer)
|
|
75
80
|
clearTimeout(timer);
|
|
76
81
|
if (duration <= 0 || maxDuration !== void 0 && maxDuration <= 0) {
|
|
@@ -108,7 +113,7 @@ function throttleFilter(ms, trailing = true, leading = true) {
|
|
|
108
113
|
}
|
|
109
114
|
};
|
|
110
115
|
const filter = (invoke) => {
|
|
111
|
-
const duration =
|
|
116
|
+
const duration = resolveUnref(ms);
|
|
112
117
|
const elapsed = Date.now() - lastExec;
|
|
113
118
|
clear();
|
|
114
119
|
if (duration <= 0) {
|
|
@@ -353,18 +358,6 @@ function isDefined(v) {
|
|
|
353
358
|
return unref(v) != null;
|
|
354
359
|
}
|
|
355
360
|
|
|
356
|
-
function logicAnd(...args) {
|
|
357
|
-
return computed(() => args.every((i) => unref(i)));
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
function logicNot(v) {
|
|
361
|
-
return computed(() => !unref(v));
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function logicOr(...args) {
|
|
365
|
-
return computed(() => args.some((i) => unref(i)));
|
|
366
|
-
}
|
|
367
|
-
|
|
368
361
|
var __defProp$8 = Object.defineProperty;
|
|
369
362
|
var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
|
|
370
363
|
var __hasOwnProp$a = Object.prototype.hasOwnProperty;
|
|
@@ -402,17 +395,20 @@ function makeDestructurable(obj, arr) {
|
|
|
402
395
|
}
|
|
403
396
|
}
|
|
404
397
|
|
|
405
|
-
function reactify(fn) {
|
|
398
|
+
function reactify(fn, options) {
|
|
399
|
+
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? unref : resolveUnref;
|
|
406
400
|
return function(...args) {
|
|
407
|
-
return computed(() => fn.apply(this, args.map((i) =>
|
|
401
|
+
return computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
|
|
408
402
|
};
|
|
409
403
|
}
|
|
410
404
|
|
|
411
405
|
function reactifyObject(obj, optionsOrKeys = {}) {
|
|
412
406
|
let keys = [];
|
|
407
|
+
let options;
|
|
413
408
|
if (Array.isArray(optionsOrKeys)) {
|
|
414
409
|
keys = optionsOrKeys;
|
|
415
410
|
} else {
|
|
411
|
+
options = optionsOrKeys;
|
|
416
412
|
const { includeOwnProperties = true } = optionsOrKeys;
|
|
417
413
|
keys.push(...Object.keys(obj));
|
|
418
414
|
if (includeOwnProperties)
|
|
@@ -422,7 +418,7 @@ function reactifyObject(obj, optionsOrKeys = {}) {
|
|
|
422
418
|
const value = obj[key];
|
|
423
419
|
return [
|
|
424
420
|
key,
|
|
425
|
-
typeof value === "function" ? reactify(value.bind(obj)) : value
|
|
421
|
+
typeof value === "function" ? reactify(value.bind(obj), options) : value
|
|
426
422
|
];
|
|
427
423
|
}));
|
|
428
424
|
}
|
|
@@ -481,7 +477,7 @@ function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
|
481
477
|
const resetAfter = () => setTimeout(() => {
|
|
482
478
|
value = defaultValue;
|
|
483
479
|
trigger();
|
|
484
|
-
},
|
|
480
|
+
}, resolveUnref$1(afterMs));
|
|
485
481
|
tryOnScopeDispose(() => {
|
|
486
482
|
clearTimeout(timer);
|
|
487
483
|
});
|
|
@@ -527,7 +523,7 @@ function refDefault(source, defaultValue) {
|
|
|
527
523
|
});
|
|
528
524
|
}
|
|
529
525
|
|
|
530
|
-
function useThrottleFn(fn, ms = 200, trailing =
|
|
526
|
+
function useThrottleFn(fn, ms = 200, trailing = false, leading = true) {
|
|
531
527
|
return createFilterWrapper(throttleFilter(ms, trailing, leading), fn);
|
|
532
528
|
}
|
|
533
529
|
|
|
@@ -594,10 +590,6 @@ function resolveRef(r) {
|
|
|
594
590
|
return typeof r === "function" ? computed(r) : ref(r);
|
|
595
591
|
}
|
|
596
592
|
|
|
597
|
-
function resolveUnref(r) {
|
|
598
|
-
return typeof r === "function" ? r() : unref(r);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
593
|
function set(...args) {
|
|
602
594
|
if (args.length === 2) {
|
|
603
595
|
const [ref, value] = args;
|
|
@@ -614,22 +606,27 @@ function set(...args) {
|
|
|
614
606
|
}
|
|
615
607
|
|
|
616
608
|
function syncRef(left, right, options = {}) {
|
|
609
|
+
var _a, _b;
|
|
617
610
|
const {
|
|
618
611
|
flush = "sync",
|
|
619
612
|
deep = false,
|
|
620
613
|
immediate = true,
|
|
621
|
-
direction = "both"
|
|
614
|
+
direction = "both",
|
|
615
|
+
transform = {}
|
|
622
616
|
} = options;
|
|
623
|
-
let
|
|
617
|
+
let watchLeft;
|
|
618
|
+
let watchRight;
|
|
619
|
+
const transformLTR = (_a = transform.ltr) != null ? _a : (v) => v;
|
|
620
|
+
const transformRTL = (_b = transform.rtl) != null ? _b : (v) => v;
|
|
624
621
|
if (direction === "both" || direction === "ltr") {
|
|
625
|
-
|
|
622
|
+
watchLeft = watch(left, (newValue) => right.value = transformLTR(newValue), { flush, deep, immediate });
|
|
626
623
|
}
|
|
627
624
|
if (direction === "both" || direction === "rtl") {
|
|
628
|
-
|
|
625
|
+
watchRight = watch(right, (newValue) => left.value = transformRTL(newValue), { flush, deep, immediate });
|
|
629
626
|
}
|
|
630
627
|
return () => {
|
|
631
|
-
|
|
632
|
-
|
|
628
|
+
watchLeft == null ? void 0 : watchLeft();
|
|
629
|
+
watchRight == null ? void 0 : watchRight();
|
|
633
630
|
};
|
|
634
631
|
}
|
|
635
632
|
|
|
@@ -734,7 +731,7 @@ function until(r) {
|
|
|
734
731
|
});
|
|
735
732
|
const promises = [watcher];
|
|
736
733
|
if (timeout != null) {
|
|
737
|
-
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() =>
|
|
734
|
+
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => resolveUnref(r)).finally(() => stop == null ? void 0 : stop()));
|
|
738
735
|
}
|
|
739
736
|
return Promise.race(promises);
|
|
740
737
|
}
|
|
@@ -757,9 +754,9 @@ function until(r) {
|
|
|
757
754
|
});
|
|
758
755
|
const promises = [watcher];
|
|
759
756
|
if (timeout != null) {
|
|
760
|
-
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() =>
|
|
757
|
+
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => resolveUnref(r)).finally(() => {
|
|
761
758
|
stop == null ? void 0 : stop();
|
|
762
|
-
return
|
|
759
|
+
return resolveUnref(r);
|
|
763
760
|
}));
|
|
764
761
|
}
|
|
765
762
|
return Promise.race(promises);
|
|
@@ -779,7 +776,7 @@ function until(r) {
|
|
|
779
776
|
function toContains(value, options) {
|
|
780
777
|
return toMatch((v) => {
|
|
781
778
|
const array = Array.from(v);
|
|
782
|
-
return array.includes(value) || array.includes(
|
|
779
|
+
return array.includes(value) || array.includes(resolveUnref(value));
|
|
783
780
|
}, options);
|
|
784
781
|
}
|
|
785
782
|
function changed(options) {
|
|
@@ -792,7 +789,7 @@ function until(r) {
|
|
|
792
789
|
return count >= n;
|
|
793
790
|
}, options);
|
|
794
791
|
}
|
|
795
|
-
if (Array.isArray(
|
|
792
|
+
if (Array.isArray(resolveUnref(r))) {
|
|
796
793
|
const instance = {
|
|
797
794
|
toMatch,
|
|
798
795
|
toContains,
|
|
@@ -823,6 +820,42 @@ function until(r) {
|
|
|
823
820
|
}
|
|
824
821
|
}
|
|
825
822
|
|
|
823
|
+
function useArrayEvery(list, fn) {
|
|
824
|
+
return computed(() => resolveUnref$1(list).every((element, index, array) => fn(resolveUnref$1(element), index, array)));
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
function useArrayFilter(list, fn) {
|
|
828
|
+
return computed(() => resolveUnref$1(list).map((i) => resolveUnref$1(i)).filter(fn));
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function useArrayFind(list, fn) {
|
|
832
|
+
return computed(() => resolveUnref$1(resolveUnref$1(list).find((element, index, array) => fn(resolveUnref$1(element), index, array))));
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
function useArrayFindIndex(list, fn) {
|
|
836
|
+
return computed(() => resolveUnref$1(list).findIndex((element, index, array) => fn(resolveUnref$1(element), index, array)));
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
function useArrayJoin(list, separator) {
|
|
840
|
+
return computed(() => resolveUnref$1(list).map((i) => resolveUnref$1(i)).join(resolveUnref$1(separator)));
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
function useArrayMap(list, fn) {
|
|
844
|
+
return computed(() => resolveUnref$1(list).map((i) => resolveUnref$1(i)).map(fn));
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
function useArrayReduce(list, reducer, ...args) {
|
|
848
|
+
const reduceCallback = (sum, value, index) => reducer(resolveUnref$1(sum), resolveUnref$1(value), index);
|
|
849
|
+
return computed(() => {
|
|
850
|
+
const resolved = resolveUnref$1(list);
|
|
851
|
+
return args.length ? resolved.reduce(reduceCallback, resolveUnref$1(args[0])) : resolved.reduce(reduceCallback);
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function useArraySome(list, fn) {
|
|
856
|
+
return computed(() => resolveUnref$1(list).some((element, index, array) => fn(resolveUnref$1(element), index, array)));
|
|
857
|
+
}
|
|
858
|
+
|
|
826
859
|
function useCounter(initialValue = 0, options = {}) {
|
|
827
860
|
const count = ref(initialValue);
|
|
828
861
|
const {
|
|
@@ -889,7 +922,7 @@ const normalizeDate = (date) => {
|
|
|
889
922
|
return new Date(date);
|
|
890
923
|
};
|
|
891
924
|
function useDateFormat(date, formatStr = "HH:mm:ss") {
|
|
892
|
-
return computed(() => formatDate(normalizeDate(
|
|
925
|
+
return computed(() => formatDate(normalizeDate(resolveUnref$1(date)), resolveUnref$1(formatStr)));
|
|
893
926
|
}
|
|
894
927
|
|
|
895
928
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
@@ -916,7 +949,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
916
949
|
if (immediateCallback)
|
|
917
950
|
cb();
|
|
918
951
|
clean();
|
|
919
|
-
timer = setInterval(cb,
|
|
952
|
+
timer = setInterval(cb, resolveUnref(interval));
|
|
920
953
|
}
|
|
921
954
|
if (immediate && isClient)
|
|
922
955
|
resume();
|
|
@@ -997,7 +1030,7 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
997
1030
|
isPending.value = false;
|
|
998
1031
|
timer = null;
|
|
999
1032
|
cb(...args);
|
|
1000
|
-
},
|
|
1033
|
+
}, resolveUnref$1(interval));
|
|
1001
1034
|
}
|
|
1002
1035
|
if (immediate) {
|
|
1003
1036
|
isPending.value = true;
|
|
@@ -1049,20 +1082,21 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1049
1082
|
falsyValue = false
|
|
1050
1083
|
} = options;
|
|
1051
1084
|
const valueIsRef = isRef(initialValue);
|
|
1052
|
-
const
|
|
1085
|
+
const _value = ref(initialValue);
|
|
1053
1086
|
function toggle(value) {
|
|
1054
1087
|
if (arguments.length) {
|
|
1055
|
-
|
|
1056
|
-
return
|
|
1088
|
+
_value.value = value;
|
|
1089
|
+
return _value.value;
|
|
1057
1090
|
} else {
|
|
1058
|
-
|
|
1059
|
-
|
|
1091
|
+
const truthy = resolveUnref(truthyValue);
|
|
1092
|
+
_value.value = _value.value === truthy ? resolveUnref(falsyValue) : truthy;
|
|
1093
|
+
return _value.value;
|
|
1060
1094
|
}
|
|
1061
1095
|
}
|
|
1062
1096
|
if (valueIsRef)
|
|
1063
1097
|
return toggle;
|
|
1064
1098
|
else
|
|
1065
|
-
return [
|
|
1099
|
+
return [_value, toggle];
|
|
1066
1100
|
}
|
|
1067
1101
|
|
|
1068
1102
|
function watchArray(source, cb, options) {
|
|
@@ -1138,7 +1172,7 @@ function watchAtMost(source, cb, options) {
|
|
|
1138
1172
|
const current = ref(0);
|
|
1139
1173
|
const stop = watchWithFilter(source, (...args) => {
|
|
1140
1174
|
current.value += 1;
|
|
1141
|
-
if (current.value >=
|
|
1175
|
+
if (current.value >= resolveUnref(count))
|
|
1142
1176
|
nextTick(() => stop());
|
|
1143
1177
|
cb(...args);
|
|
1144
1178
|
}, watchOptions);
|
|
@@ -1439,4 +1473,4 @@ function whenever(source, cb, options) {
|
|
|
1439
1473
|
}, options);
|
|
1440
1474
|
}
|
|
1441
1475
|
|
|
1442
|
-
export { __onlyVue3,
|
|
1476
|
+
export { __onlyVue3, assert, refAutoReset as autoResetRef, bypassFilter, clamp, computedEager, computedWithControl, containsProp, computedWithControl as controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createInjectionState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, refDebounced as debouncedRef, watchDebounced as debouncedWatch, directiveHooks, computedEager as eagerComputed, extendRef, formatDate, get, identity, watchIgnorable as ignorableWatch, increaseWithUnit, invoke, isBoolean, isClient, isDef, isDefined, isFunction, isIOS, isNumber, isObject, isString, isWindow, makeDestructurable, noop, normalizeDate, now, objectPick, pausableFilter, watchPausable as pausableWatch, promiseTimeout, rand, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refThrottled, refWithControl, resolveRef, resolveUnref, set, syncRef, syncRefs, throttleFilter, refThrottled as throttledRef, watchThrottled as throttledWatch, timestamp, toReactive, toRefs, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayJoin, useArrayMap, useArrayReduce, useArraySome, useCounter, useDateFormat, refDebounced as useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, refThrottled as useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToggle, watchArray, watchAtMost, watchDebounced, watchIgnorable, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/shared",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-beta.2",
|
|
4
4
|
"author": "Anthony Fu <https://github.com/antfu>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"funding": "https://github.com/sponsors/antfu",
|
|
@@ -32,18 +32,6 @@
|
|
|
32
32
|
"unpkg": "./index.iife.min.js",
|
|
33
33
|
"jsdelivr": "./index.iife.min.js",
|
|
34
34
|
"types": "./index.d.ts",
|
|
35
|
-
"peerDependencies": {
|
|
36
|
-
"@vue/composition-api": "^1.1.0",
|
|
37
|
-
"vue": "^2.6.0 || ^3.2.0"
|
|
38
|
-
},
|
|
39
|
-
"peerDependenciesMeta": {
|
|
40
|
-
"vue": {
|
|
41
|
-
"optional": true
|
|
42
|
-
},
|
|
43
|
-
"@vue/composition-api": {
|
|
44
|
-
"optional": true
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
35
|
"dependencies": {
|
|
48
36
|
"vue-demi": "*"
|
|
49
37
|
}
|