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.33 kB
Source Map (JSON)
{"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 ref,\n toValue,\n} from 'vue'\n\nimport {globalShowHideStorageInjectionKey} from '../../utils/keys'\n\nexport const useToggle = (id: MaybeRefOrGetter<string | undefined> = undefined) => {\n const instance = getCurrentInstance()\n const {values: registry} = inject(globalShowHideStorageInjectionKey, {\n register: () => ({unregister: () => {}}),\n values: ref(new Map()),\n })\n\n if (!registry) {\n throw new Error(\n 'useToggle() was called outside of the setup() function or the plugin is not provided.'\n )\n }\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":";;AAYa,MAAA,YAAY,CAAC,KAA2C,WAAc;AACjF,QAAM,WAAW,mBAAmB;AACpC,QAAM,EAAC,QAAQ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