@vielzeug/wayfinder 2.1.0 → 2.2.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.
- package/dist/compile.cjs +1 -1
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.js +1 -1
- package/dist/context.cjs +1 -1
- package/dist/context.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/router.cjs +1 -1
- package/dist/router.js +80 -80
- package/package.json +2 -13
- package/dist/devtools.cjs +0 -2
- package/dist/devtools.cjs.map +0 -1
- package/dist/devtools.d.ts +0 -47
- package/dist/devtools.d.ts.map +0 -1
- package/dist/devtools.js +0 -13
- package/dist/devtools.js.map +0 -1
package/dist/compile.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require("./
|
|
1
|
+
const e=require("./errors.cjs");require("./_dev.cjs");const t=require("./path.cjs");function n(n){let r=[],i=(n,a,o,s,c)=>{if(a.index&&a.path!==void 0)throw new e.WayfinderRouteError(`Route "${n}" cannot define both index and path`);if(!a.index&&a.path===void 0)throw new e.WayfinderRouteError(`Route "${n}" must define path or set index: true`);let l=a.index?o:t.normalizePath(a.path?t.joinPaths(o,a.path):o),u=[...s,{component:a.component,dataFn:a.data,lazy:a.lazy,meta:a.meta,name:n,onError:a.onError}],d=[...c,...a.middleware??[]];if(a.children)for(let[e,t]of Object.entries(a.children))i(`${n}.${e}`,t,l,u,d);if(a.lazy!==void 0||a.redirect!==void 0||!a.children||a.data!==void 0){let e=u[u.length-1];r.push({branchDefs:u,coerceSearch:a.coerceSearch,leaf:e,matcher:t.compilePathMatcher(l),ownMiddleware:d,path:l,redirect:a.redirect})}};for(let[e,t]of Object.entries(n.routes))i(e,t,`/`,[],[]);let a=new Set;for(let t of r){if(a.has(t.leaf.name))throw new e.WayfinderRouteError(`Duplicate route name: "${t.leaf.name}". A top-level route key must not coincide with a nested route's dot-notation name.`);a.add(t.leaf.name)}let o=!1;for(let e of r){let t=e.path===`/*`||e.path.endsWith(`/*`)||e.path.includes(`:`)&&e.path.endsWith(`*`);o&&!t&&`${e.leaf.name}${e.path}`,t&&(o=!0)}return{records:r,routesByName:new Map(r.map(e=>[e.leaf.name,e]))}}exports.compileRoutes=n;
|
|
2
2
|
//# sourceMappingURL=compile.cjs.map
|
package/dist/compile.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.cjs","names":[],"sources":["../src/compile.ts"],"sourcesContent":["import { warn } from './_dev';\nimport { WayfinderRouteError } from './errors';\nimport { compilePathMatcher, joinPaths, normalizePath } from './path';\nimport type { Middleware, RouteBranchDef, RouteDefinition, RouteRecord, RouterOptions, RouteTable } from './types';\n\nexport type CompiledRoutes<TMeta = unknown, TComponent = unknown> = {\n records: readonly RouteRecord<TMeta, TComponent>[];\n routesByName: ReadonlyMap<string, RouteRecord<TMeta, TComponent>>;\n};\n\nexport function compileRoutes<TRoutes extends RouteTable, TMeta, TComponent>(\n options: RouterOptions<TRoutes, TMeta, TComponent>,\n): CompiledRoutes<TMeta, TComponent> {\n const records: RouteRecord<TMeta, TComponent>[] = [];\n\n const compile = (\n name: string,\n route: RouteDefinition,\n ancestorPath: string,\n ancestorBranchDefs: RouteBranchDef<TMeta, TComponent>[],\n ancestorMiddleware: RouteRecord<TMeta, TComponent>['ownMiddleware'],\n ): void => {\n if (route.index && route.path !== undefined) {\n throw new WayfinderRouteError(`Route \"${name}\" cannot define both index and path`);\n }\n\n if (!route.index && route.path === undefined) {\n throw new WayfinderRouteError(`Route \"${name}\" must define path or set index: true`);\n }\n\n const ownPath = route.index\n ? ancestorPath\n : normalizePath(route.path ? joinPaths(ancestorPath, route.path) : ancestorPath);\n\n const branchDefs: RouteBranchDef<TMeta, TComponent>[] = [\n ...ancestorBranchDefs,\n {\n component: route.component as TComponent | undefined,\n dataFn: route.data,\n lazy: route.lazy as RouteBranchDef<TMeta, TComponent>['lazy'],\n meta: route.meta as TMeta | undefined,\n name,\n onError: route.onError as RouteBranchDef<TMeta, TComponent>['onError'],\n },\n ];\n\n const ownMiddleware: Middleware[] = [\n ...ancestorMiddleware,\n ...((route.middleware ?? []) as unknown as Middleware[]),\n ];\n\n if (route.children) {\n for (const [childName, childRoute] of Object.entries(route.children)) {\n compile(`${name}.${childName}`, childRoute, ownPath, branchDefs, ownMiddleware);\n }\n }\n\n // Emit a record for leaf routes (no children), redirects, lazy routes, and routes with data.\n // A bare parent-only route (children but no data/lazy/redirect) is not emitted as a leaf.\n if (route.lazy !== undefined || route.redirect !== undefined || !route.children || route.data !== undefined) {\n const leaf = branchDefs[branchDefs.length - 1]!;\n\n records.push({\n branchDefs,\n coerceSearch: route.coerceSearch,\n leaf,\n matcher: compilePathMatcher(ownPath),\n ownMiddleware,\n path: ownPath,\n redirect: route.redirect,\n });\n }\n };\n\n for (const [name, route] of Object.entries(options.routes)) {\n compile(name, route, '/', [], []);\n }\n\n // Validate duplicate names.\n const namesSeen = new Set<string>();\n\n for (const record of records) {\n if (namesSeen.has(record.leaf.name)) {\n throw new WayfinderRouteError(\n `Duplicate route name: \"${record.leaf.name}\". A top-level route key must not coincide with a nested route's dot-notation name.`,\n );\n }\n\n namesSeen.add(record.leaf.name);\n }\n\n // Warn when a catch-all or wildcard-param route precedes more specific routes.\n // Routes match in array order (object key order), so a wildcard placed too early silently shadows later routes.\n let wildcardSeen = false;\n\n for (const record of records) {\n const isCatchAll =\n record.path === '/*' || record.path.endsWith('/*') || (record.path.includes(':') && record.path.endsWith('*'));\n\n if (wildcardSeen && !isCatchAll) {\n warn(\n `Route \"${record.leaf.name}\" (${record.path}) is defined after a wildcard/catch-all route and will never match. Move specific routes before wildcards.`,\n );\n }\n\n if (isCatchAll) wildcardSeen = true;\n }\n\n return {\n records,\n routesByName: new Map(records.map((r) => [r.leaf.name, r])),\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile.cjs","names":[],"sources":["../src/compile.ts"],"sourcesContent":["import { warn } from './_dev';\nimport { WayfinderRouteError } from './errors';\nimport { compilePathMatcher, joinPaths, normalizePath } from './path';\nimport type { Middleware, RouteBranchDef, RouteDefinition, RouteRecord, RouterOptions, RouteTable } from './types';\n\nexport type CompiledRoutes<TMeta = unknown, TComponent = unknown> = {\n records: readonly RouteRecord<TMeta, TComponent>[];\n routesByName: ReadonlyMap<string, RouteRecord<TMeta, TComponent>>;\n};\n\nexport function compileRoutes<TRoutes extends RouteTable, TMeta, TComponent>(\n options: RouterOptions<TRoutes, TMeta, TComponent>,\n): CompiledRoutes<TMeta, TComponent> {\n const records: RouteRecord<TMeta, TComponent>[] = [];\n\n const compile = (\n name: string,\n route: RouteDefinition,\n ancestorPath: string,\n ancestorBranchDefs: RouteBranchDef<TMeta, TComponent>[],\n ancestorMiddleware: RouteRecord<TMeta, TComponent>['ownMiddleware'],\n ): void => {\n if (route.index && route.path !== undefined) {\n throw new WayfinderRouteError(`Route \"${name}\" cannot define both index and path`);\n }\n\n if (!route.index && route.path === undefined) {\n throw new WayfinderRouteError(`Route \"${name}\" must define path or set index: true`);\n }\n\n const ownPath = route.index\n ? ancestorPath\n : normalizePath(route.path ? joinPaths(ancestorPath, route.path) : ancestorPath);\n\n const branchDefs: RouteBranchDef<TMeta, TComponent>[] = [\n ...ancestorBranchDefs,\n {\n component: route.component as TComponent | undefined,\n dataFn: route.data,\n lazy: route.lazy as RouteBranchDef<TMeta, TComponent>['lazy'],\n meta: route.meta as TMeta | undefined,\n name,\n onError: route.onError as RouteBranchDef<TMeta, TComponent>['onError'],\n },\n ];\n\n const ownMiddleware: Middleware[] = [\n ...ancestorMiddleware,\n ...((route.middleware ?? []) as unknown as Middleware[]),\n ];\n\n if (route.children) {\n for (const [childName, childRoute] of Object.entries(route.children)) {\n compile(`${name}.${childName}`, childRoute, ownPath, branchDefs, ownMiddleware);\n }\n }\n\n // Emit a record for leaf routes (no children), redirects, lazy routes, and routes with data.\n // A bare parent-only route (children but no data/lazy/redirect) is not emitted as a leaf.\n if (route.lazy !== undefined || route.redirect !== undefined || !route.children || route.data !== undefined) {\n const leaf = branchDefs[branchDefs.length - 1]!;\n\n records.push({\n branchDefs,\n coerceSearch: route.coerceSearch,\n leaf,\n matcher: compilePathMatcher(ownPath),\n ownMiddleware,\n path: ownPath,\n redirect: route.redirect,\n });\n }\n };\n\n for (const [name, route] of Object.entries(options.routes)) {\n compile(name, route, '/', [], []);\n }\n\n // Validate duplicate names.\n const namesSeen = new Set<string>();\n\n for (const record of records) {\n if (namesSeen.has(record.leaf.name)) {\n throw new WayfinderRouteError(\n `Duplicate route name: \"${record.leaf.name}\". A top-level route key must not coincide with a nested route's dot-notation name.`,\n );\n }\n\n namesSeen.add(record.leaf.name);\n }\n\n // Warn when a catch-all or wildcard-param route precedes more specific routes.\n // Routes match in array order (object key order), so a wildcard placed too early silently shadows later routes.\n let wildcardSeen = false;\n\n for (const record of records) {\n const isCatchAll =\n record.path === '/*' || record.path.endsWith('/*') || (record.path.includes(':') && record.path.endsWith('*'));\n\n if (wildcardSeen && !isCatchAll) {\n warn(\n `Route \"${record.leaf.name}\" (${record.path}) is defined after a wildcard/catch-all route and will never match. Move specific routes before wildcards.`,\n );\n }\n\n if (isCatchAll) wildcardSeen = true;\n }\n\n return {\n records,\n routesByName: new Map(records.map((r) => [r.leaf.name, r])),\n };\n}\n"],"mappings":"oFAUA,SAAgB,EACd,EACmC,CACnC,IAAM,EAA4C,CAAC,EAE7C,GACJ,EACA,EACA,EACA,EACA,IACS,CACT,GAAI,EAAM,OAAS,EAAM,OAAS,IAAA,GAChC,MAAM,IAAI,EAAA,oBAAoB,UAAU,EAAK,oCAAoC,EAGnF,GAAI,CAAC,EAAM,OAAS,EAAM,OAAS,IAAA,GACjC,MAAM,IAAI,EAAA,oBAAoB,UAAU,EAAK,sCAAsC,EAGrF,IAAM,EAAU,EAAM,MAClB,EACA,EAAA,cAAc,EAAM,KAAO,EAAA,UAAU,EAAc,EAAM,IAAI,EAAI,CAAY,EAE3E,EAAkD,CACtD,GAAG,EACH,CACE,UAAW,EAAM,UACjB,OAAQ,EAAM,KACd,KAAM,EAAM,KACZ,KAAM,EAAM,KACZ,OACA,QAAS,EAAM,OACjB,CACF,EAEM,EAA8B,CAClC,GAAG,EACH,GAAK,EAAM,YAAc,CAAC,CAC5B,EAEA,GAAI,EAAM,SACR,IAAK,GAAM,CAAC,EAAW,KAAe,OAAO,QAAQ,EAAM,QAAQ,EACjE,EAAQ,GAAG,EAAK,GAAG,IAAa,EAAY,EAAS,EAAY,CAAa,EAMlF,GAAI,EAAM,OAAS,IAAA,IAAa,EAAM,WAAa,IAAA,IAAa,CAAC,EAAM,UAAY,EAAM,OAAS,IAAA,GAAW,CAC3G,IAAM,EAAO,EAAW,EAAW,OAAS,GAE5C,EAAQ,KAAK,CACX,aACA,aAAc,EAAM,aACpB,OACA,QAAS,EAAA,mBAAmB,CAAO,EACnC,gBACA,KAAM,EACN,SAAU,EAAM,QAClB,CAAC,CACH,CACF,EAEA,IAAK,GAAM,CAAC,EAAM,KAAU,OAAO,QAAQ,EAAQ,MAAM,EACvD,EAAQ,EAAM,EAAO,IAAK,CAAC,EAAG,CAAC,CAAC,EAIlC,IAAM,EAAY,IAAI,IAEtB,IAAK,IAAM,KAAU,EAAS,CAC5B,GAAI,EAAU,IAAI,EAAO,KAAK,IAAI,EAChC,MAAM,IAAI,EAAA,oBACR,0BAA0B,EAAO,KAAK,KAAK,oFAC7C,EAGF,EAAU,IAAI,EAAO,KAAK,IAAI,CAChC,CAIA,IAAI,EAAe,GAEnB,IAAK,IAAM,KAAU,EAAS,CAC5B,IAAM,EACJ,EAAO,OAAS,MAAQ,EAAO,KAAK,SAAS,IAAI,GAAM,EAAO,KAAK,SAAS,GAAG,GAAK,EAAO,KAAK,SAAS,GAAG,EAE1G,GAAgB,CAAC,GAEjB,GAAU,EAAO,KAAK,KAAtB,EAAgC,EAAO,KAAvC,EAIA,IAAY,EAAe,GACjC,CAEA,MAAO,CACL,UACA,aAAc,IAAI,IAAI,EAAQ,IAAK,GAAM,CAAC,EAAE,KAAK,KAAM,CAAC,CAAC,CAAC,CAC5D,CACF"}
|
package/dist/compile.js
CHANGED
package/dist/context.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require("./
|
|
1
|
+
const e=require("./errors.cjs");require("./_dev.cjs");function t(e){return{error:e.error,location:e.location,matches:e.matches,status:e.status}}function n(e,t,n,r,i){return e.map((e,a)=>({component:e.component,data:r[a],meta:e.meta,name:e.name,params:{...t},pathname:n,status:i?.[a]??`idle`}))}function r(e,t,n,r,i){return{hash:e.hash,historyState:e.historyState,locals:{},matches:r,navigate:i,params:n,pathname:e.pathname,query:t}}async function i(t,n,r){let i=!1;async function a(o){if(o<n.length){let r=!1;await n[o]?.(t,async()=>{if(r)throw new e.WayfinderApiError(`next() called multiple times`);r=!0,await a(o+1)});return}i=!0,await r()}return await a(0),i}function a(e,t,n){if(n){n(e,t);return}}exports.buildMatchBranch=n,exports.createRouteContext=r,exports.createRouteState=t,exports.executeMiddlewarePipeline=i,exports.reportError=a;
|
|
2
2
|
//# sourceMappingURL=context.cjs.map
|
package/dist/context.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./history.cjs"),n=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./history.cjs"),n=require("./middleware.cjs"),r=require("./router.cjs");exports.WayfinderApiError=e.WayfinderApiError,exports.WayfinderDisposedError=e.WayfinderDisposedError,exports.WayfinderError=e.WayfinderError,exports.WayfinderRedirectLoopError=e.WayfinderRedirectLoopError,exports.WayfinderRouteError=e.WayfinderRouteError,exports.createBrowserHistory=t.createBrowserHistory,exports.createMemoryHistory=t.createMemoryHistory,exports.createRouter=r.createRouter,exports.redirectTo=n.redirectTo;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WayfinderApiError as e, WayfinderDisposedError as t, WayfinderError as n, WayfinderRedirectLoopError as r, WayfinderRouteError as i } from "./errors.js";
|
|
2
2
|
import { createBrowserHistory as a, createMemoryHistory as o } from "./history.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export { e as WayfinderApiError, t as WayfinderDisposedError, n as WayfinderError, r as WayfinderRedirectLoopError, i as WayfinderRouteError, a as createBrowserHistory, o as createMemoryHistory,
|
|
3
|
+
import { redirectTo as s } from "./middleware.js";
|
|
4
|
+
import { createRouter as c } from "./router.js";
|
|
5
|
+
export { e as WayfinderApiError, t as WayfinderDisposedError, n as WayfinderError, r as WayfinderRedirectLoopError, i as WayfinderRouteError, a as createBrowserHistory, o as createMemoryHistory, c as createRouter, s as redirectTo };
|
package/dist/router.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./_navigation.cjs"),t=require("./errors.cjs"),n=require("./path.cjs"),r=require("./compile.cjs"),i=require("./context.cjs"),a=require("./guards.cjs"),o=require("./history.cjs"),s=require("./hydration.cjs"),c=require("./preload.cjs");function l(e,n){let r=n.get(e);if(r)return r;let i=[...n.keys()].join(`, `);throw new t.WayfinderRouteError(i?`Unknown route name: ${e}. Available routes: ${i}`:`Unknown route name: ${e}`)}function u(e,t,r=`/`){if(`path`in e)return e.path;let i=l(e.name,t),a=n.buildUrl(r,i.path,e.params,e.query);return e.hash?`${a}#${e.hash}`:a}var d=Symbol(`wayfinder.errorContext`);function f(e,t){typeof e==`object`&&e&&(e[d]=t)}function p(e){if(typeof e==`object`&&e)return e[d]}function m(e){return typeof e==`object`&&!!e&&typeof e[Symbol.asyncIterator]==`function`&&typeof e.next==`function`&&typeof e.return==`function`}var h=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=new Set;#u=e.createNavigationCoordinator();#d;#f=!1;#p=new AbortController;#m=`/`;#h=new Set;#g;#_;#v;#y;ready;constructor(e){let t=r.compileRoutes(e);if(this.#e=n.normalizePath(e.base??`/`),this.#t=e.middleware??[],this.#n=e.coerceSearch,this.#r=e.history??o.createBrowserHistory(),this.#s=e.viewTransition??!1,this.#o=e.scroll,this.#c=e.onError,this.#i=t.records,this.#a=t.routesByName,this.#_=s.createHydrationManager(),this.#v=c.createPreloadManager(),this.#d=i.createRouteState({location:{hash:``,historyState:null,pathname:`/`,query:{}},matches:[],status:`idle`}),e.notFound){let t=e.notFound,n={component:t.component,dataFn:t.data,meta:t.meta,name:`__notFound__`};this.#g={branchDefs:[n],leaf:n,matcher:{paramNames:[],pattern:/(?:)/,prefixPattern:/(?:)/},ownMiddleware:t.middleware??[],path:`/*`}}else this.#g=null;this.#y=this.#x();let{hash:a,pathname:l,search:u}=this.#r.location;this.#m=`${l}${u}${a}`;let d=this.#u.begin();this.ready=this.#F(d,n.readLocation(this.#e,this.#r),(e,t)=>{if(!d.isCurrent())return;let n=this.#z(e);t&&this.#r.replace(n,e.historyState),this.#m=n},void 0,0,!1).then(()=>void 0),this.#w(this.ready,{source:`initial-navigation`}),this.beforeLeave=this.beforeLeave.bind(this),this.dispose=this.dispose.bind(this),this.getSnapshot=this.getSnapshot.bind(this),this.isActive=this.isActive.bind(this),this.load=this.load.bind(this),this.match=this.match.bind(this),this.navigate=this.navigate.bind(this),this.preload=this.preload.bind(this),this.subscribe=this.subscribe.bind(this),this.url=this.url.bind(this),this.waitFor=this.waitFor.bind(this)}getSnapshot(){return this.#d}subscribe(e){return this.#b(),this.#h.add(e),()=>{this.#h.delete(e)}}navigate(e,t){let n=u(typeof e==`string`?{path:e}:e,this.#a);return this.#V(n,t)}url(e,t,r){let i=l(e,this.#a);return n.buildUrl(this.#e,i.path,t,r)}isActive(e,t={}){let r=l(e,this.#a),i=this.#d.location.pathname;return t.exact??!1?n.matchRouteFor(i,[r]).record!=null:n.matchesPrefix(i,r)}match(e){let t=n.stripBase(n.normalizePath(e),this.#e),{params:r,record:a}=n.matchRouteFor(t,this.#i);if(!a||a.redirect)return null;let o=this.#_.effectiveDefs(a),s=i.buildMatchBranch(o,r,t,o.map(()=>void 0));return s.length?s:null}async load(e,t){let n=await this.#k(e);if(n.type!==`matched`)return null;let{location:r,params:a,record:o,resolvedQuery:s}=n,c=this.#_.effectiveDefs(o),l=c.some(e=>e.dataFn!=null),u=c.map(()=>void 0),d,f=`idle`;if(l){let e=t?.signal??new AbortController().signal,n=i.buildMatchBranch(c,a,r.pathname,u),o=i.createRouteContext(r,s,a,n,()=>Promise.resolve());try{u=await this.#D(c,o,e)}catch(e){d=e,f=`error`}}return i.createRouteState({error:d,location:r,matches:i.buildMatchBranch(c,a,r.pathname,u),status:f})}waitFor(e){return this.#b(),new Promise((t,n)=>{let r=t=>t.status===`idle`&&t.matches.some(t=>t.name===e);if(this.#d.status===`error`){n(this.#d.error);return}if(r(this.#d)){t(this.#d);return}let i=this.subscribe(e=>{r(e)?(i(),t(e)):e.status===`error`&&(i(),n(e.error))});this.#p.signal.addEventListener(`abort`,()=>{i(),n(this.#p.signal.reason)},{once:!0})})}async preload(e,t,r){this.#b();let i=l(e,this.#a),a=n.buildPreloadKey(this.#e,i.path,t,r),o=this.#v.getInflight(a);if(o)return o;let s=this.#A(a,this.#p.signal,r).finally(()=>{this.#v.untrack(a)});this.#v.track(a,s);try{return await s}catch(e){throw this.#c&&this.#C(e,{source:`preload`}),e}}beforeLeave(e,t){this.#b();let n={handler:e,routes:t?.routes};return this.#l.add(n),()=>{this.#l.delete(n)}}get disposalSignal(){return this.#p.signal}get disposed(){return this.#f}dispose(){this.#f||(this.#f=!0,this.#l.clear(),this.#h.clear(),this.#u.invalidate(new t.WayfinderDisposedError),this.#y(),this.#p.abort(new t.WayfinderDisposedError))}[Symbol.dispose](){this.dispose()}#b(){if(this.#f)throw new t.WayfinderDisposedError}#x(){return this.#r.onPopstate(()=>{let{hash:e,pathname:t,search:n}=this.#r.location,r=`${t}${n}${e}`,i=this.#m;r!==i&&this.#w(this.#S(r,i),{source:`history-listener`})})}async#S(e,t){let r=this.#u.begin(),i=this.#d.matches.map(e=>e.name),o=this.#B(e),s=await a.runLeaveBlockers(this.#l,i,o);if(!r.isCurrent())return;if(!s){this.#r.replace(t,this.#d.location.historyState);return}let c=await this.#F(r,n.readLocation(this.#e,this.#r),(e,t)=>{if(!r.isCurrent())return;let n=this.#z(e);t&&this.#r.replace(n,e.historyState),this.#m=n},void 0,0,!1);r.isCurrent()&&!c&&this.#r.replace(t,this.#d.location.historyState)}#C(e,t){i.reportError(e,t,this.#c)}#w(e,t){e.catch(e=>{this.#C(e,p(e)??t)})}#T(){this.#h.forEach(e=>{e(this.#d)})}async#E(e,t){let n;for(;;){if(t.aborted)return await e.return(void 0).catch(()=>void 0),n;let{done:r,value:i}=await e.next();if(r)return i??n;n=i}}async#D(e,t,n){return Promise.all(e.map(async e=>{if(!e.dataFn)return;let r=e.dataFn,i=r({...t,signal:n});try{return m(i)?await this.#E(i,n):await i}catch(r){if(e.onError)return e.onError(r,{...t,signal:n});throw r}}))}async#O(e,t,n,r,a,o){let s=e.map(e=>{if(!e.dataFn)return;let r=e.dataFn;return r({...t,signal:n})}),c=[],l=await Promise.all(s.map(async(r,i)=>{if(m(r)){c.push(i);return}if(r!==void 0)try{return await r}catch(r){let a=e[i];if(a.onError)return a.onError(r,{...t,signal:n});throw r}}));if(c.length===0)return l;let u=[...l],d=(t,n)=>{if(!r())return;u[n]=t;let s=e.map((e,t)=>c.includes(t)?`streaming`:`idle`);this.#d=i.createRouteState({location:a,matches:i.buildMatchBranch(e,o,a.pathname,u,s),status:`streaming`}),this.#T()};return await Promise.all(c.map(async i=>{let a=s[i];try{u[i]=await this.#M(a,i,n,r,d)}catch(r){let a=e[i];if(a.onError)u[i]=await a.onError(r,{...t,signal:n});else throw r}})),u}async#k(e){let r=e;for(let e=0;e<5;e+=1){let e=new URL(r,`http://localhost`),t={hash:e.hash.replace(/^#/,``),historyState:null,pathname:n.stripBase(e.pathname,this.#e),query:n.parseQuery(e.search)},i=await this.#j(t);if(i.type!==`redirect`)return i;r=this.#L(i.redirectTo)}throw new t.WayfinderRedirectLoopError}async#A(e,t,r){let a=await this.#k(e);if(a.type!==`matched`)return;let{location:o,params:s,record:c,resolvedQuery:l}=a,u=this.#_.effectiveDefs(c);if(!u.some(e=>e.dataFn!=null))return;let d=i.buildMatchBranch(u,s,o.pathname,u.map(()=>void 0)),f=i.createRouteContext(o,l,s,d,()=>Promise.resolve()),p=await this.#D(u,f,t);this.#v.set(n.buildPreloadKey(this.#e,c.path,s,r??o.query),p)}async#j(e){let{params:t,record:r}=n.matchRouteFor(e.pathname,this.#i);if(!r)return{location:e,params:t,type:`unmatched`};if(r.redirect)return{location:e,params:t,redirectTo:u(r.redirect,this.#a,this.#e),type:`redirect`};let a=e.query,o=r.coerceSearch??this.#n;if(o)try{a=o(e.query)}catch(t){this.#C(t,{source:`coerce-search`}),a=e.query}await this.#_.hydrate(r);let s=this.#_.effectiveDefs(r);return{branch:i.buildMatchBranch(s,t,e.pathname,s.map(()=>void 0)),location:e,params:t,record:r,resolvedQuery:a,type:`matched`}}async#M(e,t,n,r,i){let a;try{for(;;){if(n.aborted||!r())return await e.return(void 0),a;let{done:o,value:s}=await e.next();if(o)return s??a;a=s,i(s,t)}}catch(t){throw await e.return(void 0).catch(()=>void 0),t}}async#N(e,t,r,a,o,s){if(!s())return;let c=this.#_.effectiveDefs(e),l=c.some(e=>e.dataFn!=null),u=c.map(()=>void 0);if(l){let l=n.buildPreloadKey(this.#e,e.path,a,r.query),d=this.#v.consume(l);if(d)u=d;else{let n=c.map(e=>e.dataFn?`loading`:`idle`);this.#d=i.createRouteState({location:r,matches:i.buildMatchBranch(c,a,r.pathname,u,n),status:`loading`}),this.#T();try{u=await this.#O(c,t,o,s,r,a)}catch(t){if(!s())return;throw this.#d=i.createRouteState({error:t,location:r,matches:i.buildMatchBranch(c,a,r.pathname,u),status:`error`}),f(t,{routeName:e.leaf.name,source:`data-loader`}),t}}}s()&&(this.#d=i.createRouteState({location:r,matches:i.buildMatchBranch(c,a,r.pathname,u),status:`idle`}))}async#P(e,t){if((t??this.#s)&&typeof document<`u`){let t=document;if(t.startViewTransition){await t.startViewTransition(e).finished;return}}await e()}async#F(e,n,r,a,o=0,s=!1){let c=this.#d,l=()=>e.isCurrent()&&!this.#f,u=await this.#j(n);if(!l())return!1;if(u.type===`redirect`){if(o>=5)throw new t.WayfinderRedirectLoopError;return this.#F(e,this.#R(u.redirectTo,n.historyState),r,a,o+1,!0)}if(u.type===`unmatched`){if(this.#g){let t=[this.#g.leaf],o=i.buildMatchBranch(t,{},n.pathname,[void 0]),u=!1,d=!1,f=n.query;if(this.#n)try{f=this.#n(n.query)}catch(e){this.#C(e,{source:`coerce-search`})}let p=async()=>{if(!l())return;let t=i.createRouteContext(n,f,{},o,(e,t)=>this.navigate(e,t));d=await i.executeMiddlewarePipeline(t,[...this.#t,...this.#g.ownMiddleware],async()=>{l()&&(u=!0,r(n,s),l()&&await this.#N(this.#g,t,n,{},e.signal,l))})};try{await this.#P(p,a)}finally{l()&&u&&(this.#T(),this.#I(this.#d,c))}return d&&u}return!l()||(r(u.location,s),!l())?!1:(this.#d=i.createRouteState({location:u.location,matches:[],status:`idle`}),this.#T(),this.#I(this.#d,c),!0)}let{branch:d,location:f,params:p,record:m,resolvedQuery:h}=u,g=!1,_=!1,v=async()=>{if(!l())return;let t=i.createRouteContext(f,h,p,d,(e,t)=>this.navigate(e,t));_=await i.executeMiddlewarePipeline(t,[...this.#t,...m.ownMiddleware],async()=>{l()&&(g=!0,r(f,s),l()&&await this.#N(m,t,f,p,e.signal,l))})};try{await this.#P(v,a)}finally{l()&&g&&(this.#T(),this.#I(this.#d,c))}return _&&g}#I(e,t){if(!this.#o||typeof window>`u`)return;let n=this.#o(e,t);if(n!==`preserve`){if(n===`top`){window.scrollTo(0,0);return}window.scrollTo(n.x,n.y)}}#L(e){let t=new URL(e,`http://localhost`),r=n.stripBase(t.pathname,this.#e);return`${n.joinPaths(this.#e,r)}${t.search}${t.hash}`}#R(e,t){let r=new URL(this.#L(e),`http://localhost`);return{hash:r.hash.replace(/^#/,``),historyState:t,pathname:n.stripBase(r.pathname,this.#e),query:n.parseQuery(r.search)}}#z(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e.query))Array.isArray(r)?r.forEach(e=>{t.append(n,e)}):t.set(n,r);let r=t.toString(),i=e.hash?`#${e.hash}`:``;return`${n.joinPaths(this.#e,e.pathname)}${r?`?${r}`:``}${i}`}#B(e){let t=new URL(e,`http://localhost`),r=n.stripBase(t.pathname,this.#e),{params:i,record:a}=n.matchRouteFor(r,this.#i);return{name:a?.leaf.name,params:i,pathname:r,query:n.parseQuery(t.search)}}async#V(e,t={}){this.#b();let n=this.#L(e);if(!t.force&&n===this.#m)return;let r=this.#u.begin(),i=this.#d.matches.map(e=>e.name),o=await a.runLeaveBlockers(this.#l,i,this.#B(n));!r.isCurrent()||!o||await this.#F(r,this.#R(n,t.state),(e,t)=>{if(!r.isCurrent())return;let n=this.#z(e);t?this.#r.replace(n,e.historyState):this.#r.push(n,e.historyState),this.#m=n},t.viewTransition,0,t.replace??!1)}};function g(e){return new h(e)}exports.createRouter=g;
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./history.cjs"),n=require("./_navigation.cjs"),r=require("./path.cjs"),i=require("./compile.cjs"),a=require("./context.cjs"),o=require("./guards.cjs"),s=require("./hydration.cjs"),c=require("./preload.cjs");function l(t,n){let r=n.get(t);if(r)return r;let i=[...n.keys()].join(`, `);throw new e.WayfinderRouteError(i?`Unknown route name: ${t}. Available routes: ${i}`:`Unknown route name: ${t}`)}function u(e,t,n=`/`){if(`path`in e)return e.path;let i=l(e.name,t),a=r.buildUrl(n,i.path,e.params,e.query);return e.hash?`${a}#${e.hash}`:a}var d=Symbol(`wayfinder.errorContext`);function f(e,t){typeof e==`object`&&e&&(e[d]=t)}function p(e){if(typeof e==`object`&&e)return e[d]}function m(e){return typeof e==`object`&&!!e&&typeof e[Symbol.asyncIterator]==`function`&&typeof e.next==`function`&&typeof e.return==`function`}var h=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=new Set;#u=n.createNavigationCoordinator();#d;#f=!1;#p=new AbortController;#m=`/`;#h=new Set;#g;#_;#v;#y;ready;constructor(e){let n=i.compileRoutes(e);if(this.#e=r.normalizePath(e.base??`/`),this.#t=e.middleware??[],this.#n=e.coerceSearch,this.#r=e.history??t.createBrowserHistory(),this.#s=e.viewTransition??!1,this.#o=e.scroll,this.#c=e.onError,this.#i=n.records,this.#a=n.routesByName,this.#_=s.createHydrationManager(),this.#v=c.createPreloadManager(),this.#d=a.createRouteState({location:{hash:``,historyState:null,pathname:`/`,query:{}},matches:[],status:`idle`}),e.notFound){let t=e.notFound,n={component:t.component,dataFn:t.data,meta:t.meta,name:`__notFound__`};this.#g={branchDefs:[n],leaf:n,matcher:{paramNames:[],pattern:/(?:)/,prefixPattern:/(?:)/},ownMiddleware:t.middleware??[],path:`/*`}}else this.#g=null;this.#y=this.#x();let{hash:o,pathname:l,search:u}=this.#r.location;this.#m=`${l}${u}${o}`;let d=this.#u.begin();this.ready=this.#F(d,r.readLocation(this.#e,this.#r),(e,t)=>{if(!d.isCurrent())return;let n=this.#z(e);t&&this.#r.replace(n,e.historyState),this.#m=n},void 0,0,!1).then(()=>void 0),this.#w(this.ready,{source:`initial-navigation`}),this.beforeLeave=this.beforeLeave.bind(this),this.dispose=this.dispose.bind(this),this.getSnapshot=this.getSnapshot.bind(this),this.isActive=this.isActive.bind(this),this.load=this.load.bind(this),this.match=this.match.bind(this),this.navigate=this.navigate.bind(this),this.preload=this.preload.bind(this),this.subscribe=this.subscribe.bind(this),this.url=this.url.bind(this),this.waitFor=this.waitFor.bind(this)}getSnapshot(){return this.#d}subscribe(e){return this.#b(),this.#h.add(e),()=>{this.#h.delete(e)}}navigate(e,t){let n=u(typeof e==`string`?{path:e}:e,this.#a);return this.#V(n,t)}url(e,t,n){let i=l(e,this.#a);return r.buildUrl(this.#e,i.path,t,n)}isActive(e,t={}){let n=l(e,this.#a),i=this.#d.location.pathname;return t.exact??!1?r.matchRouteFor(i,[n]).record!=null:r.matchesPrefix(i,n)}match(e){let t=r.stripBase(r.normalizePath(e),this.#e),{params:n,record:i}=r.matchRouteFor(t,this.#i);if(!i||i.redirect)return null;let o=this.#_.effectiveDefs(i),s=a.buildMatchBranch(o,n,t,o.map(()=>void 0));return s.length?s:null}async load(e,t){let n=await this.#k(e);if(n.type!==`matched`)return null;let{location:r,params:i,record:o,resolvedQuery:s}=n,c=this.#_.effectiveDefs(o),l=c.some(e=>e.dataFn!=null),u=c.map(()=>void 0),d,f=`idle`;if(l){let e=t?.signal??new AbortController().signal,n=a.buildMatchBranch(c,i,r.pathname,u),o=a.createRouteContext(r,s,i,n,()=>Promise.resolve());try{u=await this.#D(c,o,e)}catch(e){d=e,f=`error`}}return a.createRouteState({error:d,location:r,matches:a.buildMatchBranch(c,i,r.pathname,u),status:f})}waitFor(e){return this.#b(),new Promise((t,n)=>{let r=t=>t.status===`idle`&&t.matches.some(t=>t.name===e);if(this.#d.status===`error`){n(this.#d.error);return}if(r(this.#d)){t(this.#d);return}let i=this.subscribe(e=>{r(e)?(i(),t(e)):e.status===`error`&&(i(),n(e.error))});this.#p.signal.addEventListener(`abort`,()=>{i(),n(this.#p.signal.reason)},{once:!0})})}async preload(e,t,n){this.#b();let i=l(e,this.#a),a=r.buildPreloadKey(this.#e,i.path,t,n),o=this.#v.getInflight(a);if(o)return o;let s=this.#A(a,this.#p.signal,n).finally(()=>{this.#v.untrack(a)});this.#v.track(a,s);try{return await s}catch(e){throw this.#c&&this.#C(e,{source:`preload`}),e}}beforeLeave(e,t){this.#b();let n={handler:e,routes:t?.routes};return this.#l.add(n),()=>{this.#l.delete(n)}}get disposalSignal(){return this.#p.signal}get disposed(){return this.#f}dispose(){this.#f||(this.#f=!0,this.#l.clear(),this.#h.clear(),this.#u.invalidate(new e.WayfinderDisposedError),this.#y(),this.#p.abort(new e.WayfinderDisposedError))}[Symbol.dispose](){this.dispose()}#b(){if(this.#f)throw new e.WayfinderDisposedError}#x(){return this.#r.onPopstate(()=>{let{hash:e,pathname:t,search:n}=this.#r.location,r=`${t}${n}${e}`,i=this.#m;r!==i&&this.#w(this.#S(r,i),{source:`history-listener`})})}async#S(e,t){let n=this.#u.begin(),i=this.#d.matches.map(e=>e.name),a=this.#B(e),s=await o.runLeaveBlockers(this.#l,i,a);if(!n.isCurrent())return;if(!s){this.#r.replace(t,this.#d.location.historyState);return}let c=await this.#F(n,r.readLocation(this.#e,this.#r),(e,t)=>{if(!n.isCurrent())return;let r=this.#z(e);t&&this.#r.replace(r,e.historyState),this.#m=r},void 0,0,!1);n.isCurrent()&&!c&&this.#r.replace(t,this.#d.location.historyState)}#C(e,t){a.reportError(e,t,this.#c)}#w(e,t){e.catch(e=>{this.#C(e,p(e)??t)})}#T(){this.#h.forEach(e=>{e(this.#d)})}async#E(e,t){let n;for(;;){if(t.aborted)return await e.return(void 0).catch(()=>void 0),n;let{done:r,value:i}=await e.next();if(r)return i??n;n=i}}async#D(e,t,n){return Promise.all(e.map(async e=>{if(!e.dataFn)return;let r=e.dataFn,i=r({...t,signal:n});try{return m(i)?await this.#E(i,n):await i}catch(r){if(e.onError)return e.onError(r,{...t,signal:n});throw r}}))}async#O(e,t,n,r,i,o){let s=e.map(e=>{if(!e.dataFn)return;let r=e.dataFn;return r({...t,signal:n})}),c=[],l=await Promise.all(s.map(async(r,i)=>{if(m(r)){c.push(i);return}if(r!==void 0)try{return await r}catch(r){let a=e[i];if(a.onError)return a.onError(r,{...t,signal:n});throw r}}));if(c.length===0)return l;let u=[...l],d=(t,n)=>{if(!r())return;u[n]=t;let s=e.map((e,t)=>c.includes(t)?`streaming`:`idle`);this.#d=a.createRouteState({location:i,matches:a.buildMatchBranch(e,o,i.pathname,u,s),status:`streaming`}),this.#T()};return await Promise.all(c.map(async i=>{let a=s[i];try{u[i]=await this.#M(a,i,n,r,d)}catch(r){let a=e[i];if(a.onError)u[i]=await a.onError(r,{...t,signal:n});else throw r}})),u}async#k(t){let n=t;for(let e=0;e<5;e+=1){let e=new URL(n,`http://localhost`),t={hash:e.hash.replace(/^#/,``),historyState:null,pathname:r.stripBase(e.pathname,this.#e),query:r.parseQuery(e.search)},i=await this.#j(t);if(i.type!==`redirect`)return i;n=this.#L(i.redirectTo)}throw new e.WayfinderRedirectLoopError}async#A(e,t,n){let i=await this.#k(e);if(i.type!==`matched`)return;let{location:o,params:s,record:c,resolvedQuery:l}=i,u=this.#_.effectiveDefs(c);if(!u.some(e=>e.dataFn!=null))return;let d=a.buildMatchBranch(u,s,o.pathname,u.map(()=>void 0)),f=a.createRouteContext(o,l,s,d,()=>Promise.resolve()),p=await this.#D(u,f,t);this.#v.set(r.buildPreloadKey(this.#e,c.path,s,n??o.query),p)}async#j(e){let{params:t,record:n}=r.matchRouteFor(e.pathname,this.#i);if(!n)return{location:e,params:t,type:`unmatched`};if(n.redirect)return{location:e,params:t,redirectTo:u(n.redirect,this.#a,this.#e),type:`redirect`};let i=e.query,o=n.coerceSearch??this.#n;if(o)try{i=o(e.query)}catch(t){this.#C(t,{source:`coerce-search`}),i=e.query}await this.#_.hydrate(n);let s=this.#_.effectiveDefs(n);return{branch:a.buildMatchBranch(s,t,e.pathname,s.map(()=>void 0)),location:e,params:t,record:n,resolvedQuery:i,type:`matched`}}async#M(e,t,n,r,i){let a;try{for(;;){if(n.aborted||!r())return await e.return(void 0),a;let{done:o,value:s}=await e.next();if(o)return s??a;a=s,i(s,t)}}catch(t){throw await e.return(void 0).catch(()=>void 0),t}}async#N(e,t,n,i,o,s){if(!s())return;let c=this.#_.effectiveDefs(e),l=c.some(e=>e.dataFn!=null),u=c.map(()=>void 0);if(l){let l=r.buildPreloadKey(this.#e,e.path,i,n.query),d=this.#v.consume(l);if(d)u=d;else{let r=c.map(e=>e.dataFn?`loading`:`idle`);this.#d=a.createRouteState({location:n,matches:a.buildMatchBranch(c,i,n.pathname,u,r),status:`loading`}),this.#T();try{u=await this.#O(c,t,o,s,n,i)}catch(t){if(!s())return;throw this.#d=a.createRouteState({error:t,location:n,matches:a.buildMatchBranch(c,i,n.pathname,u),status:`error`}),f(t,{routeName:e.leaf.name,source:`data-loader`}),t}}}s()&&(this.#d=a.createRouteState({location:n,matches:a.buildMatchBranch(c,i,n.pathname,u),status:`idle`}))}async#P(e,t){if((t??this.#s)&&typeof document<`u`){let t=document;if(t.startViewTransition){await t.startViewTransition(e).finished;return}}await e()}async#F(t,n,r,i,o=0,s=!1){let c=this.#d,l=()=>t.isCurrent()&&!this.#f,u=await this.#j(n);if(!l())return!1;if(u.type===`redirect`){if(o>=5)throw new e.WayfinderRedirectLoopError;return this.#F(t,this.#R(u.redirectTo,n.historyState),r,i,o+1,!0)}if(u.type===`unmatched`){if(this.#g){let e=[this.#g.leaf],o=a.buildMatchBranch(e,{},n.pathname,[void 0]),u=!1,d=!1,f=n.query;if(this.#n)try{f=this.#n(n.query)}catch(e){this.#C(e,{source:`coerce-search`})}let p=async()=>{if(!l())return;let e=a.createRouteContext(n,f,{},o,(e,t)=>this.navigate(e,t));d=await a.executeMiddlewarePipeline(e,[...this.#t,...this.#g.ownMiddleware],async()=>{l()&&(u=!0,r(n,s),l()&&await this.#N(this.#g,e,n,{},t.signal,l))})};try{await this.#P(p,i)}finally{l()&&u&&(this.#T(),this.#I(this.#d,c))}return d&&u}return!l()||(r(u.location,s),!l())?!1:(this.#d=a.createRouteState({location:u.location,matches:[],status:`idle`}),this.#T(),this.#I(this.#d,c),!0)}let{branch:d,location:f,params:p,record:m,resolvedQuery:h}=u,g=!1,_=!1,v=async()=>{if(!l())return;let e=a.createRouteContext(f,h,p,d,(e,t)=>this.navigate(e,t));_=await a.executeMiddlewarePipeline(e,[...this.#t,...m.ownMiddleware],async()=>{l()&&(g=!0,r(f,s),l()&&await this.#N(m,e,f,p,t.signal,l))})};try{await this.#P(v,i)}finally{l()&&g&&(this.#T(),this.#I(this.#d,c))}return _&&g}#I(e,t){if(!this.#o||typeof window>`u`)return;let n=this.#o(e,t);if(n!==`preserve`){if(n===`top`){window.scrollTo(0,0);return}window.scrollTo(n.x,n.y)}}#L(e){let t=new URL(e,`http://localhost`),n=r.stripBase(t.pathname,this.#e);return`${r.joinPaths(this.#e,n)}${t.search}${t.hash}`}#R(e,t){let n=new URL(this.#L(e),`http://localhost`);return{hash:n.hash.replace(/^#/,``),historyState:t,pathname:r.stripBase(n.pathname,this.#e),query:r.parseQuery(n.search)}}#z(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e.query))Array.isArray(r)?r.forEach(e=>{t.append(n,e)}):t.set(n,r);let n=t.toString(),i=e.hash?`#${e.hash}`:``;return`${r.joinPaths(this.#e,e.pathname)}${n?`?${n}`:``}${i}`}#B(e){let t=new URL(e,`http://localhost`),n=r.stripBase(t.pathname,this.#e),{params:i,record:a}=r.matchRouteFor(n,this.#i);return{name:a?.leaf.name,params:i,pathname:n,query:r.parseQuery(t.search)}}async#V(e,t={}){this.#b();let n=this.#L(e);if(!t.force&&n===this.#m)return;let r=this.#u.begin(),i=this.#d.matches.map(e=>e.name),a=await o.runLeaveBlockers(this.#l,i,this.#B(n));!r.isCurrent()||!a||await this.#F(r,this.#R(n,t.state),(e,t)=>{if(!r.isCurrent())return;let n=this.#z(e);t?this.#r.replace(n,e.historyState):this.#r.push(n,e.historyState),this.#m=n},t.viewTransition,0,t.replace??!1)}};function g(e){return new h(e)}exports.createRouter=g;
|
|
2
2
|
//# sourceMappingURL=router.cjs.map
|
package/dist/router.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { WayfinderDisposedError as e, WayfinderRedirectLoopError as t, WayfinderRouteError as n } from "./errors.js";
|
|
2
|
+
import { createBrowserHistory as r } from "./history.js";
|
|
3
|
+
import { createNavigationCoordinator as i } from "./_navigation.js";
|
|
4
|
+
import { buildPreloadKey as a, buildUrl as o, joinPaths as s, matchRouteFor as c, matchesPrefix as l, normalizePath as u, parseQuery as d, readLocation as f, stripBase as p } from "./path.js";
|
|
5
|
+
import { compileRoutes as m } from "./compile.js";
|
|
6
|
+
import { buildMatchBranch as h, createRouteContext as g, createRouteState as _, executeMiddlewarePipeline as v, reportError as y } from "./context.js";
|
|
7
|
+
import { runLeaveBlockers as b } from "./guards.js";
|
|
8
8
|
import { createHydrationManager as x } from "./hydration.js";
|
|
9
9
|
import { createPreloadManager as S } from "./preload.js";
|
|
10
10
|
//#region src/router.ts
|
|
11
11
|
function C(e, t) {
|
|
12
|
-
let
|
|
13
|
-
if (
|
|
12
|
+
let r = t.get(e);
|
|
13
|
+
if (r) return r;
|
|
14
14
|
let i = [...t.keys()].join(", ");
|
|
15
|
-
throw new
|
|
15
|
+
throw new n(i ? `Unknown route name: ${e}. Available routes: ${i}` : `Unknown route name: ${e}`);
|
|
16
16
|
}
|
|
17
17
|
function w(e, t, n = "/") {
|
|
18
18
|
if ("path" in e) return e.path;
|
|
19
|
-
let r = C(e.name, t), i =
|
|
19
|
+
let r = C(e.name, t), i = o(n, r.path, e.params, e.query);
|
|
20
20
|
return e.hash ? `${i}#${e.hash}` : i;
|
|
21
21
|
}
|
|
22
22
|
var T = Symbol("wayfinder.errorContext");
|
|
@@ -40,7 +40,7 @@ var k = class {
|
|
|
40
40
|
#s;
|
|
41
41
|
#c;
|
|
42
42
|
#l = /* @__PURE__ */ new Set();
|
|
43
|
-
#u =
|
|
43
|
+
#u = i();
|
|
44
44
|
#d;
|
|
45
45
|
#f = !1;
|
|
46
46
|
#p = new AbortController();
|
|
@@ -52,8 +52,8 @@ var k = class {
|
|
|
52
52
|
#y;
|
|
53
53
|
ready;
|
|
54
54
|
constructor(e) {
|
|
55
|
-
let t =
|
|
56
|
-
if (this.#e =
|
|
55
|
+
let t = m(e);
|
|
56
|
+
if (this.#e = u(e.base ?? "/"), this.#t = e.middleware ?? [], this.#n = e.coerceSearch, this.#r = e.history ?? r(), this.#s = e.viewTransition ?? !1, this.#o = e.scroll, this.#c = e.onError, this.#i = t.records, this.#a = t.routesByName, this.#_ = x(), this.#v = S(), this.#d = _({
|
|
57
57
|
location: {
|
|
58
58
|
hash: "",
|
|
59
59
|
historyState: null,
|
|
@@ -82,11 +82,11 @@ var k = class {
|
|
|
82
82
|
};
|
|
83
83
|
} else this.#g = null;
|
|
84
84
|
this.#y = this.#x();
|
|
85
|
-
let { hash: n, pathname:
|
|
86
|
-
this.#m = `${
|
|
87
|
-
let
|
|
88
|
-
this.ready = this.#F(
|
|
89
|
-
if (!
|
|
85
|
+
let { hash: n, pathname: i, search: a } = this.#r.location;
|
|
86
|
+
this.#m = `${i}${a}${n}`;
|
|
87
|
+
let o = this.#u.begin();
|
|
88
|
+
this.ready = this.#F(o, f(this.#e, this.#r), (e, t) => {
|
|
89
|
+
if (!o.isCurrent()) return;
|
|
90
90
|
let n = this.#z(e);
|
|
91
91
|
t && this.#r.replace(n, e.historyState), this.#m = n;
|
|
92
92
|
}, void 0, 0, !1).then(() => void 0), this.#w(this.ready, { source: "initial-navigation" }), this.beforeLeave = this.beforeLeave.bind(this), this.dispose = this.dispose.bind(this), this.getSnapshot = this.getSnapshot.bind(this), this.isActive = this.isActive.bind(this), this.load = this.load.bind(this), this.match = this.match.bind(this), this.navigate = this.navigate.bind(this), this.preload = this.preload.bind(this), this.subscribe = this.subscribe.bind(this), this.url = this.url.bind(this), this.waitFor = this.waitFor.bind(this);
|
|
@@ -105,16 +105,16 @@ var k = class {
|
|
|
105
105
|
}
|
|
106
106
|
url(e, t, n) {
|
|
107
107
|
let r = C(e, this.#a);
|
|
108
|
-
return
|
|
108
|
+
return o(this.#e, r.path, t, n);
|
|
109
109
|
}
|
|
110
110
|
isActive(e, t = {}) {
|
|
111
111
|
let n = C(e, this.#a), r = this.#d.location.pathname;
|
|
112
|
-
return t.exact ?? !1 ?
|
|
112
|
+
return t.exact ?? !1 ? c(r, [n]).record != null : l(r, n);
|
|
113
113
|
}
|
|
114
114
|
match(e) {
|
|
115
|
-
let t =
|
|
115
|
+
let t = p(u(e), this.#e), { params: n, record: r } = c(t, this.#i);
|
|
116
116
|
if (!r || r.redirect) return null;
|
|
117
|
-
let i = this.#_.effectiveDefs(r), a =
|
|
117
|
+
let i = this.#_.effectiveDefs(r), a = h(i, n, t, i.map(() => void 0));
|
|
118
118
|
return a.length ? a : null;
|
|
119
119
|
}
|
|
120
120
|
async load(e, t) {
|
|
@@ -122,17 +122,17 @@ var k = class {
|
|
|
122
122
|
if (n.type !== "matched") return null;
|
|
123
123
|
let { location: r, params: i, record: a, resolvedQuery: o } = n, s = this.#_.effectiveDefs(a), c = s.some((e) => e.dataFn != null), l = s.map(() => void 0), u, d = "idle";
|
|
124
124
|
if (c) {
|
|
125
|
-
let e = t?.signal ?? new AbortController().signal, n =
|
|
125
|
+
let e = t?.signal ?? new AbortController().signal, n = h(s, i, r.pathname, l), a = g(r, o, i, n, () => Promise.resolve());
|
|
126
126
|
try {
|
|
127
127
|
l = await this.#D(s, a, e);
|
|
128
128
|
} catch (e) {
|
|
129
129
|
u = e, d = "error";
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
return
|
|
132
|
+
return _({
|
|
133
133
|
error: u,
|
|
134
134
|
location: r,
|
|
135
|
-
matches:
|
|
135
|
+
matches: h(s, i, r.pathname, l),
|
|
136
136
|
status: d
|
|
137
137
|
});
|
|
138
138
|
}
|
|
@@ -157,12 +157,12 @@ var k = class {
|
|
|
157
157
|
}
|
|
158
158
|
async preload(e, t, n) {
|
|
159
159
|
this.#b();
|
|
160
|
-
let r = C(e, this.#a),
|
|
160
|
+
let r = C(e, this.#a), i = a(this.#e, r.path, t, n), o = this.#v.getInflight(i);
|
|
161
161
|
if (o) return o;
|
|
162
|
-
let s = this.#A(
|
|
163
|
-
this.#v.untrack(
|
|
162
|
+
let s = this.#A(i, this.#p.signal, n).finally(() => {
|
|
163
|
+
this.#v.untrack(i);
|
|
164
164
|
});
|
|
165
|
-
this.#v.track(
|
|
165
|
+
this.#v.track(i, s);
|
|
166
166
|
try {
|
|
167
167
|
return await s;
|
|
168
168
|
} catch (e) {
|
|
@@ -186,13 +186,13 @@ var k = class {
|
|
|
186
186
|
return this.#f;
|
|
187
187
|
}
|
|
188
188
|
dispose() {
|
|
189
|
-
this.#f || (this.#f = !0, this.#l.clear(), this.#h.clear(), this.#u.invalidate(new
|
|
189
|
+
this.#f || (this.#f = !0, this.#l.clear(), this.#h.clear(), this.#u.invalidate(new e()), this.#y(), this.#p.abort(new e()));
|
|
190
190
|
}
|
|
191
191
|
[Symbol.dispose]() {
|
|
192
192
|
this.dispose();
|
|
193
193
|
}
|
|
194
194
|
#b() {
|
|
195
|
-
if (this.#f) throw new
|
|
195
|
+
if (this.#f) throw new e();
|
|
196
196
|
}
|
|
197
197
|
#x() {
|
|
198
198
|
return this.#r.onPopstate(() => {
|
|
@@ -201,13 +201,13 @@ var k = class {
|
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
async #S(e, t) {
|
|
204
|
-
let n = this.#u.begin(), r = this.#d.matches.map((e) => e.name), i = this.#B(e), a = await
|
|
204
|
+
let n = this.#u.begin(), r = this.#d.matches.map((e) => e.name), i = this.#B(e), a = await b(this.#l, r, i);
|
|
205
205
|
if (!n.isCurrent()) return;
|
|
206
206
|
if (!a) {
|
|
207
207
|
this.#r.replace(t, this.#d.location.historyState);
|
|
208
208
|
return;
|
|
209
209
|
}
|
|
210
|
-
let o = await this.#F(n,
|
|
210
|
+
let o = await this.#F(n, f(this.#e, this.#r), (e, t) => {
|
|
211
211
|
if (!n.isCurrent()) return;
|
|
212
212
|
let r = this.#z(e);
|
|
213
213
|
t && this.#r.replace(r, e.historyState), this.#m = r;
|
|
@@ -215,7 +215,7 @@ var k = class {
|
|
|
215
215
|
n.isCurrent() && !o && this.#r.replace(t, this.#d.location.historyState);
|
|
216
216
|
}
|
|
217
217
|
#C(e, t) {
|
|
218
|
-
|
|
218
|
+
y(e, t, this.#c);
|
|
219
219
|
}
|
|
220
220
|
#w(e, t) {
|
|
221
221
|
e.catch((e) => {
|
|
@@ -283,9 +283,9 @@ var k = class {
|
|
|
283
283
|
if (!r()) return;
|
|
284
284
|
l[n] = t;
|
|
285
285
|
let o = e.map((e, t) => s.includes(t) ? "streaming" : "idle");
|
|
286
|
-
this.#d =
|
|
286
|
+
this.#d = _({
|
|
287
287
|
location: i,
|
|
288
|
-
matches:
|
|
288
|
+
matches: h(e, a, i.pathname, l, o),
|
|
289
289
|
status: "streaming"
|
|
290
290
|
}), this.#T();
|
|
291
291
|
};
|
|
@@ -304,29 +304,29 @@ var k = class {
|
|
|
304
304
|
})), l;
|
|
305
305
|
}
|
|
306
306
|
async #k(e) {
|
|
307
|
-
let
|
|
307
|
+
let n = e;
|
|
308
308
|
for (let e = 0; e < 5; e += 1) {
|
|
309
|
-
let e = new URL(
|
|
309
|
+
let e = new URL(n, "http://localhost"), t = {
|
|
310
310
|
hash: e.hash.replace(/^#/, ""),
|
|
311
311
|
historyState: null,
|
|
312
|
-
pathname:
|
|
313
|
-
query:
|
|
314
|
-
}, r = await this.#j(
|
|
312
|
+
pathname: p(e.pathname, this.#e),
|
|
313
|
+
query: d(e.search)
|
|
314
|
+
}, r = await this.#j(t);
|
|
315
315
|
if (r.type !== "redirect") return r;
|
|
316
|
-
|
|
316
|
+
n = this.#L(r.redirectTo);
|
|
317
317
|
}
|
|
318
|
-
throw new
|
|
318
|
+
throw new t();
|
|
319
319
|
}
|
|
320
320
|
async #A(e, t, n) {
|
|
321
321
|
let r = await this.#k(e);
|
|
322
322
|
if (r.type !== "matched") return;
|
|
323
|
-
let { location:
|
|
323
|
+
let { location: i, params: o, record: s, resolvedQuery: c } = r, l = this.#_.effectiveDefs(s);
|
|
324
324
|
if (!l.some((e) => e.dataFn != null)) return;
|
|
325
|
-
let u =
|
|
326
|
-
this.#v.set(
|
|
325
|
+
let u = h(l, o, i.pathname, l.map(() => void 0)), d = g(i, c, o, u, () => Promise.resolve()), f = await this.#D(l, d, t);
|
|
326
|
+
this.#v.set(a(this.#e, s.path, o, n ?? i.query), f);
|
|
327
327
|
}
|
|
328
328
|
async #j(e) {
|
|
329
|
-
let { params: t, record: n } =
|
|
329
|
+
let { params: t, record: n } = c(e.pathname, this.#i);
|
|
330
330
|
if (!n) return {
|
|
331
331
|
location: e,
|
|
332
332
|
params: t,
|
|
@@ -347,7 +347,7 @@ var k = class {
|
|
|
347
347
|
await this.#_.hydrate(n);
|
|
348
348
|
let a = this.#_.effectiveDefs(n);
|
|
349
349
|
return {
|
|
350
|
-
branch:
|
|
350
|
+
branch: h(a, t, e.pathname, a.map(() => void 0)),
|
|
351
351
|
location: e,
|
|
352
352
|
params: t,
|
|
353
353
|
record: n,
|
|
@@ -368,27 +368,27 @@ var k = class {
|
|
|
368
368
|
throw await e.return(void 0).catch(() => void 0), t;
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
|
-
async #N(e, t, n, r,
|
|
371
|
+
async #N(e, t, n, r, i, o) {
|
|
372
372
|
if (!o()) return;
|
|
373
373
|
let s = this.#_.effectiveDefs(e), c = s.some((e) => e.dataFn != null), l = s.map(() => void 0);
|
|
374
374
|
if (c) {
|
|
375
|
-
let c =
|
|
375
|
+
let c = a(this.#e, e.path, r, n.query), u = this.#v.consume(c);
|
|
376
376
|
if (u) l = u;
|
|
377
377
|
else {
|
|
378
|
-
let
|
|
379
|
-
this.#d =
|
|
378
|
+
let a = s.map((e) => e.dataFn ? "loading" : "idle");
|
|
379
|
+
this.#d = _({
|
|
380
380
|
location: n,
|
|
381
|
-
matches:
|
|
381
|
+
matches: h(s, r, n.pathname, l, a),
|
|
382
382
|
status: "loading"
|
|
383
383
|
}), this.#T();
|
|
384
384
|
try {
|
|
385
|
-
l = await this.#O(s, t,
|
|
385
|
+
l = await this.#O(s, t, i, o, n, r);
|
|
386
386
|
} catch (t) {
|
|
387
387
|
if (!o()) return;
|
|
388
|
-
throw this.#d =
|
|
388
|
+
throw this.#d = _({
|
|
389
389
|
error: t,
|
|
390
390
|
location: n,
|
|
391
|
-
matches:
|
|
391
|
+
matches: h(s, r, n.pathname, l),
|
|
392
392
|
status: "error"
|
|
393
393
|
}), E(t, {
|
|
394
394
|
routeName: e.leaf.name,
|
|
@@ -397,9 +397,9 @@ var k = class {
|
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
|
-
o() && (this.#d =
|
|
400
|
+
o() && (this.#d = _({
|
|
401
401
|
location: n,
|
|
402
|
-
matches:
|
|
402
|
+
matches: h(s, r, n.pathname, l),
|
|
403
403
|
status: "idle"
|
|
404
404
|
}));
|
|
405
405
|
}
|
|
@@ -413,26 +413,26 @@ var k = class {
|
|
|
413
413
|
}
|
|
414
414
|
await e();
|
|
415
415
|
}
|
|
416
|
-
async #F(e,
|
|
417
|
-
let s = this.#d, c = () => e.isCurrent() && !this.#f, l = await this.#j(
|
|
416
|
+
async #F(e, n, r, i, a = 0, o = !1) {
|
|
417
|
+
let s = this.#d, c = () => e.isCurrent() && !this.#f, l = await this.#j(n);
|
|
418
418
|
if (!c()) return !1;
|
|
419
419
|
if (l.type === "redirect") {
|
|
420
|
-
if (a >= 5) throw new
|
|
421
|
-
return this.#F(e, this.#R(l.redirectTo,
|
|
420
|
+
if (a >= 5) throw new t();
|
|
421
|
+
return this.#F(e, this.#R(l.redirectTo, n.historyState), r, i, a + 1, !0);
|
|
422
422
|
}
|
|
423
423
|
if (l.type === "unmatched") {
|
|
424
424
|
if (this.#g) {
|
|
425
|
-
let
|
|
425
|
+
let t = [this.#g.leaf], a = h(t, {}, n.pathname, [void 0]), l = !1, u = !1, d = n.query;
|
|
426
426
|
if (this.#n) try {
|
|
427
|
-
d = this.#n(
|
|
427
|
+
d = this.#n(n.query);
|
|
428
428
|
} catch (e) {
|
|
429
429
|
this.#C(e, { source: "coerce-search" });
|
|
430
430
|
}
|
|
431
431
|
let f = async () => {
|
|
432
432
|
if (!c()) return;
|
|
433
|
-
let
|
|
434
|
-
u = await
|
|
435
|
-
c() && (l = !0, r(
|
|
433
|
+
let t = g(n, d, {}, a, (e, t) => this.navigate(e, t));
|
|
434
|
+
u = await v(t, [...this.#t, ...this.#g.ownMiddleware], async () => {
|
|
435
|
+
c() && (l = !0, r(n, o), c() && await this.#N(this.#g, t, n, {}, e.signal, c));
|
|
436
436
|
});
|
|
437
437
|
};
|
|
438
438
|
try {
|
|
@@ -442,16 +442,16 @@ var k = class {
|
|
|
442
442
|
}
|
|
443
443
|
return u && l;
|
|
444
444
|
}
|
|
445
|
-
return !c() || (r(l.location, o), !c()) ? !1 : (this.#d =
|
|
445
|
+
return !c() || (r(l.location, o), !c()) ? !1 : (this.#d = _({
|
|
446
446
|
location: l.location,
|
|
447
447
|
matches: [],
|
|
448
448
|
status: "idle"
|
|
449
449
|
}), this.#T(), this.#I(this.#d, s), !0);
|
|
450
450
|
}
|
|
451
|
-
let { branch: u, location: d, params: f, record: p, resolvedQuery:
|
|
451
|
+
let { branch: u, location: d, params: f, record: p, resolvedQuery: m } = l, y = !1, b = !1, x = async () => {
|
|
452
452
|
if (!c()) return;
|
|
453
|
-
let t =
|
|
454
|
-
b = await
|
|
453
|
+
let t = g(d, m, f, u, (e, t) => this.navigate(e, t));
|
|
454
|
+
b = await v(t, [...this.#t, ...p.ownMiddleware], async () => {
|
|
455
455
|
c() && (y = !0, r(d, o), c() && await this.#N(p, t, d, f, e.signal, c));
|
|
456
456
|
});
|
|
457
457
|
};
|
|
@@ -474,16 +474,16 @@ var k = class {
|
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
476
|
#L(e) {
|
|
477
|
-
let t = new URL(e, "http://localhost"), n =
|
|
478
|
-
return `${
|
|
477
|
+
let t = new URL(e, "http://localhost"), n = p(t.pathname, this.#e);
|
|
478
|
+
return `${s(this.#e, n)}${t.search}${t.hash}`;
|
|
479
479
|
}
|
|
480
480
|
#R(e, t) {
|
|
481
481
|
let n = new URL(this.#L(e), "http://localhost");
|
|
482
482
|
return {
|
|
483
483
|
hash: n.hash.replace(/^#/, ""),
|
|
484
484
|
historyState: t,
|
|
485
|
-
pathname:
|
|
486
|
-
query:
|
|
485
|
+
pathname: p(n.pathname, this.#e),
|
|
486
|
+
query: d(n.search)
|
|
487
487
|
};
|
|
488
488
|
}
|
|
489
489
|
#z(e) {
|
|
@@ -492,22 +492,22 @@ var k = class {
|
|
|
492
492
|
t.append(n, e);
|
|
493
493
|
}) : t.set(n, r);
|
|
494
494
|
let n = t.toString(), r = e.hash ? `#${e.hash}` : "";
|
|
495
|
-
return `${
|
|
495
|
+
return `${s(this.#e, e.pathname)}${n ? `?${n}` : ""}${r}`;
|
|
496
496
|
}
|
|
497
497
|
#B(e) {
|
|
498
|
-
let t = new URL(e, "http://localhost"), n =
|
|
498
|
+
let t = new URL(e, "http://localhost"), n = p(t.pathname, this.#e), { params: r, record: i } = c(n, this.#i);
|
|
499
499
|
return {
|
|
500
500
|
name: i?.leaf.name,
|
|
501
501
|
params: r,
|
|
502
502
|
pathname: n,
|
|
503
|
-
query:
|
|
503
|
+
query: d(t.search)
|
|
504
504
|
};
|
|
505
505
|
}
|
|
506
506
|
async #V(e, t = {}) {
|
|
507
507
|
this.#b();
|
|
508
508
|
let n = this.#L(e);
|
|
509
509
|
if (!t.force && n === this.#m) return;
|
|
510
|
-
let r = this.#u.begin(), i = this.#d.matches.map((e) => e.name), a = await
|
|
510
|
+
let r = this.#u.begin(), i = this.#d.matches.map((e) => e.name), a = await b(this.#l, i, this.#B(n));
|
|
511
511
|
!r.isCurrent() || !a || await this.#F(r, this.#R(n, t.state), (e, t) => {
|
|
512
512
|
if (!r.isCurrent()) return;
|
|
513
513
|
let n = this.#z(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielzeug/wayfinder",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Typed client-side router — guards, middleware, history management, and nested routes",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,20 +22,9 @@
|
|
|
22
22
|
"import": "./dist/index.js",
|
|
23
23
|
"require": "./dist/index.cjs",
|
|
24
24
|
"types": "./dist/index.d.ts"
|
|
25
|
-
},
|
|
26
|
-
"./devtools": {
|
|
27
|
-
"import": "./dist/devtools.js",
|
|
28
|
-
"require": "./dist/devtools.cjs",
|
|
29
|
-
"types": "./dist/devtools.d.ts"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"typesVersions": {
|
|
33
|
-
"*": {
|
|
34
|
-
"devtools": [
|
|
35
|
-
"dist/devtools.d.ts"
|
|
36
|
-
]
|
|
37
25
|
}
|
|
38
26
|
},
|
|
27
|
+
"sideEffects": false,
|
|
39
28
|
"publishConfig": {
|
|
40
29
|
"access": "public",
|
|
41
30
|
"registry": "https://registry.npmjs.org/"
|
package/dist/devtools.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./router.cjs");function t(t){let{label:n=`nav`,...r}=t,i=e.createRouter(r),a=`[wayfinder:${n}]`;return i.subscribe(e=>{let t=e.matches.map(e=>e.name).filter(Boolean).join(`, `),n=t?` [${t}]`:``;e.status===`error`?console.debug(`${a} error ${e.location.pathname}${n}`,e.error):console.debug(`${a} ${e.status.padEnd(8)} ${e.location.pathname}${n}`)}),i}exports.debugRouter=t;
|
|
2
|
-
//# sourceMappingURL=devtools.cjs.map
|
package/dist/devtools.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.cjs","names":[],"sources":["../src/devtools.ts"],"sourcesContent":["/**\n * @vielzeug/wayfinder — debug utilities for router navigation visualisation.\n *\n * Import from the dedicated sub-path so it is tree-shaken from production bundles:\n * ```ts\n * import { debugRouter } from '@vielzeug/wayfinder/devtools';\n * ```\n */\n\nimport type { Router, RouterOptions, RouteState, RouteTable } from './index';\n\nimport { createRouter } from './router';\n\n/** Options for {@link debugRouter}. Extends {@link RouterOptions} with debug-specific settings. */\nexport interface DebugRouterOptions<TRoutes extends RouteTable, TMeta = unknown, TComponent = unknown>\n extends RouterOptions<TRoutes, TMeta, TComponent> {\n /**\n * Label used in log prefixes. Defaults to `'nav'`, producing `[wayfinder:nav]`.\n * Useful when running multiple routers (e.g. a main router and a modal router)\n * so their log output can be distinguished:\n * ```ts\n * debugRouter({ label: 'modal', routes });\n * // [wayfinder:modal] loading /confirm\n * ```\n */\n label?: string;\n}\n\n/**\n * Creates a {@link Router} with navigation lifecycle logging pre-wired to `console.debug`.\n *\n * Equivalent to `createRouter(options)` with a `subscribe` listener attached, but imported\n * from a dedicated sub-path so `console.debug` references are tree-shaken from production\n * bundles when this sub-path is not imported.\n *\n * Logs every navigation state change with `[wayfinder:<label>]` prefixes showing the pathname,\n * status (`loading` → `idle` / `error`), and matched route names.\n *\n * @example\n * ```ts\n * import { debugRouter } from '@vielzeug/wayfinder/devtools';\n *\n * const router = debugRouter({ routes });\n * // [wayfinder:nav] loading /users\n * // [wayfinder:nav] idle /users [users]\n *\n * // Multi-router setup:\n * const modal = debugRouter({ label: 'modal', routes: modalRoutes });\n * // [wayfinder:modal] loading /confirm\n * ```\n */\nexport function debugRouter<const TRoutes extends RouteTable, TMeta = unknown, TComponent = unknown>(\n options: DebugRouterOptions<TRoutes, TMeta, TComponent>,\n): Router<TRoutes, TMeta, TComponent> {\n const { label = 'nav', ...routerOptions } = options;\n const router = createRouter<TRoutes, TMeta, TComponent>(routerOptions);\n const prefix = `[wayfinder:${label}]`;\n\n const log = (state: RouteState<TMeta, TComponent>): void => {\n const names = state.matches\n .map((m) => m.name)\n .filter(Boolean)\n .join(', ');\n const suffix = names ? ` [${names}]` : '';\n\n if (state.status === 'error') {\n console.debug(`${prefix} error ${state.location.pathname}${suffix}`, state.error);\n } else {\n console.debug(`${prefix} ${state.status.padEnd(8)} ${state.location.pathname}${suffix}`);\n }\n };\n\n router.subscribe(log);\n\n return router;\n}\n"],"mappings":"mGAmDA,SAAgB,EACd,EACoC,CACpC,GAAM,CAAE,QAAQ,MAAO,GAAG,GAAkB,EACtC,EAAS,EAAA,aAAyC,CAAa,EAC/D,EAAS,cAAc,EAAM,GAkBnC,OAFA,EAAO,UAdM,GAA+C,CAC1D,IAAM,EAAQ,EAAM,QACjB,IAAK,GAAM,EAAE,IAAI,CAAC,CAClB,OAAO,OAAO,CAAC,CACf,KAAK,IAAI,EACN,EAAS,EAAQ,MAAM,EAAM,GAAK,GAEpC,EAAM,SAAW,QACnB,QAAQ,MAAM,GAAG,EAAO,YAAY,EAAM,SAAS,WAAW,IAAU,EAAM,KAAK,EAEnF,QAAQ,MAAM,GAAG,EAAO,GAAG,EAAM,OAAO,OAAO,CAAC,EAAE,GAAG,EAAM,SAAS,WAAW,GAAQ,CAE3F,CAEoB,EAEb,CACT"}
|
package/dist/devtools.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @vielzeug/wayfinder — debug utilities for router navigation visualisation.
|
|
3
|
-
*
|
|
4
|
-
* Import from the dedicated sub-path so it is tree-shaken from production bundles:
|
|
5
|
-
* ```ts
|
|
6
|
-
* import { debugRouter } from '@vielzeug/wayfinder/devtools';
|
|
7
|
-
* ```
|
|
8
|
-
*/
|
|
9
|
-
import type { Router, RouterOptions, RouteTable } from './index';
|
|
10
|
-
/** Options for {@link debugRouter}. Extends {@link RouterOptions} with debug-specific settings. */
|
|
11
|
-
export interface DebugRouterOptions<TRoutes extends RouteTable, TMeta = unknown, TComponent = unknown> extends RouterOptions<TRoutes, TMeta, TComponent> {
|
|
12
|
-
/**
|
|
13
|
-
* Label used in log prefixes. Defaults to `'nav'`, producing `[wayfinder:nav]`.
|
|
14
|
-
* Useful when running multiple routers (e.g. a main router and a modal router)
|
|
15
|
-
* so their log output can be distinguished:
|
|
16
|
-
* ```ts
|
|
17
|
-
* debugRouter({ label: 'modal', routes });
|
|
18
|
-
* // [wayfinder:modal] loading /confirm
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
label?: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Creates a {@link Router} with navigation lifecycle logging pre-wired to `console.debug`.
|
|
25
|
-
*
|
|
26
|
-
* Equivalent to `createRouter(options)` with a `subscribe` listener attached, but imported
|
|
27
|
-
* from a dedicated sub-path so `console.debug` references are tree-shaken from production
|
|
28
|
-
* bundles when this sub-path is not imported.
|
|
29
|
-
*
|
|
30
|
-
* Logs every navigation state change with `[wayfinder:<label>]` prefixes showing the pathname,
|
|
31
|
-
* status (`loading` → `idle` / `error`), and matched route names.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* import { debugRouter } from '@vielzeug/wayfinder/devtools';
|
|
36
|
-
*
|
|
37
|
-
* const router = debugRouter({ routes });
|
|
38
|
-
* // [wayfinder:nav] loading /users
|
|
39
|
-
* // [wayfinder:nav] idle /users [users]
|
|
40
|
-
*
|
|
41
|
-
* // Multi-router setup:
|
|
42
|
-
* const modal = debugRouter({ label: 'modal', routes: modalRoutes });
|
|
43
|
-
* // [wayfinder:modal] loading /confirm
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export declare function debugRouter<const TRoutes extends RouteTable, TMeta = unknown, TComponent = unknown>(options: DebugRouterOptions<TRoutes, TMeta, TComponent>): Router<TRoutes, TMeta, TComponent>;
|
|
47
|
-
//# sourceMappingURL=devtools.d.ts.map
|
package/dist/devtools.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../src/devtools.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAc,UAAU,EAAE,MAAM,SAAS,CAAC;AAI7E,mGAAmG;AACnG,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,UAAU,EAAE,KAAK,GAAG,OAAO,EAAE,UAAU,GAAG,OAAO,CACnG,SAAQ,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC;IACjD;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CAAC,KAAK,CAAC,OAAO,SAAS,UAAU,EAAE,KAAK,GAAG,OAAO,EAAE,UAAU,GAAG,OAAO,EACjG,OAAO,EAAE,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,GACtD,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,CAsBpC"}
|
package/dist/devtools.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createRouter as e } from "./router.js";
|
|
2
|
-
//#region src/devtools.ts
|
|
3
|
-
function t(t) {
|
|
4
|
-
let { label: n = "nav", ...r } = t, i = e(r), a = `[wayfinder:${n}]`;
|
|
5
|
-
return i.subscribe((e) => {
|
|
6
|
-
let t = e.matches.map((e) => e.name).filter(Boolean).join(", "), n = t ? ` [${t}]` : "";
|
|
7
|
-
e.status === "error" ? console.debug(`${a} error ${e.location.pathname}${n}`, e.error) : console.debug(`${a} ${e.status.padEnd(8)} ${e.location.pathname}${n}`);
|
|
8
|
-
}), i;
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
export { t as debugRouter };
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=devtools.js.map
|
package/dist/devtools.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.js","names":[],"sources":["../src/devtools.ts"],"sourcesContent":["/**\n * @vielzeug/wayfinder — debug utilities for router navigation visualisation.\n *\n * Import from the dedicated sub-path so it is tree-shaken from production bundles:\n * ```ts\n * import { debugRouter } from '@vielzeug/wayfinder/devtools';\n * ```\n */\n\nimport type { Router, RouterOptions, RouteState, RouteTable } from './index';\n\nimport { createRouter } from './router';\n\n/** Options for {@link debugRouter}. Extends {@link RouterOptions} with debug-specific settings. */\nexport interface DebugRouterOptions<TRoutes extends RouteTable, TMeta = unknown, TComponent = unknown>\n extends RouterOptions<TRoutes, TMeta, TComponent> {\n /**\n * Label used in log prefixes. Defaults to `'nav'`, producing `[wayfinder:nav]`.\n * Useful when running multiple routers (e.g. a main router and a modal router)\n * so their log output can be distinguished:\n * ```ts\n * debugRouter({ label: 'modal', routes });\n * // [wayfinder:modal] loading /confirm\n * ```\n */\n label?: string;\n}\n\n/**\n * Creates a {@link Router} with navigation lifecycle logging pre-wired to `console.debug`.\n *\n * Equivalent to `createRouter(options)` with a `subscribe` listener attached, but imported\n * from a dedicated sub-path so `console.debug` references are tree-shaken from production\n * bundles when this sub-path is not imported.\n *\n * Logs every navigation state change with `[wayfinder:<label>]` prefixes showing the pathname,\n * status (`loading` → `idle` / `error`), and matched route names.\n *\n * @example\n * ```ts\n * import { debugRouter } from '@vielzeug/wayfinder/devtools';\n *\n * const router = debugRouter({ routes });\n * // [wayfinder:nav] loading /users\n * // [wayfinder:nav] idle /users [users]\n *\n * // Multi-router setup:\n * const modal = debugRouter({ label: 'modal', routes: modalRoutes });\n * // [wayfinder:modal] loading /confirm\n * ```\n */\nexport function debugRouter<const TRoutes extends RouteTable, TMeta = unknown, TComponent = unknown>(\n options: DebugRouterOptions<TRoutes, TMeta, TComponent>,\n): Router<TRoutes, TMeta, TComponent> {\n const { label = 'nav', ...routerOptions } = options;\n const router = createRouter<TRoutes, TMeta, TComponent>(routerOptions);\n const prefix = `[wayfinder:${label}]`;\n\n const log = (state: RouteState<TMeta, TComponent>): void => {\n const names = state.matches\n .map((m) => m.name)\n .filter(Boolean)\n .join(', ');\n const suffix = names ? ` [${names}]` : '';\n\n if (state.status === 'error') {\n console.debug(`${prefix} error ${state.location.pathname}${suffix}`, state.error);\n } else {\n console.debug(`${prefix} ${state.status.padEnd(8)} ${state.location.pathname}${suffix}`);\n }\n };\n\n router.subscribe(log);\n\n return router;\n}\n"],"mappings":";;AAmDA,SAAgB,EACd,GACoC;CACpC,IAAM,EAAE,WAAQ,OAAO,GAAG,MAAkB,GACtC,IAAS,EAAyC,CAAa,GAC/D,IAAS,cAAc,EAAM;CAkBnC,OAFA,EAAO,WAdM,MAA+C;EAC1D,IAAM,IAAQ,EAAM,QACjB,KAAK,MAAM,EAAE,IAAI,CAAC,CAClB,OAAO,OAAO,CAAC,CACf,KAAK,IAAI,GACN,IAAS,IAAQ,MAAM,EAAM,KAAK;EAExC,AAAI,EAAM,WAAW,UACnB,QAAQ,MAAM,GAAG,EAAO,YAAY,EAAM,SAAS,WAAW,KAAU,EAAM,KAAK,IAEnF,QAAQ,MAAM,GAAG,EAAO,GAAG,EAAM,OAAO,OAAO,CAAC,EAAE,GAAG,EAAM,SAAS,WAAW,GAAQ;CAE3F,CAEoB,GAEb;AACT"}
|