UNPKG

@extclp/vexip-ui

Version:

A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good

108 lines (107 loc) 4.08 kB
var f = Object.defineProperty; var g = (o, t, e) => t in o ? f(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e; var n = (o, t, e) => g(o, typeof t != "symbol" ? t + "" : t, e); import { render as p, createApp as w, createVNode as A, markRaw as E } from "vue"; import "./toast.vue.mjs"; import { unrefElement as T, proxyExposed as y } from "@vexip-ui/hooks"; import { toNumber as C, destroyObject as b, isClient as c, noop as v } from "@vexip-ui/utils"; import { toastProps as M } from "./props.mjs"; import _ from "./toast.vue2.mjs"; const x = { success: {}, warning: {}, error: {}, loading: { showMask: !0 } }; class l { constructor(t = {}) { n(this, "name"); n(this, "defaults"); n(this, "open"); n(this, "success"); n(this, "warning"); n(this, "error"); n(this, "loading"); n(this, "_mountedApp"); n(this, "_instance"); n(this, "_innerApp"); n(this, "_container"); n(this, "_timer"); n(this, "_wrapper"); n(this, "_mountedEl"); t = { ...t, duration: t.duration ? C(t.duration) : 2e3 }, this._mountedApp = null, this._instance = null, this._innerApp = null, this._container = null, this._timer = null, this._wrapper = null, this._mountedEl = null, this.name = "Toast", this.defaults = {}, this.config(t), this.open = (e, i) => this._open(null, e, i), this.success = (e, i) => this._open("success", e, i), this.warning = (e, i) => this._open("warning", e, i), this.error = (e, i) => this._open("error", e, i), this.loading = (e, i) => this._open("loading", e, i); } close() { var t; this._timer && clearTimeout(this._timer), (t = this._getInstance()) == null || t.closeToast(); } config(t) { this.defaults = { ...this.defaults, ...t }; } clone() { const t = new l(this.defaults); return t._mountedApp = this._mountedApp, t; } destroy() { var t, e; this._mountedEl && ((t = this._wrapper) == null || t.removeChild(this._mountedEl)), (e = this._innerApp) == null || e.unmount(), this._container && p(null, this._container), b(this); } isDestroyed() { return !1; } install(t, e = {}) { const { property: i, ...r } = e; this.config(r), this._mountedApp = t, (i || !t.config.globalProperties.$toast) && (t.config.globalProperties[i || "$toast"] = this); } transferTo(t) { if (!c) return; const e = T(t); e && (this._wrapper = e, this._instance ? this._mountedEl && this._wrapper.appendChild(this._mountedEl) : this._getInstance()); } _getInstance() { if (!this._instance && c) { if (!this._mountedApp) console.warn("[vexip-ui:Toast]: App missing, the plugin maybe not installed."), this._container = document.createElement("div"), this._innerApp = w(_), this._instance = this._innerApp.mount(this._container); else { const t = A(_, null, null); this._container = document.createElement("div"), t.appContext = this._mountedApp._context, p(t, this._container), this._instance = y(t); } this._mountedEl = this._container.firstElementChild, (this._wrapper || document.body).appendChild(this._mountedEl); } return this._instance; } _open(t, e, i) { if (!c) return v; this._timer && clearTimeout(this._timer); const r = typeof e == "string" ? { content: e, duration: i } : e, m = t ? x[t] ?? {} : {}, u = r.onClose, d = () => { if (this._timer && clearTimeout(this._timer), typeof u == "function") return u(); }, a = this._getInstance(), s = { ...this.defaults, ...m, ...r, type: t ?? r.type, onClose: d }; s.icon && typeof s.icon != "function" && (s.icon = E(s.icon)), a.openToast(s); const h = typeof s.duration == "number" ? s.duration : 2e3; return h >= 500 && (this._timer = setTimeout(() => { a.closeToast(); }, h)), () => { this._timer && clearTimeout(this._timer), a.closeToast(); }; } } const j = new l(); export { j as Toast, l as ToastManager, M as toastProps }; //# sourceMappingURL=index.mjs.map