bootstrap-vue-next
Version:
Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development
90 lines (89 loc) • 3.88 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../../../chunk-CoQrYLCe.js");
const require_keys = require("../../../keys-durSVUrO.js");
const require_src_composables_orchestratorShared_index = require("../orchestratorShared/index.umd.js");
const require_BToast = require("../../../BToast-DCSZYXIi.js");
require("../../components/index.umd.js");
let vue = require("vue");
//#region src/composables/useToast/index.ts
var posDefault = "top-end";
var useToast = () => {
const orchestratorRegistry = (0, vue.inject)(require_keys.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 {PromiseWithComponent<typeof BToast, ToastOrchestratorParam>} Returns a promise object with methods to control the toast (show, hide, toggle, get, set, destroy)
*/
const create = (obj = {}, options = {}) => {
if (!_isOrchestratorInstalled.value) throw new Error("The BApp component must be mounted to use the toast composable");
const resolvedProps = (0, vue.isRef)(obj) ? obj : (0, vue.shallowRef)(obj);
const _self = resolvedProps.value?.id || Symbol("Toast controller");
const promise = require_src_composables_orchestratorShared_index.buildPromise(_self, store);
promise.stop = (0, vue.watch)(resolvedProps, (_newValue) => {
const newValue = { ...(0, vue.toValue)(_newValue) };
const previousIndex = store.value.findIndex((el) => el._self === _self);
const v = {
...previousIndex === -1 ? { _component: (0, vue.markRaw)(require_BToast.BToast_default) } : store.value[previousIndex],
type: "toast",
_self,
promise,
options
};
if (newValue.props) {
Object.assign(v, newValue.props);
newValue.props = void 0;
}
if (newValue.pos) {
v.position = newValue.pos;
newValue.pos = void 0;
}
for (const key in newValue) if (key.startsWith("on")) v[key] = newValue[key];
else if (key === "component" && newValue.component) v._component = (0, vue.markRaw)(newValue.component);
else if (key === "slots" && newValue.slots) v.slots = (0, vue.markRaw)(newValue.slots);
else v[key] = (0, vue.toValue)(newValue[key]);
v.position = v.position || posDefault;
v.modelValue = v.modelValue ?? 5e3;
v["onUpdate:modelValue"] = (val) => {
newValue["onUpdate:modelValue"]?.(val);
const { modelValue } = (0, vue.toValue)(obj);
if ((0, vue.isRef)(obj) && !(0, vue.isRef)(modelValue)) obj.value.modelValue = val;
if ((0, vue.isRef)(modelValue) && !(0, vue.isReadonly)(modelValue)) modelValue.value = val;
if (v.modelValue !== val) {
const toast = store.value.find((el) => el._self === _self);
if (toast) toast.modelValue = val;
}
};
if (previousIndex === -1) if (resolvedProps.value?.appendToast !== void 0 ? resolvedProps.value.appendToast : _isToastAppend.value) store.value.push(v);
else store.value.unshift(v);
else store.value.splice(previousIndex, 1, v);
}, {
deep: true,
immediate: true
});
(0, vue.onScopeDispose)(() => {
const toast = store.value.find((el) => el._self === _self);
if (toast) toast.promise.value.destroy?.();
}, true);
return promise.value;
};
const show = (obj = {}) => {
console.warn("[BootstrapVueNext] useToast: The `show` method is deprecated. Use the `create` method instead.");
return create(obj);
};
return {
_isToastAppend,
_isOrchestratorInstalled,
store,
create,
show
};
};
/**
* @deprecated use useToast() instead.
* @returns {ReturnType<typeof useToast>} The toast controller
*/
var useToastController = useToast;
//#endregion
exports.useToast = useToast;
exports.useToastController = useToastController;
//# sourceMappingURL=index.umd.js.map