@vueuse/components 9.1.1 → 9.3.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 +118 -58
- package/index.d.ts +84 -55
- package/index.iife.js +118 -58
- package/index.iife.min.js +1 -1
- package/index.mjs +120 -60
- package/package.json +3 -3
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineComponent, ref, h, watch, computed, reactive, shallowRef, nextTick, toRef, toRefs } from 'vue-demi';
|
|
1
|
+
import { defineComponent, ref, h, watch, computed, reactive, shallowRef, watchEffect, nextTick, 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, usePreferredColorScheme, usePreferredContrast, usePreferredDark as usePreferredDark$1, usePreferredLanguages, usePreferredReducedMotion, useTimeAgo, useTimestamp, useVirtualList, useWindowFocus, useWindowSize } from '@vueuse/core';
|
|
3
|
-
import { resolveUnref, isClient, isString, noop, tryOnScopeDispose, directiveHooks, pausableWatch, isFunction, tryOnMounted,
|
|
3
|
+
import { resolveUnref, isClient, isString, noop, tryOnScopeDispose, directiveHooks, pausableWatch, isFunction, tryOnMounted, resolveRef, useToggle, promiseTimeout, useDebounceFn, useThrottleFn, isIOS } from '@vueuse/shared';
|
|
4
4
|
|
|
5
5
|
const OnClickOutside = defineComponent({
|
|
6
6
|
name: "OnClickOutside",
|
|
@@ -67,23 +67,21 @@ function onClickOutside(target, handler, options = {}) {
|
|
|
67
67
|
const listener = (event) => {
|
|
68
68
|
window.clearTimeout(fallback);
|
|
69
69
|
const el = unrefElement(target);
|
|
70
|
-
|
|
71
|
-
if (!el || el === event.target || composedPath.includes(el) || !shouldListen.value)
|
|
70
|
+
if (!el || el === event.target || event.composedPath().includes(el) || !shouldListen.value)
|
|
72
71
|
return;
|
|
73
|
-
if (ignore && ignore.length > 0) {
|
|
74
|
-
if (ignore.some((target2) => {
|
|
75
|
-
const el2 = unrefElement(target2);
|
|
76
|
-
return el2 && (event.target === el2 || composedPath.includes(el2));
|
|
77
|
-
}))
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
72
|
handler(event);
|
|
81
73
|
};
|
|
74
|
+
const shouldIgnore = (event) => {
|
|
75
|
+
return ignore && ignore.some((target2) => {
|
|
76
|
+
const el = unrefElement(target2);
|
|
77
|
+
return el && (event.target === el || event.composedPath().includes(el));
|
|
78
|
+
});
|
|
79
|
+
};
|
|
82
80
|
const cleanup = [
|
|
83
81
|
useEventListener(window, "click", listener, { passive: true, capture }),
|
|
84
82
|
useEventListener(window, "pointerdown", (e) => {
|
|
85
83
|
const el = unrefElement(target);
|
|
86
|
-
shouldListen.value = !!el && !e.composedPath().includes(el);
|
|
84
|
+
shouldListen.value = !!el && !e.composedPath().includes(el) && !shouldIgnore(e);
|
|
87
85
|
}, { passive: true }),
|
|
88
86
|
useEventListener(window, "pointerup", (e) => {
|
|
89
87
|
if (e.button === 0) {
|
|
@@ -103,18 +101,20 @@ function onClickOutside(target, handler, options = {}) {
|
|
|
103
101
|
return stop;
|
|
104
102
|
}
|
|
105
103
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
const vOnClickOutside = {
|
|
105
|
+
[directiveHooks.mounted](el, binding) {
|
|
106
|
+
const capture = !binding.modifiers.bubble;
|
|
107
|
+
if (typeof binding.value === "function") {
|
|
108
|
+
el.__onClickOutside_stop = onClickOutside(el, binding.value, { capture });
|
|
109
|
+
} else {
|
|
110
|
+
const [handler, options] = binding.value;
|
|
111
|
+
el.__onClickOutside_stop = onClickOutside(el, handler, Object.assign({ capture }, options));
|
|
113
112
|
}
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
},
|
|
114
|
+
[directiveHooks.unmounted](el) {
|
|
115
|
+
el.__onClickOutside_stop();
|
|
116
|
+
}
|
|
116
117
|
};
|
|
117
|
-
const vOnClickOutside = handler();
|
|
118
118
|
|
|
119
119
|
const createKeyPredicate = (keyFilter) => {
|
|
120
120
|
if (typeof keyFilter === "function")
|
|
@@ -123,12 +123,29 @@ const createKeyPredicate = (keyFilter) => {
|
|
|
123
123
|
return (event) => event.key === keyFilter;
|
|
124
124
|
else if (Array.isArray(keyFilter))
|
|
125
125
|
return (event) => keyFilter.includes(event.key);
|
|
126
|
-
|
|
127
|
-
return () => true;
|
|
128
|
-
else
|
|
129
|
-
return () => false;
|
|
126
|
+
return () => true;
|
|
130
127
|
};
|
|
131
|
-
function onKeyStroke(
|
|
128
|
+
function onKeyStroke(...args) {
|
|
129
|
+
let key;
|
|
130
|
+
let handler;
|
|
131
|
+
let options = {};
|
|
132
|
+
if (args.length === 3) {
|
|
133
|
+
key = args[0];
|
|
134
|
+
handler = args[1];
|
|
135
|
+
options = args[2];
|
|
136
|
+
} else if (args.length === 2) {
|
|
137
|
+
if (typeof args[1] === "object") {
|
|
138
|
+
key = true;
|
|
139
|
+
handler = args[0];
|
|
140
|
+
options = args[1];
|
|
141
|
+
} else {
|
|
142
|
+
key = args[0];
|
|
143
|
+
handler = args[1];
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
key = true;
|
|
147
|
+
handler = args[0];
|
|
148
|
+
}
|
|
132
149
|
const { target = defaultWindow, eventName = "keydown", passive = false } = options;
|
|
133
150
|
const predicate = createKeyPredicate(key);
|
|
134
151
|
const listener = (e) => {
|
|
@@ -157,7 +174,7 @@ var __spreadValues$d = (a, b) => {
|
|
|
157
174
|
const vOnKeyStroke = {
|
|
158
175
|
[directiveHooks.mounted](el, binding) {
|
|
159
176
|
var _a, _b;
|
|
160
|
-
const keys = (_b = (_a = binding.arg) == null ? void 0 : _a.split(",")) != null ? _b :
|
|
177
|
+
const keys = (_b = (_a = binding.arg) == null ? void 0 : _a.split(",")) != null ? _b : true;
|
|
161
178
|
if (typeof binding.value === "function") {
|
|
162
179
|
onKeyStroke(keys, binding.value, {
|
|
163
180
|
target: el
|
|
@@ -175,11 +192,11 @@ const DEFAULT_DELAY = 500;
|
|
|
175
192
|
function onLongPress(target, handler, options) {
|
|
176
193
|
var _a, _b;
|
|
177
194
|
const elementRef = computed(() => unrefElement(target));
|
|
178
|
-
let timeout
|
|
195
|
+
let timeout;
|
|
179
196
|
function clear() {
|
|
180
|
-
if (timeout
|
|
197
|
+
if (timeout) {
|
|
181
198
|
clearTimeout(timeout);
|
|
182
|
-
timeout =
|
|
199
|
+
timeout = void 0;
|
|
183
200
|
}
|
|
184
201
|
}
|
|
185
202
|
function onDown(ev) {
|
|
@@ -418,28 +435,27 @@ function useMediaQuery(query, options = {}) {
|
|
|
418
435
|
const isSupported = useSupported(() => window && "matchMedia" in window && typeof window.matchMedia === "function");
|
|
419
436
|
let mediaQuery;
|
|
420
437
|
const matches = ref(false);
|
|
438
|
+
const cleanup = () => {
|
|
439
|
+
if (!mediaQuery)
|
|
440
|
+
return;
|
|
441
|
+
if ("removeEventListener" in mediaQuery)
|
|
442
|
+
mediaQuery.removeEventListener("change", update);
|
|
443
|
+
else
|
|
444
|
+
mediaQuery.removeListener(update);
|
|
445
|
+
};
|
|
421
446
|
const update = () => {
|
|
422
447
|
if (!isSupported.value)
|
|
423
448
|
return;
|
|
424
|
-
|
|
425
|
-
|
|
449
|
+
cleanup();
|
|
450
|
+
mediaQuery = window.matchMedia(resolveRef(query).value);
|
|
426
451
|
matches.value = mediaQuery.matches;
|
|
427
|
-
};
|
|
428
|
-
tryOnBeforeMount(() => {
|
|
429
|
-
update();
|
|
430
|
-
if (!mediaQuery)
|
|
431
|
-
return;
|
|
432
452
|
if ("addEventListener" in mediaQuery)
|
|
433
453
|
mediaQuery.addEventListener("change", update);
|
|
434
454
|
else
|
|
435
455
|
mediaQuery.addListener(update);
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
else
|
|
440
|
-
mediaQuery.removeListener(update);
|
|
441
|
-
});
|
|
442
|
-
});
|
|
456
|
+
};
|
|
457
|
+
watchEffect(update);
|
|
458
|
+
tryOnScopeDispose(() => cleanup());
|
|
443
459
|
return matches;
|
|
444
460
|
}
|
|
445
461
|
|
|
@@ -645,12 +661,18 @@ const UseDraggable = defineComponent({
|
|
|
645
661
|
"preventDefault",
|
|
646
662
|
"stopPropagation",
|
|
647
663
|
"pointerTypes",
|
|
648
|
-
"as"
|
|
664
|
+
"as",
|
|
665
|
+
"handle"
|
|
649
666
|
],
|
|
650
667
|
setup(props, { slots }) {
|
|
651
668
|
const target = ref();
|
|
669
|
+
const handle = computed(() => {
|
|
670
|
+
var _a;
|
|
671
|
+
return (_a = props.handle) != null ? _a : target.value;
|
|
672
|
+
});
|
|
652
673
|
const initialValue = props.storageKey ? useStorage$1(props.storageKey, resolveUnref(props.initialValue) || { x: 0, y: 0 }, isClient$1 ? props.storageType === "session" ? sessionStorage : localStorage : void 0) : props.initialValue || { x: 0, y: 0 };
|
|
653
674
|
const data = reactive(useDraggable(target, __spreadProps$8(__spreadValues$a({}, props), {
|
|
675
|
+
handle,
|
|
654
676
|
initialValue
|
|
655
677
|
})));
|
|
656
678
|
return () => {
|
|
@@ -746,11 +768,18 @@ function useResizeObserver(target, callback, options = {}) {
|
|
|
746
768
|
}
|
|
747
769
|
|
|
748
770
|
function useElementSize(target, initialSize = { width: 0, height: 0 }, options = {}) {
|
|
771
|
+
const { box = "content-box" } = options;
|
|
749
772
|
const width = ref(initialSize.width);
|
|
750
773
|
const height = ref(initialSize.height);
|
|
751
774
|
useResizeObserver(target, ([entry]) => {
|
|
752
|
-
|
|
753
|
-
|
|
775
|
+
const boxSize = box === "border-box" ? entry.borderBoxSize : box === "content-box" ? entry.contentBoxSize : entry.devicePixelContentBoxSize;
|
|
776
|
+
if (boxSize) {
|
|
777
|
+
width.value = boxSize.reduce((acc, { inlineSize }) => acc + inlineSize, 0);
|
|
778
|
+
height.value = boxSize.reduce((acc, { blockSize }) => acc + blockSize, 0);
|
|
779
|
+
} else {
|
|
780
|
+
width.value = entry.contentRect.width;
|
|
781
|
+
height.value = entry.contentRect.height;
|
|
782
|
+
}
|
|
754
783
|
}, options);
|
|
755
784
|
watch(() => unrefElement(target), (ele) => {
|
|
756
785
|
width.value = ele ? initialSize.width : 0;
|
|
@@ -793,7 +822,7 @@ function useElementVisibility(element, { window = defaultWindow, scrollTarget }
|
|
|
793
822
|
if (!window)
|
|
794
823
|
return;
|
|
795
824
|
const document = window.document;
|
|
796
|
-
const el =
|
|
825
|
+
const el = unrefElement(element);
|
|
797
826
|
if (!el) {
|
|
798
827
|
elementIsVisible.value = false;
|
|
799
828
|
} else {
|
|
@@ -801,9 +830,12 @@ function useElementVisibility(element, { window = defaultWindow, scrollTarget }
|
|
|
801
830
|
elementIsVisible.value = rect.top <= (window.innerHeight || document.documentElement.clientHeight) && rect.left <= (window.innerWidth || document.documentElement.clientWidth) && rect.bottom >= 0 && rect.right >= 0;
|
|
802
831
|
}
|
|
803
832
|
};
|
|
804
|
-
|
|
833
|
+
watch(() => unrefElement(element), () => testBounding(), { immediate: true, flush: "post" });
|
|
805
834
|
if (window) {
|
|
806
|
-
|
|
835
|
+
useEventListener(scrollTarget || window, "scroll", testBounding, {
|
|
836
|
+
capture: false,
|
|
837
|
+
passive: true
|
|
838
|
+
});
|
|
807
839
|
}
|
|
808
840
|
return elementIsVisible;
|
|
809
841
|
}
|
|
@@ -995,10 +1027,38 @@ function useScroll(element, options = {}) {
|
|
|
995
1027
|
eventListenerOptions = {
|
|
996
1028
|
capture: false,
|
|
997
1029
|
passive: true
|
|
998
|
-
}
|
|
1030
|
+
},
|
|
1031
|
+
behavior = "auto"
|
|
999
1032
|
} = options;
|
|
1000
|
-
const
|
|
1001
|
-
const
|
|
1033
|
+
const internalX = ref(0);
|
|
1034
|
+
const internalY = ref(0);
|
|
1035
|
+
const x = computed({
|
|
1036
|
+
get() {
|
|
1037
|
+
return internalX.value;
|
|
1038
|
+
},
|
|
1039
|
+
set(x2) {
|
|
1040
|
+
scrollTo(x2, void 0);
|
|
1041
|
+
}
|
|
1042
|
+
});
|
|
1043
|
+
const y = computed({
|
|
1044
|
+
get() {
|
|
1045
|
+
return internalY.value;
|
|
1046
|
+
},
|
|
1047
|
+
set(y2) {
|
|
1048
|
+
scrollTo(void 0, y2);
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
function scrollTo(_x, _y) {
|
|
1052
|
+
var _a, _b, _c;
|
|
1053
|
+
const _element = resolveUnref(element);
|
|
1054
|
+
if (!_element)
|
|
1055
|
+
return;
|
|
1056
|
+
(_c = _element instanceof Document ? document.body : _element) == null ? void 0 : _c.scrollTo({
|
|
1057
|
+
top: (_a = resolveUnref(_y)) != null ? _a : y.value,
|
|
1058
|
+
left: (_b = resolveUnref(_x)) != null ? _b : x.value,
|
|
1059
|
+
behavior: resolveUnref(behavior)
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1002
1062
|
const isScrolling = ref(false);
|
|
1003
1063
|
const arrivedState = reactive({
|
|
1004
1064
|
left: true,
|
|
@@ -1023,19 +1083,19 @@ function useScroll(element, options = {}) {
|
|
|
1023
1083
|
const onScrollHandler = (e) => {
|
|
1024
1084
|
const eventTarget = e.target === document ? e.target.documentElement : e.target;
|
|
1025
1085
|
const scrollLeft = eventTarget.scrollLeft;
|
|
1026
|
-
directions.left = scrollLeft <
|
|
1027
|
-
directions.right = scrollLeft >
|
|
1086
|
+
directions.left = scrollLeft < internalX.value;
|
|
1087
|
+
directions.right = scrollLeft > internalY.value;
|
|
1028
1088
|
arrivedState.left = scrollLeft <= 0 + (offset.left || 0);
|
|
1029
1089
|
arrivedState.right = scrollLeft + eventTarget.clientWidth >= eventTarget.scrollWidth - (offset.right || 0) - ARRIVED_STATE_THRESHOLD_PIXELS;
|
|
1030
|
-
|
|
1090
|
+
internalX.value = scrollLeft;
|
|
1031
1091
|
let scrollTop = eventTarget.scrollTop;
|
|
1032
1092
|
if (e.target === document && !scrollTop)
|
|
1033
1093
|
scrollTop = document.body.scrollTop;
|
|
1034
|
-
directions.top = scrollTop <
|
|
1035
|
-
directions.bottom = scrollTop >
|
|
1094
|
+
directions.top = scrollTop < internalY.value;
|
|
1095
|
+
directions.bottom = scrollTop > internalY.value;
|
|
1036
1096
|
arrivedState.top = scrollTop <= 0 + (offset.top || 0);
|
|
1037
1097
|
arrivedState.bottom = scrollTop + eventTarget.clientHeight >= eventTarget.scrollHeight - (offset.bottom || 0) - ARRIVED_STATE_THRESHOLD_PIXELS;
|
|
1038
|
-
|
|
1098
|
+
internalY.value = scrollTop;
|
|
1039
1099
|
isScrolling.value = true;
|
|
1040
1100
|
onScrollEnd(e);
|
|
1041
1101
|
onScroll(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/components",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.3.0",
|
|
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": "9.
|
|
37
|
-
"@vueuse/shared": "9.
|
|
36
|
+
"@vueuse/core": "9.3.0",
|
|
37
|
+
"@vueuse/shared": "9.3.0",
|
|
38
38
|
"vue-demi": "*"
|
|
39
39
|
}
|
|
40
40
|
}
|