@tanstack/react-router 0.0.1-beta.20 → 0.0.1-beta.200
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/LICENSE +21 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -19
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/awaited.js +45 -0
- package/build/cjs/awaited.js.map +1 -0
- package/build/cjs/index.js +66 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/react.js +642 -0
- package/build/cjs/react.js.map +1 -0
- package/build/cjs/scroll-restoration.js +56 -0
- package/build/cjs/scroll-restoration.js.map +1 -0
- package/build/esm/index.js +556 -2798
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +312 -37
- package/build/types/awaited.d.ts +8 -0
- package/build/types/index.d.ts +4 -105
- package/build/types/react.d.ts +200 -0
- package/build/types/scroll-restoration.d.ts +3 -0
- package/build/umd/index.development.js +2528 -2424
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +35 -4
- package/build/umd/index.production.js.map +1 -1
- package/package.json +11 -10
- package/src/awaited.tsx +40 -0
- package/src/index.tsx +5 -660
- package/src/react.tsx +1228 -0
- package/src/scroll-restoration.tsx +27 -0
- package/build/cjs/react-router/src/index.js +0 -443
- package/build/cjs/react-router/src/index.js.map +0 -1
- package/build/cjs/router-core/build/esm/index.js +0 -2523
- package/build/cjs/router-core/build/esm/index.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router
|
|
2
|
+
* @tanstack/react-router/src/index.tsx
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) TanStack
|
|
5
5
|
*
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("
|
|
11
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("use-sync-external-store/shim/with-selector"),require("react")):"function"==typeof define&&define.amd?define(["exports","use-sync-external-store/shim/with-selector","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ReactRouter={},t.withSelector,t.React)}(this,(function(t,e,r){"use strict";function o(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,o.get?o:{enumerable:!0,get:function(){return t[r]}})}})),e.default=t,Object.freeze(e)}var s=o(r);
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* @tanstack/store/src/index.ts
|
|
14
14
|
*
|
|
15
15
|
* Copyright (c) TanStack
|
|
16
16
|
*
|
|
@@ -18,5 +18,36 @@
|
|
|
18
18
|
* LICENSE.md file in the root directory of this source tree.
|
|
19
19
|
*
|
|
20
20
|
* @license MIT
|
|
21
|
-
*/function l(){return l=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},l.apply(this,arguments)}!function(t){t.Pop="POP",t.Push="PUSH",t.Replace="REPLACE"}(o||(o={}));var c="beforeunload",u="popstate";function h(t){void 0===t&&(t={});var e=t.window,n=void 0===e?document.defaultView:e,a=n.history;function r(){var t=n.location,e=t.pathname,o=t.search,r=t.hash,i=a.state||{};return[i.idx,{pathname:e,search:o,hash:r,state:i.usr||null,key:i.key||"default"}]}var i=null;n.addEventListener(u,(function(){if(i)b.call(i),i=null;else{var t=o.Pop,e=r(),n=e[0],a=e[1];if(b.length){if(null!=n){var s=d-n;s&&(i={action:t,location:a,retry:function(){S(-1*s)}},S(s))}}else x(t)}}));var s=o.Pop,h=r(),d=h[0],f=h[1],_=m(),b=m();function P(t){return"string"==typeof t?t:g(t)}function w(t,e){return void 0===e&&(e=null),l({pathname:f.pathname,hash:"",search:""},"string"==typeof t?y(t):t,{state:e,key:v()})}function E(t,e){return[{usr:t.state,key:t.key,idx:e},P(t)]}function R(t,e,n){return!b.length||(b.call({action:t,location:e,retry:n}),!1)}function x(t){s=t;var e=r();d=e[0],f=e[1],_.call({action:s,location:f})}function S(t){a.go(t)}null==d&&(d=0,a.replaceState(l({},a.state,{idx:d}),""));var I={get action(){return s},get location(){return f},createHref:P,push:function t(e,r){var i=o.Push,s=w(e,r);if(R(i,s,(function(){t(e,r)}))){var l=E(s,d+1),c=l[0],u=l[1];try{a.pushState(c,"",u)}catch(t){n.location.assign(u)}x(i)}},replace:function t(e,n){var r=o.Replace,i=w(e,n);if(R(r,i,(function(){t(e,n)}))){var s=E(i,d),l=s[0],c=s[1];a.replaceState(l,"",c),x(r)}},go:S,back:function(){S(-1)},forward:function(){S(1)},listen:function(t){return _.push(t)},block:function(t){var e=b.push(t);return 1===b.length&&n.addEventListener(c,p),function(){e(),b.length||n.removeEventListener(c,p)}}};return I}function d(t){void 0===t&&(t={});var e=t,n=e.initialEntries,a=void 0===n?["/"]:n,r=e.initialIndex,i=a.map((function(t){return l({pathname:"/",search:"",hash:"",state:null,key:v()},"string"==typeof t?y(t):t)})),s=f(null==r?i.length-1:r,0,i.length-1),c=o.Pop,u=i[s],h=m(),d=m();function p(t,e){return void 0===e&&(e=null),l({pathname:u.pathname,search:"",hash:""},"string"==typeof t?y(t):t,{state:e,key:v()})}function _(t,e,n){return!d.length||(d.call({action:t,location:e,retry:n}),!1)}function b(t,e){c=t,u=e,h.call({action:c,location:u})}function P(t){var e=f(s+t,0,i.length-1),n=o.Pop,a=i[e];_(n,a,(function(){P(t)}))&&(s=e,b(n,a))}var w={get index(){return s},get action(){return c},get location(){return u},createHref:function(t){return"string"==typeof t?t:g(t)},push:function t(e,n){var a=o.Push,r=p(e,n);_(a,r,(function(){t(e,n)}))&&(s+=1,i.splice(s,i.length,r),b(a,r))},replace:function t(e,n){var a=o.Replace,r=p(e,n);_(a,r,(function(){t(e,n)}))&&(i[s]=r,b(a,r))},go:P,back:function(){P(-1)},forward:function(){P(1)},listen:function(t){return h.push(t)},block:function(t){return d.push(t)}};return w}function f(t,e,n){return Math.min(Math.max(t,e),n)}function p(t){t.preventDefault(),t.returnValue=""}function m(){var t=[];return{get length(){return t.length},push:function(e){return t.push(e),function(){t=t.filter((function(t){return t!==e}))}},call:function(e){t.forEach((function(t){return t&&t(e)}))}}}function v(){return Math.random().toString(36).substr(2,8)}function g(t){var e=t.pathname,n=void 0===e?"/":e,a=t.search,o=void 0===a?"":a,r=t.hash,i=void 0===r?"":r;return o&&"?"!==o&&(n+="?"===o.charAt(0)?o:"?"+o),i&&"#"!==i&&(n+="#"===i.charAt(0)?i:"#"+i),n}function y(t){var e={};if(t){var n=t.indexOf("#");n>=0&&(e.hash=t.substr(n),t=t.substr(0,n));var a=t.indexOf("?");a>=0&&(e.search=t.substr(a),t=t.substr(0,a)),t&&(e.pathname=t)}return e}function _(t,e){if(!t)throw new Error("Invariant failed")}function b(t,e){if(t===e)return t;const n=Array.isArray(t)&&Array.isArray(e);if(n||P(t)&&P(e)){const a=n?t.length:Object.keys(t).length,o=n?e:Object.keys(e),r=o.length,i=n?[]:{};let s=0;for(let a=0;a<r;a++){const r=n?a:o[a];i[r]=b(t[r],e[r]),i[r]===t[r]&&s++}return a===r&&s===a?t:i}return e}function P(t){if(!w(t))return!1;const e=t.constructor;if(void 0===e)return!0;const n=e.prototype;return!!w(n)&&!!n.hasOwnProperty("isPrototypeOf")}function w(t){return"[object Object]"===Object.prototype.toString.call(t)}function E(t){return t[t.length-1]}function R(t,e){if(t){"undefined"!=typeof console&&console.warn(e);try{throw new Error(e)}catch(t){}}return!0}function x(t,e){return"function"==typeof t?t(e):t}function S(t,e){return e.reduce(((e,n)=>(e[n]=t[n],e)),{})}function I(t){return M(t.filter(Boolean).join("/"))}function M(t){return t.replace(/\/{2,}/g,"/")}function A(t){return"/"===t?t:t.replace(/^\/{1,}/,"")}function L(t){return"/"===t?t:t.replace(/\/{1,}$/,"")}function C(t){return L(A(t))}function k(t,e,n){e=e.replace(new RegExp("^"+t),"/"),n=n.replace(new RegExp("^"+t),"/");let a=O(e);const o=O(n);o.forEach(((t,e)=>{if("/"===t.value)e?e===o.length-1&&a.push(t):a=[t];else if(".."===t.value){var n;a.length>1&&"/"===(null==(n=E(a))?void 0:n.value)&&a.pop(),a.pop()}else{if("."===t.value)return;a.push(t)}}));return M(I([t,...a.map((t=>t.value))]))}function O(t){if(!t)return[];const e=[];if("/"===(t=M(t)).slice(0,1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),!t)return e;const n=t.split("/").filter(Boolean);return e.push(...n.map((t=>t.startsWith("*")?{type:"wildcard",value:t}:":"===t.charAt(0)?{type:"param",value:t}:{type:"pathname",value:t}))),"/"===t.slice(-1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),e}function D(t,e,n){return I(O(t).map((t=>{return"*"!==t.value||n?"param"===t.type?null!=(a=e[t.value.substring(1)])?a:"":t.value:"";var a})))}function j(t,e){const n=F(t,e);if(!e.to||n)return null!=n?n:{}}function F(t,e){var n;const a=O(t),o=O(""+(null!=(n=e.to)?n:"*")),r={};return(()=>{for(let t=0;t<Math.max(a.length,o.length);t++){const n=a[t],i=o[t],s=t===o.length-1,l=t===a.length-1;if(i){if("wildcard"===i.type)return!(null==n||!n.value)&&(r["*"]=I(a.slice(t).map((t=>t.value))),!0);if("pathname"===i.type){if("/"===i.value&&(null==n||!n.value))return!0;if(n)if(e.caseSensitive){if(i.value!==n.value)return!1}else if(i.value.toLowerCase()!==n.value.toLowerCase())return!1}if(!n)return!1;if("param"===i.type){if("/"===(null==n?void 0:n.value))return!1;n.value.startsWith(":")||(r[i.value.substring(1)]=n.value)}}if(s&&!l)return!!e.fuzzy}return!0})()?r:void 0}function T(t,e){var n,a,o,r="";for(n in t)if(void 0!==(o=t[n]))if(Array.isArray(o))for(a=0;a<o.length;a++)r&&(r+="&"),r+=encodeURIComponent(n)+"="+encodeURIComponent(o[a]);else r&&(r+="&"),r+=encodeURIComponent(n)+"="+encodeURIComponent(o);return(e||"")+r}function N(t){if(!t)return"";var e=decodeURIComponent(t);return"false"!==e&&("true"===e||("0"===e.charAt(0)?e:0*+e==0?+e:e))}function B(t){for(var e,n,a={},o=t.split("&");e=o.shift();)void 0!==a[n=(e=e.split("=")).shift()]?a[n]=[].concat(a[n],N(e.shift())):a[n]=N(e.shift());return a}function U(){return U=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},U.apply(this,arguments)}function H(t,e,n,a){const{id:o,routeId:r,path:i,fullPath:s}=t,l=a.state.actions[o]||(a.state.actions[o]={submissions:[],submit:async(t,e)=>{var n;if(!u)return;const o=null==(n=null==e?void 0:e.invalidate)||n;null!=e&&e.multi||(l.submissions=l.submissions.filter((t=>t.isMulti)));const r={submittedAt:Date.now(),status:"pending",submission:t,isMulti:!(null==e||!e.multi)};l.current=r,l.latest=r,l.submissions.push(r),a.notify();try{const e=await(null==u.options.action?void 0:u.options.action(t));return r.data=e,o&&(a.invalidateRoute({to:".",fromCurrent:!0}),await a.reload()),r.status="success",e}catch(t){console.error(t),r.error=t,r.status="error"}finally{a.notify()}}},a.state.actions[o]),c=a.state.loaders[o]||(a.state.loaders[o]={pending:[],fetch:async t=>{if(!u)return;const e={loadedAt:Date.now(),loaderContext:t};c.current=e,c.latest=e,c.pending.push(e),a.notify();try{return await(null==u.options.loader?void 0:u.options.loader(t))}finally{c.pending=c.pending.filter((t=>t!==e)),a.notify()}}},a.state.loaders[o]);let u={routeId:o,routeRouteId:r,routePath:i,fullPath:s,options:e,router:a,childRoutes:void 0,parentRoute:n,action:l,loader:c,buildLink:t=>a.buildLink(U({},t,{from:s})),navigate:t=>a.navigate(U({},t,{from:s})),matchRoute:(t,e)=>a.matchRoute(U({},t,{from:s}),e)};return null==a.options.createRoute||a.options.createRoute({router:a,route:u}),u}const z="__root__",G=["component","errorComponent","pendingComponent"];function W(t,e,n){const a=U({},e,n,{router:t,routeSearch:{},search:{},childMatches:[],status:"idle",routeLoaderData:{},loaderData:{},isFetching:!1,isInvalid:!1,invalidAt:1/0,getIsInvalid:()=>{const t=Date.now();return a.isInvalid||a.invalidAt<t},__:{abortController:new AbortController,latestId:"",resolve:()=>{},notify:()=>{a.__.resolve(),a.router.notify()},validate:()=>{var e,n;const o=null!=(e=null==(n=a.parentMatch)?void 0:n.search)?e:t.location.search;try{var r;const t=a.routeSearch,e="object"==typeof a.options.validateSearch?a.options.validateSearch.parse:a.options.validateSearch;let n=b(t,null!=(r=null==e?void 0:e(o))?r:{});t!==n&&(a.isInvalid=!0),a.routeSearch=n,a.search=b(o,U({},o,n)),G.map((async t=>{const e=a.options[t];"function"!=typeof a.__[t]&&(a.__[t]=e)}))}catch(t){console.error(t);const e=new Error("Invalid search params found",{cause:t});return e.code="INVALID_SEARCH_PARAMS",a.status="error",void(a.error=e)}}},cancel:()=>{var t;null==(t=a.__.abortController)||t.abort()},invalidate:()=>{a.isInvalid=!0},hasLoaders:()=>!(!e.options.loader&&!G.some((t=>{var n;return null==(n=e.options[t])?void 0:n.preload}))),load:async e=>{const n=Date.now(),o=null!=e&&e.preload?Math.max(null==e?void 0:e.maxAge,null==e?void 0:e.gcMaxAge):0;if(null!=e&&e.preload&&o>0){if(t.state.matches.find((t=>t.matchId===a.matchId)))return;t.matchCache[a.matchId]={gc:n+e.gcMaxAge,match:a}}if("success"===a.status&&a.getIsInvalid()||"error"===a.status||"idle"===a.status){const t=null!=e&&e.preload?null==e?void 0:e.maxAge:void 0;await a.fetch({maxAge:t})}},fetch:async e=>{const n=""+Date.now()+Math.random();a.__.latestId=n;const o=async()=>{if(n!==a.__.latestId)return new Promise((()=>{}))};"idle"===a.status&&(a.status="loading"),a.isInvalid=!1,a.__.loadPromise=new Promise((async n=>{a.isFetching=!0,a.__.resolve=n,a.__.componentsPromise=(async()=>{await Promise.all(G.map((async e=>{var n;const o=a.options[e];null!=(n=a.__[e])&&n.preload&&(a.__[e]=await t.options.loadComponent(o))})))})(),a.__.dataPromise=Promise.resolve().then((async()=>{try{var n,r,i;if(a.options.loader){const e=await t.loadMatchData(a);await o(),a.routeLoaderData=b(a.routeLoaderData,e)}return a.error=void 0,a.status="success",a.updatedAt=Date.now(),a.invalidAt=a.updatedAt+(null!=(n=null!=(r=null!=(i=null==e?void 0:e.maxAge)?i:a.options.loaderMaxAge)?r:t.options.defaultLoaderMaxAge)?n:0),a.routeLoaderData}catch(t){throw await o(),a.error=t,a.status="error",a.updatedAt=Date.now(),t}}));const r=async()=>{await o(),a.isFetching=!1,delete a.__.loadPromise,a.__.notify()};try{await Promise.all([a.__.componentsPromise,a.__.dataPromise.catch((()=>{}))]),r()}catch(t){r()}})),await a.__.loadPromise,await o()}});return a.hasLoaders()||(a.status="success"),a}const q=V(JSON.parse),K=J(JSON.stringify);function V(t){return e=>{"?"===e.substring(0,1)&&(e=e.substring(1));let n=B(e);for(let e in n){const a=n[e];if("string"==typeof a)try{n[e]=t(a)}catch(t){}}return n}}function J(t){return e=>{(e=U({},e))&&Object.keys(e).forEach((n=>{const a=e[n];if(void 0===a||void 0===a)delete e[n];else if(a&&"object"==typeof a&&null!==a)try{e[n]=t(a)}catch(t){}}));const n=T(e).toString();return n?"?"+n:""}}var X;const $="undefined"==typeof window||!(null!=(X=window.document)&&X.createElement);function Q(){return{status:"idle",location:null,matches:[],actions:{},loaders:{},lastUpdated:Date.now(),isFetching:!1,isPreloading:!1}}function Y(t){var e,n;const a=(null==t?void 0:t.history)||($?d():h()),o=U({defaultLoaderGcMaxAge:3e5,defaultLoaderMaxAge:0,defaultPreloadMaxAge:2e3,defaultPreloadDelay:50},t,{stringifySearch:null!=(e=null==t?void 0:t.stringifySearch)?e:K,parseSearch:null!=(n=null==t?void 0:t.parseSearch)?n:q});let r={types:void 0,history:a,options:o,listeners:[],basepath:"",routeTree:void 0,routesById:{},location:void 0,navigationPromise:Promise.resolve(),resolveNavigation:()=>{},matchCache:{},state:Q(),reset:()=>{r.state=Q(),r.notify()},startedLoadingAt:Date.now(),subscribe:t=>(r.listeners.push(t),()=>{r.listeners=r.listeners.filter((e=>e!==t))}),getRoute:t=>r.routesById[t],notify:()=>{const t="loading"===r.state.status||r.state.matches.some((t=>t.isFetching)),e=Object.values(r.matchCache).some((t=>t.match.isFetching&&!r.state.matches.find((e=>e.matchId===t.match.matchId))));r.state.isFetching===t&&r.state.isPreloading===e||(r.state=U({},r.state,{isFetching:t,isPreloading:e})),Z(r.state.matches),r.listeners.forEach((t=>t(r)))},dehydrateState:()=>U({},S(r.state,["status","location","lastUpdated"]),{matches:r.state.matches.map((t=>S(t,["matchId","status","routeLoaderData","loaderData","isInvalid","invalidAt"])))}),hydrateState:t=>{const e=r.matchRoutes(r.location.pathname,{strictParseParams:!0});e.forEach(((e,n)=>{const a=t.matches[n];_(a),Object.assign(e,a)})),e.forEach((t=>t.__.validate())),r.state=U({},r.state,t,{matches:e})},mount:()=>{const t=r.__.buildLocation({to:".",search:!0,hash:!0});t.href!==r.location.href&&r.__.commitLocation(t,!0),r.state.matches.length||r.load();const e=r.history.listen((t=>{r.load(r.__.parseLocation(t.location,r.location))}));return!$&&window.addEventListener&&(window.addEventListener("visibilitychange",r.onFocus,!1),window.addEventListener("focus",r.onFocus,!1)),()=>{e(),!$&&window.removeEventListener&&(window.removeEventListener("visibilitychange",r.onFocus),window.removeEventListener("focus",r.onFocus))}},onFocus:()=>{r.load()},update:t=>{const e=(null==t?void 0:t.history)!==r.history;r.location&&!e||(null!=t&&t.history&&(r.history=t.history),r.location=r.__.parseLocation(r.history.location),r.state.location=r.location),Object.assign(r.options,t);const{basepath:n,routeConfig:a}=r.options;return r.basepath=M("/"+(null!=n?n:"")),a&&(r.routesById={},r.routeTree=r.__.buildRouteTree(a)),r},cancelMatches:()=>{var t,e;[...r.state.matches,...null!=(t=null==(e=r.state.pending)?void 0:e.matches)?t:[]].forEach((t=>{t.cancel()}))},load:async t=>{const e=Math.random();r.startedLoadingAt=e,t&&(r.location=t),r.cancelMatches();const n=r.matchRoutes(r.location.pathname,{strictParseParams:!0});if("undefined"!=typeof document?r.state=U({},r.state,{pending:{matches:n,location:r.location},status:"loading"}):r.state=U({},r.state,{matches:n,location:r.location,status:"loading"}),r.notify(),await r.loadMatches(n),r.startedLoadingAt!==e)return r.navigationPromise;const a=r.state.matches,o=[],i=[];a.forEach((t=>{n.find((e=>e.matchId===t.matchId))?i.push(t):o.push(t)}));const s=n.filter((t=>!a.find((e=>e.matchId===t.matchId)))),l=Date.now();o.forEach((t=>{var e,n,a,o;null==t.__.onExit||t.__.onExit({params:t.params,search:t.routeSearch}),"error"!==t.status||t.isFetching||(t.status="idle",t.error=void 0);const i=Math.max(null!=(e=null!=(n=t.options.loaderGcMaxAge)?n:r.options.defaultLoaderGcMaxAge)?e:0,null!=(a=null!=(o=t.options.loaderMaxAge)?o:r.options.defaultLoaderMaxAge)?a:0);i>0&&(r.matchCache[t.matchId]={gc:i==1/0?Number.MAX_SAFE_INTEGER:l+i,match:t})})),i.forEach((t=>{null==t.options.onTransition||t.options.onTransition({params:t.params,search:t.routeSearch})})),s.forEach((t=>{t.__.onExit=null==t.options.onMatch?void 0:t.options.onMatch({params:t.params,search:t.search}),delete r.matchCache[t.matchId]})),r.startedLoadingAt===e&&(n.forEach((t=>{t.action&&(t.action.current=void 0,t.action.submissions=[])})),r.state=U({},r.state,{location:r.location,matches:n,pending:void 0,status:"idle"}),r.notify(),r.resolveNavigation())},cleanMatchCache:()=>{const t=Date.now();Object.keys(r.matchCache).forEach((e=>{const n=r.matchCache[e];"loading"!==n.match.status&&(n.gc>0&&n.gc>t||delete r.matchCache[e])}))},loadRoute:async function(t){void 0===t&&(t=r.location);const e=r.buildNext(t),n=r.matchRoutes(e.pathname,{strictParseParams:!0});return await r.loadMatches(n),n},preloadRoute:async function(t,e){var n,a,o,i,s,l;void 0===t&&(t=r.location);const c=r.buildNext(t),u=r.matchRoutes(c.pathname,{strictParseParams:!0});return await r.loadMatches(u,{preload:!0,maxAge:null!=(n=null!=(a=null!=(o=e.maxAge)?o:r.options.defaultPreloadMaxAge)?a:r.options.defaultLoaderMaxAge)?n:0,gcMaxAge:null!=(i=null!=(s=null!=(l=e.gcMaxAge)?l:r.options.defaultPreloadGcMaxAge)?s:r.options.defaultLoaderGcMaxAge)?i:0}),u},matchRoutes:(t,e)=>{var n,a;r.cleanMatchCache();const o=[];if(!r.routeTree)return o;const i=[...r.state.matches,...null!=(n=null==(a=r.state.pending)?void 0:a.matches)?n:[]],s=async n=>{var a,l,c;const u=E(o);let h=null!=(a=null==u?void 0:u.params)?a:{};const d=null!=(l=null==r.options.filterRoutes?void 0:r.options.filterRoutes(n))?l:n;let f=[];const p=(n,a)=>(a.some((a=>{var o,i,s;if(!a.routePath&&null!=(o=a.childRoutes)&&o.length)return p([...f,a],a.childRoutes);const l=!!("/"!==a.routePath||null!=(i=a.childRoutes)&&i.length),c=j(t,{to:a.fullPath,fuzzy:l,caseSensitive:null!=(s=a.options.caseSensitive)?s:r.options.caseSensitive});if(c){let t;try{var u;t=null!=(u=null==a.options.parseParams?void 0:a.options.parseParams(c))?u:c}catch(t){if(null!=e&&e.strictParseParams)throw t}h=U({},h,t)}return c&&(f=[...n,a]),!!f.length})),!!f.length);if(p([],d),!f.length)return;f.forEach((e=>{var n;const a=D(e.routePath,h),s=D(e.routeId,h,!0),l=i.find((t=>t.matchId===s))||(null==(n=r.matchCache[s])?void 0:n.match)||W(r,e,{parentMatch:u,matchId:s,params:h,pathname:I([t,a])});o.push(l)}));const m=E(f);null!=(c=m.childRoutes)&&c.length&&s(m.childRoutes)};return s([r.routeTree]),Z(o),o},loadMatches:async(t,e)=>{const n=t.map((async t=>{t.__.validate(),t.load(e);const n=t.search;n.__data&&n.__data.matchId!==t.matchId||t.__.loadPromise&&await t.__.loadPromise}));r.notify(),await Promise.all(n)},loadMatchData:async t=>{var e;if($||!r.options.useServerData)return null!=(e=await(null==t.options.loader?void 0:t.options.loader({params:t.params,search:t.routeSearch,signal:t.__.abortController.signal})))?e:{};{const e=r.buildNext({to:".",search:e=>U({},null!=e?e:{},{__data:{matchId:t.matchId}})}),n=await fetch(e.href,{method:"GET"});if(n.ok)return n.json();throw new Error("Failed to fetch match data")}},invalidateRoute:t=>{var e,n;const a=r.buildNext(t),o=r.matchRoutes(a.pathname).map((t=>t.matchId));[...r.state.matches,...null!=(e=null==(n=r.state.pending)?void 0:n.matches)?e:[]].forEach((t=>{o.includes(t.matchId)&&t.invalidate()}))},reload:()=>r.__.navigate({fromCurrent:!0,replace:!0,search:!0}),resolvePath:(t,e)=>k(r.basepath,t,M(e)),matchRoute:(t,e)=>{var n;t=U({},t,{to:t.to?r.resolvePath(null!=(n=t.from)?n:"",t.to):void 0});const a=r.buildNext(t);var o;return null!=e&&e.pending?!(null==(o=r.state.pending)||!o.location)&&!!j(r.state.pending.location.pathname,U({},e,{to:a.pathname})):!!j(r.state.location.pathname,U({},e,{to:a.pathname}))},navigate:async t=>{let{from:e,to:n=".",search:a,hash:o,replace:i,params:s}=t;const l=String(n),c=String(e);let u;try{new URL(""+l),u=!0}catch(t){}return _(!u),r.__.navigate({from:c,to:l,search:a,hash:o,replace:i,params:s})},buildLink:t=>{var e,n;let{from:a,to:o=".",search:i,params:s,hash:l,target:c,replace:u,activeOptions:h,preload:d,preloadMaxAge:f,preloadGcMaxAge:p,preloadDelay:m,disabled:v}=t;try{return new URL(""+o),{type:"external",href:o}}catch(t){}const g={from:a,to:o,search:i,params:s,hash:l,replace:u},y=r.buildNext(g);d=null!=(e=d)?e:r.options.defaultPreload;const _=null!=(n=null!=m?m:r.options.defaultPreloadDelay)?n:0,b=r.state.location.pathname===y.pathname,P=r.state.location.pathname.split("/"),w=y.pathname.split("/").every(((t,e)=>t===P[e])),E=r.state.location.hash===y.hash,R=null!=h&&h.exact?b:w,x=null==h||!h.includeHash||E;return{type:"internal",next:y,handleFocus:t=>{d&&r.preloadRoute(g,{maxAge:f,gcMaxAge:p})},handleClick:t=>{v||function(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}(t)||t.defaultPrevented||c&&"_self"!==c||0!==t.button||(t.preventDefault(),!b||i||l||r.invalidateRoute(g),r.__.navigate(g))},handleEnter:t=>{const e=t.target||{};if(d){if(e.preloadTimeout)return;e.preloadTimeout=setTimeout((()=>{e.preloadTimeout=null,r.preloadRoute(g,{maxAge:f,gcMaxAge:p})}),_)}},handleLeave:t=>{const e=t.target||{};e.preloadTimeout&&(clearTimeout(e.preloadTimeout),e.preloadTimeout=null)},isActive:R&&x,disabled:v}},buildNext:t=>{const e=r.__.buildLocation(t),n=r.matchRoutes(e.pathname),a=n.map((t=>{var e;return null!=(e=t.options.preSearchFilters)?e:[]})).flat().filter(Boolean),o=n.map((t=>{var e;return null!=(e=t.options.postSearchFilters)?e:[]})).flat().filter(Boolean);return r.__.buildLocation(U({},t,{__preSearchFilters:a,__postSearchFilters:o}))},__:{buildRouteTree:t=>{const e=(t,n)=>t.map((t=>{const a=H(t,t.options,n,r);if(r.routesById[a.routeId])throw new Error;r.routesById[a.routeId]=a;const o=t.children;return a.childRoutes=null!=o&&o.length?e(o,a):void 0,a}));return e([t])[0]},parseLocation:(t,e)=>{var n;const a=r.options.parseSearch(t.search);return{pathname:t.pathname,searchStr:t.search,search:b(null==e?void 0:e.search,a),hash:null!=(n=t.hash.split("#").reverse()[0])?n:"",href:""+t.pathname+t.search+t.hash,state:t.state,key:t.key}},navigate:t=>{const e=r.buildNext(t);return r.__.commitLocation(e,t.replace)},buildLocation:function(t){var e,n,a,o,i,s,l,c,u;void 0===t&&(t={});const h=t.fromCurrent?r.location.pathname:null!=(e=t.from)?e:r.location.pathname;let d=k(null!=(n=r.basepath)?n:"/",h,""+(null!=(a=t.to)?a:"."));const f=r.matchRoutes(r.location.pathname,{strictParseParams:!0}),p=r.matchRoutes(d),m=U({},null==(o=E(f))?void 0:o.params);let v=!0===(null==(i=t.params)||i)?m:x(t.params,m);v&&p.map((t=>t.options.stringifyParams)).filter(Boolean).forEach((t=>{Object.assign({},v,t(v))})),d=D(d,null!=v?v:{});const g=null!=(s=t.__preSearchFilters)&&s.length?t.__preSearchFilters.reduce(((t,e)=>e(t)),r.location.search):r.location.search,y=!0===t.search?g:t.search?null!=(l=x(t.search,g))?l:{}:null!=(c=t.__preSearchFilters)&&c.length?g:{},_=null!=(u=t.__postSearchFilters)&&u.length?t.__postSearchFilters.reduce(((t,e)=>e(t)),y):y,P=b(r.location.search,_),w=r.options.stringifySearch(P);let R=!0===t.hash?r.location.hash:x(t.hash,r.location.hash);return R=R?"#"+R:"",{pathname:d,search:P,searchStr:w,state:r.location.state,hash:R,href:""+d+w+R,key:t.key}},commitLocation:(t,e)=>{const n=""+Date.now()+Math.random();r.navigateTimeout&&clearTimeout(r.navigateTimeout);let o="replace";e||(o="push");return r.__.parseLocation(a.location).href===t.href&&!t.key&&(o="replace"),"replace"===o?a.replace({pathname:t.pathname,hash:t.hash,search:t.searchStr},U({id:n},t.state)):a.push({pathname:t.pathname,hash:t.hash,search:t.searchStr},{id:n}),r.navigationPromise=new Promise((t=>{const e=r.resolveNavigation;r.resolveNavigation=()=>{e(),t()}})),r.navigationPromise}}};return r.update(t),null==r.options.createRouter||r.options.createRouter(r),r}function Z(t){t.forEach(((e,n)=>{const a=t[n-1];a&&(e.loaderData=b(e.loaderData,U({},a.loaderData,e.routeLoaderData)))}))}const tt=["type","children","target","activeProps","inactiveProps","activeOptions","disabled","hash","search","params","to","preload","preloadDelay","preloadMaxAge","replace","style","className","onClick","onFocus","onMouseEnter","onMouseLeave","onTouchStart","onTouchEnd"],et=["pending","caseSensitive","children"],nt=["children","router"];const at=r.createContext(null),ot=r.createContext(null);function rt(t){return r.createElement(at.Provider,t)}const it=t=>{n.useSyncExternalStore((e=>t.subscribe((()=>e()))),(()=>t.state),(()=>t.state))};function st(){const t=r.useContext(ot);return R(!t,"useRouter must be used inside a <Router> component!"),it(t.router),t.router}function lt(){return r.useContext(at)}function ct(){var t,e,n;const a=st(),o=lt().slice(1),i=o[0],s=r.useCallback((()=>null),[]);if(!i)return null;const l=null!=(t=null!=(e=i.__.pendingComponent)?e:a.options.defaultPendingComponent)?t:s,c=null!=(n=i.__.errorComponent)?n:a.options.defaultErrorComponent;return r.createElement(rt,{value:o},r.createElement(r.Suspense,{fallback:r.createElement(l,null)},r.createElement(ut,{errorComponent:c},(()=>{if("error"===i.status)throw i.error;var t,e;if("success"===i.status)return r.createElement(null!=(t=null!=(e=i.__.component)?e:a.options.defaultComponent)?t:ct);throw console.log(i.matchId,"suspend"),i.__.loadPromise})())))}class ut extends r.Component{constructor(){super(...arguments),this.state={error:!1}}componentDidCatch(t,e){console.error(t),this.setState({error:t,info:e})}render(){var t;const e=null!=(t=this.props.errorComponent)?t:ht;return this.state.error?r.createElement(e,this.state):this.props.children}}function ht(t){let{error:e}=t;return r.createElement("div",{style:{padding:".5rem",maxWidth:"100%"}},r.createElement("strong",{style:{fontSize:"1.2rem"}},"Something went wrong!"),r.createElement("div",{style:{height:".5rem"}}),r.createElement("div",null,r.createElement("pre",null,e.message?r.createElement("code",{style:{fontSize:".7em",border:"1px solid red",borderRadius:".25rem",padding:".5rem",color:"red"}},e.message):null)))}function dt(t,e){const n=st();r.useEffect((()=>{if(!e)return;let a=n.history.block((e=>{window.confirm(t)?(a(),e.retry()):n.location.pathname=window.location.pathname}));return a}),[e,location,t])}t.DefaultErrorBoundary=ht,t.Link=function(t){const e=st();return r.createElement(e.Link,t)},t.MatchesProvider=rt,t.Outlet=ct,t.Prompt=function(t){let{message:e,when:n,children:a}=t;return dt(e,null==n||n),null!=a?a:null},t.RouterProvider=function(t){let{children:e,router:n}=t,a=s(t,nt);return n.update(a),it(n),r.useEffect((()=>(console.log("hello"),n.mount())),[n]),r.createElement(ot.Provider,{value:{router:n}},r.createElement(rt,{value:n.state.matches},null!=e?e:r.createElement(ct,null)))},t.cleanPath=M,t.createBrowserHistory=h,t.createHashHistory=function(t){void 0===t&&(t={});var e=t.window,n=void 0===e?document.defaultView:e,a=n.history;function r(){var t=y(n.location.hash.substr(1)),e=t.pathname,o=void 0===e?"/":e,r=t.search,i=void 0===r?"":r,s=t.hash,l=void 0===s?"":s,c=a.state||{};return[c.idx,{pathname:o,search:i,hash:l,state:c.usr||null,key:c.key||"default"}]}var i=null;function s(){if(i)P.call(i),i=null;else{var t=o.Pop,e=r(),n=e[0],a=e[1];if(P.length){if(null!=n){var s=f-n;s&&(i={action:t,location:a,retry:function(){I(-1*s)}},I(s))}}else S(t)}}n.addEventListener(u,s),n.addEventListener("hashchange",(function(){g(r()[1])!==g(_)&&s()}));var h=o.Pop,d=r(),f=d[0],_=d[1],b=m(),P=m();function w(t){return function(){var t=document.querySelector("base"),e="";if(t&&t.getAttribute("href")){var a=n.location.href,o=a.indexOf("#");e=-1===o?a:a.slice(0,o)}return e}()+"#"+("string"==typeof t?t:g(t))}function E(t,e){return void 0===e&&(e=null),l({pathname:_.pathname,hash:"",search:""},"string"==typeof t?y(t):t,{state:e,key:v()})}function R(t,e){return[{usr:t.state,key:t.key,idx:e},w(t)]}function x(t,e,n){return!P.length||(P.call({action:t,location:e,retry:n}),!1)}function S(t){h=t;var e=r();f=e[0],_=e[1],b.call({action:h,location:_})}function I(t){a.go(t)}null==f&&(f=0,a.replaceState(l({},a.state,{idx:f}),""));var M={get action(){return h},get location(){return _},createHref:w,push:function t(e,r){var i=o.Push,s=E(e,r);if(x(i,s,(function(){t(e,r)}))){var l=R(s,f+1),c=l[0],u=l[1];try{a.pushState(c,"",u)}catch(t){n.location.assign(u)}S(i)}},replace:function t(e,n){var r=o.Replace,i=E(e,n);if(x(r,i,(function(){t(e,n)}))){var s=R(i,f),l=s[0],c=s[1];a.replaceState(l,"",c),S(r)}},go:I,back:function(){I(-1)},forward:function(){I(1)},listen:function(t){return b.push(t)},block:function(t){var e=P.push(t);return 1===P.length&&n.addEventListener(c,p),function(){e(),P.length||n.removeEventListener(c,p)}}};return M},t.createMemoryHistory=d,t.createReactRouter=function(t){const e=(t,e)=>({useRoute:function(n){void 0===n&&(n=".");const a=e.resolvePath(t.routeId,n),o=e.getRoute(a);return it(e),_(o),o},linkProps:e=>{var n,a;const{target:o,activeProps:l=(()=>({className:"active"})),inactiveProps:c=(()=>({})),disabled:u,style:h,className:d,onClick:f,onFocus:p,onMouseEnter:m,onMouseLeave:v}=e,g=s(e,tt),y=t.buildLink(e);if("external"===y.type){const{href:t}=y;return{href:t}}const{handleClick:_,handleFocus:b,handleEnter:P,handleLeave:w,isActive:E,next:R}=y,S=t=>e=>{e.persist(),t.forEach((t=>{t&&t(e)}))},I=E&&null!=(n=x(l,{}))?n:{},M=E?{}:null!=(a=x(c,{}))?a:{};return i({},I,M,g,{href:u?void 0:R.href,onClick:S([t=>{r.startTransition((()=>{_(t)}))},f]),onFocus:S([b,p]),onMouseEnter:S([P,m]),onMouseLeave:S([w,v]),target:o,style:i({},h,I.style,M.style),className:[d,I.className,M.className].filter(Boolean).join(" ")||void 0},u?{role:"link","aria-disabled":!0}:void 0,{"data-status":E?"active":void 0})},Link:r.forwardRef(((n,a)=>{const o=t.linkProps(n);return it(e),r.createElement("a",i({ref:a},o,{children:"function"==typeof n.children?n.children({isActive:"active"===o["data-status"]}):n.children}))})),MatchRoute:e=>{const{pending:n,caseSensitive:a}=e,o=s(e,et),r=t.matchRoute(o,{pending:n,caseSensitive:a});return r?"function"==typeof e.children?e.children(r):e.children:null}}),n=Y(i({},t,{createRouter:t=>{const n={useState:()=>(it(t),t.state),useMatch:(e,n)=>{var a,o;it(t),_(e!==z);const r=null==(a=lt())?void 0:a[0],i=t.state.matches.find((t=>t.routeId===e));return(null==(o=null==n?void 0:n.strict)||o)&&(_(i),_(r.routeId==(null==i?void 0:i.routeId),(null==i||i.routeId,r.routeId,null==i||i.routeId,null==i||i.routeId))),i}},a=e(t.getRoute("/"),t);Object.assign(t,n,a)},createRoute:t=>{let{router:n,route:a}=t;const o=e(a,n);Object.assign(a,o)},loadComponent:async t=>(t.preload&&"undefined"!=typeof document&&t.preload(),t)}));return n},t.createRoute=H,t.createRouteConfig=function t(e,n,a,o,r){void 0===e&&(e={}),void 0===a&&(a=!0),a&&(e.path=z),o===z&&(o="");let i=a?z:e.path;i&&"/"!==i&&(i=C(i));const s=i||e.id;let l=I([o,s]);i===z&&(i="/"),l!==z&&(l=I(["/",l]));const c=l===z?"/":L(I([r,i]));return{id:l,routeId:s,path:i,fullPath:c,options:e,children:n,createChildren:n=>t(e,n((e=>t(e,void 0,!1,l,c))),!1,o,r),addChildren:n=>t(e,n,!1,o,r),createRoute:e=>t(e,void 0,!1,l,c)}},t.createRouteMatch=W,t.createRouter=Y,t.decode=B,t.defaultParseSearch=q,t.defaultStringifySearch=K,t.encode=T,t.functionalUpdate=x,t.interpolatePath=D,t.invariant=_,t.joinPaths=I,t.last=E,t.lazy=function(t){const e=r.lazy(t);let n,a;const o=r.forwardRef(((t,n)=>{const o=r.useRef(a||e);return r.createElement(o.current,i({},n?{ref:n}:{},t))}));return o.preload=()=>(n||(n=t().then((t=>(a=t.default,a)))),n),o},t.matchByPath=F,t.matchPathname=j,t.matchesContext=at,t.parsePathname=O,t.parseSearchWith=V,t.pick=S,t.replaceEqualDeep=b,t.resolvePath=k,t.rootRouteId=z,t.routerContext=ot,t.stringifySearchWith=J,t.trimPath=C,t.trimPathLeft=A,t.trimPathRight=L,t.useMatch=function(t,e){return st().useMatch(t,e)},t.useMatches=lt,t.usePrompt=dt,t.useRouter=st,t.warning=R,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
21
|
+
*/class n{listeners=new Set;_batching=!1;_flushing=0;_nextPriority=null;constructor(t,e){this.state=t,this.options=e}subscribe=t=>{this.listeners.add(t);const e=this.options?.onSubscribe?.(t,this);return()=>{this.listeners.delete(t),e?.()}};setState=(t,e)=>{const r=this.state;this.state=this.options?.updateFn?this.options.updateFn(r)(t):t(r);const o=e?.priority??this.options?.defaultPriority??"high";null===this._nextPriority||"high"===this._nextPriority?this._nextPriority=o:this._nextPriority=this.options?.defaultPriority??"high",this.options?.onUpdate?.({priority:this._nextPriority}),this._flush()};_flush=()=>{if(this._batching)return;const t=++this._flushing;this.listeners.forEach((e=>{this._flushing===t&&e({priority:this._nextPriority??"high"})}))};batch=t=>{if(this._batching)return t();this._batching=!0,t(),this._batching=!1,this._flush()}}
|
|
22
|
+
/**
|
|
23
|
+
* @tanstack/react-store/src/index.tsx
|
|
24
|
+
*
|
|
25
|
+
* Copyright (c) TanStack
|
|
26
|
+
*
|
|
27
|
+
* This source code is licensed under the MIT license found in the
|
|
28
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
29
|
+
*
|
|
30
|
+
* @license MIT
|
|
31
|
+
*/function a(t,r=(t=>t)){return e.useSyncExternalStoreWithSelector(t.subscribe,(()=>t.state),(()=>t.state),r,i)}function i(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const r=Object.keys(t);if(r.length!==Object.keys(e).length)return!1;for(let o=0;o<r.length;o++)if(!Object.prototype.hasOwnProperty.call(e,r[o])||!Object.is(t[r[o]],e[r[o]]))return!1;return!0}
|
|
32
|
+
/**
|
|
33
|
+
* @tanstack/history/src/index.ts
|
|
34
|
+
*
|
|
35
|
+
* Copyright (c) TanStack
|
|
36
|
+
*
|
|
37
|
+
* This source code is licensed under the MIT license found in the
|
|
38
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
39
|
+
*
|
|
40
|
+
* @license MIT
|
|
41
|
+
*/const c="pushstate",h="popstate",u="beforeunload",l=t=>(t.preventDefault(),t.returnValue=""),d=()=>{removeEventListener(u,l,{capture:!0})};function p(t){let e=t.getLocation(),r=new Set,o=[],s=[];const n=()=>{e=t.getLocation(),r.forEach((t=>t()))},a=()=>{if(o.length)o[0]?.(a,(()=>{o=[],d()}));else{for(;s.length;)s.shift()?.();n()}},i=t=>{s.push(t),a()};return{get location(){return e},subscribe:t=>(r.add(t),()=>{r.delete(t)}),push:(e,r)=>{r=f(r),i((()=>{t.pushState(e,r,n)}))},replace:(e,r)=>{r=f(r),i((()=>{t.replaceState(e,r,n)}))},go:e=>{i((()=>{t.go(e)}))},back:()=>{i((()=>{t.back()}))},forward:()=>{i((()=>{t.forward()}))},createHref:e=>t.createHref(e),block:t=>(o.push(t),1===o.length&&addEventListener(u,l,{capture:!0}),()=>{o=o.filter((e=>e!==t)),o.length||d()}),flush:()=>t.flush?.(),destroy:()=>t.destroy?.(),update:n}}function f(t){return t||(t={}),t.key=w(),t}function m(t){const e=t?.getHref??(()=>`${window.location.pathname}${window.location.search}${window.location.hash}`),r=t?.createHref??(t=>t);let o=g(e(),window.history.state);let s,n,a=!0;const i=()=>{a=!1,(()=>{s&&(window.history[s.isPush?"pushState":"replaceState"](s.state,"",s.href),s=void 0,n=void 0)})(),a=!0},u=(t,e,a,c)=>{const h=r(e);o=g(h,a),s={href:h,state:a,isPush:s?.isPush||"push"===t},c(),n||(n=Promise.resolve().then((()=>i())))},l=()=>{o=g(e(),window.history.state),m.update()};var d=window.history.pushState,f=window.history.replaceState;const m=p({getLocation:()=>o,pushState:(t,e,r)=>u("push",t,e,r),replaceState:(t,e,r)=>u("replace",t,e,r),back:()=>window.history.back(),forward:()=>window.history.forward(),go:t=>window.history.go(t),createHref:t=>r(t),flush:i,destroy:()=>{window.history.pushState=d,window.history.replaceState=f,window.removeEventListener(c,l),window.removeEventListener(h,l)}});return window.addEventListener(c,l),window.addEventListener(h,l),window.history.pushState=function(){let t=d.apply(window.history,arguments);return a&&m.update(),t},window.history.replaceState=function(){let t=f.apply(window.history,arguments);return a&&m.update(),t},m}function y(t={initialEntries:["/"]}){const e=t.initialEntries;let r=t.initialIndex??e.length-1,o={key:w()};return p({getLocation:()=>g(e[r],o),pushState:(t,s)=>{o=s,e.push(t),r++},replaceState:(t,s)=>{o=s,e[r]=t},back:()=>{r--},forward:()=>{r=Math.min(r+1,e.length-1)},go:t=>window.history.go(t),createHref:t=>t})}function g(t,e){let r=t.indexOf("#"),o=t.indexOf("?");return{href:t,pathname:t.substring(0,r>0?o>0?Math.min(r,o):r:o>0?o:t.length),hash:r>-1?t.substring(r):"",search:o>-1?t.slice(o,-1===r?void 0:r):"",state:e||{}}}function w(){return(Math.random()+1).toString(36).substring(7)}function v(t,e){if(!t)throw new Error("Invariant failed")}
|
|
42
|
+
/**
|
|
43
|
+
* @tanstack/router-core/src/index.ts
|
|
44
|
+
*
|
|
45
|
+
* Copyright (c) TanStack
|
|
46
|
+
*
|
|
47
|
+
* This source code is licensed under the MIT license found in the
|
|
48
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
49
|
+
*
|
|
50
|
+
* @license MIT
|
|
51
|
+
*/
|
|
52
|
+
function b(t){return t[t.length-1]}function S(t,e){return"function"==typeof t?t(e):t}function R(t,e){return e.reduce(((e,r)=>(e[r]=t[r],e)),{})}function _(t,e){if(t===e)return t;const r=e,o=Array.isArray(t)&&Array.isArray(r);if(o||E(t)&&E(r)){const e=o?t.length:Object.keys(t).length,s=o?r:Object.keys(r),n=s.length,a=o?[]:{};let i=0;for(let e=0;e<n;e++){const n=o?e:s[e];a[n]=_(t[n],r[n]),a[n]===t[n]&&i++}return e===n&&i===e?t:a}return r}function E(t){if(!x(t))return!1;const e=t.constructor;if(void 0===e)return!0;const r=e.prototype;return!!x(r)&&!!r.hasOwnProperty("isPrototypeOf")}function x(t){return"[object Object]"===Object.prototype.toString.call(t)}function M(t,e){return t===e||typeof t==typeof e&&(E(t)&&E(e)?!Object.keys(e).some((r=>!M(t[r],e[r]))):!(!Array.isArray(t)||!Array.isArray(e))&&(t.length===e.length&&t.every(((t,r)=>M(t,e[r])))))}function I(t){return P(t.filter(Boolean).join("/"))}function P(t){return t.replace(/\/{2,}/g,"/")}function L(t){return"/"===t?t:t.replace(/^\/{1,}/,"")}function C(t){return"/"===t?t:t.replace(/\/{1,}$/,"")}function O(t){return C(L(t))}function A(t,e,r){e=e.replace(new RegExp(`^${t}`),"/"),r=r.replace(new RegExp(`^${t}`),"/");let o=k(e);const s=k(r);s.forEach(((t,e)=>{if("/"===t.value)e?e===s.length-1&&o.push(t):o=[t];else if(".."===t.value)o.length>1&&"/"===b(o)?.value&&o.pop(),o.pop();else{if("."===t.value)return;o.push(t)}}));return P(I([t,...o.map((t=>t.value))]))}function k(t){if(!t)return[];const e=[];if("/"===(t=P(t)).slice(0,1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),!t)return e;const r=t.split("/").filter(Boolean);return e.push(...r.map((t=>"$"===t||"*"===t?{type:"wildcard",value:t}:"$"===t.charAt(0)?{type:"param",value:t}:{type:"pathname",value:t}))),"/"===t.slice(-1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),e}function j(t,e,r=!1){return I(k(t).map((t=>{if("wildcard"===t.type){const o=e[t.value];return r?`${t.value}${o??""}`:o}return"param"===t.type?e[t.value.substring(1)]??"":t.value})))}function D(t,e,r){const o=B(t,e,r);if(!r.to||o)return o??{}}function B(t,e,r){e="/"!=t?e.substring(t.length):e;const o=`${r.to??"$"}`,s=k(e),n=k(o);e.startsWith("/")||s.unshift({type:"pathname",value:"/"}),o.startsWith("/")||n.unshift({type:"pathname",value:"/"});const a={};return(()=>{for(let t=0;t<Math.max(s.length,n.length);t++){const e=s[t],o=n[t],i=t>=s.length-1,c=t>=n.length-1;if(o){if("wildcard"===o.type)return!!e?.value&&(a["*"]=I(s.slice(t).map((t=>t.value))),!0);if("pathname"===o.type){if("/"===o.value&&!e?.value)return!0;if(e)if(r.caseSensitive){if(o.value!==e.value)return!1}else if(o.value.toLowerCase()!==e.value.toLowerCase())return!1}if(!e)return!1;if("param"===o.type){if("/"===e?.value)return!1;"$"!==e.value.charAt(0)&&(a[o.value.substring(1)]=e.value)}}if(!i&&c)return!!r.fuzzy}return!0})()?a:void 0}function T(t,e){var r,o,s,n="";for(r in t)if(void 0!==(s=t[r]))if(Array.isArray(s))for(o=0;o<s.length;o++)n&&(n+="&"),n+=encodeURIComponent(r)+"="+encodeURIComponent(s[o]);else n&&(n+="&"),n+=encodeURIComponent(r)+"="+encodeURIComponent(s);return(e||"")+n}function $(t){if(!t)return"";var e=decodeURIComponent(t);return"false"!==e&&("true"===e||(0*+e==0&&+e+""===e?+e:e))}function F(t){for(var e,r,o={},s=t.split("&");e=s.shift();)void 0!==o[r=(e=e.split("=")).shift()]?o[r]=[].concat(o[r],$(e.shift())):o[r]=$(e.shift());return o}const H="__root__";class N{constructor(t){this.options=t||{},this.isRoot=!t?.getParentRoute,N.__onInit(this)}init=t=>{this.originalIndex=t.originalIndex,this.router=t.router;const e=this.options,r=!e?.path&&!e?.id;this.parentRoute=this.options?.getParentRoute?.(),r?this.path=H:v(this.parentRoute);let o=r?H:e.path;o&&"/"!==o&&(o=O(o));const s=e?.id||o;let n=r?H:I([this.parentRoute.id===H?"":this.parentRoute.id,s]);o===H&&(o="/"),n!==H&&(n=I(["/",n]));const a=n===H?"/":I([this.parentRoute.fullPath,o]);this.path=o,this.id=n,this.fullPath=a,this.to=a};addChildren=t=>(this.children=t,this);update=t=>(Object.assign(this.options,t),this);static __onInit=t=>{}}class K extends N{constructor(t){super(t)}}const W=z(JSON.parse),U=Y(JSON.stringify,JSON.parse);function z(t){return e=>{"?"===e.substring(0,1)&&(e=e.substring(1));let r=F(e);for(let e in r){const o=r[e];if("string"==typeof o)try{r[e]=t(o)}catch(t){}}return r}}function Y(t,e){return r=>{(r={...r})&&Object.keys(r).forEach((o=>{const s=r[o];void 0===s||void 0===s?delete r[o]:r[o]=function(r){if("object"==typeof r&&null!==r)try{return t(r)}catch(t){}else if("string"==typeof r&&"function"==typeof e)try{return e(r),t(r)}catch(t){}return r}(s)}));const o=T(r).toString();return o?`?${o}`:""}}const J=["component","errorComponent","pendingComponent"],q="visibilitychange",X="focus",V="Error preloading route! ☝️";const G="undefined"==typeof window||!window.document.createElement;function Q(){return{status:"idle",isFetching:!1,resolvedLocation:null,location:null,matchesById:{},matchIds:[],pendingMatchIds:[],matches:[],pendingMatches:[],renderedMatchIds:[],renderedMatches:[],lastUpdated:Date.now()}}function Z(t){return!!t?.isRedirect}class tt extends Error{}class et extends Error{}function rt(t,e){const r=Date.now();return!!t.invalid||(e?.preload?!(t.preloadMaxAge<0)&&t.updatedAt+t.preloadMaxAge<r:!(t.maxAge<0)&&t.updatedAt+t.maxAge<r)}const ot="window",st="___";let nt,at={},it=!1;const ct="undefined"!=typeof window&&window.sessionStorage,ht=t=>t.state.key;function ut(t,e){const r=e?.getKey||ht;ct&&(nt||(nt=(()=>{const t="tsr-scroll-restoration-v1",e=JSON.parse(window.sessionStorage.getItem(t)||"{}");return{current:e,set:(r,o)=>{e[r]=o,window.sessionStorage.setItem(t,JSON.stringify(nt))}}})()));const{history:o}=window;o.scrollRestoration&&(o.scrollRestoration="manual");const s=e=>{const o=r(t.state.resolvedLocation);at[o]||(at[o]=new WeakSet);const s=at[o];if(s.has(e.target))return;s.add(e.target);const a=[o,e.target===document||e.target===window?ot:n(e.target)].join(st);nt.current[a]||nt.set(a,{scrollX:NaN,scrollY:NaN})},n=t=>{let e,r=[];for(;e=t.parentNode;)r.unshift(`${t.tagName}:nth-child(${[].indexOf.call(e.children,t)+1})`),t=e;return`${r.join(" > ")}`.toLowerCase()};"undefined"!=typeof document&&document.addEventListener("scroll",s,!0);const a=t.subscribe("onBeforeLoad",(t=>{t.pathChanged&&(t=>{const e=r(t);for(const t in nt.current){const r=nt.current[t],[o,s]=t.split(st);if(e===o){if(s===ot)r.scrollX=window.scrollX||0,r.scrollY=window.scrollY||0;else if(s){const t=document.querySelector(s);r.scrollX=t?.scrollLeft||0,r.scrollY=t?.scrollTop||0}nt.set(t,r)}}})(t.from)})),i=t.subscribe("onLoad",(t=>{t.pathChanged&&(it=!0)}));return()=>{document.removeEventListener("scroll",s),a(),i()}}function lt(t,e){if(it){if(!t.resetNextScroll)return;it=!1;const r=(e?.getKey||ht)(t.state.location);let o=!1;for(const t in nt.current){const e=nt.current[t],[s,n]=t.split(st);if(s===r)if(n===ot)o=!0,window.scrollTo(e.scrollX,e.scrollY);else if(n){const t=document.querySelector(n);t&&(t.scrollLeft=e.scrollX,t.scrollTop=e.scrollY)}}o||window.scrollTo(0,0)}}function dt(t){return"object"==typeof t&&null!==t&&!(t instanceof Promise)&&!t.then&&"__deferredState"in t}function pt(){return pt=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o])}return t},pt.apply(this,arguments)}const ft="undefined"!=typeof window?s.useLayoutEffect:s.useEffect;function mt(t){const e=St(),{type:r,children:o,target:n,activeProps:a=(()=>({className:"active"})),inactiveProps:i=(()=>({})),activeOptions:c,disabled:h,hash:u,search:l,params:d,to:p=".",state:f,mask:m,preload:y,preloadDelay:g,replace:w,style:v,className:b,onClick:R,onFocus:_,onMouseEnter:E,onMouseLeave:x,onTouchStart:M,...I}=t,P=e.buildLink(t);if("external"===P.type){const{href:t}=P;return{href:t}}const{handleClick:L,handleFocus:C,handleEnter:O,handleLeave:A,handleTouchStart:k,isActive:j,next:D}=P,B=t=>e=>{e.persist&&e.persist(),t.filter(Boolean).forEach((t=>{e.defaultPrevented||t(e)}))},T=j?S(a,{})??{}:{},$=j?{}:S(i,{})??{};return{...T,...$,...I,href:h?void 0:D.maskedLocation?D.maskedLocation.href:D.href,onClick:B([R,e=>{(t.startTransition??1)&&(s.startTransition||(t=>t))((()=>{L(e)}))}]),onFocus:B([_,C]),onMouseEnter:B([E,O]),onMouseLeave:B([x,A]),onTouchStart:B([M,k]),target:n,style:{...v,...T.style,...$.style},className:[b,T.className,$.className].filter(Boolean).join(" ")||void 0,...h?{role:"link","aria-disabled":!0}:void 0,"data-status":j?"active":void 0}}N.__onInit=t=>{Object.assign(t,{useMatch:(e={})=>Rt({...e,from:t.id}),useLoader:(e={})=>_t({...e,from:t.id}),useRouteContext:(e={})=>Rt({...e,from:t.id,select:t=>e?.select?e.select(t.context):t.context}),useSearch:(e={})=>Et({...e,from:t.id}),useParams:(e={})=>xt({...e,from:t.id})})};const yt=s.forwardRef(((t,e)=>{const r=mt(t);return s.createElement("a",pt({ref:e},r,{children:"function"==typeof t.children?t.children({isActive:"active"===r["data-status"]}):t.children}))}));const gt=s.createContext(null),wt=s.createContext(null);function vt(t){return a(St().__store,t?.select)}function bt(){const t=St(),e=vt({select:t=>t.renderedMatchIds}),r=vt({select:t=>t.resolvedLocation.state?.key}),o=t.getRoute(H),n=s.useCallback((t=>s.createElement(jt,{...t,useMatch:o.useMatch,useRouteContext:o.useRouteContext,useSearch:o.useSearch,useParams:o.useParams})),[o]);return s.createElement(gt.Provider,{value:[void 0,...e]},s.createElement(At,{resetKey:r,errorComponent:n,onCatch:()=>{}},s.createElement(It,null)))}function St(){return s.useContext(wt)}function Rt(t){const e=St(),r=s.useContext(gt)[0],o=e.getRouteMatch(r)?.routeId,n=vt({select:e=>(t?.from?e.renderedMatches.find((e=>e.routeId===t?.from)):e.renderedMatches.find((t=>t.id===r))).routeId});(t?.strict??1)&&v(o==n);return vt({select:e=>{const o=t?.from?e.renderedMatches.find((e=>e.routeId===t?.from)):e.renderedMatches.find((t=>t.id===r));return v(o,t?.from&&t.from),t?.select?t.select(o):o}})}function _t(t){return Rt({...t,select:e=>t?.select?t?.select(e.loaderData):e.loaderData})}function Et(t){return Rt({...t,select:e=>t?.select?t.select(e.search):e.search})}function xt(t){return vt({select:e=>{const r=b(e.renderedMatches)?.params;return t?.select?t.select(r):r}})}function Mt(){const t=St();return s.useCallback((e=>{const{pending:r,caseSensitive:o,...s}=e;return t.matchRoute(s,{pending:r,caseSensitive:o})}),[])}function It(){const t=s.useContext(gt).slice(1);return t[0]?s.createElement(Lt,{matchIds:t}):null}const Pt=()=>null;function Lt({matchIds:t}){const e=St(),r=t[0],o=e.getRouteMatch(r).routeId,n=e.getRoute(o),a=vt({select:t=>t.resolvedLocation.state?.key}),i=n.options.pendingComponent??e.options.defaultPendingComponent??Pt,c=n.options.errorComponent??e.options.defaultErrorComponent??jt,h=n.options.wrapInSuspense??!n.isRoot?s.Suspense:Ot,u=c?At:Ot,l=s.useCallback((t=>s.createElement(c,{...t,useMatch:n.useMatch,useRouteContext:n.useRouteContext,useSearch:n.useSearch,useParams:n.useParams})),[n]);return s.createElement(gt.Provider,{value:t},s.createElement(h,{fallback:s.createElement(i,{useMatch:n.useMatch,useRouteContext:n.useRouteContext,useSearch:n.useSearch,useParams:n.useParams})},s.createElement(u,{resetKey:a,errorComponent:l,onCatch:()=>{}},s.createElement(Ct,{matchId:r,PendingComponent:i}))))}function Ct({matchId:t,PendingComponent:e}){const r=St(),o=vt({select:e=>R(e.matchesById[t],["status","loadPromise","routeId","error"])}),n=r.getRoute(o.routeId);if("error"===o.status)throw o.error;if("pending"===o.status)return s.createElement(e,{useLoader:n.useLoader,useMatch:n.useMatch,useRouteContext:n.useRouteContext,useSearch:n.useSearch,useParams:n.useParams});if("success"===o.status){let t=n.options.component??r.options.defaultComponent;return t?s.createElement(t,{useLoader:n.useLoader,useMatch:n.useMatch,useRouteContext:n.useRouteContext,useSearch:n.useSearch,useParams:n.useParams}):s.createElement(It,null)}v(!1)}function Ot(t){return s.createElement(s.Fragment,null,t.children)}function At(t){const e=t.errorComponent??jt;return s.createElement(kt,{resetKey:t.resetKey,onCatch:t.onCatch,children:({error:r})=>r?s.createElement(e,{error:r}):t.children})}class kt extends s.Component{state={error:null};static getDerivedStateFromError(t){return{error:t}}componentDidUpdate(t,e){e.error&&t.resetKey!==this.props.resetKey&&this.setState({error:null})}componentDidCatch(t){this.props.onCatch?.(t)}render(){return this.props.children(this.state)}}function jt({error:t}){const[e,r]=s.useState(!1);return s.createElement("div",{style:{padding:".5rem",maxWidth:"100%"}},s.createElement("div",{style:{display:"flex",alignItems:"center",gap:".5rem"}},s.createElement("strong",{style:{fontSize:"1rem"}},"Something went wrong!"),s.createElement("button",{style:{appearance:"none",fontSize:".6em",border:"1px solid currentColor",padding:".1rem .2rem",fontWeight:"bold",borderRadius:".25rem"},onClick:()=>r((t=>!t))},e?"Hide Error":"Show Error")),s.createElement("div",{style:{height:".25rem"}}),e?s.createElement("div",null,s.createElement("pre",{style:{fontSize:".7em",border:"1px solid red",borderRadius:".25rem",padding:".3rem",color:"red",overflow:"auto"}},t.message?s.createElement("code",null,t.message):null)):null)}function Dt(t,e=!0){const r=St();s.useEffect((()=>{if(!e)return;let o=r.history.block(((e,r)=>{window.confirm(t)&&(o(),e())}));return o}))}const Bt="undefined"!=typeof window?s.useLayoutEffect:s.useEffect;function Tt(t){const e=St();Bt((()=>ut(e,t)),[]),Bt((()=>{lt(e,t)}))}function $t({promise:t}){const e=St();let r=t.__deferredState;const o=`__TSR__DEFERRED__${r.uid}`;if(dt(t)&&(r=e.hydrateData(o),(t=Promise.resolve(r.data)).__deferredState=r),"pending"===r.status)throw t;if("error"===r.status)throw r.error;return e.dehydrateData(o,r),[r.data]}t.Await=function(t){const e=$t(t);return t.children(...e)},t.Block=function({message:t,condition:e,children:r}){return Dt(t,e),r??null},t.CatchBoundary=At,t.CatchBoundaryImpl=kt,t.ErrorComponent=jt,t.FileRoute=class{constructor(t){this.path=t}createRoute=t=>{const e=new N(t);return e.isRoot=!1,e}},t.Link=yt,t.MatchRoute=function(t){const e=Mt()(t);return"function"==typeof t.children?t.children(e):e?t.children:null},t.Navigate=function(t){const e=St();return ft((()=>{e.navigate(t)}),[]),null},t.Outlet=It,t.PathParamError=et,t.RootRoute=K,t.Route=N,t.Router=class{#t;resetNextScroll=!1;tempLocationKey=`${Math.round(1e7*Math.random())}`;constructor(t){this.options={defaultPreloadDelay:50,context:void 0,...t,stringifySearch:t?.stringifySearch??U,parseSearch:t?.parseSearch??W},this.__store=new n(Q(),{onUpdate:()=>{const t=this.state,e=this.__store.state,r=t.matchesById!==e.matchesById;let o,s;if(r||(o=t.matchIds.length!==e.matchIds.length||t.matchIds.some(((t,r)=>t!==e.matchIds[r])),s=t.pendingMatchIds.length!==e.pendingMatchIds.length||t.pendingMatchIds.some(((t,r)=>t!==e.pendingMatchIds[r]))),(r||o)&&(e.matches=e.matchIds.map((t=>e.matchesById[t]))),(r||s)&&(e.pendingMatches=e.pendingMatchIds.map((t=>e.matchesById[t]))),r||o||s){const t=e.pendingMatches.some((t=>!!this.getRoute(t.routeId)?.options.pendingComponent));e.renderedMatchIds=t?e.pendingMatchIds:e.matchIds,e.renderedMatches=e.renderedMatchIds.map((t=>e.matchesById[t]))}e.isFetching=[...e.matches,...e.pendingMatches].some((t=>t.isFetching)),this.state=e},defaultPriority:"low"}),this.state=this.__store.state,this.update(t);const e=this.buildLocation({search:!0,params:!0,hash:!0,state:!0});this.state.location.href!==e.href&&this.#e({...e,replace:!0})}subscribers=new Set;subscribe=(t,e)=>{const r={eventType:t,fn:e};return this.subscribers.add(r),()=>{this.subscribers.delete(r)}};#r=t=>{this.subscribers.forEach((e=>{e.eventType===t.type&&e.fn(t)}))};reset=()=>{this.__store.setState((t=>Object.assign(t,Q())))};mount=()=>("undefined"!=typeof window&&window.addEventListener&&(window.addEventListener(q,this.#o,!1),window.addEventListener(X,this.#o,!1)),this.safeLoad(),()=>{"undefined"!=typeof window&&window.removeEventListener&&(window.removeEventListener(q,this.#o),window.removeEventListener(X,this.#o))});#o=()=>{(this.options.reloadOnWindowFocus??1)&&this.invalidate({__fromFocus:!0})};update=t=>{if(this.options={...this.options,...t,context:{...this.options.context,...t?.context}},!this.history||this.options.history&&this.options.history!==this.history){this.#t&&this.#t(),this.history=this.options.history??(G?y():m());const t=this.#s();this.__store.setState((e=>({...e,resolvedLocation:t,location:t}))),this.#t=this.history.subscribe((()=>{this.safeLoad({next:this.#s(this.state.location)})}))}const{basepath:e,routeTree:r}=this.options;return this.basepath=`/${O(e??"")??""}`,r&&r!==this.routeTree&&this.#n(r),this};cancelMatches=()=>{this.state.matches.forEach((t=>{this.cancelMatch(t.id)}))};cancelMatch=t=>{this.getRouteMatch(t)?.abortController?.abort()};safeLoad=async t=>{try{return this.load(t)}catch(t){}};latestLoadPromise=Promise.resolve();load=async t=>{const e=new Promise((async(r,o)=>{const s=this.state.resolvedLocation,n=!(!t?.next||s.href===t.next.href);let a;const i=()=>this.latestLoadPromise!==e?this.latestLoadPromise:void 0;let c;this.#r({type:"onBeforeLoad",from:s,to:t?.next??this.state.location,pathChanged:n}),this.__store.batch((()=>{t?.next&&this.__store.setState((e=>({...e,location:t.next}))),c=this.matchRoutes(this.state.location.pathname,this.state.location.search,{throwOnError:t?.throwOnError,debug:!0}),this.__store.setState((t=>({...t,status:"pending",pendingMatchIds:c.map((t=>t.id)),matchesById:this.#a(t.matchesById,c)})))}));try{try{await this.loadMatches(c.map((t=>t.id)))}catch(t){}if(a=i())return a;const t=this.state.matchIds.filter((t=>!this.state.pendingMatchIds.includes(t))),e=this.state.pendingMatchIds.filter((t=>!this.state.matchIds.includes(t))),o=this.state.matchIds.filter((t=>this.state.pendingMatchIds.includes(t)));this.__store.setState((t=>({...t,status:"idle",resolvedLocation:t.location,matchIds:t.pendingMatchIds,pendingMatchIds:[]}))),[[t,"onLeave"],[e,"onEnter"],[o,"onTransition"]].forEach((([t,e])=>{t.forEach((t=>{const r=this.getRouteMatch(t);this.getRoute(r.routeId).options[e]?.(r)}))})),this.#r({type:"onLoad",from:s,to:this.state.location,pathChanged:n}),r()}catch(t){if(a=i())return a;o(t)}}));return this.latestLoadPromise=e,this.latestLoadPromise.then((()=>{this.cleanMatches()})),this.latestLoadPromise};#a=(t,e)=>{let r={...t};return e.forEach((t=>{r[t.id]||(r[t.id]=t),r[t.id]={...r[t.id],...t}})),r};getRoute=t=>{const e=this.routesById[t];return v(e),e};preloadRoute=async(t=this.state.location)=>{let e=this.buildLocation(t);const r=this.matchRoutes(e.pathname,e.search,{throwOnError:!0});return this.__store.setState((t=>({...t,matchesById:this.#a(t.matchesById,r)}))),await this.loadMatches(r.map((t=>t.id)),{preload:!0,maxAge:t.maxAge}),[b(r),r]};cleanMatches=()=>{const t=Date.now(),e=Object.values(this.state.matchesById).filter((e=>{const r=this.getRoute(e.routeId);return!(this.state.matchIds.includes(e.id)||this.state.pendingMatchIds.includes(e.id)||e.preloadMaxAge>-1&&!(e.updatedAt+e.preloadMaxAge<t)||r.options.gcMaxAge&&!(e.updatedAt+r.options.gcMaxAge<t))})).map((t=>t.id));e.length&&this.__store.setState((t=>{const r={...t.matchesById};return e.forEach((t=>{delete r[t]})),{...t,matchesById:r}}))};matchRoutes=(t,e,r)=>{let o={},s=this.flatRoutes.find((e=>{const r=D(this.basepath,C(t),{to:e.fullPath,caseSensitive:e.options.caseSensitive??this.options.caseSensitive});return!!r&&(o=r,!0)}))||this.routesById.__root__,n=[s];for(;s?.parentRoute;)s=s.parentRoute,s&&n.unshift(s);const a=n.map((t=>{let e;if(t.options.parseParams)try{const e=t.options.parseParams(o);Object.assign(o,e)}catch(t){if(e=new et(t.message,{cause:t}),r?.throwOnError)throw e;return e}})),i=n.map(((t,r)=>{const s=j(t.path,o),n=t.options.loaderContext?t.options.loaderContext({search:e}):void 0,i=JSON.stringify([j(t.id,o,!0),n].filter((t=>void 0!==t)),((e,r)=>("function"==typeof r&&(console.info(t),v(!1)),"object"==typeof r&&null!==r?Object.fromEntries(Object.keys(r).sort().map((t=>[t,r[t]]))):r))),c=this.getRouteMatch(i);if(c)return{...c};const h=!(!t.options.loader&&!J.some((e=>t.options[e]?.preload)));return{id:i,loaderContext:n,routeId:t.id,params:o,pathname:I([this.basepath,s]),updatedAt:Date.now(),maxAge:-1,preloadMaxAge:-1,routeSearch:{},search:{},status:h?"pending":"success",isFetching:!1,invalid:!1,error:void 0,paramsError:a[r],searchError:void 0,loaderData:void 0,loadPromise:Promise.resolve(),context:void 0,abortController:new AbortController,fetchedAt:0}}));return i.forEach(((t,o)=>{const s=i[o-1],n=this.getRoute(t.routeId),a=(()=>{const o={search:s?.search??e,routeSearch:s?.routeSearch??e};try{let e=("object"==typeof n.options.validateSearch?n.options.validateSearch.parse:n.options.validateSearch)?.(o.search)??{},r={...o.search,...e};return e=_(t.routeSearch,e),r=_(t.search,r),{routeSearch:e,search:r,searchDidChange:t.routeSearch!==e}}catch(e){if(t.searchError=new tt(e.message,{cause:e}),r?.throwOnError)throw t.searchError;return o}})();Object.assign(t,a)})),i};loadMatches=async(t,e)=>{const r=()=>t.map((t=>this.getRouteMatch(t)));let o;e?.preload||r().forEach((t=>{this.setRouteMatch(t.id,(e=>({...e,routeSearch:t.routeSearch,search:t.search,context:t.context,error:t.error,paramsError:t.paramsError,searchError:t.searchError,params:t.params,preloadMaxAge:0})))}));try{for(const[t,s]of r().entries()){const n=r()[t-1],a=this.getRoute(s.routeId),i=(e,r)=>{if(e.routerCode=r,o=o??t,Z(e))throw e;try{a.options.onError?.(e)}catch(t){if(e=t,Z(t))throw t}this.setRouteMatch(s.id,(t=>({...t,error:e,status:"error",updatedAt:Date.now()})))};s.paramsError&&i(s.paramsError,"PARSE_PARAMS"),s.searchError&&i(s.searchError,"VALIDATE_SEARCH");let c=!1;const h=n?.context??this?.options.context??{};try{const t=await(a.options.beforeLoad?.({abortController:s.abortController,params:s.params,preload:!!e?.preload,context:{...h,...s.loaderContext}}))??{},r={...h,...s.loaderContext,...t};this.setRouteMatch(s.id,(t=>({...t,context:_(t.context,r)})))}catch(t){i(t,"BEFORE_LOAD"),c=!0}if(c)break}}catch(t){if(Z(t))return void(e?.preload||this.navigate(t));throw t}const s=r().slice(0,o),n=[];s.forEach(((t,r)=>{n.push((async()=>{const o=n[r-1],s=this.getRoute(t.routeId);if(t.isFetching||"success"===t.status&&!rt(t,{preload:e?.preload}))return this.getRouteMatch(t.id)?.loadPromise;const a=Date.now(),i=()=>{const e=this.getRouteMatch(t.id);return e&&e.fetchedAt!==a?e.loadPromise:void 0},c=t=>!!Z(t)&&(e?.preload||this.navigate(t),!0),h=async()=>{let r;try{const n=Promise.all(J.map((async t=>{const e=s.options[t];e?.preload&&await e.preload()}))),a=s.options.loader?.({params:t.params,preload:!!e?.preload,parentMatchPromise:o,abortController:t.abortController,context:t.context}),[c,h]=await Promise.all([n,a]);if(r=i())return await r;this.setRouteMatchData(t.id,(()=>h),e)}catch(e){if(r=i())return await r;if(c(e))return;try{s.options.onError?.(e)}catch(t){if(e=t,c(t))return}this.setRouteMatch(t.id,(t=>({...t,error:e,status:"error",isFetching:!1,updatedAt:Date.now()})))}};let u;this.__store.batch((()=>{this.setRouteMatch(t.id,(t=>({...t,isFetching:!0,fetchedAt:a,invalid:!1}))),u=h(),this.setRouteMatch(t.id,(t=>({...t,loadPromise:u})))})),await u})())})),await Promise.all(n)};resolvePath=(t,e)=>A(this.basepath,t,P(e));navigate=async({from:t,to:e="",...r})=>{const o=String(e),s=void 0===t?t:String(t);let n;try{new URL(`${o}`),n=!0}catch(t){}return v(!n),this.#i({...r,from:s,to:o})};matchRoute=(t,e)=>{t={...t,to:t.to?this.resolvePath(t.from??"",t.to):void 0};const r=this.buildLocation(t);if(e?.pending&&"pending"!==this.state.status)return!1;const o=e?.pending?this.state.location:this.state.resolvedLocation;if(!o)return!1;const s=D(this.basepath,o.pathname,{...e,to:r.pathname});return!!s&&(e?.includeSearch??1?!!M(o.search,r.search)&&s:s)};buildLink=t=>{const{to:e,preload:r,preloadDelay:o,activeOptions:s,disabled:n,target:a,replace:i,resetScroll:c}=t;try{return new URL(`${e}`),{type:"external",href:e}}catch(t){}const h=t,u=this.buildLocation(h),l=r??this.options.defaultPreload,d=o??this.options.defaultPreloadDelay??0,p=this.state.location.pathname.split("/"),f=u.pathname.split("/").every(((t,e)=>t===p[e])),m=s?.exact?this.state.location.pathname===u.pathname:f,y=!s?.includeHash||this.state.location.hash===u.hash,g=!(s?.includeSearch??1)||M(this.state.location.search,u.search);return{type:"internal",next:u,handleFocus:t=>{l&&this.preloadRoute(h).catch((t=>{console.warn(t),console.warn(V)}))},handleClick:t=>{n||function(t){return!!(t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)}(t)||t.defaultPrevented||a&&"_self"!==a||0!==t.button||(t.preventDefault(),this.#e({...u,replace:i,resetScroll:c}))},handleEnter:t=>{const e=t.target||{};if(l){if(e.preloadTimeout)return;e.preloadTimeout=setTimeout((()=>{e.preloadTimeout=null,this.preloadRoute(h).catch((t=>{console.warn(t),console.warn(V)}))}),d)}},handleLeave:t=>{const e=t.target||{};e.preloadTimeout&&(clearTimeout(e.preloadTimeout),e.preloadTimeout=null)},handleTouchStart:t=>{this.preloadRoute(h).catch((t=>{console.warn(t),console.warn(V)}))},isActive:m&&y&&g,disabled:n}};dehydrate=()=>({state:{matchIds:this.state.matchIds,dehydratedMatches:this.state.matches.map((t=>R(t,["fetchedAt","invalid","preloadMaxAge","maxAge","id","loaderData","status","updatedAt"])))}});hydrate=async t=>{let e=t;"undefined"!=typeof document&&(e=window.__TSR_DEHYDRATED__),v(e);const r=e;this.dehydratedData=r.payload,this.options.hydrate?.(r.payload);const o=r.router.state;let s=this.matchRoutes(this.state.location.pathname,this.state.location.search).map((t=>{const e=o.dehydratedMatches.find((e=>e.id===t.id));return v(e,t.id),e?{...t,...e}:t}));this.__store.setState((t=>({...t,matchIds:o.matchIds,matches:s,matchesById:this.#a(t.matchesById,s)})))};injectedHtml=[];injectHtml=async t=>{this.injectedHtml.push(t)};dehydrateData=(t,e)=>{if("undefined"==typeof document){const r="string"==typeof t?t:JSON.stringify(t);return this.injectHtml((async()=>{const t=`__TSR_DEHYDRATED__${r}`,o="function"==typeof e?await e():e;return`<script id='${t}' suppressHydrationWarning>window["__TSR_DEHYDRATED__${s=r,s.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"')}"] = ${JSON.stringify(o)}\n ;(() => {\n var el = document.getElementById('${t}')\n el.parentElement.removeChild(el)\n })()\n <\/script>`;var s})),()=>this.hydrateData(t)}return()=>{}};hydrateData=t=>{if("undefined"!=typeof document){const e="string"==typeof t?t:JSON.stringify(t);return window[`__TSR_DEHYDRATED__${e}`]}};#n=t=>{this.routeTree=t,this.routesById={},this.routesByPath={},this.flatRoutes=[];const e=t=>{t.forEach(((t,r)=>{t.init({originalIndex:r,router:this});if(v(!this.routesById[t.id],String(t.id)),this.routesById[t.id]=t,!t.isRoot&&t.path){const e=C(t.fullPath);this.routesByPath[e]&&!t.fullPath.endsWith("/")||(this.routesByPath[e]=t)}const o=t.children;o?.length&&e(o)}))};e([t]),this.flatRoutes=Object.values(this.routesByPath).map(((t,e)=>{const r=O(t.fullPath),o=k(r);for(;o.length>1&&"/"===o[0]?.value;)o.shift();const s=o.map((t=>"param"===t.type?.5:"wildcard"===t.type?.25:1));return{child:t,trimmed:r,parsed:o,index:e,score:s}})).sort(((t,e)=>{let r="/"===t.trimmed?1:"/"===e.trimmed?-1:0;if(0!==r)return r;const o=Math.min(t.score.length,e.score.length);if(t.score.length!==e.score.length)return e.score.length-t.score.length;for(let r=0;r<o;r++)if(t.score[r]!==e.score[r])return e.score[r]-t.score[r];for(let r=0;r<o;r++)if(t.parsed[r].value!==e.parsed[r].value)return t.parsed[r].value>e.parsed[r].value?1:-1;return t.trimmed!==e.trimmed?t.trimmed>e.trimmed?1:-1:t.index-e.index})).map(((t,e)=>(t.child.rank=e,t.child)))};#s=t=>{const e=({pathname:e,search:r,hash:o,state:s})=>{const n=this.options.parseSearch(r);return{pathname:e,searchStr:r,search:_(t?.search,n),hash:o.split("#").reverse()[0]??"",href:`${e}${r}${o}`,state:_(t?.state,s)}},r=e(this.history.location);let{__tempLocation:o,__tempKey:s}=r.state;if(o&&(!s||s===this.tempLocationKey)){const t=e(o);return t.state.key=r.state.key,delete t.state.__tempLocation,{...t,maskedLocation:r}}return r};buildLocation=(t={})=>{const e=(t={},e)=>{const r=this.state.location,o=t.from??r.pathname;let s=A(this.basepath??"/",o,`${t.to??""}`);const n={...b(this.matchRoutes(o,r.search))?.params};let a=!0===(t.params??!0)?n:S(t.params,n);a&&e?.map((t=>this.getRoute(t.routeId).options.stringifyParams)).filter(Boolean).forEach((t=>{a={...a,...t(a)}})),s=j(s,a??{});const i=e?.map((t=>this.getRoute(t.routeId).options.preSearchFilters??[])).flat().filter(Boolean)??[],c=e?.map((t=>this.getRoute(t.routeId).options.postSearchFilters??[])).flat().filter(Boolean)??[],h=i?.length?i?.reduce(((t,e)=>e(t)),r.search):r.search,u=!0===t.search?h:t.search?S(t.search,h)??{}:i?.length?h:{},l=c?.length?c.reduce(((t,e)=>e(t)),u):u,d=_(r.search,l),p=this.options.stringifySearch(d),f=!0===t.hash?r.hash:t.hash?S(t.hash,r.hash):r.hash,m=f?`#${f}`:"";let y=!0===t.state?r.state:t.state?S(t.state,r.state):r.state;return y=_(r.state,y),{pathname:s,search:d,searchStr:p,state:y,hash:f,href:this.history.createHref(`${s}${p}${m}`),unmaskOnReload:t.unmaskOnReload}},r=(t={},r)=>{let o=e(t),s=r?e(r):void 0;if(!s){let t={},n=this.options.routeMasks?.find((e=>{const r=D(this.basepath,o.pathname,{to:e.from,fuzzy:!1});return!!r&&(t=r,!0)}));n&&(n={...n,from:j(n.from,t)},s=e(r=n))}const n=this.matchRoutes(o.pathname,o.search),a=s?this.matchRoutes(s.pathname,s.search):void 0,i=s?e(r,a):void 0,c=e(t,n);return i&&(c.maskedLocation=i),c};return t.mask?r(t,{...R(t,["from"]),...t.mask}):r(t)};#i=({replace:t,resetScroll:e,...r}={})=>{const o=this.buildLocation(r);return this.#e({...o,replace:t,resetScroll:e})};#e=async t=>{this.navigateTimeout&&clearTimeout(this.navigateTimeout);if(this.state.location.href===t.href&&!t.replace)return;let{maskedLocation:e,...r}=t;return e&&(r={...e,state:{...e.state,__tempKey:void 0,__tempLocation:{...r,search:r.searchStr,state:{...r.state,__tempKey:void 0,__tempLocation:void 0,key:void 0}}}},(r.unmaskOnReload??this.options.unmaskOnReload)&&(r.state.__tempKey=this.tempLocationKey)),this.history[t.replace?"replace":"push"](r.href,r.state),this.resetNextScroll=t.resetScroll??!0,this.latestLoadPromise};getRouteMatch=t=>this.state.matchesById[t];setRouteMatch=(t,e)=>{this.__store.setState((r=>r.matchesById[t]?{...r,matchesById:{...r.matchesById,[t]:e(r.matchesById[t])}}:r))};setRouteMatchData=(t,e,r)=>{const o=this.getRouteMatch(t);if(!o)return;const s=this.getRoute(o.routeId),n=r?.updatedAt??Date.now(),a=r?.maxAge??s.options.preloadMaxAge??this.options.defaultPreloadMaxAge??5e3,i=r?.maxAge??s.options.maxAge??this.options.defaultMaxAge??-1;this.setRouteMatch(t,(t=>({...t,error:void 0,status:"success",isFetching:!1,updatedAt:n,loaderData:S(e,t.loaderData),preloadMaxAge:a,maxAge:i})))};invalidate=async t=>{if(t?.matchId){this.setRouteMatch(t.matchId,(t=>({...t,invalid:!0})));const e=this.state.matches.findIndex((e=>e.id===t.matchId)),r=this.state.matches[e+1];if(r)return this.invalidate({matchId:r.id,reload:!1,__fromFocus:t.__fromFocus})}else this.__store.batch((()=>{Object.values(this.state.matchesById).forEach((e=>{const r=this.getRoute(e.routeId);(!t?.__fromFocus||(r.options.reloadOnWindowFocus??!0))&&this.setRouteMatch(e.id,(t=>({...t,invalid:!0})))}))}));if(t?.reload??1)return this.load()}},t.RouterContext=class{constructor(){}createRootRoute=t=>new K(t)},t.RouterProvider=function({router:t,...e}){t.update(e),s.useEffect((()=>{let e;return s.startTransition((()=>{e=t.mount()})),e}),[t]);const r=t.options.Wrap||s.Fragment;return s.createElement(r,null,s.createElement(wt.Provider,{value:t},s.createElement(bt,null)))},t.ScrollRestoration=function(t){return Tt(t),null},t.SearchParamError=tt,t.cleanPath=P,t.componentTypes=J,t.createBrowserHistory=m,t.createHashHistory=function(){return m({getHref:()=>window.location.hash.substring(1),createHref:t=>`#${t}`})},t.createMemoryHistory=y,t.createRouteMask=function(t){return t},t.decode=F,t.defaultParseSearch=W,t.defaultStringifySearch=U,t.defer=function(t){const e=t;if(!e.__deferredState){e.__deferredState={uid:Math.random().toString(36).slice(2),status:"pending"};const t=e.__deferredState;e.then((e=>{t.status="success",t.data=e})).catch((e=>{t.status="error",t.error=e}))}return e},t.encode=T,t.functionalUpdate=S,t.interpolatePath=j,t.invariant=v,t.isDehydratedDeferred=dt,t.isMatchInvalid=rt,t.isPlainObject=E,t.isRedirect=Z,t.joinPaths=I,t.last=b,t.lazyFn=function(t,e){return async(...r)=>(await t())[e||"default"](...r)},t.lazyRouteComponent=function(t,e){let r;const o=()=>(r||(r=t()),r),n=s.lazy((async()=>({default:(await o())[e??"default"]})));return n.preload=o,n},t.matchByPath=B,t.matchIdsContext=gt,t.matchPathname=D,t.parsePathname=k,t.parseSearchWith=z,t.partialDeepEqual=M,t.pick=R,t.redirect=function(t){return t.isRedirect=!0,t},t.replaceEqualDeep=_,t.resolvePath=A,t.restoreScrollPositions=lt,t.rootRouteId=H,t.routerContext=wt,t.shallow=function(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const r=Object.keys(t);if(r.length!==Object.keys(e).length)return!1;for(let o=0;o<r.length;o++)if(!Object.prototype.hasOwnProperty.call(e,r[o])||!Object.is(t[r[o]],e[r[o]]))return!1;return!0},t.stringifySearchWith=Y,t.trimPath=O,t.trimPathLeft=L,t.trimPathRight=C,t.useAwaited=$t,t.useBlocker=Dt,t.useDehydrate=function(){const t=St();return s.useCallback((function(e,r){return t.dehydrateData(e,r)}),[])},t.useHydrate=function(){const t=St();return function(e){return t.hydrateData(e)}},t.useInjectHtml=function(){const t=St();return s.useCallback((e=>{t.injectHtml(e)}),[])},t.useLinkProps=mt,t.useLoader=_t,t.useMatch=Rt,t.useMatchRoute=Mt,t.useMatches=function(t){const e=s.useContext(gt);return vt({select:r=>{const o=r.renderedMatches.slice(r.renderedMatches.findIndex((t=>t.id===e[0])));return t?.select?t.select(o):o}})},t.useNavigate=function(t){const e=St();return s.useCallback((r=>e.navigate({...t,...r})),[])},t.useParams=xt,t.useRouteContext=function(t){return Rt({...t,select:e=>t?.select?t.select(e.context):e.context})},t.useRouter=St,t.useRouterContext=function(t){return Rt({...t,select:e=>t?.select?t.select(e.context):e.context})},t.useRouterState=vt,t.useScrollRestoration=Tt,t.useSearch=Et,t.useStore=a,t.warning=function(t,e){},t.watchScrollPositions=ut,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
22
53
|
//# sourceMappingURL=index.production.js.map
|