全栈小学生 b4d1350cf3 update admin
2023-07-01 16:28:06 +08:00

2 lines
11 KiB
JavaScript

import{d as V,w as z,v as K,T as ve,r as le}from"./event-4977bef7.js";import{E as ge}from"./index-25c37860.js";import{E as ye}from"./index-4ce9333e.js";import{E as be,u as Ce,b as Ee,c as he}from"./index-cd1661d3.js";import{w as q,c as Be,P as A,g as we,G as Me,bL as ke,h as Te,r as h,a4 as Se,j as B,bK as x,aP as _,ag as Ie,o as Ae,$ as Re,aD as $e,_ as Le,aa as w,m as d,D as v,E as c,a1 as N,F as y,q as f,v as i,x as ee,n as U,am as P,T as M,L as I,t as Oe,K as j,i as Ve,z as re,aI as ie,ay as ne,A as ze,a6 as Pe,ac as se,bM as oe}from"./base-45eb5090.js";import{E as De,c as Fe,u as He,b as Ke}from"./focus-trap-318ae2e0.js";import{o as te}from"./el-tooltip-58212670.js";import{i as Ne}from"./index-9670e877.js";const Ue=(e,n)=>{let a;q(()=>e.value,r=>{var o,t;r?(a=document.activeElement,Be(n)&&((t=(o=n.value).focus)==null||t.call(o))):a.focus()})},G="_trap-focus-children",b=[],ae=e=>{if(b.length===0)return;const n=b[b.length-1][G];if(n.length>0&&e.code===De.tab){if(n.length===1){e.preventDefault(),document.activeElement!==n[0]&&n[0].focus();return}const a=e.shiftKey,r=e.target===n[0],o=e.target===n[n.length-1];r&&a&&(e.preventDefault(),n[n.length-1].focus()),o&&!a&&(e.preventDefault(),n[0].focus())}},je={beforeMount(e){e[G]=te(e),b.push(e),b.length<=1&&document.addEventListener("keydown",ae)},updated(e){A(()=>{e[G]=te(e)})},unmounted(){b.shift(),b.length===0&&document.removeEventListener("keydown",ae)}},qe=we({name:"ElMessageBox",directives:{TrapFocus:je},components:{ElButton:ge,ElFocusTrap:Fe,ElInput:ye,ElOverlay:be,ElIcon:Me,...ke},inheritAttrs:!1,props:{buttonSize:{type:String,validator:Ne},modal:{type:Boolean,default:!0},lockScroll:{type:Boolean,default:!0},showClose:{type:Boolean,default:!0},closeOnClickModal:{type:Boolean,default:!0},closeOnPressEscape:{type:Boolean,default:!0},closeOnHashChange:{type:Boolean,default:!0},center:Boolean,draggable:Boolean,roundButton:{default:!1,type:Boolean},container:{type:String,default:"body"},boxType:{type:String,default:""}},emits:["vanish","action"],setup(e,{emit:n}){const{t:a}=He(),r=Te("message-box"),o=h(!1),{nextZIndex:t}=Ke(),s=Se({autofocus:!0,beforeClose:null,callback:null,cancelButtonText:"",cancelButtonClass:"",confirmButtonText:"",confirmButtonClass:"",customClass:"",customStyle:{},dangerouslyUseHTMLString:!1,distinguishCancelAndClose:!1,icon:"",inputPattern:null,inputPlaceholder:"",inputType:"text",inputValue:null,inputValidator:null,inputErrorMessage:"",message:null,modalFade:!0,modalClass:"",showCancelButton:!1,showConfirmButton:!0,type:"",title:void 0,showInput:!1,action:"",confirmButtonLoading:!1,cancelButtonLoading:!1,confirmButtonDisabled:!1,editorErrorMessage:"",validateError:!1,zIndex:t()}),m=B(()=>{const l=s.type;return{[r.bm("icon",l)]:l&&x[l]}}),D=_(),$=_(),F=Ie(B(()=>e.buttonSize),{prop:!0,form:!0,formItem:!0}),H=B(()=>s.icon||x[s.type]||""),u=B(()=>!!s.message),C=h(),X=h(),T=h(),L=h(),Z=h(),ue=B(()=>s.confirmButtonClass);q(()=>s.inputValue,async l=>{await A(),e.boxType==="prompt"&&l!==null&&J()},{immediate:!0}),q(()=>o.value,l=>{var p,E;l&&(e.boxType!=="prompt"&&(s.autofocus?T.value=(E=(p=Z.value)==null?void 0:p.$el)!=null?E:C.value:T.value=C.value),s.zIndex=t()),e.boxType==="prompt"&&(l?A().then(()=>{var Y;L.value&&L.value.$el&&(s.autofocus?T.value=(Y=me())!=null?Y:C.value:T.value=C.value)}):(s.editorErrorMessage="",s.validateError=!1))});const de=B(()=>e.draggable);Ce(C,X,de),Ae(async()=>{await A(),e.closeOnHashChange&&window.addEventListener("hashchange",S)}),Re(()=>{e.closeOnHashChange&&window.removeEventListener("hashchange",S)});function S(){o.value&&(o.value=!1,A(()=>{s.action&&n("action",s.action)}))}const W=()=>{e.closeOnClickModal&&O(s.distinguishCancelAndClose?"close":"cancel")},ce=he(W),fe=l=>{if(s.inputType!=="textarea")return l.preventDefault(),O("confirm")},O=l=>{var p;e.boxType==="prompt"&&l==="confirm"&&!J()||(s.action=l,s.beforeClose?(p=s.beforeClose)==null||p.call(s,l,s,S):S())},J=()=>{if(e.boxType==="prompt"){const l=s.inputPattern;if(l&&!l.test(s.inputValue||""))return s.editorErrorMessage=s.inputErrorMessage||a("el.messagebox.error"),s.validateError=!0,!1;const p=s.inputValidator;if(typeof p=="function"){const E=p(s.inputValue);if(E===!1)return s.editorErrorMessage=s.inputErrorMessage||a("el.messagebox.error"),s.validateError=!0,!1;if(typeof E=="string")return s.editorErrorMessage=E,s.validateError=!0,!1}}return s.editorErrorMessage="",s.validateError=!1,!0},me=()=>{const l=L.value.$refs;return l.input||l.textarea},Q=()=>{O("close")},pe=()=>{e.closeOnPressEscape&&Q()};return e.lockScroll&&Ee(o),Ue(o),{...$e(s),ns:r,overlayEvent:ce,visible:o,hasMessage:u,typeClass:m,contentId:D,inputId:$,btnSize:F,iconComponent:H,confirmButtonClasses:ue,rootRef:C,focusStartRef:T,headerRef:X,inputRef:L,confirmRef:Z,doClose:S,handleClose:Q,onCloseRequested:pe,handleWrapperClick:W,handleInputEnter:fe,handleAction:O,t:a}}}),Ge=["aria-label","aria-describedby"],Xe=["aria-label"],Ze=["id"];function We(e,n,a,r,o,t){const s=w("el-icon"),m=w("close"),D=w("el-input"),$=w("el-button"),F=w("el-focus-trap"),H=w("el-overlay");return d(),v(ve,{name:"fade-in-linear",onAfterLeave:n[11]||(n[11]=u=>e.$emit("vanish")),persisted:""},{default:c(()=>[N(y(H,{"z-index":e.zIndex,"overlay-class":[e.ns.is("message-box"),e.modalClass],mask:e.modal},{default:c(()=>[f("div",{role:"dialog","aria-label":e.title,"aria-modal":"true","aria-describedby":e.showInput?void 0:e.contentId,class:i(`${e.ns.namespace.value}-overlay-message-box`),onClick:n[8]||(n[8]=(...u)=>e.overlayEvent.onClick&&e.overlayEvent.onClick(...u)),onMousedown:n[9]||(n[9]=(...u)=>e.overlayEvent.onMousedown&&e.overlayEvent.onMousedown(...u)),onMouseup:n[10]||(n[10]=(...u)=>e.overlayEvent.onMouseup&&e.overlayEvent.onMouseup(...u))},[y(F,{loop:"",trapped:e.visible,"focus-trap-el":e.rootRef,"focus-start-el":e.focusStartRef,onReleaseRequested:e.onCloseRequested},{default:c(()=>[f("div",{ref:"rootRef",class:i([e.ns.b(),e.customClass,e.ns.is("draggable",e.draggable),{[e.ns.m("center")]:e.center}]),style:ee(e.customStyle),tabindex:"-1",onClick:n[7]||(n[7]=V(()=>{},["stop"]))},[e.title!==null&&e.title!==void 0?(d(),U("div",{key:0,ref:"headerRef",class:i(e.ns.e("header"))},[f("div",{class:i(e.ns.e("title"))},[e.iconComponent&&e.center?(d(),v(s,{key:0,class:i([e.ns.e("status"),e.typeClass])},{default:c(()=>[(d(),v(P(e.iconComponent)))]),_:1},8,["class"])):M("v-if",!0),f("span",null,I(e.title),1)],2),e.showClose?(d(),U("button",{key:0,type:"button",class:i(e.ns.e("headerbtn")),"aria-label":e.t("el.messagebox.close"),onClick:n[0]||(n[0]=u=>e.handleAction(e.distinguishCancelAndClose?"close":"cancel")),onKeydown:n[1]||(n[1]=z(V(u=>e.handleAction(e.distinguishCancelAndClose?"close":"cancel"),["prevent"]),["enter"]))},[y(s,{class:i(e.ns.e("close"))},{default:c(()=>[y(m)]),_:1},8,["class"])],42,Xe)):M("v-if",!0)],2)):M("v-if",!0),f("div",{id:e.contentId,class:i(e.ns.e("content"))},[f("div",{class:i(e.ns.e("container"))},[e.iconComponent&&!e.center&&e.hasMessage?(d(),v(s,{key:0,class:i([e.ns.e("status"),e.typeClass])},{default:c(()=>[(d(),v(P(e.iconComponent)))]),_:1},8,["class"])):M("v-if",!0),e.hasMessage?(d(),U("div",{key:1,class:i(e.ns.e("message"))},[Oe(e.$slots,"default",{},()=>[e.dangerouslyUseHTMLString?(d(),v(P(e.showInput?"label":"p"),{key:1,for:e.showInput?e.inputId:void 0,innerHTML:e.message},null,8,["for","innerHTML"])):(d(),v(P(e.showInput?"label":"p"),{key:0,for:e.showInput?e.inputId:void 0},{default:c(()=>[j(I(e.dangerouslyUseHTMLString?"":e.message),1)]),_:1},8,["for"]))])],2)):M("v-if",!0)],2),N(f("div",{class:i(e.ns.e("input"))},[y(D,{id:e.inputId,ref:"inputRef",modelValue:e.inputValue,"onUpdate:modelValue":n[2]||(n[2]=u=>e.inputValue=u),type:e.inputType,placeholder:e.inputPlaceholder,"aria-invalid":e.validateError,class:i({invalid:e.validateError}),onKeydown:z(e.handleInputEnter,["enter"])},null,8,["id","modelValue","type","placeholder","aria-invalid","class","onKeydown"]),f("div",{class:i(e.ns.e("errormsg")),style:ee({visibility:e.editorErrorMessage?"visible":"hidden"})},I(e.editorErrorMessage),7)],2),[[K,e.showInput]])],10,Ze),f("div",{class:i(e.ns.e("btns"))},[e.showCancelButton?(d(),v($,{key:0,loading:e.cancelButtonLoading,class:i([e.cancelButtonClass]),round:e.roundButton,size:e.btnSize,onClick:n[3]||(n[3]=u=>e.handleAction("cancel")),onKeydown:n[4]||(n[4]=z(V(u=>e.handleAction("cancel"),["prevent"]),["enter"]))},{default:c(()=>[j(I(e.cancelButtonText||e.t("el.messagebox.cancel")),1)]),_:1},8,["loading","class","round","size"])):M("v-if",!0),N(y($,{ref:"confirmRef",type:"primary",loading:e.confirmButtonLoading,class:i([e.confirmButtonClasses]),round:e.roundButton,disabled:e.confirmButtonDisabled,size:e.btnSize,onClick:n[5]||(n[5]=u=>e.handleAction("confirm")),onKeydown:n[6]||(n[6]=z(V(u=>e.handleAction("confirm"),["prevent"]),["enter"]))},{default:c(()=>[j(I(e.confirmButtonText||e.t("el.messagebox.confirm")),1)]),_:1},8,["loading","class","round","disabled","size"]),[[K,e.showConfirmButton]])],2)],6)]),_:3},8,["trapped","focus-trap-el","focus-start-el","onReleaseRequested"])],42,Ge)]),_:3},8,["z-index","overlay-class","mask"]),[[K,e.visible]])]),_:3})}var Je=Le(qe,[["render",We],["__file","/home/runner/work/element-plus/element-plus/packages/components/message-box/src/index.vue"]]);const R=new Map,Qe=e=>{let n=document.body;return e.appendTo&&(re(e.appendTo)&&(n=document.querySelector(e.appendTo)),oe(e.appendTo)&&(n=e.appendTo),oe(n)||(n=document.body)),n},Ye=(e,n,a=null)=>{const r=y(Je,e,se(e.message)||ie(e.message)?{default:se(e.message)?e.message:()=>e.message}:null);return r.appContext=a,le(r,n),Qe(e).appendChild(n.firstElementChild),r.component},xe=()=>document.createElement("div"),_e=(e,n)=>{const a=xe();e.onVanish=()=>{le(null,a),R.delete(o)},e.onAction=t=>{const s=R.get(o);let m;e.showInput?m={value:o.inputValue,action:t}:m=t,e.callback?e.callback(m,r.proxy):t==="cancel"||t==="close"?e.distinguishCancelAndClose&&t!=="cancel"?s.reject("close"):s.reject("cancel"):s.resolve(m)};const r=Ye(e,a,n),o=r.proxy;for(const t in e)ne(e,t)&&!ne(o.$props,t)&&(o[t]=e[t]);return o.visible=!0,o};function k(e,n=null){if(!Ve)return Promise.reject();let a;return re(e)||ie(e)?e={message:e}:a=e.callback,new Promise((r,o)=>{const t=_e(e,n??k._context);R.set(t,{options:e,callback:a,resolve:r,reject:o})})}const en=["alert","confirm","prompt"],nn={alert:{closeOnPressEscape:!1,closeOnClickModal:!1},confirm:{showCancelButton:!0},prompt:{showCancelButton:!0,showInput:!0}};en.forEach(e=>{k[e]=sn(e)});function sn(e){return(n,a,r,o)=>{let t="";return ze(a)?(r=a,t=""):Pe(a)?t="":t=a,k(Object.assign({title:t,message:n,type:"",...nn[e]},r,{boxType:e}),o)}}k.close=()=>{R.forEach((e,n)=>{n.doClose()}),R.clear()};k._context=null;const g=k;g.install=e=>{g._context=e._context,e.config.globalProperties.$msgbox=g,e.config.globalProperties.$messageBox=g,e.config.globalProperties.$alert=g.alert,e.config.globalProperties.$confirm=g.confirm,e.config.globalProperties.$prompt=g.prompt};const fn=g;export{fn as E};