bootstrap-vue-next
Version:
BootstrapVueNext is an early and lovely component library for Vue 3 & Nuxt 3 based on Bootstrap 5 and Typescript.
1 lines • 6.82 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../../../../src/plugins/popoverController/index.ts"],"sourcesContent":["import {isRef, onScopeDispose, type Plugin, ref, toRef, toValue, watch} from 'vue'\nimport {popoverPluginKey} from '../../utils/keys'\nimport type {\n ControllerKey,\n PopoverOrchestratorParam,\n PopoverOrchestratorShowParam,\n TooltipOrchestratorParam,\n TooltipOrchestratorShowParam,\n} from '../../types/ComponentOrchestratorTypes'\n\nexport const popoverPlugin: Plugin = {\n install(app) {\n const popovers = ref(new Map<ControllerKey, PopoverOrchestratorParam>())\n /**\n * @returns {ControllerKey} If `id` is passed to props, it will use that id, otherwise,\n * a symbol will be created that corresponds to its unique id.\n */\n const popover = (obj: PopoverOrchestratorShowParam): ControllerKey => {\n const resolvedProps = toRef(obj)\n const _self = resolvedProps.value?.id || Symbol('Popover controller')\n\n watch(\n resolvedProps,\n (newValue) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore: How to add refs for title & content?\n popovers.value.set(_self, {\n ...newValue,\n ...(typeof newValue['modelValue'] !== 'undefined' && isRef(obj)\n ? {\n 'onUpdate:modelValue': (val: boolean) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore: How to add emit types?\n newValue['onUpdate:modelValue']?.(val)\n obj.value.modelValue = val\n },\n }\n : {}),\n })\n },\n {\n immediate: true,\n deep: true,\n }\n )\n onScopeDispose(() => popovers.value.delete(_self), true)\n\n return _self\n }\n /**\n * @param {ControllerKey} self You can get the symbol param from the return value from the show method, or use props.id\n */\n const setPopover = (self: ControllerKey, val: Partial<PopoverOrchestratorParam>) => {\n const popover = popovers.value.get(self)\n if (!popover) return\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore: How to add refs for title & content?\n popovers.value.set(self, {\n ...popover,\n ...toValue(val),\n })\n }\n /**\n * @param {ControllerKey} self You can get the symbol param from the return value from the show method, or use props.id\n */\n const removePopover = (self: ControllerKey) => popovers.value.delete(self)\n\n const tooltips = ref(new Map<ControllerKey, TooltipOrchestratorParam>())\n /**\n * @returns {ControllerKey} If `id` is passed to props, it will use that id, otherwise,\n * a symbol will be created that corresponds to its unique id.\n */\n const tooltip = (obj: TooltipOrchestratorShowParam): ControllerKey => {\n const resolvedProps = toRef(obj)\n const _self = resolvedProps.value?.id || Symbol('Tooltip controller')\n\n watch(\n resolvedProps,\n (newValue) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore: How to add refs for title & content?\n popovers.value.set(_self, {\n ...newValue,\n ...(typeof newValue['modelValue'] !== 'undefined' && isRef(obj)\n ? {\n 'onUpdate:modelValue': (val: boolean) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore: How to add emit types?\n newValue['onUpdate:modelValue']?.(val)\n obj.value.modelValue = val\n },\n }\n : {}),\n })\n },\n {\n immediate: true,\n deep: true,\n }\n )\n onScopeDispose(() => tooltips.value.delete(_self), true)\n\n return _self\n }\n /**\n * @param {ControllerKey} self You can get the symbol param from the return value from the show method, or use props.id\n */\n const setTooltip = (self: ControllerKey, val: Partial<TooltipOrchestratorParam>) => {\n const tooltip = tooltips.value.get(self)\n if (!tooltip) return\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore: How to add refs for title & content?\n tooltips.value.set(self, {\n ...tooltip,\n ...toValue(val),\n })\n }\n /**\n * @param {ControllerKey} self You can get the symbol param from the return value from the show method, or use props.id\n */\n const removeTooltip = (self: ControllerKey) => tooltips.value.delete(self)\n\n app.provide(popoverPluginKey, {\n popovers,\n tooltips,\n tooltip,\n popover,\n setPopover,\n setTooltip,\n removePopover,\n removeTooltip,\n })\n },\n}\n"],"names":["_a","popover","tooltip"],"mappings":";;AAUO,MAAM,gBAAwB;AAAA,EACnC,QAAQ,KAAK;AACX,UAAM,WA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