@empathyco/x-components 10.2.0 → 10.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/docs/API-reference/api/x-components.arraytoobject.md +1 -1
- package/docs/API-reference/api/x-components.createusedevice.md +1 -1
- package/docs/API-reference/api/x-components.deepmergewithdefaults.md +1 -1
- package/docs/API-reference/api/x-components.md +2 -2
- package/docs/API-reference/api/x-components.querypreview.md +9 -0
- package/docs/API-reference/api/x-components.searchconfig.md +19 -0
- package/docs/API-reference/api/x-components.searchconfig.pricesortfield.md +13 -0
- package/docs/API-reference/api/x-components.useondisplay.md +1 -1
- package/docs/API-reference/api/x-components.xinstaller.md +4 -4
- package/docs/API-reference/api/x-components.xplugin.md +1 -1
- package/docs/API-reference/components/queries-preview/x-components.query-preview.md +9 -8
- package/js/components/base-dropdown.vue.js +2 -6
- package/js/components/base-dropdown.vue.js.map +1 -1
- package/js/components/base-grid.vue.js +2 -8
- package/js/components/base-grid.vue.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/result/base-result-image.vue.js +1 -1
- package/js/components/result/base-result-image.vue.js.map +1 -1
- package/js/composables/use-on-display.js +26 -3
- package/js/composables/use-on-display.js.map +1 -1
- package/js/x-modules/facets/components/facets/facets.vue.js +4 -13
- package/js/x-modules/facets/components/facets/facets.vue.js.map +1 -1
- package/js/x-modules/facets/components/lists/selected-filters-list.vue.js +3 -9
- package/js/x-modules/facets/components/lists/selected-filters-list.vue.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview.vue.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview.vue2.js +28 -10
- package/js/x-modules/queries-preview/components/query-preview.vue2.js.map +1 -1
- package/js/x-modules/search/store/getters/request.getter.js +1 -1
- package/js/x-modules/search/store/getters/request.getter.js.map +1 -1
- package/js/x-modules/search/store/module.js +1 -0
- package/js/x-modules/search/store/module.js.map +1 -1
- package/package.json +24 -24
- package/report/tsdoc-metadata.json +1 -1
- package/report/x-adapter-platform.api.json +5 -5
- package/report/x-components.api.json +698 -653
- package/report/x-components.api.md +10 -0
- package/report/x-types.api.json +30 -30
- package/types/src/composables/use-on-display.d.ts +4 -1
- package/types/src/composables/use-on-display.d.ts.map +1 -1
- package/types/src/x-modules/queries-preview/components/query-preview.vue.d.ts +15 -0
- package/types/src/x-modules/queries-preview/components/query-preview.vue.d.ts.map +1 -1
- package/types/src/x-modules/search/config.types.d.ts +5 -0
- package/types/src/x-modules/search/config.types.d.ts.map +1 -1
- package/types/src/x-modules/search/store/module.d.ts.map +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useElementVisibility } from '@vueuse/core';
|
|
2
|
-
import { watch } from 'vue';
|
|
2
|
+
import { watch, ref, onMounted, toValue } from 'vue';
|
|
3
3
|
import { useXBus } from './use-x-bus.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -12,8 +12,14 @@ import { useXBus } from './use-x-bus.js';
|
|
|
12
12
|
* @returns If the element is currently visible in the viewport or not and the watcher stop handle.
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
|
-
function useOnDisplay({ element, callback, triggerOnce = true, }) {
|
|
16
|
-
const isElementVisible = useElementVisibility(element, {
|
|
15
|
+
function useOnDisplay({ element, callback, triggerOnce = true, threshold = 0.1, rootMargin, scrollTargetId, }) {
|
|
16
|
+
const isElementVisible = useElementVisibility(element, {
|
|
17
|
+
threshold,
|
|
18
|
+
...(rootMargin !== undefined && { rootMargin }),
|
|
19
|
+
...(scrollTargetId !== undefined && {
|
|
20
|
+
scrollTarget: resolveScrollTarget(element, scrollTargetId),
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
17
23
|
const unwatchDisplay = watch(isElementVisible, newValue => {
|
|
18
24
|
if (newValue) {
|
|
19
25
|
callback();
|
|
@@ -27,6 +33,23 @@ function useOnDisplay({ element, callback, triggerOnce = true, }) {
|
|
|
27
33
|
unwatchDisplay,
|
|
28
34
|
};
|
|
29
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolves, on mount, the ancestor of the watched element that matches the given id, in an
|
|
38
|
+
* SSR-safe and shadow-DOM-safe way. If no ancestor matches, the ref stays `null`, which makes
|
|
39
|
+
* the visibility be computed against the viewport.
|
|
40
|
+
*
|
|
41
|
+
* @param element - The watched element, used as the lookup starting point.
|
|
42
|
+
* @param scrollTargetId - The id of the element to be used as the visibility root.
|
|
43
|
+
* @returns A ref holding the resolved element (`null` if not found).
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
function resolveScrollTarget(element, scrollTargetId) {
|
|
47
|
+
const scrollTarget = ref(null);
|
|
48
|
+
onMounted(() => {
|
|
49
|
+
scrollTarget.value = toValue(element)?.closest(`#${CSS.escape(scrollTargetId)}`) ?? null;
|
|
50
|
+
});
|
|
51
|
+
return scrollTarget;
|
|
52
|
+
}
|
|
30
53
|
/**
|
|
31
54
|
* Composable that emits a `TrackableElementDisplayed` event whenever the provided element
|
|
32
55
|
* appears in the viewport for the first time.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-on-display.js","sources":["../../../src/composables/use-on-display.ts"],"sourcesContent":["import type { TaggingRequest } from '@empathyco/x-types'\nimport type { Ref, WatchStopHandle } from 'vue'\nimport type { WireMetadata } from '../wiring'\nimport { useElementVisibility } from '@vueuse/core'\nimport { watch } from 'vue'\nimport { useXBus } from './use-x-bus'\n\n/**\n * Composable that triggers a callback whenever the provided element appears in the viewport.\n * It can trigger the first time only or every time the element appears in the viewport.\n *\n * @param options - The options to customize the behavior of the composable. The element that\n * will be watched, the callback to trigger and if the callback should be triggered only once\n * or every time the element appears in the viewport, true by default.\n * @returns If the element is currently visible in the viewport or not and the watcher stop handle.\n * @public\n */\nexport function useOnDisplay({\n element,\n callback,\n triggerOnce = true,\n}: UseOnDisplayOptions): UseOnDisplayReturn {\n const isElementVisible = useElementVisibility(element, {
|
|
1
|
+
{"version":3,"file":"use-on-display.js","sources":["../../../src/composables/use-on-display.ts"],"sourcesContent":["import type { TaggingRequest } from '@empathyco/x-types'\nimport type { Ref, WatchStopHandle } from 'vue'\nimport type { WireMetadata } from '../wiring'\nimport { useElementVisibility } from '@vueuse/core'\nimport { onMounted, ref, toValue, watch } from 'vue'\nimport { useXBus } from './use-x-bus'\n\n/**\n * Composable that triggers a callback whenever the provided element appears in the viewport.\n * It can trigger the first time only or every time the element appears in the viewport.\n *\n * @param options - The options to customize the behavior of the composable. The element that\n * will be watched, the callback to trigger and if the callback should be triggered only once\n * or every time the element appears in the viewport, true by default.\n * @returns If the element is currently visible in the viewport or not and the watcher stop handle.\n * @public\n */\nexport function useOnDisplay({\n element,\n callback,\n triggerOnce = true,\n threshold = 0.1,\n rootMargin,\n scrollTargetId,\n}: UseOnDisplayOptions): UseOnDisplayReturn {\n const isElementVisible = useElementVisibility(element, {\n threshold,\n ...(rootMargin !== undefined && { rootMargin }),\n ...(scrollTargetId !== undefined && {\n scrollTarget: resolveScrollTarget(element, scrollTargetId),\n }),\n })\n\n const unwatchDisplay = watch(isElementVisible, newValue => {\n if (newValue) {\n callback()\n if (triggerOnce) {\n unwatchDisplay()\n }\n }\n })\n\n return {\n isElementVisible,\n unwatchDisplay,\n }\n}\n\n/**\n * Resolves, on mount, the ancestor of the watched element that matches the given id, in an\n * SSR-safe and shadow-DOM-safe way. If no ancestor matches, the ref stays `null`, which makes\n * the visibility be computed against the viewport.\n *\n * @param element - The watched element, used as the lookup starting point.\n * @param scrollTargetId - The id of the element to be used as the visibility root.\n * @returns A ref holding the resolved element (`null` if not found).\n * @internal\n */\nfunction resolveScrollTarget(\n element: HTMLElement | Ref<HTMLElement | null>,\n scrollTargetId: string,\n) {\n const scrollTarget = ref<HTMLElement | null>(null)\n\n onMounted(() => {\n scrollTarget.value = toValue(element)?.closest(`#${CSS.escape(scrollTargetId)}`) ?? null\n })\n\n return scrollTarget\n}\n\n/**\n * Composable that emits a `TrackableElementDisplayed` event whenever the provided element\n * appears in the viewport for the first time.\n *\n * @param options - The options to customize the behavior of the composable. The element that\n * will be watched and the tagging request to emit.\n * @returns If the element is currently visible in the viewport or not and the watcher stop handle.\n * @public\n */\nexport function useEmitDisplayEvent({\n element,\n taggingRequest,\n eventMetadata = {},\n}: UseEmitDisplayEventOptions): UseOnDisplayReturn {\n const bus = useXBus()\n\n const { isElementVisible, unwatchDisplay } = useOnDisplay({\n element,\n callback: () => {\n void bus.emit(\n 'TrackableElementDisplayed',\n { tagging: { display: taggingRequest } },\n eventMetadata,\n )\n },\n })\n\n return {\n isElementVisible,\n unwatchDisplay,\n }\n}\n\n/**\n * Options for the {@link useOnDisplay} composable.\n */\ninterface UseOnDisplayOptions {\n element: HTMLElement | Ref<HTMLElement | null>\n callback: () => void\n triggerOnce?: boolean\n threshold?: number\n rootMargin?: string\n scrollTargetId?: string\n}\n\n/**\n * Return type of the {@link useOnDisplay} composable.\n */\ninterface UseOnDisplayReturn {\n isElementVisible: Ref<boolean>\n unwatchDisplay: WatchStopHandle\n}\n\n/**\n * Options for the {@link useEmitDisplayEvent} composable.\n */\ninterface UseEmitDisplayEventOptions {\n element: UseOnDisplayOptions['element']\n taggingRequest: TaggingRequest\n eventMetadata?: Omit<WireMetadata, 'moduleName' | 'origin' | 'location'>\n}\n"],"names":[],"mappings":";;;;AAOA;;;;;;;;;AASG;SACa,YAAY,CAAC,EAC3B,OAAO,EACP,QAAQ,EACR,WAAW,GAAG,IAAI,EAClB,SAAS,GAAG,GAAG,EACf,UAAU,EACV,cAAc,GACM,EAAA;AACpB,IAAA,MAAM,gBAAgB,GAAG,oBAAoB,CAAC,OAAO,EAAE;QACrD,SAAS;QACT,IAAI,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,CAAC;AAC/C,QAAA,IAAI,cAAc,KAAK,SAAS,IAAI;AAClC,YAAA,YAAY,EAAE,mBAAmB,CAAC,OAAO,EAAE,cAAc,CAAC;SAC3D,CAAC;AACH,KAAA,CAAC;IAEF,MAAM,cAAc,GAAG,KAAK,CAAC,gBAAgB,EAAE,QAAQ,IAAG;QACxD,IAAI,QAAQ,EAAE;AACZ,YAAA,QAAQ,EAAE;YACV,IAAI,WAAW,EAAE;AACf,gBAAA,cAAc,EAAE;YAClB;QACF;AACF,IAAA,CAAC,CAAC;IAEF,OAAO;QACL,gBAAgB;QAChB,cAAc;KACf;AACH;AAEA;;;;;;;;;AASG;AACH,SAAS,mBAAmB,CAC1B,OAA8C,EAC9C,cAAsB,EAAA;AAEtB,IAAA,MAAM,YAAY,GAAG,GAAG,CAAqB,IAAI,CAAC;IAElD,SAAS,CAAC,MAAK;QACb,YAAY,CAAC,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA,CAAE,CAAC,IAAI,IAAI;AAC1F,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,YAAY;AACrB;AAEA;;;;;;;;AAQG;AACG,SAAU,mBAAmB,CAAC,EAClC,OAAO,EACP,cAAc,EACd,aAAa,GAAG,EAAE,GACS,EAAA;AAC3B,IAAA,MAAM,GAAG,GAAG,OAAO,EAAE;AAErB,IAAA,MAAM,EAAE,gBAAgB,EAAE,cAAc,EAAE,GAAG,YAAY,CAAC;QACxD,OAAO;QACP,QAAQ,EAAE,MAAK;AACb,YAAA,KAAK,GAAG,CAAC,IAAI,CACX,2BAA2B,EAC3B,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EACxC,aAAa,CACd;QACH,CAAC;AACF,KAAA,CAAC;IAEF,OAAO;QACL,gBAAgB;QAChB,cAAc;KACf;AACH;;;;"}
|
|
@@ -25,22 +25,13 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
25
25
|
class: "x-facets-list__item",
|
|
26
26
|
"data-test": "facets-facet"
|
|
27
27
|
}, [
|
|
28
|
-
_ctx.hasSlot(slotNameById) ? renderSlot(_ctx.$slots, slotNameById, mergeProps({
|
|
29
|
-
key: 0,
|
|
30
|
-
ref_for: true
|
|
31
|
-
}, {
|
|
28
|
+
_ctx.hasSlot(slotNameById) ? renderSlot(_ctx.$slots, slotNameById, mergeProps({ ref_for: true }, {
|
|
32
29
|
facet,
|
|
33
30
|
selectedFilters: _ctx.selectedFiltersByFacet[facetId] || []
|
|
34
|
-
}), void 0, true) : _ctx.hasSlot(slotNameByModelName) ? renderSlot(_ctx.$slots, slotNameByModelName, mergeProps({
|
|
35
|
-
key: 1,
|
|
36
|
-
ref_for: true
|
|
37
|
-
}, {
|
|
31
|
+
}), void 0, true, 0) : _ctx.hasSlot(slotNameByModelName) ? renderSlot(_ctx.$slots, slotNameByModelName, mergeProps({ ref_for: true }, {
|
|
38
32
|
facet,
|
|
39
33
|
selectedFilters: _ctx.selectedFiltersByFacet[facetId] || []
|
|
40
|
-
}), void 0, true) : renderSlot(_ctx.$slots, "default", mergeProps({
|
|
41
|
-
key: 2,
|
|
42
|
-
ref_for: true
|
|
43
|
-
}, {
|
|
34
|
+
}), void 0, true, 1) : renderSlot(_ctx.$slots, "default", mergeProps({ ref_for: true }, {
|
|
44
35
|
facet,
|
|
45
36
|
selectedFilters: _ctx.selectedFiltersByFacet[facetId] || []
|
|
46
37
|
}), () => [
|
|
@@ -49,7 +40,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
49
40
|
1
|
|
50
41
|
/* TEXT */
|
|
51
42
|
)
|
|
52
|
-
], true)
|
|
43
|
+
], true, 2)
|
|
53
44
|
]);
|
|
54
45
|
}),
|
|
55
46
|
128
|
|
@@ -1 +1 @@
|
|
|
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 { RenderFacet } from './facets.types'\nimport { map, objectFilter } from '@empathyco/x-utils'\nimport { computed, defineComponent } from 'vue'\nimport { useAccessibilityLabels } from '../../../../composables'\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 const ariaLabels = useAccessibilityLabels('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 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;AAAA,IAAa,cAAY,IAAA,CAAA,UAAA,EAAY;AAAA,GAAA,EAAA;IACV,IAAA,CAAA,SAAA,IAAAC,SAAA,EAAA,EAAjCC,WAAA,CAmDYC,wBAnDI,IAAA,CAAA,SAAS,CAAA,EAAA;AAAA,MAAA,GAAA,EAAA,CAAA;MAAmB,KAAA,EAAM,eAAA;AAAA,MAAgB,WAAA,EAAU,QAAA;AAAA,MAAS,GAAA,EAAI;AAAA,KAAA,EAAA;uBAErF,MAA+E;AAAA,SAAAF,SAAA,CAAA,IAAA,CAAA,EADjFD,kBAAA;AAAA,UAiDKI,QAAA;AAAA,UAAA,IAAA;AAAA,UAAAC,UAAA,CAhD+D,mBAAY,CAAA,EAApE,KAAA,EAAO,YAAA,EAAc,mBAAA,IAAuB,OAAA,KAAO;gCAD/DL,kBAAA,CAiDK,IAAA,EAAA;AAAA,cA/CF,GAAA,EAAK,OAAA;AAAA,cACN,KAAA,EAAM,qBAAA;AAAA,cACN,WAAA,EAAU;AAAA,aAAA,EAAA;AASF,cAAA,IAAA,CAAA,OAAA,CAAQ,YAAY,CAAA,GAD5BM,UAAA,CAOE,IAAA,CAAA,MAAA,EADO,cANTC,UAAA,CAOE;AAAA,gBAAA,GAAA,EAAA,CAAA;;;AALsB,gBAAA,KAAA;AAAA,gBAAA,eAAA,EAAoC,4BAAuB,OAAO,CAAA,IAAA;AAAA,eAAA,CAAA,EAAA,MAAA,EAAA,IAAA,CAAA,GAa7E,aAAQ,mBAAmB,CAAA,GADxCD,UAAA,CAOE,IAAA,CAAA,MAAA,EADO,qBANTC,UAAA,CAOE;AAAA,gBAAA,GAAA,EAAA,CAAA;;;AALsB,gBAAA,KAAA;AAAA,gBAAA,eAAA,EAAoC,4BAAuB,OAAO,CAAA,IAAA;AAAA,eAAA,CAAA,EAAA,MAAA,EAAA,IAAA,CAAA,GAY1FD,UAAA,CAQO,wBARPC,UAAA,CAQO;AAAA,gBAAA,GAAA,EAAA,CAAA;;;AANiB,gBAAA,KAAA;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
|
+
{"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 { RenderFacet } from './facets.types'\nimport { map, objectFilter } from '@empathyco/x-utils'\nimport { computed, defineComponent } from 'vue'\nimport { useAccessibilityLabels } from '../../../../composables'\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 const ariaLabels = useAccessibilityLabels('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 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;AAAA,IAAa,cAAY,IAAA,CAAA,UAAA,EAAY;AAAA,GAAA,EAAA;IACV,IAAA,CAAA,SAAA,IAAAC,SAAA,EAAA,EAAjCC,WAAA,CAmDYC,wBAnDI,IAAA,CAAA,SAAS,CAAA,EAAA;AAAA,MAAA,GAAA,EAAA,CAAA;MAAmB,KAAA,EAAM,eAAA;AAAA,MAAgB,WAAA,EAAU,QAAA;AAAA,MAAS,GAAA,EAAI;AAAA,KAAA,EAAA;uBAErF,MAA+E;AAAA,SAAAF,SAAA,CAAA,IAAA,CAAA,EADjFD,kBAAA;AAAA,UAiDKI,QAAA;AAAA,UAAA,IAAA;AAAA,UAAAC,UAAA,CAhD+D,mBAAY,CAAA,EAApE,KAAA,EAAO,YAAA,EAAc,mBAAA,IAAuB,OAAA,KAAO;gCAD/DL,kBAAA,CAiDK,IAAA,EAAA;AAAA,cA/CF,GAAA,EAAK,OAAA;AAAA,cACN,KAAA,EAAM,qBAAA;AAAA,cACN,WAAA,EAAU;AAAA,aAAA,EAAA;AASF,cAAA,IAAA,CAAA,OAAA,CAAQ,YAAY,CAAA,GAD5BM,UAAA,CAOE,IAAA,CAAA,MAAA,EADO,cANTC,UAAA,CAOE,EAAA,OAAA,EAAA,IAAA,EAAA,EAAA;AAAA,gBALsB,KAAA;AAAA,gBAAA,eAAA,EAAoC,4BAAuB,OAAO,CAAA,IAAA;AAAA,eAAA,CAAA,EAAA,MAAA,EAAA,IAAA,EAAA,CAAA,CAAA,GAa7E,aAAQ,mBAAmB,CAAA,GADxCD,UAAA,CAOE,IAAA,CAAA,MAAA,EADO,qBANTC,UAAA,CAOE,EAAA,OAAA,EAAA,IAAA,EAAA,EAAA;AAAA,gBALsB,KAAA;AAAA,gBAAA,eAAA,EAAoC,4BAAuB,OAAO,CAAA,IAAA;AAAA,eAAA,CAAA,EAAA,MAAA,EAAA,IAAA,EAAA,CAAA,CAAA,GAY1FD,UAAA,CAQO,wBARPC,UAAA,CAQO,EAAA,OAAA,EAAA,IAAA,EAAA,EAAA;AAAA,gBANiB,KAAA;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,EAAA,CAAA;;;;;;;;;;;;;;;;"}
|
|
@@ -25,10 +25,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
25
25
|
class: "x-selected-filters-list__item",
|
|
26
26
|
"data-test": "selected-filters-list-item"
|
|
27
27
|
}, [
|
|
28
|
-
_ctx.hasSlot(slotName) ? renderSlot(_ctx.$slots, slotName, {
|
|
29
|
-
key: 0,
|
|
30
|
-
filter: selectedFilter
|
|
31
|
-
}, () => [
|
|
28
|
+
_ctx.hasSlot(slotName) ? renderSlot(_ctx.$slots, slotName, { filter: selectedFilter }, () => [
|
|
32
29
|
createElementVNode(
|
|
33
30
|
"span",
|
|
34
31
|
_hoisted_1,
|
|
@@ -36,16 +33,13 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
36
33
|
1
|
|
37
34
|
/* TEXT */
|
|
38
35
|
)
|
|
39
|
-
]) : renderSlot(_ctx.$slots, "default", {
|
|
40
|
-
key: 1,
|
|
41
|
-
filter: selectedFilter
|
|
42
|
-
}, () => [
|
|
36
|
+
], void 0, 0) : renderSlot(_ctx.$slots, "default", { filter: selectedFilter }, () => [
|
|
43
37
|
createTextVNode(
|
|
44
38
|
toDisplayString(selectedFilter.label),
|
|
45
39
|
1
|
|
46
40
|
/* TEXT */
|
|
47
41
|
)
|
|
48
|
-
])
|
|
42
|
+
], void 0, 1)
|
|
49
43
|
]);
|
|
50
44
|
}),
|
|
51
45
|
128
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selected-filters-list.vue.js","sources":["../../../../../../src/x-modules/facets/components/lists/selected-filters-list.vue"],"sourcesContent":["<template>\n <SelectedFilters :facets-ids=\"facetsIds\" :always-visible=\"alwaysVisible\">\n <component\n :is=\"animation\"\n class=\"x-selected-filters-list\"\n data-test=\"selected-filters-list\"\n tag=\"ul\"\n >\n <li\n v-for=\"{ slotName, selectedFilter } in mapSlot(selectedFilters)\"\n :key=\"selectedFilter.id\"\n class=\"x-selected-filters-list__item\"\n data-test=\"selected-filters-list-item\"\n >\n <!--\n @slot Custom filter rendering. Dynamic slot defined in the template with the filter\n facet id. It renders the filter label by default.\n @binding {Filter} filter - Filter to render.\n -->\n <slot v-if=\"hasSlot(slotName)\" :name=\"slotName\" :filter=\"selectedFilter\">\n <span class=\"xds:tag\">{{ (selectedFilter as BooleanFilter).label }}</span>\n </slot>\n\n <!--\n @slot Default filter rendering. It renders the filter label by default.\n @binding {Filter} filter - Filter to render.\n -->\n <slot v-else name=\"default\" :filter=\"selectedFilter\">\n {{ (selectedFilter as BooleanFilter).label }}\n </slot>\n </li>\n </component>\n </SelectedFilters>\n</template>\n\n<script lang=\"ts\">\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport type { BooleanFilter, Facet, Filter } from '@empathyco/x-types'\nimport type { PropType } from 'vue'\nimport type { RenderFilter } from './selected-filters-list.types'\nimport { isFacetFilter } from '@empathyco/x-types'\nimport { defineComponent } from 'vue'\nimport { AnimationProp } from '../../../../types'\nimport { toKebabCase } from '../../../../utils/string'\nimport { useFacets } from '../../composables/use-facets'\nimport { facetsXModule } from '../../x-module'\nimport SelectedFilters from './selected-filters.vue'\n\n/**\n * This component renders a list of selected filters from every facet, or from the facet\n * ids passed as property. It uses the SelectedFilters component (state).\n *\n * It provides two slots: a scoped one which name is the filter facet id; and a default one.\n * Both exposes the filter and renders the filter label by default.\n *\n * The property \"alwaysVisible\" handles if the component is rendered if no filters are selected.\n *\n * @public\n */\nexport default defineComponent({\n name: 'SelectedFiltersList',\n xModule: facetsXModule.name,\n components: { SelectedFilters },\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 selected filters list. */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n },\n setup(props, { slots }) {\n const { selectedFilters } = useFacets(props)\n\n /**\n * Transforms a dictionary of Filters including the slot name.\n *\n * @param selectedFilters - A list of selected filters without slot name.\n *\n * @returns A dictionary of facets with the slot name.\n */\n function mapSlot(selectedFilters: Filter[]): RenderFilter[] {\n return selectedFilters.map(filter => ({\n slotName: isFacetFilter(filter) ? toKebabCase(filter.facetId as string) : 'default',\n selectedFilter: filter,\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 selectedFilters,\n mapSlot,\n hasSlot,\n }\n },\n})\n</script>\n\n<docs lang=\"mdx\">\n## Example\n\nThis component renders a list of selected filters from every facet, or from the facets which facets\nids are passed as property. It uses the SelectedFilters component (state).\n\nIt provides two slots: a scoped one which name is the filter facet id; and a default one. Both\nexposes the filter and renders the filter label by default.\n\nThe property \"alwaysVisible\" handles if the component is rendered if no filters are selected.\n\n### Default usage\n\n```vue\n<template>\n <SelectedFiltersList />\n</template>\n\n<script setup>\nimport { SelectedFiltersList } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Customized usage\n\n```vue\n<template>\n <SelectedFiltersList #default=\"{ filter }\">Default: {{ filter.label }}</SelectedFiltersList>\n</template>\n\n<script setup>\nimport { SelectedFiltersList } from '@empathyco/x-components/facets'\n</script>\n```\n\n```vue\n<template>\n <SelectedFiltersList>\n <template #default=\"{ filter }\">Default: {{ filter.label }}</template>\n <template #brand_facet=\"{ filter }\">Brand: {{ filter.label }}</template>\n <template #age_facet=\"{ filter }\">Age: {{ filter.label }}</template>\n <template #price_facet=\"{ filter }\">Price: {{ filter.label }}</template>\n </SelectedFiltersList>\n</template>\n\n<script setup>\nimport { SelectedFiltersList } from '@empathyco/x-components/facets'\n</script>\n```\n\n#### Always visible\n\nIf \"alwaysVisible\" is true, the component is rendered no matter if there are some filter selected.\nIf \"alwaysVisible\" is false (default), the component is rendered if there are some filter selected.\n\n```vue\n<template>\n <SelectedFiltersList :alwaysVisible=\"true\" />\n</template>\n\n<script setup>\nimport { SelectedFiltersList } from '@empathyco/x-components/facets'\n</script>\n```\n\nOutput:\n\n```html\n<div class=\"x-selected-filters\">\n <ul class=\"x-selected-filters-list\" data-test=\"selected-filters-list\"></ul>\n</div>\n```\n\n#### Providing an array of facet ids\n\nIn this example, the selected filters computed are the ones that match the facet ids passed as\nproperties.\n\n```vue\n<template>\n <SelectedFiltersList :facetsIds=\"['brand_facet', 'gender_facet']\" />\n</template>\n\n<script setup>\nimport { SelectedFiltersList } from '@empathyco/x-components/facets'\n</script>\n```\n</docs>\n"],"names":["_createBlock","_openBlock","_resolveDynamicComponent","_createElementBlock","_Fragment","_renderList","_renderSlot","_createElementVNode","_toDisplayString","_createTextVNode"],"mappings":";;;;AAoBgB,MAAA,UAAA,GAAA,EAAA,KAAA,EAAM,SAAA,EAAS;;;sBAnB7BA,WAAA,CA+BkB,0BAAA,EAAA;AAAA,IA/BA,YAAA,EAAY,IAAA,CAAA,SAAA;AAAA,IAAY,gBAAA,EAAgB,IAAA,CAAA;AAAA,GAAA,EAAA;qBACxD,MA6BY;AAAA,OAAAC,SAAA,EAAA,EA7BZD,WAAA,CA6BYE,wBA5BL,IAAA,CAAA,SAAS,CAAA,EAAA;AAAA,QACd,KAAA,EAAM,yBAAA;AAAA,QACN,WAAA,EAAU,uBAAA;AAAA,QACV,GAAA,EAAI;AAAA,OAAA,EAAA;yBAGF,MAAgE;AAAA,WAAAD,SAAA,CAAA,IAAA,CAAA,EADlEE,kBAAA;AAAA,YAsBKC,QAAA;AAAA,YAAA,IAAA;AAAA,YAAAC,UAAA,CArBoC,IAAA,CAAA,OAAA,CAAQ,IAAA,CAAA,eAAe,CAAA,EAAA,CAAA,EAArD,QAAA,EAAU,cAAA,EAAc,KAAA;kCADnCF,kBAAA,CAsBK,IAAA,EAAA;AAAA,gBApBF,KAAK,cAAA,CAAe,EAAA;AAAA,gBACrB,KAAA,EAAM,+BAAA;AAAA,gBACN,WAAA,EAAU;AAAA,eAAA,EAAA;
|
|
1
|
+
{"version":3,"file":"selected-filters-list.vue.js","sources":["../../../../../../src/x-modules/facets/components/lists/selected-filters-list.vue"],"sourcesContent":["<template>\n <SelectedFilters :facets-ids=\"facetsIds\" :always-visible=\"alwaysVisible\">\n <component\n :is=\"animation\"\n class=\"x-selected-filters-list\"\n data-test=\"selected-filters-list\"\n tag=\"ul\"\n >\n <li\n v-for=\"{ slotName, selectedFilter } in mapSlot(selectedFilters)\"\n :key=\"selectedFilter.id\"\n class=\"x-selected-filters-list__item\"\n data-test=\"selected-filters-list-item\"\n >\n <!--\n @slot Custom filter rendering. Dynamic slot defined in the template with the filter\n facet id. It renders the filter label by default.\n @binding {Filter} filter - Filter to render.\n -->\n <slot v-if=\"hasSlot(slotName)\" :name=\"slotName\" :filter=\"selectedFilter\">\n <span class=\"xds:tag\">{{ (selectedFilter as BooleanFilter).label }}</span>\n </slot>\n\n <!--\n @slot Default filter rendering. It renders the filter label by default.\n @binding {Filter} filter - Filter to render.\n -->\n <slot v-else name=\"default\" :filter=\"selectedFilter\">\n {{ (selectedFilter as BooleanFilter).label }}\n </slot>\n </li>\n </component>\n </SelectedFilters>\n</template>\n\n<script lang=\"ts\">\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport type { BooleanFilter, Facet, Filter } from '@empathyco/x-types'\nimport type { PropType } from 'vue'\nimport type { RenderFilter } from './selected-filters-list.types'\nimport { isFacetFilter } from '@empathyco/x-types'\nimport { defineComponent } from 'vue'\nimport { AnimationProp } from '../../../../types'\nimport { toKebabCase } from '../../../../utils/string'\nimport { useFacets } from '../../composables/use-facets'\nimport { facetsXModule } from '../../x-module'\nimport SelectedFilters from './selected-filters.vue'\n\n/**\n * This component renders a list of selected filters from every facet, or from the facet\n * ids passed as property. It uses the SelectedFilters component (state).\n *\n * It provides two slots: a scoped one which name is the filter facet id; and a default one.\n * Both exposes the filter and renders the filter label by default.\n *\n * The property \"alwaysVisible\" handles if the component is rendered if no filters are selected.\n *\n * @public\n */\nexport default defineComponent({\n name: 'SelectedFiltersList',\n xModule: facetsXModule.name,\n components: { SelectedFilters },\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 selected filters list. */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n },\n setup(props, { slots }) {\n const { selectedFilters } = useFacets(props)\n\n /**\n * Transforms a dictionary of Filters including the slot name.\n *\n * @param selectedFilters - A list of selected filters without slot name.\n *\n * @returns A dictionary of facets with the slot name.\n */\n function mapSlot(selectedFilters: Filter[]): RenderFilter[] {\n return selectedFilters.map(filter => ({\n slotName: isFacetFilter(filter) ? toKebabCase(filter.facetId as string) : 'default',\n selectedFilter: filter,\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 selectedFilters,\n mapSlot,\n hasSlot,\n }\n },\n})\n</script>\n\n<docs lang=\"mdx\">\n## Example\n\nThis component renders a list of selected filters from every facet, or from the facets which facets\nids are passed as property. It uses the SelectedFilters component (state).\n\nIt provides two slots: a scoped one which name is the filter facet id; and a default one. Both\nexposes the filter and renders the filter label by default.\n\nThe property \"alwaysVisible\" handles if the component is rendered if no filters are selected.\n\n### Default usage\n\n```vue\n<template>\n <SelectedFiltersList />\n</template>\n\n<script setup>\nimport { SelectedFiltersList } from '@empathyco/x-components/facets'\n</script>\n```\n\n### Customized usage\n\n```vue\n<template>\n <SelectedFiltersList #default=\"{ filter }\">Default: {{ filter.label }}</SelectedFiltersList>\n</template>\n\n<script setup>\nimport { SelectedFiltersList } from '@empathyco/x-components/facets'\n</script>\n```\n\n```vue\n<template>\n <SelectedFiltersList>\n <template #default=\"{ filter }\">Default: {{ filter.label }}</template>\n <template #brand_facet=\"{ filter }\">Brand: {{ filter.label }}</template>\n <template #age_facet=\"{ filter }\">Age: {{ filter.label }}</template>\n <template #price_facet=\"{ filter }\">Price: {{ filter.label }}</template>\n </SelectedFiltersList>\n</template>\n\n<script setup>\nimport { SelectedFiltersList } from '@empathyco/x-components/facets'\n</script>\n```\n\n#### Always visible\n\nIf \"alwaysVisible\" is true, the component is rendered no matter if there are some filter selected.\nIf \"alwaysVisible\" is false (default), the component is rendered if there are some filter selected.\n\n```vue\n<template>\n <SelectedFiltersList :alwaysVisible=\"true\" />\n</template>\n\n<script setup>\nimport { SelectedFiltersList } from '@empathyco/x-components/facets'\n</script>\n```\n\nOutput:\n\n```html\n<div class=\"x-selected-filters\">\n <ul class=\"x-selected-filters-list\" data-test=\"selected-filters-list\"></ul>\n</div>\n```\n\n#### Providing an array of facet ids\n\nIn this example, the selected filters computed are the ones that match the facet ids passed as\nproperties.\n\n```vue\n<template>\n <SelectedFiltersList :facetsIds=\"['brand_facet', 'gender_facet']\" />\n</template>\n\n<script setup>\nimport { SelectedFiltersList } from '@empathyco/x-components/facets'\n</script>\n```\n</docs>\n"],"names":["_createBlock","_openBlock","_resolveDynamicComponent","_createElementBlock","_Fragment","_renderList","_renderSlot","_createElementVNode","_toDisplayString","_createTextVNode"],"mappings":";;;;AAoBgB,MAAA,UAAA,GAAA,EAAA,KAAA,EAA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;AAAA;AAAA,iBAAA,EAAA,MAAA,EAAA,CAAA;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-preview.vue.js","sources":["../../../../../src/x-modules/queries-preview/components/query-preview.vue"],"sourcesContent":["<template>\n <!-- eslint-disable vue/no-unused-refs -->\n <section\n ref=\"queryPreviewElement\"\n class=\"x-query-preview-wrapper__default-content\"\n :class=\"{ 'x-query-preview-wrapper--placeholder': showPlaceholder }\"\n >\n <ul v-if=\"hasResults\" data-test=\"query-preview\" class=\"x-query-preview\">\n <li\n v-for=\"result in queryPreviewResults?.results\"\n :key=\"result.id\"\n class=\"x-query-preview__item\"\n data-test=\"query-preview-item\"\n >\n <!--\n @slot Query Preview result slot.\n @binding {Result} result - A Query Preview result\n -->\n <slot name=\"result\" :result=\"result\">\n <span data-test=\"result-name\">{{ result.name }}</span>\n </slot>\n </li>\n </ul>\n </section>\n</template>\n\n<script lang=\"ts\">\nimport type { Filter, SearchRequest } from '@empathyco/x-types'\nimport type { PropType, Ref } from 'vue'\nimport type { FeatureLocation, QueryFeature } from '../../../types'\nimport type { DebouncedFunction } from '../../../utils'\nimport type { QueryPreviewInfo } from '../store/types'\nimport { deepEqual } from '@empathyco/x-utils'\nimport { computed, defineComponent, h, inject, onBeforeUnmount, provide, ref, watch } from 'vue'\nimport { LIST_ITEMS_KEY } from '../../../components'\nimport { useOnDisplay, useState, useXBus } from '../../../composables'\nimport { createOrigin, createRawFilters, debounceFunction } from '../../../utils'\nimport { getHashFromQueryPreviewInfo } from '../utils/get-hash-from-query-preview'\nimport { queriesPreviewXModule } from '../x-module'\n\n/**\n * Retrieves a preview of the results of a query and exposes them in the default slot,\n * along with the query preview and the totalResults of the search request.\n * By default, it renders the names of the results.\n *\n * @public\n */\nexport default defineComponent({\n name: 'QueryPreview',\n xModule: queriesPreviewXModule.name,\n props: {\n /** The information about the request of the query preview. */\n queryPreviewInfo: {\n type: Object as PropType<QueryPreviewInfo>,\n required: true,\n },\n /** The origin property for the request. */\n queryFeature: {\n type: String as PropType<QueryFeature>,\n },\n /** Number of query preview results to be rendered. */\n maxItemsToRender: {\n type: Number,\n },\n /**\n * Controls whether the query preview requests should be triggered when the component is visible in the viewport.\n */\n loadWhenVisible: {\n type: Boolean,\n default: false,\n },\n /**\n * Debounce time in milliseconds for triggering the search requests.\n * It will default to 0 to fit the most common use case (pre-search),\n * and it would work properly with a 250 value inside empathize.\n */\n debounceTimeMs: {\n type: Number,\n default: 0,\n },\n /**\n * Controls whether the QueryPreview should be removed from the state\n * when the component is destroyed.\n */\n persistInCache: {\n type: Boolean,\n default: false,\n },\n },\n emits: ['load', 'error'],\n setup(props, { emit, slots }) {\n const xBus = useXBus()\n\n /**\n * previewResults: The results preview of the queries preview cacheable mounted.\n * It is a dictionary, indexed by the query preview query.\n *\n * params: As the request is handled in this component, we need\n * the extra params that will be used in the request.\n *\n * config: As the request is handled in this component, we need\n * the config that will be used in the request.\n */\n const { queriesPreview: previewResults, params, config } = useState('queriesPreview')\n\n /**\n * Template ref for the root element to track visibility.\n */\n const queryPreviewElement = ref<HTMLElement | null>(null)\n\n /**\n * Query Preview key converted into a unique id.\n *\n * @returns The query hash.\n */\n const queryPreviewHash = computed(() =>\n getHashFromQueryPreviewInfo(props.queryPreviewInfo, {\n ...params.value,\n ...props.queryPreviewInfo.extraParams,\n }),\n )\n\n provide('queryPreviewHash', queryPreviewHash)\n\n /**\n * Gets from the state the results preview of the query preview.\n *\n * @returns The results preview of the actual query preview.\n */\n const queryPreviewResults = computed(() => {\n const resultsPreview = previewResults.value[queryPreviewHash.value]\n return resultsPreview?.results\n ? {\n ...resultsPreview,\n results: resultsPreview.results.slice(0, props.maxItemsToRender),\n }\n : undefined\n })\n\n /**\n * The results to render from the state.\n *\n * @remarks The results list are provided with `items` key. It can be\n * concatenated with list items from components such as `BannersList`, `PromotedsList`,\n * `BaseGrid` or any component that injects the list.\n *\n * @returns A list of results.\n */\n const results = computed(() => queryPreviewResults.value?.results)\n provide(LIST_ITEMS_KEY as string, results)\n\n /**\n * It injects the provided {@link FeatureLocation} of the selected query in the search request.\n *\n * @internal\n */\n const injectedLocation = inject<Ref<FeatureLocation> | FeatureLocation>('location', 'none')\n const location =\n typeof injectedLocation === 'object' && 'value' in injectedLocation\n ? injectedLocation.value\n : injectedLocation\n\n /**\n * The computed request object to be used to retrieve the query preview results.\n *\n * @returns The search request object.\n */\n const queryPreviewRequest = computed<SearchRequest>(() => {\n const origin = createOrigin({\n feature: props.queryFeature,\n location,\n })\n const filters = props.queryPreviewInfo.filters?.reduce(\n (filtersList, filterId) => {\n const facetId = filterId.split(':')[0]\n const rawFilter = createRawFilters([filterId])[0]\n filtersList[facetId] = filtersList[facetId]\n ? filtersList[facetId].concat(rawFilter)\n : [rawFilter]\n\n return filtersList\n },\n {} as Record<string, Filter[]>,\n )\n\n return {\n query: props.queryPreviewInfo.query,\n rows: config.value.maxItemsToRequest,\n extraParams: {\n ...params.value,\n ...props.queryPreviewInfo.extraParams,\n },\n filters,\n ...(origin && { origin }),\n }\n })\n\n /**\n * The debounce method to trigger the request after the debounceTimeMs defined\n * for cacheable queries.\n *\n * @returns The search request object.\n */\n const emitQueryPreviewRequestUpdated = computed<DebouncedFunction<[SearchRequest]>>(() =>\n debounceFunction(request => {\n xBus.emit('QueryPreviewRequestUpdated', request, { priority: 0, replaceable: false })\n }, props.debounceTimeMs),\n )\n\n /**\n * Initialises watcher to emit debounced requests, and first value for the requests.\n *\n * @internal\n */\n watch(queryPreviewRequest, (newRequest, oldRequest) => {\n if (!deepEqual(newRequest, oldRequest) && !props.loadWhenVisible) {\n emitQueryPreviewRequestUpdated.value(newRequest)\n }\n })\n\n const cachedQueryPreview = previewResults.value[queryPreviewHash.value]\n\n // If the query has been saved it will emit load instead of the emitting the updated request.\n if (cachedQueryPreview?.status === 'success') {\n emit('load', queryPreviewHash.value)\n xBus.emit('QueryPreviewMounted', queryPreviewHash.value, {\n priority: 0,\n replaceable: false,\n })\n } else if (!props.loadWhenVisible) {\n emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value)\n }\n\n /**\n * Watch element visibility and emit request when it becomes visible for the first time\n * (only when loadWhenVisible is true).\n */\n const { unwatchDisplay } = useOnDisplay({\n element: queryPreviewElement,\n callback: () => {\n if (props.loadWhenVisible && cachedQueryPreview?.status !== 'success') {\n emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value)\n }\n },\n })\n\n /**\n * Cancels the (remaining) requests when the component is destroyed\n * via the `debounce.cancel()` method.\n * If the prop 'persistInCache' is set to false, it also removes the QueryPreview\n * from the state when the component is destroyed.\n */\n onBeforeUnmount(() => {\n unwatchDisplay?.()\n emitQueryPreviewRequestUpdated.value.cancel()\n xBus.emit(\n 'QueryPreviewUnmounted',\n { queryPreviewHash: queryPreviewHash.value, cache: props.persistInCache },\n {\n priority: 0,\n replaceable: false,\n },\n )\n })\n\n /**\n * Cancels the previous request when the debounced function changes (e.g: the debounceTimeMs\n * prop changes or there is a request in progress that cancels it).\n *\n * @param _new - The new debounced function.\n * @param old - The previous debounced function.\n * @internal\n */\n watch(\n emitQueryPreviewRequestUpdated,\n (_new: DebouncedFunction<[SearchRequest]>, old: DebouncedFunction<[SearchRequest]>) => {\n old.cancel()\n },\n )\n\n const queryPreviewResultsStatus = computed(() => queryPreviewResults.value?.status)\n\n /**\n * Emits an event when the query results are loaded or fail to load.\n *\n * @param status - The status of the query preview request.\n */\n watch(queryPreviewResultsStatus, () => {\n if (queryPreviewResultsStatus.value === 'success') {\n emit(results.value?.length ? 'load' : 'error', queryPreviewHash.value)\n } else if (queryPreviewResultsStatus.value === 'error') {\n emit('error', queryPreviewHash.value)\n }\n })\n\n const hasResults = computed(() => (queryPreviewResults.value?.totalResults ?? 0) > 0)\n\n /**\n * Whether the wrapper should reserve placeholder space (min-height) in place of\n * the results while the query preview has not been loaded yet.\n *\n * It is only applied when `loadWhenVisible` is enabled, so the component keeps a\n * visible space and the viewport visibility trigger has a realistic area to work\n * with.\n *\n * @internal\n */\n const showPlaceholder = computed(() => {\n const status = queryPreviewResults.value?.status\n return (\n props.loadWhenVisible && !hasResults.value && status !== 'success' && status !== 'error'\n )\n })\n\n /**\n * Render function to execute the `default` slot, binding `slotsProps` and getting only the\n * first `vNode` to avoid Fragments and Text root nodes.\n *\n * @remarks `slotProps` must be values without Vue reactivity and located inside the\n * render-function to update the binding data properly.\n *\n * @returns The root `vNode` of the `default` slot or empty string if there are no results. Always wrapped in a section\n * element with the `x-query-preview-wrapper__slot-content` class.\n */\n function renderDefaultSlot() {\n const slotProps = {\n queryPreviewInfo: props.queryPreviewInfo,\n queryPreviewHash: queryPreviewHash.value,\n results: queryPreviewResults.value?.results,\n totalResults: queryPreviewResults.value?.totalResults,\n displayTagging: queryPreviewResults.value?.displayTagging,\n queryTagging: queryPreviewResults.value?.queryTagging,\n }\n\n const slotContent = hasResults.value ? slots.default?.(slotProps)[0] : ''\n\n return h(\n 'section',\n {\n ref: queryPreviewElement,\n class: showPlaceholder.value\n ? 'x-query-preview-wrapper__slot-content x-query-preview-wrapper--placeholder'\n : 'x-query-preview-wrapper__slot-content',\n },\n [slotContent],\n )\n }\n\n /* Hack to render through a render-function, the `default` slot or, in its absence,\n the component itself. It is the alternative for the NoElement antipattern. */\n const componentProps = {\n hasResults,\n queryPreviewResults,\n queryPreviewElement,\n showPlaceholder,\n }\n return (slots.default ? renderDefaultSlot : componentProps) as typeof componentProps\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-query-preview-wrapper--placeholder {\n min-block-size: 200px;\n position: relative;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nA list of events that the component will emit:\n\n- [`QueryPreviewRequestUpdated`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n the event is emitted when the component is mounted and when the properties of the request object\n changes. The event payload is the `queryPreviewRequest` object.\n\n## Vue Events\n\nA list of vue events that the component will emit:\n\n- `load`: the event is emitted when the query results have been loaded.\n- `error`: the event is emitted if there is some error when retrieving the query results.\n\n## See it in action\n\nHere you have a basic example of how the QueryPreview is rendered. Keep in mind that this component\nis intended to be used overriding its default slot. By default it will only render the names of the\nresults.\n\n```vue live\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" />\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'sandals' })\n</script>\n```\n\n### Play with the default slot\n\nIn this example, the results will be rendered inside a sliding panel.\n\n```vue live\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" #default=\"{ totalResults, results }\">\n <section>\n <p>Total results: {{ totalResults }}</p>\n <SlidingPanel :resetOnContentChange=\"false\">\n <article\n v-for=\"result in results\"\n :key=\"result.id\"\n class=\"x-result\"\n style=\"max-width: 300px; overflow: hidden\"\n >\n <BaseResultLink :result=\"result\">\n <BaseResultImage :result=\"result\" class=\"x-result__picture\" />\n </BaseResultLink>\n <div class=\"x-result__description\">\n <BaseResultLink :result=\"result\">\n <h1 class=\"x-title3\">{{ result.name }}</h1>\n </BaseResultLink>\n </div>\n </article>\n </SlidingPanel>\n </section>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { BaseResultImage, BaseResultLink, SlidingPanel } from '@empathyco/x-components'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n\n### Play with the result slot\n\nThe component exposes a slot to override the result content, without modifying the list.\n\nIn this example, the ID of the results will be rendered along with the name.\n\n```vue\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" #result=\"{ result }\">\n <span>{{ result.id }}</span>\n <span>{{ result.name }}</span>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n\n### Play with props\n\nIn this example, the query preview has been limited to render a maximum of 4 results.\n\n```vue\n<template>\n <QueryPreview\n :maxItemsToRender=\"maxItemsToRender\"\n :queryPreviewInfo=\"queryPreviewInfo\"\n #default=\"{ results }\"\n >\n <BaseGrid #default=\"{ item }\" :items=\"results\">\n <BaseResultLink :result=\"item\">\n <BaseResultImage :result=\"item\" />\n </BaseResultLink>\n </BaseGrid>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { BaseGrid, BaseResultImage, BaseResultLink } from '@empathyco/x-components'\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst maxItemsToRender = 4\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_normalizeClass","_Fragment","_renderList","_renderSlot","_createElementVNode","_toDisplayString"],"mappings":";;;;;;;EAO0B,WAAA,EAAU,eAAA;AAAA,EAAgB,KAAA,EAAM;;AAY1C,MAAA,UAAA,GAAA,EAAA,WAAA,EAAU,aAAA,EAAa;;AAjBrC,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA;AAAA,IAqBU,SAAA;AAAA,IAAA;AAAA,MApBR,GAAA,EAAI,qBAAA;AAAA,MACJ,KAAA,EAAKC,cAAA,CAAA,CAAC,0CAAA,EAA0C,EAAA,sCAAA,EACE,IAAA,CAAA,eAAA,EAAe,CAAA;AAAA,KAAA;;MAEvD,IAAA,CAAA,UAAA,IAAAF,SAAA,EAAA,EAAVC,kBAAA,CAeK,MAfL,UAAA,EAeK;AAAA,SAAAD,SAAA,CAAA,IAAA,CAAA,EAdHC,kBAAA;AAAA,UAaKE,QAAA;AAAA,UAAA,IAAA;AAAA,UAAAC,UAAA,CAZc,IAAA,CAAA,mBAAA,EAAqB,OAAA,EAAO,CAAtC,MAAA,KAAM;gCADfH,kBAAA,CAaK,IAAA,EAAA;AAAA,cAXF,KAAK,MAAA,CAAO,EAAA;AAAA,cACb,KAAA,EAAM,uBAAA;AAAA,cACN,WAAA,EAAU;AAAA,aAAA,EAAA;cAMVI,UAAA,CAEO,IAAA,CAAA,MAAA,EAAA,QAAA,EAAA,EAFc,MAAA,EAAc,EAAnC,MAEO;AAAA,gBADLC,kBAAA;AAAA,kBAAsD,MAAA;AAAA,kBAAtD,UAAA;AAAA,kBAAsDC,eAAA,CAArB,OAAO,IAAI,CAAA;AAAA,kBAAA;AAAA;AAAA;AAAA,eAAA,EAAA,IAAA;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"query-preview.vue.js","sources":["../../../../../src/x-modules/queries-preview/components/query-preview.vue"],"sourcesContent":["<template>\n <!-- eslint-disable vue/no-unused-refs -->\n <section\n ref=\"queryPreviewElement\"\n class=\"x-query-preview-wrapper__default-content\"\n :class=\"{ 'x-query-preview-wrapper--placeholder': showPlaceholder }\"\n >\n <ul v-if=\"hasResults\" data-test=\"query-preview\" class=\"x-query-preview\">\n <li\n v-for=\"result in queryPreviewResults?.results\"\n :key=\"result.id\"\n class=\"x-query-preview__item\"\n data-test=\"query-preview-item\"\n >\n <!--\n @slot Query Preview result slot.\n @binding {Result} result - A Query Preview result\n -->\n <slot name=\"result\" :result=\"result\">\n <span data-test=\"result-name\">{{ result.name }}</span>\n </slot>\n </li>\n </ul>\n </section>\n</template>\n\n<script lang=\"ts\">\nimport type { Filter, SearchRequest } from '@empathyco/x-types'\nimport type { PropType, Ref } from 'vue'\nimport type { FeatureLocation, QueryFeature } from '../../../types'\nimport type { DebouncedFunction } from '../../../utils'\nimport type { QueryPreviewInfo } from '../store/types'\nimport { deepEqual } from '@empathyco/x-utils'\nimport { computed, defineComponent, h, inject, onBeforeUnmount, provide, ref, watch } from 'vue'\nimport { LIST_ITEMS_KEY } from '../../../components'\nimport { useOnDisplay, useState, useXBus } from '../../../composables'\nimport { createOrigin, createRawFilters, debounceFunction } from '../../../utils'\nimport { getHashFromQueryPreviewInfo } from '../utils/get-hash-from-query-preview'\nimport { queriesPreviewXModule } from '../x-module'\n\n/**\n * Retrieves a preview of the results of a query and exposes them in the default slot,\n * along with the query preview and the totalResults of the search request.\n * By default, it renders the names of the results.\n *\n * @public\n */\nexport default defineComponent({\n name: 'QueryPreview',\n xModule: queriesPreviewXModule.name,\n props: {\n /** The information about the request of the query preview. */\n queryPreviewInfo: {\n type: Object as PropType<QueryPreviewInfo>,\n required: true,\n },\n /** The origin property for the request. */\n queryFeature: {\n type: String as PropType<QueryFeature>,\n },\n /** Number of query preview results to be rendered. */\n maxItemsToRender: {\n type: Number,\n },\n /**\n * Controls whether the query preview requests should be triggered when the component is visible in the viewport.\n */\n loadWhenVisible: {\n type: Boolean,\n default: false,\n },\n /**\n * The id of the scroll container to compute the visibility against.\n */\n scrollTarget: {\n type: String,\n default: 'main-scroll',\n },\n /**\n * Debounce time in milliseconds for triggering the search requests.\n * It will default to 0 to fit the most common use case (pre-search),\n * and it would work properly with a 250 value inside empathize.\n */\n debounceTimeMs: {\n type: Number,\n default: 0,\n },\n /**\n * Controls whether the QueryPreview should be removed from the state\n * when the component is destroyed.\n */\n persistInCache: {\n type: Boolean,\n default: false,\n },\n },\n emits: ['load', 'error'],\n setup(props, { emit, slots }) {\n const xBus = useXBus()\n\n /**\n * previewResults: The results preview of the queries preview cacheable mounted.\n * It is a dictionary, indexed by the query preview query.\n *\n * params: As the request is handled in this component, we need\n * the extra params that will be used in the request.\n *\n * config: As the request is handled in this component, we need\n * the config that will be used in the request.\n */\n const { queriesPreview: previewResults, params, config } = useState('queriesPreview')\n\n /**\n * Template ref for the root element to track visibility.\n */\n const queryPreviewElement = ref<HTMLElement | null>(null)\n\n /**\n * Query Preview key converted into a unique id.\n *\n * @returns The query hash.\n */\n const queryPreviewHash = computed(() =>\n getHashFromQueryPreviewInfo(props.queryPreviewInfo, {\n ...params.value,\n ...props.queryPreviewInfo.extraParams,\n }),\n )\n\n provide('queryPreviewHash', queryPreviewHash)\n\n /**\n * Gets from the state the results preview of the query preview.\n *\n * @returns The results preview of the actual query preview.\n */\n const queryPreviewResults = computed(() => {\n const resultsPreview = previewResults.value[queryPreviewHash.value]\n return resultsPreview?.results\n ? {\n ...resultsPreview,\n results: resultsPreview.results.slice(0, props.maxItemsToRender),\n }\n : undefined\n })\n\n /**\n * The results to render from the state.\n *\n * @remarks The results list are provided with `items` key. It can be\n * concatenated with list items from components such as `BannersList`, `PromotedsList`,\n * `BaseGrid` or any component that injects the list.\n *\n * @returns A list of results.\n */\n const results = computed(() => queryPreviewResults.value?.results)\n provide(LIST_ITEMS_KEY as string, results)\n\n /**\n * It injects the provided {@link FeatureLocation} of the selected query in the search request.\n *\n * @internal\n */\n const injectedLocation = inject<Ref<FeatureLocation> | FeatureLocation>('location', 'none')\n const location =\n typeof injectedLocation === 'object' && 'value' in injectedLocation\n ? injectedLocation.value\n : injectedLocation\n\n /**\n * The computed request object to be used to retrieve the query preview results.\n *\n * @returns The search request object.\n */\n const queryPreviewRequest = computed<SearchRequest>(() => {\n const origin = createOrigin({\n feature: props.queryFeature,\n location,\n })\n const filters = props.queryPreviewInfo.filters?.reduce(\n (filtersList, filterId) => {\n const facetId = filterId.split(':')[0]\n const rawFilter = createRawFilters([filterId])[0]\n filtersList[facetId] = filtersList[facetId]\n ? filtersList[facetId].concat(rawFilter)\n : [rawFilter]\n\n return filtersList\n },\n {} as Record<string, Filter[]>,\n )\n\n return {\n query: props.queryPreviewInfo.query,\n rows: config.value.maxItemsToRequest,\n extraParams: {\n ...params.value,\n ...props.queryPreviewInfo.extraParams,\n },\n filters,\n ...(origin && { origin }),\n }\n })\n\n /**\n * The debounce method to trigger the request after the debounceTimeMs defined\n * for cacheable queries.\n *\n * @returns The search request object.\n */\n const emitQueryPreviewRequestUpdated = computed<DebouncedFunction<[SearchRequest]>>(() =>\n debounceFunction(request => {\n xBus.emit('QueryPreviewRequestUpdated', request, { priority: 0, replaceable: false })\n }, props.debounceTimeMs),\n )\n\n /**\n * Initialises watcher to emit debounced requests, and first value for the requests.\n *\n * @internal\n */\n watch(queryPreviewRequest, (newRequest, oldRequest) => {\n if (!deepEqual(newRequest, oldRequest) && !props.loadWhenVisible) {\n emitQueryPreviewRequestUpdated.value(newRequest)\n }\n })\n\n const cachedQueryPreview = previewResults.value[queryPreviewHash.value]\n\n // If the query has been saved it will emit load instead of the emitting the updated request.\n if (cachedQueryPreview?.status === 'success') {\n emit('load', queryPreviewHash.value)\n xBus.emit('QueryPreviewMounted', queryPreviewHash.value, {\n priority: 0,\n replaceable: false,\n })\n } else if (!props.loadWhenVisible) {\n emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value)\n }\n\n /**\n * Watch element visibility and emit request when it becomes visible for the first time.\n *\n * It is only set up when `loadWhenVisible` is enabled.\n *\n * The visibility is computed against the `MainScroll` container (`#main-scroll`) when it\n * exists, so the `rootMargin` preload zone works. When the container is not present\n * (e.g. host applications that scroll with the window via `MainScroll`'s `useWindow=true`),\n * it falls back to the viewport.\n */\n const unwatchDisplay = props.loadWhenVisible\n ? useOnDisplay({\n element: queryPreviewElement,\n threshold: 0,\n rootMargin: '0px 0px 200px 0px',\n scrollTargetId: props.scrollTarget,\n callback: () => {\n if (cachedQueryPreview?.status !== 'success') {\n emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value)\n }\n },\n }).unwatchDisplay\n : undefined\n\n /**\n * Cancels the (remaining) requests when the component is destroyed\n * via the `debounce.cancel()` method.\n * If the prop 'persistInCache' is set to false, it also removes the QueryPreview\n * from the state when the component is destroyed.\n */\n onBeforeUnmount(() => {\n unwatchDisplay?.()\n emitQueryPreviewRequestUpdated.value.cancel()\n xBus.emit(\n 'QueryPreviewUnmounted',\n { queryPreviewHash: queryPreviewHash.value, cache: props.persistInCache },\n {\n priority: 0,\n replaceable: false,\n },\n )\n })\n\n /**\n * Cancels the previous request when the debounced function changes (e.g: the debounceTimeMs\n * prop changes or there is a request in progress that cancels it).\n *\n * @param _new - The new debounced function.\n * @param old - The previous debounced function.\n * @internal\n */\n watch(\n emitQueryPreviewRequestUpdated,\n (_new: DebouncedFunction<[SearchRequest]>, old: DebouncedFunction<[SearchRequest]>) => {\n old.cancel()\n },\n )\n\n const queryPreviewResultsStatus = computed(() => queryPreviewResults.value?.status)\n\n /**\n * Emits an event when the query results are loaded or fail to load.\n *\n * @param status - The status of the query preview request.\n */\n watch(queryPreviewResultsStatus, () => {\n if (queryPreviewResultsStatus.value === 'success') {\n emit(results.value?.length ? 'load' : 'error', queryPreviewHash.value)\n } else if (queryPreviewResultsStatus.value === 'error') {\n emit('error', queryPreviewHash.value)\n }\n })\n\n const hasResults = computed(() => (queryPreviewResults.value?.totalResults ?? 0) > 0)\n\n /**\n * Whether the wrapper should reserve placeholder space (min-height) in place of\n * the results while the query preview has not been loaded yet.\n *\n * It is only applied when `loadWhenVisible` is enabled, so the component keeps a\n * visible space and the viewport visibility trigger has a realistic area to work\n * with.\n *\n * @internal\n */\n const showPlaceholder = computed(() => {\n const status = queryPreviewResults.value?.status\n return (\n props.loadWhenVisible && !hasResults.value && status !== 'success' && status !== 'error'\n )\n })\n\n /**\n * Render function to execute the `default` slot, binding `slotsProps` and getting only the\n * first `vNode` to avoid Fragments and Text root nodes.\n *\n * @remarks `slotProps` must be values without Vue reactivity and located inside the\n * render-function to update the binding data properly.\n *\n * @returns The root `vNode` of the `default` slot or empty string if there are no results. Always wrapped in a section\n * element with the `x-query-preview-wrapper__slot-content` class.\n */\n function renderDefaultSlot() {\n const slotProps = {\n queryPreviewInfo: props.queryPreviewInfo,\n queryPreviewHash: queryPreviewHash.value,\n results: queryPreviewResults.value?.results,\n totalResults: queryPreviewResults.value?.totalResults,\n displayTagging: queryPreviewResults.value?.displayTagging,\n queryTagging: queryPreviewResults.value?.queryTagging,\n }\n\n const slotContent = hasResults.value ? slots.default?.(slotProps)[0] : ''\n\n return h(\n 'section',\n {\n ref: queryPreviewElement,\n class: showPlaceholder.value\n ? 'x-query-preview-wrapper__slot-content x-query-preview-wrapper--placeholder'\n : 'x-query-preview-wrapper__slot-content',\n },\n [slotContent],\n )\n }\n\n /* Hack to render through a render-function, the `default` slot or, in its absence,\n the component itself. It is the alternative for the NoElement antipattern. */\n const componentProps = {\n hasResults,\n queryPreviewResults,\n queryPreviewElement,\n showPlaceholder,\n }\n return (slots.default ? renderDefaultSlot : componentProps) as typeof componentProps\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-query-preview-wrapper--placeholder {\n min-block-size: 200px;\n position: relative;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nA list of events that the component will emit:\n\n- [`QueryPreviewRequestUpdated`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n the event is emitted when the component is mounted and when the properties of the request object\n changes. The event payload is the `queryPreviewRequest` object.\n\n## Vue Events\n\nA list of vue events that the component will emit:\n\n- `load`: the event is emitted when the query results have been loaded.\n- `error`: the event is emitted if there is some error when retrieving the query results.\n\n## See it in action\n\nHere you have a basic example of how the QueryPreview is rendered. Keep in mind that this component\nis intended to be used overriding its default slot. By default it will only render the names of the\nresults.\n\n```vue live\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" />\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'sandals' })\n</script>\n```\n\n### Play with the default slot\n\nIn this example, the results will be rendered inside a sliding panel.\n\n```vue live\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" #default=\"{ totalResults, results }\">\n <section>\n <p>Total results: {{ totalResults }}</p>\n <SlidingPanel :resetOnContentChange=\"false\">\n <article\n v-for=\"result in results\"\n :key=\"result.id\"\n class=\"x-result\"\n style=\"max-width: 300px; overflow: hidden\"\n >\n <BaseResultLink :result=\"result\">\n <BaseResultImage :result=\"result\" class=\"x-result__picture\" />\n </BaseResultLink>\n <div class=\"x-result__description\">\n <BaseResultLink :result=\"result\">\n <h1 class=\"x-title3\">{{ result.name }}</h1>\n </BaseResultLink>\n </div>\n </article>\n </SlidingPanel>\n </section>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { BaseResultImage, BaseResultLink, SlidingPanel } from '@empathyco/x-components'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n\n### Play with the result slot\n\nThe component exposes a slot to override the result content, without modifying the list.\n\nIn this example, the ID of the results will be rendered along with the name.\n\n```vue\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" #result=\"{ result }\">\n <span>{{ result.id }}</span>\n <span>{{ result.name }}</span>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n\n### Play with props\n\nIn this example, the query preview has been limited to render a maximum of 4 results.\n\n```vue\n<template>\n <QueryPreview\n :maxItemsToRender=\"maxItemsToRender\"\n :queryPreviewInfo=\"queryPreviewInfo\"\n #default=\"{ results }\"\n >\n <BaseGrid #default=\"{ item }\" :items=\"results\">\n <BaseResultLink :result=\"item\">\n <BaseResultImage :result=\"item\" />\n </BaseResultLink>\n </BaseGrid>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { BaseGrid, BaseResultImage, BaseResultLink } from '@empathyco/x-components'\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst maxItemsToRender = 4\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_normalizeClass","_Fragment","_renderList","_renderSlot","_createElementVNode","_toDisplayString"],"mappings":";;;;;;;EAO0B,WAAA,EAAU,eAAA;AAAA,EAAgB,KAAA,EAAM;;AAY1C,MAAA,UAAA,GAAA,EAAA,WAAA,EAAU,aAAA,EAAa;;AAjBrC,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA;AAAA,IAqBU,SAAA;AAAA,IAAA;AAAA,MApBR,GAAA,EAAI,qBAAA;AAAA,MACJ,KAAA,EAAKC,cAAA,CAAA,CAAC,0CAAA,EAA0C,EAAA,sCAAA,EACE,IAAA,CAAA,eAAA,EAAe,CAAA;AAAA,KAAA;;MAEvD,IAAA,CAAA,UAAA,IAAAF,SAAA,EAAA,EAAVC,kBAAA,CAeK,MAfL,UAAA,EAeK;AAAA,SAAAD,SAAA,CAAA,IAAA,CAAA,EAdHC,kBAAA;AAAA,UAaKE,QAAA;AAAA,UAAA,IAAA;AAAA,UAAAC,UAAA,CAZc,IAAA,CAAA,mBAAA,EAAqB,OAAA,EAAO,CAAtC,MAAA,KAAM;gCADfH,kBAAA,CAaK,IAAA,EAAA;AAAA,cAXF,KAAK,MAAA,CAAO,EAAA;AAAA,cACb,KAAA,EAAM,uBAAA;AAAA,cACN,WAAA,EAAU;AAAA,aAAA,EAAA;cAMVI,UAAA,CAEO,IAAA,CAAA,MAAA,EAAA,QAAA,EAAA,EAFc,MAAA,EAAc,EAAnC,MAEO;AAAA,gBADLC,kBAAA;AAAA,kBAAsD,MAAA;AAAA,kBAAtD,UAAA;AAAA,kBAAsDC,eAAA,CAArB,OAAO,IAAI,CAAA;AAAA,kBAAA;AAAA;AAAA;AAAA,eAAA,EAAA,IAAA;;;;;;;;;;;;;;;;"}
|
|
@@ -139,6 +139,13 @@ var _sfc_main = defineComponent({
|
|
|
139
139
|
type: Boolean,
|
|
140
140
|
default: false,
|
|
141
141
|
},
|
|
142
|
+
/**
|
|
143
|
+
* The id of the scroll container to compute the visibility against.
|
|
144
|
+
*/
|
|
145
|
+
scrollTarget: {
|
|
146
|
+
type: String,
|
|
147
|
+
default: 'main-scroll',
|
|
148
|
+
},
|
|
142
149
|
/**
|
|
143
150
|
* Debounce time in milliseconds for triggering the search requests.
|
|
144
151
|
* It will default to 0 to fit the most common use case (pre-search),
|
|
@@ -280,17 +287,28 @@ var _sfc_main = defineComponent({
|
|
|
280
287
|
emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value);
|
|
281
288
|
}
|
|
282
289
|
/**
|
|
283
|
-
* Watch element visibility and emit request when it becomes visible for the first time
|
|
284
|
-
*
|
|
290
|
+
* Watch element visibility and emit request when it becomes visible for the first time.
|
|
291
|
+
*
|
|
292
|
+
* It is only set up when `loadWhenVisible` is enabled.
|
|
293
|
+
*
|
|
294
|
+
* The visibility is computed against the `MainScroll` container (`#main-scroll`) when it
|
|
295
|
+
* exists, so the `rootMargin` preload zone works. When the container is not present
|
|
296
|
+
* (e.g. host applications that scroll with the window via `MainScroll`'s `useWindow=true`),
|
|
297
|
+
* it falls back to the viewport.
|
|
285
298
|
*/
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
299
|
+
const unwatchDisplay = props.loadWhenVisible
|
|
300
|
+
? useOnDisplay({
|
|
301
|
+
element: queryPreviewElement,
|
|
302
|
+
threshold: 0,
|
|
303
|
+
rootMargin: '0px 0px 200px 0px',
|
|
304
|
+
scrollTargetId: props.scrollTarget,
|
|
305
|
+
callback: () => {
|
|
306
|
+
if (cachedQueryPreview?.status !== 'success') {
|
|
307
|
+
emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value);
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
}).unwatchDisplay
|
|
311
|
+
: undefined;
|
|
294
312
|
/**
|
|
295
313
|
* Cancels the (remaining) requests when the component is destroyed
|
|
296
314
|
* via the `debounce.cancel()` method.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-preview.vue2.js","sources":["../../../../../src/x-modules/queries-preview/components/query-preview.vue"],"sourcesContent":["<template>\n <!-- eslint-disable vue/no-unused-refs -->\n <section\n ref=\"queryPreviewElement\"\n class=\"x-query-preview-wrapper__default-content\"\n :class=\"{ 'x-query-preview-wrapper--placeholder': showPlaceholder }\"\n >\n <ul v-if=\"hasResults\" data-test=\"query-preview\" class=\"x-query-preview\">\n <li\n v-for=\"result in queryPreviewResults?.results\"\n :key=\"result.id\"\n class=\"x-query-preview__item\"\n data-test=\"query-preview-item\"\n >\n <!--\n @slot Query Preview result slot.\n @binding {Result} result - A Query Preview result\n -->\n <slot name=\"result\" :result=\"result\">\n <span data-test=\"result-name\">{{ result.name }}</span>\n </slot>\n </li>\n </ul>\n </section>\n</template>\n\n<script lang=\"ts\">\nimport type { Filter, SearchRequest } from '@empathyco/x-types'\nimport type { PropType, Ref } from 'vue'\nimport type { FeatureLocation, QueryFeature } from '../../../types'\nimport type { DebouncedFunction } from '../../../utils'\nimport type { QueryPreviewInfo } from '../store/types'\nimport { deepEqual } from '@empathyco/x-utils'\nimport { computed, defineComponent, h, inject, onBeforeUnmount, provide, ref, watch } from 'vue'\nimport { LIST_ITEMS_KEY } from '../../../components'\nimport { useOnDisplay, useState, useXBus } from '../../../composables'\nimport { createOrigin, createRawFilters, debounceFunction } from '../../../utils'\nimport { getHashFromQueryPreviewInfo } from '../utils/get-hash-from-query-preview'\nimport { queriesPreviewXModule } from '../x-module'\n\n/**\n * Retrieves a preview of the results of a query and exposes them in the default slot,\n * along with the query preview and the totalResults of the search request.\n * By default, it renders the names of the results.\n *\n * @public\n */\nexport default defineComponent({\n name: 'QueryPreview',\n xModule: queriesPreviewXModule.name,\n props: {\n /** The information about the request of the query preview. */\n queryPreviewInfo: {\n type: Object as PropType<QueryPreviewInfo>,\n required: true,\n },\n /** The origin property for the request. */\n queryFeature: {\n type: String as PropType<QueryFeature>,\n },\n /** Number of query preview results to be rendered. */\n maxItemsToRender: {\n type: Number,\n },\n /**\n * Controls whether the query preview requests should be triggered when the component is visible in the viewport.\n */\n loadWhenVisible: {\n type: Boolean,\n default: false,\n },\n /**\n * Debounce time in milliseconds for triggering the search requests.\n * It will default to 0 to fit the most common use case (pre-search),\n * and it would work properly with a 250 value inside empathize.\n */\n debounceTimeMs: {\n type: Number,\n default: 0,\n },\n /**\n * Controls whether the QueryPreview should be removed from the state\n * when the component is destroyed.\n */\n persistInCache: {\n type: Boolean,\n default: false,\n },\n },\n emits: ['load', 'error'],\n setup(props, { emit, slots }) {\n const xBus = useXBus()\n\n /**\n * previewResults: The results preview of the queries preview cacheable mounted.\n * It is a dictionary, indexed by the query preview query.\n *\n * params: As the request is handled in this component, we need\n * the extra params that will be used in the request.\n *\n * config: As the request is handled in this component, we need\n * the config that will be used in the request.\n */\n const { queriesPreview: previewResults, params, config } = useState('queriesPreview')\n\n /**\n * Template ref for the root element to track visibility.\n */\n const queryPreviewElement = ref<HTMLElement | null>(null)\n\n /**\n * Query Preview key converted into a unique id.\n *\n * @returns The query hash.\n */\n const queryPreviewHash = computed(() =>\n getHashFromQueryPreviewInfo(props.queryPreviewInfo, {\n ...params.value,\n ...props.queryPreviewInfo.extraParams,\n }),\n )\n\n provide('queryPreviewHash', queryPreviewHash)\n\n /**\n * Gets from the state the results preview of the query preview.\n *\n * @returns The results preview of the actual query preview.\n */\n const queryPreviewResults = computed(() => {\n const resultsPreview = previewResults.value[queryPreviewHash.value]\n return resultsPreview?.results\n ? {\n ...resultsPreview,\n results: resultsPreview.results.slice(0, props.maxItemsToRender),\n }\n : undefined\n })\n\n /**\n * The results to render from the state.\n *\n * @remarks The results list are provided with `items` key. It can be\n * concatenated with list items from components such as `BannersList`, `PromotedsList`,\n * `BaseGrid` or any component that injects the list.\n *\n * @returns A list of results.\n */\n const results = computed(() => queryPreviewResults.value?.results)\n provide(LIST_ITEMS_KEY as string, results)\n\n /**\n * It injects the provided {@link FeatureLocation} of the selected query in the search request.\n *\n * @internal\n */\n const injectedLocation = inject<Ref<FeatureLocation> | FeatureLocation>('location', 'none')\n const location =\n typeof injectedLocation === 'object' && 'value' in injectedLocation\n ? injectedLocation.value\n : injectedLocation\n\n /**\n * The computed request object to be used to retrieve the query preview results.\n *\n * @returns The search request object.\n */\n const queryPreviewRequest = computed<SearchRequest>(() => {\n const origin = createOrigin({\n feature: props.queryFeature,\n location,\n })\n const filters = props.queryPreviewInfo.filters?.reduce(\n (filtersList, filterId) => {\n const facetId = filterId.split(':')[0]\n const rawFilter = createRawFilters([filterId])[0]\n filtersList[facetId] = filtersList[facetId]\n ? filtersList[facetId].concat(rawFilter)\n : [rawFilter]\n\n return filtersList\n },\n {} as Record<string, Filter[]>,\n )\n\n return {\n query: props.queryPreviewInfo.query,\n rows: config.value.maxItemsToRequest,\n extraParams: {\n ...params.value,\n ...props.queryPreviewInfo.extraParams,\n },\n filters,\n ...(origin && { origin }),\n }\n })\n\n /**\n * The debounce method to trigger the request after the debounceTimeMs defined\n * for cacheable queries.\n *\n * @returns The search request object.\n */\n const emitQueryPreviewRequestUpdated = computed<DebouncedFunction<[SearchRequest]>>(() =>\n debounceFunction(request => {\n xBus.emit('QueryPreviewRequestUpdated', request, { priority: 0, replaceable: false })\n }, props.debounceTimeMs),\n )\n\n /**\n * Initialises watcher to emit debounced requests, and first value for the requests.\n *\n * @internal\n */\n watch(queryPreviewRequest, (newRequest, oldRequest) => {\n if (!deepEqual(newRequest, oldRequest) && !props.loadWhenVisible) {\n emitQueryPreviewRequestUpdated.value(newRequest)\n }\n })\n\n const cachedQueryPreview = previewResults.value[queryPreviewHash.value]\n\n // If the query has been saved it will emit load instead of the emitting the updated request.\n if (cachedQueryPreview?.status === 'success') {\n emit('load', queryPreviewHash.value)\n xBus.emit('QueryPreviewMounted', queryPreviewHash.value, {\n priority: 0,\n replaceable: false,\n })\n } else if (!props.loadWhenVisible) {\n emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value)\n }\n\n /**\n * Watch element visibility and emit request when it becomes visible for the first time\n * (only when loadWhenVisible is true).\n */\n const { unwatchDisplay } = useOnDisplay({\n element: queryPreviewElement,\n callback: () => {\n if (props.loadWhenVisible && cachedQueryPreview?.status !== 'success') {\n emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value)\n }\n },\n })\n\n /**\n * Cancels the (remaining) requests when the component is destroyed\n * via the `debounce.cancel()` method.\n * If the prop 'persistInCache' is set to false, it also removes the QueryPreview\n * from the state when the component is destroyed.\n */\n onBeforeUnmount(() => {\n unwatchDisplay?.()\n emitQueryPreviewRequestUpdated.value.cancel()\n xBus.emit(\n 'QueryPreviewUnmounted',\n { queryPreviewHash: queryPreviewHash.value, cache: props.persistInCache },\n {\n priority: 0,\n replaceable: false,\n },\n )\n })\n\n /**\n * Cancels the previous request when the debounced function changes (e.g: the debounceTimeMs\n * prop changes or there is a request in progress that cancels it).\n *\n * @param _new - The new debounced function.\n * @param old - The previous debounced function.\n * @internal\n */\n watch(\n emitQueryPreviewRequestUpdated,\n (_new: DebouncedFunction<[SearchRequest]>, old: DebouncedFunction<[SearchRequest]>) => {\n old.cancel()\n },\n )\n\n const queryPreviewResultsStatus = computed(() => queryPreviewResults.value?.status)\n\n /**\n * Emits an event when the query results are loaded or fail to load.\n *\n * @param status - The status of the query preview request.\n */\n watch(queryPreviewResultsStatus, () => {\n if (queryPreviewResultsStatus.value === 'success') {\n emit(results.value?.length ? 'load' : 'error', queryPreviewHash.value)\n } else if (queryPreviewResultsStatus.value === 'error') {\n emit('error', queryPreviewHash.value)\n }\n })\n\n const hasResults = computed(() => (queryPreviewResults.value?.totalResults ?? 0) > 0)\n\n /**\n * Whether the wrapper should reserve placeholder space (min-height) in place of\n * the results while the query preview has not been loaded yet.\n *\n * It is only applied when `loadWhenVisible` is enabled, so the component keeps a\n * visible space and the viewport visibility trigger has a realistic area to work\n * with.\n *\n * @internal\n */\n const showPlaceholder = computed(() => {\n const status = queryPreviewResults.value?.status\n return (\n props.loadWhenVisible && !hasResults.value && status !== 'success' && status !== 'error'\n )\n })\n\n /**\n * Render function to execute the `default` slot, binding `slotsProps` and getting only the\n * first `vNode` to avoid Fragments and Text root nodes.\n *\n * @remarks `slotProps` must be values without Vue reactivity and located inside the\n * render-function to update the binding data properly.\n *\n * @returns The root `vNode` of the `default` slot or empty string if there are no results. Always wrapped in a section\n * element with the `x-query-preview-wrapper__slot-content` class.\n */\n function renderDefaultSlot() {\n const slotProps = {\n queryPreviewInfo: props.queryPreviewInfo,\n queryPreviewHash: queryPreviewHash.value,\n results: queryPreviewResults.value?.results,\n totalResults: queryPreviewResults.value?.totalResults,\n displayTagging: queryPreviewResults.value?.displayTagging,\n queryTagging: queryPreviewResults.value?.queryTagging,\n }\n\n const slotContent = hasResults.value ? slots.default?.(slotProps)[0] : ''\n\n return h(\n 'section',\n {\n ref: queryPreviewElement,\n class: showPlaceholder.value\n ? 'x-query-preview-wrapper__slot-content x-query-preview-wrapper--placeholder'\n : 'x-query-preview-wrapper__slot-content',\n },\n [slotContent],\n )\n }\n\n /* Hack to render through a render-function, the `default` slot or, in its absence,\n the component itself. It is the alternative for the NoElement antipattern. */\n const componentProps = {\n hasResults,\n queryPreviewResults,\n queryPreviewElement,\n showPlaceholder,\n }\n return (slots.default ? renderDefaultSlot : componentProps) as typeof componentProps\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-query-preview-wrapper--placeholder {\n min-block-size: 200px;\n position: relative;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nA list of events that the component will emit:\n\n- [`QueryPreviewRequestUpdated`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n the event is emitted when the component is mounted and when the properties of the request object\n changes. The event payload is the `queryPreviewRequest` object.\n\n## Vue Events\n\nA list of vue events that the component will emit:\n\n- `load`: the event is emitted when the query results have been loaded.\n- `error`: the event is emitted if there is some error when retrieving the query results.\n\n## See it in action\n\nHere you have a basic example of how the QueryPreview is rendered. Keep in mind that this component\nis intended to be used overriding its default slot. By default it will only render the names of the\nresults.\n\n```vue live\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" />\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'sandals' })\n</script>\n```\n\n### Play with the default slot\n\nIn this example, the results will be rendered inside a sliding panel.\n\n```vue live\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" #default=\"{ totalResults, results }\">\n <section>\n <p>Total results: {{ totalResults }}</p>\n <SlidingPanel :resetOnContentChange=\"false\">\n <article\n v-for=\"result in results\"\n :key=\"result.id\"\n class=\"x-result\"\n style=\"max-width: 300px; overflow: hidden\"\n >\n <BaseResultLink :result=\"result\">\n <BaseResultImage :result=\"result\" class=\"x-result__picture\" />\n </BaseResultLink>\n <div class=\"x-result__description\">\n <BaseResultLink :result=\"result\">\n <h1 class=\"x-title3\">{{ result.name }}</h1>\n </BaseResultLink>\n </div>\n </article>\n </SlidingPanel>\n </section>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { BaseResultImage, BaseResultLink, SlidingPanel } from '@empathyco/x-components'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n\n### Play with the result slot\n\nThe component exposes a slot to override the result content, without modifying the list.\n\nIn this example, the ID of the results will be rendered along with the name.\n\n```vue\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" #result=\"{ result }\">\n <span>{{ result.id }}</span>\n <span>{{ result.name }}</span>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n\n### Play with props\n\nIn this example, the query preview has been limited to render a maximum of 4 results.\n\n```vue\n<template>\n <QueryPreview\n :maxItemsToRender=\"maxItemsToRender\"\n :queryPreviewInfo=\"queryPreviewInfo\"\n #default=\"{ results }\"\n >\n <BaseGrid #default=\"{ item }\" :items=\"results\">\n <BaseResultLink :result=\"item\">\n <BaseResultImage :result=\"item\" />\n </BaseResultLink>\n </BaseGrid>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { BaseGrid, BaseResultImage, BaseResultLink } from '@empathyco/x-components'\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst maxItemsToRender = 4\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n</docs>\n"],"names":["debounceFunction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA;;;;;;AAME;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,qBAAqB,CAAC,IAAI;AACnC,IAAA,KAAK,EAAE;;AAEL,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,MAAoC;AAC1C,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;;AAED,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAgC;AACvC,SAAA;;AAED,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,MAAM;AACb,SAAA;AACD;;AAEE;AACF,QAAA,eAAe,EAAE;AACf,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,KAAK;AACf,SAAA;AACD;;;;AAIE;AACF,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,CAAC;AACX,SAAA;AACD;;;AAGE;AACF,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,KAAK;AACf,SAAA;AACF,KAAA;AACD,IAAA,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;AACxB,IAAA,KAAK,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAI,EAAG,EAAA;AAC1B,QAAA,MAAM,IAAG,GAAI,OAAO,EAAC;AAErB;;;;;;;;;AASE;AACF,QAAA,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,EAAE,MAAK,KAAM,QAAQ,CAAC,gBAAgB,CAAA;AAEpF;;AAEE;AACF,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c;AACzD,gBAAA,YAAY,EAAE,mBAAmB,CAAC,KAAK,EAAE,YAAY;aACvD;YAEA,MAAM,WAAU,GAAI,UAAU,CAAC,KAAI,GAAI,KAAK,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA,GAAI,EAAC;YAExE,OAAO,CAAC,CACN,SAAS,EACT;AACE,gBAAA,GAAG,EAAE,mBAAmB;gBACxB,KAAK,EAAE,eAAe,CAAC;AACrB,sBAAE;AACF,sBAAE,uCAAuC;AAC5C,aAAA,EACD,CAAC,WAAW,CAAC,CACf;QACF;AAEA;AAC+E;AAC/E,QAAA,MAAM,iBAAiB;YACrB,UAAU;YACV,mBAAmB;YACnB,mBAAmB;YACnB,eAAe;SACjB;AACA,QAAA,QAAQ,KAAK,CAAC,OAAM,GAAI,iBAAgB,GAAI,cAAc;IAC5D,CAAC;AACF,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"query-preview.vue2.js","sources":["../../../../../src/x-modules/queries-preview/components/query-preview.vue"],"sourcesContent":["<template>\n <!-- eslint-disable vue/no-unused-refs -->\n <section\n ref=\"queryPreviewElement\"\n class=\"x-query-preview-wrapper__default-content\"\n :class=\"{ 'x-query-preview-wrapper--placeholder': showPlaceholder }\"\n >\n <ul v-if=\"hasResults\" data-test=\"query-preview\" class=\"x-query-preview\">\n <li\n v-for=\"result in queryPreviewResults?.results\"\n :key=\"result.id\"\n class=\"x-query-preview__item\"\n data-test=\"query-preview-item\"\n >\n <!--\n @slot Query Preview result slot.\n @binding {Result} result - A Query Preview result\n -->\n <slot name=\"result\" :result=\"result\">\n <span data-test=\"result-name\">{{ result.name }}</span>\n </slot>\n </li>\n </ul>\n </section>\n</template>\n\n<script lang=\"ts\">\nimport type { Filter, SearchRequest } from '@empathyco/x-types'\nimport type { PropType, Ref } from 'vue'\nimport type { FeatureLocation, QueryFeature } from '../../../types'\nimport type { DebouncedFunction } from '../../../utils'\nimport type { QueryPreviewInfo } from '../store/types'\nimport { deepEqual } from '@empathyco/x-utils'\nimport { computed, defineComponent, h, inject, onBeforeUnmount, provide, ref, watch } from 'vue'\nimport { LIST_ITEMS_KEY } from '../../../components'\nimport { useOnDisplay, useState, useXBus } from '../../../composables'\nimport { createOrigin, createRawFilters, debounceFunction } from '../../../utils'\nimport { getHashFromQueryPreviewInfo } from '../utils/get-hash-from-query-preview'\nimport { queriesPreviewXModule } from '../x-module'\n\n/**\n * Retrieves a preview of the results of a query and exposes them in the default slot,\n * along with the query preview and the totalResults of the search request.\n * By default, it renders the names of the results.\n *\n * @public\n */\nexport default defineComponent({\n name: 'QueryPreview',\n xModule: queriesPreviewXModule.name,\n props: {\n /** The information about the request of the query preview. */\n queryPreviewInfo: {\n type: Object as PropType<QueryPreviewInfo>,\n required: true,\n },\n /** The origin property for the request. */\n queryFeature: {\n type: String as PropType<QueryFeature>,\n },\n /** Number of query preview results to be rendered. */\n maxItemsToRender: {\n type: Number,\n },\n /**\n * Controls whether the query preview requests should be triggered when the component is visible in the viewport.\n */\n loadWhenVisible: {\n type: Boolean,\n default: false,\n },\n /**\n * The id of the scroll container to compute the visibility against.\n */\n scrollTarget: {\n type: String,\n default: 'main-scroll',\n },\n /**\n * Debounce time in milliseconds for triggering the search requests.\n * It will default to 0 to fit the most common use case (pre-search),\n * and it would work properly with a 250 value inside empathize.\n */\n debounceTimeMs: {\n type: Number,\n default: 0,\n },\n /**\n * Controls whether the QueryPreview should be removed from the state\n * when the component is destroyed.\n */\n persistInCache: {\n type: Boolean,\n default: false,\n },\n },\n emits: ['load', 'error'],\n setup(props, { emit, slots }) {\n const xBus = useXBus()\n\n /**\n * previewResults: The results preview of the queries preview cacheable mounted.\n * It is a dictionary, indexed by the query preview query.\n *\n * params: As the request is handled in this component, we need\n * the extra params that will be used in the request.\n *\n * config: As the request is handled in this component, we need\n * the config that will be used in the request.\n */\n const { queriesPreview: previewResults, params, config } = useState('queriesPreview')\n\n /**\n * Template ref for the root element to track visibility.\n */\n const queryPreviewElement = ref<HTMLElement | null>(null)\n\n /**\n * Query Preview key converted into a unique id.\n *\n * @returns The query hash.\n */\n const queryPreviewHash = computed(() =>\n getHashFromQueryPreviewInfo(props.queryPreviewInfo, {\n ...params.value,\n ...props.queryPreviewInfo.extraParams,\n }),\n )\n\n provide('queryPreviewHash', queryPreviewHash)\n\n /**\n * Gets from the state the results preview of the query preview.\n *\n * @returns The results preview of the actual query preview.\n */\n const queryPreviewResults = computed(() => {\n const resultsPreview = previewResults.value[queryPreviewHash.value]\n return resultsPreview?.results\n ? {\n ...resultsPreview,\n results: resultsPreview.results.slice(0, props.maxItemsToRender),\n }\n : undefined\n })\n\n /**\n * The results to render from the state.\n *\n * @remarks The results list are provided with `items` key. It can be\n * concatenated with list items from components such as `BannersList`, `PromotedsList`,\n * `BaseGrid` or any component that injects the list.\n *\n * @returns A list of results.\n */\n const results = computed(() => queryPreviewResults.value?.results)\n provide(LIST_ITEMS_KEY as string, results)\n\n /**\n * It injects the provided {@link FeatureLocation} of the selected query in the search request.\n *\n * @internal\n */\n const injectedLocation = inject<Ref<FeatureLocation> | FeatureLocation>('location', 'none')\n const location =\n typeof injectedLocation === 'object' && 'value' in injectedLocation\n ? injectedLocation.value\n : injectedLocation\n\n /**\n * The computed request object to be used to retrieve the query preview results.\n *\n * @returns The search request object.\n */\n const queryPreviewRequest = computed<SearchRequest>(() => {\n const origin = createOrigin({\n feature: props.queryFeature,\n location,\n })\n const filters = props.queryPreviewInfo.filters?.reduce(\n (filtersList, filterId) => {\n const facetId = filterId.split(':')[0]\n const rawFilter = createRawFilters([filterId])[0]\n filtersList[facetId] = filtersList[facetId]\n ? filtersList[facetId].concat(rawFilter)\n : [rawFilter]\n\n return filtersList\n },\n {} as Record<string, Filter[]>,\n )\n\n return {\n query: props.queryPreviewInfo.query,\n rows: config.value.maxItemsToRequest,\n extraParams: {\n ...params.value,\n ...props.queryPreviewInfo.extraParams,\n },\n filters,\n ...(origin && { origin }),\n }\n })\n\n /**\n * The debounce method to trigger the request after the debounceTimeMs defined\n * for cacheable queries.\n *\n * @returns The search request object.\n */\n const emitQueryPreviewRequestUpdated = computed<DebouncedFunction<[SearchRequest]>>(() =>\n debounceFunction(request => {\n xBus.emit('QueryPreviewRequestUpdated', request, { priority: 0, replaceable: false })\n }, props.debounceTimeMs),\n )\n\n /**\n * Initialises watcher to emit debounced requests, and first value for the requests.\n *\n * @internal\n */\n watch(queryPreviewRequest, (newRequest, oldRequest) => {\n if (!deepEqual(newRequest, oldRequest) && !props.loadWhenVisible) {\n emitQueryPreviewRequestUpdated.value(newRequest)\n }\n })\n\n const cachedQueryPreview = previewResults.value[queryPreviewHash.value]\n\n // If the query has been saved it will emit load instead of the emitting the updated request.\n if (cachedQueryPreview?.status === 'success') {\n emit('load', queryPreviewHash.value)\n xBus.emit('QueryPreviewMounted', queryPreviewHash.value, {\n priority: 0,\n replaceable: false,\n })\n } else if (!props.loadWhenVisible) {\n emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value)\n }\n\n /**\n * Watch element visibility and emit request when it becomes visible for the first time.\n *\n * It is only set up when `loadWhenVisible` is enabled.\n *\n * The visibility is computed against the `MainScroll` container (`#main-scroll`) when it\n * exists, so the `rootMargin` preload zone works. When the container is not present\n * (e.g. host applications that scroll with the window via `MainScroll`'s `useWindow=true`),\n * it falls back to the viewport.\n */\n const unwatchDisplay = props.loadWhenVisible\n ? useOnDisplay({\n element: queryPreviewElement,\n threshold: 0,\n rootMargin: '0px 0px 200px 0px',\n scrollTargetId: props.scrollTarget,\n callback: () => {\n if (cachedQueryPreview?.status !== 'success') {\n emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value)\n }\n },\n }).unwatchDisplay\n : undefined\n\n /**\n * Cancels the (remaining) requests when the component is destroyed\n * via the `debounce.cancel()` method.\n * If the prop 'persistInCache' is set to false, it also removes the QueryPreview\n * from the state when the component is destroyed.\n */\n onBeforeUnmount(() => {\n unwatchDisplay?.()\n emitQueryPreviewRequestUpdated.value.cancel()\n xBus.emit(\n 'QueryPreviewUnmounted',\n { queryPreviewHash: queryPreviewHash.value, cache: props.persistInCache },\n {\n priority: 0,\n replaceable: false,\n },\n )\n })\n\n /**\n * Cancels the previous request when the debounced function changes (e.g: the debounceTimeMs\n * prop changes or there is a request in progress that cancels it).\n *\n * @param _new - The new debounced function.\n * @param old - The previous debounced function.\n * @internal\n */\n watch(\n emitQueryPreviewRequestUpdated,\n (_new: DebouncedFunction<[SearchRequest]>, old: DebouncedFunction<[SearchRequest]>) => {\n old.cancel()\n },\n )\n\n const queryPreviewResultsStatus = computed(() => queryPreviewResults.value?.status)\n\n /**\n * Emits an event when the query results are loaded or fail to load.\n *\n * @param status - The status of the query preview request.\n */\n watch(queryPreviewResultsStatus, () => {\n if (queryPreviewResultsStatus.value === 'success') {\n emit(results.value?.length ? 'load' : 'error', queryPreviewHash.value)\n } else if (queryPreviewResultsStatus.value === 'error') {\n emit('error', queryPreviewHash.value)\n }\n })\n\n const hasResults = computed(() => (queryPreviewResults.value?.totalResults ?? 0) > 0)\n\n /**\n * Whether the wrapper should reserve placeholder space (min-height) in place of\n * the results while the query preview has not been loaded yet.\n *\n * It is only applied when `loadWhenVisible` is enabled, so the component keeps a\n * visible space and the viewport visibility trigger has a realistic area to work\n * with.\n *\n * @internal\n */\n const showPlaceholder = computed(() => {\n const status = queryPreviewResults.value?.status\n return (\n props.loadWhenVisible && !hasResults.value && status !== 'success' && status !== 'error'\n )\n })\n\n /**\n * Render function to execute the `default` slot, binding `slotsProps` and getting only the\n * first `vNode` to avoid Fragments and Text root nodes.\n *\n * @remarks `slotProps` must be values without Vue reactivity and located inside the\n * render-function to update the binding data properly.\n *\n * @returns The root `vNode` of the `default` slot or empty string if there are no results. Always wrapped in a section\n * element with the `x-query-preview-wrapper__slot-content` class.\n */\n function renderDefaultSlot() {\n const slotProps = {\n queryPreviewInfo: props.queryPreviewInfo,\n queryPreviewHash: queryPreviewHash.value,\n results: queryPreviewResults.value?.results,\n totalResults: queryPreviewResults.value?.totalResults,\n displayTagging: queryPreviewResults.value?.displayTagging,\n queryTagging: queryPreviewResults.value?.queryTagging,\n }\n\n const slotContent = hasResults.value ? slots.default?.(slotProps)[0] : ''\n\n return h(\n 'section',\n {\n ref: queryPreviewElement,\n class: showPlaceholder.value\n ? 'x-query-preview-wrapper__slot-content x-query-preview-wrapper--placeholder'\n : 'x-query-preview-wrapper__slot-content',\n },\n [slotContent],\n )\n }\n\n /* Hack to render through a render-function, the `default` slot or, in its absence,\n the component itself. It is the alternative for the NoElement antipattern. */\n const componentProps = {\n hasResults,\n queryPreviewResults,\n queryPreviewElement,\n showPlaceholder,\n }\n return (slots.default ? renderDefaultSlot : componentProps) as typeof componentProps\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-query-preview-wrapper--placeholder {\n min-block-size: 200px;\n position: relative;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Events\n\nA list of events that the component will emit:\n\n- [`QueryPreviewRequestUpdated`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n the event is emitted when the component is mounted and when the properties of the request object\n changes. The event payload is the `queryPreviewRequest` object.\n\n## Vue Events\n\nA list of vue events that the component will emit:\n\n- `load`: the event is emitted when the query results have been loaded.\n- `error`: the event is emitted if there is some error when retrieving the query results.\n\n## See it in action\n\nHere you have a basic example of how the QueryPreview is rendered. Keep in mind that this component\nis intended to be used overriding its default slot. By default it will only render the names of the\nresults.\n\n```vue live\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" />\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'sandals' })\n</script>\n```\n\n### Play with the default slot\n\nIn this example, the results will be rendered inside a sliding panel.\n\n```vue live\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" #default=\"{ totalResults, results }\">\n <section>\n <p>Total results: {{ totalResults }}</p>\n <SlidingPanel :resetOnContentChange=\"false\">\n <article\n v-for=\"result in results\"\n :key=\"result.id\"\n class=\"x-result\"\n style=\"max-width: 300px; overflow: hidden\"\n >\n <BaseResultLink :result=\"result\">\n <BaseResultImage :result=\"result\" class=\"x-result__picture\" />\n </BaseResultLink>\n <div class=\"x-result__description\">\n <BaseResultLink :result=\"result\">\n <h1 class=\"x-title3\">{{ result.name }}</h1>\n </BaseResultLink>\n </div>\n </article>\n </SlidingPanel>\n </section>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { BaseResultImage, BaseResultLink, SlidingPanel } from '@empathyco/x-components'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n\n### Play with the result slot\n\nThe component exposes a slot to override the result content, without modifying the list.\n\nIn this example, the ID of the results will be rendered along with the name.\n\n```vue\n<template>\n <QueryPreview :queryPreviewInfo=\"queryPreviewInfo\" #result=\"{ result }\">\n <span>{{ result.id }}</span>\n <span>{{ result.name }}</span>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n\n### Play with props\n\nIn this example, the query preview has been limited to render a maximum of 4 results.\n\n```vue\n<template>\n <QueryPreview\n :maxItemsToRender=\"maxItemsToRender\"\n :queryPreviewInfo=\"queryPreviewInfo\"\n #default=\"{ results }\"\n >\n <BaseGrid #default=\"{ item }\" :items=\"results\">\n <BaseResultLink :result=\"item\">\n <BaseResultImage :result=\"item\" />\n </BaseResultLink>\n </BaseGrid>\n </QueryPreview>\n</template>\n\n<script setup>\nimport { BaseGrid, BaseResultImage, BaseResultLink } from '@empathyco/x-components'\nimport { QueryPreview } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst maxItemsToRender = 4\nconst queryPreviewInfo = reactive({ query: 'flip-flops' })\n</script>\n```\n</docs>\n"],"names":["debounceFunction"],"mappings":";;;;;;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,EAAE,OAAO;AAC3C,gBAAA,YAAY,EAAE,mBAAmB,CAAC,KAAK,EAAE,YAAY;AACrD,gBAAA,cAAc,EAAE,mBAAmB,CAAC,KAAK,EAAE,cAAc;AACzD,gBAAA,YAAY,EAAE,mBAAmB,CAAC,KAAK,EAAE,YAAY;aACvD;YAEA,MAAM,WAAU,GAAI,UAAU,CAAC,KAAI,GAAI,KAAK,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA,GAAI,EAAC;YAExE,OAAO,CAAC,CACN,SAAS,EACT;AACE,gBAAA,GAAG,EAAE,mBAAmB;gBACxB,KAAK,EAAE,eAAe,CAAC;AACrB,sBAAE;AACF,sBAAE,uCAAuC;AAC5C,aAAA,EACD,CAAC,WAAW,CAAC,CACf;QACF;AAEA;AAC+E;AAC/E,QAAA,MAAM,iBAAiB;YACrB,UAAU;YACV,mBAAmB;YACnB,mBAAmB;YACnB,eAAe;SACjB;AACA,QAAA,QAAQ,KAAK,CAAC,OAAM,GAAI,iBAAgB,GAAI,cAAc;IAC5D,CAAC;AACF,CAAA,CAAA;;;;"}
|
|
@@ -22,7 +22,7 @@ const request = ({ catalogSection, config, page, params, selectedFilters: filter
|
|
|
22
22
|
const selectedCatalogSection = catalogSection ?? providedCatalogSection;
|
|
23
23
|
return {
|
|
24
24
|
query,
|
|
25
|
-
sort,
|
|
25
|
+
sort: config?.priceSortField ? sort?.replace('price', config.priceSortField) : sort,
|
|
26
26
|
page,
|
|
27
27
|
filters,
|
|
28
28
|
extraParams: selectedCatalogSection !== undefined || config.defaultCatalogSection
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.getter.js","sources":["../../../../../../src/x-modules/search/store/getters/request.getter.ts"],"sourcesContent":["import type { SearchXStoreModule } from '../types'\n\n/**\n * Default implementation for the {@link SearchGetters.request} getter.\n *\n * @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the search\n * module.\n * @param getters - Current {@link https://vuex.vuejs.org/guide/getters.html | getters} of the\n * search module.\n * @param rootState - Current root state of the store, used to read the `catalogSection` extra\n * param provided by the instance, which is not broadcasted through the `ExtraParamsChanged` event.\n * @returns The search request to fetch data from the API.\n * @public\n */\nexport const request: SearchXStoreModule['getters']['request'] = (\n { catalogSection, config, page, params, selectedFilters: filters, sort },\n { query },\n rootState,\n) => {\n if (!query) {\n return null\n }\n const catalogSectionParamKey =\n rootState.x?.extraParams?.catalogSectionParamKey ?? 'catalogSection'\n const extraParams = rootState.x?.extraParams?.params\n const providedCatalogSection =\n extraParams && catalogSectionParamKey in extraParams\n ? extraParams[catalogSectionParamKey]\n : params[catalogSectionParamKey]\n const selectedCatalogSection = catalogSection ?? providedCatalogSection\n\n return {\n query,\n sort,\n page,\n filters,\n extraParams:\n selectedCatalogSection !== undefined || config.defaultCatalogSection\n ? {\n ...params,\n [catalogSectionParamKey]: selectedCatalogSection || config.defaultCatalogSection,\n }\n : params,\n }\n}\n"],"names":[],"mappings":"AAEA;;;;;;;;;;;AAWG;AACI,MAAM,OAAO,GAA6C,CAC/D,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,EACxE,EAAE,KAAK,EAAE,EACT,SAAS,KACP;IACF,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,OAAO,IAAI;IACb;IACA,MAAM,sBAAsB,GAC1B,SAAS,CAAC,CAAC,EAAE,WAAW,EAAE,sBAAsB,IAAI,gBAAgB;IACtE,MAAM,WAAW,GAAG,SAAS,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM;AACpD,IAAA,MAAM,sBAAsB,GAC1B,WAAW,IAAI,sBAAsB,IAAI;AACvC,UAAE,WAAW,CAAC,sBAAsB;AACpC,UAAE,MAAM,CAAC,sBAAsB,CAAC;AACpC,IAAA,MAAM,sBAAsB,GAAG,cAAc,IAAI,sBAAsB;IAEvE,OAAO;QACL,KAAK;QACL,IAAI;
|
|
1
|
+
{"version":3,"file":"request.getter.js","sources":["../../../../../../src/x-modules/search/store/getters/request.getter.ts"],"sourcesContent":["import type { SearchXStoreModule } from '../types'\n\n/**\n * Default implementation for the {@link SearchGetters.request} getter.\n *\n * @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the search\n * module.\n * @param getters - Current {@link https://vuex.vuejs.org/guide/getters.html | getters} of the\n * search module.\n * @param rootState - Current root state of the store, used to read the `catalogSection` extra\n * param provided by the instance, which is not broadcasted through the `ExtraParamsChanged` event.\n * @returns The search request to fetch data from the API.\n * @public\n */\nexport const request: SearchXStoreModule['getters']['request'] = (\n { catalogSection, config, page, params, selectedFilters: filters, sort },\n { query },\n rootState,\n) => {\n if (!query) {\n return null\n }\n const catalogSectionParamKey =\n rootState.x?.extraParams?.catalogSectionParamKey ?? 'catalogSection'\n const extraParams = rootState.x?.extraParams?.params\n const providedCatalogSection =\n extraParams && catalogSectionParamKey in extraParams\n ? extraParams[catalogSectionParamKey]\n : params[catalogSectionParamKey]\n const selectedCatalogSection = catalogSection ?? providedCatalogSection\n\n return {\n query,\n sort: config?.priceSortField ? sort?.replace('price', config.priceSortField) : sort,\n page,\n filters,\n extraParams:\n selectedCatalogSection !== undefined || config.defaultCatalogSection\n ? {\n ...params,\n [catalogSectionParamKey]: selectedCatalogSection || config.defaultCatalogSection,\n }\n : params,\n }\n}\n"],"names":[],"mappings":"AAEA;;;;;;;;;;;AAWG;AACI,MAAM,OAAO,GAA6C,CAC/D,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,EACxE,EAAE,KAAK,EAAE,EACT,SAAS,KACP;IACF,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,OAAO,IAAI;IACb;IACA,MAAM,sBAAsB,GAC1B,SAAS,CAAC,CAAC,EAAE,WAAW,EAAE,sBAAsB,IAAI,gBAAgB;IACtE,MAAM,WAAW,GAAG,SAAS,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM;AACpD,IAAA,MAAM,sBAAsB,GAC1B,WAAW,IAAI,sBAAsB,IAAI;AACvC,UAAE,WAAW,CAAC,sBAAsB;AACpC,UAAE,MAAM,CAAC,sBAAsB,CAAC;AACpC,IAAA,MAAM,sBAAsB,GAAG,cAAc,IAAI,sBAAsB;IAEvE,OAAO;QACL,KAAK;QACL,IAAI,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,cAAc,CAAC,GAAG,IAAI;QACnF,IAAI;QACJ,OAAO;AACP,QAAA,WAAW,EACT,sBAAsB,KAAK,SAAS,IAAI,MAAM,CAAC;AAC7C,cAAE;AACE,gBAAA,GAAG,MAAM;AACT,gBAAA,CAAC,sBAAsB,GAAG,sBAAsB,IAAI,MAAM,CAAC,qBAAqB;AACjF;AACH,cAAE,MAAM;KACb;AACH;;;;"}
|