@maas/vue-equipment 1.0.0-beta.41 → 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.
Files changed (48) hide show
  1. package/dist/composables/useScrollLockPadding/index.d.ts +9 -0
  2. package/dist/composables/useScrollLockPadding/index.js +56 -0
  3. package/dist/composables/useScrollLockPadding/index.js.map +1 -0
  4. package/dist/nuxt/module.json +1 -1
  5. package/dist/nuxt/module.mjs +9 -2
  6. package/dist/plugins/MagicAccordion/src/components/MagicAccordionContent.vue +3 -3
  7. package/dist/plugins/MagicAccordion/src/components/MagicAccordionProvider.vue +7 -3
  8. package/dist/plugins/MagicAccordion/src/components/MagicAccordionTrigger.vue +3 -3
  9. package/dist/plugins/MagicAccordion/src/components/MagicAccordionView.vue +3 -3
  10. package/dist/plugins/MagicAccordion/src/composables/private/useAccordionTrigger.d.ts +2 -2
  11. package/dist/plugins/MagicAccordion/src/composables/private/useAccordionTrigger.mjs +1 -1
  12. package/dist/plugins/MagicCommand/src/components/MagicCommandItem.d.vue.ts +2 -2
  13. package/dist/plugins/MagicCommand/src/components/MagicCommandItem.vue.d.ts +2 -2
  14. package/dist/plugins/MagicCommand/src/components/MagicCommandProvider.vue +7 -3
  15. package/dist/plugins/MagicCommand/src/components/MagicCommandTrigger.vue +3 -3
  16. package/dist/plugins/MagicCommand/src/components/MagicCommandView.vue +1 -1
  17. package/dist/plugins/MagicCommand/src/composables/private/useCommandTrigger.d.ts +2 -2
  18. package/dist/plugins/MagicCommand/src/composables/private/useCommandTrigger.mjs +1 -1
  19. package/dist/plugins/MagicDraggable/src/composables/private/useDraggableDrag.mjs +5 -14
  20. package/dist/plugins/MagicDraggable/src/composables/private/useDraggableScrollLock.d.ts +2 -4
  21. package/dist/plugins/MagicDraggable/src/composables/private/useDraggableScrollLock.mjs +11 -51
  22. package/dist/plugins/MagicDrawer/src/components/MagicDrawer.vue +4 -16
  23. package/dist/plugins/MagicDrawer/src/composables/private/useDrawerCallback.d.ts +0 -4
  24. package/dist/plugins/MagicDrawer/src/composables/private/useDrawerCallback.mjs +8 -12
  25. package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDOM.d.ts +2 -4
  26. package/dist/plugins/MagicDrawer/src/composables/private/useDrawerDOM.mjs +15 -58
  27. package/dist/plugins/MagicEmitter/src/composables/useMagicEmitter.d.ts +36 -36
  28. package/dist/plugins/MagicMenu/src/components/MagicMenuContent.vue +4 -12
  29. package/dist/plugins/MagicMenu/src/components/MagicMenuItem.d.vue.ts +2 -2
  30. package/dist/plugins/MagicMenu/src/components/MagicMenuItem.vue.d.ts +2 -2
  31. package/dist/plugins/MagicMenu/src/components/MagicMenuProvider.vue +3 -3
  32. package/dist/plugins/MagicMenu/src/components/MagicMenuRemote.vue +3 -3
  33. package/dist/plugins/MagicMenu/src/components/MagicMenuTrigger.vue +3 -3
  34. package/dist/plugins/MagicMenu/src/composables/private/useMenuCallback.d.ts +1 -4
  35. package/dist/plugins/MagicMenu/src/composables/private/useMenuCallback.mjs +7 -21
  36. package/dist/plugins/MagicMenu/src/composables/private/useMenuDOM.d.ts +2 -4
  37. package/dist/plugins/MagicMenu/src/composables/private/useMenuDOM.mjs +13 -51
  38. package/dist/plugins/MagicMenu/src/composables/private/useMenuTrigger.d.ts +2 -2
  39. package/dist/plugins/MagicMenu/src/composables/private/useMenuTrigger.mjs +1 -1
  40. package/dist/plugins/MagicModal/src/components/MagicModal.vue +4 -16
  41. package/dist/plugins/MagicModal/src/composables/private/useModalCallback.d.ts +0 -4
  42. package/dist/plugins/MagicModal/src/composables/private/useModalCallback.mjs +9 -19
  43. package/dist/plugins/MagicModal/src/composables/private/useModalDOM.d.ts +2 -4
  44. package/dist/plugins/MagicModal/src/composables/private/useModalDOM.mjs +15 -58
  45. package/dist/plugins/MagicToast/src/composables/private/useToastDrag.mjs +5 -14
  46. package/dist/plugins/MagicToast/src/composables/private/useToastScrollLock.d.ts +2 -4
  47. package/dist/plugins/MagicToast/src/composables/private/useToastScrollLock.mjs +11 -49
  48. package/package.json +2 -2
@@ -0,0 +1,9 @@
1
+ type UseScrollLockPaddingArgs = {
2
+ exclude: RegExp;
3
+ };
4
+ declare function useScrollLockPadding(args?: UseScrollLockPaddingArgs): {
5
+ add: () => void;
6
+ remove: () => void;
7
+ };
8
+
9
+ export { type UseScrollLockPaddingArgs, useScrollLockPadding };
@@ -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":[]}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maas/vue-equipment/nuxt",
3
3
  "configKey": "vueEquipment",
4
- "version": "1.0.0-beta.40",
4
+ "version": "1.0.0-beta.42",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
@@ -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",
@@ -141,7 +148,7 @@ functions.map((f) => f.name);
141
148
  const plugins = functions.filter((p) => p.package === "plugins");
142
149
  const composables = functions.filter((p) => p.package === "composables");
143
150
 
144
- const module = defineNuxtModule({
151
+ const module$1 = defineNuxtModule({
145
152
  meta: {
146
153
  name: "@maas/vue-equipment/nuxt",
147
154
  configKey: "vueEquipment"
@@ -194,4 +201,4 @@ const module = defineNuxtModule({
194
201
  }
195
202
  });
196
203
 
197
- export { module as default };
204
+ export { module$1 as default };
@@ -19,9 +19,9 @@
19
19
  @leave="onLeave"
20
20
  @after-leave="onAfterLeave"
21
21
  >
22
- <primitive v-show="view?.active" :as-child="asChild">
22
+ <vue-primitive v-show="view?.active" :as-child="asChild">
23
23
  <slot :view-active="view?.active" />
24
- </primitive>
24
+ </vue-primitive>
25
25
  </transition>
26
26
  </auto-size>
27
27
  </div>
@@ -31,7 +31,7 @@
31
31
  import { inject, computed } from "vue";
32
32
  import { defu } from "defu";
33
33
  import { AutoSize } from "@maas/vue-autosize";
34
- import { Primitive } from "@maas/vue-primitive";
34
+ import { VuePrimitive } from "@maas/vue-primitive";
35
35
  import {
36
36
  useMagicError
37
37
  } from "@maas/vue-equipment/plugins/MagicError";
@@ -1,12 +1,16 @@
1
1
  <template>
2
- <primitive :data-id="id" :as-child="asChild" class="magic-accordion-provider">
2
+ <vue-primitive
3
+ :data-id="id"
4
+ :as-child="asChild"
5
+ class="magic-accordion-provider"
6
+ >
3
7
  <slot />
4
- </primitive>
8
+ </vue-primitive>
5
9
  </template>
6
10
 
7
11
  <script setup>
8
12
  import { onBeforeUnmount, provide } from "vue";
9
- import { Primitive } from "@maas/vue-primitive";
13
+ import { VuePrimitive } from "@maas/vue-primitive";
10
14
  import { useAccordionState } from "../composables/private/useAccordionState";
11
15
  import { MagicAccordionInstanceId } from "../symbols";
12
16
  const { id, asChild, options } = defineProps({
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <primitive
2
+ <vue-primitive
3
3
  ref="el"
4
4
  :as-child="asChild"
5
5
  :data-id="`${mappedViewId}-trigger`"
@@ -10,12 +10,12 @@
10
10
  @click="onClick"
11
11
  >
12
12
  <slot :view-active="view?.active" />
13
- </primitive>
13
+ </vue-primitive>
14
14
  </template>
15
15
 
16
16
  <script setup>
17
17
  import { useTemplateRef, inject, computed, toValue } from "vue";
18
- import { Primitive } from "@maas/vue-primitive";
18
+ import { VuePrimitive } from "@maas/vue-primitive";
19
19
  import { onKeyStroke } from "@vueuse/core";
20
20
  import {
21
21
  useMagicError
@@ -1,17 +1,17 @@
1
1
  <template>
2
- <primitive
2
+ <vue-primitive
3
3
  :as-child="asChild"
4
4
  :data-id="mappedId"
5
5
  :data-active="mappedActive"
6
6
  class="magic-accordion-view"
7
7
  >
8
8
  <slot :view-active="mappedActive" />
9
- </primitive>
9
+ </vue-primitive>
10
10
  </template>
11
11
 
12
12
  <script setup>
13
13
  import { computed, inject, onBeforeUnmount, provide, useId } from "vue";
14
- import { Primitive } from "@maas/vue-primitive";
14
+ import { VuePrimitive } from "@maas/vue-primitive";
15
15
  import {
16
16
  useMagicError
17
17
  } from "@maas/vue-equipment/plugins/MagicError";
@@ -1,12 +1,12 @@
1
1
  import { type ComputedRef, type MaybeRef, type Ref } from 'vue';
2
- import { Primitive } from '@maas/vue-primitive';
2
+ import { VuePrimitive } from '@maas/vue-primitive';
3
3
  import type { Interaction } from '../../types/index.js';
4
4
  interface UseAccordionTriggerArgs {
5
5
  instanceId: MaybeRef<string>;
6
6
  viewId: string;
7
7
  trigger: Interaction;
8
8
  mappedDisabled: ComputedRef<boolean>;
9
- elRef: Ref<InstanceType<typeof Primitive> | null>;
9
+ elRef: Ref<InstanceType<typeof VuePrimitive> | null>;
10
10
  }
11
11
  export declare function useAccordionTrigger(args: UseAccordionTriggerArgs): {
12
12
  onMouseenter: () => void;
@@ -1,5 +1,5 @@
1
1
  import {} from "vue";
2
- import { Primitive } from "@maas/vue-primitive";
2
+ import { VuePrimitive } from "@maas/vue-primitive";
3
3
  import { useFocus } from "@vueuse/core";
4
4
  import { useAccordionView } from "./useAccordionView.mjs";
5
5
  export function useAccordionTrigger(args) {
@@ -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;
@@ -1,13 +1,17 @@
1
1
  <template>
2
- <primitive :data-id="id" :as-child="asChild" class="magic-command-provider">
2
+ <vue-primitive
3
+ :data-id="id"
4
+ :as-child="asChild"
5
+ class="magic-command-provider"
6
+ >
3
7
  <slot />
4
- </primitive>
8
+ </vue-primitive>
5
9
  </template>
6
10
 
7
11
  <script setup>
8
12
  import { shallowRef, provide, watch, onBeforeUnmount } from "vue";
9
13
  import { useMagicKeys, usePointer } from "@vueuse/core";
10
- import { Primitive } from "@maas/vue-primitive";
14
+ import { VuePrimitive } from "@maas/vue-primitive";
11
15
  import { useMagicError } from "@maas/vue-equipment/plugins/MagicError";
12
16
  import { createDefu } from "defu";
13
17
  import { useCommandState } from "../composables/private/useCommandState";
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <primitive
2
+ <vue-primitive
3
3
  ref="el"
4
4
  :data-id="`${mappedViewId}-trigger`"
5
5
  :data-active="mappedActive"
@@ -10,12 +10,12 @@
10
10
  @mouseenter="onMouseenter"
11
11
  >
12
12
  <slot :view-active="view?.active" :trigger-disabled="mappedDisabled" />
13
- </primitive>
13
+ </vue-primitive>
14
14
  </template>
15
15
 
16
16
  <script setup>
17
17
  import { computed, inject, useTemplateRef, toValue, watch } from "vue";
18
- import { Primitive } from "@maas/vue-primitive";
18
+ import { VuePrimitive } from "@maas/vue-primitive";
19
19
  import {
20
20
  useMagicError
21
21
  } from "@maas/vue-equipment/plugins/MagicError";
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div :data-id="mappedId" class="magic-menu-view">
2
+ <div :data-id="mappedId" class="magic-command-view">
3
3
  <slot :view-active="view.active" />
4
4
  </div>
5
5
  </template>
@@ -1,5 +1,5 @@
1
1
  import { type ComputedRef, type MaybeRef, type Ref } from 'vue';
2
- import { Primitive } from '@maas/vue-primitive';
2
+ import { VuePrimitive } from '@maas/vue-primitive';
3
3
  import type { Action, Interaction } from '../../types/index.js';
4
4
  type UseCommandTriggerArgs = {
5
5
  instanceId: MaybeRef<string>;
@@ -8,7 +8,7 @@ type UseCommandTriggerArgs = {
8
8
  mappedActive?: ComputedRef<boolean>;
9
9
  trigger: Interaction[];
10
10
  action: Action;
11
- elRef: Ref<InstanceType<typeof Primitive> | null>;
11
+ elRef: Ref<InstanceType<typeof VuePrimitive> | null>;
12
12
  };
13
13
  export declare function useCommandTrigger(args: UseCommandTriggerArgs): {
14
14
  onMouseenter: () => Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import { nextTick } from "vue";
2
- import { Primitive } from "@maas/vue-primitive";
2
+ import { VuePrimitive } from "@maas/vue-primitive";
3
3
  import { useFocus } from "@vueuse/core";
4
4
  import { useCommandView } from "./useCommandView.mjs";
5
5
  import { useCommandState } from "./useCommandState.mjs";
@@ -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
- if (typeof scrollLockValue === "object" && scrollLockValue.padding) {
288
- removeScrollLockPadding();
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
- if (typeof scrollLockValue === "object" && scrollLockValue.padding) {
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, ref } from "vue";
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
- const positionFixedElements = ref([]);
11
- function lockScroll() {
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
- function addScrollLockPadding() {
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
- if (typeof mappedOptions.scrollLock === "object" && mappedOptions.scrollLock.padding) {
288
- removeScrollLockPadding();
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
- if (typeof mappedOptions.scrollLock === "object" && mappedOptions.scrollLock.padding) {
23
- addScrollLockPadding();
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
- if (typeof mappedOptions.scrollLock === "object" && mappedOptions.scrollLock.padding) {
53
- removeScrollLockPadding();
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
  };