UNPKG

@empathyco/x-components

Version:
65 lines (62 loc) 2.11 kB
import { defineComponent, onMounted, computed } from 'vue'; import { use$x } from '../../../composables/use-_x.js'; import { useState } from '../../../composables/use-state.js'; import { nextQueriesXModule } from '../x-module.js'; /** * Retrieves a preview of the results of a next query and exposes them in the default slot, * along with the next query and the totalResults of the search request. * By default, it renders the names of the results. * * @public */ var _sfc_main = defineComponent({ name: 'NextQueryPreview', xModule: nextQueriesXModule.name, props: { /** * The next query to retrieve the results preview. * * @public */ suggestion: { type: Object, required: true, }, /** * Number of suggestion results to be rendered. * * @public */ maxItemsToRender: Number, }, setup(props) { const $x = use$x(); /** * The results preview of the next queries mounted. * It is a dictionary, indexed by the next query query. */ const { resultsPreview } = useState('nextQueries'); /** * The component emits the NextQueryPreviewMountedHook event to retrieve the results preview * of the next query. */ onMounted(() => $x.emit('NextQueryPreviewMountedHook', props.suggestion.query)); /** * Gets from the state the results preview of the next query. * * @returns The results preview of the actual next query. */ const suggestionResults = computed(() => { const previewResults = resultsPreview.value[props.suggestion.query]; return previewResults ? { ...previewResults, items: previewResults.items.slice(0, props.maxItemsToRender), } : undefined; }); return { suggestionResults }; }, }); export { _sfc_main as default }; //# sourceMappingURL=next-query-preview.vue2.js.map