@gopowerteam/modal-render 0.0.3 → 0.0.4

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.
@@ -17,6 +17,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
17
17
  esc?: boolean;
18
18
  maskClosable?: boolean;
19
19
  draggable?: boolean;
20
+ mode?: 'dialog' | 'drawer';
20
21
  }>, {
21
22
  header: boolean;
22
23
  closeable: boolean;
@@ -26,6 +27,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
26
27
  size: string;
27
28
  esc: boolean;
28
29
  draggable: boolean;
30
+ mode: string;
29
31
  }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
30
32
  submit: (...args: any[]) => void;
31
33
  }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
@@ -45,6 +47,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
45
47
  esc?: boolean;
46
48
  maskClosable?: boolean;
47
49
  draggable?: boolean;
50
+ mode?: 'dialog' | 'drawer';
48
51
  }>, {
49
52
  header: boolean;
50
53
  closeable: boolean;
@@ -54,6 +57,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
54
57
  size: string;
55
58
  esc: boolean;
56
59
  draggable: boolean;
60
+ mode: string;
57
61
  }>>> & {
58
62
  onSubmit?: (...args: any[]) => any;
59
63
  }, {
@@ -64,6 +68,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
64
68
  size: 'small' | 'middle' | 'large' | 'fullscreen';
65
69
  esc: boolean;
66
70
  draggable: boolean;
71
+ mode: 'dialog' | 'drawer';
67
72
  }, {}>;
68
73
  export default _default;
69
74
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue");const C=Symbol("__MODAL__");function O(o){return e.getCurrentScope()?(e.onScopeDispose(o),!0):!1}function g(o){return typeof o=="function"?o():e.unref(o)}const V=typeof window<"u"&&typeof document<"u",D=Object.prototype.toString,W=o=>D.call(o)==="[object Object]",T=()=>{};function F(o,s={}){if(!e.isRef(o))return e.toRefs(o);const t=Array.isArray(o.value)?Array.from({length:o.value.length}):{};for(const r in o.value)t[r]=e.customRef(()=>({get(){return o.value[r]},set(l){var d;if((d=g(s.replaceRef))!=null?d:!0)if(Array.isArray(o.value)){const m=[...o.value];m[r]=l,o.value=m}else{const m={...o.value,[r]:l};Object.setPrototypeOf(m,Object.getPrototypeOf(o.value)),o.value=m}else o.value[r]=l}}));return t}function H(o){var s;const t=g(o);return(s=t==null?void 0:t.$el)!=null?s:t}const R=V?window:void 0;function z(...o){let s,t,r,l;if(typeof o[0]=="string"||Array.isArray(o[0])?([t,r,l]=o,s=R):[s,t,r,l]=o,!s)return T;Array.isArray(t)||(t=[t]),Array.isArray(r)||(r=[r]);const d=[],y=()=>{d.forEach(u=>u()),d.length=0},m=(u,a,f,p)=>(u.addEventListener(a,f,p),()=>u.removeEventListener(a,f,p)),v=e.watch(()=>[H(s),g(l)],([u,a])=>{if(y(),!u)return;const f=W(a)?{...a}:a;d.push(...t.flatMap(p=>r.map(b=>m(u,p,b,f))))},{immediate:!0,flush:"post"}),c=()=>{v(),y()};return O(c),c}function I(o,s={}){var t,r;const{pointerTypes:l,preventDefault:d,stopPropagation:y,exact:m,onMove:v,onEnd:c,onStart:u,initialValue:a,axis:f="both",draggingElement:p=R,containerElement:b,handle:x=o}=s,h=e.ref((t=g(a))!=null?t:{x:0,y:0}),_=e.ref(),k=i=>l?l.includes(i.pointerType):!0,E=i=>{g(d)&&i.preventDefault(),g(y)&&i.stopPropagation()},M=i=>{var w;if(!k(i)||g(m)&&i.target!==g(o))return;const P=((w=g(b))!=null?w:g(o)).getBoundingClientRect(),N={x:i.clientX-P.left,y:i.clientY-P.top};(u==null?void 0:u(N,i))!==!1&&(_.value=N,E(i))},S=i=>{if(!k(i)||!_.value)return;let{x:w,y:B}=h.value;(f==="x"||f==="both")&&(w=i.clientX-_.value.x),(f==="y"||f==="both")&&(B=i.clientY-_.value.y),h.value={x:w,y:B},v==null||v(h.value,i),E(i)},n=i=>{k(i)&&_.value&&(_.value=void 0,c==null||c(h.value,i),E(i))};if(V){const i={capture:(r=s.capture)!=null?r:!0};z(x,"pointerdown",M,i),z(p,"pointermove",S,i),z(p,"pointerup",n,i)}return{...F(h),position:h,isDragging:e.computed(()=>!!_.value),style:e.computed(()=>`left:${h.value.x}px;top:${h.value.y}px;`)}}const X={class:"modal-container"},Y={class:"title font-bold"},q={class:"action"},K={key:1,class:"modal-footer space-x-2"},G=["form"],U={name:"ModalContainer",inheritAttrs:!0},J=e.defineComponent({...U,props:{id:{},form:{},component:{},componentProps:{},width:{},maxWidth:{},maxHeight:{},sizes:{},size:{default:"middle"},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}},emits:["submit"],setup(o,{emit:s}){const t=o,r=s,l=e.inject(C);let d=0,y=0;const m=e.shallowRef(),v=e.shallowRef(),c=e.shallowRef(),{x:u,y:a}=I(c,{initialValue:{x:0,y:0}});function f(){l==null||l.close(t.id)}function p(n){if(typeof n=="number")return`${n}px`;if(typeof n=="string")return n}const b=e.computed(()=>{const n={};return t.size&&(n.width=p(t.sizes[t.size])),t.width&&(n.width=p(t.width)),t.maxWidth&&(n.maxWidth=p(t.maxWidth)),t.size==="fullscreen"&&(n.maxWidth="unset",n.position="fixed",n.top=0,n.left=0,n.bottom=0,n.right=0),t.draggable&&t.size!=="fullscreen"&&(n.transform=`translate(${u.value-d}px, ${a.value-y}px)`),n}),x=e.computed(()=>{const n={};return t.draggable&&t.size!=="fullscreen"&&(n.cursor="move"),n}),h=e.computed(()=>{var i;const n={};return t.maxHeight&&(n.maxHeight=`calc(${(i=p(t.maxWidth))==null?void 0:i.replace("%","vh")} - 50px)`),t.size==="fullscreen"&&(n.maxHeight="calc(100% - 50px)"),n});function _(){const n=v.value;if(t.form&&n){const i=n.querySelector(`form[name="${t.form}"]`);i&&i.dispatchEvent(new Event("submit"))}r("submit")}function k(){l==null||l.close(t.id)}function E(){window&&window.addEventListener("resize",()=>{e.triggerRef(m),e.triggerRef(v),d=v.value.offsetLeft,y=v.value.offsetTop})}function M(){if(t.closeable&&t.esc){const n=({key:i})=>{i==="Escape"&&(l==null||l.close(t.id),window.removeEventListener("keydown",n))};window.addEventListener("keydown",n)}}function S(){d=v.value.offsetLeft,y=v.value.offsetTop}return e.onMounted(()=>{M(),E()}),e.onUnmounted(()=>{}),(n,i)=>(e.openBlock(),e.createElementBlock("div",X,[e.createElementVNode("div",{ref_key:"wrapperRef",ref:m,class:"modal-wrapper",onClick:i[0]||(i[0]=e.withModifiers(w=>n.maskClosable&&f(),["self"]))},[e.createElementVNode("div",{ref_key:"contentRef",ref:v,class:"modal-content",style:e.normalizeStyle(b.value)},[n.header?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"headerRef",ref:c,class:"modal-header",style:e.normalizeStyle(x.value),onMousedown:S},[e.createElementVNode("div",Y,e.toDisplayString(n.title),1),e.createElementVNode("div",q,[n.closeable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"i-icon-park-outline:close block cursor-pointer",onClick:f})):e.createCommentVNode("",!0)])],36)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"modal-body",style:e.normalizeStyle(h.value)},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.component),e.normalizeProps(e.guardReactiveProps(n.componentProps)),null,16))],4),n.footer?(e.openBlock(),e.createElementBlock("div",K,[e.createElementVNode("button",{class:"submit-button",form:n.form,type:"submit",onClick:_}," 确定 ",8,G),e.createElementVNode("button",{class:"cancel-button",type:"button",onClick:k}," 取消 ")])):e.createCommentVNode("",!0)],4)],512)]))}});const $=(o,s)=>{const t=o.__vccOpts||o;for(const[r,l]of s)t[r]=l;return t},L=$(J,[["__scopeId","data-v-05b670ad"]]),Q={key:0,class:"modal-teleport"},Z={name:"ModalProvider",inheritAttrs:!0},j=e.defineComponent({...Z,props:{appendToBody:{type:Boolean,default:!1},sizes:{default:()=>({small:520,middle:860,large:1190})},maxWidth:{default:"80%"},maxHeight:{default:"80%"}},setup(o,{expose:s}){const t=e.shallowRef([]),r=e.ref(!1);async function l(c,u,a){const f=e.defineAsyncComponent(()=>Promise.resolve(c));return new Promise(p=>{t.value.push({id:Math.random().toString(32).slice(2),component:f,props:u,options:a,resolve:p,onSubmit:e.ref(()=>{})}),e.triggerRef(t)})}function d(c,u){const a=t.value.findIndex(p=>p.id===c);if(a<0)return;const f=t.value[a];f==null||f.resolve(u),t.value.splice(a,1),e.triggerRef(t)}function y(){t.value.forEach(c=>{c.resolve()}),t.value=[],e.triggerRef(t)}function m(c){return t.value.find(u=>u.id===c)}function v(c,u){const a=t.value.find(f=>f.id===c);a&&(a.onSubmit.value=u)}return e.provide(C,{open:l,close:d,closeAll:y,getElement:m,addSubmitListener:v}),s({elements:t}),e.onMounted(()=>{r.value=!0}),(c,u)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.renderSlot(c.$slots,"default",{},void 0,!0),r.value?(e.openBlock(),e.createElementBlock("div",Q,[(e.openBlock(),e.createBlock(e.Teleport,{disabled:!c.appendToBody,to:"body"},[e.createVNode(e.TransitionGroup,{name:"modal-fade"},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.value,a=>(e.openBlock(),e.createBlock(L,e.mergeProps({id:a.id,key:a.id,component:a.component,"component-props":a.props,"max-height":c.maxHeight,"max-width":c.maxWidth,sizes:c.sizes},a.options,{onSubmit:a.onSubmit.value}),null,16,["id","component","component-props","max-height","max-width","sizes","onSubmit"]))),128))]),_:1})],8,["disabled"]))])):e.createCommentVNode("",!0)],64))}});const ee=$(j,[["__scopeId","data-v-171d9bdd"]]);function A(o,s){var r,l;let t=o==null?void 0:o.parent;for(;t&&((r=t==null?void 0:t.type)==null?void 0:r.name)!==s;)t=t.parent;return((l=t==null?void 0:t.type)==null?void 0:l.name)===s?t:null}function te(){const o=e.inject(C),s=e.getCurrentInstance();return{open(t,r,l){if(!o)throw new Error("Not Found Modal Provider Component");return o.open(t,r||{},l||{})},close(t){var d;if(!o)throw new Error("Not Found Modal Provider Component");const r=A(s,"ModalContainer"),l=(d=r==null?void 0:r.props)==null?void 0:d.id;if(!l)throw new Error("Not Found Current Modal Container");o.close(l,t)},closeAll(){if(!o)throw new Error("Not Found Modal Provider Component");o.closeAll()},onSubmit(t){const r=A(s,"ModalContainer");if(!(r==null?void 0:r.props.id))throw new Error("Not Found Current Modal Container")}}}function oe(o){var d;const s=e.inject(C),t=e.getCurrentInstance(),r=A(t,"ModalContainer"),l=(d=r==null?void 0:r.props)==null?void 0:d.id;s&&l&&s.addSubmitListener(l,o)}exports.ModalContainer=L;exports.ModalProvider=ee;exports.onSubmit=oe;exports.useModal=te;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue");const E=Symbol("__MODAL__");function O(n){return e.getCurrentScope()?(e.onScopeDispose(n),!0):!1}function g(n){return typeof n=="function"?n():e.unref(n)}const V=typeof window<"u"&&typeof document<"u",D=Object.prototype.toString,H=n=>D.call(n)==="[object Object]",T=()=>{};function W(n,i={}){if(!e.isRef(n))return e.toRefs(n);const t=Array.isArray(n.value)?Array.from({length:n.value.length}):{};for(const r in n.value)t[r]=e.customRef(()=>({get(){return n.value[r]},set(l){var u;if((u=g(i.replaceRef))!=null?u:!0)if(Array.isArray(n.value)){const m=[...n.value];m[r]=l,n.value=m}else{const m={...n.value,[r]:l};Object.setPrototypeOf(m,Object.getPrototypeOf(n.value)),n.value=m}else n.value[r]=l}}));return t}function F(n){var i;const t=g(n);return(i=t==null?void 0:t.$el)!=null?i:t}const $=V?window:void 0;function z(...n){let i,t,r,l;if(typeof n[0]=="string"||Array.isArray(n[0])?([t,r,l]=n,i=$):[i,t,r,l]=n,!i)return T;Array.isArray(t)||(t=[t]),Array.isArray(r)||(r=[r]);const u=[],y=()=>{u.forEach(c=>c()),u.length=0},m=(c,s,d,f)=>(c.addEventListener(s,d,f),()=>c.removeEventListener(s,d,f)),v=e.watch(()=>[F(i),g(l)],([c,s])=>{if(y(),!c)return;const d=H(s)?{...s}:s;u.push(...t.flatMap(f=>r.map(w=>m(c,f,w,d))))},{immediate:!0,flush:"post"}),a=()=>{v(),y()};return O(a),a}function I(n,i={}){var t,r;const{pointerTypes:l,preventDefault:u,stopPropagation:y,exact:m,onMove:v,onEnd:a,onStart:c,initialValue:s,axis:d="both",draggingElement:f=$,containerElement:w,handle:x=n}=i,h=e.ref((t=g(s))!=null?t:{x:0,y:0}),_=e.ref(),b=o=>l?l.includes(o.pointerType):!0,k=o=>{g(u)&&o.preventDefault(),g(y)&&o.stopPropagation()},S=o=>{var p;if(!b(o)||g(m)&&o.target!==g(n))return;const P=((p=g(w))!=null?p:g(n)).getBoundingClientRect(),N={x:o.clientX-P.left,y:o.clientY-P.top};(c==null?void 0:c(N,o))!==!1&&(_.value=N,k(o))},M=o=>{if(!b(o)||!_.value)return;let{x:p,y:C}=h.value;(d==="x"||d==="both")&&(p=o.clientX-_.value.x),(d==="y"||d==="both")&&(C=o.clientY-_.value.y),h.value={x:p,y:C},v==null||v(h.value,o),k(o)},B=o=>{b(o)&&_.value&&(_.value=void 0,a==null||a(h.value,o),k(o))};if(V){const o={capture:(r=i.capture)!=null?r:!0};z(x,"pointerdown",S,o),z(f,"pointermove",M,o),z(f,"pointerup",B,o)}return{...W(h),position:h,isDragging:e.computed(()=>!!_.value),style:e.computed(()=>`left:${h.value.x}px;top:${h.value.y}px;`)}}const X={class:"modal-container fixed inset-0"},Y={class:"title font-bold"},q={class:"action"},K={key:1,class:"modal-footer space-x-2"},j=["form"],G={name:"ModalContainer",inheritAttrs:!0},U=e.defineComponent({...G,props:{id:{},form:{},component:{},componentProps:{},width:{},maxWidth:{},maxHeight:{},sizes:{},size:{default:"middle"},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"}},emits:["submit"],setup(n,{emit:i}){const t=n,r=i,l=e.inject(E);let u=0,y=0;const m=e.shallowRef(),v=e.shallowRef(),a=e.shallowRef(),{x:c,y:s}=I(a,{initialValue:{x:0,y:0}});function d(){l==null||l.close(t.id)}function f(o){if(typeof o=="number")return`${o}px`;if(typeof o=="string")return o}const w=e.computed(()=>{const o={};return t.mode==="dialog"&&(o.justifyContent="center"),t.mode==="drawer"&&(o.justifyContent="flex-end"),o}),x=e.computed(()=>{const o={};return t.size&&(o.width=f(t.sizes[t.size])),t.width&&(o.width=f(t.width)),t.maxWidth&&(o.maxWidth=f(t.maxWidth)),t.size==="fullscreen"&&(o.maxWidth="unset",o.position="fixed",o.top=0,o.left=0,o.bottom=0,o.right=0),t.draggable&&t.size!=="fullscreen"&&t.mode==="dialog"&&(o.transform=`translate3d(${c.value-u}px, ${s.value-y}px, 0px)`),o}),h=e.computed(()=>{const o={};return t.draggable&&t.size!=="fullscreen"&&t.mode==="dialog"&&(o.cursor="move"),o}),_=e.computed(()=>{var p;const o={};return t.maxHeight&&(o.maxHeight=`calc(${(p=f(t.maxHeight))==null?void 0:p.replace("%","vh")} - 50px)`),t.mode==="drawer"&&(o.maxHeight=`calc(100vh - ${(t.header?50:0)+(t.footer?50:0)}px)`),t.size==="fullscreen"&&(o.maxHeight=`calc(100vh - ${(t.header?50:0)+(t.footer?50:0)}px)`),o});function b(){const o=v.value;if(t.form&&o){const p=o.querySelector(`form[name="${t.form}"]`);p&&p.dispatchEvent(new Event("submit"))}r("submit")}function k(){l==null||l.close(t.id)}function S(){window&&window.addEventListener("resize",()=>{e.triggerRef(m),e.triggerRef(v),u=v.value.offsetLeft,y=v.value.offsetTop})}function M(){if(t.closeable&&t.esc){const o=({key:p})=>{p==="Escape"&&(l==null||l.close(t.id),window.removeEventListener("keydown",o))};window.addEventListener("keydown",o)}}function B(){u=v.value.offsetLeft,y=v.value.offsetTop}return e.onMounted(()=>{M(),S()}),e.onUnmounted(()=>{}),(o,p)=>(e.openBlock(),e.createElementBlock("div",X,[e.createElementVNode("div",{ref_key:"wrapperRef",ref:m,class:"modal-wrapper",style:e.normalizeStyle(w.value),onClick:p[0]||(p[0]=e.withModifiers(C=>o.maskClosable&&d(),["self"]))},[e.createElementVNode("div",{ref_key:"contentRef",ref:v,class:e.normalizeClass(["modal-content",{[`${o.mode}-mode`]:!0}]),style:e.normalizeStyle(x.value)},[o.header?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"headerRef",ref:a,class:"modal-header",style:e.normalizeStyle(h.value),onMousedown:B},[e.createElementVNode("div",Y,e.toDisplayString(o.title),1),e.createElementVNode("div",q,[o.closeable?(e.openBlock(),e.createElementBlock("div",{key:0,class:"i-icon-park-outline:close block cursor-pointer",onClick:d})):e.createCommentVNode("",!0)])],36)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"modal-body",style:e.normalizeStyle(_.value)},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(o.component),e.normalizeProps(e.guardReactiveProps(o.componentProps)),null,16))],4),o.footer?(e.openBlock(),e.createElementBlock("div",K,[e.createElementVNode("button",{class:"submit-button",form:o.form,type:"submit",onClick:b}," 确定 ",8,j),e.createElementVNode("button",{class:"cancel-button",type:"button",onClick:k}," 取消 ")])):e.createCommentVNode("",!0)],6)],4)]))}});const R=(n,i)=>{const t=n.__vccOpts||n;for(const[r,l]of i)t[r]=l;return t},L=R(U,[["__scopeId","data-v-581eba51"]]),J={key:0,class:"modal-teleport"},Q={name:"ModalProvider",inheritAttrs:!0},Z=e.defineComponent({...Q,props:{appendToBody:{type:Boolean,default:!1},sizes:{default:()=>({small:520,middle:860,large:1190})},maxWidth:{default:"80%"},maxHeight:{default:"80%"}},setup(n,{expose:i}){const t=e.shallowRef([]),r=e.ref(!1);async function l(a,c,s){const d=e.defineAsyncComponent(()=>Promise.resolve(a));return new Promise(f=>{t.value.push({id:Math.random().toString(32).slice(2),component:d,props:c,options:s,resolve:f,onSubmit:e.ref(()=>{})}),e.triggerRef(t)})}function u(a,c){const s=t.value.findIndex(f=>f.id===a);if(s<0)return;const d=t.value[s];d==null||d.resolve(c),t.value.splice(s,1),e.triggerRef(t)}function y(){t.value.forEach(a=>{a.resolve()}),t.value=[],e.triggerRef(t)}function m(a){return t.value.find(c=>c.id===a)}function v(a,c){const s=t.value.find(d=>d.id===a);s&&(s.onSubmit.value=c)}return e.provide(E,{open:l,close:u,closeAll:y,getElement:m,addSubmitListener:v}),i({elements:t}),e.onMounted(()=>{r.value=!0}),(a,c)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.renderSlot(a.$slots,"default",{},void 0,!0),r.value?(e.openBlock(),e.createElementBlock("div",J,[(e.openBlock(),e.createBlock(e.Teleport,{disabled:!a.appendToBody,to:"body"},[e.createVNode(e.TransitionGroup,{name:"modal-fade"},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.value,s=>(e.openBlock(),e.createBlock(L,e.mergeProps({id:s.id,key:s.id,component:s.component,"component-props":s.props,"max-height":a.maxHeight,"max-width":a.maxWidth,sizes:a.sizes},s.options,{onSubmit:s.onSubmit.value}),null,16,["id","component","component-props","max-height","max-width","sizes","onSubmit"]))),128))]),_:1})],8,["disabled"]))])):e.createCommentVNode("",!0)],64))}});const ee=R(Z,[["__scopeId","data-v-1ef03c20"]]);function A(n,i){var r,l;let t=n==null?void 0:n.parent;for(;t&&((r=t==null?void 0:t.type)==null?void 0:r.name)!==i;)t=t.parent;return((l=t==null?void 0:t.type)==null?void 0:l.name)===i?t:null}function te(){const n=e.inject(E),i=e.getCurrentInstance();return{open(t,r,l){if(!n)throw new Error("Not Found Modal Provider Component");return n.open(t,r||{},l||{})},close(t){var u;if(!n)throw new Error("Not Found Modal Provider Component");const r=A(i,"ModalContainer"),l=(u=r==null?void 0:r.props)==null?void 0:u.id;if(!l)throw new Error("Not Found Current Modal Container");n.close(l,t)},closeAll(){if(!n)throw new Error("Not Found Modal Provider Component");n.closeAll()},onSubmit(t){const r=A(i,"ModalContainer");if(!(r==null?void 0:r.props.id))throw new Error("Not Found Current Modal Container")}}}function oe(n){var u;const i=e.inject(E),t=e.getCurrentInstance(),r=A(t,"ModalContainer"),l=(u=r==null?void 0:r.props)==null?void 0:u.id;i&&l&&i.addSubmitListener(l,n)}exports.ModalContainer=L;exports.ModalProvider=ee;exports.onSubmit=oe;exports.useModal=te;
package/dist/index.js CHANGED
@@ -1,127 +1,127 @@
1
- import { unref as J, isRef as Q, toRefs as Z, customRef as j, getCurrentScope as ee, onScopeDispose as te, ref as P, computed as S, watch as ne, defineComponent as X, inject as R, shallowRef as A, onMounted as Y, onUnmounted as oe, openBlock as _, createElementBlock as b, createElementVNode as w, withModifiers as re, normalizeStyle as W, toDisplayString as ie, createCommentVNode as z, createBlock as T, resolveDynamicComponent as se, normalizeProps as le, guardReactiveProps as ae, triggerRef as k, provide as ue, Fragment as I, renderSlot as ce, Teleport as de, createVNode as fe, TransitionGroup as pe, withCtx as me, renderList as ve, mergeProps as ye, defineAsyncComponent as he, getCurrentInstance as K } from "vue";
2
- const $ = Symbol("__MODAL__");
3
- function _e(t) {
4
- return ee() ? (te(t), !0) : !1;
1
+ import { unref as J, isRef as Q, toRefs as Z, customRef as j, getCurrentScope as ee, onScopeDispose as te, ref as $, computed as x, watch as oe, defineComponent as X, inject as R, shallowRef as A, onMounted as Y, onUnmounted as ne, openBlock as g, createElementBlock as b, createElementVNode as w, normalizeStyle as z, withModifiers as re, normalizeClass as ie, toDisplayString as se, createCommentVNode as P, createBlock as N, resolveDynamicComponent as le, normalizeProps as ae, guardReactiveProps as ue, triggerRef as S, provide as de, Fragment as I, renderSlot as ce, Teleport as fe, createVNode as pe, TransitionGroup as me, withCtx as ve, renderList as ye, mergeProps as he, defineAsyncComponent as ge, getCurrentInstance as K } from "vue";
2
+ const B = Symbol("__MODAL__");
3
+ function _e(o) {
4
+ return ee() ? (te(o), !0) : !1;
5
5
  }
6
- function h(t) {
7
- return typeof t == "function" ? t() : J(t);
6
+ function h(o) {
7
+ return typeof o == "function" ? o() : J(o);
8
8
  }
9
- const q = typeof window < "u" && typeof document < "u", ge = Object.prototype.toString, we = (t) => ge.call(t) === "[object Object]", be = () => {
9
+ const q = typeof window < "u" && typeof document < "u", we = Object.prototype.toString, be = (o) => we.call(o) === "[object Object]", xe = () => {
10
10
  };
11
- function xe(t, s = {}) {
12
- if (!Q(t))
13
- return Z(t);
14
- const e = Array.isArray(t.value) ? Array.from({ length: t.value.length }) : {};
15
- for (const o in t.value)
16
- e[o] = j(() => ({
11
+ function Ce(o, i = {}) {
12
+ if (!Q(o))
13
+ return Z(o);
14
+ const e = Array.isArray(o.value) ? Array.from({ length: o.value.length }) : {};
15
+ for (const n in o.value)
16
+ e[n] = j(() => ({
17
17
  get() {
18
- return t.value[o];
18
+ return o.value[n];
19
19
  },
20
20
  set(r) {
21
- var c;
22
- if ((c = h(s.replaceRef)) != null ? c : !0)
23
- if (Array.isArray(t.value)) {
24
- const p = [...t.value];
25
- p[o] = r, t.value = p;
21
+ var u;
22
+ if ((u = h(i.replaceRef)) != null ? u : !0)
23
+ if (Array.isArray(o.value)) {
24
+ const p = [...o.value];
25
+ p[n] = r, o.value = p;
26
26
  } else {
27
- const p = { ...t.value, [o]: r };
28
- Object.setPrototypeOf(p, Object.getPrototypeOf(t.value)), t.value = p;
27
+ const p = { ...o.value, [n]: r };
28
+ Object.setPrototypeOf(p, Object.getPrototypeOf(o.value)), o.value = p;
29
29
  }
30
30
  else
31
- t.value[o] = r;
31
+ o.value[n] = r;
32
32
  }
33
33
  }));
34
34
  return e;
35
35
  }
36
- function Ce(t) {
37
- var s;
38
- const e = h(t);
39
- return (s = e == null ? void 0 : e.$el) != null ? s : e;
36
+ function Ee(o) {
37
+ var i;
38
+ const e = h(o);
39
+ return (i = e == null ? void 0 : e.$el) != null ? i : e;
40
40
  }
41
41
  const G = q ? window : void 0;
42
- function N(...t) {
43
- let s, e, o, r;
44
- if (typeof t[0] == "string" || Array.isArray(t[0]) ? ([e, o, r] = t, s = G) : [s, e, o, r] = t, !s)
45
- return be;
46
- Array.isArray(e) || (e = [e]), Array.isArray(o) || (o = [o]);
47
- const c = [], v = () => {
48
- c.forEach((u) => u()), c.length = 0;
49
- }, p = (u, l, d, f) => (u.addEventListener(l, d, f), () => u.removeEventListener(l, d, f)), m = ne(
50
- () => [Ce(s), h(r)],
51
- ([u, l]) => {
52
- if (v(), !u)
42
+ function W(...o) {
43
+ let i, e, n, r;
44
+ if (typeof o[0] == "string" || Array.isArray(o[0]) ? ([e, n, r] = o, i = G) : [i, e, n, r] = o, !i)
45
+ return xe;
46
+ Array.isArray(e) || (e = [e]), Array.isArray(n) || (n = [n]);
47
+ const u = [], v = () => {
48
+ u.forEach((a) => a()), u.length = 0;
49
+ }, p = (a, s, d, c) => (a.addEventListener(s, d, c), () => a.removeEventListener(s, d, c)), m = oe(
50
+ () => [Ee(i), h(r)],
51
+ ([a, s]) => {
52
+ if (v(), !a)
53
53
  return;
54
- const d = we(l) ? { ...l } : l;
55
- c.push(
56
- ...e.flatMap((f) => o.map((C) => p(u, f, C, d)))
54
+ const d = be(s) ? { ...s } : s;
55
+ u.push(
56
+ ...e.flatMap((c) => n.map((C) => p(a, c, C, d)))
57
57
  );
58
58
  },
59
59
  { immediate: !0, flush: "post" }
60
- ), a = () => {
60
+ ), l = () => {
61
61
  m(), v();
62
62
  };
63
- return _e(a), a;
63
+ return _e(l), l;
64
64
  }
65
- function Ee(t, s = {}) {
66
- var e, o;
65
+ function Me(o, i = {}) {
66
+ var e, n;
67
67
  const {
68
68
  pointerTypes: r,
69
- preventDefault: c,
69
+ preventDefault: u,
70
70
  stopPropagation: v,
71
71
  exact: p,
72
72
  onMove: m,
73
- onEnd: a,
74
- onStart: u,
75
- initialValue: l,
73
+ onEnd: l,
74
+ onStart: a,
75
+ initialValue: s,
76
76
  axis: d = "both",
77
- draggingElement: f = G,
77
+ draggingElement: c = G,
78
78
  containerElement: C,
79
- handle: B = t
80
- } = s, y = P(
81
- (e = h(l)) != null ? e : { x: 0, y: 0 }
82
- ), g = P(), E = (i) => r ? r.includes(i.pointerType) : !0, M = (i) => {
83
- h(c) && i.preventDefault(), h(v) && i.stopPropagation();
84
- }, L = (i) => {
85
- var x;
86
- if (!E(i) || h(p) && i.target !== h(t))
79
+ handle: L = o
80
+ } = i, y = $(
81
+ (e = h(s)) != null ? e : { x: 0, y: 0 }
82
+ ), _ = $(), E = (t) => r ? r.includes(t.pointerType) : !0, M = (t) => {
83
+ h(u) && t.preventDefault(), h(v) && t.stopPropagation();
84
+ }, D = (t) => {
85
+ var f;
86
+ if (!E(t) || h(p) && t.target !== h(o))
87
87
  return;
88
- const V = ((x = h(C)) != null ? x : h(t)).getBoundingClientRect(), F = {
89
- x: i.clientX - V.left,
90
- y: i.clientY - V.top
88
+ const V = ((f = h(C)) != null ? f : h(o)).getBoundingClientRect(), F = {
89
+ x: t.clientX - V.left,
90
+ y: t.clientY - V.top
91
91
  };
92
- (u == null ? void 0 : u(F, i)) !== !1 && (g.value = F, M(i));
93
- }, D = (i) => {
94
- if (!E(i) || !g.value)
92
+ (a == null ? void 0 : a(F, t)) !== !1 && (_.value = F, M(t));
93
+ }, O = (t) => {
94
+ if (!E(t) || !_.value)
95
95
  return;
96
- let { x, y: O } = y.value;
97
- (d === "x" || d === "both") && (x = i.clientX - g.value.x), (d === "y" || d === "both") && (O = i.clientY - g.value.y), y.value = {
98
- x,
99
- y: O
100
- }, m == null || m(y.value, i), M(i);
101
- }, n = (i) => {
102
- E(i) && g.value && (g.value = void 0, a == null || a(y.value, i), M(i));
96
+ let { x: f, y: k } = y.value;
97
+ (d === "x" || d === "both") && (f = t.clientX - _.value.x), (d === "y" || d === "both") && (k = t.clientY - _.value.y), y.value = {
98
+ x: f,
99
+ y: k
100
+ }, m == null || m(y.value, t), M(t);
101
+ }, H = (t) => {
102
+ E(t) && _.value && (_.value = void 0, l == null || l(y.value, t), M(t));
103
103
  };
104
104
  if (q) {
105
- const i = { capture: (o = s.capture) != null ? o : !0 };
106
- N(B, "pointerdown", L, i), N(f, "pointermove", D, i), N(f, "pointerup", n, i);
105
+ const t = { capture: (n = i.capture) != null ? n : !0 };
106
+ W(L, "pointerdown", D, t), W(c, "pointermove", O, t), W(c, "pointerup", H, t);
107
107
  }
108
108
  return {
109
- ...xe(y),
109
+ ...Ce(y),
110
110
  position: y,
111
- isDragging: S(() => !!g.value),
112
- style: S(
111
+ isDragging: x(() => !!_.value),
112
+ style: x(
113
113
  () => `left:${y.value.x}px;top:${y.value.y}px;`
114
114
  )
115
115
  };
116
116
  }
117
- const Me = { class: "modal-container" }, Se = { class: "title font-bold" }, ke = { class: "action" }, Ae = {
117
+ const Se = { class: "modal-container fixed inset-0" }, ke = { class: "title font-bold" }, ze = { class: "action" }, Ae = {
118
118
  key: 1,
119
119
  class: "modal-footer space-x-2"
120
- }, ze = ["form"], Pe = {
120
+ }, Pe = ["form"], $e = {
121
121
  name: "ModalContainer",
122
122
  inheritAttrs: !0
123
- }, $e = /* @__PURE__ */ X({
124
- ...Pe,
123
+ }, Be = /* @__PURE__ */ X({
124
+ ...$e,
125
125
  props: {
126
126
  id: {},
127
127
  form: {},
@@ -138,132 +138,137 @@ const Me = { class: "modal-container" }, Se = { class: "title font-bold" }, ke =
138
138
  closeable: { type: Boolean, default: !0 },
139
139
  esc: { type: Boolean, default: !1 },
140
140
  maskClosable: { type: Boolean, default: !1 },
141
- draggable: { type: Boolean, default: !1 }
141
+ draggable: { type: Boolean, default: !1 },
142
+ mode: { default: "dialog" }
142
143
  },
143
144
  emits: ["submit"],
144
- setup(t, { emit: s }) {
145
- const e = t, o = s, r = R($);
146
- let c = 0, v = 0;
147
- const p = A(), m = A(), a = A(), { x: u, y: l } = Ee(a, {
145
+ setup(o, { emit: i }) {
146
+ const e = o, n = i, r = R(B);
147
+ let u = 0, v = 0;
148
+ const p = A(), m = A(), l = A(), { x: a, y: s } = Me(l, {
148
149
  initialValue: { x: 0, y: 0 }
149
150
  });
150
151
  function d() {
151
152
  r == null || r.close(e.id);
152
153
  }
153
- function f(n) {
154
- if (typeof n == "number")
155
- return `${n}px`;
156
- if (typeof n == "string")
157
- return n;
154
+ function c(t) {
155
+ if (typeof t == "number")
156
+ return `${t}px`;
157
+ if (typeof t == "string")
158
+ return t;
158
159
  }
159
- const C = S(() => {
160
- const n = {};
161
- return e.size && (n.width = f(e.sizes[e.size])), e.width && (n.width = f(e.width)), e.maxWidth && (n.maxWidth = f(e.maxWidth)), e.size === "fullscreen" && (n.maxWidth = "unset", n.position = "fixed", n.top = 0, n.left = 0, n.bottom = 0, n.right = 0), e.draggable && e.size !== "fullscreen" && (n.transform = `translate(${u.value - c}px, ${l.value - v}px)`), n;
162
- }), B = S(() => {
163
- const n = {};
164
- return e.draggable && e.size !== "fullscreen" && (n.cursor = "move"), n;
165
- }), y = S(() => {
166
- var i;
167
- const n = {};
168
- return e.maxHeight && (n.maxHeight = `calc(${(i = f(e.maxWidth)) == null ? void 0 : i.replace("%", "vh")} - 50px)`), e.size === "fullscreen" && (n.maxHeight = "calc(100% - 50px)"), n;
160
+ const C = x(() => {
161
+ const t = {};
162
+ return e.mode === "dialog" && (t.justifyContent = "center"), e.mode === "drawer" && (t.justifyContent = "flex-end"), t;
163
+ }), L = x(() => {
164
+ const t = {};
165
+ return e.size && (t.width = c(e.sizes[e.size])), e.width && (t.width = c(e.width)), e.maxWidth && (t.maxWidth = c(e.maxWidth)), e.size === "fullscreen" && (t.maxWidth = "unset", t.position = "fixed", t.top = 0, t.left = 0, t.bottom = 0, t.right = 0), e.draggable && e.size !== "fullscreen" && e.mode === "dialog" && (t.transform = `translate3d(${a.value - u}px, ${s.value - v}px, 0px)`), t;
166
+ }), y = x(() => {
167
+ const t = {};
168
+ return e.draggable && e.size !== "fullscreen" && e.mode === "dialog" && (t.cursor = "move"), t;
169
+ }), _ = x(() => {
170
+ var f;
171
+ const t = {};
172
+ return e.maxHeight && (t.maxHeight = `calc(${(f = c(e.maxHeight)) == null ? void 0 : f.replace("%", "vh")} - 50px)`), e.mode === "drawer" && (t.maxHeight = `calc(100vh - ${(e.header ? 50 : 0) + (e.footer ? 50 : 0)}px)`), e.size === "fullscreen" && (t.maxHeight = `calc(100vh - ${(e.header ? 50 : 0) + (e.footer ? 50 : 0)}px)`), t;
169
173
  });
170
- function g() {
171
- const n = m.value;
172
- if (e.form && n) {
173
- const i = n.querySelector(`form[name="${e.form}"]`);
174
- i && i.dispatchEvent(new Event("submit"));
174
+ function E() {
175
+ const t = m.value;
176
+ if (e.form && t) {
177
+ const f = t.querySelector(`form[name="${e.form}"]`);
178
+ f && f.dispatchEvent(new Event("submit"));
175
179
  }
176
- o("submit");
180
+ n("submit");
177
181
  }
178
- function E() {
182
+ function M() {
179
183
  r == null || r.close(e.id);
180
184
  }
181
- function M() {
185
+ function D() {
182
186
  window && window.addEventListener("resize", () => {
183
- k(p), k(m), c = m.value.offsetLeft, v = m.value.offsetTop;
187
+ S(p), S(m), u = m.value.offsetLeft, v = m.value.offsetTop;
184
188
  });
185
189
  }
186
- function L() {
190
+ function O() {
187
191
  if (e.closeable && e.esc) {
188
- const n = ({ key: i }) => {
189
- i === "Escape" && (r == null || r.close(e.id), window.removeEventListener("keydown", n));
192
+ const t = ({ key: f }) => {
193
+ f === "Escape" && (r == null || r.close(e.id), window.removeEventListener("keydown", t));
190
194
  };
191
- window.addEventListener("keydown", n);
195
+ window.addEventListener("keydown", t);
192
196
  }
193
197
  }
194
- function D() {
195
- c = m.value.offsetLeft, v = m.value.offsetTop;
198
+ function H() {
199
+ u = m.value.offsetLeft, v = m.value.offsetTop;
196
200
  }
197
201
  return Y(() => {
198
- L(), M();
199
- }), oe(() => {
200
- }), (n, i) => (_(), b("div", Me, [
202
+ O(), D();
203
+ }), ne(() => {
204
+ }), (t, f) => (g(), b("div", Se, [
201
205
  w("div", {
202
206
  ref_key: "wrapperRef",
203
207
  ref: p,
204
208
  class: "modal-wrapper",
205
- onClick: i[0] || (i[0] = re((x) => n.maskClosable && d(), ["self"]))
209
+ style: z(C.value),
210
+ onClick: f[0] || (f[0] = re((k) => t.maskClosable && d(), ["self"]))
206
211
  }, [
207
212
  w("div", {
208
213
  ref_key: "contentRef",
209
214
  ref: m,
210
- class: "modal-content",
211
- style: W(C.value)
215
+ class: ie(["modal-content", { [`${t.mode}-mode`]: !0 }]),
216
+ style: z(L.value)
212
217
  }, [
213
- n.header ? (_(), b("div", {
218
+ t.header ? (g(), b("div", {
214
219
  key: 0,
215
220
  ref_key: "headerRef",
216
- ref: a,
221
+ ref: l,
217
222
  class: "modal-header",
218
- style: W(B.value),
219
- onMousedown: D
223
+ style: z(y.value),
224
+ onMousedown: H
220
225
  }, [
221
- w("div", Se, ie(n.title), 1),
222
- w("div", ke, [
223
- n.closeable ? (_(), b("div", {
226
+ w("div", ke, se(t.title), 1),
227
+ w("div", ze, [
228
+ t.closeable ? (g(), b("div", {
224
229
  key: 0,
225
230
  class: "i-icon-park-outline:close block cursor-pointer",
226
231
  onClick: d
227
- })) : z("", !0)
232
+ })) : P("", !0)
228
233
  ])
229
- ], 36)) : z("", !0),
234
+ ], 36)) : P("", !0),
230
235
  w("div", {
231
236
  class: "modal-body",
232
- style: W(y.value)
237
+ style: z(_.value)
233
238
  }, [
234
- (_(), T(se(n.component), le(ae(n.componentProps)), null, 16))
239
+ (g(), N(le(t.component), ae(ue(t.componentProps)), null, 16))
235
240
  ], 4),
236
- n.footer ? (_(), b("div", Ae, [
241
+ t.footer ? (g(), b("div", Ae, [
237
242
  w("button", {
238
243
  class: "submit-button",
239
- form: n.form,
244
+ form: t.form,
240
245
  type: "submit",
241
- onClick: g
242
- }, " 确定 ", 8, ze),
246
+ onClick: E
247
+ }, " 确定 ", 8, Pe),
243
248
  w("button", {
244
249
  class: "cancel-button",
245
250
  type: "button",
246
- onClick: E
251
+ onClick: M
247
252
  }, " 取消 ")
248
- ])) : z("", !0)
249
- ], 4)
250
- ], 512)
253
+ ])) : P("", !0)
254
+ ], 6)
255
+ ], 4)
251
256
  ]));
252
257
  }
253
258
  });
254
- const U = (t, s) => {
255
- const e = t.__vccOpts || t;
256
- for (const [o, r] of s)
257
- e[o] = r;
259
+ const U = (o, i) => {
260
+ const e = o.__vccOpts || o;
261
+ for (const [n, r] of i)
262
+ e[n] = r;
258
263
  return e;
259
- }, Be = /* @__PURE__ */ U($e, [["__scopeId", "data-v-05b670ad"]]), Le = {
264
+ }, Le = /* @__PURE__ */ U(Be, [["__scopeId", "data-v-581eba51"]]), De = {
260
265
  key: 0,
261
266
  class: "modal-teleport"
262
- }, De = {
267
+ }, Oe = {
263
268
  name: "ModalProvider",
264
269
  inheritAttrs: !0
265
- }, Oe = /* @__PURE__ */ X({
266
- ...De,
270
+ }, He = /* @__PURE__ */ X({
271
+ ...Oe,
267
272
  props: {
268
273
  appendToBody: { type: Boolean, default: !1 },
269
274
  sizes: { default: () => ({
@@ -274,126 +279,126 @@ const U = (t, s) => {
274
279
  maxWidth: { default: "80%" },
275
280
  maxHeight: { default: "80%" }
276
281
  },
277
- setup(t, { expose: s }) {
278
- const e = A([]), o = P(!1);
279
- async function r(a, u, l) {
280
- const d = he(
281
- () => Promise.resolve(a)
282
+ setup(o, { expose: i }) {
283
+ const e = A([]), n = $(!1);
284
+ async function r(l, a, s) {
285
+ const d = ge(
286
+ () => Promise.resolve(l)
282
287
  );
283
- return new Promise((f) => {
288
+ return new Promise((c) => {
284
289
  e.value.push({
285
290
  id: Math.random().toString(32).slice(2),
286
291
  component: d,
287
- props: u,
288
- options: l,
289
- resolve: f,
290
- onSubmit: P(() => {
292
+ props: a,
293
+ options: s,
294
+ resolve: c,
295
+ onSubmit: $(() => {
291
296
  })
292
- }), k(e);
297
+ }), S(e);
293
298
  });
294
299
  }
295
- function c(a, u) {
296
- const l = e.value.findIndex((f) => f.id === a);
297
- if (l < 0)
300
+ function u(l, a) {
301
+ const s = e.value.findIndex((c) => c.id === l);
302
+ if (s < 0)
298
303
  return;
299
- const d = e.value[l];
300
- d == null || d.resolve(u), e.value.splice(l, 1), k(e);
304
+ const d = e.value[s];
305
+ d == null || d.resolve(a), e.value.splice(s, 1), S(e);
301
306
  }
302
307
  function v() {
303
- e.value.forEach((a) => {
304
- a.resolve();
305
- }), e.value = [], k(e);
308
+ e.value.forEach((l) => {
309
+ l.resolve();
310
+ }), e.value = [], S(e);
306
311
  }
307
- function p(a) {
308
- return e.value.find((u) => u.id === a);
312
+ function p(l) {
313
+ return e.value.find((a) => a.id === l);
309
314
  }
310
- function m(a, u) {
311
- const l = e.value.find((d) => d.id === a);
312
- l && (l.onSubmit.value = u);
315
+ function m(l, a) {
316
+ const s = e.value.find((d) => d.id === l);
317
+ s && (s.onSubmit.value = a);
313
318
  }
314
- return ue($, {
319
+ return de(B, {
315
320
  open: r,
316
- close: c,
321
+ close: u,
317
322
  closeAll: v,
318
323
  getElement: p,
319
324
  addSubmitListener: m
320
- }), s({
325
+ }), i({
321
326
  elements: e
322
327
  }), Y(() => {
323
- o.value = !0;
324
- }), (a, u) => (_(), b(I, null, [
325
- ce(a.$slots, "default", {}, void 0, !0),
326
- o.value ? (_(), b("div", Le, [
327
- (_(), T(de, {
328
- disabled: !a.appendToBody,
328
+ n.value = !0;
329
+ }), (l, a) => (g(), b(I, null, [
330
+ ce(l.$slots, "default", {}, void 0, !0),
331
+ n.value ? (g(), b("div", De, [
332
+ (g(), N(fe, {
333
+ disabled: !l.appendToBody,
329
334
  to: "body"
330
335
  }, [
331
- fe(pe, { name: "modal-fade" }, {
332
- default: me(() => [
333
- (_(!0), b(I, null, ve(e.value, (l) => (_(), T(Be, ye({
334
- id: l.id,
335
- key: l.id,
336
- component: l.component,
337
- "component-props": l.props,
338
- "max-height": a.maxHeight,
339
- "max-width": a.maxWidth,
340
- sizes: a.sizes
341
- }, l.options, {
342
- onSubmit: l.onSubmit.value
336
+ pe(me, { name: "modal-fade" }, {
337
+ default: ve(() => [
338
+ (g(!0), b(I, null, ye(e.value, (s) => (g(), N(Le, he({
339
+ id: s.id,
340
+ key: s.id,
341
+ component: s.component,
342
+ "component-props": s.props,
343
+ "max-height": l.maxHeight,
344
+ "max-width": l.maxWidth,
345
+ sizes: l.sizes
346
+ }, s.options, {
347
+ onSubmit: s.onSubmit.value
343
348
  }), null, 16, ["id", "component", "component-props", "max-height", "max-width", "sizes", "onSubmit"]))), 128))
344
349
  ]),
345
350
  _: 1
346
351
  })
347
352
  ], 8, ["disabled"]))
348
- ])) : z("", !0)
353
+ ])) : P("", !0)
349
354
  ], 64));
350
355
  }
351
356
  });
352
- const Ne = /* @__PURE__ */ U(Oe, [["__scopeId", "data-v-171d9bdd"]]);
353
- function H(t, s) {
354
- var o, r;
355
- let e = t == null ? void 0 : t.parent;
356
- for (; e && ((o = e == null ? void 0 : e.type) == null ? void 0 : o.name) !== s; )
357
+ const Ne = /* @__PURE__ */ U(He, [["__scopeId", "data-v-1ef03c20"]]);
358
+ function T(o, i) {
359
+ var n, r;
360
+ let e = o == null ? void 0 : o.parent;
361
+ for (; e && ((n = e == null ? void 0 : e.type) == null ? void 0 : n.name) !== i; )
357
362
  e = e.parent;
358
- return ((r = e == null ? void 0 : e.type) == null ? void 0 : r.name) === s ? e : null;
363
+ return ((r = e == null ? void 0 : e.type) == null ? void 0 : r.name) === i ? e : null;
359
364
  }
360
365
  function Te() {
361
- const t = R($), s = K();
366
+ const o = R(B), i = K();
362
367
  return {
363
- open(e, o, r) {
364
- if (!t)
368
+ open(e, n, r) {
369
+ if (!o)
365
370
  throw new Error("Not Found Modal Provider Component");
366
- return t.open(e, o || {}, r || {});
371
+ return o.open(e, n || {}, r || {});
367
372
  },
368
373
  close(e) {
369
- var c;
370
- if (!t)
374
+ var u;
375
+ if (!o)
371
376
  throw new Error("Not Found Modal Provider Component");
372
- const o = H(s, "ModalContainer"), r = (c = o == null ? void 0 : o.props) == null ? void 0 : c.id;
377
+ const n = T(i, "ModalContainer"), r = (u = n == null ? void 0 : n.props) == null ? void 0 : u.id;
373
378
  if (!r)
374
379
  throw new Error("Not Found Current Modal Container");
375
- t.close(r, e);
380
+ o.close(r, e);
376
381
  },
377
382
  closeAll() {
378
- if (!t)
383
+ if (!o)
379
384
  throw new Error("Not Found Modal Provider Component");
380
- t.closeAll();
385
+ o.closeAll();
381
386
  },
382
387
  onSubmit(e) {
383
- const o = H(s, "ModalContainer");
384
- if (!(o == null ? void 0 : o.props.id))
388
+ const n = T(i, "ModalContainer");
389
+ if (!(n == null ? void 0 : n.props.id))
385
390
  throw new Error("Not Found Current Modal Container");
386
391
  }
387
392
  };
388
393
  }
389
- function He(t) {
390
- var c;
391
- const s = R($), e = K(), o = H(e, "ModalContainer"), r = (c = o == null ? void 0 : o.props) == null ? void 0 : c.id;
392
- s && r && s.addSubmitListener(r, t);
394
+ function Re(o) {
395
+ var u;
396
+ const i = R(B), e = K(), n = T(e, "ModalContainer"), r = (u = n == null ? void 0 : n.props) == null ? void 0 : u.id;
397
+ i && r && i.addSubmitListener(r, o);
393
398
  }
394
399
  export {
395
- Be as ModalContainer,
400
+ Le as ModalContainer,
396
401
  Ne as ModalProvider,
397
- He as onSubmit,
402
+ Re as onSubmit,
398
403
  Te as useModal
399
404
  };
@@ -16,6 +16,7 @@ export interface OpenModalOptions {
16
16
  size?: 'large' | 'middle' | 'small' | 'fullscreen';
17
17
  draggable?: boolean;
18
18
  form?: string;
19
+ mode?: 'dialog' | 'drawer';
19
20
  }
20
21
  export interface ModalElement extends OpenModalOptions {
21
22
  id: string;
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}.fixed{position:fixed}.block{display:block}.flex{display:flex}.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))}.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-05b670ad]{z-index:1000;position:fixed;top:0;right:0;bottom:0;left:0;display:flex;justify-content:center;align-items:center;background:rgba(0,0,0,.3)}.modal-content[data-v-05b670ad]{background:#ffffff;border-radius:5px}.modal-header[data-v-05b670ad]{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-05b670ad]{padding:20px 10px;box-sizing:border-box;max-height:10vw;overflow:auto}.modal-footer[data-v-05b670ad]{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-05b670ad]{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-05b670ad]{color:#fff;background-color:rgb(var(--primary-6, 45, 106, 251))}.modal-footer button.submit-button[data-v-05b670ad]:hover{background-color:rgb(var(--primary-5, 28, 76, 207))}.modal-footer button.cancel-button[data-v-05b670ad]{color:rgb(var(--color-text-2, 78, 89, 105));background-color:var(--color-fill-1, #f5f5f5)}.modal-footer button.cancel-button[data-v-05b670ad]:hover{background-color:var(--color-fill-4, #c9cdd4)}.modal-fade-enter-active[data-v-171d9bdd],.modal-fade-leave-active[data-v-171d9bdd]{transition:all .5s ease}.modal-fade-enter-from[data-v-171d9bdd],.modal-fade-leave-to[data-v-171d9bdd]{opacity:0}
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}.fixed{position:fixed}.inset-0{top:0;right:0;bottom:0;left:0}.block{display: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))}.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-581eba51]{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-581eba51]{background:#ffffff;border-radius:5px}.modal-header[data-v-581eba51]{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-581eba51]{padding:20px 10px;box-sizing:border-box;max-height:10vw;overflow:auto}.modal-footer[data-v-581eba51]{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-581eba51]{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-581eba51]{color:#fff;background-color:rgb(var(--primary-6, 45, 106, 251))}.modal-footer button.submit-button[data-v-581eba51]:hover{background-color:rgb(var(--primary-5, 28, 76, 207))}.modal-footer button.cancel-button[data-v-581eba51]{color:rgb(var(--color-text-2, 78, 89, 105));background-color:var(--color-fill-1, #f5f5f5)}.modal-footer button.cancel-button[data-v-581eba51]:hover{background-color:var(--color-fill-4, #c9cdd4)}.modal-fade-enter-active[data-v-1ef03c20],.modal-fade-leave-active[data-v-1ef03c20]{transition:opacity .5s ease}.modal-fade-enter-active[data-v-1ef03c20] .modal-content.drawer-mode,.modal-fade-leave-active[data-v-1ef03c20] .modal-content.drawer-mode{transition:transform .5s ease}.modal-fade-enter-from[data-v-1ef03c20],.modal-fade-leave-to[data-v-1ef03c20]{opacity:0}.modal-fade-enter-from[data-v-1ef03c20] .modal-content.drawer-mode,.modal-fade-leave-to[data-v-1ef03c20] .modal-content.drawer-mode{transform:translate3d(100%,0,0)}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gopowerteam/modal-render",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "author": {
6
6
  "name": "zhuchentong",
7
7
  "email": "2037630@gmail.com"