@inertiaui/modal-react 1.0.0-beta-4 → 2.0.0-beta.1
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/CloseButton.d.ts +5 -0
- package/dist/Deferred.d.ts +11 -0
- package/dist/HeadlessModal.d.ts +64 -0
- package/dist/Modal.d.ts +48 -0
- package/dist/ModalContent.d.ts +24 -0
- package/dist/ModalLink.d.ts +29 -0
- package/dist/ModalRenderer.d.ts +4 -0
- package/dist/ModalRoot.d.ts +22 -0
- package/dist/SlideoverContent.d.ts +24 -0
- package/dist/WhenVisible.d.ts +16 -0
- package/dist/config.d.ts +21 -0
- package/dist/constants.d.ts +7 -0
- package/dist/helpers.d.ts +3 -0
- package/dist/inertiaui-modal.d.ts +2 -0
- package/dist/inertiaui-modal.js +1680 -2147
- package/dist/inertiaui-modal.js.map +1 -0
- package/dist/inertiaui-modal.umd.cjs +1854 -21
- package/dist/inertiaui-modal.umd.cjs.map +1 -0
- package/dist/inertiauiModal.d.ts +21 -0
- package/dist/types.d.ts +111 -0
- package/dist/useModal.d.ts +2 -0
- package/package.json +33 -23
- package/src/{CloseButton.jsx → CloseButton.tsx} +5 -1
- package/src/{Deferred.jsx → Deferred.tsx} +10 -3
- package/src/HeadlessModal.tsx +238 -0
- package/src/Modal.tsx +292 -0
- package/src/ModalContent.tsx +311 -0
- package/src/ModalLink.tsx +224 -0
- package/src/ModalRenderer.tsx +33 -0
- package/src/ModalRoot.tsx +880 -0
- package/src/SlideoverContent.tsx +319 -0
- package/src/{WhenVisible.jsx → WhenVisible.tsx} +20 -9
- package/src/config.ts +99 -0
- package/src/constants.ts +22 -0
- package/src/helpers.ts +17 -0
- package/src/inertiauiModal.ts +65 -0
- package/src/types.ts +150 -0
- package/src/useModal.ts +7 -0
- package/src/HeadlessModal.jsx +0 -143
- package/src/Modal.jsx +0 -136
- package/src/ModalContent.jsx +0 -56
- package/src/ModalLink.jsx +0 -123
- package/src/ModalRenderer.jsx +0 -34
- package/src/ModalRoot.jsx +0 -625
- package/src/SlideoverContent.jsx +0 -55
- package/src/config.js +0 -3
- package/src/helpers.js +0 -2
- package/src/inertiauiModal.js +0 -34
- package/src/useModal.js +0 -6
|
@@ -1,21 +1,1854 @@
|
|
|
1
|
-
(function(C,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react"),require("react/jsx-runtime"),require("axios"),require("@inertiajs/react"),require("@inertiajs/core"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime","axios","@inertiajs/react","@inertiajs/core","react-dom"],o):(C=typeof globalThis<"u"?globalThis:C||self,o(C.InertiaUIModal={},C.React,C.jsxRuntime,C.Axios,C.InertiaReact,C.core,C.ReactDOM))})(this,(function(C,o,O,Le,ne,Lr,Fr){"use strict";var Rl=Object.defineProperty;var eo=(C,o,O)=>o in C?Rl(C,o,{enumerable:!0,configurable:!0,writable:!0,value:O}):C[o]=O;var B=(C,o,O)=>eo(C,typeof o!="symbol"?o+"":o,O);function Mt(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const ve=Mt(o),Pt=Mt(ne),ge={type:"modal",navigate:!1,modal:{closeButton:!0,closeExplicitly:!1,maxWidth:"2xl",paddingClasses:"p-4 sm:p-6",panelClasses:"bg-white rounded",position:"center"},slideover:{closeButton:!0,closeExplicitly:!1,maxWidth:"md",paddingClasses:"p-4 sm:p-6",panelClasses:"bg-white min-h-screen",position:"right"}};class Ar{constructor(){this.config={},this.reset()}reset(){this.config=JSON.parse(JSON.stringify(ge))}put(t,r){if(typeof t=="object"){this.config={type:t.type??ge.type,navigate:t.navigate??ge.navigate,modal:{...ge.modal,...t.modal??{}},slideover:{...ge.slideover,...t.slideover??{}}};return}const n=t.split(".");let l=this.config;for(let i=0;i<n.length-1;i++)l=l[n[i]]=l[n[i]]||{};l[n[n.length-1]]=r}get(t){if(typeof t>"u")return this.config;const r=t.split(".");let n=this.config;for(const l of r){if(n[l]===void 0)return null;n=n[l]}return n}}const Fe=new Ar,Nr=()=>Fe.reset(),Ir=(e,t)=>Fe.put(e,t),Ae=e=>Fe.get(e),de=(e,t)=>Fe.get(e?`slideover.${t}`:`modal.${t}`);function Dr(e,t){const r=typeof window<"u"?window.location.origin:"http://localhost";return e=typeof e=="string"?new URL(e,r):e,t=typeof t=="string"?new URL(t,r):t,`${e.origin}${e.pathname}`==`${t.origin}${t.pathname}`}function rt(e="inertiaui_modal_"){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`${e}${crypto.randomUUID()}`:`${e}${Date.now().toString(36)}_${Math.random().toString(36).substr(2,9)}`}function ce(e){return typeof e=="string"?e.toLowerCase():e}function jr(e,t,r=!1){return r&&(t=t.map(ce)),Array.isArray(e)?e.filter(n=>!t.includes(r?ce(n):n)):Object.keys(e).reduce((n,l)=>(t.includes(r?ce(l):l)||(n[l]=e[l]),n),{})}function _r(e,t,r=!1){return r&&(t=t.map(ce)),Array.isArray(e)?e.filter(n=>t.includes(r?ce(n):n)):Object.keys(e).reduce((n,l)=>(t.includes(r?ce(l):l)&&(n[l]=e[l]),n),{})}function Wr(e){return Array.isArray(e)?e.filter(t=>t!==null):Object.keys(e).reduce((t,r)=>(r in e&&e[r]!==null&&(t[r]=e[r]),t),{})}function we(e){return e?(e=e.replace(/_/g,"-"),e=e.replace(/-+/g,"-"),/[A-Z]/.test(e)?(e=e.replace(/\s+/g,"").replace(/_/g,"").replace(/(?:^|\s|-)+([A-Za-z])/g,(t,r)=>r.toUpperCase()),e=e.replace(/(.)(?=[A-Z])/g,"$1-"),e.toLowerCase()):e):""}function Ur(e){if(typeof window<"u")return e.toLowerCase()in window;if(typeof document<"u"){const n=document.createElement("div");return e.toLowerCase()in n}const t=e.toLowerCase();return[/^on(click|dblclick|mousedown|mouseup|mouseover|mouseout|mousemove|mouseenter|mouseleave)$/,/^on(keydown|keyup|keypress)$/,/^on(focus|blur|change|input|submit|reset)$/,/^on(load|unload|error|resize|scroll)$/,/^on(touchstart|touchend|touchmove|touchcancel)$/,/^on(pointerdown|pointerup|pointermove|pointerenter|pointerleave|pointercancel)$/,/^on(drag|dragstart|dragend|dragenter|dragleave|dragover|drop)$/,/^on(animationstart|animationend|animationiteration)$/,/^on(transitionstart|transitionend|transitionrun|transitioncancel)$/].some(n=>n.test(t))}const Ne=o.createContext(null);Ne.displayName="ModalStackContext";let Tt=null,kt=null,fe=null,Ie={},nt=[],pe={};const Lt=({children:e})=>{const[t,r]=o.useState([]),[n,l]=o.useState({}),i=v=>{r(d=>{const c=v([...d]),g=b=>{var m;return c.length<2?!0:((m=c.map(x=>({id:x.id,shouldRender:x.shouldRender})).reverse().find(x=>x.shouldRender))==null?void 0:m.id)===b};return c.forEach((b,m)=>{c[m].onTopOfStack=g(b.id),c[m].getParentModal=()=>m<1?null:c.slice(0,m).reverse().find(x=>x.isOpen),c[m].getChildModal=()=>m===c.length-1?null:c.slice(m+1).find(x=>x.isOpen)}),c})};o.useEffect(()=>{nt=t},[t]);class a{constructor(d,c,g,b,m){B(this,"show",()=>{i(d=>d.map(c=>(c.id===this.id&&!c.isOpen&&(c.isOpen=!0,c.shouldRender=!0),c)))});B(this,"setOpen",d=>{d?this.show():this.close()});B(this,"close",()=>{i(d=>{let c=!1;const g=d.map(b=>{var m;return b.id===this.id&&b.isOpen&&(Object.keys(b.listeners).forEach(x=>{b.off(x)}),b.isOpen=!1,(m=b.onCloseCallback)==null||m.call(b),c=!0),b});return c?g:d})});B(this,"afterLeave",()=>{this.isOpen||i(d=>{const c=d.map(g=>{var b;return g.id===this.id&&!g.isOpen&&(g.shouldRender=!1,(b=g.afterLeaveCallback)==null||b.call(g),g.afterLeaveCallback=null),g});return this.index===0?[]:c})});B(this,"on",(d,c)=>{d=we(d),this.listeners[d]=this.listeners[d]??[],this.listeners[d].push(c)});B(this,"off",(d,c)=>{var g;d=we(d),c?this.listeners[d]=((g=this.listeners[d])==null?void 0:g.filter(b=>b!==c))??[]:delete this.listeners[d]});B(this,"emit",(d,...c)=>{var g;(g=this.listeners[we(d)])==null||g.forEach(b=>b(...c))});B(this,"registerEventListenersFromProps",d=>{const c=[];return Object.keys(d).filter(g=>g.startsWith("on")).forEach(g=>{const b=we(g).replace(/^on-/,"");this.on(b,d[g]),c.push(()=>this.off(b,d[g]))}),()=>c.forEach(g=>g())});B(this,"reload",(d={})=>{var m,x;let c=Object.keys(this.response.props);if(d.only&&(c=d.only),d.except&&(c=jr(c,d.except)),!((m=this.response)!=null&&m.url))return;const g=(d.method??"get").toLowerCase(),b=d.data??{};(x=d.onStart)==null||x.call(d),Le({url:this.response.url,method:g,data:g==="get"?{}:b,params:g==="get"?b:{},headers:{...d.headers??{},Accept:"text/html, application/xhtml+xml","X-Inertia":!0,"X-Inertia-Partial-Component":this.response.component,"X-Inertia-Version":this.response.version,"X-Inertia-Partial-Data":c.join(","),"X-InertiaUI-Modal":rt(),"X-InertiaUI-Modal-Use-Router":0,"X-InertiaUI-Modal-Base-Url":fe}}).then(S=>{var F;this.updateProps(S.data.props),(F=d.onSuccess)==null||F.call(d,S)}).catch(S=>{var F;(F=d.onError)==null||F.call(d,S)}).finally(()=>{var S;(S=d.onFinish)==null||S.call(d)})});B(this,"updateProps",d=>{Object.assign(this.props,d),i(c=>c)});if(this.id=c.id??rt(),this.isOpen=!1,this.shouldRender=!1,this.listeners={},this.component=d,this.props=c.props,this.response=c,this.config=g??{},this.onCloseCallback=b,this.afterLeaveCallback=m,pe[this.id]){this.config={...this.config,...pe[this.id].config??{}};const x=pe[this.id].onClose,S=pe[this.id].onAfterLeave;x&&(this.onCloseCallback=b?()=>{b(),x()}:x),S&&(this.afterLeaveCallback=m?()=>{m(),S()}:S),delete pe[this.id]}this.index=-1,this.getParentModal=()=>null,this.getChildModal=()=>null,this.onTopOfStack=!0}static generateId(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`inertiaui_modal_${crypto.randomUUID()}`:`inertiaui_modal_${Date.now().toString(36)}_${Math.random().toString(36).substr(2,9)}`}}const u=(v,d={},c=null,g=null)=>kt(v.component).then(b=>p(b,v,d,c,g)),s=v=>{var c,g;const d=(g=(c=v.response)==null?void 0:c.meta)==null?void 0:g.deferredProps;d&&Object.keys(d).forEach(b=>{v.reload({only:d[b]})})},p=(v,d,c,g,b)=>{const m=new a(v,d,c,g,b);return m.index=t.length,i(x=>[...x,m]),s(m),m.show(),m};function h(v,d,c,g){if(!n[v])throw new Error(`The local modal "${v}" has not been registered.`);const b=p(null,{},d,c,g);return b.name=v,n[v].callback(b),b}const w=(v,d={})=>y(v,d.method??"get",d.data??{},d.headers??{},d.config??{},d.onClose,d.onAfterLeave,d.queryStringArrayFormat??"brackets",d.navigate??Ae("navigate"),d.onStart,d.onSuccess,d.onError).then(c=>{const g=d.listeners??{};return Object.keys(g).forEach(b=>{const m=we(b);c.on(m,g[b])}),c}),y=(v,d,c={},g={},b={},m=null,x=null,S="brackets",F=!1,j=null,L=null,A=null)=>{const H=rt();return new Promise((N,T)=>{if(v.startsWith("#")){N(h(v.substring(1),b,m,x));return}const[_,he]=Lr.mergeDataIntoQueryString(d,v||"",c,S);let ae=F&&t.length===0;if(t.length===0&&(fe=typeof window<"u"?window.location.href:""),g={...g,Accept:"text/html, application/xhtml+xml","X-Requested-With":"XMLHttpRequest","X-Inertia":!0,"X-Inertia-Version":Tt,"X-InertiaUI-Modal":H,"X-InertiaUI-Modal-Use-Router":ae?1:0,"X-InertiaUI-Modal-Base-Url":fe},ae)return Ie={},pe[H]={config:b,onClose:m,onAfterLeave:x},ne.router.visit(_,{method:d,data:he,headers:g,preserveScroll:!0,preserveState:!0,onError(...k){A==null||A(...k),T(...k)},onStart(...k){j==null||j(...k)},onSuccess(...k){L==null||L(...k)},onBefore:()=>{Ie[H]=N}});j==null||j();const J=k=>{try{Pt.progress&&k(Pt.progress)}catch{}};J(k=>k.start()),Le({url:_,method:d,data:he,headers:g}).then(k=>{L==null||L(k),N(u(k.data,b,m,x))}).catch((...k)=>{A==null||A(...k),T(...k)}).finally(()=>{J(k=>k.finish())})})},$={stack:t,localModals:n,push:p,pushFromResponseData:u,length:()=>nt.length,closeAll:()=>{nt.reverse().forEach(v=>v.close())},reset:()=>i(()=>[]),visit:y,visitModal:w,registerLocalModal:(v,d)=>{l(c=>({...c,[v]:{name:v,callback:d}}))},removeLocalModal:v=>{l(d=>{const c={...d};return delete c[v],c})},onModalOnBase:v=>{const d=Ie[v.id];d&&(d(v),delete Ie[v.id])}};return O.jsx(Ne.Provider,{value:$,children:e})},be=()=>{const e=o.useContext(Ne);if(e===null)throw new Error("useModalStack must be used within a ModalStackProvider");return e},Ft=["closeButton","closeExplicitly","maxWidth","paddingClasses","panelClasses","position","slideover"],At=e=>{e.initialPage&&(Tt=e.initialPage.version),e.resolveComponent&&(kt=e.resolveComponent)},Hr=(e,t)=>{At(t);const r=({Component:n,props:l,key:i})=>{const a=()=>{const u=o.createElement(n,{key:i,...l});return typeof n.layout=="function"?n.layout(u):Array.isArray(n.layout)?n.layout.concat(u).reverse().reduce((p,h)=>o.createElement(h,l,p)):u};return O.jsxs(O.Fragment,{children:[a(),O.jsx(Nt,{})]})};return O.jsx(Lt,{children:O.jsx(e,{...t,children:r})})},Nt=({children:e})=>{var s,p;const t=o.useContext(Ne),r=ne.usePage();let n=!1,l=!1,i=!!((s=r.props)!=null&&s._inertiaui_modal);o.useEffect(()=>ne.router.on("start",()=>n=!0),[]),o.useEffect(()=>ne.router.on("finish",()=>n=!1),[]),o.useEffect(()=>ne.router.on("navigate",function(h){const w=h.detail.page.props._inertiaui_modal;if(!w){l&&t.closeAll(),fe=null,i=!1;return}l=w,fe=w.baseUrl,t.pushFromResponseData(w,{},()=>{if(!w.baseUrl){console.error("No base url in modal response data so cannot navigate back");return}!n&&typeof window<"u"&&window.location.href!==w.baseUrl&&ne.router.visit(w.baseUrl,{preserveScroll:!0,preserveState:!0})}).then(t.onModalOnBase)}),[]);const a=h=>{var w;return h.headers["X-InertiaUI-Modal-Base-Url"]=fe??(i?(w=r.props._inertiaui_modal)==null?void 0:w.baseUrl:null),h};o.useEffect(()=>(Le.interceptors.request.use(a),()=>Le.interceptors.request.eject(a)),[]);const u=o.useRef();return o.useEffect(()=>{var y,E;const h=(y=r.props)==null?void 0:y._inertiaui_modal,w=u.current;u.current=h,h&&w&&h.component===w.component&&Dr(h.url,w.url)&&((E=t.stack[0])==null||E.updateProps(h.props??{}))},[(p=r.props)==null?void 0:p._inertiaui_modal]),O.jsxs(O.Fragment,{children:[e,t.stack.length>0&&O.jsx(It,{index:0})]})},lt=o.createContext(null);lt.displayName="ModalIndexContext";const ot=()=>{const e=o.useContext(lt);if(e===void 0)throw new Error("useModalIndex must be used within a ModalIndexProvider");return e},It=({index:e})=>{const{stack:t}=be(),r=o.useMemo(()=>t[e],[t,e]);return(r==null?void 0:r.component)&&O.jsx(lt.Provider,{value:e,children:O.jsx(r.component,{...r.props,onModalEvent:(...n)=>r.emit(...n)})})};function it(){return be().stack[ot()]??null}const Dt=({children:e,data:t,fallback:r})=>{if(!t)throw new Error("`<Deferred>` requires a `data` prop to be a string or array of strings");const[n,l]=o.useState(!1),i=Array.isArray(t)?t:[t],a=it().props;return o.useEffect(()=>{l(i.every(u=>a[u]!==void 0))},[a,i]),n?e:r};Dt.displayName="InertiaModalDeferred";const st=o.forwardRef(({name:e,children:t,onFocus:r=null,onBlur:n=null,onClose:l=null,onSuccess:i=null,...a},u)=>{const s=ot(),{stack:p,registerLocalModal:h,removeLocalModal:w}=be(),[y,E]=o.useState(null),f=o.useMemo(()=>e?y:p[s],[e,y,s,p]),$=o.useMemo(()=>{var m;return(m=p.find(x=>x.shouldRender&&x.index>(f==null?void 0:f.index)))==null?void 0:m.index},[s,p]),v=o.useMemo(()=>(f==null?void 0:f.config.slideover)??a.slideover??Ae("type")==="slideover",[a.slideover]),d=o.useMemo(()=>({slideover:v,closeButton:a.closeButton??de(v,"closeButton"),closeExplicitly:a.closeExplicitly??de(v,"closeExplicitly"),maxWidth:a.maxWidth??de(v,"maxWidth"),paddingClasses:a.paddingClasses??de(v,"paddingClasses"),panelClasses:a.panelClasses??de(v,"panelClasses"),position:a.position??de(v,"position"),...f==null?void 0:f.config}),[a,f==null?void 0:f.config]);o.useEffect(()=>{if(e){let m=null;return h(e,x=>{m=x.registerEventListenersFromProps(a),E(x)}),()=>{m==null||m(),m=null,w(e)}}return f.registerEventListenersFromProps(a)},[e]);const c=o.useRef(f);o.useEffect(()=>{c.current=f},[f]),o.useEffect(()=>{f!==null&&(f.isOpen?i==null||i():l==null||l())},[f==null?void 0:f.isOpen]);const[g,b]=o.useState(!1);return o.useEffect(()=>{g&&f!==null&&f.isOpen&&(f.onTopOfStack?r==null||r():n==null||n()),b(!0)},[f==null?void 0:f.onTopOfStack]),o.useImperativeHandle(u,()=>({afterLeave:()=>{var m;return(m=c.current)==null?void 0:m.afterLeave()},close:()=>{var m;return(m=c.current)==null?void 0:m.close()},emit:(...m)=>{var x;return(x=c.current)==null?void 0:x.emit(...m)},getChildModal:()=>{var m;return(m=c.current)==null?void 0:m.getChildModal()},getParentModal:()=>{var m;return(m=c.current)==null?void 0:m.getParentModal()},reload:(...m)=>{var x;return(x=c.current)==null?void 0:x.reload(...m)},setOpen:()=>{var m;return(m=c.current)==null?void 0:m.setOpen()},get id(){var m;return(m=c.current)==null?void 0:m.id},get index(){var m;return(m=c.current)==null?void 0:m.index},get isOpen(){var m;return(m=c.current)==null?void 0:m.isOpen},get config(){var m;return(m=c.current)==null?void 0:m.config},get modalContext(){return c.current},get onTopOfStack(){var m;return(m=c.current)==null?void 0:m.onTopOfStack},get shouldRender(){var m;return(m=c.current)==null?void 0:m.shouldRender}}),[f]),(f==null?void 0:f.shouldRender)&&O.jsxs(O.Fragment,{children:[typeof t=="function"?t({afterLeave:f.afterLeave,close:f.close,config:d,emit:f.emit,getChildModal:f.getChildModal,getParentModal:f.getParentModal,id:f.id,index:f.index,isOpen:f.isOpen,modalContext:f,onTopOfStack:f.onTopOfStack,reload:f.reload,setOpen:f.setOpen,shouldRender:f.shouldRender}):t,$&&O.jsx(It,{index:$})]})});st.displayName="HeadlessModal";function jt(e){var t,r,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var l=e.length;for(t=0;t<l;t++)e[t]&&(r=jt(e[t]))&&(n&&(n+=" "),n+=r)}else for(r in e)e[r]&&(n&&(n+=" "),n+=r);return n}function De(){for(var e,t,r=0,n="",l=arguments.length;r<l;r++)(e=arguments[r])&&(t=jt(e))&&(n&&(n+=" "),n+=t);return n}var Vr=Object.defineProperty,Br=(e,t,r)=>t in e?Vr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ut=(e,t,r)=>(Br(e,typeof t!="symbol"?t+"":t,r),r);let qr=class{constructor(){ut(this,"current",this.detect()),ut(this,"handoffState","pending"),ut(this,"currentId",0)}set(t){this.current!==t&&(this.handoffState="pending",this.currentId=0,this.current=t)}reset(){this.set(this.detect())}nextId(){return++this.currentId}get isServer(){return this.current==="server"}get isClient(){return this.current==="client"}detect(){return typeof window>"u"||typeof document>"u"?"server":"client"}handoff(){this.handoffState==="pending"&&(this.handoffState="complete")}get isHandoffComplete(){return this.handoffState==="complete"}},z=new qr;function je(e){var t,r;return z.isServer?null:e?"ownerDocument"in e?e.ownerDocument:"current"in e?(r=(t=e.current)==null?void 0:t.ownerDocument)!=null?r:document:null:document}function _e(e){typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e).catch(t=>setTimeout(()=>{throw t}))}function G(){let e=[],t={addEventListener(r,n,l,i){return r.addEventListener(n,l,i),t.add(()=>r.removeEventListener(n,l,i))},requestAnimationFrame(...r){let n=requestAnimationFrame(...r);return t.add(()=>cancelAnimationFrame(n))},nextFrame(...r){return t.requestAnimationFrame(()=>t.requestAnimationFrame(...r))},setTimeout(...r){let n=setTimeout(...r);return t.add(()=>clearTimeout(n))},microTask(...r){let n={current:!0};return _e(()=>{n.current&&r[0]()}),t.add(()=>{n.current=!1})},style(r,n,l){let i=r.style.getPropertyValue(n);return Object.assign(r.style,{[n]:l}),this.add(()=>{Object.assign(r.style,{[n]:i})})},group(r){let n=G();return r(n),this.add(()=>n.dispose())},add(r){return e.includes(r)||e.push(r),()=>{let n=e.indexOf(r);if(n>=0)for(let l of e.splice(n,1))l()}},dispose(){for(let r of e.splice(0))r()}};return t}function We(){let[e]=o.useState(G);return o.useEffect(()=>()=>e.dispose(),[e]),e}let I=(e,t)=>{z.isServer?o.useEffect(e,t):o.useLayoutEffect(e,t)};function le(e){let t=o.useRef(e);return I(()=>{t.current=e},[e]),t}let P=function(e){let t=le(e);return o.useCallback((...r)=>t.current(...r),[t])};function ye(e){return o.useMemo(()=>e,Object.values(e))}let Xr=o.createContext(void 0);function zr(){return o.useContext(Xr)}function at(...e){return Array.from(new Set(e.flatMap(t=>typeof t=="string"?t.split(" "):[]))).filter(Boolean).join(" ")}function K(e,t,...r){if(e in t){let l=t[e];return typeof l=="function"?l(...r):l}let n=new Error(`Tried to handle "${e}" but there is no handler defined. Only defined handlers are: ${Object.keys(t).map(l=>`"${l}"`).join(", ")}.`);throw Error.captureStackTrace&&Error.captureStackTrace(n,K),n}var Ue=(e=>(e[e.None=0]="None",e[e.RenderStrategy=1]="RenderStrategy",e[e.Static=2]="Static",e))(Ue||{}),Q=(e=>(e[e.Unmount=0]="Unmount",e[e.Hidden=1]="Hidden",e))(Q||{});function W(){let e=Kr();return o.useCallback(t=>Gr({mergeRefs:e,...t}),[e])}function Gr({ourProps:e,theirProps:t,slot:r,defaultTag:n,features:l,visible:i=!0,name:a,mergeRefs:u}){u=u??Yr;let s=_t(t,e);if(i)return He(s,r,n,a,u);let p=l??0;if(p&2){let{static:h=!1,...w}=s;if(h)return He(w,r,n,a,u)}if(p&1){let{unmount:h=!0,...w}=s;return K(h?0:1,{0(){return null},1(){return He({...w,hidden:!0,style:{display:"none"}},r,n,a,u)}})}return He(s,r,n,a,u)}function He(e,t={},r,n,l){let{as:i=r,children:a,refName:u="ref",...s}=dt(e,["unmount","static"]),p=e.ref!==void 0?{[u]:e.ref}:{},h=typeof a=="function"?a(t):a;"className"in s&&s.className&&typeof s.className=="function"&&(s.className=s.className(t)),s["aria-labelledby"]&&s["aria-labelledby"]===s.id&&(s["aria-labelledby"]=void 0);let w={};if(t){let y=!1,E=[];for(let[f,$]of Object.entries(t))typeof $=="boolean"&&(y=!0),$===!0&&E.push(f.replace(/([A-Z])/g,v=>`-${v.toLowerCase()}`));if(y){w["data-headlessui-state"]=E.join(" ");for(let f of E)w[`data-${f}`]=""}}if(Ee(i)&&(Object.keys(oe(s)).length>0||Object.keys(oe(w)).length>0))if(!o.isValidElement(h)||Array.isArray(h)&&h.length>1||Jr(h)){if(Object.keys(oe(s)).length>0)throw new Error(['Passing props on "Fragment"!',"",`The current component <${n} /> is rendering a "Fragment".`,"However we need to passthrough the following props:",Object.keys(oe(s)).concat(Object.keys(oe(w))).map(y=>` - ${y}`).join(`
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*/var Zt;function $n(){return Zt||(Zt=1,process.env.NODE_ENV!=="production"&&(function(){function e(s,p){return s===p&&(s!==0||1/s===1/p)||s!==s&&p!==p}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var t=o,r=typeof Object.is=="function"?Object.is:e,n=t.useSyncExternalStore,l=t.useRef,i=t.useEffect,a=t.useMemo,u=t.useDebugValue;vt.useSyncExternalStoreWithSelector=function(s,p,h,w,y){var E=l(null);if(E.current===null){var f={hasValue:!1,value:null};E.current=f}else f=E.current;E=a(function(){function v(m){if(!d){if(d=!0,c=m,m=w(m),y!==void 0&&f.hasValue){var x=f.value;if(y(x,m))return g=x}return g=m}if(x=g,r(c,m))return x;var S=w(m);return y!==void 0&&y(x,S)?(c=m,x):(c=m,g=S)}var d=!1,c,g,b=h===void 0?null:h;return[function(){return v(p())},b===null?void 0:function(){return v(b())}]},[p,h,w,y]);var $=n(s,E[0],E[1]);return i(function(){f.hasValue=!0,f.value=$},[$]),u($),$},typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()),vt}var Jt;function On(){return Jt||(Jt=1,process.env.NODE_ENV==="production"?Be.exports=xn():Be.exports=$n()),Be.exports}var Sn=On();function Qt(e,t,r=Xt){return Sn.useSyncExternalStoreWithSelector(P(n=>e.subscribe(Cn,n)),P(()=>e.state),P(()=>e.state),P(t),r)}function Cn(e){return e}function Oe(e,t){let r=o.useId(),n=Kt.get(t),[l,i]=Qt(n,o.useCallback(a=>[n.selectors.isTop(a,r),n.selectors.inStack(a,r)],[n,r]));return I(()=>{if(e)return n.actions.push(r),()=>n.actions.pop(r)},[n,e,r]),e?i?l:!0:!1}let gt=new Map,Se=new Map;function Rt(e){var t;let r=(t=Se.get(e))!=null?t:0;return Se.set(e,r+1),r!==0?()=>er(e):(gt.set(e,{"aria-hidden":e.getAttribute("aria-hidden"),inert:e.inert}),e.setAttribute("aria-hidden","true"),e.inert=!0,()=>er(e))}function er(e){var t;let r=(t=Se.get(e))!=null?t:1;if(r===1?Se.delete(e):Se.set(e,r-1),r!==1)return;let n=gt.get(e);n&&(n["aria-hidden"]===null?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",n["aria-hidden"]),e.inert=n.inert,gt.delete(e))}function Mn(e,{allowed:t,disallowed:r}={}){let n=Oe(e,"inert-others");I(()=>{var l,i;if(!n)return;let a=G();for(let s of(l=r==null?void 0:r())!=null?l:[])s&&a.add(Rt(s));let u=(i=t==null?void 0:t())!=null?i:[];for(let s of u){if(!s)continue;let p=je(s);if(!p)continue;let h=s.parentElement;for(;h&&h!==p.body;){for(let w of h.children)u.some(y=>w.contains(y))||a.add(Rt(w));h=h.parentElement}}return a.dispose},[n,t,r])}function Pn(e,t,r){let n=le(l=>{let i=l.getBoundingClientRect();i.x===0&&i.y===0&&i.width===0&&i.height===0&&r()});o.useEffect(()=>{if(!e)return;let l=t===null?null:ie(t)?t:t.current;if(!l)return;let i=G();if(typeof ResizeObserver<"u"){let a=new ResizeObserver(()=>n.current(l));a.observe(l),i.add(()=>a.disconnect())}if(typeof IntersectionObserver<"u"){let a=new IntersectionObserver(()=>n.current(l));a.observe(l),i.add(()=>a.disconnect())}return()=>i.dispose()},[t,n,e])}let qe=["[contentEditable=true]","[tabindex]","a[href]","area[href]","button:not([disabled])","iframe","input:not([disabled])","select:not([disabled])","details>summary","textarea:not([disabled])"].map(e=>`${e}:not([tabindex='-1'])`).join(","),Tn=["[data-autofocus]"].map(e=>`${e}:not([tabindex='-1'])`).join(",");var Y=(e=>(e[e.First=1]="First",e[e.Previous=2]="Previous",e[e.Next=4]="Next",e[e.Last=8]="Last",e[e.WrapAround=16]="WrapAround",e[e.NoScroll=32]="NoScroll",e[e.AutoFocus=64]="AutoFocus",e))(Y||{}),wt=(e=>(e[e.Error=0]="Error",e[e.Overflow=1]="Overflow",e[e.Success=2]="Success",e[e.Underflow=3]="Underflow",e))(wt||{}),kn=(e=>(e[e.Previous=-1]="Previous",e[e.Next=1]="Next",e))(kn||{});function Ln(e=document.body){return e==null?[]:Array.from(e.querySelectorAll(qe)).sort((t,r)=>Math.sign((t.tabIndex||Number.MAX_SAFE_INTEGER)-(r.tabIndex||Number.MAX_SAFE_INTEGER)))}function Fn(e=document.body){return e==null?[]:Array.from(e.querySelectorAll(Tn)).sort((t,r)=>Math.sign((t.tabIndex||Number.MAX_SAFE_INTEGER)-(r.tabIndex||Number.MAX_SAFE_INTEGER)))}var tr=(e=>(e[e.Strict=0]="Strict",e[e.Loose=1]="Loose",e))(tr||{});function An(e,t=0){var r;return e===((r=je(e))==null?void 0:r.body)?!1:K(t,{0(){return e.matches(qe)},1(){let n=e;for(;n!==null;){if(n.matches(qe))return!0;n=n.parentElement}return!1}})}var Nn=(e=>(e[e.Keyboard=0]="Keyboard",e[e.Mouse=1]="Mouse",e))(Nn||{});typeof window<"u"&&typeof document<"u"&&(document.addEventListener("keydown",e=>{e.metaKey||e.altKey||e.ctrlKey||(document.documentElement.dataset.headlessuiFocusVisible="")},!0),document.addEventListener("click",e=>{e.detail===1?delete document.documentElement.dataset.headlessuiFocusVisible:e.detail===0&&(document.documentElement.dataset.headlessuiFocusVisible="")},!0));function Z(e){e==null||e.focus({preventScroll:!0})}let In=["textarea","input"].join(",");function Dn(e){var t,r;return(r=(t=e==null?void 0:e.matches)==null?void 0:t.call(e,In))!=null?r:!1}function jn(e,t=r=>r){return e.slice().sort((r,n)=>{let l=t(r),i=t(n);if(l===null||i===null)return 0;let a=l.compareDocumentPosition(i);return a&Node.DOCUMENT_POSITION_FOLLOWING?-1:a&Node.DOCUMENT_POSITION_PRECEDING?1:0})}function Ce(e,t,{sorted:r=!0,relativeTo:n=null,skipElements:l=[]}={}){let i=Array.isArray(e)?e.length>0?e[0].ownerDocument:document:e.ownerDocument,a=Array.isArray(e)?r?jn(e):e:t&64?Fn(e):Ln(e);l.length>0&&a.length>1&&(a=a.filter(E=>!l.some(f=>f!=null&&"current"in f?(f==null?void 0:f.current)===E:f===E))),n=n??i.activeElement;let u=(()=>{if(t&5)return 1;if(t&10)return-1;throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last")})(),s=(()=>{if(t&1)return 0;if(t&2)return Math.max(0,a.indexOf(n))-1;if(t&4)return Math.max(0,a.indexOf(n))+1;if(t&8)return a.length-1;throw new Error("Missing Focus.First, Focus.Previous, Focus.Next or Focus.Last")})(),p=t&32?{preventScroll:!0}:{},h=0,w=a.length,y;do{if(h>=w||h+w<=0)return 0;let E=s+h;if(t&16)E=(E+w)%w;else{if(E<0)return 3;if(E>=w)return 1}y=a[E],y==null||y.focus(p),h+=u}while(y!==i.activeElement);return t&6&&Dn(y)&&y.select(),2}function rr(){return/iPhone/gi.test(window.navigator.platform)||/Mac/gi.test(window.navigator.platform)&&window.navigator.maxTouchPoints>0}function _n(){return/Android/gi.test(window.navigator.userAgent)}function nr(){return rr()||_n()}function Xe(e,t,r,n){let l=le(r);o.useEffect(()=>{if(!e)return;function i(a){l.current(a)}return document.addEventListener(t,i,n),()=>document.removeEventListener(t,i,n)},[e,t,n])}function lr(e,t,r,n){let l=le(r);o.useEffect(()=>{if(!e)return;function i(a){l.current(a)}return window.addEventListener(t,i,n),()=>window.removeEventListener(t,i,n)},[e,t,n])}const or=30;function Wn(e,t,r){let n=le(r),l=o.useCallback(function(u,s){if(u.defaultPrevented)return;let p=s(u);if(p===null||!p.getRootNode().contains(p)||!p.isConnected)return;let h=(function w(y){return typeof y=="function"?w(y()):Array.isArray(y)||y instanceof Set?y:[y]})(t);for(let w of h)if(w!==null&&(w.contains(p)||u.composed&&u.composedPath().includes(w)))return;return!An(p,tr.Loose)&&p.tabIndex!==-1&&u.preventDefault(),n.current(u,p)},[n,t]),i=o.useRef(null);Xe(e,"pointerdown",u=>{var s,p;nr()||(i.current=((p=(s=u.composedPath)==null?void 0:s.call(u))==null?void 0:p[0])||u.target)},!0),Xe(e,"pointerup",u=>{if(nr()||!i.current)return;let s=i.current;return i.current=null,l(u,()=>s)},!0);let a=o.useRef({x:0,y:0});Xe(e,"touchstart",u=>{a.current.x=u.touches[0].clientX,a.current.y=u.touches[0].clientY},!0),Xe(e,"touchend",u=>{let s={x:u.changedTouches[0].clientX,y:u.changedTouches[0].clientY};if(!(Math.abs(s.x-a.current.x)>=or||Math.abs(s.y-a.current.y)>=or))return l(u,()=>ee(u.target)?u.target:null)},!0),lr(e,"blur",u=>l(u,()=>rn(window.document.activeElement)?window.document.activeElement:null),!0)}function ze(...e){return o.useMemo(()=>je(...e),[...e])}function ir(e,t,r,n){let l=le(r);o.useEffect(()=>{e=e??window;function i(a){l.current(a)}return e.addEventListener(t,i,n),()=>e.removeEventListener(t,i,n)},[e,t,n])}function Un(e){return o.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getSnapshot)}function Hn(e,t){let r=e(),n=new Set;return{getSnapshot(){return r},subscribe(l){return n.add(l),()=>n.delete(l)},dispatch(l,...i){let a=t[l].call(r,...i);a&&(r=a,n.forEach(u=>u()))}}}function Vn(){let e;return{before({doc:t}){var r;let n=t.documentElement,l=(r=t.defaultView)!=null?r:window;e=Math.max(0,l.innerWidth-n.clientWidth)},after({doc:t,d:r}){let n=t.documentElement,l=Math.max(0,n.clientWidth-n.offsetWidth),i=Math.max(0,e-l);r.style(n,"paddingRight",`${i}px`)}}}function Bn(){return rr()?{before({doc:e,d:t,meta:r}){function n(l){return r.containers.flatMap(i=>i()).some(i=>i.contains(l))}t.microTask(()=>{var l;if(window.getComputedStyle(e.documentElement).scrollBehavior!=="auto"){let u=G();u.style(e.documentElement,"scrollBehavior","auto"),t.add(()=>t.microTask(()=>u.dispose()))}let i=(l=window.scrollY)!=null?l:window.pageYOffset,a=null;t.addEventListener(e,"click",u=>{if(ee(u.target))try{let s=u.target.closest("a");if(!s)return;let{hash:p}=new URL(s.href),h=e.querySelector(p);ee(h)&&!n(h)&&(a=h)}catch{}},!0),t.addEventListener(e,"touchstart",u=>{if(ee(u.target)&&tn(u.target))if(n(u.target)){let s=u.target;for(;s.parentElement&&n(s.parentElement);)s=s.parentElement;t.style(s,"overscrollBehavior","contain")}else t.style(u.target,"touchAction","none")}),t.addEventListener(e,"touchmove",u=>{if(ee(u.target)){if(nn(u.target))return;if(n(u.target)){let s=u.target;for(;s.parentElement&&s.dataset.headlessuiPortal!==""&&!(s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth);)s=s.parentElement;s.dataset.headlessuiPortal===""&&u.preventDefault()}else u.preventDefault()}},{passive:!1}),t.add(()=>{var u;let s=(u=window.scrollY)!=null?u:window.pageYOffset;i!==s&&window.scrollTo(0,i),a&&a.isConnected&&(a.scrollIntoView({block:"nearest"}),a=null)})})}}:{}}function qn(){return{before({doc:e,d:t}){t.style(e.documentElement,"overflow","hidden")}}}function Xn(e){let t={};for(let r of e)Object.assign(t,r(t));return t}let se=Hn(()=>new Map,{PUSH(e,t){var r;let n=(r=this.get(e))!=null?r:{doc:e,count:0,d:G(),meta:new Set};return n.count++,n.meta.add(t),this.set(e,n),this},POP(e,t){let r=this.get(e);return r&&(r.count--,r.meta.delete(t)),this},SCROLL_PREVENT({doc:e,d:t,meta:r}){let n={doc:e,d:t,meta:Xn(r)},l=[Bn(),Vn(),qn()];l.forEach(({before:i})=>i==null?void 0:i(n)),l.forEach(({after:i})=>i==null?void 0:i(n))},SCROLL_ALLOW({d:e}){e.dispose()},TEARDOWN({doc:e}){this.delete(e)}});se.subscribe(()=>{let e=se.getSnapshot(),t=new Map;for(let[r]of e)t.set(r,r.documentElement.style.overflow);for(let r of e.values()){let n=t.get(r.doc)==="hidden",l=r.count!==0;(l&&!n||!l&&n)&&se.dispatch(r.count>0?"SCROLL_PREVENT":"SCROLL_ALLOW",r),r.count===0&&se.dispatch("TEARDOWN",r)}});function zn(e,t,r=()=>({containers:[]})){let n=Un(se),l=t?n.get(t):void 0,i=l?l.count>0:!1;return I(()=>{if(!(!t||!e))return se.dispatch("PUSH",t,r),()=>se.dispatch("POP",t,r)},[e,t]),i}function Gn(e,t,r=()=>[document.body]){let n=Oe(e,"scroll-lock");zn(n,t,l=>{var i;return{containers:[...(i=l.containers)!=null?i:[],r]}})}function Kn(e=0){let[t,r]=o.useState(e),n=o.useCallback(s=>r(s),[]),l=o.useCallback(s=>r(p=>p|s),[]),i=o.useCallback(s=>(t&s)===s,[t]),a=o.useCallback(s=>r(p=>p&~s),[]),u=o.useCallback(s=>r(p=>p^s),[]);return{flags:t,setFlag:n,addFlag:l,hasFlag:i,removeFlag:a,toggleFlag:u}}var sr,ur;typeof process<"u"&&typeof globalThis<"u"&&typeof Element<"u"&&((sr=process==null?void 0:process.env)==null?void 0:sr.NODE_ENV)==="test"&&typeof((ur=Element==null?void 0:Element.prototype)==null?void 0:ur.getAnimations)>"u"&&(Element.prototype.getAnimations=function(){return console.warn(["Headless UI has polyfilled `Element.prototype.getAnimations` for your tests.","Please install a proper polyfill e.g. `jsdom-testing-mocks`, to silence these warnings.","","Example usage:","```js","import { mockAnimationsApi } from 'jsdom-testing-mocks'","mockAnimationsApi()","```"].join(`
|
|
21
|
-
`)),[]});var Yn=(e=>(e[e.None=0]="None",e[e.Closed=1]="Closed",e[e.Enter=2]="Enter",e[e.Leave=4]="Leave",e))(Yn||{});function Zn(e){let t={};for(let r in e)e[r]===!0&&(t[`data-${r}`]="");return t}function Jn(e,t,r,n){let[l,i]=o.useState(r),{hasFlag:a,addFlag:u,removeFlag:s}=Kn(e&&l?3:0),p=o.useRef(!1),h=o.useRef(!1),w=We();return I(()=>{var y;if(e){if(r&&i(!0),!t){r&&u(3);return}return(y=n==null?void 0:n.start)==null||y.call(n,r),Qn(t,{inFlight:p,prepare(){h.current?h.current=!1:h.current=p.current,p.current=!0,!h.current&&(r?(u(3),s(4)):(u(4),s(2)))},run(){h.current?r?(s(3),u(4)):(s(4),u(3)):r?s(1):u(1)},done(){var E;h.current&&typeof t.getAnimations=="function"&&t.getAnimations().length>0||(p.current=!1,s(7),r||i(!1),(E=n==null?void 0:n.end)==null||E.call(n,r))}})}},[e,r,t,w]),e?[l,{closed:a(1),enter:a(2),leave:a(4),transition:a(2)||a(4)}]:[r,{closed:void 0,enter:void 0,leave:void 0,transition:void 0}]}function Qn(e,{prepare:t,run:r,done:n,inFlight:l}){let i=G();return el(e,{prepare:t,inFlight:l}),i.nextFrame(()=>{r(),i.requestAnimationFrame(()=>{i.add(Rn(e,n))})}),i.dispose}function Rn(e,t){var r,n;let l=G();if(!e)return l.dispose;let i=!1;l.add(()=>{i=!0});let a=(n=(r=e.getAnimations)==null?void 0:r.call(e).filter(u=>u instanceof CSSTransition))!=null?n:[];return a.length===0?(t(),l.dispose):(Promise.allSettled(a.map(u=>u.finished)).then(()=>{i||t()}),l.dispose)}function el(e,{inFlight:t,prepare:r}){if(t!=null&&t.current){r();return}let n=e.style.transition;e.style.transition="none",r(),e.offsetHeight,e.style.transition=n}function bt(e,t){let r=o.useRef([]),n=P(e);o.useEffect(()=>{let l=[...r.current];for(let[i,a]of t.entries())if(r.current[i]!==a){let u=n(t,l);return r.current=t,u}},[n,...t])}let Ge=o.createContext(null);Ge.displayName="OpenClosedContext";var V=(e=>(e[e.Open=1]="Open",e[e.Closed=2]="Closed",e[e.Closing=4]="Closing",e[e.Opening=8]="Opening",e))(V||{});function Ke(){return o.useContext(Ge)}function tl({value:e,children:t}){return o.createElement(Ge.Provider,{value:e},t)}function rl({children:e}){return o.createElement(Ge.Provider,{value:null},e)}function nl(e){function t(){document.readyState!=="loading"&&(e(),document.removeEventListener("DOMContentLoaded",t))}typeof window<"u"&&typeof document<"u"&&(document.addEventListener("DOMContentLoaded",t),t())}let te=[];nl(()=>{function e(t){if(!ee(t.target)||t.target===document.body||te[0]===t.target)return;let r=t.target;r=r.closest(qe),te.unshift(r??t.target),te=te.filter(n=>n!=null&&n.isConnected),te.splice(10)}window.addEventListener("click",e,{capture:!0}),window.addEventListener("mousedown",e,{capture:!0}),window.addEventListener("focus",e,{capture:!0}),document.body.addEventListener("click",e,{capture:!0}),document.body.addEventListener("mousedown",e,{capture:!0}),document.body.addEventListener("focus",e,{capture:!0})});function ar(e){let t=P(e),r=o.useRef(!1);o.useEffect(()=>(r.current=!1,()=>{r.current=!0,_e(()=>{r.current&&t()})}),[t])}let dr=o.createContext(!1);function ll(){return o.useContext(dr)}function cr(e){return o.createElement(dr.Provider,{value:e.force},e.children)}function ol(e){let t=ll(),r=o.useContext(pr),[n,l]=o.useState(()=>{var i;if(!t&&r!==null)return(i=r.current)!=null?i:null;if(z.isServer)return null;let a=e==null?void 0:e.getElementById("headlessui-portal-root");if(a)return a;if(e===null)return null;let u=e.createElement("div");return u.setAttribute("id","headlessui-portal-root"),e.body.appendChild(u)});return o.useEffect(()=>{n!==null&&(e!=null&&e.body.contains(n)||e==null||e.body.appendChild(n))},[n,e]),o.useEffect(()=>{t||r!==null&&l(r.current)},[r,l,t]),n}let fr=o.Fragment,il=D(function(e,t){let{ownerDocument:r=null,...n}=e,l=o.useRef(null),i=q(ln(y=>{l.current=y}),t),a=ze(l),u=r??a,s=ol(u),p=o.useContext(yt),h=We(),w=W();return ar(()=>{var y;s&&s.childNodes.length<=0&&((y=s.parentElement)==null||y.removeChild(s))}),s?Fr.createPortal(o.createElement("div",{"data-headlessui-portal":"",ref:y=>{h.dispose(),p&&y&&h.add(p.register(y))}},w({ourProps:{ref:i},theirProps:n,slot:{},defaultTag:fr,name:"Portal"})),s):null});function sl(e,t){let r=q(t),{enabled:n=!0,ownerDocument:l,...i}=e,a=W();return n?o.createElement(il,{...i,ownerDocument:l,ref:r}):a({ourProps:{ref:r},theirProps:i,slot:{},defaultTag:fr,name:"Portal"})}let ul=o.Fragment,pr=o.createContext(null);function al(e,t){let{target:r,...n}=e,l={ref:q(t)},i=W();return o.createElement(pr.Provider,{value:r},i({ourProps:l,theirProps:n,defaultTag:ul,name:"Popover.Group"}))}let yt=o.createContext(null);function dl(){let e=o.useContext(yt),t=o.useRef([]),r=P(i=>(t.current.push(i),e&&e.register(i),()=>n(i))),n=P(i=>{let a=t.current.indexOf(i);a!==-1&&t.current.splice(a,1),e&&e.unregister(i)}),l=o.useMemo(()=>({register:r,unregister:n,portals:t}),[r,n,t]);return[t,o.useMemo(()=>function({children:i}){return o.createElement(yt.Provider,{value:l},i)},[l])]}let cl=D(sl),mr=D(al),fl=Object.assign(cl,{Group:mr});function pl(e,t=typeof document<"u"?document.defaultView:null,r){let n=Oe(e,"escape");ir(t,"keydown",l=>{n&&(l.defaultPrevented||l.key===Ht.Escape&&r(l))})}function ml(){var e;let[t]=o.useState(()=>typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(pointer: coarse)"):null),[r,n]=o.useState((e=t==null?void 0:t.matches)!=null?e:!1);return I(()=>{if(!t)return;function l(i){n(i.matches)}return t.addEventListener("change",l),()=>t.removeEventListener("change",l)},[t]),r}function hl({defaultContainers:e=[],portals:t,mainTreeNode:r}={}){let n=ze(r),l=P(()=>{var i,a;let u=[];for(let s of e)s!==null&&(R(s)?u.push(s):"current"in s&&R(s.current)&&u.push(s.current));if(t!=null&&t.current)for(let s of t.current)u.push(s);for(let s of(i=n==null?void 0:n.querySelectorAll("html > *, body > *"))!=null?i:[])s!==document.body&&s!==document.head&&R(s)&&s.id!=="headlessui-portal-root"&&(r&&(s.contains(r)||s.contains((a=r==null?void 0:r.getRootNode())==null?void 0:a.host))||u.some(p=>s.contains(p))||u.push(s));return u});return{resolveContainers:l,contains:P(i=>l().some(a=>a.contains(i)))}}let hr=o.createContext(null);function vr({children:e,node:t}){let[r,n]=o.useState(null),l=gr(t??r);return o.createElement(hr.Provider,{value:l},e,l===null&&o.createElement(ct,{features:Ve.Hidden,ref:i=>{var a,u;if(i){for(let s of(u=(a=je(i))==null?void 0:a.querySelectorAll("html > *, body > *"))!=null?u:[])if(s!==document.body&&s!==document.head&&R(s)&&s!=null&&s.contains(i)){n(s);break}}}}))}function gr(e=null){var t;return(t=o.useContext(hr))!=null?t:e}function vl(){let e=typeof document>"u";return"useSyncExternalStore"in ve?(t=>t.useSyncExternalStore)(ve)(()=>()=>{},()=>!1,()=>!e):!1}function Ye(){let e=vl(),[t,r]=ve.useState(z.isHandoffComplete);return t&&z.isHandoffComplete===!1&&r(!1),ve.useEffect(()=>{t!==!0&&r(!0)},[t]),ve.useEffect(()=>z.handoff(),[]),e?!1:t}function Et(){let e=o.useRef(!1);return I(()=>(e.current=!0,()=>{e.current=!1}),[]),e}var Me=(e=>(e[e.Forwards=0]="Forwards",e[e.Backwards=1]="Backwards",e))(Me||{});function gl(){let e=o.useRef(0);return lr(!0,"keydown",t=>{t.key==="Tab"&&(e.current=t.shiftKey?1:0)},!0),e}function wr(e){if(!e)return new Set;if(typeof e=="function")return new Set(e());let t=new Set;for(let r of e.current)R(r.current)&&t.add(r.current);return t}let wl="div";var ue=(e=>(e[e.None=0]="None",e[e.InitialFocus=1]="InitialFocus",e[e.TabLock=2]="TabLock",e[e.FocusLock=4]="FocusLock",e[e.RestoreFocus=8]="RestoreFocus",e[e.AutoFocus=16]="AutoFocus",e))(ue||{});function bl(e,t){let r=o.useRef(null),n=q(r,t),{initialFocus:l,initialFocusFallback:i,containers:a,features:u=15,...s}=e;Ye()||(u=0);let p=ze(r);$l(u,{ownerDocument:p});let h=Ol(u,{ownerDocument:p,container:r,initialFocus:l,initialFocusFallback:i});Sl(u,{ownerDocument:p,container:r,containers:a,previousActiveElement:h});let w=gl(),y=P(c=>{if(!ie(r.current))return;let g=r.current;(b=>b())(()=>{K(w.current,{[Me.Forwards]:()=>{Ce(g,Y.First,{skipElements:[c.relatedTarget,i]})},[Me.Backwards]:()=>{Ce(g,Y.Last,{skipElements:[c.relatedTarget,i]})}})})}),E=Oe(!!(u&2),"focus-trap#tab-lock"),f=We(),$=o.useRef(!1),v={ref:n,onKeyDown(c){c.key=="Tab"&&($.current=!0,f.requestAnimationFrame(()=>{$.current=!1}))},onBlur(c){if(!(u&4))return;let g=wr(a);ie(r.current)&&g.add(r.current);let b=c.relatedTarget;ee(b)&&b.dataset.headlessuiFocusGuard!=="true"&&(br(g,b)||($.current?Ce(r.current,K(w.current,{[Me.Forwards]:()=>Y.Next,[Me.Backwards]:()=>Y.Previous})|Y.WrapAround,{relativeTo:c.target}):ee(c.target)&&Z(c.target)))}},d=W();return o.createElement(o.Fragment,null,E&&o.createElement(ct,{as:"button",type:"button","data-headlessui-focus-guard":!0,onFocus:y,features:Ve.Focusable}),d({ourProps:v,theirProps:s,defaultTag:wl,name:"FocusTrap"}),E&&o.createElement(ct,{as:"button",type:"button","data-headlessui-focus-guard":!0,onFocus:y,features:Ve.Focusable}))}let yl=D(bl),El=Object.assign(yl,{features:ue});function xl(e=!0){let t=o.useRef(te.slice());return bt(([r],[n])=>{n===!0&&r===!1&&_e(()=>{t.current.splice(0)}),n===!1&&r===!0&&(t.current=te.slice())},[e,te,t]),P(()=>{var r;return(r=t.current.find(n=>n!=null&&n.isConnected))!=null?r:null})}function $l(e,{ownerDocument:t}){let r=!!(e&8),n=xl(r);bt(()=>{r||(t==null?void 0:t.activeElement)===(t==null?void 0:t.body)&&Z(n())},[r]),ar(()=>{r&&Z(n())})}function Ol(e,{ownerDocument:t,container:r,initialFocus:n,initialFocusFallback:l}){let i=o.useRef(null),a=Oe(!!(e&1),"focus-trap#initial-focus"),u=Et();return bt(()=>{if(e===0)return;if(!a){l!=null&&l.current&&Z(l.current);return}let s=r.current;s&&_e(()=>{if(!u.current)return;let p=t==null?void 0:t.activeElement;if(n!=null&&n.current){if((n==null?void 0:n.current)===p){i.current=p;return}}else if(s.contains(p)){i.current=p;return}if(n!=null&&n.current)Z(n.current);else{if(e&16){if(Ce(s,Y.First|Y.AutoFocus)!==wt.Error)return}else if(Ce(s,Y.First)!==wt.Error)return;if(l!=null&&l.current&&(Z(l.current),(t==null?void 0:t.activeElement)===l.current))return;console.warn("There are no focusable elements inside the <FocusTrap />")}i.current=t==null?void 0:t.activeElement})},[l,a,e]),i}function Sl(e,{ownerDocument:t,container:r,containers:n,previousActiveElement:l}){let i=Et(),a=!!(e&4);ir(t==null?void 0:t.defaultView,"focus",u=>{if(!a||!i.current)return;let s=wr(n);ie(r.current)&&s.add(r.current);let p=l.current;if(!p)return;let h=u.target;ie(h)?br(s,h)?(l.current=h,Z(h)):(u.preventDefault(),u.stopPropagation(),Z(p)):Z(l.current)},!0)}function br(e,t){for(let r of e)if(r.contains(t))return!0;return!1}function yr(e){var t;return!!(e.enter||e.enterFrom||e.enterTo||e.leave||e.leaveFrom||e.leaveTo)||!Ee((t=e.as)!=null?t:xr)||o.Children.count(e.children)===1}let Ze=o.createContext(null);Ze.displayName="TransitionContext";var Cl=(e=>(e.Visible="visible",e.Hidden="hidden",e))(Cl||{});function Ml(){let e=o.useContext(Ze);if(e===null)throw new Error("A <Transition.Child /> is used but it is missing a parent <Transition /> or <Transition.Root />.");return e}function Pl(){let e=o.useContext(Je);if(e===null)throw new Error("A <Transition.Child /> is used but it is missing a parent <Transition /> or <Transition.Root />.");return e}let Je=o.createContext(null);Je.displayName="NestingContext";function Qe(e){return"children"in e?Qe(e.children):e.current.filter(({el:t})=>t.current!==null).filter(({state:t})=>t==="visible").length>0}function Er(e,t){let r=le(e),n=o.useRef([]),l=Et(),i=We(),a=P((E,f=Q.Hidden)=>{let $=n.current.findIndex(({el:v})=>v===E);$!==-1&&(K(f,{[Q.Unmount](){n.current.splice($,1)},[Q.Hidden](){n.current[$].state="hidden"}}),i.microTask(()=>{var v;!Qe(n)&&l.current&&((v=r.current)==null||v.call(r))}))}),u=P(E=>{let f=n.current.find(({el:$})=>$===E);return f?f.state!=="visible"&&(f.state="visible"):n.current.push({el:E,state:"visible"}),()=>a(E,Q.Unmount)}),s=o.useRef([]),p=o.useRef(Promise.resolve()),h=o.useRef({enter:[],leave:[]}),w=P((E,f,$)=>{s.current.splice(0),t&&(t.chains.current[f]=t.chains.current[f].filter(([v])=>v!==E)),t==null||t.chains.current[f].push([E,new Promise(v=>{s.current.push(v)})]),t==null||t.chains.current[f].push([E,new Promise(v=>{Promise.all(h.current[f].map(([d,c])=>c)).then(()=>v())})]),f==="enter"?p.current=p.current.then(()=>t==null?void 0:t.wait.current).then(()=>$(f)):$(f)}),y=P((E,f,$)=>{Promise.all(h.current[f].splice(0).map(([v,d])=>d)).then(()=>{var v;(v=s.current.shift())==null||v()}).then(()=>$(f))});return o.useMemo(()=>({children:n,register:u,unregister:a,onStart:w,onStop:y,wait:p,chains:h}),[u,a,n,w,y,h,p])}let xr=o.Fragment,$r=Ue.RenderStrategy;function Tl(e,t){var r,n;let{transition:l=!0,beforeEnter:i,afterEnter:a,beforeLeave:u,afterLeave:s,enter:p,enterFrom:h,enterTo:w,entered:y,leave:E,leaveFrom:f,leaveTo:$,...v}=e,[d,c]=o.useState(null),g=o.useRef(null),b=yr(e),m=q(...b?[g,t,c]:t===null?[]:[t]),x=(r=v.unmount)==null||r?Q.Unmount:Q.Hidden,{show:S,appear:F,initial:j}=Ml(),[L,A]=o.useState(S?"visible":"hidden"),H=Pl(),{register:N,unregister:T}=H;I(()=>N(g),[N,g]),I(()=>{if(x===Q.Hidden&&g.current){if(S&&L!=="visible"){A("visible");return}return K(L,{hidden:()=>T(g),visible:()=>N(g)})}},[L,g,N,T,S,x]);let _=Ye();I(()=>{if(b&&_&&L==="visible"&&g.current===null)throw new Error("Did you forget to passthrough the `ref` to the actual DOM node?")},[g,L,_,b]);let he=j&&!F,ae=F&&S&&j,J=o.useRef(!1),k=Er(()=>{J.current||(A("hidden"),T(g))},H),Pe=P(Ct=>{J.current=!0;let tt=Ct?"enter":"leave";k.onStart(g,tt,ke=>{ke==="enter"?i==null||i():ke==="leave"&&(u==null||u())})}),re=P(Ct=>{let tt=Ct?"enter":"leave";J.current=!1,k.onStop(g,tt,ke=>{ke==="enter"?a==null||a():ke==="leave"&&(s==null||s())}),tt==="leave"&&!Qe(k)&&(A("hidden"),T(g))});o.useEffect(()=>{b&&l||(Pe(S),re(S))},[S,b,l]);let St=!(!l||!b||!_||he),[,M]=Jn(St,d,S,{start:Pe,end:re}),et=oe({ref:m,className:((n=at(v.className,ae&&p,ae&&h,M.enter&&p,M.enter&&M.closed&&h,M.enter&&!M.closed&&w,M.leave&&E,M.leave&&!M.closed&&f,M.leave&&M.closed&&$,!M.transition&&S&&y))==null?void 0:n.trim())||void 0,...Zn(M)}),Te=0;L==="visible"&&(Te|=V.Open),L==="hidden"&&(Te|=V.Closed),S&&L==="hidden"&&(Te|=V.Opening),!S&&L==="visible"&&(Te|=V.Closing);let Ql=W();return o.createElement(Je.Provider,{value:k},o.createElement(tl,{value:Te},Ql({ourProps:et,theirProps:v,defaultTag:xr,features:$r,visible:L==="visible",name:"Transition.Child"})))}function kl(e,t){let{show:r,appear:n=!1,unmount:l=!0,...i}=e,a=o.useRef(null),u=yr(e),s=q(...u?[a,t]:t===null?[]:[t]);Ye();let p=Ke();if(r===void 0&&p!==null&&(r=(p&V.Open)===V.Open),r===void 0)throw new Error("A <Transition /> is used but it is missing a `show={true | false}` prop.");let[h,w]=o.useState(r?"visible":"hidden"),y=Er(()=>{r||w("hidden")}),[E,f]=o.useState(!0),$=o.useRef([r]);I(()=>{E!==!1&&$.current[$.current.length-1]!==r&&($.current.push(r),f(!1))},[$,r]);let v=o.useMemo(()=>({show:r,appear:n,initial:E}),[r,n,E]);I(()=>{r?w("visible"):!Qe(y)&&a.current!==null&&w("hidden")},[r,y]);let d={unmount:l},c=P(()=>{var m;E&&f(!1),(m=e.beforeEnter)==null||m.call(e)}),g=P(()=>{var m;E&&f(!1),(m=e.beforeLeave)==null||m.call(e)}),b=W();return o.createElement(Je.Provider,{value:y},o.createElement(Ze.Provider,{value:v},b({ourProps:{...d,as:o.Fragment,children:o.createElement(Or,{ref:s,...d,...i,beforeEnter:c,beforeLeave:g})},theirProps:{},defaultTag:o.Fragment,features:$r,visible:h==="visible",name:"Transition"})))}function Ll(e,t){let r=o.useContext(Ze)!==null,n=Ke()!==null;return o.createElement(o.Fragment,null,!r&&n?o.createElement(xt,{ref:t,...e}):o.createElement(Or,{ref:t,...e}))}let xt=D(kl),Or=D(Tl),me=D(Ll),Sr=Object.assign(xt,{Child:me,Root:xt});var Fl=(e=>(e[e.Open=0]="Open",e[e.Closed=1]="Closed",e))(Fl||{}),Al=(e=>(e[e.SetTitleId=0]="SetTitleId",e))(Al||{});let Nl={0(e,t){return e.titleId===t.id?e:{...e,titleId:t.id}}},$t=o.createContext(null);$t.displayName="DialogContext";function Re(e){let t=o.useContext($t);if(t===null){let r=new Error(`<${e} /> is missing a parent <Dialog /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(r,Re),r}return t}function Il(e,t){return K(t.type,Nl,e,t)}let Cr=D(function(e,t){let r=o.useId(),{id:n=`headlessui-dialog-${r}`,open:l,onClose:i,initialFocus:a,role:u="dialog",autoFocus:s=!0,__demoMode:p=!1,unmount:h=!1,...w}=e,y=o.useRef(!1);u=(function(){return u==="dialog"||u==="alertdialog"?u:(y.current||(y.current=!0,console.warn(`Invalid role [${u}] passed to <Dialog />. Only \`dialog\` and and \`alertdialog\` are supported. Using \`dialog\` instead.`)),"dialog")})();let E=Ke();l===void 0&&E!==null&&(l=(E&V.Open)===V.Open);let f=o.useRef(null),$=q(f,t),v=ze(f),d=l?0:1,[c,g]=o.useReducer(Il,{titleId:null,descriptionId:null,panelRef:o.createRef()}),b=P(()=>i(!1)),m=P(M=>g({type:0,id:M})),x=Ye()?d===0:!1,[S,F]=dl(),j={get current(){var M;return(M=c.panelRef.current)!=null?M:f.current}},L=gr(),{resolveContainers:A}=hl({mainTreeNode:L,portals:S,defaultContainers:[j]}),H=E!==null?(E&V.Closing)===V.Closing:!1;Mn(p||H?!1:x,{allowed:P(()=>{var M,et;return[(et=(M=f.current)==null?void 0:M.closest("[data-headlessui-portal]"))!=null?et:null]}),disallowed:P(()=>{var M;return[(M=L==null?void 0:L.closest("body > *:not(#headlessui-portal-root)"))!=null?M:null]})});let N=Kt.get(null);I(()=>{if(x)return N.actions.push(n),()=>N.actions.pop(n)},[N,n,x]);let T=Qt(N,o.useCallback(M=>N.selectors.isTop(M,n),[N,n]));Wn(T,A,M=>{M.preventDefault(),b()}),pl(T,v==null?void 0:v.defaultView,M=>{M.preventDefault(),M.stopPropagation(),document.activeElement&&"blur"in document.activeElement&&typeof document.activeElement.blur=="function"&&document.activeElement.blur(),b()}),Gn(p||H?!1:x,v,A),Pn(x,f,b);let[_,he]=on(),ae=o.useMemo(()=>[{dialogState:d,close:b,setTitleId:m,unmount:h},c],[d,b,m,h,c]),J=ye({open:d===0}),k={ref:$,id:n,role:u,tabIndex:-1,"aria-modal":p?void 0:d===0?!0:void 0,"aria-labelledby":c.titleId,"aria-describedby":_,unmount:h},Pe=!ml(),re=ue.None;x&&!p&&(re|=ue.RestoreFocus,re|=ue.TabLock,s&&(re|=ue.AutoFocus),Pe&&(re|=ue.InitialFocus));let St=W();return o.createElement(rl,null,o.createElement(cr,{force:!0},o.createElement(fl,null,o.createElement($t.Provider,{value:ae},o.createElement(mr,{target:f},o.createElement(cr,{force:!1},o.createElement(he,{slot:J},o.createElement(F,null,o.createElement(El,{initialFocus:a,initialFocusFallback:f,containers:A,features:re},o.createElement(fn,{value:b},St({ourProps:k,theirProps:w,slot:J,defaultTag:Dl,features:jl,visible:d===0,name:"Dialog"})))))))))))}),Dl="div",jl=Ue.RenderStrategy|Ue.Static;function _l(e,t){let{transition:r=!1,open:n,...l}=e,i=Ke(),a=e.hasOwnProperty("open")||i!==null,u=e.hasOwnProperty("onClose");if(!a&&!u)throw new Error("You have to provide an `open` and an `onClose` prop to the `Dialog` component.");if(!a)throw new Error("You provided an `onClose` prop to the `Dialog`, but forgot an `open` prop.");if(!u)throw new Error("You provided an `open` prop to the `Dialog`, but forgot an `onClose` prop.");if(!i&&typeof e.open!="boolean")throw new Error(`You provided an \`open\` prop to the \`Dialog\`, but the value is not a boolean. Received: ${e.open}`);if(typeof e.onClose!="function")throw new Error(`You provided an \`onClose\` prop to the \`Dialog\`, but the value is not a function. Received: ${e.onClose}`);return(n!==void 0||r)&&!l.static?o.createElement(vr,null,o.createElement(Sr,{show:n,transition:r,unmount:l.unmount},o.createElement(Cr,{ref:t,...l}))):o.createElement(vr,null,o.createElement(Cr,{ref:t,open:n,...l}))}let Wl="div";function Ul(e,t){let r=o.useId(),{id:n=`headlessui-dialog-panel-${r}`,transition:l=!1,...i}=e,[{dialogState:a,unmount:u},s]=Re("Dialog.Panel"),p=q(t,s.panelRef),h=ye({open:a===0}),w=P(v=>{v.stopPropagation()}),y={ref:p,id:n,onClick:w},E=l?me:o.Fragment,f=l?{unmount:u}:{},$=W();return o.createElement(E,{...f},$({ourProps:y,theirProps:i,slot:h,defaultTag:Wl,name:"Dialog.Panel"}))}let Hl="div";function Vl(e,t){let{transition:r=!1,...n}=e,[{dialogState:l,unmount:i}]=Re("Dialog.Backdrop"),a=ye({open:l===0}),u={ref:t,"aria-hidden":!0},s=r?me:o.Fragment,p=r?{unmount:i}:{},h=W();return o.createElement(s,{...p},h({ourProps:u,theirProps:n,slot:a,defaultTag:Hl,name:"Dialog.Backdrop"}))}let Bl="h2";function ql(e,t){let r=o.useId(),{id:n=`headlessui-dialog-title-${r}`,...l}=e,[{dialogState:i,setTitleId:a}]=Re("Dialog.Title"),u=q(t);o.useEffect(()=>(a(n),()=>a(null)),[n,a]);let s=ye({open:i===0}),p={ref:u,id:n};return W()({ourProps:p,theirProps:l,slot:s,defaultTag:Bl,name:"Dialog.Title"})}let Xl=D(_l),Ot=D(Ul);D(Vl);let zl=D(ql),Gl=Object.assign(Xl,{Panel:Ot,Title:zl,Description:dn});function Mr({onClick:e}){return O.jsxs("button",{type:"button",className:"im-close-button text-gray-400 hover:text-gray-500",onClick:e,children:[O.jsx("span",{className:"sr-only",children:"Close"}),O.jsx("svg",{className:"size-6",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor","aria-hidden":"true",children:O.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})]})}const Kl=({modalContext:e,config:t,children:r})=>{const[n,l]=o.useState(!1);return O.jsx("div",{className:"im-modal-container fixed inset-0 z-40 overflow-y-auto p-4",children:O.jsx("div",{className:De("im-modal-positioner flex min-h-full justify-center",{"items-start":t.position==="top","items-center":t.position==="center","items-end":t.position==="bottom"}),children:O.jsx(me,{as:"div",enterFrom:"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",enterTo:"opacity-100 translate-y-0 sm:scale-100",leaveFrom:"opacity-100 translate-y-0 sm:scale-100",leaveTo:"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",afterEnter:()=>l(!0),afterLeave:e.afterLeave,className:De("im-modal-wrapper w-full transition duration-300 ease-in-out",e.onTopOfStack?"":"blur-sm",{"sm:max-w-sm":t.maxWidth==="sm","sm:max-w-md":t.maxWidth==="md","sm:max-w-md md:max-w-lg":t.maxWidth==="lg","sm:max-w-md md:max-w-xl":t.maxWidth==="xl","sm:max-w-md md:max-w-xl lg:max-w-2xl":t.maxWidth==="2xl","sm:max-w-md md:max-w-xl lg:max-w-3xl":t.maxWidth==="3xl","sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-4xl":t.maxWidth==="4xl","sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl":t.maxWidth==="5xl","sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-6xl":t.maxWidth==="6xl","sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-7xl":t.maxWidth==="7xl"}),children:O.jsxs(Ot,{className:`im-modal-content relative ${t.paddingClasses} ${t.panelClasses}`,"data-inertiaui-modal-entered":n,children:[t.closeButton&&O.jsx("div",{className:"absolute right-0 top-0 pr-3 pt-3",children:O.jsx(Mr,{onClick:e.close})}),typeof r=="function"?r({modalContext:e,config:t}):r]})})})})},Yl=({modalContext:e,config:t,children:r})=>{const[n,l]=o.useState(!1);return O.jsx("div",{className:"im-slideover-container fixed inset-0 z-40 overflow-y-auto overflow-x-hidden",children:O.jsx("div",{className:De("im-slideover-positioner flex min-h-full items-center",{"justify-start rtl:justify-end":(t==null?void 0:t.position)==="left","justify-end rtl:justify-start":(t==null?void 0:t.position)==="right"}),children:O.jsx(me,{as:"div",enterFrom:`opacity-0 ${t.position==="left"?"-translate-x-full":"translate-x-full"}`,enterTo:"opacity-100 translate-x-0",leaveFrom:"opacity-100 translate-x-0",leaveTo:`opacity-0 ${t.position==="left"?"-translate-x-full":"translate-x-full"}`,afterEnter:()=>l(!0),afterLeave:e.afterLeave,className:De("im-slideover-wrapper w-full transition duration-300 ease-in-out",e.onTopOfStack?"":"blur-sm",{"sm:max-w-sm":t.maxWidth==="sm","sm:max-w-md":t.maxWidth==="md","sm:max-w-md md:max-w-lg":t.maxWidth==="lg","sm:max-w-md md:max-w-xl":t.maxWidth==="xl","sm:max-w-md md:max-w-xl lg:max-w-2xl":t.maxWidth==="2xl","sm:max-w-md md:max-w-xl lg:max-w-3xl":t.maxWidth==="3xl","sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-4xl":t.maxWidth==="4xl","sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl":t.maxWidth==="5xl","sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-6xl":t.maxWidth==="6xl","sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-7xl":t.maxWidth==="7xl"}),children:O.jsxs(Ot,{className:`im-slideover-content relative ${t.paddingClasses} ${t.panelClasses}`,"data-inertiaui-modal-entered":n,children:[t.closeButton&&O.jsx("div",{className:"absolute right-0 top-0 pr-3 pt-3",children:O.jsx(Mr,{onClick:e.close})}),typeof r=="function"?r({modalContext:e,config:t}):r]})})})})},Pr=o.forwardRef(({name:e,children:t,onFocus:r=null,onBlur:n=null,onClose:l=null,onSuccess:i=null,onAfterLeave:a=null,...u},s)=>{const p=w=>typeof t=="function"?t(w):t,h=o.useRef(null);return o.useImperativeHandle(s,()=>h.current,[h]),O.jsx(st,{ref:h,name:e,onFocus:r,onBlur:n,onClose:l,onSuccess:i,...u,children:({afterLeave:w,close:y,config:E,emit:f,getChildModal:$,getParentModal:v,id:d,index:c,isOpen:g,modalContext:b,onTopOfStack:m,reload:x,setOpen:S,shouldRender:F})=>O.jsx(Sr,{appear:!0,show:g??!1,afterLeave:a,children:O.jsxs(Gl,{as:"div",className:"im-dialog relative z-20",onClose:()=>E.closeExplicitly?null:y(),"data-inertiaui-modal-id":d,"data-inertiaui-modal-index":c,children:[c===0?O.jsx(me,{enter:"transition transform ease-in-out duration-300",enterFrom:"opacity-0",enterTo:"opacity-100",leave:"transition transform ease-in-out duration-300",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:m?O.jsx("div",{className:"im-backdrop fixed inset-0 z-30 bg-black/75","aria-hidden":"true"}):O.jsx("div",{})}):null,c>0&&m?O.jsx("div",{className:"im-backdrop fixed inset-0 z-30 bg-black/75"}):null,E.slideover?O.jsx(Yl,{modalContext:b,config:E,children:p({afterLeave:w,close:y,config:E,emit:f,getChildModal:$,getParentModal:v,id:d,index:c,isOpen:g,modalContext:b,onTopOfStack:m,reload:x,setOpen:S,shouldRender:F})}):O.jsx(Kl,{modalContext:b,config:E,children:p({afterLeave:w,close:y,config:E,emit:f,getChildModal:$,getParentModal:v,id:d,index:c,isOpen:g,modalContext:b,onTopOfStack:m,reload:x,setOpen:S,shouldRender:F})})]})})})});Pr.displayName="Modal";const Zl=({href:e,method:t="get",data:r={},as:n="a",headers:l={},queryStringArrayFormat:i="brackets",onAfterLeave:a=null,onBlur:u=null,onClose:s=null,onError:p=null,onFocus:h=null,onStart:w=null,onSuccess:y=null,navigate:E=null,children:f,...$})=>{const[v,d]=o.useState(!1),[c,g]=o.useState(null),{stack:b,visit:m}=be(),x=o.useMemo(()=>E??Ae("navigate"),[E]),S={},F={};Object.keys($).forEach(T=>{Ft.includes(T)||(T.startsWith("on")&&typeof $[T]=="function"?Ur(T)?S[T]=$[T]:F[T]=$[T]:S[T]=$[T])});const[j,L]=o.useState(!1);o.useEffect(()=>{c&&(c.onTopOfStack&&j?h==null||h():!c.onTopOfStack&&!j&&(u==null||u()),L(!c.onTopOfStack))},[b]);const A=o.useCallback(()=>{s==null||s()},[s]),H=o.useCallback(()=>{g(null),a==null||a()},[a]),N=o.useCallback(T=>{T==null||T.preventDefault(),!v&&(e.startsWith("#")||(d(!0),w==null||w()),m(e,t,r,l,Wr(_r($,Ft)),()=>A(b.length),H,i,x).then(_=>{g(_),_.registerEventListenersFromProps(F),y==null||y()}).catch(_=>{console.error(_),p==null||p(_)}).finally(()=>d(!1)))},[e,t,r,l,i,$,A,H]);return O.jsx(n,{...S,href:e,onClick:N,children:typeof f=="function"?f({loading:v}):f})},Tr=({children:e,data:t,params:r,buffer:n,as:l,always:i,fallback:a})=>{i=i??!1,l=l??"div",a=a??null;const[u,s]=o.useState(!1),p=o.useRef(!1),h=o.useRef(!1),w=o.useRef(null),y=it(),E=o.useCallback(()=>{if(t)return{only:Array.isArray(t)?t:[t]};if(!r)throw new Error("You must provide either a `data` or `params` prop.");return r},[r,t]);return o.useEffect(()=>{if(!w.current)return;const f=new IntersectionObserver($=>{if(!$[0].isIntersecting||(!i&&p.current&&f.disconnect(),h.current))return;p.current=!0,h.current=!0;const v=E();y.reload({...v,onStart:d=>{var c;h.current=!0,(c=v.onStart)==null||c.call(v,d)},onFinish:d=>{var c;s(!0),h.current=!1,(c=v.onFinish)==null||c.call(v,d),i||f.disconnect()}})},{rootMargin:`${n||0}px`});return f.observe(w.current),()=>{f.disconnect()}},[w,E,n]),i||!u?o.createElement(l,{props:null,ref:w},u?e:a):u?e:null};Tr.displayName="InertiaWhenVisible";const Jl=e=>t=>(t.default.layout=r=>o.createElement(e,{},r),t);C.Deferred=Dt,C.HeadlessModal=st,C.Modal=Pr,C.ModalLink=Zl,C.ModalRoot=Nt,C.ModalStackProvider=Lt,C.WhenVisible=Tr,C.getConfig=Ae,C.initFromPageProps=At,C.putConfig=Ir,C.renderApp=Hr,C.resetConfig=Nr,C.setPageLayout=Jl,C.useModal=it,C.useModalIndex=ot,C.useModalStack=be,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("react/jsx-runtime"), require("axios"), require("@inertiaui/vanilla"), require("@inertiajs/react"), require("@inertiajs/core"), require("react-dom")) : typeof define === "function" && define.amd ? define(["exports", "react", "react/jsx-runtime", "axios", "@inertiaui/vanilla", "@inertiajs/react", "@inertiajs/core", "react-dom"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.InertiaUIModal = {}, global.React, global.ReactJSXRuntime, global.axios, global.InertiaUIVanilla, global.InertiaReact, global.InertiaCore, global.ReactDOM));
|
|
3
|
+
})(this, (function(exports2, React, jsxRuntime, Axios, vanilla, react, core, reactDom) {
|
|
4
|
+
"use strict";
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
6
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
+
if (e) {
|
|
8
|
+
for (const k in e) {
|
|
9
|
+
if (k !== "default") {
|
|
10
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: () => e[k]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
const vanilla__namespace = /* @__PURE__ */ _interopNamespaceDefault(vanilla);
|
|
22
|
+
const defaultConfig = {
|
|
23
|
+
type: "modal",
|
|
24
|
+
navigate: false,
|
|
25
|
+
useNativeDialog: true,
|
|
26
|
+
appElement: "#app",
|
|
27
|
+
modal: {
|
|
28
|
+
closeButton: true,
|
|
29
|
+
closeExplicitly: false,
|
|
30
|
+
closeOnClickOutside: true,
|
|
31
|
+
maxWidth: "2xl",
|
|
32
|
+
paddingClasses: "p-4 sm:p-6",
|
|
33
|
+
panelClasses: "bg-white rounded",
|
|
34
|
+
position: "center"
|
|
35
|
+
},
|
|
36
|
+
slideover: {
|
|
37
|
+
closeButton: true,
|
|
38
|
+
closeExplicitly: false,
|
|
39
|
+
closeOnClickOutside: true,
|
|
40
|
+
maxWidth: "md",
|
|
41
|
+
paddingClasses: "p-4 sm:p-6",
|
|
42
|
+
panelClasses: "bg-white min-h-screen",
|
|
43
|
+
position: "right"
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
class Config {
|
|
47
|
+
constructor() {
|
|
48
|
+
this.config = {};
|
|
49
|
+
this.reset();
|
|
50
|
+
}
|
|
51
|
+
reset() {
|
|
52
|
+
this.config = JSON.parse(JSON.stringify(defaultConfig));
|
|
53
|
+
}
|
|
54
|
+
put(key, value) {
|
|
55
|
+
if (typeof key === "object") {
|
|
56
|
+
this.config = {
|
|
57
|
+
type: key.type ?? defaultConfig.type,
|
|
58
|
+
navigate: key.navigate ?? defaultConfig.navigate,
|
|
59
|
+
useNativeDialog: key.useNativeDialog ?? defaultConfig.useNativeDialog,
|
|
60
|
+
appElement: key.appElement !== void 0 ? key.appElement : defaultConfig.appElement,
|
|
61
|
+
modal: { ...defaultConfig.modal, ...key.modal ?? {} },
|
|
62
|
+
slideover: { ...defaultConfig.slideover, ...key.slideover ?? {} }
|
|
63
|
+
};
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const keys = key.split(".");
|
|
67
|
+
let current = this.config;
|
|
68
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
69
|
+
current = current[keys[i]] = current[keys[i]] || {};
|
|
70
|
+
}
|
|
71
|
+
current[keys[keys.length - 1]] = value;
|
|
72
|
+
}
|
|
73
|
+
get(key) {
|
|
74
|
+
if (typeof key === "undefined") {
|
|
75
|
+
return this.config;
|
|
76
|
+
}
|
|
77
|
+
const keys = key.split(".");
|
|
78
|
+
let current = this.config;
|
|
79
|
+
for (const k of keys) {
|
|
80
|
+
if (current === null || current === void 0 || typeof current !== "object") {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
current = current[k];
|
|
84
|
+
}
|
|
85
|
+
return current === void 0 ? null : current;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const configInstance = new Config();
|
|
89
|
+
const resetConfig = () => configInstance.reset();
|
|
90
|
+
const putConfig = (key, value) => configInstance.put(key, value);
|
|
91
|
+
const getConfig = (key) => configInstance.get(key);
|
|
92
|
+
const getConfigByType = (isSlideover, key) => configInstance.get(isSlideover ? `slideover.${key}` : `modal.${key}`);
|
|
93
|
+
function generateId(prefix = "inertiaui_") {
|
|
94
|
+
return vanilla.generateId(prefix);
|
|
95
|
+
}
|
|
96
|
+
const ModalStackContext = React.createContext(null);
|
|
97
|
+
ModalStackContext.displayName = "ModalStackContext";
|
|
98
|
+
let pageVersion = null;
|
|
99
|
+
let resolveComponent = null;
|
|
100
|
+
let baseUrl = null;
|
|
101
|
+
let closingToBaseUrlTarget = null;
|
|
102
|
+
const prefetchCache = /* @__PURE__ */ new Map();
|
|
103
|
+
const prefetchInFlight = /* @__PURE__ */ new Map();
|
|
104
|
+
function getPrefetchCacheKey(url, method, data) {
|
|
105
|
+
return `${method}:${url}:${JSON.stringify(data)}`;
|
|
106
|
+
}
|
|
107
|
+
function getCachedResponse(url, method, data) {
|
|
108
|
+
const key = getPrefetchCacheKey(url, method, data);
|
|
109
|
+
const cached = prefetchCache.get(key);
|
|
110
|
+
if (!cached) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
if (Date.now() > cached.expiresAt) {
|
|
114
|
+
prefetchCache.delete(key);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return cached.response;
|
|
118
|
+
}
|
|
119
|
+
function setCachedResponse(url, method, data, response, cacheFor) {
|
|
120
|
+
const key = getPrefetchCacheKey(url, method, data);
|
|
121
|
+
prefetchCache.set(key, {
|
|
122
|
+
response,
|
|
123
|
+
timestamp: Date.now(),
|
|
124
|
+
expiresAt: Date.now() + cacheFor
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function prefetch(href, options = {}) {
|
|
128
|
+
if (href.startsWith("#")) {
|
|
129
|
+
return Promise.resolve();
|
|
130
|
+
}
|
|
131
|
+
const method = (options.method ?? "get").toLowerCase();
|
|
132
|
+
const data = options.data ?? {};
|
|
133
|
+
const headers = options.headers ?? {};
|
|
134
|
+
const queryStringArrayFormat = options.queryStringArrayFormat ?? "brackets";
|
|
135
|
+
const cacheFor = options.cacheFor ?? 3e4;
|
|
136
|
+
const [url, mergedData] = core.mergeDataIntoQueryString(method, href || "", data, queryStringArrayFormat);
|
|
137
|
+
const cached = getCachedResponse(url, method, mergedData);
|
|
138
|
+
if (cached) {
|
|
139
|
+
return Promise.resolve();
|
|
140
|
+
}
|
|
141
|
+
const cacheKey = getPrefetchCacheKey(url, method, mergedData);
|
|
142
|
+
const inFlight = prefetchInFlight.get(cacheKey);
|
|
143
|
+
if (inFlight) {
|
|
144
|
+
return inFlight.then(() => {
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
options.onPrefetching?.();
|
|
148
|
+
const requestHeaders = {
|
|
149
|
+
...headers,
|
|
150
|
+
Accept: "text/html, application/xhtml+xml",
|
|
151
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
152
|
+
"X-Inertia": "true",
|
|
153
|
+
"X-Inertia-Version": pageVersion ?? "",
|
|
154
|
+
"X-InertiaUI-Modal": generateId(),
|
|
155
|
+
"X-InertiaUI-Modal-Base-Url": baseUrl ?? ""
|
|
156
|
+
};
|
|
157
|
+
const request = Axios({
|
|
158
|
+
url,
|
|
159
|
+
method,
|
|
160
|
+
data: mergedData,
|
|
161
|
+
headers: requestHeaders
|
|
162
|
+
}).then((response) => {
|
|
163
|
+
setCachedResponse(url, method, mergedData, response, cacheFor);
|
|
164
|
+
options.onPrefetched?.();
|
|
165
|
+
return response;
|
|
166
|
+
}).finally(() => {
|
|
167
|
+
prefetchInFlight.delete(cacheKey);
|
|
168
|
+
});
|
|
169
|
+
prefetchInFlight.set(cacheKey, request);
|
|
170
|
+
return request.then(() => {
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const ModalStackProvider = ({ children }) => {
|
|
174
|
+
const stackRef = React.useRef([]);
|
|
175
|
+
const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
|
|
176
|
+
const [localModals, setLocalModals] = React.useState({});
|
|
177
|
+
const updateStack = (withStack) => {
|
|
178
|
+
const newStack = withStack([...stackRef.current]);
|
|
179
|
+
const isOnTopOfStack = (modalId) => {
|
|
180
|
+
if (newStack.length < 2) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
return newStack.map((modal) => ({ id: modal.id, shouldRender: modal.shouldRender })).reverse().find((modal) => modal.shouldRender)?.id === modalId;
|
|
184
|
+
};
|
|
185
|
+
newStack.forEach((modal, index) => {
|
|
186
|
+
newStack[index].onTopOfStack = isOnTopOfStack(modal.id);
|
|
187
|
+
newStack[index].getParentModal = () => {
|
|
188
|
+
if (index < 1) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
return stackRef.current.slice(0, index).reverse().find((m) => m.isOpen) ?? null;
|
|
192
|
+
};
|
|
193
|
+
newStack[index].getChildModal = () => {
|
|
194
|
+
if (index === stackRef.current.length - 1) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
return stackRef.current.slice(index + 1).find((m) => m.isOpen) ?? null;
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
stackRef.current = newStack;
|
|
201
|
+
forceUpdate();
|
|
202
|
+
};
|
|
203
|
+
class ModalClass {
|
|
204
|
+
constructor(component, response, config, onClose, afterLeave) {
|
|
205
|
+
this.show = () => {
|
|
206
|
+
updateStack(
|
|
207
|
+
(prevStack) => prevStack.map((modal) => {
|
|
208
|
+
if (modal.id === this.id && !modal.isOpen) {
|
|
209
|
+
modal.isOpen = true;
|
|
210
|
+
modal.shouldRender = true;
|
|
211
|
+
}
|
|
212
|
+
return modal;
|
|
213
|
+
})
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
this.setOpen = (open) => {
|
|
217
|
+
if (open) {
|
|
218
|
+
this.show();
|
|
219
|
+
} else {
|
|
220
|
+
this.close();
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
this.close = () => {
|
|
224
|
+
updateStack((currentStack) => {
|
|
225
|
+
let modalClosed = false;
|
|
226
|
+
const newStack = currentStack.map((modal) => {
|
|
227
|
+
if (modal.id === this.id && modal.isOpen) {
|
|
228
|
+
Object.keys(modal.listeners).forEach((event) => {
|
|
229
|
+
modal.off(event);
|
|
230
|
+
});
|
|
231
|
+
modal.isOpen = false;
|
|
232
|
+
modal.onCloseCallback?.();
|
|
233
|
+
modalClosed = true;
|
|
234
|
+
}
|
|
235
|
+
return modal;
|
|
236
|
+
});
|
|
237
|
+
return modalClosed ? newStack : currentStack;
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
this.afterLeave = () => {
|
|
241
|
+
if (this.isOpen) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
updateStack((prevStack) => {
|
|
245
|
+
const updatedStack = prevStack.map((modal) => {
|
|
246
|
+
if (modal.id === this.id && !modal.isOpen) {
|
|
247
|
+
modal.shouldRender = false;
|
|
248
|
+
modal.afterLeaveCallback?.();
|
|
249
|
+
modal.afterLeaveCallback = null;
|
|
250
|
+
}
|
|
251
|
+
return modal;
|
|
252
|
+
});
|
|
253
|
+
if (this.index === 0) {
|
|
254
|
+
const savedBaseUrl = baseUrl;
|
|
255
|
+
baseUrl = null;
|
|
256
|
+
closingToBaseUrlTarget = savedBaseUrl;
|
|
257
|
+
if (savedBaseUrl && typeof window !== "undefined") {
|
|
258
|
+
react.router.push({
|
|
259
|
+
url: savedBaseUrl,
|
|
260
|
+
preserveScroll: true,
|
|
261
|
+
preserveState: true,
|
|
262
|
+
// Clear _inertiaui_modal prop to prevent modal from reopening
|
|
263
|
+
props: (currentProps) => {
|
|
264
|
+
const { _inertiaui_modal, ...rest } = currentProps;
|
|
265
|
+
return { ...rest, _inertiaui_modal: void 0 };
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return [];
|
|
270
|
+
}
|
|
271
|
+
return updatedStack;
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
this.on = (event, callback) => {
|
|
275
|
+
event = vanilla.kebabCase(event);
|
|
276
|
+
this.listeners[event] = this.listeners[event] ?? [];
|
|
277
|
+
this.listeners[event].push(callback);
|
|
278
|
+
};
|
|
279
|
+
this.off = (event, callback) => {
|
|
280
|
+
event = vanilla.kebabCase(event);
|
|
281
|
+
if (callback) {
|
|
282
|
+
this.listeners[event] = this.listeners[event]?.filter((cb) => cb !== callback) ?? [];
|
|
283
|
+
} else {
|
|
284
|
+
delete this.listeners[event];
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
this.emit = (event, ...args) => {
|
|
288
|
+
this.listeners[vanilla.kebabCase(event)]?.forEach((callback) => callback(...args));
|
|
289
|
+
};
|
|
290
|
+
this.registerEventListenersFromProps = (props) => {
|
|
291
|
+
const unsubscribers = [];
|
|
292
|
+
Object.keys(props).filter((key) => key.startsWith("on")).forEach((key) => {
|
|
293
|
+
const eventName = vanilla.kebabCase(key).replace(/^on-/, "");
|
|
294
|
+
const callback = props[key];
|
|
295
|
+
this.on(eventName, callback);
|
|
296
|
+
unsubscribers.push(() => this.off(eventName, callback));
|
|
297
|
+
});
|
|
298
|
+
return () => unsubscribers.forEach((unsub) => unsub());
|
|
299
|
+
};
|
|
300
|
+
this.reload = (options = {}) => {
|
|
301
|
+
let keys = Object.keys(this.response.props);
|
|
302
|
+
if (options.only) {
|
|
303
|
+
keys = options.only;
|
|
304
|
+
}
|
|
305
|
+
if (options.except) {
|
|
306
|
+
keys = vanilla.except(keys, options.except);
|
|
307
|
+
}
|
|
308
|
+
if (!this.response?.url) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const method = (options.method ?? "get").toLowerCase();
|
|
312
|
+
const data = options.data ?? {};
|
|
313
|
+
options.onStart?.();
|
|
314
|
+
Axios({
|
|
315
|
+
url: this.response.url,
|
|
316
|
+
method,
|
|
317
|
+
data: method === "get" ? {} : data,
|
|
318
|
+
params: method === "get" ? data : {},
|
|
319
|
+
headers: {
|
|
320
|
+
...options.headers ?? {},
|
|
321
|
+
Accept: "text/html, application/xhtml+xml",
|
|
322
|
+
"X-Inertia": "true",
|
|
323
|
+
"X-Inertia-Partial-Component": this.response.component,
|
|
324
|
+
"X-Inertia-Version": this.response.version ?? "",
|
|
325
|
+
"X-Inertia-Partial-Data": keys.join(","),
|
|
326
|
+
"X-InertiaUI-Modal": generateId(),
|
|
327
|
+
"X-InertiaUI-Modal-Base-Url": baseUrl ?? ""
|
|
328
|
+
}
|
|
329
|
+
}).then((response2) => {
|
|
330
|
+
this.updateProps(response2.data.props);
|
|
331
|
+
options.onSuccess?.(response2);
|
|
332
|
+
}).catch((error) => {
|
|
333
|
+
options.onError?.(error);
|
|
334
|
+
}).finally(() => {
|
|
335
|
+
options.onFinish?.();
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
this.updateProps = (props) => {
|
|
339
|
+
Object.assign(this.props, props);
|
|
340
|
+
updateStack((prevStack) => prevStack);
|
|
341
|
+
};
|
|
342
|
+
this.id = response.id ?? generateId();
|
|
343
|
+
this.isOpen = false;
|
|
344
|
+
this.shouldRender = false;
|
|
345
|
+
this.listeners = {};
|
|
346
|
+
this.component = component;
|
|
347
|
+
this.props = response.props ?? {};
|
|
348
|
+
this.response = response;
|
|
349
|
+
this.config = config ?? {};
|
|
350
|
+
this.onCloseCallback = onClose ?? null;
|
|
351
|
+
this.afterLeaveCallback = afterLeave ?? null;
|
|
352
|
+
this.index = -1;
|
|
353
|
+
this.getParentModal = () => null;
|
|
354
|
+
this.getChildModal = () => null;
|
|
355
|
+
this.onTopOfStack = true;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
const isValidModalResponse = (data) => {
|
|
359
|
+
return typeof data === "object" && data !== null && "component" in data && typeof data.component === "string";
|
|
360
|
+
};
|
|
361
|
+
const pushFromResponseData = (responseData, config = {}, onClose = null, onAfterLeave = null) => {
|
|
362
|
+
if (!resolveComponent) {
|
|
363
|
+
return Promise.reject(new Error("resolveComponent not set"));
|
|
364
|
+
}
|
|
365
|
+
if (!isValidModalResponse(responseData)) {
|
|
366
|
+
return Promise.reject(
|
|
367
|
+
new Error(
|
|
368
|
+
"Invalid modal response. This usually happens when the server returns a redirect (e.g., due to session expiration). Check if the user is still authenticated."
|
|
369
|
+
)
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
return resolveComponent(responseData.component).then(
|
|
373
|
+
(component) => push(component, responseData, config, onClose, onAfterLeave)
|
|
374
|
+
);
|
|
375
|
+
};
|
|
376
|
+
const loadDeferredProps = (modal) => {
|
|
377
|
+
const deferred = modal.response?.meta?.deferredProps;
|
|
378
|
+
if (!deferred) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
Object.keys(deferred).forEach((key) => {
|
|
382
|
+
modal.reload({ only: deferred[key] });
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
const push = (component, response, config, onClose, afterLeave) => {
|
|
386
|
+
const newModal = new ModalClass(component, response, config, onClose, afterLeave);
|
|
387
|
+
newModal.index = stackRef.current.length;
|
|
388
|
+
updateStack((prevStack) => [...prevStack, newModal]);
|
|
389
|
+
loadDeferredProps(newModal);
|
|
390
|
+
newModal.show();
|
|
391
|
+
return newModal;
|
|
392
|
+
};
|
|
393
|
+
function pushLocalModal(name, config, onClose, afterLeave, props) {
|
|
394
|
+
if (!localModals[name]) {
|
|
395
|
+
throw new Error(`The local modal "${name}" has not been registered.`);
|
|
396
|
+
}
|
|
397
|
+
const responseData = { props: props ?? {} };
|
|
398
|
+
const modal = push(null, responseData, config, onClose, afterLeave);
|
|
399
|
+
modal.name = name;
|
|
400
|
+
localModals[name].callback(modal);
|
|
401
|
+
return modal;
|
|
402
|
+
}
|
|
403
|
+
const visitModal = (url, options = {}) => visit(
|
|
404
|
+
url,
|
|
405
|
+
options.method ?? "get",
|
|
406
|
+
options.data ?? {},
|
|
407
|
+
options.headers ?? {},
|
|
408
|
+
options.config ?? {},
|
|
409
|
+
options.onClose ?? null,
|
|
410
|
+
options.onAfterLeave ?? null,
|
|
411
|
+
options.queryStringArrayFormat ?? "brackets",
|
|
412
|
+
options.navigate ?? getConfig("navigate"),
|
|
413
|
+
options.onStart ?? null,
|
|
414
|
+
options.onSuccess ?? null,
|
|
415
|
+
options.onError ?? null,
|
|
416
|
+
options.props ?? null
|
|
417
|
+
).then((modal) => {
|
|
418
|
+
const listeners = options.listeners ?? {};
|
|
419
|
+
Object.keys(listeners).forEach((event) => {
|
|
420
|
+
const eventName = vanilla.kebabCase(event);
|
|
421
|
+
modal.on(eventName, listeners[event]);
|
|
422
|
+
});
|
|
423
|
+
return modal;
|
|
424
|
+
});
|
|
425
|
+
const updateBrowserUrl = (url, useBrowserHistory, modalData) => {
|
|
426
|
+
if (!url || !useBrowserHistory || typeof window === "undefined") {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
react.router.push({
|
|
430
|
+
url,
|
|
431
|
+
preserveScroll: true,
|
|
432
|
+
preserveState: true,
|
|
433
|
+
// Store modal data in page props for history navigation
|
|
434
|
+
props: modalData ? (currentProps) => ({
|
|
435
|
+
...currentProps,
|
|
436
|
+
_inertiaui_modal: {
|
|
437
|
+
...modalData,
|
|
438
|
+
baseUrl
|
|
439
|
+
}
|
|
440
|
+
}) : void 0
|
|
441
|
+
});
|
|
442
|
+
};
|
|
443
|
+
const visit = (href, method, payload = {}, headers = {}, config = {}, onClose = null, onAfterLeave = null, queryStringArrayFormat = "brackets", useBrowserHistory = false, onStart = null, onSuccess = null, onError = null, props = null) => {
|
|
444
|
+
const modalId = generateId();
|
|
445
|
+
return new Promise((resolve, reject) => {
|
|
446
|
+
if (href.startsWith("#")) {
|
|
447
|
+
resolve(pushLocalModal(href.substring(1), config, onClose, onAfterLeave, props));
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const [url, data] = core.mergeDataIntoQueryString(method, href || "", payload, queryStringArrayFormat);
|
|
451
|
+
const cachedResponse = getCachedResponse(url, method, data);
|
|
452
|
+
if (cachedResponse) {
|
|
453
|
+
onSuccess?.(cachedResponse);
|
|
454
|
+
pushFromResponseData(cachedResponse.data, config, onClose, onAfterLeave).then((modal) => {
|
|
455
|
+
updateBrowserUrl(cachedResponse.data.url, useBrowserHistory, cachedResponse.data);
|
|
456
|
+
resolve(modal);
|
|
457
|
+
}).catch(reject);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (stackRef.current.length === 0) {
|
|
461
|
+
baseUrl = typeof window !== "undefined" ? window.location.href : "";
|
|
462
|
+
}
|
|
463
|
+
const requestHeaders = {
|
|
464
|
+
...headers,
|
|
465
|
+
Accept: "text/html, application/xhtml+xml",
|
|
466
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
467
|
+
"X-Inertia": "true",
|
|
468
|
+
"X-Inertia-Version": pageVersion ?? "",
|
|
469
|
+
"X-InertiaUI-Modal": modalId,
|
|
470
|
+
"X-InertiaUI-Modal-Base-Url": baseUrl ?? ""
|
|
471
|
+
};
|
|
472
|
+
onStart?.();
|
|
473
|
+
react.progress?.start();
|
|
474
|
+
Axios({
|
|
475
|
+
url,
|
|
476
|
+
method,
|
|
477
|
+
data,
|
|
478
|
+
headers: requestHeaders
|
|
479
|
+
}).then((response) => {
|
|
480
|
+
onSuccess?.(response);
|
|
481
|
+
pushFromResponseData(response.data, config, onClose, onAfterLeave).then((modal) => {
|
|
482
|
+
updateBrowserUrl(response.data.url, useBrowserHistory, response.data);
|
|
483
|
+
resolve(modal);
|
|
484
|
+
}).catch(reject);
|
|
485
|
+
}).catch((...args) => {
|
|
486
|
+
onError?.(...args);
|
|
487
|
+
reject(args[0]);
|
|
488
|
+
}).finally(() => {
|
|
489
|
+
react.progress?.finish();
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
};
|
|
493
|
+
const registerLocalModal = (name, callback) => {
|
|
494
|
+
setLocalModals((prevLocalModals) => ({
|
|
495
|
+
...prevLocalModals,
|
|
496
|
+
[name]: { name, callback }
|
|
497
|
+
}));
|
|
498
|
+
};
|
|
499
|
+
const removeLocalModal = (name) => {
|
|
500
|
+
setLocalModals((prevLocalModals) => {
|
|
501
|
+
const newLocalModals = { ...prevLocalModals };
|
|
502
|
+
delete newLocalModals[name];
|
|
503
|
+
return newLocalModals;
|
|
504
|
+
});
|
|
505
|
+
};
|
|
506
|
+
const value = {
|
|
507
|
+
get stack() {
|
|
508
|
+
return stackRef.current;
|
|
509
|
+
},
|
|
510
|
+
localModals,
|
|
511
|
+
push,
|
|
512
|
+
pushFromResponseData,
|
|
513
|
+
length: () => stackRef.current.length,
|
|
514
|
+
closeAll: (force = false) => {
|
|
515
|
+
if (force) {
|
|
516
|
+
updateStack(() => []);
|
|
517
|
+
} else {
|
|
518
|
+
[...stackRef.current].reverse().forEach((modal) => modal.close());
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
reset: () => updateStack(() => []),
|
|
522
|
+
visit,
|
|
523
|
+
visitModal,
|
|
524
|
+
registerLocalModal,
|
|
525
|
+
removeLocalModal
|
|
526
|
+
};
|
|
527
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ModalStackContext.Provider, { value, children });
|
|
528
|
+
};
|
|
529
|
+
const useModalStack = () => {
|
|
530
|
+
const context = React.useContext(ModalStackContext);
|
|
531
|
+
if (context === null) {
|
|
532
|
+
throw new Error("useModalStack must be used within a ModalStackProvider");
|
|
533
|
+
}
|
|
534
|
+
return context;
|
|
535
|
+
};
|
|
536
|
+
const modalPropNames = ["closeButton", "closeExplicitly", "closeOnClickOutside", "maxWidth", "paddingClasses", "panelClasses", "position", "slideover"];
|
|
537
|
+
const initFromPageProps = (pageProps) => {
|
|
538
|
+
if (pageProps.initialPage) {
|
|
539
|
+
pageVersion = pageProps.initialPage.version ?? null;
|
|
540
|
+
}
|
|
541
|
+
if (pageProps.resolveComponent) {
|
|
542
|
+
resolveComponent = pageProps.resolveComponent;
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
const renderApp = (App, pageProps) => {
|
|
546
|
+
initFromPageProps(pageProps);
|
|
547
|
+
const renderInertiaApp = ({ Component, props, key }) => {
|
|
548
|
+
const renderComponent = () => {
|
|
549
|
+
const child = React.createElement(Component, { key, ...props });
|
|
550
|
+
if (typeof Component.layout === "function") {
|
|
551
|
+
return Component.layout(child);
|
|
552
|
+
}
|
|
553
|
+
if (Array.isArray(Component.layout)) {
|
|
554
|
+
return Component.layout.slice().reverse().reduce(
|
|
555
|
+
(acc, Layout) => React.createElement(Layout, props, acc),
|
|
556
|
+
child
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
return child;
|
|
560
|
+
};
|
|
561
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
562
|
+
renderComponent(),
|
|
563
|
+
/* @__PURE__ */ jsxRuntime.jsx(ModalRoot, {})
|
|
564
|
+
] });
|
|
565
|
+
};
|
|
566
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ModalStackProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(App, { ...pageProps, children: renderInertiaApp }) });
|
|
567
|
+
};
|
|
568
|
+
const ModalRoot = ({ children }) => {
|
|
569
|
+
const context = React.useContext(ModalStackContext);
|
|
570
|
+
const $page = react.usePage();
|
|
571
|
+
const pendingModalKeysRef = React.useRef(/* @__PURE__ */ new Set());
|
|
572
|
+
const getModalKey = (modalData) => modalData.id || `${modalData.component}:${modalData.url}`;
|
|
573
|
+
const isNavigatingRef = React.useRef(false);
|
|
574
|
+
const initialModalStillOpenedRef = React.useRef(!!$page.props?._inertiaui_modal);
|
|
575
|
+
React.useEffect(() => react.router.on("start", () => isNavigatingRef.current = true), []);
|
|
576
|
+
React.useEffect(() => react.router.on("finish", () => isNavigatingRef.current = false), []);
|
|
577
|
+
React.useEffect(
|
|
578
|
+
() => react.router.on("navigate", function($event) {
|
|
579
|
+
const modalOnBase = $event.detail.page.props._inertiaui_modal;
|
|
580
|
+
const pageUrl = $event.detail.page.url;
|
|
581
|
+
if (closingToBaseUrlTarget) {
|
|
582
|
+
const targetPath = new URL(closingToBaseUrlTarget, "http://x").pathname;
|
|
583
|
+
const pagePath = new URL(pageUrl, "http://x").pathname;
|
|
584
|
+
if (targetPath === pagePath) {
|
|
585
|
+
closingToBaseUrlTarget = null;
|
|
586
|
+
context?.closeAll(true);
|
|
587
|
+
baseUrl = null;
|
|
588
|
+
initialModalStillOpenedRef.current = false;
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
closingToBaseUrlTarget = null;
|
|
592
|
+
}
|
|
593
|
+
if (!modalOnBase) {
|
|
594
|
+
context?.closeAll(true);
|
|
595
|
+
baseUrl = null;
|
|
596
|
+
initialModalStillOpenedRef.current = false;
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
if (!vanilla.sameUrlPath(pageUrl, modalOnBase.url)) {
|
|
600
|
+
context?.closeAll(true);
|
|
601
|
+
baseUrl = null;
|
|
602
|
+
initialModalStillOpenedRef.current = false;
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
const modalKey = getModalKey(modalOnBase);
|
|
606
|
+
if (pendingModalKeysRef.current.has(modalKey)) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
if (modalOnBase.id && context?.stack.some((m) => m.id === modalOnBase.id)) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
if (context?.stack.some((m) => m.response?.component === modalOnBase.component && vanilla.sameUrlPath(m.response?.url, modalOnBase.url))) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
baseUrl = modalOnBase.baseUrl;
|
|
616
|
+
pendingModalKeysRef.current.add(modalKey);
|
|
617
|
+
context?.pushFromResponseData(modalOnBase, {}, () => {
|
|
618
|
+
if (!modalOnBase.baseUrl) {
|
|
619
|
+
console.error("No base url in modal response data so cannot navigate back");
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
if (!isNavigatingRef.current && typeof window !== "undefined" && window.location.href !== modalOnBase.baseUrl) {
|
|
623
|
+
react.router.visit(modalOnBase.baseUrl, {
|
|
624
|
+
preserveScroll: true,
|
|
625
|
+
preserveState: true
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
}).finally(() => {
|
|
629
|
+
pendingModalKeysRef.current.delete(modalKey);
|
|
630
|
+
});
|
|
631
|
+
}),
|
|
632
|
+
[]
|
|
633
|
+
);
|
|
634
|
+
const axiosRequestInterceptor = (config) => {
|
|
635
|
+
const baseUrlValue = baseUrl ?? (initialModalStillOpenedRef.current ? $page.props._inertiaui_modal?.baseUrl : null);
|
|
636
|
+
if (baseUrlValue) {
|
|
637
|
+
config.headers["X-InertiaUI-Modal-Base-Url"] = baseUrlValue;
|
|
638
|
+
}
|
|
639
|
+
return config;
|
|
640
|
+
};
|
|
641
|
+
React.useEffect(() => {
|
|
642
|
+
const interceptorId = Axios.interceptors.request.use(axiosRequestInterceptor);
|
|
643
|
+
return () => Axios.interceptors.request.eject(interceptorId);
|
|
644
|
+
}, []);
|
|
645
|
+
const previousModalRef = React.useRef(void 0);
|
|
646
|
+
React.useEffect(() => {
|
|
647
|
+
const newModal = $page.props?._inertiaui_modal;
|
|
648
|
+
const previousModal = previousModalRef.current;
|
|
649
|
+
previousModalRef.current = newModal;
|
|
650
|
+
if (!newModal) {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (previousModal && newModal.component === previousModal.component && vanilla.sameUrlPath(newModal.url, previousModal.url)) {
|
|
654
|
+
context?.stack[0]?.updateProps(newModal.props ?? {});
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
if (!previousModal && context && context.stack.length > 0) {
|
|
658
|
+
const existingModal = context.stack.find(
|
|
659
|
+
(m) => m.response?.component === newModal.component && vanilla.sameUrlPath(m.response?.url, newModal.url)
|
|
660
|
+
);
|
|
661
|
+
if (existingModal) {
|
|
662
|
+
existingModal.updateProps(newModal.props ?? {});
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}, [$page.props?._inertiaui_modal]);
|
|
666
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
667
|
+
children,
|
|
668
|
+
context && context.stack.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(ModalRenderer, { index: 0 })
|
|
669
|
+
] });
|
|
670
|
+
};
|
|
671
|
+
const ModalIndexContext = React.createContext(null);
|
|
672
|
+
ModalIndexContext.displayName = "ModalIndexContext";
|
|
673
|
+
const useModalIndex = () => {
|
|
674
|
+
return React.useContext(ModalIndexContext);
|
|
675
|
+
};
|
|
676
|
+
const ModalRenderer = ({ index }) => {
|
|
677
|
+
const { stack } = useModalStack();
|
|
678
|
+
const modalContext = React.useMemo(() => {
|
|
679
|
+
return stack[index];
|
|
680
|
+
}, [stack, index]);
|
|
681
|
+
if (!modalContext?.component) {
|
|
682
|
+
return null;
|
|
683
|
+
}
|
|
684
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ModalIndexContext.Provider, { value: index, children: React.createElement(modalContext.component, {
|
|
685
|
+
...modalContext.props,
|
|
686
|
+
onModalEvent: (...args) => modalContext.emit("modal-event", ...args)
|
|
687
|
+
}) });
|
|
688
|
+
};
|
|
689
|
+
function useModal() {
|
|
690
|
+
return useModalStack().stack[useModalIndex()] ?? null;
|
|
691
|
+
}
|
|
692
|
+
const Deferred = ({ children, data, fallback }) => {
|
|
693
|
+
if (!data) {
|
|
694
|
+
throw new Error("`<Deferred>` requires a `data` prop to be a string or array of strings");
|
|
695
|
+
}
|
|
696
|
+
const [loaded, setLoaded] = React.useState(false);
|
|
697
|
+
const keys = Array.isArray(data) ? data : [data];
|
|
698
|
+
const modal = useModal();
|
|
699
|
+
const modalProps = modal?.props ?? {};
|
|
700
|
+
React.useEffect(() => {
|
|
701
|
+
setLoaded(keys.every((key) => modalProps[key] !== void 0));
|
|
702
|
+
}, [modalProps, keys]);
|
|
703
|
+
return loaded ? children : fallback;
|
|
704
|
+
};
|
|
705
|
+
Deferred.displayName = "InertiaModalDeferred";
|
|
706
|
+
const HeadlessModal = React.forwardRef(
|
|
707
|
+
(allProps, ref) => {
|
|
708
|
+
const { name, children, onFocus, onBlur, onClose, onSuccess, ...props } = allProps;
|
|
709
|
+
const modalIndex = useModalIndex();
|
|
710
|
+
const { stack, registerLocalModal, removeLocalModal } = useModalStack();
|
|
711
|
+
const [localModalContext, setLocalModalContext] = React.useState(null);
|
|
712
|
+
const modalContext = React.useMemo(
|
|
713
|
+
() => name ? localModalContext : stack[modalIndex],
|
|
714
|
+
[name, localModalContext, modalIndex, stack]
|
|
715
|
+
);
|
|
716
|
+
const nextIndex = React.useMemo(() => {
|
|
717
|
+
return stack.find((m) => m.shouldRender && m.index > (modalContext?.index ?? -1))?.index;
|
|
718
|
+
}, [modalIndex, stack]);
|
|
719
|
+
const configSlideover = React.useMemo(
|
|
720
|
+
() => modalContext?.config.slideover ?? props.slideover ?? getConfig("type") === "slideover",
|
|
721
|
+
[props.slideover, modalContext?.config.slideover]
|
|
722
|
+
);
|
|
723
|
+
const config = React.useMemo(
|
|
724
|
+
() => ({
|
|
725
|
+
slideover: configSlideover,
|
|
726
|
+
closeButton: props.closeButton ?? getConfigByType(configSlideover, "closeButton"),
|
|
727
|
+
closeExplicitly: props.closeExplicitly ?? getConfigByType(configSlideover, "closeExplicitly"),
|
|
728
|
+
closeOnClickOutside: props.closeOnClickOutside ?? getConfigByType(configSlideover, "closeOnClickOutside"),
|
|
729
|
+
maxWidth: props.maxWidth ?? getConfigByType(configSlideover, "maxWidth"),
|
|
730
|
+
paddingClasses: props.paddingClasses ?? getConfigByType(configSlideover, "paddingClasses"),
|
|
731
|
+
panelClasses: props.panelClasses ?? getConfigByType(configSlideover, "panelClasses"),
|
|
732
|
+
position: props.position ?? getConfigByType(configSlideover, "position"),
|
|
733
|
+
...modalContext?.config
|
|
734
|
+
}),
|
|
735
|
+
[props, modalContext?.config, configSlideover]
|
|
736
|
+
);
|
|
737
|
+
React.useEffect(() => {
|
|
738
|
+
if (name) {
|
|
739
|
+
let removeListeners = null;
|
|
740
|
+
registerLocalModal(name, (localContext) => {
|
|
741
|
+
removeListeners = localContext.registerEventListenersFromProps(props);
|
|
742
|
+
setLocalModalContext(localContext);
|
|
743
|
+
});
|
|
744
|
+
return () => {
|
|
745
|
+
removeListeners?.();
|
|
746
|
+
removeListeners = null;
|
|
747
|
+
removeLocalModal(name);
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
return modalContext?.registerEventListenersFromProps(props);
|
|
751
|
+
}, [name]);
|
|
752
|
+
const modalContextRef = React.useRef(modalContext);
|
|
753
|
+
React.useEffect(() => {
|
|
754
|
+
modalContextRef.current = modalContext;
|
|
755
|
+
}, [modalContext]);
|
|
756
|
+
const previousIsOpenRef = React.useRef(void 0);
|
|
757
|
+
React.useEffect(() => {
|
|
758
|
+
if (modalContext !== null) {
|
|
759
|
+
if (modalContext.isOpen) {
|
|
760
|
+
onSuccess?.();
|
|
761
|
+
} else if (previousIsOpenRef.current === true) {
|
|
762
|
+
onClose?.();
|
|
763
|
+
}
|
|
764
|
+
previousIsOpenRef.current = modalContext.isOpen;
|
|
765
|
+
}
|
|
766
|
+
}, [modalContext?.isOpen]);
|
|
767
|
+
const [rendered, setRendered] = React.useState(false);
|
|
768
|
+
React.useEffect(() => {
|
|
769
|
+
if (rendered && modalContext !== null && modalContext.isOpen) {
|
|
770
|
+
if (modalContext.onTopOfStack) {
|
|
771
|
+
onFocus?.();
|
|
772
|
+
} else {
|
|
773
|
+
onBlur?.();
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
setRendered(true);
|
|
777
|
+
}, [modalContext?.onTopOfStack]);
|
|
778
|
+
React.useImperativeHandle(
|
|
779
|
+
ref,
|
|
780
|
+
() => ({
|
|
781
|
+
afterLeave: () => modalContextRef.current?.afterLeave(),
|
|
782
|
+
close: () => modalContextRef.current?.close(),
|
|
783
|
+
emit: (...args) => modalContextRef.current?.emit(...args),
|
|
784
|
+
getChildModal: () => modalContextRef.current?.getChildModal(),
|
|
785
|
+
getParentModal: () => modalContextRef.current?.getParentModal(),
|
|
786
|
+
reload: (options) => modalContextRef.current?.reload(options),
|
|
787
|
+
setOpen: (open) => modalContextRef.current?.setOpen(open),
|
|
788
|
+
get id() {
|
|
789
|
+
return modalContextRef.current?.id;
|
|
790
|
+
},
|
|
791
|
+
get index() {
|
|
792
|
+
return modalContextRef.current?.index;
|
|
793
|
+
},
|
|
794
|
+
get isOpen() {
|
|
795
|
+
return modalContextRef.current?.isOpen;
|
|
796
|
+
},
|
|
797
|
+
get config() {
|
|
798
|
+
return modalContextRef.current?.config;
|
|
799
|
+
},
|
|
800
|
+
get modalContext() {
|
|
801
|
+
return modalContextRef.current;
|
|
802
|
+
},
|
|
803
|
+
get onTopOfStack() {
|
|
804
|
+
return modalContextRef.current?.onTopOfStack;
|
|
805
|
+
},
|
|
806
|
+
get shouldRender() {
|
|
807
|
+
return modalContextRef.current?.shouldRender;
|
|
808
|
+
}
|
|
809
|
+
}),
|
|
810
|
+
[modalContext]
|
|
811
|
+
);
|
|
812
|
+
if (!modalContext?.shouldRender) {
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
816
|
+
typeof children === "function" ? children({
|
|
817
|
+
// Spread props first so they can be overridden by built-in props
|
|
818
|
+
...modalContext.props,
|
|
819
|
+
afterLeave: modalContext.afterLeave,
|
|
820
|
+
close: modalContext.close,
|
|
821
|
+
config,
|
|
822
|
+
emit: modalContext.emit,
|
|
823
|
+
getChildModal: modalContext.getChildModal,
|
|
824
|
+
getParentModal: modalContext.getParentModal,
|
|
825
|
+
id: modalContext.id,
|
|
826
|
+
index: modalContext.index,
|
|
827
|
+
isOpen: modalContext.isOpen,
|
|
828
|
+
modalContext,
|
|
829
|
+
onTopOfStack: modalContext.onTopOfStack,
|
|
830
|
+
reload: modalContext.reload,
|
|
831
|
+
setOpen: modalContext.setOpen,
|
|
832
|
+
shouldRender: modalContext.shouldRender
|
|
833
|
+
}) : children,
|
|
834
|
+
nextIndex !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(ModalRenderer, { index: nextIndex })
|
|
835
|
+
] });
|
|
836
|
+
}
|
|
837
|
+
);
|
|
838
|
+
HeadlessModal.displayName = "HeadlessModal";
|
|
839
|
+
function CloseButton({ onClick }) {
|
|
840
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
841
|
+
"button",
|
|
842
|
+
{
|
|
843
|
+
type: "button",
|
|
844
|
+
className: "im-close-button text-gray-400 hover:text-gray-500",
|
|
845
|
+
onClick,
|
|
846
|
+
children: [
|
|
847
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Close" }),
|
|
848
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
849
|
+
"svg",
|
|
850
|
+
{
|
|
851
|
+
className: "size-6",
|
|
852
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
853
|
+
fill: "none",
|
|
854
|
+
viewBox: "0 0 24 24",
|
|
855
|
+
strokeWidth: "2",
|
|
856
|
+
stroke: "currentColor",
|
|
857
|
+
"aria-hidden": "true",
|
|
858
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
859
|
+
"path",
|
|
860
|
+
{
|
|
861
|
+
strokeLinecap: "round",
|
|
862
|
+
strokeLinejoin: "round",
|
|
863
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
864
|
+
}
|
|
865
|
+
)
|
|
866
|
+
}
|
|
867
|
+
)
|
|
868
|
+
]
|
|
869
|
+
}
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
function r(e) {
|
|
873
|
+
var t, f, n = "";
|
|
874
|
+
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
875
|
+
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
876
|
+
var o = e.length;
|
|
877
|
+
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
878
|
+
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
879
|
+
return n;
|
|
880
|
+
}
|
|
881
|
+
function clsx() {
|
|
882
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
883
|
+
return n;
|
|
884
|
+
}
|
|
885
|
+
const maxWidthClasses = {
|
|
886
|
+
sm: "sm:max-w-sm",
|
|
887
|
+
md: "sm:max-w-md",
|
|
888
|
+
lg: "sm:max-w-md md:max-w-lg",
|
|
889
|
+
xl: "sm:max-w-md md:max-w-xl",
|
|
890
|
+
"2xl": "sm:max-w-md md:max-w-xl lg:max-w-2xl",
|
|
891
|
+
"3xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl",
|
|
892
|
+
"4xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-4xl",
|
|
893
|
+
"5xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl",
|
|
894
|
+
"6xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-6xl",
|
|
895
|
+
"7xl": "sm:max-w-md md:max-w-xl lg:max-w-3xl xl:max-w-5xl 2xl:max-w-7xl"
|
|
896
|
+
};
|
|
897
|
+
const defaultMaxWidth = "2xl";
|
|
898
|
+
function getMaxWidthClass(maxWidth) {
|
|
899
|
+
return maxWidthClasses[maxWidth] || maxWidthClasses[defaultMaxWidth];
|
|
900
|
+
}
|
|
901
|
+
const ModalContent = ({ modalContext, config, useNativeDialog, isFirstModal, onAfterLeave, children }) => {
|
|
902
|
+
const [isRendered, setIsRendered] = React.useState(false);
|
|
903
|
+
const [isVisible, setIsVisible] = React.useState(false);
|
|
904
|
+
const [entered, setEntered] = React.useState(false);
|
|
905
|
+
const wrapperRef = React.useRef(null);
|
|
906
|
+
const dialogRef = React.useRef(null);
|
|
907
|
+
const nativeWrapperRef = React.useRef(null);
|
|
908
|
+
const cleanupFocusTrapRef = React.useRef(null);
|
|
909
|
+
const cleanupEscapeKeyRef = React.useRef(null);
|
|
910
|
+
const maxWidthClass = React.useMemo(() => getMaxWidthClass(config.maxWidth), [config.maxWidth]);
|
|
911
|
+
const animateIn = React.useCallback(async (element) => {
|
|
912
|
+
if (!element) return;
|
|
913
|
+
setIsVisible(true);
|
|
914
|
+
await vanilla.animate(element, [
|
|
915
|
+
{ transform: "translate3d(0, 1rem, 0) scale(0.95)", opacity: 0 },
|
|
916
|
+
{ transform: "translate3d(0, 0, 0) scale(1)", opacity: 1 }
|
|
917
|
+
]);
|
|
918
|
+
setEntered(true);
|
|
919
|
+
}, []);
|
|
920
|
+
const animateOut = React.useCallback(
|
|
921
|
+
async (element) => {
|
|
922
|
+
if (!element) return;
|
|
923
|
+
setIsVisible(false);
|
|
924
|
+
await vanilla.animate(element, [
|
|
925
|
+
{ transform: "translate3d(0, 0, 0) scale(1)", opacity: 1 },
|
|
926
|
+
{ transform: "translate3d(0, 1rem, 0) scale(0.95)", opacity: 0 }
|
|
927
|
+
]);
|
|
928
|
+
setIsRendered(false);
|
|
929
|
+
if (useNativeDialog && dialogRef.current) {
|
|
930
|
+
dialogRef.current.close();
|
|
931
|
+
}
|
|
932
|
+
onAfterLeave?.();
|
|
933
|
+
modalContext.afterLeave();
|
|
934
|
+
},
|
|
935
|
+
[useNativeDialog, onAfterLeave, modalContext]
|
|
936
|
+
);
|
|
937
|
+
const setupFocusTrap = React.useCallback(() => {
|
|
938
|
+
if (useNativeDialog) return;
|
|
939
|
+
if (!wrapperRef.current || !modalContext.onTopOfStack) return;
|
|
940
|
+
if (cleanupFocusTrapRef.current) return;
|
|
941
|
+
cleanupFocusTrapRef.current = vanilla.createFocusTrap(wrapperRef.current, {
|
|
942
|
+
initialFocus: true,
|
|
943
|
+
returnFocus: false
|
|
944
|
+
});
|
|
945
|
+
}, [modalContext.onTopOfStack, useNativeDialog]);
|
|
946
|
+
const cleanupFocusTrap = React.useCallback(() => {
|
|
947
|
+
if (cleanupFocusTrapRef.current) {
|
|
948
|
+
cleanupFocusTrapRef.current();
|
|
949
|
+
cleanupFocusTrapRef.current = null;
|
|
950
|
+
}
|
|
951
|
+
}, []);
|
|
952
|
+
const setupEscapeKey = React.useCallback(() => {
|
|
953
|
+
if (useNativeDialog) return;
|
|
954
|
+
if (cleanupEscapeKeyRef.current) return;
|
|
955
|
+
if (config?.closeExplicitly) return;
|
|
956
|
+
cleanupEscapeKeyRef.current = vanilla.onEscapeKey(() => {
|
|
957
|
+
if (modalContext.onTopOfStack) {
|
|
958
|
+
modalContext.close();
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
}, [config?.closeExplicitly, modalContext, useNativeDialog]);
|
|
962
|
+
const cleanupEscapeKey = React.useCallback(() => {
|
|
963
|
+
if (cleanupEscapeKeyRef.current) {
|
|
964
|
+
cleanupEscapeKeyRef.current();
|
|
965
|
+
cleanupEscapeKeyRef.current = null;
|
|
966
|
+
}
|
|
967
|
+
}, []);
|
|
968
|
+
const handleClickOutside = React.useCallback(
|
|
969
|
+
(event) => {
|
|
970
|
+
if (useNativeDialog) return;
|
|
971
|
+
if (!modalContext.onTopOfStack) return;
|
|
972
|
+
if (config?.closeExplicitly) return;
|
|
973
|
+
if (config?.closeOnClickOutside === false) return;
|
|
974
|
+
if (!wrapperRef.current) return;
|
|
975
|
+
if (!wrapperRef.current.contains(event.target)) {
|
|
976
|
+
modalContext.close();
|
|
977
|
+
}
|
|
978
|
+
},
|
|
979
|
+
[modalContext, config?.closeExplicitly, config?.closeOnClickOutside, useNativeDialog]
|
|
980
|
+
);
|
|
981
|
+
const handleCancel = React.useCallback(
|
|
982
|
+
(event) => {
|
|
983
|
+
event.preventDefault();
|
|
984
|
+
if (modalContext.onTopOfStack && !config?.closeExplicitly) {
|
|
985
|
+
modalContext.close();
|
|
986
|
+
}
|
|
987
|
+
},
|
|
988
|
+
[modalContext, config?.closeExplicitly]
|
|
989
|
+
);
|
|
990
|
+
const handleDialogClick = React.useCallback(
|
|
991
|
+
(event) => {
|
|
992
|
+
if (event.target === dialogRef.current) {
|
|
993
|
+
if (modalContext.onTopOfStack && !config?.closeExplicitly && config?.closeOnClickOutside !== false) {
|
|
994
|
+
modalContext.close();
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
},
|
|
998
|
+
[modalContext, config?.closeExplicitly, config?.closeOnClickOutside]
|
|
999
|
+
);
|
|
1000
|
+
const prevIsOpenRef = React.useRef(modalContext.isOpen);
|
|
1001
|
+
React.useEffect(() => {
|
|
1002
|
+
if (useNativeDialog) {
|
|
1003
|
+
if (modalContext.isOpen && !dialogRef.current?.open) {
|
|
1004
|
+
dialogRef.current?.showModal();
|
|
1005
|
+
animateIn(nativeWrapperRef.current);
|
|
1006
|
+
} else if (!modalContext.isOpen && prevIsOpenRef.current) {
|
|
1007
|
+
setEntered(false);
|
|
1008
|
+
animateOut(nativeWrapperRef.current);
|
|
1009
|
+
}
|
|
1010
|
+
} else {
|
|
1011
|
+
if (modalContext.isOpen && !isRendered) {
|
|
1012
|
+
setIsRendered(true);
|
|
1013
|
+
} else if (!modalContext.isOpen && prevIsOpenRef.current) {
|
|
1014
|
+
setEntered(false);
|
|
1015
|
+
animateOut(wrapperRef.current);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
prevIsOpenRef.current = modalContext.isOpen;
|
|
1019
|
+
}, [modalContext.isOpen, useNativeDialog, animateIn, animateOut, isRendered]);
|
|
1020
|
+
React.useEffect(() => {
|
|
1021
|
+
if (!useNativeDialog && isRendered && !entered && modalContext.isOpen) {
|
|
1022
|
+
animateIn(wrapperRef.current).then(() => {
|
|
1023
|
+
setupFocusTrap();
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
}, [isRendered, useNativeDialog, entered, modalContext.isOpen, animateIn, setupFocusTrap]);
|
|
1027
|
+
React.useEffect(() => {
|
|
1028
|
+
if (!useNativeDialog) {
|
|
1029
|
+
setupEscapeKey();
|
|
1030
|
+
}
|
|
1031
|
+
return () => {
|
|
1032
|
+
cleanupEscapeKey();
|
|
1033
|
+
};
|
|
1034
|
+
}, [useNativeDialog, setupEscapeKey, cleanupEscapeKey]);
|
|
1035
|
+
React.useEffect(() => {
|
|
1036
|
+
if (useNativeDialog) return;
|
|
1037
|
+
if (modalContext.onTopOfStack) {
|
|
1038
|
+
setupEscapeKey();
|
|
1039
|
+
if (entered) {
|
|
1040
|
+
setupFocusTrap();
|
|
1041
|
+
}
|
|
1042
|
+
} else {
|
|
1043
|
+
cleanupFocusTrap();
|
|
1044
|
+
cleanupEscapeKey();
|
|
1045
|
+
}
|
|
1046
|
+
}, [modalContext.onTopOfStack, entered, setupEscapeKey, setupFocusTrap, cleanupFocusTrap, cleanupEscapeKey, useNativeDialog]);
|
|
1047
|
+
React.useEffect(() => {
|
|
1048
|
+
return () => {
|
|
1049
|
+
const wrapper = useNativeDialog ? nativeWrapperRef.current : wrapperRef.current;
|
|
1050
|
+
if (wrapper) {
|
|
1051
|
+
vanilla.cancelAnimations(wrapper);
|
|
1052
|
+
}
|
|
1053
|
+
if (useNativeDialog) {
|
|
1054
|
+
if (dialogRef.current?.open) {
|
|
1055
|
+
dialogRef.current.close();
|
|
1056
|
+
}
|
|
1057
|
+
} else {
|
|
1058
|
+
cleanupFocusTrap();
|
|
1059
|
+
cleanupEscapeKey();
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
}, [useNativeDialog, cleanupFocusTrap, cleanupEscapeKey]);
|
|
1063
|
+
const renderContent = () => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1064
|
+
"div",
|
|
1065
|
+
{
|
|
1066
|
+
className: `im-modal-content relative ${config.paddingClasses} ${config.panelClasses}`,
|
|
1067
|
+
"data-inertiaui-modal-entered": entered,
|
|
1068
|
+
children: [
|
|
1069
|
+
config.closeButton && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute right-0 top-0 pr-3 pt-3", children: /* @__PURE__ */ jsxRuntime.jsx(CloseButton, { onClick: modalContext.close }) }),
|
|
1070
|
+
typeof children === "function" ? children({ modalContext, config }) : children
|
|
1071
|
+
]
|
|
1072
|
+
}
|
|
1073
|
+
);
|
|
1074
|
+
if (useNativeDialog) {
|
|
1075
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1076
|
+
"dialog",
|
|
1077
|
+
{
|
|
1078
|
+
ref: dialogRef,
|
|
1079
|
+
className: clsx(
|
|
1080
|
+
"im-modal-dialog m-0 overflow-visible bg-transparent p-0",
|
|
1081
|
+
"size-full max-h-none max-w-none",
|
|
1082
|
+
"backdrop:bg-black/75 backdrop:transition-opacity backdrop:duration-300",
|
|
1083
|
+
isVisible ? "backdrop:opacity-100" : "backdrop:opacity-0",
|
|
1084
|
+
!isFirstModal && "backdrop:bg-transparent"
|
|
1085
|
+
),
|
|
1086
|
+
onCancel: handleCancel,
|
|
1087
|
+
onClick: handleDialogClick,
|
|
1088
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "im-modal-container fixed inset-0 overflow-y-auto p-4", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1089
|
+
"div",
|
|
1090
|
+
{
|
|
1091
|
+
className: clsx("im-modal-positioner flex min-h-full justify-center", {
|
|
1092
|
+
"items-start": config.position === "top",
|
|
1093
|
+
"items-center": config.position === "center",
|
|
1094
|
+
"items-end": config.position === "bottom"
|
|
1095
|
+
}),
|
|
1096
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1097
|
+
"div",
|
|
1098
|
+
{
|
|
1099
|
+
ref: nativeWrapperRef,
|
|
1100
|
+
className: clsx("im-modal-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
|
|
1101
|
+
children: renderContent()
|
|
1102
|
+
}
|
|
1103
|
+
)
|
|
1104
|
+
}
|
|
1105
|
+
) })
|
|
1106
|
+
}
|
|
1107
|
+
);
|
|
1108
|
+
}
|
|
1109
|
+
if (!isRendered) return null;
|
|
1110
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1111
|
+
"div",
|
|
1112
|
+
{
|
|
1113
|
+
className: "im-modal-container fixed inset-0 z-40 overflow-y-auto p-4",
|
|
1114
|
+
onMouseDown: handleClickOutside,
|
|
1115
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1116
|
+
"div",
|
|
1117
|
+
{
|
|
1118
|
+
className: clsx("im-modal-positioner flex min-h-full justify-center", {
|
|
1119
|
+
"items-start": config.position === "top",
|
|
1120
|
+
"items-center": config.position === "center",
|
|
1121
|
+
"items-end": config.position === "bottom"
|
|
1122
|
+
}),
|
|
1123
|
+
onMouseDown: handleClickOutside,
|
|
1124
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1125
|
+
"div",
|
|
1126
|
+
{
|
|
1127
|
+
ref: wrapperRef,
|
|
1128
|
+
role: "dialog",
|
|
1129
|
+
"aria-modal": "true",
|
|
1130
|
+
className: clsx("im-modal-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
|
|
1131
|
+
children: [
|
|
1132
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Dialog" }),
|
|
1133
|
+
renderContent()
|
|
1134
|
+
]
|
|
1135
|
+
}
|
|
1136
|
+
)
|
|
1137
|
+
}
|
|
1138
|
+
)
|
|
1139
|
+
}
|
|
1140
|
+
);
|
|
1141
|
+
};
|
|
1142
|
+
const SlideoverContent = ({ modalContext, config, useNativeDialog, isFirstModal, onAfterLeave, children }) => {
|
|
1143
|
+
const [isRendered, setIsRendered] = React.useState(false);
|
|
1144
|
+
const [isVisible, setIsVisible] = React.useState(false);
|
|
1145
|
+
const [entered, setEntered] = React.useState(false);
|
|
1146
|
+
const wrapperRef = React.useRef(null);
|
|
1147
|
+
const dialogRef = React.useRef(null);
|
|
1148
|
+
const nativeWrapperRef = React.useRef(null);
|
|
1149
|
+
const cleanupFocusTrapRef = React.useRef(null);
|
|
1150
|
+
const cleanupEscapeKeyRef = React.useRef(null);
|
|
1151
|
+
const isLeft = config.position === "left";
|
|
1152
|
+
const maxWidthClass = React.useMemo(() => getMaxWidthClass(config.maxWidth), [config.maxWidth]);
|
|
1153
|
+
const getTranslateX = React.useCallback(() => isLeft ? "-100%" : "100%", [isLeft]);
|
|
1154
|
+
const animateIn = React.useCallback(
|
|
1155
|
+
async (element) => {
|
|
1156
|
+
if (!element) return;
|
|
1157
|
+
setIsVisible(true);
|
|
1158
|
+
const translateX = getTranslateX();
|
|
1159
|
+
await vanilla.animate(element, [
|
|
1160
|
+
{ transform: `translate3d(${translateX}, 0, 0)`, opacity: 0 },
|
|
1161
|
+
{ transform: "translate3d(0, 0, 0)", opacity: 1 }
|
|
1162
|
+
]);
|
|
1163
|
+
setEntered(true);
|
|
1164
|
+
},
|
|
1165
|
+
[getTranslateX]
|
|
1166
|
+
);
|
|
1167
|
+
const animateOut = React.useCallback(
|
|
1168
|
+
async (element) => {
|
|
1169
|
+
if (!element) return;
|
|
1170
|
+
setIsVisible(false);
|
|
1171
|
+
const translateX = getTranslateX();
|
|
1172
|
+
await vanilla.animate(element, [
|
|
1173
|
+
{ transform: "translate3d(0, 0, 0)", opacity: 1 },
|
|
1174
|
+
{ transform: `translate3d(${translateX}, 0, 0)`, opacity: 0 }
|
|
1175
|
+
]);
|
|
1176
|
+
setIsRendered(false);
|
|
1177
|
+
if (useNativeDialog && dialogRef.current) {
|
|
1178
|
+
dialogRef.current.close();
|
|
1179
|
+
}
|
|
1180
|
+
onAfterLeave?.();
|
|
1181
|
+
modalContext.afterLeave();
|
|
1182
|
+
},
|
|
1183
|
+
[getTranslateX, useNativeDialog, onAfterLeave, modalContext]
|
|
1184
|
+
);
|
|
1185
|
+
const setupFocusTrap = React.useCallback(() => {
|
|
1186
|
+
if (useNativeDialog) return;
|
|
1187
|
+
if (!wrapperRef.current || !modalContext.onTopOfStack) return;
|
|
1188
|
+
if (cleanupFocusTrapRef.current) return;
|
|
1189
|
+
cleanupFocusTrapRef.current = vanilla.createFocusTrap(wrapperRef.current, {
|
|
1190
|
+
initialFocus: true,
|
|
1191
|
+
returnFocus: false
|
|
1192
|
+
});
|
|
1193
|
+
}, [modalContext.onTopOfStack, useNativeDialog]);
|
|
1194
|
+
const cleanupFocusTrap = React.useCallback(() => {
|
|
1195
|
+
if (cleanupFocusTrapRef.current) {
|
|
1196
|
+
cleanupFocusTrapRef.current();
|
|
1197
|
+
cleanupFocusTrapRef.current = null;
|
|
1198
|
+
}
|
|
1199
|
+
}, []);
|
|
1200
|
+
const setupEscapeKey = React.useCallback(() => {
|
|
1201
|
+
if (useNativeDialog) return;
|
|
1202
|
+
if (cleanupEscapeKeyRef.current) return;
|
|
1203
|
+
if (config?.closeExplicitly) return;
|
|
1204
|
+
cleanupEscapeKeyRef.current = vanilla.onEscapeKey(() => {
|
|
1205
|
+
if (modalContext.onTopOfStack) {
|
|
1206
|
+
modalContext.close();
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
}, [config?.closeExplicitly, modalContext, useNativeDialog]);
|
|
1210
|
+
const cleanupEscapeKey = React.useCallback(() => {
|
|
1211
|
+
if (cleanupEscapeKeyRef.current) {
|
|
1212
|
+
cleanupEscapeKeyRef.current();
|
|
1213
|
+
cleanupEscapeKeyRef.current = null;
|
|
1214
|
+
}
|
|
1215
|
+
}, []);
|
|
1216
|
+
const handleClickOutside = React.useCallback(
|
|
1217
|
+
(event) => {
|
|
1218
|
+
if (useNativeDialog) return;
|
|
1219
|
+
if (!modalContext.onTopOfStack) return;
|
|
1220
|
+
if (config?.closeExplicitly) return;
|
|
1221
|
+
if (config?.closeOnClickOutside === false) return;
|
|
1222
|
+
if (!wrapperRef.current) return;
|
|
1223
|
+
if (!wrapperRef.current.contains(event.target)) {
|
|
1224
|
+
modalContext.close();
|
|
1225
|
+
}
|
|
1226
|
+
},
|
|
1227
|
+
[modalContext, config?.closeExplicitly, config?.closeOnClickOutside, useNativeDialog]
|
|
1228
|
+
);
|
|
1229
|
+
const handleCancel = React.useCallback(
|
|
1230
|
+
(event) => {
|
|
1231
|
+
event.preventDefault();
|
|
1232
|
+
if (modalContext.onTopOfStack && !config?.closeExplicitly) {
|
|
1233
|
+
modalContext.close();
|
|
1234
|
+
}
|
|
1235
|
+
},
|
|
1236
|
+
[modalContext, config?.closeExplicitly]
|
|
1237
|
+
);
|
|
1238
|
+
const handleDialogClick = React.useCallback(
|
|
1239
|
+
(event) => {
|
|
1240
|
+
if (event.target === dialogRef.current) {
|
|
1241
|
+
if (modalContext.onTopOfStack && !config?.closeExplicitly && config?.closeOnClickOutside !== false) {
|
|
1242
|
+
modalContext.close();
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
},
|
|
1246
|
+
[modalContext, config?.closeExplicitly, config?.closeOnClickOutside]
|
|
1247
|
+
);
|
|
1248
|
+
const prevIsOpenRef = React.useRef(modalContext.isOpen);
|
|
1249
|
+
React.useEffect(() => {
|
|
1250
|
+
if (useNativeDialog) {
|
|
1251
|
+
if (modalContext.isOpen && !dialogRef.current?.open) {
|
|
1252
|
+
dialogRef.current?.showModal();
|
|
1253
|
+
animateIn(nativeWrapperRef.current);
|
|
1254
|
+
} else if (!modalContext.isOpen && prevIsOpenRef.current) {
|
|
1255
|
+
setEntered(false);
|
|
1256
|
+
animateOut(nativeWrapperRef.current);
|
|
1257
|
+
}
|
|
1258
|
+
} else {
|
|
1259
|
+
if (modalContext.isOpen && !isRendered) {
|
|
1260
|
+
setIsRendered(true);
|
|
1261
|
+
} else if (!modalContext.isOpen && prevIsOpenRef.current) {
|
|
1262
|
+
setEntered(false);
|
|
1263
|
+
animateOut(wrapperRef.current);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
prevIsOpenRef.current = modalContext.isOpen;
|
|
1267
|
+
}, [modalContext.isOpen, useNativeDialog, animateIn, animateOut, isRendered]);
|
|
1268
|
+
React.useEffect(() => {
|
|
1269
|
+
if (!useNativeDialog && isRendered && !entered && modalContext.isOpen) {
|
|
1270
|
+
animateIn(wrapperRef.current).then(() => {
|
|
1271
|
+
setupFocusTrap();
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
}, [isRendered, useNativeDialog, entered, modalContext.isOpen, animateIn, setupFocusTrap]);
|
|
1275
|
+
React.useEffect(() => {
|
|
1276
|
+
if (!useNativeDialog) {
|
|
1277
|
+
setupEscapeKey();
|
|
1278
|
+
}
|
|
1279
|
+
return () => {
|
|
1280
|
+
cleanupEscapeKey();
|
|
1281
|
+
};
|
|
1282
|
+
}, [useNativeDialog, setupEscapeKey, cleanupEscapeKey]);
|
|
1283
|
+
React.useEffect(() => {
|
|
1284
|
+
if (useNativeDialog) return;
|
|
1285
|
+
if (modalContext.onTopOfStack) {
|
|
1286
|
+
setupEscapeKey();
|
|
1287
|
+
if (entered) {
|
|
1288
|
+
setupFocusTrap();
|
|
1289
|
+
}
|
|
1290
|
+
} else {
|
|
1291
|
+
cleanupFocusTrap();
|
|
1292
|
+
cleanupEscapeKey();
|
|
1293
|
+
}
|
|
1294
|
+
}, [modalContext.onTopOfStack, entered, setupEscapeKey, setupFocusTrap, cleanupFocusTrap, cleanupEscapeKey, useNativeDialog]);
|
|
1295
|
+
React.useEffect(() => {
|
|
1296
|
+
return () => {
|
|
1297
|
+
const wrapper = useNativeDialog ? nativeWrapperRef.current : wrapperRef.current;
|
|
1298
|
+
if (wrapper) {
|
|
1299
|
+
vanilla.cancelAnimations(wrapper);
|
|
1300
|
+
}
|
|
1301
|
+
if (useNativeDialog) {
|
|
1302
|
+
if (dialogRef.current?.open) {
|
|
1303
|
+
dialogRef.current.close();
|
|
1304
|
+
}
|
|
1305
|
+
} else {
|
|
1306
|
+
cleanupFocusTrap();
|
|
1307
|
+
cleanupEscapeKey();
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
}, [useNativeDialog, cleanupFocusTrap, cleanupEscapeKey]);
|
|
1311
|
+
const renderContent = () => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1312
|
+
"div",
|
|
1313
|
+
{
|
|
1314
|
+
className: `im-slideover-content relative ${config.paddingClasses} ${config.panelClasses}`,
|
|
1315
|
+
"data-inertiaui-modal-entered": entered,
|
|
1316
|
+
children: [
|
|
1317
|
+
config.closeButton && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute right-0 top-0 pr-3 pt-3", children: /* @__PURE__ */ jsxRuntime.jsx(CloseButton, { onClick: modalContext.close }) }),
|
|
1318
|
+
typeof children === "function" ? children({ modalContext, config }) : children
|
|
1319
|
+
]
|
|
1320
|
+
}
|
|
1321
|
+
);
|
|
1322
|
+
if (useNativeDialog) {
|
|
1323
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1324
|
+
"dialog",
|
|
1325
|
+
{
|
|
1326
|
+
ref: dialogRef,
|
|
1327
|
+
className: clsx(
|
|
1328
|
+
"im-slideover-dialog m-0 overflow-visible bg-transparent p-0",
|
|
1329
|
+
"size-full max-h-none max-w-none",
|
|
1330
|
+
"backdrop:bg-black/75 backdrop:transition-opacity backdrop:duration-300",
|
|
1331
|
+
isVisible ? "backdrop:opacity-100" : "backdrop:opacity-0",
|
|
1332
|
+
!isFirstModal && "backdrop:bg-transparent"
|
|
1333
|
+
),
|
|
1334
|
+
onCancel: handleCancel,
|
|
1335
|
+
onClick: handleDialogClick,
|
|
1336
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "im-slideover-container fixed inset-0 overflow-y-auto overflow-x-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1337
|
+
"div",
|
|
1338
|
+
{
|
|
1339
|
+
className: clsx("im-slideover-positioner flex min-h-full items-center", {
|
|
1340
|
+
"justify-start rtl:justify-end": config?.position === "left",
|
|
1341
|
+
"justify-end rtl:justify-start": config?.position === "right"
|
|
1342
|
+
}),
|
|
1343
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1344
|
+
"div",
|
|
1345
|
+
{
|
|
1346
|
+
ref: nativeWrapperRef,
|
|
1347
|
+
className: clsx("im-slideover-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
|
|
1348
|
+
children: renderContent()
|
|
1349
|
+
}
|
|
1350
|
+
)
|
|
1351
|
+
}
|
|
1352
|
+
) })
|
|
1353
|
+
}
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
if (!isRendered) return null;
|
|
1357
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1358
|
+
"div",
|
|
1359
|
+
{
|
|
1360
|
+
className: "im-slideover-container fixed inset-0 z-40 overflow-y-auto overflow-x-hidden",
|
|
1361
|
+
onMouseDown: handleClickOutside,
|
|
1362
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1363
|
+
"div",
|
|
1364
|
+
{
|
|
1365
|
+
className: clsx("im-slideover-positioner flex min-h-full items-center", {
|
|
1366
|
+
"justify-start rtl:justify-end": config?.position === "left",
|
|
1367
|
+
"justify-end rtl:justify-start": config?.position === "right"
|
|
1368
|
+
}),
|
|
1369
|
+
onMouseDown: handleClickOutside,
|
|
1370
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1371
|
+
"div",
|
|
1372
|
+
{
|
|
1373
|
+
ref: wrapperRef,
|
|
1374
|
+
role: "dialog",
|
|
1375
|
+
"aria-modal": "true",
|
|
1376
|
+
className: clsx("im-slideover-wrapper w-full transition-[filter] duration-300", modalContext.onTopOfStack ? "" : "blur-xs", maxWidthClass),
|
|
1377
|
+
children: [
|
|
1378
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Dialog" }),
|
|
1379
|
+
renderContent()
|
|
1380
|
+
]
|
|
1381
|
+
}
|
|
1382
|
+
)
|
|
1383
|
+
}
|
|
1384
|
+
)
|
|
1385
|
+
}
|
|
1386
|
+
);
|
|
1387
|
+
};
|
|
1388
|
+
const Modal = React.forwardRef(
|
|
1389
|
+
(allProps, ref) => {
|
|
1390
|
+
const { name, children, onFocus, onBlur, onClose, onSuccess, onAfterLeave, ...props } = allProps;
|
|
1391
|
+
const renderChildren = (contentProps) => {
|
|
1392
|
+
if (typeof children === "function") {
|
|
1393
|
+
return children(contentProps);
|
|
1394
|
+
}
|
|
1395
|
+
return children;
|
|
1396
|
+
};
|
|
1397
|
+
const headlessModalRef = React.useRef(null);
|
|
1398
|
+
const cleanupScrollLockRef = React.useRef(null);
|
|
1399
|
+
const cleanupAriaHiddenRef = React.useRef(null);
|
|
1400
|
+
const [rendered, setRendered] = React.useState(false);
|
|
1401
|
+
const useNativeDialog = React.useMemo(() => getConfig("useNativeDialog"), []);
|
|
1402
|
+
React.useImperativeHandle(ref, () => headlessModalRef.current, [headlessModalRef]);
|
|
1403
|
+
React.useEffect(() => {
|
|
1404
|
+
return () => {
|
|
1405
|
+
cleanupScrollLockRef.current?.();
|
|
1406
|
+
cleanupAriaHiddenRef.current?.();
|
|
1407
|
+
};
|
|
1408
|
+
}, []);
|
|
1409
|
+
const handleSuccess = React.useCallback(() => {
|
|
1410
|
+
onSuccess?.();
|
|
1411
|
+
if (!cleanupScrollLockRef.current) {
|
|
1412
|
+
cleanupScrollLockRef.current = vanilla.lockScroll();
|
|
1413
|
+
cleanupAriaHiddenRef.current = vanilla.markAriaHidden(getConfig("appElement"));
|
|
1414
|
+
}
|
|
1415
|
+
}, [onSuccess]);
|
|
1416
|
+
const handleClose = React.useCallback(() => {
|
|
1417
|
+
onClose?.();
|
|
1418
|
+
cleanupScrollLockRef.current?.();
|
|
1419
|
+
cleanupAriaHiddenRef.current?.();
|
|
1420
|
+
cleanupScrollLockRef.current = null;
|
|
1421
|
+
cleanupAriaHiddenRef.current = null;
|
|
1422
|
+
}, [onClose]);
|
|
1423
|
+
const handleAfterLeave = React.useCallback(() => {
|
|
1424
|
+
onAfterLeave?.();
|
|
1425
|
+
}, [onAfterLeave]);
|
|
1426
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1427
|
+
HeadlessModal,
|
|
1428
|
+
{
|
|
1429
|
+
ref: headlessModalRef,
|
|
1430
|
+
name,
|
|
1431
|
+
onFocus: onFocus ?? void 0,
|
|
1432
|
+
onBlur: onBlur ?? void 0,
|
|
1433
|
+
onClose: handleClose,
|
|
1434
|
+
onSuccess: handleSuccess,
|
|
1435
|
+
...props,
|
|
1436
|
+
children: ({
|
|
1437
|
+
afterLeave,
|
|
1438
|
+
close,
|
|
1439
|
+
config,
|
|
1440
|
+
emit,
|
|
1441
|
+
getChildModal,
|
|
1442
|
+
getParentModal,
|
|
1443
|
+
id,
|
|
1444
|
+
index,
|
|
1445
|
+
isOpen,
|
|
1446
|
+
modalContext,
|
|
1447
|
+
onTopOfStack,
|
|
1448
|
+
reload,
|
|
1449
|
+
setOpen,
|
|
1450
|
+
shouldRender,
|
|
1451
|
+
...extraProps
|
|
1452
|
+
}) => /* @__PURE__ */ jsxRuntime.jsx(ModalPortal, { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1453
|
+
"div",
|
|
1454
|
+
{
|
|
1455
|
+
className: "im-dialog relative z-20",
|
|
1456
|
+
"data-inertiaui-modal-id": id,
|
|
1457
|
+
"data-inertiaui-modal-index": index,
|
|
1458
|
+
"aria-hidden": !onTopOfStack,
|
|
1459
|
+
children: [
|
|
1460
|
+
index === 0 && !useNativeDialog && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1461
|
+
BackdropTransition,
|
|
1462
|
+
{
|
|
1463
|
+
show: isOpen,
|
|
1464
|
+
appear: !rendered,
|
|
1465
|
+
onAfterAppear: () => setRendered(true)
|
|
1466
|
+
}
|
|
1467
|
+
),
|
|
1468
|
+
config.slideover ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1469
|
+
SlideoverContent,
|
|
1470
|
+
{
|
|
1471
|
+
modalContext,
|
|
1472
|
+
config,
|
|
1473
|
+
useNativeDialog,
|
|
1474
|
+
isFirstModal: index === 0,
|
|
1475
|
+
onAfterLeave: handleAfterLeave,
|
|
1476
|
+
children: renderChildren({
|
|
1477
|
+
...extraProps,
|
|
1478
|
+
afterLeave,
|
|
1479
|
+
close,
|
|
1480
|
+
config,
|
|
1481
|
+
emit,
|
|
1482
|
+
getChildModal,
|
|
1483
|
+
getParentModal,
|
|
1484
|
+
id,
|
|
1485
|
+
index,
|
|
1486
|
+
isOpen,
|
|
1487
|
+
modalContext,
|
|
1488
|
+
onTopOfStack,
|
|
1489
|
+
reload,
|
|
1490
|
+
setOpen,
|
|
1491
|
+
shouldRender
|
|
1492
|
+
})
|
|
1493
|
+
}
|
|
1494
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1495
|
+
ModalContent,
|
|
1496
|
+
{
|
|
1497
|
+
modalContext,
|
|
1498
|
+
config,
|
|
1499
|
+
useNativeDialog,
|
|
1500
|
+
isFirstModal: index === 0,
|
|
1501
|
+
onAfterLeave: handleAfterLeave,
|
|
1502
|
+
children: renderChildren({
|
|
1503
|
+
...extraProps,
|
|
1504
|
+
afterLeave,
|
|
1505
|
+
close,
|
|
1506
|
+
config,
|
|
1507
|
+
emit,
|
|
1508
|
+
getChildModal,
|
|
1509
|
+
getParentModal,
|
|
1510
|
+
id,
|
|
1511
|
+
index,
|
|
1512
|
+
isOpen,
|
|
1513
|
+
modalContext,
|
|
1514
|
+
onTopOfStack,
|
|
1515
|
+
reload,
|
|
1516
|
+
setOpen,
|
|
1517
|
+
shouldRender
|
|
1518
|
+
})
|
|
1519
|
+
}
|
|
1520
|
+
)
|
|
1521
|
+
]
|
|
1522
|
+
}
|
|
1523
|
+
) })
|
|
1524
|
+
}
|
|
1525
|
+
);
|
|
1526
|
+
}
|
|
1527
|
+
);
|
|
1528
|
+
function ModalPortal({ children }) {
|
|
1529
|
+
const [mounted, setMounted] = React.useState(false);
|
|
1530
|
+
React.useEffect(() => {
|
|
1531
|
+
setMounted(true);
|
|
1532
|
+
}, []);
|
|
1533
|
+
if (!mounted) return null;
|
|
1534
|
+
return reactDom.createPortal(children, document.body);
|
|
1535
|
+
}
|
|
1536
|
+
function BackdropTransition({ show, appear, onAfterAppear }) {
|
|
1537
|
+
const [state, setState] = React.useState(() => {
|
|
1538
|
+
if (appear && show) return "entering";
|
|
1539
|
+
return show ? "entered" : "exited";
|
|
1540
|
+
});
|
|
1541
|
+
const initialRender = React.useRef(true);
|
|
1542
|
+
const backdropRef = React.useRef(null);
|
|
1543
|
+
React.useEffect(() => {
|
|
1544
|
+
if (initialRender.current) {
|
|
1545
|
+
initialRender.current = false;
|
|
1546
|
+
if (appear && show) {
|
|
1547
|
+
requestAnimationFrame(() => {
|
|
1548
|
+
setState("entered");
|
|
1549
|
+
const backdrop = backdropRef.current;
|
|
1550
|
+
if (backdrop) {
|
|
1551
|
+
const onTransitionEnd = (e) => {
|
|
1552
|
+
if (e.target !== backdrop) return;
|
|
1553
|
+
backdrop.removeEventListener("transitionend", onTransitionEnd);
|
|
1554
|
+
onAfterAppear?.();
|
|
1555
|
+
};
|
|
1556
|
+
backdrop.addEventListener("transitionend", onTransitionEnd);
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
if (show) {
|
|
1563
|
+
setState("entering");
|
|
1564
|
+
requestAnimationFrame(() => {
|
|
1565
|
+
setState("entered");
|
|
1566
|
+
});
|
|
1567
|
+
} else {
|
|
1568
|
+
setState("leaving");
|
|
1569
|
+
const backdrop = backdropRef.current;
|
|
1570
|
+
if (backdrop) {
|
|
1571
|
+
const onTransitionEnd = (e) => {
|
|
1572
|
+
if (e.target !== backdrop) return;
|
|
1573
|
+
backdrop.removeEventListener("transitionend", onTransitionEnd);
|
|
1574
|
+
setState("exited");
|
|
1575
|
+
};
|
|
1576
|
+
backdrop.addEventListener("transitionend", onTransitionEnd);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}, [show, appear, onAfterAppear]);
|
|
1580
|
+
if (state === "exited") return null;
|
|
1581
|
+
const isVisible = state === "entered";
|
|
1582
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1583
|
+
"div",
|
|
1584
|
+
{
|
|
1585
|
+
ref: backdropRef,
|
|
1586
|
+
className: `im-backdrop fixed inset-0 z-30 bg-black/75 transition-opacity duration-300 ease-in-out ${isVisible ? "opacity-100" : "opacity-0"}`,
|
|
1587
|
+
"aria-hidden": "true"
|
|
1588
|
+
}
|
|
1589
|
+
);
|
|
1590
|
+
}
|
|
1591
|
+
Modal.displayName = "Modal";
|
|
1592
|
+
const ModalLink = ({
|
|
1593
|
+
href,
|
|
1594
|
+
method = "get",
|
|
1595
|
+
data = {},
|
|
1596
|
+
as: Component = "a",
|
|
1597
|
+
headers = {},
|
|
1598
|
+
queryStringArrayFormat = "brackets",
|
|
1599
|
+
onAfterLeave,
|
|
1600
|
+
onBlur,
|
|
1601
|
+
onClose,
|
|
1602
|
+
onError,
|
|
1603
|
+
onFocus,
|
|
1604
|
+
onStart,
|
|
1605
|
+
onSuccess,
|
|
1606
|
+
onPrefetching,
|
|
1607
|
+
onPrefetched,
|
|
1608
|
+
navigate,
|
|
1609
|
+
prefetch: prefetch$1 = false,
|
|
1610
|
+
cacheFor = 3e4,
|
|
1611
|
+
children,
|
|
1612
|
+
...props
|
|
1613
|
+
}) => {
|
|
1614
|
+
const [loading, setLoading] = React.useState(false);
|
|
1615
|
+
const [modalContext, setModalContext] = React.useState(null);
|
|
1616
|
+
const { stack, visit } = useModalStack();
|
|
1617
|
+
const hoverTimeout = React.useRef(null);
|
|
1618
|
+
const shouldNavigate = React.useMemo(() => {
|
|
1619
|
+
return navigate ?? getConfig("navigate");
|
|
1620
|
+
}, [navigate]);
|
|
1621
|
+
const prefetchModes = React.useMemo(() => {
|
|
1622
|
+
if (prefetch$1 === true) {
|
|
1623
|
+
return ["hover"];
|
|
1624
|
+
}
|
|
1625
|
+
if (prefetch$1 === false) {
|
|
1626
|
+
return [];
|
|
1627
|
+
}
|
|
1628
|
+
if (Array.isArray(prefetch$1)) {
|
|
1629
|
+
return prefetch$1;
|
|
1630
|
+
}
|
|
1631
|
+
return [prefetch$1];
|
|
1632
|
+
}, [prefetch$1]);
|
|
1633
|
+
const doPrefetch = React.useCallback(() => {
|
|
1634
|
+
prefetch(href, {
|
|
1635
|
+
method,
|
|
1636
|
+
data,
|
|
1637
|
+
headers,
|
|
1638
|
+
queryStringArrayFormat,
|
|
1639
|
+
cacheFor,
|
|
1640
|
+
onPrefetching: onPrefetching ?? void 0,
|
|
1641
|
+
onPrefetched: onPrefetched ?? void 0
|
|
1642
|
+
});
|
|
1643
|
+
}, [href, method, data, headers, queryStringArrayFormat, cacheFor, onPrefetching, onPrefetched]);
|
|
1644
|
+
const handleMouseEnter = React.useCallback(() => {
|
|
1645
|
+
if (!prefetchModes.includes("hover")) return;
|
|
1646
|
+
hoverTimeout.current = setTimeout(() => {
|
|
1647
|
+
doPrefetch();
|
|
1648
|
+
}, 75);
|
|
1649
|
+
}, [prefetchModes, doPrefetch]);
|
|
1650
|
+
const handleMouseLeave = React.useCallback(() => {
|
|
1651
|
+
if (hoverTimeout.current) {
|
|
1652
|
+
clearTimeout(hoverTimeout.current);
|
|
1653
|
+
hoverTimeout.current = null;
|
|
1654
|
+
}
|
|
1655
|
+
}, []);
|
|
1656
|
+
const handleMouseDown = React.useCallback(
|
|
1657
|
+
(event) => {
|
|
1658
|
+
if (!prefetchModes.includes("click")) return;
|
|
1659
|
+
if (event.button !== 0) return;
|
|
1660
|
+
doPrefetch();
|
|
1661
|
+
},
|
|
1662
|
+
[prefetchModes, doPrefetch]
|
|
1663
|
+
);
|
|
1664
|
+
React.useEffect(() => {
|
|
1665
|
+
if (prefetchModes.includes("mount")) {
|
|
1666
|
+
doPrefetch();
|
|
1667
|
+
}
|
|
1668
|
+
}, []);
|
|
1669
|
+
React.useEffect(() => {
|
|
1670
|
+
return () => {
|
|
1671
|
+
if (hoverTimeout.current) {
|
|
1672
|
+
clearTimeout(hoverTimeout.current);
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
}, []);
|
|
1676
|
+
const standardProps = {};
|
|
1677
|
+
const customEvents = {};
|
|
1678
|
+
Object.keys(props).forEach((key) => {
|
|
1679
|
+
if (modalPropNames.includes(key)) {
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
if (key.startsWith("on") && typeof props[key] === "function") {
|
|
1683
|
+
if (vanilla.isStandardDomEvent(key)) {
|
|
1684
|
+
standardProps[key] = props[key];
|
|
1685
|
+
} else {
|
|
1686
|
+
customEvents[key] = props[key];
|
|
1687
|
+
}
|
|
1688
|
+
} else {
|
|
1689
|
+
standardProps[key] = props[key];
|
|
1690
|
+
}
|
|
1691
|
+
});
|
|
1692
|
+
const [isBlurred, setIsBlurred] = React.useState(false);
|
|
1693
|
+
React.useEffect(() => {
|
|
1694
|
+
if (!modalContext) {
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
if (modalContext.onTopOfStack && isBlurred) {
|
|
1698
|
+
onFocus?.();
|
|
1699
|
+
} else if (!modalContext.onTopOfStack && !isBlurred) {
|
|
1700
|
+
onBlur?.();
|
|
1701
|
+
}
|
|
1702
|
+
setIsBlurred(!modalContext.onTopOfStack);
|
|
1703
|
+
}, [stack]);
|
|
1704
|
+
const onCloseCallback = React.useCallback(() => {
|
|
1705
|
+
onClose?.();
|
|
1706
|
+
}, [onClose]);
|
|
1707
|
+
const onAfterLeaveCallback = React.useCallback(() => {
|
|
1708
|
+
setModalContext(null);
|
|
1709
|
+
onAfterLeave?.();
|
|
1710
|
+
}, [onAfterLeave]);
|
|
1711
|
+
const handle = React.useCallback(
|
|
1712
|
+
(e) => {
|
|
1713
|
+
e?.preventDefault();
|
|
1714
|
+
if (loading) return;
|
|
1715
|
+
if (!href.startsWith("#")) {
|
|
1716
|
+
setLoading(true);
|
|
1717
|
+
onStart?.();
|
|
1718
|
+
}
|
|
1719
|
+
visit(
|
|
1720
|
+
href,
|
|
1721
|
+
method,
|
|
1722
|
+
data,
|
|
1723
|
+
headers,
|
|
1724
|
+
vanilla.rejectNullValues(vanilla.only(props, modalPropNames)),
|
|
1725
|
+
() => onCloseCallback(),
|
|
1726
|
+
onAfterLeaveCallback,
|
|
1727
|
+
queryStringArrayFormat,
|
|
1728
|
+
shouldNavigate
|
|
1729
|
+
).then((newModalContext) => {
|
|
1730
|
+
setModalContext(newModalContext);
|
|
1731
|
+
newModalContext.registerEventListenersFromProps(customEvents);
|
|
1732
|
+
onSuccess?.();
|
|
1733
|
+
}).catch((error) => {
|
|
1734
|
+
console.error(error);
|
|
1735
|
+
onError?.(error);
|
|
1736
|
+
}).finally(() => setLoading(false));
|
|
1737
|
+
},
|
|
1738
|
+
[href, method, data, headers, queryStringArrayFormat, props, onCloseCallback, onAfterLeaveCallback]
|
|
1739
|
+
);
|
|
1740
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1741
|
+
Component,
|
|
1742
|
+
{
|
|
1743
|
+
...standardProps,
|
|
1744
|
+
href,
|
|
1745
|
+
onClick: handle,
|
|
1746
|
+
onMouseEnter: handleMouseEnter,
|
|
1747
|
+
onMouseLeave: handleMouseLeave,
|
|
1748
|
+
onMouseDown: handleMouseDown,
|
|
1749
|
+
children: typeof children === "function" ? children({ loading }) : children
|
|
1750
|
+
}
|
|
1751
|
+
);
|
|
1752
|
+
};
|
|
1753
|
+
const WhenVisible = ({ children, data, params, buffer, as, always, fallback }) => {
|
|
1754
|
+
always = always ?? false;
|
|
1755
|
+
as = as ?? "div";
|
|
1756
|
+
fallback = fallback ?? null;
|
|
1757
|
+
const [loaded, setLoaded] = React.useState(false);
|
|
1758
|
+
const hasFetched = React.useRef(false);
|
|
1759
|
+
const fetching = React.useRef(false);
|
|
1760
|
+
const ref = React.useRef(null);
|
|
1761
|
+
const modal = useModal();
|
|
1762
|
+
const getReloadParams = React.useCallback(() => {
|
|
1763
|
+
if (data) {
|
|
1764
|
+
return {
|
|
1765
|
+
only: Array.isArray(data) ? data : [data]
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
if (!params) {
|
|
1769
|
+
throw new Error("You must provide either a `data` or `params` prop.");
|
|
1770
|
+
}
|
|
1771
|
+
return params;
|
|
1772
|
+
}, [params, data]);
|
|
1773
|
+
React.useEffect(() => {
|
|
1774
|
+
if (!ref.current) {
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
const observer = new IntersectionObserver(
|
|
1778
|
+
(entries) => {
|
|
1779
|
+
if (!entries[0].isIntersecting) {
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1782
|
+
if (!always && hasFetched.current) {
|
|
1783
|
+
observer.disconnect();
|
|
1784
|
+
}
|
|
1785
|
+
if (fetching.current) {
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
hasFetched.current = true;
|
|
1789
|
+
fetching.current = true;
|
|
1790
|
+
const reloadParams = getReloadParams();
|
|
1791
|
+
modal?.reload({
|
|
1792
|
+
...reloadParams,
|
|
1793
|
+
onStart: () => {
|
|
1794
|
+
fetching.current = true;
|
|
1795
|
+
reloadParams.onStart?.();
|
|
1796
|
+
},
|
|
1797
|
+
onFinish: () => {
|
|
1798
|
+
setLoaded(true);
|
|
1799
|
+
fetching.current = false;
|
|
1800
|
+
reloadParams.onFinish?.();
|
|
1801
|
+
if (!always) {
|
|
1802
|
+
observer.disconnect();
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
});
|
|
1806
|
+
},
|
|
1807
|
+
{
|
|
1808
|
+
rootMargin: `${buffer || 0}px`
|
|
1809
|
+
}
|
|
1810
|
+
);
|
|
1811
|
+
observer.observe(ref.current);
|
|
1812
|
+
return () => {
|
|
1813
|
+
observer.disconnect();
|
|
1814
|
+
};
|
|
1815
|
+
}, [ref, getReloadParams, buffer]);
|
|
1816
|
+
if (always || !loaded) {
|
|
1817
|
+
return React.createElement(
|
|
1818
|
+
as,
|
|
1819
|
+
{
|
|
1820
|
+
props: null,
|
|
1821
|
+
ref
|
|
1822
|
+
},
|
|
1823
|
+
loaded ? children : fallback
|
|
1824
|
+
);
|
|
1825
|
+
}
|
|
1826
|
+
return loaded ? children : null;
|
|
1827
|
+
};
|
|
1828
|
+
WhenVisible.displayName = "InertiaWhenVisible";
|
|
1829
|
+
const setPageLayout = (layout) => (module2) => {
|
|
1830
|
+
module2.default.layout = (page) => React.createElement(layout, { children: page });
|
|
1831
|
+
return module2;
|
|
1832
|
+
};
|
|
1833
|
+
exports2.dialogUtils = vanilla__namespace;
|
|
1834
|
+
exports2.Deferred = Deferred;
|
|
1835
|
+
exports2.HeadlessModal = HeadlessModal;
|
|
1836
|
+
exports2.Modal = Modal;
|
|
1837
|
+
exports2.ModalLink = ModalLink;
|
|
1838
|
+
exports2.ModalRoot = ModalRoot;
|
|
1839
|
+
exports2.ModalStackProvider = ModalStackProvider;
|
|
1840
|
+
exports2.WhenVisible = WhenVisible;
|
|
1841
|
+
exports2.getConfig = getConfig;
|
|
1842
|
+
exports2.initFromPageProps = initFromPageProps;
|
|
1843
|
+
exports2.modalPropNames = modalPropNames;
|
|
1844
|
+
exports2.prefetch = prefetch;
|
|
1845
|
+
exports2.putConfig = putConfig;
|
|
1846
|
+
exports2.renderApp = renderApp;
|
|
1847
|
+
exports2.resetConfig = resetConfig;
|
|
1848
|
+
exports2.setPageLayout = setPageLayout;
|
|
1849
|
+
exports2.useModal = useModal;
|
|
1850
|
+
exports2.useModalIndex = useModalIndex;
|
|
1851
|
+
exports2.useModalStack = useModalStack;
|
|
1852
|
+
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
1853
|
+
}));
|
|
1854
|
+
//# sourceMappingURL=inertiaui-modal.umd.cjs.map
|