@empathyco/x-components 6.0.0-alpha.26 → 6.0.0-alpha.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/core/index.js.map +1 -1
  3. package/design-system/deprecated-full-theme.css +2052 -2051
  4. package/docs/API-reference/api/x-components.md +2 -1
  5. package/docs/API-reference/api/x-components.relatedprompt.md +27 -11
  6. package/docs/API-reference/api/x-components.relatedpromptsmutations.md +1 -0
  7. package/docs/API-reference/api/x-components.relatedpromptsmutations.resetselectedprompt.md +17 -0
  8. package/docs/API-reference/api/x-components.relatedpromptsmutations.setrelatedpromptsproducts.md +1 -1
  9. package/docs/API-reference/api/x-components.relatedpromptstaglist.md +22 -0
  10. package/docs/API-reference/components/related-prompts/x-components.related-prompt.md +11 -14
  11. package/docs/API-reference/components/related-prompts/x-components.related-prompts-tag-list.md +23 -0
  12. package/js/components/modals/base-modal.vue.js.map +1 -1
  13. package/js/components/modals/base-modal.vue2.js +13 -6
  14. package/js/components/modals/base-modal.vue2.js.map +1 -1
  15. package/js/index.js +1 -0
  16. package/js/index.js.map +1 -1
  17. package/js/x-modules/related-prompts/components/related-prompt.vue.js +43 -81
  18. package/js/x-modules/related-prompts/components/related-prompt.vue.js.map +1 -1
  19. package/js/x-modules/related-prompts/components/related-prompt.vue2.js +34 -26
  20. package/js/x-modules/related-prompts/components/related-prompt.vue2.js.map +1 -1
  21. package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue.js +80 -0
  22. package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue.js.map +1 -0
  23. package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue2.js +55 -0
  24. package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue2.js.map +1 -0
  25. package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue3.js +7 -0
  26. package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue3.js.map +1 -0
  27. package/js/x-modules/related-prompts/store/module.js +9 -1
  28. package/js/x-modules/related-prompts/store/module.js.map +1 -1
  29. package/js/x-modules/related-prompts/wiring.js +10 -0
  30. package/js/x-modules/related-prompts/wiring.js.map +1 -1
  31. package/package.json +2 -2
  32. package/related-prompts/index.js +1 -0
  33. package/report/x-components.api.json +209 -14
  34. package/report/x-components.api.md +47 -10
  35. package/types/components/modals/base-modal.vue.d.ts.map +1 -1
  36. package/types/x-modules/related-prompts/components/index.d.ts +1 -0
  37. package/types/x-modules/related-prompts/components/index.d.ts.map +1 -1
  38. package/types/x-modules/related-prompts/components/related-prompt.vue.d.ts +27 -13
  39. package/types/x-modules/related-prompts/components/related-prompt.vue.d.ts.map +1 -1
  40. package/types/x-modules/related-prompts/components/related-prompts-tag-list.vue.d.ts +14 -0
  41. package/types/x-modules/related-prompts/components/related-prompts-tag-list.vue.d.ts.map +1 -0
  42. package/types/x-modules/related-prompts/store/module.d.ts.map +1 -1
  43. package/types/x-modules/related-prompts/store/types.d.ts +5 -1
  44. package/types/x-modules/related-prompts/store/types.d.ts.map +1 -1
  45. package/types/x-modules/related-prompts/wiring.d.ts +6 -0
  46. package/types/x-modules/related-prompts/wiring.d.ts.map +1 -1
  47. package/js/x-modules/related-prompts/components/related-prompt.vue3.js +0 -7
  48. package/js/x-modules/related-prompts/components/related-prompt.vue3.js.map +0 -1
@@ -484,9 +484,10 @@ X-Components is a library usable everywhere not only for search experiences.
484
484
  | [Redirection](./x-components.redirection.md) | A redirection is a component that sends the user to a link in the website. It is helpful when there are queries like <code>help</code>, <code>shipping costs</code>, <code>my account</code>, where a link to a section in the website will be more helpful than the set of results returned. |
485
485
  | [refreshHistoryQueriesSession](./x-components.refreshhistoryqueriessession.md) | Triggers a session refresh, extending its validity for the time configured in the [HistoryQueriesConfig.sessionTTLInMs](./x-components.historyqueriesconfig.sessionttlinms.md)<!-- -->. |
486
486
  | [refreshSession](./x-components.refreshsession.md) | Default implementation for the [HistoryQueriesActions.refreshSession()](./x-components.historyqueriesactions.refreshsession.md)<!-- -->. |
487
- | [RelatedPrompt](./x-components.relatedprompt.md) | <p>This component shows a suggested related prompt with the associated next queries. It allows to select one of the next query and show it.</p><p>It provide slots to customize the header, the next queries list, the individual next query inside the list and the selected query.</p> |
487
+ | [RelatedPrompt](./x-components.relatedprompt.md) | <p>This component shows a suggested related prompt.</p><p>It provides a slot to customize the related prompt button information.</p> |
488
488
  | [relatedPromptRequest](./x-components.relatedpromptrequest.md) | Default implementation for the [RelatedPromptsGetters.request](./x-components.relatedpromptsgetters.request.md) getter. |
489
489
  | [RelatedPromptsList](./x-components.relatedpromptslist.md) | Component that inserts groups of related prompts in different positions of the injected search items list, based on the provided configuration. |
490
+ | [RelatedPromptsTagList](./x-components.relatedpromptstaglist.md) | |
490
491
  | [relatedPromptsXModule](./x-components.relatedpromptsxmodule.md) | Related Prompts [XModule](./x-components.xmodule.md) implementation. This module is auto-registered as soon as you import any component from the <code>related-prompts</code> entry point. |
491
492
  | [RelatedTag](./x-components.relatedtag.md) | This component renders a related tag for a query. A related tag is a descriptive keyword related to the current query to fine-tune the search. For example, if you are searching for \*lego\*, a related tag could be \*city\*, refining the search with \*lego city\*. |
492
493
  | [relatedTags](./x-components.relatedtags.md) | Default implementation for the [RelatedTagsGetters.relatedTags](./x-components.relatedtagsgetters.relatedtags.md) getter. |
@@ -4,9 +4,9 @@
4
4
 
5
5
  ## RelatedPrompt variable
6
6
 
7
- This component shows a suggested related prompt with the associated next queries. It allows to select one of the next query and show it.
7
+ This component shows a suggested related prompt.
8
8
 
9
- It provide slots to customize the header, the next queries list, the individual next query inside the list and the selected query.
9
+ It provides a slot to customize the related prompt button information.
10
10
 
11
11
  **Signature:**
12
12
 
@@ -16,23 +16,39 @@ _default: import("vue").DefineComponent<{
16
16
  type: PropType<RelatedPrompt>;
17
17
  required: true;
18
18
  };
19
- nextQueryButtonClass: {
20
- type: StringConstructor;
21
- default: string;
19
+ isPromptVisible: {
20
+ type: BooleanConstructor;
21
+ default: boolean;
22
+ };
23
+ isSelected: {
24
+ type: BooleanConstructor;
25
+ default: boolean;
26
+ };
27
+ index: {
28
+ type: NumberConstructor;
29
+ required: true;
22
30
  };
23
31
  }, {
24
- selectedNextQuery: import("vue").Ref<string>;
25
- onClick: (nextQuery: string) => void;
32
+ toggleSuggestion: (index: number) => void;
26
33
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
27
34
  relatedPrompt: {
28
35
  type: PropType<RelatedPrompt>;
29
36
  required: true;
30
37
  };
31
- nextQueryButtonClass: {
32
- type: StringConstructor;
33
- default: string;
38
+ isPromptVisible: {
39
+ type: BooleanConstructor;
40
+ default: boolean;
41
+ };
42
+ isSelected: {
43
+ type: BooleanConstructor;
44
+ default: boolean;
45
+ };
46
+ index: {
47
+ type: NumberConstructor;
48
+ required: true;
34
49
  };
35
50
  }>>, {
36
- nextQueryButtonClass: string;
51
+ isPromptVisible: boolean;
52
+ isSelected: boolean;
37
53
  }, {}>
38
54
  ```
@@ -18,6 +18,7 @@ export interface RelatedPromptsMutations extends StatusMutations, QueryMutations
18
18
  | Method | Description |
19
19
  | --- | --- |
20
20
  | [resetRelatedPromptsState()](./x-components.relatedpromptsmutations.resetrelatedpromptsstate.md) | Resets the related prompts state. |
21
+ | [resetSelectedPrompt()](./x-components.relatedpromptsmutations.resetselectedprompt.md) | Resets the selected related prompt number. |
21
22
  | [setParams(params)](./x-components.relatedpromptsmutations.setparams.md) | Sets the extra params of the module. |
22
23
  | [setRelatedPromptsProducts(products)](./x-components.relatedpromptsmutations.setrelatedpromptsproducts.md) | Sets the related prompts of the module. |
23
24
  | [setSelectedPrompt(index)](./x-components.relatedpromptsmutations.setselectedprompt.md) | Sets the selected related prompt. |
@@ -0,0 +1,17 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [@empathyco/x-components](./x-components.md) &gt; [RelatedPromptsMutations](./x-components.relatedpromptsmutations.md) &gt; [resetSelectedPrompt](./x-components.relatedpromptsmutations.resetselectedprompt.md)
4
+
5
+ ## RelatedPromptsMutations.resetSelectedPrompt() method
6
+
7
+ Resets the selected related prompt number.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ resetSelectedPrompt(): void;
13
+ ```
14
+ **Returns:**
15
+
16
+ void
17
+
@@ -16,7 +16,7 @@ setRelatedPromptsProducts(products: RelatedPrompt[]): void;
16
16
 
17
17
  | Parameter | Type | Description |
18
18
  | --- | --- | --- |
19
- | products | RelatedPrompt\[\] | |
19
+ | products | RelatedPrompt\[\] | The new related prompts to save to the state. |
20
20
 
21
21
  **Returns:**
22
22
 
@@ -0,0 +1,22 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [@empathyco/x-components](./x-components.md) &gt; [RelatedPromptsTagList](./x-components.relatedpromptstaglist.md)
4
+
5
+ ## RelatedPromptsTagList variable
6
+
7
+ **Signature:**
8
+
9
+ ```typescript
10
+ _default: import("vue").DefineComponent<{
11
+ buttonClass: StringConstructor;
12
+ }, {
13
+ arePromptsVisible: import("vue").Ref<boolean>;
14
+ hidePrompt: (index: number) => boolean;
15
+ isSelected: (index: number) => boolean;
16
+ relatedPrompts: import("vue").ComputedRef<any>;
17
+ selectedPrompt: import("vue").ComputedRef<any>;
18
+ slidingPanelContent: import("vue").Ref<Element | undefined>;
19
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
20
+ buttonClass: StringConstructor;
21
+ }>>, {}, {}>
22
+ ```
@@ -6,24 +6,21 @@ title: RelatedPrompt
6
6
 
7
7
  # RelatedPrompt
8
8
 
9
- This component shows a suggested related prompt with the associated next queries. It allows to
10
- select one of the next query and show it.
9
+ This component shows a suggested related prompt.
11
10
 
12
- It provide slots to customize the header, the next queries list, the individual next query inside
13
- the list and the selected query.
11
+ It provides a slot to customize the related prompt button information.
14
12
 
15
13
  ## Props
16
14
 
17
- | Name | Description | Type | Default |
18
- | --------------------------------- | ----------- | -------------------------- | -------------------------------- |
19
- | <code>relatedPrompt</code> | | <code>RelatedPrompt</code> | <code></code> |
20
- | <code>nextQueryButtonClass</code> | | <code>string</code> | <code>'x-button-outlined'</code> |
15
+ | Name | Description | Type | Default |
16
+ | ---------------------------- | ----------- | -------------------------- | ------------------ |
17
+ | <code>relatedPrompt</code> | | <code>RelatedPrompt</code> | <code></code> |
18
+ | <code>isPromptVisible</code> | | <code>boolean</code> | <code>false</code> |
19
+ | <code>isSelected</code> | | <code>boolean</code> | <code>false</code> |
20
+ | <code>index</code> | | <code>number</code> | <code></code> |
21
21
 
22
22
  ## Slots
23
23
 
24
- | Name | Description | Bindings<br />(name - type - description) |
25
- | --------------------------- | ----------- | ----------------------------------------- |
26
- | <code>header</code> | | |
27
- | <code>next-queries</code> | | |
28
- | <code>next-query</code> | | |
29
- | <code>selected-query</code> | | |
24
+ | Name | Description | Bindings<br />(name - type - description) |
25
+ | --------------------------------------- | ----------- | ----------------------------------------- |
26
+ | <code>related-prompt-button-info</code> | | None |
@@ -0,0 +1,23 @@
1
+ ---
2
+
3
+ title: RelatedPromptsTagList
4
+
5
+ ---
6
+
7
+ # RelatedPromptsTagList
8
+
9
+ ## Props
10
+
11
+ | Name | Description | Type | Default |
12
+ | ------------------------ | ----------- | ------------------- | ------------- |
13
+ | <code>buttonClass</code> | | <code>string</code> | <code></code> |
14
+
15
+ ## Slots
16
+
17
+ | Name | Description | Bindings<br />(name - type - description) |
18
+ | --------------------------------------- | ----------- | ----------------------------------------- |
19
+ | <code>header</code> | | None |
20
+ | <code>sliding-panel-left-button</code> | | None |
21
+ | <code>sliding-panel-content</code> | | None |
22
+ | <code>related-prompt-button</code> | | <br /><br /><br /> |
23
+ | <code>sliding-panel-right-button</code> | | None |
@@ -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 >\n <!-- @slot (Required) Modal container content -->\n <slot />\n </div>\n </component>\n <component :is=\"overlayAnimation\">\n <div\n v-if=\"open\"\n @click=\"emitOverlayClicked\"\n @keydown=\"emitOverlayClicked\"\n class=\"x-modal__overlay\"\n :class=\"overlayClass\"\n data-test=\"modal-overlay\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { defineComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';\n import { useDebounce } from '../../composables';\n import { AnimationProp } from '../../types';\n import { getTargetElement, FOCUSABLE_SELECTORS } from '../../utils';\n import { 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 */\n export 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 /** 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;\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 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 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 if (props.referenceSelector) {\n const element = document.querySelector(props.referenceSelector) as HTMLElement;\n if (element) {\n referenceElement = element;\n resizeObserver.observe(element);\n }\n }\n });\n\n onBeforeUnmount(() => {\n if (props.open) {\n removeBodyListeners();\n enableScroll();\n }\n resizeObserver.disconnect();\n });\n\n return {\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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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":["animation","_withDirectives","_openBlock","_createElementBlock","isWaitingForLeave","_createBlock","_withCtx","_normalizeClass","_renderSlot","_createCommentVNode","_resolveDynamicComponent","overlayClass"],"mappings":";;;;;MACyD,UAAe,GAAA;AAAA,EAAC,GAAA,EAAA,UAAA;AAAA,EAAA,KAAA,EAAA,SAAA;;;AACrE,SAAA,WAAA,CAAA,IAAA,EAAA,MAAA,EAFJ,MAGWA,EAAAA,MAAAA,EAAAA,KAAAA,EAAAA,QAAAA,EAAAA;SACJC,cAAY,EAAAC,SAAA,EAAA,EAAAC,kBAAA;AAAA,IAAEC,KAAAA;AAAAA,IAAAA,UAAAA;AAAAA,IAAAA;AAAAA,OAAAA,SAAAA,EACH,EAAAC,WAAA;AAAA,QAAED,uBAAAA,CAAAA,IAAAA,CAAAA,SAAAA,CAAAA;AAAAA,QAAAA;AAAAA,UAAAA,aAAAA,EAAAA,MAAAA,CAAAA,CAAAA,CAAAA,KAAAA,MAAAA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,MAAAA,KAAAA,IAAAA,CAAAA,iBAAAA,GAAAA,IAAAA,CAAAA;UALpB,YAiBY,EAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,C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,IAAA,CAAA,kBAAA,IAAA,IAAA,CAAA,kBAAA,CAAA,GAAA,IAAA,CAAA,CAAA;AAAA,cAAA,KAAA,EAAAJ,cAAA,CAAA,CAAA,kBAAA,EAAA,IAAA,CAAA,YAAA,CAAA,CAAA;AA1BjC,cAAA,WAAA,EAAA,eAAA;AAAA,aAAA;;;;AAAA,WAAA,IAAAE,kBAAA,CAAA,MAAA,EAAA,IAAA,CAAA;AAAA,SAAA,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 >\n <!-- @slot (Required) Modal container content -->\n <slot />\n </div>\n </component>\n <component :is=\"overlayAnimation\">\n <div\n v-if=\"open\"\n @click=\"emitOverlayClicked\"\n @keydown=\"emitOverlayClicked\"\n class=\"x-modal__overlay\"\n :class=\"overlayClass\"\n data-test=\"modal-overlay\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { defineComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';\n import { useDebounce } from '../../composables';\n import { AnimationProp } from '../../types';\n import { getTargetElement, FOCUSABLE_SELECTORS } from '../../utils';\n import { 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 */\n export 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 /** 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 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 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 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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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":["animation","_withDirectives","_openBlock","_createElementBlock","isWaitingForLeave","_createBlock","_withCtx","_normalizeClass","_renderSlot","_createCommentVNode","_resolveDynamicComponent","overlayClass"],"mappings":";;;;;MACyD,UAAe,GAAA;AAAA,EAAC,GAAA,EAAA,UAAA;AAAA,EAAA,KAAA,EAAA,SAAA;;;AACrE,SAAA,WAAA,CAAA,IAAA,EAAA,MAAA,EAFJ,MAGWA,EAAAA,MAAAA,EAAAA,KAAAA,EAAAA,QAAAA,EAAAA;SACJC,cAAY,EAAA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,OAAA,CAAA,MAAA;AAAA,UAAA,IAAA,CApBN,IAsBc,IAAAJ,SAAA,EAAA,EAAAC,kBAAA;AAAA,YAAA,KAAA;AAAA,YAAA;AAAA,cACL,GAAA,EAAA,CAAA;AAAA,cACD,OAAA,EAxBR,MAwBc,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KACEQ,IAAY,CAAA,kBAAA,IAAA,IAAA,CAAA,kBAAA,CAAA,GAAA,IAAA,CAAA,CAAA;AAAA,cACpB,SAAA,EAAS,OAAC,CAAe,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAA,IAAA,CAAA,kBAAA,IAAA,IAAA,CAAA,kBAAA,CAAA,GAAA,IAAA,CAAA,CAAA;AAAA,cAAA,KAAA,EAAAJ,cAAA,CAAA,CAAA,kBAAA,EAAA,IAAA,CAAA,YAAA,CAAA,CAAA;AA1BjC,cAAA,WAAA,EAAA,eAAA;AAAA,aAAA;;;;AAAA,WAAA,IAAAE,kBAAA,CAAA,MAAA,EAAA,IAAA,CAAA;AAAA,SAAA,CAAA;;;;;;;;;;;;;;;"}
@@ -188,13 +188,20 @@ var _sfc_main = defineComponent({
188
188
  syncBody(true);
189
189
  }
190
190
  resizeObserver = new ResizeObserver(debouncedUpdatePosition);
191
- if (props.referenceSelector) {
192
- const element = document.querySelector(props.referenceSelector);
193
- if (element) {
194
- referenceElement = element;
195
- resizeObserver.observe(element);
191
+ watch(() => props.referenceSelector, () => {
192
+ resizeObserver.disconnect();
193
+ if (props.referenceSelector) {
194
+ const element = document.querySelector(props.referenceSelector);
195
+ if (element) {
196
+ referenceElement = element;
197
+ resizeObserver.observe(element);
198
+ }
196
199
  }
197
- }
200
+ else {
201
+ referenceElement = undefined;
202
+ debouncedUpdatePosition();
203
+ }
204
+ }, { immediate: true });
198
205
  });
199
206
  onBeforeUnmount(() => {
200
207
  if (props.open) {
@@ -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 >\n <!-- @slot (Required) Modal container content -->\n <slot />\n </div>\n </component>\n <component :is=\"overlayAnimation\">\n <div\n v-if=\"open\"\n @click=\"emitOverlayClicked\"\n @keydown=\"emitOverlayClicked\"\n class=\"x-modal__overlay\"\n :class=\"overlayClass\"\n data-test=\"modal-overlay\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { defineComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';\n import { useDebounce } from '../../composables';\n import { AnimationProp } from '../../types';\n import { getTargetElement, FOCUSABLE_SELECTORS } from '../../utils';\n import { 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 */\n export 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 /** 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;\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 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 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 if (props.referenceSelector) {\n const element = document.querySelector(props.referenceSelector) as HTMLElement;\n if (element) {\n referenceElement = element;\n resizeObserver.observe(element);\n }\n }\n });\n\n onBeforeUnmount(() => {\n if (props.open) {\n removeBodyListeners();\n enableScroll();\n }\n resizeObserver.disconnect();\n });\n\n return {\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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCE;;;;;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,IAAG;AACd,SAAA;AACD;;;AAGE;AACF,QAAA,WAAW,EAAE;AACX,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,IAAG;AACb,SAAA;AACD;;;;AAIE;AACF,QAAA,iBAAiB,EAAE,MAAM;;AAEzB,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAMA,WAAU;AAC1B,SAAA;AACD;;;AAGE;AACF,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAM,IAAG;AACnB,SAAA;;AAED,QAAA,YAAY,EAAE,MAAM;;AAEpB,QAAA,YAAY,EAAE,MAAK;AACpB,KAAA;AACD,IAAA,KAAK,EAAE,CAAC,eAAe,EAAE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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 >\n <!-- @slot (Required) Modal container content -->\n <slot />\n </div>\n </component>\n <component :is=\"overlayAnimation\">\n <div\n v-if=\"open\"\n @click=\"emitOverlayClicked\"\n @keydown=\"emitOverlayClicked\"\n class=\"x-modal__overlay\"\n :class=\"overlayClass\"\n data-test=\"modal-overlay\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { defineComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';\n import { useDebounce } from '../../composables';\n import { AnimationProp } from '../../types';\n import { getTargetElement, FOCUSABLE_SELECTORS } from '../../utils';\n import { 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 */\n export 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 /** 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 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 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 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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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>\n import { BaseModal, FadeAndSlide } from '@empathyco/x-components';\n import Vue from 'vue';\n\n Vue.component('fadeAndSlide', FadeAndSlide);\n\n export default {\n components: {\n BaseModal\n },\n data() {\n return {\n open: false\n };\n }\n };\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCE;;;;;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,IAAG;AACd,SAAA;AACD;;;AAGE;AACF,QAAA,WAAW,EAAE;AACX,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,IAAG;AACb,SAAA;AACD;;;;AAIE;AACF,QAAA,iBAAiB,EAAE,MAAM;;AAEzB,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAMA,WAAU;AAC1B,SAAA;AACD;;;AAGE;AACF,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAM,IAAG;AACnB,SAAA;;AAED,QAAA,YAAY,EAAE,MAAM;;AAEpB,QAAA,YAAY,EAAE,MA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IAAI,EAAE;AACd,gBAAA,mBAAmB,EAAE,CAAA;AACrB,gBAAA,YAAY,EAAE,CAAA;AAChB,aAAA;YACA,cAAc,CAAC,UAAU,EAAE,CAAA;AAC7B,SAAC,CAAC,CAAA;QAEF,OAAO;YACL,kBAAkB;YAClB,iBAAiB;YACjB,eAAe;YACf,QAAO;SACR,CAAA;KACH;AACD,CAAA,CAAC;;;;"}
package/js/index.js CHANGED
@@ -331,6 +331,7 @@ export { recommendationsWiring, setRecommendationsExtraParams } from './x-module
331
331
  export { recommendationsXModule } from './x-modules/recommendations/x-module.js';
332
332
  export { default as RelatedPrompt } from './x-modules/related-prompts/components/related-prompt.vue.js';
333
333
  export { default as RelatedPromptsList } from './x-modules/related-prompts/components/related-prompts-list.vue.js';
334
+ export { default as RelatedPromptsTagList } from './x-modules/related-prompts/components/related-prompts-tag-list.vue.js';
334
335
  export { cancelFetchAndSaveRelatedPrompts, fetchAndSaveRelatedPrompts } from './x-modules/related-prompts/store/actions/fetch-and-save-related-prompts.action.js';
335
336
  export { fetchRelatedPrompts } from './x-modules/related-prompts/store/actions/fetch-related-prompts.action.js';
336
337
  export { request as relatedPromptRequest } from './x-modules/related-prompts/store/getters/request.getter.js';
package/js/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,90 +1,52 @@
1
1
  import _sfc_main from './related-prompt.vue2.js';
2
- import { resolveComponent, openBlock, createElementBlock, createElementVNode, renderSlot, createTextVNode, toDisplayString, createVNode, withCtx, Fragment, renderList, normalizeClass, createBlock } from 'vue';
3
- import './related-prompt.vue3.js';
2
+ import { resolveComponent, openBlock, createElementBlock, normalizeClass, renderSlot, createElementVNode, normalizeStyle, toDisplayString, createBlock } from 'vue';
4
3
  import _export_sfc from '../../../_virtual/_plugin-vue_export-helper.js';
5
4
 
6
- const _hoisted_1 = {
7
- class: "x-related-prompt",
8
- "data-test": "related-prompt"
9
- };
10
- const _hoisted_2 = { class: "x-related-prompt__info" };
11
- const _hoisted_3 = { class: "x-related-prompt__sliding-panel-content" };
12
- const _hoisted_4 = ["onClick"];
13
- const _hoisted_5 = { class: "x-related-prompt__query-preview" };
5
+ const _hoisted_1 = { class: "x-related-prompt__button-info" };
14
6
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
15
7
  const _component_CrossTinyIcon = resolveComponent("CrossTinyIcon");
16
8
  const _component_PlusIcon = resolveComponent("PlusIcon");
17
- const _component_SlidingPanel = resolveComponent("SlidingPanel");
18
- return openBlock(), createElementBlock("div", _hoisted_1, [
19
- createElementVNode("div", _hoisted_2, [
20
- renderSlot(_ctx.$slots, "header", {
21
- suggestionText: _ctx.relatedPrompt.suggestionText
22
- }, () => [
23
- createTextVNode(
24
- toDisplayString(_ctx.relatedPrompt.suggestionText),
25
- 1
26
- /* TEXT */
27
- )
28
- ], true),
29
- renderSlot(_ctx.$slots, "next-queries", {
30
- nextQueries: _ctx.relatedPrompt.nextQueries
31
- }, () => [
32
- createVNode(_component_SlidingPanel, { resetOnContentChange: false }, {
33
- default: withCtx(() => [
34
- createElementVNode("div", _hoisted_3, [
35
- (openBlock(true), createElementBlock(
36
- Fragment,
37
- null,
38
- renderList(_ctx.relatedPrompt.nextQueries, (nextQuery, index) => {
39
- return openBlock(), createElementBlock("button", {
40
- key: index,
41
- onClick: ($event) => _ctx.onClick(nextQuery),
42
- class: normalizeClass([
43
- "x-button",
44
- { "x-selected": _ctx.selectedNextQuery === nextQuery },
45
- _ctx.nextQueryButtonClass
46
- ])
47
- }, [
48
- renderSlot(_ctx.$slots, "next-query", { nextQuery }, () => [
49
- createElementVNode(
50
- "span",
51
- null,
52
- toDisplayString(nextQuery),
53
- 1
54
- /* TEXT */
55
- ),
56
- _ctx.selectedNextQuery === nextQuery ? (openBlock(), createBlock(_component_CrossTinyIcon, {
57
- key: 0,
58
- class: "x-icon"
59
- })) : (openBlock(), createBlock(_component_PlusIcon, {
60
- key: 1,
61
- class: "x-icon"
62
- }))
63
- ], true)
64
- ], 10, _hoisted_4);
65
- }),
66
- 128
67
- /* KEYED_FRAGMENT */
68
- ))
69
- ])
70
- ]),
71
- _: 3
72
- /* FORWARDED */
73
- })
74
- ], true)
75
- ]),
76
- createElementVNode("div", _hoisted_5, [
77
- renderSlot(_ctx.$slots, "selected-query", { selectedQuery: _ctx.selectedNextQuery }, () => [
78
- createTextVNode(
79
- toDisplayString(_ctx.selectedNextQuery),
80
- 1
81
- /* TEXT */
82
- )
83
- ], true)
84
- ])
85
- ]);
9
+ return openBlock(), createElementBlock(
10
+ "div",
11
+ {
12
+ onClick: _cache[0] || (_cache[0] = ($event) => _ctx.toggleSuggestion(_ctx.index)),
13
+ onKeydown: _cache[1] || (_cache[1] = ($event) => _ctx.toggleSuggestion(_ctx.index)),
14
+ class: normalizeClass(["x-related-prompt__button", [{ "x-related-prompt-selected__button": _ctx.isSelected }]]),
15
+ role: "button",
16
+ "aria-pressed": "true",
17
+ tabindex: "0"
18
+ },
19
+ [
20
+ renderSlot(_ctx.$slots, "related-prompt-button-info", {}, () => [
21
+ createElementVNode("div", _hoisted_1, [
22
+ createElementVNode(
23
+ "span",
24
+ {
25
+ class: normalizeClass(["x-typewritter-initial", [{ "x-typewritter-animation": _ctx.isPromptVisible }]]),
26
+ style: normalizeStyle({
27
+ animationDelay: `${_ctx.index * 0.4 + 0.05}s`,
28
+ "--suggestion-text-length": _ctx.relatedPrompt.suggestionText.length
29
+ })
30
+ },
31
+ toDisplayString(_ctx.relatedPrompt.suggestionText),
32
+ 7
33
+ /* TEXT, CLASS, STYLE */
34
+ )
35
+ ]),
36
+ _ctx.isSelected ? (openBlock(), createBlock(_component_CrossTinyIcon, {
37
+ key: 0,
38
+ class: "x-icon-lg"
39
+ })) : (openBlock(), createBlock(_component_PlusIcon, {
40
+ key: 1,
41
+ class: "x-icon-lg"
42
+ }))
43
+ ])
44
+ ],
45
+ 34
46
+ /* CLASS, NEED_HYDRATION */
47
+ );
86
48
  }
87
- var relatedPrompt = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-44e318df"]]);
49
+ var RelatedPrompt = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
88
50
 
89
- export { relatedPrompt as default };
51
+ export { RelatedPrompt as default };
90
52
  //# sourceMappingURL=related-prompt.vue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"related-prompt.vue.js","sources":["../../../../../src/x-modules/related-prompts/components/related-prompt.vue"],"sourcesContent":["<template>\n <div class=\"x-related-prompt\" data-test=\"related-prompt\">\n <div class=\"x-related-prompt__info\">\n <slot name=\"header\" :suggestionText=\"relatedPrompt.suggestionText\">\n {{ relatedPrompt.suggestionText }}\n </slot>\n <slot name=\"next-queries\" :nextQueries=\"relatedPrompt.nextQueries\">\n <SlidingPanel :resetOnContentChange=\"false\">\n <div class=\"x-related-prompt__sliding-panel-content\">\n <button\n v-for=\"(nextQuery, index) in relatedPrompt.nextQueries\"\n :key=\"index\"\n @click=\"onClick(nextQuery)\"\n :class=\"[\n 'x-button',\n { 'x-selected': selectedNextQuery === nextQuery },\n nextQueryButtonClass\n ]\"\n >\n <slot name=\"next-query\" :nextQuery=\"nextQuery\">\n <span>{{ nextQuery }}</span>\n <CrossTinyIcon v-if=\"selectedNextQuery === nextQuery\" class=\"x-icon\" />\n <PlusIcon v-else class=\"x-icon\" />\n </slot>\n </button>\n </div>\n </SlidingPanel>\n </slot>\n </div>\n <div class=\"x-related-prompt__query-preview\">\n <slot name=\"selected-query\" :selectedQuery=\"selectedNextQuery\">\n {{ selectedNextQuery }}\n </slot>\n </div>\n </div>\n</template>\n<script lang=\"ts\">\n import { defineComponent, PropType, ref } from 'vue';\n import { RelatedPrompt } from '@empathyco/x-types';\n import { relatedPromptsXModule } from '../x-module';\n import CrossTinyIcon from '../../../components/icons/cross-tiny.vue';\n import PlusIcon from '../../../components/icons/plus.vue';\n import SlidingPanel from '../../../components/sliding-panel.vue';\n\n /**\n * This component shows a suggested related prompt with the associated next queries.\n * It allows to select one of the next query and show it.\n *\n * It provide slots to customize the header, the next queries list,\n * the individual next query inside the list and the selected query.\n *\n * @public\n */\n export default defineComponent({\n name: 'RelatedPrompt',\n components: {\n SlidingPanel,\n CrossTinyIcon,\n PlusIcon\n },\n xModule: relatedPromptsXModule.name,\n props: {\n relatedPrompt: {\n type: Object as PropType<RelatedPrompt>,\n required: true\n },\n nextQueryButtonClass: {\n type: String,\n default: 'x-button-outlined'\n }\n },\n setup(props) {\n const selectedNextQuery = ref(props.relatedPrompt.nextQueries[0]);\n\n /**\n * Handles the click event on a next query button.\n *\n * @param nextQuery - The clicked next query.\n */\n function onClick(nextQuery: string): void {\n if (selectedNextQuery.value === nextQuery) {\n selectedNextQuery.value = '';\n } else {\n selectedNextQuery.value = nextQuery;\n }\n }\n\n return { selectedNextQuery, onClick };\n }\n });\n</script>\n<style lang=\"css\" scoped>\n .x-related-prompt__info {\n display: flex;\n flex-direction: column;\n }\n\n .x-related-prompt__sliding-panel-content {\n display: flex;\n gap: 8px;\n }\n</style>\n"],"names":["_resolveComponent","_openBlock","_createElementBlock","_createElementVNode","relatedPrompt","_renderSlot","_createTextVNode","_toDisplayString","_createVNode","_withCtx","_Fragment","_renderList","onClick","selectedNextQuery","nextQueryButtonClass","_createBlock"],"mappings":";;;;;MACgC,UAAU,GAAA;AAAA,EAAA,KAAA,EAAA,kBAAA;;;AAD1C,MAAA,UAAA,GAAA,EAAA,KAAA,EAAA,wBAAA,EAAA,CAAA;AA6BS,MAAA,UAAA,GAAA,EAAA,KAAA,EAAM,yCAAiC,EAAA,CAAA;;;;;;kCA5B9CA,gBAiCM,CAAA,cAAA,CAAA,CAAA;SA/BFC,SAEO,EAAA,EAAAC,kBAAA,CAAA,KAAA,EAAA,UAAA,EAAA;AAAA,IAAAC,kBAAA,CAF8BC,KAAc,EAAA,UAAA,EAAA;AAAA,MAE5CC,UAAA,CAAA,IAAA,CAAA,MAAA,EAAA,QAAA,EAAA;AAAA,QALb,cAIWD,EAAAA,IAAAA,CAAAA,aAAAA,CAAAA,cAAAA;AAAAA,OAAAA,EAAAA,MAAAA;AAEL,QAAAE,eAAA;AAAA,UAqBOC,eAAA,CAAA,IAAA,CAAA,aAAA,CAAA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A,CAAA;;wCACrC,EAAAA,WAAA,CAAA,mBAAA,EAAA;AAAA,wBAAA,GAAA,EAAA,CAAA;;;;;;;;;AAtB/C,aAAA,CAAA;AAAA,WAAA,CAAA;;;;AA6BI,OAAA,EAAA,IAAA,CAAA;AAAA,KAAA,CAAA;uBA7BJ,KA+BWF,EAAAA,UAAAA,EAAAA;AAAAA,MAAAA,UAAAA,CAAAA,IAAAA,CAAAA,MAAAA,EAAAA,gBAAAA,EAAAA,EAAAA,aAAAA,EAAAA,IAAAA,CAAAA,iBAAAA,EAAAA,EAAAA,MAAAA;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"related-prompt.vue.js","sources":["../../../../../src/x-modules/related-prompts/components/related-prompt.vue"],"sourcesContent":["<template>\n <div\n @click=\"toggleSuggestion(index)\"\n @keydown=\"toggleSuggestion(index)\"\n class=\"x-related-prompt__button\"\n :class=\"[{ 'x-related-prompt-selected__button': isSelected }]\"\n role=\"button\"\n aria-pressed=\"true\"\n tabindex=\"0\"\n >\n <slot name=\"related-prompt-button-info\">\n <div class=\"x-related-prompt__button-info\">\n <span\n class=\"x-typewritter-initial\"\n :class=\"[{ 'x-typewritter-animation': isPromptVisible }]\"\n :style=\"{\n animationDelay: `${index * 0.4 + 0.05}s`,\n '--suggestion-text-length': relatedPrompt.suggestionText.length\n }\"\n >\n {{ relatedPrompt.suggestionText }}\n </span>\n </div>\n <CrossTinyIcon v-if=\"isSelected\" class=\"x-icon-lg\" />\n <PlusIcon v-else class=\"x-icon-lg\" />\n </slot>\n </div>\n</template>\n<script lang=\"ts\">\n import { defineComponent, PropType } from 'vue';\n import { RelatedPrompt } from '@empathyco/x-types';\n import { relatedPromptsXModule } from '../x-module';\n import CrossTinyIcon from '../../../components/icons/cross-tiny.vue';\n import PlusIcon from '../../../components/icons/plus.vue';\n import { use$x } from '../../../composables/index';\n\n /**\n * This component shows a suggested related prompt.\n *\n * It provides a slot to customize the related prompt button information.\n *\n * @public\n */\n export default defineComponent({\n name: 'RelatedPrompt',\n components: {\n CrossTinyIcon,\n PlusIcon\n },\n xModule: relatedPromptsXModule.name,\n props: {\n relatedPrompt: {\n type: Object as PropType<RelatedPrompt>,\n required: true\n },\n isPromptVisible: {\n type: Boolean,\n default: false\n },\n isSelected: {\n type: Boolean,\n default: false\n },\n index: {\n type: Number,\n required: true\n }\n },\n setup() {\n const x = use$x();\n\n const toggleSuggestion = (index: number): void => {\n x.emit('UserSelectedARelatedPrompt', index);\n };\n\n return {\n toggleSuggestion\n };\n }\n });\n</script>\n"],"names":["_resolveComponent","_openBlock","_createElementBlock","_normalizeClass","_createElementVNode","index","_normalizeStyle","relatedPrompt","isSelected","_toDisplayString","_createBlock"],"mappings":";;;;;;;8BACEA,gBAyBM,CAAA,UAAA,CAAA,CAAA;SAvBHC,SAAO,EAAA,EAAAC,kBAAA;AAAA,IAAA,KAAA;AAAA,IAAA;AAAA,MACR,OAAA,EAJJ,qBAIU,CAA0B,CAAA,GAAA,CAAA,MAAA,KAAA,IAAA,CAAA,gBAAA,CAAA,IAAA,CAAA,KAAA,CAAA,CAAA;AAAA,MAEhC,WAAK,MAAQ,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,MAAA,KAAA,IAAA,CAAA,gBAAA,CAAA,IAAA,CAAA,KAAA,CAAA,CAAA;AAAA,MACb,KAAmB,EAAAC,cAAA,CAAA,CAAA,0BAAA,EAAA,CAAA,EAAA,mCAAA,EAAA,IAAA,CAAA,UAAA,EAAA,CAAA,CAAA,CAAA;AAAA,MACnB,IAAA,EAAA,QAAA;AAAA,MAAA,cAAA,EAAA,MAAA;AAEA,MAAA,QAAA,EAAA,GAAA;AAAA,KAAA;;iBAEI,IASO,CAAA,MAAA,EAAA,4BAAA,EAAA,EAAA,EAAA,MAAA;AAAA,QAAAC,kBAAA,CArBf,KAagB,EAAA,UAAA,EAAA;AAAA,UAAAA,kBAAA;AAbhB,YAAA,MAAA;AAAA,YAAA;AAAA,cAAA,KAAA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