@empathyco/x-components 6.0.0-alpha.200 → 6.0.0-alpha.201

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/docs/API-reference/api/x-components.querypreview.md +10 -0
  3. package/docs/API-reference/api/x-components.querypreviewlist.md +9 -0
  4. package/docs/API-reference/components/queries-preview/x-components.query-preview-list.md +9 -8
  5. package/docs/API-reference/components/queries-preview/x-components.query-preview.md +1 -0
  6. package/js/x-modules/queries-preview/components/query-preview-list.vue.js +37 -28
  7. package/js/x-modules/queries-preview/components/query-preview-list.vue.js.map +1 -1
  8. package/js/x-modules/queries-preview/components/query-preview-list.vue2.js +10 -0
  9. package/js/x-modules/queries-preview/components/query-preview-list.vue2.js.map +1 -1
  10. package/js/x-modules/queries-preview/components/query-preview-list.vue3.js +7 -0
  11. package/js/x-modules/queries-preview/components/query-preview-list.vue3.js.map +1 -0
  12. package/js/x-modules/queries-preview/components/query-preview.vue.js +38 -26
  13. package/js/x-modules/queries-preview/components/query-preview.vue.js.map +1 -1
  14. package/js/x-modules/queries-preview/components/query-preview.vue2.js +33 -8
  15. package/js/x-modules/queries-preview/components/query-preview.vue2.js.map +1 -1
  16. package/package.json +2 -2
  17. package/report/x-components.api.json +72 -9
  18. package/report/x-components.api.md +19 -0
  19. package/types/x-modules/queries-preview/components/query-preview-list.vue.d.ts +21 -0
  20. package/types/x-modules/queries-preview/components/query-preview-list.vue.d.ts.map +1 -1
  21. package/types/x-modules/queries-preview/components/query-preview.vue.d.ts +17 -1
  22. package/types/x-modules/queries-preview/components/query-preview.vue.d.ts.map +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
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
+ ## 6.0.0-alpha.201 (2026-02-12)
7
+
8
+ * feat(query-preview): add lazy loading support to QueryPreview (#1980) ([ce95a17](https://github.com/empathyco/x/commit/ce95a17)), closes [#1980](https://github.com/empathyco/x/issues/1980)
9
+
10
+
11
+
12
+
13
+
6
14
  ## 6.0.0-alpha.200 (2026-02-11)
7
15
 
8
16
  **Note:** Version bump only for package @empathyco/x-components
@@ -20,6 +20,10 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
20
20
  maxItemsToRender: {
21
21
  type: NumberConstructor;
22
22
  };
23
+ loadWhenVisible: {
24
+ type: BooleanConstructor;
25
+ default: boolean;
26
+ };
23
27
  debounceTimeMs: {
24
28
  type: NumberConstructor;
25
29
  default: number;
@@ -39,6 +43,7 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
39
43
  instances: number;
40
44
  status: import("../../..").RequestStatus;
41
45
  } | undefined>;
46
+ queryPreviewElement: Ref<HTMLElement | null, HTMLElement | null>;
42
47
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("load" | "error")[], "load" | "error", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
43
48
  queryPreviewInfo: {
44
49
  type: PropType<QueryPreviewInfo>;
@@ -50,6 +55,10 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
50
55
  maxItemsToRender: {
51
56
  type: NumberConstructor;
52
57
  };
58
+ loadWhenVisible: {
59
+ type: BooleanConstructor;
60
+ default: boolean;
61
+ };
53
62
  debounceTimeMs: {
54
63
  type: NumberConstructor;
55
64
  default: number;
@@ -62,6 +71,7 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
62
71
  onLoad?: ((...args: any[]) => any) | undefined;
63
72
  onError?: ((...args: any[]) => any) | undefined;
64
73
  }>, {
74
+ loadWhenVisible: boolean;
65
75
  debounceTimeMs: number;
66
76
  persistInCache: boolean;
67
77
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>
@@ -20,6 +20,10 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
20
20
  maxItemsToRender: {
21
21
  type: NumberConstructor;
22
22
  };
23
+ loadWhenVisible: {
24
+ type: BooleanConstructor;
25
+ default: boolean;
26
+ };
23
27
  debounceTimeMs: {
24
28
  type: NumberConstructor;
25
29
  default: number;
@@ -44,6 +48,10 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
44
48
  maxItemsToRender: {
45
49
  type: NumberConstructor;
46
50
  };
51
+ loadWhenVisible: {
52
+ type: BooleanConstructor;
53
+ default: boolean;
54
+ };
47
55
  debounceTimeMs: {
48
56
  type: NumberConstructor;
49
57
  default: number;
@@ -55,6 +63,7 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
55
63
  };
56
64
  }>> & Readonly<{}>, {
57
65
  persistInCache: boolean;
66
+ loadWhenVisible: boolean;
58
67
  debounceTimeMs: number;
59
68
  animation: string | Function | Record<string, any>;
60
69
  }, {}, {
@@ -12,14 +12,15 @@ The requests are made in sequential order.
12
12
 
13
13
  ## Props
14
14
 
15
- | Name | Description | Type | Default |
16
- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | ----------------- |
17
- | <code>queriesPreviewInfo</code> | The list of queries preview to render. | <code>QueryPreviewInfo[]</code> | <code></code> |
18
- | <code>queryFeature</code> | The origin property for the request on each query preview. | <code>QueryFeature</code> | <code></code> |
19
- | <code>maxItemsToRender</code> | Number of query preview results to be rendered on each query preview. | <code>number</code> | <code></code> |
20
- | <code>debounceTimeMs</code> | Debounce time in milliseconds for triggering the search requests<br />on each query preview.<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> |
21
- | <code>persistInCache</code> | Controls whether all the QueryPreview should be removed from the state<br />when the component is destroyed. | <code>boolean</code> | <code></code> |
22
- | <code>animation</code> | Animation component that will be used to animate the elements. | <code>AnimationProp</code> | <code>'ul'</code> |
15
+ | Name | Description | Type | Default |
16
+ | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | ------------------ |
17
+ | <code>queriesPreviewInfo</code> | The list of queries preview to render. | <code>QueryPreviewInfo[]</code> | <code></code> |
18
+ | <code>queryFeature</code> | The origin property for the request on each query preview. | <code>QueryFeature</code> | <code></code> |
19
+ | <code>maxItemsToRender</code> | Number of query preview results to be rendered on each query preview. | <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 />on each query preview.<br /><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 all the QueryPreview should be removed from the state<br />when the component is destroyed. | <code>boolean</code> | <code></code> |
23
+ | <code>animation</code> | Animation component that will be used to animate the elements. | <code>AnimationProp</code> | <code>'ul'</code> |
23
24
 
24
25
  ## Slots
25
26
 
@@ -17,6 +17,7 @@ By default, it renders the names of the results.
17
17
  | <code>queryPreviewInfo</code> | The information about the request of the query preview. | <code>QueryPreviewInfo</code> | <code></code> |
18
18
  | <code>queryFeature</code> | The origin property for the request. | <code>QueryFeature</code> | <code></code> |
19
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> |
20
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> |
21
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> |
22
23
 
@@ -1,5 +1,6 @@
1
1
  import _sfc_main from './query-preview-list.vue2.js';
2
- import { resolveComponent, openBlock, createBlock, resolveDynamicComponent, withCtx, createElementBlock, Fragment, renderList, createVNode, createSlots, renderSlot, mergeProps } from 'vue';
2
+ import { resolveComponent, openBlock, createBlock, resolveDynamicComponent, withCtx, createElementBlock, Fragment, renderList, normalizeClass, createVNode, createSlots, renderSlot, mergeProps } from 'vue';
3
+ import './query-preview-list.vue3.js';
3
4
  import _export_sfc from '../../../_virtual/_plugin-vue_export-helper.js';
4
5
 
5
6
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
@@ -13,32 +14,40 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
13
14
  Fragment,
14
15
  null,
15
16
  renderList(_ctx.renderedQueryPreviews, (queryPreview, index) => {
16
- return openBlock(), createElementBlock("li", {
17
- key: index,
18
- "data-test": "query-preview-item"
19
- }, [
20
- createVNode(_component_QueryPreview, {
21
- "debounce-time-ms": _ctx.debounceTimeMs,
22
- "max-items-to-render": _ctx.maxItemsToRender,
23
- "persist-in-cache": _ctx.persistInCache,
24
- "query-feature": _ctx.queryFeature,
25
- "query-preview-info": queryPreview,
26
- onLoad: _ctx.flagAsLoaded,
27
- onError: _ctx.flagAsFailed
28
- }, createSlots({
29
- _: 2
30
- /* DYNAMIC */
31
- }, [
32
- renderList(_ctx.$slots, (_, slotName) => {
33
- return {
34
- name: slotName,
35
- fn: withCtx((scope) => [
36
- renderSlot(_ctx.$slots, slotName, mergeProps({ ref_for: true }, scope))
37
- ])
38
- };
39
- })
40
- ]), 1032, ["debounce-time-ms", "max-items-to-render", "persist-in-cache", "query-feature", "query-preview-info", "onLoad", "onError"])
41
- ]);
17
+ return openBlock(), createElementBlock(
18
+ "li",
19
+ {
20
+ key: index,
21
+ class: normalizeClass({ "padding-block-1": _ctx.loadWhenVisible }),
22
+ "data-test": "query-preview-item"
23
+ },
24
+ [
25
+ createVNode(_component_QueryPreview, {
26
+ "debounce-time-ms": _ctx.debounceTimeMs,
27
+ "load-when-visible": _ctx.loadWhenVisible,
28
+ "max-items-to-render": _ctx.maxItemsToRender,
29
+ "persist-in-cache": _ctx.persistInCache,
30
+ "query-feature": _ctx.queryFeature,
31
+ "query-preview-info": queryPreview,
32
+ onLoad: _ctx.flagAsLoaded,
33
+ onError: _ctx.flagAsFailed
34
+ }, createSlots({
35
+ _: 2
36
+ /* DYNAMIC */
37
+ }, [
38
+ renderList(_ctx.$slots, (_, slotName) => {
39
+ return {
40
+ name: slotName,
41
+ fn: withCtx((scope) => [
42
+ renderSlot(_ctx.$slots, slotName, mergeProps({ ref_for: true }, scope), void 0, true)
43
+ ])
44
+ };
45
+ })
46
+ ]), 1032, ["debounce-time-ms", "load-when-visible", "max-items-to-render", "persist-in-cache", "query-feature", "query-preview-info", "onLoad", "onError"])
47
+ ],
48
+ 2
49
+ /* CLASS */
50
+ );
42
51
  }),
43
52
  128
44
53
  /* KEYED_FRAGMENT */
@@ -48,7 +57,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
48
57
  /* FORWARDED */
49
58
  });
50
59
  }
51
- var queryPreviewList = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
60
+ var queryPreviewList = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-a0750562"]]);
52
61
 
53
62
  export { queryPreviewList as default };
54
63
  //# sourceMappingURL=query-preview-list.vue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-preview-list.vue.js","sources":["../../../../../src/x-modules/queries-preview/components/query-preview-list.vue"],"sourcesContent":["<template>\n <component :is=\"animation\" class=\"x-query-preview-list\" tag=\"ul\">\n <li\n v-for=\"(queryPreview, index) in renderedQueryPreviews\"\n :key=\"index\"\n data-test=\"query-preview-item\"\n >\n <QueryPreview\n :debounce-time-ms=\"debounceTimeMs\"\n :max-items-to-render=\"maxItemsToRender\"\n :persist-in-cache=\"persistInCache\"\n :query-feature=\"queryFeature\"\n :query-preview-info=\"queryPreview\"\n @load=\"flagAsLoaded\"\n @error=\"flagAsFailed\"\n >\n <template v-for=\"(_, slotName) in $slots\" #[slotName]=\"scope\">\n <slot :name=\"slotName\" v-bind=\"scope\" />\n </template>\n </QueryPreview>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\nimport type { PropType } from 'vue'\nimport type { RequestStatus } from '../../../store'\nimport type { QueryFeature } from '../../../types'\nimport type { QueryPreviewInfo } from '../store/types'\nimport { computed, defineComponent, ref, watch } from 'vue'\nimport { useState } from '../../../composables/index'\nimport { AnimationProp } from '../../../types'\nimport { getHashFromQueryPreviewInfo } from '../utils/get-hash-from-query-preview'\nimport { queriesPreviewXModule } from '../x-module'\nimport QueryPreview from './query-preview.vue'\n\ninterface QueryPreviewStatusRecord {\n [query: string]: RequestStatus\n}\n\n/**\n * Renders the results previews of a list of objects with the information about the query preview,\n * and exposes the {@link QueryPreview} slots to modify the content.\n * The requests are made in sequential order.\n *\n * @public\n */\nexport default defineComponent({\n name: 'QueryPreviewList',\n xModule: queriesPreviewXModule.name,\n components: { QueryPreview },\n props: {\n /**\n * The list of queries preview to render.\n *\n * @public\n */\n queriesPreviewInfo: {\n type: Array as PropType<QueryPreviewInfo[]>,\n required: true,\n },\n /**\n * The origin property for the request on each query preview.\n *\n * @public\n */\n queryFeature: {\n type: String as PropType<QueryFeature>,\n },\n /**\n * Number of query preview results to be rendered on each query preview.\n *\n * @public\n */\n maxItemsToRender: {\n type: Number,\n },\n /**\n * Debounce time in milliseconds for triggering the search requests\n * on each query preview.\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 all the QueryPreview should be removed from the state\n * when the component is destroyed.\n *\n * @public\n */\n persistInCache: Boolean,\n /**\n * Animation component that will be used to animate the elements.\n *\n * @public\n */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n },\n setup(props) {\n const { params } = useState('queriesPreview')\n\n /**\n * Contains the status of the preview requests, indexed by query.\n */\n const queriesStatus = ref<QueryPreviewStatusRecord>({})\n\n /**\n * The list of queries to preview.\n *\n * @returns The list of queries in the queriesPreviewInfo list.\n * @internal\n */\n const queries = computed((): string[] =>\n props.queriesPreviewInfo.map(item =>\n getHashFromQueryPreviewInfo(item, { ...params.value, ...item.extraParams }),\n ),\n )\n\n /**\n * Gets all the queries to render, that are those that don't have an `error` status.\n *\n * @returns A list of queries.\n * @internal\n */\n const renderedQueryPreviews = computed((): QueryPreviewInfo[] => {\n return props.queriesPreviewInfo.filter(item => {\n const queryPreviewHash = getHashFromQueryPreviewInfo(item, {\n ...params.value,\n ...item.extraParams,\n })\n return (\n queriesStatus.value[queryPreviewHash] === 'success' ||\n queriesStatus.value[queryPreviewHash] === 'loading'\n )\n })\n })\n\n /**\n * Tries to load the next query.\n *\n * @internal\n */\n const loadNext = (): void => {\n const queryToLoad = queries.value.find(query => !(query in queriesStatus.value))\n if (queryToLoad) {\n queriesStatus.value[queryToLoad] = 'loading'\n }\n }\n\n /**\n * Resets the status of all queries if they change.\n *\n * @param newQueries - The new queries.\n * @param oldQueries - The old queries.\n * @internal\n */\n watch(\n queries,\n (newQueries: string[], oldQueries: string[] | undefined) => {\n if (newQueries.toString() !== oldQueries?.toString()) {\n for (const key of Object.keys(queriesStatus.value)) {\n if (!newQueries.includes(key)) {\n delete queriesStatus.value[key]\n }\n }\n loadNext()\n }\n },\n { immediate: true, deep: true },\n )\n\n /**\n * Sets the status of a given query to `success`.\n *\n * @param loadedQuery - The query to flag as loaded.\n * @internal\n */\n const flagAsLoaded = (loadedQuery: string): void => {\n queriesStatus.value[loadedQuery] = 'success'\n loadNext()\n }\n\n /**\n * Sets the status of a given query to `error`.\n *\n * @param failedQuery - The query to flag as failed.\n * @internal\n */\n const flagAsFailed = (failedQuery: string): void => {\n queriesStatus.value[failedQuery] = 'error'\n loadNext()\n }\n\n return {\n renderedQueryPreviews,\n flagAsFailed,\n flagAsLoaded,\n }\n },\n})\n</script>\n\n<docs lang=\"mdx\">\n## See it in action\n\nHere you have a basic example of how the QueryPreviewList is rendered. Keep in mind that this\ncomponent is intended to be used overriding its default slot. By default it will only render the\nnames of the results.\n\n```vue live\n<template>\n <QueryPreviewList :queriesPreviewInfo=\"queriesPreviewInfo\" />\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\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 <QueryPreviewList\n :queriesPreviewInfo=\"queriesPreviewInfo\"\n #default=\"{ queryPreviewInfo, totalResults, results }\"\n >\n <div class=\"x-flex x-flex-col x-gap-8 x-mb-16\">\n <h1 class=\"x-title2\">{{ queryPreviewInfo.query }} ({{ totalResults }})</h1>\n <SlidingPanel :resetOnContentChange=\"false\">\n <div class=\"x-flex x-gap-8\">\n <Result\n v-for=\"result in results\"\n :key=\"result.id\"\n :result=\"result\"\n style=\"max-width: 180px\"\n />\n </div>\n </SlidingPanel>\n </div>\n </QueryPreviewList>\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport SlidingPanel from '@empathyco/x-components/sliding-panel.vue'\nimport Result from '@empathyco/x-components/result.vue'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\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 <QueryPreviewList\n class=\"x-flex x-gap-8\"\n :queriesPreviewInfo=\"queriesPreviewInfo\"\n #result=\"{ result }\"\n >\n <span class=\"x-font-bold\">{{ result.id }}:</span>\n <span>{{ result.name }}</span>\n </QueryPreviewList>\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createBlock","_resolveDynamicComponent","_createElementBlock","_Fragment","_renderList","_createVNode","_createSlots","_withCtx","_renderSlot","_mergeProps"],"mappings":";;;;;;AACE,EAAA,OAAAA,SAAA,EAAA,EAAAC,WAAA,CAoBYC,wBApBI,IAAA,CAAA,SAAS,CAAA,EAAA;AAAA,IAAE,KAAA,EAAM,sBAAA;AAAA,IAAuB,GAAA,EAAI;AAAA,GAAA,EAAA;qBAExD,MAAsD;AAAA,OAAAF,SAAA,CAAA,IAAA,CAAA,EADxDG,kBAAA;AAAA,QAkBKC,QAAA;AAAA,QAAA,IAAA;AAAA,QAAAC,UAAA,CAjB6B,IAAA,CAAA,qBAAA,EAAqB,CAA7C,YAAA,EAAc,KAAA,KAAK;8BAD7BF,kBAAA,CAkBK,IAAA,EAAA;AAAA,YAhBF,GAAA,EAAK,KAAA;AAAA,YACN,WAAA,EAAU;AAAA,WAAA,EAAA;YAEVG,WAAA,CAYe,uBAAA,EAAA;AAAA,cAXZ,kBAAA,EAAkB,IAAA,CAAA,cAAA;AAAA,cAClB,qBAAA,EAAqB,IAAA,CAAA,gBAAA;AAAA,cACrB,kBAAA,EAAkB,IAAA,CAAA,cAAA;AAAA,cAClB,eAAA,EAAe,IAAA,CAAA,YAAA;AAAA,cACf,oBAAA,EAAoB,YAAA;AAAA,cACpB,MAAA,EAAM,IAAA,CAAA,YAAA;AAAA,cACN,OAAA,EAAO,IAAA,CAAA;AAAA,aAAA,EAAAC,WAAA,CAAA;;;;yBAE0B,IAAA,CAAA,MAAA,EAAM,CAAtB,GAAG,QAAA,KAAQ;;AAAc,kBAAA,IAAA,EAAA,QAAA;AAAA,kBAAA,EAAA,EAAAC,OAAA,CACzC,CAAwC,KAAA,KADkB;AAAA,oBAC1DC,UAAA,CAAwC,IAAA,CAAA,MAAA,EAA3B,QAAA,EAAbC,UAAA,CAAwC,mBAAT,KAAK,CAAA;AAAA,mBAAA;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"query-preview-list.vue.js","sources":["../../../../../src/x-modules/queries-preview/components/query-preview-list.vue"],"sourcesContent":["<template>\n <component :is=\"animation\" class=\"x-query-preview-list\" tag=\"ul\">\n <li\n v-for=\"(queryPreview, index) in renderedQueryPreviews\"\n :key=\"index\"\n :class=\"{ 'padding-block-1': loadWhenVisible }\"\n data-test=\"query-preview-item\"\n >\n <QueryPreview\n :debounce-time-ms=\"debounceTimeMs\"\n :load-when-visible=\"loadWhenVisible\"\n :max-items-to-render=\"maxItemsToRender\"\n :persist-in-cache=\"persistInCache\"\n :query-feature=\"queryFeature\"\n :query-preview-info=\"queryPreview\"\n @load=\"flagAsLoaded\"\n @error=\"flagAsFailed\"\n >\n <template v-for=\"(_, slotName) in $slots\" #[slotName]=\"scope\">\n <slot :name=\"slotName\" v-bind=\"scope\" />\n </template>\n </QueryPreview>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\nimport type { PropType } from 'vue'\nimport type { RequestStatus } from '../../../store'\nimport type { QueryFeature } from '../../../types'\nimport type { QueryPreviewInfo } from '../store/types'\nimport { computed, defineComponent, ref, watch } from 'vue'\nimport { useState } from '../../../composables/index'\nimport { AnimationProp } from '../../../types'\nimport { getHashFromQueryPreviewInfo } from '../utils/get-hash-from-query-preview'\nimport { queriesPreviewXModule } from '../x-module'\nimport QueryPreview from './query-preview.vue'\n\ninterface QueryPreviewStatusRecord {\n [query: string]: RequestStatus\n}\n\n/**\n * Renders the results previews of a list of objects with the information about the query preview,\n * and exposes the {@link QueryPreview} slots to modify the content.\n * The requests are made in sequential order.\n *\n * @public\n */\nexport default defineComponent({\n name: 'QueryPreviewList',\n xModule: queriesPreviewXModule.name,\n components: { QueryPreview },\n props: {\n /**\n * The list of queries preview to render.\n *\n * @public\n */\n queriesPreviewInfo: {\n type: Array as PropType<QueryPreviewInfo[]>,\n required: true,\n },\n /**\n * The origin property for the request on each query preview.\n *\n * @public\n */\n queryFeature: {\n type: String as PropType<QueryFeature>,\n },\n /**\n * Number of query preview results to be rendered on each query preview.\n *\n * @public\n */\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 * @public\n */\n loadWhenVisible: {\n type: Boolean,\n default: false,\n },\n /**\n * Debounce time in milliseconds for triggering the search requests\n * on each query preview.\n *\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 all the QueryPreview should be removed from the state\n * when the component is destroyed.\n *\n * @public\n */\n persistInCache: Boolean,\n /**\n * Animation component that will be used to animate the elements.\n *\n * @public\n */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n },\n setup(props) {\n const { params } = useState('queriesPreview')\n\n /**\n * Contains the status of the preview requests, indexed by query.\n */\n const queriesStatus = ref<QueryPreviewStatusRecord>({})\n\n /**\n * The list of queries to preview.\n *\n * @returns The list of queries in the queriesPreviewInfo list.\n * @internal\n */\n const queries = computed((): string[] =>\n props.queriesPreviewInfo.map(item =>\n getHashFromQueryPreviewInfo(item, { ...params.value, ...item.extraParams }),\n ),\n )\n\n /**\n * Gets all the queries to render, that are those that don't have an `error` status.\n *\n * @returns A list of queries.\n * @internal\n */\n const renderedQueryPreviews = computed((): QueryPreviewInfo[] => {\n return props.queriesPreviewInfo.filter(item => {\n const queryPreviewHash = getHashFromQueryPreviewInfo(item, {\n ...params.value,\n ...item.extraParams,\n })\n return (\n queriesStatus.value[queryPreviewHash] === 'success' ||\n queriesStatus.value[queryPreviewHash] === 'loading'\n )\n })\n })\n\n /**\n * Tries to load the next query.\n *\n * @internal\n */\n const loadNext = (): void => {\n const queryToLoad = queries.value.find(query => !(query in queriesStatus.value))\n if (queryToLoad) {\n queriesStatus.value[queryToLoad] = 'loading'\n }\n }\n\n /**\n * Resets the status of all queries if they change.\n *\n * @param newQueries - The new queries.\n * @param oldQueries - The old queries.\n * @internal\n */\n watch(\n queries,\n (newQueries: string[], oldQueries: string[] | undefined) => {\n if (newQueries.toString() !== oldQueries?.toString()) {\n for (const key of Object.keys(queriesStatus.value)) {\n if (!newQueries.includes(key)) {\n delete queriesStatus.value[key]\n }\n }\n loadNext()\n }\n },\n { immediate: true, deep: true },\n )\n\n /**\n * Sets the status of a given query to `success`.\n *\n * @param loadedQuery - The query to flag as loaded.\n * @internal\n */\n const flagAsLoaded = (loadedQuery: string): void => {\n queriesStatus.value[loadedQuery] = 'success'\n loadNext()\n }\n\n /**\n * Sets the status of a given query to `error`.\n *\n * @param failedQuery - The query to flag as failed.\n * @internal\n */\n const flagAsFailed = (failedQuery: string): void => {\n queriesStatus.value[failedQuery] = 'error'\n loadNext()\n }\n\n return {\n renderedQueryPreviews,\n flagAsFailed,\n flagAsLoaded,\n }\n },\n})\n</script>\n\n<style lang=\"scss\" scoped>\n.padding-block-1 {\n padding-block: 1px;\n}\n</style>\n\n<docs lang=\"mdx\">\n## See it in action\n\nHere you have a basic example of how the QueryPreviewList is rendered. Keep in mind that this\ncomponent is intended to be used overriding its default slot. By default it will only render the\nnames of the results.\n\n```vue live\n<template>\n <QueryPreviewList :queriesPreviewInfo=\"queriesPreviewInfo\" />\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\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 <QueryPreviewList\n :queriesPreviewInfo=\"queriesPreviewInfo\"\n #default=\"{ queryPreviewInfo, totalResults, results }\"\n >\n <div class=\"x-flex x-flex-col x-gap-8 x-mb-16\">\n <h1 class=\"x-title2\">{{ queryPreviewInfo.query }} ({{ totalResults }})</h1>\n <SlidingPanel :resetOnContentChange=\"false\">\n <div class=\"x-flex x-gap-8\">\n <Result\n v-for=\"result in results\"\n :key=\"result.id\"\n :result=\"result\"\n style=\"max-width: 180px\"\n />\n </div>\n </SlidingPanel>\n </div>\n </QueryPreviewList>\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport SlidingPanel from '@empathyco/x-components/sliding-panel.vue'\nimport Result from '@empathyco/x-components/result.vue'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\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 <QueryPreviewList\n class=\"x-flex x-gap-8\"\n :queriesPreviewInfo=\"queriesPreviewInfo\"\n #result=\"{ result }\"\n >\n <span class=\"x-font-bold\">{{ result.id }}:</span>\n <span>{{ result.name }}</span>\n </QueryPreviewList>\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createBlock","_resolveDynamicComponent","_createElementBlock","_Fragment","_renderList","_normalizeClass","_createVNode","_createSlots","_withCtx","_renderSlot","_mergeProps"],"mappings":";;;;;;;AACE,EAAA,OAAAA,SAAA,EAAA,EAAAC,WAAA,CAsBYC,wBAtBI,IAAA,CAAA,SAAS,CAAA,EAAA;AAAA,IAAE,KAAA,EAAM,sBAAA;AAAA,IAAuB,GAAA,EAAI;AAAA,GAAA,EAAA;qBAExD,MAAsD;AAAA,OAAAF,SAAA,CAAA,IAAA,CAAA,EADxDG,kBAAA;AAAA,QAoBKC,QAAA;AAAA,QAAA,IAAA;AAAA,QAAAC,UAAA,CAnB6B,IAAA,CAAA,qBAAA,EAAqB,CAA7C,YAAA,EAAc,KAAA,KAAK;AAD7B,UAAA,OAAAL,SAAA,EAAA,EAAAG,kBAAA;AAAA,YAoBK,IAAA;AAAA,YAAA;AAAA,cAlBF,GAAA,EAAK,KAAA;AAAA,cACL,KAAA,EAAKG,oCAAuB,IAAA,CAAA,eAAA,EAAe,CAAA;AAAA,cAC5C,WAAA,EAAU;AAAA,aAAA;;cAEVC,WAAA,CAae,uBAAA,EAAA;AAAA,gBAZZ,kBAAA,EAAkB,IAAA,CAAA,cAAA;AAAA,gBAClB,mBAAA,EAAmB,IAAA,CAAA,eAAA;AAAA,gBACnB,qBAAA,EAAqB,IAAA,CAAA,gBAAA;AAAA,gBACrB,kBAAA,EAAkB,IAAA,CAAA,cAAA;AAAA,gBAClB,eAAA,EAAe,IAAA,CAAA,YAAA;AAAA,gBACf,oBAAA,EAAoB,YAAA;AAAA,gBACpB,MAAA,EAAM,IAAA,CAAA,YAAA;AAAA,gBACN,OAAA,EAAO,IAAA,CAAA;AAAA,eAAA,EAAAC,WAAA,CAAA;;;;2BAE0B,IAAA,CAAA,MAAA,EAAM,CAAtB,GAAG,QAAA,KAAQ;;AAAc,oBAAA,IAAA,EAAA,QAAA;AAAA,oBAAA,EAAA,EAAAC,OAAA,CACzC,CAAwC,KAAA,KADkB;AAAA,sBAC1DC,UAAA,CAAwC,IAAA,CAAA,MAAA,EAA3B,QAAA,EAAbC,UAAA,CAAwC,mBAAT,KAAK,CAAA,EAAA,MAAA,EAAA,IAAA;AAAA,qBAAA;;;;;;;;;;;;;;;;;;;;;"}
@@ -53,9 +53,19 @@ var _sfc_main = defineComponent({
53
53
  maxItemsToRender: {
54
54
  type: Number,
55
55
  },
56
+ /**
57
+ * Controls whether the query preview requests should be triggered when the component is visible in the viewport.
58
+ *
59
+ * @public
60
+ */
61
+ loadWhenVisible: {
62
+ type: Boolean,
63
+ default: false,
64
+ },
56
65
  /**
57
66
  * Debounce time in milliseconds for triggering the search requests
58
67
  * on each query preview.
68
+ *
59
69
  * It will default to 0 to fit the most common use case (pre-search),
60
70
  * and it would work properly with a 250 value inside empathize.
61
71
  */
@@ -1 +1 @@
1
- {"version":3,"file":"query-preview-list.vue2.js","sources":["../../../../../src/x-modules/queries-preview/components/query-preview-list.vue"],"sourcesContent":["<template>\n <component :is=\"animation\" class=\"x-query-preview-list\" tag=\"ul\">\n <li\n v-for=\"(queryPreview, index) in renderedQueryPreviews\"\n :key=\"index\"\n data-test=\"query-preview-item\"\n >\n <QueryPreview\n :debounce-time-ms=\"debounceTimeMs\"\n :max-items-to-render=\"maxItemsToRender\"\n :persist-in-cache=\"persistInCache\"\n :query-feature=\"queryFeature\"\n :query-preview-info=\"queryPreview\"\n @load=\"flagAsLoaded\"\n @error=\"flagAsFailed\"\n >\n <template v-for=\"(_, slotName) in $slots\" #[slotName]=\"scope\">\n <slot :name=\"slotName\" v-bind=\"scope\" />\n </template>\n </QueryPreview>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\nimport type { PropType } from 'vue'\nimport type { RequestStatus } from '../../../store'\nimport type { QueryFeature } from '../../../types'\nimport type { QueryPreviewInfo } from '../store/types'\nimport { computed, defineComponent, ref, watch } from 'vue'\nimport { useState } from '../../../composables/index'\nimport { AnimationProp } from '../../../types'\nimport { getHashFromQueryPreviewInfo } from '../utils/get-hash-from-query-preview'\nimport { queriesPreviewXModule } from '../x-module'\nimport QueryPreview from './query-preview.vue'\n\ninterface QueryPreviewStatusRecord {\n [query: string]: RequestStatus\n}\n\n/**\n * Renders the results previews of a list of objects with the information about the query preview,\n * and exposes the {@link QueryPreview} slots to modify the content.\n * The requests are made in sequential order.\n *\n * @public\n */\nexport default defineComponent({\n name: 'QueryPreviewList',\n xModule: queriesPreviewXModule.name,\n components: { QueryPreview },\n props: {\n /**\n * The list of queries preview to render.\n *\n * @public\n */\n queriesPreviewInfo: {\n type: Array as PropType<QueryPreviewInfo[]>,\n required: true,\n },\n /**\n * The origin property for the request on each query preview.\n *\n * @public\n */\n queryFeature: {\n type: String as PropType<QueryFeature>,\n },\n /**\n * Number of query preview results to be rendered on each query preview.\n *\n * @public\n */\n maxItemsToRender: {\n type: Number,\n },\n /**\n * Debounce time in milliseconds for triggering the search requests\n * on each query preview.\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 all the QueryPreview should be removed from the state\n * when the component is destroyed.\n *\n * @public\n */\n persistInCache: Boolean,\n /**\n * Animation component that will be used to animate the elements.\n *\n * @public\n */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n },\n setup(props) {\n const { params } = useState('queriesPreview')\n\n /**\n * Contains the status of the preview requests, indexed by query.\n */\n const queriesStatus = ref<QueryPreviewStatusRecord>({})\n\n /**\n * The list of queries to preview.\n *\n * @returns The list of queries in the queriesPreviewInfo list.\n * @internal\n */\n const queries = computed((): string[] =>\n props.queriesPreviewInfo.map(item =>\n getHashFromQueryPreviewInfo(item, { ...params.value, ...item.extraParams }),\n ),\n )\n\n /**\n * Gets all the queries to render, that are those that don't have an `error` status.\n *\n * @returns A list of queries.\n * @internal\n */\n const renderedQueryPreviews = computed((): QueryPreviewInfo[] => {\n return props.queriesPreviewInfo.filter(item => {\n const queryPreviewHash = getHashFromQueryPreviewInfo(item, {\n ...params.value,\n ...item.extraParams,\n })\n return (\n queriesStatus.value[queryPreviewHash] === 'success' ||\n queriesStatus.value[queryPreviewHash] === 'loading'\n )\n })\n })\n\n /**\n * Tries to load the next query.\n *\n * @internal\n */\n const loadNext = (): void => {\n const queryToLoad = queries.value.find(query => !(query in queriesStatus.value))\n if (queryToLoad) {\n queriesStatus.value[queryToLoad] = 'loading'\n }\n }\n\n /**\n * Resets the status of all queries if they change.\n *\n * @param newQueries - The new queries.\n * @param oldQueries - The old queries.\n * @internal\n */\n watch(\n queries,\n (newQueries: string[], oldQueries: string[] | undefined) => {\n if (newQueries.toString() !== oldQueries?.toString()) {\n for (const key of Object.keys(queriesStatus.value)) {\n if (!newQueries.includes(key)) {\n delete queriesStatus.value[key]\n }\n }\n loadNext()\n }\n },\n { immediate: true, deep: true },\n )\n\n /**\n * Sets the status of a given query to `success`.\n *\n * @param loadedQuery - The query to flag as loaded.\n * @internal\n */\n const flagAsLoaded = (loadedQuery: string): void => {\n queriesStatus.value[loadedQuery] = 'success'\n loadNext()\n }\n\n /**\n * Sets the status of a given query to `error`.\n *\n * @param failedQuery - The query to flag as failed.\n * @internal\n */\n const flagAsFailed = (failedQuery: string): void => {\n queriesStatus.value[failedQuery] = 'error'\n loadNext()\n }\n\n return {\n renderedQueryPreviews,\n flagAsFailed,\n flagAsLoaded,\n }\n },\n})\n</script>\n\n<docs lang=\"mdx\">\n## See it in action\n\nHere you have a basic example of how the QueryPreviewList is rendered. Keep in mind that this\ncomponent is intended to be used overriding its default slot. By default it will only render the\nnames of the results.\n\n```vue live\n<template>\n <QueryPreviewList :queriesPreviewInfo=\"queriesPreviewInfo\" />\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\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 <QueryPreviewList\n :queriesPreviewInfo=\"queriesPreviewInfo\"\n #default=\"{ queryPreviewInfo, totalResults, results }\"\n >\n <div class=\"x-flex x-flex-col x-gap-8 x-mb-16\">\n <h1 class=\"x-title2\">{{ queryPreviewInfo.query }} ({{ totalResults }})</h1>\n <SlidingPanel :resetOnContentChange=\"false\">\n <div class=\"x-flex x-gap-8\">\n <Result\n v-for=\"result in results\"\n :key=\"result.id\"\n :result=\"result\"\n style=\"max-width: 180px\"\n />\n </div>\n </SlidingPanel>\n </div>\n </QueryPreviewList>\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport SlidingPanel from '@empathyco/x-components/sliding-panel.vue'\nimport Result from '@empathyco/x-components/result.vue'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\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 <QueryPreviewList\n class=\"x-flex x-gap-8\"\n :queriesPreviewInfo=\"queriesPreviewInfo\"\n #result=\"{ result }\"\n >\n <span class=\"x-font-bold\">{{ result.id }}:</span>\n <span>{{ result.name }}</span>\n </QueryPreviewList>\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAwCA;;;;;;AAME;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE,qBAAqB,CAAC,IAAI;IACnC,UAAU,EAAE,EAAE,YAAW,EAAG;AAC5B,IAAA,KAAK,EAAE;AACL;;;;AAIE;AACF,QAAA,kBAAkB,EAAE;AAClB,YAAA,IAAI,EAAE,KAAqC;AAC3C,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;;;AAIE;AACF,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAgC;AACvC,SAAA;AACD;;;;AAIE;AACF,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,MAAM;AACb,SAAA;AACD;;;;;AAKE;AACF,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,CAAC;AACX,SAAA;AACD;;;;;AAKE;AACF,QAAA,cAAc,EAAE,OAAO;AACvB;;;;AAIE;AACF,QAAA,SAAS,EAAE;A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AAgC,KAAG;YACxD,IAAI,UAAU,CAAC,QAAQ,EAAC,KAAM,UAAU,EAAE,QAAQ,EAAE,EAAE;AACpD,gBAAA,KAAK,MAAM,OAAO,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE;oBAClD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AAC7B,wBAAA,OAAO,aAAa,CAAC,KAAK,CAAC,GAAG,CAAA;oBAChC;gBACF;AACA,gBAAA,QAAQ,EAAC;YACX;QACF,CAAC,EACD,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAG,EAAG,CACjC;AAEA;;;;;AAKE;AACF,QAAA,MAAM,eAAe,CAAC,WAAmB,KAAS;AAChD,YAAA,aAAa,CAAC,KAAK,CAAC,WAAW,CAAA,GAAI,SAAQ;AAC3C,YAAA,QAAQ,EAAC;AACX,QAAA,CAAA;AAEA;;;;;AAKE;AACF,QAAA,MAAM,eAAe,CAAC,WAAmB,KAAS;AAChD,YAAA,aAAa,CAAC,KAAK,CAAC,WAAW,IAAI,OAAM;AACzC,YAAA,QAAQ,EAAC;AACX,QAAA,CAAA;QAEA,OAAO;YACL,qBAAqB;YACrB,YAAY;YACZ,YAAY;SACd;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"query-preview-list.vue2.js","sources":["../../../../../src/x-modules/queries-preview/components/query-preview-list.vue"],"sourcesContent":["<template>\n <component :is=\"animation\" class=\"x-query-preview-list\" tag=\"ul\">\n <li\n v-for=\"(queryPreview, index) in renderedQueryPreviews\"\n :key=\"index\"\n :class=\"{ 'padding-block-1': loadWhenVisible }\"\n data-test=\"query-preview-item\"\n >\n <QueryPreview\n :debounce-time-ms=\"debounceTimeMs\"\n :load-when-visible=\"loadWhenVisible\"\n :max-items-to-render=\"maxItemsToRender\"\n :persist-in-cache=\"persistInCache\"\n :query-feature=\"queryFeature\"\n :query-preview-info=\"queryPreview\"\n @load=\"flagAsLoaded\"\n @error=\"flagAsFailed\"\n >\n <template v-for=\"(_, slotName) in $slots\" #[slotName]=\"scope\">\n <slot :name=\"slotName\" v-bind=\"scope\" />\n </template>\n </QueryPreview>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\nimport type { PropType } from 'vue'\nimport type { RequestStatus } from '../../../store'\nimport type { QueryFeature } from '../../../types'\nimport type { QueryPreviewInfo } from '../store/types'\nimport { computed, defineComponent, ref, watch } from 'vue'\nimport { useState } from '../../../composables/index'\nimport { AnimationProp } from '../../../types'\nimport { getHashFromQueryPreviewInfo } from '../utils/get-hash-from-query-preview'\nimport { queriesPreviewXModule } from '../x-module'\nimport QueryPreview from './query-preview.vue'\n\ninterface QueryPreviewStatusRecord {\n [query: string]: RequestStatus\n}\n\n/**\n * Renders the results previews of a list of objects with the information about the query preview,\n * and exposes the {@link QueryPreview} slots to modify the content.\n * The requests are made in sequential order.\n *\n * @public\n */\nexport default defineComponent({\n name: 'QueryPreviewList',\n xModule: queriesPreviewXModule.name,\n components: { QueryPreview },\n props: {\n /**\n * The list of queries preview to render.\n *\n * @public\n */\n queriesPreviewInfo: {\n type: Array as PropType<QueryPreviewInfo[]>,\n required: true,\n },\n /**\n * The origin property for the request on each query preview.\n *\n * @public\n */\n queryFeature: {\n type: String as PropType<QueryFeature>,\n },\n /**\n * Number of query preview results to be rendered on each query preview.\n *\n * @public\n */\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 * @public\n */\n loadWhenVisible: {\n type: Boolean,\n default: false,\n },\n /**\n * Debounce time in milliseconds for triggering the search requests\n * on each query preview.\n *\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 all the QueryPreview should be removed from the state\n * when the component is destroyed.\n *\n * @public\n */\n persistInCache: Boolean,\n /**\n * Animation component that will be used to animate the elements.\n *\n * @public\n */\n animation: {\n type: AnimationProp,\n default: 'ul',\n },\n },\n setup(props) {\n const { params } = useState('queriesPreview')\n\n /**\n * Contains the status of the preview requests, indexed by query.\n */\n const queriesStatus = ref<QueryPreviewStatusRecord>({})\n\n /**\n * The list of queries to preview.\n *\n * @returns The list of queries in the queriesPreviewInfo list.\n * @internal\n */\n const queries = computed((): string[] =>\n props.queriesPreviewInfo.map(item =>\n getHashFromQueryPreviewInfo(item, { ...params.value, ...item.extraParams }),\n ),\n )\n\n /**\n * Gets all the queries to render, that are those that don't have an `error` status.\n *\n * @returns A list of queries.\n * @internal\n */\n const renderedQueryPreviews = computed((): QueryPreviewInfo[] => {\n return props.queriesPreviewInfo.filter(item => {\n const queryPreviewHash = getHashFromQueryPreviewInfo(item, {\n ...params.value,\n ...item.extraParams,\n })\n return (\n queriesStatus.value[queryPreviewHash] === 'success' ||\n queriesStatus.value[queryPreviewHash] === 'loading'\n )\n })\n })\n\n /**\n * Tries to load the next query.\n *\n * @internal\n */\n const loadNext = (): void => {\n const queryToLoad = queries.value.find(query => !(query in queriesStatus.value))\n if (queryToLoad) {\n queriesStatus.value[queryToLoad] = 'loading'\n }\n }\n\n /**\n * Resets the status of all queries if they change.\n *\n * @param newQueries - The new queries.\n * @param oldQueries - The old queries.\n * @internal\n */\n watch(\n queries,\n (newQueries: string[], oldQueries: string[] | undefined) => {\n if (newQueries.toString() !== oldQueries?.toString()) {\n for (const key of Object.keys(queriesStatus.value)) {\n if (!newQueries.includes(key)) {\n delete queriesStatus.value[key]\n }\n }\n loadNext()\n }\n },\n { immediate: true, deep: true },\n )\n\n /**\n * Sets the status of a given query to `success`.\n *\n * @param loadedQuery - The query to flag as loaded.\n * @internal\n */\n const flagAsLoaded = (loadedQuery: string): void => {\n queriesStatus.value[loadedQuery] = 'success'\n loadNext()\n }\n\n /**\n * Sets the status of a given query to `error`.\n *\n * @param failedQuery - The query to flag as failed.\n * @internal\n */\n const flagAsFailed = (failedQuery: string): void => {\n queriesStatus.value[failedQuery] = 'error'\n loadNext()\n }\n\n return {\n renderedQueryPreviews,\n flagAsFailed,\n flagAsLoaded,\n }\n },\n})\n</script>\n\n<style lang=\"scss\" scoped>\n.padding-block-1 {\n padding-block: 1px;\n}\n</style>\n\n<docs lang=\"mdx\">\n## See it in action\n\nHere you have a basic example of how the QueryPreviewList is rendered. Keep in mind that this\ncomponent is intended to be used overriding its default slot. By default it will only render the\nnames of the results.\n\n```vue live\n<template>\n <QueryPreviewList :queriesPreviewInfo=\"queriesPreviewInfo\" />\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\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 <QueryPreviewList\n :queriesPreviewInfo=\"queriesPreviewInfo\"\n #default=\"{ queryPreviewInfo, totalResults, results }\"\n >\n <div class=\"x-flex x-flex-col x-gap-8 x-mb-16\">\n <h1 class=\"x-title2\">{{ queryPreviewInfo.query }} ({{ totalResults }})</h1>\n <SlidingPanel :resetOnContentChange=\"false\">\n <div class=\"x-flex x-gap-8\">\n <Result\n v-for=\"result in results\"\n :key=\"result.id\"\n :result=\"result\"\n style=\"max-width: 180px\"\n />\n </div>\n </SlidingPanel>\n </div>\n </QueryPreviewList>\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport SlidingPanel from '@empathyco/x-components/sliding-panel.vue'\nimport Result from '@empathyco/x-components/result.vue'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\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 <QueryPreviewList\n class=\"x-flex x-gap-8\"\n :queriesPreviewInfo=\"queriesPreviewInfo\"\n #result=\"{ result }\"\n >\n <span class=\"x-font-bold\">{{ result.id }}:</span>\n <span>{{ result.name }}</span>\n </QueryPreviewList>\n</template>\n\n<script setup>\nimport { QueryPreviewList } from '@empathyco/x-components/queries-preview'\nimport { reactive } from 'vue'\nconst queriesPreviewInfo = reactive([\n { query: 'sandals' },\n { query: 'tshirt' },\n { query: 'jacket' },\n])\n</script>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AA0CA;;;;;;AAME;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE,qBAAqB,CAAC,IAAI;IACnC,UAAU,EAAE,EAAE,YAAW,EAAG;AAC5B,IAAA,KAAK,EAAE;AACL;;;;AAIE;AACF,QAAA,kBAAkB,EAAE;AAClB,YAAA,IAAI,EAAE,KAAqC;AAC3C,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;;;AAIE;AACF,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAgC;AACvC,SAAA;AACD;;;;AAIE;AACF,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,MAAM;AACb,SAAA;AACD;;;;AAIE;AACF,QAAA,eAAe,EAAE;AACf,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,KAAK;AACf,SAAA;AACD;;;;;;AAME;AACF,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,CAAC;AACX,SAAA;AACD;;;;;AAKE;AACF,QAAA,cAAc,EAAE,OAAO;AACvB;;;;AAIE;AACF,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACF,KAAA;AACD,IAAA,KAAK,CAAC,KAAK,EAAA;QACT,MAAM,EAAE,QAAO,GAAI,QAAQ,CAAC,gBAAgB,CAAA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E;oBAClD,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AAC7B,wBAAA,OAAO,aAAa,CAAC,KAAK,CAAC,GAAG,CAAA;oBAChC;gBACF;AACA,gBAAA,QAAQ,EAAC;YACX;QACF,CAAC,EACD,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAG,EAAG,CACjC;AAEA;;;;;AAKE;AACF,QAAA,MAAM,eAAe,CAAC,WAAmB,KAAS;AAChD,YAAA,aAAa,CAAC,KAAK,CAAC,WAAW,CAAA,GAAI,SAAQ;AAC3C,YAAA,QAAQ,EAAC;AACX,QAAA,CAAA;AAEA;;;;;AAKE;AACF,QAAA,MAAM,eAAe,CAAC,WAAmB,KAAS;AAChD,YAAA,aAAa,CAAC,KAAK,CAAC,WAAW,IAAI,OAAM;AACzC,YAAA,QAAQ,EAAC;AACX,QAAA,CAAA;QAEA,OAAO;YACL,qBAAqB;YACrB,YAAY;YACZ,YAAY;SACd;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
@@ -0,0 +1,7 @@
1
+ import injectCss from '../../../../tools/inject-css.js';
2
+
3
+ var css = ".padding-block-1[data-v-a0750562]{padding-bottom:1px;padding-top:1px}";
4
+ injectCss(css);
5
+
6
+ export { css };
7
+ //# sourceMappingURL=query-preview-list.vue3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-preview-list.vue3.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
@@ -3,37 +3,49 @@ import { openBlock, createElementBlock, Fragment, renderList, renderSlot, create
3
3
  import _export_sfc from '../../../_virtual/_plugin-vue_export-helper.js';
4
4
 
5
5
  const _hoisted_1 = {
6
+ ref: "queryPreviewElement",
7
+ class: "x-query-preview-wrapper__default-content"
8
+ };
9
+ const _hoisted_2 = {
6
10
  key: 0,
7
11
  "data-test": "query-preview",
8
12
  class: "x-query-preview"
9
13
  };
10
- const _hoisted_2 = { "data-test": "result-name" };
14
+ const _hoisted_3 = { "data-test": "result-name" };
11
15
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
12
- return _ctx.hasResults ? (openBlock(), createElementBlock("ul", _hoisted_1, [
13
- (openBlock(true), createElementBlock(
14
- Fragment,
15
- null,
16
- renderList(_ctx.queryPreviewResults?.results, (result) => {
17
- return openBlock(), createElementBlock("li", {
18
- key: result.id,
19
- class: "x-query-preview__item",
20
- "data-test": "query-preview-item"
21
- }, [
22
- renderSlot(_ctx.$slots, "result", { result }, () => [
23
- createElementVNode(
24
- "span",
25
- _hoisted_2,
26
- toDisplayString(result.name),
27
- 1
28
- /* TEXT */
29
- )
30
- ])
31
- ]);
32
- }),
33
- 128
34
- /* KEYED_FRAGMENT */
35
- ))
36
- ])) : createCommentVNode("v-if", true);
16
+ return openBlock(), createElementBlock(
17
+ "section",
18
+ _hoisted_1,
19
+ [
20
+ _ctx.hasResults ? (openBlock(), createElementBlock("ul", _hoisted_2, [
21
+ (openBlock(true), createElementBlock(
22
+ Fragment,
23
+ null,
24
+ renderList(_ctx.queryPreviewResults?.results, (result) => {
25
+ return openBlock(), createElementBlock("li", {
26
+ key: result.id,
27
+ class: "x-query-preview__item",
28
+ "data-test": "query-preview-item"
29
+ }, [
30
+ renderSlot(_ctx.$slots, "result", { result }, () => [
31
+ createElementVNode(
32
+ "span",
33
+ _hoisted_3,
34
+ toDisplayString(result.name),
35
+ 1
36
+ /* TEXT */
37
+ )
38
+ ])
39
+ ]);
40
+ }),
41
+ 128
42
+ /* KEYED_FRAGMENT */
43
+ ))
44
+ ])) : createCommentVNode("v-if", true)
45
+ ],
46
+ 512
47
+ /* NEED_PATCH */
48
+ );
37
49
  }
38
50
  var QueryPreview = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
39
51
 
@@ -1 +1 @@
1
- {"version":3,"file":"query-preview.vue.js","sources":["../../../../../src/x-modules/queries-preview/components/query-preview.vue"],"sourcesContent":["<template>\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</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, inject, onBeforeUnmount, provide, watch } from 'vue'\nimport { LIST_ITEMS_KEY } from '../../../components'\nimport { 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 * 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 * 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)) {\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 {\n emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value)\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 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 * Render function to execute the `default` slot, binding `slotsProps` and getting only the\n * first `vNode` to avoid Fragments and Text root nodes.\n * If there are no results, nothing is rendered.\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.\n */\n function renderDefaultSlot() {\n const slotProps = {\n queryPreviewInfo: props.queryPreviewInfo,\n results: queryPreviewResults.value?.results,\n totalResults: queryPreviewResults.value?.totalResults,\n displayTagging: queryPreviewResults.value?.displayTagging,\n queryTagging: queryPreviewResults.value?.queryTagging,\n }\n\n return hasResults.value ? slots.default?.(slotProps)[0] : ''\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 = { hasResults, queryPreviewResults }\n return (slots.default ? renderDefaultSlot : componentProps) as typeof componentProps\n },\n})\n</script>\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","_Fragment","_renderList","_renderSlot","_createElementVNode","_toDisplayString"],"mappings":";;;;;;EACwB,WAAA,EAAU,eAAA;AAAA,EAAgB,KAAA,EAAM;;AAY1C,MAAA,UAAA,GAAA,EAAA,WAAA,EAAU,aAAA,EAAa;;SAZzB,IAAA,CAAA,UAAA,IAAAA,SAAA,EAAA,EAAVC,kBAAA,CAeK,MAfL,UAAA,EAeK;AAAA,KAAAD,SAAA,CAAA,IAAA,CAAA,EAdHC,kBAAA;AAAA,MAaKC,QAAA;AAAA,MAAA,IAAA;AAAA,MAAAC,UAAA,CAZc,IAAA,CAAA,mBAAA,EAAqB,OAAA,EAAO,CAAtC,MAAA,KAAM;4BADfF,kBAAA,CAaK,IAAA,EAAA;AAAA,UAXF,KAAK,MAAA,CAAO,EAAA;AAAA,UACb,KAAA,EAAM,uBAAA;AAAA,UACN,WAAA,EAAU;AAAA,SAAA,EAAA;UAMVG,UAAA,CAEO,IAAA,CAAA,MAAA,EAAA,QAAA,EAAA,EAFc,MAAA,EAAc,EAAnC,MAEO;AAAA,YADLC,kBAAA;AAAA,cAAsD,MAAA;AAAA,cAAtD,UAAA;AAAA,cAAsDC,eAAA,CAArB,OAAO,IAAI,CAAA;AAAA,cAAA;AAAA;AAAA;AAAA,WAAA;;;;;;;;;;;;"}
1
+ {"version":3,"file":"query-preview.vue.js","sources":["../../../../../src/x-modules/queries-preview/components/query-preview.vue"],"sourcesContent":["<template>\n <!-- eslint-disable-next-line vue/no-unused-refs -->\n <section ref=\"queryPreviewElement\" class=\"x-query-preview-wrapper__default-content\">\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 * 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 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 { ref: queryPreviewElement, class: 'x-query-preview-wrapper__slot-content' },\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 = { hasResults, queryPreviewResults, queryPreviewElement }\n return (slots.default ? renderDefaultSlot : componentProps) as typeof componentProps\n },\n})\n</script>\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","_Fragment","_renderList","_renderSlot","_createElementVNode","_toDisplayString"],"mappings":";;;;;EAEW,GAAA,EAAI,qBAAA;AAAA,EAAsB,KAAA,EAAM;;;;EACjB,WAAA,EAAU,eAAA;AAAA,EAAgB,KAAA,EAAM;;AAY1C,MAAA,UAAA,GAAA,EAAA,WAAA,EAAU,aAAA,EAAa;;AAbrC,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA;AAAA,IAiBU,SAAA;AAAA,IAjBV,UAAA;AAAA,IAiBU;AAAA,MAhBE,IAAA,CAAA,UAAA,IAAAD,SAAA,EAAA,EAAVC,kBAAA,CAeK,IAAA,EAfL,UAAA,EAeK;AAAA,SAAAD,SAAA,CAAA,IAAA,CAAA,EAdHC,kBAAA;AAAA,UAaKC,QAAA;AAAA,UAAA,IAAA;AAAA,UAAAC,UAAA,CAZc,IAAA,CAAA,mBAAA,EAAqB,OAAA,EAAO,CAAtC,MAAA,KAAM;gCADfF,kBAAA,CAaK,IAAA,EAAA;AAAA,cAXF,KAAK,MAAA,CAAO,EAAA;AAAA,cACb,KAAA,EAAM,uBAAA;AAAA,cACN,WAAA,EAAU;AAAA,aAAA,EAAA;cAMVG,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;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { deepEqual } from '@empathyco/x-utils';
2
- import { defineComponent, computed, provide, inject, watch, onBeforeUnmount } from 'vue';
2
+ import { defineComponent, ref, computed, provide, inject, watch, onBeforeUnmount, h } from 'vue';
3
3
  import '../../../components/animations/animate-clip-path/animate-clip-path.style.scss.js';
4
4
  import '../../../components/animations/animate-scale/animate-scale.style.scss.js';
5
5
  import '../../../components/animations/animate-translate/animate-translate.style.scss.js';
@@ -106,7 +106,7 @@ import '../../../components/suggestions/base-suggestions.vue2.js';
106
106
  import '../../../components/suggestions/base-suggestions.vue3.js';
107
107
  import '../../../composables/create-use-device.js';
108
108
  import { debounce } from '../../../utils/debounce.js';
109
- import '@vueuse/core';
109
+ import { useOnDisplay } from '../../../composables/use-on-display.js';
110
110
  import { useState } from '../../../composables/use-state.js';
111
111
  import { createRawFilters } from '../../../utils/filters.js';
112
112
  import { createOrigin } from '../../../utils/origin.js';
@@ -138,6 +138,13 @@ var _sfc_main = defineComponent({
138
138
  maxItemsToRender: {
139
139
  type: Number,
140
140
  },
141
+ /**
142
+ * Controls whether the query preview requests should be triggered when the component is visible in the viewport.
143
+ */
144
+ loadWhenVisible: {
145
+ type: Boolean,
146
+ default: false,
147
+ },
141
148
  /**
142
149
  * Debounce time in milliseconds for triggering the search requests.
143
150
  * It will default to 0 to fit the most common use case (pre-search),
@@ -170,6 +177,10 @@ var _sfc_main = defineComponent({
170
177
  * the config that will be used in the request.
171
178
  */
172
179
  const { queriesPreview: previewResults, params, config } = useState('queriesPreview');
180
+ /**
181
+ * Template ref for the root element to track visibility.
182
+ */
183
+ const queryPreviewElement = ref(null);
173
184
  /**
174
185
  * Query Preview key converted into a unique id.
175
186
  *
@@ -258,7 +269,7 @@ var _sfc_main = defineComponent({
258
269
  * @internal
259
270
  */
260
271
  watch(queryPreviewRequest, (newRequest, oldRequest) => {
261
- if (!deepEqual(newRequest, oldRequest)) {
272
+ if (!deepEqual(newRequest, oldRequest) && !props.loadWhenVisible) {
262
273
  emitQueryPreviewRequestUpdated.value(newRequest);
263
274
  }
264
275
  });
@@ -271,9 +282,21 @@ var _sfc_main = defineComponent({
271
282
  replaceable: false,
272
283
  });
273
284
  }
274
- else {
285
+ else if (!props.loadWhenVisible) {
275
286
  emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value);
276
287
  }
288
+ /**
289
+ * Watch element visibility and emit request when it becomes visible for the first time
290
+ * (only when loadWhenVisible is true).
291
+ */
292
+ const { unwatchDisplay } = useOnDisplay({
293
+ element: queryPreviewElement,
294
+ callback: () => {
295
+ if (props.loadWhenVisible && cachedQueryPreview?.status !== 'success') {
296
+ emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value);
297
+ }
298
+ },
299
+ });
277
300
  /**
278
301
  * Cancels the (remaining) requests when the component is destroyed
279
302
  * via the `debounce.cancel()` method.
@@ -281,6 +304,7 @@ var _sfc_main = defineComponent({
281
304
  * from the state when the component is destroyed.
282
305
  */
283
306
  onBeforeUnmount(() => {
307
+ unwatchDisplay?.();
284
308
  emitQueryPreviewRequestUpdated.value.cancel();
285
309
  xBus.emit('QueryPreviewUnmounted', { queryPreviewHash: queryPreviewHash.value, cache: props.persistInCache }, {
286
310
  priority: 0,
@@ -316,12 +340,12 @@ var _sfc_main = defineComponent({
316
340
  /**
317
341
  * Render function to execute the `default` slot, binding `slotsProps` and getting only the
318
342
  * first `vNode` to avoid Fragments and Text root nodes.
319
- * If there are no results, nothing is rendered.
320
343
  *
321
344
  * @remarks `slotProps` must be values without Vue reactivity and located inside the
322
345
  * render-function to update the binding data properly.
323
346
  *
324
- * @returns The root `vNode` of the `default` slot or empty string if there are no results.
347
+ * @returns The root `vNode` of the `default` slot or empty string if there are no results. Always wrapped in a section
348
+ * element with the `x-query-preview-wrapper__slot-content` class.
325
349
  */
326
350
  function renderDefaultSlot() {
327
351
  const slotProps = {
@@ -331,11 +355,12 @@ var _sfc_main = defineComponent({
331
355
  displayTagging: queryPreviewResults.value?.displayTagging,
332
356
  queryTagging: queryPreviewResults.value?.queryTagging,
333
357
  };
334
- return hasResults.value ? slots.default?.(slotProps)[0] : '';
358
+ const slotContent = hasResults.value ? slots.default?.(slotProps)[0] : '';
359
+ return h('section', { ref: queryPreviewElement, class: 'x-query-preview-wrapper__slot-content' }, [slotContent]);
335
360
  }
336
361
  /* Hack to render through a render-function, the `default` slot or, in its absence,
337
362
  the component itself. It is the alternative for the NoElement antipattern. */
338
- const componentProps = { hasResults, queryPreviewResults };
363
+ const componentProps = { hasResults, queryPreviewResults, queryPreviewElement };
339
364
  return (slots.default ? renderDefaultSlot : componentProps);
340
365
  },
341
366
  });
@@ -1 +1 @@
1
- {"version":3,"file":"query-preview.vue2.js","sources":["../../../../../src/x-modules/queries-preview/components/query-preview.vue"],"sourcesContent":["<template>\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</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, inject, onBeforeUnmount, provide, watch } from 'vue'\nimport { LIST_ITEMS_KEY } from '../../../components'\nimport { 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 * 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 * 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)) {\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 {\n emitQueryPreviewRequestUpdated.value(queryPreviewRequest.value)\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 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 * Render function to execute the `default` slot, binding `slotsProps` and getting only the\n * first `vNode` to avoid Fragments and Text root nodes.\n * If there are no results, nothing is rendered.\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.\n */\n function renderDefaultSlot() {\n const slotProps = {\n queryPreviewInfo: props.queryPreviewInfo,\n results: queryPreviewResults.value?.results,\n totalResults: queryPreviewResults.value?.totalResults,\n displayTagging: queryPreviewResults.value?.displayTagging,\n queryTagging: queryPreviewResults.value?.queryTagging,\n }\n\n return hasResults.value ? slots.default?.(slotProps)[0] : ''\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 = { hasResults, queryPreviewResults }\n return (slots.default ? renderDefaultSlot : componentProps) as typeof componentProps\n },\n})\n</script>\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA;;;;;;AAME;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,qBAAqB,CAAC,IAAI;AACnC,IAAA,KAAK,EAAE;;AAEL,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,MAAoC;AAC1C,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;;AAED,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAgC;AACvC,SAAA;;AAED,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,MAAM;AACb,SAAA;AACD;;;;AAIE;AACF,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,CAAC;AACX,SAAA;AACD;;;AAGE;AACF,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,KAAK;AACf,SAAA;AACF,KAAA;AACD,IAAA,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;AACxB,IAAA,KAAK,CAA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,KAAI,KAAM,SAAS,EAAE;AACjD,gBAAA,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,MAAK,GAAI,MAAK,GAAI,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAA;YACvE;AAAO,iBAAA,IAAI,yBAAyB,CAAC,UAAU,OAAO,EAAE;AACtD,gBAAA,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAA;YACtC;AACF,QAAA,CAAC,CAAA;AAED,QAAA,MAAM,UAAS,GAAI,QAAQ,CAAC,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAA;AAEpF;;;;;;;;;AASE;AACF,QAAA,SAAS,iBAAiB,GAAA;AACxB,YAAA,MAAM,YAAY;gBAChB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;AACxC,gBAAA,OAAO,EAAE,mBAAmB,CAAC,KAAK,EAAE,OAAO;AAC3C,gBAAA,YAAY,EAAE,mBAAmB,CAAC,KAAK,EAAE,YAAY;AACrD,gBAAA,cAAc,EAAE,mBAAmB,CAAC,KAAK,EAAE,cAAc;AACzD,gBAAA,YAAY,EAAE,mBAAmB,CAAC,KAAK,EAAE,YAAY;aACvD;YAEA,OAAO,UAAU,CAAC,KAAI,GAAI,KAAK,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA,GAAI,EAAC;QAC7D;AAEA;AAC+E;AAC/E,QAAA,MAAM,iBAAiB,EAAE,UAAU,EAAE,mBAAkB,EAAE;AACzD,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-next-line vue/no-unused-refs -->\n <section ref=\"queryPreviewElement\" class=\"x-query-preview-wrapper__default-content\">\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 * 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 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 { ref: queryPreviewElement, class: 'x-query-preview-wrapper__slot-content' },\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 = { hasResults, queryPreviewResults, queryPreviewElement }\n return (slots.default ? renderDefaultSlot : componentProps) as typeof componentProps\n },\n})\n</script>\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA;;;;;;AAME;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,qBAAqB,CAAC,IAAI;AACnC,IAAA,KAAK,EAAE;;AAEL,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAA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C,UAAU,OAAO,EAAE;AACtD,gBAAA,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAA;YACtC;AACF,QAAA,CAAC,CAAA;AAED,QAAA,MAAM,UAAS,GAAI,QAAQ,CAAC,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAA;AAEpF;;;;;;;;;AASE;AACF,QAAA,SAAS,iBAAiB,GAAA;AACxB,YAAA,MAAM,YAAY;gBAChB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;AACxC,gBAAA,OAAO,EAAE,mBAAmB,CAAC,KAAK,EAAE,OAAO;AAC3C,gBAAA,YAAY,EAAE,mBAAmB,CAAC,KAAK,EAAE,YAAY;AACrD,gBAAA,cAAc,EAAE,mBAAmB,CAAC,KAAK,EAAE,cAAc;AACzD,gBAAA,YAAY,EAAE,mBAAmB,CAAC,KAAK,EAAE,YAAY;aACvD;YAEA,MAAM,WAAU,GAAI,UAAU,CAAC,KAAI,GAAI,KAAK,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA,GAAI,EAAC;AAExE,YAAA,OAAO,CAAC,CACN,SAAS,EACT,EAAE,GAAG,EAAE,mBAAmB,EAAE,KAAK,EAAE,yCAAyC,EAC5E,CAAC,WAAW,CAAC,CACf;QACF;AAEA;AAC+E;QAC/E,MAAM,cAAa,GAAI,EAAE,UAAU,EAAE,mBAAmB,EAAE,mBAAkB,EAAE;AAC9E,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": "6.0.0-alpha.200",
3
+ "version": "6.0.0-alpha.201",
4
4
  "description": "Empathy X Components",
5
5
  "author": "Empathy Systems Corporation S.L.",
6
6
  "license": "Apache-2.0",
@@ -143,5 +143,5 @@
143
143
  "access": "public",
144
144
  "directory": "dist"
145
145
  },
146
- "gitHead": "54fb952d29874732259857df8fbadb4c25e2bca1"
146
+ "gitHead": "cd9ef371f82015903705d1348fd36d03817c240e"
147
147
  }
@@ -49556,7 +49556,16 @@
49556
49556
  },
49557
49557
  {
49558
49558
  "kind": "Content",
49559
- "text": ";\n };\n debounceTimeMs: {\n type: "
49559
+ "text": ";\n };\n loadWhenVisible: {\n type: "
49560
+ },
49561
+ {
49562
+ "kind": "Reference",
49563
+ "text": "BooleanConstructor",
49564
+ "canonicalReference": "!BooleanConstructor:interface"
49565
+ },
49566
+ {
49567
+ "kind": "Content",
49568
+ "text": ";\n default: boolean;\n };\n debounceTimeMs: {\n type: "
49560
49569
  },
49561
49570
  {
49562
49571
  "kind": "Reference",
@@ -49637,7 +49646,34 @@
49637
49646
  },
49638
49647
  {
49639
49648
  "kind": "Content",
49640
- "text": ";\n } | undefined>;\n}, {}, {}, {}, import(\"vue\")."
49649
+ "text": ";\n } | undefined>;\n queryPreviewElement: "
49650
+ },
49651
+ {
49652
+ "kind": "Reference",
49653
+ "text": "Ref",
49654
+ "canonicalReference": "@vue/reactivity!Ref:interface"
49655
+ },
49656
+ {
49657
+ "kind": "Content",
49658
+ "text": "<"
49659
+ },
49660
+ {
49661
+ "kind": "Reference",
49662
+ "text": "HTMLElement",
49663
+ "canonicalReference": "!HTMLElement:interface"
49664
+ },
49665
+ {
49666
+ "kind": "Content",
49667
+ "text": " | null, "
49668
+ },
49669
+ {
49670
+ "kind": "Reference",
49671
+ "text": "HTMLElement",
49672
+ "canonicalReference": "!HTMLElement:interface"
49673
+ },
49674
+ {
49675
+ "kind": "Content",
49676
+ "text": " | null>;\n}, {}, {}, {}, import(\"vue\")."
49641
49677
  },
49642
49678
  {
49643
49679
  "kind": "Reference",
@@ -49727,7 +49763,16 @@
49727
49763
  },
49728
49764
  {
49729
49765
  "kind": "Content",
49730
- "text": ";\n };\n debounceTimeMs: {\n type: "
49766
+ "text": ";\n };\n loadWhenVisible: {\n type: "
49767
+ },
49768
+ {
49769
+ "kind": "Reference",
49770
+ "text": "BooleanConstructor",
49771
+ "canonicalReference": "!BooleanConstructor:interface"
49772
+ },
49773
+ {
49774
+ "kind": "Content",
49775
+ "text": ";\n default: boolean;\n };\n debounceTimeMs: {\n type: "
49731
49776
  },
49732
49777
  {
49733
49778
  "kind": "Reference",
@@ -49754,7 +49799,7 @@
49754
49799
  },
49755
49800
  {
49756
49801
  "kind": "Content",
49757
- "text": "<{\n onLoad?: ((...args: any[]) => any) | undefined;\n onError?: ((...args: any[]) => any) | undefined;\n}>, {\n debounceTimeMs: number;\n persistInCache: boolean;\n}, {}, {}, {}, string, import(\"vue\")."
49802
+ "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\")."
49758
49803
  },
49759
49804
  {
49760
49805
  "kind": "Reference",
@@ -49772,7 +49817,7 @@
49772
49817
  "name": "QueryPreview",
49773
49818
  "variableTypeTokenRange": {
49774
49819
  "startIndex": 1,
49775
- "endIndex": 62
49820
+ "endIndex": 72
49776
49821
  }
49777
49822
  },
49778
49823
  {
@@ -50474,7 +50519,16 @@
50474
50519
  },
50475
50520
  {
50476
50521
  "kind": "Content",
50477
- "text": ";\n };\n debounceTimeMs: {\n type: "
50522
+ "text": ";\n };\n loadWhenVisible: {\n type: "
50523
+ },
50524
+ {
50525
+ "kind": "Reference",
50526
+ "text": "BooleanConstructor",
50527
+ "canonicalReference": "!BooleanConstructor:interface"
50528
+ },
50529
+ {
50530
+ "kind": "Content",
50531
+ "text": ";\n default: boolean;\n };\n debounceTimeMs: {\n type: "
50478
50532
  },
50479
50533
  {
50480
50534
  "kind": "Reference",
@@ -50627,7 +50681,16 @@
50627
50681
  },
50628
50682
  {
50629
50683
  "kind": "Content",
50630
- "text": ";\n };\n debounceTimeMs: {\n type: "
50684
+ "text": ";\n };\n loadWhenVisible: {\n type: "
50685
+ },
50686
+ {
50687
+ "kind": "Reference",
50688
+ "text": "BooleanConstructor",
50689
+ "canonicalReference": "!BooleanConstructor:interface"
50690
+ },
50691
+ {
50692
+ "kind": "Content",
50693
+ "text": ";\n default: boolean;\n };\n debounceTimeMs: {\n type: "
50631
50694
  },
50632
50695
  {
50633
50696
  "kind": "Reference",
@@ -50681,7 +50744,7 @@
50681
50744
  },
50682
50745
  {
50683
50746
  "kind": "Content",
50684
- "text": "<{}>, {\n persistInCache: boolean;\n debounceTimeMs: number;\n animation: string | "
50747
+ "text": "<{}>, {\n persistInCache: boolean;\n loadWhenVisible: boolean;\n debounceTimeMs: number;\n animation: string | "
50685
50748
  },
50686
50749
  {
50687
50750
  "kind": "Reference",
@@ -50726,7 +50789,7 @@
50726
50789
  "name": "QueryPreviewList",
50727
50790
  "variableTypeTokenRange": {
50728
50791
  "startIndex": 1,
50729
- "endIndex": 70
50792
+ "endIndex": 74
50730
50793
  }
50731
50794
  },
50732
50795
  {
@@ -5383,6 +5383,10 @@ type: PropType<QueryFeature>;
5383
5383
  maxItemsToRender: {
5384
5384
  type: NumberConstructor;
5385
5385
  };
5386
+ loadWhenVisible: {
5387
+ type: BooleanConstructor;
5388
+ default: boolean;
5389
+ };
5386
5390
  debounceTimeMs: {
5387
5391
  type: NumberConstructor;
5388
5392
  default: number;
@@ -5402,6 +5406,7 @@ totalResults: number;
5402
5406
  instances: number;
5403
5407
  status: RequestStatus;
5404
5408
  } | undefined>;
5409
+ queryPreviewElement: Ref<HTMLElement | null, HTMLElement | null>;
5405
5410
  }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ("load" | "error")[], "load" | "error", PublicProps, Readonly<ExtractPropTypes< {
5406
5411
  queryPreviewInfo: {
5407
5412
  type: PropType<QueryPreviewInfo>;
@@ -5413,6 +5418,10 @@ type: PropType<QueryFeature>;
5413
5418
  maxItemsToRender: {
5414
5419
  type: NumberConstructor;
5415
5420
  };
5421
+ loadWhenVisible: {
5422
+ type: BooleanConstructor;
5423
+ default: boolean;
5424
+ };
5416
5425
  debounceTimeMs: {
5417
5426
  type: NumberConstructor;
5418
5427
  default: number;
@@ -5425,6 +5434,7 @@ default: boolean;
5425
5434
  onLoad?: ((...args: any[]) => any) | undefined;
5426
5435
  onError?: ((...args: any[]) => any) | undefined;
5427
5436
  }>, {
5437
+ loadWhenVisible: boolean;
5428
5438
  debounceTimeMs: number;
5429
5439
  persistInCache: boolean;
5430
5440
  }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
@@ -5484,6 +5494,10 @@ type: PropType<QueryFeature>;
5484
5494
  maxItemsToRender: {
5485
5495
  type: NumberConstructor;
5486
5496
  };
5497
+ loadWhenVisible: {
5498
+ type: BooleanConstructor;
5499
+ default: boolean;
5500
+ };
5487
5501
  debounceTimeMs: {
5488
5502
  type: NumberConstructor;
5489
5503
  default: number;
@@ -5508,6 +5522,10 @@ type: PropType<QueryFeature>;
5508
5522
  maxItemsToRender: {
5509
5523
  type: NumberConstructor;
5510
5524
  };
5525
+ loadWhenVisible: {
5526
+ type: BooleanConstructor;
5527
+ default: boolean;
5528
+ };
5511
5529
  debounceTimeMs: {
5512
5530
  type: NumberConstructor;
5513
5531
  default: number;
@@ -5519,6 +5537,7 @@ default: string;
5519
5537
  };
5520
5538
  }>> & Readonly<{}>, {
5521
5539
  persistInCache: boolean;
5540
+ loadWhenVisible: boolean;
5522
5541
  debounceTimeMs: number;
5523
5542
  animation: string | Function | Record<string, any>;
5524
5543
  }, {}, {
@@ -34,9 +34,19 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
34
34
  maxItemsToRender: {
35
35
  type: NumberConstructor;
36
36
  };
37
+ /**
38
+ * Controls whether the query preview requests should be triggered when the component is visible in the viewport.
39
+ *
40
+ * @public
41
+ */
42
+ loadWhenVisible: {
43
+ type: BooleanConstructor;
44
+ default: boolean;
45
+ };
37
46
  /**
38
47
  * Debounce time in milliseconds for triggering the search requests
39
48
  * on each query preview.
49
+ *
40
50
  * It will default to 0 to fit the most common use case (pre-search),
41
51
  * and it would work properly with a 250 value inside empathize.
42
52
  */
@@ -90,9 +100,19 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
90
100
  maxItemsToRender: {
91
101
  type: NumberConstructor;
92
102
  };
103
+ /**
104
+ * Controls whether the query preview requests should be triggered when the component is visible in the viewport.
105
+ *
106
+ * @public
107
+ */
108
+ loadWhenVisible: {
109
+ type: BooleanConstructor;
110
+ default: boolean;
111
+ };
93
112
  /**
94
113
  * Debounce time in milliseconds for triggering the search requests
95
114
  * on each query preview.
115
+ *
96
116
  * It will default to 0 to fit the most common use case (pre-search),
97
117
  * and it would work properly with a 250 value inside empathize.
98
118
  */
@@ -118,6 +138,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
118
138
  };
119
139
  }>> & Readonly<{}>, {
120
140
  persistInCache: boolean;
141
+ loadWhenVisible: boolean;
121
142
  debounceTimeMs: number;
122
143
  animation: string | Function | Record<string, any>;
123
144
  }, {}, {
@@ -1 +1 @@
1
- {"version":3,"file":"query-preview-list.vue?vue&type=script&lang.d.ts","sourceRoot":"","sources":["../../../../../src/x-modules/queries-preview/components/query-preview-list.vue?vue&type=script&lang.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AAEnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAYtD;;;;;;GAMG;;IAMC;;;;OAIG;;cAEc,QAAQ,CAAC,gBAAgB,EAAE,CAAC;;;IAG7C;;;;OAIG;;cAEe,QAAQ,CAAC,YAAY,CAAC;;IAExC;;;;OAIG;;;;IAIH;;;;;OAKG;;;;;IAKH;;;;;OAKG;;IAEH;;;;OAIG;;;;;;;gCAgGgC,MAAM,KAAG,IAAI;gCAXb,MAAM,KAAG,IAAI;;IAnIhD;;;;OAIG;;cAEc,QAAQ,CAAC,gBAAgB,EAAE,CAAC;;;IAG7C;;;;OAIG;;cAEe,QAAQ,CAAC,YAAY,CAAC;;IAExC;;;;OAIG;;;;IAIH;;;;;OAKG;;;;;IAKH;;;;;OAKG;;IAEH;;;;OAIG;;;;;;;;;;;;AAnDP,wBA8JE"}
1
+ {"version":3,"file":"query-preview-list.vue?vue&type=script&lang.d.ts","sourceRoot":"","sources":["../../../../../src/x-modules/queries-preview/components/query-preview-list.vue?vue&type=script&lang.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AAEnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAYtD;;;;;;GAMG;;IAMC;;;;OAIG;;cAEc,QAAQ,CAAC,gBAAgB,EAAE,CAAC;;;IAG7C;;;;OAIG;;cAEe,QAAQ,CAAC,YAAY,CAAC;;IAExC;;;;OAIG;;;;IAIH;;;;OAIG;;;;;IAKH;;;;;;OAMG;;;;;IAKH;;;;;OAKG;;IAEH;;;;OAIG;;;;;;;gCAgGgC,MAAM,KAAG,IAAI;gCAXb,MAAM,KAAG,IAAI;;IA7IhD;;;;OAIG;;cAEc,QAAQ,CAAC,gBAAgB,EAAE,CAAC;;;IAG7C;;;;OAIG;;cAEe,QAAQ,CAAC,YAAY,CAAC;;IAExC;;;;OAIG;;;;IAIH;;;;OAIG;;;;;IAKH;;;;;;OAMG;;;;;IAKH;;;;;OAKG;;IAEH;;;;OAIG;;;;;;;;;;;;;AA7DP,wBAwKE"}
@@ -1,5 +1,5 @@
1
1
  import type { SearchRequest } from '@empathyco/x-types';
2
- import type { PropType } from 'vue';
2
+ import type { PropType, Ref } from 'vue';
3
3
  import type { QueryFeature } from '../../../types';
4
4
  import type { QueryPreviewInfo } from '../store/types';
5
5
  /**
@@ -23,6 +23,13 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
23
23
  maxItemsToRender: {
24
24
  type: NumberConstructor;
25
25
  };
26
+ /**
27
+ * Controls whether the query preview requests should be triggered when the component is visible in the viewport.
28
+ */
29
+ loadWhenVisible: {
30
+ type: BooleanConstructor;
31
+ default: boolean;
32
+ };
26
33
  /**
27
34
  * Debounce time in milliseconds for triggering the search requests.
28
35
  * It will default to 0 to fit the most common use case (pre-search),
@@ -51,6 +58,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
51
58
  instances: number;
52
59
  status: import("../../..").RequestStatus;
53
60
  } | undefined>;
61
+ queryPreviewElement: Ref<HTMLElement | null, HTMLElement | null>;
54
62
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("load" | "error")[], "load" | "error", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
55
63
  /** The information about the request of the query preview. */
56
64
  queryPreviewInfo: {
@@ -65,6 +73,13 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
65
73
  maxItemsToRender: {
66
74
  type: NumberConstructor;
67
75
  };
76
+ /**
77
+ * Controls whether the query preview requests should be triggered when the component is visible in the viewport.
78
+ */
79
+ loadWhenVisible: {
80
+ type: BooleanConstructor;
81
+ default: boolean;
82
+ };
68
83
  /**
69
84
  * Debounce time in milliseconds for triggering the search requests.
70
85
  * It will default to 0 to fit the most common use case (pre-search),
@@ -86,6 +101,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
86
101
  onLoad?: ((...args: any[]) => any) | undefined;
87
102
  onError?: ((...args: any[]) => any) | undefined;
88
103
  }>, {
104
+ loadWhenVisible: boolean;
89
105
  debounceTimeMs: number;
90
106
  persistInCache: boolean;
91
107
  }, {}, {}, {}, 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,EAAO,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;;;;OAIG;;;;;IAKH;;;OAGG;;;;;;;;;;;;;;;;;IAzBH,8DAA8D;;cAE5C,QAAQ,CAAC,gBAAgB,CAAC;;;IAG5C,2CAA2C;;cAEzB,QAAQ,CAAC,YAAY,CAAC;;IAExC,sDAAsD;;;;IAItD;;;;OAIG;;;;;IAKH;;;OAGG;;;;;;;;;;;;AA7BP,wBA2PE"}
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,wBA2RE"}