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 2.89 kB
{"version":3,"file":"index.mjs","sources":["../../../../src/plugins/modalManager/index.ts"],"sourcesContent":["import {type ComponentInternalInstance, computed, type Plugin, readonly, type Ref, ref} from 'vue'\nimport {modalManagerPluginKey} from '../../utils/keys'\n\nexport const modalManagerPlugin: Plugin = {\n install(app) {\n /**\n * A collection of all currently active modals\n *\n * It was made into a map so that if a modal is ever added into the stack twice, it will not be duplicated\n * (if modelValue is true when started, it gets added in setup scope, then a watcher is triggered and it gets added again in the next tick)\n * Didn't feel like fixing it in the modal component, so I just made it a map\n */\n const stack: Ref<Map<number, ComponentInternalInstance>> = ref(new Map())\n\n const countStack = computed(() => stack.value.size)\n const valuesStack = computed(() => [...stack.value.values()])\n const lastStack = computed(() => valuesStack.value[valuesStack.value.length - 1])\n\n const pushStack = (modal: Readonly<ComponentInternalInstance>) => {\n stack.value.set(modal.uid, modal)\n }\n const removeStack = (modal: Readonly<ComponentInternalInstance>) => {\n stack.value.delete(modal.uid)\n }\n\n /**\n * A collection of all registered modals\n */\n const registry: Ref<Map<number, ComponentInternalInstance>> = ref(new Map())\n\n // Utility getters not made, would not be used (count, last)\n\n const pushRegistry = (modal: Readonly<ComponentInternalInstance>) => {\n registry.value.set(modal.uid, modal)\n }\n const removeRegistry = (modal: Readonly<ComponentInternalInstance>) => {\n registry.value.delete(modal.uid)\n }\n\n app.provide(modalManagerPluginKey, {\n countStack,\n lastStack,\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n registry: readonly(registry) as Readonly<Ref<Map<number, ComponentInternalInstance>>>,\n stack: valuesStack,\n pushStack,\n removeStack,\n pushRegistry,\n removeRegistry,\n })\n },\n}\n"],"names":[],"mappings":";;AAGO,MAAM,qBAA6B;AAAA,EACxC,QAAQ,KAAK;AAQX,UAAM,QAAqD,IAAQ,oBAAA,KAAK;AAExE,UAAM,aAAa,SAAS,MAAM,MAAM,MAAM,IAAI;AAC5C,UAAA,cAAc,SAAS,MAAM,CAAC,GAAG,MAAM,MAAM,OAAO,CAAC,CAAC;AACtD,UAAA,YAAY,SAAS,MAAM,YAAY,MAAM,YAAY,MAAM,SAAS,CAAC,CAAC;AAE1E,UAAA,YAAY,CAAC,UAA+C;AAChE,YAAM,MAAM,IAAI,MAAM,KAAK,KAAK;AAAA,IAClC;AACM,UAAA,cAAc,CAAC,UAA+C;AAC5D,YAAA,MAAM,OAAO,MAAM,GAAG;AAAA,IAC9B;AAKA,UAAM,WAAwD,IAAQ,oBAAA,KAAK;AAIrE,UAAA,eAAe,CAAC,UAA+C;AACnE,eAAS,MAAM,IAAI,MAAM,KAAK,KAAK;AAAA,IACrC;AACM,UAAA,iBAAiB,CAAC,UAA+C;AAC5D,eAAA,MAAM,OAAO,MAAM,GAAG;AAAA,IACjC;AAEA,QAAI,QAAQ,uBAAuB;AAAA,MACjC;AAAA,MACA;AAAA;AAAA;AAAA,MAGA,UAAU,SAAS,QAAQ;AAAA,MAC3B,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EAAA;AAEL;"}