@maas/vue-equipment 1.0.0-beta.42 → 1.0.0-beta.43
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/dist/composables/useScrollLockPadding/index.d.ts +9 -0
- package/dist/composables/useScrollLockPadding/index.js +56 -0
- package/dist/composables/useScrollLockPadding/index.js.map +1 -0
- package/dist/nuxt/module.json +1 -1
- package/dist/nuxt/module.mjs +7 -0
- package/dist/plugins/MagicCommand/src/components/MagicCommandItem.d.vue.ts +2 -2
- package/dist/plugins/MagicCommand/src/components/MagicCommandItem.vue.d.ts +2 -2
- package/dist/plugins/MagicCommand/src/components/MagicCommandView.vue +1 -1
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableDrag.mjs +5 -14
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableScrollLock.d.ts +2 -4
- package/dist/plugins/MagicDraggable/src/composables/private/useDraggableScrollLock.mjs +11 -51
- package/dist/plugins/MagicDrawer/src/components/MagicDrawer.vue +4 -16
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerCallback.d.ts +0 -4
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerCallback.mjs +8 -12
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDOM.d.ts +2 -4
- package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDOM.mjs +15 -58
- package/dist/plugins/MagicMenu/src/components/MagicMenuContent.vue +4 -12
- package/dist/plugins/MagicMenu/src/components/MagicMenuItem.d.vue.ts +2 -2
- package/dist/plugins/MagicMenu/src/components/MagicMenuItem.vue.d.ts +2 -2
- package/dist/plugins/MagicMenu/src/composables/private/useMenuCallback.d.ts +1 -4
- package/dist/plugins/MagicMenu/src/composables/private/useMenuCallback.mjs +7 -21
- package/dist/plugins/MagicMenu/src/composables/private/useMenuDOM.d.ts +2 -4
- package/dist/plugins/MagicMenu/src/composables/private/useMenuDOM.mjs +13 -51
- package/dist/plugins/MagicModal/src/components/MagicModal.vue +4 -16
- package/dist/plugins/MagicModal/src/composables/private/useModalCallback.d.ts +0 -4
- package/dist/plugins/MagicModal/src/composables/private/useModalCallback.mjs +9 -19
- package/dist/plugins/MagicModal/src/composables/private/useModalDOM.d.ts +2 -4
- package/dist/plugins/MagicModal/src/composables/private/useModalDOM.mjs +15 -58
- package/dist/plugins/MagicToast/src/composables/private/useToastDrag.mjs +5 -14
- package/dist/plugins/MagicToast/src/composables/private/useToastScrollLock.d.ts +2 -4
- package/dist/plugins/MagicToast/src/composables/private/useToastScrollLock.mjs +11 -49
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// useScrollLockPadding/index.ts
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import {
|
|
4
|
+
matchClass,
|
|
5
|
+
scrollbarGutterSupport,
|
|
6
|
+
scrollbarWidth
|
|
7
|
+
} from "@maas/vue-equipment/utils";
|
|
8
|
+
function useScrollLockPadding(args) {
|
|
9
|
+
const exclude = args?.exclude || "";
|
|
10
|
+
const positionFixedElements = ref([]);
|
|
11
|
+
function add() {
|
|
12
|
+
if (typeof window === "undefined") {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const excludeRegEx = new RegExp(exclude);
|
|
16
|
+
document.body.style.setProperty(
|
|
17
|
+
"--scrollbar-width",
|
|
18
|
+
`${scrollbarWidth()}px`
|
|
19
|
+
);
|
|
20
|
+
positionFixedElements.value = [
|
|
21
|
+
...document.body.getElementsByTagName("*")
|
|
22
|
+
].filter(
|
|
23
|
+
(x) => getComputedStyle(x, null).getPropertyValue("position") === "fixed" && getComputedStyle(x, null).getPropertyValue("right") === "0px" && !matchClass(x, excludeRegEx)
|
|
24
|
+
);
|
|
25
|
+
switch (scrollbarGutterSupport()) {
|
|
26
|
+
case true:
|
|
27
|
+
document.documentElement.style.scrollbarGutter = "stable";
|
|
28
|
+
positionFixedElements.value.forEach((elem) => {
|
|
29
|
+
elem.style.scrollbarGutter = "stable";
|
|
30
|
+
elem.style.overflow = "auto";
|
|
31
|
+
});
|
|
32
|
+
break;
|
|
33
|
+
case false:
|
|
34
|
+
document.body.style.paddingRight = "var(--scrollbar-width)";
|
|
35
|
+
positionFixedElements.value.forEach(
|
|
36
|
+
(elem) => elem.style.paddingRight = "var(--scrollbar-width)"
|
|
37
|
+
);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function remove() {
|
|
42
|
+
document.documentElement.style.scrollbarGutter = "";
|
|
43
|
+
document.body.style.removeProperty("--scrollbar-width");
|
|
44
|
+
document.body.style.paddingRight = "";
|
|
45
|
+
positionFixedElements.value.forEach((elem) => {
|
|
46
|
+
elem.style.paddingRight = "";
|
|
47
|
+
elem.style.scrollbarGutter = "";
|
|
48
|
+
elem.style.overflow = "";
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return { add, remove };
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
useScrollLockPadding
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../packages/composables/useScrollLockPadding/index.ts"],"sourcesContent":["import { ref } from 'vue'\nimport {\n matchClass,\n scrollbarGutterSupport,\n scrollbarWidth,\n} from '@maas/vue-equipment/utils'\n\nexport type UseScrollLockPaddingArgs = {\n exclude: RegExp\n}\n\nexport function useScrollLockPadding(args?: UseScrollLockPaddingArgs) {\n const exclude = args?.exclude || ''\n const positionFixedElements = ref<HTMLElement[]>([])\n\n function add() {\n if (typeof window === 'undefined') {\n return\n }\n\n const excludeRegEx = new RegExp(exclude)\n\n document.body.style.setProperty(\n '--scrollbar-width',\n `${scrollbarWidth()}px`\n )\n\n positionFixedElements.value = [\n ...document.body.getElementsByTagName('*'),\n ].filter(\n (x) =>\n getComputedStyle(x, null).getPropertyValue('position') === 'fixed' &&\n getComputedStyle(x, null).getPropertyValue('right') === '0px' &&\n !matchClass(x, excludeRegEx)\n ) as HTMLElement[]\n\n switch (scrollbarGutterSupport()) {\n case true:\n document.documentElement.style.scrollbarGutter = 'stable'\n positionFixedElements.value.forEach((elem) => {\n elem.style.scrollbarGutter = 'stable'\n elem.style.overflow = 'auto'\n })\n break\n case false:\n document.body.style.paddingRight = 'var(--scrollbar-width)'\n positionFixedElements.value.forEach(\n (elem) => (elem.style.paddingRight = 'var(--scrollbar-width)')\n )\n break\n }\n }\n\n function remove() {\n document.documentElement.style.scrollbarGutter = ''\n document.body.style.removeProperty('--scrollbar-width')\n document.body.style.paddingRight = ''\n positionFixedElements.value.forEach((elem) => {\n elem.style.paddingRight = ''\n elem.style.scrollbarGutter = ''\n elem.style.overflow = ''\n })\n }\n\n return { add, remove }\n}\n"],"mappings":";AAAA,SAAS,WAAW;AACpB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMA,SAAS,qBAAqB,MAAiC;AACpE,QAAM,UAAU,MAAM,WAAW;AACjC,QAAM,wBAAwB,IAAmB,CAAC,CAAC;AAEnD,WAAS,MAAM;AACb,QAAI,OAAO,WAAW,aAAa;AACjC;AAAA,IACF;AAEA,UAAM,eAAe,IAAI,OAAO,OAAO;AAEvC,aAAS,KAAK,MAAM;AAAA,MAClB;AAAA,MACA,GAAG,eAAe,CAAC;AAAA,IACrB;AAEA,0BAAsB,QAAQ;AAAA,MAC5B,GAAG,SAAS,KAAK,qBAAqB,GAAG;AAAA,IAC3C,EAAE;AAAA,MACA,CAAC,MACC,iBAAiB,GAAG,IAAI,EAAE,iBAAiB,UAAU,MAAM,WAC3D,iBAAiB,GAAG,IAAI,EAAE,iBAAiB,OAAO,MAAM,SACxD,CAAC,WAAW,GAAG,YAAY;AAAA,IAC/B;AAEA,YAAQ,uBAAuB,GAAG;AAAA,MAChC,KAAK;AACH,iBAAS,gBAAgB,MAAM,kBAAkB;AACjD,8BAAsB,MAAM,QAAQ,CAAC,SAAS;AAC5C,eAAK,MAAM,kBAAkB;AAC7B,eAAK,MAAM,WAAW;AAAA,QACxB,CAAC;AACD;AAAA,MACF,KAAK;AACH,iBAAS,KAAK,MAAM,eAAe;AACnC,8BAAsB,MAAM;AAAA,UAC1B,CAAC,SAAU,KAAK,MAAM,eAAe;AAAA,QACvC;AACA;AAAA,IACJ;AAAA,EACF;AAEA,WAAS,SAAS;AAChB,aAAS,gBAAgB,MAAM,kBAAkB;AACjD,aAAS,KAAK,MAAM,eAAe,mBAAmB;AACtD,aAAS,KAAK,MAAM,eAAe;AACnC,0BAAsB,MAAM,QAAQ,CAAC,SAAS;AAC5C,WAAK,MAAM,eAAe;AAC1B,WAAK,MAAM,kBAAkB;AAC7B,WAAK,MAAM,WAAW;AAAA,IACxB,CAAC;AAAA,EACH;AAEA,SAAO,EAAE,KAAK,OAAO;AACvB;","names":[]}
|
package/dist/nuxt/module.json
CHANGED
package/dist/nuxt/module.mjs
CHANGED
|
@@ -127,6 +127,13 @@ const functions$1 = [
|
|
|
127
127
|
docs: "https://maas.egineering/vue-equipment/composables/useMetaViewport/",
|
|
128
128
|
description: "Set and reset the meta viewport tag programatically"
|
|
129
129
|
},
|
|
130
|
+
{
|
|
131
|
+
name: "useScrollLockPadding",
|
|
132
|
+
"package": "composables",
|
|
133
|
+
lastUpdated: 1763989817000,
|
|
134
|
+
docs: "https://maas.egineering/vue-equipment/composables/useScrollLockPadding/",
|
|
135
|
+
description: "A small utility to prevent fixed elements from jumping when locking scroll"
|
|
136
|
+
},
|
|
130
137
|
{
|
|
131
138
|
name: "useScrollTo",
|
|
132
139
|
"package": "composables",
|
|
@@ -11,11 +11,11 @@ type __VLS_Slots = {} & {
|
|
|
11
11
|
default?: (props: typeof __VLS_1) => any;
|
|
12
12
|
};
|
|
13
13
|
declare const __VLS_base: import("vue").DefineComponent<MagicCommandItemProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
14
|
-
click: (event: MouseEvent) => any;
|
|
15
14
|
enter: () => any;
|
|
15
|
+
click: (event: MouseEvent) => any;
|
|
16
16
|
}, string, import("vue").PublicProps, Readonly<MagicCommandItemProps> & Readonly<{
|
|
17
|
-
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
18
17
|
onEnter?: (() => any) | undefined;
|
|
18
|
+
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
19
19
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
20
20
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
21
21
|
declare const _default: typeof __VLS_export;
|
|
@@ -11,11 +11,11 @@ type __VLS_Slots = {} & {
|
|
|
11
11
|
default?: (props: typeof __VLS_1) => any;
|
|
12
12
|
};
|
|
13
13
|
declare const __VLS_base: import("vue").DefineComponent<MagicCommandItemProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
14
|
-
click: (event: MouseEvent) => any;
|
|
15
14
|
enter: () => any;
|
|
15
|
+
click: (event: MouseEvent) => any;
|
|
16
16
|
}, string, import("vue").PublicProps, Readonly<MagicCommandItemProps> & Readonly<{
|
|
17
|
-
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
18
17
|
onEnter?: (() => any) | undefined;
|
|
18
|
+
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
19
19
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
20
20
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
21
21
|
declare const _default: typeof __VLS_export;
|
|
@@ -95,12 +95,7 @@ export function useDraggableDrag(args) {
|
|
|
95
95
|
snapPoints
|
|
96
96
|
});
|
|
97
97
|
const emitter = useMagicEmitter();
|
|
98
|
-
const {
|
|
99
|
-
lockScroll,
|
|
100
|
-
unlockScroll,
|
|
101
|
-
addScrollLockPadding,
|
|
102
|
-
removeScrollLockPadding
|
|
103
|
-
} = useDraggableScrollLock();
|
|
98
|
+
const { lockScroll, unlockScroll } = useDraggableScrollLock();
|
|
104
99
|
function getSizes() {
|
|
105
100
|
elRect.value = unrefElement(elRef)?.getBoundingClientRect();
|
|
106
101
|
wrapperRect.value = unrefElement(wrapperRef)?.getBoundingClientRect();
|
|
@@ -283,10 +278,9 @@ export function useDraggableDrag(args) {
|
|
|
283
278
|
resetStateAndListeners();
|
|
284
279
|
const scrollLockValue = toValue(scrollLock);
|
|
285
280
|
if (scrollLockValue) {
|
|
286
|
-
unlockScroll(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
281
|
+
unlockScroll(
|
|
282
|
+
typeof scrollLockValue === "object" && scrollLockValue.padding
|
|
283
|
+
);
|
|
290
284
|
}
|
|
291
285
|
guardedReleasePointerCapture({ event: e, element: elRef.value });
|
|
292
286
|
}
|
|
@@ -324,10 +318,7 @@ export function useDraggableDrag(args) {
|
|
|
324
318
|
}
|
|
325
319
|
const scrollLockValue = toValue(scrollLock);
|
|
326
320
|
if (scrollLockValue) {
|
|
327
|
-
|
|
328
|
-
addScrollLockPadding();
|
|
329
|
-
}
|
|
330
|
-
lockScroll();
|
|
321
|
+
lockScroll(typeof scrollLockValue === "object" && scrollLockValue.padding);
|
|
331
322
|
}
|
|
332
323
|
if (dragging.value) {
|
|
333
324
|
return;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export declare function useDraggableScrollLock(): {
|
|
2
|
-
lockScroll: () => void;
|
|
3
|
-
unlockScroll: () => void;
|
|
4
|
-
addScrollLockPadding: () => void;
|
|
5
|
-
removeScrollLockPadding: () => void;
|
|
2
|
+
lockScroll: (padding?: boolean) => void;
|
|
3
|
+
unlockScroll: (padding?: boolean) => void;
|
|
6
4
|
};
|
|
@@ -1,63 +1,23 @@
|
|
|
1
|
-
import { shallowRef
|
|
1
|
+
import { shallowRef } from "vue";
|
|
2
2
|
import { useScrollLock } from "@vueuse/core";
|
|
3
|
-
import {
|
|
4
|
-
matchClass,
|
|
5
|
-
scrollbarWidth,
|
|
6
|
-
scrollbarGutterSupport
|
|
7
|
-
} from "@maas/vue-equipment/utils";
|
|
3
|
+
import { useScrollLockPadding } from "@maas/vue-equipment/composables/useScrollLockPadding";
|
|
8
4
|
const scrollLock = typeof window !== "undefined" ? useScrollLock(document?.documentElement) : shallowRef(false);
|
|
5
|
+
const { add, remove } = useScrollLockPadding({ exclude: /magic-draggable/ });
|
|
9
6
|
export function useDraggableScrollLock() {
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
function lockScroll(padding) {
|
|
8
|
+
if (padding) {
|
|
9
|
+
add();
|
|
10
|
+
}
|
|
12
11
|
scrollLock.value = true;
|
|
13
12
|
}
|
|
14
|
-
function unlockScroll() {
|
|
13
|
+
function unlockScroll(padding) {
|
|
15
14
|
scrollLock.value = false;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (typeof window === "undefined") {
|
|
19
|
-
return;
|
|
15
|
+
if (padding) {
|
|
16
|
+
remove();
|
|
20
17
|
}
|
|
21
|
-
const exclude = new RegExp(/magic-draggable/);
|
|
22
|
-
document.body.style.setProperty(
|
|
23
|
-
"--scrollbar-width",
|
|
24
|
-
`${scrollbarWidth()}px`
|
|
25
|
-
);
|
|
26
|
-
positionFixedElements.value = [
|
|
27
|
-
...document.body.getElementsByTagName("*")
|
|
28
|
-
].filter(
|
|
29
|
-
(x) => getComputedStyle(x, null).getPropertyValue("position") === "fixed" && getComputedStyle(x, null).getPropertyValue("right") === "0px" && !matchClass(x, exclude)
|
|
30
|
-
);
|
|
31
|
-
switch (scrollbarGutterSupport()) {
|
|
32
|
-
case true:
|
|
33
|
-
document.documentElement.style.scrollbarGutter = "stable";
|
|
34
|
-
positionFixedElements.value.forEach((elem) => {
|
|
35
|
-
elem.style.scrollbarGutter = "stable";
|
|
36
|
-
elem.style.overflow = "auto";
|
|
37
|
-
});
|
|
38
|
-
break;
|
|
39
|
-
case false:
|
|
40
|
-
document.body.style.paddingRight = "var(--scrollbar-width)";
|
|
41
|
-
positionFixedElements.value.forEach(
|
|
42
|
-
(elem) => elem.style.paddingRight = "var(--scrollbar-width)"
|
|
43
|
-
);
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function removeScrollLockPadding() {
|
|
48
|
-
document.documentElement.style.scrollbarGutter = "";
|
|
49
|
-
document.body.style.removeProperty("--scrollbar-width");
|
|
50
|
-
document.body.style.paddingRight = "";
|
|
51
|
-
positionFixedElements.value.forEach((elem) => {
|
|
52
|
-
elem.style.paddingRight = "";
|
|
53
|
-
elem.style.scrollbarGutter = "";
|
|
54
|
-
elem.style.overflow = "";
|
|
55
|
-
});
|
|
56
18
|
}
|
|
57
19
|
return {
|
|
58
20
|
lockScroll,
|
|
59
|
-
unlockScroll
|
|
60
|
-
addScrollLockPadding,
|
|
61
|
-
removeScrollLockPadding
|
|
21
|
+
unlockScroll
|
|
62
22
|
};
|
|
63
23
|
}
|
|
@@ -110,14 +110,7 @@ const mappedId = toValue(id);
|
|
|
110
110
|
const elRef = useTemplateRef("el");
|
|
111
111
|
const drawerRef = useTemplateRef("drawer");
|
|
112
112
|
const wrapperRef = useTemplateRef("wrapper");
|
|
113
|
-
const {
|
|
114
|
-
trapFocus,
|
|
115
|
-
releaseFocus,
|
|
116
|
-
lockScroll,
|
|
117
|
-
unlockScroll,
|
|
118
|
-
addScrollLockPadding,
|
|
119
|
-
removeScrollLockPadding
|
|
120
|
-
} = useDrawerDOM({
|
|
113
|
+
const { trapFocus, releaseFocus, unlockScroll } = useDrawerDOM({
|
|
121
114
|
focusTarget: drawerRef,
|
|
122
115
|
focusTrap: mappedOptions.focusTrap
|
|
123
116
|
});
|
|
@@ -177,10 +170,6 @@ const {
|
|
|
177
170
|
} = useDrawerCallback({
|
|
178
171
|
id,
|
|
179
172
|
mappedOptions,
|
|
180
|
-
addScrollLockPadding,
|
|
181
|
-
removeScrollLockPadding,
|
|
182
|
-
lockScroll,
|
|
183
|
-
unlockScroll,
|
|
184
173
|
trapFocus,
|
|
185
174
|
releaseFocus,
|
|
186
175
|
wrapperActive,
|
|
@@ -283,10 +272,9 @@ onBeforeUnmount(() => {
|
|
|
283
272
|
});
|
|
284
273
|
onUnmounted(() => {
|
|
285
274
|
if (mappedOptions.scrollLock) {
|
|
286
|
-
unlockScroll(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
275
|
+
unlockScroll(
|
|
276
|
+
typeof mappedOptions.scrollLock === "object" && mappedOptions.scrollLock.padding
|
|
277
|
+
);
|
|
290
278
|
}
|
|
291
279
|
if (mappedOptions.focusTrap) {
|
|
292
280
|
releaseFocus();
|
|
@@ -3,10 +3,6 @@ import type { MagicDrawerOptions } from '../../types/index.js';
|
|
|
3
3
|
type UseDrawerCallbackArgs = {
|
|
4
4
|
id: MaybeRef<string>;
|
|
5
5
|
mappedOptions: MagicDrawerOptions;
|
|
6
|
-
addScrollLockPadding: () => void;
|
|
7
|
-
removeScrollLockPadding: () => void;
|
|
8
|
-
lockScroll: () => void;
|
|
9
|
-
unlockScroll: () => void;
|
|
10
6
|
trapFocus: () => void;
|
|
11
7
|
releaseFocus: () => void;
|
|
12
8
|
wrapperActive: Ref<boolean>;
|
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
import { toValue, nextTick } from "vue";
|
|
2
2
|
import { useMetaViewport } from "@maas/vue-equipment/composables/useMetaViewport";
|
|
3
3
|
import { useMagicEmitter } from "@maas/vue-equipment/plugins/MagicEmitter";
|
|
4
|
+
import { useDrawerDOM } from "./useDrawerDOM.mjs";
|
|
4
5
|
export function useDrawerCallback(args) {
|
|
5
6
|
const {
|
|
6
7
|
id,
|
|
7
8
|
mappedOptions,
|
|
8
|
-
addScrollLockPadding,
|
|
9
|
-
removeScrollLockPadding,
|
|
10
|
-
lockScroll,
|
|
11
|
-
unlockScroll,
|
|
12
9
|
trapFocus,
|
|
13
10
|
releaseFocus,
|
|
14
11
|
wrapperActive,
|
|
15
12
|
wasActive
|
|
16
13
|
} = args;
|
|
14
|
+
const { lockScroll, unlockScroll } = useDrawerDOM();
|
|
17
15
|
const { setMetaViewport, resetMetaViewport } = useMetaViewport();
|
|
18
16
|
const emitter = useMagicEmitter();
|
|
19
17
|
function onBeforeEnter() {
|
|
20
18
|
emitter.emit("beforeEnter", toValue(id));
|
|
21
19
|
if (mappedOptions.scrollLock) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
lockScroll();
|
|
20
|
+
lockScroll(
|
|
21
|
+
typeof mappedOptions.scrollLock === "object" && mappedOptions.scrollLock.padding
|
|
22
|
+
);
|
|
26
23
|
}
|
|
27
24
|
if (mappedOptions.preventZoom) {
|
|
28
25
|
setMetaViewport();
|
|
@@ -48,10 +45,9 @@ export function useDrawerCallback(args) {
|
|
|
48
45
|
function onAfterLeave() {
|
|
49
46
|
emitter.emit("afterLeave", toValue(id));
|
|
50
47
|
if (mappedOptions.scrollLock) {
|
|
51
|
-
unlockScroll(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
48
|
+
unlockScroll(
|
|
49
|
+
typeof mappedOptions.scrollLock === "object" && mappedOptions.scrollLock.padding
|
|
50
|
+
);
|
|
55
51
|
}
|
|
56
52
|
if (mappedOptions.focusTrap) {
|
|
57
53
|
releaseFocus();
|
|
@@ -6,8 +6,6 @@ export type UseDrawerDOMArgs = Pick<MagicDrawerOptions, 'scrollLock' | 'focusTra
|
|
|
6
6
|
export declare function useDrawerDOM(args?: UseDrawerDOMArgs): {
|
|
7
7
|
trapFocus: () => void;
|
|
8
8
|
releaseFocus: () => void;
|
|
9
|
-
lockScroll: () => void;
|
|
10
|
-
unlockScroll: () => void;
|
|
11
|
-
addScrollLockPadding: () => void;
|
|
12
|
-
removeScrollLockPadding: () => void;
|
|
9
|
+
lockScroll: (padding?: boolean) => void;
|
|
10
|
+
unlockScroll: (padding?: boolean) => void;
|
|
13
11
|
};
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { shallowRef } from "vue";
|
|
2
2
|
import { defu } from "defu";
|
|
3
3
|
import { useScrollLock } from "@vueuse/core";
|
|
4
4
|
import { useFocusTrap } from "@vueuse/integrations/useFocusTrap";
|
|
5
|
-
import {
|
|
6
|
-
matchClass,
|
|
7
|
-
scrollbarGutterSupport,
|
|
8
|
-
scrollbarWidth
|
|
9
|
-
} from "@maas/vue-equipment/utils";
|
|
5
|
+
import { useScrollLockPadding } from "@maas/vue-equipment/composables/useScrollLockPadding";
|
|
10
6
|
const defaultOptions = {
|
|
11
7
|
focusTrap: false,
|
|
12
|
-
focusTarget: void 0
|
|
13
|
-
scrollLock: true
|
|
8
|
+
focusTarget: void 0
|
|
14
9
|
};
|
|
15
10
|
const scrollLock = typeof window !== "undefined" ? useScrollLock(document?.documentElement) : shallowRef(false);
|
|
11
|
+
const { add, remove } = useScrollLockPadding({
|
|
12
|
+
exclude: /magic-drawer(__backdrop)?/
|
|
13
|
+
});
|
|
16
14
|
export function useDrawerDOM(args) {
|
|
17
|
-
const positionFixedElements = ref([]);
|
|
18
15
|
const mappedOptions = defu(args, defaultOptions);
|
|
19
16
|
const focusTrap = mappedOptions.focusTarget ? typeof mappedOptions.focusTrap === "boolean" ? useFocusTrap(mappedOptions.focusTarget) : useFocusTrap(mappedOptions.focusTarget, mappedOptions.focusTrap) : void 0;
|
|
20
17
|
function trapFocus() {
|
|
@@ -27,62 +24,22 @@ export function useDrawerDOM(args) {
|
|
|
27
24
|
focusTrap.deactivate();
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
|
-
function lockScroll() {
|
|
31
|
-
if (
|
|
32
|
-
|
|
27
|
+
function lockScroll(padding) {
|
|
28
|
+
if (padding) {
|
|
29
|
+
add();
|
|
33
30
|
}
|
|
31
|
+
scrollLock.value = true;
|
|
34
32
|
}
|
|
35
|
-
function unlockScroll() {
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
function unlockScroll(padding) {
|
|
34
|
+
scrollLock.value = false;
|
|
35
|
+
if (padding) {
|
|
36
|
+
remove();
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
|
-
function addScrollLockPadding() {
|
|
41
|
-
if (typeof window === "undefined") {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const exclude = new RegExp(/magic-drawer(__backdrop)?/);
|
|
45
|
-
document.body.style.setProperty(
|
|
46
|
-
"--scrollbar-width",
|
|
47
|
-
`${scrollbarWidth()}px`
|
|
48
|
-
);
|
|
49
|
-
positionFixedElements.value = [
|
|
50
|
-
...document.body.getElementsByTagName("*")
|
|
51
|
-
].filter(
|
|
52
|
-
(x) => getComputedStyle(x, null).getPropertyValue("position") === "fixed" && getComputedStyle(x, null).getPropertyValue("right") === "0px" && !matchClass(x, exclude)
|
|
53
|
-
);
|
|
54
|
-
switch (scrollbarGutterSupport()) {
|
|
55
|
-
case true:
|
|
56
|
-
document.documentElement.style.scrollbarGutter = "stable";
|
|
57
|
-
positionFixedElements.value.forEach((elem) => {
|
|
58
|
-
elem.style.scrollbarGutter = "stable";
|
|
59
|
-
elem.style.overflow = "auto";
|
|
60
|
-
});
|
|
61
|
-
break;
|
|
62
|
-
case false:
|
|
63
|
-
document.body.style.paddingRight = "var(--scrollbar-width)";
|
|
64
|
-
positionFixedElements.value.forEach(
|
|
65
|
-
(elem) => elem.style.paddingRight = "var(--scrollbar-width)"
|
|
66
|
-
);
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function removeScrollLockPadding() {
|
|
71
|
-
document.documentElement.style.scrollbarGutter = "";
|
|
72
|
-
document.body.style.removeProperty("--scrollbar-width");
|
|
73
|
-
document.body.style.paddingRight = "";
|
|
74
|
-
positionFixedElements.value.forEach((elem) => {
|
|
75
|
-
elem.style.paddingRight = "";
|
|
76
|
-
elem.style.scrollbarGutter = "";
|
|
77
|
-
elem.style.overflow = "";
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
39
|
return {
|
|
81
40
|
trapFocus,
|
|
82
41
|
releaseFocus,
|
|
83
42
|
lockScroll,
|
|
84
|
-
unlockScroll
|
|
85
|
-
addScrollLockPadding,
|
|
86
|
-
removeScrollLockPadding
|
|
43
|
+
unlockScroll
|
|
87
44
|
};
|
|
88
45
|
}
|
|
@@ -68,7 +68,6 @@ import {
|
|
|
68
68
|
import { useMenuView } from "../composables/private/useMenuView";
|
|
69
69
|
import { useMenuState } from "../composables/private/useMenuState";
|
|
70
70
|
import { useMenuCallback } from "../composables/private/useMenuCallback";
|
|
71
|
-
import { useMenuDOM } from "../composables/private/useMenuDOM";
|
|
72
71
|
import { useMenuCursor } from "../composables/private/useMenuCursor";
|
|
73
72
|
import {
|
|
74
73
|
useMagicError
|
|
@@ -78,7 +77,8 @@ import { ModeDelayMouseleave } from "../utils/modeDelayDefaults";
|
|
|
78
77
|
import {
|
|
79
78
|
MagicMenuInstanceId,
|
|
80
79
|
MagicMenuViewId,
|
|
81
|
-
MagicMenuContentId
|
|
80
|
+
MagicMenuContentId,
|
|
81
|
+
MagicMenuParentTree
|
|
82
82
|
} from "../symbols";
|
|
83
83
|
import "@maas/vue-equipment/utils/css/keyframes/fade-in.css";
|
|
84
84
|
import "@maas/vue-equipment/utils/css/keyframes/fade-out.css";
|
|
@@ -95,6 +95,7 @@ const magicError = useMagicError({
|
|
|
95
95
|
prefix: "MagicMenu",
|
|
96
96
|
source: "MagicMenu"
|
|
97
97
|
});
|
|
98
|
+
const parentTree = inject(MagicMenuParentTree, []);
|
|
98
99
|
const instanceId = inject(MagicMenuInstanceId, void 0);
|
|
99
100
|
const viewId = inject(MagicMenuViewId, void 0);
|
|
100
101
|
magicError.assert(instanceId, {
|
|
@@ -124,12 +125,6 @@ const mappedTransition = computed(() => {
|
|
|
124
125
|
});
|
|
125
126
|
const innerActive = shallowRef(false);
|
|
126
127
|
const wrapperActive = shallowRef(false);
|
|
127
|
-
const {
|
|
128
|
-
lockScroll,
|
|
129
|
-
unlockScroll,
|
|
130
|
-
addScrollLockPadding,
|
|
131
|
-
removeScrollLockPadding
|
|
132
|
-
} = useMenuDOM();
|
|
133
128
|
const {
|
|
134
129
|
onBeforeEnter,
|
|
135
130
|
onEnter,
|
|
@@ -143,10 +138,7 @@ const {
|
|
|
143
138
|
viewId,
|
|
144
139
|
innerActive,
|
|
145
140
|
wrapperActive,
|
|
146
|
-
|
|
147
|
-
unlockScroll,
|
|
148
|
-
addScrollLockPadding,
|
|
149
|
-
removeScrollLockPadding
|
|
141
|
+
parentTree
|
|
150
142
|
});
|
|
151
143
|
async function onOpen() {
|
|
152
144
|
wrapperActive.value = true;
|
|
@@ -10,11 +10,11 @@ type __VLS_Slots = {} & {
|
|
|
10
10
|
default?: (props: typeof __VLS_1) => any;
|
|
11
11
|
};
|
|
12
12
|
declare const __VLS_base: import("vue").DefineComponent<MagicMenuItemProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
13
|
-
click: (event: MouseEvent) => any;
|
|
14
13
|
enter: () => any;
|
|
14
|
+
click: (event: MouseEvent) => any;
|
|
15
15
|
}, string, import("vue").PublicProps, Readonly<MagicMenuItemProps> & Readonly<{
|
|
16
|
-
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
17
16
|
onEnter?: (() => any) | undefined;
|
|
17
|
+
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
18
18
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
19
19
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
20
20
|
declare const _default: typeof __VLS_export;
|
|
@@ -10,11 +10,11 @@ type __VLS_Slots = {} & {
|
|
|
10
10
|
default?: (props: typeof __VLS_1) => any;
|
|
11
11
|
};
|
|
12
12
|
declare const __VLS_base: import("vue").DefineComponent<MagicMenuItemProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
13
|
-
click: (event: MouseEvent) => any;
|
|
14
13
|
enter: () => any;
|
|
14
|
+
click: (event: MouseEvent) => any;
|
|
15
15
|
}, string, import("vue").PublicProps, Readonly<MagicMenuItemProps> & Readonly<{
|
|
16
|
-
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
17
16
|
onEnter?: (() => any) | undefined;
|
|
17
|
+
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
18
18
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
19
19
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
20
20
|
declare const _default: typeof __VLS_export;
|
|
@@ -6,10 +6,7 @@ type UseMenuCallbackArgs = {
|
|
|
6
6
|
viewId: string;
|
|
7
7
|
innerActive: Ref<boolean>;
|
|
8
8
|
wrapperActive: Ref<boolean>;
|
|
9
|
-
|
|
10
|
-
unlockScroll: () => void;
|
|
11
|
-
addScrollLockPadding: () => void;
|
|
12
|
-
removeScrollLockPadding: () => void;
|
|
9
|
+
parentTree: string[];
|
|
13
10
|
};
|
|
14
11
|
export declare function useMenuCallback(args: UseMenuCallbackArgs): {
|
|
15
12
|
onBeforeEnter: () => void;
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { toValue } from "vue";
|
|
2
2
|
import { useMagicEmitter } from "@maas/vue-equipment/plugins/MagicEmitter";
|
|
3
|
+
import { useMenuDOM } from "./useMenuDOM.mjs";
|
|
3
4
|
import { ModeScrollLock } from "../../utils/modeScrollLockDefaults.mjs";
|
|
4
5
|
export function useMenuCallback(args) {
|
|
5
|
-
const {
|
|
6
|
-
state,
|
|
7
|
-
instanceId,
|
|
8
|
-
viewId,
|
|
9
|
-
innerActive,
|
|
10
|
-
wrapperActive,
|
|
11
|
-
lockScroll,
|
|
12
|
-
unlockScroll,
|
|
13
|
-
addScrollLockPadding,
|
|
14
|
-
removeScrollLockPadding
|
|
15
|
-
} = args;
|
|
6
|
+
const { state, instanceId, viewId, innerActive, wrapperActive, parentTree } = args;
|
|
16
7
|
const emitter = useMagicEmitter();
|
|
8
|
+
const { lockScroll, unlockScroll } = useMenuDOM();
|
|
17
9
|
function onBeforeEnter() {
|
|
18
10
|
emitter.emit("beforeEnter", { id: toValue(instanceId), viewId });
|
|
19
11
|
}
|
|
@@ -23,11 +15,8 @@ export function useMenuCallback(args) {
|
|
|
23
15
|
function onAfterEnter() {
|
|
24
16
|
emitter.emit("afterEnter", { id: toValue(instanceId), viewId });
|
|
25
17
|
const scrollLock = state.options.scrollLock ?? ModeScrollLock[state.options.mode].value;
|
|
26
|
-
if (scrollLock) {
|
|
27
|
-
|
|
28
|
-
addScrollLockPadding();
|
|
29
|
-
}
|
|
30
|
-
lockScroll();
|
|
18
|
+
if (scrollLock && parentTree.length === 2) {
|
|
19
|
+
lockScroll(typeof scrollLock === "object" && scrollLock.padding);
|
|
31
20
|
}
|
|
32
21
|
}
|
|
33
22
|
function onBeforeLeave() {
|
|
@@ -39,11 +28,8 @@ export function useMenuCallback(args) {
|
|
|
39
28
|
function onAfterLeave() {
|
|
40
29
|
emitter.emit("afterLeave", { id: toValue(instanceId), viewId });
|
|
41
30
|
const scrollLock = state.options.scrollLock ?? ModeScrollLock[state.options.mode].value;
|
|
42
|
-
if (scrollLock) {
|
|
43
|
-
unlockScroll();
|
|
44
|
-
if (typeof scrollLock === "object" && scrollLock.padding) {
|
|
45
|
-
removeScrollLockPadding();
|
|
46
|
-
}
|
|
31
|
+
if (scrollLock && parentTree.length === 2) {
|
|
32
|
+
unlockScroll(typeof scrollLock === "object" && scrollLock.padding);
|
|
47
33
|
}
|
|
48
34
|
if (!innerActive.value) {
|
|
49
35
|
wrapperActive.value = false;
|
|
@@ -1,63 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { shallowRef } from "vue";
|
|
2
2
|
import { useScrollLock } from "@vueuse/core";
|
|
3
|
-
import {
|
|
4
|
-
matchClass,
|
|
5
|
-
scrollbarGutterSupport,
|
|
6
|
-
scrollbarWidth
|
|
7
|
-
} from "@maas/vue-equipment/utils";
|
|
3
|
+
import { useScrollLockPadding } from "@maas/vue-equipment/composables/useScrollLockPadding";
|
|
8
4
|
const scrollLock = typeof window !== "undefined" ? useScrollLock(document?.documentElement) : shallowRef(false);
|
|
5
|
+
const { add, remove } = useScrollLockPadding({
|
|
6
|
+
exclude: /magic-menu/
|
|
7
|
+
});
|
|
9
8
|
export function useMenuDOM() {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
function lockScroll(padding) {
|
|
10
|
+
if (padding) {
|
|
11
|
+
add();
|
|
12
|
+
}
|
|
12
13
|
scrollLock.value = true;
|
|
13
14
|
}
|
|
14
|
-
function unlockScroll() {
|
|
15
|
+
function unlockScroll(padding) {
|
|
15
16
|
scrollLock.value = false;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (typeof window === "undefined") {
|
|
19
|
-
return;
|
|
17
|
+
if (padding) {
|
|
18
|
+
remove();
|
|
20
19
|
}
|
|
21
|
-
const exclude = new RegExp(/magic-menu/);
|
|
22
|
-
document.body.style.setProperty(
|
|
23
|
-
"--scrollbar-width",
|
|
24
|
-
`${scrollbarWidth()}px`
|
|
25
|
-
);
|
|
26
|
-
positionFixedElements.value = [
|
|
27
|
-
...document.body.getElementsByTagName("*")
|
|
28
|
-
].filter(
|
|
29
|
-
(x) => getComputedStyle(x, null).getPropertyValue("position") === "fixed" && getComputedStyle(x, null).getPropertyValue("right") === "0px" && !matchClass(x, exclude)
|
|
30
|
-
);
|
|
31
|
-
switch (scrollbarGutterSupport()) {
|
|
32
|
-
case true:
|
|
33
|
-
document.documentElement.style.scrollbarGutter = "stable";
|
|
34
|
-
positionFixedElements.value.forEach((elem) => {
|
|
35
|
-
elem.style.scrollbarGutter = "stable";
|
|
36
|
-
elem.style.overflow = "auto";
|
|
37
|
-
});
|
|
38
|
-
break;
|
|
39
|
-
case false:
|
|
40
|
-
document.body.style.paddingRight = "var(--scrollbar-width)";
|
|
41
|
-
positionFixedElements.value.forEach(
|
|
42
|
-
(elem) => elem.style.paddingRight = "var(--scrollbar-width)"
|
|
43
|
-
);
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function removeScrollLockPadding() {
|
|
48
|
-
document.documentElement.style.scrollbarGutter = "";
|
|
49
|
-
document.body.style.removeProperty("--scrollbar-width");
|
|
50
|
-
document.body.style.paddingRight = "";
|
|
51
|
-
positionFixedElements.value.forEach((elem) => {
|
|
52
|
-
elem.style.paddingRight = "";
|
|
53
|
-
elem.style.scrollbarGutter = "";
|
|
54
|
-
elem.style.overflow = "";
|
|
55
|
-
});
|
|
56
20
|
}
|
|
57
21
|
return {
|
|
58
22
|
lockScroll,
|
|
59
|
-
unlockScroll
|
|
60
|
-
addScrollLockPadding,
|
|
61
|
-
removeScrollLockPadding
|
|
23
|
+
unlockScroll
|
|
62
24
|
};
|
|
63
25
|
}
|
|
@@ -81,14 +81,7 @@ const { id, options = {} } = defineProps({
|
|
|
81
81
|
const mappedOptions = customDefu(options, defaultOptions);
|
|
82
82
|
const mappedId = toValue(id);
|
|
83
83
|
const modalRef = useTemplateRef("modal");
|
|
84
|
-
const {
|
|
85
|
-
trapFocus,
|
|
86
|
-
releaseFocus,
|
|
87
|
-
lockScroll,
|
|
88
|
-
unlockScroll,
|
|
89
|
-
addScrollLockPadding,
|
|
90
|
-
removeScrollLockPadding
|
|
91
|
-
} = useModalDOM({
|
|
84
|
+
const { trapFocus, releaseFocus, unlockScroll } = useModalDOM({
|
|
92
85
|
focusTarget: modalRef,
|
|
93
86
|
focusTrap: mappedOptions.focusTrap
|
|
94
87
|
});
|
|
@@ -105,10 +98,6 @@ const {
|
|
|
105
98
|
} = useModalCallback({
|
|
106
99
|
id,
|
|
107
100
|
mappedOptions,
|
|
108
|
-
addScrollLockPadding,
|
|
109
|
-
removeScrollLockPadding,
|
|
110
|
-
lockScroll,
|
|
111
|
-
unlockScroll,
|
|
112
101
|
trapFocus,
|
|
113
102
|
releaseFocus,
|
|
114
103
|
wrapperActive
|
|
@@ -139,10 +128,9 @@ onBeforeUnmount(() => {
|
|
|
139
128
|
});
|
|
140
129
|
onUnmounted(() => {
|
|
141
130
|
if (mappedOptions.scrollLock) {
|
|
142
|
-
unlockScroll(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
131
|
+
unlockScroll(
|
|
132
|
+
typeof mappedOptions.scrollLock === "object" && mappedOptions.scrollLock.padding
|
|
133
|
+
);
|
|
146
134
|
}
|
|
147
135
|
if (mappedOptions.focusTrap) {
|
|
148
136
|
releaseFocus();
|
|
@@ -3,10 +3,6 @@ import type { MagicModalOptions } from '../../types/index.js';
|
|
|
3
3
|
type UseModalCallbackArgs = {
|
|
4
4
|
id: MaybeRef<string>;
|
|
5
5
|
mappedOptions: MagicModalOptions;
|
|
6
|
-
addScrollLockPadding: () => void;
|
|
7
|
-
removeScrollLockPadding: () => void;
|
|
8
|
-
lockScroll: () => void;
|
|
9
|
-
unlockScroll: () => void;
|
|
10
6
|
trapFocus: () => void;
|
|
11
7
|
releaseFocus: () => void;
|
|
12
8
|
wrapperActive: Ref<boolean>;
|
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
import { toValue, nextTick } from "vue";
|
|
2
2
|
import { useMagicEmitter } from "@maas/vue-equipment/plugins/MagicEmitter";
|
|
3
|
+
import { useModalDOM } from "./useModalDOM.mjs";
|
|
3
4
|
export function useModalCallback(args) {
|
|
4
|
-
const {
|
|
5
|
-
id,
|
|
6
|
-
mappedOptions,
|
|
7
|
-
addScrollLockPadding,
|
|
8
|
-
removeScrollLockPadding,
|
|
9
|
-
lockScroll,
|
|
10
|
-
unlockScroll,
|
|
11
|
-
trapFocus,
|
|
12
|
-
releaseFocus,
|
|
13
|
-
wrapperActive
|
|
14
|
-
} = args;
|
|
5
|
+
const { id, mappedOptions, trapFocus, releaseFocus, wrapperActive } = args;
|
|
15
6
|
const emitter = useMagicEmitter();
|
|
7
|
+
const { lockScroll, unlockScroll } = useModalDOM();
|
|
16
8
|
function onBeforeEnter() {
|
|
17
9
|
emitter.emit("beforeEnter", toValue(id));
|
|
18
10
|
if (mappedOptions.scrollLock) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
lockScroll();
|
|
11
|
+
lockScroll(
|
|
12
|
+
typeof mappedOptions.scrollLock === "object" && mappedOptions.scrollLock.padding
|
|
13
|
+
);
|
|
23
14
|
}
|
|
24
15
|
}
|
|
25
16
|
function onEnter() {
|
|
@@ -41,10 +32,9 @@ export function useModalCallback(args) {
|
|
|
41
32
|
function onAfterLeave() {
|
|
42
33
|
emitter.emit("afterLeave", toValue(id));
|
|
43
34
|
if (mappedOptions.scrollLock) {
|
|
44
|
-
unlockScroll(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
35
|
+
unlockScroll(
|
|
36
|
+
typeof mappedOptions.scrollLock === "object" && mappedOptions.scrollLock.padding
|
|
37
|
+
);
|
|
48
38
|
}
|
|
49
39
|
if (mappedOptions.focusTrap) {
|
|
50
40
|
releaseFocus();
|
|
@@ -6,8 +6,6 @@ export type useModalDOMArgs = Pick<MagicModalOptions, 'scrollLock' | 'focusTrap'
|
|
|
6
6
|
export declare function useModalDOM(args?: useModalDOMArgs): {
|
|
7
7
|
trapFocus: () => void;
|
|
8
8
|
releaseFocus: () => void;
|
|
9
|
-
lockScroll: () => void;
|
|
10
|
-
unlockScroll: () => void;
|
|
11
|
-
addScrollLockPadding: () => void;
|
|
12
|
-
removeScrollLockPadding: () => void;
|
|
9
|
+
lockScroll: (padding?: boolean) => void;
|
|
10
|
+
unlockScroll: (padding?: boolean) => void;
|
|
13
11
|
};
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { shallowRef } from "vue";
|
|
2
2
|
import { defu } from "defu";
|
|
3
3
|
import { useScrollLock } from "@vueuse/core";
|
|
4
4
|
import { useFocusTrap } from "@vueuse/integrations/useFocusTrap";
|
|
5
|
-
import {
|
|
6
|
-
matchClass,
|
|
7
|
-
scrollbarGutterSupport,
|
|
8
|
-
scrollbarWidth
|
|
9
|
-
} from "@maas/vue-equipment/utils";
|
|
5
|
+
import { useScrollLockPadding } from "@maas/vue-equipment/composables/useScrollLockPadding";
|
|
10
6
|
const defaultOptions = {
|
|
11
7
|
focusTrap: false,
|
|
12
|
-
focusTarget: void 0
|
|
13
|
-
scrollLock: true
|
|
8
|
+
focusTarget: void 0
|
|
14
9
|
};
|
|
15
10
|
const scrollLock = typeof window !== "undefined" ? useScrollLock(document?.documentElement) : shallowRef(false);
|
|
11
|
+
const { add, remove } = useScrollLockPadding({
|
|
12
|
+
exclude: /magic-modal(__backdrop)?/
|
|
13
|
+
});
|
|
16
14
|
export function useModalDOM(args) {
|
|
17
|
-
const positionFixedElements = ref([]);
|
|
18
15
|
const mappedOptions = defu(args, defaultOptions);
|
|
19
16
|
const focusTrap = mappedOptions.focusTarget ? typeof mappedOptions.focusTrap === "boolean" ? useFocusTrap(mappedOptions.focusTarget) : useFocusTrap(mappedOptions.focusTarget, mappedOptions.focusTrap) : void 0;
|
|
20
17
|
function trapFocus() {
|
|
@@ -27,62 +24,22 @@ export function useModalDOM(args) {
|
|
|
27
24
|
focusTrap.deactivate();
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
|
-
function lockScroll() {
|
|
31
|
-
if (
|
|
32
|
-
|
|
27
|
+
function lockScroll(padding) {
|
|
28
|
+
if (padding) {
|
|
29
|
+
add();
|
|
33
30
|
}
|
|
31
|
+
scrollLock.value = true;
|
|
34
32
|
}
|
|
35
|
-
function unlockScroll() {
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
function unlockScroll(padding) {
|
|
34
|
+
scrollLock.value = false;
|
|
35
|
+
if (padding) {
|
|
36
|
+
remove();
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
|
-
function addScrollLockPadding() {
|
|
41
|
-
if (typeof window === "undefined") {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const exclude = new RegExp(/magic-modal(__backdrop)?/);
|
|
45
|
-
document.body.style.setProperty(
|
|
46
|
-
"--scrollbar-width",
|
|
47
|
-
`${scrollbarWidth()}px`
|
|
48
|
-
);
|
|
49
|
-
positionFixedElements.value = [
|
|
50
|
-
...document.body.getElementsByTagName("*")
|
|
51
|
-
].filter(
|
|
52
|
-
(x) => getComputedStyle(x, null).getPropertyValue("position") === "fixed" && getComputedStyle(x, null).getPropertyValue("right") === "0px" && !matchClass(x, exclude)
|
|
53
|
-
);
|
|
54
|
-
switch (scrollbarGutterSupport()) {
|
|
55
|
-
case true:
|
|
56
|
-
document.documentElement.style.scrollbarGutter = "stable";
|
|
57
|
-
positionFixedElements.value.forEach((elem) => {
|
|
58
|
-
elem.style.scrollbarGutter = "stable";
|
|
59
|
-
elem.style.overflow = "auto";
|
|
60
|
-
});
|
|
61
|
-
break;
|
|
62
|
-
case false:
|
|
63
|
-
document.body.style.paddingRight = "var(--scrollbar-width)";
|
|
64
|
-
positionFixedElements.value.forEach(
|
|
65
|
-
(elem) => elem.style.paddingRight = "var(--scrollbar-width)"
|
|
66
|
-
);
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function removeScrollLockPadding() {
|
|
71
|
-
document.documentElement.style.scrollbarGutter = "";
|
|
72
|
-
document.body.style.removeProperty("--scrollbar-width");
|
|
73
|
-
document.body.style.paddingRight = "";
|
|
74
|
-
positionFixedElements.value.forEach((elem) => {
|
|
75
|
-
elem.style.paddingRight = "";
|
|
76
|
-
elem.style.scrollbarGutter = "";
|
|
77
|
-
elem.style.overflow = "";
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
39
|
return {
|
|
81
40
|
trapFocus,
|
|
82
41
|
releaseFocus,
|
|
83
42
|
lockScroll,
|
|
84
|
-
unlockScroll
|
|
85
|
-
addScrollLockPadding,
|
|
86
|
-
removeScrollLockPadding
|
|
43
|
+
unlockScroll
|
|
87
44
|
};
|
|
88
45
|
}
|
|
@@ -51,12 +51,7 @@ export function useToastDrag(args) {
|
|
|
51
51
|
() => `transform: translate(${draggedX.value}px, ${draggedY.value}px)`
|
|
52
52
|
);
|
|
53
53
|
const emitter = useMagicEmitter();
|
|
54
|
-
const {
|
|
55
|
-
lockScroll,
|
|
56
|
-
unlockScroll,
|
|
57
|
-
addScrollLockPadding,
|
|
58
|
-
removeScrollLockPadding
|
|
59
|
-
} = useToastScrollLock();
|
|
54
|
+
const { lockScroll, unlockScroll } = useToastScrollLock();
|
|
60
55
|
function interpolateDragged(args2) {
|
|
61
56
|
const {
|
|
62
57
|
to,
|
|
@@ -228,10 +223,9 @@ export function useToastDrag(args) {
|
|
|
228
223
|
resetStateAndListeners();
|
|
229
224
|
const scrollLockValue = toValue(scrollLock);
|
|
230
225
|
if (scrollLockValue) {
|
|
231
|
-
unlockScroll(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
226
|
+
unlockScroll(
|
|
227
|
+
typeof scrollLockValue === "object" && scrollLockValue.padding
|
|
228
|
+
);
|
|
235
229
|
}
|
|
236
230
|
if (hasDragged.value) {
|
|
237
231
|
e.preventDefault();
|
|
@@ -257,10 +251,7 @@ export function useToastDrag(args) {
|
|
|
257
251
|
function onPointerdown(e) {
|
|
258
252
|
const scrollLockValue = toValue(scrollLock);
|
|
259
253
|
if (scrollLockValue) {
|
|
260
|
-
|
|
261
|
-
addScrollLockPadding();
|
|
262
|
-
}
|
|
263
|
-
lockScroll();
|
|
254
|
+
lockScroll(typeof scrollLockValue === "object" && scrollLockValue.padding);
|
|
264
255
|
}
|
|
265
256
|
if (dragging.value) {
|
|
266
257
|
return;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export declare function useToastScrollLock(): {
|
|
2
|
-
lockScroll: () => void;
|
|
3
|
-
unlockScroll: () => void;
|
|
4
|
-
addScrollLockPadding: () => void;
|
|
5
|
-
removeScrollLockPadding: () => void;
|
|
2
|
+
lockScroll: (padding?: boolean) => void;
|
|
3
|
+
unlockScroll: (padding?: boolean) => void;
|
|
6
4
|
};
|
|
@@ -1,61 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { shallowRef } from "vue";
|
|
2
2
|
import { useScrollLock } from "@vueuse/core";
|
|
3
|
-
import {
|
|
4
|
-
scrollbarGutterSupport,
|
|
5
|
-
scrollbarWidth
|
|
6
|
-
} from "@maas/vue-equipment/utils";
|
|
3
|
+
import { useScrollLockPadding } from "@maas/vue-equipment/composables/useScrollLockPadding";
|
|
7
4
|
const scrollLock = typeof window !== "undefined" ? useScrollLock(document?.documentElement) : shallowRef(false);
|
|
5
|
+
const { add, remove } = useScrollLockPadding();
|
|
8
6
|
export function useToastScrollLock() {
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
function lockScroll(padding) {
|
|
8
|
+
if (padding) {
|
|
9
|
+
add();
|
|
10
|
+
}
|
|
11
11
|
scrollLock.value = true;
|
|
12
12
|
}
|
|
13
|
-
function unlockScroll() {
|
|
13
|
+
function unlockScroll(padding) {
|
|
14
14
|
scrollLock.value = false;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (typeof window === "undefined") {
|
|
18
|
-
return;
|
|
15
|
+
if (padding) {
|
|
16
|
+
remove();
|
|
19
17
|
}
|
|
20
|
-
document.body.style.setProperty(
|
|
21
|
-
"--scrollbar-width",
|
|
22
|
-
`${scrollbarWidth()}px`
|
|
23
|
-
);
|
|
24
|
-
positionFixedElements.value = [
|
|
25
|
-
...document.body.getElementsByTagName("*")
|
|
26
|
-
].filter(
|
|
27
|
-
(x) => getComputedStyle(x, null).getPropertyValue("position") === "fixed" && getComputedStyle(x, null).getPropertyValue("right") === "0px"
|
|
28
|
-
);
|
|
29
|
-
switch (scrollbarGutterSupport()) {
|
|
30
|
-
case true:
|
|
31
|
-
document.documentElement.style.scrollbarGutter = "stable";
|
|
32
|
-
positionFixedElements.value.forEach((elem) => {
|
|
33
|
-
elem.style.scrollbarGutter = "stable";
|
|
34
|
-
elem.style.overflow = "auto";
|
|
35
|
-
});
|
|
36
|
-
break;
|
|
37
|
-
case false:
|
|
38
|
-
document.body.style.paddingRight = "var(--scrollbar-width)";
|
|
39
|
-
positionFixedElements.value.forEach(
|
|
40
|
-
(elem) => elem.style.paddingRight = "var(--scrollbar-width)"
|
|
41
|
-
);
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function removeScrollLockPadding() {
|
|
46
|
-
document.documentElement.style.scrollbarGutter = "";
|
|
47
|
-
document.body.style.removeProperty("--scrollbar-width");
|
|
48
|
-
document.body.style.paddingRight = "";
|
|
49
|
-
positionFixedElements.value.forEach((elem) => {
|
|
50
|
-
elem.style.paddingRight = "";
|
|
51
|
-
elem.style.scrollbarGutter = "";
|
|
52
|
-
elem.style.overflow = "";
|
|
53
|
-
});
|
|
54
18
|
}
|
|
55
19
|
return {
|
|
56
20
|
lockScroll,
|
|
57
|
-
unlockScroll
|
|
58
|
-
addScrollLockPadding,
|
|
59
|
-
removeScrollLockPadding
|
|
21
|
+
unlockScroll
|
|
60
22
|
};
|
|
61
23
|
}
|