Files
aiot-platform-ui/apps/web-antd/dist/js/use-modal-BABce5hC.js
lzh 19d36d1ffb
All checks were successful
Web UI CI/CD / build-and-deploy (push) Successful in 8s
chore: build and deploy web-antd
2026-03-09 13:05:46 +08:00

2 lines
16 KiB
JavaScript

var Ze=Object.defineProperty,et=Object.defineProperties;var tt=Object.getOwnPropertyDescriptors;var le=Object.getOwnPropertySymbols;var xe=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable;var de=(o,t,s)=>t in o?Ze(o,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[t]=s,f=(o,t)=>{for(var s in t||(t={}))xe.call(t,s)&&de(o,s,t[s]);if(le)for(var s of le(t))we.call(t,s)&&de(o,s,t[s]);return o},R=(o,t)=>et(o,tt(t));var K=(o,t)=>{var s={};for(var a in o)xe.call(o,a)&&t.indexOf(a)<0&&(s[a]=o[a]);if(o!=null&&le)for(var a of le(o))t.indexOf(a)<0&&we.call(o,a)&&(s[a]=o[a]);return s};var W=(o,t,s)=>de(o,typeof t!="symbol"?t+"":t,s);var J=(o,t,s)=>new Promise((a,l)=>{var r=m=>{try{b(s.next(m))}catch(d){l(d)}},u=m=>{try{b(s.throw(m))}catch(d){l(d)}},b=m=>m.done?a(m.value):Promise.resolve(m.value).then(r,u);b((s=s.apply(o,t)).next())});import{m as T,ab as h,b2 as p,u as e,aS as ot,aw as st,bJ as y,bc as g,aE as $e,ad as ue,aa as P,b9 as _,a2 as at,j as N,ac as B,aT as nt,aR as X,cd as $,aQ as pe,b7 as Te,v as lt,bF as it,aW as rt,cP as ce,by as dt,w as ct,aX as ut,ae as pt,ai as Q,bp as G,bf as Be,n as fe,b4 as Ae,cn as ft,i as mt,L as ke}from"../jse/index-index-CMeVxoEG.js";import{U as Ee,a_ as Se,a$ as ht,b0 as yt,b1 as Pe,b3 as vt,b2 as gt,b9 as bt,aQ as Ct,ba as xt,aS as wt,bb as Bt,aU as kt,bc as Ot,X as Oe,aP as Dt,aV as Mt}from"./bootstrap-CRjSNGHY.js";import{c as _t,D as $t,X as Tt,a as At,b as Et,d as St}from"./x-CpZ5_sBZ.js";const Pt=Ee("expand",[["path",{d:"m15 15 6 6",key:"1s409w"}],["path",{d:"m15 9 6-6",key:"ko1vev"}],["path",{d:"M21 16v5h-5",key:"1ck2sf"}],["path",{d:"M21 8V3h-5",key:"1qoq8a"}],["path",{d:"M3 16v5h5",key:"1t08am"}],["path",{d:"m3 21 6-6",key:"wwnumi"}],["path",{d:"M3 8V3h5",key:"1ln10m"}],["path",{d:"M9 9 3 3",key:"v551iv"}]]);const Lt=Ee("shrink",[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]]),It=T({__name:"Dialog",props:{open:{type:Boolean},defaultOpen:{type:Boolean},modal:{type:Boolean}},emits:["update:open"],setup(o,{emit:t}){const l=Se(o,t);return(r,u)=>(p(),h(e(_t),ot(st(e(l))),{default:y(()=>[g(r.$slots,"default")]),_:3},16))}}),zt=["data-dismissable-modal"],Ft=T({__name:"DialogOverlay",setup(o){ht();const t=$e("DISMISSABLE_MODAL_ID");return(s,a)=>(p(),ue("div",{"data-dismissable-modal":e(t),class:"z-popup inset-0 bg-overlay"},null,8,zt))}}),Vt=T({__name:"DialogContent",props:{forceMount:{type:Boolean},disableOutsidePointerEvents:{type:Boolean},asChild:{type:Boolean},as:{},animationType:{default:"slide"},appendTo:{default:"body"},class:{},closeClass:{},closeDisabled:{type:Boolean,default:!1},modal:{type:Boolean},open:{type:Boolean},overlayBlur:{},showClose:{type:Boolean,default:!0},zIndex:{}},emits:["escapeKeyDown","pointerDownOutside","focusOutside","interactOutside","openAutoFocus","closeAutoFocus","close","closed","opened"],setup(o,{expose:t,emit:s}){const a=o,l=s,r=P(()=>{const A=a,{class:i,modal:c,open:x,showClose:w,animationType:k}=A;return K(A,["class","modal","open","showClose","animationType"])});function u(){return a.appendTo==="body"||a.appendTo===document.body||!a.appendTo}const b=P(()=>u()?"fixed":"absolute"),m=Se(r,l),d=_(null);function v(i){var c;i.target===((c=d.value)==null?void 0:c.$el)&&(a.open?l("opened"):l("closed"))}return t({getContentRef:()=>d.value}),(i,c)=>(p(),h(at,{defer:"",to:o.appendTo},[N(yt,{name:"fade"},{default:y(()=>[o.open&&o.modal?(p(),h(Ft,{key:0,style:nt(R(f({},o.zIndex?{zIndex:o.zIndex}:{}),{position:b.value,backdropFilter:o.overlayBlur&&o.overlayBlur>0?`blur(${o.overlayBlur}px)`:"none"})),onClick:c[0]||(c[0]=()=>l("close"))},null,8,["style"])):B("",!0)]),_:1}),N(e(At),pe({ref_key:"contentRef",ref:d,style:R(f({},o.zIndex?{zIndex:o.zIndex}:{}),{position:b.value}),onAnimationend:v},e(m),{class:e($)("z-popup w-full bg-background p-6 shadow-lg outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 sm:rounded-xl",{"data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-top-[48%]":o.animationType==="slide"},a.class)}),{default:y(()=>[g(i.$slots,"default"),o.showClose?(p(),h(e($t),{key:0,disabled:o.closeDisabled,class:X(e($)("flex-center absolute right-3 top-3 h-6 w-6 rounded-full px-1 text-lg text-foreground/80 opacity-70 transition-opacity hover:bg-accent hover:text-accent-foreground hover:opacity-100 focus:outline-none disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",a.closeClass)),onClick:c[1]||(c[1]=()=>l("close"))},{default:y(()=>[N(e(Tt),{class:"h-4 w-4"})]),_:1},8,["disabled","class"])):B("",!0)]),_:3},16,["style","class"])],8,["to"]))}}),De=T({__name:"DialogDescription",props:{asChild:{type:Boolean},as:{},class:{}},setup(o){const t=o,s=P(()=>{const u=t,{class:l}=u;return K(u,["class"])}),a=Pe(s);return(l,r)=>(p(),h(e(Et),pe(e(a),{class:e($)("text-sm text-muted-foreground",t.class)}),{default:y(()=>[g(l.$slots,"default")]),_:3},16,["class"]))}}),Rt=T({__name:"DialogFooter",props:{class:{}},setup(o){const t=o;return(s,a)=>(p(),ue("div",{class:X(e($)("flex flex-row flex-col-reverse justify-end gap-x-2",t.class))},[g(s.$slots,"default")],2))}}),Xt=T({__name:"DialogHeader",props:{class:{}},setup(o){const t=o;return(s,a)=>(p(),ue("div",{class:X(e($)("flex flex-col gap-y-1.5 text-center sm:text-left",t.class))},[g(s.$slots,"default")],2))}}),Me=T({__name:"DialogTitle",props:{asChild:{type:Boolean},as:{},class:{}},setup(o){const t=o,s=P(()=>{const u=t,{class:l}=u;return K(u,["class"])}),a=Pe(s);return(l,r)=>(p(),h(e(St),pe(e(a),{class:e($)("text-lg font-semibold leading-none tracking-tight",t.class)}),{default:y(()=>[g(l.$slots,"default")]),_:3},16,["class"]))}});function Nt(o,t,s,a,l){const r=Te({offsetX:0,offsetY:0}),u=_(!1),b=i=>{const c=i.clientX,x=i.clientY;if(!o.value)return;const w=o.value.getBoundingClientRect(),{offsetX:k,offsetY:D}=r,A=w.left,F=w.top,Z=w.width,ee=w.height;let L=null;if(a!=null&&a.value){const M=document.querySelector(a.value);M&&(L=M.getBoundingClientRect())}let Y,H,I,U;if(L)I=L.left-A+k,Y=L.right-A-Z+k,U=L.top-F+D,H=L.bottom-F-ee+D;else{const M=document.documentElement,O=M.clientWidth,E=M.clientHeight;I=-A+k,U=-F+D,Y=O-A-Z+k,H=E-F-ee+D}const te=M=>{let O=k+M.clientX-c,E=D+M.clientY-x;if(O=Math.min(Math.max(O,I),Y),E=Math.min(Math.max(E,U),H),r.offsetX=O,r.offsetY=E,o.value){const se=l==null?void 0:l.value;o.value.style.transform=se?`translate(${O}px, calc(-50% + ${E}px))`:`translate(${O}px, ${E}px)`,u.value=!0}},oe=()=>{u.value=!1,document.removeEventListener("mousemove",te),document.removeEventListener("mouseup",oe)};document.addEventListener("mousemove",te),document.addEventListener("mouseup",oe)},m=()=>{const i=ce(t);i&&o.value&&i.addEventListener("mousedown",b)},d=()=>{const i=ce(t);i&&o.value&&i.removeEventListener("mousedown",b)},v=()=>{r.offsetX=0,r.offsetY=0;const i=ce(o);i&&(i.style.transform="")};return lt(()=>{it(()=>{s.value?m():d()})}),rt(()=>{d()}),{dragging:u,resetPosition:v,transform:r}}const Yt=T({__name:"modal",props:{modalApi:{default:void 0},animationType:{},appendToMain:{type:Boolean,default:!1},bordered:{type:Boolean},cancelText:{},centered:{type:Boolean},class:{},closable:{type:Boolean},closeOnClickModal:{type:Boolean},closeOnPressEscape:{type:Boolean},confirmDisabled:{type:Boolean},confirmLoading:{type:Boolean},confirmText:{},contentClass:{},description:{},destroyOnClose:{type:Boolean,default:!1},draggable:{type:Boolean},footer:{type:Boolean},footerClass:{},fullscreen:{type:Boolean},fullscreenButton:{type:Boolean},header:{type:Boolean},headerClass:{},loading:{type:Boolean},modal:{type:Boolean},openAutoFocus:{type:Boolean},overlayBlur:{},showCancelButton:{type:Boolean},showConfirmButton:{type:Boolean},submitting:{type:Boolean},title:{},titleTooltip:{},zIndex:{}},setup(o){var ne,Ce;const t=o,s=vt.getComponents(),a=_(),l=_(),r=_(),u=_(),b=_(),m=dt();Ae("DISMISSABLE_MODAL_ID",m);const{$t:d}=gt(),{isMobile:v}=bt(),i=(Ce=(ne=t.modalApi)==null?void 0:ne.useStore)==null?void 0:Ce.call(ne),{appendToMain:c,bordered:x,cancelText:w,centered:k,class:D,closable:A,closeOnClickModal:F,closeOnPressEscape:Z,confirmDisabled:ee,confirmLoading:L,confirmText:Y,contentClass:H,description:I,destroyOnClose:U,draggable:te,footer:oe,footerClass:M,fullscreen:O,fullscreenButton:E,header:se,headerClass:Le,loading:me,modal:Ie,openAutoFocus:ze,overlayBlur:Fe,showCancelButton:Ve,showConfirmButton:Re,submitting:S,title:ae,titleTooltip:he,animationType:Xe,zIndex:Ne}=Ct(t,i),j=P(()=>O.value||v.value),ye=P(()=>te.value&&!j.value&&se.value),ve=P(()=>k.value&&!j.value),ge=P(()=>c.value?`#${xt}>div:not(.absolute)>div`:void 0),{dragging:Ye,transform:He}=Nt(r,u,ye,ge,ve),ie=_(!1),re=_(!0);ct(()=>{var n;return(n=i==null?void 0:i.value)==null?void 0:n.isOpen},n=>J(null,null,function*(){if(n){if(re.value=!1,ie.value||(ie.value=!0),yield fe(),!a.value)return;const C=a.value.getContentRef();r.value=C.$el;const{offsetX:V,offsetY:z}=He;r.value.style.transform=ve.value?`translate(${V}px, calc(-50% + ${z}px))`:`translate(${V}px, ${z}px)`}}),{immediate:!0}),ut(()=>{var n;c.value||(n=t.modalApi)==null||n.close()});function Ue(){var n;(n=t.modalApi)==null||n.setState(C=>R(f({},C),{fullscreen:!O.value}))}function je(n){(!F.value||S.value)&&(n.preventDefault(),n.stopPropagation())}function qe(n){(!Z.value||S.value)&&n.preventDefault()}function Ke(n){ze.value||n==null||n.preventDefault()}function We(n){const C=n.target,V=C==null?void 0:C.dataset.dismissableModal;(!F.value||V!==m||S.value)&&(n.preventDefault(),n.stopPropagation())}function be(n){n.preventDefault(),n.stopPropagation()}const Je=P(()=>!e(U)&&e(ie)),Qe=()=>{requestAnimationFrame(()=>{var n;(n=t.modalApi)==null||n.onOpened()})};function Ge(){var n;re.value=!0,(n=t.modalApi)==null||n.onClosed()}return(n,C)=>{var V;return p(),h(e(It),{modal:!1,open:(V=e(i))==null?void 0:V.isOpen,"onUpdate:open":C[2]||(C[2]=()=>{var z;return e(S)||(z=o.modalApi)==null?void 0:z.close()})},{default:y(()=>{var z;return[N(e(Vt),{ref_key:"contentRef",ref:a,"append-to":ge.value,class:X(e($)("left-0 right-0 top-[10vh] mx-auto flex max-h-[80%] w-[520px] flex-col p-0",j.value?"sm:rounded-none":"sm:rounded-[var(--radius)]",e(D),{"border border-border":e(x),"shadow-3xl":!e(x),"left-0 top-0 size-full max-h-full !translate-x-0 !translate-y-0":j.value,"top-1/2":e(k)&&!j.value,"duration-300":!e(Ye),hidden:re.value})),"force-mount":Je.value,modal:e(Ie),open:(z=e(i))==null?void 0:z.isOpen,"show-close":e(A),"animation-type":e(Xe),"z-index":e(Ne),"overlay-blur":e(Fe),"close-class":"top-3",onCloseAutoFocus:be,onClosed:Ge,"close-disabled":e(S),onEscapeKeyDown:qe,onFocusOutside:be,onInteractOutside:je,onOpenAutoFocus:Ke,onOpened:Qe,onPointerDownOutside:We},{default:y(()=>[N(e(Xt),{ref_key:"headerRef",ref:u,class:X(e($)("px-5 py-4",{"border-b":e(x),hidden:!e(se),"cursor-move select-none":ye.value},e(Le)))},{default:y(()=>[e(ae)?(p(),h(e(Me),{key:0,class:"text-left"},{default:y(()=>[g(n.$slots,"title",{},()=>[Q(G(e(ae))+" ",1),e(he)?g(n.$slots,"titleTooltip",{key:0},()=>[N(e(wt),{"trigger-class":"pb-1"},{default:y(()=>[Q(G(e(he)),1)]),_:1})]):B("",!0)])]),_:3})):B("",!0),e(I)?(p(),h(e(De),{key:1},{default:y(()=>[g(n.$slots,"description",{},()=>[Q(G(e(I)),1)])]),_:3})):B("",!0),!e(ae)||!e(I)?(p(),h(e(Bt),{key:2},{default:y(()=>[e(ae)?B("",!0):(p(),h(e(Me),{key:0})),e(I)?B("",!0):(p(),h(e(De),{key:1}))]),_:1})):B("",!0)]),_:3},8,["class"]),pt("div",{ref_key:"wrapperRef",ref:l,class:X(e($)("relative min-h-40 flex-1 overflow-y-auto p-3",e(H),{"pointer-events-none":e(me)||e(S)}))},[g(n.$slots,"default")],2),e(me)||e(S)?(p(),h(e(kt),{key:0,spinning:""})):B("",!0),e(E)?(p(),h(e(Ot),{key:1,class:"flex-center absolute right-10 top-3 hidden size-6 rounded-full px-1 text-lg text-foreground/80 opacity-70 transition-opacity hover:bg-accent hover:text-accent-foreground hover:opacity-100 focus:outline-none disabled:pointer-events-none sm:block",onClick:Ue},{default:y(()=>[e(O)?(p(),h(e(Lt),{key:0,class:"size-3.5"})):(p(),h(e(Pt),{key:1,class:"size-3.5"}))]),_:1})):B("",!0),e(oe)?(p(),h(e(Rt),{key:2,ref_key:"footerRef",ref:b,class:X(e($)("flex-row items-center justify-end p-2",{"border-t":e(x)},e(M)))},{default:y(()=>[g(n.$slots,"prepend-footer"),g(n.$slots,"footer",{},()=>[e(Ve)?(p(),h(Be(e(s).DefaultButton||e(Oe)),{key:0,variant:"ghost",disabled:e(S),onClick:C[0]||(C[0]=()=>{var q;return(q=o.modalApi)==null?void 0:q.onCancel()})},{default:y(()=>[g(n.$slots,"cancelText",{},()=>[Q(G(e(w)||e(d)("cancel")),1)])]),_:3},8,["disabled"])):B("",!0),g(n.$slots,"center-footer"),e(Re)?(p(),h(Be(e(s).PrimaryButton||e(Oe)),{key:1,disabled:e(ee),loading:e(L)||e(S),onClick:C[1]||(C[1]=()=>{var q;return(q=o.modalApi)==null?void 0:q.onConfirm()})},{default:y(()=>[g(n.$slots,"confirmText",{},()=>[Q(G(e(Y)||e(d)("confirm")),1)])]),_:3},8,["disabled","loading"])):B("",!0)]),g(n.$slots,"append-footer")]),_:3},8,["class"])):B("",!0)]),_:3},8,["append-to","class","force-mount","modal","open","show-close","animation-type","z-index","overlay-blur","close-disabled"])]}),_:3},8,["open"])}}});class Ht{constructor(t={}){W(this,"sharedData",{payload:{}});W(this,"store");W(this,"api");W(this,"state");const i=t,{connectedComponent:s,onBeforeClose:a,onCancel:l,onClosed:r,onConfirm:u,onOpenChange:b,onOpened:m}=i,d=K(i,["connectedComponent","onBeforeClose","onCancel","onClosed","onConfirm","onOpenChange","onOpened"]),v={bordered:!0,centered:!1,class:"",closeOnClickModal:!0,closeOnPressEscape:!0,confirmDisabled:!1,confirmLoading:!1,contentClass:"",destroyOnClose:!0,draggable:!1,footer:!0,footerClass:"",fullscreen:!1,fullscreenButton:!0,header:!0,headerClass:"",isOpen:!1,loading:!1,modal:!0,openAutoFocus:!1,showCancelButton:!0,showConfirmButton:!0,title:"",animationType:"slide"};this.store=new Dt(f(f({},v),d),{onUpdate:()=>{var x,w,k;const c=this.store.state;(c==null?void 0:c.isOpen)===((x=this.state)==null?void 0:x.isOpen)?this.state=c:(this.state=c,(k=(w=this.api).onOpenChange)==null||k.call(w,!!(c!=null&&c.isOpen)))}}),this.state=this.store.state,this.api={onBeforeClose:a,onCancel:l,onClosed:r,onConfirm:u,onOpenChange:b,onOpened:m},ft(this)}close(){return J(this,null,function*(){var s,a,l;((l=yield(a=(s=this.api).onBeforeClose)==null?void 0:a.call(s))!=null?l:!0)&&this.store.setState(r=>R(f({},r),{isOpen:!1}))})}getData(){var t,s;return(s=(t=this.sharedData)==null?void 0:t.payload)!=null?s:{}}lock(t=!0){return this.setState({submitting:t})}onCancel(){var t,s;this.api.onCancel?(s=(t=this.api).onCancel)==null||s.call(t):this.close()}onClosed(){var t,s;this.state.isOpen||(s=(t=this.api).onClosed)==null||s.call(t)}onConfirm(){var t,s;(s=(t=this.api).onConfirm)==null||s.call(t)}onOpened(){var t,s;this.state.isOpen&&((s=(t=this.api).onOpened)==null||s.call(t))}open(){this.store.setState(t=>R(f({},t),{isOpen:!0,submitting:!1}))}setData(t){return this.sharedData.payload=t,this}setState(t){return mt(t)?this.store.setState(t):this.store.setState(s=>f(f({},s),t)),this}unlock(){return this.lock(!1)}}const _e=Symbol("VBEN_MODAL_INJECT"),Ut={};function Qt(o={}){var m;const{connectedComponent:t}=o;if(t){const d=Te({}),v=_(!0);return[T((c,{attrs:x,slots:w})=>(Ae(_e,{extendApi(D){Object.setPrototypeOf(d,D)},options:o,reCreateModal(){return J(this,null,function*(){v.value=!1,yield fe(),v.value=!0})}}),jt(d,f(f(f({},c),x),w)),()=>ke(v.value?t:"div",f(f({},c),x),w)),{name:"VbenParentModal",inheritAttrs:!1}),d]}const s=$e(_e,{}),a=f(f(f({},Ut),s.options),o);a.onOpenChange=d=>{var v,i,c;(v=o.onOpenChange)==null||v.call(o,d),(c=(i=s.options)==null?void 0:i.onOpenChange)==null||c.call(i,d)};const l=a.onClosed;a.onClosed=()=>{var d;l==null||l(),a.destroyOnClose&&((d=s.reCreateModal)==null||d.call(s))};const r=new Ht(a),u=r;u.useStore=d=>Mt(r.store,d);const b=T((d,{attrs:v,slots:i})=>()=>ke(Yt,R(f(f({},d),v),{modalApi:u}),i),{name:"VbenModal",inheritAttrs:!1});return(m=s.extendApi)==null||m.call(s,u),[b,u]}function jt(o,t){return J(this,null,function*(){var l;if(!t||Object.keys(t).length===0)return;yield fe();const s=(l=o==null?void 0:o.store)==null?void 0:l.state;if(!s)return;const a=new Set(Object.keys(s));for(const r of Object.keys(t))a.has(r)&&!["class"].includes(r)&&console.warn(`[Vben Modal]: When 'connectedComponent' exists, do not set props or slots '${r}', which will increase complexity. If you need to modify the props of Modal, please use useVbenModal or api.`)})}export{Qt as u};