@empathyco/x-components 6.0.0-alpha.200 → 6.0.0-alpha.202
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/docs/API-reference/api/x-components.querypreview.md +10 -0
- package/docs/API-reference/api/x-components.querypreviewlist.md +9 -0
- package/docs/API-reference/components/queries-preview/x-components.query-preview-list.md +9 -8
- package/docs/API-reference/components/queries-preview/x-components.query-preview.md +1 -0
- package/js/components/sliding-panel.vue.js.map +1 -1
- package/js/components/sliding-panel.vue2.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview-list.vue.js +37 -28
- package/js/x-modules/queries-preview/components/query-preview-list.vue.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview-list.vue2.js +10 -0
- package/js/x-modules/queries-preview/components/query-preview-list.vue2.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview-list.vue3.js +7 -0
- package/js/x-modules/queries-preview/components/query-preview-list.vue3.js.map +1 -0
- package/js/x-modules/queries-preview/components/query-preview.vue.js +38 -26
- package/js/x-modules/queries-preview/components/query-preview.vue.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview.vue2.js +33 -8
- package/js/x-modules/queries-preview/components/query-preview.vue2.js.map +1 -1
- package/package.json +2 -2
- package/report/x-components.api.json +72 -9
- package/report/x-components.api.md +19 -0
- package/types/x-modules/queries-preview/components/query-preview-list.vue.d.ts +21 -0
- package/types/x-modules/queries-preview/components/query-preview-list.vue.d.ts.map +1 -1
- package/types/x-modules/queries-preview/components/query-preview.vue.d.ts +17 -1
- package/types/x-modules/queries-preview/components/query-preview.vue.d.ts.map +1 -1
|
@@ -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 '
|
|
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
|
-
|
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAmB,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,EAAE,MAAoC;AAC1C,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;;AAED,QAAA,YAAY,EAAE;AACZ,YAAA,IAAI,EAAE,MAAgC;AACvC,SAAA;;AAED,QAAA,gBAAgB,EAAE;AAChB,YAAA,IAAI,EAAE,MAAM;AACb,SAAA;AACD;;AAEE;AACF,QAAA,eAAe,EAAE;AACf,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,KAAK;AACf,SAAA;AACD;;;;AAIE;AACF,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,OAAO,EAAE,CAAC;AACX,SAAA;AACD;;;AAGE;AACF,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,KAAK;AACf,SAAA;AACF,KAAA;AACD,IAAA,KAAK,EAAE,CAA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AAE,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.
|
|
3
|
+
"version": "6.0.0-alpha.202",
|
|
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": "
|
|
146
|
+
"gitHead": "24227b2e9617df5be735f870d67b43d1854f031d"
|
|
147
147
|
}
|
|
@@ -49556,7 +49556,16 @@
|
|
|
49556
49556
|
},
|
|
49557
49557
|
{
|
|
49558
49558
|
"kind": "Content",
|
|
49559
|
-
"text": ";\n };\n
|
|
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
|
|
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
|
|
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":
|
|
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
|
|
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
|
|
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":
|
|
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;;;;;
|
|
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,
|
|
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"}
|