inertiax-core
Advanced tools
Comparing version 2.6.1 to 2.6.2
@@ -1,2 +0,2 @@ | ||
import{default as Y}from"axios";function T(i,e){let t;return function(...r){clearTimeout(t),t=setTimeout(()=>i.apply(this,r),e)}}function b(i,e){return document.dispatchEvent(new CustomEvent(`inertia:${i}`,e))}var $=i=>b("before",{cancelable:!0,detail:{visit:i}}),q=i=>b("error",{detail:{errors:i}}),W=i=>b("exception",{cancelable:!0,detail:{exception:i}}),I=i=>b("finish",{detail:{visit:i}}),_=i=>b("invalid",{cancelable:!0,detail:{response:i}}),S=i=>b("navigate",{detail:{page:i}}),K=i=>b("progress",{detail:{progress:i}}),X=i=>b("start",{detail:{visit:i}}),J=i=>b("success",{detail:{page:i}});function O(i){return i instanceof File||i instanceof Blob||i instanceof FileList&&i.length>0||i instanceof FormData&&Array.from(i.values()).some(e=>O(e))||typeof i=="object"&&i!==null&&Object.values(i).some(e=>O(e))}function A(i,e=new FormData,t=null){i=i||{};for(let r in i)Object.prototype.hasOwnProperty.call(i,r)&&B(e,z(t,r),i[r]);return e}function z(i,e){return i?i+"["+e+"]":e}function B(i,e,t){if(Array.isArray(t))return Array.from(t.keys()).forEach(r=>B(i,z(e,r.toString()),t[r]));if(t instanceof Date)return i.append(e,t.toISOString());if(t instanceof File)return i.append(e,t,t.name);if(t instanceof Blob)return i.append(e,t);if(typeof t=="boolean")return i.append(e,t?"1":"0");if(typeof t=="string")return i.append(e,t);if(typeof t=="number")return i.append(e,`${t}`);if(t==null)return i.append(e,"");A(t,i,e)}var Q={modal:null,listener:null,show(i){typeof i=="object"&&(i=`All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(i)}`);let e=document.createElement("html");e.innerHTML=i,e.querySelectorAll("a").forEach(r=>r.setAttribute("target","_top")),this.modal=document.createElement("div"),this.modal.style.position="fixed",this.modal.style.width="100vw",this.modal.style.height="100vh",this.modal.style.padding="50px",this.modal.style.boxSizing="border-box",this.modal.style.backgroundColor="rgba(0, 0, 0, .6)",this.modal.style.zIndex=2e5,this.modal.addEventListener("click",()=>this.hide());let t=document.createElement("iframe");if(t.style.backgroundColor="white",t.style.borderRadius="5px",t.style.width="100%",t.style.height="100%",this.modal.appendChild(t),document.body.prepend(this.modal),document.body.style.overflow="hidden",!t.contentWindow)throw new Error("iframe not yet ready.");t.contentWindow.document.open(),t.contentWindow.document.write(e.outerHTML),t.contentWindow.document.close(),this.listener=this.hideOnEscape.bind(this),document.addEventListener("keydown",this.listener)},hide(){this.modal.outerHTML="",this.modal=null,document.body.style.overflow="visible",document.removeEventListener("keydown",this.listener)},hideOnEscape(i){i.keyCode===27&&this.hide()}};import se from"deepmerge";import*as C from"qs";function E(i){return new URL(i.toString(),window.location.toString())}function D(i,e,t,r="brackets"){let o=/^https?:\/\//.test(e.toString()),l=o||e.toString().startsWith("/"),d=!l&&!e.toString().startsWith("#")&&!e.toString().startsWith("?"),p=e.toString().includes("?")||i==="get"&&Object.keys(t).length,h=e.toString().includes("#"),c=new URL(e.toString(),"http://localhost");return i==="get"&&Object.keys(t).length&&(c.search=C.stringify(se(C.parse(c.search,{ignoreQueryPrefix:!0}),t),{encodeValuesOnly:!0,arrayFormat:r}),t={}),[[o?`${c.protocol}//${c.host}`:"",l?c.pathname:"",d?c.pathname.substring(1):"",p?c.search:"",h?c.hash:""].join(""),t]}function w(i){return i=new URL(i.href),i.hash="",i}var Z=typeof window>"u",F=class{constructor(){this.visitId=null}init({initialPage:e,resolveComponent:t,swapComponent:r}){this.page=e,this.resolveComponent=t,this.swapComponent=r,this.setNavigationType(),this.clearRememberedStateOnReload(),this.isBackForwardVisit()?this.handleBackForwardVisit(this.page):this.isLocationVisit()?this.handleLocationVisit(this.page):this.handleInitialPageVisit(this.page),this.setupEventListeners()}setNavigationType(){this.navigationType=window.performance&&window.performance.getEntriesByType("navigation").length>0?window.performance.getEntriesByType("navigation")[0].type:"navigate"}clearRememberedStateOnReload(){this.navigationType==="reload"&&window.history.state?.rememberedState&&delete window.history.state.rememberedState}handleInitialPageVisit(e){this.page.url+=window.location.hash,this.setPage(e,{preserveScroll:!0,preserveState:!0}).then(()=>S(e))}setupEventListeners(){window.addEventListener("popstate",this.handlePopstateEvent.bind(this)),document.addEventListener("scroll",T(this.handleScrollEvent.bind(this),100),!0),document.addEventListener("click",e=>{let t=e.target;if(e.defaultPrevented||t.closest("[data-inertia-ignore]"))return;let r=t.closest("a"),o=t.closest("[data-inertia-frame-id]")?.dataset.inertiaFrameId,l=t.closest("[data-hint]")?.dataset.hint,d=t.closest("[data-component]")?.dataset.component;if(!(!r||r.rel=="external"||r.target=="_blank")&&r.href&&r.href.startsWith(location.origin)){let p=r.attributes.getNamedItem("href")?.value,h=r.dataset["preserve-scroll"],c=r.dataset["preserve-state"];if(e.preventDefault(),e.stopPropagation(),p?.startsWith("#")){let s=this.page;s.url=r.href,this.setPage(s,{preserveScroll:h,preserveState:c}).then(()=>{S(s)})}else this.visit(r.href,{method:r.dataset.method,target:r.dataset.target||o,hint:l,component:d,preserveScroll:h,preserveState:c})}})}scrollRegions(){return document.querySelectorAll("[scroll-region]")}handleScrollEvent(e){typeof e.target.hasAttribute=="function"&&e.target.hasAttribute("scroll-region")&&this.saveScrollPositions()}saveScrollPositions(){this.replaceState({...history.state,scrollRegions:Array.from(this.scrollRegions()).map(e=>({top:e.scrollTop,left:e.scrollLeft}))})}resetScrollPositions(){window.scrollTo(0,0),this.scrollRegions().forEach(e=>{typeof e.scrollTo=="function"?e.scrollTo(0,0):(e.scrollTop=0,e.scrollLeft=0)}),this.saveScrollPositions(),window.location.hash&&setTimeout(()=>document.getElementById(window.location.hash.slice(1))?.scrollIntoView())}restoreScrollPositions(){this.page.scrollRegions&&this.scrollRegions().forEach((e,t)=>{let r=this.page.scrollRegions[t];if(r)typeof e.scrollTo=="function"?e.scrollTo(r.left,r.top):(e.scrollTop=r.top,e.scrollLeft=r.left);else return})}isBackForwardVisit(){return window.history.state&&this.navigationType==="back_forward"}handleBackForwardVisit(e){let t;e.props?t=e:(window.history.state.version=e.version,t=window.history.state),this.setPage(t,{preserveScroll:!0,preserveState:!0}).then(()=>{this.restoreScrollPositions(),S(e)})}locationVisit(e,t){try{let r={preserveScroll:t};window.sessionStorage.setItem("inertiaLocationVisit",JSON.stringify(r)),window.location.href=e.href,w(window.location).href===w(e).href&&window.location.reload()}catch{return!1}}isLocationVisit(){try{return window.sessionStorage.getItem("inertiaLocationVisit")!==null}catch{return!1}}handleLocationVisit(e){let t=JSON.parse(window.sessionStorage.getItem("inertiaLocationVisit")||"");window.sessionStorage.removeItem("inertiaLocationVisit"),e.url+=window.location.hash,e.rememberedState=window.history.state?.rememberedState??{},e.scrollRegions=window.history.state?.scrollRegions??[],this.setPage(e,{preserveScroll:t.preserveScroll,preserveState:!0}).then(()=>{t.preserveScroll&&this.restoreScrollPositions(),S(e)})}isLocationVisitResponse(e){return!!(e&&e.status===409&&e.headers["x-inertia-location"])}isInertiaResponse(e){return!!e?.headers["x-inertia"]}createVisitId(){return this.visitId={},this.visitId}cancelVisit(e,{cancelled:t=!1,interrupted:r=!1}){e&&!e.completed&&!e.cancelled&&!e.interrupted&&(e.cancelToken.abort(),e.onCancel(),e.completed=!1,e.cancelled=t,e.interrupted=r,I(e),e.onFinish(e))}finishVisit(e){!e.cancelled&&!e.interrupted&&(e.completed=!0,e.cancelled=!1,e.interrupted=!1,I(e),e.onFinish(e))}resolvePreserveOption(e,t){return typeof e=="function"?e(t):e==="errors"?Object.keys(t.props.errors||{}).length>0:e}cancel(){this.activeVisit&&this.cancelVisit(this.activeVisit,{cancelled:!0})}visit(e,{method:t="get",data:r={},replace:o=!1,preserveScroll:l=!1,preserveState:d=!1,preserveURL:p=!1,only:h=[],headers:c={},errorBag:s="",forceFormData:y=!1,target:u=null,component:f=null,hint:m=f,onCancelToken:R=()=>{},onBefore:P=()=>{},onStart:M=()=>{},onProgress:U=()=>{},onFinish:ne=()=>{},onCancel:oe=()=>{},onSuccess:G=()=>{},onError:H=()=>{},transformProps:N=()=>{},queryStringArrayFormat:k="brackets"}={}){let x=typeof e=="string"?E(e):e;if((O(r)||y)&&!(r instanceof FormData)&&(r=A(r)),!(r instanceof FormData)){let[n,a]=D(t,x,r,k);x=E(n),r=a}let L={url:x,method:t,data:r,replace:o,preserveScroll:l,preserveState:d,preserveURL:p,only:h,headers:c,errorBag:s,target:u,hint:m,component:f,forceFormData:y,transformProps:N,queryStringArrayFormat:k,noProgress:!1,cancelled:!1,completed:!1,interrupted:!1};if(P(L)===!1||!$(L))return;this.activeVisit&&this.cancelVisit(this.activeVisit,{interrupted:!0}),this.saveScrollPositions(),L.target&&(L.noProgress=!0);let j=this.createVisitId();if(this.activeVisit={...L,onCancelToken:R,onBefore:P,onStart:M,onProgress:U,onFinish:ne,onCancel:oe,onSuccess:G,onError:H,queryStringArrayFormat:k,cancelToken:new AbortController},R({cancel:()=>{this.activeVisit&&this.cancelVisit(this.activeVisit,{cancelled:!0})}}),m&&Promise.resolve(this.resolveComponent(m)).then(n=>{u&&u!=="_top"&&u!=="_parent"&&u!=="main"?this.swapComponent({component:n,page:{...this.page,target:u,url:w(x).pathname},preserveState:d}):this.swapComponent({component:n,page:{...this.page,url:w(x).pathname},preserveState:d})}),X(L),f){(!u||u==="_top"||u==="_parent"||u==="main")&&(o=o||E(this.page.url).href===window.location.href,o?this.replaceState(this.page):this.pushState(this.page)),l||this.resetScrollPositions(),o||S(this.page),I(this.activeVisit);return}M(L),Y({method:t,url:w(x).href,data:t==="get"?{}:r,params:t==="get"?r:{},signal:this.activeVisit.cancelToken.signal,headers:{...c,Accept:"text/html, application/xhtml+xml","X-Requested-With":"XMLHttpRequest","X-Inertia":!0,...h.length?{"X-Inertia-Partial-Component":this.page.component,"X-Inertia-Partial-Data":h.join(",")}:{},...s&&s.length?{"X-Inertia-Error-Bag":s}:{},...this.page.version?{"X-Inertia-Version":this.page.version}:{}},onUploadProgress:n=>{r instanceof FormData&&(n.percentage=n.progress?Math.round(n.progress*100):0,K(n),U(n))}}).then(n=>{if(!this.isInertiaResponse(n))return Promise.reject({response:n});let a=n.data;n.headers["x-inertia-frame"]&&(u=n.headers["x-inertia-frame"]),h.length&&a.component===this.page.component&&(a.props={...this.page.props,...a.props}),l=this.resolvePreserveOption(l,a),d=this.resolvePreserveOption(d,a),d&&window.history.state?.rememberedState&&a.component===this.page.component&&(a.rememberedState=window.history.state.rememberedState);let g=x,V=E(a.url);return g.hash&&!V.hash&&w(g).href===V.href&&(V.hash=g.hash,a.url=V.href),N&&N(a.props),this.setPage(a,{target:u,visitId:j,replace:o,preserveScroll:l,preserveState:d,preserveURL:p})}).then(n=>{let a=n.props.errors||{};if(Object.keys(a).length>0){let g=s?a[s]?a[s]:{}:a;return q(g),H(g)}return J(n),G(n)}).catch(n=>{if(this.isInertiaResponse(n.response))return this.setPage(n.response.data,{visitId:j});if(this.isLocationVisitResponse(n.response)){let a=E(n.response.headers["x-inertia-location"]),g=x;g.hash&&!a.hash&&w(g).href===a.href&&(a.hash=g.hash),this.locationVisit(a,l===!0)}else if(n.response)_(n.response)&&Q.show(n.response.data);else return Promise.reject(n)}).then(()=>{this.activeVisit&&this.finishVisit(this.activeVisit)}).catch(n=>{if(!Y.isCancel(n)){let a=W(n);if(this.activeVisit&&this.finishVisit(this.activeVisit),a)return Promise.reject(n)}})}setPage(e,{visitId:t=this.createVisitId(),replace:r=!1,preserveURL:o=!1,preserveScroll:l=!1,preserveState:d=!1,target:p=null}={}){return Promise.resolve(this.resolveComponent(e.component)).then(h=>(t===this.visitId&&(e.scrollRegions=e.scrollRegions||[],e.rememberedState=e.rememberedState||{},o&&(e.url=window.location.href),!p||p==="_top"||p==="_parent"||p==="main"?(r=r||E(e.url).href===window.location.href,r?this.replaceState(e):this.pushState(e)):e.target=p,this.swapComponent({component:h,page:e,preserveState:d}).then(()=>{l||this.resetScrollPositions(),r||S(e)})),e))}pushState(e){this.page=e,window.history.pushState(e,"",e.url)}replaceState(e){this.page=e,window.history.replaceState(e,"",e.url)}handlePopstateEvent(e){if(e.state!==null&&e.state.component){let t=e.state,r=this.createVisitId();Promise.resolve(this.resolveComponent(t.component)).then(o=>{r===this.visitId&&(this.page=t,this.swapComponent({component:o,page:t,preserveState:!1}).then(()=>{this.restoreScrollPositions(),S(t)}))})}else{if(!this.page.url)return;let t=E(this.page.url);t.hash=window.location.hash,this.replaceState({...history.state,url:t.href}),this.resetScrollPositions()}}get(e,t={},r={}){return this.visit(e,{...r,method:"get",data:t})}reload(e={}){return this.visit(window.location.href,{preserveScroll:!0,preserveState:!0,preserveURL:!0,...e})}replace(e,t={}){return console.warn(`Inertia.replace() has been deprecated and will be removed in a future release. Please use Inertia.${t.method??"get"}() instead.`),this.visit(e,{preserveState:!0,...t,replace:!0})}post(e,t={},r={}){return this.visit(e,{preserveState:!0,...r,method:"post",data:t})}put(e,t={},r={}){return this.visit(e,{preserveState:!0,...r,method:"put",data:t})}patch(e,t={},r={}){return this.visit(e,{preserveState:!0,...r,method:"patch",data:t})}delete(e,t={}){return this.visit(e,{preserveState:!0,...t,method:"delete"})}remember(e,t="default"){Z||this.replaceState({...history.state,rememberedState:{...this.page?.rememberedState,[t]:e}})}restore(e="default"){if(!Z)return window.history.state?.rememberedState?.[e]}on(e,t){let r=o=>{let l=t(o);o.cancelable&&!o.defaultPrevented&&l===!1&&o.preventDefault()};return document.addEventListener(`inertia:${e}`,r),()=>document.removeEventListener(`inertia:${e}`,r)}};var ae={buildDOMElement(i){let e=document.createElement("template");e.innerHTML=i;let t=e.content.firstChild;if(!i.startsWith("<script "))return t;let r=document.createElement("script");return r.innerHTML=t.innerHTML,t.getAttributeNames().forEach(o=>{r.setAttribute(o,t.getAttribute(o)||"")}),r},isInertiaManagedElement(i){return i.nodeType===Node.ELEMENT_NODE&&i.getAttribute("inertia")!==null},findMatchingElementIndex(i,e){let t=i.getAttribute("inertia");return t!==null?e.findIndex(r=>r.getAttribute("inertia")===t):-1},update:T(function(i){let e=i.map(r=>this.buildDOMElement(r));Array.from(document.head.childNodes).filter(r=>this.isInertiaManagedElement(r)).forEach(r=>{let o=this.findMatchingElementIndex(r,e);if(o===-1){r?.parentNode?.removeChild(r);return}let l=e.splice(o,1)[0];l&&!r.isEqualNode(l)&&r?.parentNode?.replaceChild(l,r)}),e.forEach(r=>document.head.appendChild(r))},1)};function ee(i,e,t){let r={},o=0;function l(){let s=o+=1;return r[s]=[],s.toString()}function d(s){s===null||Object.keys(r).indexOf(s)===-1||(delete r[s],c())}function p(s,y=[]){s!==null&&Object.keys(r).indexOf(s)>-1&&(r[s]=y),c()}function h(){let s=e(""),y={...s?{title:`<title inertia="">${s}</title>`}:{}},u=Object.values(r).reduce((f,m)=>f.concat(m),[]).reduce((f,m)=>{if(m.indexOf("<")===-1)return f;if(m.indexOf("<title ")===0){let P=m.match(/(<title [^>]+>)(.*?)(<\/title>)/);return f.title=P?`${P[1]}${e(P[2])}${P[3]}`:m,f}let R=m.match(/ inertia="[^"]+"/);return R?f[R[0]]=m:f[Object.keys(f).length]=m,f},y);return Object.values(u)}function c(){i?t(h()):ae.update(h())}return c(),{forceUpdate:c,createProvider:function(){let s=l();return{update:y=>p(s,y),disconnect:()=>d(s)}}}}import v from"nprogress";var te=null;function le(i){document.addEventListener("inertia:start",ce(i)),document.addEventListener("inertia:progress",de),document.addEventListener("inertia:finish",pe)}function ce(i){return function(e){e.detail.visit.noProgress||(te=setTimeout(()=>v.start(),i))}}function de(i){v.isStarted()&&i.detail.progress?.percentage&&v.set(Math.max(v.status,i.detail.progress.percentage/100*.9))}function pe(i){if(clearTimeout(te),v.isStarted())i.detail.visit.completed?v.done():i.detail.visit.interrupted?v.set(0):i.detail.visit.cancelled&&(v.done(),v.remove());else return}function he(i){let e=document.createElement("style");e.type="text/css",e.textContent=` | ||
import{default as Y}from"axios";function T(i,e){let t;return function(...n){clearTimeout(t),t=setTimeout(()=>i.apply(this,n),e)}}function b(i,e){return document.dispatchEvent(new CustomEvent(`inertia:${i}`,e))}var $=i=>b("before",{cancelable:!0,detail:{visit:i}}),q=i=>b("error",{detail:{errors:i}}),W=i=>b("exception",{cancelable:!0,detail:{exception:i}}),I=i=>b("finish",{detail:{visit:i}}),_=i=>b("invalid",{cancelable:!0,detail:{response:i}}),S=i=>b("navigate",{detail:{page:i}}),K=i=>b("progress",{detail:{progress:i}}),X=i=>b("start",{detail:{visit:i}}),J=i=>b("success",{detail:{page:i}});function O(i){return i instanceof File||i instanceof Blob||i instanceof FileList&&i.length>0||i instanceof FormData&&Array.from(i.values()).some(e=>O(e))||typeof i=="object"&&i!==null&&Object.values(i).some(e=>O(e))}function A(i,e=new FormData,t=null){i=i||{};for(let n in i)Object.prototype.hasOwnProperty.call(i,n)&&B(e,z(t,n),i[n]);return e}function z(i,e){return i?i+"["+e+"]":e}function B(i,e,t){if(Array.isArray(t))return Array.from(t.keys()).forEach(n=>B(i,z(e,n.toString()),t[n]));if(t instanceof Date)return i.append(e,t.toISOString());if(t instanceof File)return i.append(e,t,t.name);if(t instanceof Blob)return i.append(e,t);if(typeof t=="boolean")return i.append(e,t?"1":"0");if(typeof t=="string")return i.append(e,t);if(typeof t=="number")return i.append(e,`${t}`);if(t==null)return i.append(e,"");A(t,i,e)}var Q={modal:null,listener:null,show(i){typeof i=="object"&&(i=`All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(i)}`);let e=document.createElement("html");e.innerHTML=i,e.querySelectorAll("a").forEach(n=>n.setAttribute("target","_top")),this.modal=document.createElement("div"),this.modal.style.position="fixed",this.modal.style.width="100vw",this.modal.style.height="100vh",this.modal.style.padding="50px",this.modal.style.boxSizing="border-box",this.modal.style.backgroundColor="rgba(0, 0, 0, .6)",this.modal.style.zIndex=2e5,this.modal.addEventListener("click",()=>this.hide());let t=document.createElement("iframe");if(t.style.backgroundColor="white",t.style.borderRadius="5px",t.style.width="100%",t.style.height="100%",this.modal.appendChild(t),document.body.prepend(this.modal),document.body.style.overflow="hidden",!t.contentWindow)throw new Error("iframe not yet ready.");t.contentWindow.document.open(),t.contentWindow.document.write(e.outerHTML),t.contentWindow.document.close(),this.listener=this.hideOnEscape.bind(this),document.addEventListener("keydown",this.listener)},hide(){this.modal.outerHTML="",this.modal=null,document.body.style.overflow="visible",document.removeEventListener("keydown",this.listener)},hideOnEscape(i){i.keyCode===27&&this.hide()}};import se from"deepmerge";import*as C from"qs";function E(i){return new URL(i.toString(),window.location.toString())}function D(i,e,t,n="brackets"){let o=/^https?:\/\//.test(e.toString()),l=o||e.toString().startsWith("/"),d=!l&&!e.toString().startsWith("#")&&!e.toString().startsWith("?"),p=e.toString().includes("?")||i==="get"&&Object.keys(t).length,h=e.toString().includes("#"),c=new URL(e.toString(),"http://localhost");return i==="get"&&Object.keys(t).length&&(c.search=C.stringify(se(C.parse(c.search,{ignoreQueryPrefix:!0}),t),{encodeValuesOnly:!0,arrayFormat:n}),t={}),[[o?`${c.protocol}//${c.host}`:"",l?c.pathname:"",d?c.pathname.substring(1):"",p?c.search:"",h?c.hash:""].join(""),t]}function w(i){return i=new URL(i.href),i.hash="",i}var Z=typeof window>"u",F=class{constructor(){this.visitId=null}init({initialPage:e,resolveComponent:t,swapComponent:n}){this.page=e,this.resolveComponent=t,this.swapComponent=n,this.setNavigationType(),this.clearRememberedStateOnReload(),this.isBackForwardVisit()?this.handleBackForwardVisit(this.page):this.isLocationVisit()?this.handleLocationVisit(this.page):this.handleInitialPageVisit(this.page),this.setupEventListeners()}setNavigationType(){this.navigationType=window.performance&&window.performance.getEntriesByType("navigation").length>0?window.performance.getEntriesByType("navigation")[0].type:"navigate"}clearRememberedStateOnReload(){this.navigationType==="reload"&&window.history.state?.rememberedState&&delete window.history.state.rememberedState}handleInitialPageVisit(e){this.page.url+=window.location.hash,this.setPage(e,{preserveScroll:!0,preserveState:!0}).then(()=>S(e))}setupEventListeners(){window.addEventListener("popstate",this.handlePopstateEvent.bind(this)),document.addEventListener("scroll",T(this.handleScrollEvent.bind(this),100),!0),document.addEventListener("click",e=>{let t=e.target;if(e.defaultPrevented||t.closest("[data-inertia-ignore]"))return;let n=t.closest("a"),o=t.closest("[data-inertia-frame-id]")?.dataset.inertiaFrameId,l=t.closest("[data-hint]")?.dataset.hint,d=t.closest("[data-component]")?.dataset.component;if(!(!n||n.rel=="external"||n.target=="_blank")&&n.href&&n.href.startsWith(location.origin)){let p=n.attributes.getNamedItem("href")?.value,h=n.dataset["preserve-scroll"],c=n.dataset["preserve-state"];if(e.preventDefault(),e.stopPropagation(),p?.startsWith("#")){let s=this.page;s.url=n.href,this.setPage(s,{preserveScroll:h,preserveState:c}).then(()=>{S(s)})}else this.visit(n.href,{method:n.dataset.method,target:n.dataset.target||o,hint:l,component:d,preserveScroll:h,preserveState:c})}})}scrollRegions(){return document.querySelectorAll("[scroll-region]")}handleScrollEvent(e){typeof e.target.hasAttribute=="function"&&e.target.hasAttribute("scroll-region")&&this.saveScrollPositions()}saveScrollPositions(){let e=Array.from(this.scrollRegions()).map(t=>({top:t.scrollTop,left:t.scrollLeft}));this.replaceState({...history.state,scrollRegions:e})}resetScrollPositions(){window.scrollTo(0,0),this.scrollRegions().forEach(e=>{typeof e.scrollTo=="function"?e.scrollTo(0,0):(e.scrollTop=0,e.scrollLeft=0)}),this.saveScrollPositions(),window.location.hash&&setTimeout(()=>document.getElementById(window.location.hash.slice(1))?.scrollIntoView())}restoreScrollPositions(){this.page.scrollRegions&&this.scrollRegions().forEach((e,t)=>{let n=this.page.scrollRegions[t];if(n)typeof e.scrollTo=="function"?e.scrollTo(n.left,n.top):(e.scrollTop=n.top,e.scrollLeft=n.left);else return})}isBackForwardVisit(){return window.history.state&&this.navigationType==="back_forward"}handleBackForwardVisit(e){let t;e.props?t=e:(window.history.state.version=e.version,t=window.history.state),this.setPage(t,{preserveScroll:!0,preserveState:!0}).then(()=>{this.restoreScrollPositions(),S(e)})}locationVisit(e,t){try{let n={preserveScroll:t};window.sessionStorage.setItem("inertiaLocationVisit",JSON.stringify(n)),window.location.href=e.href,w(window.location).href===w(e).href&&window.location.reload()}catch{return!1}}isLocationVisit(){try{return window.sessionStorage.getItem("inertiaLocationVisit")!==null}catch{return!1}}handleLocationVisit(e){let t=JSON.parse(window.sessionStorage.getItem("inertiaLocationVisit")||"");window.sessionStorage.removeItem("inertiaLocationVisit"),e.url+=window.location.hash,e.rememberedState=window.history.state?.rememberedState??{},e.scrollRegions=window.history.state?.scrollRegions??[],this.setPage(e,{preserveScroll:t.preserveScroll,preserveState:!0}).then(()=>{t.preserveScroll&&this.restoreScrollPositions(),S(e)})}isLocationVisitResponse(e){return!!(e&&e.status===409&&e.headers["x-inertia-location"])}isInertiaResponse(e){return!!e?.headers["x-inertia"]}createVisitId(){return this.visitId={},this.visitId}cancelVisit(e,{cancelled:t=!1,interrupted:n=!1}){e&&!e.completed&&!e.cancelled&&!e.interrupted&&(e.cancelToken.abort(),e.onCancel(),e.completed=!1,e.cancelled=t,e.interrupted=n,I(e),e.onFinish(e))}finishVisit(e){!e.cancelled&&!e.interrupted&&(e.completed=!0,e.cancelled=!1,e.interrupted=!1,I(e),e.onFinish(e))}resolvePreserveOption(e,t){return typeof e=="function"?e(t):e==="errors"?Object.keys(t.props.errors||{}).length>0:e}cancel(){this.activeVisit&&this.cancelVisit(this.activeVisit,{cancelled:!0})}visit(e,{method:t="get",data:n={},replace:o=!1,preserveScroll:l=!1,preserveState:d=!1,preserveURL:p=!1,only:h=[],headers:c={},errorBag:s="",forceFormData:y=!1,target:u=null,component:f=null,hint:m=f,onCancelToken:R=()=>{},onBefore:P=()=>{},onStart:M=()=>{},onProgress:U=()=>{},onFinish:re=()=>{},onCancel:oe=()=>{},onSuccess:G=()=>{},onError:H=()=>{},transformProps:N=()=>{},queryStringArrayFormat:k="brackets"}={}){let x=typeof e=="string"?E(e):e;if((O(n)||y)&&!(n instanceof FormData)&&(n=A(n)),!(n instanceof FormData)){let[r,a]=D(t,x,n,k);x=E(r),n=a}let L={url:x,method:t,data:n,replace:o,preserveScroll:l,preserveState:d,preserveURL:p,only:h,headers:c,errorBag:s,target:u,hint:m,component:f,forceFormData:y,transformProps:N,queryStringArrayFormat:k,noProgress:!1,cancelled:!1,completed:!1,interrupted:!1};if(P(L)===!1||!$(L))return;this.activeVisit&&this.cancelVisit(this.activeVisit,{interrupted:!0}),this.saveScrollPositions(),L.target&&(L.noProgress=!0);let j=this.createVisitId();if(this.activeVisit={...L,onCancelToken:R,onBefore:P,onStart:M,onProgress:U,onFinish:re,onCancel:oe,onSuccess:G,onError:H,queryStringArrayFormat:k,cancelToken:new AbortController},R({cancel:()=>{this.activeVisit&&this.cancelVisit(this.activeVisit,{cancelled:!0})}}),m&&Promise.resolve(this.resolveComponent(m)).then(r=>{u&&u!=="_top"&&u!=="_parent"&&u!=="main"?this.swapComponent({component:r,page:{...this.page,target:u,url:w(x).pathname},preserveState:d}):this.swapComponent({component:r,page:{...this.page,url:w(x).pathname},preserveState:d})}),X(L),f){(!u||u==="_top"||u==="_parent"||u==="main")&&(o=o||E(this.page.url).href===window.location.href,o?this.replaceState(this.page):this.pushState(this.page)),l||this.resetScrollPositions(),o||S(this.page),I(this.activeVisit);return}M(L),Y({method:t,url:w(x).href,data:t==="get"?{}:n,params:t==="get"?n:{},signal:this.activeVisit.cancelToken.signal,headers:{...c,Accept:"text/html, application/xhtml+xml","X-Requested-With":"XMLHttpRequest","X-Inertia":!0,...h.length?{"X-Inertia-Partial-Component":this.page.component,"X-Inertia-Partial-Data":h.join(",")}:{},...s&&s.length?{"X-Inertia-Error-Bag":s}:{},...this.page.version?{"X-Inertia-Version":this.page.version}:{}},onUploadProgress:r=>{n instanceof FormData&&(r.percentage=r.progress?Math.round(r.progress*100):0,K(r),U(r))}}).then(r=>{if(!this.isInertiaResponse(r))return Promise.reject({response:r});let a=r.data;r.headers["x-inertia-frame"]&&(u=r.headers["x-inertia-frame"]),h.length&&a.component===this.page.component&&(a.props={...this.page.props,...a.props}),l=this.resolvePreserveOption(l,a),d=this.resolvePreserveOption(d,a),d&&window.history.state?.rememberedState&&a.component===this.page.component&&(a.rememberedState=window.history.state.rememberedState);let g=x,V=E(a.url);return g.hash&&!V.hash&&w(g).href===V.href&&(V.hash=g.hash,a.url=V.href),N&&N(a.props),this.setPage(a,{target:u,visitId:j,replace:o,preserveScroll:l,preserveState:d,preserveURL:p})}).then(r=>{let a=r.props.errors||{};if(Object.keys(a).length>0){let g=s?a[s]?a[s]:{}:a;return q(g),H(g)}return J(r),G(r)}).catch(r=>{if(this.isInertiaResponse(r.response))return this.setPage(r.response.data,{visitId:j});if(this.isLocationVisitResponse(r.response)){let a=E(r.response.headers["x-inertia-location"]),g=x;g.hash&&!a.hash&&w(g).href===a.href&&(a.hash=g.hash),this.locationVisit(a,l===!0)}else if(r.response)_(r.response)&&Q.show(r.response.data);else return Promise.reject(r)}).then(()=>{this.activeVisit&&this.finishVisit(this.activeVisit)}).catch(r=>{if(!Y.isCancel(r)){let a=W(r);if(this.activeVisit&&this.finishVisit(this.activeVisit),a)return Promise.reject(r)}})}setPage(e,{visitId:t=this.createVisitId(),replace:n=!1,preserveURL:o=!1,preserveScroll:l=!1,preserveState:d=!1,target:p=null}={}){return Promise.resolve(this.resolveComponent(e.component)).then(h=>(t===this.visitId&&(e.scrollRegions=e.scrollRegions||[],e.rememberedState=e.rememberedState||{},o&&(e.url=window.location.href),!p||p==="_top"||p==="_parent"||p==="main"?(n=n||E(e.url).href===window.location.href,n?this.replaceState(e):this.pushState(e)):e.target=p,this.swapComponent({component:h,page:e,preserveState:d}).then(()=>{l||this.resetScrollPositions(),n||S(e)})),e))}pushState(e){this.page=e,window.history.pushState(e,"",e.url)}replaceState(e){this.page=e,window.history.replaceState(e,"",e.url)}handlePopstateEvent(e){if(e.state!==null&&e.state.component){let t=e.state,n=this.createVisitId();Promise.resolve(this.resolveComponent(t.component)).then(o=>{n===this.visitId&&(this.page=t,this.swapComponent({component:o,page:t,preserveState:!1}).then(()=>{this.restoreScrollPositions(),S(t)}))})}else{if(!this.page.url)return;let t=E(this.page.url);t.hash=window.location.hash,this.replaceState({...history.state,url:t.href}),this.resetScrollPositions()}}get(e,t={},n={}){return this.visit(e,{...n,method:"get",data:t})}reload(e={}){return this.visit(window.location.href,{preserveScroll:!0,preserveState:!0,preserveURL:!0,...e})}replace(e,t={}){return console.warn(`Inertia.replace() has been deprecated and will be removed in a future release. Please use Inertia.${t.method??"get"}() instead.`),this.visit(e,{preserveState:!0,...t,replace:!0})}post(e,t={},n={}){return this.visit(e,{preserveState:!0,...n,method:"post",data:t})}put(e,t={},n={}){return this.visit(e,{preserveState:!0,...n,method:"put",data:t})}patch(e,t={},n={}){return this.visit(e,{preserveState:!0,...n,method:"patch",data:t})}delete(e,t={}){return this.visit(e,{preserveState:!0,...t,method:"delete"})}remember(e,t="default"){Z||this.replaceState({...history.state,rememberedState:{...this.page?.rememberedState,[t]:e}})}restore(e="default"){if(!Z)return window.history.state?.rememberedState?.[e]}on(e,t){let n=o=>{let l=t(o);o.cancelable&&!o.defaultPrevented&&l===!1&&o.preventDefault()};return document.addEventListener(`inertia:${e}`,n),()=>document.removeEventListener(`inertia:${e}`,n)}};var ae={buildDOMElement(i){let e=document.createElement("template");e.innerHTML=i;let t=e.content.firstChild;if(!i.startsWith("<script "))return t;let n=document.createElement("script");return n.innerHTML=t.innerHTML,t.getAttributeNames().forEach(o=>{n.setAttribute(o,t.getAttribute(o)||"")}),n},isInertiaManagedElement(i){return i.nodeType===Node.ELEMENT_NODE&&i.getAttribute("inertia")!==null},findMatchingElementIndex(i,e){let t=i.getAttribute("inertia");return t!==null?e.findIndex(n=>n.getAttribute("inertia")===t):-1},update:T(function(i){let e=i.map(n=>this.buildDOMElement(n));Array.from(document.head.childNodes).filter(n=>this.isInertiaManagedElement(n)).forEach(n=>{let o=this.findMatchingElementIndex(n,e);if(o===-1){n?.parentNode?.removeChild(n);return}let l=e.splice(o,1)[0];l&&!n.isEqualNode(l)&&n?.parentNode?.replaceChild(l,n)}),e.forEach(n=>document.head.appendChild(n))},1)};function ee(i,e,t){let n={},o=0;function l(){let s=o+=1;return n[s]=[],s.toString()}function d(s){s===null||Object.keys(n).indexOf(s)===-1||(delete n[s],c())}function p(s,y=[]){s!==null&&Object.keys(n).indexOf(s)>-1&&(n[s]=y),c()}function h(){let s=e(""),y={...s?{title:`<title inertia="">${s}</title>`}:{}},u=Object.values(n).reduce((f,m)=>f.concat(m),[]).reduce((f,m)=>{if(m.indexOf("<")===-1)return f;if(m.indexOf("<title ")===0){let P=m.match(/(<title [^>]+>)(.*?)(<\/title>)/);return f.title=P?`${P[1]}${e(P[2])}${P[3]}`:m,f}let R=m.match(/ inertia="[^"]+"/);return R?f[R[0]]=m:f[Object.keys(f).length]=m,f},y);return Object.values(u)}function c(){i?t(h()):ae.update(h())}return c(),{forceUpdate:c,createProvider:function(){let s=l();return{update:y=>p(s,y),disconnect:()=>d(s)}}}}import v from"nprogress";var te=null;function le(i){document.addEventListener("inertia:start",ce(i)),document.addEventListener("inertia:progress",de),document.addEventListener("inertia:finish",pe)}function ce(i){return function(e){e.detail.visit.noProgress||(te=setTimeout(()=>v.start(),i))}}function de(i){v.isStarted()&&i.detail.progress?.percentage&&v.set(Math.max(v.status,i.detail.progress.percentage/100*.9))}function pe(i){if(clearTimeout(te),v.isStarted())i.detail.visit.completed?v.done():i.detail.visit.interrupted?v.set(0):i.detail.visit.cancelled&&(v.done(),v.remove());else return}function he(i){let e=document.createElement("style");e.type="text/css",e.textContent=` | ||
#nprogress { | ||
@@ -72,3 +72,3 @@ pointer-events: none; | ||
} | ||
`,document.head.appendChild(e)}function ie({delay:i=250,color:e="#29d",includeCSS:t=!0,showSpinner:r=!1}={}){le(i),v.configure({showSpinner:r}),t&&he(e)}function re(i){let e=i.currentTarget.tagName.toLowerCase()==="a";return!(i.target&&(i?.target).isContentEditable||i.defaultPrevented||e&&i.which>1||e&&i.altKey||e&&i.ctrlKey||e&&i.metaKey||e&&i.shiftKey)}var Ae=new F;export{ee as createHeadManager,E as hrefToUrl,D as mergeDataIntoQueryString,Ae as router,ie as setupProgress,re as shouldIntercept,w as urlWithoutHash}; | ||
`,document.head.appendChild(e)}function ie({delay:i=250,color:e="#29d",includeCSS:t=!0,showSpinner:n=!1}={}){le(i),v.configure({showSpinner:n}),t&&he(e)}function ne(i){let e=i.currentTarget.tagName.toLowerCase()==="a";return!(i.target&&(i?.target).isContentEditable||i.defaultPrevented||e&&i.which>1||e&&i.altKey||e&&i.ctrlKey||e&&i.metaKey||e&&i.shiftKey)}var Ae=new F;export{ee as createHeadManager,E as hrefToUrl,D as mergeDataIntoQueryString,Ae as router,ie as setupProgress,ne as shouldIntercept,w as urlWithoutHash}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";var de=Object.create;var I=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,fe=Object.prototype.hasOwnProperty;var me=(t,e)=>{for(var i in e)I(t,i,{get:e[i],enumerable:!0})},J=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of he(e))!fe.call(t,n)&&n!==i&&I(t,n,{get:()=>e[n],enumerable:!(r=pe(e,n))||r.enumerable});return t};var O=(t,e,i)=>(i=t!=null?de(ue(t)):{},J(e||!t||!t.__esModule?I(i,"default",{value:t,enumerable:!0}):i,t)),ge=t=>J(I({},"__esModule",{value:!0}),t);var Pe={};me(Pe,{createHeadManager:()=>H,hrefToUrl:()=>b,mergeDataIntoQueryString:()=>k,router:()=>Se,setupProgress:()=>j,shouldIntercept:()=>$,urlWithoutHash:()=>E});module.exports=ge(Pe);var G=O(require("axios"),1);function T(t,e){let i;return function(...r){clearTimeout(i),i=setTimeout(()=>t.apply(this,r),e)}}function w(t,e){return document.dispatchEvent(new CustomEvent(`inertia:${t}`,e))}var z=t=>w("before",{cancelable:!0,detail:{visit:t}}),B=t=>w("error",{detail:{errors:t}}),Q=t=>w("exception",{cancelable:!0,detail:{exception:t}}),C=t=>w("finish",{detail:{visit:t}}),Y=t=>w("invalid",{cancelable:!0,detail:{response:t}}),S=t=>w("navigate",{detail:{page:t}}),Z=t=>w("progress",{detail:{progress:t}}),ee=t=>w("start",{detail:{visit:t}}),te=t=>w("success",{detail:{page:t}});function F(t){return t instanceof File||t instanceof Blob||t instanceof FileList&&t.length>0||t instanceof FormData&&Array.from(t.values()).some(e=>F(e))||typeof t=="object"&&t!==null&&Object.values(t).some(e=>F(e))}function U(t,e=new FormData,i=null){t=t||{};for(let r in t)Object.prototype.hasOwnProperty.call(t,r)&&re(e,ie(i,r),t[r]);return e}function ie(t,e){return t?t+"["+e+"]":e}function re(t,e,i){if(Array.isArray(i))return Array.from(i.keys()).forEach(r=>re(t,ie(e,r.toString()),i[r]));if(i instanceof Date)return t.append(e,i.toISOString());if(i instanceof File)return t.append(e,i,i.name);if(i instanceof Blob)return t.append(e,i);if(typeof i=="boolean")return t.append(e,i?"1":"0");if(typeof i=="string")return t.append(e,i);if(typeof i=="number")return t.append(e,`${i}`);if(i==null)return t.append(e,"");U(i,t,e)}var ne={modal:null,listener:null,show(t){typeof t=="object"&&(t=`All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(t)}`);let e=document.createElement("html");e.innerHTML=t,e.querySelectorAll("a").forEach(r=>r.setAttribute("target","_top")),this.modal=document.createElement("div"),this.modal.style.position="fixed",this.modal.style.width="100vw",this.modal.style.height="100vh",this.modal.style.padding="50px",this.modal.style.boxSizing="border-box",this.modal.style.backgroundColor="rgba(0, 0, 0, .6)",this.modal.style.zIndex=2e5,this.modal.addEventListener("click",()=>this.hide());let i=document.createElement("iframe");if(i.style.backgroundColor="white",i.style.borderRadius="5px",i.style.width="100%",i.style.height="100%",this.modal.appendChild(i),document.body.prepend(this.modal),document.body.style.overflow="hidden",!i.contentWindow)throw new Error("iframe not yet ready.");i.contentWindow.document.open(),i.contentWindow.document.write(e.outerHTML),i.contentWindow.document.close(),this.listener=this.hideOnEscape.bind(this),document.addEventListener("keydown",this.listener)},hide(){this.modal.outerHTML="",this.modal=null,document.body.style.overflow="visible",document.removeEventListener("keydown",this.listener)},hideOnEscape(t){t.keyCode===27&&this.hide()}};var oe=O(require("deepmerge"),1),N=O(require("qs"),1);function b(t){return new URL(t.toString(),window.location.toString())}function k(t,e,i,r="brackets"){let n=/^https?:\/\//.test(e.toString()),l=n||e.toString().startsWith("/"),d=!l&&!e.toString().startsWith("#")&&!e.toString().startsWith("?"),p=e.toString().includes("?")||t==="get"&&Object.keys(i).length,h=e.toString().includes("#"),c=new URL(e.toString(),"http://localhost");return t==="get"&&Object.keys(i).length&&(c.search=N.stringify((0,oe.default)(N.parse(c.search,{ignoreQueryPrefix:!0}),i),{encodeValuesOnly:!0,arrayFormat:r}),i={}),[[n?`${c.protocol}//${c.host}`:"",l?c.pathname:"",d?c.pathname.substring(1):"",p?c.search:"",h?c.hash:""].join(""),i]}function E(t){return t=new URL(t.href),t.hash="",t}var se=typeof window>"u",A=class{constructor(){this.visitId=null}init({initialPage:e,resolveComponent:i,swapComponent:r}){this.page=e,this.resolveComponent=i,this.swapComponent=r,this.setNavigationType(),this.clearRememberedStateOnReload(),this.isBackForwardVisit()?this.handleBackForwardVisit(this.page):this.isLocationVisit()?this.handleLocationVisit(this.page):this.handleInitialPageVisit(this.page),this.setupEventListeners()}setNavigationType(){this.navigationType=window.performance&&window.performance.getEntriesByType("navigation").length>0?window.performance.getEntriesByType("navigation")[0].type:"navigate"}clearRememberedStateOnReload(){this.navigationType==="reload"&&window.history.state?.rememberedState&&delete window.history.state.rememberedState}handleInitialPageVisit(e){this.page.url+=window.location.hash,this.setPage(e,{preserveScroll:!0,preserveState:!0}).then(()=>S(e))}setupEventListeners(){window.addEventListener("popstate",this.handlePopstateEvent.bind(this)),document.addEventListener("scroll",T(this.handleScrollEvent.bind(this),100),!0),document.addEventListener("click",e=>{let i=e.target;if(e.defaultPrevented||i.closest("[data-inertia-ignore]"))return;let r=i.closest("a"),n=i.closest("[data-inertia-frame-id]")?.dataset.inertiaFrameId,l=i.closest("[data-hint]")?.dataset.hint,d=i.closest("[data-component]")?.dataset.component;if(!(!r||r.rel=="external"||r.target=="_blank")&&r.href&&r.href.startsWith(location.origin)){let p=r.attributes.getNamedItem("href")?.value,h=r.dataset["preserve-scroll"],c=r.dataset["preserve-state"];if(e.preventDefault(),e.stopPropagation(),p?.startsWith("#")){let s=this.page;s.url=r.href,this.setPage(s,{preserveScroll:h,preserveState:c}).then(()=>{S(s)})}else this.visit(r.href,{method:r.dataset.method,target:r.dataset.target||n,hint:l,component:d,preserveScroll:h,preserveState:c})}})}scrollRegions(){return document.querySelectorAll("[scroll-region]")}handleScrollEvent(e){typeof e.target.hasAttribute=="function"&&e.target.hasAttribute("scroll-region")&&this.saveScrollPositions()}saveScrollPositions(){this.replaceState({...history.state,scrollRegions:Array.from(this.scrollRegions()).map(e=>({top:e.scrollTop,left:e.scrollLeft}))})}resetScrollPositions(){window.scrollTo(0,0),this.scrollRegions().forEach(e=>{typeof e.scrollTo=="function"?e.scrollTo(0,0):(e.scrollTop=0,e.scrollLeft=0)}),this.saveScrollPositions(),window.location.hash&&setTimeout(()=>document.getElementById(window.location.hash.slice(1))?.scrollIntoView())}restoreScrollPositions(){this.page.scrollRegions&&this.scrollRegions().forEach((e,i)=>{let r=this.page.scrollRegions[i];if(r)typeof e.scrollTo=="function"?e.scrollTo(r.left,r.top):(e.scrollTop=r.top,e.scrollLeft=r.left);else return})}isBackForwardVisit(){return window.history.state&&this.navigationType==="back_forward"}handleBackForwardVisit(e){let i;e.props?i=e:(window.history.state.version=e.version,i=window.history.state),this.setPage(i,{preserveScroll:!0,preserveState:!0}).then(()=>{this.restoreScrollPositions(),S(e)})}locationVisit(e,i){try{let r={preserveScroll:i};window.sessionStorage.setItem("inertiaLocationVisit",JSON.stringify(r)),window.location.href=e.href,E(window.location).href===E(e).href&&window.location.reload()}catch{return!1}}isLocationVisit(){try{return window.sessionStorage.getItem("inertiaLocationVisit")!==null}catch{return!1}}handleLocationVisit(e){let i=JSON.parse(window.sessionStorage.getItem("inertiaLocationVisit")||"");window.sessionStorage.removeItem("inertiaLocationVisit"),e.url+=window.location.hash,e.rememberedState=window.history.state?.rememberedState??{},e.scrollRegions=window.history.state?.scrollRegions??[],this.setPage(e,{preserveScroll:i.preserveScroll,preserveState:!0}).then(()=>{i.preserveScroll&&this.restoreScrollPositions(),S(e)})}isLocationVisitResponse(e){return!!(e&&e.status===409&&e.headers["x-inertia-location"])}isInertiaResponse(e){return!!e?.headers["x-inertia"]}createVisitId(){return this.visitId={},this.visitId}cancelVisit(e,{cancelled:i=!1,interrupted:r=!1}){e&&!e.completed&&!e.cancelled&&!e.interrupted&&(e.cancelToken.abort(),e.onCancel(),e.completed=!1,e.cancelled=i,e.interrupted=r,C(e),e.onFinish(e))}finishVisit(e){!e.cancelled&&!e.interrupted&&(e.completed=!0,e.cancelled=!1,e.interrupted=!1,C(e),e.onFinish(e))}resolvePreserveOption(e,i){return typeof e=="function"?e(i):e==="errors"?Object.keys(i.props.errors||{}).length>0:e}cancel(){this.activeVisit&&this.cancelVisit(this.activeVisit,{cancelled:!0})}visit(e,{method:i="get",data:r={},replace:n=!1,preserveScroll:l=!1,preserveState:d=!1,preserveURL:p=!1,only:h=[],headers:c={},errorBag:s="",forceFormData:y=!1,target:u=null,component:f=null,hint:m=f,onCancelToken:R=()=>{},onBefore:P=()=>{},onStart:q=()=>{},onProgress:W=()=>{},onFinish:le=()=>{},onCancel:ce=()=>{},onSuccess:_=()=>{},onError:K=()=>{},transformProps:D=()=>{},queryStringArrayFormat:M="brackets"}={}){let x=typeof e=="string"?b(e):e;if((F(r)||y)&&!(r instanceof FormData)&&(r=U(r)),!(r instanceof FormData)){let[o,a]=k(i,x,r,M);x=b(o),r=a}let L={url:x,method:i,data:r,replace:n,preserveScroll:l,preserveState:d,preserveURL:p,only:h,headers:c,errorBag:s,target:u,hint:m,component:f,forceFormData:y,transformProps:D,queryStringArrayFormat:M,noProgress:!1,cancelled:!1,completed:!1,interrupted:!1};if(P(L)===!1||!z(L))return;this.activeVisit&&this.cancelVisit(this.activeVisit,{interrupted:!0}),this.saveScrollPositions(),L.target&&(L.noProgress=!0);let X=this.createVisitId();if(this.activeVisit={...L,onCancelToken:R,onBefore:P,onStart:q,onProgress:W,onFinish:le,onCancel:ce,onSuccess:_,onError:K,queryStringArrayFormat:M,cancelToken:new AbortController},R({cancel:()=>{this.activeVisit&&this.cancelVisit(this.activeVisit,{cancelled:!0})}}),m&&Promise.resolve(this.resolveComponent(m)).then(o=>{u&&u!=="_top"&&u!=="_parent"&&u!=="main"?this.swapComponent({component:o,page:{...this.page,target:u,url:E(x).pathname},preserveState:d}):this.swapComponent({component:o,page:{...this.page,url:E(x).pathname},preserveState:d})}),ee(L),f){(!u||u==="_top"||u==="_parent"||u==="main")&&(n=n||b(this.page.url).href===window.location.href,n?this.replaceState(this.page):this.pushState(this.page)),l||this.resetScrollPositions(),n||S(this.page),C(this.activeVisit);return}q(L),(0,G.default)({method:i,url:E(x).href,data:i==="get"?{}:r,params:i==="get"?r:{},signal:this.activeVisit.cancelToken.signal,headers:{...c,Accept:"text/html, application/xhtml+xml","X-Requested-With":"XMLHttpRequest","X-Inertia":!0,...h.length?{"X-Inertia-Partial-Component":this.page.component,"X-Inertia-Partial-Data":h.join(",")}:{},...s&&s.length?{"X-Inertia-Error-Bag":s}:{},...this.page.version?{"X-Inertia-Version":this.page.version}:{}},onUploadProgress:o=>{r instanceof FormData&&(o.percentage=o.progress?Math.round(o.progress*100):0,Z(o),W(o))}}).then(o=>{if(!this.isInertiaResponse(o))return Promise.reject({response:o});let a=o.data;o.headers["x-inertia-frame"]&&(u=o.headers["x-inertia-frame"]),h.length&&a.component===this.page.component&&(a.props={...this.page.props,...a.props}),l=this.resolvePreserveOption(l,a),d=this.resolvePreserveOption(d,a),d&&window.history.state?.rememberedState&&a.component===this.page.component&&(a.rememberedState=window.history.state.rememberedState);let v=x,V=b(a.url);return v.hash&&!V.hash&&E(v).href===V.href&&(V.hash=v.hash,a.url=V.href),D&&D(a.props),this.setPage(a,{target:u,visitId:X,replace:n,preserveScroll:l,preserveState:d,preserveURL:p})}).then(o=>{let a=o.props.errors||{};if(Object.keys(a).length>0){let v=s?a[s]?a[s]:{}:a;return B(v),K(v)}return te(o),_(o)}).catch(o=>{if(this.isInertiaResponse(o.response))return this.setPage(o.response.data,{visitId:X});if(this.isLocationVisitResponse(o.response)){let a=b(o.response.headers["x-inertia-location"]),v=x;v.hash&&!a.hash&&E(v).href===a.href&&(a.hash=v.hash),this.locationVisit(a,l===!0)}else if(o.response)Y(o.response)&&ne.show(o.response.data);else return Promise.reject(o)}).then(()=>{this.activeVisit&&this.finishVisit(this.activeVisit)}).catch(o=>{if(!G.default.isCancel(o)){let a=Q(o);if(this.activeVisit&&this.finishVisit(this.activeVisit),a)return Promise.reject(o)}})}setPage(e,{visitId:i=this.createVisitId(),replace:r=!1,preserveURL:n=!1,preserveScroll:l=!1,preserveState:d=!1,target:p=null}={}){return Promise.resolve(this.resolveComponent(e.component)).then(h=>(i===this.visitId&&(e.scrollRegions=e.scrollRegions||[],e.rememberedState=e.rememberedState||{},n&&(e.url=window.location.href),!p||p==="_top"||p==="_parent"||p==="main"?(r=r||b(e.url).href===window.location.href,r?this.replaceState(e):this.pushState(e)):e.target=p,this.swapComponent({component:h,page:e,preserveState:d}).then(()=>{l||this.resetScrollPositions(),r||S(e)})),e))}pushState(e){this.page=e,window.history.pushState(e,"",e.url)}replaceState(e){this.page=e,window.history.replaceState(e,"",e.url)}handlePopstateEvent(e){if(e.state!==null&&e.state.component){let i=e.state,r=this.createVisitId();Promise.resolve(this.resolveComponent(i.component)).then(n=>{r===this.visitId&&(this.page=i,this.swapComponent({component:n,page:i,preserveState:!1}).then(()=>{this.restoreScrollPositions(),S(i)}))})}else{if(!this.page.url)return;let i=b(this.page.url);i.hash=window.location.hash,this.replaceState({...history.state,url:i.href}),this.resetScrollPositions()}}get(e,i={},r={}){return this.visit(e,{...r,method:"get",data:i})}reload(e={}){return this.visit(window.location.href,{preserveScroll:!0,preserveState:!0,preserveURL:!0,...e})}replace(e,i={}){return console.warn(`Inertia.replace() has been deprecated and will be removed in a future release. Please use Inertia.${i.method??"get"}() instead.`),this.visit(e,{preserveState:!0,...i,replace:!0})}post(e,i={},r={}){return this.visit(e,{preserveState:!0,...r,method:"post",data:i})}put(e,i={},r={}){return this.visit(e,{preserveState:!0,...r,method:"put",data:i})}patch(e,i={},r={}){return this.visit(e,{preserveState:!0,...r,method:"patch",data:i})}delete(e,i={}){return this.visit(e,{preserveState:!0,...i,method:"delete"})}remember(e,i="default"){se||this.replaceState({...history.state,rememberedState:{...this.page?.rememberedState,[i]:e}})}restore(e="default"){if(!se)return window.history.state?.rememberedState?.[e]}on(e,i){let r=n=>{let l=i(n);n.cancelable&&!n.defaultPrevented&&l===!1&&n.preventDefault()};return document.addEventListener(`inertia:${e}`,r),()=>document.removeEventListener(`inertia:${e}`,r)}};var ve={buildDOMElement(t){let e=document.createElement("template");e.innerHTML=t;let i=e.content.firstChild;if(!t.startsWith("<script "))return i;let r=document.createElement("script");return r.innerHTML=i.innerHTML,i.getAttributeNames().forEach(n=>{r.setAttribute(n,i.getAttribute(n)||"")}),r},isInertiaManagedElement(t){return t.nodeType===Node.ELEMENT_NODE&&t.getAttribute("inertia")!==null},findMatchingElementIndex(t,e){let i=t.getAttribute("inertia");return i!==null?e.findIndex(r=>r.getAttribute("inertia")===i):-1},update:T(function(t){let e=t.map(r=>this.buildDOMElement(r));Array.from(document.head.childNodes).filter(r=>this.isInertiaManagedElement(r)).forEach(r=>{let n=this.findMatchingElementIndex(r,e);if(n===-1){r?.parentNode?.removeChild(r);return}let l=e.splice(n,1)[0];l&&!r.isEqualNode(l)&&r?.parentNode?.replaceChild(l,r)}),e.forEach(r=>document.head.appendChild(r))},1)};function H(t,e,i){let r={},n=0;function l(){let s=n+=1;return r[s]=[],s.toString()}function d(s){s===null||Object.keys(r).indexOf(s)===-1||(delete r[s],c())}function p(s,y=[]){s!==null&&Object.keys(r).indexOf(s)>-1&&(r[s]=y),c()}function h(){let s=e(""),y={...s?{title:`<title inertia="">${s}</title>`}:{}},u=Object.values(r).reduce((f,m)=>f.concat(m),[]).reduce((f,m)=>{if(m.indexOf("<")===-1)return f;if(m.indexOf("<title ")===0){let P=m.match(/(<title [^>]+>)(.*?)(<\/title>)/);return f.title=P?`${P[1]}${e(P[2])}${P[3]}`:m,f}let R=m.match(/ inertia="[^"]+"/);return R?f[R[0]]=m:f[Object.keys(f).length]=m,f},y);return Object.values(u)}function c(){t?i(h()):ve.update(h())}return c(),{forceUpdate:c,createProvider:function(){let s=l();return{update:y=>p(s,y),disconnect:()=>d(s)}}}}var g=O(require("nprogress"),1),ae=null;function be(t){document.addEventListener("inertia:start",Ee(t)),document.addEventListener("inertia:progress",we),document.addEventListener("inertia:finish",ye)}function Ee(t){return function(e){e.detail.visit.noProgress||(ae=setTimeout(()=>g.default.start(),t))}}function we(t){g.default.isStarted()&&t.detail.progress?.percentage&&g.default.set(Math.max(g.default.status,t.detail.progress.percentage/100*.9))}function ye(t){if(clearTimeout(ae),g.default.isStarted())t.detail.visit.completed?g.default.done():t.detail.visit.interrupted?g.default.set(0):t.detail.visit.cancelled&&(g.default.done(),g.default.remove());else return}function xe(t){let e=document.createElement("style");e.type="text/css",e.textContent=` | ||
"use strict";var de=Object.create;var I=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,fe=Object.prototype.hasOwnProperty;var me=(t,e)=>{for(var i in e)I(t,i,{get:e[i],enumerable:!0})},J=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of he(e))!fe.call(t,r)&&r!==i&&I(t,r,{get:()=>e[r],enumerable:!(n=pe(e,r))||n.enumerable});return t};var O=(t,e,i)=>(i=t!=null?de(ue(t)):{},J(e||!t||!t.__esModule?I(i,"default",{value:t,enumerable:!0}):i,t)),ge=t=>J(I({},"__esModule",{value:!0}),t);var Pe={};me(Pe,{createHeadManager:()=>H,hrefToUrl:()=>b,mergeDataIntoQueryString:()=>k,router:()=>Se,setupProgress:()=>j,shouldIntercept:()=>$,urlWithoutHash:()=>E});module.exports=ge(Pe);var G=O(require("axios"),1);function T(t,e){let i;return function(...n){clearTimeout(i),i=setTimeout(()=>t.apply(this,n),e)}}function w(t,e){return document.dispatchEvent(new CustomEvent(`inertia:${t}`,e))}var z=t=>w("before",{cancelable:!0,detail:{visit:t}}),B=t=>w("error",{detail:{errors:t}}),Q=t=>w("exception",{cancelable:!0,detail:{exception:t}}),C=t=>w("finish",{detail:{visit:t}}),Y=t=>w("invalid",{cancelable:!0,detail:{response:t}}),S=t=>w("navigate",{detail:{page:t}}),Z=t=>w("progress",{detail:{progress:t}}),ee=t=>w("start",{detail:{visit:t}}),te=t=>w("success",{detail:{page:t}});function F(t){return t instanceof File||t instanceof Blob||t instanceof FileList&&t.length>0||t instanceof FormData&&Array.from(t.values()).some(e=>F(e))||typeof t=="object"&&t!==null&&Object.values(t).some(e=>F(e))}function U(t,e=new FormData,i=null){t=t||{};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&ne(e,ie(i,n),t[n]);return e}function ie(t,e){return t?t+"["+e+"]":e}function ne(t,e,i){if(Array.isArray(i))return Array.from(i.keys()).forEach(n=>ne(t,ie(e,n.toString()),i[n]));if(i instanceof Date)return t.append(e,i.toISOString());if(i instanceof File)return t.append(e,i,i.name);if(i instanceof Blob)return t.append(e,i);if(typeof i=="boolean")return t.append(e,i?"1":"0");if(typeof i=="string")return t.append(e,i);if(typeof i=="number")return t.append(e,`${i}`);if(i==null)return t.append(e,"");U(i,t,e)}var re={modal:null,listener:null,show(t){typeof t=="object"&&(t=`All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(t)}`);let e=document.createElement("html");e.innerHTML=t,e.querySelectorAll("a").forEach(n=>n.setAttribute("target","_top")),this.modal=document.createElement("div"),this.modal.style.position="fixed",this.modal.style.width="100vw",this.modal.style.height="100vh",this.modal.style.padding="50px",this.modal.style.boxSizing="border-box",this.modal.style.backgroundColor="rgba(0, 0, 0, .6)",this.modal.style.zIndex=2e5,this.modal.addEventListener("click",()=>this.hide());let i=document.createElement("iframe");if(i.style.backgroundColor="white",i.style.borderRadius="5px",i.style.width="100%",i.style.height="100%",this.modal.appendChild(i),document.body.prepend(this.modal),document.body.style.overflow="hidden",!i.contentWindow)throw new Error("iframe not yet ready.");i.contentWindow.document.open(),i.contentWindow.document.write(e.outerHTML),i.contentWindow.document.close(),this.listener=this.hideOnEscape.bind(this),document.addEventListener("keydown",this.listener)},hide(){this.modal.outerHTML="",this.modal=null,document.body.style.overflow="visible",document.removeEventListener("keydown",this.listener)},hideOnEscape(t){t.keyCode===27&&this.hide()}};var oe=O(require("deepmerge"),1),N=O(require("qs"),1);function b(t){return new URL(t.toString(),window.location.toString())}function k(t,e,i,n="brackets"){let r=/^https?:\/\//.test(e.toString()),l=r||e.toString().startsWith("/"),d=!l&&!e.toString().startsWith("#")&&!e.toString().startsWith("?"),p=e.toString().includes("?")||t==="get"&&Object.keys(i).length,h=e.toString().includes("#"),c=new URL(e.toString(),"http://localhost");return t==="get"&&Object.keys(i).length&&(c.search=N.stringify((0,oe.default)(N.parse(c.search,{ignoreQueryPrefix:!0}),i),{encodeValuesOnly:!0,arrayFormat:n}),i={}),[[r?`${c.protocol}//${c.host}`:"",l?c.pathname:"",d?c.pathname.substring(1):"",p?c.search:"",h?c.hash:""].join(""),i]}function E(t){return t=new URL(t.href),t.hash="",t}var se=typeof window>"u",A=class{constructor(){this.visitId=null}init({initialPage:e,resolveComponent:i,swapComponent:n}){this.page=e,this.resolveComponent=i,this.swapComponent=n,this.setNavigationType(),this.clearRememberedStateOnReload(),this.isBackForwardVisit()?this.handleBackForwardVisit(this.page):this.isLocationVisit()?this.handleLocationVisit(this.page):this.handleInitialPageVisit(this.page),this.setupEventListeners()}setNavigationType(){this.navigationType=window.performance&&window.performance.getEntriesByType("navigation").length>0?window.performance.getEntriesByType("navigation")[0].type:"navigate"}clearRememberedStateOnReload(){this.navigationType==="reload"&&window.history.state?.rememberedState&&delete window.history.state.rememberedState}handleInitialPageVisit(e){this.page.url+=window.location.hash,this.setPage(e,{preserveScroll:!0,preserveState:!0}).then(()=>S(e))}setupEventListeners(){window.addEventListener("popstate",this.handlePopstateEvent.bind(this)),document.addEventListener("scroll",T(this.handleScrollEvent.bind(this),100),!0),document.addEventListener("click",e=>{let i=e.target;if(e.defaultPrevented||i.closest("[data-inertia-ignore]"))return;let n=i.closest("a"),r=i.closest("[data-inertia-frame-id]")?.dataset.inertiaFrameId,l=i.closest("[data-hint]")?.dataset.hint,d=i.closest("[data-component]")?.dataset.component;if(!(!n||n.rel=="external"||n.target=="_blank")&&n.href&&n.href.startsWith(location.origin)){let p=n.attributes.getNamedItem("href")?.value,h=n.dataset["preserve-scroll"],c=n.dataset["preserve-state"];if(e.preventDefault(),e.stopPropagation(),p?.startsWith("#")){let s=this.page;s.url=n.href,this.setPage(s,{preserveScroll:h,preserveState:c}).then(()=>{S(s)})}else this.visit(n.href,{method:n.dataset.method,target:n.dataset.target||r,hint:l,component:d,preserveScroll:h,preserveState:c})}})}scrollRegions(){return document.querySelectorAll("[scroll-region]")}handleScrollEvent(e){typeof e.target.hasAttribute=="function"&&e.target.hasAttribute("scroll-region")&&this.saveScrollPositions()}saveScrollPositions(){let e=Array.from(this.scrollRegions()).map(i=>({top:i.scrollTop,left:i.scrollLeft}));this.replaceState({...history.state,scrollRegions:e})}resetScrollPositions(){window.scrollTo(0,0),this.scrollRegions().forEach(e=>{typeof e.scrollTo=="function"?e.scrollTo(0,0):(e.scrollTop=0,e.scrollLeft=0)}),this.saveScrollPositions(),window.location.hash&&setTimeout(()=>document.getElementById(window.location.hash.slice(1))?.scrollIntoView())}restoreScrollPositions(){this.page.scrollRegions&&this.scrollRegions().forEach((e,i)=>{let n=this.page.scrollRegions[i];if(n)typeof e.scrollTo=="function"?e.scrollTo(n.left,n.top):(e.scrollTop=n.top,e.scrollLeft=n.left);else return})}isBackForwardVisit(){return window.history.state&&this.navigationType==="back_forward"}handleBackForwardVisit(e){let i;e.props?i=e:(window.history.state.version=e.version,i=window.history.state),this.setPage(i,{preserveScroll:!0,preserveState:!0}).then(()=>{this.restoreScrollPositions(),S(e)})}locationVisit(e,i){try{let n={preserveScroll:i};window.sessionStorage.setItem("inertiaLocationVisit",JSON.stringify(n)),window.location.href=e.href,E(window.location).href===E(e).href&&window.location.reload()}catch{return!1}}isLocationVisit(){try{return window.sessionStorage.getItem("inertiaLocationVisit")!==null}catch{return!1}}handleLocationVisit(e){let i=JSON.parse(window.sessionStorage.getItem("inertiaLocationVisit")||"");window.sessionStorage.removeItem("inertiaLocationVisit"),e.url+=window.location.hash,e.rememberedState=window.history.state?.rememberedState??{},e.scrollRegions=window.history.state?.scrollRegions??[],this.setPage(e,{preserveScroll:i.preserveScroll,preserveState:!0}).then(()=>{i.preserveScroll&&this.restoreScrollPositions(),S(e)})}isLocationVisitResponse(e){return!!(e&&e.status===409&&e.headers["x-inertia-location"])}isInertiaResponse(e){return!!e?.headers["x-inertia"]}createVisitId(){return this.visitId={},this.visitId}cancelVisit(e,{cancelled:i=!1,interrupted:n=!1}){e&&!e.completed&&!e.cancelled&&!e.interrupted&&(e.cancelToken.abort(),e.onCancel(),e.completed=!1,e.cancelled=i,e.interrupted=n,C(e),e.onFinish(e))}finishVisit(e){!e.cancelled&&!e.interrupted&&(e.completed=!0,e.cancelled=!1,e.interrupted=!1,C(e),e.onFinish(e))}resolvePreserveOption(e,i){return typeof e=="function"?e(i):e==="errors"?Object.keys(i.props.errors||{}).length>0:e}cancel(){this.activeVisit&&this.cancelVisit(this.activeVisit,{cancelled:!0})}visit(e,{method:i="get",data:n={},replace:r=!1,preserveScroll:l=!1,preserveState:d=!1,preserveURL:p=!1,only:h=[],headers:c={},errorBag:s="",forceFormData:y=!1,target:u=null,component:f=null,hint:m=f,onCancelToken:R=()=>{},onBefore:P=()=>{},onStart:q=()=>{},onProgress:W=()=>{},onFinish:le=()=>{},onCancel:ce=()=>{},onSuccess:_=()=>{},onError:K=()=>{},transformProps:D=()=>{},queryStringArrayFormat:M="brackets"}={}){let x=typeof e=="string"?b(e):e;if((F(n)||y)&&!(n instanceof FormData)&&(n=U(n)),!(n instanceof FormData)){let[o,a]=k(i,x,n,M);x=b(o),n=a}let L={url:x,method:i,data:n,replace:r,preserveScroll:l,preserveState:d,preserveURL:p,only:h,headers:c,errorBag:s,target:u,hint:m,component:f,forceFormData:y,transformProps:D,queryStringArrayFormat:M,noProgress:!1,cancelled:!1,completed:!1,interrupted:!1};if(P(L)===!1||!z(L))return;this.activeVisit&&this.cancelVisit(this.activeVisit,{interrupted:!0}),this.saveScrollPositions(),L.target&&(L.noProgress=!0);let X=this.createVisitId();if(this.activeVisit={...L,onCancelToken:R,onBefore:P,onStart:q,onProgress:W,onFinish:le,onCancel:ce,onSuccess:_,onError:K,queryStringArrayFormat:M,cancelToken:new AbortController},R({cancel:()=>{this.activeVisit&&this.cancelVisit(this.activeVisit,{cancelled:!0})}}),m&&Promise.resolve(this.resolveComponent(m)).then(o=>{u&&u!=="_top"&&u!=="_parent"&&u!=="main"?this.swapComponent({component:o,page:{...this.page,target:u,url:E(x).pathname},preserveState:d}):this.swapComponent({component:o,page:{...this.page,url:E(x).pathname},preserveState:d})}),ee(L),f){(!u||u==="_top"||u==="_parent"||u==="main")&&(r=r||b(this.page.url).href===window.location.href,r?this.replaceState(this.page):this.pushState(this.page)),l||this.resetScrollPositions(),r||S(this.page),C(this.activeVisit);return}q(L),(0,G.default)({method:i,url:E(x).href,data:i==="get"?{}:n,params:i==="get"?n:{},signal:this.activeVisit.cancelToken.signal,headers:{...c,Accept:"text/html, application/xhtml+xml","X-Requested-With":"XMLHttpRequest","X-Inertia":!0,...h.length?{"X-Inertia-Partial-Component":this.page.component,"X-Inertia-Partial-Data":h.join(",")}:{},...s&&s.length?{"X-Inertia-Error-Bag":s}:{},...this.page.version?{"X-Inertia-Version":this.page.version}:{}},onUploadProgress:o=>{n instanceof FormData&&(o.percentage=o.progress?Math.round(o.progress*100):0,Z(o),W(o))}}).then(o=>{if(!this.isInertiaResponse(o))return Promise.reject({response:o});let a=o.data;o.headers["x-inertia-frame"]&&(u=o.headers["x-inertia-frame"]),h.length&&a.component===this.page.component&&(a.props={...this.page.props,...a.props}),l=this.resolvePreserveOption(l,a),d=this.resolvePreserveOption(d,a),d&&window.history.state?.rememberedState&&a.component===this.page.component&&(a.rememberedState=window.history.state.rememberedState);let v=x,V=b(a.url);return v.hash&&!V.hash&&E(v).href===V.href&&(V.hash=v.hash,a.url=V.href),D&&D(a.props),this.setPage(a,{target:u,visitId:X,replace:r,preserveScroll:l,preserveState:d,preserveURL:p})}).then(o=>{let a=o.props.errors||{};if(Object.keys(a).length>0){let v=s?a[s]?a[s]:{}:a;return B(v),K(v)}return te(o),_(o)}).catch(o=>{if(this.isInertiaResponse(o.response))return this.setPage(o.response.data,{visitId:X});if(this.isLocationVisitResponse(o.response)){let a=b(o.response.headers["x-inertia-location"]),v=x;v.hash&&!a.hash&&E(v).href===a.href&&(a.hash=v.hash),this.locationVisit(a,l===!0)}else if(o.response)Y(o.response)&&re.show(o.response.data);else return Promise.reject(o)}).then(()=>{this.activeVisit&&this.finishVisit(this.activeVisit)}).catch(o=>{if(!G.default.isCancel(o)){let a=Q(o);if(this.activeVisit&&this.finishVisit(this.activeVisit),a)return Promise.reject(o)}})}setPage(e,{visitId:i=this.createVisitId(),replace:n=!1,preserveURL:r=!1,preserveScroll:l=!1,preserveState:d=!1,target:p=null}={}){return Promise.resolve(this.resolveComponent(e.component)).then(h=>(i===this.visitId&&(e.scrollRegions=e.scrollRegions||[],e.rememberedState=e.rememberedState||{},r&&(e.url=window.location.href),!p||p==="_top"||p==="_parent"||p==="main"?(n=n||b(e.url).href===window.location.href,n?this.replaceState(e):this.pushState(e)):e.target=p,this.swapComponent({component:h,page:e,preserveState:d}).then(()=>{l||this.resetScrollPositions(),n||S(e)})),e))}pushState(e){this.page=e,window.history.pushState(e,"",e.url)}replaceState(e){this.page=e,window.history.replaceState(e,"",e.url)}handlePopstateEvent(e){if(e.state!==null&&e.state.component){let i=e.state,n=this.createVisitId();Promise.resolve(this.resolveComponent(i.component)).then(r=>{n===this.visitId&&(this.page=i,this.swapComponent({component:r,page:i,preserveState:!1}).then(()=>{this.restoreScrollPositions(),S(i)}))})}else{if(!this.page.url)return;let i=b(this.page.url);i.hash=window.location.hash,this.replaceState({...history.state,url:i.href}),this.resetScrollPositions()}}get(e,i={},n={}){return this.visit(e,{...n,method:"get",data:i})}reload(e={}){return this.visit(window.location.href,{preserveScroll:!0,preserveState:!0,preserveURL:!0,...e})}replace(e,i={}){return console.warn(`Inertia.replace() has been deprecated and will be removed in a future release. Please use Inertia.${i.method??"get"}() instead.`),this.visit(e,{preserveState:!0,...i,replace:!0})}post(e,i={},n={}){return this.visit(e,{preserveState:!0,...n,method:"post",data:i})}put(e,i={},n={}){return this.visit(e,{preserveState:!0,...n,method:"put",data:i})}patch(e,i={},n={}){return this.visit(e,{preserveState:!0,...n,method:"patch",data:i})}delete(e,i={}){return this.visit(e,{preserveState:!0,...i,method:"delete"})}remember(e,i="default"){se||this.replaceState({...history.state,rememberedState:{...this.page?.rememberedState,[i]:e}})}restore(e="default"){if(!se)return window.history.state?.rememberedState?.[e]}on(e,i){let n=r=>{let l=i(r);r.cancelable&&!r.defaultPrevented&&l===!1&&r.preventDefault()};return document.addEventListener(`inertia:${e}`,n),()=>document.removeEventListener(`inertia:${e}`,n)}};var ve={buildDOMElement(t){let e=document.createElement("template");e.innerHTML=t;let i=e.content.firstChild;if(!t.startsWith("<script "))return i;let n=document.createElement("script");return n.innerHTML=i.innerHTML,i.getAttributeNames().forEach(r=>{n.setAttribute(r,i.getAttribute(r)||"")}),n},isInertiaManagedElement(t){return t.nodeType===Node.ELEMENT_NODE&&t.getAttribute("inertia")!==null},findMatchingElementIndex(t,e){let i=t.getAttribute("inertia");return i!==null?e.findIndex(n=>n.getAttribute("inertia")===i):-1},update:T(function(t){let e=t.map(n=>this.buildDOMElement(n));Array.from(document.head.childNodes).filter(n=>this.isInertiaManagedElement(n)).forEach(n=>{let r=this.findMatchingElementIndex(n,e);if(r===-1){n?.parentNode?.removeChild(n);return}let l=e.splice(r,1)[0];l&&!n.isEqualNode(l)&&n?.parentNode?.replaceChild(l,n)}),e.forEach(n=>document.head.appendChild(n))},1)};function H(t,e,i){let n={},r=0;function l(){let s=r+=1;return n[s]=[],s.toString()}function d(s){s===null||Object.keys(n).indexOf(s)===-1||(delete n[s],c())}function p(s,y=[]){s!==null&&Object.keys(n).indexOf(s)>-1&&(n[s]=y),c()}function h(){let s=e(""),y={...s?{title:`<title inertia="">${s}</title>`}:{}},u=Object.values(n).reduce((f,m)=>f.concat(m),[]).reduce((f,m)=>{if(m.indexOf("<")===-1)return f;if(m.indexOf("<title ")===0){let P=m.match(/(<title [^>]+>)(.*?)(<\/title>)/);return f.title=P?`${P[1]}${e(P[2])}${P[3]}`:m,f}let R=m.match(/ inertia="[^"]+"/);return R?f[R[0]]=m:f[Object.keys(f).length]=m,f},y);return Object.values(u)}function c(){t?i(h()):ve.update(h())}return c(),{forceUpdate:c,createProvider:function(){let s=l();return{update:y=>p(s,y),disconnect:()=>d(s)}}}}var g=O(require("nprogress"),1),ae=null;function be(t){document.addEventListener("inertia:start",Ee(t)),document.addEventListener("inertia:progress",we),document.addEventListener("inertia:finish",ye)}function Ee(t){return function(e){e.detail.visit.noProgress||(ae=setTimeout(()=>g.default.start(),t))}}function we(t){g.default.isStarted()&&t.detail.progress?.percentage&&g.default.set(Math.max(g.default.status,t.detail.progress.percentage/100*.9))}function ye(t){if(clearTimeout(ae),g.default.isStarted())t.detail.visit.completed?g.default.done():t.detail.visit.interrupted?g.default.set(0):t.detail.visit.cancelled&&(g.default.done(),g.default.remove());else return}function xe(t){let e=document.createElement("style");e.type="text/css",e.textContent=` | ||
#nprogress { | ||
@@ -72,3 +72,3 @@ pointer-events: none; | ||
} | ||
`,document.head.appendChild(e)}function j({delay:t=250,color:e="#29d",includeCSS:i=!0,showSpinner:r=!1}={}){be(t),g.default.configure({showSpinner:r}),i&&xe(e)}function $(t){let e=t.currentTarget.tagName.toLowerCase()==="a";return!(t.target&&(t?.target).isContentEditable||t.defaultPrevented||e&&t.which>1||e&&t.altKey||e&&t.ctrlKey||e&&t.metaKey||e&&t.shiftKey)}var Se=new A; | ||
`,document.head.appendChild(e)}function j({delay:t=250,color:e="#29d",includeCSS:i=!0,showSpinner:n=!1}={}){be(t),g.default.configure({showSpinner:n}),i&&xe(e)}function $(t){let e=t.currentTarget.tagName.toLowerCase()==="a";return!(t.target&&(t?.target).isContentEditable||t.defaultPrevented||e&&t.which>1||e&&t.altKey||e&&t.ctrlKey||e&&t.metaKey||e&&t.shiftKey)}var Se=new A; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "inertiax-core", | ||
"version": "2.6.1", | ||
"version": "2.6.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A framework for creating server-driven single page apps.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
181308