UNPKG

bootstrap-vue-next

Version:

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

151 lines (150 loc) 4.66 kB
import { inject, provide, ref, computed, readonly } from "vue"; import { s as showHideRegistryKey, m as modalManagerKey, e as breadcrumbRegistryKey, a as breadcrumbGlobalIndexKey, r as rtlRegistryKey } from "../../../keys-BLeKMItg.mjs"; const useRegistry = (rtl = false) => { const showHideStorage = inject(showHideRegistryKey, void 0); if (!showHideStorage) { const { register, values } = _newShowHideRegistry(); provide(showHideRegistryKey, { register, values }); } const modalManager = inject(modalManagerKey, void 0); if (!modalManager) { 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); }; 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 }); } const breadcrumb = inject(breadcrumbRegistryKey, void 0); if (!breadcrumb) { const items = ref({ [breadcrumbGlobalIndexKey]: [] }); const reset = (key = breadcrumbGlobalIndexKey) => { items.value[key] = []; }; provide(breadcrumbRegistryKey, { items, reset }); } const rtlRegistry = inject(rtlRegistryKey, void 0); if (!rtlRegistry) { 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; const isRtl = ref(rtlInitial); const locale = ref(localeInitial); provide(rtlRegistryKey, { isRtl, locale }); } }; const createGetActive = (instances) => () => instances.length > 0 ? instances[instances.length - 1] : void 0; const _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, // Returns the last mounted instance (most recent) 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 }; }; export { _newShowHideRegistry, useRegistry }; //# sourceMappingURL=index.mjs.map