@vueuse/components 10.0.0-beta.1 → 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 +284 -178
- package/index.d.ts +7 -1
- package/index.iife.js +284 -178
- package/index.iife.min.js +1 -1
- package/index.mjs +286 -180
- package/package.json +3 -3
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineComponent, ref, h, watch, computed, reactive, shallowRef, nextTick, watchEffect, toRef, toRefs } from 'vue-demi';
|
|
1
|
+
import { defineComponent, ref, h, watch, computed, reactive, shallowRef, nextTick, getCurrentInstance, onMounted, watchEffect, toRef, toRefs } from 'vue-demi';
|
|
2
2
|
import { onClickOutside as onClickOutside$1, useActiveElement, useBattery, useBrowserLocation, useDark, useDeviceMotion, useDeviceOrientation, useDevicePixelRatio, useDevicesList, useDocumentVisibility, useStorage as useStorage$1, isClient as isClient$1, useDraggable, useElementBounding, useElementSize as useElementSize$1, useElementVisibility as useElementVisibility$1, useEyeDropper, useFullscreen, useGeolocation, useIdle, useMouse, useMouseInElement, useMousePressed, useNetwork, useNow, useObjectUrl, useOffsetPagination, useOnline, usePageLeave, usePointer, usePointerLock, usePreferredColorScheme, usePreferredContrast, usePreferredDark as usePreferredDark$1, usePreferredLanguages, usePreferredReducedMotion, useMutationObserver, useTimeAgo, useTimestamp, useVirtualList, useWindowFocus, useWindowSize } from '@vueuse/core';
|
|
3
|
-
import { resolveUnref, isClient, isString, noop, tryOnScopeDispose, isIOS, directiveHooks, pausableWatch, isFunction,
|
|
3
|
+
import { resolveUnref, isClient, isString, noop, tryOnScopeDispose, isIOS, directiveHooks, pausableWatch, isFunction, resolveRef, tryOnMounted, useToggle, promiseTimeout, useDebounceFn, useThrottleFn } from '@vueuse/shared';
|
|
4
4
|
|
|
5
5
|
const OnClickOutside = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
6
6
|
name: "OnClickOutside",
|
|
@@ -52,14 +52,20 @@ function useEventListener(...args) {
|
|
|
52
52
|
el.addEventListener(event, listener, options2);
|
|
53
53
|
return () => el.removeEventListener(event, listener, options2);
|
|
54
54
|
};
|
|
55
|
-
const stopWatch = watch(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
const stopWatch = watch(
|
|
56
|
+
() => [unrefElement(target), resolveUnref(options)],
|
|
57
|
+
([el, options2]) => {
|
|
58
|
+
cleanup();
|
|
59
|
+
if (!el)
|
|
60
|
+
return;
|
|
61
|
+
cleanups.push(
|
|
62
|
+
...events.flatMap((event) => {
|
|
63
|
+
return listeners.map((listener) => register(el, event, listener, options2));
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
{ immediate: true, flush: "post" }
|
|
68
|
+
);
|
|
63
69
|
const stop = () => {
|
|
64
70
|
stopWatch();
|
|
65
71
|
cleanup();
|
|
@@ -133,7 +139,7 @@ const vOnClickOutside = {
|
|
|
133
139
|
}
|
|
134
140
|
};
|
|
135
141
|
|
|
136
|
-
|
|
142
|
+
function createKeyPredicate(keyFilter) {
|
|
137
143
|
if (typeof keyFilter === "function")
|
|
138
144
|
return keyFilter;
|
|
139
145
|
else if (typeof keyFilter === "string")
|
|
@@ -141,7 +147,7 @@ const createKeyPredicate = (keyFilter) => {
|
|
|
141
147
|
else if (Array.isArray(keyFilter))
|
|
142
148
|
return (event) => keyFilter.includes(event.key);
|
|
143
149
|
return () => true;
|
|
144
|
-
}
|
|
150
|
+
}
|
|
145
151
|
function onKeyStroke(...args) {
|
|
146
152
|
let key;
|
|
147
153
|
let handler;
|
|
@@ -163,9 +169,16 @@ function onKeyStroke(...args) {
|
|
|
163
169
|
key = true;
|
|
164
170
|
handler = args[0];
|
|
165
171
|
}
|
|
166
|
-
const {
|
|
172
|
+
const {
|
|
173
|
+
target = defaultWindow,
|
|
174
|
+
eventName = "keydown",
|
|
175
|
+
passive = false,
|
|
176
|
+
dedupe = false
|
|
177
|
+
} = options;
|
|
167
178
|
const predicate = createKeyPredicate(key);
|
|
168
179
|
const listener = (e) => {
|
|
180
|
+
if (e.repeat && resolveUnref(dedupe))
|
|
181
|
+
return;
|
|
169
182
|
if (predicate(e))
|
|
170
183
|
handler(e);
|
|
171
184
|
};
|
|
@@ -225,7 +238,10 @@ function onLongPress(target, handler, options) {
|
|
|
225
238
|
ev.preventDefault();
|
|
226
239
|
if ((_c = options == null ? void 0 : options.modifiers) == null ? void 0 : _c.stop)
|
|
227
240
|
ev.stopPropagation();
|
|
228
|
-
timeout = setTimeout(
|
|
241
|
+
timeout = setTimeout(
|
|
242
|
+
() => handler(ev),
|
|
243
|
+
(_d = options == null ? void 0 : options.delay) != null ? _d : DEFAULT_DELAY
|
|
244
|
+
);
|
|
229
245
|
}
|
|
230
246
|
const listenerOptions = {
|
|
231
247
|
capture: (_a = options == null ? void 0 : options.modifiers) == null ? void 0 : _a.capture,
|
|
@@ -242,9 +258,13 @@ const OnLongPress = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
242
258
|
emits: ["trigger"],
|
|
243
259
|
setup(props, { slots, emit }) {
|
|
244
260
|
const target = ref();
|
|
245
|
-
onLongPress(
|
|
246
|
-
|
|
247
|
-
|
|
261
|
+
onLongPress(
|
|
262
|
+
target,
|
|
263
|
+
(e) => {
|
|
264
|
+
emit("trigger", e);
|
|
265
|
+
},
|
|
266
|
+
props.options
|
|
267
|
+
);
|
|
248
268
|
return () => {
|
|
249
269
|
if (slots.default)
|
|
250
270
|
return h(props.as || "div", { ref: target }, slots.default());
|
|
@@ -390,7 +410,11 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
390
410
|
const rawInit = resolveUnref(defaults);
|
|
391
411
|
const type = guessSerializerType(rawInit);
|
|
392
412
|
const serializer = (_a = options.serializer) != null ? _a : StorageSerializers[type];
|
|
393
|
-
const { pause: pauseWatch, resume: resumeWatch } = pausableWatch(
|
|
413
|
+
const { pause: pauseWatch, resume: resumeWatch } = pausableWatch(
|
|
414
|
+
data,
|
|
415
|
+
() => write(data.value),
|
|
416
|
+
{ flush, deep, eventFilter }
|
|
417
|
+
);
|
|
394
418
|
if (window && listenToStorageChanges) {
|
|
395
419
|
useEventListener(window, "storage", update);
|
|
396
420
|
useEventListener(window, customStorageEventName, updateFromCustomEvent);
|
|
@@ -467,12 +491,22 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
467
491
|
}
|
|
468
492
|
}
|
|
469
493
|
|
|
470
|
-
function
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
494
|
+
function useMounted() {
|
|
495
|
+
const isMounted = ref(false);
|
|
496
|
+
if (getCurrentInstance()) {
|
|
497
|
+
onMounted(() => {
|
|
498
|
+
isMounted.value = true;
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
return isMounted;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function useSupported(callback) {
|
|
505
|
+
const isMounted = useMounted();
|
|
506
|
+
return computed(() => {
|
|
507
|
+
isMounted.value;
|
|
508
|
+
return Boolean(callback());
|
|
509
|
+
});
|
|
476
510
|
}
|
|
477
511
|
|
|
478
512
|
function useMediaQuery(query, options = {}) {
|
|
@@ -493,7 +527,9 @@ function useMediaQuery(query, options = {}) {
|
|
|
493
527
|
return;
|
|
494
528
|
cleanup();
|
|
495
529
|
mediaQuery = window.matchMedia(resolveRef(query).value);
|
|
496
|
-
matches.value = mediaQuery.matches;
|
|
530
|
+
matches.value = !!(mediaQuery == null ? void 0 : mediaQuery.matches);
|
|
531
|
+
if (!mediaQuery)
|
|
532
|
+
return;
|
|
497
533
|
if ("addEventListener" in mediaQuery)
|
|
498
534
|
mediaQuery.addEventListener("change", update);
|
|
499
535
|
else
|
|
@@ -535,6 +571,7 @@ function useColorMode(options = {}) {
|
|
|
535
571
|
listenToStorageChanges = true,
|
|
536
572
|
storageRef,
|
|
537
573
|
emitAuto,
|
|
574
|
+
// TODO: switch to true in v10
|
|
538
575
|
disableTransition = false
|
|
539
576
|
} = options;
|
|
540
577
|
const modes = __spreadValues$b({
|
|
@@ -553,33 +590,36 @@ function useColorMode(options = {}) {
|
|
|
553
590
|
store.value = v;
|
|
554
591
|
}
|
|
555
592
|
});
|
|
556
|
-
const updateHTMLAttrs = getSSRHandler(
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
593
|
+
const updateHTMLAttrs = getSSRHandler(
|
|
594
|
+
"updateHTMLAttrs",
|
|
595
|
+
(selector2, attribute2, value) => {
|
|
596
|
+
const el = window == null ? void 0 : window.document.querySelector(selector2);
|
|
597
|
+
if (!el)
|
|
598
|
+
return;
|
|
599
|
+
let style;
|
|
600
|
+
if (disableTransition) {
|
|
601
|
+
style = window.document.createElement("style");
|
|
602
|
+
style.type = "text/css";
|
|
603
|
+
style.appendChild(document.createTextNode("*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}"));
|
|
604
|
+
window.document.head.appendChild(style);
|
|
605
|
+
}
|
|
606
|
+
if (attribute2 === "class") {
|
|
607
|
+
const current = value.split(/\s/g);
|
|
608
|
+
Object.values(modes).flatMap((i) => (i || "").split(/\s/g)).filter(Boolean).forEach((v) => {
|
|
609
|
+
if (current.includes(v))
|
|
610
|
+
el.classList.add(v);
|
|
611
|
+
else
|
|
612
|
+
el.classList.remove(v);
|
|
613
|
+
});
|
|
614
|
+
} else {
|
|
615
|
+
el.setAttribute(attribute2, value);
|
|
616
|
+
}
|
|
617
|
+
if (disableTransition) {
|
|
618
|
+
window.getComputedStyle(style).opacity;
|
|
619
|
+
document.head.removeChild(style);
|
|
620
|
+
}
|
|
581
621
|
}
|
|
582
|
-
|
|
622
|
+
);
|
|
583
623
|
function defaultOnChanged(mode) {
|
|
584
624
|
var _a;
|
|
585
625
|
const resolvedMode = mode === "auto" ? preferredMode.value : mode;
|
|
@@ -719,7 +759,8 @@ const UseDraggable = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
719
759
|
"stopPropagation",
|
|
720
760
|
"pointerTypes",
|
|
721
761
|
"as",
|
|
722
|
-
"handle"
|
|
762
|
+
"handle",
|
|
763
|
+
"axis"
|
|
723
764
|
],
|
|
724
765
|
setup(props, { slots }) {
|
|
725
766
|
const target = ref();
|
|
@@ -727,7 +768,11 @@ const UseDraggable = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
727
768
|
var _a;
|
|
728
769
|
return (_a = props.handle) != null ? _a : target.value;
|
|
729
770
|
});
|
|
730
|
-
const storageValue = props.storageKey && useStorage$1(
|
|
771
|
+
const storageValue = props.storageKey && useStorage$1(
|
|
772
|
+
props.storageKey,
|
|
773
|
+
resolveUnref(props.initialValue) || { x: 0, y: 0 },
|
|
774
|
+
isClient$1 ? props.storageType === "session" ? sessionStorage : localStorage : void 0
|
|
775
|
+
);
|
|
731
776
|
const initialValue = storageValue || props.initialValue || { x: 0, y: 0 };
|
|
732
777
|
const onEnd = (position) => {
|
|
733
778
|
if (!storageValue)
|
|
@@ -833,13 +878,21 @@ function useResizeObserver(target, callback, options = {}) {
|
|
|
833
878
|
observer = void 0;
|
|
834
879
|
}
|
|
835
880
|
};
|
|
836
|
-
const
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
881
|
+
const targets = computed(
|
|
882
|
+
() => Array.isArray(target) ? target.map((el) => unrefElement(el)) : [unrefElement(target)]
|
|
883
|
+
);
|
|
884
|
+
const stopWatch = watch(
|
|
885
|
+
targets,
|
|
886
|
+
(els) => {
|
|
887
|
+
cleanup();
|
|
888
|
+
if (isSupported.value && window) {
|
|
889
|
+
observer = new ResizeObserver(callback);
|
|
890
|
+
for (const _el of els)
|
|
891
|
+
_el && observer.observe(_el, observerOptions);
|
|
892
|
+
}
|
|
893
|
+
},
|
|
894
|
+
{ immediate: true, flush: "post", deep: true }
|
|
895
|
+
);
|
|
843
896
|
const stop = () => {
|
|
844
897
|
cleanup();
|
|
845
898
|
stopWatch();
|
|
@@ -859,30 +912,37 @@ function useElementSize(target, initialSize = { width: 0, height: 0 }, options =
|
|
|
859
912
|
});
|
|
860
913
|
const width = ref(initialSize.width);
|
|
861
914
|
const height = ref(initialSize.height);
|
|
862
|
-
useResizeObserver(
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
const
|
|
866
|
-
if (
|
|
867
|
-
const
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
const formatBoxSize = Array.isArray(boxSize) ? boxSize : [boxSize];
|
|
874
|
-
width.value = formatBoxSize.reduce((acc, { inlineSize }) => acc + inlineSize, 0);
|
|
875
|
-
height.value = formatBoxSize.reduce((acc, { blockSize }) => acc + blockSize, 0);
|
|
915
|
+
useResizeObserver(
|
|
916
|
+
target,
|
|
917
|
+
([entry]) => {
|
|
918
|
+
const boxSize = box === "border-box" ? entry.borderBoxSize : box === "content-box" ? entry.contentBoxSize : entry.devicePixelContentBoxSize;
|
|
919
|
+
if (window && isSVG.value) {
|
|
920
|
+
const $elem = unrefElement(target);
|
|
921
|
+
if ($elem) {
|
|
922
|
+
const styles = window.getComputedStyle($elem);
|
|
923
|
+
width.value = parseFloat(styles.width);
|
|
924
|
+
height.value = parseFloat(styles.height);
|
|
925
|
+
}
|
|
876
926
|
} else {
|
|
877
|
-
|
|
878
|
-
|
|
927
|
+
if (boxSize) {
|
|
928
|
+
const formatBoxSize = Array.isArray(boxSize) ? boxSize : [boxSize];
|
|
929
|
+
width.value = formatBoxSize.reduce((acc, { inlineSize }) => acc + inlineSize, 0);
|
|
930
|
+
height.value = formatBoxSize.reduce((acc, { blockSize }) => acc + blockSize, 0);
|
|
931
|
+
} else {
|
|
932
|
+
width.value = entry.contentRect.width;
|
|
933
|
+
height.value = entry.contentRect.height;
|
|
934
|
+
}
|
|
879
935
|
}
|
|
936
|
+
},
|
|
937
|
+
options
|
|
938
|
+
);
|
|
939
|
+
watch(
|
|
940
|
+
() => unrefElement(target),
|
|
941
|
+
(ele) => {
|
|
942
|
+
width.value = ele ? initialSize.width : 0;
|
|
943
|
+
height.value = ele ? initialSize.height : 0;
|
|
880
944
|
}
|
|
881
|
-
|
|
882
|
-
watch(() => unrefElement(target), (ele) => {
|
|
883
|
-
width.value = ele ? initialSize.width : 0;
|
|
884
|
-
height.value = ele ? initialSize.height : 0;
|
|
885
|
-
});
|
|
945
|
+
);
|
|
886
946
|
return {
|
|
887
947
|
width,
|
|
888
948
|
height
|
|
@@ -914,27 +974,63 @@ const UseElementVisibility = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
914
974
|
}
|
|
915
975
|
});
|
|
916
976
|
|
|
977
|
+
function useIntersectionObserver(target, callback, options = {}) {
|
|
978
|
+
const {
|
|
979
|
+
root,
|
|
980
|
+
rootMargin = "0px",
|
|
981
|
+
threshold = 0.1,
|
|
982
|
+
window = defaultWindow
|
|
983
|
+
} = options;
|
|
984
|
+
const isSupported = useSupported(() => window && "IntersectionObserver" in window);
|
|
985
|
+
let cleanup = noop;
|
|
986
|
+
const stopWatch = isSupported.value ? watch(
|
|
987
|
+
() => ({
|
|
988
|
+
el: unrefElement(target),
|
|
989
|
+
root: unrefElement(root)
|
|
990
|
+
}),
|
|
991
|
+
({ el, root: root2 }) => {
|
|
992
|
+
cleanup();
|
|
993
|
+
if (!el)
|
|
994
|
+
return;
|
|
995
|
+
const observer = new IntersectionObserver(
|
|
996
|
+
callback,
|
|
997
|
+
{
|
|
998
|
+
root: root2,
|
|
999
|
+
rootMargin,
|
|
1000
|
+
threshold
|
|
1001
|
+
}
|
|
1002
|
+
);
|
|
1003
|
+
observer.observe(el);
|
|
1004
|
+
cleanup = () => {
|
|
1005
|
+
observer.disconnect();
|
|
1006
|
+
cleanup = noop;
|
|
1007
|
+
};
|
|
1008
|
+
},
|
|
1009
|
+
{ immediate: true, flush: "post" }
|
|
1010
|
+
) : noop;
|
|
1011
|
+
const stop = () => {
|
|
1012
|
+
cleanup();
|
|
1013
|
+
stopWatch();
|
|
1014
|
+
};
|
|
1015
|
+
tryOnScopeDispose(stop);
|
|
1016
|
+
return {
|
|
1017
|
+
isSupported,
|
|
1018
|
+
stop
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
|
|
917
1022
|
function useElementVisibility(element, { window = defaultWindow, scrollTarget } = {}) {
|
|
918
1023
|
const elementIsVisible = ref(false);
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
const rect = el.getBoundingClientRect();
|
|
928
|
-
elementIsVisible.value = rect.top <= (window.innerHeight || document.documentElement.clientHeight) && rect.left <= (window.innerWidth || document.documentElement.clientWidth) && rect.bottom >= 0 && rect.right >= 0;
|
|
1024
|
+
useIntersectionObserver(
|
|
1025
|
+
element,
|
|
1026
|
+
([{ isIntersecting }]) => {
|
|
1027
|
+
elementIsVisible.value = isIntersecting;
|
|
1028
|
+
},
|
|
1029
|
+
{
|
|
1030
|
+
root: scrollTarget,
|
|
1031
|
+
window
|
|
929
1032
|
}
|
|
930
|
-
|
|
931
|
-
watch(() => unrefElement(element), () => testBounding(), { immediate: true, flush: "post" });
|
|
932
|
-
if (window) {
|
|
933
|
-
useEventListener(scrollTarget || window, "scroll", testBounding, {
|
|
934
|
-
capture: false,
|
|
935
|
-
passive: true
|
|
936
|
-
});
|
|
937
|
-
}
|
|
1033
|
+
);
|
|
938
1034
|
return elementIsVisible;
|
|
939
1035
|
}
|
|
940
1036
|
|
|
@@ -1081,13 +1177,21 @@ async function loadImage(options) {
|
|
|
1081
1177
|
img.onerror = reject;
|
|
1082
1178
|
});
|
|
1083
1179
|
}
|
|
1084
|
-
|
|
1085
|
-
const state = useAsyncState(
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1180
|
+
function useImage(options, asyncStateOptions = {}) {
|
|
1181
|
+
const state = useAsyncState(
|
|
1182
|
+
() => loadImage(resolveUnref(options)),
|
|
1183
|
+
void 0,
|
|
1184
|
+
__spreadValues$9({
|
|
1185
|
+
resetOnExecute: true
|
|
1186
|
+
}, asyncStateOptions)
|
|
1187
|
+
);
|
|
1188
|
+
watch(
|
|
1189
|
+
() => resolveUnref(options),
|
|
1190
|
+
() => state.execute(asyncStateOptions.delay),
|
|
1191
|
+
{ deep: true }
|
|
1192
|
+
);
|
|
1089
1193
|
return state;
|
|
1090
|
-
}
|
|
1194
|
+
}
|
|
1091
1195
|
|
|
1092
1196
|
const UseImage = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
1093
1197
|
name: "UseImage",
|
|
@@ -1203,8 +1307,18 @@ function useScroll(element, options = {}) {
|
|
|
1203
1307
|
onScrollEndDebounced(e);
|
|
1204
1308
|
onScroll(e);
|
|
1205
1309
|
};
|
|
1206
|
-
useEventListener(
|
|
1207
|
-
|
|
1310
|
+
useEventListener(
|
|
1311
|
+
element,
|
|
1312
|
+
"scroll",
|
|
1313
|
+
throttle ? useThrottleFn(onScrollHandler, throttle, true, false) : onScrollHandler,
|
|
1314
|
+
eventListenerOptions
|
|
1315
|
+
);
|
|
1316
|
+
useEventListener(
|
|
1317
|
+
element,
|
|
1318
|
+
"scrollend",
|
|
1319
|
+
onScrollEnd,
|
|
1320
|
+
eventListenerOptions
|
|
1321
|
+
);
|
|
1208
1322
|
return {
|
|
1209
1323
|
x,
|
|
1210
1324
|
y,
|
|
@@ -1236,30 +1350,36 @@ var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
|
1236
1350
|
function useInfiniteScroll(element, onLoadMore, options = {}) {
|
|
1237
1351
|
var _a, _b;
|
|
1238
1352
|
const direction = (_a = options.direction) != null ? _a : "bottom";
|
|
1239
|
-
const state = reactive(useScroll(
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
elem.
|
|
1256
|
-
|
|
1257
|
-
|
|
1353
|
+
const state = reactive(useScroll(
|
|
1354
|
+
element,
|
|
1355
|
+
__spreadProps$7(__spreadValues$8({}, options), {
|
|
1356
|
+
offset: __spreadValues$8({
|
|
1357
|
+
[direction]: (_b = options.distance) != null ? _b : 0
|
|
1358
|
+
}, options.offset)
|
|
1359
|
+
})
|
|
1360
|
+
));
|
|
1361
|
+
watch(
|
|
1362
|
+
() => state.arrivedState[direction],
|
|
1363
|
+
async (v) => {
|
|
1364
|
+
var _a2, _b2;
|
|
1365
|
+
if (v) {
|
|
1366
|
+
const elem = resolveUnref(element);
|
|
1367
|
+
const previous = {
|
|
1368
|
+
height: (_a2 = elem == null ? void 0 : elem.scrollHeight) != null ? _a2 : 0,
|
|
1369
|
+
width: (_b2 = elem == null ? void 0 : elem.scrollWidth) != null ? _b2 : 0
|
|
1370
|
+
};
|
|
1371
|
+
await onLoadMore(state);
|
|
1372
|
+
if (options.preserveScrollPosition && elem) {
|
|
1373
|
+
nextTick(() => {
|
|
1374
|
+
elem.scrollTo({
|
|
1375
|
+
top: elem.scrollHeight - previous.height,
|
|
1376
|
+
left: elem.scrollWidth - previous.width
|
|
1377
|
+
});
|
|
1258
1378
|
});
|
|
1259
|
-
}
|
|
1379
|
+
}
|
|
1260
1380
|
}
|
|
1261
1381
|
}
|
|
1262
|
-
|
|
1382
|
+
);
|
|
1263
1383
|
}
|
|
1264
1384
|
|
|
1265
1385
|
const vInfiniteScroll = {
|
|
@@ -1271,44 +1391,6 @@ const vInfiniteScroll = {
|
|
|
1271
1391
|
}
|
|
1272
1392
|
};
|
|
1273
1393
|
|
|
1274
|
-
function useIntersectionObserver(target, callback, options = {}) {
|
|
1275
|
-
const {
|
|
1276
|
-
root,
|
|
1277
|
-
rootMargin = "0px",
|
|
1278
|
-
threshold = 0.1,
|
|
1279
|
-
window = defaultWindow
|
|
1280
|
-
} = options;
|
|
1281
|
-
const isSupported = useSupported(() => window && "IntersectionObserver" in window);
|
|
1282
|
-
let cleanup = noop;
|
|
1283
|
-
const stopWatch = isSupported.value ? watch(() => ({
|
|
1284
|
-
el: unrefElement(target),
|
|
1285
|
-
root: unrefElement(root)
|
|
1286
|
-
}), ({ el, root: root2 }) => {
|
|
1287
|
-
cleanup();
|
|
1288
|
-
if (!el)
|
|
1289
|
-
return;
|
|
1290
|
-
const observer = new IntersectionObserver(callback, {
|
|
1291
|
-
root: root2,
|
|
1292
|
-
rootMargin,
|
|
1293
|
-
threshold
|
|
1294
|
-
});
|
|
1295
|
-
observer.observe(el);
|
|
1296
|
-
cleanup = () => {
|
|
1297
|
-
observer.disconnect();
|
|
1298
|
-
cleanup = noop;
|
|
1299
|
-
};
|
|
1300
|
-
}, { immediate: true, flush: "post" }) : noop;
|
|
1301
|
-
const stop = () => {
|
|
1302
|
-
cleanup();
|
|
1303
|
-
stopWatch();
|
|
1304
|
-
};
|
|
1305
|
-
tryOnScopeDispose(stop);
|
|
1306
|
-
return {
|
|
1307
|
-
isSupported,
|
|
1308
|
-
stop
|
|
1309
|
-
};
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
1394
|
const vIntersectionObserver = {
|
|
1313
1395
|
[directiveHooks.mounted](el, binding) {
|
|
1314
1396
|
if (typeof binding.value === "function")
|
|
@@ -1655,12 +1737,19 @@ function useCssVar(prop, target, options = {}) {
|
|
|
1655
1737
|
window
|
|
1656
1738
|
});
|
|
1657
1739
|
}
|
|
1658
|
-
watch(
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1740
|
+
watch(
|
|
1741
|
+
[elRef, () => resolveUnref(prop)],
|
|
1742
|
+
updateCssVar,
|
|
1743
|
+
{ immediate: true }
|
|
1744
|
+
);
|
|
1745
|
+
watch(
|
|
1746
|
+
variable,
|
|
1747
|
+
(val) => {
|
|
1748
|
+
var _a;
|
|
1749
|
+
if ((_a = elRef.value) == null ? void 0 : _a.style)
|
|
1750
|
+
elRef.value.style.setProperty(resolveUnref(prop), val);
|
|
1751
|
+
}
|
|
1752
|
+
);
|
|
1664
1753
|
return variable;
|
|
1665
1754
|
}
|
|
1666
1755
|
|
|
@@ -1827,9 +1916,14 @@ function useScrollLock(element, initialState = false) {
|
|
|
1827
1916
|
if (!ele || isLocked.value)
|
|
1828
1917
|
return;
|
|
1829
1918
|
if (isIOS) {
|
|
1830
|
-
stopTouchMoveListener = useEventListener(
|
|
1831
|
-
|
|
1832
|
-
|
|
1919
|
+
stopTouchMoveListener = useEventListener(
|
|
1920
|
+
ele,
|
|
1921
|
+
"touchmove",
|
|
1922
|
+
(e) => {
|
|
1923
|
+
preventDefault(e);
|
|
1924
|
+
},
|
|
1925
|
+
{ passive: false }
|
|
1926
|
+
);
|
|
1833
1927
|
}
|
|
1834
1928
|
ele.style.overflow = "hidden";
|
|
1835
1929
|
isLocked.value = true;
|
|
@@ -1856,7 +1950,7 @@ function useScrollLock(element, initialState = false) {
|
|
|
1856
1950
|
});
|
|
1857
1951
|
}
|
|
1858
1952
|
|
|
1859
|
-
|
|
1953
|
+
function onScrollLock() {
|
|
1860
1954
|
let isMounted = false;
|
|
1861
1955
|
const state = ref(false);
|
|
1862
1956
|
return (el, binding) => {
|
|
@@ -1867,7 +1961,7 @@ const onScrollLock = () => {
|
|
|
1867
1961
|
const isLocked = useScrollLock(el, binding.value);
|
|
1868
1962
|
watch(state, (v) => isLocked.value = v);
|
|
1869
1963
|
};
|
|
1870
|
-
}
|
|
1964
|
+
}
|
|
1871
1965
|
const vScrollLock = onScrollLock();
|
|
1872
1966
|
|
|
1873
1967
|
var __defProp$2 = Object.defineProperty;
|
|
@@ -1960,9 +2054,21 @@ const UseVirtualList = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
1960
2054
|
const { list, containerProps, wrapperProps, scrollTo } = useVirtualList(listRef, props.options);
|
|
1961
2055
|
expose({ scrollTo });
|
|
1962
2056
|
typeof containerProps.style === "object" && !Array.isArray(containerProps.style) && (containerProps.style.height = props.height || "300px");
|
|
1963
|
-
return () => h(
|
|
1964
|
-
|
|
1965
|
-
|
|
2057
|
+
return () => h(
|
|
2058
|
+
"div",
|
|
2059
|
+
__spreadValues({}, containerProps),
|
|
2060
|
+
[
|
|
2061
|
+
h(
|
|
2062
|
+
"div",
|
|
2063
|
+
__spreadValues({}, wrapperProps.value),
|
|
2064
|
+
list.value.map((item) => h(
|
|
2065
|
+
"div",
|
|
2066
|
+
{ style: { overFlow: "hidden", height: item.height } },
|
|
2067
|
+
slots.default ? slots.default(item) : "Please set content!"
|
|
2068
|
+
))
|
|
2069
|
+
)
|
|
2070
|
+
]
|
|
2071
|
+
);
|
|
1966
2072
|
}
|
|
1967
2073
|
});
|
|
1968
2074
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/components",
|
|
3
|
-
"version": "10.0.0-beta.
|
|
3
|
+
"version": "10.0.0-beta.3",
|
|
4
4
|
"description": "Renderless components for VueUse",
|
|
5
5
|
"author": "Jacob Clevenger<https://github.com/wheatjs>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"jsdelivr": "./index.iife.min.js",
|
|
34
34
|
"types": "./index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@vueuse/core": "10.0.0-beta.
|
|
37
|
-
"@vueuse/shared": "10.0.0-beta.
|
|
36
|
+
"@vueuse/core": "10.0.0-beta.3",
|
|
37
|
+
"@vueuse/shared": "10.0.0-beta.3",
|
|
38
38
|
"vue-demi": "*"
|
|
39
39
|
}
|
|
40
40
|
}
|