inertiax-core 2.6.2 → 5.0.2
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/index.esm.js +6 -6
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +6 -6
- package/dist/index.js.map +4 -4
- package/package.json +10 -7
- package/types/debug.d.ts +1 -0
- package/types/encryption.d.ts +6 -0
- package/types/eventHandler.d.ts +17 -0
- package/types/events.d.ts +2 -0
- package/types/formData.d.ts +1 -0
- package/types/history.d.ts +26 -0
- package/types/index.d.ts +2 -4
- package/types/initialVisit.d.ts +10 -0
- package/types/navigationType.d.ts +9 -0
- package/types/objectUtils.d.ts +1 -0
- package/types/page.d.ts +45 -0
- package/types/poll.d.ts +13 -0
- package/types/polls.d.ts +14 -0
- package/types/prefetched.d.ts +23 -0
- package/types/progress.d.ts +2 -0
- package/types/request.d.ts +22 -0
- package/types/requestParams.d.ts +34 -0
- package/types/requestStream.d.ts +18 -0
- package/types/response.d.ts +31 -0
- package/types/router.d.ts +31 -56
- package/types/scroll.d.ts +8 -0
- package/types/sessionStorage.d.ts +10 -0
- package/types/shouldIntercept.d.ts +1 -1
- package/types/time.d.ts +1 -0
- package/types/types.d.ts +93 -18
- package/types/url.d.ts +4 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
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=`
|
|
1
|
+
function T(r,e){let t;return function(...s){clearTimeout(t),t=setTimeout(()=>r.apply(this,s),e)}}var Ce={buildDOMElement(r){let e=document.createElement("template");e.innerHTML=r;let t=e.content.firstChild;if(!r.startsWith("<script "))return t;let s=document.createElement("script");return s.innerHTML=t.innerHTML,t.getAttributeNames().forEach(i=>{s.setAttribute(i,t.getAttribute(i)||"")}),s},isInertiaManagedElement(r){return r.nodeType===Node.ELEMENT_NODE&&r.getAttribute("inertia")!==null},findMatchingElementIndex(r,e){let t=r.getAttribute("inertia");return t!==null?e.findIndex(s=>s.getAttribute("inertia")===t):-1},update:T(function(r){let e=r.map(s=>this.buildDOMElement(s));Array.from(document.head.childNodes).filter(s=>this.isInertiaManagedElement(s)).forEach(s=>{let i=this.findMatchingElementIndex(s,e);if(i===-1){s?.parentNode?.removeChild(s);return}let o=e.splice(i,1)[0];o&&!s.isEqualNode(o)&&s?.parentNode?.replaceChild(o,s)}),e.forEach(s=>document.head.appendChild(s))},1)};function ne(r,e,t){let s={},i=0;function o(){let l=i+=1;return s[l]=[],l.toString()}function u(l){l===null||Object.keys(s).indexOf(l)===-1||(delete s[l],p())}function d(l,f=[]){l!==null&&Object.keys(s).indexOf(l)>-1&&(s[l]=f),p()}function P(){let l=e(""),f={...l?{title:`<title inertia="">${l}</title>`}:{}},K=Object.values(s).reduce((b,y)=>b.concat(y),[]).reduce((b,y)=>{if(y.indexOf("<")===-1)return b;if(y.indexOf("<title ")===0){let O=y.match(/(<title [^>]+>)(.*?)(<\/title>)/);return b.title=O?`${O[1]}${e(O[2])}${O[3]}`:y,b}let ie=y.match(/ inertia="[^"]+"/);return ie?b[ie[0]]=y:b[Object.keys(b).length]=y,b},f);return Object.values(K)}function p(){r?t(P()):Ce.update(P())}return p(),{forceUpdate:p,createProvider:function(){let l=o();return{update:f=>d(l,f),disconnect:()=>u(l)}}}}import v from"nprogress";var A=(()=>{if(typeof document>"u")return null;let r=document.createElement("style");return r.innerHTML="#nprogress { display: none; }",r})(),L=0,Te=()=>{if(A&&document.head.contains(A))return document.head.removeChild(A)},U=(r=!1)=>{L=Math.max(0,L-1),(r||L===0)&&Te()},H=()=>{L++,A&&!document.head.contains(A)&&document.head.appendChild(A)};function Ve(r){document.addEventListener("inertia:start",e=>ke(e,r)),document.addEventListener("inertia:progress",Ie)}function ke(r,e){r.detail.visit.showProgress||H();let t=setTimeout(()=>v.start(),e);document.addEventListener("inertia:finish",s=>Oe(s,t),{once:!0})}function Ie(r){v.isStarted()&&r.detail.progress?.percentage&&v.set(Math.max(v.status,r.detail.progress.percentage/100*.9))}function Oe(r,e){clearTimeout(e),v.isStarted()&&(r.detail.visit.completed?v.done():r.detail.visit.interrupted?v.set(0):r.detail.visit.cancelled&&(v.done(),v.remove()))}function Le(r){let e=document.createElement("style");e.textContent=`
|
|
2
2
|
#nprogress {
|
|
3
3
|
pointer-events: none;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
#nprogress .bar {
|
|
7
|
-
background: ${
|
|
7
|
+
background: ${r};
|
|
8
8
|
|
|
9
9
|
position: fixed;
|
|
10
10
|
z-index: 1031;
|
|
@@ -21,7 +21,7 @@ import{default as Y}from"axios";function T(i,e){let t;return function(...n){clea
|
|
|
21
21
|
right: 0px;
|
|
22
22
|
width: 100px;
|
|
23
23
|
height: 100%;
|
|
24
|
-
box-shadow: 0 0 10px ${
|
|
24
|
+
box-shadow: 0 0 10px ${r}, 0 0 5px ${r};
|
|
25
25
|
opacity: 1.0;
|
|
26
26
|
|
|
27
27
|
-webkit-transform: rotate(3deg) translate(0px, -4px);
|
|
@@ -43,8 +43,8 @@ import{default as Y}from"axios";function T(i,e){let t;return function(...n){clea
|
|
|
43
43
|
box-sizing: border-box;
|
|
44
44
|
|
|
45
45
|
border: solid 2px transparent;
|
|
46
|
-
border-top-color: ${
|
|
47
|
-
border-left-color: ${
|
|
46
|
+
border-top-color: ${r};
|
|
47
|
+
border-left-color: ${r};
|
|
48
48
|
border-radius: 50%;
|
|
49
49
|
|
|
50
50
|
-webkit-animation: nprogress-spinner 400ms linear infinite;
|
|
@@ -69,5 +69,5 @@ import{default as Y}from"axios";function T(i,e){let t;return function(...n){clea
|
|
|
69
69
|
0% { transform: rotate(0deg); }
|
|
70
70
|
100% { transform: rotate(360deg); }
|
|
71
71
|
}
|
|
72
|
-
`,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};
|
|
72
|
+
`,document.head.appendChild(e)}function oe({delay:r=250,color:e="#29d",includeCSS:t=!0,showSpinner:s=!1}={}){Ve(r),v.configure({showSpinner:s}),t&&Le(e)}function ae(r){let e=r.currentTarget.tagName.toLowerCase()==="a";return!(r.target&&(r?.target).isContentEditable||r.defaultPrevented||e&&r.which>1||e&&r.altKey||e&&r.ctrlKey||e&&r.metaKey||e&&r.shiftKey||e&&"button"in r&&r.button!==0)}import Ue from"deepmerge";import*as N from"qs";function D(r){return r instanceof File||r instanceof Blob||r instanceof FileList&&r.length>0||r instanceof FormData&&Array.from(r.values()).some(e=>D(e))||typeof r=="object"&&r!==null&&Object.values(r).some(e=>D(e))}var j=r=>r instanceof FormData;function $(r,e=new FormData,t=null){r=r||{};for(let s in r)Object.prototype.hasOwnProperty.call(r,s)&&ce(e,le(t,s),r[s]);return e}function le(r,e){return r?r+"["+e+"]":e}function ce(r,e,t){if(Array.isArray(t))return Array.from(t.keys()).forEach(s=>ce(r,le(e,s.toString()),t[s]));if(t instanceof Date)return r.append(e,t.toISOString());if(t instanceof File)return r.append(e,t,t.name);if(t instanceof Blob)return r.append(e,t);if(typeof t=="boolean")return r.append(e,t?"1":"0");if(typeof t=="string")return r.append(e,t);if(typeof t=="number")return r.append(e,`${t}`);if(t==null)return r.append(e,"");$(t,r,e)}function h(r){return new URL(r.toString(),typeof window>"u"?void 0:window.location.toString())}var pe=(r,e,t,s,i)=>{let o=typeof r=="string"?h(r):r;if((D(e)||s)&&!j(e)&&(e=$(e)),j(e))return[o,e];let[u,d]=ue(t,o,e,i);return[h(u),d]};function ue(r,e,t,s="brackets"){let i=/^https?:\/\//.test(e.toString()),o=i||e.toString().startsWith("/"),u=!o&&!e.toString().startsWith("#")&&!e.toString().startsWith("?"),d=e.toString().includes("?")||r==="get"&&Object.keys(t).length,P=e.toString().includes("#"),p=new URL(e.toString(),"http://localhost");return r==="get"&&Object.keys(t).length&&(p.search=N.stringify(Ue(N.parse(p.search,{ignoreQueryPrefix:!0}),t),{encodeValuesOnly:!0,arrayFormat:s}),t={}),[[i?`${p.protocol}//${p.host}`:"",o?p.pathname:"",u?p.pathname.substring(1):"",d?p.search:"",P?p.hash:""].join(""),t]}function R(r){return r=new URL(r.href),r.hash="",r}var _=(r,e)=>{r.hash&&!e.hash&&R(r).href===e.href&&(e.hash=r.hash)},V=(r,e)=>R(r).href===R(e).href;function g(r,e){return document.dispatchEvent(new CustomEvent(`inertia:${r}`,e))}var W=r=>g("before",{cancelable:!0,detail:{visit:r}}),de=r=>g("error",{detail:{errors:r}}),he=r=>g("exception",{cancelable:!0,detail:{exception:r}}),me=r=>g("finish",{detail:{visit:r}}),fe=r=>g("invalid",{cancelable:!0,detail:{response:r}}),w=r=>g("navigate",{detail:{page:r}}),ge=r=>g("progress",{detail:{progress:r}}),ve=r=>g("start",{detail:{visit:r}}),be=r=>g("success",{detail:{page:r}}),ye=(r,e)=>g("prefetched",{detail:{fetchedAt:Date.now(),response:r.data,visit:e}}),Pe=r=>g("prefetching",{detail:{visit:r}});var c=class{static set(e,t){typeof window<"u"&&window.sessionStorage.setItem(e,JSON.stringify(t))}static get(e){if(typeof window<"u")return JSON.parse(window.sessionStorage.getItem(e)||"null")}static merge(e,t){let s=this.get(e);s===null?this.set(e,t):this.set(e,{...s,...t})}static remove(e){typeof window<"u"&&window.sessionStorage.removeItem(e)}static removeNested(e,t){let s=this.get(e);s!==null&&(delete s[t],this.set(e,s))}static exists(e){try{return this.get(e)!==null}catch{return!1}}static clear(){typeof window<"u"&&window.sessionStorage.clear()}};c.locationVisitKey="inertiaLocationVisit";var we=async r=>{if(typeof window>"u")throw new Error("Unable to encrypt history");let e=Se(),t=await Re(),s=await Me(t);if(!s)throw new Error("Unable to encrypt history");return await He(e,s,r)},x={key:"historyKey",iv:"historyIv"},Ee=async r=>{let e=Se(),t=await Re();if(!t)throw new Error("Unable to decrypt history");return await De(e,t,r)},He=async(r,e,t)=>{if(typeof window>"u")throw new Error("Unable to encrypt history");if(typeof window.crypto.subtle>"u")return console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve(t);let s=new TextEncoder,i=JSON.stringify(t),o=new Uint8Array(i.length);return s.encodeInto(i,o),window.crypto.subtle.encrypt({name:"AES-GCM",iv:r},e,o)},De=async(r,e,t)=>{if(typeof window.crypto.subtle>"u")return console.warn("Decryption is not supported in this environment. SSL is required."),Promise.resolve(t);let s=await window.crypto.subtle.decrypt({name:"AES-GCM",iv:r},e,t);return JSON.parse(new TextDecoder().decode(s))},Se=()=>{let r=c.get(x.iv);if(r)return new Uint8Array(r);let e=window.crypto.getRandomValues(new Uint8Array(12));return c.set(x.iv,Array.from(e)),e},Ne=async()=>typeof window.crypto.subtle>"u"?(console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve(null)):window.crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),Ge=async r=>{if(typeof window.crypto.subtle>"u")return console.warn("Encryption is not supported in this environment. SSL is required."),Promise.resolve();let e=await window.crypto.subtle.exportKey("raw",r);c.set(x.key,Array.from(new Uint8Array(e)))},Me=async r=>{if(r)return r;let e=await Ne();return e?(await Ge(e),e):null},Re=async()=>{let r=c.get(x.key);return r?await window.crypto.subtle.importKey("raw",new Uint8Array(r),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]):null};var m=class{static save(e){a.replaceState({...e,scrollRegions:Array.from(this.regions()).map(t=>({top:t.scrollTop,left:t.scrollLeft}))})}static regions(){return document.querySelectorAll("[scroll-region]")}static reset(e){typeof window<"u"&&window.scrollTo(0,0),this.regions().forEach(t=>{typeof t.scrollTo=="function"?t.scrollTo(0,0):(t.scrollTop=0,t.scrollLeft=0)}),this.save(e),window.location.hash&&setTimeout(()=>document.getElementById(window.location.hash.slice(1))?.scrollIntoView())}static restore(e){e.scrollRegions&&this.regions().forEach((t,s)=>{let i=e.scrollRegions[s];i&&(typeof t.scrollTo=="function"?t.scrollTo(i.left,i.top):(t.scrollTop=i.top,t.scrollLeft=i.left))})}static onScroll(e){let t=e.target;typeof t.hasAttribute=="function"&&t.hasAttribute("scroll-region")&&this.save(n.get())}};var Q=class{constructor(){this.page={frames:{},version:null,scrollRegions:[]};this.swappers={};this.componentId={};this.listeners=[];this.isFirstPageLoad=!0;this.cleared=!1}init({frame:e,initialState:t,swapComponent:s}){var i;return(i=this.page).version||(i.version=t?.version),t?.component&&this.merge({frames:{[e]:t}}),this.swappers[e]=s,this}async set(e,{replace:t=!1,preserveScroll:s=!1,preserveState:i=!1}={}){this.componentId={};let o=this.componentId;return e.clearHistory&&a.clear(),this.resolve(e.frames).then(u=>{if(o===this.componentId){if(e.scrollRegions??(e.scrollRegions=[]),e.frames._top?.url===void 0){let d=typeof window<"u"?window.location:new URL(e.frames._top.url);t=t||V(h(e.frames._top?.url),d)}return t?a.replaceState(e):a.pushState(e),this.page=e,this.cleared=!1,this.isFirstPageLoad&&this.fireEventsFor("firstLoad"),this.isFirstPageLoad=!1,this.swap({components:u,page:e,preserveState:i}).then(()=>{s||m.reset(e),t||w(e)})}})}async setQuietly(e,{preserveState:t=!1}={}){return this.resolve(e.frames).then(s=>(this.page=e,this.cleared=!1,this.swap({components:s,page:e,preserveState:t})))}async setFrame(e,t,s={}){return this.set({...this.page,frames:{...this.page.frames,[e]:t}},s)}clear(){this.cleared=!0}isCleared(){return this.cleared}frame(e){return this.page.frames[e]||{}}get(){return this.page}merge(e){this.page={...this.page,...e,frames:{...this.page.frames,...e.frames}}}setUrlHash(e){this.page.frames._top.url+=e}remember(e,t){this.page.frames[e].rememberedState=t}scrollRegions(e){this.page.scrollRegions=e}swap({components:e,page:t,preserveState:s}){return Promise.all(Object.entries(e).map(([i,o])=>this.swappers[i]({component:o,frame:t.frames[i],preserveState:s})))}async resolve(e){let t={};return await Promise.all(Object.keys(e).map(async s=>{let i=e[s];t[s]=await k.resolveComponent(i.component)})),t}isTheSame(e,t){return this.page.frames[e].component===t.component}on(e,t){return this.listeners.push({event:e,callback:t}),()=>{this.listeners=this.listeners.filter(s=>s.event!==e&&s.callback!==t)}}fireEventsFor(e){this.listeners.filter(t=>t.event===e).forEach(t=>t.callback())}},n=new Q;var G=typeof window>"u",X=class{constructor(){this.rememberedState="rememberedState";this.scrollRegions="scrollRegions";this.preserveUrl=!1;this.current={};this.queue=[];this.initialState=null}remember(e,t,s){this.replaceState({...n.get(),frames:{...n.get().frames,[e]:{...n.get().frames[e],rememberedState:{...n.get().frames[e]?.rememberedState??{},[s]:t}}}})}restore(e,t){if(!G)return this.initialState?.frames?.[e]?.rememberedState?.[t]}pushState(e){G||this.preserveUrl||(this.current=e,this.addToQueue(()=>this.getPageData(e).then(t=>{window.history.pushState({page:t,timestamp:Date.now()},"",e.frames._top.url)})))}getPageData(e){return new Promise(t=>e.encryptHistory?we(e).then(t):t(e))}processQueue(){let e=this.queue.shift();return e?e().then(()=>this.processQueue()):Promise.resolve()}decrypt(e=null){if(G)return Promise.resolve(e??n.get());let t=e??window.history.state?.page;return this.decryptPageData(t).then(s=>{if(!s)throw new Error("Unable to decrypt history");return this.initialState===null?this.initialState=s??void 0:this.current=s??{},s})}decryptPageData(e){return e instanceof ArrayBuffer?Ee(e):Promise.resolve(e)}replaceState(e){n.merge(e),!(G||this.preserveUrl)&&(this.current=e,this.addToQueue(()=>this.getPageData(e).then(t=>{window.history.replaceState({page:t,timestamp:Date.now()},"",e.frames._top.url)})))}addToQueue(e){this.queue.push(e),this.processQueue()}getState(e,t){return this.current?.[e]??t}deleteRememberedState(){this.current.frames&&(Object.values(this.current.frames).forEach(e=>{delete e.rememberedState}),this.replaceState(this.current))}hasAnyState(){return!!this.getAllState()}clear(){c.remove(x.key),c.remove(x.iv)}isValidState(e){return!!e.page}getAllState(){return this.current}},a=new X;var J=class{constructor(){this.internalListeners=[]}init(){typeof window<"u"&&window.addEventListener("popstate",this.handlePopstateEvent.bind(this)),typeof document<"u"&&document.addEventListener("scroll",T(m.onScroll.bind(m),100),!0)}onGlobalEvent(e,t){let s=i=>{let o=t(i);i.cancelable&&!i.defaultPrevented&&o===!1&&i.preventDefault()};return this.registerListener(`inertia:${e}`,s)}on(e,t){return this.internalListeners.push({event:e,listener:t}),()=>{this.internalListeners=this.internalListeners.filter(s=>s.listener!==t)}}onMissingHistoryItem(){n.clear(),this.fireInternalEvent("missingHistoryItem")}fireInternalEvent(e){this.internalListeners.filter(t=>t.event===e).forEach(t=>t.listener())}registerListener(e,t){return document.addEventListener(e,t),()=>document.removeEventListener(e,t)}handlePopstateEvent(e){let t=e.state||null;if(t===null){let s=h(n.frame("_top").url);s.hash=window.location.hash,a.replaceState({...n.get(),frames:{...n.get().frames,_top:{...n.frame("_top"),url:s.href}}}),m.reset(n.get());return}if(a.isValidState(t)){a.decrypt(t.page).then(s=>{n.setQuietly(s,{preserveState:!1}).then(()=>{m.restore(n.get()),w(n.get())})}).catch(()=>{this.onMissingHistoryItem()});return}this.onMissingHistoryItem()}},E=new J;var z=class{constructor(){typeof window<"u"&&window?.performance.getEntriesByType("navigation").length>0?this.type=window.performance.getEntriesByType("navigation")[0].type:this.type="navigate"}get(){return this.type}isBackForward(){return this.type==="back_forward"}isReload(){return this.type==="reload"}},Y=new z;var M=class{static handle(){this.clearRememberedStateOnReload(),[this.handleBackForward,this.handleLocation,this.handleDefault].find(t=>t.bind(this)())}static clearRememberedStateOnReload(){Y.isReload()&&a.deleteRememberedState()}static handleBackForward(){return!Y.isBackForward()||!a.hasAnyState()||!window.history.state?.page?!1:(a.decrypt().then(e=>{n.set(e,{preserveScroll:!0,preserveState:!0}).then(()=>{m.restore(n.get()),w(n.get())})}).catch(()=>{E.onMissingHistoryItem()}),!0)}static handleLocation(){if(!c.exists(c.locationVisitKey))return!1;let e=c.get(c.locationVisitKey)||{};return c.remove(c.locationVisitKey),typeof window<"u"&&n.setUrlHash(window.location.hash),a.decrypt().then(()=>{let t=a.getState("frames",{}),s=a.getState(a.scrollRegions,[]);Object.entries(t).forEach(([i,o])=>{n.remember(i,o.rememberedState)}),n.scrollRegions(s),n.set(n.get(),{preserveScroll:e.preserveScroll,preserveState:!0}).then(()=>{e.preserveScroll&&m.restore(n.get()),w(n.get())})}).catch(()=>{E.onMissingHistoryItem()}),!0}static handleDefault(){typeof window<"u"&&n.setUrlHash(window.location.hash),n.set(n.get(),{preserveState:!0}).then(()=>{w(n.get())})}};var B=class{constructor(e,t,s){this.id=null;this.throttle=!1;this.keepAlive=!1;this.cbCount=0;this.keepAlive=s.keepAlive??!1,this.cb=t,this.interval=e,(s.autoStart??!0)&&this.start()}stop(){this.id&&clearInterval(this.id)}start(){typeof window>"u"||(this.stop(),this.id=window.setInterval(()=>{(!this.throttle||this.cbCount%10===0)&&this.cb(),this.throttle&&this.cbCount++},this.interval))}isInBackground(e){this.throttle=this.keepAlive?!1:e,this.throttle&&(this.cbCount=0)}};var Z=class{constructor(){this.polls=[];this.setupVisibilityListener()}add(e,t,s){let i=new B(e,t,s);return this.polls.push(i),{stop:()=>i.stop(),start:()=>i.start()}}clear(){this.polls.forEach(e=>e.stop()),this.polls=[]}setupVisibilityListener(){typeof document>"u"||document.addEventListener("visibilitychange",()=>{this.polls.forEach(e=>e.isInBackground(document.hidden))},!1)}},xe=new Z;var ee=(r,e,t)=>{if(r===e)return!0;for(let s in r)if(!t.includes(s)&&r[s]!==e[s]&&!Be(r[s],e[s]))return!1;return!0},Be=(r,e)=>{switch(typeof r){case"object":return ee(r,e,[]);case"function":return r.toString()===e.toString();default:return r===e}};var Ke={ms:1,s:1e3,m:6e4,h:36e5,d:864e5},te=r=>{if(typeof r=="number")return r;for(let[e,t]of Object.entries(Ke))if(r.endsWith(e))return parseFloat(r)*t;return parseInt(r)};var re=class{constructor(){this.cached=[];this.inFlightRequests=[];this.removalTimers=[];this.currentUseId=null}add(e,t,{cacheFor:s}){if(this.findInFlight(e))return Promise.resolve();let o=this.findCached(e);if(!e.fresh&&o&&o.staleTimestamp>Date.now())return Promise.resolve();let[u,d]=this.extractStaleValues(s),P=new Promise((p,l)=>{t({...e,onCancel:()=>{this.remove(e),e.onCancel(),l()},onError:f=>{this.remove(e),e.onError(f),l()},onPrefetching(f){e.onPrefetching(f)},onPrefetched(f,K){e.onPrefetched(f,K)},onPrefetchResponse(f){p(f)}})}).then(p=>(this.remove(e),this.cached.push({params:{...e},staleTimestamp:Date.now()+u,response:P,singleUse:s===0,timestamp:Date.now(),inFlight:!1}),this.scheduleForRemoval(e,d),this.inFlightRequests=this.inFlightRequests.filter(l=>!this.paramsAreEqual(l.params,e)),p.handlePrefetch(),p));return this.inFlightRequests.push({params:{...e},response:P,staleTimestamp:null,inFlight:!0}),P}removeAll(){this.cached=[],this.removalTimers.forEach(e=>{clearTimeout(e.timer)}),this.removalTimers=[]}remove(e){this.cached=this.cached.filter(t=>!this.paramsAreEqual(t.params,e)),this.clearTimer(e)}extractStaleValues(e){let[t,s]=this.cacheForToStaleAndExpires(e);return[te(t),te(s)]}cacheForToStaleAndExpires(e){if(!Array.isArray(e))return[e,e];switch(e.length){case 0:return[0,0];case 1:return[e[0],e[0]];default:return[e[0],e[1]]}}clearTimer(e){let t=this.removalTimers.find(s=>this.paramsAreEqual(s.params,e));t&&(clearTimeout(t.timer),this.removalTimers=this.removalTimers.filter(s=>s!==t))}scheduleForRemoval(e,t){if(!(typeof window>"u")&&(this.clearTimer(e),t>0)){let s=window.setTimeout(()=>this.remove(e),t);this.removalTimers.push({params:e,timer:s})}}get(e){return this.findCached(e)||this.findInFlight(e)}use(e,t){let s=`${t.url.pathname}-${Date.now()}-${Math.random().toString(36).substring(7)}`;return this.currentUseId=s,e.response.then(i=>{if(this.currentUseId===s)return i.mergeParams({...t,onPrefetched:()=>{}}),this.removeSingleUseItems(t),i.handle()})}removeSingleUseItems(e){this.cached=this.cached.filter(t=>this.paramsAreEqual(t.params,e)?!t.singleUse:!0)}findCached(e){return this.cached.find(t=>this.paramsAreEqual(t.params,e))||null}findInFlight(e){return this.inFlightRequests.find(t=>this.paramsAreEqual(t.params,e))||null}paramsAreEqual(e,t){return ee(e,t,["showProgress","replace","prefetch","onBefore","onStart","onProgress","onFinish","onCancel","onSuccess","onError","onPrefetched","onCancelToken","onPrefetching","async"])}},S=new re;import{default as Ae}from"axios";var C=class{constructor(e){this.callbacks=[];if(!e.prefetch)this.params=e;else{let t={onBefore:this.wrapCallback(e,"onBefore"),onStart:this.wrapCallback(e,"onStart"),onProgress:this.wrapCallback(e,"onProgress"),onFinish:this.wrapCallback(e,"onFinish"),onCancel:this.wrapCallback(e,"onCancel"),onSuccess:this.wrapCallback(e,"onSuccess"),onError:this.wrapCallback(e,"onError"),onCancelToken:this.wrapCallback(e,"onCancelToken"),onPrefetched:this.wrapCallback(e,"onPrefetched"),onPrefetching:this.wrapCallback(e,"onPrefetching")};this.params={...e,...t,onPrefetchResponse:e.onPrefetchResponse||(()=>{})}}}static create(e){return new C(e)}data(){return this.params.method==="get"?{}:this.params.data}queryParams(){return this.params.method==="get"?this.params.data:{}}isPartial(){return this.params.only.length>0||this.params.except.length>0||this.params.reset.length>0}onCancelToken(e){this.params.onCancelToken({cancel:e})}markAsFinished(){this.params.completed=!0,this.params.cancelled=!1,this.params.interrupted=!1}markAsCancelled({cancelled:e=!0,interrupted:t=!1}){this.params.onCancel(),this.params.completed=!1,this.params.cancelled=e,this.params.interrupted=t}wasCancelledAtAll(){return this.params.cancelled||this.params.interrupted}onFinish(){this.params.onFinish(this.params)}onStart(){this.params.onStart(this.params)}onPrefetching(){this.params.onPrefetching(this.params)}onPrefetchResponse(e){this.params.onPrefetchResponse&&this.params.onPrefetchResponse(e)}all(){return this.params}headers(){let e={...this.params.headers};this.isPartial()&&(e["X-Inertia-Partial-Component"]=n.frame(this.params.frame).component);let t=this.params.only.concat(this.params.reset);return t.length>0&&(e["X-Inertia-Partial-Data"]=t.join(",")),this.params.except.length>0&&(e["X-Inertia-Partial-Except"]=this.params.except.join(",")),this.params.reset.length>0&&(e["X-Inertia-Reset"]=this.params.reset.join(",")),this.params.errorBag&&this.params.errorBag.length>0&&(e["X-Inertia-Error-Bag"]=this.params.errorBag),e}setPreserveOptions(e){this.params.preserveScroll=this.resolvePreserveOption(this.params.preserveScroll,e),this.params.preserveState=this.resolvePreserveOption(this.params.preserveState,e)}runCallbacks(){this.callbacks.forEach(({name:e,args:t})=>{this.params[e](...t)})}merge(e){this.params={...this.params,...e}}wrapCallback(e,t){return(...s)=>{this.recordCallback(t,s),e[t](...s)}}recordCallback(e,t){this.callbacks.push({name:e,args:t})}resolvePreserveOption(e,t){return typeof e=="function"?e(t):e==="errors"?Object.keys(t.frames[this.params.frame].props.errors||{}).length>0:e}};var qe={modal:null,listener:null,show(r){typeof r=="object"&&(r=`All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.<hr>${JSON.stringify(r)}`);let e=document.createElement("html");e.innerHTML=r,e.querySelectorAll("a").forEach(s=>s.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(r){r.keyCode===27&&this.hide()}};var se=class{constructor(){this.queue=[];this.processing=!1}add(e){this.queue.push(e)}async process(){return this.processing||(this.processing=!0,await this.processQueue(),this.processing=!1),Promise.resolve()}async processQueue(){let e=this.queue.shift();return e?(await e.process(),this.processQueue()):Promise.resolve()}},Fe=new se,q=class{constructor(e,t,s){this.requestParams=e;this.response=t;this.originatingPage=s}static create(e,t,s){return new q(e,t,s)}async handlePrefetch(){V(this.requestParams.all().url,window.location)&&this.handle()}async handle(){return Fe.add(this),Fe.process()}async process(){if(this.requestParams.all().prefetch)return this.requestParams.all().prefetch=!1,this.requestParams.all().onPrefetched(this.response,this.requestParams.all()),ye(this.response,this.requestParams.all()),Promise.resolve();if(this.requestParams.runCallbacks(),!this.isInertiaResponse())return this.handleNonInertiaResponse();await a.processQueue(),a.preserveUrl=this.requestParams.all().preserveUrl,await this.setFrame();let e=this.requestParams.all().frame,t=n.frame(e).props.errors||{};if(Object.keys(t).length>0){let s=this.getScopedErrors(t);return de(s),this.requestParams.all().onError(s)}be(n.get()),await this.requestParams.all().onSuccess(n.get()),a.preserveUrl=!1}mergeParams(e){this.requestParams.merge(e)}async handleNonInertiaResponse(){if(this.isLocationVisit()){let t=h(this.getHeader("x-inertia-location"));return _(this.requestParams.all().url,t),this.locationVisit(t)}let e={...this.response,data:this.getDataFromResponse(this.response.data)};if(fe(e))return qe.show(e.data)}isInertiaResponse(){return this.hasHeader("x-inertia")}hasStatus(e){return this.response.status===e}getHeader(e){return this.response.headers[e]}hasHeader(e){return this.getHeader(e)!==void 0}isLocationVisit(){return this.hasStatus(409)&&this.hasHeader("x-inertia-location")}locationVisit(e){try{if(c.set(c.locationVisitKey,{preserveScroll:this.requestParams.all().preserveScroll===!0}),typeof window>"u")return;V(window.location,e)?window.location.reload():window.location.href=e.href}catch{return!1}}async setFrame(){let e=this.getDataFromResponse(this.response.data);return this.shouldSetFrame(e)?(this.mergeProps(e),await this.setRememberedState(e),this.requestParams.setPreserveOptions(e),e.url=a.preserveUrl?n.frame("_top").url:this.pageUrl(e),delete e.version,n.setFrame(this.requestParams.all().frame,e,{replace:this.requestParams.all().replace,preserveScroll:this.requestParams.all().preserveScroll,preserveState:this.requestParams.all().preserveState})):Promise.resolve()}getDataFromResponse(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}shouldSetFrame(e){let t=this.requestParams.all().frame;if(!this.requestParams.all().async||this.originatingPage.frames[t].component!==e.component)return!0;if(this.originatingPage.frames[t].component!==n.frame(t).component)return!1;let s=h(this.originatingPage.frames._top.url),i=h(n.frame("_top").url);return s.origin===i.origin&&s.pathname===i.pathname}pageUrl(e){let t=h(e.url);return _(this.requestParams.all().url,t),t.href}mergeProps(e){let t=this.requestParams.all().frame;this.requestParams.isPartial()&&e.component===n.frame(t).component&&((e.mergeProps||[]).forEach(i=>{let o=e.props[i];Array.isArray(o)?e.props[i]=[...n.frame(t).props[i]||[],...o]:typeof o=="object"&&(e.props[i]={...n.frame(t).props[i]||[],...o})}),e.props={...n.frame(t).props,...e.props})}async setRememberedState(e){let t=await a.getState("frames",{}),s=this.requestParams.all().frame,i=t[s]?.rememberedState||{};this.requestParams.all().preserveState&&i&&e.component===n.frame(s).component&&(e.rememberedState=i)}getScopedErrors(e){return this.requestParams.all().errorBag?e[this.requestParams.all().errorBag||""]||{}:e}};var F=class{constructor(e,t){this.page=t;this.requestHasFinished=!1;this.requestParams=C.create(e),this.cancelToken=new AbortController}static create(e,t){return new F(e,t)}async send(){this.requestParams.onCancelToken(()=>this.cancel({cancelled:!0})),ve(this.requestParams.all()),this.requestParams.onStart(),this.requestParams.all().prefetch&&(this.requestParams.onPrefetching(),Pe(this.requestParams.all()));let e=this.requestParams.all().prefetch;return Ae({method:this.requestParams.all().method,url:R(this.requestParams.all().url).href,data:this.requestParams.data(),params:this.requestParams.queryParams(),signal:this.cancelToken.signal,headers:this.getHeaders(),onUploadProgress:this.onProgress.bind(this),responseType:"text"}).then(t=>(this.response=q.create(this.requestParams,t,this.page),this.response.handle())).catch(t=>t?.response?(this.response=q.create(this.requestParams,t.response,this.page),this.response.handle()):Promise.reject(t)).catch(t=>{if(!Ae.isCancel(t)&&he(t))return Promise.reject(t)}).finally(()=>{this.finish(),e&&this.response&&this.requestParams.onPrefetchResponse(this.response)})}finish(){this.requestParams.wasCancelledAtAll()||(this.requestParams.markAsFinished(),this.fireFinishEvents())}fireFinishEvents(){this.requestHasFinished||(this.requestHasFinished=!0,me(this.requestParams.all()),this.requestParams.onFinish())}cancel({cancelled:e=!1,interrupted:t=!1}){this.requestHasFinished||(this.cancelToken.abort(),this.requestParams.markAsCancelled({cancelled:e,interrupted:t}),this.fireFinishEvents())}onProgress(e){this.requestParams.data()instanceof FormData&&(e.percentage=e.progress?Math.round(e.progress*100):0,ge(e),this.requestParams.all().onProgress(e))}getHeaders(){let e={...this.requestParams.headers(),Accept:"text/html, application/xhtml+xml","X-Requested-With":"XMLHttpRequest","X-Inertia":!0},t=this.requestParams.all().frame,s=n.frame(t).url;return s&&(e["X-Inertia-Referer"]=R(h(s)).href),n.get().version&&(e["X-Inertia-Version"]=n.get().version),e}};var I=class{constructor({maxConcurrent:e,interruptible:t}){this.requests=[];this.maxConcurrent=e,this.interruptible=t}send(e){this.requests.push(e),e.send().then(()=>{this.requests=this.requests.filter(t=>t!==e)})}interruptInFlight(){this.cancel({interrupted:!0},!1)}cancelInFlight(){this.cancel({cancelled:!0},!0)}cancel({cancelled:e=!1,interrupted:t=!1}={},s){if(!this.shouldCancel(s))return;this.requests.shift()?.cancel({interrupted:t,cancelled:e})}shouldCancel(e){return e?!0:this.interruptible&&this.requests.length>=this.maxConcurrent}};var k=class{constructor({frame:e,initialState:t,swapComponent:s}){this.syncRequestStream=new I({maxConcurrent:1,interruptible:!0});this.asyncRequestStream=new I({maxConcurrent:1/0,interruptible:!1});this.frame=e,!import.meta.env.SSR&&(n.init({frame:e,initialState:t,swapComponent:s}),e==="_top"&&(M.handle(),E.init(),E.on("missingHistoryItem",()=>{typeof window<"u"&&this.visit(window.location.href,{preserveState:!0,preserveScroll:!0,replace:!0})}),E.onGlobalEvent("navigate",()=>{this.loadDeferredProps()})))}get(e,t={},s={}){return this.visit(e,{...s,method:"get",data:t})}post(e,t={},s={}){return this.visit(e,{preserveState:!0,...s,method:"post",data:t})}put(e,t={},s={}){return this.visit(e,{preserveState:!0,...s,method:"put",data:t})}patch(e,t={},s={}){return this.visit(e,{preserveState:!0,...s,method:"patch",data:t})}delete(e,t={}){return this.visit(e,{preserveState:!0,...t,method:"delete"})}reload(e={}){if(!(typeof window>"u"))return this.visit(window.location.href,{...e,preserveScroll:!0,preserveState:!0,async:!0,headers:{...e.headers||{},"Cache-Control":"no-cache"}})}remember(e,t="default"){a.remember(this.frame,e,t)}restore(e="default"){return a.restore(this.frame,e)}on(e,t){return E.onGlobalEvent(e,t)}cancel(){this.syncRequestStream.cancelInFlight()}cancelAll(){this.asyncRequestStream.cancelInFlight(),this.syncRequestStream.cancelInFlight()}poll(e,t={},s={}){return xe.add(e,()=>this.reload(t),{autoStart:s.autoStart??!0,keepAlive:s.keepAlive??!1})}visit(e,t={}){if(import.meta.env.SSR)return;let s=this.getPendingVisit(e,{...t,showProgress:t.showProgress??!t.async}),i=this.getVisitEvents(t);if(i.onBefore(s)===!1||!W(s))return;let o=s.async?this.asyncRequestStream:this.syncRequestStream;o.interruptInFlight(),!n.isCleared()&&!s.preserveUrl&&m.save(n.get());let u={...s,...i},d=S.get(u);d?(U(d.inFlight),S.use(d,u)):(U(!0),o.send(F.create(u,n.get())))}getCached(e,t={}){return S.findCached(this.getPrefetchParams(e,t))}flush(e,t={}){S.remove(this.getPrefetchParams(e,t))}flushAll(){S.removeAll()}getPrefetching(e,t={}){return S.findInFlight(this.getPrefetchParams(e,t))}prefetch(e,t={},{cacheFor:s}){if(t.method!=="get")throw new Error("Prefetch requests must use the GET method");let i=this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),o=this.getVisitEvents(t);if(o.onBefore(i)===!1||!W(i))return;H(),this.asyncRequestStream.interruptInFlight();let u={...i,...o};S.add(u,d=>{this.asyncRequestStream.send(F.create(d,n.get()))},{cacheFor:s})}clearHistory(){a.clear()}decryptHistory(){return a.decrypt()}getPrefetchParams(e,t){return{...this.getPendingVisit(e,{...t,async:!0,showProgress:!1,prefetch:!0}),...this.getVisitEvents(t)}}getPendingVisit(e,t,s={}){let i={method:"get",data:{},replace:!1,preserveScroll:!1,preserveState:!1,only:[],except:[],headers:{},errorBag:"",forceFormData:!1,queryStringArrayFormat:"brackets",async:!1,showProgress:!0,fresh:!1,reset:[],preserveUrl:!1,prefetch:!1,frame:this.frame,...t},[o,u]=pe(e,i.data,i.method,i.forceFormData,i.queryStringArrayFormat);return{cancelled:!1,completed:!1,interrupted:!1,...i,...s,url:o,data:u}}getVisitEvents(e){return{onCancelToken:e.onCancelToken||(()=>{}),onBefore:e.onBefore||(()=>{}),onStart:e.onStart||(()=>{}),onProgress:e.onProgress||(()=>{}),onFinish:e.onFinish||(()=>{}),onCancel:e.onCancel||(()=>{}),onSuccess:e.onSuccess||(()=>{}),onError:e.onError||(()=>{}),onPrefetched:e.onPrefetched||(()=>{}),onPrefetching:e.onPrefetching||(()=>{})}}loadDeferredProps(){let e=n.frame(this.frame)?.deferredProps;e&&Object.entries(e).forEach(([t,s])=>{this.reload({only:s})})}};export{k as Router,ne as createHeadManager,H as hideProgress,h as hrefToUrl,ue as mergeDataIntoQueryString,U as revealProgress,oe as setupProgress,ae as shouldIntercept,R as urlWithoutHash};
|
|
73
73
|
//# sourceMappingURL=index.esm.js.map
|