全栈小学生 0e47055ccb v1.0.0-beta.1
2023-04-15 17:12:49 +08:00

2 lines
4.5 KiB
JavaScript

import{v as z,a as Z,T as W,r as x}from"./error-492b6a5b.js";import{c as G}from"./index-2083be2e.js";import{i as K,C as J,T as H,E as P}from"./index-868cd458.js";import{b as Q,d as S,u as R,_ as X,z as F,A as Y}from"./plugin-vue_export-helper-edbdb6f8.js";import{E as N,b as ee}from"./focus-trap-bb1e8c7a.js";import{d as O,r as te,c as C,o as oe,b as m,m as E,p as _,L as $,f as h,n as v,u as i,h as A,U as ne,C as w,x as D,g as se,e as V,F as ie,q as j,a0 as I,j as ae}from"./runtime-core.esm-bundler-7c3fd514.js";import{c as le,i as re}from"./index-f02197a7.js";const q=["success","info","warning","error"],ce=Q({customClass:{type:String,default:""},dangerouslyUseHTMLString:{type:Boolean,default:!1},duration:{type:Number,default:4500},icon:{type:K},id:{type:String,default:""},message:{type:S([String,Object]),default:""},offset:{type:Number,default:0},onClick:{type:S(Function),default:()=>{}},onClose:{type:S(Function),required:!0},position:{type:String,values:["top-right","top-left","bottom-right","bottom-left"],default:"top-right"},showClose:{type:Boolean,default:!0},title:{type:String,default:""},type:{type:String,values:[...q,""],default:""},zIndex:{type:Number,default:0}}),fe={destroy:()=>!0},ue=["id"],pe=["textContent"],de={key:0},me=["innerHTML"],ve=O({name:"ElNotification"}),ye=O({...ve,props:ce,emits:fe,setup(e,{expose:s}){const o=e,n=R("notification"),{Close:f}=J,a=te(!1);let p;const d=C(()=>{const t=o.type;return t&&H[o.type]?n.m(t):""}),r=C(()=>o.type&&H[o.type]||o.icon),c=C(()=>o.position.endsWith("right")?"right":"left"),l=C(()=>o.position.startsWith("top")?"top":"bottom"),g=C(()=>({[l.value]:`${o.offset}px`,zIndex:o.zIndex}));function u(){o.duration>0&&({stop:p}=le(()=>{a.value&&b()},o.duration))}function L(){p==null||p()}function b(){a.value=!1}function U({code:t}){t===N.delete||t===N.backspace?L():t===N.esc?a.value&&b():u()}return oe(()=>{u(),a.value=!0}),G(document,"keydown",U),s({visible:a,close:b}),(t,T)=>(m(),E(W,{name:i(n).b("fade"),onBeforeLeave:t.onClose,onAfterLeave:T[1]||(T[1]=M=>t.$emit("destroy")),persisted:""},{default:_(()=>[$(h("div",{id:t.id,class:v([i(n).b(),t.customClass,i(c)]),style:A(i(g)),role:"alert",onMouseenter:L,onMouseleave:u,onClick:T[0]||(T[0]=(...M)=>t.onClick&&t.onClick(...M))},[i(r)?(m(),E(i(P),{key:0,class:v([i(n).e("icon"),i(d)])},{default:_(()=>[(m(),E(ne(i(r))))]),_:1},8,["class"])):w("v-if",!0),h("div",{class:v(i(n).e("group"))},[h("h2",{class:v(i(n).e("title")),textContent:D(t.title)},null,10,pe),$(h("div",{class:v(i(n).e("content")),style:A(t.title?void 0:{margin:0})},[se(t.$slots,"default",{},()=>[t.dangerouslyUseHTMLString?(m(),V(ie,{key:1},[w(" Caution here, message could've been compromised, never use user's input as message "),h("p",{innerHTML:t.message},null,8,me)],2112)):(m(),V("p",de,D(t.message),1))])],6),[[z,t.message]]),t.showClose?(m(),E(i(P),{key:0,class:v(i(n).e("closeBtn")),onClick:Z(b,["stop"])},{default:_(()=>[j(i(f))]),_:1},8,["class","onClick"])):w("v-if",!0)],2)],46,ue),[[z,a.value]])]),_:3},8,["name","onBeforeLeave"]))}});var ge=X(ye,[["__file","/home/runner/work/element-plus/element-plus/packages/components/notification/src/notification.vue"]]);const k={"top-left":[],"top-right":[],"bottom-left":[],"bottom-right":[]},B=16;let Ce=1;const y=function(e={},s=null){if(!re)return{close:()=>{}};(typeof e=="string"||I(e))&&(e={message:e});const o=e.position||"top-right";let n=e.offset||0;k[o].forEach(({vm:g})=>{var u;n+=(((u=g.el)==null?void 0:u.offsetHeight)||0)+B}),n+=B;const{nextZIndex:f}=ee(),a=`notification_${Ce++}`,p=e.onClose,d={zIndex:f(),...e,offset:n,id:a,onClose:()=>{he(a,o,p)}};let r=document.body;F(e.appendTo)?r=e.appendTo:ae(e.appendTo)&&(r=document.querySelector(e.appendTo)),F(r)||(r=document.body);const c=document.createElement("div"),l=j(ge,d,I(d.message)?{default:()=>d.message}:null);return l.appContext=s??y._context,l.props.onDestroy=()=>{x(null,c)},x(l,c),k[o].push({vm:l}),r.appendChild(c.firstElementChild),{close:()=>{l.component.exposed.visible.value=!1}}};q.forEach(e=>{y[e]=(s={})=>((typeof s=="string"||I(s))&&(s={message:s}),y({...s,type:e}))});function he(e,s,o){const n=k[s],f=n.findIndex(({vm:c})=>{var l;return((l=c.component)==null?void 0:l.props.id)===e});if(f===-1)return;const{vm:a}=n[f];if(!a)return;o==null||o(a);const p=a.el.offsetHeight,d=s.split("-")[0];n.splice(f,1);const r=n.length;if(!(r<1))for(let c=f;c<r;c++){const{el:l,component:g}=n[c].vm,u=Number.parseInt(l.style[d],10)-p-B;g.props.offset=u}}function be(){for(const e of Object.values(k))e.forEach(({vm:s})=>{s.component.exposed.visible.value=!1})}y.closeAll=be;y._context=null;const Ie=Y(y,"$notify");export{Ie as E};