@empathyco/x-components 9.2.0 → 9.3.1
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 +14 -0
- package/core/index.js +2 -0
- package/core/index.js.map +1 -1
- package/docs/API-reference/api/x-components.accessibility_key.md +11 -0
- package/docs/API-reference/api/x-components.aicarousel.md +4 -0
- package/docs/API-reference/api/x-components.arialabels.aicarousel.md +14 -0
- package/docs/API-reference/api/x-components.arialabels.basecolumnpickerdropdown.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.basecolumnpickerlist.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.basedropdown.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.baseeventsmodalclose.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.baseeventsmodalopen.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.basemodal.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.clearhistoryqueries.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.editablenumberrangefilter.md +14 -0
- package/docs/API-reference/api/x-components.arialabels.facets.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.filterssearch.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.historyqueriesswitch.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.historyquery.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.md +419 -0
- package/docs/API-reference/api/x-components.arialabels.pageloaderbutton.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.pageselector.md +16 -0
- package/docs/API-reference/api/x-components.arialabels.removehistoryquery.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.scrolltotop.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.searchinput.md +13 -0
- package/docs/API-reference/api/x-components.arialabels.sliderfilter.md +14 -0
- package/docs/API-reference/api/x-components.arialabels.sortdropdown.md +13 -0
- package/docs/API-reference/api/x-components.basecolumnpickerdropdown.md +3 -0
- package/docs/API-reference/api/x-components.basecolumnpickerlist.md +3 -0
- package/docs/API-reference/api/x-components.basedropdown.md +3 -2
- package/docs/API-reference/api/x-components.baseeventsmodalclose.md +3 -0
- package/docs/API-reference/api/x-components.baseeventsmodalopen.md +3 -0
- package/docs/API-reference/api/x-components.basemodal.md +3 -0
- package/docs/API-reference/api/x-components.clearhistoryqueries.md +3 -0
- package/docs/API-reference/api/x-components.editablenumberrangefilter.md +4 -2
- package/docs/API-reference/api/x-components.facets.md +3 -0
- package/docs/API-reference/api/x-components.filterssearch.md +3 -0
- package/docs/API-reference/api/x-components.historyqueriesswitch.md +3 -0
- package/docs/API-reference/api/x-components.historyquery.md +3 -0
- package/docs/API-reference/api/x-components.md +20 -0
- package/docs/API-reference/api/x-components.pageloaderbutton.md +3 -0
- package/docs/API-reference/api/x-components.pageselector.md +6 -0
- package/docs/API-reference/api/x-components.removehistoryquery.md +3 -0
- package/docs/API-reference/api/x-components.scrolltotop.md +3 -0
- package/docs/API-reference/api/x-components.searchinput.md +3 -0
- package/docs/API-reference/api/x-components.sliderfilter.md +4 -0
- package/docs/API-reference/api/x-components.sortdropdown.md +3 -0
- package/docs/API-reference/components/common/x-components.base-dropdown.md +0 -1
- package/js/components/base-dropdown.vue.js +1 -1
- package/js/components/base-dropdown.vue.js.map +1 -1
- package/js/components/base-dropdown.vue2.js +4 -3
- package/js/components/base-dropdown.vue2.js.map +1 -1
- package/js/components/column-picker/base-column-picker-dropdown.vue.js +2 -2
- package/js/components/column-picker/base-column-picker-dropdown.vue.js.map +1 -1
- package/js/components/column-picker/base-column-picker-dropdown.vue2.js +4 -1
- package/js/components/column-picker/base-column-picker-dropdown.vue2.js.map +1 -1
- package/js/components/column-picker/base-column-picker-list.vue.js +1 -1
- package/js/components/column-picker/base-column-picker-list.vue.js.map +1 -1
- package/js/components/column-picker/base-column-picker-list.vue2.js +4 -2
- package/js/components/column-picker/base-column-picker-list.vue2.js.map +1 -1
- package/js/components/modals/base-events-modal-close.vue.js +2 -2
- package/js/components/modals/base-events-modal-close.vue.js.map +1 -1
- package/js/components/modals/base-events-modal-close.vue2.js +4 -1
- package/js/components/modals/base-events-modal-close.vue2.js.map +1 -1
- package/js/components/modals/base-events-modal-open.vue.js +2 -2
- package/js/components/modals/base-events-modal-open.vue.js.map +1 -1
- package/js/components/modals/base-events-modal-open.vue2.js +4 -1
- package/js/components/modals/base-events-modal-open.vue2.js.map +1 -1
- package/js/components/modals/base-modal.vue.js +11 -16
- package/js/components/modals/base-modal.vue.js.map +1 -1
- package/js/components/modals/base-modal.vue2.js +4 -1
- package/js/components/modals/base-modal.vue2.js.map +1 -1
- package/js/components/page-loader-button.vue.js +2 -2
- package/js/components/page-loader-button.vue.js.map +1 -1
- package/js/components/page-loader-button.vue2.js +4 -1
- package/js/components/page-loader-button.vue2.js.map +1 -1
- package/js/components/page-selector.vue.js +12 -12
- package/js/components/page-selector.vue.js.map +1 -1
- package/js/components/page-selector.vue2.js +4 -1
- package/js/components/page-selector.vue2.js.map +1 -1
- package/js/components/sort/sort-dropdown.vue.js +2 -2
- package/js/components/sort/sort-dropdown.vue.js.map +1 -1
- package/js/components/sort/sort-dropdown.vue2.js +4 -1
- package/js/components/sort/sort-dropdown.vue2.js.map +1 -1
- package/js/index.js +2 -0
- package/js/index.js.map +1 -1
- package/js/types/accessibility.js +4 -0
- package/js/types/accessibility.js.map +1 -0
- package/js/utils/accessibility.js +55 -0
- package/js/utils/accessibility.js.map +1 -0
- package/js/x-installer/x-installer.js +4 -0
- package/js/x-installer/x-installer.js.map +1 -1
- package/js/x-modules/ai/components/ai-carousel.vue.js +8 -3
- package/js/x-modules/ai/components/ai-carousel.vue.js.map +1 -1
- package/js/x-modules/ai/components/ai-carousel.vue2.js +4 -1
- package/js/x-modules/ai/components/ai-carousel.vue2.js.map +1 -1
- package/js/x-modules/facets/components/facets/facets.vue.js +57 -51
- package/js/x-modules/facets/components/facets/facets.vue.js.map +1 -1
- package/js/x-modules/facets/components/facets/facets.vue2.js +4 -1
- package/js/x-modules/facets/components/facets/facets.vue2.js.map +1 -1
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue.js +2 -2
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue.js.map +1 -1
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue2.js +4 -5
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue2.js.map +1 -1
- package/js/x-modules/facets/components/filters/slider-filter.vue.js +4 -4
- package/js/x-modules/facets/components/filters/slider-filter.vue.js.map +1 -1
- package/js/x-modules/facets/components/filters/slider-filter.vue2.js +4 -1
- package/js/x-modules/facets/components/filters/slider-filter.vue2.js.map +1 -1
- package/js/x-modules/facets/components/lists/filters-search.vue.js +2 -2
- package/js/x-modules/facets/components/lists/filters-search.vue.js.map +1 -1
- package/js/x-modules/facets/components/lists/filters-search.vue2.js +4 -1
- package/js/x-modules/facets/components/lists/filters-search.vue2.js.map +1 -1
- package/js/x-modules/history-queries/components/clear-history-queries.vue.js +2 -2
- package/js/x-modules/history-queries/components/clear-history-queries.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/clear-history-queries.vue2.js +4 -1
- package/js/x-modules/history-queries/components/clear-history-queries.vue2.js.map +1 -1
- package/js/x-modules/history-queries/components/history-queries-switch.vue.js +2 -2
- package/js/x-modules/history-queries/components/history-queries-switch.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/history-queries-switch.vue2.js +4 -1
- package/js/x-modules/history-queries/components/history-queries-switch.vue2.js.map +1 -1
- package/js/x-modules/history-queries/components/history-query.vue.js +2 -1
- package/js/x-modules/history-queries/components/history-query.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/history-query.vue2.js +4 -1
- package/js/x-modules/history-queries/components/history-query.vue2.js.map +1 -1
- package/js/x-modules/history-queries/components/remove-history-query.vue.js +2 -2
- package/js/x-modules/history-queries/components/remove-history-query.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/remove-history-query.vue2.js +4 -1
- package/js/x-modules/history-queries/components/remove-history-query.vue2.js.map +1 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue.js +2 -2
- package/js/x-modules/scroll/components/scroll-to-top.vue.js.map +1 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue2.js +4 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue2.js.map +1 -1
- package/js/x-modules/search-box/components/search-input.vue.js +2 -2
- package/js/x-modules/search-box/components/search-input.vue.js.map +1 -1
- package/js/x-modules/search-box/components/search-input.vue2.js +4 -1
- package/js/x-modules/search-box/components/search-input.vue2.js.map +1 -1
- package/package.json +2 -2
- package/report/x-components.api.json +618 -41
- package/report/x-components.api.md +173 -11
- package/types/src/components/base-dropdown.vue.d.ts +3 -4
- package/types/src/components/base-dropdown.vue.d.ts.map +1 -1
- package/types/src/components/column-picker/base-column-picker-dropdown.vue.d.ts +3 -0
- package/types/src/components/column-picker/base-column-picker-dropdown.vue.d.ts.map +1 -1
- package/types/src/components/column-picker/base-column-picker-list.vue.d.ts +3 -0
- package/types/src/components/column-picker/base-column-picker-list.vue.d.ts.map +1 -1
- package/types/src/components/modals/base-events-modal-close.vue.d.ts +3 -0
- package/types/src/components/modals/base-events-modal-close.vue.d.ts.map +1 -1
- package/types/src/components/modals/base-events-modal-open.vue.d.ts +3 -0
- package/types/src/components/modals/base-events-modal-open.vue.d.ts.map +1 -1
- package/types/src/components/modals/base-modal.vue.d.ts +3 -0
- package/types/src/components/modals/base-modal.vue.d.ts.map +1 -1
- package/types/src/components/page-loader-button.vue.d.ts +3 -0
- package/types/src/components/page-loader-button.vue.d.ts.map +1 -1
- package/types/src/components/page-selector.vue.d.ts +6 -0
- package/types/src/components/page-selector.vue.d.ts.map +1 -1
- package/types/src/components/sort/sort-dropdown.vue.d.ts +3 -0
- package/types/src/components/sort/sort-dropdown.vue.d.ts.map +1 -1
- package/types/src/types/accessibility.d.ts +79 -0
- package/types/src/types/accessibility.d.ts.map +1 -0
- package/types/src/types/index.d.ts +1 -0
- package/types/src/types/index.d.ts.map +1 -1
- package/types/src/utils/accessibility.d.ts +20 -0
- package/types/src/utils/accessibility.d.ts.map +1 -0
- package/types/src/utils/index.d.ts +1 -0
- package/types/src/utils/index.d.ts.map +1 -1
- package/types/src/x-installer/x-installer.d.ts.map +1 -1
- package/types/src/x-modules/ai/components/ai-carousel.vue.d.ts +4 -0
- package/types/src/x-modules/ai/components/ai-carousel.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/facets/facets.vue.d.ts +3 -0
- package/types/src/x-modules/facets/components/facets/facets.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/filters/editable-number-range-filter.vue.d.ts +4 -2
- package/types/src/x-modules/facets/components/filters/editable-number-range-filter.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/filters/slider-filter.vue.d.ts +4 -0
- package/types/src/x-modules/facets/components/filters/slider-filter.vue.d.ts.map +1 -1
- package/types/src/x-modules/facets/components/lists/filters-search.vue.d.ts +3 -0
- package/types/src/x-modules/facets/components/lists/filters-search.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/clear-history-queries.vue.d.ts +3 -0
- package/types/src/x-modules/history-queries/components/clear-history-queries.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/history-queries-switch.vue.d.ts +3 -0
- package/types/src/x-modules/history-queries/components/history-queries-switch.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/history-query.vue.d.ts +3 -0
- package/types/src/x-modules/history-queries/components/history-query.vue.d.ts.map +1 -1
- package/types/src/x-modules/history-queries/components/remove-history-query.vue.d.ts +3 -0
- package/types/src/x-modules/history-queries/components/remove-history-query.vue.d.ts.map +1 -1
- package/types/src/x-modules/scroll/components/scroll-to-top.vue.d.ts +3 -0
- package/types/src/x-modules/scroll/components/scroll-to-top.vue.d.ts.map +1 -1
- package/types/src/x-modules/search-box/components/search-input.vue.d.ts +3 -0
- package/types/src/x-modules/search-box/components/search-input.vue.d.ts.map +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for default labels (moved verbatim from the SFC `DEFAULTS`
|
|
3
|
+
* constants). Every namespace has an explicit entry (even when empty) so the merge
|
|
4
|
+
* iterates all keys uniformly and a consumer override is never dropped.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_ARIA_LABELS = {
|
|
9
|
+
pageSelector: {
|
|
10
|
+
pagination: 'Pagination',
|
|
11
|
+
prevPage: 'Previous page',
|
|
12
|
+
nextPage: 'Next page',
|
|
13
|
+
numberPage: (page) => `Page ${page}`,
|
|
14
|
+
},
|
|
15
|
+
aiCarousel: { expand: 'Expand', collapse: 'Collapse' },
|
|
16
|
+
baseColumnPickerDropdown: { dropdown: 'Select number of columns' },
|
|
17
|
+
baseColumnPickerList: { button: (column) => `${column} columns` },
|
|
18
|
+
pageLoaderButton: { button: 'Load' },
|
|
19
|
+
baseModal: { modal: 'Base modal content' },
|
|
20
|
+
baseEventsModalOpen: { button: 'Open' },
|
|
21
|
+
baseEventsModalClose: { button: 'Close' },
|
|
22
|
+
sortDropdown: { dropdown: 'Select sorting' },
|
|
23
|
+
facets: { root: 'Facets' },
|
|
24
|
+
filtersSearch: { input: 'search into the filter values' },
|
|
25
|
+
sliderFilter: { min: 'minimum amount', max: 'maximum amount' },
|
|
26
|
+
editableNumberRangeFilter: { min: 'minimum amount', max: 'maximum amount' },
|
|
27
|
+
searchInput: { input: 'type your query here' },
|
|
28
|
+
clearHistoryQueries: { button: 'Clear all' },
|
|
29
|
+
historyQueriesSwitch: { root: "Queries' history" },
|
|
30
|
+
historyQuery: { removeButton: 'Remove' },
|
|
31
|
+
removeHistoryQuery: { button: 'remove' },
|
|
32
|
+
scrollToTop: { button: 'Scroll to top' },
|
|
33
|
+
baseDropdown: { toggleButton: '' },
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Merges the provided aria labels entries onto the defaults: for each known key the provided
|
|
37
|
+
* value wins, and unknown keys are ignored.
|
|
38
|
+
*
|
|
39
|
+
* @param labels - The aria labels entries to merge onto the defaults.
|
|
40
|
+
* @returns The fully resolved aria labels configuration.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
function mergeAccessibilityLabels(labels) {
|
|
45
|
+
return Object.fromEntries(Object.entries(DEFAULT_ARIA_LABELS).map(([namespace, defaults]) => [
|
|
46
|
+
namespace,
|
|
47
|
+
{
|
|
48
|
+
...defaults,
|
|
49
|
+
...labels[namespace],
|
|
50
|
+
},
|
|
51
|
+
]));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { DEFAULT_ARIA_LABELS, mergeAccessibilityLabels };
|
|
55
|
+
//# sourceMappingURL=accessibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessibility.js","sources":["../../../src/utils/accessibility.ts"],"sourcesContent":["import type { AriaLabels } from '../types/accessibility'\n\n/**\n * Single source of truth for default labels (moved verbatim from the SFC `DEFAULTS`\n * constants). Every namespace has an explicit entry (even when empty) so the merge\n * iterates all keys uniformly and a consumer override is never dropped.\n *\n * @internal\n */\nexport const DEFAULT_ARIA_LABELS: AriaLabels = {\n pageSelector: {\n pagination: 'Pagination',\n prevPage: 'Previous page',\n nextPage: 'Next page',\n numberPage: (page: number | string) => `Page ${page}`,\n },\n aiCarousel: { expand: 'Expand', collapse: 'Collapse' },\n baseColumnPickerDropdown: { dropdown: 'Select number of columns' },\n baseColumnPickerList: { button: (column: number) => `${column} columns` },\n pageLoaderButton: { button: 'Load' },\n baseModal: { modal: 'Base modal content' },\n baseEventsModalOpen: { button: 'Open' },\n baseEventsModalClose: { button: 'Close' },\n sortDropdown: { dropdown: 'Select sorting' },\n facets: { root: 'Facets' },\n filtersSearch: { input: 'search into the filter values' },\n sliderFilter: { min: 'minimum amount', max: 'maximum amount' },\n editableNumberRangeFilter: { min: 'minimum amount', max: 'maximum amount' },\n searchInput: { input: 'type your query here' },\n clearHistoryQueries: { button: 'Clear all' },\n historyQueriesSwitch: { root: \"Queries' history\" },\n historyQuery: { removeButton: 'Remove' },\n removeHistoryQuery: { button: 'remove' },\n scrollToTop: { button: 'Scroll to top' },\n baseDropdown: { toggleButton: '' },\n}\n\n/**\n * Merges the provided aria labels entries onto the defaults: for each known key the provided\n * value wins, and unknown keys are ignored.\n *\n * @param labels - The aria labels entries to merge onto the defaults.\n * @returns The fully resolved aria labels configuration.\n *\n * @internal\n */\nexport function mergeAccessibilityLabels(labels: AriaLabels): AriaLabels {\n return Object.fromEntries(\n Object.entries(DEFAULT_ARIA_LABELS).map(([namespace, defaults]) => [\n namespace,\n {\n ...defaults,\n ...labels[namespace as keyof AriaLabels],\n },\n ]),\n ) as AriaLabels\n}\n"],"names":[],"mappings":"AAEA;;;;;;AAMG;AACI,MAAM,mBAAmB,GAAe;AAC7C,IAAA,YAAY,EAAE;AACZ,QAAA,UAAU,EAAE,YAAY;AACxB,QAAA,QAAQ,EAAE,eAAe;AACzB,QAAA,QAAQ,EAAE,WAAW;QACrB,UAAU,EAAE,CAAC,IAAqB,KAAK,CAAA,KAAA,EAAQ,IAAI,CAAA,CAAE;AACtD,KAAA;IACD,UAAU,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE;AACtD,IAAA,wBAAwB,EAAE,EAAE,QAAQ,EAAE,0BAA0B,EAAE;AAClE,IAAA,oBAAoB,EAAE,EAAE,MAAM,EAAE,CAAC,MAAc,KAAK,CAAA,EAAG,MAAM,CAAA,QAAA,CAAU,EAAE;AACzE,IAAA,gBAAgB,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;AACpC,IAAA,SAAS,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE;AAC1C,IAAA,mBAAmB,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;AACvC,IAAA,oBAAoB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;AACzC,IAAA,YAAY,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAAE;AAC5C,IAAA,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;AAC1B,IAAA,aAAa,EAAE,EAAE,KAAK,EAAE,+BAA+B,EAAE;IACzD,YAAY,EAAE,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,gBAAgB,EAAE;IAC9D,yBAAyB,EAAE,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,gBAAgB,EAAE;AAC3E,IAAA,WAAW,EAAE,EAAE,KAAK,EAAE,sBAAsB,EAAE;AAC9C,IAAA,mBAAmB,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE;AAC5C,IAAA,oBAAoB,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE;AAClD,IAAA,YAAY,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE;AACxC,IAAA,kBAAkB,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;AACxC,IAAA,WAAW,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE;AACxC,IAAA,YAAY,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE;;AAGpC;;;;;;;;AAQG;AACG,SAAU,wBAAwB,CAAC,MAAkB,EAAA;IACzD,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,KAAK;QACjE,SAAS;AACT,QAAA;AACE,YAAA,GAAG,QAAQ;YACX,GAAG,MAAM,CAAC,SAA6B,CAAC;AACzC,SAAA;AACF,KAAA,CAAC,CACW;AACjB;;;;"}
|
|
@@ -2,6 +2,9 @@ import { isFunction, forEach } from '@empathyco/x-utils';
|
|
|
2
2
|
import { reactive, createApp } from 'vue';
|
|
3
3
|
import { bus } from '../plugins/x-bus.js';
|
|
4
4
|
import { XPlugin } from '../plugins/x-plugin.js';
|
|
5
|
+
import { ACCESSIBILITY_KEY } from '../types/accessibility.js';
|
|
6
|
+
import { DEFAULT_ARIA_LABELS } from '../utils/accessibility.js';
|
|
7
|
+
import '../utils/storage.js';
|
|
5
8
|
import { BaseXAPI } from './api/base-api.js';
|
|
6
9
|
|
|
7
10
|
/**
|
|
@@ -134,6 +137,7 @@ class XInstaller {
|
|
|
134
137
|
const plugin = this.installPlugin(pluginOptions, bus);
|
|
135
138
|
await this.installExtraPlugins(bus);
|
|
136
139
|
this.api?.setBus(bus);
|
|
140
|
+
this.app.provide(ACCESSIBILITY_KEY, DEFAULT_ARIA_LABELS);
|
|
137
141
|
this.app.mount(this.getMountingTarget(this.options.domElement));
|
|
138
142
|
return {
|
|
139
143
|
api: this.api,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x-installer.js","sources":["../../../src/x-installer/x-installer.ts"],"sourcesContent":["import type { App, Plugin } from 'vue'\nimport type { XPluginOptions } from '../plugins/x-plugin.types'\nimport type { WireMetadata, XEventsTypes } from '../wiring/index'\nimport type { XBus } from '../x-bus'\nimport type { NormalisedSnippetConfig, SnippetConfig, XAPI } from './api/api.types'\nimport type { InitWrapper, InstallXOptions } from './types'\nimport { forEach, isFunction } from '@empathyco/x-utils'\nimport { createApp, reactive } from 'vue'\nimport { bus } from '../plugins/x-bus'\nimport { XPlugin } from '../plugins/x-plugin'\nimport { BaseXAPI } from './api/base-api'\n\ndeclare global {\n interface Window {\n InterfaceX?: XAPI\n initX?: (() => SnippetConfig) | SnippetConfig\n }\n}\n\n/**\n * The purpose of this class is to offer a quick way to initialize the XComponents in a setup\n * project. It allows to receive all the options in {@link InstallXOptions} which is an extension\n * of {@link XPluginOptions} with all the options for the plugin and some options more.\n *\n * This class does multiple things:\n * 1. Install the {@link XPlugin} with the {@link XPluginOptions}.\n * 2. Creates the public {@link XAPI} and add it to global window.\n * 3. Creates the Vue Application for the customer project.\n *\n * The steps 2 & 3 are optional and depends on the options passed in {@link InstallXOptions}.\n *\n * @example The way to use this class is the next:\n * 1. Create the installer passing in the {@link InstallXOptions}. This only save the options:\n *\n * ```\n * const installer = new XInstaller(installXOptions)\n * ```\n *\n * 2. Initialize passing the {@link SnippetConfig}. This installs the plugin and creates the App.\n * There are 3 different ways to do this:\n *\n * 2.1 Using the created installer:\n *\n * ```\n * installer.init(snippetConfig)\n * ```\n *\n * 2.2 If the API option is enabled (`createAPI` is `true` in {@link InstallXOptions}, or\n * is not present as the default value is `true`) then this init step can be done with\n * the Public API:\n *\n * ```\n * window.InterfaceX.init(snippetConfig)\n * ```\n *\n * 2.3 When the script of the project build is loaded it searches for a global `initX`\n * variable that the customer must have in their website. This variable can be a\n * function that returns the {@link SnippetConfig} or an object that contains the\n * {@link SnippetConfig} itself:\n *\n * ```\n * window.initX = function() {\n * return {\n * instance,\n * env,\n * scope,\n * lang,\n * uiLang,\n * currency,\n * consent,\n * documentDirection\n * };\n * };\n * ```\n *\n * ```\n * window.initX = {\n * instance,\n * env,\n * scope,\n * lang,\n * uiLang,\n * currency,\n * consent,\n * documentDirection\n * };\n * ```\n *\n * @public\n */\nexport class XInstaller {\n private app!: App\n private api?: XAPI\n\n /**\n * The configuration coming from the snippet {@link SnippetConfig}.\n *\n * @internal\n */\n protected snippetConfig?: NormalisedSnippetConfig\n\n /**\n * Receives the {@link InstallXOptions} and merges it with the default fallback options. Also\n * creates the public {@link XAPI}.\n *\n * @remarks Auto initializes the Vue application if window.initX is defined as a function or\n * object specifying the {@link SnippetConfig | snippet config}.\n *\n *\n * @param options - The {@link InstallXOptions}.\n *\n * @public\n */\n public constructor(protected readonly options: InstallXOptions) {\n this.createAPI()\n }\n\n /**\n * Creates the public {@link XAPI} using the `api` option from {@link InstallXOptions}. If this\n * `api` option is not passed, then a default {@link BaseXAPI} is created. To disable the API\n * creation the value `false` must be passed in the `api` option.\n *\n * @internal\n */\n protected createAPI(): void {\n const { api } = this.options\n if (api !== false) {\n this.api = api ?? new BaseXAPI()\n // eslint-disable-next-line ts/no-misused-promises\n this.api.setInitCallback(this.init.bind(this))\n this.api.setSnippetConfigCallback(this.updateSnippetConfig.bind(this))\n this.api.setSnippetConfigGetter(this.getSnippetConfig.bind(this))\n window.InterfaceX = this.api\n }\n }\n\n /**\n * Retrieves the {@link SnippetConfig | snippet config} it is defined in the window.initX.\n *\n * @returns The snippet config if it is defined or undefined otherwise.\n *\n * @internal\n */\n private retrieveSnippetConfig(): SnippetConfig | undefined {\n if (typeof window.initX === 'function') {\n return window.initX()\n } else if (typeof window.initX === 'object') {\n return window.initX\n }\n }\n\n /**\n * Receives the {@link SnippetConfig | snippet config} or retrieves it from window.initX and\n * installs the plugin and initializes the Vue application.\n *\n * @param snippetConfig - The {@link SnippetConfig} that receives from snippet integration.\n *\n * @returns If {@link SnippetConfig | snippet config} is passed or configured in window.initX,\n * returns an object with the {@link XAPI}, the XBus, the {@link XPlugin}\n * and the Vue application instance. Else, a rejected promise is returned.\n *\n * @public\n */\n init(snippetConfig: SnippetConfig): Promise<InitWrapper>\n init(): Promise<InitWrapper | void>\n async init(snippetConfig = this.retrieveSnippetConfig()): Promise<InitWrapper | void> {\n if (snippetConfig) {\n this.snippetConfig = reactive(this.normaliseSnippetConfig(snippetConfig))\n this.createApp()\n const bus = this.createBus()\n const pluginOptions = this.getPluginOptions()\n const plugin = this.installPlugin(pluginOptions, bus)\n await this.installExtraPlugins(bus)\n this.api?.setBus(bus)\n this.app.mount(this.getMountingTarget(this.options.domElement))\n\n return {\n api: this.api,\n app: this.app,\n bus,\n plugin,\n }\n }\n\n return Promise.resolve()\n }\n\n /**\n * Creates the {@link XPluginOptions} object.\n *\n * @returns The {@link XPluginOptions} object.\n *\n * @internal\n */\n protected getPluginOptions(): XPluginOptions {\n const { adapter, store, initialXModules, xModules, __PRIVATE__xModules } = this.options\n return {\n adapter,\n store,\n xModules,\n initialXModules,\n __PRIVATE__xModules,\n }\n }\n\n /**\n * This method returns the bus instance to be used in the {@link XPlugin} and in the {@link XAPI}.\n * It returns the `bus` parameter in the {@link InstallXOptions} or if not provided, then\n * creates a new instance of {@link @empathyco/x-bus#XPriorityBus | bus}.\n *\n * @returns XBus - The bus instance.\n *\n * @internal\n */\n protected createBus(): XBus<XEventsTypes, WireMetadata> {\n return this.options.bus ?? bus\n }\n\n /**\n * Creates and install the Vue Plugin. If `plugin` parameter is passed in the\n * {@link InstallXOptions}, then it is used. If not, then a new instance of {@link XPlugin} is\n * created and installed.\n *\n * @param pluginOptions - The {@link XPluginOptions} to passed as parameter to the install method\n * of the plugin.\n * @param bus - The XBus to be used to create the XPlugin.\n *\n * @returns Plugin<XPluginOption> - The plugin instance.\n * @internal\n */\n protected installPlugin(\n pluginOptions: XPluginOptions,\n bus: XBus<XEventsTypes, WireMetadata>,\n ): Plugin<XPluginOptions> {\n const plugin = this.options.plugin ?? new XPlugin(bus)\n this.app.use(plugin, pluginOptions)\n return plugin\n }\n\n /**\n * Runs the installExtraPlugins callback defined in the {@link InstallXOptions}\n * to allow the user to install more plugins to the App.\n *\n * @param bus - The events bus used in the application.\n * @returns An empty promise.\n * @internal\n */\n protected async installExtraPlugins(bus: XBus<XEventsTypes, WireMetadata>): Promise<void> {\n return Promise.resolve(\n this.options.installExtraPlugins?.({ app: this.app, snippet: this.snippetConfig!, bus }),\n )\n }\n\n /**\n * In the case that the `rootComponent` parameter is present in the {@link InstallXOptions},\n * then a new Vue application is created using that component as root.\n *\n * @internal\n */\n protected createApp(): void {\n if (this.options.rootComponent !== undefined) {\n this.app = createApp(this.options.rootComponent)\n this.app.provide('snippetConfig', this.snippetConfig)\n this.options.onCreateApp?.(this.app)\n }\n }\n\n protected normaliseSnippetConfig(snippetConfig: SnippetConfig): NormalisedSnippetConfig\n protected normaliseSnippetConfig(snippetConfig: Partial<SnippetConfig>): Partial<SnippetConfig>\n /**\n * Transforms the snippet configuration.\n * - If `lang` is provided and `uiLang` is not, it sets `uiLang=lang`.\n *\n * @param snippetConfig - The snippet config to normalise.\n * @returns The normalised version of the given snippet config.\n * @internal\n */\n protected normaliseSnippetConfig(\n snippetConfig: SnippetConfig | Partial<SnippetConfig>,\n ): NormalisedSnippetConfig | Partial<SnippetConfig> {\n if (snippetConfig.lang) {\n snippetConfig.uiLang ??= snippetConfig.lang\n }\n return snippetConfig\n }\n\n /**\n * It returns the HTML element to mount the Vue Application. If the `domElement` parameter in\n * the {@link InstallXOptions} is an Element or an element selector, then this will be used.\n * The `domElement` can also be a function with the {@link SnippetConfig} as parameter which\n * returns an Element or element selector to use.\n * If it is not present, a new <div> Element is created and appended to the body.\n *\n * @param domElement - {@link InstallXOptions.domElement} Element, ShadowRoot, string or function\n * used to mount the Vue Application.\n *\n * @returns The Element or ShadowRoot to use as mounting target for the Vue Application.\n * @internal\n */\n protected getMountingTarget(domElement?: InstallXOptions['domElement']): Element | ShadowRoot {\n if (isFunction(domElement)) {\n domElement = domElement(this.snippetConfig!)\n }\n if (typeof domElement === 'string') {\n const target = document.querySelector(domElement)\n if (!target) {\n throw new Error(\n `XComponents app couldn't be mounted: Element \"${domElement}\" couldn't be found`,\n )\n }\n return target\n }\n return domElement ?? document.body.appendChild(document.createElement('div'))\n }\n\n /**\n * It updates all the provided properties from the current snippet config.\n *\n * @param newSnippetConfig - All the properties to be updated in the {@link SnippetConfig}.\n *\n * @internal\n */\n protected updateSnippetConfig(newSnippetConfig: Partial<SnippetConfig>): void {\n if (!this.snippetConfig) {\n return\n }\n forEach(this.normaliseSnippetConfig(newSnippetConfig), (name, value) => {\n this.snippetConfig![name] = value\n })\n }\n\n /**\n * Getter for the snippet config object.\n *\n * @returns The {@link NormalisedSnippetConfig | snippetConfig} object.\n *\n * @public\n */\n protected getSnippetConfig(): NormalisedSnippetConfig {\n return this.snippetConfig!\n }\n}\n"],"names":[],"mappings":";;;;;;AAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEG;MACU,UAAU,CAAA;AAWrB;;;;;;;;;;;AAWG;AACH,IAAA,WAAA,CAAsC,OAAwB,EAAA;QAAxB,IAAA,CAAA,OAAO,GAAP,OAAO;QAC3C,I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,EAAE;YACvB;QACF;AACA,QAAA,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAI;AACrE,YAAA,IAAI,CAAC,aAAc,CAAC,IAAI,CAAC,GAAG,KAAK;AACnC,QAAA,CAAC,CAAC;IACJ;AAEA;;;;;;AAMG;IACO,gBAAgB,GAAA;QACxB,OAAO,IAAI,CAAC,aAAc;IAC5B;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"x-installer.js","sources":["../../../src/x-installer/x-installer.ts"],"sourcesContent":["import type { App, Plugin } from 'vue'\nimport type { XPluginOptions } from '../plugins/x-plugin.types'\nimport type { WireMetadata, XEventsTypes } from '../wiring/index'\nimport type { XBus } from '../x-bus'\nimport type { NormalisedSnippetConfig, SnippetConfig, XAPI } from './api/api.types'\nimport type { InitWrapper, InstallXOptions } from './types'\nimport { forEach, isFunction } from '@empathyco/x-utils'\nimport { createApp, reactive } from 'vue'\nimport { bus } from '../plugins/x-bus'\nimport { XPlugin } from '../plugins/x-plugin'\nimport { ACCESSIBILITY_KEY } from '../types'\nimport { DEFAULT_ARIA_LABELS } from '../utils'\nimport { BaseXAPI } from './api/base-api'\n\ndeclare global {\n interface Window {\n InterfaceX?: XAPI\n initX?: (() => SnippetConfig) | SnippetConfig\n }\n}\n\n/**\n * The purpose of this class is to offer a quick way to initialize the XComponents in a setup\n * project. It allows to receive all the options in {@link InstallXOptions} which is an extension\n * of {@link XPluginOptions} with all the options for the plugin and some options more.\n *\n * This class does multiple things:\n * 1. Install the {@link XPlugin} with the {@link XPluginOptions}.\n * 2. Creates the public {@link XAPI} and add it to global window.\n * 3. Creates the Vue Application for the customer project.\n *\n * The steps 2 & 3 are optional and depends on the options passed in {@link InstallXOptions}.\n *\n * @example The way to use this class is the next:\n * 1. Create the installer passing in the {@link InstallXOptions}. This only save the options:\n *\n * ```\n * const installer = new XInstaller(installXOptions)\n * ```\n *\n * 2. Initialize passing the {@link SnippetConfig}. This installs the plugin and creates the App.\n * There are 3 different ways to do this:\n *\n * 2.1 Using the created installer:\n *\n * ```\n * installer.init(snippetConfig)\n * ```\n *\n * 2.2 If the API option is enabled (`createAPI` is `true` in {@link InstallXOptions}, or\n * is not present as the default value is `true`) then this init step can be done with\n * the Public API:\n *\n * ```\n * window.InterfaceX.init(snippetConfig)\n * ```\n *\n * 2.3 When the script of the project build is loaded it searches for a global `initX`\n * variable that the customer must have in their website. This variable can be a\n * function that returns the {@link SnippetConfig} or an object that contains the\n * {@link SnippetConfig} itself:\n *\n * ```\n * window.initX = function() {\n * return {\n * instance,\n * env,\n * scope,\n * lang,\n * uiLang,\n * currency,\n * consent,\n * documentDirection\n * };\n * };\n * ```\n *\n * ```\n * window.initX = {\n * instance,\n * env,\n * scope,\n * lang,\n * uiLang,\n * currency,\n * consent,\n * documentDirection\n * };\n * ```\n *\n * @public\n */\nexport class XInstaller {\n private app!: App\n private api?: XAPI\n\n /**\n * The configuration coming from the snippet {@link SnippetConfig}.\n *\n * @internal\n */\n protected snippetConfig?: NormalisedSnippetConfig\n\n /**\n * Receives the {@link InstallXOptions} and merges it with the default fallback options. Also\n * creates the public {@link XAPI}.\n *\n * @remarks Auto initializes the Vue application if window.initX is defined as a function or\n * object specifying the {@link SnippetConfig | snippet config}.\n *\n *\n * @param options - The {@link InstallXOptions}.\n *\n * @public\n */\n public constructor(protected readonly options: InstallXOptions) {\n this.createAPI()\n }\n\n /**\n * Creates the public {@link XAPI} using the `api` option from {@link InstallXOptions}. If this\n * `api` option is not passed, then a default {@link BaseXAPI} is created. To disable the API\n * creation the value `false` must be passed in the `api` option.\n *\n * @internal\n */\n protected createAPI(): void {\n const { api } = this.options\n if (api !== false) {\n this.api = api ?? new BaseXAPI()\n // eslint-disable-next-line ts/no-misused-promises\n this.api.setInitCallback(this.init.bind(this))\n this.api.setSnippetConfigCallback(this.updateSnippetConfig.bind(this))\n this.api.setSnippetConfigGetter(this.getSnippetConfig.bind(this))\n window.InterfaceX = this.api\n }\n }\n\n /**\n * Retrieves the {@link SnippetConfig | snippet config} it is defined in the window.initX.\n *\n * @returns The snippet config if it is defined or undefined otherwise.\n *\n * @internal\n */\n private retrieveSnippetConfig(): SnippetConfig | undefined {\n if (typeof window.initX === 'function') {\n return window.initX()\n } else if (typeof window.initX === 'object') {\n return window.initX\n }\n }\n\n /**\n * Receives the {@link SnippetConfig | snippet config} or retrieves it from window.initX and\n * installs the plugin and initializes the Vue application.\n *\n * @param snippetConfig - The {@link SnippetConfig} that receives from snippet integration.\n *\n * @returns If {@link SnippetConfig | snippet config} is passed or configured in window.initX,\n * returns an object with the {@link XAPI}, the XBus, the {@link XPlugin}\n * and the Vue application instance. Else, a rejected promise is returned.\n *\n * @public\n */\n init(snippetConfig: SnippetConfig): Promise<InitWrapper>\n init(): Promise<InitWrapper | void>\n async init(snippetConfig = this.retrieveSnippetConfig()): Promise<InitWrapper | void> {\n if (snippetConfig) {\n this.snippetConfig = reactive(this.normaliseSnippetConfig(snippetConfig))\n this.createApp()\n const bus = this.createBus()\n const pluginOptions = this.getPluginOptions()\n const plugin = this.installPlugin(pluginOptions, bus)\n await this.installExtraPlugins(bus)\n this.api?.setBus(bus)\n this.app.provide(ACCESSIBILITY_KEY, DEFAULT_ARIA_LABELS)\n this.app.mount(this.getMountingTarget(this.options.domElement))\n\n return {\n api: this.api,\n app: this.app,\n bus,\n plugin,\n }\n }\n\n return Promise.resolve()\n }\n\n /**\n * Creates the {@link XPluginOptions} object.\n *\n * @returns The {@link XPluginOptions} object.\n *\n * @internal\n */\n protected getPluginOptions(): XPluginOptions {\n const { adapter, store, initialXModules, xModules, __PRIVATE__xModules } = this.options\n return {\n adapter,\n store,\n xModules,\n initialXModules,\n __PRIVATE__xModules,\n }\n }\n\n /**\n * This method returns the bus instance to be used in the {@link XPlugin} and in the {@link XAPI}.\n * It returns the `bus` parameter in the {@link InstallXOptions} or if not provided, then\n * creates a new instance of {@link @empathyco/x-bus#XPriorityBus | bus}.\n *\n * @returns XBus - The bus instance.\n *\n * @internal\n */\n protected createBus(): XBus<XEventsTypes, WireMetadata> {\n return this.options.bus ?? bus\n }\n\n /**\n * Creates and install the Vue Plugin. If `plugin` parameter is passed in the\n * {@link InstallXOptions}, then it is used. If not, then a new instance of {@link XPlugin} is\n * created and installed.\n *\n * @param pluginOptions - The {@link XPluginOptions} to passed as parameter to the install method\n * of the plugin.\n * @param bus - The XBus to be used to create the XPlugin.\n *\n * @returns Plugin<XPluginOption> - The plugin instance.\n * @internal\n */\n protected installPlugin(\n pluginOptions: XPluginOptions,\n bus: XBus<XEventsTypes, WireMetadata>,\n ): Plugin<XPluginOptions> {\n const plugin = this.options.plugin ?? new XPlugin(bus)\n this.app.use(plugin, pluginOptions)\n return plugin\n }\n\n /**\n * Runs the installExtraPlugins callback defined in the {@link InstallXOptions}\n * to allow the user to install more plugins to the App.\n *\n * @param bus - The events bus used in the application.\n * @returns An empty promise.\n * @internal\n */\n protected async installExtraPlugins(bus: XBus<XEventsTypes, WireMetadata>): Promise<void> {\n return Promise.resolve(\n this.options.installExtraPlugins?.({ app: this.app, snippet: this.snippetConfig!, bus }),\n )\n }\n\n /**\n * In the case that the `rootComponent` parameter is present in the {@link InstallXOptions},\n * then a new Vue application is created using that component as root.\n *\n * @internal\n */\n protected createApp(): void {\n if (this.options.rootComponent !== undefined) {\n this.app = createApp(this.options.rootComponent)\n this.app.provide('snippetConfig', this.snippetConfig)\n this.options.onCreateApp?.(this.app)\n }\n }\n\n protected normaliseSnippetConfig(snippetConfig: SnippetConfig): NormalisedSnippetConfig\n protected normaliseSnippetConfig(snippetConfig: Partial<SnippetConfig>): Partial<SnippetConfig>\n /**\n * Transforms the snippet configuration.\n * - If `lang` is provided and `uiLang` is not, it sets `uiLang=lang`.\n *\n * @param snippetConfig - The snippet config to normalise.\n * @returns The normalised version of the given snippet config.\n * @internal\n */\n protected normaliseSnippetConfig(\n snippetConfig: SnippetConfig | Partial<SnippetConfig>,\n ): NormalisedSnippetConfig | Partial<SnippetConfig> {\n if (snippetConfig.lang) {\n snippetConfig.uiLang ??= snippetConfig.lang\n }\n return snippetConfig\n }\n\n /**\n * It returns the HTML element to mount the Vue Application. If the `domElement` parameter in\n * the {@link InstallXOptions} is an Element or an element selector, then this will be used.\n * The `domElement` can also be a function with the {@link SnippetConfig} as parameter which\n * returns an Element or element selector to use.\n * If it is not present, a new <div> Element is created and appended to the body.\n *\n * @param domElement - {@link InstallXOptions.domElement} Element, ShadowRoot, string or function\n * used to mount the Vue Application.\n *\n * @returns The Element or ShadowRoot to use as mounting target for the Vue Application.\n * @internal\n */\n protected getMountingTarget(domElement?: InstallXOptions['domElement']): Element | ShadowRoot {\n if (isFunction(domElement)) {\n domElement = domElement(this.snippetConfig!)\n }\n if (typeof domElement === 'string') {\n const target = document.querySelector(domElement)\n if (!target) {\n throw new Error(\n `XComponents app couldn't be mounted: Element \"${domElement}\" couldn't be found`,\n )\n }\n return target\n }\n return domElement ?? document.body.appendChild(document.createElement('div'))\n }\n\n /**\n * It updates all the provided properties from the current snippet config.\n *\n * @param newSnippetConfig - All the properties to be updated in the {@link SnippetConfig}.\n *\n * @internal\n */\n protected updateSnippetConfig(newSnippetConfig: Partial<SnippetConfig>): void {\n if (!this.snippetConfig) {\n return\n }\n forEach(this.normaliseSnippetConfig(newSnippetConfig), (name, value) => {\n this.snippetConfig![name] = value\n })\n }\n\n /**\n * Getter for the snippet config object.\n *\n * @returns The {@link NormalisedSnippetConfig | snippetConfig} object.\n *\n * @public\n */\n protected getSnippetConfig(): NormalisedSnippetConfig {\n return this.snippetConfig!\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAqBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEG;MACU,UAAU,CAAA;AAWrB;;;;;;;;;;;AAWG;AACH,IAAA,WAAA,CAAsC,OAAwB,EAAA;QAAxB,IAAA,CAAA,OAAO,GAAP,OAAO;QAC3C,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A,mBAAmB,CAAC,gBAAwC,EAAA;AACpE,QAAA,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB;QACF;AACA,QAAA,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAI;AACrE,YAAA,IAAI,CAAC,aAAc,CAAC,IAAI,CAAC,GAAG,KAAK;AACnC,QAAA,CAAC,CAAC;IACJ;AAEA;;;;;;AAMG;IACO,gBAAgB,GAAA;QACxB,OAAO,IAAI,CAAC,aAAc;IAC5B;AACD;;;;"}
|
|
@@ -71,7 +71,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
71
71
|
key: 0,
|
|
72
72
|
class: "x-ai-carousel-title-button",
|
|
73
73
|
"data-test": "ai-carousel-title-button",
|
|
74
|
-
"aria-label": _ctx.titleExpanded ?
|
|
74
|
+
"aria-label": _ctx.titleExpanded ? _ctx.ariaLabels?.collapse : _ctx.ariaLabels?.expand
|
|
75
75
|
}, [
|
|
76
76
|
createVNode(_component_ChevronDownIcon, {
|
|
77
77
|
class: normalizeClass(["x-ai-carousel-title-button-icon", { "x-ai-carousel-title-button-icon--expanded": _ctx.titleExpanded }])
|
|
@@ -85,7 +85,12 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
85
85
|
_: 1
|
|
86
86
|
/* STABLE */
|
|
87
87
|
}, 8, ["payload", "event-metadata"]),
|
|
88
|
-
_ctx.group ? (openBlock(), createBlock(_component_AiGroupedCarousel, {
|
|
88
|
+
_ctx.group ? (openBlock(), createBlock(_component_AiGroupedCarousel, {
|
|
89
|
+
key: 0,
|
|
90
|
+
"sliding-panel-classes": _ctx.slidingPanelClasses,
|
|
91
|
+
"sliding-panel-container-classes": _ctx.slidingPanelContainerClasses,
|
|
92
|
+
"sliding-panel-buttons-classes": _ctx.slidingPanelButtonsClasses
|
|
93
|
+
}, {
|
|
89
94
|
"sliding-panels-addons": withCtx(({ arrivedState }) => [
|
|
90
95
|
renderSlot(_ctx.$slots, "sliding-panels-addons", { arrivedState })
|
|
91
96
|
]),
|
|
@@ -100,7 +105,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
100
105
|
]),
|
|
101
106
|
_: 3
|
|
102
107
|
/* FORWARDED */
|
|
103
|
-
})) : (openBlock(), createElementBlock("div", _hoisted_3, [
|
|
108
|
+
}, 8, ["sliding-panel-classes", "sliding-panel-container-classes", "sliding-panel-buttons-classes"])) : (openBlock(), createElementBlock("div", _hoisted_3, [
|
|
104
109
|
(openBlock(true), createElementBlock(
|
|
105
110
|
Fragment,
|
|
106
111
|
null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-carousel.vue.js","sources":["../../../../../src/x-modules/ai/components/ai-carousel.vue"],"sourcesContent":["<template>\n <CollapseHeight>\n <div v-if=\"suggestionsSearch.length\" class=\"x-ai-carousel\">\n <DisplayEmitter\n :payload=\"tagging?.toolingDisplay ?? emptyTaggingRequest\"\n :event-metadata=\"{\n feature: 'ai_carousel',\n displayOriginalQuery: query || 'ai-carousel-without-query',\n replaceable: false,\n }\"\n data-test=\"ai-carousel-display-emitter\"\n >\n <span\n class=\"x-ai-carousel-title\"\n :class=\"{ 'x-ai-carousel-title--expanded': titleExpanded }\"\n data-test=\"ai-carousel-title\"\n @click=\"toggleTitleExpansion\"\n >\n <AIStarIcon class=\"x-ai-carousel-title-icon\" />\n <ChangeHeight>\n <span\n ref=\"titleRef\"\n class=\"x-ai-carousel-title-text\"\n :class=\"{ 'x-ai-carousel-title-text--expanded': titleExpanded }\"\n >\n {{ title }}\n </span>\n </ChangeHeight>\n <button\n v-if=\"isTitleOverflowing\"\n class=\"x-ai-carousel-title-button\"\n data-test=\"ai-carousel-title-button\"\n :aria-label=\"titleExpanded ? 'Collapse' : 'Expand'\"\n >\n <ChevronDownIcon\n class=\"x-ai-carousel-title-button-icon\"\n :class=\"{ 'x-ai-carousel-title-button-icon--expanded': titleExpanded }\"\n />\n </button>\n </span>\n </DisplayEmitter>\n\n <AiGroupedCarousel v-if=\"group\">\n <template #sliding-panels-addons=\"{ arrivedState }\">\n <slot name=\"sliding-panels-addons\" :arrived-state=\"arrivedState\" />\n </template>\n <template #sliding-panels-left-button>\n <slot name=\"sliding-panels-left-button\" />\n </template>\n <template #sliding-panels-right-button>\n <slot name=\"sliding-panels-right-button\" />\n </template>\n <template #result=\"{ result }\">\n <slot name=\"result\" :result=\"result\" />\n </template>\n </AiGroupedCarousel>\n\n <div v-else class=\"x-ai-carousel-suggestions\" data-test=\"ai-carousel-suggestions-container\">\n <DisplayEmitter\n v-for=\"{ query: suggestionQuery, results: queriesResults } in suggestionsSearch\"\n :key=\"suggestionQuery\"\n :payload=\"tagging?.searchQueries[suggestionQuery].toolingDisplay ?? emptyTaggingRequest\"\n :event-metadata=\"{\n feature: 'ai_carousel',\n displayOriginalQuery: query || 'ai-carousel-without-query',\n replaceable: false,\n }\"\n data-test=\"ai-carousel-query-display-emitter\"\n >\n <div class=\"x-ai-carousel-suggestion\" data-test=\"ai-carousel-suggestion\">\n <BaseEventButton\n class=\"x-ai-carousel-suggestion-query-btn\"\n :events=\"{ UserAcceptedAQuery: suggestionQuery }\"\n >\n {{ suggestionQuery }}\n <ArrowRightIcon class=\"x-ai-carousel-suggestion-query-btn-icon\" />\n </BaseEventButton>\n\n <DisplayClickProvider\n :tooling-display-tagging=\"tagging?.searchQueries[suggestionQuery].toolingDisplayClick\"\n :tooling-add2-cart-tagging=\"\n tagging?.searchQueries[suggestionQuery].toolingDisplayAdd2Cart\n \"\n result-feature=\"ai_carousel\"\n >\n <slot name=\"sliding-panel\" :results=\"queriesResults\">\n <SlidingPanel\n :class=\"slidingPanelClasses\"\n :scroll-container-class=\"slidingPanelContainerClasses\"\n :button-class=\"slidingPanelButtonsClasses\"\n :reset-on-content-change=\"false\"\n >\n <template #sliding-panel-addons=\"{ arrivedState }\">\n <slot name=\"sliding-panels-addons\" :arrived-state=\"arrivedState\" />\n </template>\n <template #sliding-panel-left-button>\n <slot name=\"sliding-panels-left-button\" />\n </template>\n <template #sliding-panel-right-button>\n <slot name=\"sliding-panels-right-button\" />\n </template>\n <ul class=\"x-ai-carousel-suggestion-results\">\n <li\n v-for=\"result in queriesResults\"\n :key=\"result.id\"\n data-test=\"ai-carousel-suggestion-result\"\n >\n <!-- @slot (required) result card -->\n <slot name=\"result\" :result=\"result\" />\n </li>\n </ul>\n </SlidingPanel>\n </slot>\n </DisplayClickProvider>\n </div>\n </DisplayEmitter>\n <slot name=\"suggestions-extra-content\" />\n </div>\n\n <slot name=\"extra-content\" />\n <slot name=\"cta-button\" />\n </div>\n </CollapseHeight>\n</template>\n\n<script lang=\"ts\">\nimport type { TaggingRequest } from '@empathyco/x-types'\nimport { useResizeObserver } from '@vueuse/core'\nimport { computed, defineComponent, onMounted, ref, watch } from 'vue'\nimport {\n AIStarIcon,\n ArrowRightIcon,\n BaseEventButton,\n ChangeHeight,\n ChevronDownIcon,\n CollapseHeight,\n DisplayClickProvider,\n DisplayEmitter,\n SlidingPanel,\n} from '../../../components'\nimport { use$x, useState } from '../../../composables'\nimport { aiXModule } from '../x-module'\nimport AiGroupedCarousel from './ai-grouped-carousel.vue'\n\nexport default defineComponent({\n xModule: aiXModule.name,\n components: {\n AIStarIcon,\n AiGroupedCarousel,\n ArrowRightIcon,\n BaseEventButton,\n ChangeHeight,\n ChevronDownIcon,\n CollapseHeight,\n DisplayClickProvider,\n DisplayEmitter,\n SlidingPanel,\n },\n props: {\n /* The title text displayed */\n title: String,\n /* The classes added to the sliding panel. */\n slidingPanelClasses: String,\n /* The classes added to the sliding panel container. */\n slidingPanelContainerClasses: String,\n /* The classes added to the sliding panel buttons. */\n slidingPanelButtonsClasses: String,\n /* Controls whether the carousel should group results or display N carousels per N queries. */\n group: {\n type: Boolean,\n default: true,\n },\n },\n setup(props) {\n const $x = use$x()\n const { query, suggestionsSearch, queries, tagging } = useState('ai')\n const emptyTaggingRequest: TaggingRequest = { url: '', params: {} }\n\n const titleRef = ref<HTMLElement | null>(null)\n const titleExpanded = ref(false)\n const isTitleOverflowing = ref(false)\n\n /**\n * Checks if the title is overflowing and updates the state.\n */\n function updateTitleOverflow() {\n if (titleExpanded.value) {\n return\n }\n if (titleRef.value) {\n isTitleOverflowing.value = titleRef.value.scrollWidth > titleRef.value.clientWidth\n }\n }\n\n /**\n * Toggles the title expanded state if it is overflowing.\n */\n function toggleTitleExpansion() {\n if (isTitleOverflowing.value) {\n titleExpanded.value = !titleExpanded.value\n }\n }\n\n const title = computed(() => {\n if (!props.title) {\n const queriesList = new Intl.ListFormat('en', {\n style: 'long',\n type: 'conjunction',\n }).format(queries.value.map(({ query }) => query))\n return `Searching for ${queriesList}`\n }\n return props.title\n })\n\n watch(queries, () => {\n if (queries.value.length > 0) {\n $x.emit('AiSuggestionsSearchRequestUpdated')\n }\n })\n\n onMounted(() => {\n $x.emit('AiComponentMounted', undefined, { feature: 'ai_carousel' })\n })\n\n useResizeObserver(titleRef, updateTitleOverflow)\n\n return {\n emptyTaggingRequest,\n isTitleOverflowing,\n queries,\n query,\n suggestionsSearch,\n tagging,\n title,\n titleExpanded,\n titleRef,\n toggleTitleExpansion,\n }\n },\n})\n</script>\n\n<style lang=\"css\">\n.x-ai-carousel {\n --color: var(--x-ai-carousel-color, #bbc9cf);\n --color-lighter: var(--x-ai-carousel-color-lighter, color-mix(in srgb, var(--color) 25%, white));\n\n padding: 8px 0;\n position: relative;\n border-radius: 1.5rem;\n background-color: var(--color-lighter);\n}\n\n.x-ai-carousel-title {\n display: flex;\n font-size: 12px;\n gap: 8px;\n align-items: flex-start;\n margin: 0 14px 8px;\n cursor: pointer;\n}\n.x-ai-carousel-title-text {\n display: block;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.x-ai-carousel-title-text--expanded {\n white-space: normal;\n}\n.x-ai-carousel-title-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n color: var(--color);\n flex-shrink: 0;\n margin-bottom: auto;\n}\n.x-ai-carousel-title-button {\n background: none;\n border: none;\n padding: 0;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n color: var(--color);\n margin-bottom: auto;\n}\n.x-ai-carousel-title-button-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n transition: transform 0.3s ease;\n}\n.x-ai-carousel-title-button-icon--expanded {\n transform: rotate(180deg);\n}\n\n.x-ai-carousel-suggestions {\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n padding-bottom: 1rem;\n}\n\n.x-ai-carousel-suggestion {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.x-ai-carousel-suggestion-query-btn {\n border-color: transparent;\n background-color: transparent;\n margin-left: 1rem;\n margin-right: 1rem;\n font-weight: 700;\n width: fit-content;\n display: flex;\n align-items: center;\n gap: 1rem;\n cursor: pointer;\n}\n\n.x-ai-carousel-suggestion-query-btn-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n}\n\n.x-ai-carousel-suggestion-results {\n display: flex;\n gap: 1rem;\n padding-left: 1rem;\n padding-right: 1rem;\n}\n</style>\n"],"names":["_createBlock","_withCtx","_openBlock","_createElementBlock","_createVNode","_createElementVNode","_normalizeClass","_renderSlot","_Fragment","_renderList","_createTextVNode","_toDisplayString","_createCommentVNode"],"mappings":";;;;;;;EAEyC,KAAA,EAAM;;;;;EAuD7B,KAAA,EAAM,2BAAA;AAAA,EAA4B,WAAA,EAAU;;;EAY/C,KAAA,EAAM,0BAAA;AAAA,EAA2B,WAAA,EAAU;;AAgCpC,MAAA,UAAA,GAAA,EAAA,KAAA,EAAM,kCAAA,EAAkC;;;;;;;;;;;;sBApG5DA,WAAA,CAyHiB,yBAAA,EAAA,IAAA,EAAA;AAAA,IAAA,OAAA,EAAAC,OAAA,CAxHf,MAuHM;AAAA,MAvHK,IAAA,CAAA,iBAAA,CAAkB,MAAA,IAAAC,SAAA,EAAA,EAA7BC,kBAAA,CAuHM,KA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IAAA;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"ai-carousel.vue.js","sources":["../../../../../src/x-modules/ai/components/ai-carousel.vue"],"sourcesContent":["<template>\n <CollapseHeight>\n <div v-if=\"suggestionsSearch.length\" class=\"x-ai-carousel\">\n <DisplayEmitter\n :payload=\"tagging?.toolingDisplay ?? emptyTaggingRequest\"\n :event-metadata=\"{\n feature: 'ai_carousel',\n displayOriginalQuery: query || 'ai-carousel-without-query',\n replaceable: false,\n }\"\n data-test=\"ai-carousel-display-emitter\"\n >\n <span\n class=\"x-ai-carousel-title\"\n :class=\"{ 'x-ai-carousel-title--expanded': titleExpanded }\"\n data-test=\"ai-carousel-title\"\n @click=\"toggleTitleExpansion\"\n >\n <AIStarIcon class=\"x-ai-carousel-title-icon\" />\n <ChangeHeight>\n <span\n ref=\"titleRef\"\n class=\"x-ai-carousel-title-text\"\n :class=\"{ 'x-ai-carousel-title-text--expanded': titleExpanded }\"\n >\n {{ title }}\n </span>\n </ChangeHeight>\n <button\n v-if=\"isTitleOverflowing\"\n class=\"x-ai-carousel-title-button\"\n data-test=\"ai-carousel-title-button\"\n :aria-label=\"titleExpanded ? ariaLabels?.collapse : ariaLabels?.expand\"\n >\n <ChevronDownIcon\n class=\"x-ai-carousel-title-button-icon\"\n :class=\"{ 'x-ai-carousel-title-button-icon--expanded': titleExpanded }\"\n />\n </button>\n </span>\n </DisplayEmitter>\n\n <AiGroupedCarousel\n v-if=\"group\"\n :sliding-panel-classes=\"slidingPanelClasses\"\n :sliding-panel-container-classes=\"slidingPanelContainerClasses\"\n :sliding-panel-buttons-classes=\"slidingPanelButtonsClasses\"\n >\n <template #sliding-panels-addons=\"{ arrivedState }\">\n <slot name=\"sliding-panels-addons\" :arrived-state=\"arrivedState\" />\n </template>\n <template #sliding-panels-left-button>\n <slot name=\"sliding-panels-left-button\" />\n </template>\n <template #sliding-panels-right-button>\n <slot name=\"sliding-panels-right-button\" />\n </template>\n <template #result=\"{ result }\">\n <slot name=\"result\" :result=\"result\" />\n </template>\n </AiGroupedCarousel>\n\n <div v-else class=\"x-ai-carousel-suggestions\" data-test=\"ai-carousel-suggestions-container\">\n <DisplayEmitter\n v-for=\"{ query: suggestionQuery, results: queriesResults } in suggestionsSearch\"\n :key=\"suggestionQuery\"\n :payload=\"tagging?.searchQueries[suggestionQuery].toolingDisplay ?? emptyTaggingRequest\"\n :event-metadata=\"{\n feature: 'ai_carousel',\n displayOriginalQuery: query || 'ai-carousel-without-query',\n replaceable: false,\n }\"\n data-test=\"ai-carousel-query-display-emitter\"\n >\n <div class=\"x-ai-carousel-suggestion\" data-test=\"ai-carousel-suggestion\">\n <BaseEventButton\n class=\"x-ai-carousel-suggestion-query-btn\"\n :events=\"{ UserAcceptedAQuery: suggestionQuery }\"\n >\n {{ suggestionQuery }}\n <ArrowRightIcon class=\"x-ai-carousel-suggestion-query-btn-icon\" />\n </BaseEventButton>\n\n <DisplayClickProvider\n :tooling-display-tagging=\"tagging?.searchQueries[suggestionQuery].toolingDisplayClick\"\n :tooling-add2-cart-tagging=\"\n tagging?.searchQueries[suggestionQuery].toolingDisplayAdd2Cart\n \"\n result-feature=\"ai_carousel\"\n >\n <slot name=\"sliding-panel\" :results=\"queriesResults\">\n <SlidingPanel\n :class=\"slidingPanelClasses\"\n :scroll-container-class=\"slidingPanelContainerClasses\"\n :button-class=\"slidingPanelButtonsClasses\"\n :reset-on-content-change=\"false\"\n >\n <template #sliding-panel-addons=\"{ arrivedState }\">\n <slot name=\"sliding-panels-addons\" :arrived-state=\"arrivedState\" />\n </template>\n <template #sliding-panel-left-button>\n <slot name=\"sliding-panels-left-button\" />\n </template>\n <template #sliding-panel-right-button>\n <slot name=\"sliding-panels-right-button\" />\n </template>\n <ul class=\"x-ai-carousel-suggestion-results\">\n <li\n v-for=\"result in queriesResults\"\n :key=\"result.id\"\n data-test=\"ai-carousel-suggestion-result\"\n >\n <!-- @slot (required) result card -->\n <slot name=\"result\" :result=\"result\" />\n </li>\n </ul>\n </SlidingPanel>\n </slot>\n </DisplayClickProvider>\n </div>\n </DisplayEmitter>\n <slot name=\"suggestions-extra-content\" />\n </div>\n\n <slot name=\"extra-content\" />\n <slot name=\"cta-button\" />\n </div>\n </CollapseHeight>\n</template>\n\n<script lang=\"ts\">\nimport type { TaggingRequest } from '@empathyco/x-types'\nimport type { AriaLabels } from '../../../types'\nimport { useResizeObserver } from '@vueuse/core'\nimport { computed, defineComponent, inject, onMounted, ref, watch } from 'vue'\nimport {\n AIStarIcon,\n ArrowRightIcon,\n BaseEventButton,\n ChangeHeight,\n ChevronDownIcon,\n CollapseHeight,\n DisplayClickProvider,\n DisplayEmitter,\n SlidingPanel,\n} from '../../../components'\nimport { use$x, useState } from '../../../composables'\nimport { ACCESSIBILITY_KEY } from '../../../types'\nimport { aiXModule } from '../x-module'\nimport AiGroupedCarousel from './ai-grouped-carousel.vue'\n\nexport default defineComponent({\n xModule: aiXModule.name,\n components: {\n AIStarIcon,\n AiGroupedCarousel,\n ArrowRightIcon,\n BaseEventButton,\n ChangeHeight,\n ChevronDownIcon,\n CollapseHeight,\n DisplayClickProvider,\n DisplayEmitter,\n SlidingPanel,\n },\n props: {\n /* The title text displayed */\n title: String,\n /* The classes added to the sliding panel. */\n slidingPanelClasses: String,\n /* The classes added to the sliding panel container. */\n slidingPanelContainerClasses: String,\n /* The classes added to the sliding panel buttons. */\n slidingPanelButtonsClasses: String,\n /* Controls whether the carousel should group results or display N carousels per N queries. */\n group: {\n type: Boolean,\n default: true,\n },\n },\n setup(props) {\n const $x = use$x()\n const { query, suggestionsSearch, queries, tagging } = useState('ai')\n const emptyTaggingRequest: TaggingRequest = { url: '', params: {} }\n\n const { aiCarousel: ariaLabels } = inject(ACCESSIBILITY_KEY) as AriaLabels\n\n const titleRef = ref<HTMLElement | null>(null)\n const titleExpanded = ref(false)\n const isTitleOverflowing = ref(false)\n\n /**\n * Checks if the title is overflowing and updates the state.\n */\n function updateTitleOverflow() {\n if (titleExpanded.value) {\n return\n }\n if (titleRef.value) {\n isTitleOverflowing.value = titleRef.value.scrollWidth > titleRef.value.clientWidth\n }\n }\n\n /**\n * Toggles the title expanded state if it is overflowing.\n */\n function toggleTitleExpansion() {\n if (isTitleOverflowing.value) {\n titleExpanded.value = !titleExpanded.value\n }\n }\n\n const title = computed(() => {\n if (!props.title) {\n const queriesList = new Intl.ListFormat('en', {\n style: 'long',\n type: 'conjunction',\n }).format(queries.value.map(({ query }) => query))\n return `Searching for ${queriesList}`\n }\n return props.title\n })\n\n watch(queries, () => {\n if (queries.value.length > 0) {\n $x.emit('AiSuggestionsSearchRequestUpdated')\n }\n })\n\n onMounted(() => {\n $x.emit('AiComponentMounted', undefined, { feature: 'ai_carousel' })\n })\n\n useResizeObserver(titleRef, updateTitleOverflow)\n\n return {\n ariaLabels,\n emptyTaggingRequest,\n isTitleOverflowing,\n queries,\n query,\n suggestionsSearch,\n tagging,\n title,\n titleExpanded,\n titleRef,\n toggleTitleExpansion,\n }\n },\n})\n</script>\n\n<style lang=\"css\">\n.x-ai-carousel {\n --color: var(--x-ai-carousel-color, #bbc9cf);\n --color-lighter: var(--x-ai-carousel-color-lighter, color-mix(in srgb, var(--color) 25%, white));\n\n padding: 8px 0;\n position: relative;\n border-radius: 1.5rem;\n background-color: var(--color-lighter);\n}\n\n.x-ai-carousel-title {\n display: flex;\n font-size: 12px;\n gap: 8px;\n align-items: flex-start;\n margin: 0 14px 8px;\n cursor: pointer;\n}\n.x-ai-carousel-title-text {\n display: block;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.x-ai-carousel-title-text--expanded {\n white-space: normal;\n}\n.x-ai-carousel-title-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n color: var(--color);\n flex-shrink: 0;\n margin-bottom: auto;\n}\n.x-ai-carousel-title-button {\n background: none;\n border: none;\n padding: 0;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n color: var(--color);\n margin-bottom: auto;\n}\n.x-ai-carousel-title-button-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n transition: transform 0.3s ease;\n}\n.x-ai-carousel-title-button-icon--expanded {\n transform: rotate(180deg);\n}\n\n.x-ai-carousel-suggestions {\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n padding-bottom: 1rem;\n}\n\n.x-ai-carousel-suggestion {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.x-ai-carousel-suggestion-query-btn {\n border-color: transparent;\n background-color: transparent;\n margin-left: 1rem;\n margin-right: 1rem;\n font-weight: 700;\n width: fit-content;\n display: flex;\n align-items: center;\n gap: 1rem;\n cursor: pointer;\n}\n\n.x-ai-carousel-suggestion-query-btn-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n}\n\n.x-ai-carousel-suggestion-results {\n display: flex;\n gap: 1rem;\n padding-left: 1rem;\n padding-right: 1rem;\n}\n</style>\n"],"names":["_createBlock","_withCtx","_openBlock","_createElementBlock","_createVNode","_createElementVNode","_normalizeClass","_renderSlot","_Fragment","_renderList","_createTextVNode","_toDisplayString","_createCommentVNode"],"mappings":";;;;;;;EAEyC,KAAA,EAAM;;;;;EA4D7B,KAAA,EAAM,2BAAA;AAAA,EAA4B,WAAA,EAAU;;;EAY/C,KAAA,EAAM,0BAAA;AAAA,EAA2B,WAAA,EAAU;;AAgCpC,MAAA,UAAA,GAAA,EAAA,KAAA,EAAM,kCAAA,EAAkC;;;;;;;;;;;;sBAzG5DA,WAAA,CA8HiB,yBAAA,EAAA,IAAA,EAAA;AAAA,IAAA,OAAA,EAAAC,OAAA,CA7Hf,MA4HM;AAAA,MA5HK,IAAA,CAAA,iBAAA,CAAkB,MAAA,IAAAC,SAAA,EAAA,EAA7BC,kBAAA,CA4HM,KAAA,EA5HN,UAAA,EA4HM;AAAA,QA3HJC,WAAA,CAqCiB,yBAAA,EAAA;AAAA,UApCd,OAAA,EAAS,cAAS,cAAA,IAAkB,IAAA,CAAA,mBAAA;AAAA,UACpC,gBAAA,EAAc;AAAA,YAAA,OAA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IAAA,CAAA,MAAA,EAAA,YAAA;AAAA,OAAA,CAAA,IAAAK,kBAAA,CAAA,MAAA,EAAA,IAAA;;;;;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useResizeObserver } from '@vueuse/core';
|
|
2
|
-
import { defineComponent, ref, computed, watch, onMounted } from 'vue';
|
|
2
|
+
import { defineComponent, inject, ref, computed, watch, onMounted } from 'vue';
|
|
3
3
|
import '../../../components/animations/animate-clip-path.vue2.js';
|
|
4
4
|
import '../../../components/animations/animate-scale.vue2.js';
|
|
5
5
|
import '../../../components/animations/animate-translate.vue2.js';
|
|
@@ -100,6 +100,7 @@ import '../../../plugins/x-bus.js';
|
|
|
100
100
|
import '../../../plugins/x-plugin.js';
|
|
101
101
|
import 'rxjs';
|
|
102
102
|
import { useState } from '../../../composables/use-state.js';
|
|
103
|
+
import { ACCESSIBILITY_KEY } from '../../../types/accessibility.js';
|
|
103
104
|
import { aiXModule } from '../x-module.js';
|
|
104
105
|
import AiGroupedCarousel from './ai-grouped-carousel.vue.js';
|
|
105
106
|
|
|
@@ -136,6 +137,7 @@ var _sfc_main = defineComponent({
|
|
|
136
137
|
const $x = use$x();
|
|
137
138
|
const { query, suggestionsSearch, queries, tagging } = useState('ai');
|
|
138
139
|
const emptyTaggingRequest = { url: '', params: {} };
|
|
140
|
+
const { aiCarousel: ariaLabels } = inject(ACCESSIBILITY_KEY);
|
|
139
141
|
const titleRef = ref(null);
|
|
140
142
|
const titleExpanded = ref(false);
|
|
141
143
|
const isTitleOverflowing = ref(false);
|
|
@@ -178,6 +180,7 @@ var _sfc_main = defineComponent({
|
|
|
178
180
|
});
|
|
179
181
|
useResizeObserver(titleRef, updateTitleOverflow);
|
|
180
182
|
return {
|
|
183
|
+
ariaLabels,
|
|
181
184
|
emptyTaggingRequest,
|
|
182
185
|
isTitleOverflowing,
|
|
183
186
|
queries,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-carousel.vue2.js","sources":["../../../../../src/x-modules/ai/components/ai-carousel.vue"],"sourcesContent":["<template>\n <CollapseHeight>\n <div v-if=\"suggestionsSearch.length\" class=\"x-ai-carousel\">\n <DisplayEmitter\n :payload=\"tagging?.toolingDisplay ?? emptyTaggingRequest\"\n :event-metadata=\"{\n feature: 'ai_carousel',\n displayOriginalQuery: query || 'ai-carousel-without-query',\n replaceable: false,\n }\"\n data-test=\"ai-carousel-display-emitter\"\n >\n <span\n class=\"x-ai-carousel-title\"\n :class=\"{ 'x-ai-carousel-title--expanded': titleExpanded }\"\n data-test=\"ai-carousel-title\"\n @click=\"toggleTitleExpansion\"\n >\n <AIStarIcon class=\"x-ai-carousel-title-icon\" />\n <ChangeHeight>\n <span\n ref=\"titleRef\"\n class=\"x-ai-carousel-title-text\"\n :class=\"{ 'x-ai-carousel-title-text--expanded': titleExpanded }\"\n >\n {{ title }}\n </span>\n </ChangeHeight>\n <button\n v-if=\"isTitleOverflowing\"\n class=\"x-ai-carousel-title-button\"\n data-test=\"ai-carousel-title-button\"\n :aria-label=\"titleExpanded ? 'Collapse' : 'Expand'\"\n >\n <ChevronDownIcon\n class=\"x-ai-carousel-title-button-icon\"\n :class=\"{ 'x-ai-carousel-title-button-icon--expanded': titleExpanded }\"\n />\n </button>\n </span>\n </DisplayEmitter>\n\n <AiGroupedCarousel v-if=\"group\">\n <template #sliding-panels-addons=\"{ arrivedState }\">\n <slot name=\"sliding-panels-addons\" :arrived-state=\"arrivedState\" />\n </template>\n <template #sliding-panels-left-button>\n <slot name=\"sliding-panels-left-button\" />\n </template>\n <template #sliding-panels-right-button>\n <slot name=\"sliding-panels-right-button\" />\n </template>\n <template #result=\"{ result }\">\n <slot name=\"result\" :result=\"result\" />\n </template>\n </AiGroupedCarousel>\n\n <div v-else class=\"x-ai-carousel-suggestions\" data-test=\"ai-carousel-suggestions-container\">\n <DisplayEmitter\n v-for=\"{ query: suggestionQuery, results: queriesResults } in suggestionsSearch\"\n :key=\"suggestionQuery\"\n :payload=\"tagging?.searchQueries[suggestionQuery].toolingDisplay ?? emptyTaggingRequest\"\n :event-metadata=\"{\n feature: 'ai_carousel',\n displayOriginalQuery: query || 'ai-carousel-without-query',\n replaceable: false,\n }\"\n data-test=\"ai-carousel-query-display-emitter\"\n >\n <div class=\"x-ai-carousel-suggestion\" data-test=\"ai-carousel-suggestion\">\n <BaseEventButton\n class=\"x-ai-carousel-suggestion-query-btn\"\n :events=\"{ UserAcceptedAQuery: suggestionQuery }\"\n >\n {{ suggestionQuery }}\n <ArrowRightIcon class=\"x-ai-carousel-suggestion-query-btn-icon\" />\n </BaseEventButton>\n\n <DisplayClickProvider\n :tooling-display-tagging=\"tagging?.searchQueries[suggestionQuery].toolingDisplayClick\"\n :tooling-add2-cart-tagging=\"\n tagging?.searchQueries[suggestionQuery].toolingDisplayAdd2Cart\n \"\n result-feature=\"ai_carousel\"\n >\n <slot name=\"sliding-panel\" :results=\"queriesResults\">\n <SlidingPanel\n :class=\"slidingPanelClasses\"\n :scroll-container-class=\"slidingPanelContainerClasses\"\n :button-class=\"slidingPanelButtonsClasses\"\n :reset-on-content-change=\"false\"\n >\n <template #sliding-panel-addons=\"{ arrivedState }\">\n <slot name=\"sliding-panels-addons\" :arrived-state=\"arrivedState\" />\n </template>\n <template #sliding-panel-left-button>\n <slot name=\"sliding-panels-left-button\" />\n </template>\n <template #sliding-panel-right-button>\n <slot name=\"sliding-panels-right-button\" />\n </template>\n <ul class=\"x-ai-carousel-suggestion-results\">\n <li\n v-for=\"result in queriesResults\"\n :key=\"result.id\"\n data-test=\"ai-carousel-suggestion-result\"\n >\n <!-- @slot (required) result card -->\n <slot name=\"result\" :result=\"result\" />\n </li>\n </ul>\n </SlidingPanel>\n </slot>\n </DisplayClickProvider>\n </div>\n </DisplayEmitter>\n <slot name=\"suggestions-extra-content\" />\n </div>\n\n <slot name=\"extra-content\" />\n <slot name=\"cta-button\" />\n </div>\n </CollapseHeight>\n</template>\n\n<script lang=\"ts\">\nimport type { TaggingRequest } from '@empathyco/x-types'\nimport { useResizeObserver } from '@vueuse/core'\nimport { computed, defineComponent, onMounted, ref, watch } from 'vue'\nimport {\n AIStarIcon,\n ArrowRightIcon,\n BaseEventButton,\n ChangeHeight,\n ChevronDownIcon,\n CollapseHeight,\n DisplayClickProvider,\n DisplayEmitter,\n SlidingPanel,\n} from '../../../components'\nimport { use$x, useState } from '../../../composables'\nimport { aiXModule } from '../x-module'\nimport AiGroupedCarousel from './ai-grouped-carousel.vue'\n\nexport default defineComponent({\n xModule: aiXModule.name,\n components: {\n AIStarIcon,\n AiGroupedCarousel,\n ArrowRightIcon,\n BaseEventButton,\n ChangeHeight,\n ChevronDownIcon,\n CollapseHeight,\n DisplayClickProvider,\n DisplayEmitter,\n SlidingPanel,\n },\n props: {\n /* The title text displayed */\n title: String,\n /* The classes added to the sliding panel. */\n slidingPanelClasses: String,\n /* The classes added to the sliding panel container. */\n slidingPanelContainerClasses: String,\n /* The classes added to the sliding panel buttons. */\n slidingPanelButtonsClasses: String,\n /* Controls whether the carousel should group results or display N carousels per N queries. */\n group: {\n type: Boolean,\n default: true,\n },\n },\n setup(props) {\n const $x = use$x()\n const { query, suggestionsSearch, queries, tagging } = useState('ai')\n const emptyTaggingRequest: TaggingRequest = { url: '', params: {} }\n\n const titleRef = ref<HTMLElement | null>(null)\n const titleExpanded = ref(false)\n const isTitleOverflowing = ref(false)\n\n /**\n * Checks if the title is overflowing and updates the state.\n */\n function updateTitleOverflow() {\n if (titleExpanded.value) {\n return\n }\n if (titleRef.value) {\n isTitleOverflowing.value = titleRef.value.scrollWidth > titleRef.value.clientWidth\n }\n }\n\n /**\n * Toggles the title expanded state if it is overflowing.\n */\n function toggleTitleExpansion() {\n if (isTitleOverflowing.value) {\n titleExpanded.value = !titleExpanded.value\n }\n }\n\n const title = computed(() => {\n if (!props.title) {\n const queriesList = new Intl.ListFormat('en', {\n style: 'long',\n type: 'conjunction',\n }).format(queries.value.map(({ query }) => query))\n return `Searching for ${queriesList}`\n }\n return props.title\n })\n\n watch(queries, () => {\n if (queries.value.length > 0) {\n $x.emit('AiSuggestionsSearchRequestUpdated')\n }\n })\n\n onMounted(() => {\n $x.emit('AiComponentMounted', undefined, { feature: 'ai_carousel' })\n })\n\n useResizeObserver(titleRef, updateTitleOverflow)\n\n return {\n emptyTaggingRequest,\n isTitleOverflowing,\n queries,\n query,\n suggestionsSearch,\n tagging,\n title,\n titleExpanded,\n titleRef,\n toggleTitleExpansion,\n }\n },\n})\n</script>\n\n<style lang=\"css\">\n.x-ai-carousel {\n --color: var(--x-ai-carousel-color, #bbc9cf);\n --color-lighter: var(--x-ai-carousel-color-lighter, color-mix(in srgb, var(--color) 25%, white));\n\n padding: 8px 0;\n position: relative;\n border-radius: 1.5rem;\n background-color: var(--color-lighter);\n}\n\n.x-ai-carousel-title {\n display: flex;\n font-size: 12px;\n gap: 8px;\n align-items: flex-start;\n margin: 0 14px 8px;\n cursor: pointer;\n}\n.x-ai-carousel-title-text {\n display: block;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.x-ai-carousel-title-text--expanded {\n white-space: normal;\n}\n.x-ai-carousel-title-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n color: var(--color);\n flex-shrink: 0;\n margin-bottom: auto;\n}\n.x-ai-carousel-title-button {\n background: none;\n border: none;\n padding: 0;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n color: var(--color);\n margin-bottom: auto;\n}\n.x-ai-carousel-title-button-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n transition: transform 0.3s ease;\n}\n.x-ai-carousel-title-button-icon--expanded {\n transform: rotate(180deg);\n}\n\n.x-ai-carousel-suggestions {\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n padding-bottom: 1rem;\n}\n\n.x-ai-carousel-suggestion {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.x-ai-carousel-suggestion-query-btn {\n border-color: transparent;\n background-color: transparent;\n margin-left: 1rem;\n margin-right: 1rem;\n font-weight: 700;\n width: fit-content;\n display: flex;\n align-items: center;\n gap: 1rem;\n cursor: pointer;\n}\n\n.x-ai-carousel-suggestion-query-btn-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n}\n\n.x-ai-carousel-suggestion-results {\n display: flex;\n gap: 1rem;\n padding-left: 1rem;\n padding-right: 1rem;\n}\n</style>\n"],"names":["DisplayClickProvider","DisplayEmitter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgJA,gBAAe,eAAe,CAAC;IAC7B,OAAO,EAAE,SAAS,CAAC,IAAI;AACvB,IAAA,UAAU,EAAE;QACV,UAAU;QACV,iBAAiB;QACjB,cAAc;QACd,eAAe;QACf,YAAY;QACZ,eAAe;QACf,cAAc;8BACdA,WAAoB;wBACpBC,WAAc;QACd,YAAY;AACb,KAAA;AACD,IAAA,KAAK,EAAE;;AAEL,QAAA,KAAK,EAAE,MAAM;;AAEb,QAAA,mBAAmB,EAAE,MAAM;;AAE3B,QAAA,4BAA4B,EAAE,MAAM;;AAEpC,QAAA,0BAA0B,EAAE,MAAM;;AAElC,QAAA,KAAK,EAAE;AACL,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACF,KAAA;AACD,IAAA,KAAK,CAAC,KAAK,EAAA;AACT,QAAA,MAAM,EAAC,GAAI,KAAK,EAAC;AACjB,QAAA,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAM,EAAE,GAAI,QAAQ,CAAC,IAAI,CAAA;QACpE,MAAM,mBAAmB,GAAmB,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,EAAC,EAAE;AAElE,QAAA,MAAM,QAAO,GAAI,GAAG,CAAqB,IAAI,CAAA;AAC7C,QAAA,MAAM,aAAY,GAAI,GAAG,CAAC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EAAG,CAAA;AACrE,QAAA,CAAC,CAAA;AAED,QAAA,iBAAiB,CAAC,QAAQ,EAAE,mBAAmB,CAAA;QAE/C,OAAO;YACL,mBAAmB;YACnB,kBAAkB;YAClB,OAAO;YACP,KAAK;YACL,iBAAiB;YACjB,OAAO;YACP,KAAK;YACL,aAAa;YACb,QAAQ;YACR,oBAAoB;SACtB;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"ai-carousel.vue2.js","sources":["../../../../../src/x-modules/ai/components/ai-carousel.vue"],"sourcesContent":["<template>\n <CollapseHeight>\n <div v-if=\"suggestionsSearch.length\" class=\"x-ai-carousel\">\n <DisplayEmitter\n :payload=\"tagging?.toolingDisplay ?? emptyTaggingRequest\"\n :event-metadata=\"{\n feature: 'ai_carousel',\n displayOriginalQuery: query || 'ai-carousel-without-query',\n replaceable: false,\n }\"\n data-test=\"ai-carousel-display-emitter\"\n >\n <span\n class=\"x-ai-carousel-title\"\n :class=\"{ 'x-ai-carousel-title--expanded': titleExpanded }\"\n data-test=\"ai-carousel-title\"\n @click=\"toggleTitleExpansion\"\n >\n <AIStarIcon class=\"x-ai-carousel-title-icon\" />\n <ChangeHeight>\n <span\n ref=\"titleRef\"\n class=\"x-ai-carousel-title-text\"\n :class=\"{ 'x-ai-carousel-title-text--expanded': titleExpanded }\"\n >\n {{ title }}\n </span>\n </ChangeHeight>\n <button\n v-if=\"isTitleOverflowing\"\n class=\"x-ai-carousel-title-button\"\n data-test=\"ai-carousel-title-button\"\n :aria-label=\"titleExpanded ? ariaLabels?.collapse : ariaLabels?.expand\"\n >\n <ChevronDownIcon\n class=\"x-ai-carousel-title-button-icon\"\n :class=\"{ 'x-ai-carousel-title-button-icon--expanded': titleExpanded }\"\n />\n </button>\n </span>\n </DisplayEmitter>\n\n <AiGroupedCarousel\n v-if=\"group\"\n :sliding-panel-classes=\"slidingPanelClasses\"\n :sliding-panel-container-classes=\"slidingPanelContainerClasses\"\n :sliding-panel-buttons-classes=\"slidingPanelButtonsClasses\"\n >\n <template #sliding-panels-addons=\"{ arrivedState }\">\n <slot name=\"sliding-panels-addons\" :arrived-state=\"arrivedState\" />\n </template>\n <template #sliding-panels-left-button>\n <slot name=\"sliding-panels-left-button\" />\n </template>\n <template #sliding-panels-right-button>\n <slot name=\"sliding-panels-right-button\" />\n </template>\n <template #result=\"{ result }\">\n <slot name=\"result\" :result=\"result\" />\n </template>\n </AiGroupedCarousel>\n\n <div v-else class=\"x-ai-carousel-suggestions\" data-test=\"ai-carousel-suggestions-container\">\n <DisplayEmitter\n v-for=\"{ query: suggestionQuery, results: queriesResults } in suggestionsSearch\"\n :key=\"suggestionQuery\"\n :payload=\"tagging?.searchQueries[suggestionQuery].toolingDisplay ?? emptyTaggingRequest\"\n :event-metadata=\"{\n feature: 'ai_carousel',\n displayOriginalQuery: query || 'ai-carousel-without-query',\n replaceable: false,\n }\"\n data-test=\"ai-carousel-query-display-emitter\"\n >\n <div class=\"x-ai-carousel-suggestion\" data-test=\"ai-carousel-suggestion\">\n <BaseEventButton\n class=\"x-ai-carousel-suggestion-query-btn\"\n :events=\"{ UserAcceptedAQuery: suggestionQuery }\"\n >\n {{ suggestionQuery }}\n <ArrowRightIcon class=\"x-ai-carousel-suggestion-query-btn-icon\" />\n </BaseEventButton>\n\n <DisplayClickProvider\n :tooling-display-tagging=\"tagging?.searchQueries[suggestionQuery].toolingDisplayClick\"\n :tooling-add2-cart-tagging=\"\n tagging?.searchQueries[suggestionQuery].toolingDisplayAdd2Cart\n \"\n result-feature=\"ai_carousel\"\n >\n <slot name=\"sliding-panel\" :results=\"queriesResults\">\n <SlidingPanel\n :class=\"slidingPanelClasses\"\n :scroll-container-class=\"slidingPanelContainerClasses\"\n :button-class=\"slidingPanelButtonsClasses\"\n :reset-on-content-change=\"false\"\n >\n <template #sliding-panel-addons=\"{ arrivedState }\">\n <slot name=\"sliding-panels-addons\" :arrived-state=\"arrivedState\" />\n </template>\n <template #sliding-panel-left-button>\n <slot name=\"sliding-panels-left-button\" />\n </template>\n <template #sliding-panel-right-button>\n <slot name=\"sliding-panels-right-button\" />\n </template>\n <ul class=\"x-ai-carousel-suggestion-results\">\n <li\n v-for=\"result in queriesResults\"\n :key=\"result.id\"\n data-test=\"ai-carousel-suggestion-result\"\n >\n <!-- @slot (required) result card -->\n <slot name=\"result\" :result=\"result\" />\n </li>\n </ul>\n </SlidingPanel>\n </slot>\n </DisplayClickProvider>\n </div>\n </DisplayEmitter>\n <slot name=\"suggestions-extra-content\" />\n </div>\n\n <slot name=\"extra-content\" />\n <slot name=\"cta-button\" />\n </div>\n </CollapseHeight>\n</template>\n\n<script lang=\"ts\">\nimport type { TaggingRequest } from '@empathyco/x-types'\nimport type { AriaLabels } from '../../../types'\nimport { useResizeObserver } from '@vueuse/core'\nimport { computed, defineComponent, inject, onMounted, ref, watch } from 'vue'\nimport {\n AIStarIcon,\n ArrowRightIcon,\n BaseEventButton,\n ChangeHeight,\n ChevronDownIcon,\n CollapseHeight,\n DisplayClickProvider,\n DisplayEmitter,\n SlidingPanel,\n} from '../../../components'\nimport { use$x, useState } from '../../../composables'\nimport { ACCESSIBILITY_KEY } from '../../../types'\nimport { aiXModule } from '../x-module'\nimport AiGroupedCarousel from './ai-grouped-carousel.vue'\n\nexport default defineComponent({\n xModule: aiXModule.name,\n components: {\n AIStarIcon,\n AiGroupedCarousel,\n ArrowRightIcon,\n BaseEventButton,\n ChangeHeight,\n ChevronDownIcon,\n CollapseHeight,\n DisplayClickProvider,\n DisplayEmitter,\n SlidingPanel,\n },\n props: {\n /* The title text displayed */\n title: String,\n /* The classes added to the sliding panel. */\n slidingPanelClasses: String,\n /* The classes added to the sliding panel container. */\n slidingPanelContainerClasses: String,\n /* The classes added to the sliding panel buttons. */\n slidingPanelButtonsClasses: String,\n /* Controls whether the carousel should group results or display N carousels per N queries. */\n group: {\n type: Boolean,\n default: true,\n },\n },\n setup(props) {\n const $x = use$x()\n const { query, suggestionsSearch, queries, tagging } = useState('ai')\n const emptyTaggingRequest: TaggingRequest = { url: '', params: {} }\n\n const { aiCarousel: ariaLabels } = inject(ACCESSIBILITY_KEY) as AriaLabels\n\n const titleRef = ref<HTMLElement | null>(null)\n const titleExpanded = ref(false)\n const isTitleOverflowing = ref(false)\n\n /**\n * Checks if the title is overflowing and updates the state.\n */\n function updateTitleOverflow() {\n if (titleExpanded.value) {\n return\n }\n if (titleRef.value) {\n isTitleOverflowing.value = titleRef.value.scrollWidth > titleRef.value.clientWidth\n }\n }\n\n /**\n * Toggles the title expanded state if it is overflowing.\n */\n function toggleTitleExpansion() {\n if (isTitleOverflowing.value) {\n titleExpanded.value = !titleExpanded.value\n }\n }\n\n const title = computed(() => {\n if (!props.title) {\n const queriesList = new Intl.ListFormat('en', {\n style: 'long',\n type: 'conjunction',\n }).format(queries.value.map(({ query }) => query))\n return `Searching for ${queriesList}`\n }\n return props.title\n })\n\n watch(queries, () => {\n if (queries.value.length > 0) {\n $x.emit('AiSuggestionsSearchRequestUpdated')\n }\n })\n\n onMounted(() => {\n $x.emit('AiComponentMounted', undefined, { feature: 'ai_carousel' })\n })\n\n useResizeObserver(titleRef, updateTitleOverflow)\n\n return {\n ariaLabels,\n emptyTaggingRequest,\n isTitleOverflowing,\n queries,\n query,\n suggestionsSearch,\n tagging,\n title,\n titleExpanded,\n titleRef,\n toggleTitleExpansion,\n }\n },\n})\n</script>\n\n<style lang=\"css\">\n.x-ai-carousel {\n --color: var(--x-ai-carousel-color, #bbc9cf);\n --color-lighter: var(--x-ai-carousel-color-lighter, color-mix(in srgb, var(--color) 25%, white));\n\n padding: 8px 0;\n position: relative;\n border-radius: 1.5rem;\n background-color: var(--color-lighter);\n}\n\n.x-ai-carousel-title {\n display: flex;\n font-size: 12px;\n gap: 8px;\n align-items: flex-start;\n margin: 0 14px 8px;\n cursor: pointer;\n}\n.x-ai-carousel-title-text {\n display: block;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.x-ai-carousel-title-text--expanded {\n white-space: normal;\n}\n.x-ai-carousel-title-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n color: var(--color);\n flex-shrink: 0;\n margin-bottom: auto;\n}\n.x-ai-carousel-title-button {\n background: none;\n border: none;\n padding: 0;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n color: var(--color);\n margin-bottom: auto;\n}\n.x-ai-carousel-title-button-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n transition: transform 0.3s ease;\n}\n.x-ai-carousel-title-button-icon--expanded {\n transform: rotate(180deg);\n}\n\n.x-ai-carousel-suggestions {\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n padding-bottom: 1rem;\n}\n\n.x-ai-carousel-suggestion {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.x-ai-carousel-suggestion-query-btn {\n border-color: transparent;\n background-color: transparent;\n margin-left: 1rem;\n margin-right: 1rem;\n font-weight: 700;\n width: fit-content;\n display: flex;\n align-items: center;\n gap: 1rem;\n cursor: pointer;\n}\n\n.x-ai-carousel-suggestion-query-btn-icon {\n height: 1rem;\n aspect-ratio: 1 / 1;\n}\n\n.x-ai-carousel-suggestion-results {\n display: flex;\n gap: 1rem;\n padding-left: 1rem;\n padding-right: 1rem;\n}\n</style>\n"],"names":["DisplayClickProvider","DisplayEmitter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuJA,gBAAe,eAAe,CAAC;IAC7B,OAAO,EAAE,SAAS,CAAC,IAAI;AACvB,IAAA,UAAU,EAAE;QACV,UAAU;QACV,iBAAiB;QACjB,cAAc;QACd,eAAe;QACf,YAAY;QACZ,eAAe;QACf,cAAc;8BACdA,WAAoB;wBACpBC,WAAc;QACd,YAAY;AACb,KAAA;AACD,IAAA,KAAK,EAAE;;AAEL,QAAA,KAAK,EAAE,MAAM;;AAEb,QA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WAAU,GAAI,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;AAC5C,oBAAA,KAAK,EAAE,MAAM;AACb,oBAAA,IAAI,EAAE,aAAa;AACpB,iBAAA,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,KAAK,KAAK,CAAC,CAAA;gBACjD,OAAO,CAAA,cAAA,EAAiB,WAAW,CAAA,CAAC;YACtC;YACA,OAAO,KAAK,CAAC,KAAI;AACnB,QAAA,CAAC,CAAA;AAED,QAAA,KAAK,CAAC,OAAO,EAAE,MAAI;YACjB,IAAI,OAAO,CAAC,KAAK,CAAC,MAAK,GAAI,CAAC,EAAE;AAC5B,gBAAA,EAAE,CAAC,IAAI,CAAC,mCAAmC,CAAA;YAC7C;AACF,QAAA,CAAC,CAAA;QAED,SAAS,CAAC,MAAI;AACZ,YAAA,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,aAAY,EAAG,CAAA;AACrE,QAAA,CAAC,CAAA;AAED,QAAA,iBAAiB,CAAC,QAAQ,EAAE,mBAAmB,CAAA;QAE/C,OAAO;YACL,UAAU;YACV,mBAAmB;YACnB,kBAAkB;YAClB,OAAO;YACP,KAAK;YACL,iBAAiB;YACjB,OAAO;YACP,KAAK;YACL,aAAa;YACb,QAAQ;YACR,oBAAoB;SACtB;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
|
|
@@ -1,59 +1,65 @@
|
|
|
1
1
|
import _sfc_main from './facets.vue2.js';
|
|
2
|
-
import { openBlock, createBlock, resolveDynamicComponent, withCtx,
|
|
2
|
+
import { openBlock, createElementBlock, createBlock, resolveDynamicComponent, withCtx, Fragment, renderList, renderSlot, mergeProps, createTextVNode, toDisplayString, createCommentVNode } from 'vue';
|
|
3
3
|
import './facets.vue3.js';
|
|
4
4
|
import _export_sfc from '../../../../_virtual/_plugin-vue_export-helper.js';
|
|
5
5
|
|
|
6
|
+
const _hoisted_1 = ["aria-label"];
|
|
6
7
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
8
|
+
return openBlock(), createElementBlock("nav", {
|
|
9
|
+
id: "facet-nav",
|
|
10
|
+
"aria-label": _ctx.ariaLabels?.root
|
|
11
|
+
}, [
|
|
12
|
+
_ctx.hasFacets ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.animation), {
|
|
13
|
+
key: 0,
|
|
14
|
+
class: "x-facets-list",
|
|
15
|
+
"data-test": "facets",
|
|
16
|
+
tag: "ul"
|
|
17
|
+
}, {
|
|
18
|
+
default: withCtx(() => [
|
|
19
|
+
(openBlock(true), createElementBlock(
|
|
20
|
+
Fragment,
|
|
21
|
+
null,
|
|
22
|
+
renderList(_ctx.mappedFacets, ({ facet, slotNameById, slotNameByModelName }, facetId) => {
|
|
23
|
+
return openBlock(), createElementBlock("li", {
|
|
24
|
+
key: facetId,
|
|
25
|
+
class: "x-facets-list__item",
|
|
26
|
+
"data-test": "facets-facet"
|
|
27
|
+
}, [
|
|
28
|
+
_ctx.hasSlot(slotNameById) ? renderSlot(_ctx.$slots, slotNameById, mergeProps({
|
|
29
|
+
key: 0,
|
|
30
|
+
ref_for: true
|
|
31
|
+
}, {
|
|
32
|
+
facet,
|
|
33
|
+
selectedFilters: _ctx.selectedFiltersByFacet[facetId] || []
|
|
34
|
+
}), void 0, true) : _ctx.hasSlot(slotNameByModelName) ? renderSlot(_ctx.$slots, slotNameByModelName, mergeProps({
|
|
35
|
+
key: 1,
|
|
36
|
+
ref_for: true
|
|
37
|
+
}, {
|
|
38
|
+
facet,
|
|
39
|
+
selectedFilters: _ctx.selectedFiltersByFacet[facetId] || []
|
|
40
|
+
}), void 0, true) : renderSlot(_ctx.$slots, "default", mergeProps({
|
|
41
|
+
key: 2,
|
|
42
|
+
ref_for: true
|
|
43
|
+
}, {
|
|
44
|
+
facet,
|
|
45
|
+
selectedFilters: _ctx.selectedFiltersByFacet[facetId] || []
|
|
46
|
+
}), () => [
|
|
47
|
+
createTextVNode(
|
|
48
|
+
" This is the " + toDisplayString(facet.label) + " facet. Pass something into its slot to display content. ",
|
|
49
|
+
1
|
|
50
|
+
/* TEXT */
|
|
51
|
+
)
|
|
52
|
+
], true)
|
|
53
|
+
]);
|
|
54
|
+
}),
|
|
55
|
+
128
|
|
56
|
+
/* KEYED_FRAGMENT */
|
|
57
|
+
))
|
|
58
|
+
]),
|
|
59
|
+
_: 3
|
|
60
|
+
/* FORWARDED */
|
|
61
|
+
})) : createCommentVNode("v-if", true)
|
|
62
|
+
], 8, _hoisted_1);
|
|
57
63
|
}
|
|
58
64
|
var facets = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ec0aa26c"]]);
|
|
59
65
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facets.vue.js","sources":["../../../../../../src/x-modules/facets/components/facets/facets.vue"],"sourcesContent":["<template>\n <component :is=\"animation\" v-if=\"hasFacets\" class=\"x-facets-list\" data-test=\"facets\" tag=\"ul\">\n <li\n v-for=\"({ facet, slotNameById, slotNameByModelName }, facetId) in mappedFacets\"\n :key=\"facetId\"\n class=\"x-facets-list__item\"\n data-test=\"facets-facet\"\n >\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's name will result in the\n facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-if=\"hasSlot(slotNameById)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameById\"\n />\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's modelName will result\n in the facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else-if=\"hasSlot(slotNameByModelName)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameByModelName\"\n />\n <!--\n @slot (required) Default Facet rendering. This slot will be used by default for rendering\n the facets without an specific slot implementation.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n >\n This is the {{ facet.label }} facet. Pass something into its slot to display content.\n </slot>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\nimport type { Facet } from '@empathyco/x-types'\nimport type { Dictionary } from '@empathyco/x-utils'\nimport type { PropType } from 'vue'\nimport type { RenderFacet } from './facets.types'\nimport { map, objectFilter } from '@empathyco/x-utils'\nimport { computed, defineComponent } from 'vue'\nimport { useGetter } from '../../../../composables/use-getter'\nimport { AnimationProp } from '../../../../types'\nimport { toKebabCase } from '../../../../utils/string'\nimport { useFacets } from '../../composables/use-facets'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * This component renders the list of facets stored in the Facets module. Facets can be rendered\n * differently based on their purpose and this can be achieved using the exposed slots:\n * - A default and required slot.\n * - A custom slot for each facet with the facetId as its name. This allows each facet to be\n * rendered differently based on its needs.\n *\n * @public\n */\nexport default defineComponent({\n name: 'Facets',\n xModule: facetsXModule.name,\n props: {\n /** Array of facets ids used to get the selected filters for those facets. */\n facetsIds: Array as PropType<Array<Facet['id']>>,\n /** Flag to render the component even if there are no filters selected. */\n alwaysVisible: Boolean,\n /** Animation component that will be used to animate the facets. */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n /**\n * Discriminates the facets rendered by this component. It expects a string containing facets\n * ids, comma separated. This property will include or exclude facets based on its value.\n * The default value is an empty string and the component will render all existing facets.\n *\n * @remarks\n * To behave as a `include`, simply set the facets ids, comma separated:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"brand, category\"`\n *\n * The component will render brand and category facets.\n *\n * On the other hand, to simulate an `exclude` behaviour and exclude a facet from being\n * rendered, append a '!' before its id:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"!brand,!price\"`\n *\n * The component will render category and color facets.\n */\n renderableFacets: String,\n },\n setup(props, { slots }) {\n const { selectedFiltersByFacet } = useFacets(props)\n const { facets } = useGetter('facets')\n\n /**\n * The facets to be rendered after filtering {@link Facets.facets} by\n * {@link Facets.renderableFacets} content.\n *\n * @returns The list of facets to be rendered.\n */\n const facetsToRender = computed<Dictionary<Facet>>(() => {\n if (!props.renderableFacets) {\n return facets.value\n } else {\n const excludedRegExp = /^!/\n const facetIds: string[] = props.renderableFacets.split(',').map(facetId => facetId.trim())\n const included: string[] = []\n const excluded: string[] = []\n facetIds.forEach(facetId => {\n if (excludedRegExp.test(facetId)) {\n excluded.push(facetId.replace(excludedRegExp, ''))\n } else {\n included.push(facetId)\n }\n })\n\n return filterFacetsToRender(included, excluded)\n }\n })\n\n /**\n * Transforms a dictionary of Facets including the slot name.\n *\n * @returns A dictionary of facets with the slot name.\n */\n const mappedFacets = computed<Dictionary<RenderFacet>>(() => {\n return map(facetsToRender.value, (facetId, facet) => ({\n slotNameById: toKebabCase(facetId),\n slotNameByModelName: toKebabCase(facet.modelName),\n facet,\n }))\n })\n\n /**\n * Indicates if there are facets available to show.\n *\n * @returns True if there are facets available and false otherwise.\n */\n const hasFacets = computed<boolean>(() => !!Object.keys(facetsToRender.value).length)\n\n /**\n * Filter facets dictionary retrieving those included and/or removing excluded.\n *\n * @param included - List of facets to render.\n * @param excluded - List of not renderable facets.\n *\n * @returns The filtered list of facets to render.\n */\n function filterFacetsToRender(included: string[], excluded: string[]): Dictionary<Facet> {\n const hasAnyFacetIncluded = included.length > 0\n return objectFilter(facets.value, facetKey => {\n const isIncluded = included.includes(String(facetKey))\n const isExcluded = excluded.includes(String(facetKey))\n\n return hasAnyFacetIncluded ? isIncluded && !isExcluded : !isExcluded\n })\n }\n\n /**\n * Whether the slot is present in the template or not.\n *\n * @param name - The slot name.\n *\n * @returns True is the slot is present in the template. False otherwise.\n */\n function hasSlot(name: string): boolean {\n return !!slots[name]\n }\n\n return {\n selectedFiltersByFacet,\n hasFacets,\n mappedFacets,\n hasSlot,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-facets-list {\n display: flex;\n flex-flow: column nowrap;\n list-style-type: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders the list of facets stored in the Facets module. Facets can be rendered\ndifferently based on their purpose and this can be achieved using the exposed slots:\n\n- A default and required slot.\n- A custom slot for each facet with the facetId as its name. This allows each facet to be rendered\n differently based on its needs.\n\nBelow, there are some examples showing how to use the component with its different configurations.\n\n### Default usage\n\nThe default slot of this component is mandatory. If no other slot is defined, every Facet will be\nrendered as specified in the default slot.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} selected` }}</span>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Customized usage\n\nCustomized compositions for a specific Facet can be achieved by using a slot with the same id as the\nfacet to customize. For example, the Facet with the id \"color\" requires a composition that differs\nfrom the rest of the Facets. Doing it in a slot with the name \"color\" will apply this customization\njust to the \"color\" Facet. The other facets will fallback to the composition of the default slot.\n\nIt is also possible to customize the Facet content by the facet \"model name\". For example, to\nconfigure different content for \"Hierarchical Facets\" the \"hierarchical-facet\" slot will apply that\ncustomization. This can be combined with the facets by facet id. If some hierarchical facet needs\nsome different customization from the rest of the hierarchical, it can be achieve using the slot\nwith the facet id.\n\n```vue\n<template>\n <Facets>\n <template #color=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n\n <template #hierarchical-facet=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n <ul v-for=\"childFilter in filter.children\" :key=\"childFilter.id\">\n <li v-if=\"!childFilter.selected\">\n {{ childFilter.label }}\n </li>\n </ul>\n </li>\n </ul>\n </template>\n\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets I\n\nBy default, this component will render all existing facets. However, it has the renderableFacets\nprop to filter which facets will be rendered. Its value is a string containing the different facets\nids. This value is treated as an include or exclude list (to exclude a facet from being rendered,\njust prefix its id with a `!`). The component will only render included facets and discard excluded\nones. In the following example, the component will only render color and category facets.\n\n```vue\n<template>\n <Facets renderableFacets=\"color, category\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets II\n\nExclude facets so the component does not render them. In the following example, the component will\nrender every facet except color and price.\n\n```vue\n<template>\n <Facets renderableFacets=\"!color, !price\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Integrating with the filters components\n\nThere are many components that will help you build your own awesome filters list. `Facets` just\nrenders the list, but what to render for each facet is up to you. Below you can see an example of\nthe `Facets` component using the `FiltersSearch`, `MultiSelectFilters`, `SimpleFilter`, `Filters`,\n`HierarchicalFilter`, `NumberRangeFilter` and `BasePriceFilterLabel` components.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <FiltersSearch :filters=\"facet.filters\">\n <MultiSelectFilters v-slot=\"{ filter }\">\n <SimpleFilter :filter=\"filter\" />\n </MultiSelectFilters>\n </FiltersSearch>\n </template>\n\n <template #category=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <HierarchicalFilter :filter=\"filter\" />\n </Filters>\n </template>\n\n <template #price=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <NumberRangeFilter :filter=\"filter\">\n <BasePriceFilterLabel :filter=\"filter\" />\n </NumberRangeFilter>\n </Filters>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport {\n Facets,\n Filters,\n FiltersSearch,\n HierarchicalFilter,\n MultiSelectFilters,\n NumberRangeFilter,\n SimpleFilter,\n} from '@empathyco/x-components/facets'\n\nimport { BasePriceFilterLabel } from '@empathyco/x-components'\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createBlock","_resolveDynamicComponent","_createElementBlock","_Fragment","_renderList","_renderSlot","_mergeProps","_createTextVNode","_toDisplayString"],"mappings":";;;;;;SACmC,IAAA,CAAA,SAAA,IAAAA,SAAA,EAAA,EAAjCC,WAAA,CAmDYC,wBAnDI,IAAA,CAAA,SAAS,CAAA,EAAA;AAAA,IAAA,GAAA,EAAA,CAAA;IAAmB,KAAA,EAAM,eAAA;AAAA,IAAgB,WAAA,EAAU,QAAA;AAAA,IAAS,GAAA,EAAI;AAAA,GAAA,EAAA;qBAErF,MAA+E;AAAA,OAAAF,SAAA,CAAA,IAAA,CAAA,EADjFG,kBAAA;AAAA,QAiDKC,QAAA;AAAA,QAAA,IAAA;AAAA,QAAAC,UAAA,CAhD+D,mBAAY,CAAA,EAApE,KAAA,EAAO,YAAA,EAAc,mBAAA,IAAuB,OAAA,KAAO;8BAD/DF,kBAAA,CAiDK,IAAA,EAAA;AAAA,YA/CF,GAAA,EAAK,OAAA;AAAA,YACN,KAAA,EAAM,qBAAA;AAAA,YACN,WAAA,EAAU;AAAA,WAAA,EAAA;AASF,YAAA,IAAA,CAAA,OAAA,CAAQ,YAAY,CAAA,GAD5BG,UAAA,CAOE,IAAA,CAAA,MAAA,EADO,cANTC,UAAA,CAOE;AAAA,cAAA,GAAA,EAAA,CAAA;;;AALoB,cAAA,KAAA;AAAA,cAAA,eAAA,EAAkC,4BAAuB,OAAO,CAAA,IAAA;AAAA,aAAA,CAAA,EAAA,MAAA,EAAA,IAAA,CAAA,GAazE,aAAQ,mBAAmB,CAAA,GADxCD,UAAA,CAOE,IAAA,CAAA,MAAA,EADO,qBANTC,UAAA,CAOE;AAAA,cAAA,GAAA,EAAA,CAAA;;;AALoB,cAAA,KAAA;AAAA,cAAA,eAAA,EAAkC,4BAAuB,OAAO,CAAA,IAAA;AAAA,aAAA,CAAA,EAAA,MAAA,EAAA,IAAA,CAAA,GAYtFD,UAAA,CAQO,wBARPC,UAAA,CAQO;AAAA,cAAA,GAAA,EAAA,CAAA;;;AANe,cAAA,KAAA;AAAA,cAAA,eAAA,EAAkC,4BAAuB,OAAO,CAAA,IAAA;AAAA,aAAA,CAAA,EAFtF,MAQO;AAAA,cAAAC,eAAA;gBAFN,eAAA,GACaC,eAAA,CAAG,KAAA,CAAM,KAAK,CAAA,GAAG,2DAAA;AAAA,gBAC/B;AAAA;AAAA;AAAA,aAAA,EAAA,IAAA;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"facets.vue.js","sources":["../../../../../../src/x-modules/facets/components/facets/facets.vue"],"sourcesContent":["<template>\n <nav id=\"facet-nav\" :aria-label=\"ariaLabels?.root\">\n <component :is=\"animation\" v-if=\"hasFacets\" class=\"x-facets-list\" data-test=\"facets\" tag=\"ul\">\n <li\n v-for=\"({ facet, slotNameById, slotNameByModelName }, facetId) in mappedFacets\"\n :key=\"facetId\"\n class=\"x-facets-list__item\"\n data-test=\"facets-facet\"\n >\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's name will result in the\n facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-if=\"hasSlot(slotNameById)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameById\"\n />\n <!--\n @slot Customized Facet rendering. Specifying a slot with the facet's modelName will result\n in the facet using that slot composition to render.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else-if=\"hasSlot(slotNameByModelName)\"\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n :name=\"slotNameByModelName\"\n />\n <!--\n @slot (required) Default Facet rendering. This slot will be used by default for rendering\n the facets without an specific slot implementation.\n @binding {Facet} facet - Facet to render\n @binding {Filter[]} selectedFilters - List of selected filters of the given facet\n -->\n <slot\n v-else\n v-bind=\"{\n facet,\n selectedFilters: selectedFiltersByFacet[facetId] || [],\n }\"\n >\n This is the {{ facet.label }} facet. Pass something into its slot to display content.\n </slot>\n </li>\n </component>\n </nav>\n</template>\n\n<script lang=\"ts\">\nimport type { Facet } from '@empathyco/x-types'\nimport type { Dictionary } from '@empathyco/x-utils'\nimport type { PropType } from 'vue'\nimport type { AriaLabels } from '../../../../types'\nimport type { RenderFacet } from './facets.types'\nimport { map, objectFilter } from '@empathyco/x-utils'\nimport { computed, defineComponent, inject } from 'vue'\nimport { useGetter } from '../../../../composables/use-getter'\nimport { ACCESSIBILITY_KEY, AnimationProp } from '../../../../types'\nimport { toKebabCase } from '../../../../utils/string'\nimport { useFacets } from '../../composables/use-facets'\nimport { facetsXModule } from '../../x-module'\n\n/**\n * This component renders the list of facets stored in the Facets module. Facets can be rendered\n * differently based on their purpose and this can be achieved using the exposed slots:\n * - A default and required slot.\n * - A custom slot for each facet with the facetId as its name. This allows each facet to be\n * rendered differently based on its needs.\n *\n * @public\n */\nexport default defineComponent({\n name: 'Facets',\n xModule: facetsXModule.name,\n props: {\n /** Array of facets ids used to get the selected filters for those facets. */\n facetsIds: Array as PropType<Array<Facet['id']>>,\n /** Flag to render the component even if there are no filters selected. */\n alwaysVisible: Boolean,\n /** Animation component that will be used to animate the facets. */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n /**\n * Discriminates the facets rendered by this component. It expects a string containing facets\n * ids, comma separated. This property will include or exclude facets based on its value.\n * The default value is an empty string and the component will render all existing facets.\n *\n * @remarks\n * To behave as a `include`, simply set the facets ids, comma separated:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"brand, category\"`\n *\n * The component will render brand and category facets.\n *\n * On the other hand, to simulate an `exclude` behaviour and exclude a facet from being\n * rendered, append a '!' before its id:\n * `existingFacets=[{ brand: ... }, category: { ... }, color: { ... }, price: { ... }]`\n * `renderableFacets=\"!brand,!price\"`\n *\n * The component will render category and color facets.\n */\n renderableFacets: String,\n },\n setup(props, { slots }) {\n const { selectedFiltersByFacet } = useFacets(props)\n const { facets } = useGetter('facets')\n\n const { facets: ariaLabels } = inject(ACCESSIBILITY_KEY) as AriaLabels\n\n /**\n * The facets to be rendered after filtering {@link Facets.facets} by\n * {@link Facets.renderableFacets} content.\n *\n * @returns The list of facets to be rendered.\n */\n const facetsToRender = computed<Dictionary<Facet>>(() => {\n if (!props.renderableFacets) {\n return facets.value\n } else {\n const excludedRegExp = /^!/\n const facetIds: string[] = props.renderableFacets.split(',').map(facetId => facetId.trim())\n const included: string[] = []\n const excluded: string[] = []\n facetIds.forEach(facetId => {\n if (excludedRegExp.test(facetId)) {\n excluded.push(facetId.replace(excludedRegExp, ''))\n } else {\n included.push(facetId)\n }\n })\n\n return filterFacetsToRender(included, excluded)\n }\n })\n\n /**\n * Transforms a dictionary of Facets including the slot name.\n *\n * @returns A dictionary of facets with the slot name.\n */\n const mappedFacets = computed<Dictionary<RenderFacet>>(() => {\n return map(facetsToRender.value, (facetId, facet) => ({\n slotNameById: toKebabCase(facetId),\n slotNameByModelName: toKebabCase(facet.modelName),\n facet,\n }))\n })\n\n /**\n * Indicates if there are facets available to show.\n *\n * @returns True if there are facets available and false otherwise.\n */\n const hasFacets = computed<boolean>(() => !!Object.keys(facetsToRender.value).length)\n\n /**\n * Filter facets dictionary retrieving those included and/or removing excluded.\n *\n * @param included - List of facets to render.\n * @param excluded - List of not renderable facets.\n *\n * @returns The filtered list of facets to render.\n */\n function filterFacetsToRender(included: string[], excluded: string[]): Dictionary<Facet> {\n const hasAnyFacetIncluded = included.length > 0\n return objectFilter(facets.value, facetKey => {\n const isIncluded = included.includes(String(facetKey))\n const isExcluded = excluded.includes(String(facetKey))\n\n return hasAnyFacetIncluded ? isIncluded && !isExcluded : !isExcluded\n })\n }\n\n /**\n * Whether the slot is present in the template or not.\n *\n * @param name - The slot name.\n *\n * @returns True is the slot is present in the template. False otherwise.\n */\n function hasSlot(name: string): boolean {\n return !!slots[name]\n }\n\n return {\n ariaLabels,\n selectedFiltersByFacet,\n hasFacets,\n mappedFacets,\n hasSlot,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-facets-list {\n display: flex;\n flex-flow: column nowrap;\n list-style-type: none;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders the list of facets stored in the Facets module. Facets can be rendered\ndifferently based on their purpose and this can be achieved using the exposed slots:\n\n- A default and required slot.\n- A custom slot for each facet with the facetId as its name. This allows each facet to be rendered\n differently based on its needs.\n\nBelow, there are some examples showing how to use the component with its different configurations.\n\n### Default usage\n\nThe default slot of this component is mandatory. If no other slot is defined, every Facet will be\nrendered as specified in the default slot.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} selected` }}</span>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Customized usage\n\nCustomized compositions for a specific Facet can be achieved by using a slot with the same id as the\nfacet to customize. For example, the Facet with the id \"color\" requires a composition that differs\nfrom the rest of the Facets. Doing it in a slot with the name \"color\" will apply this customization\njust to the \"color\" Facet. The other facets will fallback to the composition of the default slot.\n\nIt is also possible to customize the Facet content by the facet \"model name\". For example, to\nconfigure different content for \"Hierarchical Facets\" the \"hierarchical-facet\" slot will apply that\ncustomization. This can be combined with the facets by facet id. If some hierarchical facet needs\nsome different customization from the rest of the hierarchical, it can be achieve using the slot\nwith the facet id.\n\n```vue\n<template>\n <Facets>\n <template #color=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n\n <template #hierarchical-facet=\"{ facet, selectedFilters }\">\n <span v-if=\"selectedFilters.length > 0\">{{ `${selectedFilters.length} colors chosen` }}</span>\n\n <ul v-for=\"filter in facet.filters\" :key=\"filter.id\">\n <li v-if=\"!filter.selected\">\n {{ filter.label }}\n <ul v-for=\"childFilter in filter.children\" :key=\"childFilter.id\">\n <li v-if=\"!childFilter.selected\">\n {{ childFilter.label }}\n </li>\n </ul>\n </li>\n </ul>\n </template>\n\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets I\n\nBy default, this component will render all existing facets. However, it has the renderableFacets\nprop to filter which facets will be rendered. Its value is a string containing the different facets\nids. This value is treated as an include or exclude list (to exclude a facet from being rendered,\njust prefix its id with a `!`). The component will only render included facets and discard excluded\nones. In the following example, the component will only render color and category facets.\n\n```vue\n<template>\n <Facets renderableFacets=\"color, category\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Render specific facets II\n\nExclude facets so the component does not render them. In the following example, the component will\nrender every facet except color and price.\n\n```vue\n<template>\n <Facets renderableFacets=\"!color, !price\">\n <template #default=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n\n <ul>\n <li v-for=\"filter in facet.filters\" :key=\"filter.id\">\n {{ filter.label }}\n </li>\n </ul>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport { Facets } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Integrating with the filters components\n\nThere are many components that will help you build your own awesome filters list. `Facets` just\nrenders the list, but what to render for each facet is up to you. Below you can see an example of\nthe `Facets` component using the `FiltersSearch`, `MultiSelectFilters`, `SimpleFilter`, `Filters`,\n`HierarchicalFilter`, `NumberRangeFilter` and `BasePriceFilterLabel` components.\n\n```vue\n<template>\n <Facets>\n <template #default=\"{ facet, selectedFilters }\">\n <h1>{{ facet.label }}</h1>\n <FiltersSearch :filters=\"facet.filters\">\n <MultiSelectFilters v-slot=\"{ filter }\">\n <SimpleFilter :filter=\"filter\" />\n </MultiSelectFilters>\n </FiltersSearch>\n </template>\n\n <template #category=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <HierarchicalFilter :filter=\"filter\" />\n </Filters>\n </template>\n\n <template #price=\"{ facet }\">\n <h1>{{ facet.label }}</h1>\n <Filters v-slot=\"{ filter }\" :filters=\"facet.filters\">\n <NumberRangeFilter :filter=\"filter\">\n <BasePriceFilterLabel :filter=\"filter\" />\n </NumberRangeFilter>\n </Filters>\n </template>\n </Facets>\n</template>\n\n<script setup>\nimport {\n Facets,\n Filters,\n FiltersSearch,\n HierarchicalFilter,\n MultiSelectFilters,\n NumberRangeFilter,\n SimpleFilter,\n} from '@empathyco/x-components/facets'\n\nimport { BasePriceFilterLabel } from '@empathyco/x-components'\n</script>\n```\n</docs>\n"],"names":["_createElementBlock","_openBlock","_createBlock","_resolveDynamicComponent","_Fragment","_renderList","_renderSlot","_mergeProps","_createTextVNode","_toDisplayString"],"mappings":";;;;;;;sBACEA,kBAAA,CAqDM,KAAA,EAAA;AAAA,IArDD,EAAA,EAAG,WAAA;A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AAAA,gBAAA,eAAA,EAAoC,4BAAuB,OAAO,CAAA,IAAA;AAAA,eAAA,CAAA,EAF1F,MAQO;AAAA,gBAAAC,eAAA;kBAFN,eAAA,GACaC,eAAA,CAAG,KAAA,CAAM,KAAK,CAAA,GAAG,2DAAA;AAAA,kBAC/B;AAAA;AAAA;AAAA,eAAA,EAAA,IAAA;;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { map, objectFilter } from '@empathyco/x-utils';
|
|
2
|
-
import { defineComponent, computed } from 'vue';
|
|
2
|
+
import { defineComponent, inject, computed } from 'vue';
|
|
3
3
|
import { useGetter } from '../../../../composables/use-getter.js';
|
|
4
|
+
import { ACCESSIBILITY_KEY } from '../../../../types/accessibility.js';
|
|
4
5
|
import { AnimationProp } from '../../../../types/animation-prop.js';
|
|
5
6
|
import { toKebabCase } from '../../../../utils/string.js';
|
|
6
7
|
import { useFacets } from '../../composables/use-facets.js';
|
|
@@ -52,6 +53,7 @@ var _sfc_main = defineComponent({
|
|
|
52
53
|
setup(props, { slots }) {
|
|
53
54
|
const { selectedFiltersByFacet } = useFacets(props);
|
|
54
55
|
const { facets } = useGetter('facets');
|
|
56
|
+
const { facets: ariaLabels } = inject(ACCESSIBILITY_KEY);
|
|
55
57
|
/**
|
|
56
58
|
* The facets to be rendered after filtering {@link Facets.facets} by
|
|
57
59
|
* {@link Facets.renderableFacets} content.
|
|
@@ -123,6 +125,7 @@ var _sfc_main = defineComponent({
|
|
|
123
125
|
return !!slots[name];
|
|
124
126
|
}
|
|
125
127
|
return {
|
|
128
|
+
ariaLabels,
|
|
126
129
|
selectedFiltersByFacet,
|
|
127
130
|
hasFacets,
|
|
128
131
|
mappedFacets,
|