2 lines
8.4 KiB
JavaScript
2 lines
8.4 KiB
JavaScript
import{ac as I,W as ge,a2 as he,y as g,ad as be,q as P,s as V,p as f,a6 as ke,Q as U,P as we,A as J,D as X,_ as ye,z as K,T as R}from"./index-QUdrNkKl.js";import{u as qe,a as Pe,b as pe,c as xe,d as Se}from"./use-prevent-scroll-eZQDeoK_.js";import{u as Ee}from"./use-timeout-Jkrq6Sig.js";import{i as E,v as _e,f as Ce}from"./QBtn-AYMizH8c.js";import{r as N,i as Te,e as $e}from"./use-key-composition-TTwP9QMZ.js";import{h as Be}from"./render-B4qP-w0Q.js";let Fe=1,De=document.body;function Me(e,n){const o=document.createElement("div");if(o.id=n!==void 0?`q-portal--${n}--${Fe++}`:e,I.globalNodes!==void 0){const a=I.globalNodes.class;a!==void 0&&(o.className=a)}return De.appendChild(o),o}function He(e){e.remove()}const _=[];function tt(e){return _.find(n=>n.contentEl!==null&&n.contentEl.contains(e))}function Qe(e,n){do{if(e.$options.name==="QMenu"){if(e.hide(n),e.$props.separateClosePopup===!0)return E(e)}else if(e.__qPortal===!0){const o=E(e);return o?.$options.name==="QPopupProxy"?(e.hide(n),o):e}e=E(e)}while(e!=null)}function nt(e,n,o){for(;o!==0&&e!==void 0&&e!==null;){if(e.__qPortal===!0){if(o--,e.$options.name==="QMenu"){e=Qe(e,n);continue}e.hide(n)}e=E(e)}}const ze=V({name:"QPortal",setup(e,{slots:n}){return()=>n.default()}});function Oe(e){for(e=e.parent;e!=null;){if(e.type.name==="QGlobalDialog")return!0;if(e.type.name==="QDialog"||e.type.name==="QMenu")return!1;e=e.parent}return!1}function Le(e,n,o,a){const l=P(!1),u=P(!1);let s=null;const c={},r=a==="dialog"&&Oe(e);function d(v){if(v===!0){N(c),u.value=!0;return}u.value=!1,l.value===!1&&(r===!1&&s===null&&(s=Me(!1,a)),l.value=!0,_.push(e.proxy),Te(c))}function m(v){if(u.value=!1,v!==!0)return;N(c),l.value=!1;const y=_.indexOf(e.proxy);y!==-1&&_.splice(y,1),s!==null&&(He(s),s=null)}return ge(()=>{m(!0)}),e.proxy.__qPortal=!0,he(e.proxy,"contentEl",()=>n.value),{showPortal:d,hidePortal:m,portalIsActive:l,portalIsAccessible:u,renderPortal:()=>r===!0?o():l.value===!0?[g(be,{to:s},g(ze,o))]:void 0}}const Ae={transitionShow:{type:String,default:"fade"},transitionHide:{type:String,default:"fade"},transitionDuration:{type:[String,Number],default:300}};function Ie(e,n=()=>{},o=()=>{}){return{transitionProps:f(()=>{const a=`q-transition--${e.transitionShow||n()}`,l=`q-transition--${e.transitionHide||o()}`;return{appear:!0,enterFromClass:`${a}-enter-from`,enterActiveClass:`${a}-enter-active`,enterToClass:`${a}-enter-to`,leaveFromClass:`${l}-leave-from`,leaveActiveClass:`${l}-leave-active`,leaveToClass:`${l}-leave-to`}}),transitionStyle:f(()=>`--q-transition-duration: ${e.transitionDuration}ms`)}}function Ke(){let e;const n=J();function o(){e=void 0}return ke(o),U(o),{removeTick:o,registerTick(a){e=a,we(()=>{e===a&&(_e(n)===!1&&e(),e=void 0)})}}}const h=[];let w;function Re(e){w=e.keyCode===27}function Ne(){w===!0&&(w=!1)}function je(e){w===!0&&(w=!1,ye(e,27)===!0&&h[h.length-1](e))}function Y(e){window[e]("keydown",Re),window[e]("blur",Ne),window[e]("keyup",je),w=!1}function Ge(e){X.is.desktop===!0&&(h.push(e),h.length===1&&Y("addEventListener"))}function j(e){const n=h.indexOf(e);n!==-1&&(h.splice(n,1),h.length===0&&Y("removeEventListener"))}const b=[];function Z(e){b[b.length-1](e)}function We(e){X.is.desktop===!0&&(b.push(e),b.length===1&&document.body.addEventListener("focusin",Z))}function G(e){const n=b.indexOf(e);n!==-1&&(b.splice(n,1),b.length===0&&document.body.removeEventListener("focusin",Z))}let S=0;const Ve={standard:"fixed-full flex-center",top:"fixed-top justify-center",bottom:"fixed-bottom justify-center",right:"fixed-right items-center",left:"fixed-left items-center"},W={standard:["scale","scale"],top:["slide-down","slide-up"],bottom:["slide-up","slide-down"],right:["slide-left","slide-right"],left:["slide-right","slide-left"]},ot=V({name:"QDialog",inheritAttrs:!1,props:{...Pe,...Ae,transitionShow:String,transitionHide:String,persistent:Boolean,autoClose:Boolean,allowFocusOutside:Boolean,noEscDismiss:Boolean,noBackdropDismiss:Boolean,noRouteDismiss:Boolean,noRefocus:Boolean,noFocus:Boolean,noShake:Boolean,seamless:Boolean,maximized:Boolean,fullWidth:Boolean,fullHeight:Boolean,square:Boolean,backdropFilter:String,position:{type:String,default:"standard",validator:e=>["standard","top","bottom","left","right"].includes(e)}},emits:[...qe,"shake","click","escapeKey"],setup(e,{slots:n,emit:o,attrs:a}){const l=J(),u=P(null),s=P(!1),c=P(!1);let r=null,d=null,m,v;const y=f(()=>e.persistent!==!0&&e.noRouteDismiss!==!0&&e.seamless!==!0),{preventBodyScroll:D}=Se(),{registerTimeout:M}=Ee(),{registerTick:ee,removeTick:H}=Ke(),{transitionProps:te,transitionStyle:Q}=Ie(e,()=>W[e.position][0],()=>W[e.position][1]),ne=f(()=>Q.value+(e.backdropFilter!==void 0?`;backdrop-filter:${e.backdropFilter};-webkit-backdrop-filter:${e.backdropFilter}`:"")),{showPortal:z,hidePortal:O,portalIsAccessible:oe,renderPortal:ie}=Le(l,u,ve,"dialog"),{hide:p}=pe({showing:s,hideOnRouteChange:y,handleShow:ce,handleHide:de,processOnMount:!0}),{addToHistory:ae,removeFromHistory:le}=xe(s,p,y),se=f(()=>`q-dialog__inner flex no-pointer-events q-dialog__inner--${e.maximized===!0?"maximized":"minimized"} q-dialog__inner--${e.position} ${Ve[e.position]}`+(c.value===!0?" q-dialog__inner--animating":"")+(e.fullWidth===!0?" q-dialog__inner--fullwidth":"")+(e.fullHeight===!0?" q-dialog__inner--fullheight":"")+(e.square===!0?" q-dialog__inner--square":"")),x=f(()=>s.value===!0&&e.seamless!==!0),ue=f(()=>e.autoClose===!0?{onClick:fe}:{}),re=f(()=>[`q-dialog fullscreen no-pointer-events q-dialog--${x.value===!0?"modal":"seamless"}`,a.class]);K(()=>e.maximized,t=>{s.value===!0&&$(t)}),K(x,t=>{D(t),t===!0?(We(B),Ge(T)):(G(B),j(T))});function ce(t){ae(),d=e.noRefocus===!1&&document.activeElement!==null?document.activeElement:null,$(e.maximized),z(),c.value=!0,e.noFocus!==!0?(document.activeElement?.blur(),ee(q)):H(),M(()=>{if(l.proxy.$q.platform.is.ios===!0){if(e.seamless!==!0&&document.activeElement){const{top:i,bottom:k}=document.activeElement.getBoundingClientRect(),{innerHeight:A}=window,F=window.visualViewport!==void 0?window.visualViewport.height:A;i>0&&k>F/2&&(document.scrollingElement.scrollTop=Math.min(document.scrollingElement.scrollHeight-F,k>=A?1/0:Math.ceil(document.scrollingElement.scrollTop+k-F/2))),document.activeElement.scrollIntoView()}v=!0,u.value.click(),v=!1}z(!0),c.value=!1,o("show",t)},e.transitionDuration)}function de(t){H(),le(),L(!0),c.value=!0,O(),d!==null&&(((t?.type.indexOf("key")===0?d.closest('[tabindex]:not([tabindex^="-"])'):void 0)||d).focus(),d=null),M(()=>{O(!0),c.value=!1,o("hide",t)},e.transitionDuration)}function q(t){$e(()=>{let i=u.value;if(i!==null){if(t!==void 0){const k=i.querySelector(t);if(k!==null){k.focus({preventScroll:!0});return}}i.contains(document.activeElement)!==!0&&(i=i.querySelector("[autofocus][tabindex], [data-autofocus][tabindex]")||i.querySelector("[autofocus] [tabindex], [data-autofocus] [tabindex]")||i.querySelector("[autofocus], [data-autofocus]")||i,i.focus({preventScroll:!0}))}})}function C(t){t&&typeof t.focus=="function"?t.focus({preventScroll:!0}):q(),o("shake");const i=u.value;i!==null&&(i.classList.remove("q-animate--scale"),i.classList.add("q-animate--scale"),r!==null&&clearTimeout(r),r=setTimeout(()=>{r=null,u.value!==null&&(i.classList.remove("q-animate--scale"),q())},170))}function T(){e.seamless!==!0&&(e.persistent===!0||e.noEscDismiss===!0?e.maximized!==!0&&e.noShake!==!0&&C():(o("escapeKey"),p()))}function L(t){r!==null&&(clearTimeout(r),r=null),(t===!0||s.value===!0)&&($(!1),e.seamless!==!0&&(D(!1),G(B),j(T))),t!==!0&&(d=null)}function $(t){t===!0?m!==!0&&(S<1&&document.body.classList.add("q-body--dialog"),S++,m=!0):m===!0&&(S<2&&document.body.classList.remove("q-body--dialog"),S--,m=!1)}function fe(t){v!==!0&&(p(t),o("click",t))}function me(t){e.persistent!==!0&&e.noBackdropDismiss!==!0?p(t):e.noShake!==!0&&C()}function B(t){e.allowFocusOutside!==!0&&oe.value===!0&&Ce(u.value,t.target)!==!0&&q('[tabindex]:not([tabindex="-1"])')}Object.assign(l.proxy,{focus:q,shake:C,__updateRefocusTarget(t){d=t||null}}),U(L);function ve(){return g("div",{role:"dialog","aria-modal":x.value===!0?"true":"false",...a,class:re.value},[g(R,{name:"q-transition--fade",appear:!0},()=>x.value===!0?g("div",{class:"q-dialog__backdrop fixed-full",style:ne.value,"aria-hidden":"true",tabindex:-1,onClick:me}):null),g(R,te.value,()=>s.value===!0?g("div",{ref:u,class:se.value,style:Q.value,tabindex:-1,...ue.value},Be(n.default)):null)])}return ie}});export{ot as Q,Ke as a,Le as b,nt as c,Ge as d,We as e,G as f,tt as g,Ie as h,Qe as i,_ as p,j as r,Ae as u};
|