bootstrap-vue-next
Version:
Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development
66 lines (65 loc) • 2.1 kB
JavaScript
import { _ as orchestratorRegistryKey } from "../../../keys-BgLwJbLV.js";
import { buildController, getOrchestratorControllerId } from "../orchestratorShared/index.mjs";
import { t as BToast_default } from "../../../BToast-Di9HwBOV.js";
import { computed, inject, markRaw, onScopeDispose, ref } from "vue";
//#region src/composables/useToast/index.ts
var posDefault = "top-end";
var useToast = () => {
const orchestratorRegistry = inject(orchestratorRegistryKey, null);
if (!orchestratorRegistry) throw new Error("useToast() must be called within setup(), and BApp, useRegistry or plugin must be installed/provided.");
const { store, _isToastAppend, _isOrchestratorInstalled } = orchestratorRegistry;
/**
* @returns {ComponentController<typeof BToast, ToastOrchestratorParam>}
*/
function create(obj = {}) {
if (!_isOrchestratorInstalled.value) throw new Error("The BApp component must be mounted to use the toast composable");
const toastComp = markRaw(BToast_default);
const resolvedProps = ref(obj);
const toastStore = computed(() => store.value.toast);
const { htmlAttributeId, storeId } = getOrchestratorControllerId(resolvedProps.value.id);
const { resolve, controller } = buildController(storeId, toastStore);
const value = computed({
get: () => {
const { component = toastComp, options, slots, ...props } = resolvedProps.value;
return {
component,
options,
slots,
id: storeId,
fns: {
resolve,
setRef: (v) => {
controller.ref = v;
},
destroy: controller.destroy
},
props: {
...props,
id: htmlAttributeId,
position: props.position || posDefault
}
};
},
set: (v) => {
resolvedProps.value = {
...resolvedProps.value,
...v.props
};
}
});
toastStore.value.set(storeId, value);
onScopeDispose(async () => {
await controller[Symbol.asyncDispose]();
}, true);
return controller;
}
return {
_isToastAppend,
_isOrchestratorInstalled,
store,
create
};
};
//#endregion
export { useToast };
//# sourceMappingURL=index.mjs.map