@vueuse/components 11.0.0-beta.1 → 11.0.0-beta.2
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 +79 -28
- package/index.d.cts +54 -25
- package/index.d.mts +54 -25
- package/index.d.ts +54 -25
- package/index.iife.js +79 -28
- package/index.iife.min.js +1 -1
- package/index.mjs +79 -29
- package/package.json +3 -3
package/index.mjs
CHANGED
|
@@ -465,8 +465,10 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
465
465
|
);
|
|
466
466
|
if (window && listenToStorageChanges) {
|
|
467
467
|
tryOnMounted(() => {
|
|
468
|
-
|
|
469
|
-
|
|
468
|
+
if (storage instanceof Storage)
|
|
469
|
+
useEventListener(window, "storage", update);
|
|
470
|
+
else
|
|
471
|
+
useEventListener(window, customStorageEventName, updateFromCustomEvent);
|
|
470
472
|
if (initOnMounted)
|
|
471
473
|
update();
|
|
472
474
|
});
|
|
@@ -474,7 +476,7 @@ function useStorage(key, defaults, storage, options = {}) {
|
|
|
474
476
|
if (!initOnMounted)
|
|
475
477
|
update();
|
|
476
478
|
function dispatchWriteEvent(oldValue, newValue) {
|
|
477
|
-
if (window) {
|
|
479
|
+
if (window && !(storage instanceof Storage)) {
|
|
478
480
|
window.dispatchEvent(new CustomEvent(customStorageEventName, {
|
|
479
481
|
detail: {
|
|
480
482
|
key,
|
|
@@ -607,6 +609,7 @@ function usePreferredDark(options) {
|
|
|
607
609
|
return useMediaQuery("(prefers-color-scheme: dark)", options);
|
|
608
610
|
}
|
|
609
611
|
|
|
612
|
+
const CSS_DISABLE_TRANS = "*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}";
|
|
610
613
|
function useColorMode(options = {}) {
|
|
611
614
|
const {
|
|
612
615
|
selector = "html",
|
|
@@ -636,23 +639,36 @@ function useColorMode(options = {}) {
|
|
|
636
639
|
const el = typeof selector2 === "string" ? window == null ? void 0 : window.document.querySelector(selector2) : unrefElement(selector2);
|
|
637
640
|
if (!el)
|
|
638
641
|
return;
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const styleString = "*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}";
|
|
643
|
-
style.appendChild(document.createTextNode(styleString));
|
|
644
|
-
window.document.head.appendChild(style);
|
|
645
|
-
}
|
|
642
|
+
const classesToAdd = /* @__PURE__ */ new Set();
|
|
643
|
+
const classesToRemove = /* @__PURE__ */ new Set();
|
|
644
|
+
let attributeToChange = null;
|
|
646
645
|
if (attribute2 === "class") {
|
|
647
646
|
const current = value.split(/\s/g);
|
|
648
647
|
Object.values(modes).flatMap((i) => (i || "").split(/\s/g)).filter(Boolean).forEach((v) => {
|
|
649
648
|
if (current.includes(v))
|
|
650
|
-
|
|
649
|
+
classesToAdd.add(v);
|
|
651
650
|
else
|
|
652
|
-
|
|
651
|
+
classesToRemove.add(v);
|
|
653
652
|
});
|
|
654
653
|
} else {
|
|
655
|
-
|
|
654
|
+
attributeToChange = { key: attribute2, value };
|
|
655
|
+
}
|
|
656
|
+
if (classesToAdd.size === 0 && classesToRemove.size === 0 && attributeToChange === null)
|
|
657
|
+
return;
|
|
658
|
+
let style;
|
|
659
|
+
if (disableTransition) {
|
|
660
|
+
style = window.document.createElement("style");
|
|
661
|
+
style.appendChild(document.createTextNode(CSS_DISABLE_TRANS));
|
|
662
|
+
window.document.head.appendChild(style);
|
|
663
|
+
}
|
|
664
|
+
for (const c of classesToAdd) {
|
|
665
|
+
el.classList.add(c);
|
|
666
|
+
}
|
|
667
|
+
for (const c of classesToRemove) {
|
|
668
|
+
el.classList.remove(c);
|
|
669
|
+
}
|
|
670
|
+
if (attributeToChange) {
|
|
671
|
+
el.setAttribute(attributeToChange.key, attributeToChange.value);
|
|
656
672
|
}
|
|
657
673
|
if (disableTransition) {
|
|
658
674
|
window.getComputedStyle(style).opacity;
|
|
@@ -796,7 +812,8 @@ const UseDraggable = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
796
812
|
"onStart",
|
|
797
813
|
"onMove",
|
|
798
814
|
"onEnd",
|
|
799
|
-
"disabled"
|
|
815
|
+
"disabled",
|
|
816
|
+
"buttons"
|
|
800
817
|
],
|
|
801
818
|
setup(props, { slots }) {
|
|
802
819
|
const target = ref();
|
|
@@ -874,9 +891,14 @@ function useElementHover(el, options = {}) {
|
|
|
874
891
|
|
|
875
892
|
const vElementHover = {
|
|
876
893
|
[directiveHooks.mounted](el, binding) {
|
|
877
|
-
|
|
894
|
+
const value = binding.value;
|
|
895
|
+
if (typeof value === "function") {
|
|
878
896
|
const isHovered = useElementHover(el);
|
|
879
|
-
watch(isHovered, (v) =>
|
|
897
|
+
watch(isHovered, (v) => value(v));
|
|
898
|
+
} else {
|
|
899
|
+
const [handler, options] = value;
|
|
900
|
+
const isHovered = useElementHover(el, options);
|
|
901
|
+
watch(isHovered, (v) => handler(v));
|
|
880
902
|
}
|
|
881
903
|
}
|
|
882
904
|
};
|
|
@@ -904,15 +926,20 @@ function useResizeObserver(target, callback, options = {}) {
|
|
|
904
926
|
observer = void 0;
|
|
905
927
|
}
|
|
906
928
|
};
|
|
907
|
-
const targets = computed(() =>
|
|
929
|
+
const targets = computed(() => {
|
|
930
|
+
const _targets = toValue(target);
|
|
931
|
+
return Array.isArray(_targets) ? _targets.map((el) => unrefElement(el)) : [unrefElement(_targets)];
|
|
932
|
+
});
|
|
908
933
|
const stopWatch = watch(
|
|
909
934
|
targets,
|
|
910
935
|
(els) => {
|
|
911
936
|
cleanup();
|
|
912
937
|
if (isSupported.value && window) {
|
|
913
938
|
observer = new ResizeObserver(callback);
|
|
914
|
-
for (const _el of els)
|
|
915
|
-
|
|
939
|
+
for (const _el of els) {
|
|
940
|
+
if (_el)
|
|
941
|
+
observer.observe(_el, observerOptions);
|
|
942
|
+
}
|
|
916
943
|
}
|
|
917
944
|
},
|
|
918
945
|
{ immediate: true, flush: "post" }
|
|
@@ -1014,7 +1041,7 @@ function useIntersectionObserver(target, callback, options = {}) {
|
|
|
1014
1041
|
const {
|
|
1015
1042
|
root,
|
|
1016
1043
|
rootMargin = "0px",
|
|
1017
|
-
threshold = 0
|
|
1044
|
+
threshold = 0,
|
|
1018
1045
|
window = defaultWindow,
|
|
1019
1046
|
immediate = true
|
|
1020
1047
|
} = options;
|
|
@@ -1503,7 +1530,10 @@ function useInfiniteScroll(element, onLoadMore, options = {}) {
|
|
|
1503
1530
|
{ immediate: true }
|
|
1504
1531
|
);
|
|
1505
1532
|
return {
|
|
1506
|
-
isLoading
|
|
1533
|
+
isLoading,
|
|
1534
|
+
reset() {
|
|
1535
|
+
nextTick(() => checkAndLoad());
|
|
1536
|
+
}
|
|
1507
1537
|
};
|
|
1508
1538
|
}
|
|
1509
1539
|
|
|
@@ -1766,6 +1796,15 @@ const UsePreferredReducedMotion = /* @__PURE__ */ /* #__PURE__ */ defineComponen
|
|
|
1766
1796
|
}
|
|
1767
1797
|
});
|
|
1768
1798
|
|
|
1799
|
+
const vResizeObserver = {
|
|
1800
|
+
[directiveHooks.mounted](el, binding) {
|
|
1801
|
+
if (typeof binding.value === "function")
|
|
1802
|
+
useResizeObserver(el, binding.value);
|
|
1803
|
+
else
|
|
1804
|
+
useResizeObserver(el, ...binding.value);
|
|
1805
|
+
}
|
|
1806
|
+
};
|
|
1807
|
+
|
|
1769
1808
|
function useMutationObserver(target, callback, options = {}) {
|
|
1770
1809
|
const { window = defaultWindow, ...mutationOptions } = options;
|
|
1771
1810
|
let observer;
|
|
@@ -1808,7 +1847,7 @@ function useMutationObserver(target, callback, options = {}) {
|
|
|
1808
1847
|
}
|
|
1809
1848
|
|
|
1810
1849
|
function useCssVar(prop, target, options = {}) {
|
|
1811
|
-
const { window = defaultWindow, initialValue
|
|
1850
|
+
const { window = defaultWindow, initialValue, observe = false } = options;
|
|
1812
1851
|
const variable = ref(initialValue);
|
|
1813
1852
|
const elRef = computed(() => {
|
|
1814
1853
|
var _a;
|
|
@@ -1818,7 +1857,7 @@ function useCssVar(prop, target, options = {}) {
|
|
|
1818
1857
|
var _a;
|
|
1819
1858
|
const key = toValue(prop);
|
|
1820
1859
|
const el = toValue(elRef);
|
|
1821
|
-
if (el && window) {
|
|
1860
|
+
if (el && window && key) {
|
|
1822
1861
|
const value = (_a = window.getComputedStyle(el).getPropertyValue(key)) == null ? void 0 : _a.trim();
|
|
1823
1862
|
variable.value = value || initialValue;
|
|
1824
1863
|
}
|
|
@@ -1831,15 +1870,24 @@ function useCssVar(prop, target, options = {}) {
|
|
|
1831
1870
|
}
|
|
1832
1871
|
watch(
|
|
1833
1872
|
[elRef, () => toValue(prop)],
|
|
1834
|
-
|
|
1873
|
+
(_, old) => {
|
|
1874
|
+
if (old[0] && old[1] && window)
|
|
1875
|
+
window.getComputedStyle(old[0]).removeProperty(old[1]);
|
|
1876
|
+
updateCssVar();
|
|
1877
|
+
},
|
|
1835
1878
|
{ immediate: true }
|
|
1836
1879
|
);
|
|
1837
1880
|
watch(
|
|
1838
1881
|
variable,
|
|
1839
1882
|
(val) => {
|
|
1840
1883
|
var _a;
|
|
1841
|
-
|
|
1842
|
-
|
|
1884
|
+
const raw_prop = toValue(prop);
|
|
1885
|
+
if (((_a = elRef.value) == null ? void 0 : _a.style) && raw_prop) {
|
|
1886
|
+
if (val == null)
|
|
1887
|
+
elRef.value.style.removeProperty(raw_prop);
|
|
1888
|
+
else
|
|
1889
|
+
elRef.value.style.setProperty(raw_prop, val);
|
|
1890
|
+
}
|
|
1843
1891
|
}
|
|
1844
1892
|
);
|
|
1845
1893
|
return variable;
|
|
@@ -2013,7 +2061,8 @@ function useScrollLock(element, initialState = false) {
|
|
|
2013
2061
|
const el = resolveElement(toValue(element));
|
|
2014
2062
|
if (!el || !isLocked.value)
|
|
2015
2063
|
return;
|
|
2016
|
-
|
|
2064
|
+
if (isIOS)
|
|
2065
|
+
stopTouchMoveListener == null ? void 0 : stopTouchMoveListener();
|
|
2017
2066
|
el.style.overflow = initialOverflow;
|
|
2018
2067
|
elInitialOverflow.delete(el);
|
|
2019
2068
|
isLocked.value = false;
|
|
@@ -2026,7 +2075,8 @@ function useScrollLock(element, initialState = false) {
|
|
|
2026
2075
|
set(v) {
|
|
2027
2076
|
if (v)
|
|
2028
2077
|
lock();
|
|
2029
|
-
else
|
|
2078
|
+
else
|
|
2079
|
+
unlock();
|
|
2030
2080
|
}
|
|
2031
2081
|
});
|
|
2032
2082
|
}
|
|
@@ -2113,4 +2163,4 @@ const UseWindowSize = /* @__PURE__ */ /* #__PURE__ */ defineComponent({
|
|
|
2113
2163
|
}
|
|
2114
2164
|
});
|
|
2115
2165
|
|
|
2116
|
-
export { OnClickOutside, OnLongPress, UseActiveElement, UseBattery, UseBrowserLocation, UseClipboard, UseColorMode, UseDark, UseDeviceMotion, UseDeviceOrientation, UseDevicePixelRatio, UseDevicesList, UseDocumentVisibility, UseDraggable, UseElementBounding, UseElementSize, UseElementVisibility, UseEyeDropper, UseFullscreen, UseGeolocation, UseIdle, UseImage, UseMouse, UseMouseInElement, UseMousePressed, UseNetwork, UseNow, UseObjectUrl, UseOffsetPagination, UseOnline, UsePageLeave, UsePointer, UsePointerLock, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePreferredReducedMotion, UseScreenSafeArea, UseTimeAgo, UseTimestamp, UseVirtualList, UseWindowFocus, UseWindowSize, vOnClickOutside as VOnClickOutside, vOnLongPress as VOnLongPress, vElementHover, vElementSize, vElementVisibility, vInfiniteScroll, vIntersectionObserver, vOnClickOutside, vOnKeyStroke, vOnLongPress, vScroll, vScrollLock };
|
|
2166
|
+
export { OnClickOutside, OnLongPress, UseActiveElement, UseBattery, UseBrowserLocation, UseClipboard, UseColorMode, UseDark, UseDeviceMotion, UseDeviceOrientation, UseDevicePixelRatio, UseDevicesList, UseDocumentVisibility, UseDraggable, UseElementBounding, UseElementSize, UseElementVisibility, UseEyeDropper, UseFullscreen, UseGeolocation, UseIdle, UseImage, UseMouse, UseMouseInElement, UseMousePressed, UseNetwork, UseNow, UseObjectUrl, UseOffsetPagination, UseOnline, UsePageLeave, UsePointer, UsePointerLock, UsePreferredColorScheme, UsePreferredContrast, UsePreferredDark, UsePreferredLanguages, UsePreferredReducedMotion, UseScreenSafeArea, UseTimeAgo, UseTimestamp, UseVirtualList, UseWindowFocus, UseWindowSize, vOnClickOutside as VOnClickOutside, vOnLongPress as VOnLongPress, vElementHover, vElementSize, vElementVisibility, vInfiniteScroll, vIntersectionObserver, vOnClickOutside, vOnKeyStroke, vOnLongPress, vResizeObserver, vScroll, vScrollLock };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/components",
|
|
3
|
-
"version": "11.0.0-beta.
|
|
3
|
+
"version": "11.0.0-beta.2",
|
|
4
4
|
"description": "Renderless components for VueUse",
|
|
5
5
|
"author": "Jacob Clevenger<https://github.com/wheatjs>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"jsdelivr": "./index.iife.min.js",
|
|
33
33
|
"types": "./index.d.cts",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@vueuse/core": "11.0.0-beta.
|
|
36
|
-
"@vueuse/shared": "11.0.0-beta.
|
|
35
|
+
"@vueuse/core": "11.0.0-beta.2",
|
|
36
|
+
"@vueuse/shared": "11.0.0-beta.2",
|
|
37
37
|
"vue-demi": ">=0.14.8"
|
|
38
38
|
}
|
|
39
39
|
}
|