@vueuse/shared 11.2.0 → 12.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 +105 -121
- package/index.d.cts +4 -17
- package/index.d.mts +4 -17
- package/index.d.ts +4 -17
- package/index.iife.js +106 -249
- package/index.iife.min.js +1 -1
- package/index.mjs +4 -19
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var vue = require('vue');
|
|
4
4
|
|
|
5
5
|
function computedEager(fn, options) {
|
|
6
6
|
var _a;
|
|
7
|
-
const result =
|
|
8
|
-
|
|
7
|
+
const result = vue.shallowRef();
|
|
8
|
+
vue.watchEffect(() => {
|
|
9
9
|
result.value = fn();
|
|
10
10
|
}, {
|
|
11
11
|
...options,
|
|
12
12
|
flush: (_a = options == null ? void 0 : options.flush) != null ? _a : "sync"
|
|
13
13
|
});
|
|
14
|
-
return
|
|
14
|
+
return vue.readonly(result);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
function computedWithControl(source, fn) {
|
|
18
18
|
let v = void 0;
|
|
19
19
|
let track;
|
|
20
20
|
let trigger;
|
|
21
|
-
const dirty =
|
|
21
|
+
const dirty = vue.ref(true);
|
|
22
22
|
const update = () => {
|
|
23
23
|
dirty.value = true;
|
|
24
24
|
trigger();
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
vue.watch(source, update, { flush: "sync" });
|
|
27
27
|
const get = typeof fn === "function" ? fn : fn.get;
|
|
28
28
|
const set = typeof fn === "function" ? void 0 : fn.set;
|
|
29
|
-
const result =
|
|
29
|
+
const result = vue.customRef((_track, _trigger) => {
|
|
30
30
|
track = _track;
|
|
31
31
|
trigger = _trigger;
|
|
32
32
|
return {
|
|
@@ -49,8 +49,8 @@ function computedWithControl(source, fn) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
function tryOnScopeDispose(fn) {
|
|
52
|
-
if (
|
|
53
|
-
|
|
52
|
+
if (vue.getCurrentScope()) {
|
|
53
|
+
vue.onScopeDispose(fn);
|
|
54
54
|
return true;
|
|
55
55
|
}
|
|
56
56
|
return false;
|
|
@@ -82,7 +82,7 @@ function createEventHook() {
|
|
|
82
82
|
function createGlobalState(stateFactory) {
|
|
83
83
|
let initialized = false;
|
|
84
84
|
let state;
|
|
85
|
-
const scope =
|
|
85
|
+
const scope = vue.effectScope(true);
|
|
86
86
|
return (...args) => {
|
|
87
87
|
if (!initialized) {
|
|
88
88
|
state = scope.run(() => stateFactory(...args));
|
|
@@ -97,24 +97,24 @@ const localProvidedStateMap = /* @__PURE__ */ new WeakMap();
|
|
|
97
97
|
const injectLocal = (...args) => {
|
|
98
98
|
var _a;
|
|
99
99
|
const key = args[0];
|
|
100
|
-
const instance = (_a =
|
|
100
|
+
const instance = (_a = vue.getCurrentInstance()) == null ? void 0 : _a.proxy;
|
|
101
101
|
if (instance == null)
|
|
102
102
|
throw new Error("injectLocal must be called in setup");
|
|
103
103
|
if (localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance))
|
|
104
104
|
return localProvidedStateMap.get(instance)[key];
|
|
105
|
-
return
|
|
105
|
+
return vue.inject(...args);
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
const provideLocal = (key, value) => {
|
|
109
109
|
var _a;
|
|
110
|
-
const instance = (_a =
|
|
110
|
+
const instance = (_a = vue.getCurrentInstance()) == null ? void 0 : _a.proxy;
|
|
111
111
|
if (instance == null)
|
|
112
112
|
throw new Error("provideLocal must be called in setup");
|
|
113
113
|
if (!localProvidedStateMap.has(instance))
|
|
114
114
|
localProvidedStateMap.set(instance, /* @__PURE__ */ Object.create(null));
|
|
115
115
|
const localProvidedState = localProvidedStateMap.get(instance);
|
|
116
116
|
localProvidedState[key] = value;
|
|
117
|
-
|
|
117
|
+
vue.provide(key, value);
|
|
118
118
|
};
|
|
119
119
|
|
|
120
120
|
function createInjectionState(composable, options) {
|
|
@@ -144,7 +144,7 @@ function createSharedComposable(composable) {
|
|
|
144
144
|
return (...args) => {
|
|
145
145
|
subscribers += 1;
|
|
146
146
|
if (!scope) {
|
|
147
|
-
scope =
|
|
147
|
+
scope = vue.effectScope(true);
|
|
148
148
|
state = scope.run(() => composable(...args));
|
|
149
149
|
}
|
|
150
150
|
tryOnScopeDispose(dispose);
|
|
@@ -153,15 +153,10 @@ function createSharedComposable(composable) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) {
|
|
156
|
-
if (!vueDemi.isVue3 && !vueDemi.version.startsWith("2.7.")) {
|
|
157
|
-
if (process.env.NODE_ENV !== "production")
|
|
158
|
-
throw new Error("[VueUse] extendRef only works in Vue 2.7 or above.");
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
156
|
for (const [key, value] of Object.entries(extend)) {
|
|
162
157
|
if (key === "value")
|
|
163
158
|
continue;
|
|
164
|
-
if (
|
|
159
|
+
if (vue.isRef(value) && unwrap) {
|
|
165
160
|
Object.defineProperty(ref, key, {
|
|
166
161
|
get() {
|
|
167
162
|
return value.value;
|
|
@@ -180,12 +175,12 @@ function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) {
|
|
|
180
175
|
|
|
181
176
|
function get(obj, key) {
|
|
182
177
|
if (key == null)
|
|
183
|
-
return
|
|
184
|
-
return
|
|
178
|
+
return vue.unref(obj);
|
|
179
|
+
return vue.unref(obj)[key];
|
|
185
180
|
}
|
|
186
181
|
|
|
187
182
|
function isDefined(v) {
|
|
188
|
-
return
|
|
183
|
+
return vue.unref(v) != null;
|
|
189
184
|
}
|
|
190
185
|
|
|
191
186
|
function makeDestructurable(obj, arr) {
|
|
@@ -210,14 +205,14 @@ function makeDestructurable(obj, arr) {
|
|
|
210
205
|
}
|
|
211
206
|
|
|
212
207
|
function toValue(r) {
|
|
213
|
-
return typeof r === "function" ? r() :
|
|
208
|
+
return typeof r === "function" ? r() : vue.unref(r);
|
|
214
209
|
}
|
|
215
210
|
const resolveUnref = toValue;
|
|
216
211
|
|
|
217
212
|
function reactify(fn, options) {
|
|
218
|
-
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ?
|
|
213
|
+
const unrefFn = (options == null ? void 0 : options.computedGetter) === false ? vue.unref : toValue;
|
|
219
214
|
return function(...args) {
|
|
220
|
-
return
|
|
215
|
+
return vue.computed(() => fn.apply(this, args.map((i) => unrefFn(i))));
|
|
221
216
|
};
|
|
222
217
|
}
|
|
223
218
|
|
|
@@ -245,14 +240,14 @@ function reactifyObject(obj, optionsOrKeys = {}) {
|
|
|
245
240
|
}
|
|
246
241
|
|
|
247
242
|
function toReactive(objectRef) {
|
|
248
|
-
if (!
|
|
249
|
-
return
|
|
243
|
+
if (!vue.isRef(objectRef))
|
|
244
|
+
return vue.reactive(objectRef);
|
|
250
245
|
const proxy = new Proxy({}, {
|
|
251
246
|
get(_, p, receiver) {
|
|
252
|
-
return
|
|
247
|
+
return vue.unref(Reflect.get(objectRef.value, p, receiver));
|
|
253
248
|
},
|
|
254
249
|
set(_, p, value) {
|
|
255
|
-
if (
|
|
250
|
+
if (vue.isRef(objectRef.value[p]) && !vue.isRef(value))
|
|
256
251
|
objectRef.value[p].value = value;
|
|
257
252
|
else
|
|
258
253
|
objectRef.value[p] = value;
|
|
@@ -274,25 +269,19 @@ function toReactive(objectRef) {
|
|
|
274
269
|
};
|
|
275
270
|
}
|
|
276
271
|
});
|
|
277
|
-
return
|
|
272
|
+
return vue.reactive(proxy);
|
|
278
273
|
}
|
|
279
274
|
|
|
280
275
|
function reactiveComputed(fn) {
|
|
281
|
-
return toReactive(
|
|
276
|
+
return toReactive(vue.computed(fn));
|
|
282
277
|
}
|
|
283
278
|
|
|
284
279
|
function reactiveOmit(obj, ...keys) {
|
|
285
280
|
const flatKeys = keys.flat();
|
|
286
281
|
const predicate = flatKeys[0];
|
|
287
|
-
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(
|
|
282
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vue.toRefs(obj)).filter(([k, v]) => !predicate(toValue(v), k))) : Object.fromEntries(Object.entries(vue.toRefs(obj)).filter((e) => !flatKeys.includes(e[0]))));
|
|
288
283
|
}
|
|
289
284
|
|
|
290
|
-
const directiveHooks = {
|
|
291
|
-
mounted: vueDemi.isVue3 ? "mounted" : "inserted",
|
|
292
|
-
updated: vueDemi.isVue3 ? "updated" : "componentUpdated",
|
|
293
|
-
unmounted: vueDemi.isVue3 ? "unmounted" : "unbind"
|
|
294
|
-
};
|
|
295
|
-
|
|
296
285
|
const isClient = typeof window !== "undefined" && typeof document !== "undefined";
|
|
297
286
|
const isWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
|
|
298
287
|
const isDef = (val) => typeof val !== "undefined";
|
|
@@ -382,7 +371,7 @@ function throttleFilter(...args) {
|
|
|
382
371
|
let trailing;
|
|
383
372
|
let leading;
|
|
384
373
|
let rejectOnCancel;
|
|
385
|
-
if (!
|
|
374
|
+
if (!vue.isRef(args[0]) && typeof args[0] === "object")
|
|
386
375
|
({ delay: ms, trailing = true, leading = true, rejectOnCancel = false } = args[0]);
|
|
387
376
|
else
|
|
388
377
|
[ms, trailing = true, leading = true, rejectOnCancel = false] = args;
|
|
@@ -427,7 +416,7 @@ function throttleFilter(...args) {
|
|
|
427
416
|
return filter;
|
|
428
417
|
}
|
|
429
418
|
function pausableFilter(extendFilter = bypassFilter) {
|
|
430
|
-
const isActive =
|
|
419
|
+
const isActive = vue.ref(true);
|
|
431
420
|
function pause() {
|
|
432
421
|
isActive.value = false;
|
|
433
422
|
}
|
|
@@ -438,7 +427,7 @@ function pausableFilter(extendFilter = bypassFilter) {
|
|
|
438
427
|
if (isActive.value)
|
|
439
428
|
extendFilter(...args);
|
|
440
429
|
};
|
|
441
|
-
return { isActive:
|
|
430
|
+
return { isActive: vue.readonly(isActive), pause, resume, eventFilter };
|
|
442
431
|
}
|
|
443
432
|
|
|
444
433
|
function cacheStringFunction(fn) {
|
|
@@ -516,25 +505,25 @@ function objectEntries(obj) {
|
|
|
516
505
|
return Object.entries(obj);
|
|
517
506
|
}
|
|
518
507
|
function getLifeCycleTarget(target) {
|
|
519
|
-
return target ||
|
|
508
|
+
return target || vue.getCurrentInstance();
|
|
520
509
|
}
|
|
521
510
|
|
|
522
511
|
function toRef(...args) {
|
|
523
512
|
if (args.length !== 1)
|
|
524
|
-
return
|
|
513
|
+
return vue.toRef(...args);
|
|
525
514
|
const r = args[0];
|
|
526
|
-
return typeof r === "function" ?
|
|
515
|
+
return typeof r === "function" ? vue.readonly(vue.customRef(() => ({ get: r, set: noop }))) : vue.ref(r);
|
|
527
516
|
}
|
|
528
517
|
const resolveRef = toRef;
|
|
529
518
|
|
|
530
519
|
function reactivePick(obj, ...keys) {
|
|
531
520
|
const flatKeys = keys.flat();
|
|
532
521
|
const predicate = flatKeys[0];
|
|
533
|
-
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(
|
|
522
|
+
return reactiveComputed(() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vue.toRefs(obj)).filter(([k, v]) => predicate(toValue(v), k))) : Object.fromEntries(flatKeys.map((k) => [k, toRef(obj, k)])));
|
|
534
523
|
}
|
|
535
524
|
|
|
536
525
|
function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
537
|
-
return
|
|
526
|
+
return vue.customRef((track, trigger) => {
|
|
538
527
|
let value = toValue(defaultValue);
|
|
539
528
|
let timer;
|
|
540
529
|
const resetAfter = () => setTimeout(() => {
|
|
@@ -567,16 +556,16 @@ function useDebounceFn(fn, ms = 200, options = {}) {
|
|
|
567
556
|
}
|
|
568
557
|
|
|
569
558
|
function refDebounced(value, ms = 200, options = {}) {
|
|
570
|
-
const debounced =
|
|
559
|
+
const debounced = vue.ref(value.value);
|
|
571
560
|
const updater = useDebounceFn(() => {
|
|
572
561
|
debounced.value = value.value;
|
|
573
562
|
}, ms, options);
|
|
574
|
-
|
|
563
|
+
vue.watch(value, () => updater());
|
|
575
564
|
return debounced;
|
|
576
565
|
}
|
|
577
566
|
|
|
578
567
|
function refDefault(source, defaultValue) {
|
|
579
|
-
return
|
|
568
|
+
return vue.computed({
|
|
580
569
|
get() {
|
|
581
570
|
var _a;
|
|
582
571
|
return (_a = source.value) != null ? _a : defaultValue;
|
|
@@ -597,11 +586,11 @@ function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnC
|
|
|
597
586
|
function refThrottled(value, delay = 200, trailing = true, leading = true) {
|
|
598
587
|
if (delay <= 0)
|
|
599
588
|
return value;
|
|
600
|
-
const throttled =
|
|
589
|
+
const throttled = vue.ref(value.value);
|
|
601
590
|
const updater = useThrottleFn(() => {
|
|
602
591
|
throttled.value = value.value;
|
|
603
592
|
}, delay, trailing, leading);
|
|
604
|
-
|
|
593
|
+
vue.watch(value, () => updater());
|
|
605
594
|
return throttled;
|
|
606
595
|
}
|
|
607
596
|
|
|
@@ -609,7 +598,7 @@ function refWithControl(initial, options = {}) {
|
|
|
609
598
|
let source = initial;
|
|
610
599
|
let track;
|
|
611
600
|
let trigger;
|
|
612
|
-
const ref =
|
|
601
|
+
const ref = vue.customRef((_track, _trigger) => {
|
|
613
602
|
track = _track;
|
|
614
603
|
trigger = _trigger;
|
|
615
604
|
return {
|
|
@@ -663,12 +652,8 @@ function set(...args) {
|
|
|
663
652
|
ref.value = value;
|
|
664
653
|
}
|
|
665
654
|
if (args.length === 3) {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
} else {
|
|
669
|
-
const [target, key, value] = args;
|
|
670
|
-
target[key] = value;
|
|
671
|
-
}
|
|
655
|
+
const [target, key, value] = args;
|
|
656
|
+
target[key] = value;
|
|
672
657
|
}
|
|
673
658
|
}
|
|
674
659
|
|
|
@@ -677,7 +662,7 @@ function watchWithFilter(source, cb, options = {}) {
|
|
|
677
662
|
eventFilter = bypassFilter,
|
|
678
663
|
...watchOptions
|
|
679
664
|
} = options;
|
|
680
|
-
return
|
|
665
|
+
return vue.watch(
|
|
681
666
|
source,
|
|
682
667
|
createFilterWrapper(
|
|
683
668
|
eventFilter,
|
|
@@ -751,7 +736,7 @@ function syncRefs(source, targets, options = {}) {
|
|
|
751
736
|
} = options;
|
|
752
737
|
if (!Array.isArray(targets))
|
|
753
738
|
targets = [targets];
|
|
754
|
-
return
|
|
739
|
+
return vue.watch(
|
|
755
740
|
source,
|
|
756
741
|
(newValue) => targets.forEach((target) => target.value = newValue),
|
|
757
742
|
{ flush, deep, immediate }
|
|
@@ -759,11 +744,11 @@ function syncRefs(source, targets, options = {}) {
|
|
|
759
744
|
}
|
|
760
745
|
|
|
761
746
|
function toRefs(objectRef, options = {}) {
|
|
762
|
-
if (!
|
|
763
|
-
return
|
|
747
|
+
if (!vue.isRef(objectRef))
|
|
748
|
+
return vue.toRefs(objectRef);
|
|
764
749
|
const result = Array.isArray(objectRef.value) ? Array.from({ length: objectRef.value.length }) : {};
|
|
765
750
|
for (const key in objectRef.value) {
|
|
766
|
-
result[key] =
|
|
751
|
+
result[key] = vue.customRef(() => ({
|
|
767
752
|
get() {
|
|
768
753
|
return objectRef.value[key];
|
|
769
754
|
},
|
|
@@ -792,47 +777,47 @@ function toRefs(objectRef, options = {}) {
|
|
|
792
777
|
function tryOnBeforeMount(fn, sync = true, target) {
|
|
793
778
|
const instance = getLifeCycleTarget(target);
|
|
794
779
|
if (instance)
|
|
795
|
-
|
|
780
|
+
vue.onBeforeMount(fn, target);
|
|
796
781
|
else if (sync)
|
|
797
782
|
fn();
|
|
798
783
|
else
|
|
799
|
-
|
|
784
|
+
vue.nextTick(fn);
|
|
800
785
|
}
|
|
801
786
|
|
|
802
787
|
function tryOnBeforeUnmount(fn, target) {
|
|
803
788
|
const instance = getLifeCycleTarget(target);
|
|
804
789
|
if (instance)
|
|
805
|
-
|
|
790
|
+
vue.onBeforeUnmount(fn, target);
|
|
806
791
|
}
|
|
807
792
|
|
|
808
793
|
function tryOnMounted(fn, sync = true, target) {
|
|
809
794
|
const instance = getLifeCycleTarget();
|
|
810
795
|
if (instance)
|
|
811
|
-
|
|
796
|
+
vue.onMounted(fn, target);
|
|
812
797
|
else if (sync)
|
|
813
798
|
fn();
|
|
814
799
|
else
|
|
815
|
-
|
|
800
|
+
vue.nextTick(fn);
|
|
816
801
|
}
|
|
817
802
|
|
|
818
803
|
function tryOnUnmounted(fn, target) {
|
|
819
804
|
const instance = getLifeCycleTarget(target);
|
|
820
805
|
if (instance)
|
|
821
|
-
|
|
806
|
+
vue.onUnmounted(fn, target);
|
|
822
807
|
}
|
|
823
808
|
|
|
824
809
|
function createUntil(r, isNot = false) {
|
|
825
810
|
function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
|
|
826
811
|
let stop = null;
|
|
827
812
|
const watcher = new Promise((resolve) => {
|
|
828
|
-
stop =
|
|
813
|
+
stop = vue.watch(
|
|
829
814
|
r,
|
|
830
815
|
(v) => {
|
|
831
816
|
if (condition(v) !== isNot) {
|
|
832
817
|
if (stop)
|
|
833
818
|
stop();
|
|
834
819
|
else
|
|
835
|
-
|
|
820
|
+
vue.nextTick(() => stop == null ? void 0 : stop());
|
|
836
821
|
resolve(v);
|
|
837
822
|
}
|
|
838
823
|
},
|
|
@@ -852,19 +837,19 @@ function createUntil(r, isNot = false) {
|
|
|
852
837
|
return Promise.race(promises);
|
|
853
838
|
}
|
|
854
839
|
function toBe(value, options) {
|
|
855
|
-
if (!
|
|
840
|
+
if (!vue.isRef(value))
|
|
856
841
|
return toMatch((v) => v === value, options);
|
|
857
842
|
const { flush = "sync", deep = false, timeout, throwOnTimeout } = options != null ? options : {};
|
|
858
843
|
let stop = null;
|
|
859
844
|
const watcher = new Promise((resolve) => {
|
|
860
|
-
stop =
|
|
845
|
+
stop = vue.watch(
|
|
861
846
|
[r, value],
|
|
862
847
|
([v1, v2]) => {
|
|
863
848
|
if (isNot !== (v1 === v2)) {
|
|
864
849
|
if (stop)
|
|
865
850
|
stop();
|
|
866
851
|
else
|
|
867
|
-
|
|
852
|
+
vue.nextTick(() => stop == null ? void 0 : stop());
|
|
868
853
|
resolve(v1);
|
|
869
854
|
}
|
|
870
855
|
},
|
|
@@ -958,25 +943,25 @@ function useArrayDifference(...args) {
|
|
|
958
943
|
const key = compareFn;
|
|
959
944
|
compareFn = (value, othVal) => value[key] === othVal[key];
|
|
960
945
|
}
|
|
961
|
-
return
|
|
946
|
+
return vue.computed(() => toValue(list).filter((x) => toValue(values).findIndex((y) => compareFn(x, y)) === -1));
|
|
962
947
|
}
|
|
963
948
|
|
|
964
949
|
function useArrayEvery(list, fn) {
|
|
965
|
-
return
|
|
950
|
+
return vue.computed(() => toValue(list).every((element, index, array) => fn(toValue(element), index, array)));
|
|
966
951
|
}
|
|
967
952
|
|
|
968
953
|
function useArrayFilter(list, fn) {
|
|
969
|
-
return
|
|
954
|
+
return vue.computed(() => toValue(list).map((i) => toValue(i)).filter(fn));
|
|
970
955
|
}
|
|
971
956
|
|
|
972
957
|
function useArrayFind(list, fn) {
|
|
973
|
-
return
|
|
958
|
+
return vue.computed(() => toValue(
|
|
974
959
|
toValue(list).find((element, index, array) => fn(toValue(element), index, array))
|
|
975
960
|
));
|
|
976
961
|
}
|
|
977
962
|
|
|
978
963
|
function useArrayFindIndex(list, fn) {
|
|
979
|
-
return
|
|
964
|
+
return vue.computed(() => toValue(list).findIndex((element, index, array) => fn(toValue(element), index, array)));
|
|
980
965
|
}
|
|
981
966
|
|
|
982
967
|
function findLast(arr, cb) {
|
|
@@ -988,7 +973,7 @@ function findLast(arr, cb) {
|
|
|
988
973
|
return void 0;
|
|
989
974
|
}
|
|
990
975
|
function useArrayFindLast(list, fn) {
|
|
991
|
-
return
|
|
976
|
+
return vue.computed(() => toValue(
|
|
992
977
|
!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))
|
|
993
978
|
));
|
|
994
979
|
}
|
|
@@ -1011,7 +996,7 @@ function useArrayIncludes(...args) {
|
|
|
1011
996
|
comparator = (element, value2) => element[key] === toValue(value2);
|
|
1012
997
|
}
|
|
1013
998
|
comparator = comparator != null ? comparator : (element, value2) => element === toValue(value2);
|
|
1014
|
-
return
|
|
999
|
+
return vue.computed(() => toValue(list).slice(formIndex).some((element, index, array) => comparator(
|
|
1015
1000
|
toValue(element),
|
|
1016
1001
|
toValue(value),
|
|
1017
1002
|
index,
|
|
@@ -1020,23 +1005,23 @@ function useArrayIncludes(...args) {
|
|
|
1020
1005
|
}
|
|
1021
1006
|
|
|
1022
1007
|
function useArrayJoin(list, separator) {
|
|
1023
|
-
return
|
|
1008
|
+
return vue.computed(() => toValue(list).map((i) => toValue(i)).join(toValue(separator)));
|
|
1024
1009
|
}
|
|
1025
1010
|
|
|
1026
1011
|
function useArrayMap(list, fn) {
|
|
1027
|
-
return
|
|
1012
|
+
return vue.computed(() => toValue(list).map((i) => toValue(i)).map(fn));
|
|
1028
1013
|
}
|
|
1029
1014
|
|
|
1030
1015
|
function useArrayReduce(list, reducer, ...args) {
|
|
1031
1016
|
const reduceCallback = (sum, value, index) => reducer(toValue(sum), toValue(value), index);
|
|
1032
|
-
return
|
|
1017
|
+
return vue.computed(() => {
|
|
1033
1018
|
const resolved = toValue(list);
|
|
1034
1019
|
return args.length ? resolved.reduce(reduceCallback, typeof args[0] === "function" ? toValue(args[0]()) : toValue(args[0])) : resolved.reduce(reduceCallback);
|
|
1035
1020
|
});
|
|
1036
1021
|
}
|
|
1037
1022
|
|
|
1038
1023
|
function useArraySome(list, fn) {
|
|
1039
|
-
return
|
|
1024
|
+
return vue.computed(() => toValue(list).some((element, index, array) => fn(toValue(element), index, array)));
|
|
1040
1025
|
}
|
|
1041
1026
|
|
|
1042
1027
|
function uniq(array) {
|
|
@@ -1050,15 +1035,15 @@ function uniqueElementsBy(array, fn) {
|
|
|
1050
1035
|
}, []);
|
|
1051
1036
|
}
|
|
1052
1037
|
function useArrayUnique(list, compareFn) {
|
|
1053
|
-
return
|
|
1038
|
+
return vue.computed(() => {
|
|
1054
1039
|
const resolvedList = toValue(list).map((element) => toValue(element));
|
|
1055
1040
|
return compareFn ? uniqueElementsBy(resolvedList, compareFn) : uniq(resolvedList);
|
|
1056
1041
|
});
|
|
1057
1042
|
}
|
|
1058
1043
|
|
|
1059
1044
|
function useCounter(initialValue = 0, options = {}) {
|
|
1060
|
-
let _initialValue =
|
|
1061
|
-
const count =
|
|
1045
|
+
let _initialValue = vue.unref(initialValue);
|
|
1046
|
+
const count = vue.ref(initialValue);
|
|
1062
1047
|
const {
|
|
1063
1048
|
max = Number.POSITIVE_INFINITY,
|
|
1064
1049
|
min = Number.NEGATIVE_INFINITY
|
|
@@ -1155,7 +1140,7 @@ function normalizeDate(date) {
|
|
|
1155
1140
|
return new Date(date);
|
|
1156
1141
|
}
|
|
1157
1142
|
function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
|
|
1158
|
-
return
|
|
1143
|
+
return vue.computed(() => formatDate(normalizeDate(toValue(date)), toValue(formatStr), options));
|
|
1159
1144
|
}
|
|
1160
1145
|
|
|
1161
1146
|
function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
@@ -1164,7 +1149,7 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
1164
1149
|
immediateCallback = false
|
|
1165
1150
|
} = options;
|
|
1166
1151
|
let timer = null;
|
|
1167
|
-
const isActive =
|
|
1152
|
+
const isActive = vue.ref(false);
|
|
1168
1153
|
function clean() {
|
|
1169
1154
|
if (timer) {
|
|
1170
1155
|
clearInterval(timer);
|
|
@@ -1188,8 +1173,8 @@ function useIntervalFn(cb, interval = 1e3, options = {}) {
|
|
|
1188
1173
|
}
|
|
1189
1174
|
if (immediate && isClient)
|
|
1190
1175
|
resume();
|
|
1191
|
-
if (
|
|
1192
|
-
const stopWatch =
|
|
1176
|
+
if (vue.isRef(interval) || typeof interval === "function") {
|
|
1177
|
+
const stopWatch = vue.watch(interval, () => {
|
|
1193
1178
|
if (isActive.value && isClient)
|
|
1194
1179
|
resume();
|
|
1195
1180
|
});
|
|
@@ -1209,7 +1194,7 @@ function useInterval(interval = 1e3, options = {}) {
|
|
|
1209
1194
|
immediate = true,
|
|
1210
1195
|
callback
|
|
1211
1196
|
} = options;
|
|
1212
|
-
const counter =
|
|
1197
|
+
const counter = vue.ref(0);
|
|
1213
1198
|
const update = () => counter.value += 1;
|
|
1214
1199
|
const reset = () => {
|
|
1215
1200
|
counter.value = 0;
|
|
@@ -1235,8 +1220,8 @@ function useInterval(interval = 1e3, options = {}) {
|
|
|
1235
1220
|
|
|
1236
1221
|
function useLastChanged(source, options = {}) {
|
|
1237
1222
|
var _a;
|
|
1238
|
-
const ms =
|
|
1239
|
-
|
|
1223
|
+
const ms = vue.ref((_a = options.initialValue) != null ? _a : null);
|
|
1224
|
+
vue.watch(
|
|
1240
1225
|
source,
|
|
1241
1226
|
() => ms.value = timestamp(),
|
|
1242
1227
|
options
|
|
@@ -1248,7 +1233,7 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1248
1233
|
const {
|
|
1249
1234
|
immediate = true
|
|
1250
1235
|
} = options;
|
|
1251
|
-
const isPending =
|
|
1236
|
+
const isPending = vue.ref(false);
|
|
1252
1237
|
let timer = null;
|
|
1253
1238
|
function clear() {
|
|
1254
1239
|
if (timer) {
|
|
@@ -1276,7 +1261,7 @@ function useTimeoutFn(cb, interval, options = {}) {
|
|
|
1276
1261
|
}
|
|
1277
1262
|
tryOnScopeDispose(stop);
|
|
1278
1263
|
return {
|
|
1279
|
-
isPending:
|
|
1264
|
+
isPending: vue.readonly(isPending),
|
|
1280
1265
|
start,
|
|
1281
1266
|
stop
|
|
1282
1267
|
};
|
|
@@ -1292,7 +1277,7 @@ function useTimeout(interval = 1e3, options = {}) {
|
|
|
1292
1277
|
interval,
|
|
1293
1278
|
options
|
|
1294
1279
|
);
|
|
1295
|
-
const ready =
|
|
1280
|
+
const ready = vue.computed(() => !controls.isPending.value);
|
|
1296
1281
|
if (exposeControls) {
|
|
1297
1282
|
return {
|
|
1298
1283
|
ready,
|
|
@@ -1309,7 +1294,7 @@ function useToNumber(value, options = {}) {
|
|
|
1309
1294
|
radix,
|
|
1310
1295
|
nanToZero
|
|
1311
1296
|
} = options;
|
|
1312
|
-
return
|
|
1297
|
+
return vue.computed(() => {
|
|
1313
1298
|
let resolved = toValue(value);
|
|
1314
1299
|
if (typeof resolved === "string")
|
|
1315
1300
|
resolved = Number[method](resolved, radix);
|
|
@@ -1320,7 +1305,7 @@ function useToNumber(value, options = {}) {
|
|
|
1320
1305
|
}
|
|
1321
1306
|
|
|
1322
1307
|
function useToString(value) {
|
|
1323
|
-
return
|
|
1308
|
+
return vue.computed(() => `${toValue(value)}`);
|
|
1324
1309
|
}
|
|
1325
1310
|
|
|
1326
1311
|
function useToggle(initialValue = false, options = {}) {
|
|
@@ -1328,8 +1313,8 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1328
1313
|
truthyValue = true,
|
|
1329
1314
|
falsyValue = false
|
|
1330
1315
|
} = options;
|
|
1331
|
-
const valueIsRef =
|
|
1332
|
-
const _value =
|
|
1316
|
+
const valueIsRef = vue.isRef(initialValue);
|
|
1317
|
+
const _value = vue.ref(initialValue);
|
|
1333
1318
|
function toggle(value) {
|
|
1334
1319
|
if (arguments.length) {
|
|
1335
1320
|
_value.value = value;
|
|
@@ -1348,7 +1333,7 @@ function useToggle(initialValue = false, options = {}) {
|
|
|
1348
1333
|
|
|
1349
1334
|
function watchArray(source, cb, options) {
|
|
1350
1335
|
let oldList = (options == null ? void 0 : options.immediate) ? [] : [...source instanceof Function ? source() : Array.isArray(source) ? source : toValue(source)];
|
|
1351
|
-
return
|
|
1336
|
+
return vue.watch(source, (newList, _, onCleanup) => {
|
|
1352
1337
|
const oldListRemains = Array.from({ length: oldList.length });
|
|
1353
1338
|
const added = [];
|
|
1354
1339
|
for (const obj of newList) {
|
|
@@ -1374,13 +1359,13 @@ function watchAtMost(source, cb, options) {
|
|
|
1374
1359
|
count,
|
|
1375
1360
|
...watchOptions
|
|
1376
1361
|
} = options;
|
|
1377
|
-
const current =
|
|
1362
|
+
const current = vue.ref(0);
|
|
1378
1363
|
const stop = watchWithFilter(
|
|
1379
1364
|
source,
|
|
1380
1365
|
(...args) => {
|
|
1381
1366
|
current.value += 1;
|
|
1382
1367
|
if (current.value >= toValue(count))
|
|
1383
|
-
|
|
1368
|
+
vue.nextTick(() => stop());
|
|
1384
1369
|
cb(...args);
|
|
1385
1370
|
},
|
|
1386
1371
|
watchOptions
|
|
@@ -1405,7 +1390,7 @@ function watchDebounced(source, cb, options = {}) {
|
|
|
1405
1390
|
}
|
|
1406
1391
|
|
|
1407
1392
|
function watchDeep(source, cb, options) {
|
|
1408
|
-
return
|
|
1393
|
+
return vue.watch(
|
|
1409
1394
|
source,
|
|
1410
1395
|
cb,
|
|
1411
1396
|
{
|
|
@@ -1428,7 +1413,7 @@ function watchIgnorable(source, cb, options = {}) {
|
|
|
1428
1413
|
let ignorePrevAsyncUpdates;
|
|
1429
1414
|
let stop;
|
|
1430
1415
|
if (watchOptions.flush === "sync") {
|
|
1431
|
-
const ignore =
|
|
1416
|
+
const ignore = vue.ref(false);
|
|
1432
1417
|
ignorePrevAsyncUpdates = () => {
|
|
1433
1418
|
};
|
|
1434
1419
|
ignoreUpdates = (updater) => {
|
|
@@ -1436,7 +1421,7 @@ function watchIgnorable(source, cb, options = {}) {
|
|
|
1436
1421
|
updater();
|
|
1437
1422
|
ignore.value = false;
|
|
1438
1423
|
};
|
|
1439
|
-
stop =
|
|
1424
|
+
stop = vue.watch(
|
|
1440
1425
|
source,
|
|
1441
1426
|
(...args) => {
|
|
1442
1427
|
if (!ignore.value)
|
|
@@ -1446,13 +1431,13 @@ function watchIgnorable(source, cb, options = {}) {
|
|
|
1446
1431
|
);
|
|
1447
1432
|
} else {
|
|
1448
1433
|
const disposables = [];
|
|
1449
|
-
const ignoreCounter =
|
|
1450
|
-
const syncCounter =
|
|
1434
|
+
const ignoreCounter = vue.ref(0);
|
|
1435
|
+
const syncCounter = vue.ref(0);
|
|
1451
1436
|
ignorePrevAsyncUpdates = () => {
|
|
1452
1437
|
ignoreCounter.value = syncCounter.value;
|
|
1453
1438
|
};
|
|
1454
1439
|
disposables.push(
|
|
1455
|
-
|
|
1440
|
+
vue.watch(
|
|
1456
1441
|
source,
|
|
1457
1442
|
() => {
|
|
1458
1443
|
syncCounter.value++;
|
|
@@ -1466,7 +1451,7 @@ function watchIgnorable(source, cb, options = {}) {
|
|
|
1466
1451
|
ignoreCounter.value += syncCounter.value - syncCounterPrev;
|
|
1467
1452
|
};
|
|
1468
1453
|
disposables.push(
|
|
1469
|
-
|
|
1454
|
+
vue.watch(
|
|
1470
1455
|
source,
|
|
1471
1456
|
(...args) => {
|
|
1472
1457
|
const ignore = ignoreCounter.value > 0 && ignoreCounter.value === syncCounter.value;
|
|
@@ -1487,7 +1472,7 @@ function watchIgnorable(source, cb, options = {}) {
|
|
|
1487
1472
|
}
|
|
1488
1473
|
|
|
1489
1474
|
function watchImmediate(source, cb, options) {
|
|
1490
|
-
return
|
|
1475
|
+
return vue.watch(
|
|
1491
1476
|
source,
|
|
1492
1477
|
cb,
|
|
1493
1478
|
{
|
|
@@ -1498,8 +1483,8 @@ function watchImmediate(source, cb, options) {
|
|
|
1498
1483
|
}
|
|
1499
1484
|
|
|
1500
1485
|
function watchOnce(source, cb, options) {
|
|
1501
|
-
const stop =
|
|
1502
|
-
|
|
1486
|
+
const stop = vue.watch(source, (...args) => {
|
|
1487
|
+
vue.nextTick(() => stop());
|
|
1503
1488
|
return cb(...args);
|
|
1504
1489
|
}, options);
|
|
1505
1490
|
return stop;
|
|
@@ -1553,7 +1538,7 @@ function watchTriggerable(source, cb, options = {}) {
|
|
|
1553
1538
|
};
|
|
1554
1539
|
}
|
|
1555
1540
|
function getWatchSources(sources) {
|
|
1556
|
-
if (
|
|
1541
|
+
if (vue.isReactive(sources))
|
|
1557
1542
|
return sources;
|
|
1558
1543
|
if (Array.isArray(sources))
|
|
1559
1544
|
return sources.map((item) => toValue(item));
|
|
@@ -1564,12 +1549,12 @@ function getOldValue(source) {
|
|
|
1564
1549
|
}
|
|
1565
1550
|
|
|
1566
1551
|
function whenever(source, cb, options) {
|
|
1567
|
-
const stop =
|
|
1552
|
+
const stop = vue.watch(
|
|
1568
1553
|
source,
|
|
1569
1554
|
(v, ov, onInvalidate) => {
|
|
1570
1555
|
if (v) {
|
|
1571
1556
|
if (options == null ? void 0 : options.once)
|
|
1572
|
-
|
|
1557
|
+
vue.nextTick(() => stop());
|
|
1573
1558
|
cb(v, ov, onInvalidate);
|
|
1574
1559
|
}
|
|
1575
1560
|
},
|
|
@@ -1601,7 +1586,6 @@ exports.createSingletonPromise = createSingletonPromise;
|
|
|
1601
1586
|
exports.debounceFilter = debounceFilter;
|
|
1602
1587
|
exports.debouncedRef = refDebounced;
|
|
1603
1588
|
exports.debouncedWatch = watchDebounced;
|
|
1604
|
-
exports.directiveHooks = directiveHooks;
|
|
1605
1589
|
exports.eagerComputed = computedEager;
|
|
1606
1590
|
exports.extendRef = extendRef;
|
|
1607
1591
|
exports.formatDate = formatDate;
|