vue-amazing-ui
Version:
An Amazing Vue3 UI Components Library, Using TypeScript.
2 lines (1 loc) • 12.5 kB
JavaScript
;Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),L=require("../scrollbar/index.cjs"),c=require("../button/index.cjs"),b=require("../utils/index.cjs"),T={class:"dialog-root"},P={focusable:"false","data-icon":"fullscreen",width:"1em",height:"1em",fill:"currentColor","aria-hidden":"true",viewBox:"64 64 896 896"},$={focusable:"false","data-icon":"fullscreen-exit",width:"1em",height:"1em",fill:"currentColor","aria-hidden":"true",viewBox:"64 64 896 896"},D={key:1,class:"dialog-footer"},O={focusable:"false","data-icon":"fullscreen",width:"1em",height:"1em",fill:"currentColor","aria-hidden":"true",viewBox:"64 64 896 896"},M={focusable:"false","data-icon":"fullscreen-exit",width:"1em",height:"1em",fill:"currentColor","aria-hidden":"true",viewBox:"64 64 896 896"},x={key:1,class:"dialog-footer"},F=e.defineComponent({__name:"Dialog",props:{width:{default:520},height:{default:"auto"},title:{default:void 0},titleStyle:{default:()=>({})},content:{default:void 0},contentStyle:{default:()=>({})},bodyClass:{default:void 0},bodyStyle:{default:()=>({})},scrollbarProps:{default:()=>({})},cancelText:{default:"取消"},cancelProps:{default:()=>({})},okText:{default:"确定"},okType:{default:"primary"},okProps:{default:()=>({})},footer:{type:Boolean,default:!0},destroyOnClose:{type:Boolean,default:!1},switchFullscreen:{type:Boolean,default:!1},centered:{type:Boolean,default:!1},top:{default:100},transformOrigin:{default:"mouse"},confirmLoading:{type:Boolean,default:!1},blockScroll:{type:Boolean,default:!0},keyboard:{type:Boolean,default:!0},maskClosable:{type:Boolean,default:!0},maskStyle:{default:()=>({})},open:{type:Boolean,default:!1}},emits:["update:open","cancel","ok"],setup(w,{emit:k}){const l=w,f=e.ref(),r=e.ref(null),n=e.ref(),d=e.ref(),i=e.ref("50% 50%"),a=e.ref(!1),{isSupported:m}=b.useOptionsSupported("capture"),u=k,p=e.computed(()=>typeof l.width=="number"?`${l.width}px`:l.width),S=e.computed(()=>typeof l.height=="number"?`${l.height}px`:l.height),C=e.computed(()=>typeof l.top=="number"?`${l.top}px`:l.top),z=e.computed(()=>a.value?l.transformOrigin==="mouse"?{width:"100%",transformOrigin:`${r.value?.x}px ${r.value?.y}px`}:{width:"100%",transformOrigin:i.value}:l.centered?{width:p.value,transformOrigin:i.value}:{width:p.value,transformOrigin:i.value,top:C.value}),v=e.computed(()=>a.value?{height:"100vh",...l.bodyStyle}:{height:S.value,...l.bodyStyle});e.watch(n,async t=>{t?(await e.nextTick(),f.value.focus(),l.blockScroll&&(document.documentElement.style.overflowY="hidden",document.body.style.overflowY="hidden")):l.blockScroll&&(document.documentElement.style.removeProperty("overflow-y"),document.body.style.removeProperty("overflow-y"))},{immediate:!0}),e.watchEffect(()=>{n.value=l.open}),e.onMounted(()=>{document.addEventListener("click",y,m.value?{capture:!0}:!0)}),e.onUnmounted(()=>{document.removeEventListener("click",y,m.value?{capture:!0}:!0)});function y(t){n.value||(r.value={x:t.clientX,y:t.clientY})}async function B(t){if(d.value=!0,await e.nextTick(),l.transformOrigin==="mouse"&&r.value){const o=t.getBoundingClientRect();i.value=`${r.value.x-o.left}px ${r.value.y-o.top}px`}else i.value="50% 50%"}function N(t){if(l.transformOrigin==="mouse"&&r.value){const o=t.getBoundingClientRect();i.value=`${r.value.x-o.left}px ${r.value.y-o.top}px`}else i.value="50% 50%"}function V(){d.value=!1,a.value=!1}function h(){a.value=!a.value}function s(){n.value=!1,u("update:open",!1),u("cancel")}function g(){u("ok")}return(t,o)=>(e.openBlock(),e.createElementBlock("div",T,[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[e.withDirectives(e.createElementVNode("div",{class:"dialog-mask",style:e.normalizeStyle(t.maskStyle)},null,4),[[e.vShow,n.value]])]),_:1}),e.withDirectives(e.createElementVNode("div",{tabindex:"-1",ref_key:"dialogRef",ref:f,class:e.normalizeClass(["dialog-wrap",{"flex-centered":t.centered}]),onClick:o[0]||(o[0]=e.withModifiers(E=>l.maskClosable?s():()=>!1,["self"])),onKeydown:o[1]||(o[1]=e.withKeys(E=>l.keyboard?s():()=>!1,["esc"]))},[e.createVNode(e.Transition,{name:"zoom","enter-from-class":"zoom-enter","enter-active-class":"zoom-enter","enter-to-class":"zoom-enter zoom-enter-active","leave-from-class":"zoom-leave","leave-active-class":"zoom-leave zoom-leave-active","leave-to-class":"zoom-leave zoom-leave-active",onBeforeEnter:B,onBeforeLeave:N,onAfterLeave:V},{default:e.withCtx(()=>[e.withDirectives(e.createElementVNode("div",{class:e.normalizeClass(["dialog-container",{"dialog-with-fullscreen":a.value}]),style:e.normalizeStyle(z.value)},[t.destroyOnClose?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["dialog-body-wrap",t.bodyClass]),style:e.normalizeStyle(v.value)},[e.createElementVNode("div",{class:e.normalizeClass(["dialog-header",{"header-with-switch":t.switchFullscreen}]),style:e.normalizeStyle(t.titleStyle)},[e.renderSlot(t.$slots,"title",{},()=>[e.createTextVNode(e.toDisplayString(t.title),1)],!0)],6),t.switchFullscreen?(e.openBlock(),e.createElementBlock("span",{key:0,class:"fullscreen-action",onClick:h},[e.withDirectives((e.openBlock(),e.createElementBlock("svg",P,[...o[2]||(o[2]=[e.createElementVNode("path",{d:"M290 236.4l43.9-43.9a8.01 8.01 0 00-4.7-13.6L169 160c-5.1-.6-9.5 3.7-8.9 8.9L179 329.1c.8 6.6 8.9 9.4 13.6 4.7l43.7-43.7L370 423.7c3.1 3.1 8.2 3.1 11.3 0l42.4-42.3c3.1-3.1 3.1-8.2 0-11.3L290 236.4zm352.7 187.3c3.1 3.1 8.2 3.1 11.3 0l133.7-133.6 43.7 43.7a8.01 8.01 0 0013.6-4.7L863.9 169c.6-5.1-3.7-9.5-8.9-8.9L694.8 179c-6.6.8-9.4 8.9-4.7 13.6l43.9 43.9L600.3 370a8.03 8.03 0 000 11.3l42.4 42.4zM845 694.9c-.8-6.6-8.9-9.4-13.6-4.7l-43.7 43.7L654 600.3a8.03 8.03 0 00-11.3 0l-42.4 42.3a8.03 8.03 0 000 11.3L734 787.6l-43.9 43.9a8.01 8.01 0 004.7 13.6L855 864c5.1.6 9.5-3.7 8.9-8.9L845 694.9zm-463.7-94.6a8.03 8.03 0 00-11.3 0L236.3 733.9l-43.7-43.7a8.01 8.01 0 00-13.6 4.7L160.1 855c-.6 5.1 3.7 9.5 8.9 8.9L329.2 845c6.6-.8 9.4-8.9 4.7-13.6L290 787.6 423.7 654c3.1-3.1 3.1-8.2 0-11.3l-42.4-42.4z"},null,-1)])],512)),[[e.vShow,!a.value]]),e.withDirectives((e.openBlock(),e.createElementBlock("svg",$,[...o[3]||(o[3]=[e.createElementVNode("path",{d:"M391 240.9c-.8-6.6-8.9-9.4-13.6-4.7l-43.7 43.7L200 146.3a8.03 8.03 0 00-11.3 0l-42.4 42.3a8.03 8.03 0 000 11.3L280 333.6l-43.9 43.9a8.01 8.01 0 004.7 13.6L401 410c5.1.6 9.5-3.7 8.9-8.9L391 240.9zm10.1 373.2L240.8 633c-6.6.8-9.4 8.9-4.7 13.6l43.9 43.9L146.3 824a8.03 8.03 0 000 11.3l42.4 42.3c3.1 3.1 8.2 3.1 11.3 0L333.7 744l43.7 43.7A8.01 8.01 0 00391 783l18.9-160.1c.6-5.1-3.7-9.4-8.8-8.8zm221.8-204.2L783.2 391c6.6-.8 9.4-8.9 4.7-13.6L744 333.6 877.7 200c3.1-3.1 3.1-8.2 0-11.3l-42.4-42.3a8.03 8.03 0 00-11.3 0L690.3 279.9l-43.7-43.7a8.01 8.01 0 00-13.6 4.7L614.1 401c-.6 5.2 3.7 9.5 8.8 8.9zM744 690.4l43.9-43.9a8.01 8.01 0 00-4.7-13.6L623 614c-5.1-.6-9.5 3.7-8.9 8.9L633 783.1c.8 6.6 8.9 9.4 13.6 4.7l43.7-43.7L824 877.7c3.1 3.1 8.2 3.1 11.3 0l42.4-42.3c3.1-3.1 3.1-8.2 0-11.3L744 690.4z"},null,-1)])],512)),[[e.vShow,a.value]])])):e.createCommentVNode("",!0),e.createElementVNode("span",{class:"close-action",onClick:s},[...o[4]||(o[4]=[e.createElementVNode("svg",{width:"1em",height:"1em",fill:"currentColor",viewBox:"64 64 896 896","data-icon":"close","aria-hidden":"true",focusable:"false"},[e.createElementVNode("path",{d:"M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"})],-1)])]),e.createVNode(e.unref(L.default),e.normalizeProps(e.guardReactiveProps(t.scrollbarProps)),{default:e.withCtx(()=>[e.createElementVNode("div",{class:"dialog-content",style:e.normalizeStyle(t.contentStyle)},[e.renderSlot(t.$slots,"default",{},()=>[e.createTextVNode(e.toDisplayString(t.content),1)],!0)],4)]),_:3},16),t.footer?(e.openBlock(),e.createElementBlock("div",D,[e.renderSlot(t.$slots,"footer",{},()=>[e.createVNode(e.unref(c.default),e.mergeProps({class:"mr8",onClick:s},t.cancelProps),{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.cancelText),1)]),_:1},16),e.createVNode(e.unref(c.default),e.mergeProps({type:t.okType,loading:l.confirmLoading,onClick:g},t.okProps),{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.okText),1)]),_:1},16,["type","loading"])],!0)])):e.createCommentVNode("",!0)],6)),t.destroyOnClose&&n.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(["dialog-body-wrap",t.bodyClass]),style:e.normalizeStyle(v.value)},[e.createElementVNode("div",{class:e.normalizeClass(["dialog-header",{"header-with-switch":t.switchFullscreen}]),style:e.normalizeStyle(t.titleStyle)},[e.renderSlot(t.$slots,"title",{},()=>[e.createTextVNode(e.toDisplayString(t.title),1)],!0)],6),t.switchFullscreen?(e.openBlock(),e.createElementBlock("span",{key:0,class:"fullscreen-action",onClick:h},[e.withDirectives((e.openBlock(),e.createElementBlock("svg",O,[...o[5]||(o[5]=[e.createElementVNode("path",{d:"M290 236.4l43.9-43.9a8.01 8.01 0 00-4.7-13.6L169 160c-5.1-.6-9.5 3.7-8.9 8.9L179 329.1c.8 6.6 8.9 9.4 13.6 4.7l43.7-43.7L370 423.7c3.1 3.1 8.2 3.1 11.3 0l42.4-42.3c3.1-3.1 3.1-8.2 0-11.3L290 236.4zm352.7 187.3c3.1 3.1 8.2 3.1 11.3 0l133.7-133.6 43.7 43.7a8.01 8.01 0 0013.6-4.7L863.9 169c.6-5.1-3.7-9.5-8.9-8.9L694.8 179c-6.6.8-9.4 8.9-4.7 13.6l43.9 43.9L600.3 370a8.03 8.03 0 000 11.3l42.4 42.4zM845 694.9c-.8-6.6-8.9-9.4-13.6-4.7l-43.7 43.7L654 600.3a8.03 8.03 0 00-11.3 0l-42.4 42.3a8.03 8.03 0 000 11.3L734 787.6l-43.9 43.9a8.01 8.01 0 004.7 13.6L855 864c5.1.6 9.5-3.7 8.9-8.9L845 694.9zm-463.7-94.6a8.03 8.03 0 00-11.3 0L236.3 733.9l-43.7-43.7a8.01 8.01 0 00-13.6 4.7L160.1 855c-.6 5.1 3.7 9.5 8.9 8.9L329.2 845c6.6-.8 9.4-8.9 4.7-13.6L290 787.6 423.7 654c3.1-3.1 3.1-8.2 0-11.3l-42.4-42.4z"},null,-1)])],512)),[[e.vShow,!a.value]]),e.withDirectives((e.openBlock(),e.createElementBlock("svg",M,[...o[6]||(o[6]=[e.createElementVNode("path",{d:"M391 240.9c-.8-6.6-8.9-9.4-13.6-4.7l-43.7 43.7L200 146.3a8.03 8.03 0 00-11.3 0l-42.4 42.3a8.03 8.03 0 000 11.3L280 333.6l-43.9 43.9a8.01 8.01 0 004.7 13.6L401 410c5.1.6 9.5-3.7 8.9-8.9L391 240.9zm10.1 373.2L240.8 633c-6.6.8-9.4 8.9-4.7 13.6l43.9 43.9L146.3 824a8.03 8.03 0 000 11.3l42.4 42.3c3.1 3.1 8.2 3.1 11.3 0L333.7 744l43.7 43.7A8.01 8.01 0 00391 783l18.9-160.1c.6-5.1-3.7-9.4-8.8-8.8zm221.8-204.2L783.2 391c6.6-.8 9.4-8.9 4.7-13.6L744 333.6 877.7 200c3.1-3.1 3.1-8.2 0-11.3l-42.4-42.3a8.03 8.03 0 00-11.3 0L690.3 279.9l-43.7-43.7a8.01 8.01 0 00-13.6 4.7L614.1 401c-.6 5.2 3.7 9.5 8.8 8.9zM744 690.4l43.9-43.9a8.01 8.01 0 00-4.7-13.6L623 614c-5.1-.6-9.5 3.7-8.9 8.9L633 783.1c.8 6.6 8.9 9.4 13.6 4.7l43.7-43.7L824 877.7c3.1 3.1 8.2 3.1 11.3 0l42.4-42.3c3.1-3.1 3.1-8.2 0-11.3L744 690.4z"},null,-1)])],512)),[[e.vShow,a.value]])])):e.createCommentVNode("",!0),e.createElementVNode("span",{class:"close-action",onClick:s},[...o[7]||(o[7]=[e.createElementVNode("svg",{width:"1em",height:"1em",fill:"currentColor",viewBox:"64 64 896 896","data-icon":"close","aria-hidden":"true",focusable:"false"},[e.createElementVNode("path",{d:"M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"})],-1)])]),e.createVNode(e.unref(L.default),e.normalizeProps(e.guardReactiveProps(t.scrollbarProps)),{default:e.withCtx(()=>[e.createElementVNode("div",{class:"dialog-content",style:e.normalizeStyle(t.contentStyle)},[e.renderSlot(t.$slots,"default",{},()=>[e.createTextVNode(e.toDisplayString(t.content),1)],!0)],4)]),_:3},16),t.footer?(e.openBlock(),e.createElementBlock("div",x,[e.renderSlot(t.$slots,"footer",{},()=>[e.createVNode(e.unref(c.default),e.mergeProps({class:"mr8",onClick:s},t.cancelProps),{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.cancelText),1)]),_:1},16),e.createVNode(e.unref(c.default),e.mergeProps({type:t.okType,loading:l.confirmLoading,onClick:g},t.okProps),{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.okText),1)]),_:1},16,["type","loading"])],!0)])):e.createCommentVNode("",!0)],6)):e.createCommentVNode("",!0)],6),[[e.vShow,n.value]])]),_:3})],34),[[e.vShow,d.value]])]))}});exports.default=F;