UNPKG

bootstrap-vue-next

Version:

Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development

132 lines (131 loc) 4.07 kB
import { b as rtlRegistryKey, h as modalManagerKey, i as breadcrumbRegistryKey, r as breadcrumbGlobalIndexKey, x as showHideRegistryKey } from "../../../keys-CQKrwmvN.mjs"; import { computed, inject, provide, readonly, ref } from "vue"; //#region src/composables/useRegistry/index.ts var useRegistry = (rtl = false) => { if (!inject(showHideRegistryKey, null)) { const { register, values } = _newShowHideRegistry(); provide(showHideRegistryKey, { register, values }); } if (!inject(modalManagerKey, null)) { const stack = ref(/* @__PURE__ */ new Map()); const countStack = computed(() => stack.value.size); const valuesStack = computed(() => [...stack.value.values()]); const lastStack = computed(() => valuesStack.value[valuesStack.value.length - 1]); const pushStack = (modal) => { stack.value.set(modal.uid, modal); }; const removeStack = (modal) => { stack.value.delete(modal.uid); }; /** * A collection of all registered modals */ const registry = ref(/* @__PURE__ */ new Map()); const pushRegistry = (modal) => { registry.value.set(modal.uid, modal); }; const removeRegistry = (modal) => { registry.value.delete(modal.uid); }; provide(modalManagerKey, { countStack, lastStack, registry: computed(() => registry.value), stack: valuesStack, pushStack, removeStack, pushRegistry, removeRegistry }); } if (!inject(breadcrumbRegistryKey, null)) { const items = ref({ [breadcrumbGlobalIndexKey]: [] }); const reset = (key = breadcrumbGlobalIndexKey) => { items.value[key] = []; }; provide(breadcrumbRegistryKey, { items, reset }); } if (!inject(rtlRegistryKey, null)) { const rtlDefault = false; const localeDefault = void 0; const rtlInitial = typeof rtl === "boolean" ? rtlDefault : rtl?.rtlInitial ?? rtlDefault; const localeInitial = typeof rtl === "boolean" ? localeDefault : rtl?.localeInitial ?? localeDefault; provide(rtlRegistryKey, { isRtl: ref(rtlInitial), locale: ref(localeInitial) }); } }; var createGetActive = (instances) => () => instances.length > 0 ? instances[instances.length - 1] : void 0; var _newShowHideRegistry = () => { const values = ref(/* @__PURE__ */ new Map()); const register = ({ id, component, value, toggle, show, hide, registerTrigger, unregisterTrigger }) => { let currentId = id; const instanceValue = { id, component, value: readonly(value), toggle, show, hide, registerTrigger, unregisterTrigger }; let instancesHolder = values.value.get(currentId); if (!instancesHolder) { const instances = []; instancesHolder = { instances, getActive: createGetActive(instances) }; values.value.set(currentId, instancesHolder); } instancesHolder.instances.push(instanceValue); const componentUid = component.uid; return { unregister() { const holder = values.value.get(currentId); if (!holder) return; const index = holder.instances.findIndex((inst) => inst.component.uid === componentUid); if (index !== -1) holder.instances.splice(index, 1); if (holder.instances.length === 0) values.value.delete(currentId); }, updateId(newId, oldId) { const holder = values.value.get(oldId); if (!holder) return; const instance = holder.instances.find((inst) => inst.component.uid === componentUid); if (!instance) return; instance.id = newId; let newHolder = values.value.get(newId); if (!newHolder) { const instances = []; newHolder = { instances, getActive: createGetActive(instances) }; values.value.set(newId, newHolder); } const index = holder.instances.findIndex((inst) => inst.component.uid === componentUid); if (index !== -1) { holder.instances.splice(index, 1); newHolder.instances.push(instance); } if (holder.instances.length === 0) values.value.delete(oldId); currentId = newId; } }; }; return { register, values }; }; //#endregion export { _newShowHideRegistry, useRegistry }; //# sourceMappingURL=index.mjs.map