@vueuse/shared 12.2.0 → 12.4.0
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 +95 -92
- package/index.d.cts +10 -5
- package/index.d.mts +10 -5
- package/index.d.ts +10 -5
- package/index.iife.js +95 -92
- package/index.iife.min.js +1 -1
- package/index.mjs +96 -94
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { shallowRef, watchEffect, readonly, ref, watch, customRef, getCurrentScope, onScopeDispose, effectScope, getCurrentInstance, hasInjectionContext, inject, provide, isRef, unref, computed, reactive, toRefs as toRefs$1, toRef as toRef$1, onBeforeMount, nextTick, onBeforeUnmount, onMounted, onUnmounted, isReactive } from 'vue';
|
|
1
|
+
import { shallowRef, watchEffect, readonly, ref, watch, customRef, getCurrentScope, onScopeDispose, effectScope, getCurrentInstance, hasInjectionContext, inject, provide, isRef, unref, toValue as toValue$1, computed, reactive, toRefs as toRefs$1, toRef as toRef$1, onBeforeMount, nextTick, onBeforeUnmount, onMounted, onUnmounted, isReactive } from 'vue';
|
|
2
2
|
|
|
3
3
|
function computedEager(fn, options) {
|
|
4
4
|
var _a;
|
|
@@ -7,13 +7,13 @@ function computedEager(fn, options) {
|
|
|
7
7
|
result.value = fn();
|
|
8
8
|
}, {
|
|
9
9
|
...options,
|
|
10
|
-
flush: (_a = options == null ?
|
|
10
|
+
flush: (_a = options == null ? undefined : options.flush) != null ? _a : "sync"
|
|
11
11
|
});
|
|
12
12
|
return readonly(result);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function computedWithControl(source, fn) {
|
|
16
|
-
let v =
|
|
16
|
+
let v = undefined;
|
|
17
17
|
let track;
|
|
18
18
|
let trigger;
|
|
19
19
|
const dirty = ref(true);
|
|
@@ -23,7 +23,7 @@ function computedWithControl(source, fn) {
|
|
|
23
23
|
};
|
|
24
24
|
watch(source, update, { flush: "sync" });
|
|
25
25
|
const get = typeof fn === "function" ? fn : fn.get;
|
|
26
|
-
const set = typeof fn === "function" ?
|
|
26
|
+
const set = typeof fn === "function" ? undefined : fn.set;
|
|
27
27
|
const result = customRef((_track, _trigger) => {
|
|
28
28
|
track = _track;
|
|
29
29
|
trigger = _trigger;
|
|
@@ -37,7 +37,7 @@ function computedWithControl(source, fn) {
|
|
|
37
37
|
return v;
|
|
38
38
|
},
|
|
39
39
|
set(v2) {
|
|
40
|
-
set == null ?
|
|
40
|
+
set == null ? undefined : set(v2);
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
});
|
|
@@ -99,7 +99,7 @@ const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
|
|
|
99
99
|
const injectLocal = (...args) => {
|
|
100
100
|
var _a;
|
|
101
101
|
const key = args[0];
|
|
102
|
-
const instance = (_a = getCurrentInstance()) == null ?
|
|
102
|
+
const instance = (_a = getCurrentInstance()) == null ? undefined : _a.proxy;
|
|
103
103
|
if (instance == null && !hasInjectionContext())
|
|
104
104
|
throw new Error("injectLocal must be called in setup");
|
|
105
105
|
if (instance && localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance))
|
|
@@ -109,7 +109,7 @@ const injectLocal = (...args) => {
|
|
|
109
109
|
|
|
110
110
|
const provideLocal = (key, value) => {
|
|
111
111
|
var _a;
|
|
112
|
-
const instance = (_a = getCurrentInstance()) == null ?
|
|
112
|
+
const instance = (_a = getCurrentInstance()) == null ? undefined : _a.proxy;
|
|
113
113
|
if (instance == null)
|
|
114
114
|
throw new Error("provideLocal must be called in setup");
|
|
115
115
|
if (!localProvidedStateMap.has(instance))
|
|
@@ -120,8 +120,8 @@ const provideLocal = (key, value) => {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
function createInjectionState(composable, options) {
|
|
123
|
-
const key = (options == null ?
|
|
124
|
-
const defaultValue = options == null ?
|
|
123
|
+
const key = (options == null ? undefined : options.injectionKey) || Symbol(composable.name || "InjectionState");
|
|
124
|
+
const defaultValue = options == null ? undefined : options.defaultValue;
|
|
125
125
|
const useProvidingState = (...args) => {
|
|
126
126
|
const state = composable(...args);
|
|
127
127
|
provideLocal(key, state);
|
|
@@ -139,8 +139,8 @@ function createSharedComposable(composable) {
|
|
|
139
139
|
subscribers -= 1;
|
|
140
140
|
if (scope && subscribers <= 0) {
|
|
141
141
|
scope.stop();
|
|
142
|
-
state =
|
|
143
|
-
scope =
|
|
142
|
+
state = undefined;
|
|
143
|
+
scope = undefined;
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
146
|
return (...args) => {
|
|
@@ -206,13 +206,8 @@ function makeDestructurable(obj, arr) {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
function toValue(r) {
|
|
210
|
-
return typeof r === "function" ? r() : unref(r);
|
|
211
|
-
}
|
|
212
|
-
const resolveUnref = toValue;
|
|
213
|
-
|
|
214
209
|
function reactify(fn, options) {
|
|
215
|
-
const unrefFn = (options == null ?
|
|
210
|
+
const unrefFn = (options == null ? undefined : options.computedGetter) === false ? unref : toValue$1;
|
|
216
211
|
return function(...args) {
|
|
217
212
|
return computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
|
|
218
213
|
};
|
|
@@ -281,7 +276,7 @@ function reactiveComputed(fn) {
|
|
|
281
276
|
function reactiveOmit(obj, ...keys) {
|
|
282
277
|
const flatKeys = keys.flat();
|
|
283
278
|
const predicate = flatKeys[0];
|
|
284
|
-
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(toRefs$1(obj)).filter((e) => !flatKeys.includes(e[0]))));
|
|
279
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => !predicate(toValue$1(v), k))) : Object.fromEntries(Object.entries(toRefs$1(obj)).filter((e) => !flatKeys.includes(e[0]))));
|
|
285
280
|
}
|
|
286
281
|
|
|
287
282
|
const isClient = typeof window !== "undefined" && typeof document !== "undefined";
|
|
@@ -308,7 +303,7 @@ const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
|
|
|
308
303
|
const isIOS = /* @__PURE__ */ getIsIOS();
|
|
309
304
|
function getIsIOS() {
|
|
310
305
|
var _a, _b;
|
|
311
|
-
return isClient && ((_a = window == null ?
|
|
306
|
+
return isClient && ((_a = window == null ? undefined : window.navigator) == null ? undefined : _a.userAgent) && (/iP(?:ad|hone|od)/.test(window.navigator.userAgent) || ((_b = window == null ? undefined : window.navigator) == null ? undefined : _b.maxTouchPoints) > 2 && /iPad|Macintosh/.test(window == null ? undefined : window.navigator.userAgent));
|
|
312
307
|
}
|
|
313
308
|
|
|
314
309
|
function createFilterWrapper(filter, fn) {
|
|
@@ -332,11 +327,11 @@ function debounceFilter(ms, options = {}) {
|
|
|
332
327
|
lastRejector = noop;
|
|
333
328
|
};
|
|
334
329
|
const filter = (invoke) => {
|
|
335
|
-
const duration = toValue(ms);
|
|
336
|
-
const maxDuration = toValue(options.maxWait);
|
|
330
|
+
const duration = toValue$1(ms);
|
|
331
|
+
const maxDuration = toValue$1(options.maxWait);
|
|
337
332
|
if (timer)
|
|
338
333
|
_clearTimeout(timer);
|
|
339
|
-
if (duration <= 0 || maxDuration !==
|
|
334
|
+
if (duration <= 0 || maxDuration !== undefined && maxDuration <= 0) {
|
|
340
335
|
if (maxTimer) {
|
|
341
336
|
_clearTimeout(maxTimer);
|
|
342
337
|
maxTimer = null;
|
|
@@ -380,13 +375,13 @@ function throttleFilter(...args) {
|
|
|
380
375
|
const clear = () => {
|
|
381
376
|
if (timer) {
|
|
382
377
|
clearTimeout(timer);
|
|
383
|
-
timer =
|
|
378
|
+
timer = undefined;
|
|
384
379
|
lastRejector();
|
|
385
380
|
lastRejector = noop;
|
|
386
381
|
}
|
|
387
382
|
};
|
|
388
383
|
const filter = (_invoke) => {
|
|
389
|
-
const duration = toValue(ms);
|
|
384
|
+
const duration = toValue$1(ms);
|
|
390
385
|
const elapsed = Date.now() - lastExec;
|
|
391
386
|
const invoke = () => {
|
|
392
387
|
return lastValue = _invoke();
|
|
@@ -466,7 +461,7 @@ function createSingletonPromise(fn) {
|
|
|
466
461
|
}
|
|
467
462
|
wrapper.reset = async () => {
|
|
468
463
|
const _prev = _promise;
|
|
469
|
-
_promise =
|
|
464
|
+
_promise = undefined;
|
|
470
465
|
if (_prev)
|
|
471
466
|
await _prev;
|
|
472
467
|
};
|
|
@@ -482,7 +477,7 @@ function increaseWithUnit(target, delta) {
|
|
|
482
477
|
var _a;
|
|
483
478
|
if (typeof target === "number")
|
|
484
479
|
return target + delta;
|
|
485
|
-
const value = ((_a = target.match(/^-?\d+\.?\d*/)) == null ?
|
|
480
|
+
const value = ((_a = target.match(/^-?\d+\.?\d*/)) == null ? undefined : _a[0]) || "";
|
|
486
481
|
const unit = target.slice(value.length);
|
|
487
482
|
const result = Number.parseFloat(value) + delta;
|
|
488
483
|
if (Number.isNaN(result))
|
|
@@ -495,7 +490,7 @@ function pxValue(px) {
|
|
|
495
490
|
function objectPick(obj, keys, omitUndefined = false) {
|
|
496
491
|
return keys.reduce((n, k) => {
|
|
497
492
|
if (k in obj) {
|
|
498
|
-
if (!omitUndefined || obj[k] !==
|
|
493
|
+
if (!omitUndefined || obj[k] !== undefined)
|
|
499
494
|
n[k] = obj[k];
|
|
500
495
|
}
|
|
501
496
|
return n;
|
|
@@ -503,7 +498,7 @@ function objectPick(obj, keys, omitUndefined = false) {
|
|
|
503
498
|
}
|
|
504
499
|
function objectOmit(obj, keys, omitUndefined = false) {
|
|
505
500
|
return Object.fromEntries(Object.entries(obj).filter(([key, value]) => {
|
|
506
|
-
return (!omitUndefined || value !==
|
|
501
|
+
return (!omitUndefined || value !== undefined) && !keys.includes(key);
|
|
507
502
|
}));
|
|
508
503
|
}
|
|
509
504
|
function objectEntries(obj) {
|
|
@@ -512,6 +507,9 @@ function objectEntries(obj) {
|
|
|
512
507
|
function getLifeCycleTarget(target) {
|
|
513
508
|
return target || getCurrentInstance();
|
|
514
509
|
}
|
|
510
|
+
function toArray(value) {
|
|
511
|
+
return Array.isArray(value) ? value : [value];
|
|
512
|
+
}
|
|
515
513
|
|
|
516
514
|
function toRef(...args) {
|
|
517
515
|
if (args.length !== 1)
|
|
@@ -524,17 +522,17 @@ const resolveRef = toRef;
|
|
|
524
522
|
function reactivePick(obj, ...keys) {
|
|
525
523
|
const flatKeys = keys.flat();
|
|
526
524
|
const predicate = flatKeys[0];
|
|
527
|
-
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => predicate(toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
|
|
525
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(toRefs$1(obj)).filter(([k, v]) => predicate(toValue$1(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
|
|
528
526
|
}
|
|
529
527
|
|
|
530
528
|
function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
531
529
|
return customRef((track, trigger) => {
|
|
532
|
-
let value = toValue(defaultValue);
|
|
530
|
+
let value = toValue$1(defaultValue);
|
|
533
531
|
let timer;
|
|
534
532
|
const resetAfter = () => setTimeout(() => {
|
|
535
|
-
value = toValue(defaultValue);
|
|
533
|
+
value = toValue$1(defaultValue);
|
|
536
534
|
trigger();
|
|
537
|
-
}, toValue(afterMs));
|
|
535
|
+
}, toValue$1(afterMs));
|
|
538
536
|
tryOnScopeDispose(() => {
|
|
539
537
|
clearTimeout(timer);
|
|
540
538
|
});
|
|
@@ -625,10 +623,10 @@ function refWithControl(initial, options = {}) {
|
|
|
625
623
|
if (value === source)
|
|
626
624
|
return;
|
|
627
625
|
const old = source;
|
|
628
|
-
if (((_a = options.onBeforeChange) == null ?
|
|
626
|
+
if (((_a = options.onBeforeChange) == null ? undefined : _a.call(options, value, old)) === false)
|
|
629
627
|
return;
|
|
630
628
|
source = value;
|
|
631
|
-
(_b = options.onChanged) == null ?
|
|
629
|
+
(_b = options.onChanged) == null ? undefined : _b.call(options, value, old);
|
|
632
630
|
if (triggering)
|
|
633
631
|
trigger();
|
|
634
632
|
}
|
|
@@ -739,8 +737,7 @@ function syncRefs(source, targets, options = {}) {
|
|
|
739
737
|
deep = false,
|
|
740
738
|
immediate = true
|
|
741
739
|
} = options;
|
|
742
|
-
|
|
743
|
-
targets = [targets];
|
|
740
|
+
targets = toArray(targets);
|
|
744
741
|
return watch(
|
|
745
742
|
source,
|
|
746
743
|
(newValue) => targets.forEach((target) => target.value = newValue),
|
|
@@ -759,7 +756,7 @@ function toRefs(objectRef, options = {}) {
|
|
|
759
756
|
},
|
|
760
757
|
set(v) {
|
|
761
758
|
var _a;
|
|
762
|
-
const replaceRef = (_a = toValue(options.replaceRef)) != null ? _a : true;
|
|
759
|
+
const replaceRef = (_a = toValue$1(options.replaceRef)) != null ? _a : true;
|
|
763
760
|
if (replaceRef) {
|
|
764
761
|
if (Array.isArray(objectRef.value)) {
|
|
765
762
|
const copy = [...objectRef.value];
|
|
@@ -779,6 +776,9 @@ function toRefs(objectRef, options = {}) {
|
|
|
779
776
|
return result;
|
|
780
777
|
}
|
|
781
778
|
|
|
779
|
+
const toValue = toValue$1;
|
|
780
|
+
const resolveUnref = toValue$1;
|
|
781
|
+
|
|
782
782
|
function tryOnBeforeMount(fn, sync = true, target) {
|
|
783
783
|
const instance = getLifeCycleTarget(target);
|
|
784
784
|
if (instance)
|
|
@@ -822,7 +822,7 @@ function createUntil(r, isNot = false) {
|
|
|
822
822
|
if (stop)
|
|
823
823
|
stop();
|
|
824
824
|
else
|
|
825
|
-
nextTick(() => stop == null ?
|
|
825
|
+
nextTick(() => stop == null ? undefined : stop());
|
|
826
826
|
resolve(v);
|
|
827
827
|
}
|
|
828
828
|
},
|
|
@@ -836,7 +836,7 @@ function createUntil(r, isNot = false) {
|
|
|
836
836
|
const promises = [watcher];
|
|
837
837
|
if (timeout != null) {
|
|
838
838
|
promises.push(
|
|
839
|
-
promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => stop == null ?
|
|
839
|
+
promiseTimeout(timeout, throwOnTimeout).then(() => toValue$1(r)).finally(() => stop == null ? undefined : stop())
|
|
840
840
|
);
|
|
841
841
|
}
|
|
842
842
|
return Promise.race(promises);
|
|
@@ -854,7 +854,7 @@ function createUntil(r, isNot = false) {
|
|
|
854
854
|
if (stop)
|
|
855
855
|
stop();
|
|
856
856
|
else
|
|
857
|
-
nextTick(() => stop == null ?
|
|
857
|
+
nextTick(() => stop == null ? undefined : stop());
|
|
858
858
|
resolve(v1);
|
|
859
859
|
}
|
|
860
860
|
},
|
|
@@ -868,9 +868,9 @@ function createUntil(r, isNot = false) {
|
|
|
868
868
|
const promises = [watcher];
|
|
869
869
|
if (timeout != null) {
|
|
870
870
|
promises.push(
|
|
871
|
-
promiseTimeout(timeout, throwOnTimeout).then(() => toValue(r)).finally(() => {
|
|
872
|
-
stop == null ?
|
|
873
|
-
return toValue(r);
|
|
871
|
+
promiseTimeout(timeout, throwOnTimeout).then(() => toValue$1(r)).finally(() => {
|
|
872
|
+
stop == null ? undefined : stop();
|
|
873
|
+
return toValue$1(r);
|
|
874
874
|
})
|
|
875
875
|
);
|
|
876
876
|
}
|
|
@@ -883,7 +883,7 @@ function createUntil(r, isNot = false) {
|
|
|
883
883
|
return toBe(null, options);
|
|
884
884
|
}
|
|
885
885
|
function toBeUndefined(options) {
|
|
886
|
-
return toBe(
|
|
886
|
+
return toBe(undefined, options);
|
|
887
887
|
}
|
|
888
888
|
function toBeNaN(options) {
|
|
889
889
|
return toMatch(Number.isNaN, options);
|
|
@@ -891,7 +891,7 @@ function createUntil(r, isNot = false) {
|
|
|
891
891
|
function toContains(value, options) {
|
|
892
892
|
return toMatch((v) => {
|
|
893
893
|
const array = Array.from(v);
|
|
894
|
-
return array.includes(value) || array.includes(toValue(value));
|
|
894
|
+
return array.includes(value) || array.includes(toValue$1(value));
|
|
895
895
|
}, options);
|
|
896
896
|
}
|
|
897
897
|
function changed(options) {
|
|
@@ -904,7 +904,7 @@ function createUntil(r, isNot = false) {
|
|
|
904
904
|
return count >= n;
|
|
905
905
|
}, options);
|
|
906
906
|
}
|
|
907
|
-
if (Array.isArray(toValue(r))) {
|
|
907
|
+
if (Array.isArray(toValue$1(r))) {
|
|
908
908
|
const instance = {
|
|
909
909
|
toMatch,
|
|
910
910
|
toContains,
|
|
@@ -951,31 +951,31 @@ function useArrayDifference(...args) {
|
|
|
951
951
|
const key = compareFn;
|
|
952
952
|
compareFn = (value, othVal) => value[key] === othVal[key];
|
|
953
953
|
}
|
|
954
|
-
const diff1 = computed(() => toValue(list).filter((x) => toValue(values).findIndex((y) => compareFn(x, y)) === -1));
|
|
954
|
+
const diff1 = computed(() => toValue$1(list).filter((x) => toValue$1(values).findIndex((y) => compareFn(x, y)) === -1));
|
|
955
955
|
if (symmetric) {
|
|
956
|
-
const diff2 = computed(() => toValue(values).filter((x) => toValue(list).findIndex((y) => compareFn(x, y)) === -1));
|
|
957
|
-
return computed(() => symmetric ? [...toValue(diff1), ...toValue(diff2)] : toValue(diff1));
|
|
956
|
+
const diff2 = computed(() => toValue$1(values).filter((x) => toValue$1(list).findIndex((y) => compareFn(x, y)) === -1));
|
|
957
|
+
return computed(() => symmetric ? [...toValue$1(diff1), ...toValue$1(diff2)] : toValue$1(diff1));
|
|
958
958
|
} else {
|
|
959
959
|
return diff1;
|
|
960
960
|
}
|
|
961
961
|
}
|
|
962
962
|
|
|
963
963
|
function useArrayEvery(list, fn) {
|
|
964
|
-
return computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
|
|
964
|
+
return computed(() => toValue$1(list).every((element, index, array) => fn(toValue$1(element), index, array)));
|
|
965
965
|
}
|
|
966
966
|
|
|
967
967
|
function useArrayFilter(list, fn) {
|
|
968
|
-
return computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
|
|
968
|
+
return computed(() => toValue$1(list).map((i) => toValue$1(i)).filter(fn));
|
|
969
969
|
}
|
|
970
970
|
|
|
971
971
|
function useArrayFind(list, fn) {
|
|
972
|
-
return computed(() => toValue(
|
|
973
|
-
toValue(list).find((element, index, array) => fn(toValue(element), index, array))
|
|
972
|
+
return computed(() => toValue$1(
|
|
973
|
+
toValue$1(list).find((element, index, array) => fn(toValue$1(element), index, array))
|
|
974
974
|
));
|
|
975
975
|
}
|
|
976
976
|
|
|
977
977
|
function useArrayFindIndex(list, fn) {
|
|
978
|
-
return computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
|
|
978
|
+
return computed(() => toValue$1(list).findIndex((element, index, array) => fn(toValue$1(element), index, array)));
|
|
979
979
|
}
|
|
980
980
|
|
|
981
981
|
function findLast(arr, cb) {
|
|
@@ -984,11 +984,11 @@ function findLast(arr, cb) {
|
|
|
984
984
|
if (cb(arr[index], index, arr))
|
|
985
985
|
return arr[index];
|
|
986
986
|
}
|
|
987
|
-
return
|
|
987
|
+
return undefined;
|
|
988
988
|
}
|
|
989
989
|
function useArrayFindLast(list, fn) {
|
|
990
|
-
return computed(() => toValue(
|
|
991
|
-
!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))
|
|
990
|
+
return computed(() => toValue$1(
|
|
991
|
+
!Array.prototype.findLast ? findLast(toValue$1(list), (element, index, array) => fn(toValue$1(element), index, array)) : toValue$1(list).findLast((element, index, array) => fn(toValue$1(element), index, array))
|
|
992
992
|
));
|
|
993
993
|
}
|
|
994
994
|
|
|
@@ -1007,35 +1007,35 @@ function useArrayIncludes(...args) {
|
|
|
1007
1007
|
}
|
|
1008
1008
|
if (typeof comparator === "string") {
|
|
1009
1009
|
const key = comparator;
|
|
1010
|
-
comparator = (element, value2) => element[key] === toValue(value2);
|
|
1010
|
+
comparator = (element, value2) => element[key] === toValue$1(value2);
|
|
1011
1011
|
}
|
|
1012
|
-
comparator = comparator != null ? comparator : (element, value2) => element === toValue(value2);
|
|
1013
|
-
return computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(
|
|
1014
|
-
toValue(element),
|
|
1015
|
-
toValue(value),
|
|
1012
|
+
comparator = comparator != null ? comparator : (element, value2) => element === toValue$1(value2);
|
|
1013
|
+
return computed(() => toValue$1(list).slice(formIndex).some((element, index, array) => comparator(
|
|
1014
|
+
toValue$1(element),
|
|
1015
|
+
toValue$1(value),
|
|
1016
1016
|
index,
|
|
1017
|
-
toValue(array)
|
|
1017
|
+
toValue$1(array)
|
|
1018
1018
|
)));
|
|
1019
1019
|
}
|
|
1020
1020
|
|
|
1021
1021
|
function useArrayJoin(list, separator) {
|
|
1022
|
-
return computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
|
|
1022
|
+
return computed(() => toValue$1(list).map((i) => toValue$1(i)).join(toValue$1(separator)));
|
|
1023
1023
|
}
|
|
1024
1024
|
|
|
1025
1025
|
function useArrayMap(list, fn) {
|
|
1026
|
-
return computed(() => toValue(list).map((i) => toValue(i)).map(fn));
|
|
1026
|
+
return computed(() => toValue$1(list).map((i) => toValue$1(i)).map(fn));
|
|
1027
1027
|
}
|
|
1028
1028
|
|
|
1029
1029
|
function useArrayReduce(list, reducer, ...args) {
|
|
1030
|
-
const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
|
|
1030
|
+
const reduceCallback = (sum, value, index) => reducer(toValue$1(sum), toValue$1(value), index);
|
|
1031
1031
|
return computed(() => {
|
|
1032
|
-
const resolved = toValue(list);
|
|
1033
|
-
return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue(args[0]()) : toValue(args[0])) : resolved.reduce(reduceCallback);
|
|
1032
|
+
const resolved = toValue$1(list);
|
|
1033
|
+
return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue$1(args[0]()) : toValue$1(args[0])) : resolved.reduce(reduceCallback);
|
|
1034
1034
|
});
|
|
1035
1035
|
}
|
|
1036
1036
|
|
|
1037
1037
|
function useArraySome(list, fn) {
|
|
1038
|
-
return computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
|
|
1038
|
+
return computed(() => toValue$1(list).some((element, index, array) => fn(toValue$1(element), index, array)));
|
|
1039
1039
|
}
|
|
1040
1040
|
|
|
1041
1041
|
function uniq(array) {
|
|
@@ -1050,7 +1050,7 @@ function uniqueElementsBy(array, fn) {
|
|
|
1050
1050
|
}
|
|
1051
1051
|
function useArrayUnique(list, compareFn) {
|
|
1052
1052
|
return computed(() => {
|
|
1053
|
-
const resolvedList = toValue(list).map((element) => toValue(element));
|
|
1053
|
+
const resolvedList = toValue$1(list).map((element) => toValue$1(element));
|
|
1054
1054
|
return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
|
|
1055
1055
|
});
|
|
1056
1056
|
}
|
|
@@ -1104,8 +1104,8 @@ function formatDate(date, formatStr, options = {}) {
|
|
|
1104
1104
|
M: () => month + 1,
|
|
1105
1105
|
Mo: () => formatOrdinal(month + 1),
|
|
1106
1106
|
MM: () => `${month + 1}`.padStart(2, "0"),
|
|
1107
|
-
MMM: () => date.toLocaleDateString(toValue(options.locales), { month: "short" }),
|
|
1108
|
-
MMMM: () => date.toLocaleDateString(toValue(options.locales), { month: "long" }),
|
|
1107
|
+
MMM: () => date.toLocaleDateString(toValue$1(options.locales), { month: "short" }),
|
|
1108
|
+
MMMM: () => date.toLocaleDateString(toValue$1(options.locales), { month: "long" }),
|
|
1109
1109
|
D: () => String(days),
|
|
1110
1110
|
Do: () => formatOrdinal(days),
|
|
1111
1111
|
DD: () => `${days}`.padStart(2, "0"),
|
|
@@ -1123,9 +1123,9 @@ function formatDate(date, formatStr, options = {}) {
|
|
|
1123
1123
|
ss: () => `${seconds}`.padStart(2, "0"),
|
|
1124
1124
|
SSS: () => `${milliseconds}`.padStart(3, "0"),
|
|
1125
1125
|
d: () => day,
|
|
1126
|
-
dd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "narrow" }),
|
|
1127
|
-
ddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "short" }),
|
|
1128
|
-
dddd: () => date.toLocaleDateString(toValue(options.locales), { weekday: "long" }),
|
|
1126
|
+
dd: () => date.toLocaleDateString(toValue$1(options.locales), { weekday: "narrow" }),
|
|
1127
|
+
ddd: () => date.toLocaleDateString(toValue$1(options.locales), { weekday: "short" }),
|
|
1128
|
+
dddd: () => date.toLocaleDateString(toValue$1(options.locales), { weekday: "long" }),
|
|
1129
1129
|
A: () => meridiem(hours, minutes),
|
|
1130
1130
|
AA: () => meridiem(hours, minutes, false, true),
|
|
1131
1131
|
a: () => meridiem(hours, minutes, true),
|
|
@@ -1133,13 +1133,13 @@ function formatDate(date, formatStr, options = {}) {
|
|
|
1133
1133
|
};
|
|
1134
1134
|
return formatStr.replace(REGEX_FORMAT, (match, $1) => {
|
|
1135
1135
|
var _a2, _b;
|
|
1136
|
-
return (_b = $1 != null ? $1 : (_a2 = matches[match]) == null ?
|
|
1136
|
+
return (_b = $1 != null ? $1 : (_a2 = matches[match]) == null ? undefined : _a2.call(matches)) != null ? _b : match;
|
|
1137
1137
|
});
|
|
1138
1138
|
}
|
|
1139
1139
|
function normalizeDate(date) {
|
|
1140
1140
|
if (date === null)
|
|
1141
1141
|
return new Date(Number.NaN);
|
|
1142
|
-
if (date ===
|
|
1142
|
+
if (date === undefined)
|
|
1143
1143
|
return /* @__PURE__ */ new Date();
|
|
1144
1144
|
if (date instanceof Date)
|
|
1145
1145
|
return new Date(date);
|
|
@@ -1154,7 +1154,7 @@ function normalizeDate(date) {
|
|
|
1154
1154
|
return new Date(date);
|
|
1155
1155
|
}
|
|
1156
1156
|
function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
|
|
1157
|
-
return computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
|
|
1157
|
+
return computed(() => formatDate(normalizeDate(toValue$1(date)), toValue$1(formatStr), options));
|
|
1158
1158
|
}
|
|
1159
1159
|
|
|
1160
1160
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
@@ -1175,7 +1175,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
1175
1175
|
clean();
|
|
1176
1176
|
}
|
|
1177
1177
|
function resume() {
|
|
1178
|
-
const intervalValue = toValue(interval);
|
|
1178
|
+
const intervalValue = toValue$1(interval);
|
|
1179
1179
|
if (intervalValue <= 0)
|
|
1180
1180
|
return;
|
|
1181
1181
|
isActive.value = true;
|
|
@@ -1266,7 +1266,7 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1266
1266
|
isPending.value = false;
|
|
1267
1267
|
timer = null;
|
|
1268
1268
|
cb(...args);
|
|
1269
|
-
}, toValue(interval));
|
|
1269
|
+
}, toValue$1(interval));
|
|
1270
1270
|
}
|
|
1271
1271
|
if (immediate) {
|
|
1272
1272
|
isPending.value = true;
|
|
@@ -1309,8 +1309,10 @@ function useToNumber(value, options = {}) {
|
|
|
1309
1309
|
nanToZero
|
|
1310
1310
|
} = options;
|
|
1311
1311
|
return computed(() => {
|
|
1312
|
-
let resolved = toValue(value);
|
|
1313
|
-
if (typeof
|
|
1312
|
+
let resolved = toValue$1(value);
|
|
1313
|
+
if (typeof method === "function")
|
|
1314
|
+
resolved = method(resolved);
|
|
1315
|
+
else if (typeof resolved === "string")
|
|
1314
1316
|
resolved = Number[method](resolved, radix);
|
|
1315
1317
|
if (nanToZero && Number.isNaN(resolved))
|
|
1316
1318
|
resolved = 0;
|
|
@@ -1319,7 +1321,7 @@ function useToNumber(value, options = {}) {
|
|
|
1319
1321
|
}
|
|
1320
1322
|
|
|
1321
1323
|
function useToString(value) {
|
|
1322
|
-
return computed(() => `${toValue(value)}`);
|
|
1324
|
+
return computed(() => `${toValue$1(value)}`);
|
|
1323
1325
|
}
|
|
1324
1326
|
|
|
1325
1327
|
function useToggle(initialValue = false, options = {}) {
|
|
@@ -1334,8 +1336,8 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1334
1336
|
_value.value = value;
|
|
1335
1337
|
return _value.value;
|
|
1336
1338
|
} else {
|
|
1337
|
-
const truthy = toValue(truthyValue);
|
|
1338
|
-
_value.value = _value.value === truthy ? toValue(falsyValue) : truthy;
|
|
1339
|
+
const truthy = toValue$1(truthyValue);
|
|
1340
|
+
_value.value = _value.value === truthy ? toValue$1(falsyValue) : truthy;
|
|
1339
1341
|
return _value.value;
|
|
1340
1342
|
}
|
|
1341
1343
|
}
|
|
@@ -1346,7 +1348,7 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1346
1348
|
}
|
|
1347
1349
|
|
|
1348
1350
|
function watchArray(source, cb, options) {
|
|
1349
|
-
let oldList = (options == null ?
|
|
1351
|
+
let oldList = (options == null ? undefined : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue$1(source)];
|
|
1350
1352
|
return watch(source, (newList, _, onCleanup) => {
|
|
1351
1353
|
const oldListRemains = Array.from({ length: oldList.length });
|
|
1352
1354
|
const added = [];
|
|
@@ -1378,7 +1380,7 @@ function watchAtMost(source, cb, options) {
|
|
|
1378
1380
|
source,
|
|
1379
1381
|
(...args) => {
|
|
1380
1382
|
current.value += 1;
|
|
1381
|
-
if (current.value >= toValue(count))
|
|
1383
|
+
if (current.value >= toValue$1(count))
|
|
1382
1384
|
nextTick(() => stop());
|
|
1383
1385
|
cb(...args);
|
|
1384
1386
|
},
|
|
@@ -1390,7 +1392,7 @@ function watchAtMost(source, cb, options) {
|
|
|
1390
1392
|
function watchDebounced(source, cb, options = {}) {
|
|
1391
1393
|
const {
|
|
1392
1394
|
debounce = 0,
|
|
1393
|
-
maxWait =
|
|
1395
|
+
maxWait = undefined,
|
|
1394
1396
|
...watchOptions
|
|
1395
1397
|
} = options;
|
|
1396
1398
|
return watchWithFilter(
|
|
@@ -1527,7 +1529,7 @@ function watchTriggerable(source, cb, options = {}) {
|
|
|
1527
1529
|
if (!cleanupFn)
|
|
1528
1530
|
return;
|
|
1529
1531
|
const fn = cleanupFn;
|
|
1530
|
-
cleanupFn =
|
|
1532
|
+
cleanupFn = undefined;
|
|
1531
1533
|
fn();
|
|
1532
1534
|
}
|
|
1533
1535
|
function onCleanup(callback) {
|
|
@@ -1555,11 +1557,11 @@ function getWatchSources(sources) {
|
|
|
1555
1557
|
if (isReactive(sources))
|
|
1556
1558
|
return sources;
|
|
1557
1559
|
if (Array.isArray(sources))
|
|
1558
|
-
return sources.map((item) => toValue(item));
|
|
1559
|
-
return toValue(sources);
|
|
1560
|
+
return sources.map((item) => toValue$1(item));
|
|
1561
|
+
return toValue$1(sources);
|
|
1560
1562
|
}
|
|
1561
1563
|
function getOldValue(source) {
|
|
1562
|
-
return Array.isArray(source) ? source.map(() =>
|
|
1564
|
+
return Array.isArray(source) ? source.map(() => undefined) : undefined;
|
|
1563
1565
|
}
|
|
1564
1566
|
|
|
1565
1567
|
function whenever(source, cb, options) {
|
|
@@ -1567,7 +1569,7 @@ function whenever(source, cb, options) {
|
|
|
1567
1569
|
source,
|
|
1568
1570
|
(v, ov, onInvalidate) => {
|
|
1569
1571
|
if (v) {
|
|
1570
|
-
if (options == null ?
|
|
1572
|
+
if (options == null ? undefined : options.once)
|
|
1571
1573
|
nextTick(() => stop());
|
|
1572
1574
|
cb(v, ov, onInvalidate);
|
|
1573
1575
|
}
|
|
@@ -1580,4 +1582,4 @@ function whenever(source, cb, options) {
|
|
|
1580
1582
|
return stop;
|
|
1581
1583
|
}
|
|
1582
1584
|
|
|
1583
|
-
export { assert, refAutoReset as autoResetRef, bypassFilter, camelize, clamp, computedEager, computedWithControl, containsProp, computedWithControl as controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createInjectionState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, refDebounced as debouncedRef, watchDebounced as debouncedWatch, computedEager as eagerComputed, extendRef, formatDate, get, getLifeCycleTarget, hasOwn, hyphenate, identity, watchIgnorable as ignorableWatch, increaseWithUnit, injectLocal, invoke, isClient, isDef, isDefined, isIOS, isObject, isWorker, makeDestructurable, noop, normalizeDate, notNullish, now, objectEntries, objectOmit, objectPick, pausableFilter, watchPausable as pausableWatch, promiseTimeout, provideLocal, pxValue, 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, toRef, toRefs, toValue, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useArrayDifference, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayFindLast, useArrayIncludes, useArrayJoin, useArrayMap, useArrayReduce, useArraySome, useArrayUnique, useCounter, useDateFormat, refDebounced as useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, refThrottled as useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToNumber, useToString, useToggle, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };
|
|
1585
|
+
export { assert, refAutoReset as autoResetRef, bypassFilter, camelize, clamp, computedEager, computedWithControl, containsProp, computedWithControl as controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createInjectionState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, refDebounced as debouncedRef, watchDebounced as debouncedWatch, computedEager as eagerComputed, extendRef, formatDate, get, getLifeCycleTarget, hasOwn, hyphenate, identity, watchIgnorable as ignorableWatch, increaseWithUnit, injectLocal, invoke, isClient, isDef, isDefined, isIOS, isObject, isWorker, makeDestructurable, noop, normalizeDate, notNullish, now, objectEntries, objectOmit, objectPick, pausableFilter, watchPausable as pausableWatch, promiseTimeout, provideLocal, pxValue, rand, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refThrottled, refWithControl, resolveRef, resolveUnref, set, syncRef, syncRefs, throttleFilter, refThrottled as throttledRef, watchThrottled as throttledWatch, timestamp, toArray, toReactive, toRef, toRefs, toValue, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useArrayDifference, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayFindLast, useArrayIncludes, useArrayJoin, useArrayMap, useArrayReduce, useArraySome, useArrayUnique, useCounter, useDateFormat, refDebounced as useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, refThrottled as useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToNumber, useToString, useToggle, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };
|