UNPKG

@empathyco/x-components

Version:
80 lines (77 loc) 2.61 kB
import { defineComponent, ref, inject } from 'vue'; import '../../composables/create-use-device.js'; import { use$x } from '../../composables/use-_x.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'; /** * Component to be reused that renders an `<a>` wrapping the result contents. * * @remarks * It has the logic to emit {@link XEventsTypes.UserClickedAResult} to the bus on click mouse * events. Additionally, this component may be injected other events to be emitted on click * event, so, depending on where it's used its father component may provide this events. * * @public */ var _sfc_main = defineComponent({ props: { /** * (Required) The {@link @empathyco/x-types#Result} information. * * @public */ result: { type: Object, required: true, }, }, setup(props) { const $x = use$x(); /** * The rendered DOM element. * * @internal */ const el = ref(); /** * The list of additional events to be emitted by the component when user clicks the link. * * @internal */ const resultClickExtraEvents = inject('resultClickExtraEvents', []); /** * The metadata to be injected in the events emitted by the component. This component can emit * have extra events so this record pairs each event to its metadata. */ const resultLinkMetadataPerEvent = inject('resultLinkMetadataPerEvent', {}); /** * Emits the {@link XEventsTypes.UserClickedAResult} when user clicks on the result, and also * additional events if have been injected in the component. * * @internal */ const emitUserClickedAResult = () => { $x.emit('UserClickedAResult', props.result, { target: el.value, ...resultLinkMetadataPerEvent.UserClickedAResult, }); resultClickExtraEvents.forEach(event => { $x.emit(event, props.result, { target: el.value, ...resultLinkMetadataPerEvent[event] }); }); }; return { el, emitUserClickedAResult, }; }, }); export { _sfc_main as default }; //# sourceMappingURL=base-result-link.vue2.js.map