@remix-run/router 1.0.2 → 1.0.3-pre.0

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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @remix-run/router v1.0.3-pre.0
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).RemixRouter={})}(this,(function(e){"use strict";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},t.apply(this,arguments)}var r;e.Action=void 0,(r=e.Action||(e.Action={})).Pop="POP",r.Push="PUSH",r.Replace="REPLACE";const a="popstate";function n(e,t){if(!e){"undefined"!=typeof console&&console.warn(t);try{throw new Error(t)}catch(e){}}}function o(e){return{usr:e.state,key:e.key}}function i(e,r,a,n){return void 0===a&&(a=null),t({pathname:"string"==typeof e?e:e.pathname,search:"",hash:""},"string"==typeof r?l(r):r,{state:a,key:r&&r.key||n||Math.random().toString(36).substr(2,8)})}function s(e){let{pathname:t="/",search:r="",hash:a=""}=e;return r&&"?"!==r&&(t+="?"===r.charAt(0)?r:"?"+r),a&&"#"!==a&&(t+="#"===a.charAt(0)?a:"#"+a),t}function l(e){let t={};if(e){let r=e.indexOf("#");r>=0&&(t.hash=e.substr(r),e=e.substr(0,r));let a=e.indexOf("?");a>=0&&(t.search=e.substr(a),e=e.substr(0,a)),e&&(t.pathname=e)}return t}function c(t,r,n,s){void 0===s&&(s={});let{window:l=document.defaultView,v5Compat:c=!1}=s,d=l.history,u=e.Action.Pop,h=null;function f(){u=e.Action.Pop,h&&h({action:u,location:p.location})}let p={get action(){return u},get location(){return t(l,d)},listen(e){if(h)throw new Error("A history only accepts one active listener");return l.addEventListener(a,f),h=e,()=>{l.removeEventListener(a,f),h=null}},createHref:e=>r(l,e),push:function(t,r){u=e.Action.Push;let a=i(p.location,t,r);n&&n(a,t);let s=o(a),f=p.createHref(a);try{d.pushState(s,"",f)}catch(e){l.location.assign(f)}c&&h&&h({action:u,location:p.location})},replace:function(t,r){u=e.Action.Replace;let a=i(p.location,t,r);n&&n(a,t);let s=o(a),l=p.createHref(a);d.replaceState(s,"",l),c&&h&&h({action:u,location:p.location})},go:e=>d.go(e)};return p}let d;function u(e,r,a){return void 0===r&&(r=[]),void 0===a&&(a=new Set),e.map(((e,n)=>{let o=[...r,n],i="string"==typeof e.id?e.id:o.join("-");if(D(!0!==e.index||!e.children,"Cannot specify children on an index route"),D(!a.has(i),'Found a route id collision on id "'+i+"\". Route id's must be globally unique within Data Router usages"),a.add(i),function(e){return!0===e.index}(e)){return t({},e,{id:i})}return t({},e,{id:i,children:e.children?u(e.children,o,a):void 0})}))}function h(e,t,r){void 0===r&&(r="/");let a=b(("string"==typeof t?l(t):t).pathname||"/",r);if(null==a)return null;let n=f(e);!function(e){e.sort(((e,t)=>e.score!==t.score?t.score-e.score:function(e,t){return e.length===t.length&&e.slice(0,-1).every(((e,r)=>e===t[r]))?e[e.length-1]-t[t.length-1]:0}(e.routesMeta.map((e=>e.childrenIndex)),t.routesMeta.map((e=>e.childrenIndex)))))}(n);let o=null;for(let e=0;null==o&&e<n.length;++e)o=v(n[e],w(a));return o}function f(e,t,r,a){return void 0===t&&(t=[]),void 0===r&&(r=[]),void 0===a&&(a=""),e.forEach(((e,n)=>{let o={relativePath:e.path||"",caseSensitive:!0===e.caseSensitive,childrenIndex:n,route:e};o.relativePath.startsWith("/")&&(D(o.relativePath.startsWith(a),'Absolute route path "'+o.relativePath+'" nested under path "'+a+'" is not valid. An absolute child route path must start with the combined path of all its parent routes.'),o.relativePath=o.relativePath.slice(a.length));let i=M([a,o.relativePath]),s=r.concat(o);e.children&&e.children.length>0&&(D(!0!==e.index,'Index routes must not have child routes. Please remove all child routes from route path "'+i+'".'),f(e.children,t,s,i)),(null!=e.path||e.index)&&t.push({path:i,score:g(i,e.index),routesMeta:s})})),t}!function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"}(d||(d={}));const p=/^:\w+$/,m=e=>"*"===e;function g(e,t){let r=e.split("/"),a=r.length;return r.some(m)&&(a+=-2),t&&(a+=2),r.filter((e=>!m(e))).reduce(((e,t)=>e+(p.test(t)?3:""===t?1:10)),a)}function v(e,t){let{routesMeta:r}=e,a={},n="/",o=[];for(let e=0;e<r.length;++e){let i=r[e],s=e===r.length-1,l="/"===n?t:t.slice(n.length)||"/",c=y({path:i.relativePath,caseSensitive:i.caseSensitive,end:s},l);if(!c)return null;Object.assign(a,c.params);let d=i.route;o.push({params:a,pathname:M([n,c.pathname]),pathnameBase:S(M([n,c.pathnameBase])),route:d}),"/"!==c.pathnameBase&&(n=M([n,c.pathnameBase]))}return o}function y(e,t){"string"==typeof e&&(e={path:e,caseSensitive:!1,end:!0});let[r,a]=function(e,t,r){void 0===t&&(t=!1);void 0===r&&(r=!0);E("*"===e||!e.endsWith("*")||e.endsWith("/*"),'Route path "'+e+'" will be treated as if it were "'+e.replace(/\*$/,"/*")+'" because the `*` character must always follow a `/` in the pattern. To get rid of this warning, please change the route path to "'+e.replace(/\*$/,"/*")+'".');let a=[],n="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^$?{}|()[\]]/g,"\\$&").replace(/:(\w+)/g,((e,t)=>(a.push(t),"([^\\/]+)")));e.endsWith("*")?(a.push("*"),n+="*"===e||"/*"===e?"(.*)$":"(?:\\/(.+)|\\/*)$"):r?n+="\\/*$":""!==e&&"/"!==e&&(n+="(?:(?=\\/|$))");return[new RegExp(n,t?void 0:"i"),a]}(e.path,e.caseSensitive,e.end),n=t.match(r);if(!n)return null;let o=n[0],i=o.replace(/(.)\/+$/,"$1"),s=n.slice(1);return{params:a.reduce(((e,t,r)=>{if("*"===t){let e=s[r]||"";i=o.slice(0,o.length-e.length).replace(/(.)\/+$/,"$1")}return e[t]=function(e,t){try{return decodeURIComponent(e)}catch(r){return E(!1,'The value for the URL param "'+t+'" will not be decoded because the string "'+e+'" is a malformed URL segment. This is probably due to a bad percent encoding ('+r+")."),e}}(s[r]||"",t),e}),{}),pathname:o,pathnameBase:i,pattern:e}}function w(e){try{return decodeURI(e)}catch(t){return E(!1,'The URL path "'+e+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent encoding ('+t+")."),e}}function b(e,t){if("/"===t)return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let r=t.endsWith("/")?t.length-1:t.length,a=e.charAt(r);return a&&"/"!==a?null:e.slice(r)||"/"}function D(e,t){if(!1===e||null==e)throw new Error(t)}function E(e,t){if(!e){"undefined"!=typeof console&&console.warn(t);try{throw new Error(t)}catch(e){}}}function A(e,t){void 0===t&&(t="/");let{pathname:r,search:a="",hash:n=""}="string"==typeof e?l(e):e,o=r?r.startsWith("/")?r:function(e,t){let r=t.replace(/\/+$/,"").split("/");return e.split("/").forEach((e=>{".."===e?r.length>1&&r.pop():"."!==e&&r.push(e)})),r.length>1?r.join("/"):"/"}(r,t):t;return{pathname:o,search:C(a),hash:T(n)}}function R(e,t,r,a){return"Cannot include a '"+e+"' character in a manually specified `to."+t+"` field ["+JSON.stringify(a)+"]. Please separate it out to the `to."+r+'` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.'}function P(e){return e.filter(((e,t)=>0===t||e.route.path&&e.route.path.length>0))}function x(e,r,a,n){let o;void 0===n&&(n=!1),"string"==typeof e?o=l(e):(o=t({},e),D(!o.pathname||!o.pathname.includes("?"),R("?","pathname","search",o)),D(!o.pathname||!o.pathname.includes("#"),R("#","pathname","hash",o)),D(!o.search||!o.search.includes("#"),R("#","search","hash",o)));let i,s=""===e||""===o.pathname,c=s?"/":o.pathname;if(n||null==c)i=a;else{let e=r.length-1;if(c.startsWith("..")){let t=c.split("/");for(;".."===t[0];)t.shift(),e-=1;o.pathname=t.join("/")}i=e>=0?r[e]:"/"}let d=A(o,i),u=c&&"/"!==c&&c.endsWith("/"),h=(s||"."===c)&&a.endsWith("/");return d.pathname.endsWith("/")||!u&&!h||(d.pathname+="/"),d}const M=e=>e.join("/").replace(/\/\/+/g,"/"),S=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),C=e=>e&&"?"!==e?e.startsWith("?")?e:"?"+e:"",T=e=>e&&"#"!==e?e.startsWith("#")?e:"#"+e:"";class j extends Error{}class L{constructor(e){let t;this.pendingKeys=new Set,this.subscriber=void 0,D(e&&"object"==typeof e&&!Array.isArray(e),"defer() only accepts plain objects"),this.abortPromise=new Promise(((e,r)=>t=r)),this.controller=new AbortController;let r=()=>t(new j("Deferred data aborted"));this.unlistenAbortSignal=()=>this.controller.signal.removeEventListener("abort",r),this.controller.signal.addEventListener("abort",r),this.data=Object.entries(e).reduce(((e,t)=>{let[r,a]=t;return Object.assign(e,{[r]:this.trackPromise(r,a)})}),{})}trackPromise(e,t){if(!(t instanceof Promise))return t;this.pendingKeys.add(e);let r=Promise.race([t,this.abortPromise]).then((t=>this.onSettle(r,e,null,t)),(t=>this.onSettle(r,e,t)));return r.catch((()=>{})),Object.defineProperty(r,"_tracked",{get:()=>!0}),r}onSettle(e,t,r,a){if(this.controller.signal.aborted&&r instanceof j)return this.unlistenAbortSignal(),Object.defineProperty(e,"_error",{get:()=>r}),Promise.reject(r);this.pendingKeys.delete(t),this.done&&this.unlistenAbortSignal();const n=this.subscriber;return r?(Object.defineProperty(e,"_error",{get:()=>r}),n&&n(!1),Promise.reject(r)):(Object.defineProperty(e,"_data",{get:()=>a}),n&&n(!1),a)}subscribe(e){this.subscriber=e}cancel(){this.controller.abort(),this.pendingKeys.forEach(((e,t)=>this.pendingKeys.delete(t)));let e=this.subscriber;e&&e(!0)}async resolveData(e){let t=!1;if(!this.done){let r=()=>this.cancel();e.addEventListener("abort",r),t=await new Promise((t=>{this.subscribe((a=>{e.removeEventListener("abort",r),(a||this.done)&&t(a)}))}))}return t}get done(){return 0===this.pendingKeys.size}get unwrappedData(){return D(null!==this.data&&this.done,"Can only unwrap data on initialized and settled deferreds"),Object.entries(this.data).reduce(((e,t)=>{let[r,a]=t;return Object.assign(e,{[r]:O(a)})}),{})}}function O(e){if(!function(e){return e instanceof Promise&&!0===e._tracked}(e))return e;if(e._error)throw e._error;return e._data}class H{constructor(e,t,r){this.status=e,this.statusText=t||"",this.data=r}}function U(e){return e instanceof H}const _={state:"idle",location:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},k={state:"idle",data:void 0,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0},N=!("undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement);const W=new Set(["POST","PUT","PATCH","DELETE"]),$=new Set(["GET","HEAD",...W]);function q(e,t,r){void 0===r&&(r=!1);let a="string"==typeof e?e:s(e);if(!t||!("formMethod"in t)&&!("formData"in t))return{path:a};if(null!=t.formMethod&&"get"!==t.formMethod)return{path:a,submission:{formMethod:t.formMethod,formAction:ne(l(a)),formEncType:t&&t.formEncType||"application/x-www-form-urlencoded",formData:t.formData}};if(!t.formData)return{path:a};let n=l(a);try{let e=G(t.formData);r&&n.search&&ue(n.search)&&e.append("index",""),n.search="?"+e}catch(e){return{path:a,error:new H(400,"Bad Request","Cannot submit binary form data using GET")}}return{path:s(n)}}function F(e,t){let{formMethod:r,formAction:a,formEncType:n,formData:o}=e.navigation;return{state:"loading",location:i(e.location,t.location),formMethod:r||void 0,formAction:a||void 0,formEncType:n||void 0,formData:o||void 0}}function I(e,t){let r=e;if(t){let a=e.findIndex((e=>e.route.id===t));a>=0&&(r=e.slice(0,a))}return r}function B(e,t,r,a,n,o,i,s,l,c){let d=l?Object.values(l)[0]:s?Object.values(s)[0]:null,u=I(t,l?Object.keys(l)[0]:void 0).filter(((t,i)=>null!=t.route.loader&&(function(e,t,r){let a=!t||r.route.id!==t.route.id,n=void 0===e[r.route.id];return a||n}(e.loaderData,e.matches[i],t)||o.some((e=>e===t.route.id))||K(e.location,e.matches[i],r,a,t,n,d)))),h=[];return c&&c.forEach(((e,t)=>{let[a,o,s]=e;if(i.includes(t))h.push([t,a,o,s]);else if(n){K(a,o,r,a,o,n,d)&&h.push([t,a,o,s])}})),[u,h]}function z(e,t){let r=e.route.path;return e.pathname!==t.pathname||r&&r.endsWith("*")&&e.params["*"]!==t.params["*"]}function K(e,r,a,n,o,i,s){let l=pe(e),c=r.params,d=pe(n),u=o.params,h=z(r,o)||l.toString()===d.toString()||l.search!==d.search||i;if(o.route.shouldRevalidate){let e=o.route.shouldRevalidate(t({currentUrl:l,currentParams:c,nextUrl:d,nextParams:u},a,{actionResult:s,defaultShouldRevalidate:h}));if("boolean"==typeof e)return e}return h}async function J(e,t,r,a,n,o,i){let l,c,u;void 0===o&&(o=!1),void 0===i&&(i=!1);let h=new Promise(((e,t)=>u=t)),f=()=>u();t.signal.addEventListener("abort",f);try{let a=r.route[e];D(a,"Could not find the "+e+' to run on the "'+r.route.id+'" route'),c=await Promise.race([a({request:t,params:r.params}),h])}catch(e){l=d.error,c=e}finally{t.signal.removeEventListener("abort",f)}if(c instanceof Response){let e,u=c.status;if(u>=300&&u<=399){let e=c.headers.get("Location");D(e,"Redirects returned/thrown from loaders/actions must have a Location header");let i=x(e,P(a.slice(0,a.indexOf(r)+1)).map((e=>e.pathnameBase)),pe(t.url).pathname);if(D(s(i),"Unable to resolve redirect location: "+c.headers.get("Location")),n){let e=i.pathname;i.pathname="/"===e?n:M([n,e])}if(e=s(i),o)throw c.headers.set("Location",e),c;return{type:d.redirect,status:u,location:e,revalidate:null!==c.headers.get("X-Remix-Revalidate")}}if(i)throw{type:l||d.data,response:c};let h=c.headers.get("Content-Type");return e=h&&h.startsWith("application/json")?await c.json():await c.text(),l===d.error?{type:l,error:new H(u,c.statusText,e),headers:c.headers}:{type:d.data,data:e,statusCode:c.status,headers:c.headers}}return l===d.error?{type:l,error:c}:c instanceof L?{type:d.deferred,deferredData:c}:{type:d.data,data:c}}function Y(e,t,r){let a=pe(e).toString(),n={signal:t};if(r){let{formMethod:e,formEncType:t,formData:a}=r;n.method=e.toUpperCase(),n.body="application/x-www-form-urlencoded"===t?G(a):a}return new Request(a,n)}function G(e){let t=new URLSearchParams;for(let[r,a]of e.entries())D("string"==typeof a,'File inputs are not supported with encType "application/x-www-form-urlencoded", please use "multipart/form-data" instead.'),t.append(r,a);return t}function V(e,t,r,a,n){let o,i={},s=null,l=!1,c={};return r.forEach(((r,d)=>{let u=t[d].route.id;if(D(!se(r),"Cannot handle redirect results in processLoaderData"),ie(r)){let t=Z(e,u),n=r.error;a&&(n=Object.values(a)[0],a=void 0),s=Object.assign(s||{},{[t.route.id]:n}),l||(l=!0,o=U(r.error)?r.error.status:500),r.headers&&(c[u]=r.headers)}else oe(r)?(n&&n.set(u,r.deferredData),i[u]=r.deferredData.data):(i[u]=r.data,null==r.statusCode||200===r.statusCode||l||(o=r.statusCode),r.headers&&(c[u]=r.headers))})),a&&(s=a),{loaderData:i,errors:s,statusCode:o||200,loaderHeaders:c}}function X(e,r,a,n,o,i,s,l){let{loaderData:c,errors:d}=V(r,a,n,o,l);for(let r=0;r<i.length;r++){let[a,,n]=i[r];D(void 0!==s&&void 0!==s[r],"Did not find corresponding fetcher result");let o=s[r];if(ie(o)){let r=Z(e.matches,n.route.id);d&&d[r.route.id]||(d=t({},d,{[r.route.id]:o.error})),e.fetchers.delete(a)}else{if(se(o))throw new Error("Unhandled fetcher revalidation redirect");if(oe(o))throw new Error("Unhandled fetcher deferred data");{let t={state:"idle",data:o.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};e.fetchers.set(a,t)}}}return{loaderData:c,errors:d}}function Q(e,r,a){let n=t({},r);return a.forEach((t=>{let a=t.route.id;void 0===r[a]&&void 0!==e[a]&&(n[a]=e[a])})),n}function Z(e,t){return(t?e.slice(0,e.findIndex((e=>e.route.id===t))+1):[...e]).reverse().find((e=>!0===e.route.hasErrorBoundary))||e[0]}function ee(e,t,r){let a=e.find((e=>e.index||!e.path||"/"===e.path))||{id:"__shim-"+t+"-route__"};return{matches:[{params:{},pathname:"",pathnameBase:"",route:a}],route:a,error:new H(t,r,null)}}function te(e){return ee(e,404,"Not Found")}function re(e){let t="string"==typeof e?e:ne(e);return console.warn("You're trying to submit to a route that does not have an action. To fix this, please add an `action` function to the route for ["+t+"]"),{type:d.error,error:new H(405,"Method Not Allowed","")}}function ae(e){for(let t=e.length-1;t>=0;t--){let r=e[t];if(se(r))return r}}function ne(e){return(e.pathname||"")+(e.search||"")}function oe(e){return e.type===d.deferred}function ie(e){return e.type===d.error}function se(e){return(e&&e.type)===d.redirect}function le(e){if(!(e instanceof Response))return!1;let t=e.status,r=e.headers.get("Location");return t>=300&&t<=399&&null!=r}async function ce(e,t,r,a,n,o){for(let i=0;i<r.length;i++){let s=r[i],l=t[i],c=e.find((e=>e.route.id===l.route.id)),d=null!=c&&!z(c,l)&&void 0!==(o&&o[l.route.id]);oe(s)&&(n||d)&&await de(s,a,n).then((e=>{e&&(r[i]=e||r[i])}))}}async function de(e,t,r){if(void 0===r&&(r=!1),!await e.deferredData.resolveData(t)){if(r)try{return{type:d.data,data:e.deferredData.unwrappedData}}catch(e){return{type:d.error,error:e}}return{type:d.data,data:e.deferredData.data}}}function ue(e){return new URLSearchParams(e).getAll("index").some((e=>""===e))}function he(e,t){let{route:r,pathname:a,params:n}=e;return{id:r.id,pathname:a,params:n,data:t[r.id],handle:r.handle}}function fe(e,t){let r="string"==typeof t?l(t).search:t.search;if(e[e.length-1].route.index&&ue(r||""))return e[e.length-1];let a=P(e);return a[a.length-1]}function pe(e){let t="undefined"!=typeof window&&void 0!==window.location?window.location.origin:"unknown://unknown",r="string"==typeof e?e:ne(e);return new URL(r,t)}e.AbortedDeferredError=j,e.ErrorResponse=H,e.IDLE_FETCHER=k,e.IDLE_NAVIGATION=_,e.UNSAFE_convertRoutesToDataRoutes=u,e.UNSAFE_getPathContributingMatches=P,e.createBrowserHistory=function(e){return void 0===e&&(e={}),c((function(e,t){let{pathname:r,search:a,hash:n}=e.location;return i("",{pathname:r,search:a,hash:n},t.state&&t.state.usr||null,t.state&&t.state.key||"default")}),(function(e,t){return"string"==typeof t?t:s(t)}),null,e)},e.createHashHistory=function(e){return void 0===e&&(e={}),c((function(e,t){let{pathname:r="/",search:a="",hash:n=""}=l(e.location.hash.substr(1));return i("",{pathname:r,search:a,hash:n},t.state&&t.state.usr||null,t.state&&t.state.key||"default")}),(function(e,t){let r=e.document.querySelector("base"),a="";if(r&&r.getAttribute("href")){let t=e.location.href,r=t.indexOf("#");a=-1===r?t:t.slice(0,r)}return a+"#"+("string"==typeof t?t:s(t))}),(function(e,t){n("/"===e.pathname.charAt(0),"relative pathnames are not supported in hash history.push("+JSON.stringify(t)+")")}),e)},e.createMemoryHistory=function(t){void 0===t&&(t={});let r,{initialEntries:a=["/"],initialIndex:o,v5Compat:l=!1}=t;r=a.map(((e,t)=>p(e,"string"==typeof e?null:e.state,0===t?"default":void 0)));let c=h(null==o?r.length-1:o),d=e.Action.Pop,u=null;function h(e){return Math.min(Math.max(e,0),r.length-1)}function f(){return r[c]}function p(e,t,a){void 0===t&&(t=null);let o=i(r?f().pathname:"/",e,t,a);return n("/"===o.pathname.charAt(0),"relative pathnames are not supported in memory history: "+JSON.stringify(e)),o}return{get index(){return c},get action(){return d},get location(){return f()},createHref:e=>"string"==typeof e?e:s(e),push(t,a){d=e.Action.Push;let n=p(t,a);c+=1,r.splice(c,r.length,n),l&&u&&u({action:d,location:n})},replace(t,a){d=e.Action.Replace;let n=p(t,a);r[c]=n,l&&u&&u({action:d,location:n})},go(t){d=e.Action.Pop,c=h(c+t),u&&u({action:d,location:f()})},listen:e=>(u=e,()=>{u=null})}},e.createPath=s,e.createRouter=function(r){D(r.routes.length>0,"You must provide a non-empty routes array to createRouter");let a=u(r.routes),n=null,o=new Set,l=null,c=null,d=null,f=!1,p=h(a,r.history.location,r.basename),m=null;if(null==p){let{matches:e,route:t,error:r}=te(a);p=e,m={[t.id]:r}}let g,v,y=!p.some((e=>e.route.loader))||null!=r.hydrationData,w={historyAction:r.history.action,location:r.history.location,matches:p,initialized:y,navigation:_,restoreScrollPosition:null,preventScrollReset:!1,revalidation:"idle",loaderData:r.hydrationData&&r.hydrationData.loaderData||{},actionData:r.hydrationData&&r.hydrationData.actionData||null,errors:r.hydrationData&&r.hydrationData.errors||m,fetchers:new Map},b=e.Action.Pop,E=!1,A=!1,R=!1,P=[],x=[],M=new Map,S=0,C=-1,T=new Map,j=new Set,L=new Map,O=new Map;function U(e){w=t({},w,e),o.forEach((e=>e(w)))}function W(a,n){var o;U(t({},null!=w.actionData&&null!=w.navigation.formMethod&&"loading"===w.navigation.state&&(null==(o=w.navigation.formAction)?void 0:o.split("?")[0])===a.pathname?{}:{actionData:null},n,n.loaderData?{loaderData:Q(w.loaderData,n.loaderData,n.matches||[])}:{},{historyAction:b,location:a,initialized:!0,navigation:_,revalidation:"idle",restoreScrollPosition:!w.navigation.formData&&ge(a,n.matches||w.matches),preventScrollReset:E})),A||b===e.Action.Pop||(b===e.Action.Push?r.history.push(a,a.state):b===e.Action.Replace&&r.history.replace(a,a.state)),b=e.Action.Pop,E=!1,A=!1,R=!1,P=[],x=[]}async function $(n,o,s){v&&v.abort(),v=null,b=n,A=!0===(s&&s.startUninterruptedRevalidation),function(e,t){if(l&&c&&d){let r=t.map((e=>he(e,w.loaderData))),a=c(e,r)||e.key;l[a]=d()}}(w.location,w.matches),E=!0===(s&&s.preventScrollReset);let u=s&&s.overrideNavigation,f=h(a,o,r.basename);if(!f){let{matches:e,route:t,error:r}=te(a);return me(),void W(o,{matches:e,loaderData:{},errors:{[t.id]:r}})}if(p=w.location,m=o,p.pathname===m.pathname&&p.search===m.search&&p.hash!==m.hash)return void W(o,{matches:f});var p,m;v=new AbortController;let y,T,H=Y(o,v.signal,s&&s.submission);if(s&&s.pendingError)T={[Z(f).route.id]:s.pendingError};else if(s&&s.submission){let r=await async function(r,a,n,o,s){let l;G(),U({navigation:t({state:"submitting",location:a},n)});let c=fe(o,a);if(c.route.action){if(l=await J("action",r,c,o,g.basename),r.signal.aborted)return{shortCircuited:!0}}else l=re(a);if(se(l)){let e=t({state:"loading",location:i(w.location,l.location)},n);return await z(l,e,s&&s.replace),{shortCircuited:!0}}if(ie(l)){let t=Z(o,c.route.id);return!0!==(s&&s.replace)&&(b=e.Action.Push),{pendingActionError:{[t.route.id]:l.error}}}if(oe(l))throw new Error("defer() is not supported in actions");return{pendingActionData:{[c.route.id]:l.data}}}(H,o,s.submission,f,{replace:s.replace});if(r.shortCircuited)return;y=r.pendingActionData,T=r.pendingActionError,u=t({state:"loading",location:o},s.submission)}let{shortCircuited:_,loaderData:k,errors:N}=await async function(e,r,a,n,o,i,s,l){let c=n;if(!c){c={state:"loading",location:r,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0}}let[d,u]=B(w,a,o,r,R,P,x,s,l,L);if(me((e=>!(a&&a.some((t=>t.route.id===e)))||d&&d.some((t=>t.route.id===e)))),0===d.length&&0===u.length)return W(r,{matches:a,loaderData:Q(w.loaderData,{},a),errors:l||null,actionData:s||null}),{shortCircuited:!0};A||(u.forEach((e=>{let[t]=e,r=w.fetchers.get(t),a={state:"loading",data:r&&r.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};w.fetchers.set(t,a)})),U(t({navigation:c,actionData:s||w.actionData||null},u.length>0?{fetchers:new Map(w.fetchers)}:{})));C=++S,u.forEach((e=>{let[t]=e;return M.set(t,v)}));let{results:h,loaderResults:f,fetcherResults:p}=await K(w.matches,a,d,u,e);if(e.signal.aborted)return{shortCircuited:!0};u.forEach((e=>{let[t]=e;return M.delete(t)}));let m=ae(h);if(m){let e=F(w,m);return await z(m,e,i),{shortCircuited:!0}}let{loaderData:g,errors:y}=X(w,a,d,f,l,u,p,O);O.forEach(((e,t)=>{e.subscribe((r=>{(r||e.done)&&O.delete(t)}))})),function(){let e=[];for(let t of j){let r=w.fetchers.get(t);D(r,"Expected fetcher: "+t),"loading"===r.state&&(j.delete(t),e.push(t))}le(e)}();let b=ue(C);return t({loaderData:g,errors:y},b||u.length>0?{fetchers:new Map(w.fetchers)}:{})}(H,o,f,u,s&&s.submission,s&&s.replace,y,T);_||(v=null,W(o,{matches:f,loaderData:k,errors:N}))}function I(e){return w.fetchers.get(e)||k}async function z(t,r,a){t.revalidate&&(R=!0),D(r.location,"Expected a location on the redirect navigation"),v=null;let n=!0===a?e.Action.Replace:e.Action.Push;await $(n,r.location,{overrideNavigation:r})}async function K(e,t,r,a,n){let o=await Promise.all([...r.map((e=>J("loader",n,e,t,g.basename))),...a.map((e=>{let[,t,r,a]=e;return J("loader",Y(t,n.signal),r,a,g.basename)}))]),i=o.slice(0,r.length),s=o.slice(r.length);return await Promise.all([ce(e,r,i,n.signal,!1,w.loaderData),ce(e,a.map((e=>{let[,,t]=e;return t})),s,n.signal,!0)]),{results:o,loaderResults:i,fetcherResults:s}}function G(){R=!0,P.push(...me()),L.forEach(((e,t)=>{M.has(t)&&(x.push(t),ne(t))}))}function V(e,t,r){let a=Z(w.matches,t);ee(e),U({errors:{[a.route.id]:r},fetchers:new Map(w.fetchers)})}function ee(e){M.has(e)&&ne(e),L.delete(e),T.delete(e),j.delete(e),w.fetchers.delete(e)}function ne(e){let t=M.get(e);D(t,"Expected fetch controller: "+e),t.abort(),M.delete(e)}function le(e){for(let t of e){let e={state:"idle",data:I(t).data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};w.fetchers.set(t,e)}}function ue(e){let t=[];for(let[r,a]of T)if(a<e){let e=w.fetchers.get(r);D(e,"Expected fetcher: "+r),"loading"===e.state&&(ne(r),T.delete(r),t.push(r))}return le(t),t.length>0}function me(e){let t=[];return O.forEach(((r,a)=>{e&&!e(a)||(r.cancel(),t.push(a),O.delete(a))})),t}function ge(e,t){if(l&&c&&d){let r=t.map((e=>he(e,w.loaderData))),a=c(e,r)||e.key,n=l[a];if("number"==typeof n)return n}return null}return g={get basename(){return r.basename},get state(){return w},get routes(){return a},initialize:function(){return n=r.history.listen((e=>{let{action:t,location:r}=e;return $(t,r)})),w.initialized||$(e.Action.Pop,w.location),g},subscribe:function(e){return o.add(e),()=>o.delete(e)},enableScrollRestoration:function(e,t,r){if(l=e,d=t,c=r||(e=>e.key),!f&&w.navigation===_){f=!0;let e=ge(w.location,w.matches);null!=e&&U({restoreScrollPosition:e})}return()=>{l=null,d=null,c=null}},navigate:async function(a,n){if("number"==typeof a)return void r.history.go(a);let{path:o,submission:l,error:c}=q(a,n),d=i(w.location,o,n&&n.state),u=pe(s(d));d=t({},d,{pathname:u.pathname,search:u.search,hash:u.hash});let h=!0===(n&&n.replace)||null!=l?e.Action.Replace:e.Action.Push,f=n&&"preventScrollReset"in n?!0===n.preventScrollReset:void 0;return await $(h,d,{submission:l,pendingError:c,preventScrollReset:f,replace:n&&n.replace})},fetch:function(e,n,o,s){if(N)throw new Error("router.fetch() was called during the server render, but it shouldn't be. You are likely calling a useFetcher() method in the body of your component. Try moving it to a useEffect or a callback.");M.has(e)&&ne(e);let l=h(a,o,r.basename);if(!l)return void V(e,n,new H(404,"Not Found",null));let{path:c,submission:d}=q(o,s,!0),u=fe(l,c);d?async function(e,n,o,s,l,c){if(G(),L.delete(e),!s.route.action){let{error:t}=re(o);return void V(e,n,t)}let d=w.fetchers.get(e),u=t({state:"submitting"},c,{data:d&&d.data});w.fetchers.set(e,u),U({fetchers:new Map(w.fetchers)});let f=new AbortController,p=Y(o,f.signal,c);M.set(e,f);let m=await J("action",p,s,l,g.basename);if(p.signal.aborted)return void(M.get(e)===f&&M.delete(e));if(se(m)){M.delete(e),j.add(e);let r=t({state:"loading"},c,{data:void 0});w.fetchers.set(e,r),U({fetchers:new Map(w.fetchers)});let a=t({state:"loading",location:i(w.location,m.location)},c);return void await z(m,a)}if(ie(m))return void V(e,n,m.error);oe(m)&&D(!1,"defer() is not supported in actions");let y=w.navigation.location||w.location,E=Y(y,f.signal),A="idle"!==w.navigation.state?h(a,w.navigation.location,r.basename):w.matches;D(A,"Didn't find any matches after fetcher action");let H=++S;T.set(e,H);let _=t({state:"loading",data:m.data},c);w.fetchers.set(e,_);let[k,N]=B(w,A,c,y,R,P,x,{[s.route.id]:m.data},void 0,L);N.filter((t=>{let[r]=t;return r!==e})).forEach((e=>{let[t]=e,r=w.fetchers.get(t),a={state:"loading",data:r&&r.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};w.fetchers.set(t,a),M.set(t,f)})),U({fetchers:new Map(w.fetchers)});let{results:$,loaderResults:q,fetcherResults:I}=await K(w.matches,A,k,N,E);if(f.signal.aborted)return;T.delete(e),M.delete(e),N.forEach((e=>{let[t]=e;return M.delete(t)}));let Z=ae($);if(Z){let e=F(w,Z);return void await z(Z,e)}let{loaderData:ee,errors:te}=X(w,w.matches,k,q,void 0,N,I,O),ne={state:"idle",data:m.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};w.fetchers.set(e,ne);let le=ue(H);"loading"===w.navigation.state&&H>C?(D(b,"Expected pending action"),v&&v.abort(),W(w.navigation.location,{matches:A,loaderData:ee,errors:te,fetchers:new Map(w.fetchers)})):(U(t({errors:te,loaderData:Q(w.loaderData,ee,A)},le?{fetchers:new Map(w.fetchers)}:{})),R=!1)}(e,n,c,u,l,d):(L.set(e,[c,u,l]),async function(e,t,r,a,n){let o=w.fetchers.get(e),i={state:"loading",formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0,data:o&&o.data};w.fetchers.set(e,i),U({fetchers:new Map(w.fetchers)});let s=new AbortController,l=Y(r,s.signal);M.set(e,s);let c=await J("loader",l,a,n,g.basename);oe(c)&&(c=await de(c,l.signal,!0)||c);M.get(e)===s&&M.delete(e);if(l.signal.aborted)return;if(se(c)){let e=F(w,c);return void await z(c,e)}if(ie(c)){let r=Z(w.matches,t);return w.fetchers.delete(e),void U({fetchers:new Map(w.fetchers),errors:{[r.route.id]:c.error}})}D(!oe(c),"Unhandled fetcher deferred data");let d={state:"idle",data:c.data,formMethod:void 0,formAction:void 0,formEncType:void 0,formData:void 0};w.fetchers.set(e,d),U({fetchers:new Map(w.fetchers)})}(e,n,c,u,l))},revalidate:function(){G(),U({revalidation:"loading"}),"submitting"!==w.navigation.state&&("idle"!==w.navigation.state?$(b||w.historyAction,w.navigation.location,{overrideNavigation:w.navigation}):$(w.historyAction,w.location,{startUninterruptedRevalidation:!0}))},createHref:e=>r.history.createHref(e),getFetcher:I,deleteFetcher:ee,dispose:function(){n&&n(),o.clear(),v&&v.abort(),w.fetchers.forEach(((e,t)=>ee(t)))},_internalFetchControllers:M,_internalActiveDeferreds:O},g},e.defer=function(e){return new L(e)},e.generatePath=function(e,t){return void 0===t&&(t={}),e.replace(/:(\w+)/g,((e,r)=>(D(null!=t[r],'Missing ":'+r+'" param'),t[r]))).replace(/(\/?)\*/,((e,r,a,n)=>null==t["*"]?"/*"===n?"/":"":""+r+t["*"]))},e.getStaticContextFromError=function(e,r,a){return t({},r,{statusCode:500,errors:{[r._deepestRenderedBoundaryId||e[0].id]:a}})},e.getToPathname=function(e){return""===e||""===e.pathname?"/":"string"==typeof e?l(e).pathname:e.pathname},e.invariant=D,e.isRouteErrorResponse=U,e.joinPaths=M,e.json=function(e,r){void 0===r&&(r={});let a="number"==typeof r?{status:r}:r,n=new Headers(a.headers);return n.has("Content-Type")||n.set("Content-Type","application/json; charset=utf-8"),new Response(JSON.stringify(e),t({},a,{headers:n}))},e.matchPath=y,e.matchRoutes=h,e.normalizePathname=S,e.parsePath=l,e.redirect=function(e,r){void 0===r&&(r=302);let a=r;"number"==typeof a?a={status:a}:void 0===a.status&&(a.status=302);let n=new Headers(a.headers);return n.set("Location",e),new Response(null,t({},a,{headers:n}))},e.resolvePath=A,e.resolveTo=x,e.stripBasename=b,e.unstable_createStaticHandler=function(e){D(e.length>0,"You must provide a non-empty routes array to unstable_createStaticHandler");let r=u(e);async function a(e,r,a,i){D(e.signal,"query()/queryRoute() requests must contain an AbortController signal");try{if(W.has(e.method)){let s=await async function(e,r,a,i){let s;if(a.route.action){if(s=await J("action",e,a,r,void 0,!0,i),e.signal.aborted){throw new Error((i?"queryRoute":"query")+"() call aborted")}}else{let t=ne(new URL(e.url));if(i)throw o(null,{status:405,statusText:"Method Not Allowed"});s=re(t)}if(se(s))throw new Response(null,{status:s.status,headers:{Location:s.location}});if(oe(s))throw new Error("defer() is not supported in actions");if(i){if(ie(s)){return{matches:[a],loaderData:{},actionData:null,errors:{[Z(r,a.route.id).route.id]:s.error},statusCode:500,loaderHeaders:{},actionHeaders:{}}}return{matches:[a],loaderData:{},actionData:{[a.route.id]:s.data},errors:null,statusCode:200,loaderHeaders:{},actionHeaders:{}}}if(ie(s)){let o=Z(r,a.route.id);return t({},await n(e,r,void 0,{[o.route.id]:s.error}),{statusCode:U(s.error)?s.error.status:500,actionData:null,actionHeaders:t({},s.headers?{[a.route.id]:s.headers}:{})})}return t({},await n(e,r),s.statusCode?{statusCode:s.statusCode}:{},{actionData:{[a.route.id]:s.data},actionHeaders:t({},s.headers?{[a.route.id]:s.headers}:{})})}(e,a,i||fe(a,r),null!=i);return s}let s=await n(e,a,i);return s instanceof Response?s:t({},s,{actionData:null,actionHeaders:{}})}catch(e){if((s=e)&&s.response instanceof Response&&(s.type===d.data||d.error)){if(e.type===d.error&&!le(e.response))throw e.response;return e.response}if(le(e))return e;throw e}var s}async function n(e,r,a,n){let o=null!=a,i=(a?[a]:I(r,Object.keys(n||{})[0])).filter((e=>e.route.loader));if(0===i.length)return{matches:r,loaderData:{},errors:n||null,statusCode:200,loaderHeaders:{}};let s=await Promise.all([...i.map((t=>J("loader",e,t,r,void 0,!0,o)))]);if(e.signal.aborted){throw new Error((o?"queryRoute":"query")+"() call aborted")}return s.forEach((e=>{oe(e)&&e.deferredData.cancel()})),t({},V(r,i,s,n),{matches:r})}function o(e,r){return new Response(e,t({},r,{headers:t({},r.headers,{"X-Remix-Router-Error":"yes"})}))}return{dataRoutes:r,query:async function(e){let n=i("",s(new URL(e.url)),null,"default"),o=h(r,n);if(!$.has(e.method)){let{matches:e,route:t,error:a}=function(e){return ee(e,405,"Method Not Allowed")}(r);return{location:n,matches:e,loaderData:{},actionData:null,errors:{[t.id]:a},statusCode:a.status,loaderHeaders:{},actionHeaders:{}}}if(!o){let{matches:e,route:t,error:a}=te(r);return{location:n,matches:e,loaderData:{},actionData:null,errors:{[t.id]:a},statusCode:a.status,loaderHeaders:{},actionHeaders:{}}}let l=await a(e,n,o);return l instanceof Response?l:t({location:n},l)},queryRoute:async function(e,t){let n=i("",s(new URL(e.url)),null,"default"),l=h(r,n);if(!$.has(e.method))throw o(null,{status:405,statusText:"Method Not Allowed"});if(!l)throw o(null,{status:404,statusText:"Not Found"});let c=t?l.find((e=>e.route.id===t)):fe(l,n);if(!c)throw o(null,{status:404,statusText:"Not Found"});let d=await a(e,n,l,c);if(d instanceof Response)return d;let u=d.errors?Object.values(d.errors)[0]:void 0;if(void 0!==u)throw u;let f=[d.actionData,d.loaderData].find((e=>e));return Object.values(f||{})[0]}}},e.warning=E,Object.defineProperty(e,"__esModule",{value:!0})}));
12
+ //# sourceMappingURL=router.umd.min.js.map