@vueuse/shared 10.0.0-beta.2 → 10.0.0-beta.3
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 +224 -112
- package/index.d.ts +5 -5
- package/index.iife.js +224 -112
- package/index.iife.min.js +1 -1
- package/index.mjs +224 -112
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -56,8 +56,8 @@ const rand = (min, max) => {
|
|
|
56
56
|
max = Math.floor(max);
|
|
57
57
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
58
58
|
};
|
|
59
|
-
const isIOS = isClient && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
|
|
60
59
|
const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);
|
|
60
|
+
const isIOS = isClient && ((_a = window == null ? void 0 : window.navigator) == null ? void 0 : _a.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
|
|
61
61
|
|
|
62
62
|
function resolveUnref(r) {
|
|
63
63
|
return typeof r === "function" ? r() : vueDemi.unref(r);
|
|
@@ -291,7 +291,7 @@ function tryOnScopeDispose(fn) {
|
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
function createEventHook() {
|
|
294
|
-
const fns = new Set();
|
|
294
|
+
const fns = /* @__PURE__ */ new Set();
|
|
295
295
|
const off = (fn) => {
|
|
296
296
|
fns.delete(fn);
|
|
297
297
|
};
|
|
@@ -448,13 +448,15 @@ function reactifyObject(obj, optionsOrKeys = {}) {
|
|
|
448
448
|
if (includeOwnProperties)
|
|
449
449
|
keys.push(...Object.getOwnPropertyNames(obj));
|
|
450
450
|
}
|
|
451
|
-
return Object.fromEntries(
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
451
|
+
return Object.fromEntries(
|
|
452
|
+
keys.map((key) => {
|
|
453
|
+
const value = obj[key];
|
|
454
|
+
return [
|
|
455
|
+
key,
|
|
456
|
+
typeof value === "function" ? reactify(value.bind(obj), options) : value
|
|
457
|
+
];
|
|
458
|
+
})
|
|
459
|
+
);
|
|
458
460
|
}
|
|
459
461
|
|
|
460
462
|
function toReactive(objectRef) {
|
|
@@ -497,7 +499,9 @@ function reactiveComputed(fn) {
|
|
|
497
499
|
function reactiveOmit(obj, ...keys) {
|
|
498
500
|
const flatKeys = keys.flat();
|
|
499
501
|
const predicate = flatKeys[0];
|
|
500
|
-
return reactiveComputed(
|
|
502
|
+
return reactiveComputed(
|
|
503
|
+
() => typeof predicate === "function" ? Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter(([k, v]) => !predicate(resolveUnref(v), k))) : Object.fromEntries(Object.entries(vueDemi.toRefs(obj)).filter((e) => !flatKeys.includes(e[0])))
|
|
504
|
+
);
|
|
501
505
|
}
|
|
502
506
|
|
|
503
507
|
function reactivePick(obj, ...keys) {
|
|
@@ -533,7 +537,10 @@ function refAutoReset(defaultValue, afterMs = 1e4) {
|
|
|
533
537
|
}
|
|
534
538
|
|
|
535
539
|
function useDebounceFn(fn, ms = 200, options = {}) {
|
|
536
|
-
return createFilterWrapper(
|
|
540
|
+
return createFilterWrapper(
|
|
541
|
+
debounceFilter(ms, options),
|
|
542
|
+
fn
|
|
543
|
+
);
|
|
537
544
|
}
|
|
538
545
|
|
|
539
546
|
function refDebounced(value, ms = 200, options = {}) {
|
|
@@ -558,7 +565,10 @@ function refDefault(source, defaultValue) {
|
|
|
558
565
|
}
|
|
559
566
|
|
|
560
567
|
function useThrottleFn(fn, ms = 200, trailing = false, leading = true, rejectOnCancel = false) {
|
|
561
|
-
return createFilterWrapper(
|
|
568
|
+
return createFilterWrapper(
|
|
569
|
+
throttleFilter(ms, trailing, leading, rejectOnCancel),
|
|
570
|
+
fn
|
|
571
|
+
);
|
|
562
572
|
}
|
|
563
573
|
|
|
564
574
|
function refThrottled(value, delay = 200, trailing = true, leading = true) {
|
|
@@ -609,14 +619,18 @@ function refWithControl(initial, options = {}) {
|
|
|
609
619
|
const silentSet = (v) => set(v, false);
|
|
610
620
|
const peek = () => get(false);
|
|
611
621
|
const lay = (v) => set(v, false);
|
|
612
|
-
return extendRef(
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
622
|
+
return extendRef(
|
|
623
|
+
ref,
|
|
624
|
+
{
|
|
625
|
+
get,
|
|
626
|
+
set,
|
|
627
|
+
untrackedGet,
|
|
628
|
+
silentSet,
|
|
629
|
+
peek,
|
|
630
|
+
lay
|
|
631
|
+
},
|
|
632
|
+
{ enumerable: true }
|
|
633
|
+
);
|
|
620
634
|
}
|
|
621
635
|
const controlledRef = refWithControl;
|
|
622
636
|
|
|
@@ -653,10 +667,18 @@ function syncRef(left, right, options = {}) {
|
|
|
653
667
|
const transformLTR = (_a = transform.ltr) != null ? _a : (v) => v;
|
|
654
668
|
const transformRTL = (_b = transform.rtl) != null ? _b : (v) => v;
|
|
655
669
|
if (direction === "both" || direction === "ltr") {
|
|
656
|
-
watchLeft = vueDemi.watch(
|
|
670
|
+
watchLeft = vueDemi.watch(
|
|
671
|
+
left,
|
|
672
|
+
(newValue) => right.value = transformLTR(newValue),
|
|
673
|
+
{ flush, deep, immediate }
|
|
674
|
+
);
|
|
657
675
|
}
|
|
658
676
|
if (direction === "both" || direction === "rtl") {
|
|
659
|
-
watchRight = vueDemi.watch(
|
|
677
|
+
watchRight = vueDemi.watch(
|
|
678
|
+
right,
|
|
679
|
+
(newValue) => left.value = transformRTL(newValue),
|
|
680
|
+
{ flush, deep, immediate }
|
|
681
|
+
);
|
|
660
682
|
}
|
|
661
683
|
return () => {
|
|
662
684
|
watchLeft == null ? void 0 : watchLeft();
|
|
@@ -672,7 +694,11 @@ function syncRefs(source, targets, options = {}) {
|
|
|
672
694
|
} = options;
|
|
673
695
|
if (!Array.isArray(targets))
|
|
674
696
|
targets = [targets];
|
|
675
|
-
return vueDemi.watch(
|
|
697
|
+
return vueDemi.watch(
|
|
698
|
+
source,
|
|
699
|
+
(newValue) => targets.forEach((target) => target.value = newValue),
|
|
700
|
+
{ flush, deep, immediate }
|
|
701
|
+
);
|
|
676
702
|
}
|
|
677
703
|
|
|
678
704
|
var __defProp$9 = Object.defineProperty;
|
|
@@ -751,20 +777,26 @@ function createUntil(r, isNot = false) {
|
|
|
751
777
|
function toMatch(condition, { flush = "sync", deep = false, timeout, throwOnTimeout } = {}) {
|
|
752
778
|
let stop = null;
|
|
753
779
|
const watcher = new Promise((resolve) => {
|
|
754
|
-
stop = vueDemi.watch(
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
780
|
+
stop = vueDemi.watch(
|
|
781
|
+
r,
|
|
782
|
+
(v) => {
|
|
783
|
+
if (condition(v) !== isNot) {
|
|
784
|
+
stop == null ? void 0 : stop();
|
|
785
|
+
resolve(v);
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
flush,
|
|
790
|
+
deep,
|
|
791
|
+
immediate: true
|
|
758
792
|
}
|
|
759
|
-
|
|
760
|
-
flush,
|
|
761
|
-
deep,
|
|
762
|
-
immediate: true
|
|
763
|
-
});
|
|
793
|
+
);
|
|
764
794
|
});
|
|
765
795
|
const promises = [watcher];
|
|
766
796
|
if (timeout != null) {
|
|
767
|
-
promises.push(
|
|
797
|
+
promises.push(
|
|
798
|
+
promiseTimeout(timeout, throwOnTimeout).then(() => resolveUnref(r)).finally(() => stop == null ? void 0 : stop())
|
|
799
|
+
);
|
|
768
800
|
}
|
|
769
801
|
return Promise.race(promises);
|
|
770
802
|
}
|
|
@@ -774,23 +806,29 @@ function createUntil(r, isNot = false) {
|
|
|
774
806
|
const { flush = "sync", deep = false, timeout, throwOnTimeout } = options != null ? options : {};
|
|
775
807
|
let stop = null;
|
|
776
808
|
const watcher = new Promise((resolve) => {
|
|
777
|
-
stop = vueDemi.watch(
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
809
|
+
stop = vueDemi.watch(
|
|
810
|
+
[r, value],
|
|
811
|
+
([v1, v2]) => {
|
|
812
|
+
if (isNot !== (v1 === v2)) {
|
|
813
|
+
stop == null ? void 0 : stop();
|
|
814
|
+
resolve(v1);
|
|
815
|
+
}
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
flush,
|
|
819
|
+
deep,
|
|
820
|
+
immediate: true
|
|
781
821
|
}
|
|
782
|
-
|
|
783
|
-
flush,
|
|
784
|
-
deep,
|
|
785
|
-
immediate: true
|
|
786
|
-
});
|
|
822
|
+
);
|
|
787
823
|
});
|
|
788
824
|
const promises = [watcher];
|
|
789
825
|
if (timeout != null) {
|
|
790
|
-
promises.push(
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
826
|
+
promises.push(
|
|
827
|
+
promiseTimeout(timeout, throwOnTimeout).then(() => resolveUnref(r)).finally(() => {
|
|
828
|
+
stop == null ? void 0 : stop();
|
|
829
|
+
return resolveUnref(r);
|
|
830
|
+
})
|
|
831
|
+
);
|
|
794
832
|
}
|
|
795
833
|
return Promise.race(promises);
|
|
796
834
|
}
|
|
@@ -854,7 +892,9 @@ function until(r) {
|
|
|
854
892
|
return createUntil(r);
|
|
855
893
|
}
|
|
856
894
|
|
|
857
|
-
|
|
895
|
+
function defaultComparator(value, othVal) {
|
|
896
|
+
return value === othVal;
|
|
897
|
+
}
|
|
858
898
|
function useArrayDifference(...args) {
|
|
859
899
|
var _a;
|
|
860
900
|
const list = args[0];
|
|
@@ -876,7 +916,11 @@ function useArrayFilter(list, fn) {
|
|
|
876
916
|
}
|
|
877
917
|
|
|
878
918
|
function useArrayFind(list, fn) {
|
|
879
|
-
return vueDemi.computed(
|
|
919
|
+
return vueDemi.computed(
|
|
920
|
+
() => resolveUnref(
|
|
921
|
+
resolveUnref(list).find((element, index, array) => fn(resolveUnref(element), index, array))
|
|
922
|
+
)
|
|
923
|
+
);
|
|
880
924
|
}
|
|
881
925
|
|
|
882
926
|
function useArrayFindIndex(list, fn) {
|
|
@@ -892,7 +936,11 @@ function findLast(arr, cb) {
|
|
|
892
936
|
return void 0;
|
|
893
937
|
}
|
|
894
938
|
function useArrayFindLast(list, fn) {
|
|
895
|
-
return vueDemi.computed(
|
|
939
|
+
return vueDemi.computed(
|
|
940
|
+
() => resolveUnref(
|
|
941
|
+
!Array.prototype.findLast ? findLast(resolveUnref(list), (element, index, array) => fn(resolveUnref(element), index, array)) : resolveUnref(list).findLast((element, index, array) => fn(resolveUnref(element), index, array))
|
|
942
|
+
)
|
|
943
|
+
);
|
|
896
944
|
}
|
|
897
945
|
|
|
898
946
|
function isArrayIncludesOptions(obj) {
|
|
@@ -913,7 +961,11 @@ function useArrayIncludes(...args) {
|
|
|
913
961
|
comparator = (element, value2) => element[key] === resolveUnref(value2);
|
|
914
962
|
}
|
|
915
963
|
comparator = comparator != null ? comparator : (element, value2) => element === resolveUnref(value2);
|
|
916
|
-
return vueDemi.computed(
|
|
964
|
+
return vueDemi.computed(
|
|
965
|
+
() => resolveUnref(list).slice(formIndex).some(
|
|
966
|
+
(element, index, array) => comparator(resolveUnref(element), resolveUnref(value), index, resolveUnref(array))
|
|
967
|
+
)
|
|
968
|
+
);
|
|
917
969
|
}
|
|
918
970
|
|
|
919
971
|
function useArrayJoin(list, separator) {
|
|
@@ -972,13 +1024,13 @@ function useCounter(initialValue = 0, options = {}) {
|
|
|
972
1024
|
|
|
973
1025
|
const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/;
|
|
974
1026
|
const REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
|
|
975
|
-
|
|
1027
|
+
function defaultMeridiem(hours, minutes, isLowercase, hasPeriod) {
|
|
976
1028
|
let m = hours < 12 ? "AM" : "PM";
|
|
977
1029
|
if (hasPeriod)
|
|
978
1030
|
m = m.split("").reduce((acc, curr) => acc += `${curr}.`, "");
|
|
979
1031
|
return isLowercase ? m.toLowerCase() : m;
|
|
980
|
-
}
|
|
981
|
-
|
|
1032
|
+
}
|
|
1033
|
+
function formatDate(date, formatStr, options = {}) {
|
|
982
1034
|
var _a;
|
|
983
1035
|
const years = date.getFullYear();
|
|
984
1036
|
const month = date.getMonth();
|
|
@@ -1017,12 +1069,12 @@ const formatDate = (date, formatStr, options = {}) => {
|
|
|
1017
1069
|
aa: () => meridiem(hours, minutes, true, true)
|
|
1018
1070
|
};
|
|
1019
1071
|
return formatStr.replace(REGEX_FORMAT, (match, $1) => $1 || matches[match]());
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1072
|
+
}
|
|
1073
|
+
function normalizeDate(date) {
|
|
1022
1074
|
if (date === null)
|
|
1023
|
-
return new Date(NaN);
|
|
1075
|
+
return /* @__PURE__ */ new Date(NaN);
|
|
1024
1076
|
if (date === void 0)
|
|
1025
|
-
return new Date();
|
|
1077
|
+
return /* @__PURE__ */ new Date();
|
|
1026
1078
|
if (date instanceof Date)
|
|
1027
1079
|
return new Date(date);
|
|
1028
1080
|
if (typeof date === "string" && !/Z$/i.test(date)) {
|
|
@@ -1034,7 +1086,7 @@ const normalizeDate = (date) => {
|
|
|
1034
1086
|
}
|
|
1035
1087
|
}
|
|
1036
1088
|
return new Date(date);
|
|
1037
|
-
}
|
|
1089
|
+
}
|
|
1038
1090
|
function useDateFormat(date, formatStr = "HH:mm:ss", options = {}) {
|
|
1039
1091
|
return vueDemi.computed(() => formatDate(normalizeDate(resolveUnref(date)), resolveUnref(formatStr), options));
|
|
1040
1092
|
}
|
|
@@ -1110,10 +1162,14 @@ function useInterval(interval = 1e3, options = {}) {
|
|
|
1110
1162
|
const reset = () => {
|
|
1111
1163
|
counter.value = 0;
|
|
1112
1164
|
};
|
|
1113
|
-
const controls = useIntervalFn(
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1165
|
+
const controls = useIntervalFn(
|
|
1166
|
+
callback ? () => {
|
|
1167
|
+
update();
|
|
1168
|
+
callback(counter.value);
|
|
1169
|
+
} : update,
|
|
1170
|
+
interval,
|
|
1171
|
+
{ immediate }
|
|
1172
|
+
);
|
|
1117
1173
|
if (exposeControls) {
|
|
1118
1174
|
return __spreadValues$8({
|
|
1119
1175
|
counter,
|
|
@@ -1127,7 +1183,11 @@ function useInterval(interval = 1e3, options = {}) {
|
|
|
1127
1183
|
function useLastChanged(source, options = {}) {
|
|
1128
1184
|
var _a;
|
|
1129
1185
|
const ms = vueDemi.ref((_a = options.initialValue) != null ? _a : null);
|
|
1130
|
-
vueDemi.watch(
|
|
1186
|
+
vueDemi.watch(
|
|
1187
|
+
source,
|
|
1188
|
+
() => ms.value = timestamp(),
|
|
1189
|
+
options
|
|
1190
|
+
);
|
|
1131
1191
|
return ms;
|
|
1132
1192
|
}
|
|
1133
1193
|
|
|
@@ -1190,7 +1250,11 @@ function useTimeout(interval = 1e3, options = {}) {
|
|
|
1190
1250
|
controls: exposeControls = false,
|
|
1191
1251
|
callback
|
|
1192
1252
|
} = options;
|
|
1193
|
-
const controls = useTimeoutFn(
|
|
1253
|
+
const controls = useTimeoutFn(
|
|
1254
|
+
callback != null ? callback : noop,
|
|
1255
|
+
interval,
|
|
1256
|
+
options
|
|
1257
|
+
);
|
|
1194
1258
|
const ready = vueDemi.computed(() => !controls.isPending.value);
|
|
1195
1259
|
if (exposeControls) {
|
|
1196
1260
|
return __spreadValues$7({
|
|
@@ -1290,7 +1354,14 @@ function watchWithFilter(source, cb, options = {}) {
|
|
|
1290
1354
|
} = _a, watchOptions = __objRest$5(_a, [
|
|
1291
1355
|
"eventFilter"
|
|
1292
1356
|
]);
|
|
1293
|
-
return vueDemi.watch(
|
|
1357
|
+
return vueDemi.watch(
|
|
1358
|
+
source,
|
|
1359
|
+
createFilterWrapper(
|
|
1360
|
+
eventFilter,
|
|
1361
|
+
cb
|
|
1362
|
+
),
|
|
1363
|
+
watchOptions
|
|
1364
|
+
);
|
|
1294
1365
|
}
|
|
1295
1366
|
|
|
1296
1367
|
var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
|
|
@@ -1315,12 +1386,16 @@ function watchAtMost(source, cb, options) {
|
|
|
1315
1386
|
"count"
|
|
1316
1387
|
]);
|
|
1317
1388
|
const current = vueDemi.ref(0);
|
|
1318
|
-
const stop = watchWithFilter(
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1389
|
+
const stop = watchWithFilter(
|
|
1390
|
+
source,
|
|
1391
|
+
(...args) => {
|
|
1392
|
+
current.value += 1;
|
|
1393
|
+
if (current.value >= resolveUnref(count))
|
|
1394
|
+
vueDemi.nextTick(() => stop());
|
|
1395
|
+
cb(...args);
|
|
1396
|
+
},
|
|
1397
|
+
watchOptions
|
|
1398
|
+
);
|
|
1324
1399
|
return { count: current, stop };
|
|
1325
1400
|
}
|
|
1326
1401
|
|
|
@@ -1363,9 +1438,13 @@ function watchDebounced(source, cb, options = {}) {
|
|
|
1363
1438
|
"debounce",
|
|
1364
1439
|
"maxWait"
|
|
1365
1440
|
]);
|
|
1366
|
-
return watchWithFilter(
|
|
1367
|
-
|
|
1368
|
-
|
|
1441
|
+
return watchWithFilter(
|
|
1442
|
+
source,
|
|
1443
|
+
cb,
|
|
1444
|
+
__spreadProps$6(__spreadValues$6({}, watchOptions), {
|
|
1445
|
+
eventFilter: debounceFilter(debounce, { maxWait })
|
|
1446
|
+
})
|
|
1447
|
+
);
|
|
1369
1448
|
}
|
|
1370
1449
|
|
|
1371
1450
|
var __defProp$5 = Object.defineProperty;
|
|
@@ -1388,12 +1467,13 @@ var __spreadValues$5 = (a, b) => {
|
|
|
1388
1467
|
};
|
|
1389
1468
|
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
1390
1469
|
function watchDeep(source, cb, options) {
|
|
1391
|
-
return vueDemi.watch(
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1470
|
+
return vueDemi.watch(
|
|
1471
|
+
source,
|
|
1472
|
+
cb,
|
|
1473
|
+
__spreadProps$5(__spreadValues$5({}, options), {
|
|
1474
|
+
deep: true
|
|
1475
|
+
})
|
|
1476
|
+
);
|
|
1397
1477
|
}
|
|
1398
1478
|
|
|
1399
1479
|
var __defProp$4 = Object.defineProperty;
|
|
@@ -1433,7 +1513,10 @@ function watchIgnorable(source, cb, options = {}) {
|
|
|
1433
1513
|
} = _a, watchOptions = __objRest$2(_a, [
|
|
1434
1514
|
"eventFilter"
|
|
1435
1515
|
]);
|
|
1436
|
-
const filteredCb = createFilterWrapper(
|
|
1516
|
+
const filteredCb = createFilterWrapper(
|
|
1517
|
+
eventFilter,
|
|
1518
|
+
cb
|
|
1519
|
+
);
|
|
1437
1520
|
let ignoreUpdates;
|
|
1438
1521
|
let ignorePrevAsyncUpdates;
|
|
1439
1522
|
let stop;
|
|
@@ -1446,10 +1529,14 @@ function watchIgnorable(source, cb, options = {}) {
|
|
|
1446
1529
|
updater();
|
|
1447
1530
|
ignore.value = false;
|
|
1448
1531
|
};
|
|
1449
|
-
stop = vueDemi.watch(
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1532
|
+
stop = vueDemi.watch(
|
|
1533
|
+
source,
|
|
1534
|
+
(...args) => {
|
|
1535
|
+
if (!ignore.value)
|
|
1536
|
+
filteredCb(...args);
|
|
1537
|
+
},
|
|
1538
|
+
watchOptions
|
|
1539
|
+
);
|
|
1453
1540
|
} else {
|
|
1454
1541
|
const disposables = [];
|
|
1455
1542
|
const ignoreCounter = vueDemi.ref(0);
|
|
@@ -1457,22 +1544,34 @@ function watchIgnorable(source, cb, options = {}) {
|
|
|
1457
1544
|
ignorePrevAsyncUpdates = () => {
|
|
1458
1545
|
ignoreCounter.value = syncCounter.value;
|
|
1459
1546
|
};
|
|
1460
|
-
disposables.push(
|
|
1461
|
-
|
|
1462
|
-
|
|
1547
|
+
disposables.push(
|
|
1548
|
+
vueDemi.watch(
|
|
1549
|
+
source,
|
|
1550
|
+
() => {
|
|
1551
|
+
syncCounter.value++;
|
|
1552
|
+
},
|
|
1553
|
+
__spreadProps$4(__spreadValues$4({}, watchOptions), { flush: "sync" })
|
|
1554
|
+
)
|
|
1555
|
+
);
|
|
1463
1556
|
ignoreUpdates = (updater) => {
|
|
1464
1557
|
const syncCounterPrev = syncCounter.value;
|
|
1465
1558
|
updater();
|
|
1466
1559
|
ignoreCounter.value += syncCounter.value - syncCounterPrev;
|
|
1467
1560
|
};
|
|
1468
|
-
disposables.push(
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1561
|
+
disposables.push(
|
|
1562
|
+
vueDemi.watch(
|
|
1563
|
+
source,
|
|
1564
|
+
(...args) => {
|
|
1565
|
+
const ignore = ignoreCounter.value > 0 && ignoreCounter.value === syncCounter.value;
|
|
1566
|
+
ignoreCounter.value = 0;
|
|
1567
|
+
syncCounter.value = 0;
|
|
1568
|
+
if (ignore)
|
|
1569
|
+
return;
|
|
1570
|
+
filteredCb(...args);
|
|
1571
|
+
},
|
|
1572
|
+
watchOptions
|
|
1573
|
+
)
|
|
1574
|
+
);
|
|
1476
1575
|
stop = () => {
|
|
1477
1576
|
disposables.forEach((fn) => fn());
|
|
1478
1577
|
};
|
|
@@ -1500,12 +1599,13 @@ var __spreadValues$3 = (a, b) => {
|
|
|
1500
1599
|
};
|
|
1501
1600
|
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
1502
1601
|
function watchImmediate(source, cb, options) {
|
|
1503
|
-
return vueDemi.watch(
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1602
|
+
return vueDemi.watch(
|
|
1603
|
+
source,
|
|
1604
|
+
cb,
|
|
1605
|
+
__spreadProps$3(__spreadValues$3({}, options), {
|
|
1606
|
+
immediate: true
|
|
1607
|
+
})
|
|
1608
|
+
);
|
|
1509
1609
|
}
|
|
1510
1610
|
|
|
1511
1611
|
function watchOnce(source, cb, options) {
|
|
@@ -1553,9 +1653,13 @@ function watchPausable(source, cb, options = {}) {
|
|
|
1553
1653
|
"eventFilter"
|
|
1554
1654
|
]);
|
|
1555
1655
|
const { eventFilter, pause, resume, isActive } = pausableFilter(filter);
|
|
1556
|
-
const stop = watchWithFilter(
|
|
1557
|
-
|
|
1558
|
-
|
|
1656
|
+
const stop = watchWithFilter(
|
|
1657
|
+
source,
|
|
1658
|
+
cb,
|
|
1659
|
+
__spreadProps$2(__spreadValues$2({}, watchOptions), {
|
|
1660
|
+
eventFilter
|
|
1661
|
+
})
|
|
1662
|
+
);
|
|
1559
1663
|
return { stop, pause, resume, isActive };
|
|
1560
1664
|
}
|
|
1561
1665
|
|
|
@@ -1600,9 +1704,13 @@ function watchThrottled(source, cb, options = {}) {
|
|
|
1600
1704
|
"trailing",
|
|
1601
1705
|
"leading"
|
|
1602
1706
|
]);
|
|
1603
|
-
return watchWithFilter(
|
|
1604
|
-
|
|
1605
|
-
|
|
1707
|
+
return watchWithFilter(
|
|
1708
|
+
source,
|
|
1709
|
+
cb,
|
|
1710
|
+
__spreadProps$1(__spreadValues$1({}, watchOptions), {
|
|
1711
|
+
eventFilter: throttleFilter(throttle, trailing, leading)
|
|
1712
|
+
})
|
|
1713
|
+
);
|
|
1606
1714
|
}
|
|
1607
1715
|
|
|
1608
1716
|
var __defProp = Object.defineProperty;
|
|
@@ -1668,10 +1776,14 @@ function getOldValue(source) {
|
|
|
1668
1776
|
}
|
|
1669
1777
|
|
|
1670
1778
|
function whenever(source, cb, options) {
|
|
1671
|
-
return vueDemi.watch(
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1779
|
+
return vueDemi.watch(
|
|
1780
|
+
source,
|
|
1781
|
+
(v, ov, onInvalidate) => {
|
|
1782
|
+
if (v)
|
|
1783
|
+
cb(v, ov, onInvalidate);
|
|
1784
|
+
},
|
|
1785
|
+
options
|
|
1786
|
+
);
|
|
1675
1787
|
}
|
|
1676
1788
|
|
|
1677
1789
|
exports.__onlyVue27Plus = __onlyVue27Plus;
|
package/index.d.ts
CHANGED
|
@@ -47,8 +47,8 @@ declare const timestamp: () => number;
|
|
|
47
47
|
declare const clamp: (n: number, min: number, max: number) => number;
|
|
48
48
|
declare const noop: () => void;
|
|
49
49
|
declare const rand: (min: number, max: number) => number;
|
|
50
|
-
declare const isIOS: boolean | "";
|
|
51
50
|
declare const hasOwn: <T extends object, K extends keyof T>(val: T, key: K) => key is K;
|
|
51
|
+
declare const isIOS: boolean | "";
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Void function
|
|
@@ -804,8 +804,8 @@ interface UseDateFormatOptions {
|
|
|
804
804
|
*/
|
|
805
805
|
customMeridiem?: (hours: number, minutes: number, isLowercase?: boolean, hasPeriod?: boolean) => string;
|
|
806
806
|
}
|
|
807
|
-
declare
|
|
808
|
-
declare
|
|
807
|
+
declare function formatDate(date: Date, formatStr: string, options?: UseDateFormatOptions): string;
|
|
808
|
+
declare function normalizeDate(date: DateLike): Date;
|
|
809
809
|
/**
|
|
810
810
|
* Get the formatted date according to the string of tokens passed in.
|
|
811
811
|
*
|
|
@@ -1029,7 +1029,7 @@ declare function watchDebounced<T extends object, Immediate extends Readonly<boo
|
|
|
1029
1029
|
*
|
|
1030
1030
|
* @see https://vueuse.org/watchDeep
|
|
1031
1031
|
*/
|
|
1032
|
-
declare function watchDeep<T>(source: WatchSource<T
|
|
1032
|
+
declare function watchDeep<T>(source: WatchSource<T>, cb: WatchCallback<T>, options?: Omit<WatchOptions, 'deep'>): vue_demi.WatchStopHandle;
|
|
1033
1033
|
|
|
1034
1034
|
type IgnoredUpdater = (updater: () => void) => void;
|
|
1035
1035
|
interface WatchIgnorableReturn {
|
|
@@ -1046,7 +1046,7 @@ declare function watchIgnorable<T extends object, Immediate extends Readonly<boo
|
|
|
1046
1046
|
*
|
|
1047
1047
|
* @see https://vueuse.org/watchImmediate
|
|
1048
1048
|
*/
|
|
1049
|
-
declare function watchImmediate<T>(source: WatchSource<T
|
|
1049
|
+
declare function watchImmediate<T>(source: WatchSource<T>, cb: WatchCallback<T>, options?: Omit<WatchOptions, 'immediate'>): vue_demi.WatchStopHandle;
|
|
1050
1050
|
|
|
1051
1051
|
declare function watchOnce<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(source: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchOptions<Immediate>): void;
|
|
1052
1052
|
declare function watchOnce<T, Immediate extends Readonly<boolean> = false>(sources: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchOptions<Immediate>): void;
|