@gopowerteam/modal-render 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/interfaces.d.ts +1 -0
- package/dist/es/index.mjs +67 -65
- package/dist/es/interfaces.d.ts +1 -0
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue");const S=Symbol("__MODAL__");function R(o){return e.getCurrentScope()?(e.onScopeDispose(o),!0):!1}function b(o){return typeof o=="function"?o():e.unref(o)}const A=typeof window<"u"&&typeof document<"u",F=Object.prototype.toString,I=o=>F.call(o)==="[object Object]",H=()=>{};function W(o,s={}){if(!e.isRef(o))return e.toRefs(o);const n=Array.isArray(o.value)?Array.from({length:o.value.length}):{};for(const t in o.value)n[t]=e.customRef(()=>({get(){return o.value[t]},set(a){var i;if((i=b(s.replaceRef))!=null?i:!0)if(Array.isArray(o.value)){const y=[...o.value];y[t]=a,o.value=y}else{const y={...o.value,[t]:a};Object.setPrototypeOf(y,Object.getPrototypeOf(o.value)),o.value=y}else o.value[t]=a}}));return n}function j(o){var s;const n=b(o);return(s=n==null?void 0:n.$el)!=null?s:n}const D=A?window:void 0;function P(...o){let s,n,t,a;if(typeof o[0]=="string"||Array.isArray(o[0])?([n,t,a]=o,s=D):[s,n,t,a]=o,!s)return H;Array.isArray(n)||(n=[n]),Array.isArray(t)||(t=[t]);const i=[],p=()=>{i.forEach(m=>m()),i.length=0},y=(m,g,l,f)=>(m.addEventListener(g,l,f),()=>m.removeEventListener(g,l,f)),_=e.watch(()=>[j(s),b(a)],([m,g])=>{if(p(),!m)return;const l=I(g)?{...g}:g;i.push(...n.flatMap(f=>t.map(c=>y(m,f,c,l))))},{immediate:!0,flush:"post"}),w=()=>{_(),p()};return R(w),w}function K(o,s={}){var n,t;const{pointerTypes:a,preventDefault:i,stopPropagation:p,exact:y,onMove:_,onEnd:w,onStart:m,initialValue:g,axis:l="both",draggingElement:f=D,containerElement:c,handle:v=o}=s,d=e.ref((n=b(g))!=null?n:{x:0,y:0}),h=e.ref(),C=u=>a?a.includes(u.pointerType):!0,B=u=>{b(i)&&u.preventDefault(),b(p)&&u.stopPropagation()},V=u=>{var E;if(!C(u)||b(y)&&u.target!==b(o))return;const x=((E=b(c))!=null?E:b(o)).getBoundingClientRect(),r={x:u.clientX-x.left,y:u.clientY-x.top};(m==null?void 0:m(r,u))!==!1&&(h.value=r,B(u))},L=u=>{if(!C(u)||!h.value)return;let{x:E,y:M}=d.value;(l==="x"||l==="both")&&(E=u.clientX-h.value.x),(l==="y"||l==="both")&&(M=u.clientY-h.value.y),d.value={x:E,y:M},_==null||_(d.value,u),B(u)},$=u=>{C(u)&&h.value&&(h.value=void 0,w==null||w(d.value,u),B(u))};if(A){const u={capture:(t=s.capture)!=null?t:!0};P(v,"pointerdown",V,u),P(f,"pointermove",L,u),P(f,"pointerup",$,u)}return{...W(d),position:d,isDragging:e.computed(()=>!!h.value),style:e.computed(()=>`left:${d.value.x}px;top:${d.value.y}px;`)}}const X=o=>(e.pushScopeId("data-v-450bcc09"),o=o(),e.popScopeId(),o),Y={class:"title font-bold"},q={class:"action"},G={key:1,class:"modal-footer space-x-2"},U=["form"],J={key:2,class:"modal-loading"},Q=X(()=>e.createElementVNode("div",{class:"lds-ring"},[e.createElementVNode("div"),e.createElementVNode("div"),e.createElementVNode("div"),e.createElementVNode("div")],-1)),Z=[Q],ee={name:"ModalContainer",inheritAttrs:!0},te=e.defineComponent({...ee,props:{id:{},form:{},component:{},componentProps:{},width:{},maxWidth:{},maxHeight:{},sizes:{},size:{default:"middle"},fullscreen:{type:Boolean},title:{},header:{type:Boolean,default:!0},footer:{type:Boolean,default:!1},closeable:{type:Boolean,default:!0},esc:{type:Boolean,default:!1},maskClosable:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},mode:{default:"dialog"},type:{}},emits:["submit"],setup(o,{expose:s,emit:n}){const t=o,a=n,i=e.inject(S),p=e.ref(!1);let y=0,_=0;const w=e.shallowRef(),m=e.shallowRef(),g=e.shallowRef(),{x:l,y:f}=K(g,{initialValue:{x:0,y:0}});function c(){i==null||i.close(t.id)}function v(r){if(typeof r=="number")return`${r}px`;if(typeof r=="string")return r}const d=e.computed(()=>{const r={};return t.mode==="dialog"&&(r.justifyContent="center"),t.mode==="drawer"&&(r.justifyContent="flex-end"),r}),h=e.computed(()=>{const r={};return t.size&&(r.width=v(t.sizes[t.size])),t.width&&(r.width=v(t.width)),t.maxWidth&&(r.maxWidth=v(t.maxWidth)),t.fullscreen&&(r.maxWidth="unset",r.width="100%",r.position="fixed",r.top=0,r.left=0,r.bottom=0,r.right=0,r.borderRadius=0),t.draggable&&!t.fullscreen&&t.mode==="dialog"&&(r.transform=`translate3d(${l.value-y}px, ${f.value-_}px, 0px)`),t.mode==="drawer"&&(r.borderRadius=0),r}),C=e.computed(()=>{const r={};return t.draggable&&!t.fullscreen&&t.mode==="dialog"&&(r.cursor="move"),r}),B=e.computed(()=>{var k;const r={};return t.maxHeight&&(r.maxHeight=`calc(${(k=v(t.maxHeight))==null?void 0:k.replace("%","vh")} - 50px)`),t.mode==="drawer"&&(r.maxHeight="unset",r.height=`calc(100vh - ${(t.header?50:0)+(t.footer?50:0)}px)`),t.fullscreen&&(r.maxHeight="unset",r.height=`calc(100vh - ${(t.header?50:0)+(t.footer?50:0)}px)`),t.type!=="component"&&(r.padding="0"),r});function V(){const r=m.value;if(t.form&&r){const k=r.querySelector(`form[name="${t.form}"]`);k&&k.dispatchEvent(new Event("submit"))}a("submit")}function L(){i==null||i.close(t.id)}function $(){window&&window.addEventListener("resize",()=>{e.triggerRef(w),e.triggerRef(m),y=m.value.offsetLeft,_=m.value.offsetTop})}function u(){if(t.closeable&&t.esc){const r=({key:k})=>{k==="Escape"&&(i==null||i.close(t.id),window.removeEventListener("keydown",r))};window.addEventListener("keydown",r)}}function E(){y=m.value.offsetLeft,_=m.value.offsetTop}e.onMounted(()=>{u(),$()}),e.onUnmounted(()=>{});function M(){return p.value=!0,()=>x()}function x(){p.value=!1}return s({showLoading:M,hideLoading:x}),(r,k)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"wrapperRef",ref:w,class:"modal-wrapper",style:e.normalizeStyle(d.value),onClick:k[0]||(k[0]=e.withModifiers(pe=>r.maskClosable&&c(),["self"]))},[e.createElementVNode("div",{ref_key:"contentRef",ref:m,class:e.normalizeClass(["modal-content",{[`${r.mode}-mode`]:!0}]),style:e.normalizeStyle(h.value)},[r.header?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"headerRef",ref:g,class:"modal-header",style:e.normalizeStyle(C.value),onMousedown:E},[e.createElementVNode("div",Y,e.toDisplayString(r.title),1),e.createElementVNode("div",q,[r.closeable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"i-icon-park-outline:close block cursor-pointer",onClick:c})):e.createCommentVNode("",!0)])],36)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"modal-body",style:e.normalizeStyle(B.value)},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(r.component),e.normalizeProps(e.guardReactiveProps(r.componentProps)),null,16))],4),r.footer?(e.openBlock(),e.createElementBlock("div",G,[e.createElementVNode("button",{class:"submit-button",form:r.form,type:"submit",onClick:V}," 确定 ",8,U),e.createElementVNode("button",{class:"cancel-button",type:"button",onClick:L}," 取消 ")])):e.createCommentVNode("",!0),p.value?(e.openBlock(),e.createElementBlock("div",J,Z)):e.createCommentVNode("",!0)],6)],4))}});const z=(o,s)=>{const n=o.__vccOpts||o;for(const[t,a]of s)n[t]=a;return n},O=z(te,[["__scopeId","data-v-450bcc09"]]),oe={class:"modal-dialog"},ne={class:"dialog-body"},re={class:"dialog-title"},ie={class:"dialog-content"},le=e.defineComponent({__name:"modal-dialog",props:{type:{},title:{},content:{},okText:{default:"确定"},cancelText:{default:"取消"},onOk:{},onCancel:{},footer:{}},setup(o){const s=o,n=T(),t=e.computed(()=>s.title?s.title:{confirm:"提示",info:"提示",warning:"警告",error:"错误",success:"成功"}[s.type]);async function a(){s.onOk&&await s.onOk(),n.close()}async function i(){s.onCancel&&await s.onCancel(),n.close()}return(p,y)=>(e.openBlock(),e.createElementBlock("section",oe,[e.createElementVNode("div",ne,[e.createElementVNode("div",re,e.toDisplayString(t.value),1),e.createElementVNode("div",ie,e.toDisplayString(p.content),1)]),e.createElementVNode("div",{class:"dialog-footer space-x-2",style:e.normalizeStyle(p.type==="confirm"?{"justify-content":"end"}:{"border-top":"none"})},[p.footer?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(p.footer),{key:0})):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("button",{class:"submit-button",type:"submit",onClick:a},e.toDisplayString(p.okText),1),p.type==="confirm"?(e.openBlock(),e.createElementBlock("button",{key:0,class:"cancel-button",type:"button",onClick:i},e.toDisplayString(p.cancelText),1)):e.createCommentVNode("",!0)],64))],4)]))}});const se=z(le,[["__scopeId","data-v-8326e5a5"]]),ae={key:0,class:"modal-teleport"},ce={name:"ModalProvider",inheritAttrs:!0},de=e.defineComponent({...ce,props:{appendToBody:{type:[Boolean,String],default:!1},sizes:{default:()=>({small:520,middle:860,large:1190})},maxWidth:{default:"80%"},maxHeight:{default:"80%"}},setup(o,{expose:s}){const n=e.shallowRef([]),t=e.ref(!1),a=e.getCurrentInstance();function i(l,f={},c={}){const v=e.defineAsyncComponent(()=>Promise.resolve(typeof l=="string"?se:l));typeof l=="string"&&(f.type=l,c.size="small",c.fullscreen=!1,c.mode="dialog",c.footer=!1,c.header=!1);const d=Math.random().toString(32).slice(2),h=new Promise(C=>{n.value.push({id:d,component:v,props:f||{},options:{...c,type:typeof l=="string"?l:"component"},resolve:C,listeners:[]}),e.triggerRef(n)});return Object.assign(h,{close:()=>p(d)})}function p(l,f){const c=n.value.findIndex(d=>d.id===l);if(c<0)return;const v=n.value[c];v==null||v.resolve(f),n.value.splice(c,1),e.triggerRef(n)}function y(){n.value.forEach(l=>{l.resolve()}),n.value=[],e.triggerRef(n)}function _(l,f){const c=n.value.find(d=>d.id===l);if(!c)return;const v=c.listeners.find(d=>d.event===f);v&&v.callback({open:i,close:d=>p(c.id,d),closeAll:y,showLoading:()=>w(c.id),hideLoading:()=>m(c.id),confirm:d=>i("confirm",d),success:d=>i("success",d),error:d=>i("error",d),warning:d=>i("warning",d),info:d=>i("info",d)})}function w(l){if(!a)return;const[f]=a.refs[`modal-container_${l}`];if(f)return f.showLoading()}function m(l){if(!a)return;const[f]=a.refs[`modal-container_${l}`];if(f)return f.hideLoading()}function g(l,f,c){const v=n.value.find(d=>d.id===l);v&&v.listeners.push({event:f,callback:c})}return e.provide(S,{open:i,close:p,closeAll:y,addEventListener:g}),s({elements:n,open:i}),e.onMounted(()=>{t.value=!0}),(l,f)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.renderSlot(l.$slots,"default",{},void 0,!0),t.value?(e.openBlock(),e.createElementBlock("div",ae,[(e.openBlock(),e.createBlock(e.Teleport,{disabled:!l.appendToBody,to:typeof l.appendToBody=="string"?l.appendToBody:"body"},[e.createVNode(e.TransitionGroup,{name:"modal-fade"},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.value,c=>(e.openBlock(),e.createBlock(O,e.mergeProps({id:c.id,key:c.id,ref_for:!0,ref:`modal-container_${c.id}`,component:c.component,"component-props":c.props,"max-height":l.maxHeight,"max-width":l.maxWidth,sizes:l.sizes},c.options,{onSubmit:()=>_(c.id,"submit")}),null,16,["id","component","component-props","max-height","max-width","sizes","onSubmit"]))),128))]),_:1})],8,["disabled","to"]))])):e.createCommentVNode("",!0)],64))}});const ue=z(de,[["__scopeId","data-v-cbdbb036"]]);function N(o,s){var t,a;let n=o==null?void 0:o.parent;for(;n&&((t=n==null?void 0:n.type)==null?void 0:t.name)!==s;)n=n.parent;return((a=n==null?void 0:n.type)==null?void 0:a.name)===s?n:null}function T(){const o=e.inject(S),s=e.getCurrentInstance();function n(t,a,i){if(!o)throw new Error("Not Found Modal Provider Component");return o.open(t,a,i)}return{open:n,close(t){var p;if(!o)throw new Error("Not Found Modal Provider Component");const a=N(s,"ModalContainer"),i=(p=a==null?void 0:a.props)==null?void 0:p.id;if(!i)throw new Error("Not Found Current Modal Container");o.close(i,t)},closeAll(){if(!o)throw new Error("Not Found Modal Provider Component");o.closeAll()},showLoading(){var i;if(!o)throw new Error("Not Found Modal Provider Component");const t=N(s,"ModalContainer");if(!((i=t==null?void 0:t.props)==null?void 0:i.id))throw new Error("Not Found Current Modal Container");t!=null&&t.exposed&&(t==null||t.exposed.showLoading())},hideLoading(){var i;if(!o)throw new Error("Not Found Modal Provider Component");const t=N(s,"ModalContainer");if(!((i=t==null?void 0:t.props)==null?void 0:i.id))throw new Error("Not Found Current Modal Container");t!=null&&t.exposed&&(t==null||t.exposed.hideLoading())},confirm(t){return this.open("confirm",t)},info(t){return this.open("info",t)},error(t){return this.open("error",t)},warning(t){return this.open("warning",t)},success(t){return this.open("success",t)}}}function fe(o){var i;const s=e.inject(S),n=e.getCurrentInstance(),t=N(n,"ModalContainer"),a=(i=t==null?void 0:t.props)==null?void 0:i.id;s&&a&&s.addEventListener(a,"submit",o)}exports.ModalContainer=O;exports.ModalKey=S;exports.ModalProvider=ue;exports.onSubmit=fe;exports.useModal=T;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue");const S=Symbol("__MODAL__");function R(o){return e.getCurrentScope()?(e.onScopeDispose(o),!0):!1}function E(o){return typeof o=="function"?o():e.unref(o)}const z=typeof window<"u"&&typeof document<"u",F=Object.prototype.toString,I=o=>F.call(o)==="[object Object]",H=()=>{};function W(o,s={}){if(!e.isRef(o))return e.toRefs(o);const n=Array.isArray(o.value)?Array.from({length:o.value.length}):{};for(const t in o.value)n[t]=e.customRef(()=>({get(){return o.value[t]},set(a){var i;if((i=E(s.replaceRef))!=null?i:!0)if(Array.isArray(o.value)){const y=[...o.value];y[t]=a,o.value=y}else{const y={...o.value,[t]:a};Object.setPrototypeOf(y,Object.getPrototypeOf(o.value)),o.value=y}else o.value[t]=a}}));return n}function j(o){var s;const n=E(o);return(s=n==null?void 0:n.$el)!=null?s:n}const D=z?window:void 0;function P(...o){let s,n,t,a;if(typeof o[0]=="string"||Array.isArray(o[0])?([n,t,a]=o,s=D):[s,n,t,a]=o,!s)return H;Array.isArray(n)||(n=[n]),Array.isArray(t)||(t=[t]);const i=[],p=()=>{i.forEach(m=>m()),i.length=0},y=(m,g,l,f)=>(m.addEventListener(g,l,f),()=>m.removeEventListener(g,l,f)),_=e.watch(()=>[j(s),E(a)],([m,g])=>{if(p(),!m)return;const l=I(g)?{...g}:g;i.push(...n.flatMap(f=>t.map(c=>y(m,f,c,l))))},{immediate:!0,flush:"post"}),w=()=>{_(),p()};return R(w),w}function K(o,s={}){var n,t;const{pointerTypes:a,preventDefault:i,stopPropagation:p,exact:y,onMove:_,onEnd:w,onStart:m,initialValue:g,axis:l="both",draggingElement:f=D,containerElement:c,handle:v=o}=s,d=e.ref((n=E(g))!=null?n:{x:0,y:0}),h=e.ref(),k=u=>a?a.includes(u.pointerType):!0,b=u=>{E(i)&&u.preventDefault(),E(p)&&u.stopPropagation()},V=u=>{var B;if(!k(u)||E(y)&&u.target!==E(o))return;const x=((B=E(c))!=null?B:E(o)).getBoundingClientRect(),r={x:u.clientX-x.left,y:u.clientY-x.top};(m==null?void 0:m(r,u))!==!1&&(h.value=r,b(u))},L=u=>{if(!k(u)||!h.value)return;let{x:B,y:M}=d.value;(l==="x"||l==="both")&&(B=u.clientX-h.value.x),(l==="y"||l==="both")&&(M=u.clientY-h.value.y),d.value={x:B,y:M},_==null||_(d.value,u),b(u)},$=u=>{k(u)&&h.value&&(h.value=void 0,w==null||w(d.value,u),b(u))};if(z){const u={capture:(t=s.capture)!=null?t:!0};P(v,"pointerdown",V,u),P(f,"pointermove",L,u),P(f,"pointerup",$,u)}return{...W(d),position:d,isDragging:e.computed(()=>!!h.value),style:e.computed(()=>`left:${d.value.x}px;top:${d.value.y}px;`)}}const X=o=>(e.pushScopeId("data-v-7f0b9287"),o=o(),e.popScopeId(),o),Y={class:"title font-bold"},q={class:"action"},G={key:1,class:"modal-footer space-x-2"},U=["form"],J={key:2,class:"modal-loading"},Q=X(()=>e.createElementVNode("div",{class:"lds-ring"},[e.createElementVNode("div"),e.createElementVNode("div"),e.createElementVNode("div"),e.createElementVNode("div")],-1)),Z=[Q],ee={name:"ModalContainer",inheritAttrs:!0},te=e.defineComponent({...ee,props:{id:{},form:{},component:{},componentProps:{},width:{},maxWidth:{},maxHeight:{},sizes:{},size:{default:"middle"},fullscreen:{type:Boolean},title:{},header:{type:Boolean,default:!0},footer:{type:Boolean,default:!1},closeable:{type:Boolean,default:!0},esc:{type:Boolean,default:!1},maskClosable:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},mode:{default:"dialog"},type:{}},emits:["submit"],setup(o,{expose:s,emit:n}){const t=o,a=n,i=e.inject(S),p=e.ref(!1);let y=0,_=0;const w=e.shallowRef(),m=e.shallowRef(),g=e.shallowRef(),{x:l,y:f}=K(g,{initialValue:{x:0,y:0}});function c(){i==null||i.close(t.id)}function v(r){if(typeof r=="number")return`${r}px`;if(typeof r=="string")return r}const d=e.computed(()=>{const r={};return t.mode==="dialog"&&(r.justifyContent="center"),t.mode==="drawer"&&(r.justifyContent="flex-end"),r}),h=e.computed(()=>{const r={};return t.size&&(r.width=v(t.sizes[t.size])),t.width&&(r.width=v(t.width)),t.maxWidth&&(r.maxWidth=v(t.maxWidth)),t.fullscreen&&(r.maxWidth="unset",r.width="100%",r.position="fixed",r.top=0,r.left=0,r.bottom=0,r.right=0,r.borderRadius=0),t.draggable&&!t.fullscreen&&t.mode==="dialog"&&(r.transform=`translate3d(${l.value-y}px, ${f.value-_}px, 0px)`),t.mode==="drawer"&&(r.borderRadius=0),r}),k=e.computed(()=>{const r={};return t.draggable&&!t.fullscreen&&t.mode==="dialog"&&(r.cursor="move"),r}),b=e.computed(()=>{var C;const r={};return t.maxHeight&&(r.maxHeight=`calc(${(C=v(t.maxHeight))==null?void 0:C.replace("%","vh")} - 50px)`),t.mode==="drawer"&&(r.maxHeight="unset",r.height=`calc(100vh - ${(t.header?50:0)+(t.footer?50:0)}px)`),t.fullscreen&&(r.maxHeight="unset",r.height=`calc(100vh - ${(t.header?50:0)+(t.footer?50:0)}px)`),t.type!=="component"&&(r.padding="0"),r});function V(){const r=m.value;if(t.form&&r){const C=r.querySelector(`form[name="${t.form}"]`);C&&C.dispatchEvent(new Event("submit"))}a("submit")}function L(){i==null||i.close(t.id)}function $(){window&&window.addEventListener("resize",()=>{e.triggerRef(w),e.triggerRef(m),m.value&&(y=m.value.offsetLeft,_=m.value.offsetTop)})}function u(){if(t.closeable&&t.esc){const r=({key:C})=>{C==="Escape"&&(i==null||i.close(t.id),window.removeEventListener("keydown",r))};window.addEventListener("keydown",r)}}function B(){y=m.value.offsetLeft,_=m.value.offsetTop}e.onMounted(()=>{u(),$()}),e.onUnmounted(()=>{});function M(){return p.value=!0,()=>x()}function x(){p.value=!1}return s({showLoading:M,hideLoading:x}),(r,C)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"wrapperRef",ref:w,class:"modal-wrapper",style:e.normalizeStyle(d.value),onClick:C[0]||(C[0]=e.withModifiers(pe=>r.maskClosable&&c(),["self"]))},[e.createElementVNode("div",{ref_key:"contentRef",ref:m,class:e.normalizeClass(["modal-content",{[`${r.mode}-mode`]:!0}]),style:e.normalizeStyle(h.value)},[r.header?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"headerRef",ref:g,class:"modal-header",style:e.normalizeStyle(k.value),onMousedown:B},[e.createElementVNode("div",Y,e.toDisplayString(r.title),1),e.createElementVNode("div",q,[r.closeable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"i-icon-park-outline:close block cursor-pointer",onClick:c})):e.createCommentVNode("",!0)])],36)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"modal-body",style:e.normalizeStyle(b.value)},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(r.component),e.normalizeProps(e.guardReactiveProps(r.componentProps)),null,16))],4),r.footer?(e.openBlock(),e.createElementBlock("div",G,[e.createElementVNode("button",{class:"submit-button",form:r.form,type:"submit",onClick:V}," 确定 ",8,U),e.createElementVNode("button",{class:"cancel-button",type:"button",onClick:L}," 取消 ")])):e.createCommentVNode("",!0),p.value?(e.openBlock(),e.createElementBlock("div",J,Z)):e.createCommentVNode("",!0)],6)],4))}});const A=(o,s)=>{const n=o.__vccOpts||o;for(const[t,a]of s)n[t]=a;return n},O=A(te,[["__scopeId","data-v-7f0b9287"]]),oe={class:"modal-dialog"},ne={class:"dialog-body"},re={class:"dialog-title"},ie={class:"dialog-content"},le=e.defineComponent({__name:"modal-dialog",props:{type:{},title:{},content:{},okText:{default:"确定"},cancelText:{default:"取消"},onOk:{},onCancel:{},footer:{}},setup(o){const s=o,n=T(),t=e.computed(()=>s.title?s.title:{confirm:"提示",info:"提示",warning:"警告",error:"错误",success:"成功"}[s.type]);async function a(){s.onOk&&await s.onOk(),n.close()}async function i(){s.onCancel&&await s.onCancel(),n.close()}return(p,y)=>(e.openBlock(),e.createElementBlock("section",oe,[e.createElementVNode("div",ne,[e.createElementVNode("div",re,e.toDisplayString(t.value),1),e.createElementVNode("div",ie,e.toDisplayString(p.content),1)]),e.createElementVNode("div",{class:"dialog-footer space-x-2",style:e.normalizeStyle(p.type==="confirm"?{"justify-content":"end"}:{"border-top":"none"})},[p.footer?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(p.footer),{key:0})):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("button",{class:"submit-button",type:"submit",onClick:a},e.toDisplayString(p.okText),1),p.type==="confirm"?(e.openBlock(),e.createElementBlock("button",{key:0,class:"cancel-button",type:"button",onClick:i},e.toDisplayString(p.cancelText),1)):e.createCommentVNode("",!0)],64))],4)]))}});const se=A(le,[["__scopeId","data-v-8326e5a5"]]),ae={key:0,class:"modal-teleport"},ce={name:"ModalProvider",inheritAttrs:!0},de=e.defineComponent({...ce,props:{appendToBody:{type:[Boolean,String],default:!1},sizes:{default:()=>({small:520,middle:860,large:1190})},maxWidth:{default:"80%"},maxHeight:{default:"80%"}},setup(o,{expose:s}){const n=e.shallowRef([]),t=e.ref(!1),a=e.getCurrentInstance();function i(l,f={},c={}){const v=e.defineAsyncComponent(()=>Promise.resolve(typeof l=="string"?se:l));typeof l=="string"&&(f.type=l,c.size="small",c.fullscreen=!1,c.mode="dialog",c.footer=!1,c.header=!1);const d=Math.random().toString(32).slice(2),h=new Promise((k,b)=>{n.value.push({id:d,component:v,props:f||{},options:{...c,type:typeof l=="string"?l:"component"},resolve:k,reject:b,listeners:[]}),e.triggerRef(n)}).catch(k=>k==="CANCEL"?new Promise(()=>{}):Promise.reject(k));return Object.assign(h,{close:()=>p(d)})}function p(l,f){const c=n.value.findIndex(d=>d.id===l);if(c<0)return;const v=n.value[c];f===void 0?v==null||v.reject("CANCEL"):v==null||v.resolve(f),n.value.splice(c,1),e.triggerRef(n)}function y(){n.value.forEach(l=>{l.resolve()}),n.value=[],e.triggerRef(n)}function _(l,f){const c=n.value.find(d=>d.id===l);if(!c)return;const v=c.listeners.find(d=>d.event===f);v&&v.callback({open:i,close:d=>p(c.id,d),closeAll:y,showLoading:()=>w(c.id),hideLoading:()=>m(c.id),confirm:d=>i("confirm",d),success:d=>i("success",d),error:d=>i("error",d),warning:d=>i("warning",d),info:d=>i("info",d)})}function w(l){if(!a)return;const[f]=a.refs[`modal-container_${l}`];if(f)return f.showLoading()}function m(l){if(!a)return;const[f]=a.refs[`modal-container_${l}`];if(f)return f.hideLoading()}function g(l,f,c){const v=n.value.find(d=>d.id===l);v&&v.listeners.push({event:f,callback:c})}return e.provide(S,{open:i,close:p,closeAll:y,addEventListener:g}),s({elements:n,open:i}),e.onMounted(()=>{t.value=!0}),(l,f)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.renderSlot(l.$slots,"default",{},void 0,!0),t.value?(e.openBlock(),e.createElementBlock("div",ae,[(e.openBlock(),e.createBlock(e.Teleport,{disabled:!l.appendToBody,to:typeof l.appendToBody=="string"?l.appendToBody:"body"},[e.createVNode(e.TransitionGroup,{name:"modal-fade"},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.value,c=>(e.openBlock(),e.createBlock(O,e.mergeProps({id:c.id,key:c.id,ref_for:!0,ref:`modal-container_${c.id}`,component:c.component,"component-props":c.props,"max-height":l.maxHeight,"max-width":l.maxWidth,sizes:l.sizes},c.options,{onSubmit:()=>_(c.id,"submit")}),null,16,["id","component","component-props","max-height","max-width","sizes","onSubmit"]))),128))]),_:1})],8,["disabled","to"]))])):e.createCommentVNode("",!0)],64))}});const ue=A(de,[["__scopeId","data-v-4ee644e1"]]);function N(o,s){var t,a;let n=o==null?void 0:o.parent;for(;n&&((t=n==null?void 0:n.type)==null?void 0:t.name)!==s;)n=n.parent;return((a=n==null?void 0:n.type)==null?void 0:a.name)===s?n:null}function T(){const o=e.inject(S),s=e.getCurrentInstance();function n(t,a,i){if(!o)throw new Error("Not Found Modal Provider Component");return o.open(t,a,i)}return{open:n,close(t){var p;if(!o)throw new Error("Not Found Modal Provider Component");const a=N(s,"ModalContainer"),i=(p=a==null?void 0:a.props)==null?void 0:p.id;if(!i)throw new Error("Not Found Current Modal Container");o.close(i,t)},closeAll(){if(!o)throw new Error("Not Found Modal Provider Component");o.closeAll()},showLoading(){var i;if(!o)throw new Error("Not Found Modal Provider Component");const t=N(s,"ModalContainer");if(!((i=t==null?void 0:t.props)==null?void 0:i.id))throw new Error("Not Found Current Modal Container");t!=null&&t.exposed&&(t==null||t.exposed.showLoading())},hideLoading(){var i;if(!o)throw new Error("Not Found Modal Provider Component");const t=N(s,"ModalContainer");if(!((i=t==null?void 0:t.props)==null?void 0:i.id))throw new Error("Not Found Current Modal Container");t!=null&&t.exposed&&(t==null||t.exposed.hideLoading())},confirm(t){return this.open("confirm",t)},info(t){return this.open("info",t)},error(t){return this.open("error",t)},warning(t){return this.open("warning",t)},success(t){return this.open("success",t)}}}function fe(o){var i;const s=e.inject(S),n=e.getCurrentInstance(),t=N(n,"ModalContainer"),a=(i=t==null?void 0:t.props)==null?void 0:i.id;s&&a&&s.addEventListener(a,"submit",o)}exports.ModalContainer=O;exports.ModalKey=S;exports.ModalProvider=ue;exports.onSubmit=fe;exports.useModal=T;
|
package/dist/cjs/interfaces.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface OpenModalOptions {
|
|
|
23
23
|
export interface ModalElement extends OpenModalOptions {
|
|
24
24
|
id: string;
|
|
25
25
|
resolve: (data?: any) => void;
|
|
26
|
+
reject: (key: 'CANCEL') => void;
|
|
26
27
|
component: Component;
|
|
27
28
|
props: Record<string, any>;
|
|
28
29
|
options: OpenModalOptions & {
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { unref as Z, isRef as ee, toRefs as te, customRef as oe, getCurrentScope as ne, onScopeDispose as re, ref as N, computed as S, watch as ie, defineComponent as Y, inject as
|
|
1
|
+
import { unref as Z, isRef as ee, toRefs as te, customRef as oe, getCurrentScope as ne, onScopeDispose as re, ref as N, computed as S, watch as ie, defineComponent as Y, inject as j, shallowRef as T, onMounted as G, onUnmounted as se, openBlock as h, createElementBlock as w, normalizeStyle as z, withModifiers as le, createElementVNode as y, normalizeClass as ae, toDisplayString as B, createCommentVNode as $, createBlock as F, resolveDynamicComponent as U, normalizeProps as de, guardReactiveProps as ce, triggerRef as O, pushScopeId as ue, popScopeId as fe, Fragment as X, getCurrentInstance as K, provide as pe, renderSlot as me, Teleport as ve, createVNode as ye, TransitionGroup as he, withCtx as ge, renderList as _e, mergeProps as we, defineAsyncComponent as be } from "vue";
|
|
2
2
|
const H = Symbol("__MODAL__");
|
|
3
3
|
function Ce(t) {
|
|
4
4
|
return ne() ? (re(t), !0) : !1;
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function E(t) {
|
|
7
7
|
return typeof t == "function" ? t() : Z(t);
|
|
8
8
|
}
|
|
9
|
-
const J = typeof window < "u" && typeof document < "u", ke = Object.prototype.toString, xe = (t) => ke.call(t) === "[object Object]",
|
|
9
|
+
const J = typeof window < "u" && typeof document < "u", ke = Object.prototype.toString, xe = (t) => ke.call(t) === "[object Object]", Ee = () => {
|
|
10
10
|
};
|
|
11
|
-
function
|
|
11
|
+
function Me(t, s = {}) {
|
|
12
12
|
if (!ee(t))
|
|
13
13
|
return te(t);
|
|
14
14
|
const o = Array.isArray(t.value) ? Array.from({ length: t.value.length }) : {};
|
|
@@ -19,7 +19,7 @@ function Ee(t, s = {}) {
|
|
|
19
19
|
},
|
|
20
20
|
set(l) {
|
|
21
21
|
var r;
|
|
22
|
-
if ((r =
|
|
22
|
+
if ((r = E(s.replaceRef)) != null ? r : !0)
|
|
23
23
|
if (Array.isArray(t.value)) {
|
|
24
24
|
const v = [...t.value];
|
|
25
25
|
v[e] = l, t.value = v;
|
|
@@ -33,21 +33,21 @@ function Ee(t, s = {}) {
|
|
|
33
33
|
}));
|
|
34
34
|
return o;
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function Le(t) {
|
|
37
37
|
var s;
|
|
38
|
-
const o =
|
|
38
|
+
const o = E(t);
|
|
39
39
|
return (s = o == null ? void 0 : o.$el) != null ? s : o;
|
|
40
40
|
}
|
|
41
41
|
const Q = J ? window : void 0;
|
|
42
42
|
function V(...t) {
|
|
43
43
|
let s, o, e, l;
|
|
44
44
|
if (typeof t[0] == "string" || Array.isArray(t[0]) ? ([o, e, l] = t, s = Q) : [s, o, e, l] = t, !s)
|
|
45
|
-
return
|
|
45
|
+
return Ee;
|
|
46
46
|
Array.isArray(o) || (o = [o]), Array.isArray(e) || (e = [e]);
|
|
47
47
|
const r = [], f = () => {
|
|
48
48
|
r.forEach((p) => p()), r.length = 0;
|
|
49
49
|
}, v = (p, g, i, u) => (p.addEventListener(g, i, u), () => p.removeEventListener(g, i, u)), b = ie(
|
|
50
|
-
() => [
|
|
50
|
+
() => [Le(s), E(l)],
|
|
51
51
|
([p, g]) => {
|
|
52
52
|
if (f(), !p)
|
|
53
53
|
return;
|
|
@@ -62,7 +62,7 @@ function V(...t) {
|
|
|
62
62
|
};
|
|
63
63
|
return Ce(C), C;
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function Se(t, s = {}) {
|
|
66
66
|
var o, e;
|
|
67
67
|
const {
|
|
68
68
|
pointerTypes: l,
|
|
@@ -78,35 +78,35 @@ function $e(t, s = {}) {
|
|
|
78
78
|
containerElement: a,
|
|
79
79
|
handle: m = t
|
|
80
80
|
} = s, d = N(
|
|
81
|
-
(o =
|
|
82
|
-
), _ = N(),
|
|
83
|
-
|
|
81
|
+
(o = E(g)) != null ? o : { x: 0, y: 0 }
|
|
82
|
+
), _ = N(), k = (c) => l ? l.includes(c.pointerType) : !0, M = (c) => {
|
|
83
|
+
E(r) && c.preventDefault(), E(f) && c.stopPropagation();
|
|
84
84
|
}, R = (c) => {
|
|
85
|
-
var
|
|
86
|
-
if (!
|
|
85
|
+
var L;
|
|
86
|
+
if (!k(c) || E(v) && c.target !== E(t))
|
|
87
87
|
return;
|
|
88
|
-
const P = ((
|
|
88
|
+
const P = ((L = E(a)) != null ? L : E(t)).getBoundingClientRect(), n = {
|
|
89
89
|
x: c.clientX - P.left,
|
|
90
90
|
y: c.clientY - P.top
|
|
91
91
|
};
|
|
92
|
-
(p == null ? void 0 : p(n, c)) !== !1 && (_.value = n,
|
|
92
|
+
(p == null ? void 0 : p(n, c)) !== !1 && (_.value = n, M(c));
|
|
93
93
|
}, W = (c) => {
|
|
94
|
-
if (!
|
|
94
|
+
if (!k(c) || !_.value)
|
|
95
95
|
return;
|
|
96
|
-
let { x:
|
|
97
|
-
(i === "x" || i === "both") && (
|
|
98
|
-
x:
|
|
96
|
+
let { x: L, y: A } = d.value;
|
|
97
|
+
(i === "x" || i === "both") && (L = c.clientX - _.value.x), (i === "y" || i === "both") && (A = c.clientY - _.value.y), d.value = {
|
|
98
|
+
x: L,
|
|
99
99
|
y: A
|
|
100
|
-
}, b == null || b(d.value, c),
|
|
100
|
+
}, b == null || b(d.value, c), M(c);
|
|
101
101
|
}, I = (c) => {
|
|
102
|
-
|
|
102
|
+
k(c) && _.value && (_.value = void 0, C == null || C(d.value, c), M(c));
|
|
103
103
|
};
|
|
104
104
|
if (J) {
|
|
105
105
|
const c = { capture: (e = s.capture) != null ? e : !0 };
|
|
106
106
|
V(m, "pointerdown", R, c), V(u, "pointermove", W, c), V(u, "pointerup", I, c);
|
|
107
107
|
}
|
|
108
108
|
return {
|
|
109
|
-
...
|
|
109
|
+
...Me(d),
|
|
110
110
|
position: d,
|
|
111
111
|
isDragging: S(() => !!_.value),
|
|
112
112
|
style: S(
|
|
@@ -114,13 +114,13 @@ function $e(t, s = {}) {
|
|
|
114
114
|
)
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
|
-
const
|
|
117
|
+
const $e = (t) => (ue("data-v-7f0b9287"), t = t(), fe(), t), Ae = { class: "title font-bold" }, Pe = { class: "action" }, ze = {
|
|
118
118
|
key: 1,
|
|
119
119
|
class: "modal-footer space-x-2"
|
|
120
120
|
}, Be = ["form"], Oe = {
|
|
121
121
|
key: 2,
|
|
122
122
|
class: "modal-loading"
|
|
123
|
-
}, Te = /* @__PURE__ */
|
|
123
|
+
}, Te = /* @__PURE__ */ $e(() => /* @__PURE__ */ y("div", { class: "lds-ring" }, [
|
|
124
124
|
/* @__PURE__ */ y("div"),
|
|
125
125
|
/* @__PURE__ */ y("div"),
|
|
126
126
|
/* @__PURE__ */ y("div"),
|
|
@@ -155,9 +155,9 @@ const Le = (t) => (ue("data-v-450bcc09"), t = t(), fe(), t), Ae = { class: "titl
|
|
|
155
155
|
},
|
|
156
156
|
emits: ["submit"],
|
|
157
157
|
setup(t, { expose: s, emit: o }) {
|
|
158
|
-
const e = t, l = o, r =
|
|
158
|
+
const e = t, l = o, r = j(H), f = N(!1);
|
|
159
159
|
let v = 0, b = 0;
|
|
160
|
-
const C = T(), p = T(), g = T(), { x: i, y: u } =
|
|
160
|
+
const C = T(), p = T(), g = T(), { x: i, y: u } = Se(g, {
|
|
161
161
|
initialValue: { x: 0, y: 0 }
|
|
162
162
|
});
|
|
163
163
|
function a() {
|
|
@@ -175,19 +175,19 @@ const Le = (t) => (ue("data-v-450bcc09"), t = t(), fe(), t), Ae = { class: "titl
|
|
|
175
175
|
}), _ = S(() => {
|
|
176
176
|
const n = {};
|
|
177
177
|
return e.size && (n.width = m(e.sizes[e.size])), e.width && (n.width = m(e.width)), e.maxWidth && (n.maxWidth = m(e.maxWidth)), e.fullscreen && (n.maxWidth = "unset", n.width = "100%", n.position = "fixed", n.top = 0, n.left = 0, n.bottom = 0, n.right = 0, n.borderRadius = 0), e.draggable && !e.fullscreen && e.mode === "dialog" && (n.transform = `translate3d(${i.value - v}px, ${u.value - b}px, 0px)`), e.mode === "drawer" && (n.borderRadius = 0), n;
|
|
178
|
-
}),
|
|
178
|
+
}), k = S(() => {
|
|
179
179
|
const n = {};
|
|
180
180
|
return e.draggable && !e.fullscreen && e.mode === "dialog" && (n.cursor = "move"), n;
|
|
181
|
-
}),
|
|
182
|
-
var
|
|
181
|
+
}), M = S(() => {
|
|
182
|
+
var x;
|
|
183
183
|
const n = {};
|
|
184
|
-
return e.maxHeight && (n.maxHeight = `calc(${(
|
|
184
|
+
return e.maxHeight && (n.maxHeight = `calc(${(x = m(e.maxHeight)) == null ? void 0 : x.replace("%", "vh")} - 50px)`), e.mode === "drawer" && (n.maxHeight = "unset", n.height = `calc(100vh - ${(e.header ? 50 : 0) + (e.footer ? 50 : 0)}px)`), e.fullscreen && (n.maxHeight = "unset", n.height = `calc(100vh - ${(e.header ? 50 : 0) + (e.footer ? 50 : 0)}px)`), e.type !== "component" && (n.padding = "0"), n;
|
|
185
185
|
});
|
|
186
186
|
function R() {
|
|
187
187
|
const n = p.value;
|
|
188
188
|
if (e.form && n) {
|
|
189
|
-
const
|
|
190
|
-
|
|
189
|
+
const x = n.querySelector(`form[name="${e.form}"]`);
|
|
190
|
+
x && x.dispatchEvent(new Event("submit"));
|
|
191
191
|
}
|
|
192
192
|
l("submit");
|
|
193
193
|
}
|
|
@@ -196,21 +196,21 @@ const Le = (t) => (ue("data-v-450bcc09"), t = t(), fe(), t), Ae = { class: "titl
|
|
|
196
196
|
}
|
|
197
197
|
function I() {
|
|
198
198
|
window && window.addEventListener("resize", () => {
|
|
199
|
-
O(C), O(p), v = p.value.offsetLeft, b = p.value.offsetTop;
|
|
199
|
+
O(C), O(p), p.value && (v = p.value.offsetLeft, b = p.value.offsetTop);
|
|
200
200
|
});
|
|
201
201
|
}
|
|
202
202
|
function c() {
|
|
203
203
|
if (e.closeable && e.esc) {
|
|
204
|
-
const n = ({ key:
|
|
205
|
-
|
|
204
|
+
const n = ({ key: x }) => {
|
|
205
|
+
x === "Escape" && (r == null || r.close(e.id), window.removeEventListener("keydown", n));
|
|
206
206
|
};
|
|
207
207
|
window.addEventListener("keydown", n);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
function
|
|
210
|
+
function L() {
|
|
211
211
|
v = p.value.offsetLeft, b = p.value.offsetTop;
|
|
212
212
|
}
|
|
213
|
-
|
|
213
|
+
G(() => {
|
|
214
214
|
c(), I();
|
|
215
215
|
}), se(() => {
|
|
216
216
|
});
|
|
@@ -223,12 +223,12 @@ const Le = (t) => (ue("data-v-450bcc09"), t = t(), fe(), t), Ae = { class: "titl
|
|
|
223
223
|
return s({
|
|
224
224
|
showLoading: A,
|
|
225
225
|
hideLoading: P
|
|
226
|
-
}), (n,
|
|
226
|
+
}), (n, x) => (h(), w("div", {
|
|
227
227
|
ref_key: "wrapperRef",
|
|
228
228
|
ref: C,
|
|
229
229
|
class: "modal-wrapper",
|
|
230
230
|
style: z(d.value),
|
|
231
|
-
onClick:
|
|
231
|
+
onClick: x[0] || (x[0] = le((Ue) => n.maskClosable && a(), ["self"]))
|
|
232
232
|
}, [
|
|
233
233
|
y("div", {
|
|
234
234
|
ref_key: "contentRef",
|
|
@@ -241,8 +241,8 @@ const Le = (t) => (ue("data-v-450bcc09"), t = t(), fe(), t), Ae = { class: "titl
|
|
|
241
241
|
ref_key: "headerRef",
|
|
242
242
|
ref: g,
|
|
243
243
|
class: "modal-header",
|
|
244
|
-
style: z(
|
|
245
|
-
onMousedown:
|
|
244
|
+
style: z(k.value),
|
|
245
|
+
onMousedown: L
|
|
246
246
|
}, [
|
|
247
247
|
y("div", Ae, B(n.title), 1),
|
|
248
248
|
y("div", Pe, [
|
|
@@ -255,9 +255,9 @@ const Le = (t) => (ue("data-v-450bcc09"), t = t(), fe(), t), Ae = { class: "titl
|
|
|
255
255
|
], 36)) : $("", !0),
|
|
256
256
|
y("div", {
|
|
257
257
|
class: "modal-body",
|
|
258
|
-
style: z(
|
|
258
|
+
style: z(M.value)
|
|
259
259
|
}, [
|
|
260
|
-
(h(), F(
|
|
260
|
+
(h(), F(U(n.component), de(ce(n.componentProps)), null, 16))
|
|
261
261
|
], 4),
|
|
262
262
|
n.footer ? (h(), w("div", ze, [
|
|
263
263
|
y("button", {
|
|
@@ -277,12 +277,12 @@ const Le = (t) => (ue("data-v-450bcc09"), t = t(), fe(), t), Ae = { class: "titl
|
|
|
277
277
|
], 4));
|
|
278
278
|
}
|
|
279
279
|
});
|
|
280
|
-
const
|
|
280
|
+
const q = (t, s) => {
|
|
281
281
|
const o = t.__vccOpts || t;
|
|
282
282
|
for (const [e, l] of s)
|
|
283
283
|
o[e] = l;
|
|
284
284
|
return o;
|
|
285
|
-
}, He = /* @__PURE__ */
|
|
285
|
+
}, He = /* @__PURE__ */ q(Fe, [["__scopeId", "data-v-7f0b9287"]]), Re = { class: "modal-dialog" }, We = { class: "dialog-body" }, Ie = { class: "dialog-title" }, Ve = { class: "dialog-content" }, Xe = /* @__PURE__ */ Y({
|
|
286
286
|
__name: "modal-dialog",
|
|
287
287
|
props: {
|
|
288
288
|
type: {},
|
|
@@ -295,7 +295,7 @@ const G = (t, s) => {
|
|
|
295
295
|
footer: {}
|
|
296
296
|
},
|
|
297
297
|
setup(t) {
|
|
298
|
-
const s = t, o =
|
|
298
|
+
const s = t, o = Ge(), e = S(() => s.title ? s.title : {
|
|
299
299
|
confirm: "提示",
|
|
300
300
|
info: "提示",
|
|
301
301
|
warning: "警告",
|
|
@@ -317,7 +317,7 @@ const G = (t, s) => {
|
|
|
317
317
|
class: "dialog-footer space-x-2",
|
|
318
318
|
style: z(f.type === "confirm" ? { "justify-content": "end" } : { "border-top": "none" })
|
|
319
319
|
}, [
|
|
320
|
-
f.footer ? (h(), F(
|
|
320
|
+
f.footer ? (h(), F(U(f.footer), { key: 0 })) : (h(), w(X, { key: 1 }, [
|
|
321
321
|
y("button", {
|
|
322
322
|
class: "submit-button",
|
|
323
323
|
type: "submit",
|
|
@@ -334,14 +334,14 @@ const G = (t, s) => {
|
|
|
334
334
|
]));
|
|
335
335
|
}
|
|
336
336
|
});
|
|
337
|
-
const Ye = /* @__PURE__ */
|
|
337
|
+
const Ye = /* @__PURE__ */ q(Xe, [["__scopeId", "data-v-8326e5a5"]]), je = {
|
|
338
338
|
key: 0,
|
|
339
339
|
class: "modal-teleport"
|
|
340
|
-
},
|
|
340
|
+
}, Ke = {
|
|
341
341
|
name: "ModalProvider",
|
|
342
342
|
inheritAttrs: !0
|
|
343
|
-
},
|
|
344
|
-
...
|
|
343
|
+
}, qe = /* @__PURE__ */ Y({
|
|
344
|
+
...Ke,
|
|
345
345
|
props: {
|
|
346
346
|
appendToBody: { type: [Boolean, String], default: !1 },
|
|
347
347
|
sizes: { default: () => ({
|
|
@@ -353,13 +353,13 @@ const Ye = /* @__PURE__ */ G(Xe, [["__scopeId", "data-v-8326e5a5"]]), Ke = {
|
|
|
353
353
|
maxHeight: { default: "80%" }
|
|
354
354
|
},
|
|
355
355
|
setup(t, { expose: s }) {
|
|
356
|
-
const o = T([]), e = N(!1), l =
|
|
356
|
+
const o = T([]), e = N(!1), l = K();
|
|
357
357
|
function r(i, u = {}, a = {}) {
|
|
358
358
|
const m = be(
|
|
359
359
|
() => Promise.resolve(typeof i == "string" ? Ye : i)
|
|
360
360
|
);
|
|
361
361
|
typeof i == "string" && (u.type = i, a.size = "small", a.fullscreen = !1, a.mode = "dialog", a.footer = !1, a.header = !1);
|
|
362
|
-
const d = Math.random().toString(32).slice(2), _ = new Promise((M) => {
|
|
362
|
+
const d = Math.random().toString(32).slice(2), _ = new Promise((k, M) => {
|
|
363
363
|
o.value.push({
|
|
364
364
|
id: d,
|
|
365
365
|
component: m,
|
|
@@ -368,10 +368,12 @@ const Ye = /* @__PURE__ */ G(Xe, [["__scopeId", "data-v-8326e5a5"]]), Ke = {
|
|
|
368
368
|
...a,
|
|
369
369
|
type: typeof i == "string" ? i : "component"
|
|
370
370
|
},
|
|
371
|
-
resolve:
|
|
371
|
+
resolve: k,
|
|
372
|
+
reject: M,
|
|
372
373
|
listeners: []
|
|
373
374
|
}), O(o);
|
|
374
|
-
})
|
|
375
|
+
}).catch((k) => k === "CANCEL" ? new Promise(() => {
|
|
376
|
+
}) : Promise.reject(k));
|
|
375
377
|
return Object.assign(_, {
|
|
376
378
|
close: () => f(d)
|
|
377
379
|
});
|
|
@@ -381,7 +383,7 @@ const Ye = /* @__PURE__ */ G(Xe, [["__scopeId", "data-v-8326e5a5"]]), Ke = {
|
|
|
381
383
|
if (a < 0)
|
|
382
384
|
return;
|
|
383
385
|
const m = o.value[a];
|
|
384
|
-
m == null || m.resolve(u), o.value.splice(a, 1), O(o);
|
|
386
|
+
u === void 0 ? m == null || m.reject("CANCEL") : m == null || m.resolve(u), o.value.splice(a, 1), O(o);
|
|
385
387
|
}
|
|
386
388
|
function v() {
|
|
387
389
|
o.value.forEach((i) => {
|
|
@@ -435,11 +437,11 @@ const Ye = /* @__PURE__ */ G(Xe, [["__scopeId", "data-v-8326e5a5"]]), Ke = {
|
|
|
435
437
|
}), s({
|
|
436
438
|
elements: o,
|
|
437
439
|
open: r
|
|
438
|
-
}),
|
|
440
|
+
}), G(() => {
|
|
439
441
|
e.value = !0;
|
|
440
442
|
}), (i, u) => (h(), w(X, null, [
|
|
441
443
|
me(i.$slots, "default", {}, void 0, !0),
|
|
442
|
-
e.value ? (h(), w("div",
|
|
444
|
+
e.value ? (h(), w("div", je, [
|
|
443
445
|
(h(), F(ve, {
|
|
444
446
|
disabled: !i.appendToBody,
|
|
445
447
|
to: typeof i.appendToBody == "string" ? i.appendToBody : "body"
|
|
@@ -467,7 +469,7 @@ const Ye = /* @__PURE__ */ G(Xe, [["__scopeId", "data-v-8326e5a5"]]), Ke = {
|
|
|
467
469
|
], 64));
|
|
468
470
|
}
|
|
469
471
|
});
|
|
470
|
-
const Qe = /* @__PURE__ */
|
|
472
|
+
const Qe = /* @__PURE__ */ q(qe, [["__scopeId", "data-v-4ee644e1"]]);
|
|
471
473
|
function D(t, s) {
|
|
472
474
|
var e, l;
|
|
473
475
|
let o = t == null ? void 0 : t.parent;
|
|
@@ -475,8 +477,8 @@ function D(t, s) {
|
|
|
475
477
|
o = o.parent;
|
|
476
478
|
return ((l = o == null ? void 0 : o.type) == null ? void 0 : l.name) === s ? o : null;
|
|
477
479
|
}
|
|
478
|
-
function
|
|
479
|
-
const t =
|
|
480
|
+
function Ge() {
|
|
481
|
+
const t = j(H), s = K();
|
|
480
482
|
function o(e, l, r) {
|
|
481
483
|
if (!t)
|
|
482
484
|
throw new Error("Not Found Modal Provider Component");
|
|
@@ -535,7 +537,7 @@ function Ue() {
|
|
|
535
537
|
}
|
|
536
538
|
function Ze(t) {
|
|
537
539
|
var r;
|
|
538
|
-
const s =
|
|
540
|
+
const s = j(H), o = K(), e = D(o, "ModalContainer"), l = (r = e == null ? void 0 : e.props) == null ? void 0 : r.id;
|
|
539
541
|
s && l && s.addEventListener(l, "submit", t);
|
|
540
542
|
}
|
|
541
543
|
export {
|
|
@@ -543,5 +545,5 @@ export {
|
|
|
543
545
|
H as ModalKey,
|
|
544
546
|
Qe as ModalProvider,
|
|
545
547
|
Ze as onSubmit,
|
|
546
|
-
|
|
548
|
+
Ge as useModal
|
|
547
549
|
};
|
package/dist/es/interfaces.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface OpenModalOptions {
|
|
|
23
23
|
export interface ModalElement extends OpenModalOptions {
|
|
24
24
|
id: string;
|
|
25
25
|
resolve: (data?: any) => void;
|
|
26
|
+
reject: (key: 'CANCEL') => void;
|
|
26
27
|
component: Component;
|
|
27
28
|
props: Record<string, any>;
|
|
28
29
|
options: OpenModalOptions & {
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
*,:before,:after{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 rgb(0 0 0 / 0);--un-ring-shadow:0 0 rgb(0 0 0 / 0);--un-shadow-inset: ;--un-shadow:0 0 rgb(0 0 0 / 0);--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgb(147 197 253 / .5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }::backdrop{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 rgb(0 0 0 / 0);--un-ring-shadow:0 0 rgb(0 0 0 / 0);--un-shadow-inset: ;--un-shadow:0 0 rgb(0 0 0 / 0);--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgb(147 197 253 / .5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }.i-icon-park-outline\:close{--un-icon:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 48 48' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='4' d='m8 8l32 32M8 40L40 8'/%3E%3C/svg%3E");-webkit-mask:var(--un-icon) no-repeat;mask:var(--un-icon) no-repeat;-webkit-mask-size:100% 100%;mask-size:100% 100%;background-color:currentColor;color:inherit;width:1em;height:1em}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.block{display:block}.inline-block{display:inline-block}.flex{display:flex}.transform{transform:translate(var(--un-translate-x)) translateY(var(--un-translate-y)) translateZ(var(--un-translate-z)) rotate(var(--un-rotate)) rotateX(var(--un-rotate-x)) rotateY(var(--un-rotate-y)) rotate(var(--un-rotate-z)) skew(var(--un-skew-x)) skewY(var(--un-skew-y)) scaleX(var(--un-scale-x)) scaleY(var(--un-scale-y)) scaleZ(var(--un-scale-z))}.cursor-pointer{cursor:pointer}.resize{resize:both}.space-x-2>:not([hidden])~:not([hidden]){--un-space-x-reverse:0;margin-left:calc(.5rem * calc(1 - var(--un-space-x-reverse)));margin-right:calc(.5rem * var(--un-space-x-reverse))}.border{border-width:1px}.px{padding-left:1rem;padding-right:1rem}.font-bold{font-weight:700}.outline{outline-style:solid}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.ease{transition-timing-function:cubic-bezier(.4,0,.2,1)}.modal-wrapper[data-v-
|
|
1
|
+
*,:before,:after{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 rgb(0 0 0 / 0);--un-ring-shadow:0 0 rgb(0 0 0 / 0);--un-shadow-inset: ;--un-shadow:0 0 rgb(0 0 0 / 0);--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgb(147 197 253 / .5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }::backdrop{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 rgb(0 0 0 / 0);--un-ring-shadow:0 0 rgb(0 0 0 / 0);--un-shadow-inset: ;--un-shadow:0 0 rgb(0 0 0 / 0);--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgb(147 197 253 / .5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }.i-icon-park-outline\:close{--un-icon:url("data:image/svg+xml;utf8,%3Csvg viewBox='0 0 48 48' width='1em' height='1em' xmlns='http://www.w3.org/2000/svg' %3E%3Cpath fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='4' d='m8 8l32 32M8 40L40 8'/%3E%3C/svg%3E");-webkit-mask:var(--un-icon) no-repeat;mask:var(--un-icon) no-repeat;-webkit-mask-size:100% 100%;mask-size:100% 100%;background-color:currentColor;color:inherit;width:1em;height:1em}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.block{display:block}.inline-block{display:inline-block}.flex{display:flex}.transform{transform:translate(var(--un-translate-x)) translateY(var(--un-translate-y)) translateZ(var(--un-translate-z)) rotate(var(--un-rotate)) rotateX(var(--un-rotate-x)) rotateY(var(--un-rotate-y)) rotate(var(--un-rotate-z)) skew(var(--un-skew-x)) skewY(var(--un-skew-y)) scaleX(var(--un-scale-x)) scaleY(var(--un-scale-y)) scaleZ(var(--un-scale-z))}.cursor-pointer{cursor:pointer}.resize{resize:both}.space-x-2>:not([hidden])~:not([hidden]){--un-space-x-reverse:0;margin-left:calc(.5rem * calc(1 - var(--un-space-x-reverse)));margin-right:calc(.5rem * var(--un-space-x-reverse))}.border{border-width:1px}.px{padding-left:1rem;padding-right:1rem}.font-bold{font-weight:700}.outline{outline-style:solid}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.ease{transition-timing-function:cubic-bezier(.4,0,.2,1)}.modal-wrapper[data-v-7f0b9287]{z-index:1000;position:fixed;top:0;right:0;bottom:0;left:0;display:flex;align-items:center;background:rgba(0,0,0,.3)}.modal-content[data-v-7f0b9287]{background:#ffffff;border-radius:5px;position:relative}.modal-header[data-v-7f0b9287]{box-sizing:border-box;padding:10px;height:50px;display:flex;justify-content:space-between;align-items:center;border-bottom:solid 1px var(--color-border-1, #e8e8e8)}.modal-body[data-v-7f0b9287]{padding:20px 10px;box-sizing:border-box;max-height:10vw;overflow:auto}.modal-footer[data-v-7f0b9287]{box-sizing:border-box;height:50px;border-top:solid 1px var(--color-border-1, #e8e8e8);display:flex;justify-content:end;padding:10px}.modal-footer button[data-v-7f0b9287]{height:28px;line-height:28px;width:80px;outline:none;border-color:transparent;font-size:14px;border-radius:4px;padding:0;box-sizing:content-box}.modal-footer button.submit-button[data-v-7f0b9287]{color:#fff;background-color:rgb(var(--primary-6, 45, 106, 251))}.modal-footer button.submit-button[data-v-7f0b9287]:hover{background-color:rgb(var(--primary-5, 28, 76, 207))}.modal-footer button.cancel-button[data-v-7f0b9287]{color:rgb(var(--color-text-2, 78, 89, 105));background-color:var(--color-fill-1, #f5f5f5)}.modal-footer button.cancel-button[data-v-7f0b9287]:hover{background-color:var(--color-fill-4, #c9cdd4)}.modal-loading[data-v-7f0b9287]{position:absolute;z-index:1001;top:0;right:0;bottom:0;left:0;display:flex;justify-content:center;align-items:center;background-color:#0000001a}.modal-loading .lds-ring[data-v-7f0b9287]{display:inline-block;position:relative;width:80px;height:80px}.modal-loading .lds-ring div[data-v-7f0b9287]{box-sizing:border-box;display:block;position:absolute;width:48px;height:48px;margin:8px;border:5px solid #fff;border-radius:50%;animation:lds-ring-7f0b9287 1.2s cubic-bezier(.5,0,.5,1) infinite;border-color:#fff transparent transparent transparent}.modal-loading .lds-ring div[data-v-7f0b9287]:nth-child(1){animation-delay:-.45s}.modal-loading .lds-ring div[data-v-7f0b9287]:nth-child(2){animation-delay:-.3s}.modal-loading .lds-ring div[data-v-7f0b9287]:nth-child(3){animation-delay:-.15s}@keyframes lds-ring-7f0b9287{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.dialog-body[data-v-8326e5a5]{padding:20px 10px 10px}.dialog-title[data-v-8326e5a5]{padding:5px;font-weight:700;font-size:16px}.dialog-content[data-v-8326e5a5]{padding:5px}.dialog-footer[data-v-8326e5a5]{box-sizing:border-box;height:50px;border-top:solid 1px var(--color-border-1, #e8e8e8);display:flex;justify-content:center;align-items:center;padding:0 10px}.dialog-footer button[data-v-8326e5a5]{height:28px;line-height:28px;width:80px;outline:none;border-color:transparent;font-size:14px;border-radius:4px;padding:0;box-sizing:content-box}.dialog-footer button.submit-button[data-v-8326e5a5]{color:#fff;background-color:rgb(var(--primary-6, 45, 106, 251))}.dialog-footer button.submit-button[data-v-8326e5a5]:hover{background-color:rgb(var(--primary-5, 28, 76, 207))}.dialog-footer button.cancel-button[data-v-8326e5a5]{color:rgb(var(--color-text-2, 78, 89, 105));background-color:var(--color-fill-1, #f5f5f5)}.dialog-footer button.cancel-button[data-v-8326e5a5]:hover{background-color:var(--color-fill-4, #c9cdd4)}.modal-fade-enter-active[data-v-4ee644e1],.modal-fade-leave-active[data-v-4ee644e1]{transition:opacity .5s ease}.modal-fade-enter-active[data-v-4ee644e1] .modal-content.drawer-mode,.modal-fade-leave-active[data-v-4ee644e1] .modal-content.drawer-mode{transition:transform .5s ease}.modal-fade-enter-from[data-v-4ee644e1],.modal-fade-leave-to[data-v-4ee644e1]{opacity:0}.modal-fade-enter-from[data-v-4ee644e1] .modal-content.drawer-mode,.modal-fade-leave-to[data-v-4ee644e1] .modal-content.drawer-mode{transform:translate3d(100%,0,0)}
|