@firsthandjs/router 0.7.0 → 0.7.1
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/history.d.ts +6 -6
- package/dist/history.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/links.d.ts +2 -2
- package/dist/links.d.ts.map +1 -1
- package/dist/match.d.ts +2 -2
- package/dist/match.d.ts.map +1 -1
- package/dist/router.d.ts +4 -4
- package/dist/router.d.ts.map +1 -1
- package/dist/routes.d.ts +10 -10
- package/dist/routes.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/history.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* reactive read rather than a subscription the application has to manage.
|
|
9
9
|
*/
|
|
10
10
|
import { type ReadonlyCell } from '@firsthandjs/core';
|
|
11
|
-
export
|
|
11
|
+
export type Location = {
|
|
12
12
|
readonly pathname: string;
|
|
13
13
|
/** Including the leading `?`, or empty. */
|
|
14
14
|
readonly search: string;
|
|
@@ -18,12 +18,12 @@ export interface Location {
|
|
|
18
18
|
readonly state: unknown;
|
|
19
19
|
/** Changes on every navigation, including to the same URL. */
|
|
20
20
|
readonly key: string;
|
|
21
|
-
}
|
|
22
|
-
export
|
|
21
|
+
};
|
|
22
|
+
export type NavigateOptions = {
|
|
23
23
|
readonly replace?: boolean;
|
|
24
24
|
readonly state?: unknown;
|
|
25
|
-
}
|
|
26
|
-
export
|
|
25
|
+
};
|
|
26
|
+
export type History = {
|
|
27
27
|
readonly location: ReadonlyCell<Location>;
|
|
28
28
|
push(to: string, options?: NavigateOptions): void;
|
|
29
29
|
replace(to: string, options?: NavigateOptions): void;
|
|
@@ -32,7 +32,7 @@ export interface History {
|
|
|
32
32
|
href(to: string): string;
|
|
33
33
|
/** Stops listening. Returns nothing; calling it twice is harmless. */
|
|
34
34
|
dispose(): void;
|
|
35
|
-
}
|
|
35
|
+
};
|
|
36
36
|
/** Splits a URL-ish string into its three parts. */
|
|
37
37
|
export declare function parsePath(to: string): Omit<Location, 'state' | 'key'>;
|
|
38
38
|
/**
|
package/dist/history.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAU,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAU,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2CAA2C;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,8DAA8D;IAC9D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAClD,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IACrD,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,4DAA4D;IAC5D,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,sEAAsE;IACtE,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC;AAKF,oDAAoD;AACpD,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,GAAG,KAAK,CAAC,CAQrE;AAMD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,SAAK,GAAG,OAAO,CA2C3D;AAED,8EAA8E;AAC9E,wBAAgB,iBAAiB,IAAI,OAAO,CAqC3C;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,SAAS,MAAM,EAAU,GAAG,OAAO,CA+B/E"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{computed as M,createContext as T,onCleanup as me,provide as $,useContext as U}from"@firsthandjs/core";import{component as H}from"@firsthandjs/dom";import{isComponent as fe}from"@firsthandjs/dom/internal";import{part as
|
|
1
|
+
import{computed as M,createContext as T,onCleanup as me,provide as $,useContext as U}from"@firsthandjs/core";import{component as H}from"@firsthandjs/dom";import{isComponent as fe}from"@firsthandjs/dom/internal";import{part as ye}from"@firsthandjs/dom/internal";import{signal as O}from"@firsthandjs/core";var Z=0,m=()=>`k${String(++Z)}`;function f(e){let t=e.indexOf("#"),n=t===-1?"":e.slice(t),r=t===-1?e:e.slice(0,t),o=r.indexOf("?"),a=o===-1?"":r.slice(o),i=o===-1?r:r.slice(0,o);return{pathname:i===""?"/":i,search:a,hash:n}}function C(e,t){return{...f(e),state:t,key:m()}}function S(e=""){let t=e.endsWith("/")?e.slice(0,-1):e,n=u=>t!==""&&u.startsWith(t)?u.slice(t.length)||"/":u,r=()=>({pathname:n(window.location.pathname),search:window.location.search,hash:window.location.hash,state:window.history.state,key:m()}),o=O(r()),a=()=>{o.value=r()};window.addEventListener("popstate",a);let i=u=>`${t}${u.startsWith("/")?u:`/${u}`}`,s=(u,l,w)=>{let B=l?.state??null;window.history[w?"replaceState":"pushState"](B,"",i(u)),o.value=C(u,B)};return{location:o,push:(u,l)=>{s(u,l,l?.replace===!0)},replace:(u,l)=>{s(u,l,!0)},go:u=>{window.history.go(u)},href:i,dispose:()=>{window.removeEventListener("popstate",a)}}}function ee(){let e=()=>({...f(window.location.hash.slice(1)||"/"),state:null,key:m()}),t=O(e()),n=()=>{t.value=e()};window.addEventListener("hashchange",n);let r=o=>`#${o.startsWith("/")?o:`/${o}`}`;return{location:t,push:(o,a)=>{a?.replace===!0?window.location.replace(r(o)):window.location.hash=r(o).slice(1),t.value={...f(o),state:a?.state??null,key:m()}},replace:(o,a)=>{window.location.replace(r(o)),t.value={...f(o),state:a?.state??null,key:m()}},go:o=>{window.history.go(o)},href:r,dispose:()=>{window.removeEventListener("hashchange",n)}}}function te(e=["/"]){let t=e.map(o=>C(o,null)),n=t.length-1,r=O(t[n]);return{location:r,push:(o,a)=>{let i=C(o,a?.state??null);a?.replace===!0?t[n]=i:(t.length=n+1,t.push(i),n++),r.value=i},replace:(o,a)=>{let i=C(o,a?.state??null);t[n]=i,r.value=i},go:o=>{let a=Math.min(Math.max(n+o,0),t.length-1);n=a,r.value=t[a]},href:o=>o,dispose:()=>{}}}import{signal as ue}from"@firsthandjs/core";function y(e,t){let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(r=>e[r]===t[r])}var ne=10,oe=6,re=4,ae=1,ie=2;function se(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function p(e){return e.split("/").filter(t=>t!=="")}function h(e,t){let n=p(e),r=[],o=n.length===0?ie:0,a="";for(let s of n){if(s==="*"){r.push("*"),o+=ae,a+="(?:/(.*))?";continue}if(s.startsWith(":")){let u=s.endsWith("?");r.push(s.slice(1,u?-1:void 0)),o+=u?re:oe,a+=u?"(?:/([^/]+))?":"/([^/]+)";continue}o+=ne,a+=`/${se(s)}`}let i=new RegExp(`^${a}${t?"/?$":"(?=/|$)"}`,"i");return{source:e,regex:i,keys:r,score:o,end:t}}function g(e,t){let n=e.regex.exec(t);if(n===null)return null;let r={};for(let o=0;o<e.keys.length;o++){let a=n[o+1];a!==void 0&&(r[e.keys[o]]=decodeURIComponent(a))}return{params:r,consumed:n[0]}}function v(e){return`/${p(e).join("/")}`}var z=new WeakMap;function le(e){return e.index===!0?"":e.path??""}function W(e,t,n){for(let r of e){let o=[...t,r];n.push(ce(o));let a=r.children;a!==void 0&&W(a,o,n)}}function ce(e){let t=e.map((n,r)=>({route:n,pattern:h(le(n),r===e.length-1)}));return{levels:t,score:t.reduce((n,r)=>n+r.pattern.score,0)}}function pe(e){let t=z.get(e);if(t!==void 0)return t;let n=[];return W(e,[],n),n.sort((r,o)=>o.score-r.score),z.set(e,n),n}function L(e,t){for(let n of pe(e)){let r=[],o=t===""?"/":t,a="",i={},s=!1;for(let u of n.levels){let l=g(u.pattern,o);if(l===null){s=!0;break}i={...i,...l.params},a+=l.consumed,r.push({route:u.route,params:i,pathname:a===""?"/":a}),o=o.slice(l.consumed.length)}if(!s)return r}return null}var V=new WeakMap;function k(e){if(e.component!==void 0)return e.component;let t=V.get(e);return t===void 0&&(t=ue(void 0),V.set(e,t),de(e,t)),t.value}async function de(e,t){let n=await e.lazy();t.value=typeof n=="function"?n:n.default}function D(e,t){let n=L(e,t);if(n!==null)for(let r of n)r.route.component===void 0&&r.route.lazy!==void 0&&k(r.route)}var I=e=>{let{children:t,...n}=e;return typeof t!="function"?e:{...n,children:t(I)}};var c=T(),P=T(-1,"route depth"),he=()=>null,ge=Object.freeze({}),K=new WeakMap;function ve(e,t){if(fe(e))return e;let n=K.get(e);return n===void 0&&(n=H(r=>e(r),void 0,`firsthand/router:route(${t})`,"Route"),K.set(e,n)),n}function _(e){let t=U(c),n=M(()=>t.value.matches.value[e]?.route),r=M(()=>t.value.matches.value[e]?.params??ge,{equals:y}),o=new Proxy({},{get:(i,s)=>typeof s=="string"?r.value[s]:void 0,has:(i,s)=>typeof s=="string"&&s in r.value,ownKeys:()=>Object.keys(r.value),getOwnPropertyDescriptor:(i,s)=>typeof s=="string"&&s in r.value?{configurable:!0,enumerable:!0,value:r.value[s]}:void 0}),a=Object.freeze({params:o});return ye(()=>{let i=n.value;if(i===void 0)return null;$(P,e);let s=k(i);return s===void 0?(i.pending??t.value.pending??he)():ve(s,i.path??"")(a)})}var Pe=H(e=>{let t=e.history===void 0,n=e.history??S(e.basename??"");t&&me(()=>{n.dispose()});let r=e.routes,o=M(()=>L(r,n.location.value.pathname)??[]);return $(c,{history:n,routes:r,matches:o,pending:e.pending}),$(P,-1),_(0)},void 0,"firsthand/router:Router","Router"),Re=H(()=>_(U(P).value+1),void 0,"firsthand/router:Outlet","Outlet");import{bind as A,computed as q,useContext as Y}from"@firsthandjs/core";import{component as X}from"@firsthandjs/dom";import{insert as ke,on as be,rest as Ne,setAttribute as G,setClass as Oe,spread as Se}from"@firsthandjs/dom/internal";import{computed as b,useContext as d}from"@firsthandjs/core";function R(e,t){let n=e.search(/[?#]/),r=n===-1?e:e.slice(0,n),o=n===-1?"":e.slice(n);if(r.startsWith("/"))return`${v(r)}${o}`;let a=p(t);for(let i of p(r))if(i!=="."){if(i===".."){a.pop();continue}a.push(i)}return`/${a.join("/")}${o}`}function x(){let e=d(c),t=d(P).value;return b(()=>e.value.matches.value[t]?.pathname??"/")}function F(){return d(c).value}function j(){return F().history.location}function xe(){let e=d(c);return b(()=>{let t=e.value.matches.value;return t[t.length-1]?.params??{}},{equals:y})}function we(){return d(c).value.matches}function N(){let e=d(c),t=x();return(n,r)=>{let{history:o}=e.value;if(typeof n=="number"){o.go(n);return}let a=R(n,t.value);r?.replace===!0?o.replace(a,r):o.push(a,r)}}function E(e,t,n){let r=v(e),o=v(t);return n?r===o:r===o||r.startsWith(o==="/"?"/":`${o}/`)}function Ce(e){let t=h(e,!0),n=j();return b(()=>g(t,n.value.pathname))}function Le(){let e=j(),t=N();return[b(()=>new URLSearchParams(e.value.search)),(o,a)=>{let i=new URLSearchParams(o).toString();t(`${e.value.pathname}${i===""?"":`?${i}`}`,a)}]}var J=["to","replace","state","preload","onClick","children"],De=[...J,"end","activeClass","class"];function Me(e,t){return e.button===0&&!e.metaKey&&!e.altKey&&!e.ctrlKey&&!e.shiftKey&&(t.target===""||t.target==="_self")}function Q(e,t){let n=Y(c),r=x(),o=document.createElement("a"),a=q(()=>R(e.to,r.value));A(()=>{G(o,"href",n.value.history.href(a.value))});let i=Ne(e,t);if(A(()=>{Se(o,i)}),ke(o,()=>e.children),be(o,"click",s=>{let u=s;if(e.onClick?.(u),u.defaultPrevented||!Me(u,o))return;u.preventDefault();let{history:l}=n.value,w={replace:e.replace===!0,state:e.state};e.replace===!0?l.replace(a.value,w):l.push(a.value,w)}),e.preload===!0){let s=()=>{D(n.value.routes,a.value)};o.addEventListener("pointerenter",s),o.addEventListener("focus",s)}return o}var $e=X(e=>Q(e,J),void 0,"firsthand/router:Link","Link"),He=X(e=>{let t=Q(e,De),n=Y(c),r=x(),o=q(()=>E(n.value.history.location.value.pathname,R(e.to,r.value),e.end===!0));return A(()=>{let a=o.value?e.activeClass??"active":"",i=e.class??"";Oe(t,`${i}${i!==""&&a!==""?" ":""}${a}`),G(t,"aria-current",o.value?"page":null)}),t},void 0,"firsthand/router:NavLink","NavLink");import{onCleanup as je}from"@firsthandjs/core";import{component as Ee}from"@firsthandjs/dom";var Ae=Ee(e=>{let t=N(),n=!0;return je(()=>{n=!1}),queueMicrotask(()=>{n&&t(e.to,{replace:e.replace??!0,state:e.state})}),null},void 0,"firsthand/router:Navigate","Navigate");export{$e as Link,He as NavLink,Ae as Navigate,Re as Outlet,Pe as Router,c as RouterContext,h as compilePattern,S as createBrowserHistory,ee as createHashHistory,te as createMemoryHistory,E as isActivePath,g as matchPattern,L as matchRoutes,v as normalizePath,f as parsePath,D as preloadRoutes,R as resolvePath,I as route,k as routeComponent,y as sameParams,p as segments,x as useBasePath,j as useLocation,Ce as useMatch,we as useMatches,N as useNavigate,xe as useRouteParams,F as useRouter,Le as useSearchParams};
|
package/dist/links.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type View } from '@firsthandjs/dom';
|
|
2
|
-
export
|
|
2
|
+
export type LinkProps = {
|
|
3
3
|
readonly to: string;
|
|
4
4
|
readonly replace?: boolean;
|
|
5
5
|
readonly state?: unknown;
|
|
@@ -14,7 +14,7 @@ export interface LinkProps {
|
|
|
14
14
|
readonly children?: View;
|
|
15
15
|
/** Anything else is forwarded to the anchor. */
|
|
16
16
|
readonly [attribute: string]: unknown;
|
|
17
|
-
}
|
|
17
|
+
};
|
|
18
18
|
export interface NavLinkProps extends LinkProps {
|
|
19
19
|
/** Active only on an exact match, rather than on a prefix. */
|
|
20
20
|
readonly end?: boolean;
|
package/dist/links.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAaA,OAAO,EAAa,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAMxD,MAAM,
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAaA,OAAO,EAAa,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAMxD,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAC/C,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC;IACzB,gDAAgD;IAChD,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;CACvC,CAAC;AAEF,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC7C,8DAA8D;IAC9D,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,kEAAkE;IAClE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AA8DD,eAAO,MAAM,IAAI,iDAKhB,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,OAAO,oDAuBnB,CAAC"}
|
package/dist/match.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ type SegmentParams<S extends string> = S extends `:${infer Name}?` ? {
|
|
|
42
42
|
* has to be declared twice: the route table already says what the path is.
|
|
43
43
|
*/
|
|
44
44
|
export type ParamsOf<Path extends string> = Path extends `${infer Head}/${infer Rest}` ? SegmentParams<Head> & ParamsOf<Rest> : SegmentParams<Path>;
|
|
45
|
-
export
|
|
45
|
+
export type Pattern = {
|
|
46
46
|
readonly source: string;
|
|
47
47
|
readonly regex: RegExp;
|
|
48
48
|
readonly keys: readonly string[];
|
|
@@ -50,7 +50,7 @@ export interface Pattern {
|
|
|
50
50
|
readonly score: number;
|
|
51
51
|
/** Whether the pattern must consume the whole path. */
|
|
52
52
|
readonly end: boolean;
|
|
53
|
-
}
|
|
53
|
+
};
|
|
54
54
|
/** Splits a path into segments, ignoring empty ones from leading/double slashes. */
|
|
55
55
|
export declare function segments(path: string): string[];
|
|
56
56
|
/**
|
package/dist/match.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../src/match.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,sDAAsD;AACtD,MAAM,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,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AA;CAAE,GAAG,IAAI,CAa7C;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGtD"}
|
package/dist/router.d.ts
CHANGED
|
@@ -13,18 +13,18 @@ import { type ReadonlyCell } from '@firsthandjs/core';
|
|
|
13
13
|
import { type Component, type View } from '@firsthandjs/dom';
|
|
14
14
|
import { type History } from './history.js';
|
|
15
15
|
import { type RouteDefinition, type RouteMatch } from './routes.js';
|
|
16
|
-
export
|
|
16
|
+
export type RouterState = {
|
|
17
17
|
readonly history: History;
|
|
18
18
|
readonly routes: readonly RouteDefinition[];
|
|
19
19
|
/** The chain from the outermost matched route to the leaf. Empty if none matched. */
|
|
20
20
|
readonly matches: ReadonlyCell<readonly RouteMatch[]>;
|
|
21
21
|
/** Shown while a lazy route is loading, unless the route has its own. */
|
|
22
22
|
readonly pending: (() => View) | undefined;
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
export declare const RouterContext: import("@firsthandjs/core").Context<RouterState>;
|
|
25
25
|
/** How deep in the matched chain the surrounding route sits. */
|
|
26
26
|
export declare const DepthContext: import("@firsthandjs/core").Context<number>;
|
|
27
|
-
export
|
|
27
|
+
export type RouterProps = {
|
|
28
28
|
readonly routes: readonly RouteDefinition[];
|
|
29
29
|
/** Defaults to a browser history over the real URL. */
|
|
30
30
|
readonly history?: History;
|
|
@@ -32,7 +32,7 @@ export interface RouterProps {
|
|
|
32
32
|
readonly basename?: string;
|
|
33
33
|
/** Shown while a lazy route is loading. */
|
|
34
34
|
readonly pending?: () => View;
|
|
35
|
-
}
|
|
35
|
+
};
|
|
36
36
|
/**
|
|
37
37
|
* The root of a routed application.
|
|
38
38
|
*
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAML,KAAK,YAAY,E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M,CAAC;IAC3B,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,MAAM,wBAsBlB,CAAC;AAEF,qDAAqD;AACrD,eAAO,MAAM,MAAM,kCAKlB,CAAC"}
|
package/dist/routes.d.ts
CHANGED
|
@@ -8,16 +8,16 @@ import { type Params, type ParamsOf, type Simplify } from './match.js';
|
|
|
8
8
|
* ordinary reactive read, so a navigation from `/users/1` to `/users/2`
|
|
9
9
|
* updates what read it and remounts nothing.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export type RouteProps<P extends Params = Params> = {
|
|
12
12
|
readonly params: P;
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
14
|
/** A component that a route renders. */
|
|
15
15
|
export type RouteComponent<P extends Params = Params> = (props: RouteProps<P>) => View;
|
|
16
16
|
/** What a `lazy` import may resolve to: the component, or a module holding it. */
|
|
17
17
|
export type LazyModule<P extends Params = Params> = RouteComponent<P> | {
|
|
18
18
|
readonly default: RouteComponent<P>;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export type RouteDefinition = {
|
|
21
21
|
/** Relative to the parent, unless it starts with `/`. */
|
|
22
22
|
readonly path?: string;
|
|
23
23
|
/** Matches when the parent matches and nothing is left over. */
|
|
@@ -34,13 +34,13 @@ export interface RouteDefinition {
|
|
|
34
34
|
/** Shown while `lazy` is loading, instead of the router's own fallback. */
|
|
35
35
|
readonly pending?: () => View;
|
|
36
36
|
readonly children?: readonly RouteDefinition[];
|
|
37
|
-
}
|
|
38
|
-
export
|
|
37
|
+
};
|
|
38
|
+
export type RouteMatch = {
|
|
39
39
|
readonly route: RouteDefinition;
|
|
40
40
|
readonly params: Params;
|
|
41
41
|
/** The portion of the pathname this route and its ancestors consumed. */
|
|
42
42
|
readonly pathname: string;
|
|
43
|
-
}
|
|
43
|
+
};
|
|
44
44
|
/**
|
|
45
45
|
* Matches a pathname against a route tree.
|
|
46
46
|
*
|
|
@@ -94,16 +94,16 @@ export declare function preloadRoutes(routes: readonly RouteDefinition[], pathna
|
|
|
94
94
|
*/
|
|
95
95
|
export declare const route: RouteBuilder<unknown>;
|
|
96
96
|
/** What `route` accepts, with `Own` from its path and `Inherited` from above. */
|
|
97
|
-
|
|
97
|
+
type RouteSpec<Own, Inherited> = {
|
|
98
98
|
readonly component?: RouteComponent<Simplify<Inherited & Own> & Params>;
|
|
99
99
|
/** Loaded when the route is first entered; the result is cached. */
|
|
100
100
|
readonly lazy?: () => Promise<LazyModule<Simplify<Inherited & Own> & Params>>;
|
|
101
101
|
/** Shown while `lazy` is loading, instead of the router's own fallback. */
|
|
102
102
|
readonly pending?: () => View;
|
|
103
103
|
readonly children?: readonly RouteDefinition[] | ((child: RouteBuilder<Simplify<Inherited & Own>>) => readonly RouteDefinition[]);
|
|
104
|
-
}
|
|
104
|
+
};
|
|
105
105
|
/** Builds one route, knowing what the routes above it captured. */
|
|
106
|
-
export
|
|
106
|
+
export type RouteBuilder<Inherited> = {
|
|
107
107
|
<const Path extends string>(spec: {
|
|
108
108
|
readonly path: Path;
|
|
109
109
|
} & RouteSpec<ParamsOf<Path>, Inherited>): RouteDefinition;
|
|
@@ -111,6 +111,6 @@ export interface RouteBuilder<Inherited> {
|
|
|
111
111
|
(spec: {
|
|
112
112
|
readonly index: true;
|
|
113
113
|
} & RouteSpec<unknown, Inherited>): RouteDefinition;
|
|
114
|
-
}
|
|
114
|
+
};
|
|
115
115
|
export {};
|
|
116
116
|
//# sourceMappingURL=routes.d.ts.map
|
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,QAAQ,EAEb,KAAK,QAAQ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AC,SAAS,IAAI;IACpC,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EACxB,IAAI,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;KAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,GACnE,eAAe,CAAC;IACnB,+EAA+E;IAC/E,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAA;KAAE,GAAG,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,eAAe,CAAC;CACnF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firsthandjs/router",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Routing for Firsthand: nested routes, params, and route code loaded on demand.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@firsthandjs/core": "0.7.
|
|
23
|
-
"@firsthandjs/dom": "0.7.
|
|
22
|
+
"@firsthandjs/core": "0.7.1",
|
|
23
|
+
"@firsthandjs/dom": "0.7.1"
|
|
24
24
|
},
|
|
25
25
|
"engines": {
|
|
26
26
|
"node": ">=20.11.0"
|