UNPKG

vexip-ui

Version:

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

129 lines (128 loc) 4.92 kB
var C = Object.defineProperty; var b = (c, e, t) => e in c ? C(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t; var i = (c, e, t) => b(c, typeof e != "symbol" ? e + "" : e, t); import { render as g, createApp as x, createVNode as I, markRaw as R } from "vue"; import "./message.vue.mjs"; import { unrefElement as T, proxyExposed as L } from "@vexip-ui/hooks"; import { toNumber as F, isNull as M, destroyObject as N, isClient as u, 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 h { 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"); i(this, "_installed"); i(this, "_configRecord"); e = { ...e, duration: e.duration ? F(e.duration) : 3e3 }, this._mountedApp = null, this._instance = null, this._innerApp = null, this._container = null, this._wrapper = null, this._mountedEl = null, this._installed = !1, this._configRecord = 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; M(e) ? this.clear() : (t = this._getInstance()) == null || t.remove(e); } config({ placement: e, startOffset: t, itemGap: n, ...s }) { if (this._configRecord = { placement: e, startOffset: t, itemGap: n }, this.defaults = { ...this.defaults, ...s }, this._installed) { const o = this._getInstance(); o && (e && o.config({ placement: E.includes(e) ? e : E[0] }), o.config({ startOffset: t, itemGap: n })); } } clone() { const e = new h(this.defaults); return e._mountedApp = this._mountedApp, e._configRecord = this._configRecord, e._installed = this._installed, 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), N(this); } isDestroyed() { return !1; } install(e, t = {}) { const { property: n, ...s } = t; this._mountedApp = e, this._installed = !0, this.config(s), (n || !e.config.globalProperties.$message) && (e.config.globalProperties[n || "$message"] = this); } transferTo(e) { if (!u) return; const t = T(e); t && (this._wrapper = t, this._instance ? this._mountedEl && this._wrapper.appendChild(this._mountedEl) : this._getInstance()); } _getInstance() { if (!this._instance && u) { 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 = L(e); } this._mountedEl = this._container.firstElementChild, (this._wrapper || document.body).appendChild(this._mountedEl); } return this._instance; } _open(e, t, n) { if (!u) return $; const s = typeof t == "string" ? { content: t, duration: n } : t, o = s.key ?? k(), a = this._getInstance(); let l; const p = s.onClose, A = () => { if (clearTimeout(l), typeof p == "function") return p(); }, _ = s.onEnter, v = () => { if (s.liveOnEnter && clearTimeout(l), typeof _ == "function") return _(); }, d = s.onLeave, w = () => { if (s.liveOnEnter && (clearTimeout(l), f()), typeof d == "function") return d(); }, r = { ...this.defaults, ...s, key: o, type: e ?? s.type, onClose: A, onEnter: v, onLeave: w }; r.icon && typeof r.icon != "function" && (r.icon = R(r.icon)), a.add(r), f(); function f() { const m = typeof r.duration == "number" ? r.duration : 3e3; m >= 500 && (l = setTimeout(() => { a.remove(o); }, m)); } return () => { clearTimeout(l), a.remove(o); }; } } const q = new h(); export { q as Message, h as MessageManager }; //# sourceMappingURL=index.mjs.map