UNPKG

@empathyco/x-components

Version:
72 lines (69 loc) 2.96 kB
import { defineComponent, computed } from 'vue'; import BaseSuggestions from '../../../components/suggestions/base-suggestions.vue.js'; import '../../../composables/create-use-device.js'; import 'vuex'; import '@vue/devtools-api'; import '../../../plugins/devtools/timeline.devtools.js'; import '@empathyco/x-utils'; import 'rxjs/operators'; import 'rxjs'; import '../../../plugins/devtools/colors.utils.js'; import '../../../plugins/x-bus.js'; import '../../../plugins/x-plugin.js'; import '@vueuse/core'; import { useState } from '../../../composables/use-state.js'; import { semanticQueriesXModule } from '../x-module.js'; import SemanticQuery from './semantic-query.vue.js'; /** * Retrieves a list of semantic queries from the state and exposes them in the slots. * * @public */ var _sfc_main = defineComponent({ name: 'SemanticQueries', xModule: semanticQueriesXModule.name, components: { BaseSuggestions, SemanticQuery }, setup(_, { slots }) { /** The semantic queries from the state. */ const suggestions = useState('semanticQueries').semanticQueries; /** * Maps the list of semantic queries to a list of queries, to make it compatible with * other components. */ const queries = computed(() => suggestions.value.map(suggestion => suggestion.query)); /** * Finds a {@link @empathyco/x-types#Suggestion} given a query. * * @param query - The query to search. * @returns The {@link @empathyco/x-types#Suggestion} or undefined if not found. */ function findSemanticQuery(query) { return suggestions.value.find(suggestion => suggestion.query === query); } /** * Render function to execute the `default` slot, binding `slotsProps` and getting only the * first `vNode` to avoid Fragments and Text root nodes. * If there are no suggestions, nothing is rendered. * * @remarks `slotProps` must be values without Vue reactivity and located inside the * render-function to update the binding data properly. * * @returns The root `vNode` of the `default` slot or empty string if there are * no suggestions. */ function renderDefaultSlot() { const slotProps = { suggestions: suggestions.value, queries: queries.value, findSemanticQuery, }; return suggestions.value.length ? slots.default?.(slotProps)[0] : ''; } /* Hack to render through a render-function, the `default` slot or, in its absence, the component itself. It is the alternative for the NoElement antipattern. */ const componentProps = { suggestions }; return (slots.default ? renderDefaultSlot : componentProps); }, }); export { _sfc_main as default }; //# sourceMappingURL=semantic-queries.vue2.js.map