@empathyco/x-components 10.2.0 → 10.3.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 CHANGED
@@ -3,6 +3,13 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [10.3.0](https://github.com/empathyco/x/compare/@empathyco/x-components@10.2.0...@empathyco/x-components@10.3.0) (2026-10-30)
7
+
8
+ ### Features
9
+
10
+ * **x-components:** add rootMargin support to useOnDisplay (#2193)
11
+
12
+
6
13
  ## [10.2.0](https://github.com/empathyco/x/compare/@empathyco/x-components@10.1.1...@empathyco/x-components@10.2.0) (2026-10-27)
7
14
 
8
15
  ### Features
@@ -1257,7 +1257,7 @@ Composable to share filters injection logic.
1257
1257
  </td></tr>
1258
1258
  <tr><td>
1259
1259
 
1260
- [useOnDisplay({ element, callback, triggerOnce, }, input)](./x-components.useondisplay.md)
1260
+ [useOnDisplay({ element, callback, triggerOnce, threshold, rootMargin, scrollTargetId, }, input)](./x-components.useondisplay.md)
1261
1261
 
1262
1262
 
1263
1263
  </td><td>
@@ -24,6 +24,10 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
24
24
  type: BooleanConstructor;
25
25
  default: boolean;
26
26
  };
27
+ scrollTarget: {
28
+ type: StringConstructor;
29
+ default: string;
30
+ };
27
31
  debounceTimeMs: {
28
32
  type: NumberConstructor;
29
33
  default: number;
@@ -60,6 +64,10 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
60
64
  type: BooleanConstructor;
61
65
  default: boolean;
62
66
  };
67
+ scrollTarget: {
68
+ type: StringConstructor;
69
+ default: string;
70
+ };
63
71
  debounceTimeMs: {
64
72
  type: NumberConstructor;
65
73
  default: number;
@@ -73,6 +81,7 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
73
81
  onError?: ((...args: any[]) => any) | undefined;
74
82
  }>, {
75
83
  loadWhenVisible: boolean;
84
+ scrollTarget: string;
76
85
  debounceTimeMs: number;
77
86
  persistInCache: boolean;
78
87
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>
@@ -32,7 +32,7 @@ Description
32
32
  </th></tr></thead>
33
33
  <tbody><tr><td>
34
34
 
35
- { element, callback, triggerOnce, }
35
+ { element, callback, triggerOnce, threshold, rootMargin, scrollTargetId, }
36
36
 
37
37
 
38
38
  </td><td>
@@ -12,14 +12,15 @@ By default, it renders the names of the results.
12
12
 
13
13
  ## Props
14
14
 
15
- | Name | Description | Type | Default |
16
- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------- | ------------------ |
17
- | <code>queryPreviewInfo</code> | The information about the request of the query preview. | <code>QueryPreviewInfo</code> | <code></code> |
18
- | <code>queryFeature</code> | The origin property for the request. | <code>QueryFeature</code> | <code></code> |
19
- | <code>maxItemsToRender</code> | Number of query preview results to be rendered. | <code>number</code> | <code></code> |
20
- | <code>loadWhenVisible</code> | Controls whether the query preview requests should be triggered when the component is visible in the viewport. | <code>boolean</code> | <code>false</code> |
21
- | <code>debounceTimeMs</code> | Debounce time in milliseconds for triggering the search requests.<br />It will default to 0 to fit the most common use case (pre-search),<br />and it would work properly with a 250 value inside empathize. | <code>number</code> | <code>0</code> |
22
- | <code>persistInCache</code> | Controls whether the QueryPreview should be removed from the state<br />when the component is destroyed. | <code>boolean</code> | <code>false</code> |
15
+ | Name | Description | Type | Default |
16
+ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------- | -------------------------- |
17
+ | <code>queryPreviewInfo</code> | The information about the request of the query preview. | <code>QueryPreviewInfo</code> | <code></code> |
18
+ | <code>queryFeature</code> | The origin property for the request. | <code>QueryFeature</code> | <code></code> |
19
+ | <code>maxItemsToRender</code> | Number of query preview results to be rendered. | <code>number</code> | <code></code> |
20
+ | <code>loadWhenVisible</code> | Controls whether the query preview requests should be triggered when the component is visible in the viewport. | <code>boolean</code> | <code>false</code> |
21
+ | <code>scrollTarget</code> | The id of the scroll container to compute the visibility against. | <code>string</code> | <code>'main-scroll'</code> |
22
+ | <code>debounceTimeMs</code> | Debounce time in milliseconds for triggering the search requests.<br />It will default to 0 to fit the most common use case (pre-search),<br />and it would work properly with a 250 value inside empathize. | <code>number</code> | <code>0</code> |
23
+ | <code>persistInCache</code> | Controls whether the QueryPreview should be removed from the state<br />when the component is destroyed. | <code>boolean</code> | <code>false</code> |
23
24
 
24
25
  ## Events
25
26
 
@@ -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, { threshold: 0.1 });
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, { threshold: 0.1 })\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 * 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}\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;AACG,SAAU,YAAY,CAAC,EAC3B,OAAO,EACP,QAAQ,EACR,WAAW,GAAG,IAAI,GACE,EAAA;AACpB,IAAA,MAAM,gBAAgB,GAAG,oBAAoB,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;IAE1E,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;;;;;;;;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;;;;"}
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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CAAC;AACF,KAAA,CAAC;IAEF,OAAO;QACL,gBAAgB;QAChB,cAAc;KACf;AACH;;;;"}
@@ -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
- * (only when loadWhenVisible is true).
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 { unwatchDisplay } = useOnDisplay({
287
- element: queryPreviewElement,
288
- callback: () => {
289
- if (props.loadWhenVisible && cachedQueryPreview?.status !== 'success') {
290
- emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value);
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,C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E,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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA;;;;;;AAME;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,qBAAqB,CAAC,IAAI;AACnC,IAAA,KAAK,EAAE;;AAEL,QA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,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;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empathyco/x-components",
3
- "version": "10.2.0",
3
+ "version": "10.3.0",
4
4
  "description": "Empathy X Components",
5
5
  "author": "Empathy Systems Corporation S.L.",
6
6
  "license": "Apache-2.0",
@@ -117,5 +117,5 @@
117
117
  "access": "public",
118
118
  "directory": "dist"
119
119
  },
120
- "gitHead": "74de7591d6177596a288687d41591e911a723d8e"
120
+ "gitHead": "8cb068430bea35d465a4b59054a0afd8e2fb1b6a"
121
121
  }
@@ -54434,7 +54434,16 @@
54434
54434
  },
54435
54435
  {
54436
54436
  "kind": "Content",
54437
- "text": ";\n default: boolean;\n };\n debounceTimeMs: {\n type: "
54437
+ "text": ";\n default: boolean;\n };\n scrollTarget: {\n type: "
54438
+ },
54439
+ {
54440
+ "kind": "Reference",
54441
+ "text": "StringConstructor",
54442
+ "canonicalReference": "!StringConstructor:interface"
54443
+ },
54444
+ {
54445
+ "kind": "Content",
54446
+ "text": ";\n default: string;\n };\n debounceTimeMs: {\n type: "
54438
54447
  },
54439
54448
  {
54440
54449
  "kind": "Reference",
@@ -54650,7 +54659,16 @@
54650
54659
  },
54651
54660
  {
54652
54661
  "kind": "Content",
54653
- "text": ";\n default: boolean;\n };\n debounceTimeMs: {\n type: "
54662
+ "text": ";\n default: boolean;\n };\n scrollTarget: {\n type: "
54663
+ },
54664
+ {
54665
+ "kind": "Reference",
54666
+ "text": "StringConstructor",
54667
+ "canonicalReference": "!StringConstructor:interface"
54668
+ },
54669
+ {
54670
+ "kind": "Content",
54671
+ "text": ";\n default: string;\n };\n debounceTimeMs: {\n type: "
54654
54672
  },
54655
54673
  {
54656
54674
  "kind": "Reference",
@@ -54677,7 +54695,7 @@
54677
54695
  },
54678
54696
  {
54679
54697
  "kind": "Content",
54680
- "text": "<{\n onLoad?: ((...args: any[]) => any) | undefined;\n onError?: ((...args: any[]) => any) | undefined;\n}>, {\n loadWhenVisible: boolean;\n debounceTimeMs: number;\n persistInCache: boolean;\n}, {}, {}, {}, string, import(\"vue\")."
54698
+ "text": "<{\n onLoad?: ((...args: any[]) => any) | undefined;\n onError?: ((...args: any[]) => any) | undefined;\n}>, {\n loadWhenVisible: boolean;\n scrollTarget: string;\n debounceTimeMs: number;\n persistInCache: boolean;\n}, {}, {}, {}, string, import(\"vue\")."
54681
54699
  },
54682
54700
  {
54683
54701
  "kind": "Reference",
@@ -54695,7 +54713,7 @@
54695
54713
  "name": "QueryPreview",
54696
54714
  "variableTypeTokenRange": {
54697
54715
  "startIndex": 1,
54698
- "endIndex": 74
54716
+ "endIndex": 78
54699
54717
  }
54700
54718
  },
54701
54719
  {
@@ -91656,7 +91674,7 @@
91656
91674
  "overloadIndex": 1,
91657
91675
  "parameters": [
91658
91676
  {
91659
- "parameterName": "{ element, callback, triggerOnce, }",
91677
+ "parameterName": "{ element, callback, triggerOnce, threshold, rootMargin, scrollTargetId, }",
91660
91678
  "parameterTypeTokenRange": {
91661
91679
  "startIndex": 0,
91662
91680
  "endIndex": 0
@@ -5867,6 +5867,10 @@ loadWhenVisible: {
5867
5867
  type: BooleanConstructor;
5868
5868
  default: boolean;
5869
5869
  };
5870
+ scrollTarget: {
5871
+ type: StringConstructor;
5872
+ default: string;
5873
+ };
5870
5874
  debounceTimeMs: {
5871
5875
  type: NumberConstructor;
5872
5876
  default: number;
@@ -5903,6 +5907,10 @@ loadWhenVisible: {
5903
5907
  type: BooleanConstructor;
5904
5908
  default: boolean;
5905
5909
  };
5910
+ scrollTarget: {
5911
+ type: StringConstructor;
5912
+ default: string;
5913
+ };
5906
5914
  debounceTimeMs: {
5907
5915
  type: NumberConstructor;
5908
5916
  default: number;
@@ -5916,6 +5924,7 @@ onLoad?: ((...args: any[]) => any) | undefined;
5916
5924
  onError?: ((...args: any[]) => any) | undefined;
5917
5925
  }>, {
5918
5926
  loadWhenVisible: boolean;
5927
+ scrollTarget: string;
5919
5928
  debounceTimeMs: number;
5920
5929
  persistInCache: boolean;
5921
5930
  }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
@@ -11,7 +11,7 @@ import type { WireMetadata } from '../wiring';
11
11
  * @returns If the element is currently visible in the viewport or not and the watcher stop handle.
12
12
  * @public
13
13
  */
14
- export declare function useOnDisplay({ element, callback, triggerOnce, }: UseOnDisplayOptions): UseOnDisplayReturn;
14
+ export declare function useOnDisplay({ element, callback, triggerOnce, threshold, rootMargin, scrollTargetId, }: UseOnDisplayOptions): UseOnDisplayReturn;
15
15
  /**
16
16
  * Composable that emits a `TrackableElementDisplayed` event whenever the provided element
17
17
  * appears in the viewport for the first time.
@@ -29,6 +29,9 @@ interface UseOnDisplayOptions {
29
29
  element: HTMLElement | Ref<HTMLElement | null>;
30
30
  callback: () => void;
31
31
  triggerOnce?: boolean;
32
+ threshold?: number;
33
+ rootMargin?: string;
34
+ scrollTargetId?: string;
32
35
  }
33
36
  /**
34
37
  * Return type of the {@link useOnDisplay} composable.
@@ -1 +1 @@
1
- {"version":3,"file":"use-on-display.d.ts","sourceRoot":"","sources":["../../../../src/composables/use-on-display.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,KAAK,CAAA;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAK7C;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,QAAQ,EACR,WAAkB,GACnB,EAAE,mBAAmB,GAAG,kBAAkB,CAgB1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,OAAO,EACP,cAAc,EACd,aAAkB,GACnB,EAAE,0BAA0B,GAAG,kBAAkB,CAkBjD;AAED;;GAEG;AACH,UAAU,mBAAmB;IAC3B,OAAO,EAAE,WAAW,GAAG,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC9C,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED;;GAEG;AACH,UAAU,kBAAkB;IAC1B,gBAAgB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IAC9B,cAAc,EAAE,eAAe,CAAA;CAChC;AAED;;GAEG;AACH,UAAU,0BAA0B;IAClC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAA;IACvC,cAAc,EAAE,cAAc,CAAA;IAC9B,aAAa,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,GAAG,QAAQ,GAAG,UAAU,CAAC,CAAA;CACzE"}
1
+ {"version":3,"file":"use-on-display.d.ts","sourceRoot":"","sources":["../../../../src/composables/use-on-display.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,KAAK,CAAA;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAK7C;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,QAAQ,EACR,WAAkB,EAClB,SAAe,EACf,UAAU,EACV,cAAc,GACf,EAAE,mBAAmB,GAAG,kBAAkB,CAsB1C;AAyBD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,OAAO,EACP,cAAc,EACd,aAAkB,GACnB,EAAE,0BAA0B,GAAG,kBAAkB,CAkBjD;AAED;;GAEG;AACH,UAAU,mBAAmB;IAC3B,OAAO,EAAE,WAAW,GAAG,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC9C,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,UAAU,kBAAkB;IAC1B,gBAAgB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IAC9B,cAAc,EAAE,eAAe,CAAA;CAChC;AAED;;GAEG;AACH,UAAU,0BAA0B;IAClC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAA;IACvC,cAAc,EAAE,cAAc,CAAA;IAC9B,aAAa,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,GAAG,QAAQ,GAAG,UAAU,CAAC,CAAA;CACzE"}
@@ -30,6 +30,13 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
30
30
  type: BooleanConstructor;
31
31
  default: boolean;
32
32
  };
33
+ /**
34
+ * The id of the scroll container to compute the visibility against.
35
+ */
36
+ scrollTarget: {
37
+ type: StringConstructor;
38
+ default: string;
39
+ };
33
40
  /**
34
41
  * Debounce time in milliseconds for triggering the search requests.
35
42
  * It will default to 0 to fit the most common use case (pre-search),
@@ -81,6 +88,13 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
81
88
  type: BooleanConstructor;
82
89
  default: boolean;
83
90
  };
91
+ /**
92
+ * The id of the scroll container to compute the visibility against.
93
+ */
94
+ scrollTarget: {
95
+ type: StringConstructor;
96
+ default: string;
97
+ };
84
98
  /**
85
99
  * Debounce time in milliseconds for triggering the search requests.
86
100
  * It will default to 0 to fit the most common use case (pre-search),
@@ -103,6 +117,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
103
117
  onError?: ((...args: any[]) => any) | undefined;
104
118
  }>, {
105
119
  loadWhenVisible: boolean;
120
+ scrollTarget: string;
106
121
  debounceTimeMs: number;
107
122
  persistInCache: boolean;
108
123
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -1 +1 @@
1
- {"version":3,"file":"query-preview.vue?vue&type=script&lang.d.ts","sourceRoot":"","sources":["../../../../../../src/x-modules/queries-preview/components/query-preview.vue?vue&type=script&lang.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAU,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AACxC,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAStD;;;;;;GAMG;;IAKC,8DAA8D;;cAE5C,QAAQ,CAAC,gBAAgB,CAAC;;;IAG5C,2CAA2C;;cAEzB,QAAQ,CAAC,YAAY,CAAC;;IAExC,sDAAsD;;;;IAItD;;OAEG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;OAGG;;;;;;;;;;;;;;;;;;;IAhCH,8DAA8D;;cAE5C,QAAQ,CAAC,gBAAgB,CAAC;;;IAG5C,2CAA2C;;cAEzB,QAAQ,CAAC,YAAY,CAAC;;IAExC,sDAAsD;;;;IAItD;;OAEG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;OAGG;;;;;;;;;;;;;AApCP,wBAuTE"}
1
+ {"version":3,"file":"query-preview.vue?vue&type=script&lang.d.ts","sourceRoot":"","sources":["../../../../../../src/x-modules/queries-preview/components/query-preview.vue?vue&type=script&lang.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAU,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AACxC,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAStD;;;;;;GAMG;;IAKC,8DAA8D;;cAE5C,QAAQ,CAAC,gBAAgB,CAAC;;;IAG5C,2CAA2C;;cAEzB,QAAQ,CAAC,YAAY,CAAC;;IAExC,sDAAsD;;;;IAItD;;OAEG;;;;;IAKH;;OAEG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;OAGG;;;;;;;;;;;;;;;;;;;IAvCH,8DAA8D;;cAE5C,QAAQ,CAAC,gBAAgB,CAAC;;;IAG5C,2CAA2C;;cAEzB,QAAQ,CAAC,YAAY,CAAC;;IAExC,sDAAsD;;;;IAItD;;OAEG;;;;;IAKH;;OAEG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;OAGG;;;;;;;;;;;;;;AA3CP,wBAyUE"}