UNPKG

bootstrap-vue-next

Version:

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

111 lines (110 loc) 3.58 kB
import { _ as orchestratorRegistryKey } from "../../../keys-BgLwJbLV.js"; import { inject, nextTick, provide, readonly, ref } from "vue"; //#region src/composables/orchestratorShared/index.ts var buildController = (id, store) => { let resolveFunc = () => {}; const basePromise = new Promise((resolve) => { resolveFunc = resolve; }); const findItem = () => store.value.get(id); const controller = { id, ref: null, async show() { if (controller.get()?.value.props.modelValue) { const event = await basePromise; return Object.assign(Object.create(event), { [Symbol.asyncDispose]: controller.destroy }); } const refWithMethods = controller.ref; if (refWithMethods !== null && "show" in refWithMethods && typeof refWithMethods.show === "function") refWithMethods.show(); else controller.set({ modelValue: true }); const event = await basePromise; return Object.assign(Object.create(event), { [Symbol.asyncDispose]: controller.destroy }); }, hide(trigger) { const refWithMethods = controller.ref; if (refWithMethods !== null && "hide" in refWithMethods && typeof refWithMethods.hide === "function") refWithMethods.hide(trigger, true); else controller.set({ modelValue: false }); }, toggle() { const currentItem = controller.get(); const refWithMethods = controller.ref; if (refWithMethods !== null && "toggle" in refWithMethods && typeof refWithMethods.toggle === "function") refWithMethods.toggle(); else controller.set({ modelValue: !currentItem?.value.props.modelValue }); }, get: findItem, set(val) { const current = findItem(); if (current?.value) current.value = { ...current.value, props: { ...current.value.props, ...val } }; }, async destroy() { const item = findItem(); if (!item) return; try { if (item.value.props.modelValue) { await basePromise; await nextTick(); controller.hide("destroy"); } } finally { store.value.delete(id); } }, [Symbol.asyncDispose]() { return controller.destroy(); } }; return { controller, resolve: resolveFunc }; }; var _newOrchestratorRegistry = () => { const _isOrchestratorInstalled = ref(false); const _isToastAppend = ref(false); return { store: ref({ modal: /* @__PURE__ */ new Map(), tooltip: /* @__PURE__ */ new Map(), popover: /* @__PURE__ */ new Map(), toast: /* @__PURE__ */ new Map() }), _isOrchestratorInstalled: readonly(_isOrchestratorInstalled), _setOrchestratorInstalled: (v) => { _isOrchestratorInstalled.value = v; }, _isToastAppend: readonly(_isToastAppend), _setToastAppend: (v) => { _isToastAppend.value = v; } }; }; var useOrchestratorRegistry = () => { const orchestratorRegistry = inject(orchestratorRegistryKey, null); if (orchestratorRegistry) return orchestratorRegistry; const newOrchestratorRegistry = _newOrchestratorRegistry(); provide(orchestratorRegistryKey, newOrchestratorRegistry); return newOrchestratorRegistry; }; var getOrchestratorControllerId = (propId) => { const id = propId || Symbol("OrchestratorItem"); return { /** * This id is used for stability in the store, using the createIdWatcher will update the store if the id ever changes */ storeId: id, /** * Do not pass in the symbol as a prop. Html attribute cannot be a symbol. Thus it's internal */ htmlAttributeId: typeof id === "string" ? id : void 0 }; }; //#endregion export { _newOrchestratorRegistry, buildController, getOrchestratorControllerId, useOrchestratorRegistry }; //# sourceMappingURL=index.mjs.map