UNPKG

@extclp/vexip-ui

Version:

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

125 lines (124 loc) 4.55 kB
var C = Object.defineProperty; var b = (o, e, t) => e in o ? C(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t; var i = (o, e, t) => b(o, typeof e != "symbol" ? e + "" : e, t); import { render as g, createApp as x, createVNode as I, markRaw as T } from "vue"; import "./message.vue.mjs"; import { unrefElement as L, proxyExposed as F } from "@vexip-ui/hooks"; import { toNumber as M, isNull as N, destroyObject as O, isClient as l, noop as $ } from "@vexip-ui/utils"; import y from "./message.vue2.mjs"; const E = ["top", "bottom"]; let j = 1; function k() { return `message-${j++}`; } class p { constructor(e = {}) { i(this, "name"); i(this, "defaults"); i(this, "open"); i(this, "primary"); i(this, "info"); i(this, "success"); i(this, "warning"); i(this, "error"); i(this, "_mountedApp"); i(this, "_instance"); i(this, "_innerApp"); i(this, "_container"); i(this, "_wrapper"); i(this, "_mountedEl"); e = { ...e, duration: e.duration ? M(e.duration) : 3e3 }, this._mountedApp = null, this._instance = null, this._innerApp = null, this._container = null, this._wrapper = null, this._mountedEl = null, this.name = "Message", this.defaults = {}, this.config(e), this.open = (t, n) => this._open(null, t, n), this.primary = (t, n) => this._open("primary", t, n), this.info = (t, n) => this._open("info", t, n), this.success = (t, n) => this._open("success", t, n), this.warning = (t, n) => this._open("warning", t, n), this.error = (t, n) => this._open("error", t, n); } judge(e, t, n, s) { e ? this.success(t, s) : this.error(n, s); } close(e) { var t; N(e) ? this.clear() : (t = this._getInstance()) == null || t.remove(e); } config({ placement: e, ...t }) { var n; e && ((n = this._getInstance()) == null || n.config({ placement: E.includes(e) ? e : E[0] })), this.defaults = { ...this.defaults, ...t }; } clone() { const e = new p(this.defaults); return e._mountedApp = this._mountedApp, e; } clear() { var e; (e = this._getInstance()) == null || e.clear(); } destroy() { var e, t; this._mountedEl && ((e = this._wrapper) == null || e.removeChild(this._mountedEl)), (t = this._innerApp) == null || t.unmount(), this._container && g(null, this._container), O(this); } isDestroyed() { return !1; } install(e, t = {}) { const { property: n, ...s } = t; this.config(s), this._mountedApp = e, (n || !e.config.globalProperties.$message) && (e.config.globalProperties[n || "$message"] = this); } transferTo(e) { if (!l) return; const t = L(e); t && (this._wrapper = t, this._instance ? this._mountedEl && this._wrapper.appendChild(this._mountedEl) : this._getInstance()); } _getInstance() { if (!this._instance && l) { if (!this._mountedApp) console.warn("[vexip-ui:Message]: App missing, the plugin maybe not installed."), this._container = document.createElement("div"), this._innerApp = x(y), this._instance = this._innerApp.mount(this._container); else { const e = I(y, null, null); this._container = document.createElement("div"), e.appContext = this._mountedApp._context, g(e, this._container), this._instance = F(e); } this._mountedEl = this._container.firstElementChild, (this._wrapper || document.body).appendChild(this._mountedEl); } return this._instance; } _open(e, t, n) { if (!l) return $; const s = typeof t == "string" ? { content: t, duration: n } : t, a = s.key ?? k(), c = this._getInstance(); let u; const h = s.onClose, A = () => { if (clearTimeout(u), typeof h == "function") return h(); }, m = s.onEnter, v = () => { if (s.liveOnEnter && clearTimeout(u), typeof m == "function") return m(); }, _ = s.onLeave, w = () => { if (s.liveOnEnter && (clearTimeout(u), f()), typeof _ == "function") return _(); }, r = { ...this.defaults, ...s, key: a, type: e ?? s.type, onClose: A, onEnter: v, onLeave: w }; r.icon && typeof r.icon != "function" && (r.icon = T(r.icon)), c.add(r), f(); function f() { const d = typeof r.duration == "number" ? r.duration : 3e3; d >= 500 && (u = setTimeout(() => { c.remove(a); }, d)); } return () => { clearTimeout(u), c.remove(a); }; } } const q = new p(); export { q as Message, p as MessageManager }; //# sourceMappingURL=index.mjs.map