UNPKG

vexip-ui

Version:

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

3 lines (2 loc) 3.29 kB
"use strict";var g=Object.defineProperty;var T=(r,t,e)=>t in r?g(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var n=(r,t,e)=>T(r,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("vue");require("./toast.vue.cjs");const _=require("@vexip-ui/hooks"),o=require("@vexip-ui/utils"),w=require("./props.cjs"),d=require("./toast.vue2.cjs"),y={success:{},warning:{},error:{},loading:{showMask:!0}};class c{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?o.toNumber(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 c(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&&u.render(null,this._container),o.destroyObject(this)}isDestroyed(){return!1}install(t,e={}){const{property:i,...a}=e;this.config(a),this._mountedApp=t,(i||!t.config.globalProperties.$toast)&&(t.config.globalProperties[i||"$toast"]=this)}transferTo(t){if(!o.isClient)return;const e=_.unrefElement(t);e&&(this._wrapper=e,this._instance?this._mountedEl&&this._wrapper.appendChild(this._mountedEl):this._getInstance())}_getInstance(){if(!this._instance&&o.isClient){if(!this._mountedApp)console.warn("[vexip-ui:Toast]: App missing, the plugin maybe not installed."),this._container=document.createElement("div"),this._innerApp=u.createApp(d),this._instance=this._innerApp.mount(this._container);else{const t=u.createVNode(d,null,null);this._container=document.createElement("div"),t.appContext=this._mountedApp._context,u.render(t,this._container),this._instance=_.proxyExposed(t)}this._mountedEl=this._container.firstElementChild,(this._wrapper||document.body).appendChild(this._mountedEl)}return this._instance}_open(t,e,i){if(!o.isClient)return o.noop;this._timer&&clearTimeout(this._timer);const a=typeof e=="string"?{content:e,duration:i}:e,m=t?y[t]??{}:{},h=a.onClose,f=()=>{if(this._timer&&clearTimeout(this._timer),typeof h=="function")return h()},l=this._getInstance(),s={...this.defaults,...m,...a,type:t??a.type,onClose:f};s.icon&&typeof s.icon!="function"&&(s.icon=u.markRaw(s.icon)),l.openToast(s);const p=typeof s.duration=="number"?s.duration:2e3;return p>=500&&(this._timer=setTimeout(()=>{l.closeToast()},p)),()=>{this._timer&&clearTimeout(this._timer),l.closeToast()}}}const A=new c;exports.toastProps=w.toastProps;exports.Toast=A;exports.ToastManager=c; //# sourceMappingURL=index.cjs.map