bootstrap-vue-next
Version:
Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development
1 lines • 2.89 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","names":[],"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'\nimport {getActiveShowHide} from '../../utils/registryAccess'\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 (resolvedId) {\n return getActiveShowHide(registry, resolvedId)\n }\n\n if (!instance) {\n return null\n }\n\n const component = findComponent(instance)\n const componentId = toValue(component?.exposed?.id)\n return getActiveShowHide(registry, componentId)\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"],"mappings":";;;;AAYA,IAAa,aAAa,KAA2C,KAAA,MAAc;CACjF,MAAM,WAAW,mBAAmB;CACpC,MAAM,UAAU,OAAO,qBAAqB,IAAI;CAEhD,IAAI,CAAC,SACH,MAAM,IAAI,MACR,wGACF;CAEF,MAAM,WAAW,QAAQ;CAEzB,MAAM,iBACJ,cACqC;EACrC,IAAI,CAAC,UAAU,QACb,OAAO;EAGT,IACE,UAAU,OAAO,UAAU,SAC3B,SAAS,MAAM,IAAI,QAAQ,UAAU,OAAO,QAAQ,EAAE,CAAC,GAEvD,OAAO,UAAU;EAGnB,OAAO,cAAc,UAAU,MAAM;CACvC;CAEA,MAAM,cAAc,eAAe;EACjC,MAAM,aAAa,QAAQ,EAAE;EAE7B,IAAI,YACF,OAAO,kBAAkB,UAAU,UAAU;EAG/C,IAAI,CAAC,UACH,OAAO;EAGT,MAAM,YAAY,cAAc,QAAQ;EACxC,MAAM,cAAc,QAAQ,WAAW,SAAS,EAAE;EAClD,OAAO,kBAAkB,UAAU,WAAW;CAChD,CAAC;CAED,OAAO;EACL,OAAO,eAAe,YAAY,OAAO,KAAK;EAC9C,OAAO,kBACL,YAAY,OAAO,KAAK,aAAa,KAAK,QAAQ,OAAO,WAAW;EACtE,OAAO,YACL,YAAY,OAAO,KAAK,SAAS,IAAI,KAAK,QAAQ,OAAO,WAAW;EACtE,SAAS,kBACP,YAAY,OAAO,OAAO,aAAa,KAAK,QAAQ,OAAO,WAAW;EACxE,WAAW,eAAe,YAAY,OAAO,SAAS;CACxD;AACF"}