UNPKG

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 3.09 kB
{"version":3,"file":"index.mjs","sources":["../../../../src/composables/useToggle/index.ts"],"sourcesContent":["import {\n type ComponentInternalInstance,\n computed,\n getCurrentInstance,\n inject,\n type MaybeRefOrGetter,\n toValue,\n} from 'vue'\n\nimport {showHideRegistryKey} from '../../utils/keys'\n\nexport const useToggle = (id: MaybeRefOrGetter<string | undefined> = undefined) => {\n const instance = getCurrentInstance()\n const storage = inject(showHideRegistryKey, null)\n\n if (!storage) {\n throw new Error(\n 'useToggle() must be called within setup(), and BApp, useRegistry or plugin must be installed/provided.'\n )\n }\n const registry = storage.values\n // const registry = toRef(() => appRegistry.value)\n const findComponent = (\n component: ComponentInternalInstance\n ): ComponentInternalInstance | null => {\n if (!component.parent) {\n return null\n }\n\n if (\n component.parent.exposed?.['id'] &&\n registry.value.get(toValue(component.parent.exposed.id))\n ) {\n return component.parent\n }\n\n return findComponent(component.parent)\n }\n\n const myComponent = computed(() => {\n const resolvedId = toValue(id)\n\n if (!registry) return null\n if (resolvedId) {\n const value = registry.value.get(resolvedId)\n return toValue(value) || null\n }\n\n if (!instance) {\n return null\n }\n\n const component = findComponent(instance)\n return toValue(registry.value.get(toValue(component?.exposed?.id))) || null\n })\n\n return {\n value: computed(() => myComponent.value?.value),\n show: (resolveOnHide?: boolean) =>\n myComponent.value?.show(resolveOnHide) || Promise.reject('not found'),\n hide: (trigger?: string) =>\n myComponent.value?.hide(trigger, true) || Promise.reject('not found'),\n toggle: (resolveOnHide?: boolean) =>\n myComponent.value?.toggle(resolveOnHide) || Promise.reject('not found'),\n component: computed(() => myComponent.value?.component),\n }\n}\n"],"names":[],"mappings":";;AAWO,MAAM,YAAY,CAAC,KAA2C,WAAc;AACjF,QAAM,WAAW,mBAAA;AACjB,QAAM,UAAU,OAAO,qBAAqB,IAAI;AAEhD,MAAI,CAAC,SAAS;AACZ,U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