vue3-confirm-dialog
Version:
Simple Confirm Dialog verification plugin with Vue 3.
2 lines (1 loc) • 4.34 kB
JavaScript
(function(e,a){typeof exports=="object"&&typeof module<"u"?module.exports=a(require("vue")):typeof define=="function"&&define.amd?define(["vue"],a):(e=typeof globalThis<"u"?globalThis:e||self,e["vue3-confirm-dialog"]=a(e.Vue))})(this,function(e){"use strict";class a{constructor(){this.events={}}on(o,n){this.events[o]=this.events[o]||[],this.events[o].push(n)}close(o,n){if(this.events[o]){for(var i=0;i<this.events[o].length;i++)if(this.events[o][i]===n){this.events[o].splice(i,1);break}}}emit(o,n){this.events[o]&&this.events[o].forEach(function(i){i(n)})}}const r=new a,C="",c=(t,o)=>{const n=t.__vccOpts||t;for(const[i,l]of o)n[i]=l;return n},d={name:"Vue3ConfirmDialog",directives:{focus:{mounted:t=>t.focus()}},data(){return{isShow:!1,password:null,dialog:{auth:!1,title:"",message:"",button:{}},params:{}}},methods:{resetState(){this.password=null,this.dialog={auth:!1,title:"",message:"",button:{},callback:()=>{}}},handleClickButton({target:t},o){t.id!="vueConfirm"&&(o&&this.dialog.auth&&!this.password||(this.isShow=!1,this.params.callback&&this.params.callback(o,this.password)))},handleClickOverlay({target:t}){t.id=="vueConfirm"&&(this.isShow=!1,this.params.callback&&this.params.callback(!1,this.password))},handleKeyUp({keyCode:t}){t==27&&this.handleClickOverlay({target:{id:"vueConfirm"}}),t==13&&this.handleClickButton({target:{id:""}},!0)},open(t){this.resetState(),this.params=t,this.isShow=!0,Object.entries(t).forEach(o=>{typeof o[1]==typeof this.dialog[o[0]]&&(this.dialog[o[0]]=o[1])})}},mounted(){r.on("open",t=>{this.open(t)}),r.on("close",()=>{this.handleClickOverlay({target:{id:"vueConfirm"}})})}},f={key:0,ref:"vueConfirmDialog",class:"vc-container"},h={class:"vc-text-grid"},p=["innerHTML"],u=["innerHTML"],m={key:2},k=["disabled"];function g(t,o,n,i,l,E){const b=e.resolveDirective("focus");return e.openBlock(),e.createBlock(e.Transition,{name:"fade"},{default:e.withCtx(()=>[t.isShow?(e.openBlock(),e.createElementBlock("div",{key:0,onClick:o[4]||(o[4]=(...s)=>t.handleClickOverlay&&t.handleClickOverlay(...s)),class:"vc-overlay",id:"vueConfirm"},[e.createVNode(e.Transition,{name:"zoom"},{default:e.withCtx(()=>[t.isShow?(e.openBlock(),e.createElementBlock("div",f,[e.createElementVNode("span",h,[t.dialog.title?(e.openBlock(),e.createElementBlock("h4",{key:0,class:"vc-title",innerHTML:t.dialog.title},null,8,p)):e.createCommentVNode("",!0),t.dialog.message?(e.openBlock(),e.createElementBlock("p",{key:1,class:"vc-text",innerHTML:t.dialog.message},null,8,u)):e.createCommentVNode("",!0),t.dialog.auth?(e.openBlock(),e.createElementBlock("span",m,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":o[0]||(o[0]=s=>t.password=s),onKeyup:o[1]||(o[1]=e.withKeys(s=>t.handleClickButton(s,!0),["13"])),class:"vc-input",type:"password",name:"vc-password",placeholder:"Password",autocomplete:"off"},null,544),[[b],[e.vModelText,t.password]])])):e.createCommentVNode("",!0)]),e.createElementVNode("div",{class:e.normalizeClass(["vc-btn-grid",{isMono:!t.dialog.button.no||!t.dialog.button.yes}])},[t.dialog.button.no?(e.openBlock(),e.createElementBlock("button",{key:0,onClick:o[2]||(o[2]=e.withModifiers(s=>t.handleClickButton(s,!1),["stop"])),class:"vc-btn left",type:"button"},e.toDisplayString(t.dialog.button.no),1)):e.createCommentVNode("",!0),t.dialog.button.yes?(e.openBlock(),e.createElementBlock("button",{key:1,disabled:t.dialog.auth?!t.password:!1,onClick:o[3]||(o[3]=e.withModifiers(s=>t.handleClickButton(s,!0),["stop"])),class:"vc-btn",type:"button"},e.toDisplayString(t.dialog.button.yes),9,k)):e.createCommentVNode("",!0)],2)],512)):e.createCommentVNode("",!0)]),_:1})])):e.createCommentVNode("",!0)]),_:1})}const y=c(d,[["render",g]]);return{install:(t,o={})=>{if(globalThis.installed)return;globalThis.installed=!0,globalThis.params=o,t.component(o.componentName||"vue3-confirm-dialog",y);const n=i=>{if(typeof i!="object"||Array.isArray(i)){let l=typeof i;throw Array.isArray(i)&&(l="array"),new Error(`Options type must be an object. Caught: ${l}. Expected: object`)}if(typeof i=="object"){if(i.hasOwnProperty("callback")&&typeof i.callback!="function"){let l=typeof i.callback;throw new Error(`Callback type must be an function. Caught: ${l}. Expected: function`)}r.emit("open",i)}};n.close=()=>{r.emit("close")},t.config.globalProperties.$confirm=n,t.$confirm=n}}});