@vueuse/shared 8.9.3 → 9.0.0-beta.1
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 +71 -45
- package/index.d.ts +66 -61
- package/index.iife.js +72 -63
- package/index.iife.min.js +1 -1
- package/index.mjs +66 -41
- 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;
|
|
@@ -738,7 +730,7 @@ function until(r) {
|
|
|
738
730
|
});
|
|
739
731
|
const promises = [watcher];
|
|
740
732
|
if (timeout != null) {
|
|
741
|
-
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() =>
|
|
733
|
+
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => resolveUnref(r)).finally(() => stop == null ? void 0 : stop()));
|
|
742
734
|
}
|
|
743
735
|
return Promise.race(promises);
|
|
744
736
|
}
|
|
@@ -761,9 +753,9 @@ function until(r) {
|
|
|
761
753
|
});
|
|
762
754
|
const promises = [watcher];
|
|
763
755
|
if (timeout != null) {
|
|
764
|
-
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() =>
|
|
756
|
+
promises.push(promiseTimeout(timeout, throwOnTimeout).then(() => resolveUnref(r)).finally(() => {
|
|
765
757
|
stop == null ? void 0 : stop();
|
|
766
|
-
return
|
|
758
|
+
return resolveUnref(r);
|
|
767
759
|
}));
|
|
768
760
|
}
|
|
769
761
|
return Promise.race(promises);
|
|
@@ -783,7 +775,7 @@ function until(r) {
|
|
|
783
775
|
function toContains(value, options) {
|
|
784
776
|
return toMatch((v) => {
|
|
785
777
|
const array = Array.from(v);
|
|
786
|
-
return array.includes(value) || array.includes(
|
|
778
|
+
return array.includes(value) || array.includes(resolveUnref(value));
|
|
787
779
|
}, options);
|
|
788
780
|
}
|
|
789
781
|
function changed(options) {
|
|
@@ -796,7 +788,7 @@ function until(r) {
|
|
|
796
788
|
return count >= n;
|
|
797
789
|
}, options);
|
|
798
790
|
}
|
|
799
|
-
if (Array.isArray(
|
|
791
|
+
if (Array.isArray(resolveUnref(r))) {
|
|
800
792
|
const instance = {
|
|
801
793
|
toMatch,
|
|
802
794
|
toContains,
|
|
@@ -827,6 +819,38 @@ function until(r) {
|
|
|
827
819
|
}
|
|
828
820
|
}
|
|
829
821
|
|
|
822
|
+
function useArrayEvery(list, fn) {
|
|
823
|
+
return vueDemi.computed(() => shared.resolveUnref(list).every((element, index, array) => fn(shared.resolveUnref(element), index, array)));
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function useArrayFilter(list, fn) {
|
|
827
|
+
return vueDemi.computed(() => shared.resolveUnref(list).map((i) => shared.resolveUnref(i)).filter(fn));
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
function useArrayFind(list, fn) {
|
|
831
|
+
return vueDemi.computed(() => shared.resolveUnref(shared.resolveUnref(list).find((element, index, array) => fn(shared.resolveUnref(element), index, array))));
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
function useArrayJoin(list, separator) {
|
|
835
|
+
return vueDemi.computed(() => shared.resolveUnref(list).map((i) => shared.resolveUnref(i)).join(shared.resolveUnref(separator)));
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
function useArrayMap(list, fn) {
|
|
839
|
+
return vueDemi.computed(() => shared.resolveUnref(list).map((i) => shared.resolveUnref(i)).map(fn));
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function useArrayReduce(list, reducer, ...args) {
|
|
843
|
+
const reduceCallback = (sum, value, index) => reducer(shared.resolveUnref(sum), shared.resolveUnref(value), index);
|
|
844
|
+
return vueDemi.computed(() => {
|
|
845
|
+
const resolved = shared.resolveUnref(list);
|
|
846
|
+
return args.length ? resolved.reduce(reduceCallback, shared.resolveUnref(args[0])) : resolved.reduce(reduceCallback);
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
function useArraySome(list, fn) {
|
|
851
|
+
return vueDemi.computed(() => shared.resolveUnref(list).some((element, index, array) => fn(shared.resolveUnref(element), index, array)));
|
|
852
|
+
}
|
|
853
|
+
|
|
830
854
|
function useCounter(initialValue = 0, options = {}) {
|
|
831
855
|
const count = vueDemi.ref(initialValue);
|
|
832
856
|
const {
|
|
@@ -893,7 +917,7 @@ const normalizeDate = (date) => {
|
|
|
893
917
|
return new Date(date);
|
|
894
918
|
};
|
|
895
919
|
function useDateFormat(date, formatStr = "HH:mm:ss") {
|
|
896
|
-
return vueDemi.computed(() => formatDate(normalizeDate(
|
|
920
|
+
return vueDemi.computed(() => formatDate(normalizeDate(shared.resolveUnref(date)), shared.resolveUnref(formatStr)));
|
|
897
921
|
}
|
|
898
922
|
|
|
899
923
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
@@ -920,7 +944,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
920
944
|
if (immediateCallback)
|
|
921
945
|
cb();
|
|
922
946
|
clean();
|
|
923
|
-
timer = setInterval(cb,
|
|
947
|
+
timer = setInterval(cb, resolveUnref(interval));
|
|
924
948
|
}
|
|
925
949
|
if (immediate && isClient)
|
|
926
950
|
resume();
|
|
@@ -1001,7 +1025,7 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1001
1025
|
isPending.value = false;
|
|
1002
1026
|
timer = null;
|
|
1003
1027
|
cb(...args);
|
|
1004
|
-
},
|
|
1028
|
+
}, shared.resolveUnref(interval));
|
|
1005
1029
|
}
|
|
1006
1030
|
if (immediate) {
|
|
1007
1031
|
isPending.value = true;
|
|
@@ -1053,20 +1077,21 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1053
1077
|
falsyValue = false
|
|
1054
1078
|
} = options;
|
|
1055
1079
|
const valueIsRef = vueDemi.isRef(initialValue);
|
|
1056
|
-
const
|
|
1080
|
+
const _value = vueDemi.ref(initialValue);
|
|
1057
1081
|
function toggle(value) {
|
|
1058
1082
|
if (arguments.length) {
|
|
1059
|
-
|
|
1060
|
-
return
|
|
1083
|
+
_value.value = value;
|
|
1084
|
+
return _value.value;
|
|
1061
1085
|
} else {
|
|
1062
|
-
|
|
1063
|
-
|
|
1086
|
+
const truthy = resolveUnref(truthyValue);
|
|
1087
|
+
_value.value = _value.value === truthy ? resolveUnref(falsyValue) : truthy;
|
|
1088
|
+
return _value.value;
|
|
1064
1089
|
}
|
|
1065
1090
|
}
|
|
1066
1091
|
if (valueIsRef)
|
|
1067
1092
|
return toggle;
|
|
1068
1093
|
else
|
|
1069
|
-
return [
|
|
1094
|
+
return [_value, toggle];
|
|
1070
1095
|
}
|
|
1071
1096
|
|
|
1072
1097
|
function watchArray(source, cb, options) {
|
|
@@ -1142,7 +1167,7 @@ function watchAtMost(source, cb, options) {
|
|
|
1142
1167
|
const current = vueDemi.ref(0);
|
|
1143
1168
|
const stop = watchWithFilter(source, (...args) => {
|
|
1144
1169
|
current.value += 1;
|
|
1145
|
-
if (current.value >=
|
|
1170
|
+
if (current.value >= resolveUnref(count))
|
|
1146
1171
|
vueDemi.nextTick(() => stop());
|
|
1147
1172
|
cb(...args);
|
|
1148
1173
|
}, watchOptions);
|
|
@@ -1444,7 +1469,6 @@ function whenever(source, cb, options) {
|
|
|
1444
1469
|
}
|
|
1445
1470
|
|
|
1446
1471
|
exports.__onlyVue3 = __onlyVue3;
|
|
1447
|
-
exports.and = logicAnd;
|
|
1448
1472
|
exports.assert = assert;
|
|
1449
1473
|
exports.autoResetRef = refAutoReset;
|
|
1450
1474
|
exports.bypassFilter = bypassFilter;
|
|
@@ -1483,16 +1507,11 @@ exports.isNumber = isNumber;
|
|
|
1483
1507
|
exports.isObject = isObject;
|
|
1484
1508
|
exports.isString = isString;
|
|
1485
1509
|
exports.isWindow = isWindow;
|
|
1486
|
-
exports.logicAnd = logicAnd;
|
|
1487
|
-
exports.logicNot = logicNot;
|
|
1488
|
-
exports.logicOr = logicOr;
|
|
1489
1510
|
exports.makeDestructurable = makeDestructurable;
|
|
1490
1511
|
exports.noop = noop;
|
|
1491
1512
|
exports.normalizeDate = normalizeDate;
|
|
1492
|
-
exports.not = logicNot;
|
|
1493
1513
|
exports.now = now;
|
|
1494
1514
|
exports.objectPick = objectPick;
|
|
1495
|
-
exports.or = logicOr;
|
|
1496
1515
|
exports.pausableFilter = pausableFilter;
|
|
1497
1516
|
exports.pausableWatch = watchPausable;
|
|
1498
1517
|
exports.promiseTimeout = promiseTimeout;
|
|
@@ -1524,6 +1543,13 @@ exports.tryOnMounted = tryOnMounted;
|
|
|
1524
1543
|
exports.tryOnScopeDispose = tryOnScopeDispose;
|
|
1525
1544
|
exports.tryOnUnmounted = tryOnUnmounted;
|
|
1526
1545
|
exports.until = until;
|
|
1546
|
+
exports.useArrayEvery = useArrayEvery;
|
|
1547
|
+
exports.useArrayFilter = useArrayFilter;
|
|
1548
|
+
exports.useArrayFind = useArrayFind;
|
|
1549
|
+
exports.useArrayJoin = useArrayJoin;
|
|
1550
|
+
exports.useArrayMap = useArrayMap;
|
|
1551
|
+
exports.useArrayReduce = useArrayReduce;
|
|
1552
|
+
exports.useArraySome = useArraySome;
|
|
1527
1553
|
exports.useCounter = useCounter;
|
|
1528
1554
|
exports.useDateFormat = useDateFormat;
|
|
1529
1555
|
exports.useDebounce = refDebounced;
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as vue_demi from 'vue-demi';
|
|
2
2
|
import { WatchOptionsBase, Ref, ComputedRef, WritableComputedRef, WatchSource, ComputedGetter, WritableComputedOptions, ShallowUnwrapRef as ShallowUnwrapRef$1, WatchOptions, UnwrapRef, ToRefs, WatchCallback, WatchStopHandle } from 'vue-demi';
|
|
3
|
-
import {
|
|
3
|
+
import { MaybeComputedRef as MaybeComputedRef$1 } from '@vueuse/shared';
|
|
4
4
|
|
|
5
5
|
declare function computedEager<T>(fn: () => T, options?: WatchOptionsBase): Readonly<Ref<T>>;
|
|
6
6
|
|
|
@@ -125,13 +125,13 @@ declare type RemoveableRef<T> = RemovableRef<T>;
|
|
|
125
125
|
*/
|
|
126
126
|
declare type MaybeRef<T> = T | Ref<T>;
|
|
127
127
|
/**
|
|
128
|
-
* Maybe it's a ref, or a getter function
|
|
128
|
+
* Maybe it's a ref, or a plain value, or a getter function
|
|
129
129
|
*
|
|
130
130
|
* ```ts
|
|
131
|
-
* type
|
|
131
|
+
* type MaybeComputedRef<T> = T | Ref<T> | (() => T)
|
|
132
132
|
* ```
|
|
133
133
|
*/
|
|
134
|
-
declare type MaybeComputedRef<T> = T extends
|
|
134
|
+
declare type MaybeComputedRef<T> = T extends () => void ? never : (() => T) | MaybeRef<T>;
|
|
135
135
|
/**
|
|
136
136
|
* Make all the nested attributes of an object or array to MaybeRef<T>
|
|
137
137
|
*
|
|
@@ -150,6 +150,7 @@ declare type DeepMaybeRef<T> = T extends Ref<infer V> ? MaybeRef<V> : T extends
|
|
|
150
150
|
declare type ElementOf<T> = T extends (infer E)[] ? E : never;
|
|
151
151
|
declare type ShallowUnwrapRef<T> = T extends Ref<infer P> ? P : T;
|
|
152
152
|
declare type Awaitable<T> = Promise<T> | T;
|
|
153
|
+
declare type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
|
|
153
154
|
interface Pausable {
|
|
154
155
|
/**
|
|
155
156
|
* A ref indicate whether a pusable instance is active
|
|
@@ -226,7 +227,7 @@ interface DebounceFilterOptions {
|
|
|
226
227
|
* The maximum time allowed to be delayed before it's invoked.
|
|
227
228
|
* In milliseconds.
|
|
228
229
|
*/
|
|
229
|
-
maxWait?: number
|
|
230
|
+
maxWait?: MaybeComputedRef<number>;
|
|
230
231
|
}
|
|
231
232
|
/**
|
|
232
233
|
* @internal
|
|
@@ -239,7 +240,7 @@ declare const bypassFilter: EventFilter;
|
|
|
239
240
|
* @param ms
|
|
240
241
|
* @param [maxWait=null]
|
|
241
242
|
*/
|
|
242
|
-
declare function debounceFilter(ms:
|
|
243
|
+
declare function debounceFilter(ms: MaybeComputedRef<number>, options?: DebounceFilterOptions): EventFilter<any[], any>;
|
|
243
244
|
/**
|
|
244
245
|
* Create an EventFilter that throttle the events
|
|
245
246
|
*
|
|
@@ -247,7 +248,7 @@ declare function debounceFilter(ms: MaybeRef<number>, options?: DebounceFilterOp
|
|
|
247
248
|
* @param [trailing=true]
|
|
248
249
|
* @param [leading=true]
|
|
249
250
|
*/
|
|
250
|
-
declare function throttleFilter(ms:
|
|
251
|
+
declare function throttleFilter(ms: MaybeComputedRef<number>, trailing?: boolean, leading?: boolean): EventFilter<any[], any>;
|
|
251
252
|
/**
|
|
252
253
|
* EventFilter that gives extra controls to pause and resume the filter
|
|
253
254
|
*
|
|
@@ -316,32 +317,19 @@ declare function isDefined<T>(v: Ref<T>): v is Ref<Exclude<T, null | undefined>>
|
|
|
316
317
|
declare function isDefined<T>(v: ComputedRef<T>): v is ComputedRef<Exclude<T, null | undefined>>;
|
|
317
318
|
declare function isDefined<T>(v: T): v is Exclude<T, null | undefined>;
|
|
318
319
|
|
|
319
|
-
/**
|
|
320
|
-
* `AND` conditions for refs.
|
|
321
|
-
*
|
|
322
|
-
* @see https://vueuse.org/logicAnd
|
|
323
|
-
*/
|
|
324
|
-
declare function logicAnd(...args: MaybeRef<any>[]): ComputedRef<boolean>;
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* `NOT` conditions for refs.
|
|
328
|
-
*
|
|
329
|
-
* @see https://vueuse.org/logicNot
|
|
330
|
-
*/
|
|
331
|
-
declare function logicNot(v: MaybeRef<any>): ComputedRef<boolean>;
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* `OR` conditions for refs.
|
|
335
|
-
*
|
|
336
|
-
* @see https://vueuse.org/logicOr
|
|
337
|
-
*/
|
|
338
|
-
declare function logicOr(...args: MaybeRef<any>[]): ComputedRef<boolean>;
|
|
339
|
-
|
|
340
320
|
declare function makeDestructurable<T extends Record<string, unknown>, A extends readonly any[]>(obj: T, arr: A): T & A;
|
|
341
321
|
|
|
342
|
-
declare type
|
|
343
|
-
[K in keyof A]: MaybeRef<A[K]>;
|
|
322
|
+
declare type Reactified<T, Computed extends boolean> = T extends (...args: infer A) => infer R ? (...args: {
|
|
323
|
+
[K in keyof A]: Computed extends true ? MaybeComputedRef<A[K]> : MaybeRef<A[K]>;
|
|
344
324
|
}) => ComputedRef<R> : never;
|
|
325
|
+
interface ReactifyOptions<T extends boolean> {
|
|
326
|
+
/**
|
|
327
|
+
* Accept passing a function as a reactive getter
|
|
328
|
+
*
|
|
329
|
+
* @default true
|
|
330
|
+
*/
|
|
331
|
+
computedGetter?: T;
|
|
332
|
+
}
|
|
345
333
|
/**
|
|
346
334
|
* Converts plain function into a reactive function.
|
|
347
335
|
* The converted function accepts refs as it's arguments
|
|
@@ -349,12 +337,12 @@ declare type Reactify<T> = T extends (...args: infer A) => infer R ? (...args: {
|
|
|
349
337
|
*
|
|
350
338
|
* @param fn - Source function
|
|
351
339
|
*/
|
|
352
|
-
declare function reactify<T extends Function>(fn: T):
|
|
340
|
+
declare function reactify<T extends Function, K extends boolean = true>(fn: T, options?: ReactifyOptions<K>): Reactified<T, K>;
|
|
353
341
|
|
|
354
|
-
declare type ReactifyNested<T, Keys extends keyof T = keyof T> = {
|
|
355
|
-
[K in Keys]: T[K] extends (...args: any[]) => any ?
|
|
342
|
+
declare type ReactifyNested<T, Keys extends keyof T = keyof T, S extends boolean = true> = {
|
|
343
|
+
[K in Keys]: T[K] extends (...args: any[]) => any ? Reactified<T[K], S> : T[K];
|
|
356
344
|
};
|
|
357
|
-
interface ReactifyObjectOptions {
|
|
345
|
+
interface ReactifyObjectOptions<T extends boolean> extends ReactifyOptions<T> {
|
|
358
346
|
/**
|
|
359
347
|
* Includes names from Object.getOwnPropertyNames
|
|
360
348
|
*
|
|
@@ -365,8 +353,8 @@ interface ReactifyObjectOptions {
|
|
|
365
353
|
/**
|
|
366
354
|
* Apply `reactify` to an object
|
|
367
355
|
*/
|
|
368
|
-
declare function reactifyObject<T extends object, Keys extends keyof T>(obj: T, keys?: (keyof T)[]): ReactifyNested<T, Keys>;
|
|
369
|
-
declare function reactifyObject<T extends object>(obj: T, options?: ReactifyObjectOptions): ReactifyNested<T>;
|
|
356
|
+
declare function reactifyObject<T extends object, Keys extends keyof T>(obj: T, keys?: (keyof T)[]): ReactifyNested<T, Keys, true>;
|
|
357
|
+
declare function reactifyObject<T extends object, S extends boolean = true>(obj: T, options?: ReactifyObjectOptions<S>): ReactifyNested<T, keyof T, S>;
|
|
370
358
|
|
|
371
359
|
/**
|
|
372
360
|
* Computed reactive object.
|
|
@@ -396,7 +384,7 @@ declare function reactivePick<T extends object, K extends keyof T>(obj: T, ...ke
|
|
|
396
384
|
* @param defaultValue The value which will be set.
|
|
397
385
|
* @param afterMs A zero-or-greater delay in milliseconds.
|
|
398
386
|
*/
|
|
399
|
-
declare function refAutoReset<T>(defaultValue: T, afterMs?:
|
|
387
|
+
declare function refAutoReset<T>(defaultValue: T, afterMs?: MaybeComputedRef$1<number>): Ref<T>;
|
|
400
388
|
|
|
401
389
|
/**
|
|
402
390
|
* Debounce updates of a ref.
|
|
@@ -462,6 +450,7 @@ declare const controlledRef: typeof refWithControl;
|
|
|
462
450
|
*/
|
|
463
451
|
declare function resolveRef<T>(r: MaybeComputedRef<T>): ComputedRef<T>;
|
|
464
452
|
declare function resolveRef<T>(r: MaybeRef<T>): Ref<T>;
|
|
453
|
+
declare function resolveRef<T>(r: T): Ref<T>;
|
|
465
454
|
|
|
466
455
|
/**
|
|
467
456
|
* Normalize value/ref/getter to `ref` or `computed`.
|
|
@@ -610,7 +599,7 @@ interface UntilBaseInstance<T, Not extends boolean = false> {
|
|
|
610
599
|
declare type Falsy = false | void | null | undefined | 0 | 0n | '';
|
|
611
600
|
interface UntilValueInstance<T, Not extends boolean = false> extends UntilBaseInstance<T, Not> {
|
|
612
601
|
readonly not: UntilValueInstance<T, Not extends true ? false : true>;
|
|
613
|
-
toBe<P = T>(value:
|
|
602
|
+
toBe<P = T>(value: MaybeComputedRef<P>, options?: UntilToMatchOptions): Not extends true ? Promise<T> : Promise<P>;
|
|
614
603
|
toBeTruthy(options?: UntilToMatchOptions): Not extends true ? Promise<T & Falsy> : Promise<Exclude<T, Falsy>>;
|
|
615
604
|
toBeNull(options?: UntilToMatchOptions): Not extends true ? Promise<Exclude<T, null>> : Promise<null>;
|
|
616
605
|
toBeUndefined(options?: UntilToMatchOptions): Not extends true ? Promise<Exclude<T, undefined>> : Promise<undefined>;
|
|
@@ -618,7 +607,7 @@ interface UntilValueInstance<T, Not extends boolean = false> extends UntilBaseIn
|
|
|
618
607
|
}
|
|
619
608
|
interface UntilArrayInstance<T> extends UntilBaseInstance<T> {
|
|
620
609
|
readonly not: UntilArrayInstance<T>;
|
|
621
|
-
toContains(value:
|
|
610
|
+
toContains(value: MaybeComputedRef<ElementOf<ShallowUnwrapRef<T>>>, options?: UntilToMatchOptions): Promise<T>;
|
|
622
611
|
}
|
|
623
612
|
/**
|
|
624
613
|
* Promised one-time watch for changes
|
|
@@ -633,8 +622,24 @@ interface UntilArrayInstance<T> extends UntilBaseInstance<T> {
|
|
|
633
622
|
* alert('Counter is now larger than 7!')
|
|
634
623
|
* ```
|
|
635
624
|
*/
|
|
636
|
-
declare function until<T extends unknown[]>(r: WatchSource<T> |
|
|
637
|
-
declare function until<T>(r: WatchSource<T> |
|
|
625
|
+
declare function until<T extends unknown[]>(r: WatchSource<T> | MaybeComputedRef<T>): UntilArrayInstance<T>;
|
|
626
|
+
declare function until<T>(r: WatchSource<T> | MaybeComputedRef<T>): UntilValueInstance<T>;
|
|
627
|
+
|
|
628
|
+
declare function useArrayEvery<T>(list: MaybeComputedRef$1<MaybeComputedRef$1<T>[]>, fn: (element: T, index: number, array: MaybeComputedRef$1<T>[]) => unknown): ComputedRef<boolean>;
|
|
629
|
+
|
|
630
|
+
declare function useArrayFilter<T>(list: MaybeComputedRef$1<MaybeComputedRef$1<T>[]>, fn: (element: T, index: number, array: T[]) => boolean): ComputedRef<T[]>;
|
|
631
|
+
|
|
632
|
+
declare function useArrayFind<T>(list: MaybeComputedRef$1<MaybeComputedRef$1<T>[]>, fn: (element: T, index: number, array: MaybeComputedRef$1<T>[]) => boolean): ComputedRef<T | undefined>;
|
|
633
|
+
|
|
634
|
+
declare function useArrayJoin(list: MaybeComputedRef$1<MaybeComputedRef$1<any>[]>, separator?: MaybeComputedRef$1<string>): ComputedRef<string>;
|
|
635
|
+
|
|
636
|
+
declare function useArrayMap<T>(list: MaybeComputedRef$1<MaybeComputedRef$1<T>[]>, fn: (element: T, index: number, array: T[]) => T): ComputedRef<T[]>;
|
|
637
|
+
|
|
638
|
+
declare type UseArrayReducer<PV, CV, R> = (previousValue: PV, currentValue: CV, currentIndex: number) => R;
|
|
639
|
+
declare function useArrayReduce<T>(list: MaybeComputedRef$1<MaybeComputedRef$1<T>[]>, reducer: UseArrayReducer<T, T, T>): ComputedRef<T>;
|
|
640
|
+
declare function useArrayReduce<T, U>(list: MaybeComputedRef$1<MaybeComputedRef$1<T>[]>, reducer: UseArrayReducer<U, T, U>, initialValue: MaybeComputedRef$1<U>): ComputedRef<U>;
|
|
641
|
+
|
|
642
|
+
declare function useArraySome<T>(list: MaybeComputedRef$1<MaybeComputedRef$1<T>[]>, fn: (element: T, index: number, array: MaybeComputedRef$1<T>[]) => unknown): ComputedRef<boolean>;
|
|
638
643
|
|
|
639
644
|
interface UseCounterOptions {
|
|
640
645
|
min?: number;
|
|
@@ -666,7 +671,7 @@ declare const normalizeDate: (date: DateLike) => Date;
|
|
|
666
671
|
* @param date
|
|
667
672
|
* @param formatStr
|
|
668
673
|
*/
|
|
669
|
-
declare function useDateFormat(date:
|
|
674
|
+
declare function useDateFormat(date: MaybeComputedRef$1<DateLike>, formatStr?: MaybeComputedRef$1<string>): vue_demi.ComputedRef<string>;
|
|
670
675
|
declare type UseDateFormatReturn = ReturnType<typeof useDateFormat>;
|
|
671
676
|
|
|
672
677
|
/**
|
|
@@ -678,9 +683,9 @@ declare type UseDateFormatReturn = ReturnType<typeof useDateFormat>;
|
|
|
678
683
|
*
|
|
679
684
|
* @return A new, debounce, function.
|
|
680
685
|
*/
|
|
681
|
-
declare function useDebounceFn<T extends FunctionArgs>(fn: T, ms?:
|
|
686
|
+
declare function useDebounceFn<T extends FunctionArgs>(fn: T, ms?: MaybeComputedRef$1<number>, options?: DebounceFilterOptions): T;
|
|
682
687
|
|
|
683
|
-
interface
|
|
688
|
+
interface UseIntervalOptions<Controls extends boolean> {
|
|
684
689
|
/**
|
|
685
690
|
* Expose more controls
|
|
686
691
|
*
|
|
@@ -694,12 +699,12 @@ interface IntervalOptions<Controls extends boolean> {
|
|
|
694
699
|
*/
|
|
695
700
|
immediate?: boolean;
|
|
696
701
|
}
|
|
697
|
-
declare function useInterval(interval?:
|
|
698
|
-
declare function useInterval(interval:
|
|
702
|
+
declare function useInterval(interval?: MaybeComputedRef<number>, options?: UseIntervalOptions<false>): Ref<number>;
|
|
703
|
+
declare function useInterval(interval: MaybeComputedRef<number>, options: UseIntervalOptions<true>): {
|
|
699
704
|
counter: Ref<number>;
|
|
700
705
|
} & Pausable;
|
|
701
706
|
|
|
702
|
-
interface
|
|
707
|
+
interface UseIntervalFnOptions {
|
|
703
708
|
/**
|
|
704
709
|
* Start the timer immediately
|
|
705
710
|
*
|
|
@@ -720,7 +725,7 @@ interface IntervalFnOptions {
|
|
|
720
725
|
* @param interval
|
|
721
726
|
* @param options
|
|
722
727
|
*/
|
|
723
|
-
declare function useIntervalFn(cb: Fn, interval?:
|
|
728
|
+
declare function useIntervalFn(cb: Fn, interval?: MaybeComputedRef<number>, options?: UseIntervalFnOptions): Pausable;
|
|
724
729
|
|
|
725
730
|
interface UseLastChangedOptions<Immediate extends boolean, InitialValue extends number | null | undefined = undefined> extends WatchOptions<Immediate> {
|
|
726
731
|
initialValue?: InitialValue;
|
|
@@ -742,15 +747,15 @@ declare function useLastChanged(source: WatchSource, options: UseLastChangedOpti
|
|
|
742
747
|
* to `callback` when the throttled-function is executed.
|
|
743
748
|
* @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
|
744
749
|
*
|
|
745
|
-
* @param [trailing=
|
|
750
|
+
* @param [trailing=false] if true, call fn again after the time is up
|
|
746
751
|
*
|
|
747
752
|
* @param [leading=true] if true, call fn on the leading edge of the ms timeout
|
|
748
753
|
*
|
|
749
754
|
* @return A new, throttled, function.
|
|
750
755
|
*/
|
|
751
|
-
declare function useThrottleFn<T extends FunctionArgs>(fn: T, ms?:
|
|
756
|
+
declare function useThrottleFn<T extends FunctionArgs>(fn: T, ms?: MaybeComputedRef<number>, trailing?: boolean, leading?: boolean): T;
|
|
752
757
|
|
|
753
|
-
interface
|
|
758
|
+
interface UseTimeoutFnOptions {
|
|
754
759
|
/**
|
|
755
760
|
* Start the timer immediate after calling this function
|
|
756
761
|
*
|
|
@@ -765,9 +770,9 @@ interface TimeoutFnOptions {
|
|
|
765
770
|
* @param interval
|
|
766
771
|
* @param immediate
|
|
767
772
|
*/
|
|
768
|
-
declare function useTimeoutFn(cb: (...args: unknown[]) => any, interval:
|
|
773
|
+
declare function useTimeoutFn(cb: (...args: unknown[]) => any, interval: MaybeComputedRef$1<number>, options?: UseTimeoutFnOptions): Stoppable;
|
|
769
774
|
|
|
770
|
-
interface
|
|
775
|
+
interface UseTimeoutOptions<Controls extends boolean> extends UseTimeoutFnOptions {
|
|
771
776
|
/**
|
|
772
777
|
* Expose more controls
|
|
773
778
|
*
|
|
@@ -782,14 +787,14 @@ interface TimeoutOptions<Controls extends boolean> extends TimeoutFnOptions {
|
|
|
782
787
|
* @param interval
|
|
783
788
|
* @param immediate
|
|
784
789
|
*/
|
|
785
|
-
declare function useTimeout(interval?: number, options?:
|
|
786
|
-
declare function useTimeout(interval: number, options:
|
|
790
|
+
declare function useTimeout(interval?: number, options?: UseTimeoutOptions<false>): ComputedRef<boolean>;
|
|
791
|
+
declare function useTimeout(interval: number, options: UseTimeoutOptions<true>): {
|
|
787
792
|
ready: ComputedRef<boolean>;
|
|
788
793
|
} & Stoppable;
|
|
789
794
|
|
|
790
795
|
interface UseToggleOptions<Truthy, Falsy> {
|
|
791
|
-
truthyValue?:
|
|
792
|
-
falsyValue?:
|
|
796
|
+
truthyValue?: MaybeComputedRef<Truthy>;
|
|
797
|
+
falsyValue?: MaybeComputedRef<Falsy>;
|
|
793
798
|
}
|
|
794
799
|
declare function useToggle<Truthy, Falsy, T = Truthy | Falsy>(initialValue: Ref<T>, options?: UseToggleOptions<Truthy, Falsy>): (value?: T) => T;
|
|
795
800
|
declare function useToggle<Truthy = true, Falsy = false, T = Truthy | Falsy>(initialValue?: T, options?: UseToggleOptions<Truthy, Falsy>): [Ref<T>, (value?: T) => T];
|
|
@@ -809,7 +814,7 @@ declare function watchWithFilter<T, Immediate extends Readonly<boolean> = false>
|
|
|
809
814
|
declare function watchWithFilter<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchStopHandle;
|
|
810
815
|
|
|
811
816
|
interface WatchAtMostOptions<Immediate> extends WatchWithFilterOptions<Immediate> {
|
|
812
|
-
count:
|
|
817
|
+
count: MaybeComputedRef<number>;
|
|
813
818
|
}
|
|
814
819
|
interface WatchAtMostReturn {
|
|
815
820
|
stop: WatchStopHandle;
|
|
@@ -819,7 +824,7 @@ declare function watchAtMost<T extends Readonly<WatchSource<unknown>[]>, Immedia
|
|
|
819
824
|
declare function watchAtMost<T, Immediate extends Readonly<boolean> = false>(sources: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options: WatchAtMostOptions<Immediate>): WatchAtMostReturn;
|
|
820
825
|
|
|
821
826
|
interface WatchDebouncedOptions<Immediate> extends WatchOptions<Immediate>, DebounceFilterOptions {
|
|
822
|
-
debounce?:
|
|
827
|
+
debounce?: MaybeComputedRef<number>;
|
|
823
828
|
}
|
|
824
829
|
declare function watchDebounced<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchDebouncedOptions<Immediate>): WatchStopHandle;
|
|
825
830
|
declare function watchDebounced<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchDebouncedOptions<Immediate>): WatchStopHandle;
|
|
@@ -846,7 +851,7 @@ declare function watchPausable<T, Immediate extends Readonly<boolean> = false>(s
|
|
|
846
851
|
declare function watchPausable<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchPausableReturn;
|
|
847
852
|
|
|
848
853
|
interface WatchThrottledOptions<Immediate> extends WatchOptions<Immediate> {
|
|
849
|
-
throttle?:
|
|
854
|
+
throttle?: MaybeComputedRef<number>;
|
|
850
855
|
trailing?: boolean;
|
|
851
856
|
leading?: boolean;
|
|
852
857
|
}
|
|
@@ -871,4 +876,4 @@ declare function watchTriggerable<T extends object, FnReturnT>(source: T, cb: Wa
|
|
|
871
876
|
*/
|
|
872
877
|
declare function whenever<T>(source: WatchSource<T | false | null | undefined>, cb: WatchCallback<T>, options?: WatchOptions): vue_demi.WatchStopHandle;
|
|
873
878
|
|
|
874
|
-
export { Awaitable, ComputedRefWithControl, ComputedWithControlRefExtra, ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, CreateGlobalStateReturn, DateLike, DebounceFilterOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnoredUpdater,
|
|
879
|
+
export { ArgumentsType, Awaitable, ComputedRefWithControl, ComputedWithControlRefExtra, ConfigurableEventFilter, ConfigurableFlush, ConfigurableFlushSync, ControlledRefOptions, CreateGlobalStateReturn, DateLike, DebounceFilterOptions, DeepMaybeRef, ElementOf, EventFilter, EventHook, EventHookOff, EventHookOn, EventHookTrigger, ExtendRefOptions, Fn, FunctionArgs, FunctionWrapperOptions, IgnoredUpdater, MapOldSources, MapSources, MaybeComputedRef, MaybeRef, Pausable, Reactified, ReactifyNested, ReactifyObjectOptions, ReactifyOptions, RemovableRef, RemoveableRef, ShallowUnwrapRef, SingletonPromiseReturn, Stopable, Stoppable, SyncRefOptions, SyncRefsOptions, UntilArrayInstance, UntilBaseInstance, UntilToMatchOptions, UntilValueInstance, UseArrayReducer, UseCounterOptions, UseDateFormatReturn, UseIntervalFnOptions, UseIntervalOptions, UseLastChangedOptions, UseTimeoutFnOptions, UseTimeoutOptions, UseToggleOptions, WatchArrayCallback, WatchAtMostOptions, WatchAtMostReturn, WatchDebouncedOptions, WatchIgnorableReturn, WatchPausableReturn, WatchThrottledOptions, WatchTriggerableCallback, WatchTriggerableReturn, WatchWithFilterOptions, WritableComputedRefWithControl, __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, 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 };
|