@empathyco/x-components 10.6.0 → 10.8.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/CHANGELOG.md +27 -0
- package/docs/API-reference/api/x-components.basemodal.md +9 -0
- package/docs/API-reference/components/common/modals/x-components.base-modal.md +22 -9
- package/js/components/base-teleport.vue.js.map +1 -1
- package/js/components/base-teleport.vue2.js +1 -0
- package/js/components/base-teleport.vue2.js.map +1 -1
- package/js/components/modals/base-modal.vue.js.map +1 -1
- package/js/components/modals/base-modal.vue2.js +24 -0
- package/js/components/modals/base-modal.vue2.js.map +1 -1
- package/package.json +7 -7
- package/report/x-components.api.json +22 -4
- package/report/x-components.api.md +9 -0
- package/types/src/components/base-teleport.vue.d.ts.map +1 -1
- package/types/src/components/modals/base-modal.vue.d.ts +19 -0
- package/types/src/components/modals/base-modal.vue.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.8.0](https://github.com/empathyco/x/compare/@empathyco/x-components@10.3.0...@empathyco/x-components@10.8.0) (2026-11-12)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **base-modal:** add scrollLock prop to control page scroll behavior (#2200)
|
|
11
|
+
* **search:** add priceFacetId to SearchConfig and update request accordingly (#2194)
|
|
12
|
+
* **x-components:** add responsive image props and loading events to BaseResultImage (#2195)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* change CSS selector for only child teleport (#2197)
|
|
17
|
+
* remove parent selector when BaseTeleport is unmounted (#2198)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## [10.7.0](https://github.com/empathyco/x/compare/@empathyco/x-components@10.3.0...@empathyco/x-components@10.7.0) (2026-11-10)
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* **search:** add priceFacetId to SearchConfig and update request accordingly (#2194)
|
|
25
|
+
* **x-components:** add responsive image props and loading events to BaseResultImage (#2195)
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
* change CSS selector for only child teleport (#2197)
|
|
30
|
+
* remove parent selector when BaseTeleport is unmounted (#2198)
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
## [10.6.0](https://github.com/empathyco/x/compare/@empathyco/x-components@10.3.0...@empathyco/x-components@10.6.0) (2026-11-09)
|
|
7
34
|
|
|
8
35
|
### Features
|
|
@@ -27,6 +27,10 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
27
27
|
type: (StringConstructor | ObjectConstructor | FunctionConstructor)[];
|
|
28
28
|
default: () => import("vue").DefineComponent<{}, {}, any>;
|
|
29
29
|
};
|
|
30
|
+
scrollLock: {
|
|
31
|
+
type: BooleanConstructor;
|
|
32
|
+
default: boolean;
|
|
33
|
+
};
|
|
30
34
|
contentClass: StringConstructor;
|
|
31
35
|
overlayClass: StringConstructor;
|
|
32
36
|
}>, {
|
|
@@ -55,6 +59,10 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
55
59
|
type: (StringConstructor | ObjectConstructor | FunctionConstructor)[];
|
|
56
60
|
default: () => import("vue").DefineComponent<{}, {}, any>;
|
|
57
61
|
};
|
|
62
|
+
scrollLock: {
|
|
63
|
+
type: BooleanConstructor;
|
|
64
|
+
default: boolean;
|
|
65
|
+
};
|
|
58
66
|
contentClass: StringConstructor;
|
|
59
67
|
overlayClass: StringConstructor;
|
|
60
68
|
}>> & Readonly<{
|
|
@@ -64,5 +72,6 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
64
72
|
focusOnOpen: boolean;
|
|
65
73
|
animation: string | Function | Record<string, any>;
|
|
66
74
|
overlayAnimation: string | Function | Record<string, any>;
|
|
75
|
+
scrollLock: boolean;
|
|
67
76
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>
|
|
68
77
|
```
|
|
@@ -11,15 +11,16 @@ complex modals.
|
|
|
11
11
|
|
|
12
12
|
## Props
|
|
13
13
|
|
|
14
|
-
| Name | Description
|
|
15
|
-
| ------------------------------ |
|
|
16
|
-
| <code>open</code> | Determines if the modal is open or not.
|
|
17
|
-
| <code>focusOnOpen</code> | Determines if the focused element changes to one inside the modal when it opens. Either the<br />first element with a positive tabindex or just the first focusable element.
|
|
18
|
-
| <code>referenceSelector</code> | The reference selector of a DOM element to use as reference to position the modal.<br />This selector can be an ID or a class, if it is a class, it will use the first<br />element that matches.
|
|
19
|
-
| <code>animation</code> | Animation to use for opening/closing the modal.This animation only affects the content.
|
|
20
|
-
| <code>overlayAnimation</code> | Animation to use for the overlay (backdrop) part of the modal. By default, it uses<br />a fade transition.
|
|
21
|
-
| <code>
|
|
22
|
-
| <code>
|
|
14
|
+
| Name | Description | Type | Default |
|
|
15
|
+
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | ------------------------------ |
|
|
16
|
+
| <code>open</code> | Determines if the modal is open or not. | <code>boolean</code> | <code></code> |
|
|
17
|
+
| <code>focusOnOpen</code> | Determines if the focused element changes to one inside the modal when it opens. Either the<br />first element with a positive tabindex or just the first focusable element. | <code>boolean</code> | <code>true</code> |
|
|
18
|
+
| <code>referenceSelector</code> | The reference selector of a DOM element to use as reference to position the modal.<br />This selector can be an ID or a class, if it is a class, it will use the first<br />element that matches. | <code>string</code> | <code></code> |
|
|
19
|
+
| <code>animation</code> | Animation to use for opening/closing the modal.This animation only affects the content. | <code>AnimationProp</code> | <code>() => NoAnimation</code> |
|
|
20
|
+
| <code>overlayAnimation</code> | Animation to use for the overlay (backdrop) part of the modal. By default, it uses<br />a fade transition. | <code>AnimationProp</code> | <code>() => Fade</code> |
|
|
21
|
+
| <code>scrollLock</code> | Determines if the scroll of the body and the window is disabled while the modal is open.<br />Set it to `false` for modals that must not lock the page scroll. It can be toggled while the<br />modal is open. | <code>boolean</code> | <code>true</code> |
|
|
22
|
+
| <code>contentClass</code> | Class inherited by content element. | <code>string</code> | <code></code> |
|
|
23
|
+
| <code>overlayClass</code> | Class inherited by overlay element. | <code>string</code> | <code></code> |
|
|
23
24
|
|
|
24
25
|
## Events
|
|
25
26
|
|
|
@@ -131,6 +132,18 @@ const fadeAndSlide = FadeAndSlide;
|
|
|
131
132
|
</script>
|
|
132
133
|
```
|
|
133
134
|
|
|
135
|
+
#### Not locking the page scroll
|
|
136
|
+
|
|
137
|
+
By default (`scrollLock` is `true`) the modal sets `overflow: hidden` on the `body` and `html`
|
|
138
|
+
elements while it is open, and restores them when it closes. Set the `scrollLock` prop to `false`
|
|
139
|
+
to keep the page scrollable. The prop can be toggled while the modal is open.
|
|
140
|
+
|
|
141
|
+
```vue
|
|
142
|
+
<BaseModal :open="open" :scroll-lock="false">
|
|
143
|
+
<p>The page behind can still be scrolled.</p>
|
|
144
|
+
</BaseModal>
|
|
145
|
+
```
|
|
146
|
+
|
|
134
147
|
## Vue Events
|
|
135
148
|
|
|
136
149
|
A list of events that the component will emit:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-teleport.vue.js","sources":["../../../src/components/base-teleport.vue"],"sourcesContent":["<template>\n <Teleport v-if=\"teleportHost\" :to=\"teleportHost.shadowRoot ?? teleportHost\" :disabled>\n <slot></slot>\n </Teleport>\n</template>\n\n<script lang=\"ts\">\nimport type { PropType } from 'vue'\nimport {\n defineComponent,\n getCurrentInstance,\n onBeforeUnmount,\n onMounted,\n onUnmounted,\n ref,\n watch,\n watchEffect,\n} from 'vue'\n\nexport default defineComponent({\n name: 'BaseTeleport',\n props: {\n /** The element or css selector to which the component will be teleported. */\n target: {\n type: [String, Object] as PropType<string | Element>,\n required: true,\n },\n /**\n * The position relative to the target\n * - `beforebegin`: Before the target element.\n * - `afterbegin`: Inside the target element, before its first child.\n * - `beforeend`: Inside the target element, after its last child.\n * - `afterend`: After the target element.\n * - `onlychild`: Adds it as child and hides all other children of the target element.\n */\n position: {\n type: String as PropType<\n 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend' | 'onlychild'\n >,\n default: 'onlychild',\n },\n /** If disabled, the slot content will not be teleported */\n disabled: {\n type: Boolean,\n default: false,\n },\n /** Styles for the teleport (content container) */\n hostStyle: Object as PropType<string | CSSStyleDeclaration>,\n },\n setup(props) {\n if (typeof document === 'undefined') {\n return { teleportHost: ref<HTMLElement>() }\n }\n\n const instance = getCurrentInstance()\n /** Hook where the slot content will be teleported to. */\n const teleportHost = ref<HTMLElement>()\n /** The page element where the teleport host will be inserted. */\n const targetElement = ref<HTMLElement>()\n let isIsolated = false\n\n // Before doing app.mount it is unknown if it will be mounted in a shadow so we need to wait.\n if (instance?.appContext.app._container) {\n createHost()\n } else {\n afterAppMount(createHost)\n }\n\n const targetAddedObserver = new MutationObserver(targetAdded)\n const targetRemovedObserver = new MutationObserver(targetRemoved)\n\n onUnmounted(() => {\n if (isIsolated && teleportHost.value) {\n ;(window as any).xCSSInjector.removeHost(teleportHost.value.shadowRoot)\n }\n })\n\n onBeforeUnmount(() => {\n targetAddedObserver.disconnect()\n targetRemovedObserver.disconnect()\n teleportHost.value?.remove()\n })\n\n // Handles target prop changes and init the observers accordingly.\n watch(\n () => props.target,\n newTarget => {\n targetAddedObserver.disconnect()\n targetRemovedObserver.disconnect()\n const target = typeof newTarget === 'string' ? document.querySelector(newTarget) : newTarget\n if (target?.isConnected) {\n targetAdded()\n } else {\n targetRemoved()\n }\n },\n { immediate: true },\n )\n\n // Updates the teleport host when props change.\n watchEffect(() => {\n if (!teleportHost.value) {\n return\n }\n if (props.disabled) {\n teleportHost.value.remove()\n return\n }\n teleportHost.value.className = `x-base-teleport x-base-teleport--${props.position}`\n\n if (!targetElement.value) {\n console.warn(`BaseTeleport: Target element \"${props.target}\" not found.`)\n return\n }\n const position = props.position === 'onlychild' ? 'beforeend' : props.position\n targetElement.value.insertAdjacentElement(position, teleportHost.value)\n\n if (props.position === 'onlychild') {\n targetElement.value.className += ' x-base-teleport-parent--onlychild'\n }\n })\n\n /* Update the host inline styles when it changes */\n watchEffect(() => {\n if (teleportHost.value && props.hostStyle) {\n if (typeof props.hostStyle === 'string') {\n teleportHost.value.style.cssText = props.hostStyle\n } else {\n Object.assign(teleportHost.value.style, props.hostStyle)\n }\n }\n })\n\n /** Checks if the target element exists in the DOM and updates the observers */\n function targetAdded() {\n let element: string | Element | null = props.target\n if (typeof element === 'string') {\n element = document.querySelector(element)\n }\n if (element instanceof HTMLElement && element.isConnected) {\n targetAddedObserver.disconnect()\n targetElement.value = element\n while (element.parentElement) {\n element = element.parentElement\n targetRemovedObserver.observe(element, { childList: true })\n }\n }\n }\n\n /** Checks if the target was disconnected from the DOM and updates the observers */\n function targetRemoved() {\n if (targetElement.value && !targetElement.value.isConnected) {\n targetRemovedObserver.disconnect()\n targetAddedObserver.observe(document.body, { childList: true, subtree: true })\n targetElement.value = undefined\n }\n }\n\n /** Creates and sets the teleport host element */\n function createHost() {\n teleportHost.value = document.createElement('div')\n isIsolated = instance?.appContext.app._container instanceof ShadowRoot\n if (isIsolated) {\n teleportHost.value.attachShadow({ mode: 'open' })\n ;(window as any).xCSSInjector.addHost(teleportHost.value.shadowRoot)\n }\n }\n\n function afterAppMount(fn: () => void) {\n onMounted(() => setTimeout(fn, 0))\n }\n\n return { teleportHost }\n },\n})\n\n/** Teleport host styles should be injected outside our shadowRoots */\nif (typeof document !== 'undefined') {\n const css = document.createElement('style')\n css.textContent = `.x-base-teleport-parent--onlychild > *:not(.x-base-teleport) { display: none; }`\n document.head?.appendChild(css) ||\n document.addEventListener('DOMContentLoaded', () => document.head.appendChild(css))\n}\n</script>\n\n<docs lang=\"mdx\">\n## Example\n\nThe BaseTeleport component allows you to teleport its slot content to a specified target element in\nthe DOM. It provides flexibility in positioning the content relative to the target element and\nsupports shadow DOM integration.\n\n### Basic example\n\nTeleport content to a specific element in the DOM:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\">\n <div>This content will be teleported.</div>\n </BaseTeleport>\n</template>\n```\n\n### Positioning options\n\nTeleport content inside the target element, before its first child:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\" position=\"afterbegin\">\n <div>Teleported content at the beginning.</div>\n </BaseTeleport>\n</template>\n```\n\n### Disabled Teleport\n\nPrevent teleporting the content:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\" :disabled=\"true\">\n <div>This content will not be teleported.</div>\n </BaseTeleport>\n</template>\n```\n\n### Notes\n\n- When using the `onlychild` position, all other children of the target element will be hidden.\n- The component supports shadow DOM integration, automatically handling style injection. Anyway, Empathy's custom CSS\n injector is required. Teleport depends on it to add the styles.\n</docs>\n"],"names":["_openBlock","_createBlock","_Teleport","_renderSlot","_createCommentVNode"],"mappings":";;;;;AACkB,EAAA,OAAA,IAAA,CAAA,YAAA,IAAAA,SAAA,EAAA,EAAhBC,WAAA,CAEWC,QAAA,EAAA;AAAA,IAAA,GAAA,EAAA,CAAA;AAFoB,IAAA,EAAA,EAAI,kBAAa,UAAA,IAAc,IAAA,CAAA,YAAA;AAAA,IAAe,QAAA,EAAA,IAAA,CAAA;AAAA,GAAA,EAAA;IAC3EC,UAAA,CAAa,IAAA,CAAA,MAAA,EAAA,SAAA;AAAA,GAAA,EAAA,CAAA,EAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA,IAAAC,kBAAA,CAAA,MAAA,EAAA,IAAA,CAAA;;;;;;"}
|
|
1
|
+
{"version":3,"file":"base-teleport.vue.js","sources":["../../../src/components/base-teleport.vue"],"sourcesContent":["<template>\n <Teleport v-if=\"teleportHost\" :to=\"teleportHost.shadowRoot ?? teleportHost\" :disabled>\n <slot></slot>\n </Teleport>\n</template>\n\n<script lang=\"ts\">\nimport type { PropType } from 'vue'\nimport {\n defineComponent,\n getCurrentInstance,\n onBeforeUnmount,\n onMounted,\n onUnmounted,\n ref,\n watch,\n watchEffect,\n} from 'vue'\n\nexport default defineComponent({\n name: 'BaseTeleport',\n props: {\n /** The element or css selector to which the component will be teleported. */\n target: {\n type: [String, Object] as PropType<string | Element>,\n required: true,\n },\n /**\n * The position relative to the target\n * - `beforebegin`: Before the target element.\n * - `afterbegin`: Inside the target element, before its first child.\n * - `beforeend`: Inside the target element, after its last child.\n * - `afterend`: After the target element.\n * - `onlychild`: Adds it as child and hides all other children of the target element.\n */\n position: {\n type: String as PropType<\n 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend' | 'onlychild'\n >,\n default: 'onlychild',\n },\n /** If disabled, the slot content will not be teleported */\n disabled: {\n type: Boolean,\n default: false,\n },\n /** Styles for the teleport (content container) */\n hostStyle: Object as PropType<string | CSSStyleDeclaration>,\n },\n setup(props) {\n if (typeof document === 'undefined') {\n return { teleportHost: ref<HTMLElement>() }\n }\n\n const instance = getCurrentInstance()\n /** Hook where the slot content will be teleported to. */\n const teleportHost = ref<HTMLElement>()\n /** The page element where the teleport host will be inserted. */\n const targetElement = ref<HTMLElement>()\n let isIsolated = false\n\n // Before doing app.mount it is unknown if it will be mounted in a shadow so we need to wait.\n if (instance?.appContext.app._container) {\n createHost()\n } else {\n afterAppMount(createHost)\n }\n\n const targetAddedObserver = new MutationObserver(targetAdded)\n const targetRemovedObserver = new MutationObserver(targetRemoved)\n\n onUnmounted(() => {\n if (isIsolated && teleportHost.value) {\n ;(window as any).xCSSInjector.removeHost(teleportHost.value.shadowRoot)\n }\n })\n\n onBeforeUnmount(() => {\n targetAddedObserver.disconnect()\n targetRemovedObserver.disconnect()\n teleportHost.value?.remove()\n targetElement.value?.classList.remove('x-base-teleport-parent--onlychild')\n })\n\n // Handles target prop changes and init the observers accordingly.\n watch(\n () => props.target,\n newTarget => {\n targetAddedObserver.disconnect()\n targetRemovedObserver.disconnect()\n const target = typeof newTarget === 'string' ? document.querySelector(newTarget) : newTarget\n if (target?.isConnected) {\n targetAdded()\n } else {\n targetRemoved()\n }\n },\n { immediate: true },\n )\n\n // Updates the teleport host when props change.\n watchEffect(() => {\n if (!teleportHost.value) {\n return\n }\n if (props.disabled) {\n teleportHost.value.remove()\n return\n }\n teleportHost.value.className = `x-base-teleport x-base-teleport--${props.position}`\n\n if (!targetElement.value) {\n console.warn(`BaseTeleport: Target element \"${props.target}\" not found.`)\n return\n }\n const position = props.position === 'onlychild' ? 'beforeend' : props.position\n targetElement.value.insertAdjacentElement(position, teleportHost.value)\n\n if (props.position === 'onlychild') {\n targetElement.value.className += ' x-base-teleport-parent--onlychild'\n }\n })\n\n /* Update the host inline styles when it changes */\n watchEffect(() => {\n if (teleportHost.value && props.hostStyle) {\n if (typeof props.hostStyle === 'string') {\n teleportHost.value.style.cssText = props.hostStyle\n } else {\n Object.assign(teleportHost.value.style, props.hostStyle)\n }\n }\n })\n\n /** Checks if the target element exists in the DOM and updates the observers */\n function targetAdded() {\n let element: string | Element | null = props.target\n if (typeof element === 'string') {\n element = document.querySelector(element)\n }\n if (element instanceof HTMLElement && element.isConnected) {\n targetAddedObserver.disconnect()\n targetElement.value = element\n while (element.parentElement) {\n element = element.parentElement\n targetRemovedObserver.observe(element, { childList: true })\n }\n }\n }\n\n /** Checks if the target was disconnected from the DOM and updates the observers */\n function targetRemoved() {\n if (targetElement.value && !targetElement.value.isConnected) {\n targetRemovedObserver.disconnect()\n targetAddedObserver.observe(document.body, { childList: true, subtree: true })\n targetElement.value = undefined\n }\n }\n\n /** Creates and sets the teleport host element */\n function createHost() {\n teleportHost.value = document.createElement('div')\n isIsolated = instance?.appContext.app._container instanceof ShadowRoot\n if (isIsolated) {\n teleportHost.value.attachShadow({ mode: 'open' })\n ;(window as any).xCSSInjector.addHost(teleportHost.value.shadowRoot)\n }\n }\n\n function afterAppMount(fn: () => void) {\n onMounted(() => setTimeout(fn, 0))\n }\n\n return { teleportHost }\n },\n})\n\n/** Teleport host styles should be injected outside our shadowRoots */\nif (typeof document !== 'undefined') {\n const css = document.createElement('style')\n css.textContent = `.x-base-teleport-parent--onlychild > *:not(.x-base-teleport) { display: none; }`\n document.head?.appendChild(css) ||\n document.addEventListener('DOMContentLoaded', () => document.head.appendChild(css))\n}\n</script>\n\n<docs lang=\"mdx\">\n## Example\n\nThe BaseTeleport component allows you to teleport its slot content to a specified target element in\nthe DOM. It provides flexibility in positioning the content relative to the target element and\nsupports shadow DOM integration.\n\n### Basic example\n\nTeleport content to a specific element in the DOM:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\">\n <div>This content will be teleported.</div>\n </BaseTeleport>\n</template>\n```\n\n### Positioning options\n\nTeleport content inside the target element, before its first child:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\" position=\"afterbegin\">\n <div>Teleported content at the beginning.</div>\n </BaseTeleport>\n</template>\n```\n\n### Disabled Teleport\n\nPrevent teleporting the content:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\" :disabled=\"true\">\n <div>This content will not be teleported.</div>\n </BaseTeleport>\n</template>\n```\n\n### Notes\n\n- When using the `onlychild` position, all other children of the target element will be hidden.\n- The component supports shadow DOM integration, automatically handling style injection. Anyway, Empathy's custom CSS\n injector is required. Teleport depends on it to add the styles.\n</docs>\n"],"names":["_openBlock","_createBlock","_Teleport","_renderSlot","_createCommentVNode"],"mappings":";;;;;AACkB,EAAA,OAAA,IAAA,CAAA,YAAA,IAAAA,SAAA,EAAA,EAAhBC,WAAA,CAEWC,QAAA,EAAA;AAAA,IAAA,GAAA,EAAA,CAAA;AAFoB,IAAA,EAAA,EAAI,kBAAa,UAAA,IAAc,IAAA,CAAA,YAAA;AAAA,IAAe,QAAA,EAAA,IAAA,CAAA;AAAA,GAAA,EAAA;IAC3EC,UAAA,CAAa,IAAA,CAAA,MAAA,EAAA,SAAA;AAAA,GAAA,EAAA,CAAA,EAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA,IAAAC,kBAAA,CAAA,MAAA,EAAA,IAAA,CAAA;;;;;;"}
|
|
@@ -56,6 +56,7 @@ var _sfc_main = defineComponent({
|
|
|
56
56
|
targetAddedObserver.disconnect();
|
|
57
57
|
targetRemovedObserver.disconnect();
|
|
58
58
|
teleportHost.value?.remove();
|
|
59
|
+
targetElement.value?.classList.remove('x-base-teleport-parent--onlychild');
|
|
59
60
|
});
|
|
60
61
|
// Handles target prop changes and init the observers accordingly.
|
|
61
62
|
watch(() => props.target, newTarget => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-teleport.vue2.js","sources":["../../../src/components/base-teleport.vue"],"sourcesContent":["<template>\n <Teleport v-if=\"teleportHost\" :to=\"teleportHost.shadowRoot ?? teleportHost\" :disabled>\n <slot></slot>\n </Teleport>\n</template>\n\n<script lang=\"ts\">\nimport type { PropType } from 'vue'\nimport {\n defineComponent,\n getCurrentInstance,\n onBeforeUnmount,\n onMounted,\n onUnmounted,\n ref,\n watch,\n watchEffect,\n} from 'vue'\n\nexport default defineComponent({\n name: 'BaseTeleport',\n props: {\n /** The element or css selector to which the component will be teleported. */\n target: {\n type: [String, Object] as PropType<string | Element>,\n required: true,\n },\n /**\n * The position relative to the target\n * - `beforebegin`: Before the target element.\n * - `afterbegin`: Inside the target element, before its first child.\n * - `beforeend`: Inside the target element, after its last child.\n * - `afterend`: After the target element.\n * - `onlychild`: Adds it as child and hides all other children of the target element.\n */\n position: {\n type: String as PropType<\n 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend' | 'onlychild'\n >,\n default: 'onlychild',\n },\n /** If disabled, the slot content will not be teleported */\n disabled: {\n type: Boolean,\n default: false,\n },\n /** Styles for the teleport (content container) */\n hostStyle: Object as PropType<string | CSSStyleDeclaration>,\n },\n setup(props) {\n if (typeof document === 'undefined') {\n return { teleportHost: ref<HTMLElement>() }\n }\n\n const instance = getCurrentInstance()\n /** Hook where the slot content will be teleported to. */\n const teleportHost = ref<HTMLElement>()\n /** The page element where the teleport host will be inserted. */\n const targetElement = ref<HTMLElement>()\n let isIsolated = false\n\n // Before doing app.mount it is unknown if it will be mounted in a shadow so we need to wait.\n if (instance?.appContext.app._container) {\n createHost()\n } else {\n afterAppMount(createHost)\n }\n\n const targetAddedObserver = new MutationObserver(targetAdded)\n const targetRemovedObserver = new MutationObserver(targetRemoved)\n\n onUnmounted(() => {\n if (isIsolated && teleportHost.value) {\n ;(window as any).xCSSInjector.removeHost(teleportHost.value.shadowRoot)\n }\n })\n\n onBeforeUnmount(() => {\n targetAddedObserver.disconnect()\n targetRemovedObserver.disconnect()\n teleportHost.value?.remove()\n })\n\n // Handles target prop changes and init the observers accordingly.\n watch(\n () => props.target,\n newTarget => {\n targetAddedObserver.disconnect()\n targetRemovedObserver.disconnect()\n const target = typeof newTarget === 'string' ? document.querySelector(newTarget) : newTarget\n if (target?.isConnected) {\n targetAdded()\n } else {\n targetRemoved()\n }\n },\n { immediate: true },\n )\n\n // Updates the teleport host when props change.\n watchEffect(() => {\n if (!teleportHost.value) {\n return\n }\n if (props.disabled) {\n teleportHost.value.remove()\n return\n }\n teleportHost.value.className = `x-base-teleport x-base-teleport--${props.position}`\n\n if (!targetElement.value) {\n console.warn(`BaseTeleport: Target element \"${props.target}\" not found.`)\n return\n }\n const position = props.position === 'onlychild' ? 'beforeend' : props.position\n targetElement.value.insertAdjacentElement(position, teleportHost.value)\n\n if (props.position === 'onlychild') {\n targetElement.value.className += ' x-base-teleport-parent--onlychild'\n }\n })\n\n /* Update the host inline styles when it changes */\n watchEffect(() => {\n if (teleportHost.value && props.hostStyle) {\n if (typeof props.hostStyle === 'string') {\n teleportHost.value.style.cssText = props.hostStyle\n } else {\n Object.assign(teleportHost.value.style, props.hostStyle)\n }\n }\n })\n\n /** Checks if the target element exists in the DOM and updates the observers */\n function targetAdded() {\n let element: string | Element | null = props.target\n if (typeof element === 'string') {\n element = document.querySelector(element)\n }\n if (element instanceof HTMLElement && element.isConnected) {\n targetAddedObserver.disconnect()\n targetElement.value = element\n while (element.parentElement) {\n element = element.parentElement\n targetRemovedObserver.observe(element, { childList: true })\n }\n }\n }\n\n /** Checks if the target was disconnected from the DOM and updates the observers */\n function targetRemoved() {\n if (targetElement.value && !targetElement.value.isConnected) {\n targetRemovedObserver.disconnect()\n targetAddedObserver.observe(document.body, { childList: true, subtree: true })\n targetElement.value = undefined\n }\n }\n\n /** Creates and sets the teleport host element */\n function createHost() {\n teleportHost.value = document.createElement('div')\n isIsolated = instance?.appContext.app._container instanceof ShadowRoot\n if (isIsolated) {\n teleportHost.value.attachShadow({ mode: 'open' })\n ;(window as any).xCSSInjector.addHost(teleportHost.value.shadowRoot)\n }\n }\n\n function afterAppMount(fn: () => void) {\n onMounted(() => setTimeout(fn, 0))\n }\n\n return { teleportHost }\n },\n})\n\n/** Teleport host styles should be injected outside our shadowRoots */\nif (typeof document !== 'undefined') {\n const css = document.createElement('style')\n css.textContent = `.x-base-teleport-parent--onlychild > *:not(.x-base-teleport) { display: none; }`\n document.head?.appendChild(css) ||\n document.addEventListener('DOMContentLoaded', () => document.head.appendChild(css))\n}\n</script>\n\n<docs lang=\"mdx\">\n## Example\n\nThe BaseTeleport component allows you to teleport its slot content to a specified target element in\nthe DOM. It provides flexibility in positioning the content relative to the target element and\nsupports shadow DOM integration.\n\n### Basic example\n\nTeleport content to a specific element in the DOM:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\">\n <div>This content will be teleported.</div>\n </BaseTeleport>\n</template>\n```\n\n### Positioning options\n\nTeleport content inside the target element, before its first child:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\" position=\"afterbegin\">\n <div>Teleported content at the beginning.</div>\n </BaseTeleport>\n</template>\n```\n\n### Disabled Teleport\n\nPrevent teleporting the content:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\" :disabled=\"true\">\n <div>This content will not be teleported.</div>\n </BaseTeleport>\n</template>\n```\n\n### Notes\n\n- When using the `onlychild` position, all other children of the target element will be hidden.\n- The component supports shadow DOM integration, automatically handling style injection. Anyway, Empathy's custom CSS\n injector is required. Teleport depends on it to add the styles.\n</docs>\n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Aa,CAAC,KAAI,GAAI,SAAQ;YAChC;QACF;;AAGA,QAAA,SAAS,UAAU,GAAA;YACjB,YAAY,CAAC,QAAQ,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAA;YACjD,UAAS,GAAI,QAAQ,EAAE,UAAU,CAAC,GAAG,CAAC,UAAS,YAAa,UAAS;YACrE,IAAI,UAAU,EAAE;gBACd,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAA;gBAC9C,MAAc,CAAC,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAA;YACrE;QACF;QAEA,SAAS,aAAa,CAAC,EAAc,EAAA;YACnC,SAAS,CAAC,MAAM,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;QACnC;QAEA,OAAO,EAAE,YAAW,EAAE;IACxB,CAAC;AACF,CAAA,CAAA;AAED;AACA,IAAI,OAAO,QAAO,KAAM,WAAW,EAAE;IACnC,MAAM,GAAE,GAAI,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAA;AAC1C,IAAA,GAAG,CAAC,WAAU,GAAI,CAAA,+EAAA,CAAgF;AAClG,IAAA,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG;AAC5B,QAAA,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;AACtF;;;;"}
|
|
1
|
+
{"version":3,"file":"base-teleport.vue2.js","sources":["../../../src/components/base-teleport.vue"],"sourcesContent":["<template>\n <Teleport v-if=\"teleportHost\" :to=\"teleportHost.shadowRoot ?? teleportHost\" :disabled>\n <slot></slot>\n </Teleport>\n</template>\n\n<script lang=\"ts\">\nimport type { PropType } from 'vue'\nimport {\n defineComponent,\n getCurrentInstance,\n onBeforeUnmount,\n onMounted,\n onUnmounted,\n ref,\n watch,\n watchEffect,\n} from 'vue'\n\nexport default defineComponent({\n name: 'BaseTeleport',\n props: {\n /** The element or css selector to which the component will be teleported. */\n target: {\n type: [String, Object] as PropType<string | Element>,\n required: true,\n },\n /**\n * The position relative to the target\n * - `beforebegin`: Before the target element.\n * - `afterbegin`: Inside the target element, before its first child.\n * - `beforeend`: Inside the target element, after its last child.\n * - `afterend`: After the target element.\n * - `onlychild`: Adds it as child and hides all other children of the target element.\n */\n position: {\n type: String as PropType<\n 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend' | 'onlychild'\n >,\n default: 'onlychild',\n },\n /** If disabled, the slot content will not be teleported */\n disabled: {\n type: Boolean,\n default: false,\n },\n /** Styles for the teleport (content container) */\n hostStyle: Object as PropType<string | CSSStyleDeclaration>,\n },\n setup(props) {\n if (typeof document === 'undefined') {\n return { teleportHost: ref<HTMLElement>() }\n }\n\n const instance = getCurrentInstance()\n /** Hook where the slot content will be teleported to. */\n const teleportHost = ref<HTMLElement>()\n /** The page element where the teleport host will be inserted. */\n const targetElement = ref<HTMLElement>()\n let isIsolated = false\n\n // Before doing app.mount it is unknown if it will be mounted in a shadow so we need to wait.\n if (instance?.appContext.app._container) {\n createHost()\n } else {\n afterAppMount(createHost)\n }\n\n const targetAddedObserver = new MutationObserver(targetAdded)\n const targetRemovedObserver = new MutationObserver(targetRemoved)\n\n onUnmounted(() => {\n if (isIsolated && teleportHost.value) {\n ;(window as any).xCSSInjector.removeHost(teleportHost.value.shadowRoot)\n }\n })\n\n onBeforeUnmount(() => {\n targetAddedObserver.disconnect()\n targetRemovedObserver.disconnect()\n teleportHost.value?.remove()\n targetElement.value?.classList.remove('x-base-teleport-parent--onlychild')\n })\n\n // Handles target prop changes and init the observers accordingly.\n watch(\n () => props.target,\n newTarget => {\n targetAddedObserver.disconnect()\n targetRemovedObserver.disconnect()\n const target = typeof newTarget === 'string' ? document.querySelector(newTarget) : newTarget\n if (target?.isConnected) {\n targetAdded()\n } else {\n targetRemoved()\n }\n },\n { immediate: true },\n )\n\n // Updates the teleport host when props change.\n watchEffect(() => {\n if (!teleportHost.value) {\n return\n }\n if (props.disabled) {\n teleportHost.value.remove()\n return\n }\n teleportHost.value.className = `x-base-teleport x-base-teleport--${props.position}`\n\n if (!targetElement.value) {\n console.warn(`BaseTeleport: Target element \"${props.target}\" not found.`)\n return\n }\n const position = props.position === 'onlychild' ? 'beforeend' : props.position\n targetElement.value.insertAdjacentElement(position, teleportHost.value)\n\n if (props.position === 'onlychild') {\n targetElement.value.className += ' x-base-teleport-parent--onlychild'\n }\n })\n\n /* Update the host inline styles when it changes */\n watchEffect(() => {\n if (teleportHost.value && props.hostStyle) {\n if (typeof props.hostStyle === 'string') {\n teleportHost.value.style.cssText = props.hostStyle\n } else {\n Object.assign(teleportHost.value.style, props.hostStyle)\n }\n }\n })\n\n /** Checks if the target element exists in the DOM and updates the observers */\n function targetAdded() {\n let element: string | Element | null = props.target\n if (typeof element === 'string') {\n element = document.querySelector(element)\n }\n if (element instanceof HTMLElement && element.isConnected) {\n targetAddedObserver.disconnect()\n targetElement.value = element\n while (element.parentElement) {\n element = element.parentElement\n targetRemovedObserver.observe(element, { childList: true })\n }\n }\n }\n\n /** Checks if the target was disconnected from the DOM and updates the observers */\n function targetRemoved() {\n if (targetElement.value && !targetElement.value.isConnected) {\n targetRemovedObserver.disconnect()\n targetAddedObserver.observe(document.body, { childList: true, subtree: true })\n targetElement.value = undefined\n }\n }\n\n /** Creates and sets the teleport host element */\n function createHost() {\n teleportHost.value = document.createElement('div')\n isIsolated = instance?.appContext.app._container instanceof ShadowRoot\n if (isIsolated) {\n teleportHost.value.attachShadow({ mode: 'open' })\n ;(window as any).xCSSInjector.addHost(teleportHost.value.shadowRoot)\n }\n }\n\n function afterAppMount(fn: () => void) {\n onMounted(() => setTimeout(fn, 0))\n }\n\n return { teleportHost }\n },\n})\n\n/** Teleport host styles should be injected outside our shadowRoots */\nif (typeof document !== 'undefined') {\n const css = document.createElement('style')\n css.textContent = `.x-base-teleport-parent--onlychild > *:not(.x-base-teleport) { display: none; }`\n document.head?.appendChild(css) ||\n document.addEventListener('DOMContentLoaded', () => document.head.appendChild(css))\n}\n</script>\n\n<docs lang=\"mdx\">\n## Example\n\nThe BaseTeleport component allows you to teleport its slot content to a specified target element in\nthe DOM. It provides flexibility in positioning the content relative to the target element and\nsupports shadow DOM integration.\n\n### Basic example\n\nTeleport content to a specific element in the DOM:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\">\n <div>This content will be teleported.</div>\n </BaseTeleport>\n</template>\n```\n\n### Positioning options\n\nTeleport content inside the target element, before its first child:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\" position=\"afterbegin\">\n <div>Teleported content at the beginning.</div>\n </BaseTeleport>\n</template>\n```\n\n### Disabled Teleport\n\nPrevent teleporting the content:\n\n```vue\n<template>\n <BaseTeleport target=\"#my-target\" :disabled=\"true\">\n <div>This content will not be teleported.</div>\n </BaseTeleport>\n</template>\n```\n\n### Notes\n\n- When using the `onlychild` position, all other children of the target element will be hidden.\n- The component supports shadow DOM integration, automatically handling style injection. Anyway, Empathy's custom CSS\n injector is required. Teleport depends on it to add the styles.\n</docs>\n"],"names":[],"mappings":";;AAmBA,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,cAAc;AACpB,IAAA,KAAK,EAAE;;AAEL,QAAA,MAAM,EAAE;AACN,YAAA,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAA+B;AACpD,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;;;;;;AAOE;AACF,QAAA,QAAQ,EAAE;AACR,YAAA,IAAI,EAAE,MAEL;AACD,YAAA,OAAO,EAAE,WAAW;AACrB,SAAA;;AAED,QAAA,QAAQ,EAAE;AACR,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,KAAK;AACf,SAAA;;AAED,QAAA,SAAS,EAAE,MAAgD;AAC5D,KAAA;AACD,IAAA,KAAK,CAAC,KAAK,EAAA;AACT,QAAA,IAAI,OAAO,QAAO,KAAM,WAAW,E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E,CAAC,CAAC,CAAA;QACnC;QAEA,OAAO,EAAE,YAAW,EAAE;IACxB,CAAC;AACF,CAAA,CAAA;AAED;AACA,IAAI,OAAO,QAAO,KAAM,WAAW,EAAE;IACnC,MAAM,GAAE,GAAI,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAA;AAC1C,IAAA,GAAG,CAAC,WAAU,GAAI,CAAA,+EAAA,CAAgF;AAClG,IAAA,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG;AAC5B,QAAA,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;AACtF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-modal.vue.js","sources":["../../../../src/components/modals/base-modal.vue"],"sourcesContent":["<template>\n <div v-show=\"isWaitingForLeave || open\" ref=\"modalRef\" class=\"x-modal\" data-test=\"modal\">\n <component\n :is=\"animation\"\n @before-leave=\"isWaitingForLeave = true\"\n @after-leave=\"isWaitingForLeave = false\"\n >\n <div\n v-if=\"open\"\n ref=\"modalContentRef\"\n class=\"x-modal__content\"\n data-test=\"modal-content\"\n role=\"dialog\"\n :class=\"contentClass\"\n :aria-label=\"ariaLabels?.modal\"\n >\n <!-- @slot (Required) Modal container content -->\n <slot />\n </div>\n </component>\n <component :is=\"overlayAnimation\">\n <div\n v-if=\"open\"\n class=\"x-modal__overlay\"\n :class=\"overlayClass\"\n data-test=\"modal-overlay\"\n @click=\"emitOverlayClicked\"\n @keydown=\"emitOverlayClicked\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { useAccessibilityLabels, useDebounce } from '../../composables'\nimport { AnimationProp } from '../../types'\nimport { FOCUSABLE_SELECTORS, getTargetElement } from '../../utils'\nimport { Fade, NoAnimation } from '../animations'\n\n/**\n * Base component with no XPlugin dependencies that serves as a utility for constructing more\n * complex modals.\n *\n * @public\n */\nexport default defineComponent({\n name: 'BaseModal',\n props: {\n /** Determines if the modal is open or not. */\n open: {\n type: Boolean,\n required: true,\n },\n /**\n * Determines if the focused element changes to one inside the modal when it opens. Either the\n * first element with a positive tabindex or just the first focusable element.\n */\n focusOnOpen: {\n type: Boolean,\n default: true,\n },\n /**\n * The reference selector of a DOM element to use as reference to position the modal.\n * This selector can be an ID or a class, if it is a class, it will use the first\n * element that matches.\n */\n referenceSelector: String,\n /** Animation to use for opening/closing the modal.This animation only affects the content. */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /**\n * Animation to use for the overlay (backdrop) part of the modal. By default, it uses\n * a fade transition.\n */\n overlayAnimation: {\n type: AnimationProp,\n default: () => Fade,\n },\n /** Class inherited by content element. */\n contentClass: String,\n /** Class inherited by overlay element. */\n overlayClass: String,\n },\n emits: ['click:overlay', 'focusin:body'],\n setup(props, { emit }) {\n const ariaLabels = useAccessibilityLabels('baseModal')\n\n /** Reference to the modal element in the DOM. */\n const modalRef = ref<HTMLDivElement>()\n /** Reference to the modal content element in the DOM. */\n const modalContentRef = ref<HTMLDivElement>()\n\n /** The previous value of the body overflow style. */\n const previousBodyOverflow = ref('')\n /** The previous value of the HTML element overflow style. */\n const previousHTMLOverflow = ref('')\n /** Boolean to delay the leave animation until it has completed. */\n const isWaitingForLeave = ref(false)\n /** The reference element to use to find the modal's position. */\n let referenceElement: HTMLElement | undefined\n\n /** Disables the scroll of both the body and the window. */\n function disableScroll() {\n previousBodyOverflow.value = document.body.style.overflow\n previousHTMLOverflow.value = document.documentElement.style.overflow\n document.body.style.overflow = document.documentElement.style.overflow = 'hidden'\n }\n\n /** Restores the scroll of both the body and the window. */\n function enableScroll() {\n document.body.style.overflow = previousBodyOverflow.value\n document.documentElement.style.overflow = previousHTMLOverflow.value\n }\n\n /**\n * Emits the `click:overlay` event if the click has been triggered in the overlay layer.\n *\n * @param event - The click event.\n */\n function emitOverlayClicked(event: Event) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('click:overlay', event)\n }\n\n /**\n * Emits the `focusin:body` event if a focus event has been triggered outside the modal.\n *\n * @param event - The focusin event.\n */\n function emitFocusInBody(event: FocusEvent) {\n if (!modalContentRef.value?.contains(getTargetElement(event))) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('focusin:body', event)\n }\n }\n\n /**\n * Adds listeners to the body element ot detect if the modal should be closed.\n *\n * @remarks TODO find a better solution and remove the timeout\n * To avoid emit the focusin on opening X that provokes closing it immediately.\n * This is because this event was emitted after the open of main modal when the user clicks\n * on the customer website search box (focus event). This way we avoid add the listener before\n * the open and the avoid the event that provokes the close.\n */\n function addBodyListeners() {\n setTimeout(() => {\n document.body.addEventListener('focusin', emitFocusInBody)\n })\n }\n\n /** Removes the body listeners. */\n function removeBodyListeners() {\n document.body.removeEventListener('focusin', emitFocusInBody)\n }\n\n /**\n * Sets the focused element to the first element either the first element with a positive\n * tabindex or, if there isn't any, the first focusable element inside the modal.\n */\n function setFocus() {\n const candidates: HTMLElement[] = Array.from(\n modalContentRef.value?.querySelectorAll(FOCUSABLE_SELECTORS) ?? [],\n )\n const element = candidates.find(element => element.tabIndex) ?? candidates[0]\n element?.focus()\n }\n\n /**\n * Syncs the body to the open state of the modal, adding or removing styles and listeners.\n *\n * @remarks nextTick() to wait for `modalContentRef` to be updated to look for focusable\n * candidates inside.\n *\n * @param isOpen - True when the modal is opened.\n */\n async function syncBody(isOpen: boolean) {\n if (isOpen) {\n disableScroll()\n addBodyListeners()\n if (props.focusOnOpen) {\n await nextTick()\n setFocus()\n }\n } else {\n enableScroll()\n removeBodyListeners()\n }\n }\n\n /**\n * Updates the position of the modal setting the top of the element depending\n * on the selector. The modal will be placed under this selector.\n */\n const debouncedUpdatePosition = useDebounce(\n () => {\n const { height, y } = referenceElement?.getBoundingClientRect() ?? { height: 0, y: 0 }\n modalRef.value!.style.top = `${height + y}px`\n modalRef.value!.style.bottom = '0'\n modalRef.value!.style.height = 'auto'\n },\n 100,\n { leading: true },\n )\n\n let resizeObserver: ResizeObserver\n\n onMounted(() => {\n watch(() => props.open, syncBody)\n if (props.open) {\n syncBody(true)\n }\n\n resizeObserver = new ResizeObserver(debouncedUpdatePosition)\n\n watch(\n () => props.referenceSelector,\n () => {\n resizeObserver.disconnect()\n\n if (props.referenceSelector) {\n const element = document.querySelector(props.referenceSelector) as HTMLElement\n if (element) {\n referenceElement = element\n resizeObserver.observe(element)\n }\n } else {\n referenceElement = undefined\n debouncedUpdatePosition()\n }\n },\n { immediate: true },\n )\n })\n\n onBeforeUnmount(() => {\n if (props.open) {\n removeBodyListeners()\n enableScroll()\n }\n resizeObserver.disconnect()\n })\n\n return {\n ariaLabels,\n emitOverlayClicked,\n isWaitingForLeave,\n modalContentRef,\n modalRef,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-modal {\n position: fixed;\n top: 0;\n left: 0;\n display: flex;\n align-items: flex-start;\n justify-content: flex-start;\n width: 100%;\n height: 100%;\n z-index: 1;\n}\n\n.x-modal__content {\n display: flex;\n flex-flow: column nowrap;\n z-index: 1;\n}\n\n.x-modal__overlay {\n width: 100%;\n height: 100%;\n position: absolute;\n background-color: rgb(0, 0, 0);\n opacity: 0.3;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThe `BaseModal` is a simple component that serves to create complex modals. Its open state has to be\npassed via prop. There is a prop, `referenceSelector`, used to place the modal under some element\ninstead of set the top of the element directly. It also accepts an animation to use for opening &\nclosing.\n\nIt emits a `click:overlay` event when any part out of the content is clicked, but only if the modal\nis open.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n### Customized usage\n\n#### Customizing the content with classes\n\nThe `contentClass` prop can be used to add classes to the modal content.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n contentClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n#### Customizing the overlay with classes\n\nThe `overlayClass` prop can be used to add classes to the modal overlay.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n overlayClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n## Vue Events\n\nA list of events that the component will emit:\n\n- `click:overlay`: the event is emitted after the user clicks any part out of the content but only\n if the modal is open. The event payload is the mouse event that triggers it.\n- `focusin:body`: the event is emitted after the user focus in any part out of the content but only\n if the modal is open. The event payload is the focus event that triggers it.\n</docs>\n"],"names":["_withDirectives","_openBlock","_createElementBlock","_createBlock","_resolveDynamicComponent","_normalizeClass","_renderSlot","_createCommentVNode","_withCtx","_vShow"],"mappings":";;;;;;EAC0C,GAAA,EAAI,UAAA;AAAA,EAAW,KAAA,E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AA,cACpB,WAAA,EAAU,eAAA;AAAA,cACT,SAAK,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAE,IAAA,CAAA,kBAAA,IAAA,IAAA,CAAA,kBAAA,CAAA,GAAA,IAAA,CAAA,CAAA;AAAA,cACP,WAAO,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAE,IAAA,CAAA,kBAAA,IAAA,IAAA,CAAA,kBAAA,CAAA,GAAA,IAAA,CAAA;AAAA,aAAA;;;;;;;;;;;;;AA1BH,IAAA,CAAAI,KAAA,EAAA,IAAA,CAAA,iBAAA,IAAqB,IAAA,CAAA,IAAI;AAAA,GAAA,CAAA;;;;;;"}
|
|
1
|
+
{"version":3,"file":"base-modal.vue.js","sources":["../../../../src/components/modals/base-modal.vue"],"sourcesContent":["<template>\n <div v-show=\"isWaitingForLeave || open\" ref=\"modalRef\" class=\"x-modal\" data-test=\"modal\">\n <component\n :is=\"animation\"\n @before-leave=\"isWaitingForLeave = true\"\n @after-leave=\"isWaitingForLeave = false\"\n >\n <div\n v-if=\"open\"\n ref=\"modalContentRef\"\n class=\"x-modal__content\"\n data-test=\"modal-content\"\n role=\"dialog\"\n :class=\"contentClass\"\n :aria-label=\"ariaLabels?.modal\"\n >\n <!-- @slot (Required) Modal container content -->\n <slot />\n </div>\n </component>\n <component :is=\"overlayAnimation\">\n <div\n v-if=\"open\"\n class=\"x-modal__overlay\"\n :class=\"overlayClass\"\n data-test=\"modal-overlay\"\n @click=\"emitOverlayClicked\"\n @keydown=\"emitOverlayClicked\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { useAccessibilityLabels, useDebounce } from '../../composables'\nimport { AnimationProp } from '../../types'\nimport { FOCUSABLE_SELECTORS, getTargetElement } from '../../utils'\nimport { Fade, NoAnimation } from '../animations'\n\n/**\n * Base component with no XPlugin dependencies that serves as a utility for constructing more\n * complex modals.\n *\n * @public\n */\nexport default defineComponent({\n name: 'BaseModal',\n props: {\n /** Determines if the modal is open or not. */\n open: {\n type: Boolean,\n required: true,\n },\n /**\n * Determines if the focused element changes to one inside the modal when it opens. Either the\n * first element with a positive tabindex or just the first focusable element.\n */\n focusOnOpen: {\n type: Boolean,\n default: true,\n },\n /**\n * The reference selector of a DOM element to use as reference to position the modal.\n * This selector can be an ID or a class, if it is a class, it will use the first\n * element that matches.\n */\n referenceSelector: String,\n /** Animation to use for opening/closing the modal.This animation only affects the content. */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /**\n * Animation to use for the overlay (backdrop) part of the modal. By default, it uses\n * a fade transition.\n */\n overlayAnimation: {\n type: AnimationProp,\n default: () => Fade,\n },\n /**\n * Determines if the scroll of the body and the window is disabled while the modal is open.\n * Set it to `false` for modals that must not lock the page scroll. It can be toggled while the\n * modal is open.\n */\n scrollLock: {\n type: Boolean,\n default: true,\n },\n /** Class inherited by content element. */\n contentClass: String,\n /** Class inherited by overlay element. */\n overlayClass: String,\n },\n emits: ['click:overlay', 'focusin:body'],\n setup(props, { emit }) {\n const ariaLabels = useAccessibilityLabels('baseModal')\n\n /** Reference to the modal element in the DOM. */\n const modalRef = ref<HTMLDivElement>()\n /** Reference to the modal content element in the DOM. */\n const modalContentRef = ref<HTMLDivElement>()\n\n /** The previous value of the body overflow style. */\n const previousBodyOverflow = ref('')\n /** The previous value of the HTML element overflow style. */\n const previousHTMLOverflow = ref('')\n /** Boolean to delay the leave animation until it has completed. */\n const isWaitingForLeave = ref(false)\n /** The reference element to use to find the modal's position. */\n let referenceElement: HTMLElement | undefined\n\n /** Whether this modal is currently holding the scroll lock, so it only restores what it set. */\n let isScrollDisabled = false\n\n /** Disables the scroll of both the body and the window. */\n function disableScroll() {\n if (!props.scrollLock || isScrollDisabled) {\n return\n }\n isScrollDisabled = true\n previousBodyOverflow.value = document.body.style.overflow\n previousHTMLOverflow.value = document.documentElement.style.overflow\n document.body.style.overflow = document.documentElement.style.overflow = 'hidden'\n }\n\n /** Restores the scroll of both the body and the window. */\n function enableScroll() {\n if (!isScrollDisabled) {\n return\n }\n isScrollDisabled = false\n document.body.style.overflow = previousBodyOverflow.value\n document.documentElement.style.overflow = previousHTMLOverflow.value\n }\n\n /**\n * Emits the `click:overlay` event if the click has been triggered in the overlay layer.\n *\n * @param event - The click event.\n */\n function emitOverlayClicked(event: Event) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('click:overlay', event)\n }\n\n /**\n * Emits the `focusin:body` event if a focus event has been triggered outside the modal.\n *\n * @param event - The focusin event.\n */\n function emitFocusInBody(event: FocusEvent) {\n if (!modalContentRef.value?.contains(getTargetElement(event))) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('focusin:body', event)\n }\n }\n\n /**\n * Adds listeners to the body element ot detect if the modal should be closed.\n *\n * @remarks TODO find a better solution and remove the timeout\n * To avoid emit the focusin on opening X that provokes closing it immediately.\n * This is because this event was emitted after the open of main modal when the user clicks\n * on the customer website search box (focus event). This way we avoid add the listener before\n * the open and the avoid the event that provokes the close.\n */\n function addBodyListeners() {\n setTimeout(() => {\n document.body.addEventListener('focusin', emitFocusInBody)\n })\n }\n\n /** Removes the body listeners. */\n function removeBodyListeners() {\n document.body.removeEventListener('focusin', emitFocusInBody)\n }\n\n /**\n * Sets the focused element to the first element either the first element with a positive\n * tabindex or, if there isn't any, the first focusable element inside the modal.\n */\n function setFocus() {\n const candidates: HTMLElement[] = Array.from(\n modalContentRef.value?.querySelectorAll(FOCUSABLE_SELECTORS) ?? [],\n )\n const element = candidates.find(element => element.tabIndex) ?? candidates[0]\n element?.focus()\n }\n\n /**\n * Syncs the body to the open state of the modal, adding or removing styles and listeners.\n *\n * @remarks nextTick() to wait for `modalContentRef` to be updated to look for focusable\n * candidates inside.\n *\n * @param isOpen - True when the modal is opened.\n */\n async function syncBody(isOpen: boolean) {\n if (isOpen) {\n disableScroll()\n addBodyListeners()\n if (props.focusOnOpen) {\n await nextTick()\n setFocus()\n }\n } else {\n enableScroll()\n removeBodyListeners()\n }\n }\n\n /**\n * Updates the position of the modal setting the top of the element depending\n * on the selector. The modal will be placed under this selector.\n */\n const debouncedUpdatePosition = useDebounce(\n () => {\n const { height, y } = referenceElement?.getBoundingClientRect() ?? { height: 0, y: 0 }\n modalRef.value!.style.top = `${height + y}px`\n modalRef.value!.style.bottom = '0'\n modalRef.value!.style.height = 'auto'\n },\n 100,\n { leading: true },\n )\n\n let resizeObserver: ResizeObserver\n\n onMounted(() => {\n watch(() => props.open, syncBody)\n watch(\n () => props.scrollLock,\n shouldLockScroll => {\n if (props.open) {\n shouldLockScroll ? disableScroll() : enableScroll()\n }\n },\n )\n if (props.open) {\n syncBody(true)\n }\n\n resizeObserver = new ResizeObserver(debouncedUpdatePosition)\n\n watch(\n () => props.referenceSelector,\n () => {\n resizeObserver.disconnect()\n\n if (props.referenceSelector) {\n const element = document.querySelector(props.referenceSelector) as HTMLElement\n if (element) {\n referenceElement = element\n resizeObserver.observe(element)\n }\n } else {\n referenceElement = undefined\n debouncedUpdatePosition()\n }\n },\n { immediate: true },\n )\n })\n\n onBeforeUnmount(() => {\n if (props.open) {\n removeBodyListeners()\n enableScroll()\n }\n resizeObserver.disconnect()\n })\n\n return {\n ariaLabels,\n emitOverlayClicked,\n isWaitingForLeave,\n modalContentRef,\n modalRef,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-modal {\n position: fixed;\n top: 0;\n left: 0;\n display: flex;\n align-items: flex-start;\n justify-content: flex-start;\n width: 100%;\n height: 100%;\n z-index: 1;\n}\n\n.x-modal__content {\n display: flex;\n flex-flow: column nowrap;\n z-index: 1;\n}\n\n.x-modal__overlay {\n width: 100%;\n height: 100%;\n position: absolute;\n background-color: rgb(0, 0, 0);\n opacity: 0.3;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThe `BaseModal` is a simple component that serves to create complex modals. Its open state has to be\npassed via prop. There is a prop, `referenceSelector`, used to place the modal under some element\ninstead of set the top of the element directly. It also accepts an animation to use for opening &\nclosing.\n\nIt emits a `click:overlay` event when any part out of the content is clicked, but only if the modal\nis open.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n### Customized usage\n\n#### Customizing the content with classes\n\nThe `contentClass` prop can be used to add classes to the modal content.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n contentClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n#### Customizing the overlay with classes\n\nThe `overlayClass` prop can be used to add classes to the modal overlay.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n overlayClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n#### Not locking the page scroll\n\nBy default (`scrollLock` is `true`) the modal sets `overflow: hidden` on the `body` and `html`\nelements while it is open, and restores them when it closes. Set the `scrollLock` prop to `false`\nto keep the page scrollable. The prop can be toggled while the modal is open.\n\n```vue\n<BaseModal :open=\"open\" :scroll-lock=\"false\">\n <p>The page behind can still be scrolled.</p>\n</BaseModal>\n```\n\n## Vue Events\n\nA list of events that the component will emit:\n\n- `click:overlay`: the event is emitted after the user clicks any part out of the content but only\n if the modal is open. The event payload is the mouse event that triggers it.\n- `focusin:body`: the event is emitted after the user focus in any part out of the content but only\n if the modal is open. The event payload is the focus event that triggers it.\n</docs>\n"],"names":["_withDirectives","_openBlock","_createElementBlock","_createBlock","_resolveDynamicComponent","_normalizeClass","_renderSlot","_createCommentVNode","_withCtx","_vShow"],"mappings":";;;;;;EAC0C,GAAA,EAAI,UAAA;AAAA,EAAW,KAAA,EAAM,SAAA;AAAA,EAAU,WAAA,EAAU;;;;AAAjF,EAAA,OAAAA,cAAA,EAAAC,SAAA,EAAA,EAAAC,kBAAA;AAAA,IA6BM,KAAA;AAAA,IA7BN,UAAA;AAAA,IA6BM;AAAA,OAAAD,SAAA,EAAA,EA5BJE,WAAA;AAAA,QAiBYC,wBAhBL,IAAA,CAAA,SAAS,CAAA;AAAA,QAAA;AAAA,UACb,aAAA,EAAY,sCAAE,IAAA,CAAA,iBAAA,GAAiB,IAAA,CAAA;AAAA,UAC/B,YAAA,EAAW,sCAAE,IAAA,CAAA,iBAAA,GAAiB,KAAA;AAAA,SAAA;;2BAE/B,MAWM;AAAA,YAVE,0BADRF,kBAAA,CAWM,KAAA,EAAA;AAAA,cAAA,GAAA,EAAA,CAAA;cATJ,GAAA,EAAI,iBAAA;AAAA,cACJ,KAAA,EAAKG,cAAA,CAAA,CAAC,kBAAA,EAGE,IAAA,CAAA,YAAY,CAAA,CAAA;AAAA,cA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|
},
|
|
76
|
+
/**
|
|
77
|
+
* Determines if the scroll of the body and the window is disabled while the modal is open.
|
|
78
|
+
* Set it to `false` for modals that must not lock the page scroll. It can be toggled while the
|
|
79
|
+
* modal is open.
|
|
80
|
+
*/
|
|
81
|
+
scrollLock: {
|
|
82
|
+
type: Boolean,
|
|
83
|
+
default: true,
|
|
84
|
+
},
|
|
76
85
|
/** Class inherited by content element. */
|
|
77
86
|
contentClass: String,
|
|
78
87
|
/** Class inherited by overlay element. */
|
|
@@ -93,14 +102,24 @@ var _sfc_main = defineComponent({
|
|
|
93
102
|
const isWaitingForLeave = ref(false);
|
|
94
103
|
/** The reference element to use to find the modal's position. */
|
|
95
104
|
let referenceElement;
|
|
105
|
+
/** Whether this modal is currently holding the scroll lock, so it only restores what it set. */
|
|
106
|
+
let isScrollDisabled = false;
|
|
96
107
|
/** Disables the scroll of both the body and the window. */
|
|
97
108
|
function disableScroll() {
|
|
109
|
+
if (!props.scrollLock || isScrollDisabled) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
isScrollDisabled = true;
|
|
98
113
|
previousBodyOverflow.value = document.body.style.overflow;
|
|
99
114
|
previousHTMLOverflow.value = document.documentElement.style.overflow;
|
|
100
115
|
document.body.style.overflow = document.documentElement.style.overflow = 'hidden';
|
|
101
116
|
}
|
|
102
117
|
/** Restores the scroll of both the body and the window. */
|
|
103
118
|
function enableScroll() {
|
|
119
|
+
if (!isScrollDisabled) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
isScrollDisabled = false;
|
|
104
123
|
document.body.style.overflow = previousBodyOverflow.value;
|
|
105
124
|
document.documentElement.style.overflow = previousHTMLOverflow.value;
|
|
106
125
|
}
|
|
@@ -186,6 +205,11 @@ var _sfc_main = defineComponent({
|
|
|
186
205
|
let resizeObserver;
|
|
187
206
|
onMounted(() => {
|
|
188
207
|
watch(() => props.open, syncBody);
|
|
208
|
+
watch(() => props.scrollLock, shouldLockScroll => {
|
|
209
|
+
if (props.open) {
|
|
210
|
+
shouldLockScroll ? disableScroll() : enableScroll();
|
|
211
|
+
}
|
|
212
|
+
});
|
|
189
213
|
if (props.open) {
|
|
190
214
|
syncBody(true);
|
|
191
215
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-modal.vue2.js","sources":["../../../../src/components/modals/base-modal.vue"],"sourcesContent":["<template>\n <div v-show=\"isWaitingForLeave || open\" ref=\"modalRef\" class=\"x-modal\" data-test=\"modal\">\n <component\n :is=\"animation\"\n @before-leave=\"isWaitingForLeave = true\"\n @after-leave=\"isWaitingForLeave = false\"\n >\n <div\n v-if=\"open\"\n ref=\"modalContentRef\"\n class=\"x-modal__content\"\n data-test=\"modal-content\"\n role=\"dialog\"\n :class=\"contentClass\"\n :aria-label=\"ariaLabels?.modal\"\n >\n <!-- @slot (Required) Modal container content -->\n <slot />\n </div>\n </component>\n <component :is=\"overlayAnimation\">\n <div\n v-if=\"open\"\n class=\"x-modal__overlay\"\n :class=\"overlayClass\"\n data-test=\"modal-overlay\"\n @click=\"emitOverlayClicked\"\n @keydown=\"emitOverlayClicked\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { useAccessibilityLabels, useDebounce } from '../../composables'\nimport { AnimationProp } from '../../types'\nimport { FOCUSABLE_SELECTORS, getTargetElement } from '../../utils'\nimport { Fade, NoAnimation } from '../animations'\n\n/**\n * Base component with no XPlugin dependencies that serves as a utility for constructing more\n * complex modals.\n *\n * @public\n */\nexport default defineComponent({\n name: 'BaseModal',\n props: {\n /** Determines if the modal is open or not. */\n open: {\n type: Boolean,\n required: true,\n },\n /**\n * Determines if the focused element changes to one inside the modal when it opens. Either the\n * first element with a positive tabindex or just the first focusable element.\n */\n focusOnOpen: {\n type: Boolean,\n default: true,\n },\n /**\n * The reference selector of a DOM element to use as reference to position the modal.\n * This selector can be an ID or a class, if it is a class, it will use the first\n * element that matches.\n */\n referenceSelector: String,\n /** Animation to use for opening/closing the modal.This animation only affects the content. */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /**\n * Animation to use for the overlay (backdrop) part of the modal. By default, it uses\n * a fade transition.\n */\n overlayAnimation: {\n type: AnimationProp,\n default: () => Fade,\n },\n /** Class inherited by content element. */\n contentClass: String,\n /** Class inherited by overlay element. */\n overlayClass: String,\n },\n emits: ['click:overlay', 'focusin:body'],\n setup(props, { emit }) {\n const ariaLabels = useAccessibilityLabels('baseModal')\n\n /** Reference to the modal element in the DOM. */\n const modalRef = ref<HTMLDivElement>()\n /** Reference to the modal content element in the DOM. */\n const modalContentRef = ref<HTMLDivElement>()\n\n /** The previous value of the body overflow style. */\n const previousBodyOverflow = ref('')\n /** The previous value of the HTML element overflow style. */\n const previousHTMLOverflow = ref('')\n /** Boolean to delay the leave animation until it has completed. */\n const isWaitingForLeave = ref(false)\n /** The reference element to use to find the modal's position. */\n let referenceElement: HTMLElement | undefined\n\n /** Disables the scroll of both the body and the window. */\n function disableScroll() {\n previousBodyOverflow.value = document.body.style.overflow\n previousHTMLOverflow.value = document.documentElement.style.overflow\n document.body.style.overflow = document.documentElement.style.overflow = 'hidden'\n }\n\n /** Restores the scroll of both the body and the window. */\n function enableScroll() {\n document.body.style.overflow = previousBodyOverflow.value\n document.documentElement.style.overflow = previousHTMLOverflow.value\n }\n\n /**\n * Emits the `click:overlay` event if the click has been triggered in the overlay layer.\n *\n * @param event - The click event.\n */\n function emitOverlayClicked(event: Event) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('click:overlay', event)\n }\n\n /**\n * Emits the `focusin:body` event if a focus event has been triggered outside the modal.\n *\n * @param event - The focusin event.\n */\n function emitFocusInBody(event: FocusEvent) {\n if (!modalContentRef.value?.contains(getTargetElement(event))) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('focusin:body', event)\n }\n }\n\n /**\n * Adds listeners to the body element ot detect if the modal should be closed.\n *\n * @remarks TODO find a better solution and remove the timeout\n * To avoid emit the focusin on opening X that provokes closing it immediately.\n * This is because this event was emitted after the open of main modal when the user clicks\n * on the customer website search box (focus event). This way we avoid add the listener before\n * the open and the avoid the event that provokes the close.\n */\n function addBodyListeners() {\n setTimeout(() => {\n document.body.addEventListener('focusin', emitFocusInBody)\n })\n }\n\n /** Removes the body listeners. */\n function removeBodyListeners() {\n document.body.removeEventListener('focusin', emitFocusInBody)\n }\n\n /**\n * Sets the focused element to the first element either the first element with a positive\n * tabindex or, if there isn't any, the first focusable element inside the modal.\n */\n function setFocus() {\n const candidates: HTMLElement[] = Array.from(\n modalContentRef.value?.querySelectorAll(FOCUSABLE_SELECTORS) ?? [],\n )\n const element = candidates.find(element => element.tabIndex) ?? candidates[0]\n element?.focus()\n }\n\n /**\n * Syncs the body to the open state of the modal, adding or removing styles and listeners.\n *\n * @remarks nextTick() to wait for `modalContentRef` to be updated to look for focusable\n * candidates inside.\n *\n * @param isOpen - True when the modal is opened.\n */\n async function syncBody(isOpen: boolean) {\n if (isOpen) {\n disableScroll()\n addBodyListeners()\n if (props.focusOnOpen) {\n await nextTick()\n setFocus()\n }\n } else {\n enableScroll()\n removeBodyListeners()\n }\n }\n\n /**\n * Updates the position of the modal setting the top of the element depending\n * on the selector. The modal will be placed under this selector.\n */\n const debouncedUpdatePosition = useDebounce(\n () => {\n const { height, y } = referenceElement?.getBoundingClientRect() ?? { height: 0, y: 0 }\n modalRef.value!.style.top = `${height + y}px`\n modalRef.value!.style.bottom = '0'\n modalRef.value!.style.height = 'auto'\n },\n 100,\n { leading: true },\n )\n\n let resizeObserver: ResizeObserver\n\n onMounted(() => {\n watch(() => props.open, syncBody)\n if (props.open) {\n syncBody(true)\n }\n\n resizeObserver = new ResizeObserver(debouncedUpdatePosition)\n\n watch(\n () => props.referenceSelector,\n () => {\n resizeObserver.disconnect()\n\n if (props.referenceSelector) {\n const element = document.querySelector(props.referenceSelector) as HTMLElement\n if (element) {\n referenceElement = element\n resizeObserver.observe(element)\n }\n } else {\n referenceElement = undefined\n debouncedUpdatePosition()\n }\n },\n { immediate: true },\n )\n })\n\n onBeforeUnmount(() => {\n if (props.open) {\n removeBodyListeners()\n enableScroll()\n }\n resizeObserver.disconnect()\n })\n\n return {\n ariaLabels,\n emitOverlayClicked,\n isWaitingForLeave,\n modalContentRef,\n modalRef,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-modal {\n position: fixed;\n top: 0;\n left: 0;\n display: flex;\n align-items: flex-start;\n justify-content: flex-start;\n width: 100%;\n height: 100%;\n z-index: 1;\n}\n\n.x-modal__content {\n display: flex;\n flex-flow: column nowrap;\n z-index: 1;\n}\n\n.x-modal__overlay {\n width: 100%;\n height: 100%;\n position: absolute;\n background-color: rgb(0, 0, 0);\n opacity: 0.3;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThe `BaseModal` is a simple component that serves to create complex modals. Its open state has to be\npassed via prop. There is a prop, `referenceSelector`, used to place the modal under some element\ninstead of set the top of the element directly. It also accepts an animation to use for opening &\nclosing.\n\nIt emits a `click:overlay` event when any part out of the content is clicked, but only if the modal\nis open.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n### Customized usage\n\n#### Customizing the content with classes\n\nThe `contentClass` prop can be used to add classes to the modal content.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n contentClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n#### Customizing the overlay with classes\n\nThe `overlayClass` prop can be used to add classes to the modal overlay.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n overlayClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n## Vue Events\n\nA list of events that the component will emit:\n\n- `click:overlay`: the event is emitted after the user clicks any part out of the content but only\n if the modal is open. The event payload is the mouse event that triggers it.\n- `focusin:body`: the event is emitted after the user focus in any part out of the content but only\n if the modal is open. The event payload is the focus event that triggers it.\n</docs>\n"],"names":["NoAnimation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA;;;;;AAKE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,KAAK,EAAE;;AAEL,QAAA,IAAI,EAAE;AACJ,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;;AAGE;AACF,QAAA,WAAW,EAAE;AACX,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACD;;;;AAIE;AACF,QAAA,iBAAiB,EAAE,MAAM;;AAEzB,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAA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AK,CAAC,IAAI,EAAE;AACd,gBAAA,mBAAmB,EAAC;AACpB,gBAAA,YAAY,EAAC;YACf;YACA,cAAc,CAAC,UAAU,EAAC;AAC5B,QAAA,CAAC,CAAA;QAED,OAAO;YACL,UAAU;YACV,kBAAkB;YAClB,iBAAiB;YACjB,eAAe;YACf,QAAQ;SACV;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"base-modal.vue2.js","sources":["../../../../src/components/modals/base-modal.vue"],"sourcesContent":["<template>\n <div v-show=\"isWaitingForLeave || open\" ref=\"modalRef\" class=\"x-modal\" data-test=\"modal\">\n <component\n :is=\"animation\"\n @before-leave=\"isWaitingForLeave = true\"\n @after-leave=\"isWaitingForLeave = false\"\n >\n <div\n v-if=\"open\"\n ref=\"modalContentRef\"\n class=\"x-modal__content\"\n data-test=\"modal-content\"\n role=\"dialog\"\n :class=\"contentClass\"\n :aria-label=\"ariaLabels?.modal\"\n >\n <!-- @slot (Required) Modal container content -->\n <slot />\n </div>\n </component>\n <component :is=\"overlayAnimation\">\n <div\n v-if=\"open\"\n class=\"x-modal__overlay\"\n :class=\"overlayClass\"\n data-test=\"modal-overlay\"\n @click=\"emitOverlayClicked\"\n @keydown=\"emitOverlayClicked\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { useAccessibilityLabels, useDebounce } from '../../composables'\nimport { AnimationProp } from '../../types'\nimport { FOCUSABLE_SELECTORS, getTargetElement } from '../../utils'\nimport { Fade, NoAnimation } from '../animations'\n\n/**\n * Base component with no XPlugin dependencies that serves as a utility for constructing more\n * complex modals.\n *\n * @public\n */\nexport default defineComponent({\n name: 'BaseModal',\n props: {\n /** Determines if the modal is open or not. */\n open: {\n type: Boolean,\n required: true,\n },\n /**\n * Determines if the focused element changes to one inside the modal when it opens. Either the\n * first element with a positive tabindex or just the first focusable element.\n */\n focusOnOpen: {\n type: Boolean,\n default: true,\n },\n /**\n * The reference selector of a DOM element to use as reference to position the modal.\n * This selector can be an ID or a class, if it is a class, it will use the first\n * element that matches.\n */\n referenceSelector: String,\n /** Animation to use for opening/closing the modal.This animation only affects the content. */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /**\n * Animation to use for the overlay (backdrop) part of the modal. By default, it uses\n * a fade transition.\n */\n overlayAnimation: {\n type: AnimationProp,\n default: () => Fade,\n },\n /**\n * Determines if the scroll of the body and the window is disabled while the modal is open.\n * Set it to `false` for modals that must not lock the page scroll. It can be toggled while the\n * modal is open.\n */\n scrollLock: {\n type: Boolean,\n default: true,\n },\n /** Class inherited by content element. */\n contentClass: String,\n /** Class inherited by overlay element. */\n overlayClass: String,\n },\n emits: ['click:overlay', 'focusin:body'],\n setup(props, { emit }) {\n const ariaLabels = useAccessibilityLabels('baseModal')\n\n /** Reference to the modal element in the DOM. */\n const modalRef = ref<HTMLDivElement>()\n /** Reference to the modal content element in the DOM. */\n const modalContentRef = ref<HTMLDivElement>()\n\n /** The previous value of the body overflow style. */\n const previousBodyOverflow = ref('')\n /** The previous value of the HTML element overflow style. */\n const previousHTMLOverflow = ref('')\n /** Boolean to delay the leave animation until it has completed. */\n const isWaitingForLeave = ref(false)\n /** The reference element to use to find the modal's position. */\n let referenceElement: HTMLElement | undefined\n\n /** Whether this modal is currently holding the scroll lock, so it only restores what it set. */\n let isScrollDisabled = false\n\n /** Disables the scroll of both the body and the window. */\n function disableScroll() {\n if (!props.scrollLock || isScrollDisabled) {\n return\n }\n isScrollDisabled = true\n previousBodyOverflow.value = document.body.style.overflow\n previousHTMLOverflow.value = document.documentElement.style.overflow\n document.body.style.overflow = document.documentElement.style.overflow = 'hidden'\n }\n\n /** Restores the scroll of both the body and the window. */\n function enableScroll() {\n if (!isScrollDisabled) {\n return\n }\n isScrollDisabled = false\n document.body.style.overflow = previousBodyOverflow.value\n document.documentElement.style.overflow = previousHTMLOverflow.value\n }\n\n /**\n * Emits the `click:overlay` event if the click has been triggered in the overlay layer.\n *\n * @param event - The click event.\n */\n function emitOverlayClicked(event: Event) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('click:overlay', event)\n }\n\n /**\n * Emits the `focusin:body` event if a focus event has been triggered outside the modal.\n *\n * @param event - The focusin event.\n */\n function emitFocusInBody(event: FocusEvent) {\n if (!modalContentRef.value?.contains(getTargetElement(event))) {\n // eslint-disable-next-line vue/custom-event-name-casing\n emit('focusin:body', event)\n }\n }\n\n /**\n * Adds listeners to the body element ot detect if the modal should be closed.\n *\n * @remarks TODO find a better solution and remove the timeout\n * To avoid emit the focusin on opening X that provokes closing it immediately.\n * This is because this event was emitted after the open of main modal when the user clicks\n * on the customer website search box (focus event). This way we avoid add the listener before\n * the open and the avoid the event that provokes the close.\n */\n function addBodyListeners() {\n setTimeout(() => {\n document.body.addEventListener('focusin', emitFocusInBody)\n })\n }\n\n /** Removes the body listeners. */\n function removeBodyListeners() {\n document.body.removeEventListener('focusin', emitFocusInBody)\n }\n\n /**\n * Sets the focused element to the first element either the first element with a positive\n * tabindex or, if there isn't any, the first focusable element inside the modal.\n */\n function setFocus() {\n const candidates: HTMLElement[] = Array.from(\n modalContentRef.value?.querySelectorAll(FOCUSABLE_SELECTORS) ?? [],\n )\n const element = candidates.find(element => element.tabIndex) ?? candidates[0]\n element?.focus()\n }\n\n /**\n * Syncs the body to the open state of the modal, adding or removing styles and listeners.\n *\n * @remarks nextTick() to wait for `modalContentRef` to be updated to look for focusable\n * candidates inside.\n *\n * @param isOpen - True when the modal is opened.\n */\n async function syncBody(isOpen: boolean) {\n if (isOpen) {\n disableScroll()\n addBodyListeners()\n if (props.focusOnOpen) {\n await nextTick()\n setFocus()\n }\n } else {\n enableScroll()\n removeBodyListeners()\n }\n }\n\n /**\n * Updates the position of the modal setting the top of the element depending\n * on the selector. The modal will be placed under this selector.\n */\n const debouncedUpdatePosition = useDebounce(\n () => {\n const { height, y } = referenceElement?.getBoundingClientRect() ?? { height: 0, y: 0 }\n modalRef.value!.style.top = `${height + y}px`\n modalRef.value!.style.bottom = '0'\n modalRef.value!.style.height = 'auto'\n },\n 100,\n { leading: true },\n )\n\n let resizeObserver: ResizeObserver\n\n onMounted(() => {\n watch(() => props.open, syncBody)\n watch(\n () => props.scrollLock,\n shouldLockScroll => {\n if (props.open) {\n shouldLockScroll ? disableScroll() : enableScroll()\n }\n },\n )\n if (props.open) {\n syncBody(true)\n }\n\n resizeObserver = new ResizeObserver(debouncedUpdatePosition)\n\n watch(\n () => props.referenceSelector,\n () => {\n resizeObserver.disconnect()\n\n if (props.referenceSelector) {\n const element = document.querySelector(props.referenceSelector) as HTMLElement\n if (element) {\n referenceElement = element\n resizeObserver.observe(element)\n }\n } else {\n referenceElement = undefined\n debouncedUpdatePosition()\n }\n },\n { immediate: true },\n )\n })\n\n onBeforeUnmount(() => {\n if (props.open) {\n removeBodyListeners()\n enableScroll()\n }\n resizeObserver.disconnect()\n })\n\n return {\n ariaLabels,\n emitOverlayClicked,\n isWaitingForLeave,\n modalContentRef,\n modalRef,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-modal {\n position: fixed;\n top: 0;\n left: 0;\n display: flex;\n align-items: flex-start;\n justify-content: flex-start;\n width: 100%;\n height: 100%;\n z-index: 1;\n}\n\n.x-modal__content {\n display: flex;\n flex-flow: column nowrap;\n z-index: 1;\n}\n\n.x-modal__overlay {\n width: 100%;\n height: 100%;\n position: absolute;\n background-color: rgb(0, 0, 0);\n opacity: 0.3;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThe `BaseModal` is a simple component that serves to create complex modals. Its open state has to be\npassed via prop. There is a prop, `referenceSelector`, used to place the modal under some element\ninstead of set the top of the element directly. It also accepts an animation to use for opening &\nclosing.\n\nIt emits a `click:overlay` event when any part out of the content is clicked, but only if the modal\nis open.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n### Customized usage\n\n#### Customizing the content with classes\n\nThe `contentClass` prop can be used to add classes to the modal content.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n contentClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n#### Customizing the overlay with classes\n\nThe `overlayClass` prop can be used to add classes to the modal overlay.\n\n```vue\n<template>\n <div>\n <button @click=\"open = true\">Open modal</button>\n <BaseModal\n :animation=\"fadeAndSlide\"\n :open=\"open\"\n @click:overlay=\"open = false\"\n referenceSelector=\".header\"\n overlayClass=\"x-bg-neutral-75\"\n >\n <h1>Hello</h1>\n <p>The modal is working</p>\n <button @click=\"open = false\">Close modal</button>\n </BaseModal>\n </div>\n</template>\n\n<script setup>\nimport { ref } from 'vue'\nimport { BaseModal, FadeAndSlide } from '@empathyco/x-components'\nconst open = ref(false)\nconst fadeAndSlide = FadeAndSlide\n</script>\n```\n\n#### Not locking the page scroll\n\nBy default (`scrollLock` is `true`) the modal sets `overflow: hidden` on the `body` and `html`\nelements while it is open, and restores them when it closes. Set the `scrollLock` prop to `false`\nto keep the page scrollable. The prop can be toggled while the modal is open.\n\n```vue\n<BaseModal :open=\"open\" :scroll-lock=\"false\">\n <p>The page behind can still be scrolled.</p>\n</BaseModal>\n```\n\n## Vue Events\n\nA list of events that the component will emit:\n\n- `click:overlay`: the event is emitted after the user clicks any part out of the content but only\n if the modal is open. The event payload is the mouse event that triggers it.\n- `focusin:body`: the event is emitted after the user focus in any part out of the content but only\n if the modal is open. The event payload is the focus event that triggers it.\n</docs>\n"],"names":["NoAnimation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA;;;;;AAKE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,KAAK,EAAE;;AAEL,QAAA,IAAI,EAAE;AACJ,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;;AAGE;AACF,QAAA,WAAW,EAAE;AACX,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACD;;;;AAIE;AACF,QAAA,iBAAiB,EAAE,MAAM;;AAEzB,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAMA,WAAW;AAC3B,SAAA;AACD;;;AAGE;AACF,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAM,IAAI;AACpB,SAAA;AACD;;;;AAIE;AACF,QAAA,UAAU,EAAE;AACV,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;;AAED,QAAA,YAAY,EAAE,MAAM;;AAEpB,QAAA,YAAY,EAAE,MAAM;AACrB,KAAA;AACD,IAAA,KAAK,EAAE,CAAC,eAAe,EAAE,cAAc,CAAC;AACxC,IAAA,KAAK,CAAC,KAAK,EAAE,EAAE,IAAG,EAAG,EAAA;AACnB,QAAA,MAAM,UAAS,GAAI,sBAAsB,CAAC,WAAW,CAAA;;AAGrD,QAAA,MAAM,QAAO,GAAI,GAAG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Ac,CAAC,UAAU,EAAC;AAC5B,QAAA,CAAC,CAAA;QAED,OAAO;YACL,UAAU;YACV,kBAAkB;YAClB,iBAAiB;YACjB,eAAe;YACf,QAAQ;SACV;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empathyco/x-components",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.8.0",
|
|
4
4
|
"description": "Empathy X Components",
|
|
5
5
|
"author": "Empathy Systems Corporation S.L.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -67,10 +67,10 @@
|
|
|
67
67
|
"vuex": "4.0.2"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@empathyco/x-adapter": "8.2.
|
|
71
|
-
"@empathyco/x-adapter-platform": "2.0.
|
|
72
|
-
"@empathyco/x-types": "11.0.
|
|
73
|
-
"@empathyco/x-utils": "1.1.
|
|
70
|
+
"@empathyco/x-adapter": "8.2.5",
|
|
71
|
+
"@empathyco/x-adapter-platform": "2.0.5",
|
|
72
|
+
"@empathyco/x-types": "11.0.5",
|
|
73
|
+
"@empathyco/x-utils": "1.1.5",
|
|
74
74
|
"@vue/devtools-api": "~6.6.4",
|
|
75
75
|
"@vueuse/core": "~12.8.2",
|
|
76
76
|
"js-md5": "~0.9.2",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@babel/preset-env": "8.0.7",
|
|
85
|
-
"@empathyco/x-design-system": "1.2.
|
|
85
|
+
"@empathyco/x-design-system": "1.2.5",
|
|
86
86
|
"@microsoft/api-documenter": "7.30.19",
|
|
87
87
|
"@microsoft/api-extractor": "7.60.0",
|
|
88
88
|
"@tailwindcss/vite": "4.3.3",
|
|
@@ -117,5 +117,5 @@
|
|
|
117
117
|
"access": "public",
|
|
118
118
|
"directory": "dist"
|
|
119
119
|
},
|
|
120
|
-
"gitHead": "
|
|
120
|
+
"gitHead": "317191ef5637e5f390f558ced832dee6b57df8cc"
|
|
121
121
|
}
|
|
@@ -10054,7 +10054,16 @@
|
|
|
10054
10054
|
},
|
|
10055
10055
|
{
|
|
10056
10056
|
"kind": "Content",
|
|
10057
|
-
"text": "<{}, {}, any>;\n };\n
|
|
10057
|
+
"text": "<{}, {}, any>;\n };\n scrollLock: {\n type: "
|
|
10058
|
+
},
|
|
10059
|
+
{
|
|
10060
|
+
"kind": "Reference",
|
|
10061
|
+
"text": "BooleanConstructor",
|
|
10062
|
+
"canonicalReference": "!BooleanConstructor:interface"
|
|
10063
|
+
},
|
|
10064
|
+
{
|
|
10065
|
+
"kind": "Content",
|
|
10066
|
+
"text": ";\n default: boolean;\n };\n contentClass: "
|
|
10058
10067
|
},
|
|
10059
10068
|
{
|
|
10060
10069
|
"kind": "Reference",
|
|
@@ -10297,7 +10306,16 @@
|
|
|
10297
10306
|
},
|
|
10298
10307
|
{
|
|
10299
10308
|
"kind": "Content",
|
|
10300
|
-
"text": "<{}, {}, any>;\n };\n
|
|
10309
|
+
"text": "<{}, {}, any>;\n };\n scrollLock: {\n type: "
|
|
10310
|
+
},
|
|
10311
|
+
{
|
|
10312
|
+
"kind": "Reference",
|
|
10313
|
+
"text": "BooleanConstructor",
|
|
10314
|
+
"canonicalReference": "!BooleanConstructor:interface"
|
|
10315
|
+
},
|
|
10316
|
+
{
|
|
10317
|
+
"kind": "Content",
|
|
10318
|
+
"text": ";\n default: boolean;\n };\n contentClass: "
|
|
10301
10319
|
},
|
|
10302
10320
|
{
|
|
10303
10321
|
"kind": "Reference",
|
|
@@ -10360,7 +10378,7 @@
|
|
|
10360
10378
|
},
|
|
10361
10379
|
{
|
|
10362
10380
|
"kind": "Content",
|
|
10363
|
-
"text": "<string, any>;\n}, {}, {}, {}, string, import(\"vue\")."
|
|
10381
|
+
"text": "<string, any>;\n scrollLock: boolean;\n}, {}, {}, {}, string, import(\"vue\")."
|
|
10364
10382
|
},
|
|
10365
10383
|
{
|
|
10366
10384
|
"kind": "Reference",
|
|
@@ -10378,7 +10396,7 @@
|
|
|
10378
10396
|
"name": "BaseModal",
|
|
10379
10397
|
"variableTypeTokenRange": {
|
|
10380
10398
|
"startIndex": 1,
|
|
10381
|
-
"endIndex":
|
|
10399
|
+
"endIndex": 102
|
|
10382
10400
|
}
|
|
10383
10401
|
},
|
|
10384
10402
|
{
|
|
@@ -1230,6 +1230,10 @@ overlayAnimation: {
|
|
|
1230
1230
|
type: (StringConstructor | ObjectConstructor | FunctionConstructor)[];
|
|
1231
1231
|
default: () => DefineComponent< {}, {}, any>;
|
|
1232
1232
|
};
|
|
1233
|
+
scrollLock: {
|
|
1234
|
+
type: BooleanConstructor;
|
|
1235
|
+
default: boolean;
|
|
1236
|
+
};
|
|
1233
1237
|
contentClass: StringConstructor;
|
|
1234
1238
|
overlayClass: StringConstructor;
|
|
1235
1239
|
}>, {
|
|
@@ -1258,6 +1262,10 @@ overlayAnimation: {
|
|
|
1258
1262
|
type: (StringConstructor | ObjectConstructor | FunctionConstructor)[];
|
|
1259
1263
|
default: () => DefineComponent< {}, {}, any>;
|
|
1260
1264
|
};
|
|
1265
|
+
scrollLock: {
|
|
1266
|
+
type: BooleanConstructor;
|
|
1267
|
+
default: boolean;
|
|
1268
|
+
};
|
|
1261
1269
|
contentClass: StringConstructor;
|
|
1262
1270
|
overlayClass: StringConstructor;
|
|
1263
1271
|
}>> & Readonly<{
|
|
@@ -1267,6 +1275,7 @@ overlayClass: StringConstructor;
|
|
|
1267
1275
|
focusOnOpen: boolean;
|
|
1268
1276
|
animation: string | Function | Record<string, any>;
|
|
1269
1277
|
overlayAnimation: string | Function | Record<string, any>;
|
|
1278
|
+
scrollLock: boolean;
|
|
1270
1279
|
}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
|
|
1271
1280
|
|
|
1272
1281
|
export { BasePlaceholderImage }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-teleport.vue?vue&type=script&lang.d.ts","sourceRoot":"","sources":["../../../../src/components/base-teleport.vue?vue&type=script&lang.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;;IAe/B,6EAA6E;;cAEjD,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC;;;IAGtD;;;;;;;OAOG;;cAEe,QAAQ,CACtB,aAAa,GAAG,YAAY,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CACtE;;;IAGH,2DAA2D;;;;;IAK3D,kDAAkD;eAC7B,QAAQ,CAAC,MAAM,GAAG,mBAAmB,CAAC;;;;IAzB3D,6EAA6E;;cAEjD,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC;;;IAGtD;;;;;;;OAOG;;cAEe,QAAQ,CACtB,aAAa,GAAG,YAAY,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CACtE;;;IAGH,2DAA2D;;;;;IAK3D,kDAAkD;eAC7B,QAAQ,CAAC,MAAM,GAAG,mBAAmB,CAAC;;;;;AA5B/D,
|
|
1
|
+
{"version":3,"file":"base-teleport.vue?vue&type=script&lang.d.ts","sourceRoot":"","sources":["../../../../src/components/base-teleport.vue?vue&type=script&lang.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;;IAe/B,6EAA6E;;cAEjD,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC;;;IAGtD;;;;;;;OAOG;;cAEe,QAAQ,CACtB,aAAa,GAAG,YAAY,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CACtE;;;IAGH,2DAA2D;;;;;IAK3D,kDAAkD;eAC7B,QAAQ,CAAC,MAAM,GAAG,mBAAmB,CAAC;;;;IAzB3D,6EAA6E;;cAEjD,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC;;;IAGtD;;;;;;;OAOG;;cAEe,QAAQ,CACtB,aAAa,GAAG,YAAY,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CACtE;;;IAGH,2DAA2D;;;;;IAK3D,kDAAkD;eAC7B,QAAQ,CAAC,MAAM,GAAG,mBAAmB,CAAC;;;;;AA5B/D,wBA4JE"}
|
|
@@ -37,6 +37,15 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
37
37
|
type: (StringConstructor | ObjectConstructor | FunctionConstructor)[];
|
|
38
38
|
default: () => import("vue").DefineComponent<{}, {}, any>;
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Determines if the scroll of the body and the window is disabled while the modal is open.
|
|
42
|
+
* Set it to `false` for modals that must not lock the page scroll. It can be toggled while the
|
|
43
|
+
* modal is open.
|
|
44
|
+
*/
|
|
45
|
+
scrollLock: {
|
|
46
|
+
type: BooleanConstructor;
|
|
47
|
+
default: boolean;
|
|
48
|
+
};
|
|
40
49
|
/** Class inherited by content element. */
|
|
41
50
|
contentClass: StringConstructor;
|
|
42
51
|
/** Class inherited by overlay element. */
|
|
@@ -82,6 +91,15 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
82
91
|
type: (StringConstructor | ObjectConstructor | FunctionConstructor)[];
|
|
83
92
|
default: () => import("vue").DefineComponent<{}, {}, any>;
|
|
84
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* Determines if the scroll of the body and the window is disabled while the modal is open.
|
|
96
|
+
* Set it to `false` for modals that must not lock the page scroll. It can be toggled while the
|
|
97
|
+
* modal is open.
|
|
98
|
+
*/
|
|
99
|
+
scrollLock: {
|
|
100
|
+
type: BooleanConstructor;
|
|
101
|
+
default: boolean;
|
|
102
|
+
};
|
|
85
103
|
/** Class inherited by content element. */
|
|
86
104
|
contentClass: StringConstructor;
|
|
87
105
|
/** Class inherited by overlay element. */
|
|
@@ -93,6 +111,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
93
111
|
focusOnOpen: boolean;
|
|
94
112
|
animation: string | Function | Record<string, any>;
|
|
95
113
|
overlayAnimation: string | Function | Record<string, any>;
|
|
114
|
+
scrollLock: boolean;
|
|
96
115
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
97
116
|
export default _default;
|
|
98
117
|
//# sourceMappingURL=base-modal.vue?vue&type=script&lang.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-modal.vue?vue&type=script&lang.d.ts","sourceRoot":"","sources":["../../../../../src/components/modals/base-modal.vue?vue&type=script&lang.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;;IAIC,8CAA8C;;;;;IAK9C;;;OAGG;;;;;IAKH;;;;OAIG;;IAEH,8FAA8F;;;;;IAK9F;;;OAGG;;;;;IAKH,0CAA0C;;IAE1C,0CAA0C;;;;;;
|
|
1
|
+
{"version":3,"file":"base-modal.vue?vue&type=script&lang.d.ts","sourceRoot":"","sources":["../../../../../src/components/modals/base-modal.vue?vue&type=script&lang.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;;IAIC,8CAA8C;;;;;IAK9C;;;OAGG;;;;;IAKH;;;;OAIG;;IAEH,8FAA8F;;;;;IAK9F;;;OAGG;;;;;IAKH;;;;OAIG;;;;;IAKH,0CAA0C;;IAE1C,0CAA0C;;;;;;gCAkDP,KAAK;;;;;IA7FxC,8CAA8C;;;;;IAK9C;;;OAGG;;;;;IAKH;;;;OAIG;;IAEH,8FAA8F;;;;;IAK9F;;;OAGG;;;;;IAKH;;;;OAIG;;;;;IAKH,0CAA0C;;IAE1C,0CAA0C;;;;;;;;;;;AA9C9C,wBA4OE"}
|