vue-m-message
Version:
A message plugin base on Vue
2 lines (1 loc) • 10.2 kB
JavaScript
var Y=Object.defineProperty,Z=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var E=(n,e,i)=>e in n?Y(n,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[e]=i,m=(n,e)=>{for(var i in e||(e={}))x.call(e,i)&&E(n,i,e[i]);if(b)for(var i of b(e))v.call(e,i)&&E(n,i,e[i]);return n},h=(n,e)=>Z(n,_(e));(function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n.VueMMessage={},n.Vue))})(this,function(n,e){"use strict";const i={},z=function(t,s){i[t]=s},f=e.defineComponent({name:"Icon",props:{name:String,color:String},computed:{svg(){if(!!this.name)return i[this.name]}},render(t){const s=this.svg;if(!s)return console.warn(`The name of '${this.name}' could not be found.`),e.createVNode("span",{class:"m-svg-icon"},null);const a={color:this.color?this.color:s.fill?s.fill:null};return e.createVNode("span",{class:["m-svg-icon","m-svg-icon--"+this.name]},[e.createVNode("svg",{version:"1.1",xmlns:"http://www.w3.org/2000/svg",viewBox:s.viewBox,style:a,class:s.class},[s.defs&&e.createVNode("defs",{innerHTML:s.defs},null),s.path&&e.createVNode("path",{fill:"currentColor",d:s.path},null),s.html&&e.createVNode("g",{innerHTML:s.html},null),this.$slots.default])])}});f.add=z;const w={name:"error",fill:"#F56C6C",viewBox:"0 0 1024 1024",path:"M512,952C269,952,72,755,72,512S269,72,512,72s440,197,440,440S755,952,512,952z M579.7,512l101.6-101.6 c18.7-18.7,18.7-49,0-67.7c-18.7-18.7-49-18.7-67.7,0l0,0L512,444.3L410.4,342.7c-18.7-18.7-49-18.7-67.7,0s-18.7,49,0,67.7 L444.3,512L342.7,613.6c-18.7,18.7-18.7,49,0,67.7c18.7,18.7,49,18.7,67.7,0L512,579.7l101.6,101.6c18.7,18.7,49,18.7,67.7,0 c18.7-18.7,18.7-49,0-67.7L579.7,512z"},N={name:"info",fill:"#1CADF2",viewBox:"0 0 1024 1024",path:"M512,72C269,72,72,269,72,512s197,440,440,440s440-197,440-440S755,72,512,72z M581,673.9 c-33.2,49.9-67,88.3-123.8,88.3c-38.8-6.3-54.7-34.1-46.3-62.4L484,457.6c1.8-5.9-1.2-12.3-6.6-14.2c-5.4-1.9-15.9,5.1-25.1,15.1 l-44.2,53.2c-1.2-8.9-0.1-23.7-0.1-29.6c33.2-49.9,87.8-89.2,124.8-89.2c35.2,3.6,51.8,31.7,45.7,62.6l-73.6,243.3 c-1,5.5,1.9,11.1,6.9,12.8c5.4,1.9,16.8-5.1,26-15.1l44.2-53.1C583,652.3,581,667.9,581,673.9z M571.2,357.6 c-28,0-50.6-20.4-50.6-50.4c0-30,22.7-50.3,50.6-50.3c28,0,50.6,20.4,50.6,50.3C621.8,337.3,599.1,357.6,571.2,357.6z"},M={name:"success",fill:"#17B77E",viewBox:"0 0 1024 1024",path:"M512,72C269,72,72,269,72,512s197,440,440,440s440-197,440-440S755,72,512,72L512,72z M758.9,374 c-48.5,48.6-81.2,76.9-172.3,186.8c-52.6,63.4-102.3,131.5-102.7,132L462.1,720c-4.6,6.1-13.5,6.8-19.1,1.6L267.9,558.9 c-17.8-16.5-18.8-44.4-2.3-62.2s44.4-18.8,62.2-2.3l104.9,97.5c5.5,5.1,14.1,4.5,18.9-1.3c16.2-20.1,38.4-44.5,62.4-68.6 c90.2-90.9,145.6-139.7,175.2-161.3c36-26.2,77.3-48.6,87.3-36.2C792,343.9,782.5,350.3,758.9,374L758.9,374z"},S={name:"warning",fill:"#FFC603",viewBox:"0 0 1024 1024",path:"M512,952C269,952,72,755,72,512S269,72,512,72s440,197,440,440S755,952,512,952z M510,770.8 c30.4,0,55-24.6,55-55s-24.6-55-55-55s-55,24.6-55,55S479.6,770.8,510,770.8z M509.8,255.3c-39.3,0-71.2,31.9-71.2,71.2 c0,3.1,0.2,6.2,0.6,9.3L472.4,588c2.5,19.3,18.9,33.7,38.4,33.7c19.4,0,35.8-14.4,38.2-33.7l31.8-252.2c5-39.2-22.8-75-62-79.9 C515.9,255.5,512.8,255.3,509.8,255.3z"},T={name:"loading",viewBox:"0 0 50 50",html:'<g stroke="#f2f2f2" stroke-width="3.5" stroke-linecap="round" fill="none"><circle cx="25" cy="25" r="20" class="m-loading-icon-bg-path"></circle><circle cx="25" cy="25" r="20" stroke="#20a0ff" stroke-dasharray="90, 150" stroke-dashoffset="0" class="m-loading-icon-active-path"><animate attributeName="stroke-dasharray" dur="1.5s" values="1,200;90,150;90,150" repeatCount="indefinite"/><animate attributeName="stroke-dashoffset" dur="1.5s" values="0;-40px;-120px" repeatCount="indefinite"/><animateTransform attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="2s" repeatCount="indefinite"/></circle></g>'};f.add(w.name,w),f.add(N.name,N),f.add(M.name,M),f.add(S.name,S),f.add(T.name,T);var $=(t,s)=>{const a=t.__vccOpts||t;for(const[c,d]of s)a[c]=d;return a};function O(t,s){const a=e.ref(0);return a.value=window.setTimeout(t,s),{stop(){window.clearTimeout(a.value)}}}const H=e.defineComponent({components:{Icon:f},name:"m-message",emits:["close","destroy","collapsed"],props:{id:String,type:{type:String,default:"info"},title:String,message:String,iconURL:String,duration:{type:Number,default:3e3},isCollapsed:Boolean,collapsable:Boolean,supportHTML:Boolean,width:String,className:String,wrapperClassName:String,closable:Boolean,stopTimerOnHover:{type:Boolean,default:!0}},setup(t,{expose:s,emit:a}){const c=e.reactive({visible:!0,collapsed:t.isCollapsed,timer:null});let d;const g=()=>{t.duration<0||({stop:d}=O(()=>{r()},t.duration))},o=()=>{d==null||d()},r=()=>{c.visible=!1},p=()=>{c.collapsed=!c.collapsed,a("collapsed",c.collapsed)},u=()=>{c.visible=!1},k=()=>{t.stopTimerOnHover&&o()},C=()=>{t.stopTimerOnHover&&g()};return e.onBeforeMount(()=>{o()}),e.onMounted(()=>{g()}),s({close:r}),{state:c,handleClearTimer:k,handleStartTimer:C,triggerCollapse:p,handleClose:u}}}),I=["id"],D={key:0,class:"m-message-icons"},F=["src"],R={class:"m-message-content"},U={key:0,class:"m-message--title"},j=["innerHTML"],A={key:0,class:"m-message--description"},P={class:"m-message--control"},q=[e.createElementVNode("svg",{viewBox:"0 0 35 35",width:"20",height:"20",version:"1.1",fill:"currentColor"},[e.createElementVNode("path",{d:"M9.4,13.9c-0.2,0.2-0.2,0.6,0,0.8l8.1,8.1l0,0l0,0l8.1-8.1c0.2-0.2,0.2-0.6,0-0.8l-1.3-1.3 c-0.2-0.2-0.6-0.2-0.8,0l-5.5,5.5c-0.2,0.2-0.6,0.2-0.8,0l-5.5-5.5c-0.2-0.2-0.6-0.2-0.8,0L9.4,13.9z"})],-1)],K=[e.createElementVNode("svg",{viewBox:"0 0 35 35",width:"20",height:"20",version:"1.1",fill:"currentColor"},[e.createElementVNode("path",{d:"M19.5,17.5l5.1,5.1l-2,2l-5.1-5.1l-5.1,5.1l-2-2l5.1-5.1l-5.1-5.1l2-2l5.1,5.1l5.1-5.1l2,2L19.5,17.5z"})],-1)];function G(t,s,a,c,d,g){const o=e.resolveComponent("icon");return e.openBlock(),e.createBlock(e.Transition,{name:"m-message-fade",appear:"",mode:"in-out",onBeforeLeave:s[4]||(s[4]=r=>t.$emit("close")),onAfterLeave:s[5]||(s[5]=r=>t.$emit("destroy"))},{default:e.withCtx(()=>[t.state.visible?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["m-message-wrapper",t.wrapperClassName]),id:t.id,style:e.normalizeStyle({width:t.width})},[e.createElementVNode("div",{class:e.normalizeClass(["m-message",t.className]),onMouseenter:s[2]||(s[2]=(...r)=>t.handleClearTimer&&t.handleClearTimer(...r)),onMouseleave:s[3]||(s[3]=(...r)=>t.handleStartTimer&&t.handleStartTimer(...r))},[t.iconURL||t.type?(e.openBlock(),e.createElementBlock("div",D,[t.iconURL?(e.openBlock(),e.createElementBlock("img",{key:0,src:t.iconURL,class:"m-message--icon"},null,8,F)):t.type?(e.openBlock(),e.createBlock(o,{key:1,name:t.type,class:"m-message--icon"},null,8,["name"])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),e.createElementVNode("div",R,[t.title||t.$slots.title?(e.openBlock(),e.createElementBlock("div",U,[e.renderSlot(t.$slots,"title",{},()=>[e.createTextVNode(e.toDisplayString(t.title),1)])])):e.createCommentVNode("",!0),t.supportHTML&&t.message?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[t.state.collapsed?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",{key:0,class:"m-message--description",innerHTML:t.message},null,8,j))],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[t.state.collapsed?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",A,[e.renderSlot(t.$slots,"default",{},()=>[e.createTextVNode(e.toDisplayString(t.message),1)])]))],64))]),e.createElementVNode("div",P,[t.collapsable&&(t.title||t.$slots.title)?(e.openBlock(),e.createElementBlock("button",{key:0,class:e.normalizeClass(["m-message--button m-message--arrow-down",{"is-collapsed":t.state.collapsed}]),onClick:s[0]||(s[0]=(...r)=>t.triggerCollapse&&t.triggerCollapse(...r))},q,2)):e.createCommentVNode("",!0),t.closable?(e.openBlock(),e.createElementBlock("button",{key:1,class:"m-message--button m-message--close",onClick:s[1]||(s[1]=(...r)=>t.handleClose&&t.handleClose(...r))},K)):e.createCommentVNode("",!0)])],34)],14,I)):e.createCommentVNode("",!0)]),_:3})}var J=$(H,[["render",G]]);const y=[];let Q=0;const B={};let V={};const W={stopTimerOnHover:!0,duration:3e3},l=t=>{const s="m-message-"+Q++,a=h(m(m(m({},W),V),t),{id:s});delete a.hasMask,delete a.position,delete a.zIndex;const c=t.position||"top-center",d=t.hasMask||!1,g=c+(d?"-mask":"");let o=B[g];o?o.count++:(o=B[g]={el:document.createElement("div"),count:1},o.el.className=["m-message-container","is-"+c,d?"has-mask":""].filter(function(C){return!!C}).join(" "),document.body.appendChild(o.el)),t.zIndex&&(o.el.style.zIndex=String(t.zIndex));let r=null;e.isVNode(t.message)?(r={default:()=>t.message},a.message=""):typeof t.message=="function"&&(r={default:t.message},a.message="");const p=e.createVNode(J,a,r),u=document.createElement("div");p.appContext=t.ctx||l._context||null,p.props.onClose=t.onClose,p.props.onDestroy=()=>{o.count--,o.count===0&&(delete B[g],o.el.remove()),e.render(null,u)},e.render(p,u),c.indexOf("bottom")===0&&o.el.firstChild?o.el.insertBefore(u.firstElementChild,o.el.firstChild):o.el.appendChild(u.firstElementChild);const k={id:s,close(){var C,L;(L=(C=p==null?void 0:p.component)==null?void 0:C.exposed)==null||L.close()}};return y.push(k),k};l.success=(t,s)=>l(h(m({},s),{type:"success",message:t})),l.info=(t,s)=>l(h(m({},s),{type:"info",message:t})),l.warning=(t,s)=>l(h(m({},s),{type:"warning",message:t})),l.error=(t,s)=>l(h(m({},s),{type:"error",message:t})),l.loading=(t,s)=>l(h(m({},s),{type:"loading",message:t})),l.closeAll=function(){for(let t=y.length-1;t>=0;t--)y[t].close()},l.setDefault=t=>{V=m({},t)};var se="",X=((t,s)=>(t.install=s,t))(l,function(t,s={}){l._context=t._context,t.config.globalProperties["$"+(s.name||"mmessage")]=l,s.defaultOptions&&l.setDefault(s.defaultOptions)});n.default=X,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});